1
/******************************************************************************
3
Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved.
5
This program is free software; you can redistribute it and/or modify it
6
under the terms of version 2 of the GNU General Public License as
7
published by the Free Software Foundation.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14
You should have received a copy of the GNU General Public License along with
15
this program; if not, write to the Free Software Foundation, Inc., 59
16
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
The full GNU General Public License is included in this distribution in the
22
Intel Linux Wireless <ilw@linux.intel.com>
23
Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
Portions of this file are based on the sample_* files provided by Wireless
26
Extensions 0.26 package and copyright (c) 1997-2003 Jean Tourrilhes
29
Portions of this file are based on the Host AP project,
30
Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
32
Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
34
Portions of ipw2100_mod_firmware_load, ipw2100_do_mod_firmware_load, and
35
ipw2100_fw_load are loosely based on drivers/sound/sound_firmware.c
36
available in the 2.4.25 kernel sources, and are copyright (c) Alan Cox
38
******************************************************************************/
41
Initial driver on which this is based was developed by Janusz Gorycki,
42
Maciej Urbaniak, and Maciej Sosnowski.
44
Promiscuous mode support added by Jacek Wysoczynski and Maciej Urbaniak.
48
Tx - Commands and Data
50
Firmware and host share a circular queue of Transmit Buffer Descriptors (TBDs)
51
Each TBD contains a pointer to the physical (dma_addr_t) address of data being
52
sent to the firmware as well as the length of the data.
54
The host writes to the TBD queue at the WRITE index. The WRITE index points
55
to the _next_ packet to be written and is advanced when after the TBD has been
58
The firmware pulls from the TBD queue at the READ index. The READ index points
59
to the currently being read entry, and is advanced once the firmware is
62
When data is sent to the firmware, the first TBD is used to indicate to the
63
firmware if a Command or Data is being sent. If it is Command, all of the
64
command information is contained within the physical address referred to by the
65
TBD. If it is Data, the first TBD indicates the type of data packet, number
66
of fragments, etc. The next TBD then referrs to the actual packet location.
68
The Tx flow cycle is as follows:
70
1) ipw2100_tx() is called by kernel with SKB to transmit
71
2) Packet is move from the tx_free_list and appended to the transmit pending
73
3) work is scheduled to move pending packets into the shared circular queue.
74
4) when placing packet in the circular queue, the incoming SKB is DMA mapped
75
to a physical address. That address is entered into a TBD. Two TBDs are
76
filled out. The first indicating a data packet, the second referring to the
78
5) the packet is removed from tx_pend_list and placed on the end of the
79
firmware pending list (fw_pend_list)
80
6) firmware is notified that the WRITE index has
81
7) Once the firmware has processed the TBD, INTA is triggered.
82
8) For each Tx interrupt received from the firmware, the READ index is checked
83
to see which TBDs are done being processed.
84
9) For each TBD that has been processed, the ISR pulls the oldest packet
85
from the fw_pend_list.
86
10)The packet structure contained in the fw_pend_list is then used
87
to unmap the DMA address and to free the SKB originally passed to the driver
89
11)The packet structure is placed onto the tx_free_list
91
The above steps are the same for commands, only the msg_free_list/msg_pend_list
92
are used instead of tx_free_list/tx_pend_list
96
Critical Sections / Locking :
98
There are two locks utilized. The first is the low level lock (priv->low_lock)
99
that protects the following:
101
- Access to the Tx/Rx queue lists via priv->low_lock. The lists are as follows:
103
tx_free_list : Holds pre-allocated Tx buffers.
104
TAIL modified in __ipw2100_tx_process()
105
HEAD modified in ipw2100_tx()
107
tx_pend_list : Holds used Tx buffers waiting to go into the TBD ring
108
TAIL modified ipw2100_tx()
109
HEAD modified by ipw2100_tx_send_data()
111
msg_free_list : Holds pre-allocated Msg (Command) buffers
112
TAIL modified in __ipw2100_tx_process()
113
HEAD modified in ipw2100_hw_send_command()
115
msg_pend_list : Holds used Msg buffers waiting to go into the TBD ring
116
TAIL modified in ipw2100_hw_send_command()
117
HEAD modified in ipw2100_tx_send_commands()
119
The flow of data on the TX side is as follows:
121
MSG_FREE_LIST + COMMAND => MSG_PEND_LIST => TBD => MSG_FREE_LIST
122
TX_FREE_LIST + DATA => TX_PEND_LIST => TBD => TX_FREE_LIST
124
The methods that work on the TBD ring are protected via priv->low_lock.
126
- The internal data state of the device itself
127
- Access to the firmware read/write indexes for the BD queues
130
All external entry functions are locked with the priv->action_lock to ensure
131
that only one external action is invoked at a time.
136
#include <linux/compiler.h>
137
#include <linux/errno.h>
138
#include <linux/if_arp.h>
139
#include <linux/in6.h>
140
#include <linux/in.h>
141
#include <linux/ip.h>
142
#include <linux/kernel.h>
143
#include <linux/kmod.h>
144
#include <linux/module.h>
145
#include <linux/netdevice.h>
146
#include <linux/ethtool.h>
147
#include <linux/pci.h>
148
#include <linux/dma-mapping.h>
149
#include <linux/proc_fs.h>
150
#include <linux/skbuff.h>
151
#include <asm/uaccess.h>
153
#include <linux/fs.h>
154
#include <linux/mm.h>
155
#include <linux/slab.h>
156
#include <linux/unistd.h>
157
#include <linux/stringify.h>
158
#include <linux/tcp.h>
159
#include <linux/types.h>
160
#include <linux/time.h>
161
#include <linux/firmware.h>
162
#include <linux/acpi.h>
163
#include <linux/ctype.h>
164
#include <linux/pm_qos_params.h>
166
#include <net/lib80211.h>
170
#define IPW2100_VERSION "git-1.2.2"
172
#define DRV_NAME "ipw2100"
173
#define DRV_VERSION IPW2100_VERSION
174
#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2100 Network Driver"
175
#define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
177
/* Debugging stuff */
178
#ifdef CONFIG_IPW2100_DEBUG
179
#define IPW2100_RX_DEBUG /* Reception debugging */
182
MODULE_DESCRIPTION(DRV_DESCRIPTION);
183
MODULE_VERSION(DRV_VERSION);
184
MODULE_AUTHOR(DRV_COPYRIGHT);
185
MODULE_LICENSE("GPL");
187
static int debug = 0;
188
static int network_mode = 0;
189
static int channel = 0;
190
static int associate = 0;
191
static int disable = 0;
193
static struct ipw2100_fw ipw2100_firmware;
196
#include <linux/moduleparam.h>
197
module_param(debug, int, 0444);
198
module_param_named(mode, network_mode, int, 0444);
199
module_param(channel, int, 0444);
200
module_param(associate, int, 0444);
201
module_param(disable, int, 0444);
203
MODULE_PARM_DESC(debug, "debug level");
204
MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
205
MODULE_PARM_DESC(channel, "channel");
206
MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
207
MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
209
static u32 ipw2100_debug_level = IPW_DL_NONE;
211
#ifdef CONFIG_IPW2100_DEBUG
212
#define IPW_DEBUG(level, message...) \
214
if (ipw2100_debug_level & (level)) { \
215
printk(KERN_DEBUG "ipw2100: %c %s ", \
216
in_interrupt() ? 'I' : 'U', __func__); \
221
#define IPW_DEBUG(level, message...) do {} while (0)
222
#endif /* CONFIG_IPW2100_DEBUG */
224
#ifdef CONFIG_IPW2100_DEBUG
225
static const char *command_types[] = {
227
"unused", /* HOST_ATTENTION */
229
"unused", /* SLEEP */
230
"unused", /* HOST_POWER_DOWN */
233
"unused", /* SET_IMR */
236
"AUTHENTICATION_TYPE",
239
"INTERNATIONAL_MODE",
254
"CLEAR_ALL_MULTICAST",
275
"AP_OR_STATION_TABLE",
279
"unused", /* SAVE_CALIBRATION */
280
"unused", /* RESTORE_CALIBRATION */
284
"HOST_PRE_POWER_DOWN",
285
"unused", /* HOST_INTERRUPT_COALESCING */
287
"CARD_DISABLE_PHY_OFF",
288
"MSDU_TX_RATES" "undefined",
290
"SET_STATION_STAT_BITS",
291
"CLEAR_STATIONS_STAT_BITS",
293
"SET_SECURITY_INFORMATION",
294
"DISASSOCIATION_BSSID",
299
#define WEXT_USECHANNELS 1
301
static const long ipw2100_frequencies[] = {
302
2412, 2417, 2422, 2427,
303
2432, 2437, 2442, 2447,
304
2452, 2457, 2462, 2467,
308
#define FREQ_COUNT ARRAY_SIZE(ipw2100_frequencies)
310
static const long ipw2100_rates_11b[] = {
317
static struct ieee80211_rate ipw2100_bg_rates[] = {
319
{ .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
320
{ .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
321
{ .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
324
#define RATE_COUNT ARRAY_SIZE(ipw2100_rates_11b)
326
/* Pre-decl until we get the code solid and then we can clean it up */
327
static void ipw2100_tx_send_commands(struct ipw2100_priv *priv);
328
static void ipw2100_tx_send_data(struct ipw2100_priv *priv);
329
static int ipw2100_adapter_setup(struct ipw2100_priv *priv);
331
static void ipw2100_queues_initialize(struct ipw2100_priv *priv);
332
static void ipw2100_queues_free(struct ipw2100_priv *priv);
333
static int ipw2100_queues_allocate(struct ipw2100_priv *priv);
335
static int ipw2100_fw_download(struct ipw2100_priv *priv,
336
struct ipw2100_fw *fw);
337
static int ipw2100_get_firmware(struct ipw2100_priv *priv,
338
struct ipw2100_fw *fw);
339
static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
341
static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
343
static void ipw2100_release_firmware(struct ipw2100_priv *priv,
344
struct ipw2100_fw *fw);
345
static int ipw2100_ucode_download(struct ipw2100_priv *priv,
346
struct ipw2100_fw *fw);
347
static void ipw2100_wx_event_work(struct work_struct *work);
348
static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev);
349
static struct iw_handler_def ipw2100_wx_handler_def;
351
static inline void read_register(struct net_device *dev, u32 reg, u32 * val)
353
*val = readl((void __iomem *)(dev->base_addr + reg));
354
IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val);
357
static inline void write_register(struct net_device *dev, u32 reg, u32 val)
359
writel(val, (void __iomem *)(dev->base_addr + reg));
360
IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val);
363
static inline void read_register_word(struct net_device *dev, u32 reg,
366
*val = readw((void __iomem *)(dev->base_addr + reg));
367
IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val);
370
static inline void read_register_byte(struct net_device *dev, u32 reg, u8 * val)
372
*val = readb((void __iomem *)(dev->base_addr + reg));
373
IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val);
376
static inline void write_register_word(struct net_device *dev, u32 reg, u16 val)
378
writew(val, (void __iomem *)(dev->base_addr + reg));
379
IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val);
382
static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val)
384
writeb(val, (void __iomem *)(dev->base_addr + reg));
385
IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val);
388
static inline void read_nic_dword(struct net_device *dev, u32 addr, u32 * val)
390
write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
391
addr & IPW_REG_INDIRECT_ADDR_MASK);
392
read_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
395
static inline void write_nic_dword(struct net_device *dev, u32 addr, u32 val)
397
write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
398
addr & IPW_REG_INDIRECT_ADDR_MASK);
399
write_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
402
static inline void read_nic_word(struct net_device *dev, u32 addr, u16 * val)
404
write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
405
addr & IPW_REG_INDIRECT_ADDR_MASK);
406
read_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
409
static inline void write_nic_word(struct net_device *dev, u32 addr, u16 val)
411
write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
412
addr & IPW_REG_INDIRECT_ADDR_MASK);
413
write_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
416
static inline void read_nic_byte(struct net_device *dev, u32 addr, u8 * val)
418
write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
419
addr & IPW_REG_INDIRECT_ADDR_MASK);
420
read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
423
static inline void write_nic_byte(struct net_device *dev, u32 addr, u8 val)
425
write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
426
addr & IPW_REG_INDIRECT_ADDR_MASK);
427
write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
430
static inline void write_nic_auto_inc_address(struct net_device *dev, u32 addr)
432
write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
433
addr & IPW_REG_INDIRECT_ADDR_MASK);
436
static inline void write_nic_dword_auto_inc(struct net_device *dev, u32 val)
438
write_register(dev, IPW_REG_AUTOINCREMENT_DATA, val);
441
static void write_nic_memory(struct net_device *dev, u32 addr, u32 len,
449
/* read first nibble byte by byte */
450
aligned_addr = addr & (~0x3);
451
dif_len = addr - aligned_addr;
453
/* Start reading at aligned_addr + dif_len */
454
write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
456
for (i = dif_len; i < 4; i++, buf++)
457
write_register_byte(dev,
458
IPW_REG_INDIRECT_ACCESS_DATA + i,
465
/* read DWs through autoincrement registers */
466
write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr);
467
aligned_len = len & (~0x3);
468
for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
469
write_register(dev, IPW_REG_AUTOINCREMENT_DATA, *(u32 *) buf);
471
/* copy the last nibble */
472
dif_len = len - aligned_len;
473
write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
474
for (i = 0; i < dif_len; i++, buf++)
475
write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i,
479
static void read_nic_memory(struct net_device *dev, u32 addr, u32 len,
487
/* read first nibble byte by byte */
488
aligned_addr = addr & (~0x3);
489
dif_len = addr - aligned_addr;
491
/* Start reading at aligned_addr + dif_len */
492
write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
494
for (i = dif_len; i < 4; i++, buf++)
495
read_register_byte(dev,
496
IPW_REG_INDIRECT_ACCESS_DATA + i,
503
/* read DWs through autoincrement registers */
504
write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr);
505
aligned_len = len & (~0x3);
506
for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
507
read_register(dev, IPW_REG_AUTOINCREMENT_DATA, (u32 *) buf);
509
/* copy the last nibble */
510
dif_len = len - aligned_len;
511
write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
512
for (i = 0; i < dif_len; i++, buf++)
513
read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i, buf);
516
static inline int ipw2100_hw_is_adapter_in_system(struct net_device *dev)
518
return (dev->base_addr &&
520
((void __iomem *)(dev->base_addr +
521
IPW_REG_DOA_DEBUG_AREA_START))
522
== IPW_DATA_DOA_DEBUG_VALUE));
525
static int ipw2100_get_ordinal(struct ipw2100_priv *priv, u32 ord,
526
void *val, u32 * len)
528
struct ipw2100_ordinals *ordinals = &priv->ordinals;
535
if (ordinals->table1_addr == 0) {
536
printk(KERN_WARNING DRV_NAME ": attempt to use fw ordinals "
537
"before they have been loaded.\n");
541
if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
542
if (*len < IPW_ORD_TAB_1_ENTRY_SIZE) {
543
*len = IPW_ORD_TAB_1_ENTRY_SIZE;
545
printk(KERN_WARNING DRV_NAME
546
": ordinal buffer length too small, need %zd\n",
547
IPW_ORD_TAB_1_ENTRY_SIZE);
552
read_nic_dword(priv->net_dev,
553
ordinals->table1_addr + (ord << 2), &addr);
554
read_nic_dword(priv->net_dev, addr, val);
556
*len = IPW_ORD_TAB_1_ENTRY_SIZE;
561
if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) {
563
ord -= IPW_START_ORD_TAB_2;
565
/* get the address of statistic */
566
read_nic_dword(priv->net_dev,
567
ordinals->table2_addr + (ord << 3), &addr);
569
/* get the second DW of statistics ;
570
* two 16-bit words - first is length, second is count */
571
read_nic_dword(priv->net_dev,
572
ordinals->table2_addr + (ord << 3) + sizeof(u32),
575
/* get each entry length */
576
field_len = *((u16 *) & field_info);
578
/* get number of entries */
579
field_count = *(((u16 *) & field_info) + 1);
581
/* abort if no enough memory */
582
total_length = field_len * field_count;
583
if (total_length > *len) {
592
/* read the ordinal data from the SRAM */
593
read_nic_memory(priv->net_dev, addr, total_length, val);
598
printk(KERN_WARNING DRV_NAME ": ordinal %d neither in table 1 nor "
599
"in table 2\n", ord);
604
static int ipw2100_set_ordinal(struct ipw2100_priv *priv, u32 ord, u32 * val,
607
struct ipw2100_ordinals *ordinals = &priv->ordinals;
610
if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
611
if (*len != IPW_ORD_TAB_1_ENTRY_SIZE) {
612
*len = IPW_ORD_TAB_1_ENTRY_SIZE;
613
IPW_DEBUG_INFO("wrong size\n");
617
read_nic_dword(priv->net_dev,
618
ordinals->table1_addr + (ord << 2), &addr);
620
write_nic_dword(priv->net_dev, addr, *val);
622
*len = IPW_ORD_TAB_1_ENTRY_SIZE;
627
IPW_DEBUG_INFO("wrong table\n");
628
if (IS_ORDINAL_TABLE_TWO(ordinals, ord))
634
static char *snprint_line(char *buf, size_t count,
635
const u8 * data, u32 len, u32 ofs)
640
out = snprintf(buf, count, "%08X", ofs);
642
for (l = 0, i = 0; i < 2; i++) {
643
out += snprintf(buf + out, count - out, " ");
644
for (j = 0; j < 8 && l < len; j++, l++)
645
out += snprintf(buf + out, count - out, "%02X ",
648
out += snprintf(buf + out, count - out, " ");
651
out += snprintf(buf + out, count - out, " ");
652
for (l = 0, i = 0; i < 2; i++) {
653
out += snprintf(buf + out, count - out, " ");
654
for (j = 0; j < 8 && l < len; j++, l++) {
655
c = data[(i * 8 + j)];
656
if (!isascii(c) || !isprint(c))
659
out += snprintf(buf + out, count - out, "%c", c);
663
out += snprintf(buf + out, count - out, " ");
669
static void printk_buf(int level, const u8 * data, u32 len)
673
if (!(ipw2100_debug_level & level))
677
printk(KERN_DEBUG "%s\n",
678
snprint_line(line, sizeof(line), &data[ofs],
679
min(len, 16U), ofs));
681
len -= min(len, 16U);
685
#define MAX_RESET_BACKOFF 10
687
static void schedule_reset(struct ipw2100_priv *priv)
689
unsigned long now = get_seconds();
691
/* If we haven't received a reset request within the backoff period,
692
* then we can reset the backoff interval so this reset occurs
694
if (priv->reset_backoff &&
695
(now - priv->last_reset > priv->reset_backoff))
696
priv->reset_backoff = 0;
698
priv->last_reset = get_seconds();
700
if (!(priv->status & STATUS_RESET_PENDING)) {
701
IPW_DEBUG_INFO("%s: Scheduling firmware restart (%ds).\n",
702
priv->net_dev->name, priv->reset_backoff);
703
netif_carrier_off(priv->net_dev);
704
netif_stop_queue(priv->net_dev);
705
priv->status |= STATUS_RESET_PENDING;
706
if (priv->reset_backoff)
707
queue_delayed_work(priv->workqueue, &priv->reset_work,
708
priv->reset_backoff * HZ);
710
queue_delayed_work(priv->workqueue, &priv->reset_work,
713
if (priv->reset_backoff < MAX_RESET_BACKOFF)
714
priv->reset_backoff++;
716
wake_up_interruptible(&priv->wait_command_queue);
718
IPW_DEBUG_INFO("%s: Firmware restart already in progress.\n",
719
priv->net_dev->name);
723
#define HOST_COMPLETE_TIMEOUT (2 * HZ)
724
static int ipw2100_hw_send_command(struct ipw2100_priv *priv,
725
struct host_command *cmd)
727
struct list_head *element;
728
struct ipw2100_tx_packet *packet;
732
IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
733
command_types[cmd->host_command], cmd->host_command,
734
cmd->host_command_length);
735
printk_buf(IPW_DL_HC, (u8 *) cmd->host_command_parameters,
736
cmd->host_command_length);
738
spin_lock_irqsave(&priv->low_lock, flags);
740
if (priv->fatal_error) {
742
("Attempt to send command while hardware in fatal error condition.\n");
747
if (!(priv->status & STATUS_RUNNING)) {
749
("Attempt to send command while hardware is not running.\n");
754
if (priv->status & STATUS_CMD_ACTIVE) {
756
("Attempt to send command while another command is pending.\n");
761
if (list_empty(&priv->msg_free_list)) {
762
IPW_DEBUG_INFO("no available msg buffers\n");
766
priv->status |= STATUS_CMD_ACTIVE;
767
priv->messages_sent++;
769
element = priv->msg_free_list.next;
771
packet = list_entry(element, struct ipw2100_tx_packet, list);
772
packet->jiffy_start = jiffies;
774
/* initialize the firmware command packet */
775
packet->info.c_struct.cmd->host_command_reg = cmd->host_command;
776
packet->info.c_struct.cmd->host_command_reg1 = cmd->host_command1;
777
packet->info.c_struct.cmd->host_command_len_reg =
778
cmd->host_command_length;
779
packet->info.c_struct.cmd->sequence = cmd->host_command_sequence;
781
memcpy(packet->info.c_struct.cmd->host_command_params_reg,
782
cmd->host_command_parameters,
783
sizeof(packet->info.c_struct.cmd->host_command_params_reg));
786
DEC_STAT(&priv->msg_free_stat);
788
list_add_tail(element, &priv->msg_pend_list);
789
INC_STAT(&priv->msg_pend_stat);
791
ipw2100_tx_send_commands(priv);
792
ipw2100_tx_send_data(priv);
794
spin_unlock_irqrestore(&priv->low_lock, flags);
797
* We must wait for this command to complete before another
798
* command can be sent... but if we wait more than 3 seconds
799
* then there is a problem.
803
wait_event_interruptible_timeout(priv->wait_command_queue,
805
status & STATUS_CMD_ACTIVE),
806
HOST_COMPLETE_TIMEOUT);
809
IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
810
1000 * (HOST_COMPLETE_TIMEOUT / HZ));
811
priv->fatal_error = IPW2100_ERR_MSG_TIMEOUT;
812
priv->status &= ~STATUS_CMD_ACTIVE;
813
schedule_reset(priv);
817
if (priv->fatal_error) {
818
printk(KERN_WARNING DRV_NAME ": %s: firmware fatal error\n",
819
priv->net_dev->name);
823
/* !!!!! HACK TEST !!!!!
824
* When lots of debug trace statements are enabled, the driver
825
* doesn't seem to have as many firmware restart cycles...
827
* As a test, we're sticking in a 1/100s delay here */
828
schedule_timeout_uninterruptible(msecs_to_jiffies(10));
833
spin_unlock_irqrestore(&priv->low_lock, flags);
839
* Verify the values and data access of the hardware
840
* No locks needed or used. No functions called.
842
static int ipw2100_verify(struct ipw2100_priv *priv)
847
u32 val1 = 0x76543210;
848
u32 val2 = 0xFEDCBA98;
850
/* Domain 0 check - all values should be DOA_DEBUG */
851
for (address = IPW_REG_DOA_DEBUG_AREA_START;
852
address < IPW_REG_DOA_DEBUG_AREA_END; address += sizeof(u32)) {
853
read_register(priv->net_dev, address, &data1);
854
if (data1 != IPW_DATA_DOA_DEBUG_VALUE)
858
/* Domain 1 check - use arbitrary read/write compare */
859
for (address = 0; address < 5; address++) {
860
/* The memory area is not used now */
861
write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
863
write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
865
read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
867
read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
869
if (val1 == data1 && val2 == data2)
878
* Loop until the CARD_DISABLED bit is the same value as the
881
* TODO: See if it would be more efficient to do a wait/wake
882
* cycle and have the completion event trigger the wakeup
885
#define IPW_CARD_DISABLE_COMPLETE_WAIT 100 // 100 milli
886
static int ipw2100_wait_for_card_state(struct ipw2100_priv *priv, int state)
890
u32 len = sizeof(card_state);
893
for (i = 0; i <= IPW_CARD_DISABLE_COMPLETE_WAIT * 1000; i += 50) {
894
err = ipw2100_get_ordinal(priv, IPW_ORD_CARD_DISABLED,
897
IPW_DEBUG_INFO("Query of CARD_DISABLED ordinal "
902
/* We'll break out if either the HW state says it is
903
* in the state we want, or if HOST_COMPLETE command
905
if ((card_state == state) ||
906
((priv->status & STATUS_ENABLED) ?
907
IPW_HW_STATE_ENABLED : IPW_HW_STATE_DISABLED) == state) {
908
if (state == IPW_HW_STATE_ENABLED)
909
priv->status |= STATUS_ENABLED;
911
priv->status &= ~STATUS_ENABLED;
919
IPW_DEBUG_INFO("ipw2100_wait_for_card_state to %s state timed out\n",
920
state ? "DISABLED" : "ENABLED");
924
/*********************************************************************
925
Procedure : sw_reset_and_clock
926
Purpose : Asserts s/w reset, asserts clock initialization
927
and waits for clock stabilization
928
********************************************************************/
929
static int sw_reset_and_clock(struct ipw2100_priv *priv)
935
write_register(priv->net_dev, IPW_REG_RESET_REG,
936
IPW_AUX_HOST_RESET_REG_SW_RESET);
938
// wait for clock stabilization
939
for (i = 0; i < 1000; i++) {
940
udelay(IPW_WAIT_RESET_ARC_COMPLETE_DELAY);
942
// check clock ready bit
943
read_register(priv->net_dev, IPW_REG_RESET_REG, &r);
944
if (r & IPW_AUX_HOST_RESET_REG_PRINCETON_RESET)
949
return -EIO; // TODO: better error value
951
/* set "initialization complete" bit to move adapter to
953
write_register(priv->net_dev, IPW_REG_GP_CNTRL,
954
IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE);
956
/* wait for clock stabilization */
957
for (i = 0; i < 10000; i++) {
958
udelay(IPW_WAIT_CLOCK_STABILIZATION_DELAY * 4);
960
/* check clock ready bit */
961
read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
962
if (r & IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY)
967
return -EIO; /* TODO: better error value */
969
/* set D0 standby bit */
970
read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
971
write_register(priv->net_dev, IPW_REG_GP_CNTRL,
972
r | IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
977
/*********************************************************************
978
Procedure : ipw2100_download_firmware
979
Purpose : Initiaze adapter after power on.
981
1. assert s/w reset first!
982
2. awake clocks & wait for clock stabilization
983
3. hold ARC (don't ask me why...)
984
4. load Dino ucode and reset/clock init again
985
5. zero-out shared mem
987
*******************************************************************/
988
static int ipw2100_download_firmware(struct ipw2100_priv *priv)
994
/* Fetch the firmware and microcode */
995
struct ipw2100_fw ipw2100_firmware;
998
if (priv->fatal_error) {
999
IPW_DEBUG_ERROR("%s: ipw2100_download_firmware called after "
1000
"fatal error %d. Interface must be brought down.\n",
1001
priv->net_dev->name, priv->fatal_error);
1005
if (!ipw2100_firmware.version) {
1006
err = ipw2100_get_firmware(priv, &ipw2100_firmware);
1008
IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
1009
priv->net_dev->name, err);
1010
priv->fatal_error = IPW2100_ERR_FW_LOAD;
1015
err = ipw2100_get_firmware(priv, &ipw2100_firmware);
1017
IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
1018
priv->net_dev->name, err);
1019
priv->fatal_error = IPW2100_ERR_FW_LOAD;
1023
priv->firmware_version = ipw2100_firmware.version;
1025
/* s/w reset and clock stabilization */
1026
err = sw_reset_and_clock(priv);
1028
IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n",
1029
priv->net_dev->name, err);
1033
err = ipw2100_verify(priv);
1035
IPW_DEBUG_ERROR("%s: ipw2100_verify failed: %d\n",
1036
priv->net_dev->name, err);
1041
write_nic_dword(priv->net_dev,
1042
IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x80000000);
1044
/* allow ARC to run */
1045
write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1047
/* load microcode */
1048
err = ipw2100_ucode_download(priv, &ipw2100_firmware);
1050
printk(KERN_ERR DRV_NAME ": %s: Error loading microcode: %d\n",
1051
priv->net_dev->name, err);
1056
write_nic_dword(priv->net_dev,
1057
IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x00000000);
1059
/* s/w reset and clock stabilization (again!!!) */
1060
err = sw_reset_and_clock(priv);
1062
printk(KERN_ERR DRV_NAME
1063
": %s: sw_reset_and_clock failed: %d\n",
1064
priv->net_dev->name, err);
1069
err = ipw2100_fw_download(priv, &ipw2100_firmware);
1071
IPW_DEBUG_ERROR("%s: Error loading firmware: %d\n",
1072
priv->net_dev->name, err);
1077
* When the .resume method of the driver is called, the other
1078
* part of the system, i.e. the ide driver could still stay in
1079
* the suspend stage. This prevents us from loading the firmware
1080
* from the disk. --YZ
1083
/* free any storage allocated for firmware image */
1084
ipw2100_release_firmware(priv, &ipw2100_firmware);
1087
/* zero out Domain 1 area indirectly (Si requirement) */
1088
for (address = IPW_HOST_FW_SHARED_AREA0;
1089
address < IPW_HOST_FW_SHARED_AREA0_END; address += 4)
1090
write_nic_dword(priv->net_dev, address, 0);
1091
for (address = IPW_HOST_FW_SHARED_AREA1;
1092
address < IPW_HOST_FW_SHARED_AREA1_END; address += 4)
1093
write_nic_dword(priv->net_dev, address, 0);
1094
for (address = IPW_HOST_FW_SHARED_AREA2;
1095
address < IPW_HOST_FW_SHARED_AREA2_END; address += 4)
1096
write_nic_dword(priv->net_dev, address, 0);
1097
for (address = IPW_HOST_FW_SHARED_AREA3;
1098
address < IPW_HOST_FW_SHARED_AREA3_END; address += 4)
1099
write_nic_dword(priv->net_dev, address, 0);
1100
for (address = IPW_HOST_FW_INTERRUPT_AREA;
1101
address < IPW_HOST_FW_INTERRUPT_AREA_END; address += 4)
1102
write_nic_dword(priv->net_dev, address, 0);
1107
ipw2100_release_firmware(priv, &ipw2100_firmware);
1111
static inline void ipw2100_enable_interrupts(struct ipw2100_priv *priv)
1113
if (priv->status & STATUS_INT_ENABLED)
1115
priv->status |= STATUS_INT_ENABLED;
1116
write_register(priv->net_dev, IPW_REG_INTA_MASK, IPW_INTERRUPT_MASK);
1119
static inline void ipw2100_disable_interrupts(struct ipw2100_priv *priv)
1121
if (!(priv->status & STATUS_INT_ENABLED))
1123
priv->status &= ~STATUS_INT_ENABLED;
1124
write_register(priv->net_dev, IPW_REG_INTA_MASK, 0x0);
1127
static void ipw2100_initialize_ordinals(struct ipw2100_priv *priv)
1129
struct ipw2100_ordinals *ord = &priv->ordinals;
1131
IPW_DEBUG_INFO("enter\n");
1133
read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1,
1136
read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2,
1139
read_nic_dword(priv->net_dev, ord->table1_addr, &ord->table1_size);
1140
read_nic_dword(priv->net_dev, ord->table2_addr, &ord->table2_size);
1142
ord->table2_size &= 0x0000FFFF;
1144
IPW_DEBUG_INFO("table 1 size: %d\n", ord->table1_size);
1145
IPW_DEBUG_INFO("table 2 size: %d\n", ord->table2_size);
1146
IPW_DEBUG_INFO("exit\n");
1149
static inline void ipw2100_hw_set_gpio(struct ipw2100_priv *priv)
1153
* Set GPIO 3 writable by FW; GPIO 1 writable
1154
* by driver and enable clock
1156
reg = (IPW_BIT_GPIO_GPIO3_MASK | IPW_BIT_GPIO_GPIO1_ENABLE |
1157
IPW_BIT_GPIO_LED_OFF);
1158
write_register(priv->net_dev, IPW_REG_GPIO, reg);
1161
static int rf_kill_active(struct ipw2100_priv *priv)
1163
#define MAX_RF_KILL_CHECKS 5
1164
#define RF_KILL_CHECK_DELAY 40
1166
unsigned short value = 0;
1170
if (!(priv->hw_features & HW_FEATURE_RFKILL)) {
1171
wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
1172
priv->status &= ~STATUS_RF_KILL_HW;
1176
for (i = 0; i < MAX_RF_KILL_CHECKS; i++) {
1177
udelay(RF_KILL_CHECK_DELAY);
1178
read_register(priv->net_dev, IPW_REG_GPIO, ®);
1179
value = (value << 1) | ((reg & IPW_BIT_GPIO_RF_KILL) ? 0 : 1);
1183
wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
1184
priv->status |= STATUS_RF_KILL_HW;
1186
wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
1187
priv->status &= ~STATUS_RF_KILL_HW;
1190
return (value == 0);
1193
static int ipw2100_get_hw_features(struct ipw2100_priv *priv)
1199
* EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1
1202
if (ipw2100_get_ordinal
1203
(priv, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS, &addr, &len)) {
1204
IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
1209
IPW_DEBUG_INFO("EEPROM address: %08X\n", addr);
1212
* EEPROM version is the byte at offset 0xfd in firmware
1213
* We read 4 bytes, then shift out the byte we actually want */
1214
read_nic_dword(priv->net_dev, addr + 0xFC, &val);
1215
priv->eeprom_version = (val >> 24) & 0xFF;
1216
IPW_DEBUG_INFO("EEPROM version: %d\n", priv->eeprom_version);
1219
* HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware
1221
* notice that the EEPROM bit is reverse polarity, i.e.
1222
* bit = 0 signifies HW RF kill switch is supported
1223
* bit = 1 signifies HW RF kill switch is NOT supported
1225
read_nic_dword(priv->net_dev, addr + 0x20, &val);
1226
if (!((val >> 24) & 0x01))
1227
priv->hw_features |= HW_FEATURE_RFKILL;
1229
IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n",
1230
(priv->hw_features & HW_FEATURE_RFKILL) ? "" : "not ");
1236
* Start firmware execution after power on and intialization
1239
* 2. Wait for f/w initialization completes;
1241
static int ipw2100_start_adapter(struct ipw2100_priv *priv)
1244
u32 inta, inta_mask, gpio;
1246
IPW_DEBUG_INFO("enter\n");
1248
if (priv->status & STATUS_RUNNING)
1252
* Initialize the hw - drive adapter to DO state by setting
1253
* init_done bit. Wait for clk_ready bit and Download
1256
if (ipw2100_download_firmware(priv)) {
1257
printk(KERN_ERR DRV_NAME
1258
": %s: Failed to power on the adapter.\n",
1259
priv->net_dev->name);
1263
/* Clear the Tx, Rx and Msg queues and the r/w indexes
1264
* in the firmware RBD and TBD ring queue */
1265
ipw2100_queues_initialize(priv);
1267
ipw2100_hw_set_gpio(priv);
1269
/* TODO -- Look at disabling interrupts here to make sure none
1270
* get fired during FW initialization */
1272
/* Release ARC - clear reset bit */
1273
write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
1275
/* wait for f/w intialization complete */
1276
IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n");
1279
schedule_timeout_uninterruptible(msecs_to_jiffies(40));
1280
/* Todo... wait for sync command ... */
1282
read_register(priv->net_dev, IPW_REG_INTA, &inta);
1284
/* check "init done" bit */
1285
if (inta & IPW2100_INTA_FW_INIT_DONE) {
1286
/* reset "init done" bit */
1287
write_register(priv->net_dev, IPW_REG_INTA,
1288
IPW2100_INTA_FW_INIT_DONE);
1292
/* check error conditions : we check these after the firmware
1293
* check so that if there is an error, the interrupt handler
1294
* will see it and the adapter will be reset */
1296
(IPW2100_INTA_FATAL_ERROR | IPW2100_INTA_PARITY_ERROR)) {
1297
/* clear error conditions */
1298
write_register(priv->net_dev, IPW_REG_INTA,
1299
IPW2100_INTA_FATAL_ERROR |
1300
IPW2100_INTA_PARITY_ERROR);
1304
/* Clear out any pending INTAs since we aren't supposed to have
1305
* interrupts enabled at this point... */
1306
read_register(priv->net_dev, IPW_REG_INTA, &inta);
1307
read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
1308
inta &= IPW_INTERRUPT_MASK;
1309
/* Clear out any pending interrupts */
1310
if (inta & inta_mask)
1311
write_register(priv->net_dev, IPW_REG_INTA, inta);
1313
IPW_DEBUG_FW("f/w initialization complete: %s\n",
1314
i ? "SUCCESS" : "FAILED");
1317
printk(KERN_WARNING DRV_NAME
1318
": %s: Firmware did not initialize.\n",
1319
priv->net_dev->name);
1323
/* allow firmware to write to GPIO1 & GPIO3 */
1324
read_register(priv->net_dev, IPW_REG_GPIO, &gpio);
1326
gpio |= (IPW_BIT_GPIO_GPIO1_MASK | IPW_BIT_GPIO_GPIO3_MASK);
1328
write_register(priv->net_dev, IPW_REG_GPIO, gpio);
1330
/* Ready to receive commands */
1331
priv->status |= STATUS_RUNNING;
1333
/* The adapter has been reset; we are not associated */
1334
priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
1336
IPW_DEBUG_INFO("exit\n");
1341
static inline void ipw2100_reset_fatalerror(struct ipw2100_priv *priv)
1343
if (!priv->fatal_error)
1346
priv->fatal_errors[priv->fatal_index++] = priv->fatal_error;
1347
priv->fatal_index %= IPW2100_ERROR_QUEUE;
1348
priv->fatal_error = 0;
1351
/* NOTE: Our interrupt is disabled when this method is called */
1352
static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv)
1357
IPW_DEBUG_INFO("Power cycling the hardware.\n");
1359
ipw2100_hw_set_gpio(priv);
1361
/* Step 1. Stop Master Assert */
1362
write_register(priv->net_dev, IPW_REG_RESET_REG,
1363
IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1365
/* Step 2. Wait for stop Master Assert
1366
* (not more than 50us, otherwise ret error */
1369
udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
1370
read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
1372
if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1376
priv->status &= ~STATUS_RESET_PENDING;
1380
("exit - waited too long for master assert stop\n");
1384
write_register(priv->net_dev, IPW_REG_RESET_REG,
1385
IPW_AUX_HOST_RESET_REG_SW_RESET);
1387
/* Reset any fatal_error conditions */
1388
ipw2100_reset_fatalerror(priv);
1390
/* At this point, the adapter is now stopped and disabled */
1391
priv->status &= ~(STATUS_RUNNING | STATUS_ASSOCIATING |
1392
STATUS_ASSOCIATED | STATUS_ENABLED);
1398
* Send the CARD_DISABLE_PHY_OFF comamnd to the card to disable it
1400
* After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent.
1402
* STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of
1403
* if STATUS_ASSN_LOST is sent.
1405
static int ipw2100_hw_phy_off(struct ipw2100_priv *priv)
1408
#define HW_PHY_OFF_LOOP_DELAY (HZ / 5000)
1410
struct host_command cmd = {
1411
.host_command = CARD_DISABLE_PHY_OFF,
1412
.host_command_sequence = 0,
1413
.host_command_length = 0,
1418
IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n");
1420
/* Turn off the radio */
1421
err = ipw2100_hw_send_command(priv, &cmd);
1425
for (i = 0; i < 2500; i++) {
1426
read_nic_dword(priv->net_dev, IPW2100_CONTROL_REG, &val1);
1427
read_nic_dword(priv->net_dev, IPW2100_COMMAND, &val2);
1429
if ((val1 & IPW2100_CONTROL_PHY_OFF) &&
1430
(val2 & IPW2100_COMMAND_PHY_OFF))
1433
schedule_timeout_uninterruptible(HW_PHY_OFF_LOOP_DELAY);
1439
static int ipw2100_enable_adapter(struct ipw2100_priv *priv)
1441
struct host_command cmd = {
1442
.host_command = HOST_COMPLETE,
1443
.host_command_sequence = 0,
1444
.host_command_length = 0
1448
IPW_DEBUG_HC("HOST_COMPLETE\n");
1450
if (priv->status & STATUS_ENABLED)
1453
mutex_lock(&priv->adapter_mutex);
1455
if (rf_kill_active(priv)) {
1456
IPW_DEBUG_HC("Command aborted due to RF kill active.\n");
1460
err = ipw2100_hw_send_command(priv, &cmd);
1462
IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n");
1466
err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_ENABLED);
1468
IPW_DEBUG_INFO("%s: card not responding to init command.\n",
1469
priv->net_dev->name);
1473
if (priv->stop_hang_check) {
1474
priv->stop_hang_check = 0;
1475
queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
1479
mutex_unlock(&priv->adapter_mutex);
1483
static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv)
1485
#define HW_POWER_DOWN_DELAY (msecs_to_jiffies(100))
1487
struct host_command cmd = {
1488
.host_command = HOST_PRE_POWER_DOWN,
1489
.host_command_sequence = 0,
1490
.host_command_length = 0,
1495
if (!(priv->status & STATUS_RUNNING))
1498
priv->status |= STATUS_STOPPING;
1500
/* We can only shut down the card if the firmware is operational. So,
1501
* if we haven't reset since a fatal_error, then we can not send the
1502
* shutdown commands. */
1503
if (!priv->fatal_error) {
1504
/* First, make sure the adapter is enabled so that the PHY_OFF
1505
* command can shut it down */
1506
ipw2100_enable_adapter(priv);
1508
err = ipw2100_hw_phy_off(priv);
1510
printk(KERN_WARNING DRV_NAME
1511
": Error disabling radio %d\n", err);
1514
* If in D0-standby mode going directly to D3 may cause a
1515
* PCI bus violation. Therefore we must change out of the D0
1518
* Sending the PREPARE_FOR_POWER_DOWN will restrict the
1519
* hardware from going into standby mode and will transition
1520
* out of D0-standby if it is already in that state.
1522
* STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the
1523
* driver upon completion. Once received, the driver can
1524
* proceed to the D3 state.
1526
* Prepare for power down command to fw. This command would
1527
* take HW out of D0-standby and prepare it for D3 state.
1529
* Currently FW does not support event notification for this
1530
* event. Therefore, skip waiting for it. Just wait a fixed
1533
IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n");
1535
err = ipw2100_hw_send_command(priv, &cmd);
1537
printk(KERN_WARNING DRV_NAME ": "
1538
"%s: Power down command failed: Error %d\n",
1539
priv->net_dev->name, err);
1541
schedule_timeout_uninterruptible(HW_POWER_DOWN_DELAY);
1544
priv->status &= ~STATUS_ENABLED;
1547
* Set GPIO 3 writable by FW; GPIO 1 writable
1548
* by driver and enable clock
1550
ipw2100_hw_set_gpio(priv);
1553
* Power down adapter. Sequence:
1554
* 1. Stop master assert (RESET_REG[9]=1)
1555
* 2. Wait for stop master (RESET_REG[8]==1)
1556
* 3. S/w reset assert (RESET_REG[7] = 1)
1559
/* Stop master assert */
1560
write_register(priv->net_dev, IPW_REG_RESET_REG,
1561
IPW_AUX_HOST_RESET_REG_STOP_MASTER);
1563
/* wait stop master not more than 50 usec.
1564
* Otherwise return error. */
1565
for (i = 5; i > 0; i--) {
1568
/* Check master stop bit */
1569
read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
1571
if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
1576
printk(KERN_WARNING DRV_NAME
1577
": %s: Could now power down adapter.\n",
1578
priv->net_dev->name);
1580
/* assert s/w reset */
1581
write_register(priv->net_dev, IPW_REG_RESET_REG,
1582
IPW_AUX_HOST_RESET_REG_SW_RESET);
1584
priv->status &= ~(STATUS_RUNNING | STATUS_STOPPING);
1589
static int ipw2100_disable_adapter(struct ipw2100_priv *priv)
1591
struct host_command cmd = {
1592
.host_command = CARD_DISABLE,
1593
.host_command_sequence = 0,
1594
.host_command_length = 0
1598
IPW_DEBUG_HC("CARD_DISABLE\n");
1600
if (!(priv->status & STATUS_ENABLED))
1603
/* Make sure we clear the associated state */
1604
priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1606
if (!priv->stop_hang_check) {
1607
priv->stop_hang_check = 1;
1608
cancel_delayed_work(&priv->hang_check);
1611
mutex_lock(&priv->adapter_mutex);
1613
err = ipw2100_hw_send_command(priv, &cmd);
1615
printk(KERN_WARNING DRV_NAME
1616
": exit - failed to send CARD_DISABLE command\n");
1620
err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_DISABLED);
1622
printk(KERN_WARNING DRV_NAME
1623
": exit - card failed to change to DISABLED\n");
1627
IPW_DEBUG_INFO("TODO: implement scan state machine\n");
1630
mutex_unlock(&priv->adapter_mutex);
1634
static int ipw2100_set_scan_options(struct ipw2100_priv *priv)
1636
struct host_command cmd = {
1637
.host_command = SET_SCAN_OPTIONS,
1638
.host_command_sequence = 0,
1639
.host_command_length = 8
1643
IPW_DEBUG_INFO("enter\n");
1645
IPW_DEBUG_SCAN("setting scan options\n");
1647
cmd.host_command_parameters[0] = 0;
1649
if (!(priv->config & CFG_ASSOCIATE))
1650
cmd.host_command_parameters[0] |= IPW_SCAN_NOASSOCIATE;
1651
if ((priv->ieee->sec.flags & SEC_ENABLED) && priv->ieee->sec.enabled)
1652
cmd.host_command_parameters[0] |= IPW_SCAN_MIXED_CELL;
1653
if (priv->config & CFG_PASSIVE_SCAN)
1654
cmd.host_command_parameters[0] |= IPW_SCAN_PASSIVE;
1656
cmd.host_command_parameters[1] = priv->channel_mask;
1658
err = ipw2100_hw_send_command(priv, &cmd);
1660
IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n",
1661
cmd.host_command_parameters[0]);
1666
static int ipw2100_start_scan(struct ipw2100_priv *priv)
1668
struct host_command cmd = {
1669
.host_command = BROADCAST_SCAN,
1670
.host_command_sequence = 0,
1671
.host_command_length = 4
1675
IPW_DEBUG_HC("START_SCAN\n");
1677
cmd.host_command_parameters[0] = 0;
1679
/* No scanning if in monitor mode */
1680
if (priv->ieee->iw_mode == IW_MODE_MONITOR)
1683
if (priv->status & STATUS_SCANNING) {
1684
IPW_DEBUG_SCAN("Scan requested while already in scan...\n");
1688
IPW_DEBUG_INFO("enter\n");
1690
/* Not clearing here; doing so makes iwlist always return nothing...
1692
* We should modify the table logic to use aging tables vs. clearing
1693
* the table on each scan start.
1695
IPW_DEBUG_SCAN("starting scan\n");
1697
priv->status |= STATUS_SCANNING;
1698
err = ipw2100_hw_send_command(priv, &cmd);
1700
priv->status &= ~STATUS_SCANNING;
1702
IPW_DEBUG_INFO("exit\n");
1707
static const struct libipw_geo ipw_geos[] = {
1711
.bg = {{2412, 1}, {2417, 2}, {2422, 3},
1712
{2427, 4}, {2432, 5}, {2437, 6},
1713
{2442, 7}, {2447, 8}, {2452, 9},
1714
{2457, 10}, {2462, 11}, {2467, 12},
1715
{2472, 13}, {2484, 14}},
1719
static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
1721
unsigned long flags;
1724
u32 ord_len = sizeof(lock);
1726
/* Age scan list entries found before suspend */
1727
if (priv->suspend_time) {
1728
libipw_networks_age(priv->ieee, priv->suspend_time);
1729
priv->suspend_time = 0;
1732
/* Quiet if manually disabled. */
1733
if (priv->status & STATUS_RF_KILL_SW) {
1734
IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable "
1735
"switch\n", priv->net_dev->name);
1739
/* the ipw2100 hardware really doesn't want power management delays
1740
* longer than 175usec
1742
pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100", 175);
1744
/* If the interrupt is enabled, turn it off... */
1745
spin_lock_irqsave(&priv->low_lock, flags);
1746
ipw2100_disable_interrupts(priv);
1748
/* Reset any fatal_error conditions */
1749
ipw2100_reset_fatalerror(priv);
1750
spin_unlock_irqrestore(&priv->low_lock, flags);
1752
if (priv->status & STATUS_POWERED ||
1753
(priv->status & STATUS_RESET_PENDING)) {
1754
/* Power cycle the card ... */
1755
if (ipw2100_power_cycle_adapter(priv)) {
1756
printk(KERN_WARNING DRV_NAME
1757
": %s: Could not cycle adapter.\n",
1758
priv->net_dev->name);
1763
priv->status |= STATUS_POWERED;
1765
/* Load the firmware, start the clocks, etc. */
1766
if (ipw2100_start_adapter(priv)) {
1767
printk(KERN_ERR DRV_NAME
1768
": %s: Failed to start the firmware.\n",
1769
priv->net_dev->name);
1774
ipw2100_initialize_ordinals(priv);
1776
/* Determine capabilities of this particular HW configuration */
1777
if (ipw2100_get_hw_features(priv)) {
1778
printk(KERN_ERR DRV_NAME
1779
": %s: Failed to determine HW features.\n",
1780
priv->net_dev->name);
1785
/* Initialize the geo */
1786
if (libipw_set_geo(priv->ieee, &ipw_geos[0])) {
1787
printk(KERN_WARNING DRV_NAME "Could not set geo\n");
1790
priv->ieee->freq_band = LIBIPW_24GHZ_BAND;
1793
if (ipw2100_set_ordinal(priv, IPW_ORD_PERS_DB_LOCK, &lock, &ord_len)) {
1794
printk(KERN_ERR DRV_NAME
1795
": %s: Failed to clear ordinal lock.\n",
1796
priv->net_dev->name);
1801
priv->status &= ~STATUS_SCANNING;
1803
if (rf_kill_active(priv)) {
1804
printk(KERN_INFO "%s: Radio is disabled by RF switch.\n",
1805
priv->net_dev->name);
1807
if (priv->stop_rf_kill) {
1808
priv->stop_rf_kill = 0;
1809
queue_delayed_work(priv->workqueue, &priv->rf_kill,
1810
round_jiffies_relative(HZ));
1816
/* Turn on the interrupt so that commands can be processed */
1817
ipw2100_enable_interrupts(priv);
1819
/* Send all of the commands that must be sent prior to
1821
if (ipw2100_adapter_setup(priv)) {
1822
printk(KERN_ERR DRV_NAME ": %s: Failed to start the card.\n",
1823
priv->net_dev->name);
1829
/* Enable the adapter - sends HOST_COMPLETE */
1830
if (ipw2100_enable_adapter(priv)) {
1831
printk(KERN_ERR DRV_NAME ": "
1832
"%s: failed in call to enable adapter.\n",
1833
priv->net_dev->name);
1834
ipw2100_hw_stop_adapter(priv);
1839
/* Start a scan . . . */
1840
ipw2100_set_scan_options(priv);
1841
ipw2100_start_scan(priv);
1848
static void ipw2100_down(struct ipw2100_priv *priv)
1850
unsigned long flags;
1851
union iwreq_data wrqu = {
1853
.sa_family = ARPHRD_ETHER}
1855
int associated = priv->status & STATUS_ASSOCIATED;
1857
/* Kill the RF switch timer */
1858
if (!priv->stop_rf_kill) {
1859
priv->stop_rf_kill = 1;
1860
cancel_delayed_work(&priv->rf_kill);
1863
/* Kill the firmware hang check timer */
1864
if (!priv->stop_hang_check) {
1865
priv->stop_hang_check = 1;
1866
cancel_delayed_work(&priv->hang_check);
1869
/* Kill any pending resets */
1870
if (priv->status & STATUS_RESET_PENDING)
1871
cancel_delayed_work(&priv->reset_work);
1873
/* Make sure the interrupt is on so that FW commands will be
1874
* processed correctly */
1875
spin_lock_irqsave(&priv->low_lock, flags);
1876
ipw2100_enable_interrupts(priv);
1877
spin_unlock_irqrestore(&priv->low_lock, flags);
1879
if (ipw2100_hw_stop_adapter(priv))
1880
printk(KERN_ERR DRV_NAME ": %s: Error stopping adapter.\n",
1881
priv->net_dev->name);
1883
/* Do not disable the interrupt until _after_ we disable
1884
* the adaptor. Otherwise the CARD_DISABLE command will never
1885
* be ack'd by the firmware */
1886
spin_lock_irqsave(&priv->low_lock, flags);
1887
ipw2100_disable_interrupts(priv);
1888
spin_unlock_irqrestore(&priv->low_lock, flags);
1890
pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100",
1891
PM_QOS_DEFAULT_VALUE);
1893
/* We have to signal any supplicant if we are disassociating */
1895
wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1897
priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1898
netif_carrier_off(priv->net_dev);
1899
netif_stop_queue(priv->net_dev);
1902
/* Called by register_netdev() */
1903
static int ipw2100_net_init(struct net_device *dev)
1905
struct ipw2100_priv *priv = libipw_priv(dev);
1906
const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
1907
struct wireless_dev *wdev = &priv->ieee->wdev;
1911
ret = ipw2100_up(priv, 1);
1915
memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
1917
/* fill-out priv->ieee->bg_band */
1918
if (geo->bg_channels) {
1919
struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
1921
bg_band->band = IEEE80211_BAND_2GHZ;
1922
bg_band->n_channels = geo->bg_channels;
1924
kzalloc(geo->bg_channels *
1925
sizeof(struct ieee80211_channel), GFP_KERNEL);
1926
/* translate geo->bg to bg_band.channels */
1927
for (i = 0; i < geo->bg_channels; i++) {
1928
bg_band->channels[i].band = IEEE80211_BAND_2GHZ;
1929
bg_band->channels[i].center_freq = geo->bg[i].freq;
1930
bg_band->channels[i].hw_value = geo->bg[i].channel;
1931
bg_band->channels[i].max_power = geo->bg[i].max_power;
1932
if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
1933
bg_band->channels[i].flags |=
1934
IEEE80211_CHAN_PASSIVE_SCAN;
1935
if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
1936
bg_band->channels[i].flags |=
1937
IEEE80211_CHAN_NO_IBSS;
1938
if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
1939
bg_band->channels[i].flags |=
1940
IEEE80211_CHAN_RADAR;
1941
/* No equivalent for LIBIPW_CH_80211H_RULES,
1942
LIBIPW_CH_UNIFORM_SPREADING, or
1943
LIBIPW_CH_B_ONLY... */
1945
/* point at bitrate info */
1946
bg_band->bitrates = ipw2100_bg_rates;
1947
bg_band->n_bitrates = RATE_COUNT;
1949
wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band;
1952
set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
1953
if (wiphy_register(wdev->wiphy)) {
1960
static void ipw2100_reset_adapter(struct work_struct *work)
1962
struct ipw2100_priv *priv =
1963
container_of(work, struct ipw2100_priv, reset_work.work);
1964
unsigned long flags;
1965
union iwreq_data wrqu = {
1967
.sa_family = ARPHRD_ETHER}
1969
int associated = priv->status & STATUS_ASSOCIATED;
1971
spin_lock_irqsave(&priv->low_lock, flags);
1972
IPW_DEBUG_INFO(": %s: Restarting adapter.\n", priv->net_dev->name);
1974
priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1975
priv->status |= STATUS_SECURITY_UPDATED;
1977
/* Force a power cycle even if interface hasn't been opened
1979
cancel_delayed_work(&priv->reset_work);
1980
priv->status |= STATUS_RESET_PENDING;
1981
spin_unlock_irqrestore(&priv->low_lock, flags);
1983
mutex_lock(&priv->action_mutex);
1984
/* stop timed checks so that they don't interfere with reset */
1985
priv->stop_hang_check = 1;
1986
cancel_delayed_work(&priv->hang_check);
1988
/* We have to signal any supplicant if we are disassociating */
1990
wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1992
ipw2100_up(priv, 0);
1993
mutex_unlock(&priv->action_mutex);
1997
static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status)
2000
#define MAC_ASSOCIATION_READ_DELAY (HZ)
2002
unsigned int len, essid_len;
2003
char essid[IW_ESSID_MAX_SIZE];
2008
DECLARE_SSID_BUF(ssid);
2011
* TBD: BSSID is usually 00:00:00:00:00:00 here and not
2012
* an actual MAC of the AP. Seems like FW sets this
2013
* address too late. Read it later and expose through
2014
* /proc or schedule a later task to query and update
2017
essid_len = IW_ESSID_MAX_SIZE;
2018
ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID,
2021
IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
2027
ret = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &txrate, &len);
2029
IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
2035
ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &len);
2037
IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
2042
ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, &bssid, &len);
2044
IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
2048
memcpy(priv->ieee->bssid, bssid, ETH_ALEN);
2051
case TX_RATE_1_MBIT:
2052
txratename = "1Mbps";
2054
case TX_RATE_2_MBIT:
2055
txratename = "2Mbsp";
2057
case TX_RATE_5_5_MBIT:
2058
txratename = "5.5Mbps";
2060
case TX_RATE_11_MBIT:
2061
txratename = "11Mbps";
2064
IPW_DEBUG_INFO("Unknown rate: %d\n", txrate);
2065
txratename = "unknown rate";
2069
IPW_DEBUG_INFO("%s: Associated with '%s' at %s, channel %d (BSSID=%pM)\n",
2070
priv->net_dev->name, print_ssid(ssid, essid, essid_len),
2071
txratename, chan, bssid);
2073
/* now we copy read ssid into dev */
2074
if (!(priv->config & CFG_STATIC_ESSID)) {
2075
priv->essid_len = min((u8) essid_len, (u8) IW_ESSID_MAX_SIZE);
2076
memcpy(priv->essid, essid, priv->essid_len);
2078
priv->channel = chan;
2079
memcpy(priv->bssid, bssid, ETH_ALEN);
2081
priv->status |= STATUS_ASSOCIATING;
2082
priv->connect_start = get_seconds();
2084
queue_delayed_work(priv->workqueue, &priv->wx_event_work, HZ / 10);
2087
static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
2088
int length, int batch_mode)
2090
int ssid_len = min(length, IW_ESSID_MAX_SIZE);
2091
struct host_command cmd = {
2092
.host_command = SSID,
2093
.host_command_sequence = 0,
2094
.host_command_length = ssid_len
2097
DECLARE_SSID_BUF(ssid);
2099
IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
2102
memcpy(cmd.host_command_parameters, essid, ssid_len);
2105
err = ipw2100_disable_adapter(priv);
2110
/* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to
2111
* disable auto association -- so we cheat by setting a bogus SSID */
2112
if (!ssid_len && !(priv->config & CFG_ASSOCIATE)) {
2114
u8 *bogus = (u8 *) cmd.host_command_parameters;
2115
for (i = 0; i < IW_ESSID_MAX_SIZE; i++)
2116
bogus[i] = 0x18 + i;
2117
cmd.host_command_length = IW_ESSID_MAX_SIZE;
2120
/* NOTE: We always send the SSID command even if the provided ESSID is
2121
* the same as what we currently think is set. */
2123
err = ipw2100_hw_send_command(priv, &cmd);
2125
memset(priv->essid + ssid_len, 0, IW_ESSID_MAX_SIZE - ssid_len);
2126
memcpy(priv->essid, essid, ssid_len);
2127
priv->essid_len = ssid_len;
2131
if (ipw2100_enable_adapter(priv))
2138
static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status)
2140
DECLARE_SSID_BUF(ssid);
2142
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
2143
"disassociated: '%s' %pM \n",
2144
print_ssid(ssid, priv->essid, priv->essid_len),
2147
priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
2149
if (priv->status & STATUS_STOPPING) {
2150
IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n");
2154
memset(priv->bssid, 0, ETH_ALEN);
2155
memset(priv->ieee->bssid, 0, ETH_ALEN);
2157
netif_carrier_off(priv->net_dev);
2158
netif_stop_queue(priv->net_dev);
2160
if (!(priv->status & STATUS_RUNNING))
2163
if (priv->status & STATUS_SECURITY_UPDATED)
2164
queue_delayed_work(priv->workqueue, &priv->security_work, 0);
2166
queue_delayed_work(priv->workqueue, &priv->wx_event_work, 0);
2169
static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status)
2171
IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n",
2172
priv->net_dev->name);
2174
/* RF_KILL is now enabled (else we wouldn't be here) */
2175
wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
2176
priv->status |= STATUS_RF_KILL_HW;
2178
/* Make sure the RF Kill check timer is running */
2179
priv->stop_rf_kill = 0;
2180
cancel_delayed_work(&priv->rf_kill);
2181
queue_delayed_work(priv->workqueue, &priv->rf_kill,
2182
round_jiffies_relative(HZ));
2185
static void send_scan_event(void *data)
2187
struct ipw2100_priv *priv = data;
2188
union iwreq_data wrqu;
2190
wrqu.data.length = 0;
2191
wrqu.data.flags = 0;
2192
wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
2195
static void ipw2100_scan_event_later(struct work_struct *work)
2197
send_scan_event(container_of(work, struct ipw2100_priv,
2198
scan_event_later.work));
2201
static void ipw2100_scan_event_now(struct work_struct *work)
2203
send_scan_event(container_of(work, struct ipw2100_priv,
2207
static void isr_scan_complete(struct ipw2100_priv *priv, u32 status)
2209
IPW_DEBUG_SCAN("scan complete\n");
2210
/* Age the scan results... */
2211
priv->ieee->scans++;
2212
priv->status &= ~STATUS_SCANNING;
2214
/* Only userspace-requested scan completion events go out immediately */
2215
if (!priv->user_requested_scan) {
2216
if (!delayed_work_pending(&priv->scan_event_later))
2217
queue_delayed_work(priv->workqueue,
2218
&priv->scan_event_later,
2219
round_jiffies_relative(msecs_to_jiffies(4000)));
2221
priv->user_requested_scan = 0;
2222
cancel_delayed_work(&priv->scan_event_later);
2223
queue_work(priv->workqueue, &priv->scan_event_now);
2227
#ifdef CONFIG_IPW2100_DEBUG
2228
#define IPW2100_HANDLER(v, f) { v, f, # v }
2229
struct ipw2100_status_indicator {
2231
void (*cb) (struct ipw2100_priv * priv, u32 status);
2235
#define IPW2100_HANDLER(v, f) { v, f }
2236
struct ipw2100_status_indicator {
2238
void (*cb) (struct ipw2100_priv * priv, u32 status);
2240
#endif /* CONFIG_IPW2100_DEBUG */
2242
static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status)
2244
IPW_DEBUG_SCAN("Scanning...\n");
2245
priv->status |= STATUS_SCANNING;
2248
static const struct ipw2100_status_indicator status_handlers[] = {
2249
IPW2100_HANDLER(IPW_STATE_INITIALIZED, NULL),
2250
IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, NULL),
2251
IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated),
2252
IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost),
2253
IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, NULL),
2254
IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete),
2255
IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, NULL),
2256
IPW2100_HANDLER(IPW_STATE_LEFT_PSP, NULL),
2257
IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill),
2258
IPW2100_HANDLER(IPW_STATE_DISABLED, NULL),
2259
IPW2100_HANDLER(IPW_STATE_POWER_DOWN, NULL),
2260
IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning),
2261
IPW2100_HANDLER(-1, NULL)
2264
static void isr_status_change(struct ipw2100_priv *priv, int status)
2268
if (status == IPW_STATE_SCANNING &&
2269
priv->status & STATUS_ASSOCIATED &&
2270
!(priv->status & STATUS_SCANNING)) {
2271
IPW_DEBUG_INFO("Scan detected while associated, with "
2272
"no scan request. Restarting firmware.\n");
2274
/* Wake up any sleeping jobs */
2275
schedule_reset(priv);
2278
for (i = 0; status_handlers[i].status != -1; i++) {
2279
if (status == status_handlers[i].status) {
2280
IPW_DEBUG_NOTIF("Status change: %s\n",
2281
status_handlers[i].name);
2282
if (status_handlers[i].cb)
2283
status_handlers[i].cb(priv, status);
2284
priv->wstats.status = status;
2289
IPW_DEBUG_NOTIF("unknown status received: %04x\n", status);
2292
static void isr_rx_complete_command(struct ipw2100_priv *priv,
2293
struct ipw2100_cmd_header *cmd)
2295
#ifdef CONFIG_IPW2100_DEBUG
2296
if (cmd->host_command_reg < ARRAY_SIZE(command_types)) {
2297
IPW_DEBUG_HC("Command completed '%s (%d)'\n",
2298
command_types[cmd->host_command_reg],
2299
cmd->host_command_reg);
2302
if (cmd->host_command_reg == HOST_COMPLETE)
2303
priv->status |= STATUS_ENABLED;
2305
if (cmd->host_command_reg == CARD_DISABLE)
2306
priv->status &= ~STATUS_ENABLED;
2308
priv->status &= ~STATUS_CMD_ACTIVE;
2310
wake_up_interruptible(&priv->wait_command_queue);
2313
#ifdef CONFIG_IPW2100_DEBUG
2314
static const char *frame_types[] = {
2315
"COMMAND_STATUS_VAL",
2316
"STATUS_CHANGE_VAL",
2319
"HOST_NOTIFICATION_VAL"
2323
static int ipw2100_alloc_skb(struct ipw2100_priv *priv,
2324
struct ipw2100_rx_packet *packet)
2326
packet->skb = dev_alloc_skb(sizeof(struct ipw2100_rx));
2330
packet->rxp = (struct ipw2100_rx *)packet->skb->data;
2331
packet->dma_addr = pci_map_single(priv->pci_dev, packet->skb->data,
2332
sizeof(struct ipw2100_rx),
2333
PCI_DMA_FROMDEVICE);
2334
/* NOTE: pci_map_single does not return an error code, and 0 is a valid
2340
#define SEARCH_ERROR 0xffffffff
2341
#define SEARCH_FAIL 0xfffffffe
2342
#define SEARCH_SUCCESS 0xfffffff0
2343
#define SEARCH_DISCARD 0
2344
#define SEARCH_SNAPSHOT 1
2346
#define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff))
2347
static void ipw2100_snapshot_free(struct ipw2100_priv *priv)
2350
if (!priv->snapshot[0])
2352
for (i = 0; i < 0x30; i++)
2353
kfree(priv->snapshot[i]);
2354
priv->snapshot[0] = NULL;
2357
#ifdef IPW2100_DEBUG_C3
2358
static int ipw2100_snapshot_alloc(struct ipw2100_priv *priv)
2361
if (priv->snapshot[0])
2363
for (i = 0; i < 0x30; i++) {
2364
priv->snapshot[i] = kmalloc(0x1000, GFP_ATOMIC);
2365
if (!priv->snapshot[i]) {
2366
IPW_DEBUG_INFO("%s: Error allocating snapshot "
2367
"buffer %d\n", priv->net_dev->name, i);
2369
kfree(priv->snapshot[--i]);
2370
priv->snapshot[0] = NULL;
2378
static u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 * in_buf,
2379
size_t len, int mode)
2387
if (mode == SEARCH_SNAPSHOT) {
2388
if (!ipw2100_snapshot_alloc(priv))
2389
mode = SEARCH_DISCARD;
2392
for (ret = SEARCH_FAIL, i = 0; i < 0x30000; i += 4) {
2393
read_nic_dword(priv->net_dev, i, &tmp);
2394
if (mode == SEARCH_SNAPSHOT)
2395
*(u32 *) SNAPSHOT_ADDR(i) = tmp;
2396
if (ret == SEARCH_FAIL) {
2398
for (j = 0; j < 4; j++) {
2407
if ((s - in_buf) == len)
2408
ret = (i + j) - len + 1;
2410
} else if (mode == SEARCH_DISCARD)
2420
* 0) Disconnect the SKB from the firmware (just unmap)
2421
* 1) Pack the ETH header into the SKB
2422
* 2) Pass the SKB to the network stack
2424
* When packet is provided by the firmware, it contains the following:
2429
* The size of the constructed ethernet
2432
#ifdef IPW2100_RX_DEBUG
2433
static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH];
2436
static void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i)
2438
#ifdef IPW2100_DEBUG_C3
2439
struct ipw2100_status *status = &priv->status_queue.drv[i];
2444
IPW_DEBUG_INFO(": PCI latency error detected at 0x%04zX.\n",
2445
i * sizeof(struct ipw2100_status));
2447
#ifdef IPW2100_DEBUG_C3
2448
/* Halt the firmware so we can get a good image */
2449
write_register(priv->net_dev, IPW_REG_RESET_REG,
2450
IPW_AUX_HOST_RESET_REG_STOP_MASTER);
2453
udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
2454
read_register(priv->net_dev, IPW_REG_RESET_REG, ®);
2456
if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
2460
match = ipw2100_match_buf(priv, (u8 *) status,
2461
sizeof(struct ipw2100_status),
2463
if (match < SEARCH_SUCCESS)
2464
IPW_DEBUG_INFO("%s: DMA status match in Firmware at "
2465
"offset 0x%06X, length %d:\n",
2466
priv->net_dev->name, match,
2467
sizeof(struct ipw2100_status));
2469
IPW_DEBUG_INFO("%s: No DMA status match in "
2470
"Firmware.\n", priv->net_dev->name);
2472
printk_buf((u8 *) priv->status_queue.drv,
2473
sizeof(struct ipw2100_status) * RX_QUEUE_LENGTH);
2476
priv->fatal_error = IPW2100_ERR_C3_CORRUPTION;
2477
priv->net_dev->stats.rx_errors++;
2478
schedule_reset(priv);
2481
static void isr_rx(struct ipw2100_priv *priv, int i,
2482
struct libipw_rx_stats *stats)
2484
struct net_device *dev = priv->net_dev;
2485
struct ipw2100_status *status = &priv->status_queue.drv[i];
2486
struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2488
IPW_DEBUG_RX("Handler...\n");
2490
if (unlikely(status->frame_size > skb_tailroom(packet->skb))) {
2491
IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2494
status->frame_size, skb_tailroom(packet->skb));
2495
dev->stats.rx_errors++;
2499
if (unlikely(!netif_running(dev))) {
2500
dev->stats.rx_errors++;
2501
priv->wstats.discard.misc++;
2502
IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2506
if (unlikely(priv->ieee->iw_mode != IW_MODE_MONITOR &&
2507
!(priv->status & STATUS_ASSOCIATED))) {
2508
IPW_DEBUG_DROP("Dropping packet while not associated.\n");
2509
priv->wstats.discard.misc++;
2513
pci_unmap_single(priv->pci_dev,
2515
sizeof(struct ipw2100_rx), PCI_DMA_FROMDEVICE);
2517
skb_put(packet->skb, status->frame_size);
2519
#ifdef IPW2100_RX_DEBUG
2520
/* Make a copy of the frame so we can dump it to the logs if
2521
* libipw_rx fails */
2522
skb_copy_from_linear_data(packet->skb, packet_data,
2523
min_t(u32, status->frame_size,
2524
IPW_RX_NIC_BUFFER_LENGTH));
2527
if (!libipw_rx(priv->ieee, packet->skb, stats)) {
2528
#ifdef IPW2100_RX_DEBUG
2529
IPW_DEBUG_DROP("%s: Non consumed packet:\n",
2531
printk_buf(IPW_DL_DROP, packet_data, status->frame_size);
2533
dev->stats.rx_errors++;
2535
/* libipw_rx failed, so it didn't free the SKB */
2536
dev_kfree_skb_any(packet->skb);
2540
/* We need to allocate a new SKB and attach it to the RDB. */
2541
if (unlikely(ipw2100_alloc_skb(priv, packet))) {
2542
printk(KERN_WARNING DRV_NAME ": "
2543
"%s: Unable to allocate SKB onto RBD ring - disabling "
2544
"adapter.\n", dev->name);
2545
/* TODO: schedule adapter shutdown */
2546
IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2549
/* Update the RDB entry */
2550
priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2553
#ifdef CONFIG_IPW2100_MONITOR
2555
static void isr_rx_monitor(struct ipw2100_priv *priv, int i,
2556
struct libipw_rx_stats *stats)
2558
struct net_device *dev = priv->net_dev;
2559
struct ipw2100_status *status = &priv->status_queue.drv[i];
2560
struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
2562
/* Magic struct that slots into the radiotap header -- no reason
2563
* to build this manually element by element, we can write it much
2564
* more efficiently than we can parse it. ORDER MATTERS HERE */
2566
struct ieee80211_radiotap_header rt_hdr;
2567
s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
2570
IPW_DEBUG_RX("Handler...\n");
2572
if (unlikely(status->frame_size > skb_tailroom(packet->skb) -
2573
sizeof(struct ipw_rt_hdr))) {
2574
IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
2578
skb_tailroom(packet->skb));
2579
dev->stats.rx_errors++;
2583
if (unlikely(!netif_running(dev))) {
2584
dev->stats.rx_errors++;
2585
priv->wstats.discard.misc++;
2586
IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
2590
if (unlikely(priv->config & CFG_CRC_CHECK &&
2591
status->flags & IPW_STATUS_FLAG_CRC_ERROR)) {
2592
IPW_DEBUG_RX("CRC error in packet. Dropping.\n");
2593
dev->stats.rx_errors++;
2597
pci_unmap_single(priv->pci_dev, packet->dma_addr,
2598
sizeof(struct ipw2100_rx), PCI_DMA_FROMDEVICE);
2599
memmove(packet->skb->data + sizeof(struct ipw_rt_hdr),
2600
packet->skb->data, status->frame_size);
2602
ipw_rt = (struct ipw_rt_hdr *) packet->skb->data;
2604
ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
2605
ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
2606
ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total hdr+data */
2608
ipw_rt->rt_hdr.it_present = cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
2610
ipw_rt->rt_dbmsignal = status->rssi + IPW2100_RSSI_TO_DBM;
2612
skb_put(packet->skb, status->frame_size + sizeof(struct ipw_rt_hdr));
2614
if (!libipw_rx(priv->ieee, packet->skb, stats)) {
2615
dev->stats.rx_errors++;
2617
/* libipw_rx failed, so it didn't free the SKB */
2618
dev_kfree_skb_any(packet->skb);
2622
/* We need to allocate a new SKB and attach it to the RDB. */
2623
if (unlikely(ipw2100_alloc_skb(priv, packet))) {
2625
"%s: Unable to allocate SKB onto RBD ring - disabling "
2626
"adapter.\n", dev->name);
2627
/* TODO: schedule adapter shutdown */
2628
IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
2631
/* Update the RDB entry */
2632
priv->rx_queue.drv[i].host_addr = packet->dma_addr;
2637
static int ipw2100_corruption_check(struct ipw2100_priv *priv, int i)
2639
struct ipw2100_status *status = &priv->status_queue.drv[i];
2640
struct ipw2100_rx *u = priv->rx_buffers[i].rxp;
2641
u16 frame_type = status->status_fields & STATUS_TYPE_MASK;
2643
switch (frame_type) {
2644
case COMMAND_STATUS_VAL:
2645
return (status->frame_size != sizeof(u->rx_data.command));
2646
case STATUS_CHANGE_VAL:
2647
return (status->frame_size != sizeof(u->rx_data.status));
2648
case HOST_NOTIFICATION_VAL:
2649
return (status->frame_size < sizeof(u->rx_data.notification));
2650
case P80211_DATA_VAL:
2651
case P8023_DATA_VAL:
2652
#ifdef CONFIG_IPW2100_MONITOR
2655
switch (WLAN_FC_GET_TYPE(le16_to_cpu(u->rx_data.header.frame_ctl))) {
2656
case IEEE80211_FTYPE_MGMT:
2657
case IEEE80211_FTYPE_CTL:
2659
case IEEE80211_FTYPE_DATA:
2660
return (status->frame_size >
2661
IPW_MAX_802_11_PAYLOAD_LENGTH);
2670
* ipw2100 interrupts are disabled at this point, and the ISR
2671
* is the only code that calls this method. So, we do not need
2672
* to play with any locks.
2674
* RX Queue works as follows:
2676
* Read index - firmware places packet in entry identified by the
2677
* Read index and advances Read index. In this manner,
2678
* Read index will always point to the next packet to
2679
* be filled--but not yet valid.
2681
* Write index - driver fills this entry with an unused RBD entry.
2682
* This entry has not filled by the firmware yet.
2684
* In between the W and R indexes are the RBDs that have been received
2685
* but not yet processed.
2687
* The process of handling packets will start at WRITE + 1 and advance
2688
* until it reaches the READ index.
2690
* The WRITE index is cached in the variable 'priv->rx_queue.next'.
2693
static void __ipw2100_rx_process(struct ipw2100_priv *priv)
2695
struct ipw2100_bd_queue *rxq = &priv->rx_queue;
2696
struct ipw2100_status_queue *sq = &priv->status_queue;
2697
struct ipw2100_rx_packet *packet;
2700
struct ipw2100_rx *u;
2701
struct libipw_rx_stats stats = {
2702
.mac_time = jiffies,
2705
read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_READ_INDEX, &r);
2706
read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, &w);
2708
if (r >= rxq->entries) {
2709
IPW_DEBUG_RX("exit - bad read index\n");
2713
i = (rxq->next + 1) % rxq->entries;
2716
/* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n",
2717
r, rxq->next, i); */
2719
packet = &priv->rx_buffers[i];
2721
/* Sync the DMA for the STATUS buffer so CPU is sure to get
2722
* the correct values */
2723
pci_dma_sync_single_for_cpu(priv->pci_dev,
2725
sizeof(struct ipw2100_status) * i,
2726
sizeof(struct ipw2100_status),
2727
PCI_DMA_FROMDEVICE);
2729
/* Sync the DMA for the RX buffer so CPU is sure to get
2730
* the correct values */
2731
pci_dma_sync_single_for_cpu(priv->pci_dev, packet->dma_addr,
2732
sizeof(struct ipw2100_rx),
2733
PCI_DMA_FROMDEVICE);
2735
if (unlikely(ipw2100_corruption_check(priv, i))) {
2736
ipw2100_corruption_detected(priv, i);
2741
frame_type = sq->drv[i].status_fields & STATUS_TYPE_MASK;
2742
stats.rssi = sq->drv[i].rssi + IPW2100_RSSI_TO_DBM;
2743
stats.len = sq->drv[i].frame_size;
2746
if (stats.rssi != 0)
2747
stats.mask |= LIBIPW_STATMASK_RSSI;
2748
stats.freq = LIBIPW_24GHZ_BAND;
2750
IPW_DEBUG_RX("%s: '%s' frame type received (%d).\n",
2751
priv->net_dev->name, frame_types[frame_type],
2754
switch (frame_type) {
2755
case COMMAND_STATUS_VAL:
2756
/* Reset Rx watchdog */
2757
isr_rx_complete_command(priv, &u->rx_data.command);
2760
case STATUS_CHANGE_VAL:
2761
isr_status_change(priv, u->rx_data.status);
2764
case P80211_DATA_VAL:
2765
case P8023_DATA_VAL:
2766
#ifdef CONFIG_IPW2100_MONITOR
2767
if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
2768
isr_rx_monitor(priv, i, &stats);
2772
if (stats.len < sizeof(struct libipw_hdr_3addr))
2774
switch (WLAN_FC_GET_TYPE(le16_to_cpu(u->rx_data.header.frame_ctl))) {
2775
case IEEE80211_FTYPE_MGMT:
2776
libipw_rx_mgt(priv->ieee,
2777
&u->rx_data.header, &stats);
2780
case IEEE80211_FTYPE_CTL:
2783
case IEEE80211_FTYPE_DATA:
2784
isr_rx(priv, i, &stats);
2792
/* clear status field associated with this RBD */
2793
rxq->drv[i].status.info.field = 0;
2795
i = (i + 1) % rxq->entries;
2799
/* backtrack one entry, wrapping to end if at 0 */
2800
rxq->next = (i ? i : rxq->entries) - 1;
2802
write_register(priv->net_dev,
2803
IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, rxq->next);
2808
* __ipw2100_tx_process
2810
* This routine will determine whether the next packet on
2811
* the fw_pend_list has been processed by the firmware yet.
2813
* If not, then it does nothing and returns.
2815
* If so, then it removes the item from the fw_pend_list, frees
2816
* any associated storage, and places the item back on the
2817
* free list of its source (either msg_free_list or tx_free_list)
2819
* TX Queue works as follows:
2821
* Read index - points to the next TBD that the firmware will
2822
* process. The firmware will read the data, and once
2823
* done processing, it will advance the Read index.
2825
* Write index - driver fills this entry with an constructed TBD
2826
* entry. The Write index is not advanced until the
2827
* packet has been configured.
2829
* In between the W and R indexes are the TBDs that have NOT been
2830
* processed. Lagging behind the R index are packets that have
2831
* been processed but have not been freed by the driver.
2833
* In order to free old storage, an internal index will be maintained
2834
* that points to the next packet to be freed. When all used
2835
* packets have been freed, the oldest index will be the same as the
2836
* firmware's read index.
2838
* The OLDEST index is cached in the variable 'priv->tx_queue.oldest'
2840
* Because the TBD structure can not contain arbitrary data, the
2841
* driver must keep an internal queue of cached allocations such that
2842
* it can put that data back into the tx_free_list and msg_free_list
2843
* for use by future command and data packets.
2846
static int __ipw2100_tx_process(struct ipw2100_priv *priv)
2848
struct ipw2100_bd_queue *txq = &priv->tx_queue;
2849
struct ipw2100_bd *tbd;
2850
struct list_head *element;
2851
struct ipw2100_tx_packet *packet;
2852
int descriptors_used;
2854
u32 r, w, frag_num = 0;
2856
if (list_empty(&priv->fw_pend_list))
2859
element = priv->fw_pend_list.next;
2861
packet = list_entry(element, struct ipw2100_tx_packet, list);
2862
tbd = &txq->drv[packet->index];
2864
/* Determine how many TBD entries must be finished... */
2865
switch (packet->type) {
2867
/* COMMAND uses only one slot; don't advance */
2868
descriptors_used = 1;
2873
/* DATA uses two slots; advance and loop position. */
2874
descriptors_used = tbd->num_fragments;
2875
frag_num = tbd->num_fragments - 1;
2876
e = txq->oldest + frag_num;
2881
printk(KERN_WARNING DRV_NAME ": %s: Bad fw_pend_list entry!\n",
2882
priv->net_dev->name);
2886
/* if the last TBD is not done by NIC yet, then packet is
2887
* not ready to be released.
2890
read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
2892
read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
2895
printk(KERN_WARNING DRV_NAME ": %s: write index mismatch\n",
2896
priv->net_dev->name);
2899
* txq->next is the index of the last packet written txq->oldest is
2900
* the index of the r is the index of the next packet to be read by
2905
* Quick graphic to help you visualize the following
2906
* if / else statement
2908
* ===>| s---->|===============
2910
* | a | b | c | d | e | f | g | h | i | j | k | l
2914
* w - updated by driver
2915
* r - updated by firmware
2916
* s - start of oldest BD entry (txq->oldest)
2917
* e - end of oldest BD entry
2920
if (!((r <= w && (e < r || e >= w)) || (e < r && e >= w))) {
2921
IPW_DEBUG_TX("exit - no processed packets ready to release.\n");
2926
DEC_STAT(&priv->fw_pend_stat);
2928
#ifdef CONFIG_IPW2100_DEBUG
2931
IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i,
2933
(u32) (txq->nic + i * sizeof(struct ipw2100_bd)),
2934
txq->drv[i].host_addr, txq->drv[i].buf_length);
2936
if (packet->type == DATA) {
2937
i = (i + 1) % txq->entries;
2939
IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i,
2941
(u32) (txq->nic + i *
2942
sizeof(struct ipw2100_bd)),
2943
(u32) txq->drv[i].host_addr,
2944
txq->drv[i].buf_length);
2949
switch (packet->type) {
2951
if (txq->drv[txq->oldest].status.info.fields.txType != 0)
2952
printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
2953
"Expecting DATA TBD but pulled "
2954
"something else: ids %d=%d.\n",
2955
priv->net_dev->name, txq->oldest, packet->index);
2957
/* DATA packet; we have to unmap and free the SKB */
2958
for (i = 0; i < frag_num; i++) {
2959
tbd = &txq->drv[(packet->index + 1 + i) % txq->entries];
2961
IPW_DEBUG_TX("TX%d P=%08x L=%d\n",
2962
(packet->index + 1 + i) % txq->entries,
2963
tbd->host_addr, tbd->buf_length);
2965
pci_unmap_single(priv->pci_dev,
2967
tbd->buf_length, PCI_DMA_TODEVICE);
2970
libipw_txb_free(packet->info.d_struct.txb);
2971
packet->info.d_struct.txb = NULL;
2973
list_add_tail(element, &priv->tx_free_list);
2974
INC_STAT(&priv->tx_free_stat);
2976
/* We have a free slot in the Tx queue, so wake up the
2977
* transmit layer if it is stopped. */
2978
if (priv->status & STATUS_ASSOCIATED)
2979
netif_wake_queue(priv->net_dev);
2981
/* A packet was processed by the hardware, so update the
2983
priv->net_dev->trans_start = jiffies;
2988
if (txq->drv[txq->oldest].status.info.fields.txType != 1)
2989
printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
2990
"Expecting COMMAND TBD but pulled "
2991
"something else: ids %d=%d.\n",
2992
priv->net_dev->name, txq->oldest, packet->index);
2994
#ifdef CONFIG_IPW2100_DEBUG
2995
if (packet->info.c_struct.cmd->host_command_reg <
2996
ARRAY_SIZE(command_types))
2997
IPW_DEBUG_TX("Command '%s (%d)' processed: %d.\n",
2998
command_types[packet->info.c_struct.cmd->
3000
packet->info.c_struct.cmd->
3002
packet->info.c_struct.cmd->cmd_status_reg);
3005
list_add_tail(element, &priv->msg_free_list);
3006
INC_STAT(&priv->msg_free_stat);
3010
/* advance oldest used TBD pointer to start of next entry */
3011
txq->oldest = (e + 1) % txq->entries;
3012
/* increase available TBDs number */
3013
txq->available += descriptors_used;
3014
SET_STAT(&priv->txq_stat, txq->available);
3016
IPW_DEBUG_TX("packet latency (send to process) %ld jiffies\n",
3017
jiffies - packet->jiffy_start);
3019
return (!list_empty(&priv->fw_pend_list));
3022
static inline void __ipw2100_tx_complete(struct ipw2100_priv *priv)
3026
while (__ipw2100_tx_process(priv) && i < 200)
3030
printk(KERN_WARNING DRV_NAME ": "
3031
"%s: Driver is running slow (%d iters).\n",
3032
priv->net_dev->name, i);
3036
static void ipw2100_tx_send_commands(struct ipw2100_priv *priv)
3038
struct list_head *element;
3039
struct ipw2100_tx_packet *packet;
3040
struct ipw2100_bd_queue *txq = &priv->tx_queue;
3041
struct ipw2100_bd *tbd;
3042
int next = txq->next;
3044
while (!list_empty(&priv->msg_pend_list)) {
3045
/* if there isn't enough space in TBD queue, then
3046
* don't stuff a new one in.
3047
* NOTE: 3 are needed as a command will take one,
3048
* and there is a minimum of 2 that must be
3049
* maintained between the r and w indexes
3051
if (txq->available <= 3) {
3052
IPW_DEBUG_TX("no room in tx_queue\n");
3056
element = priv->msg_pend_list.next;
3058
DEC_STAT(&priv->msg_pend_stat);
3060
packet = list_entry(element, struct ipw2100_tx_packet, list);
3062
IPW_DEBUG_TX("using TBD at virt=%p, phys=%p\n",
3063
&txq->drv[txq->next],
3064
(void *)(txq->nic + txq->next *
3065
sizeof(struct ipw2100_bd)));
3067
packet->index = txq->next;
3069
tbd = &txq->drv[txq->next];
3071
/* initialize TBD */
3072
tbd->host_addr = packet->info.c_struct.cmd_phys;
3073
tbd->buf_length = sizeof(struct ipw2100_cmd_header);
3074
/* not marking number of fragments causes problems
3075
* with f/w debug version */
3076
tbd->num_fragments = 1;
3077
tbd->status.info.field =
3078
IPW_BD_STATUS_TX_FRAME_COMMAND |
3079
IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
3081
/* update TBD queue counters */
3083
txq->next %= txq->entries;
3085
DEC_STAT(&priv->txq_stat);
3087
list_add_tail(element, &priv->fw_pend_list);
3088
INC_STAT(&priv->fw_pend_stat);
3091
if (txq->next != next) {
3092
/* kick off the DMA by notifying firmware the
3093
* write index has moved; make sure TBD stores are sync'd */
3095
write_register(priv->net_dev,
3096
IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
3102
* ipw2100_tx_send_data
3105
static void ipw2100_tx_send_data(struct ipw2100_priv *priv)
3107
struct list_head *element;
3108
struct ipw2100_tx_packet *packet;
3109
struct ipw2100_bd_queue *txq = &priv->tx_queue;
3110
struct ipw2100_bd *tbd;
3111
int next = txq->next;
3113
struct ipw2100_data_header *ipw_hdr;
3114
struct libipw_hdr_3addr *hdr;
3116
while (!list_empty(&priv->tx_pend_list)) {
3117
/* if there isn't enough space in TBD queue, then
3118
* don't stuff a new one in.
3119
* NOTE: 4 are needed as a data will take two,
3120
* and there is a minimum of 2 that must be
3121
* maintained between the r and w indexes
3123
element = priv->tx_pend_list.next;
3124
packet = list_entry(element, struct ipw2100_tx_packet, list);
3126
if (unlikely(1 + packet->info.d_struct.txb->nr_frags >
3128
/* TODO: Support merging buffers if more than
3129
* IPW_MAX_BDS are used */
3130
IPW_DEBUG_INFO("%s: Maximum BD threshold exceeded. "
3131
"Increase fragmentation level.\n",
3132
priv->net_dev->name);
3135
if (txq->available <= 3 + packet->info.d_struct.txb->nr_frags) {
3136
IPW_DEBUG_TX("no room in tx_queue\n");
3141
DEC_STAT(&priv->tx_pend_stat);
3143
tbd = &txq->drv[txq->next];
3145
packet->index = txq->next;
3147
ipw_hdr = packet->info.d_struct.data;
3148
hdr = (struct libipw_hdr_3addr *)packet->info.d_struct.txb->
3151
if (priv->ieee->iw_mode == IW_MODE_INFRA) {
3152
/* To DS: Addr1 = BSSID, Addr2 = SA,
3154
memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
3155
memcpy(ipw_hdr->dst_addr, hdr->addr3, ETH_ALEN);
3156
} else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
3157
/* not From/To DS: Addr1 = DA, Addr2 = SA,
3159
memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
3160
memcpy(ipw_hdr->dst_addr, hdr->addr1, ETH_ALEN);
3163
ipw_hdr->host_command_reg = SEND;
3164
ipw_hdr->host_command_reg1 = 0;
3166
/* For now we only support host based encryption */
3167
ipw_hdr->needs_encryption = 0;
3168
ipw_hdr->encrypted = packet->info.d_struct.txb->encrypted;
3169
if (packet->info.d_struct.txb->nr_frags > 1)
3170
ipw_hdr->fragment_size =
3171
packet->info.d_struct.txb->frag_size -
3174
ipw_hdr->fragment_size = 0;
3176
tbd->host_addr = packet->info.d_struct.data_phys;
3177
tbd->buf_length = sizeof(struct ipw2100_data_header);
3178
tbd->num_fragments = 1 + packet->info.d_struct.txb->nr_frags;
3179
tbd->status.info.field =
3180
IPW_BD_STATUS_TX_FRAME_802_3 |
3181
IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
3183
txq->next %= txq->entries;
3185
IPW_DEBUG_TX("data header tbd TX%d P=%08x L=%d\n",
3186
packet->index, tbd->host_addr, tbd->buf_length);
3187
#ifdef CONFIG_IPW2100_DEBUG
3188
if (packet->info.d_struct.txb->nr_frags > 1)
3189
IPW_DEBUG_FRAG("fragment Tx: %d frames\n",
3190
packet->info.d_struct.txb->nr_frags);
3193
for (i = 0; i < packet->info.d_struct.txb->nr_frags; i++) {
3194
tbd = &txq->drv[txq->next];
3195
if (i == packet->info.d_struct.txb->nr_frags - 1)
3196
tbd->status.info.field =
3197
IPW_BD_STATUS_TX_FRAME_802_3 |
3198
IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
3200
tbd->status.info.field =
3201
IPW_BD_STATUS_TX_FRAME_802_3 |
3202
IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
3204
tbd->buf_length = packet->info.d_struct.txb->
3205
fragments[i]->len - LIBIPW_3ADDR_LEN;
3207
tbd->host_addr = pci_map_single(priv->pci_dev,
3208
packet->info.d_struct.
3215
IPW_DEBUG_TX("data frag tbd TX%d P=%08x L=%d\n",
3216
txq->next, tbd->host_addr,
3219
pci_dma_sync_single_for_device(priv->pci_dev,
3225
txq->next %= txq->entries;
3228
txq->available -= 1 + packet->info.d_struct.txb->nr_frags;
3229
SET_STAT(&priv->txq_stat, txq->available);
3231
list_add_tail(element, &priv->fw_pend_list);
3232
INC_STAT(&priv->fw_pend_stat);
3235
if (txq->next != next) {
3236
/* kick off the DMA by notifying firmware the
3237
* write index has moved; make sure TBD stores are sync'd */
3238
write_register(priv->net_dev,
3239
IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
3245
static void ipw2100_irq_tasklet(struct ipw2100_priv *priv)
3247
struct net_device *dev = priv->net_dev;
3248
unsigned long flags;
3251
spin_lock_irqsave(&priv->low_lock, flags);
3252
ipw2100_disable_interrupts(priv);
3254
read_register(dev, IPW_REG_INTA, &inta);
3256
IPW_DEBUG_ISR("enter - INTA: 0x%08lX\n",
3257
(unsigned long)inta & IPW_INTERRUPT_MASK);
3262
/* We do not loop and keep polling for more interrupts as this
3263
* is frowned upon and doesn't play nicely with other potentially
3265
IPW_DEBUG_ISR("INTA: 0x%08lX\n",
3266
(unsigned long)inta & IPW_INTERRUPT_MASK);
3268
if (inta & IPW2100_INTA_FATAL_ERROR) {
3269
printk(KERN_WARNING DRV_NAME
3270
": Fatal interrupt. Scheduling firmware restart.\n");
3272
write_register(dev, IPW_REG_INTA, IPW2100_INTA_FATAL_ERROR);
3274
read_nic_dword(dev, IPW_NIC_FATAL_ERROR, &priv->fatal_error);
3275
IPW_DEBUG_INFO("%s: Fatal error value: 0x%08X\n",
3276
priv->net_dev->name, priv->fatal_error);
3278
read_nic_dword(dev, IPW_ERROR_ADDR(priv->fatal_error), &tmp);
3279
IPW_DEBUG_INFO("%s: Fatal error address value: 0x%08X\n",
3280
priv->net_dev->name, tmp);
3282
/* Wake up any sleeping jobs */
3283
schedule_reset(priv);
3286
if (inta & IPW2100_INTA_PARITY_ERROR) {
3287
printk(KERN_ERR DRV_NAME
3288
": ***** PARITY ERROR INTERRUPT !!!! \n");
3290
write_register(dev, IPW_REG_INTA, IPW2100_INTA_PARITY_ERROR);
3293
if (inta & IPW2100_INTA_RX_TRANSFER) {
3294
IPW_DEBUG_ISR("RX interrupt\n");
3296
priv->rx_interrupts++;
3298
write_register(dev, IPW_REG_INTA, IPW2100_INTA_RX_TRANSFER);
3300
__ipw2100_rx_process(priv);
3301
__ipw2100_tx_complete(priv);
3304
if (inta & IPW2100_INTA_TX_TRANSFER) {
3305
IPW_DEBUG_ISR("TX interrupt\n");
3307
priv->tx_interrupts++;
3309
write_register(dev, IPW_REG_INTA, IPW2100_INTA_TX_TRANSFER);
3311
__ipw2100_tx_complete(priv);
3312
ipw2100_tx_send_commands(priv);
3313
ipw2100_tx_send_data(priv);
3316
if (inta & IPW2100_INTA_TX_COMPLETE) {
3317
IPW_DEBUG_ISR("TX complete\n");
3319
write_register(dev, IPW_REG_INTA, IPW2100_INTA_TX_COMPLETE);
3321
__ipw2100_tx_complete(priv);
3324
if (inta & IPW2100_INTA_EVENT_INTERRUPT) {
3325
/* ipw2100_handle_event(dev); */
3327
write_register(dev, IPW_REG_INTA, IPW2100_INTA_EVENT_INTERRUPT);
3330
if (inta & IPW2100_INTA_FW_INIT_DONE) {
3331
IPW_DEBUG_ISR("FW init done interrupt\n");
3334
read_register(dev, IPW_REG_INTA, &tmp);
3335
if (tmp & (IPW2100_INTA_FATAL_ERROR |
3336
IPW2100_INTA_PARITY_ERROR)) {
3337
write_register(dev, IPW_REG_INTA,
3338
IPW2100_INTA_FATAL_ERROR |
3339
IPW2100_INTA_PARITY_ERROR);
3342
write_register(dev, IPW_REG_INTA, IPW2100_INTA_FW_INIT_DONE);
3345
if (inta & IPW2100_INTA_STATUS_CHANGE) {
3346
IPW_DEBUG_ISR("Status change interrupt\n");
3348
write_register(dev, IPW_REG_INTA, IPW2100_INTA_STATUS_CHANGE);
3351
if (inta & IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE) {
3352
IPW_DEBUG_ISR("slave host mode interrupt\n");
3354
write_register(dev, IPW_REG_INTA,
3355
IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE);
3359
ipw2100_enable_interrupts(priv);
3361
spin_unlock_irqrestore(&priv->low_lock, flags);
3363
IPW_DEBUG_ISR("exit\n");
3366
static irqreturn_t ipw2100_interrupt(int irq, void *data)
3368
struct ipw2100_priv *priv = data;
3369
u32 inta, inta_mask;
3374
spin_lock(&priv->low_lock);
3376
/* We check to see if we should be ignoring interrupts before
3377
* we touch the hardware. During ucode load if we try and handle
3378
* an interrupt we can cause keyboard problems as well as cause
3379
* the ucode to fail to initialize */
3380
if (!(priv->status & STATUS_INT_ENABLED)) {
3385
read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
3386
read_register(priv->net_dev, IPW_REG_INTA, &inta);
3388
if (inta == 0xFFFFFFFF) {
3389
/* Hardware disappeared */
3390
printk(KERN_WARNING DRV_NAME ": IRQ INTA == 0xFFFFFFFF\n");
3394
inta &= IPW_INTERRUPT_MASK;
3396
if (!(inta & inta_mask)) {
3397
/* Shared interrupt */
3401
/* We disable the hardware interrupt here just to prevent unneeded
3402
* calls to be made. We disable this again within the actual
3403
* work tasklet, so if another part of the code re-enables the
3404
* interrupt, that is fine */
3405
ipw2100_disable_interrupts(priv);
3407
tasklet_schedule(&priv->irq_tasklet);
3408
spin_unlock(&priv->low_lock);
3412
spin_unlock(&priv->low_lock);
3416
static netdev_tx_t ipw2100_tx(struct libipw_txb *txb,
3417
struct net_device *dev, int pri)
3419
struct ipw2100_priv *priv = libipw_priv(dev);
3420
struct list_head *element;
3421
struct ipw2100_tx_packet *packet;
3422
unsigned long flags;
3424
spin_lock_irqsave(&priv->low_lock, flags);
3426
if (!(priv->status & STATUS_ASSOCIATED)) {
3427
IPW_DEBUG_INFO("Can not transmit when not connected.\n");
3428
priv->net_dev->stats.tx_carrier_errors++;
3429
netif_stop_queue(dev);
3433
if (list_empty(&priv->tx_free_list))
3436
element = priv->tx_free_list.next;
3437
packet = list_entry(element, struct ipw2100_tx_packet, list);
3439
packet->info.d_struct.txb = txb;
3441
IPW_DEBUG_TX("Sending fragment (%d bytes):\n", txb->fragments[0]->len);
3442
printk_buf(IPW_DL_TX, txb->fragments[0]->data, txb->fragments[0]->len);
3444
packet->jiffy_start = jiffies;
3447
DEC_STAT(&priv->tx_free_stat);
3449
list_add_tail(element, &priv->tx_pend_list);
3450
INC_STAT(&priv->tx_pend_stat);
3452
ipw2100_tx_send_data(priv);
3454
spin_unlock_irqrestore(&priv->low_lock, flags);
3455
return NETDEV_TX_OK;
3458
netif_stop_queue(dev);
3459
spin_unlock_irqrestore(&priv->low_lock, flags);
3460
return NETDEV_TX_BUSY;
3463
static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
3465
int i, j, err = -EINVAL;
3470
(struct ipw2100_tx_packet *)kmalloc(IPW_COMMAND_POOL_SIZE *
3474
if (!priv->msg_buffers) {
3475
printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for msg "
3476
"buffers.\n", priv->net_dev->name);
3480
for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3481
v = pci_alloc_consistent(priv->pci_dev,
3482
sizeof(struct ipw2100_cmd_header), &p);
3484
printk(KERN_ERR DRV_NAME ": "
3485
"%s: PCI alloc failed for msg "
3486
"buffers.\n", priv->net_dev->name);
3491
memset(v, 0, sizeof(struct ipw2100_cmd_header));
3493
priv->msg_buffers[i].type = COMMAND;
3494
priv->msg_buffers[i].info.c_struct.cmd =
3495
(struct ipw2100_cmd_header *)v;
3496
priv->msg_buffers[i].info.c_struct.cmd_phys = p;
3499
if (i == IPW_COMMAND_POOL_SIZE)
3502
for (j = 0; j < i; j++) {
3503
pci_free_consistent(priv->pci_dev,
3504
sizeof(struct ipw2100_cmd_header),
3505
priv->msg_buffers[j].info.c_struct.cmd,
3506
priv->msg_buffers[j].info.c_struct.
3510
kfree(priv->msg_buffers);
3511
priv->msg_buffers = NULL;
3516
static int ipw2100_msg_initialize(struct ipw2100_priv *priv)
3520
INIT_LIST_HEAD(&priv->msg_free_list);
3521
INIT_LIST_HEAD(&priv->msg_pend_list);
3523
for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++)
3524
list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list);
3525
SET_STAT(&priv->msg_free_stat, i);
3530
static void ipw2100_msg_free(struct ipw2100_priv *priv)
3534
if (!priv->msg_buffers)
3537
for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
3538
pci_free_consistent(priv->pci_dev,
3539
sizeof(struct ipw2100_cmd_header),
3540
priv->msg_buffers[i].info.c_struct.cmd,
3541
priv->msg_buffers[i].info.c_struct.
3545
kfree(priv->msg_buffers);
3546
priv->msg_buffers = NULL;
3549
static ssize_t show_pci(struct device *d, struct device_attribute *attr,
3552
struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev);
3557
for (i = 0; i < 16; i++) {
3558
out += sprintf(out, "[%08X] ", i * 16);
3559
for (j = 0; j < 16; j += 4) {
3560
pci_read_config_dword(pci_dev, i * 16 + j, &val);
3561
out += sprintf(out, "%08X ", val);
3563
out += sprintf(out, "\n");
3569
static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL);
3571
static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
3574
struct ipw2100_priv *p = dev_get_drvdata(d);
3575
return sprintf(buf, "0x%08x\n", (int)p->config);
3578
static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
3580
static ssize_t show_status(struct device *d, struct device_attribute *attr,
3583
struct ipw2100_priv *p = dev_get_drvdata(d);
3584
return sprintf(buf, "0x%08x\n", (int)p->status);
3587
static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3589
static ssize_t show_capability(struct device *d, struct device_attribute *attr,
3592
struct ipw2100_priv *p = dev_get_drvdata(d);
3593
return sprintf(buf, "0x%08x\n", (int)p->capability);
3596
static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL);
3598
#define IPW2100_REG(x) { IPW_ ##x, #x }
3599
static const struct {
3603
IPW2100_REG(REG_GP_CNTRL),
3604
IPW2100_REG(REG_GPIO),
3605
IPW2100_REG(REG_INTA),
3606
IPW2100_REG(REG_INTA_MASK), IPW2100_REG(REG_RESET_REG),};
3607
#define IPW2100_NIC(x, s) { x, #x, s }
3608
static const struct {
3613
IPW2100_NIC(IPW2100_CONTROL_REG, 2),
3614
IPW2100_NIC(0x210014, 1), IPW2100_NIC(0x210000, 1),};
3615
#define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
3616
static const struct {
3621
IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"),
3622
IPW2100_ORD(STAT_TX_HOST_COMPLETE,
3623
"successful Host Tx's (MSDU)"),
3624
IPW2100_ORD(STAT_TX_DIR_DATA,
3625
"successful Directed Tx's (MSDU)"),
3626
IPW2100_ORD(STAT_TX_DIR_DATA1,
3627
"successful Directed Tx's (MSDU) @ 1MB"),
3628
IPW2100_ORD(STAT_TX_DIR_DATA2,
3629
"successful Directed Tx's (MSDU) @ 2MB"),
3630
IPW2100_ORD(STAT_TX_DIR_DATA5_5,
3631
"successful Directed Tx's (MSDU) @ 5_5MB"),
3632
IPW2100_ORD(STAT_TX_DIR_DATA11,
3633
"successful Directed Tx's (MSDU) @ 11MB"),
3634
IPW2100_ORD(STAT_TX_NODIR_DATA1,
3635
"successful Non_Directed Tx's (MSDU) @ 1MB"),
3636
IPW2100_ORD(STAT_TX_NODIR_DATA2,
3637
"successful Non_Directed Tx's (MSDU) @ 2MB"),
3638
IPW2100_ORD(STAT_TX_NODIR_DATA5_5,
3639
"successful Non_Directed Tx's (MSDU) @ 5.5MB"),
3640
IPW2100_ORD(STAT_TX_NODIR_DATA11,
3641
"successful Non_Directed Tx's (MSDU) @ 11MB"),
3642
IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"),
3643
IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"),
3644
IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"),
3645
IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"),
3646
IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"),
3647
IPW2100_ORD(STAT_TX_ASSN_RESP,
3648
"successful Association response Tx's"),
3649
IPW2100_ORD(STAT_TX_REASSN,
3650
"successful Reassociation Tx's"),
3651
IPW2100_ORD(STAT_TX_REASSN_RESP,
3652
"successful Reassociation response Tx's"),
3653
IPW2100_ORD(STAT_TX_PROBE,
3654
"probes successfully transmitted"),
3655
IPW2100_ORD(STAT_TX_PROBE_RESP,
3656
"probe responses successfully transmitted"),
3657
IPW2100_ORD(STAT_TX_BEACON, "tx beacon"),
3658
IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"),
3659
IPW2100_ORD(STAT_TX_DISASSN,
3660
"successful Disassociation TX"),
3661
IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"),
3662
IPW2100_ORD(STAT_TX_DEAUTH,
3663
"successful Deauthentication TX"),
3664
IPW2100_ORD(STAT_TX_TOTAL_BYTES,
3665
"Total successful Tx data bytes"),
3666
IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"),
3667
IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"),
3668
IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"),
3669
IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"),
3670
IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"),
3671
IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"),
3672
IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,
3673
"times max tries in a hop failed"),
3674
IPW2100_ORD(STAT_TX_DISASSN_FAIL,
3675
"times disassociation failed"),
3676
IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"),
3677
IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"),
3678
IPW2100_ORD(STAT_RX_HOST, "packets passed to host"),
3679
IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"),
3680
IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"),
3681
IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"),
3682
IPW2100_ORD(STAT_RX_DIR_DATA5_5,
3683
"directed packets at 5.5MB"),
3684
IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"),
3685
IPW2100_ORD(STAT_RX_NODIR_DATA, "nondirected packets"),
3686
IPW2100_ORD(STAT_RX_NODIR_DATA1,
3687
"nondirected packets at 1MB"),
3688
IPW2100_ORD(STAT_RX_NODIR_DATA2,
3689
"nondirected packets at 2MB"),
3690
IPW2100_ORD(STAT_RX_NODIR_DATA5_5,
3691
"nondirected packets at 5.5MB"),
3692
IPW2100_ORD(STAT_RX_NODIR_DATA11,
3693
"nondirected packets at 11MB"),
3694
IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"),
3695
IPW2100_ORD(STAT_RX_RTS, "Rx RTS"), IPW2100_ORD(STAT_RX_CTS,
3697
IPW2100_ORD(STAT_RX_ACK, "Rx ACK"),
3698
IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"),
3699
IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"),
3700
IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"),
3701
IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"),
3702
IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"),
3703
IPW2100_ORD(STAT_RX_REASSN_RESP,
3704
"Reassociation response Rx's"),
3705
IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"),
3706
IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"),
3707
IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"),
3708
IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"),
3709
IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"),
3710
IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"),
3711
IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"),
3712
IPW2100_ORD(STAT_RX_TOTAL_BYTES,
3713
"Total rx data bytes received"),
3714
IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"),
3715
IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"),
3716
IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"),
3717
IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"),
3718
IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"),
3719
IPW2100_ORD(STAT_RX_DUPLICATE1,
3720
"duplicate rx packets at 1MB"),
3721
IPW2100_ORD(STAT_RX_DUPLICATE2,
3722
"duplicate rx packets at 2MB"),
3723
IPW2100_ORD(STAT_RX_DUPLICATE5_5,
3724
"duplicate rx packets at 5.5MB"),
3725
IPW2100_ORD(STAT_RX_DUPLICATE11,
3726
"duplicate rx packets at 11MB"),
3727
IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"),
3728
IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"),
3729
IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"),
3730
IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"),
3731
IPW2100_ORD(STAT_RX_INVALID_PROTOCOL,
3732
"rx frames with invalid protocol"),
3733
IPW2100_ORD(SYS_BOOT_TIME, "Boot time"),
3734
IPW2100_ORD(STAT_RX_NO_BUFFER,
3735
"rx frames rejected due to no buffer"),
3736
IPW2100_ORD(STAT_RX_MISSING_FRAG,
3737
"rx frames dropped due to missing fragment"),
3738
IPW2100_ORD(STAT_RX_ORPHAN_FRAG,
3739
"rx frames dropped due to non-sequential fragment"),
3740
IPW2100_ORD(STAT_RX_ORPHAN_FRAME,
3741
"rx frames dropped due to unmatched 1st frame"),
3742
IPW2100_ORD(STAT_RX_FRAG_AGEOUT,
3743
"rx frames dropped due to uncompleted frame"),
3744
IPW2100_ORD(STAT_RX_ICV_ERRORS,
3745
"ICV errors during decryption"),
3746
IPW2100_ORD(STAT_PSP_SUSPENSION, "times adapter suspended"),
3747
IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"),
3748
IPW2100_ORD(STAT_PSP_POLL_TIMEOUT,
3749
"poll response timeouts"),
3750
IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT,
3751
"timeouts waiting for last {broad,multi}cast pkt"),
3752
IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"),
3753
IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"),
3754
IPW2100_ORD(STAT_PSP_STATION_ID, "PSP Station ID"),
3755
IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"),
3756
IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,
3757
"current calculation of % missed beacons"),
3758
IPW2100_ORD(STAT_PERCENT_RETRIES,
3759
"current calculation of % missed tx retries"),
3760
IPW2100_ORD(ASSOCIATED_AP_PTR,
3761
"0 if not associated, else pointer to AP table entry"),
3762
IPW2100_ORD(AVAILABLE_AP_CNT,
3763
"AP's decsribed in the AP table"),
3764
IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"),
3765
IPW2100_ORD(STAT_AP_ASSNS, "associations"),
3766
IPW2100_ORD(STAT_ASSN_FAIL, "association failures"),
3767
IPW2100_ORD(STAT_ASSN_RESP_FAIL,
3768
"failures due to response fail"),
3769
IPW2100_ORD(STAT_FULL_SCANS, "full scans"),
3770
IPW2100_ORD(CARD_DISABLED, "Card Disabled"),
3771
IPW2100_ORD(STAT_ROAM_INHIBIT,
3772
"times roaming was inhibited due to activity"),
3773
IPW2100_ORD(RSSI_AT_ASSN,
3774
"RSSI of associated AP at time of association"),
3775
IPW2100_ORD(STAT_ASSN_CAUSE1,
3776
"reassociation: no probe response or TX on hop"),
3777
IPW2100_ORD(STAT_ASSN_CAUSE2,
3778
"reassociation: poor tx/rx quality"),
3779
IPW2100_ORD(STAT_ASSN_CAUSE3,
3780
"reassociation: tx/rx quality (excessive AP load"),
3781
IPW2100_ORD(STAT_ASSN_CAUSE4,
3782
"reassociation: AP RSSI level"),
3783
IPW2100_ORD(STAT_ASSN_CAUSE5,
3784
"reassociations due to load leveling"),
3785
IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"),
3786
IPW2100_ORD(STAT_AUTH_RESP_FAIL,
3787
"times authentication response failed"),
3788
IPW2100_ORD(STATION_TABLE_CNT,
3789
"entries in association table"),
3790
IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"),
3791
IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"),
3792
IPW2100_ORD(COUNTRY_CODE,
3793
"IEEE country code as recv'd from beacon"),
3794
IPW2100_ORD(COUNTRY_CHANNELS,
3795
"channels suported by country"),
3796
IPW2100_ORD(RESET_CNT, "adapter resets (warm)"),
3797
IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"),
3798
IPW2100_ORD(ANTENNA_DIVERSITY,
3799
"TRUE if antenna diversity is disabled"),
3800
IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"),
3801
IPW2100_ORD(OUR_FREQ,
3802
"current radio freq lower digits - channel ID"),
3803
IPW2100_ORD(RTC_TIME, "current RTC time"),
3804
IPW2100_ORD(PORT_TYPE, "operating mode"),
3805
IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"),
3806
IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"),
3807
IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"),
3808
IPW2100_ORD(BASIC_RATES, "basic tx rates"),
3809
IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"),
3810
IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"),
3811
IPW2100_ORD(CAPABILITIES,
3812
"Management frame capability field"),
3813
IPW2100_ORD(AUTH_TYPE, "Type of authentication"),
3814
IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"),
3815
IPW2100_ORD(RTS_THRESHOLD,
3816
"Min packet length for RTS handshaking"),
3817
IPW2100_ORD(INT_MODE, "International mode"),
3818
IPW2100_ORD(FRAGMENTATION_THRESHOLD,
3819
"protocol frag threshold"),
3820
IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS,
3821
"EEPROM offset in SRAM"),
3822
IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE,
3823
"EEPROM size in SRAM"),
3824
IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"),
3825
IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS,
3826
"EEPROM IBSS 11b channel set"),
3827
IPW2100_ORD(MAC_VERSION, "MAC Version"),
3828
IPW2100_ORD(MAC_REVISION, "MAC Revision"),
3829
IPW2100_ORD(RADIO_VERSION, "Radio Version"),
3830
IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"),
3831
IPW2100_ORD(UCODE_VERSION, "Ucode Version"),};
3833
static ssize_t show_registers(struct device *d, struct device_attribute *attr,
3837
struct ipw2100_priv *priv = dev_get_drvdata(d);
3838
struct net_device *dev = priv->net_dev;
3842
out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
3844
for (i = 0; i < ARRAY_SIZE(hw_data); i++) {
3845
read_register(dev, hw_data[i].addr, &val);
3846
out += sprintf(out, "%30s [%08X] : %08X\n",
3847
hw_data[i].name, hw_data[i].addr, val);
3853
static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
3855
static ssize_t show_hardware(struct device *d, struct device_attribute *attr,
3858
struct ipw2100_priv *priv = dev_get_drvdata(d);
3859
struct net_device *dev = priv->net_dev;
3863
out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
3865
for (i = 0; i < ARRAY_SIZE(nic_data); i++) {
3870
switch (nic_data[i].size) {
3872
read_nic_byte(dev, nic_data[i].addr, &tmp8);
3873
out += sprintf(out, "%30s [%08X] : %02X\n",
3874
nic_data[i].name, nic_data[i].addr,
3878
read_nic_word(dev, nic_data[i].addr, &tmp16);
3879
out += sprintf(out, "%30s [%08X] : %04X\n",
3880
nic_data[i].name, nic_data[i].addr,
3884
read_nic_dword(dev, nic_data[i].addr, &tmp32);
3885
out += sprintf(out, "%30s [%08X] : %08X\n",
3886
nic_data[i].name, nic_data[i].addr,
3894
static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL);
3896
static ssize_t show_memory(struct device *d, struct device_attribute *attr,
3899
struct ipw2100_priv *priv = dev_get_drvdata(d);
3900
struct net_device *dev = priv->net_dev;
3901
static unsigned long loop = 0;
3907
if (loop >= 0x30000)
3910
/* sysfs provides us PAGE_SIZE buffer */
3911
while (len < PAGE_SIZE - 128 && loop < 0x30000) {
3913
if (priv->snapshot[0])
3914
for (i = 0; i < 4; i++)
3916
*(u32 *) SNAPSHOT_ADDR(loop + i * 4);
3918
for (i = 0; i < 4; i++)
3919
read_nic_dword(dev, loop + i * 4, &buffer[i]);
3922
len += sprintf(buf + len,
3927
((u8 *) buffer)[0x0],
3928
((u8 *) buffer)[0x1],
3929
((u8 *) buffer)[0x2],
3930
((u8 *) buffer)[0x3],
3931
((u8 *) buffer)[0x4],
3932
((u8 *) buffer)[0x5],
3933
((u8 *) buffer)[0x6],
3934
((u8 *) buffer)[0x7],
3935
((u8 *) buffer)[0x8],
3936
((u8 *) buffer)[0x9],
3937
((u8 *) buffer)[0xa],
3938
((u8 *) buffer)[0xb],
3939
((u8 *) buffer)[0xc],
3940
((u8 *) buffer)[0xd],
3941
((u8 *) buffer)[0xe],
3942
((u8 *) buffer)[0xf]);
3944
len += sprintf(buf + len, "%s\n",
3945
snprint_line(line, sizeof(line),
3946
(u8 *) buffer, 16, loop));
3953
static ssize_t store_memory(struct device *d, struct device_attribute *attr,
3954
const char *buf, size_t count)
3956
struct ipw2100_priv *priv = dev_get_drvdata(d);
3957
struct net_device *dev = priv->net_dev;
3958
const char *p = buf;
3960
(void)dev; /* kill unused-var warning for debug-only code */
3966
(count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) {
3967
IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
3971
} else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' &&
3972
tolower(p[1]) == 'f')) {
3973
IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
3977
} else if (tolower(p[0]) == 'r') {
3978
IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n", dev->name);
3979
ipw2100_snapshot_free(priv);
3982
IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
3983
"reset = clear memory snapshot\n", dev->name);
3988
static DEVICE_ATTR(memory, S_IWUSR | S_IRUGO, show_memory, store_memory);
3990
static ssize_t show_ordinals(struct device *d, struct device_attribute *attr,
3993
struct ipw2100_priv *priv = dev_get_drvdata(d);
3997
static int loop = 0;
3999
if (priv->status & STATUS_RF_KILL_MASK)
4002
if (loop >= ARRAY_SIZE(ord_data))
4005
/* sysfs provides us PAGE_SIZE buffer */
4006
while (len < PAGE_SIZE - 128 && loop < ARRAY_SIZE(ord_data)) {
4007
val_len = sizeof(u32);
4009
if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
4011
len += sprintf(buf + len, "[0x%02X] = ERROR %s\n",
4012
ord_data[loop].index,
4013
ord_data[loop].desc);
4015
len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n",
4016
ord_data[loop].index, val,
4017
ord_data[loop].desc);
4024
static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL);
4026
static ssize_t show_stats(struct device *d, struct device_attribute *attr,
4029
struct ipw2100_priv *priv = dev_get_drvdata(d);
4032
out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
4033
priv->interrupts, priv->tx_interrupts,
4034
priv->rx_interrupts, priv->inta_other);
4035
out += sprintf(out, "firmware resets: %d\n", priv->resets);
4036
out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
4037
#ifdef CONFIG_IPW2100_DEBUG
4038
out += sprintf(out, "packet mismatch image: %s\n",
4039
priv->snapshot[0] ? "YES" : "NO");
4045
static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
4047
static int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode)
4051
if (mode == priv->ieee->iw_mode)
4054
err = ipw2100_disable_adapter(priv);
4056
printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
4057
priv->net_dev->name, err);
4063
priv->net_dev->type = ARPHRD_ETHER;
4066
priv->net_dev->type = ARPHRD_ETHER;
4068
#ifdef CONFIG_IPW2100_MONITOR
4069
case IW_MODE_MONITOR:
4070
priv->last_mode = priv->ieee->iw_mode;
4071
priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
4073
#endif /* CONFIG_IPW2100_MONITOR */
4076
priv->ieee->iw_mode = mode;
4079
/* Indicate ipw2100_download_firmware download firmware
4080
* from disk instead of memory. */
4081
ipw2100_firmware.version = 0;
4084
printk(KERN_INFO "%s: Reseting on mode change.\n", priv->net_dev->name);
4085
priv->reset_backoff = 0;
4086
schedule_reset(priv);
4091
static ssize_t show_internals(struct device *d, struct device_attribute *attr,
4094
struct ipw2100_priv *priv = dev_get_drvdata(d);
4097
#define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" y "\n", priv-> x)
4099
if (priv->status & STATUS_ASSOCIATED)
4100
len += sprintf(buf + len, "connected: %lu\n",
4101
get_seconds() - priv->connect_start);
4103
len += sprintf(buf + len, "not connected\n");
4105
DUMP_VAR(ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx], "p");
4106
DUMP_VAR(status, "08lx");
4107
DUMP_VAR(config, "08lx");
4108
DUMP_VAR(capability, "08lx");
4111
sprintf(buf + len, "last_rtc: %lu\n",
4112
(unsigned long)priv->last_rtc);
4114
DUMP_VAR(fatal_error, "d");
4115
DUMP_VAR(stop_hang_check, "d");
4116
DUMP_VAR(stop_rf_kill, "d");
4117
DUMP_VAR(messages_sent, "d");
4119
DUMP_VAR(tx_pend_stat.value, "d");
4120
DUMP_VAR(tx_pend_stat.hi, "d");
4122
DUMP_VAR(tx_free_stat.value, "d");
4123
DUMP_VAR(tx_free_stat.lo, "d");
4125
DUMP_VAR(msg_free_stat.value, "d");
4126
DUMP_VAR(msg_free_stat.lo, "d");
4128
DUMP_VAR(msg_pend_stat.value, "d");
4129
DUMP_VAR(msg_pend_stat.hi, "d");
4131
DUMP_VAR(fw_pend_stat.value, "d");
4132
DUMP_VAR(fw_pend_stat.hi, "d");
4134
DUMP_VAR(txq_stat.value, "d");
4135
DUMP_VAR(txq_stat.lo, "d");
4137
DUMP_VAR(ieee->scans, "d");
4138
DUMP_VAR(reset_backoff, "d");
4143
static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL);
4145
static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr,
4148
struct ipw2100_priv *priv = dev_get_drvdata(d);
4149
char essid[IW_ESSID_MAX_SIZE + 1];
4153
unsigned int length;
4156
if (priv->status & STATUS_RF_KILL_MASK)
4159
memset(essid, 0, sizeof(essid));
4160
memset(bssid, 0, sizeof(bssid));
4162
length = IW_ESSID_MAX_SIZE;
4163
ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length);
4165
IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4168
length = sizeof(bssid);
4169
ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
4172
IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4175
length = sizeof(u32);
4176
ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length);
4178
IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
4181
out += sprintf(out, "ESSID: %s\n", essid);
4182
out += sprintf(out, "BSSID: %pM\n", bssid);
4183
out += sprintf(out, "Channel: %d\n", chan);
4188
static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL);
4190
#ifdef CONFIG_IPW2100_DEBUG
4191
static ssize_t show_debug_level(struct device_driver *d, char *buf)
4193
return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
4196
static ssize_t store_debug_level(struct device_driver *d,
4197
const char *buf, size_t count)
4199
char *p = (char *)buf;
4202
if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4204
if (p[0] == 'x' || p[0] == 'X')
4206
val = simple_strtoul(p, &p, 16);
4208
val = simple_strtoul(p, &p, 10);
4210
IPW_DEBUG_INFO(": %s is not in hex or decimal form.\n", buf);
4212
ipw2100_debug_level = val;
4214
return strnlen(buf, count);
4217
static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level,
4219
#endif /* CONFIG_IPW2100_DEBUG */
4221
static ssize_t show_fatal_error(struct device *d,
4222
struct device_attribute *attr, char *buf)
4224
struct ipw2100_priv *priv = dev_get_drvdata(d);
4228
if (priv->fatal_error)
4229
out += sprintf(out, "0x%08X\n", priv->fatal_error);
4231
out += sprintf(out, "0\n");
4233
for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) {
4234
if (!priv->fatal_errors[(priv->fatal_index - i) %
4235
IPW2100_ERROR_QUEUE])
4238
out += sprintf(out, "%d. 0x%08X\n", i,
4239
priv->fatal_errors[(priv->fatal_index - i) %
4240
IPW2100_ERROR_QUEUE]);
4246
static ssize_t store_fatal_error(struct device *d,
4247
struct device_attribute *attr, const char *buf,
4250
struct ipw2100_priv *priv = dev_get_drvdata(d);
4251
schedule_reset(priv);
4255
static DEVICE_ATTR(fatal_error, S_IWUSR | S_IRUGO, show_fatal_error,
4258
static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
4261
struct ipw2100_priv *priv = dev_get_drvdata(d);
4262
return sprintf(buf, "%d\n", priv->ieee->scan_age);
4265
static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
4266
const char *buf, size_t count)
4268
struct ipw2100_priv *priv = dev_get_drvdata(d);
4269
struct net_device *dev = priv->net_dev;
4270
char buffer[] = "00000000";
4272
(sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
4276
(void)dev; /* kill unused-var warning for debug-only code */
4278
IPW_DEBUG_INFO("enter\n");
4280
strncpy(buffer, buf, len);
4283
if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
4285
if (p[0] == 'x' || p[0] == 'X')
4287
val = simple_strtoul(p, &p, 16);
4289
val = simple_strtoul(p, &p, 10);
4291
IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
4293
priv->ieee->scan_age = val;
4294
IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
4297
IPW_DEBUG_INFO("exit\n");
4301
static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
4303
static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
4306
/* 0 - RF kill not enabled
4307
1 - SW based RF kill active (sysfs)
4308
2 - HW based RF kill active
4309
3 - Both HW and SW baed RF kill active */
4310
struct ipw2100_priv *priv = dev_get_drvdata(d);
4311
int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
4312
(rf_kill_active(priv) ? 0x2 : 0x0);
4313
return sprintf(buf, "%i\n", val);
4316
static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
4318
if ((disable_radio ? 1 : 0) ==
4319
(priv->status & STATUS_RF_KILL_SW ? 1 : 0))
4322
IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
4323
disable_radio ? "OFF" : "ON");
4325
mutex_lock(&priv->action_mutex);
4327
if (disable_radio) {
4328
priv->status |= STATUS_RF_KILL_SW;
4331
priv->status &= ~STATUS_RF_KILL_SW;
4332
if (rf_kill_active(priv)) {
4333
IPW_DEBUG_RF_KILL("Can not turn radio back on - "
4334
"disabled by HW switch\n");
4335
/* Make sure the RF_KILL check timer is running */
4336
priv->stop_rf_kill = 0;
4337
cancel_delayed_work(&priv->rf_kill);
4338
queue_delayed_work(priv->workqueue, &priv->rf_kill,
4339
round_jiffies_relative(HZ));
4341
schedule_reset(priv);
4344
mutex_unlock(&priv->action_mutex);
4348
static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
4349
const char *buf, size_t count)
4351
struct ipw2100_priv *priv = dev_get_drvdata(d);
4352
ipw_radio_kill_sw(priv, buf[0] == '1');
4356
static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
4358
static struct attribute *ipw2100_sysfs_entries[] = {
4359
&dev_attr_hardware.attr,
4360
&dev_attr_registers.attr,
4361
&dev_attr_ordinals.attr,
4363
&dev_attr_stats.attr,
4364
&dev_attr_internals.attr,
4365
&dev_attr_bssinfo.attr,
4366
&dev_attr_memory.attr,
4367
&dev_attr_scan_age.attr,
4368
&dev_attr_fatal_error.attr,
4369
&dev_attr_rf_kill.attr,
4371
&dev_attr_status.attr,
4372
&dev_attr_capability.attr,
4376
static struct attribute_group ipw2100_attribute_group = {
4377
.attrs = ipw2100_sysfs_entries,
4380
static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
4382
struct ipw2100_status_queue *q = &priv->status_queue;
4384
IPW_DEBUG_INFO("enter\n");
4386
q->size = entries * sizeof(struct ipw2100_status);
4388
(struct ipw2100_status *)pci_alloc_consistent(priv->pci_dev,
4391
IPW_DEBUG_WARNING("Can not allocate status queue.\n");
4395
memset(q->drv, 0, q->size);
4397
IPW_DEBUG_INFO("exit\n");
4402
static void status_queue_free(struct ipw2100_priv *priv)
4404
IPW_DEBUG_INFO("enter\n");
4406
if (priv->status_queue.drv) {
4407
pci_free_consistent(priv->pci_dev, priv->status_queue.size,
4408
priv->status_queue.drv,
4409
priv->status_queue.nic);
4410
priv->status_queue.drv = NULL;
4413
IPW_DEBUG_INFO("exit\n");
4416
static int bd_queue_allocate(struct ipw2100_priv *priv,
4417
struct ipw2100_bd_queue *q, int entries)
4419
IPW_DEBUG_INFO("enter\n");
4421
memset(q, 0, sizeof(struct ipw2100_bd_queue));
4423
q->entries = entries;
4424
q->size = entries * sizeof(struct ipw2100_bd);
4425
q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic);
4428
("can't allocate shared memory for buffer descriptors\n");
4431
memset(q->drv, 0, q->size);
4433
IPW_DEBUG_INFO("exit\n");
4438
static void bd_queue_free(struct ipw2100_priv *priv, struct ipw2100_bd_queue *q)
4440
IPW_DEBUG_INFO("enter\n");
4446
pci_free_consistent(priv->pci_dev, q->size, q->drv, q->nic);
4450
IPW_DEBUG_INFO("exit\n");
4453
static void bd_queue_initialize(struct ipw2100_priv *priv,
4454
struct ipw2100_bd_queue *q, u32 base, u32 size,
4457
IPW_DEBUG_INFO("enter\n");
4459
IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv,
4462
write_register(priv->net_dev, base, q->nic);
4463
write_register(priv->net_dev, size, q->entries);
4464
write_register(priv->net_dev, r, q->oldest);
4465
write_register(priv->net_dev, w, q->next);
4467
IPW_DEBUG_INFO("exit\n");
4470
static void ipw2100_kill_workqueue(struct ipw2100_priv *priv)
4472
if (priv->workqueue) {
4473
priv->stop_rf_kill = 1;
4474
priv->stop_hang_check = 1;
4475
cancel_delayed_work(&priv->reset_work);
4476
cancel_delayed_work(&priv->security_work);
4477
cancel_delayed_work(&priv->wx_event_work);
4478
cancel_delayed_work(&priv->hang_check);
4479
cancel_delayed_work(&priv->rf_kill);
4480
cancel_delayed_work(&priv->scan_event_later);
4481
destroy_workqueue(priv->workqueue);
4482
priv->workqueue = NULL;
4486
static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
4488
int i, j, err = -EINVAL;
4492
IPW_DEBUG_INFO("enter\n");
4494
err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH);
4496
IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
4497
priv->net_dev->name);
4502
(struct ipw2100_tx_packet *)kmalloc(TX_PENDED_QUEUE_LENGTH *
4506
if (!priv->tx_buffers) {
4507
printk(KERN_ERR DRV_NAME
4508
": %s: alloc failed form tx buffers.\n",
4509
priv->net_dev->name);
4510
bd_queue_free(priv, &priv->tx_queue);
4514
for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4515
v = pci_alloc_consistent(priv->pci_dev,
4516
sizeof(struct ipw2100_data_header),
4519
printk(KERN_ERR DRV_NAME
4520
": %s: PCI alloc failed for tx " "buffers.\n",
4521
priv->net_dev->name);
4526
priv->tx_buffers[i].type = DATA;
4527
priv->tx_buffers[i].info.d_struct.data =
4528
(struct ipw2100_data_header *)v;
4529
priv->tx_buffers[i].info.d_struct.data_phys = p;
4530
priv->tx_buffers[i].info.d_struct.txb = NULL;
4533
if (i == TX_PENDED_QUEUE_LENGTH)
4536
for (j = 0; j < i; j++) {
4537
pci_free_consistent(priv->pci_dev,
4538
sizeof(struct ipw2100_data_header),
4539
priv->tx_buffers[j].info.d_struct.data,
4540
priv->tx_buffers[j].info.d_struct.
4544
kfree(priv->tx_buffers);
4545
priv->tx_buffers = NULL;
4550
static void ipw2100_tx_initialize(struct ipw2100_priv *priv)
4554
IPW_DEBUG_INFO("enter\n");
4557
* reinitialize packet info lists
4559
INIT_LIST_HEAD(&priv->fw_pend_list);
4560
INIT_STAT(&priv->fw_pend_stat);
4563
* reinitialize lists
4565
INIT_LIST_HEAD(&priv->tx_pend_list);
4566
INIT_LIST_HEAD(&priv->tx_free_list);
4567
INIT_STAT(&priv->tx_pend_stat);
4568
INIT_STAT(&priv->tx_free_stat);
4570
for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4571
/* We simply drop any SKBs that have been queued for
4573
if (priv->tx_buffers[i].info.d_struct.txb) {
4574
libipw_txb_free(priv->tx_buffers[i].info.d_struct.
4576
priv->tx_buffers[i].info.d_struct.txb = NULL;
4579
list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list);
4582
SET_STAT(&priv->tx_free_stat, i);
4584
priv->tx_queue.oldest = 0;
4585
priv->tx_queue.available = priv->tx_queue.entries;
4586
priv->tx_queue.next = 0;
4587
INIT_STAT(&priv->txq_stat);
4588
SET_STAT(&priv->txq_stat, priv->tx_queue.available);
4590
bd_queue_initialize(priv, &priv->tx_queue,
4591
IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE,
4592
IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE,
4593
IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
4594
IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX);
4596
IPW_DEBUG_INFO("exit\n");
4600
static void ipw2100_tx_free(struct ipw2100_priv *priv)
4604
IPW_DEBUG_INFO("enter\n");
4606
bd_queue_free(priv, &priv->tx_queue);
4608
if (!priv->tx_buffers)
4611
for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
4612
if (priv->tx_buffers[i].info.d_struct.txb) {
4613
libipw_txb_free(priv->tx_buffers[i].info.d_struct.
4615
priv->tx_buffers[i].info.d_struct.txb = NULL;
4617
if (priv->tx_buffers[i].info.d_struct.data)
4618
pci_free_consistent(priv->pci_dev,
4619
sizeof(struct ipw2100_data_header),
4620
priv->tx_buffers[i].info.d_struct.
4622
priv->tx_buffers[i].info.d_struct.
4626
kfree(priv->tx_buffers);
4627
priv->tx_buffers = NULL;
4629
IPW_DEBUG_INFO("exit\n");
4632
static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
4634
int i, j, err = -EINVAL;
4636
IPW_DEBUG_INFO("enter\n");
4638
err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH);
4640
IPW_DEBUG_INFO("failed bd_queue_allocate\n");
4644
err = status_queue_allocate(priv, RX_QUEUE_LENGTH);
4646
IPW_DEBUG_INFO("failed status_queue_allocate\n");
4647
bd_queue_free(priv, &priv->rx_queue);
4654
priv->rx_buffers = (struct ipw2100_rx_packet *)
4655
kmalloc(RX_QUEUE_LENGTH * sizeof(struct ipw2100_rx_packet),
4657
if (!priv->rx_buffers) {
4658
IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
4660
bd_queue_free(priv, &priv->rx_queue);
4662
status_queue_free(priv);
4667
for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4668
struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
4670
err = ipw2100_alloc_skb(priv, packet);
4671
if (unlikely(err)) {
4676
/* The BD holds the cache aligned address */
4677
priv->rx_queue.drv[i].host_addr = packet->dma_addr;
4678
priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH;
4679
priv->status_queue.drv[i].status_fields = 0;
4682
if (i == RX_QUEUE_LENGTH)
4685
for (j = 0; j < i; j++) {
4686
pci_unmap_single(priv->pci_dev, priv->rx_buffers[j].dma_addr,
4687
sizeof(struct ipw2100_rx_packet),
4688
PCI_DMA_FROMDEVICE);
4689
dev_kfree_skb(priv->rx_buffers[j].skb);
4692
kfree(priv->rx_buffers);
4693
priv->rx_buffers = NULL;
4695
bd_queue_free(priv, &priv->rx_queue);
4697
status_queue_free(priv);
4702
static void ipw2100_rx_initialize(struct ipw2100_priv *priv)
4704
IPW_DEBUG_INFO("enter\n");
4706
priv->rx_queue.oldest = 0;
4707
priv->rx_queue.available = priv->rx_queue.entries - 1;
4708
priv->rx_queue.next = priv->rx_queue.entries - 1;
4710
INIT_STAT(&priv->rxq_stat);
4711
SET_STAT(&priv->rxq_stat, priv->rx_queue.available);
4713
bd_queue_initialize(priv, &priv->rx_queue,
4714
IPW_MEM_HOST_SHARED_RX_BD_BASE,
4715
IPW_MEM_HOST_SHARED_RX_BD_SIZE,
4716
IPW_MEM_HOST_SHARED_RX_READ_INDEX,
4717
IPW_MEM_HOST_SHARED_RX_WRITE_INDEX);
4719
/* set up the status queue */
4720
write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE,
4721
priv->status_queue.nic);
4723
IPW_DEBUG_INFO("exit\n");
4726
static void ipw2100_rx_free(struct ipw2100_priv *priv)
4730
IPW_DEBUG_INFO("enter\n");
4732
bd_queue_free(priv, &priv->rx_queue);
4733
status_queue_free(priv);
4735
if (!priv->rx_buffers)
4738
for (i = 0; i < RX_QUEUE_LENGTH; i++) {
4739
if (priv->rx_buffers[i].rxp) {
4740
pci_unmap_single(priv->pci_dev,
4741
priv->rx_buffers[i].dma_addr,
4742
sizeof(struct ipw2100_rx),
4743
PCI_DMA_FROMDEVICE);
4744
dev_kfree_skb(priv->rx_buffers[i].skb);
4748
kfree(priv->rx_buffers);
4749
priv->rx_buffers = NULL;
4751
IPW_DEBUG_INFO("exit\n");
4754
static int ipw2100_read_mac_address(struct ipw2100_priv *priv)
4756
u32 length = ETH_ALEN;
4761
err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC, addr, &length);
4763
IPW_DEBUG_INFO("MAC address read failed\n");
4767
memcpy(priv->net_dev->dev_addr, addr, ETH_ALEN);
4768
IPW_DEBUG_INFO("card MAC is %pM\n", priv->net_dev->dev_addr);
4773
/********************************************************************
4777
********************************************************************/
4779
static int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode)
4781
struct host_command cmd = {
4782
.host_command = ADAPTER_ADDRESS,
4783
.host_command_sequence = 0,
4784
.host_command_length = ETH_ALEN
4788
IPW_DEBUG_HC("SET_MAC_ADDRESS\n");
4790
IPW_DEBUG_INFO("enter\n");
4792
if (priv->config & CFG_CUSTOM_MAC) {
4793
memcpy(cmd.host_command_parameters, priv->mac_addr, ETH_ALEN);
4794
memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
4796
memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr,
4799
err = ipw2100_hw_send_command(priv, &cmd);
4801
IPW_DEBUG_INFO("exit\n");
4805
static int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type,
4808
struct host_command cmd = {
4809
.host_command = PORT_TYPE,
4810
.host_command_sequence = 0,
4811
.host_command_length = sizeof(u32)
4815
switch (port_type) {
4817
cmd.host_command_parameters[0] = IPW_BSS;
4820
cmd.host_command_parameters[0] = IPW_IBSS;
4824
IPW_DEBUG_HC("PORT_TYPE: %s\n",
4825
port_type == IPW_IBSS ? "Ad-Hoc" : "Managed");
4828
err = ipw2100_disable_adapter(priv);
4830
printk(KERN_ERR DRV_NAME
4831
": %s: Could not disable adapter %d\n",
4832
priv->net_dev->name, err);
4837
/* send cmd to firmware */
4838
err = ipw2100_hw_send_command(priv, &cmd);
4841
ipw2100_enable_adapter(priv);
4846
static int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel,
4849
struct host_command cmd = {
4850
.host_command = CHANNEL,
4851
.host_command_sequence = 0,
4852
.host_command_length = sizeof(u32)
4856
cmd.host_command_parameters[0] = channel;
4858
IPW_DEBUG_HC("CHANNEL: %d\n", channel);
4860
/* If BSS then we don't support channel selection */
4861
if (priv->ieee->iw_mode == IW_MODE_INFRA)
4864
if ((channel != 0) &&
4865
((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL)))
4869
err = ipw2100_disable_adapter(priv);
4874
err = ipw2100_hw_send_command(priv, &cmd);
4876
IPW_DEBUG_INFO("Failed to set channel to %d", channel);
4881
priv->config |= CFG_STATIC_CHANNEL;
4883
priv->config &= ~CFG_STATIC_CHANNEL;
4885
priv->channel = channel;
4888
err = ipw2100_enable_adapter(priv);
4896
static int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode)
4898
struct host_command cmd = {
4899
.host_command = SYSTEM_CONFIG,
4900
.host_command_sequence = 0,
4901
.host_command_length = 12,
4903
u32 ibss_mask, len = sizeof(u32);
4906
/* Set system configuration */
4909
err = ipw2100_disable_adapter(priv);
4914
if (priv->ieee->iw_mode == IW_MODE_ADHOC)
4915
cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START;
4917
cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK |
4918
IPW_CFG_BSS_MASK | IPW_CFG_802_1x_ENABLE;
4920
if (!(priv->config & CFG_LONG_PREAMBLE))
4921
cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO;
4923
err = ipw2100_get_ordinal(priv,
4924
IPW_ORD_EEPROM_IBSS_11B_CHANNELS,
4927
ibss_mask = IPW_IBSS_11B_DEFAULT_MASK;
4929
cmd.host_command_parameters[1] = REG_CHANNEL_MASK;
4930
cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask;
4933
/*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A; */
4935
err = ipw2100_hw_send_command(priv, &cmd);
4939
/* If IPv6 is configured in the kernel then we don't want to filter out all
4940
* of the multicast packets as IPv6 needs some. */
4941
#if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
4942
cmd.host_command = ADD_MULTICAST;
4943
cmd.host_command_sequence = 0;
4944
cmd.host_command_length = 0;
4946
ipw2100_hw_send_command(priv, &cmd);
4949
err = ipw2100_enable_adapter(priv);
4957
static int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate,
4960
struct host_command cmd = {
4961
.host_command = BASIC_TX_RATES,
4962
.host_command_sequence = 0,
4963
.host_command_length = 4
4967
cmd.host_command_parameters[0] = rate & TX_RATE_MASK;
4970
err = ipw2100_disable_adapter(priv);
4975
/* Set BASIC TX Rate first */
4976
ipw2100_hw_send_command(priv, &cmd);
4979
cmd.host_command = TX_RATES;
4980
ipw2100_hw_send_command(priv, &cmd);
4982
/* Set MSDU TX Rate */
4983
cmd.host_command = MSDU_TX_RATES;
4984
ipw2100_hw_send_command(priv, &cmd);
4987
err = ipw2100_enable_adapter(priv);
4992
priv->tx_rates = rate;
4997
static int ipw2100_set_power_mode(struct ipw2100_priv *priv, int power_level)
4999
struct host_command cmd = {
5000
.host_command = POWER_MODE,
5001
.host_command_sequence = 0,
5002
.host_command_length = 4
5006
cmd.host_command_parameters[0] = power_level;
5008
err = ipw2100_hw_send_command(priv, &cmd);
5012
if (power_level == IPW_POWER_MODE_CAM)
5013
priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
5015
priv->power_mode = IPW_POWER_ENABLED | power_level;
5017
#ifdef IPW2100_TX_POWER
5018
if (priv->port_type == IBSS && priv->adhoc_power != DFTL_IBSS_TX_POWER) {
5019
/* Set beacon interval */
5020
cmd.host_command = TX_POWER_INDEX;
5021
cmd.host_command_parameters[0] = (u32) priv->adhoc_power;
5023
err = ipw2100_hw_send_command(priv, &cmd);
5032
static int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold)
5034
struct host_command cmd = {
5035
.host_command = RTS_THRESHOLD,
5036
.host_command_sequence = 0,
5037
.host_command_length = 4
5041
if (threshold & RTS_DISABLED)
5042
cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD;
5044
cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED;
5046
err = ipw2100_hw_send_command(priv, &cmd);
5050
priv->rts_threshold = threshold;
5056
int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv,
5057
u32 threshold, int batch_mode)
5059
struct host_command cmd = {
5060
.host_command = FRAG_THRESHOLD,
5061
.host_command_sequence = 0,
5062
.host_command_length = 4,
5063
.host_command_parameters[0] = 0,
5068
err = ipw2100_disable_adapter(priv);
5074
threshold = DEFAULT_FRAG_THRESHOLD;
5076
threshold = max(threshold, MIN_FRAG_THRESHOLD);
5077
threshold = min(threshold, MAX_FRAG_THRESHOLD);
5080
cmd.host_command_parameters[0] = threshold;
5082
IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold);
5084
err = ipw2100_hw_send_command(priv, &cmd);
5087
ipw2100_enable_adapter(priv);
5090
priv->frag_threshold = threshold;
5096
static int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry)
5098
struct host_command cmd = {
5099
.host_command = SHORT_RETRY_LIMIT,
5100
.host_command_sequence = 0,
5101
.host_command_length = 4
5105
cmd.host_command_parameters[0] = retry;
5107
err = ipw2100_hw_send_command(priv, &cmd);
5111
priv->short_retry_limit = retry;
5116
static int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry)
5118
struct host_command cmd = {
5119
.host_command = LONG_RETRY_LIMIT,
5120
.host_command_sequence = 0,
5121
.host_command_length = 4
5125
cmd.host_command_parameters[0] = retry;
5127
err = ipw2100_hw_send_command(priv, &cmd);
5131
priv->long_retry_limit = retry;
5136
static int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 * bssid,
5139
struct host_command cmd = {
5140
.host_command = MANDATORY_BSSID,
5141
.host_command_sequence = 0,
5142
.host_command_length = (bssid == NULL) ? 0 : ETH_ALEN
5146
#ifdef CONFIG_IPW2100_DEBUG
5148
IPW_DEBUG_HC("MANDATORY_BSSID: %pM\n", bssid);
5150
IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
5152
/* if BSSID is empty then we disable mandatory bssid mode */
5154
memcpy(cmd.host_command_parameters, bssid, ETH_ALEN);
5157
err = ipw2100_disable_adapter(priv);
5162
err = ipw2100_hw_send_command(priv, &cmd);
5165
ipw2100_enable_adapter(priv);
5170
static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv)
5172
struct host_command cmd = {
5173
.host_command = DISASSOCIATION_BSSID,
5174
.host_command_sequence = 0,
5175
.host_command_length = ETH_ALEN
5180
IPW_DEBUG_HC("DISASSOCIATION_BSSID\n");
5183
/* The Firmware currently ignores the BSSID and just disassociates from
5184
* the currently associated AP -- but in the off chance that a future
5185
* firmware does use the BSSID provided here, we go ahead and try and
5186
* set it to the currently associated AP's BSSID */
5187
memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN);
5189
err = ipw2100_hw_send_command(priv, &cmd);
5194
static int ipw2100_set_wpa_ie(struct ipw2100_priv *,
5195
struct ipw2100_wpa_assoc_frame *, int)
5196
__attribute__ ((unused));
5198
static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv,
5199
struct ipw2100_wpa_assoc_frame *wpa_frame,
5202
struct host_command cmd = {
5203
.host_command = SET_WPA_IE,
5204
.host_command_sequence = 0,
5205
.host_command_length = sizeof(struct ipw2100_wpa_assoc_frame),
5209
IPW_DEBUG_HC("SET_WPA_IE\n");
5212
err = ipw2100_disable_adapter(priv);
5217
memcpy(cmd.host_command_parameters, wpa_frame,
5218
sizeof(struct ipw2100_wpa_assoc_frame));
5220
err = ipw2100_hw_send_command(priv, &cmd);
5223
if (ipw2100_enable_adapter(priv))
5230
struct security_info_params {
5231
u32 allowed_ciphers;
5234
u8 replay_counters_number;
5235
u8 unicast_using_group;
5236
} __attribute__ ((packed));
5238
static int ipw2100_set_security_information(struct ipw2100_priv *priv,
5241
int unicast_using_group,
5244
struct host_command cmd = {
5245
.host_command = SET_SECURITY_INFORMATION,
5246
.host_command_sequence = 0,
5247
.host_command_length = sizeof(struct security_info_params)
5249
struct security_info_params *security =
5250
(struct security_info_params *)&cmd.host_command_parameters;
5252
memset(security, 0, sizeof(*security));
5254
/* If shared key AP authentication is turned on, then we need to
5255
* configure the firmware to try and use it.
5257
* Actual data encryption/decryption is handled by the host. */
5258
security->auth_mode = auth_mode;
5259
security->unicast_using_group = unicast_using_group;
5261
switch (security_level) {
5264
security->allowed_ciphers = IPW_NONE_CIPHER;
5267
security->allowed_ciphers = IPW_WEP40_CIPHER |
5271
security->allowed_ciphers = IPW_WEP40_CIPHER |
5272
IPW_WEP104_CIPHER | IPW_TKIP_CIPHER;
5274
case SEC_LEVEL_2_CKIP:
5275
security->allowed_ciphers = IPW_WEP40_CIPHER |
5276
IPW_WEP104_CIPHER | IPW_CKIP_CIPHER;
5279
security->allowed_ciphers = IPW_WEP40_CIPHER |
5280
IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER;
5285
("SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n",
5286
security->auth_mode, security->allowed_ciphers, security_level);
5288
security->replay_counters_number = 0;
5291
err = ipw2100_disable_adapter(priv);
5296
err = ipw2100_hw_send_command(priv, &cmd);
5299
ipw2100_enable_adapter(priv);
5304
static int ipw2100_set_tx_power(struct ipw2100_priv *priv, u32 tx_power)
5306
struct host_command cmd = {
5307
.host_command = TX_POWER_INDEX,
5308
.host_command_sequence = 0,
5309
.host_command_length = 4
5314
if (tx_power != IPW_TX_POWER_DEFAULT)
5315
tmp = (tx_power - IPW_TX_POWER_MIN_DBM) * 16 /
5316
(IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM);
5318
cmd.host_command_parameters[0] = tmp;
5320
if (priv->ieee->iw_mode == IW_MODE_ADHOC)
5321
err = ipw2100_hw_send_command(priv, &cmd);
5323
priv->tx_power = tx_power;
5328
static int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv,
5329
u32 interval, int batch_mode)
5331
struct host_command cmd = {
5332
.host_command = BEACON_INTERVAL,
5333
.host_command_sequence = 0,
5334
.host_command_length = 4
5338
cmd.host_command_parameters[0] = interval;
5340
IPW_DEBUG_INFO("enter\n");
5342
if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5344
err = ipw2100_disable_adapter(priv);
5349
ipw2100_hw_send_command(priv, &cmd);
5352
err = ipw2100_enable_adapter(priv);
5358
IPW_DEBUG_INFO("exit\n");
5363
static void ipw2100_queues_initialize(struct ipw2100_priv *priv)
5365
ipw2100_tx_initialize(priv);
5366
ipw2100_rx_initialize(priv);
5367
ipw2100_msg_initialize(priv);
5370
static void ipw2100_queues_free(struct ipw2100_priv *priv)
5372
ipw2100_tx_free(priv);
5373
ipw2100_rx_free(priv);
5374
ipw2100_msg_free(priv);
5377
static int ipw2100_queues_allocate(struct ipw2100_priv *priv)
5379
if (ipw2100_tx_allocate(priv) ||
5380
ipw2100_rx_allocate(priv) || ipw2100_msg_allocate(priv))
5386
ipw2100_tx_free(priv);
5387
ipw2100_rx_free(priv);
5388
ipw2100_msg_free(priv);
5392
#define IPW_PRIVACY_CAPABLE 0x0008
5394
static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags,
5397
struct host_command cmd = {
5398
.host_command = WEP_FLAGS,
5399
.host_command_sequence = 0,
5400
.host_command_length = 4
5404
cmd.host_command_parameters[0] = flags;
5406
IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags);
5409
err = ipw2100_disable_adapter(priv);
5411
printk(KERN_ERR DRV_NAME
5412
": %s: Could not disable adapter %d\n",
5413
priv->net_dev->name, err);
5418
/* send cmd to firmware */
5419
err = ipw2100_hw_send_command(priv, &cmd);
5422
ipw2100_enable_adapter(priv);
5427
struct ipw2100_wep_key {
5433
/* Macros to ease up priting WEP keys */
5434
#define WEP_FMT_64 "%02X%02X%02X%02X-%02X"
5435
#define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
5436
#define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
5437
#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]
5442
* @priv: struct to work on
5443
* @idx: index of the key we want to set
5444
* @key: ptr to the key data to set
5445
* @len: length of the buffer at @key
5446
* @batch_mode: FIXME perform the operation in batch mode, not
5447
* disabling the device.
5449
* @returns 0 if OK, < 0 errno code on error.
5451
* Fill out a command structure with the new wep key, length an
5452
* index and send it down the wire.
5454
static int ipw2100_set_key(struct ipw2100_priv *priv,
5455
int idx, char *key, int len, int batch_mode)
5457
int keylen = len ? (len <= 5 ? 5 : 13) : 0;
5458
struct host_command cmd = {
5459
.host_command = WEP_KEY_INFO,
5460
.host_command_sequence = 0,
5461
.host_command_length = sizeof(struct ipw2100_wep_key),
5463
struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
5466
IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
5469
/* NOTE: We don't check cached values in case the firmware was reset
5470
* or some other problem is occurring. If the user is setting the key,
5471
* then we push the change */
5474
wep_key->len = keylen;
5477
memcpy(wep_key->key, key, len);
5478
memset(wep_key->key + len, 0, keylen - len);
5481
/* Will be optimized out on debug not being configured in */
5483
IPW_DEBUG_WEP("%s: Clearing key %d\n",
5484
priv->net_dev->name, wep_key->idx);
5485
else if (keylen == 5)
5486
IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n",
5487
priv->net_dev->name, wep_key->idx, wep_key->len,
5488
WEP_STR_64(wep_key->key));
5490
IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128
5492
priv->net_dev->name, wep_key->idx, wep_key->len,
5493
WEP_STR_128(wep_key->key));
5496
err = ipw2100_disable_adapter(priv);
5497
/* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */
5499
printk(KERN_ERR DRV_NAME
5500
": %s: Could not disable adapter %d\n",
5501
priv->net_dev->name, err);
5506
/* send cmd to firmware */
5507
err = ipw2100_hw_send_command(priv, &cmd);
5510
int err2 = ipw2100_enable_adapter(priv);
5517
static int ipw2100_set_key_index(struct ipw2100_priv *priv,
5518
int idx, int batch_mode)
5520
struct host_command cmd = {
5521
.host_command = WEP_KEY_INDEX,
5522
.host_command_sequence = 0,
5523
.host_command_length = 4,
5524
.host_command_parameters = {idx},
5528
IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx);
5530
if (idx < 0 || idx > 3)
5534
err = ipw2100_disable_adapter(priv);
5536
printk(KERN_ERR DRV_NAME
5537
": %s: Could not disable adapter %d\n",
5538
priv->net_dev->name, err);
5543
/* send cmd to firmware */
5544
err = ipw2100_hw_send_command(priv, &cmd);
5547
ipw2100_enable_adapter(priv);
5552
static int ipw2100_configure_security(struct ipw2100_priv *priv, int batch_mode)
5554
int i, err, auth_mode, sec_level, use_group;
5556
if (!(priv->status & STATUS_RUNNING))
5560
err = ipw2100_disable_adapter(priv);
5565
if (!priv->ieee->sec.enabled) {
5567
ipw2100_set_security_information(priv, IPW_AUTH_OPEN,
5570
auth_mode = IPW_AUTH_OPEN;
5571
if (priv->ieee->sec.flags & SEC_AUTH_MODE) {
5572
if (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)
5573
auth_mode = IPW_AUTH_SHARED;
5574
else if (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)
5575
auth_mode = IPW_AUTH_LEAP_CISCO_ID;
5578
sec_level = SEC_LEVEL_0;
5579
if (priv->ieee->sec.flags & SEC_LEVEL)
5580
sec_level = priv->ieee->sec.level;
5583
if (priv->ieee->sec.flags & SEC_UNICAST_GROUP)
5584
use_group = priv->ieee->sec.unicast_uses_group;
5587
ipw2100_set_security_information(priv, auth_mode, sec_level,
5594
if (priv->ieee->sec.enabled) {
5595
for (i = 0; i < 4; i++) {
5596
if (!(priv->ieee->sec.flags & (1 << i))) {
5597
memset(priv->ieee->sec.keys[i], 0, WEP_KEY_LEN);
5598
priv->ieee->sec.key_sizes[i] = 0;
5600
err = ipw2100_set_key(priv, i,
5601
priv->ieee->sec.keys[i],
5609
ipw2100_set_key_index(priv, priv->ieee->crypt_info.tx_keyidx, 1);
5612
/* Always enable privacy so the Host can filter WEP packets if
5613
* encrypted data is sent up */
5615
ipw2100_set_wep_flags(priv,
5617
enabled ? IPW_PRIVACY_CAPABLE : 0, 1);
5621
priv->status &= ~STATUS_SECURITY_UPDATED;
5625
ipw2100_enable_adapter(priv);
5630
static void ipw2100_security_work(struct work_struct *work)
5632
struct ipw2100_priv *priv =
5633
container_of(work, struct ipw2100_priv, security_work.work);
5635
/* If we happen to have reconnected before we get a chance to
5636
* process this, then update the security settings--which causes
5637
* a disassociation to occur */
5638
if (!(priv->status & STATUS_ASSOCIATED) &&
5639
priv->status & STATUS_SECURITY_UPDATED)
5640
ipw2100_configure_security(priv, 0);
5643
static void shim__set_security(struct net_device *dev,
5644
struct libipw_security *sec)
5646
struct ipw2100_priv *priv = libipw_priv(dev);
5647
int i, force_update = 0;
5649
mutex_lock(&priv->action_mutex);
5650
if (!(priv->status & STATUS_INITIALIZED))
5653
for (i = 0; i < 4; i++) {
5654
if (sec->flags & (1 << i)) {
5655
priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
5656
if (sec->key_sizes[i] == 0)
5657
priv->ieee->sec.flags &= ~(1 << i);
5659
memcpy(priv->ieee->sec.keys[i], sec->keys[i],
5661
if (sec->level == SEC_LEVEL_1) {
5662
priv->ieee->sec.flags |= (1 << i);
5663
priv->status |= STATUS_SECURITY_UPDATED;
5665
priv->ieee->sec.flags &= ~(1 << i);
5669
if ((sec->flags & SEC_ACTIVE_KEY) &&
5670
priv->ieee->sec.active_key != sec->active_key) {
5671
if (sec->active_key <= 3) {
5672
priv->ieee->sec.active_key = sec->active_key;
5673
priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
5675
priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
5677
priv->status |= STATUS_SECURITY_UPDATED;
5680
if ((sec->flags & SEC_AUTH_MODE) &&
5681
(priv->ieee->sec.auth_mode != sec->auth_mode)) {
5682
priv->ieee->sec.auth_mode = sec->auth_mode;
5683
priv->ieee->sec.flags |= SEC_AUTH_MODE;
5684
priv->status |= STATUS_SECURITY_UPDATED;
5687
if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
5688
priv->ieee->sec.flags |= SEC_ENABLED;
5689
priv->ieee->sec.enabled = sec->enabled;
5690
priv->status |= STATUS_SECURITY_UPDATED;
5694
if (sec->flags & SEC_ENCRYPT)
5695
priv->ieee->sec.encrypt = sec->encrypt;
5697
if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
5698
priv->ieee->sec.level = sec->level;
5699
priv->ieee->sec.flags |= SEC_LEVEL;
5700
priv->status |= STATUS_SECURITY_UPDATED;
5703
IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n",
5704
priv->ieee->sec.flags & (1 << 8) ? '1' : '0',
5705
priv->ieee->sec.flags & (1 << 7) ? '1' : '0',
5706
priv->ieee->sec.flags & (1 << 6) ? '1' : '0',
5707
priv->ieee->sec.flags & (1 << 5) ? '1' : '0',
5708
priv->ieee->sec.flags & (1 << 4) ? '1' : '0',
5709
priv->ieee->sec.flags & (1 << 3) ? '1' : '0',
5710
priv->ieee->sec.flags & (1 << 2) ? '1' : '0',
5711
priv->ieee->sec.flags & (1 << 1) ? '1' : '0',
5712
priv->ieee->sec.flags & (1 << 0) ? '1' : '0');
5714
/* As a temporary work around to enable WPA until we figure out why
5715
* wpa_supplicant toggles the security capability of the driver, which
5716
* forces a disassocation with force_update...
5718
* if (force_update || !(priv->status & STATUS_ASSOCIATED))*/
5719
if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
5720
ipw2100_configure_security(priv, 0);
5722
mutex_unlock(&priv->action_mutex);
5725
static int ipw2100_adapter_setup(struct ipw2100_priv *priv)
5731
IPW_DEBUG_INFO("enter\n");
5733
err = ipw2100_disable_adapter(priv);
5736
#ifdef CONFIG_IPW2100_MONITOR
5737
if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5738
err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5742
IPW_DEBUG_INFO("exit\n");
5746
#endif /* CONFIG_IPW2100_MONITOR */
5748
err = ipw2100_read_mac_address(priv);
5752
err = ipw2100_set_mac_address(priv, batch_mode);
5756
err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode);
5760
if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5761
err = ipw2100_set_channel(priv, priv->channel, batch_mode);
5766
err = ipw2100_system_config(priv, batch_mode);
5770
err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode);
5774
/* Default to power mode OFF */
5775
err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
5779
err = ipw2100_set_rts_threshold(priv, priv->rts_threshold);
5783
if (priv->config & CFG_STATIC_BSSID)
5784
bssid = priv->bssid;
5787
err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode);
5791
if (priv->config & CFG_STATIC_ESSID)
5792
err = ipw2100_set_essid(priv, priv->essid, priv->essid_len,
5795
err = ipw2100_set_essid(priv, NULL, 0, batch_mode);
5799
err = ipw2100_configure_security(priv, batch_mode);
5803
if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5805
ipw2100_set_ibss_beacon_interval(priv,
5806
priv->beacon_interval,
5811
err = ipw2100_set_tx_power(priv, priv->tx_power);
5817
err = ipw2100_set_fragmentation_threshold(
5818
priv, priv->frag_threshold, batch_mode);
5823
IPW_DEBUG_INFO("exit\n");
5828
/*************************************************************************
5830
* EXTERNALLY CALLED METHODS
5832
*************************************************************************/
5834
/* This method is called by the network layer -- not to be confused with
5835
* ipw2100_set_mac_address() declared above called by this driver (and this
5836
* method as well) to talk to the firmware */
5837
static int ipw2100_set_address(struct net_device *dev, void *p)
5839
struct ipw2100_priv *priv = libipw_priv(dev);
5840
struct sockaddr *addr = p;
5843
if (!is_valid_ether_addr(addr->sa_data))
5844
return -EADDRNOTAVAIL;
5846
mutex_lock(&priv->action_mutex);
5848
priv->config |= CFG_CUSTOM_MAC;
5849
memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
5851
err = ipw2100_set_mac_address(priv, 0);
5855
priv->reset_backoff = 0;
5856
mutex_unlock(&priv->action_mutex);
5857
ipw2100_reset_adapter(&priv->reset_work.work);
5861
mutex_unlock(&priv->action_mutex);
5865
static int ipw2100_open(struct net_device *dev)
5867
struct ipw2100_priv *priv = libipw_priv(dev);
5868
unsigned long flags;
5869
IPW_DEBUG_INFO("dev->open\n");
5871
spin_lock_irqsave(&priv->low_lock, flags);
5872
if (priv->status & STATUS_ASSOCIATED) {
5873
netif_carrier_on(dev);
5874
netif_start_queue(dev);
5876
spin_unlock_irqrestore(&priv->low_lock, flags);
5881
static int ipw2100_close(struct net_device *dev)
5883
struct ipw2100_priv *priv = libipw_priv(dev);
5884
unsigned long flags;
5885
struct list_head *element;
5886
struct ipw2100_tx_packet *packet;
5888
IPW_DEBUG_INFO("enter\n");
5890
spin_lock_irqsave(&priv->low_lock, flags);
5892
if (priv->status & STATUS_ASSOCIATED)
5893
netif_carrier_off(dev);
5894
netif_stop_queue(dev);
5896
/* Flush the TX queue ... */
5897
while (!list_empty(&priv->tx_pend_list)) {
5898
element = priv->tx_pend_list.next;
5899
packet = list_entry(element, struct ipw2100_tx_packet, list);
5902
DEC_STAT(&priv->tx_pend_stat);
5904
libipw_txb_free(packet->info.d_struct.txb);
5905
packet->info.d_struct.txb = NULL;
5907
list_add_tail(element, &priv->tx_free_list);
5908
INC_STAT(&priv->tx_free_stat);
5910
spin_unlock_irqrestore(&priv->low_lock, flags);
5912
IPW_DEBUG_INFO("exit\n");
5918
* TODO: Fix this function... its just wrong
5920
static void ipw2100_tx_timeout(struct net_device *dev)
5922
struct ipw2100_priv *priv = libipw_priv(dev);
5924
dev->stats.tx_errors++;
5926
#ifdef CONFIG_IPW2100_MONITOR
5927
if (priv->ieee->iw_mode == IW_MODE_MONITOR)
5931
IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n",
5933
schedule_reset(priv);
5936
static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value)
5938
/* This is called when wpa_supplicant loads and closes the driver
5940
priv->ieee->wpa_enabled = value;
5944
static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value)
5947
struct libipw_device *ieee = priv->ieee;
5948
struct libipw_security sec = {
5949
.flags = SEC_AUTH_MODE,
5953
if (value & IW_AUTH_ALG_SHARED_KEY) {
5954
sec.auth_mode = WLAN_AUTH_SHARED_KEY;
5956
} else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
5957
sec.auth_mode = WLAN_AUTH_OPEN;
5959
} else if (value & IW_AUTH_ALG_LEAP) {
5960
sec.auth_mode = WLAN_AUTH_LEAP;
5965
if (ieee->set_security)
5966
ieee->set_security(ieee->dev, &sec);
5973
static void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv,
5974
char *wpa_ie, int wpa_ie_len)
5977
struct ipw2100_wpa_assoc_frame frame;
5979
frame.fixed_ie_mask = 0;
5982
memcpy(frame.var_ie, wpa_ie, wpa_ie_len);
5983
frame.var_ie_len = wpa_ie_len;
5985
/* make sure WPA is enabled */
5986
ipw2100_wpa_enable(priv, 1);
5987
ipw2100_set_wpa_ie(priv, &frame, 0);
5990
static void ipw_ethtool_get_drvinfo(struct net_device *dev,
5991
struct ethtool_drvinfo *info)
5993
struct ipw2100_priv *priv = libipw_priv(dev);
5994
char fw_ver[64], ucode_ver[64];
5996
strcpy(info->driver, DRV_NAME);
5997
strcpy(info->version, DRV_VERSION);
5999
ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver));
6000
ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver));
6002
snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
6003
fw_ver, priv->eeprom_version, ucode_ver);
6005
strcpy(info->bus_info, pci_name(priv->pci_dev));
6008
static u32 ipw2100_ethtool_get_link(struct net_device *dev)
6010
struct ipw2100_priv *priv = libipw_priv(dev);
6011
return (priv->status & STATUS_ASSOCIATED) ? 1 : 0;
6014
static const struct ethtool_ops ipw2100_ethtool_ops = {
6015
.get_link = ipw2100_ethtool_get_link,
6016
.get_drvinfo = ipw_ethtool_get_drvinfo,
6019
static void ipw2100_hang_check(struct work_struct *work)
6021
struct ipw2100_priv *priv =
6022
container_of(work, struct ipw2100_priv, hang_check.work);
6023
unsigned long flags;
6024
u32 rtc = 0xa5a5a5a5;
6025
u32 len = sizeof(rtc);
6028
spin_lock_irqsave(&priv->low_lock, flags);
6030
if (priv->fatal_error != 0) {
6031
/* If fatal_error is set then we need to restart */
6032
IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n",
6033
priv->net_dev->name);
6036
} else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) ||
6037
(rtc == priv->last_rtc)) {
6038
/* Check if firmware is hung */
6039
IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n",
6040
priv->net_dev->name);
6047
priv->stop_hang_check = 1;
6050
/* Restart the NIC */
6051
schedule_reset(priv);
6054
priv->last_rtc = rtc;
6056
if (!priv->stop_hang_check)
6057
queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
6059
spin_unlock_irqrestore(&priv->low_lock, flags);
6062
static void ipw2100_rf_kill(struct work_struct *work)
6064
struct ipw2100_priv *priv =
6065
container_of(work, struct ipw2100_priv, rf_kill.work);
6066
unsigned long flags;
6068
spin_lock_irqsave(&priv->low_lock, flags);
6070
if (rf_kill_active(priv)) {
6071
IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
6072
if (!priv->stop_rf_kill)
6073
queue_delayed_work(priv->workqueue, &priv->rf_kill,
6074
round_jiffies_relative(HZ));
6078
/* RF Kill is now disabled, so bring the device back up */
6080
if (!(priv->status & STATUS_RF_KILL_MASK)) {
6081
IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
6083
schedule_reset(priv);
6085
IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
6089
spin_unlock_irqrestore(&priv->low_lock, flags);
6092
static void ipw2100_irq_tasklet(struct ipw2100_priv *priv);
6094
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
6095
static const struct net_device_ops ipw2100_netdev_ops = {
6096
.ndo_open = ipw2100_open,
6097
.ndo_stop = ipw2100_close,
6098
.ndo_start_xmit = libipw_xmit,
6099
.ndo_change_mtu = libipw_change_mtu,
6100
.ndo_init = ipw2100_net_init,
6101
.ndo_tx_timeout = ipw2100_tx_timeout,
6102
.ndo_set_mac_address = ipw2100_set_address,
6103
.ndo_validate_addr = eth_validate_addr,
6107
/* Look into using netdev destructor to shutdown ieee80211? */
6109
static struct net_device *ipw2100_alloc_device(struct pci_dev *pci_dev,
6110
void __iomem * base_addr,
6111
unsigned long mem_start,
6112
unsigned long mem_len)
6114
struct ipw2100_priv *priv;
6115
struct net_device *dev;
6117
dev = alloc_ieee80211(sizeof(struct ipw2100_priv), 0);
6120
priv = libipw_priv(dev);
6121
priv->ieee = netdev_priv(dev);
6122
priv->pci_dev = pci_dev;
6123
priv->net_dev = dev;
6125
priv->ieee->hard_start_xmit = ipw2100_tx;
6126
priv->ieee->set_security = shim__set_security;
6128
priv->ieee->perfect_rssi = -20;
6129
priv->ieee->worst_rssi = -85;
6131
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
6132
dev->netdev_ops = &ipw2100_netdev_ops;
6134
dev->open = ipw2100_open;
6135
dev->stop = ipw2100_close;
6136
dev->init = ipw2100_net_init;
6137
dev->tx_timeout = ipw2100_tx_timeout;
6138
dev->set_mac_address = ipw2100_set_address;
6141
dev->ethtool_ops = &ipw2100_ethtool_ops;
6142
dev->wireless_handlers = &ipw2100_wx_handler_def;
6143
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31))
6144
priv->wireless_data.libipw = priv->ieee;
6146
priv->wireless_data.ieee80211 = (struct ieee80211_device *) priv->ieee;
6148
dev->wireless_data = &priv->wireless_data;
6149
dev->watchdog_timeo = 3 * HZ;
6152
dev->base_addr = (unsigned long)base_addr;
6153
dev->mem_start = mem_start;
6154
dev->mem_end = dev->mem_start + mem_len - 1;
6156
/* NOTE: We don't use the wireless_handlers hook
6157
* in dev as the system will start throwing WX requests
6158
* to us before we're actually initialized and it just
6159
* ends up causing problems. So, we just handle
6160
* the WX extensions through the ipw2100_ioctl interface */
6162
/* memset() puts everything to 0, so we only have explicitly set
6163
* those values that need to be something else */
6165
/* If power management is turned on, default to AUTO mode */
6166
priv->power_mode = IPW_POWER_AUTO;
6168
#ifdef CONFIG_IPW2100_MONITOR
6169
priv->config |= CFG_CRC_CHECK;
6171
priv->ieee->wpa_enabled = 0;
6172
priv->ieee->drop_unencrypted = 0;
6173
priv->ieee->privacy_invoked = 0;
6174
priv->ieee->ieee802_1x = 1;
6176
/* Set module parameters */
6177
switch (network_mode) {
6179
priv->ieee->iw_mode = IW_MODE_ADHOC;
6181
#ifdef CONFIG_IPW2100_MONITOR
6183
priv->ieee->iw_mode = IW_MODE_MONITOR;
6188
priv->ieee->iw_mode = IW_MODE_INFRA;
6193
priv->status |= STATUS_RF_KILL_SW;
6196
((channel >= REG_MIN_CHANNEL) && (channel <= REG_MAX_CHANNEL))) {
6197
priv->config |= CFG_STATIC_CHANNEL;
6198
priv->channel = channel;
6202
priv->config |= CFG_ASSOCIATE;
6204
priv->beacon_interval = DEFAULT_BEACON_INTERVAL;
6205
priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
6206
priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
6207
priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED;
6208
priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED;
6209
priv->tx_power = IPW_TX_POWER_DEFAULT;
6210
priv->tx_rates = DEFAULT_TX_RATES;
6212
strcpy(priv->nick, "ipw2100");
6214
spin_lock_init(&priv->low_lock);
6215
mutex_init(&priv->action_mutex);
6216
mutex_init(&priv->adapter_mutex);
6218
init_waitqueue_head(&priv->wait_command_queue);
6220
netif_carrier_off(dev);
6222
INIT_LIST_HEAD(&priv->msg_free_list);
6223
INIT_LIST_HEAD(&priv->msg_pend_list);
6224
INIT_STAT(&priv->msg_free_stat);
6225
INIT_STAT(&priv->msg_pend_stat);
6227
INIT_LIST_HEAD(&priv->tx_free_list);
6228
INIT_LIST_HEAD(&priv->tx_pend_list);
6229
INIT_STAT(&priv->tx_free_stat);
6230
INIT_STAT(&priv->tx_pend_stat);
6232
INIT_LIST_HEAD(&priv->fw_pend_list);
6233
INIT_STAT(&priv->fw_pend_stat);
6235
priv->workqueue = create_workqueue(DRV_NAME);
6237
INIT_DELAYED_WORK(&priv->reset_work, ipw2100_reset_adapter);
6238
INIT_DELAYED_WORK(&priv->security_work, ipw2100_security_work);
6239
INIT_DELAYED_WORK(&priv->wx_event_work, ipw2100_wx_event_work);
6240
INIT_DELAYED_WORK(&priv->hang_check, ipw2100_hang_check);
6241
INIT_DELAYED_WORK(&priv->rf_kill, ipw2100_rf_kill);
6242
INIT_WORK(&priv->scan_event_now, ipw2100_scan_event_now);
6243
INIT_DELAYED_WORK(&priv->scan_event_later, ipw2100_scan_event_later);
6245
tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
6246
ipw2100_irq_tasklet, (unsigned long)priv);
6248
/* NOTE: We do not start the deferred work for status checks yet */
6249
priv->stop_rf_kill = 1;
6250
priv->stop_hang_check = 1;
6255
static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
6256
const struct pci_device_id *ent)
6258
unsigned long mem_start, mem_len, mem_flags;
6259
void __iomem *base_addr = NULL;
6260
struct net_device *dev = NULL;
6261
struct ipw2100_priv *priv = NULL;
6266
IPW_DEBUG_INFO("enter\n");
6268
mem_start = pci_resource_start(pci_dev, 0);
6269
mem_len = pci_resource_len(pci_dev, 0);
6270
mem_flags = pci_resource_flags(pci_dev, 0);
6272
if ((mem_flags & IORESOURCE_MEM) != IORESOURCE_MEM) {
6273
IPW_DEBUG_INFO("weird - resource type is not memory\n");
6278
base_addr = ioremap_nocache(mem_start, mem_len);
6280
printk(KERN_WARNING DRV_NAME
6281
"Error calling ioremap_nocache.\n");
6286
/* allocate and initialize our net_device */
6287
dev = ipw2100_alloc_device(pci_dev, base_addr, mem_start, mem_len);
6289
printk(KERN_WARNING DRV_NAME
6290
"Error calling ipw2100_alloc_device.\n");
6295
/* set up PCI mappings for device */
6296
err = pci_enable_device(pci_dev);
6298
printk(KERN_WARNING DRV_NAME
6299
"Error calling pci_enable_device.\n");
6303
priv = libipw_priv(dev);
6305
pci_set_master(pci_dev);
6306
pci_set_drvdata(pci_dev, priv);
6308
err = pci_set_dma_mask(pci_dev, DMA_BIT_MASK(32));
6310
printk(KERN_WARNING DRV_NAME
6311
"Error calling pci_set_dma_mask.\n");
6312
pci_disable_device(pci_dev);
6316
err = pci_request_regions(pci_dev, DRV_NAME);
6318
printk(KERN_WARNING DRV_NAME
6319
"Error calling pci_request_regions.\n");
6320
pci_disable_device(pci_dev);
6324
/* We disable the RETRY_TIMEOUT register (0x41) to keep
6325
* PCI Tx retries from interfering with C3 CPU state */
6326
pci_read_config_dword(pci_dev, 0x40, &val);
6327
if ((val & 0x0000ff00) != 0)
6328
pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6330
pci_set_power_state(pci_dev, PCI_D0);
6332
if (!ipw2100_hw_is_adapter_in_system(dev)) {
6333
printk(KERN_WARNING DRV_NAME
6334
"Device not found via register read.\n");
6339
SET_NETDEV_DEV(dev, &pci_dev->dev);
6341
/* Force interrupts to be shut off on the device */
6342
priv->status |= STATUS_INT_ENABLED;
6343
ipw2100_disable_interrupts(priv);
6345
/* Allocate and initialize the Tx/Rx queues and lists */
6346
if (ipw2100_queues_allocate(priv)) {
6347
printk(KERN_WARNING DRV_NAME
6348
"Error calling ipw2100_queues_allocate.\n");
6352
ipw2100_queues_initialize(priv);
6354
err = request_irq(pci_dev->irq,
6355
ipw2100_interrupt, IRQF_SHARED, dev->name, priv);
6357
printk(KERN_WARNING DRV_NAME
6358
"Error calling request_irq: %d.\n", pci_dev->irq);
6361
dev->irq = pci_dev->irq;
6363
IPW_DEBUG_INFO("Attempting to register device...\n");
6365
printk(KERN_INFO DRV_NAME
6366
": Detected Intel PRO/Wireless 2100 Network Connection\n");
6368
/* Bring up the interface. Pre 0.46, after we registered the
6369
* network device we would call ipw2100_up. This introduced a race
6370
* condition with newer hotplug configurations (network was coming
6371
* up and making calls before the device was initialized).
6373
* If we called ipw2100_up before we registered the device, then the
6374
* device name wasn't registered. So, we instead use the net_dev->init
6375
* member to call a function that then just turns and calls ipw2100_up.
6376
* net_dev->init is called after name allocation but before the
6377
* notifier chain is called */
6378
err = register_netdev(dev);
6380
printk(KERN_WARNING DRV_NAME
6381
"Error calling register_netdev.\n");
6385
mutex_lock(&priv->action_mutex);
6388
IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev));
6390
/* perform this after register_netdev so that dev->name is set */
6391
err = sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
6395
/* If the RF Kill switch is disabled, go ahead and complete the
6396
* startup sequence */
6397
if (!(priv->status & STATUS_RF_KILL_MASK)) {
6398
/* Enable the adapter - sends HOST_COMPLETE */
6399
if (ipw2100_enable_adapter(priv)) {
6400
printk(KERN_WARNING DRV_NAME
6401
": %s: failed in call to enable adapter.\n",
6402
priv->net_dev->name);
6403
ipw2100_hw_stop_adapter(priv);
6408
/* Start a scan . . . */
6409
ipw2100_set_scan_options(priv);
6410
ipw2100_start_scan(priv);
6413
IPW_DEBUG_INFO("exit\n");
6415
priv->status |= STATUS_INITIALIZED;
6417
mutex_unlock(&priv->action_mutex);
6422
mutex_unlock(&priv->action_mutex);
6427
unregister_netdev(dev);
6429
ipw2100_hw_stop_adapter(priv);
6431
ipw2100_disable_interrupts(priv);
6434
free_irq(dev->irq, priv);
6436
ipw2100_kill_workqueue(priv);
6438
/* These are safe to call even if they weren't allocated */
6439
ipw2100_queues_free(priv);
6440
sysfs_remove_group(&pci_dev->dev.kobj,
6441
&ipw2100_attribute_group);
6443
free_ieee80211(dev, 0);
6444
pci_set_drvdata(pci_dev, NULL);
6450
pci_release_regions(pci_dev);
6451
pci_disable_device(pci_dev);
6456
static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev)
6458
struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6459
struct net_device *dev;
6462
mutex_lock(&priv->action_mutex);
6464
priv->status &= ~STATUS_INITIALIZED;
6466
dev = priv->net_dev;
6467
sysfs_remove_group(&pci_dev->dev.kobj,
6468
&ipw2100_attribute_group);
6471
if (ipw2100_firmware.version)
6472
ipw2100_release_firmware(priv, &ipw2100_firmware);
6474
/* Take down the hardware */
6477
/* Release the mutex so that the network subsystem can
6478
* complete any needed calls into the driver... */
6479
mutex_unlock(&priv->action_mutex);
6481
/* Unregister the device first - this results in close()
6482
* being called if the device is open. If we free storage
6483
* first, then close() will crash. */
6484
unregister_netdev(dev);
6486
/* ipw2100_down will ensure that there is no more pending work
6487
* in the workqueue's, so we can safely remove them now. */
6488
ipw2100_kill_workqueue(priv);
6490
ipw2100_queues_free(priv);
6492
/* Free potential debugging firmware snapshot */
6493
ipw2100_snapshot_free(priv);
6496
free_irq(dev->irq, priv);
6499
iounmap((void __iomem *)dev->base_addr);
6501
/* wiphy_unregister needs to be here, before free_ieee80211 */
6502
wiphy_unregister(priv->ieee->wdev.wiphy);
6503
kfree(priv->ieee->bg_band.channels);
6504
free_ieee80211(dev, 0);
6507
pci_release_regions(pci_dev);
6508
pci_disable_device(pci_dev);
6510
IPW_DEBUG_INFO("exit\n");
6514
static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
6516
struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6517
struct net_device *dev = priv->net_dev;
6519
IPW_DEBUG_INFO("%s: Going into suspend...\n", dev->name);
6521
mutex_lock(&priv->action_mutex);
6522
if (priv->status & STATUS_INITIALIZED) {
6523
/* Take down the device; powers it off, etc. */
6527
/* Remove the PRESENT state of the device */
6528
netif_device_detach(dev);
6530
pci_save_state(pci_dev);
6531
pci_disable_device(pci_dev);
6532
pci_set_power_state(pci_dev, PCI_D3hot);
6534
priv->suspend_at = get_seconds();
6536
mutex_unlock(&priv->action_mutex);
6541
static int ipw2100_resume(struct pci_dev *pci_dev)
6543
struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6544
struct net_device *dev = priv->net_dev;
6548
if (IPW2100_PM_DISABLED)
6551
mutex_lock(&priv->action_mutex);
6553
IPW_DEBUG_INFO("%s: Coming out of suspend...\n", dev->name);
6555
pci_set_power_state(pci_dev, PCI_D0);
6556
err = pci_enable_device(pci_dev);
6558
printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
6560
mutex_unlock(&priv->action_mutex);
6563
pci_restore_state(pci_dev);
6566
* Suspend/Resume resets the PCI configuration space, so we have to
6567
* re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
6568
* from interfering with C3 CPU state. pci_restore_state won't help
6569
* here since it only restores the first 64 bytes pci config header.
6571
pci_read_config_dword(pci_dev, 0x40, &val);
6572
if ((val & 0x0000ff00) != 0)
6573
pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
6575
/* Set the device back into the PRESENT state; this will also wake
6576
* the queue of needed */
6577
netif_device_attach(dev);
6579
priv->suspend_time = get_seconds() - priv->suspend_at;
6581
/* Bring the device back up */
6582
if (!(priv->status & STATUS_RF_KILL_SW))
6583
ipw2100_up(priv, 0);
6585
mutex_unlock(&priv->action_mutex);
6591
static void ipw2100_shutdown(struct pci_dev *pci_dev)
6593
struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
6595
/* Take down the device; powers it off, etc. */
6598
pci_disable_device(pci_dev);
6601
#define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
6603
static struct pci_device_id ipw2100_pci_id_table[] __devinitdata = {
6604
IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
6605
IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
6606
IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
6607
IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
6608
IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
6609
IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
6610
IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
6611
IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
6612
IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
6613
IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
6614
IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
6615
IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
6616
IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
6618
IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
6619
IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
6620
IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
6621
IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
6622
IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
6624
IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
6625
IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
6626
IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
6627
IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
6628
IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
6629
IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
6630
IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
6632
IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
6634
IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
6635
IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
6636
IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
6637
IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
6638
IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
6639
IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
6640
IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
6642
IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
6643
IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
6644
IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
6645
IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
6646
IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
6647
IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
6649
IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
6653
MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);
6655
static struct pci_driver ipw2100_pci_driver = {
6657
.id_table = ipw2100_pci_id_table,
6658
.probe = ipw2100_pci_init_one,
6659
.remove = __devexit_p(ipw2100_pci_remove_one),
6661
.suspend = ipw2100_suspend,
6662
.resume = ipw2100_resume,
6664
.shutdown = ipw2100_shutdown,
6668
* Initialize the ipw2100 driver/module
6670
* @returns 0 if ok, < 0 errno node con error.
6672
* Note: we cannot init the /proc stuff until the PCI driver is there,
6673
* or we risk an unlikely race condition on someone accessing
6674
* uninitialized data in the PCI dev struct through /proc.
6676
static int __init ipw2100_init(void)
6680
printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
6681
printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
6683
ret = pci_register_driver(&ipw2100_pci_driver);
6687
pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100",
6688
PM_QOS_DEFAULT_VALUE);
6689
#ifdef CONFIG_IPW2100_DEBUG
6690
ipw2100_debug_level = debug;
6691
ret = driver_create_file(&ipw2100_pci_driver.driver,
6692
&driver_attr_debug_level);
6700
* Cleanup ipw2100 driver registration
6702
static void __exit ipw2100_exit(void)
6704
/* FIXME: IPG: check that we have no instances of the devices open */
6705
#ifdef CONFIG_IPW2100_DEBUG
6706
driver_remove_file(&ipw2100_pci_driver.driver,
6707
&driver_attr_debug_level);
6709
pci_unregister_driver(&ipw2100_pci_driver);
6710
pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100");
6713
module_init(ipw2100_init);
6714
module_exit(ipw2100_exit);
6716
static int ipw2100_wx_get_name(struct net_device *dev,
6717
struct iw_request_info *info,
6718
union iwreq_data *wrqu, char *extra)
6721
* This can be called at any time. No action lock required
6724
struct ipw2100_priv *priv = libipw_priv(dev);
6725
if (!(priv->status & STATUS_ASSOCIATED))
6726
strcpy(wrqu->name, "unassociated");
6728
snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
6730
IPW_DEBUG_WX("Name: %s\n", wrqu->name);
6734
static int ipw2100_wx_set_freq(struct net_device *dev,
6735
struct iw_request_info *info,
6736
union iwreq_data *wrqu, char *extra)
6738
struct ipw2100_priv *priv = libipw_priv(dev);
6739
struct iw_freq *fwrq = &wrqu->freq;
6742
if (priv->ieee->iw_mode == IW_MODE_INFRA)
6745
mutex_lock(&priv->action_mutex);
6746
if (!(priv->status & STATUS_INITIALIZED)) {
6751
/* if setting by freq convert to channel */
6753
if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) {
6754
int f = fwrq->m / 100000;
6757
while ((c < REG_MAX_CHANNEL) &&
6758
(f != ipw2100_frequencies[c]))
6761
/* hack to fall through */
6767
if (fwrq->e > 0 || fwrq->m > 1000) {
6770
} else { /* Set the channel */
6771
IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
6772
err = ipw2100_set_channel(priv, fwrq->m, 0);
6776
mutex_unlock(&priv->action_mutex);
6780
static int ipw2100_wx_get_freq(struct net_device *dev,
6781
struct iw_request_info *info,
6782
union iwreq_data *wrqu, char *extra)
6785
* This can be called at any time. No action lock required
6788
struct ipw2100_priv *priv = libipw_priv(dev);
6792
/* If we are associated, trying to associate, or have a statically
6793
* configured CHANNEL then return that; otherwise return ANY */
6794
if (priv->config & CFG_STATIC_CHANNEL ||
6795
priv->status & STATUS_ASSOCIATED)
6796
wrqu->freq.m = priv->channel;
6800
IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
6805
static int ipw2100_wx_set_mode(struct net_device *dev,
6806
struct iw_request_info *info,
6807
union iwreq_data *wrqu, char *extra)
6809
struct ipw2100_priv *priv = libipw_priv(dev);
6812
IPW_DEBUG_WX("SET Mode -> %d \n", wrqu->mode);
6814
if (wrqu->mode == priv->ieee->iw_mode)
6817
mutex_lock(&priv->action_mutex);
6818
if (!(priv->status & STATUS_INITIALIZED)) {
6823
switch (wrqu->mode) {
6824
#ifdef CONFIG_IPW2100_MONITOR
6825
case IW_MODE_MONITOR:
6826
err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
6828
#endif /* CONFIG_IPW2100_MONITOR */
6830
err = ipw2100_switch_mode(priv, IW_MODE_ADHOC);
6835
err = ipw2100_switch_mode(priv, IW_MODE_INFRA);
6840
mutex_unlock(&priv->action_mutex);
6844
static int ipw2100_wx_get_mode(struct net_device *dev,
6845
struct iw_request_info *info,
6846
union iwreq_data *wrqu, char *extra)
6849
* This can be called at any time. No action lock required
6852
struct ipw2100_priv *priv = libipw_priv(dev);
6854
wrqu->mode = priv->ieee->iw_mode;
6855
IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode);
6860
#define POWER_MODES 5
6862
/* Values are in microsecond */
6863
static const s32 timeout_duration[POWER_MODES] = {
6871
static const s32 period_duration[POWER_MODES] = {
6879
static int ipw2100_wx_get_range(struct net_device *dev,
6880
struct iw_request_info *info,
6881
union iwreq_data *wrqu, char *extra)
6884
* This can be called at any time. No action lock required
6887
struct ipw2100_priv *priv = libipw_priv(dev);
6888
struct iw_range *range = (struct iw_range *)extra;
6892
wrqu->data.length = sizeof(*range);
6893
memset(range, 0, sizeof(*range));
6895
/* Let's try to keep this struct in the same order as in
6896
* linux/include/wireless.h
6899
/* TODO: See what values we can set, and remove the ones we can't
6900
* set, or fill them with some default data.
6903
/* ~5 Mb/s real (802.11b) */
6904
range->throughput = 5 * 1000 * 1000;
6906
// range->sensitivity; /* signal level threshold range */
6908
range->max_qual.qual = 100;
6909
/* TODO: Find real max RSSI and stick here */
6910
range->max_qual.level = 0;
6911
range->max_qual.noise = 0;
6912
range->max_qual.updated = 7; /* Updated all three */
6914
range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
6915
/* TODO: Find real 'good' to 'bad' threshold value for RSSI */
6916
range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM;
6917
range->avg_qual.noise = 0;
6918
range->avg_qual.updated = 7; /* Updated all three */
6920
range->num_bitrates = RATE_COUNT;
6922
for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
6923
range->bitrate[i] = ipw2100_rates_11b[i];
6926
range->min_rts = MIN_RTS_THRESHOLD;
6927
range->max_rts = MAX_RTS_THRESHOLD;
6928
range->min_frag = MIN_FRAG_THRESHOLD;
6929
range->max_frag = MAX_FRAG_THRESHOLD;
6931
range->min_pmp = period_duration[0]; /* Minimal PM period */
6932
range->max_pmp = period_duration[POWER_MODES - 1]; /* Maximal PM period */
6933
range->min_pmt = timeout_duration[POWER_MODES - 1]; /* Minimal PM timeout */
6934
range->max_pmt = timeout_duration[0]; /* Maximal PM timeout */
6936
/* How to decode max/min PM period */
6937
range->pmp_flags = IW_POWER_PERIOD;
6938
/* How to decode max/min PM period */
6939
range->pmt_flags = IW_POWER_TIMEOUT;
6940
/* What PM options are supported */
6941
range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD;
6943
range->encoding_size[0] = 5;
6944
range->encoding_size[1] = 13; /* Different token sizes */
6945
range->num_encoding_sizes = 2; /* Number of entry in the list */
6946
range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */
6947
// range->encoding_login_index; /* token index for login token */
6949
if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6950
range->txpower_capa = IW_TXPOW_DBM;
6951
range->num_txpower = IW_MAX_TXPOWER;
6952
for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16);
6955
((IPW_TX_POWER_MAX_DBM -
6956
IPW_TX_POWER_MIN_DBM) * 16) / (IW_MAX_TXPOWER - 1))
6957
range->txpower[i] = level / 16;
6959
range->txpower_capa = 0;
6960
range->num_txpower = 0;
6963
/* Set the Wireless Extension versions */
6964
range->we_version_compiled = WIRELESS_EXT;
6965
range->we_version_source = 18;
6967
// range->retry_capa; /* What retry options are supported */
6968
// range->retry_flags; /* How to decode max/min retry limit */
6969
// range->r_time_flags; /* How to decode max/min retry life */
6970
// range->min_retry; /* Minimal number of retries */
6971
// range->max_retry; /* Maximal number of retries */
6972
// range->min_r_time; /* Minimal retry lifetime */
6973
// range->max_r_time; /* Maximal retry lifetime */
6975
range->num_channels = FREQ_COUNT;
6978
for (i = 0; i < FREQ_COUNT; i++) {
6979
// TODO: Include only legal frequencies for some countries
6980
// if (local->channel_mask & (1 << i)) {
6981
range->freq[val].i = i + 1;
6982
range->freq[val].m = ipw2100_frequencies[i] * 100000;
6983
range->freq[val].e = 1;
6986
if (val == IW_MAX_FREQUENCIES)
6989
range->num_frequency = val;
6991
/* Event capability (kernel + driver) */
6992
range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
6993
IW_EVENT_CAPA_MASK(SIOCGIWAP));
6994
range->event_capa[1] = IW_EVENT_CAPA_K_1;
6996
range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
6997
IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
6999
IPW_DEBUG_WX("GET Range\n");
7004
static int ipw2100_wx_set_wap(struct net_device *dev,
7005
struct iw_request_info *info,
7006
union iwreq_data *wrqu, char *extra)
7008
struct ipw2100_priv *priv = libipw_priv(dev);
7011
static const unsigned char any[] = {
7012
0xff, 0xff, 0xff, 0xff, 0xff, 0xff
7014
static const unsigned char off[] = {
7015
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
7019
if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
7022
mutex_lock(&priv->action_mutex);
7023
if (!(priv->status & STATUS_INITIALIZED)) {
7028
if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
7029
!memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
7030
/* we disable mandatory BSSID association */
7031
IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
7032
priv->config &= ~CFG_STATIC_BSSID;
7033
err = ipw2100_set_mandatory_bssid(priv, NULL, 0);
7037
priv->config |= CFG_STATIC_BSSID;
7038
memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN);
7040
err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
7042
IPW_DEBUG_WX("SET BSSID -> %pM\n", wrqu->ap_addr.sa_data);
7045
mutex_unlock(&priv->action_mutex);
7049
static int ipw2100_wx_get_wap(struct net_device *dev,
7050
struct iw_request_info *info,
7051
union iwreq_data *wrqu, char *extra)
7054
* This can be called at any time. No action lock required
7057
struct ipw2100_priv *priv = libipw_priv(dev);
7059
/* If we are associated, trying to associate, or have a statically
7060
* configured BSSID then return that; otherwise return ANY */
7061
if (priv->config & CFG_STATIC_BSSID || priv->status & STATUS_ASSOCIATED) {
7062
wrqu->ap_addr.sa_family = ARPHRD_ETHER;
7063
memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
7065
memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
7067
IPW_DEBUG_WX("Getting WAP BSSID: %pM\n", wrqu->ap_addr.sa_data);
7071
static int ipw2100_wx_set_essid(struct net_device *dev,
7072
struct iw_request_info *info,
7073
union iwreq_data *wrqu, char *extra)
7075
struct ipw2100_priv *priv = libipw_priv(dev);
7076
char *essid = ""; /* ANY */
7079
DECLARE_SSID_BUF(ssid);
7081
mutex_lock(&priv->action_mutex);
7082
if (!(priv->status & STATUS_INITIALIZED)) {
7087
if (wrqu->essid.flags && wrqu->essid.length) {
7088
length = wrqu->essid.length;
7093
IPW_DEBUG_WX("Setting ESSID to ANY\n");
7094
priv->config &= ~CFG_STATIC_ESSID;
7095
err = ipw2100_set_essid(priv, NULL, 0, 0);
7099
length = min(length, IW_ESSID_MAX_SIZE);
7101
priv->config |= CFG_STATIC_ESSID;
7103
if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
7104
IPW_DEBUG_WX("ESSID set to current ESSID.\n");
7109
IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
7110
print_ssid(ssid, essid, length), length);
7112
priv->essid_len = length;
7113
memcpy(priv->essid, essid, priv->essid_len);
7115
err = ipw2100_set_essid(priv, essid, length, 0);
7118
mutex_unlock(&priv->action_mutex);
7122
static int ipw2100_wx_get_essid(struct net_device *dev,
7123
struct iw_request_info *info,
7124
union iwreq_data *wrqu, char *extra)
7127
* This can be called at any time. No action lock required
7130
struct ipw2100_priv *priv = libipw_priv(dev);
7131
DECLARE_SSID_BUF(ssid);
7133
/* If we are associated, trying to associate, or have a statically
7134
* configured ESSID then return that; otherwise return ANY */
7135
if (priv->config & CFG_STATIC_ESSID || priv->status & STATUS_ASSOCIATED) {
7136
IPW_DEBUG_WX("Getting essid: '%s'\n",
7137
print_ssid(ssid, priv->essid, priv->essid_len));
7138
memcpy(extra, priv->essid, priv->essid_len);
7139
wrqu->essid.length = priv->essid_len;
7140
wrqu->essid.flags = 1; /* active */
7142
IPW_DEBUG_WX("Getting essid: ANY\n");
7143
wrqu->essid.length = 0;
7144
wrqu->essid.flags = 0; /* active */
7150
static int ipw2100_wx_set_nick(struct net_device *dev,
7151
struct iw_request_info *info,
7152
union iwreq_data *wrqu, char *extra)
7155
* This can be called at any time. No action lock required
7158
struct ipw2100_priv *priv = libipw_priv(dev);
7160
if (wrqu->data.length > IW_ESSID_MAX_SIZE)
7163
wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
7164
memset(priv->nick, 0, sizeof(priv->nick));
7165
memcpy(priv->nick, extra, wrqu->data.length);
7167
IPW_DEBUG_WX("SET Nickname -> %s \n", priv->nick);
7172
static int ipw2100_wx_get_nick(struct net_device *dev,
7173
struct iw_request_info *info,
7174
union iwreq_data *wrqu, char *extra)
7177
* This can be called at any time. No action lock required
7180
struct ipw2100_priv *priv = libipw_priv(dev);
7182
wrqu->data.length = strlen(priv->nick);
7183
memcpy(extra, priv->nick, wrqu->data.length);
7184
wrqu->data.flags = 1; /* active */
7186
IPW_DEBUG_WX("GET Nickname -> %s \n", extra);
7191
static int ipw2100_wx_set_rate(struct net_device *dev,
7192
struct iw_request_info *info,
7193
union iwreq_data *wrqu, char *extra)
7195
struct ipw2100_priv *priv = libipw_priv(dev);
7196
u32 target_rate = wrqu->bitrate.value;
7200
mutex_lock(&priv->action_mutex);
7201
if (!(priv->status & STATUS_INITIALIZED)) {
7208
if (target_rate == 1000000 ||
7209
(!wrqu->bitrate.fixed && target_rate > 1000000))
7210
rate |= TX_RATE_1_MBIT;
7211
if (target_rate == 2000000 ||
7212
(!wrqu->bitrate.fixed && target_rate > 2000000))
7213
rate |= TX_RATE_2_MBIT;
7214
if (target_rate == 5500000 ||
7215
(!wrqu->bitrate.fixed && target_rate > 5500000))
7216
rate |= TX_RATE_5_5_MBIT;
7217
if (target_rate == 11000000 ||
7218
(!wrqu->bitrate.fixed && target_rate > 11000000))
7219
rate |= TX_RATE_11_MBIT;
7221
rate = DEFAULT_TX_RATES;
7223
err = ipw2100_set_tx_rates(priv, rate, 0);
7225
IPW_DEBUG_WX("SET Rate -> %04X \n", rate);
7227
mutex_unlock(&priv->action_mutex);
7231
static int ipw2100_wx_get_rate(struct net_device *dev,
7232
struct iw_request_info *info,
7233
union iwreq_data *wrqu, char *extra)
7235
struct ipw2100_priv *priv = libipw_priv(dev);
7237
unsigned int len = sizeof(val);
7240
if (!(priv->status & STATUS_ENABLED) ||
7241
priv->status & STATUS_RF_KILL_MASK ||
7242
!(priv->status & STATUS_ASSOCIATED)) {
7243
wrqu->bitrate.value = 0;
7247
mutex_lock(&priv->action_mutex);
7248
if (!(priv->status & STATUS_INITIALIZED)) {
7253
err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len);
7255
IPW_DEBUG_WX("failed querying ordinals.\n");
7259
switch (val & TX_RATE_MASK) {
7260
case TX_RATE_1_MBIT:
7261
wrqu->bitrate.value = 1000000;
7263
case TX_RATE_2_MBIT:
7264
wrqu->bitrate.value = 2000000;
7266
case TX_RATE_5_5_MBIT:
7267
wrqu->bitrate.value = 5500000;
7269
case TX_RATE_11_MBIT:
7270
wrqu->bitrate.value = 11000000;
7273
wrqu->bitrate.value = 0;
7276
IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
7279
mutex_unlock(&priv->action_mutex);
7283
static int ipw2100_wx_set_rts(struct net_device *dev,
7284
struct iw_request_info *info,
7285
union iwreq_data *wrqu, char *extra)
7287
struct ipw2100_priv *priv = libipw_priv(dev);
7290
/* Auto RTS not yet supported */
7291
if (wrqu->rts.fixed == 0)
7294
mutex_lock(&priv->action_mutex);
7295
if (!(priv->status & STATUS_INITIALIZED)) {
7300
if (wrqu->rts.disabled)
7301
value = priv->rts_threshold | RTS_DISABLED;
7303
if (wrqu->rts.value < 1 || wrqu->rts.value > 2304) {
7307
value = wrqu->rts.value;
7310
err = ipw2100_set_rts_threshold(priv, value);
7312
IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X \n", value);
7314
mutex_unlock(&priv->action_mutex);
7318
static int ipw2100_wx_get_rts(struct net_device *dev,
7319
struct iw_request_info *info,
7320
union iwreq_data *wrqu, char *extra)
7323
* This can be called at any time. No action lock required
7326
struct ipw2100_priv *priv = libipw_priv(dev);
7328
wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED;
7329
wrqu->rts.fixed = 1; /* no auto select */
7331
/* If RTS is set to the default value, then it is disabled */
7332
wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0;
7334
IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X \n", wrqu->rts.value);
7339
static int ipw2100_wx_set_txpow(struct net_device *dev,
7340
struct iw_request_info *info,
7341
union iwreq_data *wrqu, char *extra)
7343
struct ipw2100_priv *priv = libipw_priv(dev);
7346
if (ipw_radio_kill_sw(priv, wrqu->txpower.disabled))
7347
return -EINPROGRESS;
7349
if (priv->ieee->iw_mode != IW_MODE_ADHOC)
7352
if ((wrqu->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
7355
if (wrqu->txpower.fixed == 0)
7356
value = IPW_TX_POWER_DEFAULT;
7358
if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM ||
7359
wrqu->txpower.value > IPW_TX_POWER_MAX_DBM)
7362
value = wrqu->txpower.value;
7365
mutex_lock(&priv->action_mutex);
7366
if (!(priv->status & STATUS_INITIALIZED)) {
7371
err = ipw2100_set_tx_power(priv, value);
7373
IPW_DEBUG_WX("SET TX Power -> %d \n", value);
7376
mutex_unlock(&priv->action_mutex);
7380
static int ipw2100_wx_get_txpow(struct net_device *dev,
7381
struct iw_request_info *info,
7382
union iwreq_data *wrqu, char *extra)
7385
* This can be called at any time. No action lock required
7388
struct ipw2100_priv *priv = libipw_priv(dev);
7390
wrqu->txpower.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
7392
if (priv->tx_power == IPW_TX_POWER_DEFAULT) {
7393
wrqu->txpower.fixed = 0;
7394
wrqu->txpower.value = IPW_TX_POWER_MAX_DBM;
7396
wrqu->txpower.fixed = 1;
7397
wrqu->txpower.value = priv->tx_power;
7400
wrqu->txpower.flags = IW_TXPOW_DBM;
7402
IPW_DEBUG_WX("GET TX Power -> %d \n", wrqu->txpower.value);
7407
static int ipw2100_wx_set_frag(struct net_device *dev,
7408
struct iw_request_info *info,
7409
union iwreq_data *wrqu, char *extra)
7412
* This can be called at any time. No action lock required
7415
struct ipw2100_priv *priv = libipw_priv(dev);
7417
if (!wrqu->frag.fixed)
7420
if (wrqu->frag.disabled) {
7421
priv->frag_threshold |= FRAG_DISABLED;
7422
priv->ieee->fts = DEFAULT_FTS;
7424
if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
7425
wrqu->frag.value > MAX_FRAG_THRESHOLD)
7428
priv->ieee->fts = wrqu->frag.value & ~0x1;
7429
priv->frag_threshold = priv->ieee->fts;
7432
IPW_DEBUG_WX("SET Frag Threshold -> %d \n", priv->ieee->fts);
7437
static int ipw2100_wx_get_frag(struct net_device *dev,
7438
struct iw_request_info *info,
7439
union iwreq_data *wrqu, char *extra)
7442
* This can be called at any time. No action lock required
7445
struct ipw2100_priv *priv = libipw_priv(dev);
7446
wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED;
7447
wrqu->frag.fixed = 0; /* no auto select */
7448
wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0;
7450
IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
7455
static int ipw2100_wx_set_retry(struct net_device *dev,
7456
struct iw_request_info *info,
7457
union iwreq_data *wrqu, char *extra)
7459
struct ipw2100_priv *priv = libipw_priv(dev);
7462
if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
7465
if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
7468
mutex_lock(&priv->action_mutex);
7469
if (!(priv->status & STATUS_INITIALIZED)) {
7474
if (wrqu->retry.flags & IW_RETRY_SHORT) {
7475
err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7476
IPW_DEBUG_WX("SET Short Retry Limit -> %d \n",
7481
if (wrqu->retry.flags & IW_RETRY_LONG) {
7482
err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7483
IPW_DEBUG_WX("SET Long Retry Limit -> %d \n",
7488
err = ipw2100_set_short_retry(priv, wrqu->retry.value);
7490
err = ipw2100_set_long_retry(priv, wrqu->retry.value);
7492
IPW_DEBUG_WX("SET Both Retry Limits -> %d \n", wrqu->retry.value);
7495
mutex_unlock(&priv->action_mutex);
7499
static int ipw2100_wx_get_retry(struct net_device *dev,
7500
struct iw_request_info *info,
7501
union iwreq_data *wrqu, char *extra)
7504
* This can be called at any time. No action lock required
7507
struct ipw2100_priv *priv = libipw_priv(dev);
7509
wrqu->retry.disabled = 0; /* can't be disabled */
7511
if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME)
7514
if (wrqu->retry.flags & IW_RETRY_LONG) {
7515
wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
7516
wrqu->retry.value = priv->long_retry_limit;
7519
(priv->short_retry_limit !=
7520
priv->long_retry_limit) ?
7521
IW_RETRY_LIMIT | IW_RETRY_SHORT : IW_RETRY_LIMIT;
7523
wrqu->retry.value = priv->short_retry_limit;
7526
IPW_DEBUG_WX("GET Retry -> %d \n", wrqu->retry.value);
7531
static int ipw2100_wx_set_scan(struct net_device *dev,
7532
struct iw_request_info *info,
7533
union iwreq_data *wrqu, char *extra)
7535
struct ipw2100_priv *priv = libipw_priv(dev);
7538
mutex_lock(&priv->action_mutex);
7539
if (!(priv->status & STATUS_INITIALIZED)) {
7544
IPW_DEBUG_WX("Initiating scan...\n");
7546
priv->user_requested_scan = 1;
7547
if (ipw2100_set_scan_options(priv) || ipw2100_start_scan(priv)) {
7548
IPW_DEBUG_WX("Start scan failed.\n");
7550
/* TODO: Mark a scan as pending so when hardware initialized
7555
mutex_unlock(&priv->action_mutex);
7559
static int ipw2100_wx_get_scan(struct net_device *dev,
7560
struct iw_request_info *info,
7561
union iwreq_data *wrqu, char *extra)
7564
* This can be called at any time. No action lock required
7567
struct ipw2100_priv *priv = libipw_priv(dev);
7568
return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
7572
* Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
7574
static int ipw2100_wx_set_encode(struct net_device *dev,
7575
struct iw_request_info *info,
7576
union iwreq_data *wrqu, char *key)
7579
* No check of STATUS_INITIALIZED required
7582
struct ipw2100_priv *priv = libipw_priv(dev);
7583
return libipw_wx_set_encode(priv->ieee, info, wrqu, key);
7586
static int ipw2100_wx_get_encode(struct net_device *dev,
7587
struct iw_request_info *info,
7588
union iwreq_data *wrqu, char *key)
7591
* This can be called at any time. No action lock required
7594
struct ipw2100_priv *priv = libipw_priv(dev);
7595
return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
7598
static int ipw2100_wx_set_power(struct net_device *dev,
7599
struct iw_request_info *info,
7600
union iwreq_data *wrqu, char *extra)
7602
struct ipw2100_priv *priv = libipw_priv(dev);
7605
mutex_lock(&priv->action_mutex);
7606
if (!(priv->status & STATUS_INITIALIZED)) {
7611
if (wrqu->power.disabled) {
7612
priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
7613
err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
7614
IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7618
switch (wrqu->power.flags & IW_POWER_MODE) {
7619
case IW_POWER_ON: /* If not specified */
7620
case IW_POWER_MODE: /* If set all mask */
7621
case IW_POWER_ALL_R: /* If explicitly state all */
7623
default: /* Otherwise we don't support it */
7624
IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7630
/* If the user hasn't specified a power management mode yet, default
7632
priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
7633
err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
7635
IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
7638
mutex_unlock(&priv->action_mutex);
7643
static int ipw2100_wx_get_power(struct net_device *dev,
7644
struct iw_request_info *info,
7645
union iwreq_data *wrqu, char *extra)
7648
* This can be called at any time. No action lock required
7651
struct ipw2100_priv *priv = libipw_priv(dev);
7653
if (!(priv->power_mode & IPW_POWER_ENABLED))
7654
wrqu->power.disabled = 1;
7656
wrqu->power.disabled = 0;
7657
wrqu->power.flags = 0;
7660
IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
7670
static int ipw2100_wx_set_genie(struct net_device *dev,
7671
struct iw_request_info *info,
7672
union iwreq_data *wrqu, char *extra)
7675
struct ipw2100_priv *priv = libipw_priv(dev);
7676
struct libipw_device *ieee = priv->ieee;
7679
if (!ieee->wpa_enabled)
7682
if (wrqu->data.length > MAX_WPA_IE_LEN ||
7683
(wrqu->data.length && extra == NULL))
7686
if (wrqu->data.length) {
7687
buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
7691
kfree(ieee->wpa_ie);
7693
ieee->wpa_ie_len = wrqu->data.length;
7695
kfree(ieee->wpa_ie);
7696
ieee->wpa_ie = NULL;
7697
ieee->wpa_ie_len = 0;
7700
ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
7706
static int ipw2100_wx_get_genie(struct net_device *dev,
7707
struct iw_request_info *info,
7708
union iwreq_data *wrqu, char *extra)
7710
struct ipw2100_priv *priv = libipw_priv(dev);
7711
struct libipw_device *ieee = priv->ieee;
7713
if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
7714
wrqu->data.length = 0;
7718
if (wrqu->data.length < ieee->wpa_ie_len)
7721
wrqu->data.length = ieee->wpa_ie_len;
7722
memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
7728
static int ipw2100_wx_set_auth(struct net_device *dev,
7729
struct iw_request_info *info,
7730
union iwreq_data *wrqu, char *extra)
7732
struct ipw2100_priv *priv = libipw_priv(dev);
7733
struct libipw_device *ieee = priv->ieee;
7734
struct iw_param *param = &wrqu->param;
7735
struct lib80211_crypt_data *crypt;
7736
unsigned long flags;
7739
switch (param->flags & IW_AUTH_INDEX) {
7740
case IW_AUTH_WPA_VERSION:
7741
case IW_AUTH_CIPHER_PAIRWISE:
7742
case IW_AUTH_CIPHER_GROUP:
7743
case IW_AUTH_KEY_MGMT:
7745
* ipw2200 does not use these parameters
7749
case IW_AUTH_TKIP_COUNTERMEASURES:
7750
crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
7751
if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
7754
flags = crypt->ops->get_flags(crypt->priv);
7757
flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
7759
flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
7761
crypt->ops->set_flags(flags, crypt->priv);
7765
case IW_AUTH_DROP_UNENCRYPTED:{
7768
* wpa_supplicant calls set_wpa_enabled when the driver
7769
* is loaded and unloaded, regardless of if WPA is being
7770
* used. No other calls are made which can be used to
7771
* determine if encryption will be used or not prior to
7772
* association being expected. If encryption is not being
7773
* used, drop_unencrypted is set to false, else true -- we
7774
* can use this to determine if the CAP_PRIVACY_ON bit should
7777
struct libipw_security sec = {
7778
.flags = SEC_ENABLED,
7779
.enabled = param->value,
7781
priv->ieee->drop_unencrypted = param->value;
7782
/* We only change SEC_LEVEL for open mode. Others
7783
* are set by ipw_wpa_set_encryption.
7785
if (!param->value) {
7786
sec.flags |= SEC_LEVEL;
7787
sec.level = SEC_LEVEL_0;
7789
sec.flags |= SEC_LEVEL;
7790
sec.level = SEC_LEVEL_1;
7792
if (priv->ieee->set_security)
7793
priv->ieee->set_security(priv->ieee->dev, &sec);
7797
case IW_AUTH_80211_AUTH_ALG:
7798
ret = ipw2100_wpa_set_auth_algs(priv, param->value);
7801
case IW_AUTH_WPA_ENABLED:
7802
ret = ipw2100_wpa_enable(priv, param->value);
7805
case IW_AUTH_RX_UNENCRYPTED_EAPOL:
7806
ieee->ieee802_1x = param->value;
7809
//case IW_AUTH_ROAMING_CONTROL:
7810
case IW_AUTH_PRIVACY_INVOKED:
7811
ieee->privacy_invoked = param->value;
7821
static int ipw2100_wx_get_auth(struct net_device *dev,
7822
struct iw_request_info *info,
7823
union iwreq_data *wrqu, char *extra)
7825
struct ipw2100_priv *priv = libipw_priv(dev);
7826
struct libipw_device *ieee = priv->ieee;
7827
struct lib80211_crypt_data *crypt;
7828
struct iw_param *param = &wrqu->param;
7831
switch (param->flags & IW_AUTH_INDEX) {
7832
case IW_AUTH_WPA_VERSION:
7833
case IW_AUTH_CIPHER_PAIRWISE:
7834
case IW_AUTH_CIPHER_GROUP:
7835
case IW_AUTH_KEY_MGMT:
7837
* wpa_supplicant will control these internally
7842
case IW_AUTH_TKIP_COUNTERMEASURES:
7843
crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
7844
if (!crypt || !crypt->ops->get_flags) {
7845
IPW_DEBUG_WARNING("Can't get TKIP countermeasures: "
7846
"crypt not set!\n");
7850
param->value = (crypt->ops->get_flags(crypt->priv) &
7851
IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
7855
case IW_AUTH_DROP_UNENCRYPTED:
7856
param->value = ieee->drop_unencrypted;
7859
case IW_AUTH_80211_AUTH_ALG:
7860
param->value = priv->ieee->sec.auth_mode;
7863
case IW_AUTH_WPA_ENABLED:
7864
param->value = ieee->wpa_enabled;
7867
case IW_AUTH_RX_UNENCRYPTED_EAPOL:
7868
param->value = ieee->ieee802_1x;
7871
case IW_AUTH_ROAMING_CONTROL:
7872
case IW_AUTH_PRIVACY_INVOKED:
7873
param->value = ieee->privacy_invoked;
7882
/* SIOCSIWENCODEEXT */
7883
static int ipw2100_wx_set_encodeext(struct net_device *dev,
7884
struct iw_request_info *info,
7885
union iwreq_data *wrqu, char *extra)
7887
struct ipw2100_priv *priv = libipw_priv(dev);
7888
return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
7891
/* SIOCGIWENCODEEXT */
7892
static int ipw2100_wx_get_encodeext(struct net_device *dev,
7893
struct iw_request_info *info,
7894
union iwreq_data *wrqu, char *extra)
7896
struct ipw2100_priv *priv = libipw_priv(dev);
7897
return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
7901
static int ipw2100_wx_set_mlme(struct net_device *dev,
7902
struct iw_request_info *info,
7903
union iwreq_data *wrqu, char *extra)
7905
struct ipw2100_priv *priv = libipw_priv(dev);
7906
struct iw_mlme *mlme = (struct iw_mlme *)extra;
7909
reason = cpu_to_le16(mlme->reason_code);
7911
switch (mlme->cmd) {
7912
case IW_MLME_DEAUTH:
7916
case IW_MLME_DISASSOC:
7917
ipw2100_disassociate_bssid(priv);
7931
#ifdef CONFIG_IPW2100_MONITOR
7932
static int ipw2100_wx_set_promisc(struct net_device *dev,
7933
struct iw_request_info *info,
7934
union iwreq_data *wrqu, char *extra)
7936
struct ipw2100_priv *priv = libipw_priv(dev);
7937
int *parms = (int *)extra;
7938
int enable = (parms[0] > 0);
7941
mutex_lock(&priv->action_mutex);
7942
if (!(priv->status & STATUS_INITIALIZED)) {
7948
if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7949
err = ipw2100_set_channel(priv, parms[1], 0);
7952
priv->channel = parms[1];
7953
err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
7955
if (priv->ieee->iw_mode == IW_MODE_MONITOR)
7956
err = ipw2100_switch_mode(priv, priv->last_mode);
7959
mutex_unlock(&priv->action_mutex);
7963
static int ipw2100_wx_reset(struct net_device *dev,
7964
struct iw_request_info *info,
7965
union iwreq_data *wrqu, char *extra)
7967
struct ipw2100_priv *priv = libipw_priv(dev);
7968
if (priv->status & STATUS_INITIALIZED)
7969
schedule_reset(priv);
7975
static int ipw2100_wx_set_powermode(struct net_device *dev,
7976
struct iw_request_info *info,
7977
union iwreq_data *wrqu, char *extra)
7979
struct ipw2100_priv *priv = libipw_priv(dev);
7980
int err = 0, mode = *(int *)extra;
7982
mutex_lock(&priv->action_mutex);
7983
if (!(priv->status & STATUS_INITIALIZED)) {
7988
if ((mode < 0) || (mode > POWER_MODES))
7989
mode = IPW_POWER_AUTO;
7991
if (IPW_POWER_LEVEL(priv->power_mode) != mode)
7992
err = ipw2100_set_power_mode(priv, mode);
7994
mutex_unlock(&priv->action_mutex);
7998
#define MAX_POWER_STRING 80
7999
static int ipw2100_wx_get_powermode(struct net_device *dev,
8000
struct iw_request_info *info,
8001
union iwreq_data *wrqu, char *extra)
8004
* This can be called at any time. No action lock required
8007
struct ipw2100_priv *priv = libipw_priv(dev);
8008
int level = IPW_POWER_LEVEL(priv->power_mode);
8009
s32 timeout, period;
8011
if (!(priv->power_mode & IPW_POWER_ENABLED)) {
8012
snprintf(extra, MAX_POWER_STRING,
8013
"Power save level: %d (Off)", level);
8016
case IPW_POWER_MODE_CAM:
8017
snprintf(extra, MAX_POWER_STRING,
8018
"Power save level: %d (None)", level);
8020
case IPW_POWER_AUTO:
8021
snprintf(extra, MAX_POWER_STRING,
8022
"Power save level: %d (Auto)", level);
8025
timeout = timeout_duration[level - 1] / 1000;
8026
period = period_duration[level - 1] / 1000;
8027
snprintf(extra, MAX_POWER_STRING,
8028
"Power save level: %d "
8029
"(Timeout %dms, Period %dms)",
8030
level, timeout, period);
8034
wrqu->data.length = strlen(extra) + 1;
8039
static int ipw2100_wx_set_preamble(struct net_device *dev,
8040
struct iw_request_info *info,
8041
union iwreq_data *wrqu, char *extra)
8043
struct ipw2100_priv *priv = libipw_priv(dev);
8044
int err, mode = *(int *)extra;
8046
mutex_lock(&priv->action_mutex);
8047
if (!(priv->status & STATUS_INITIALIZED)) {
8053
priv->config |= CFG_LONG_PREAMBLE;
8055
priv->config &= ~CFG_LONG_PREAMBLE;
8061
err = ipw2100_system_config(priv, 0);
8064
mutex_unlock(&priv->action_mutex);
8068
static int ipw2100_wx_get_preamble(struct net_device *dev,
8069
struct iw_request_info *info,
8070
union iwreq_data *wrqu, char *extra)
8073
* This can be called at any time. No action lock required
8076
struct ipw2100_priv *priv = libipw_priv(dev);
8078
if (priv->config & CFG_LONG_PREAMBLE)
8079
snprintf(wrqu->name, IFNAMSIZ, "long (1)");
8081
snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
8086
#ifdef CONFIG_IPW2100_MONITOR
8087
static int ipw2100_wx_set_crc_check(struct net_device *dev,
8088
struct iw_request_info *info,
8089
union iwreq_data *wrqu, char *extra)
8091
struct ipw2100_priv *priv = libipw_priv(dev);
8092
int err, mode = *(int *)extra;
8094
mutex_lock(&priv->action_mutex);
8095
if (!(priv->status & STATUS_INITIALIZED)) {
8101
priv->config |= CFG_CRC_CHECK;
8103
priv->config &= ~CFG_CRC_CHECK;
8111
mutex_unlock(&priv->action_mutex);
8115
static int ipw2100_wx_get_crc_check(struct net_device *dev,
8116
struct iw_request_info *info,
8117
union iwreq_data *wrqu, char *extra)
8120
* This can be called at any time. No action lock required
8123
struct ipw2100_priv *priv = libipw_priv(dev);
8125
if (priv->config & CFG_CRC_CHECK)
8126
snprintf(wrqu->name, IFNAMSIZ, "CRC checked (1)");
8128
snprintf(wrqu->name, IFNAMSIZ, "CRC ignored (0)");
8132
#endif /* CONFIG_IPW2100_MONITOR */
8134
static iw_handler ipw2100_wx_handlers[] = {
8135
NULL, /* SIOCSIWCOMMIT */
8136
ipw2100_wx_get_name, /* SIOCGIWNAME */
8137
NULL, /* SIOCSIWNWID */
8138
NULL, /* SIOCGIWNWID */
8139
ipw2100_wx_set_freq, /* SIOCSIWFREQ */
8140
ipw2100_wx_get_freq, /* SIOCGIWFREQ */
8141
ipw2100_wx_set_mode, /* SIOCSIWMODE */
8142
ipw2100_wx_get_mode, /* SIOCGIWMODE */
8143
NULL, /* SIOCSIWSENS */
8144
NULL, /* SIOCGIWSENS */
8145
NULL, /* SIOCSIWRANGE */
8146
ipw2100_wx_get_range, /* SIOCGIWRANGE */
8147
NULL, /* SIOCSIWPRIV */
8148
NULL, /* SIOCGIWPRIV */
8149
NULL, /* SIOCSIWSTATS */
8150
NULL, /* SIOCGIWSTATS */
8151
NULL, /* SIOCSIWSPY */
8152
NULL, /* SIOCGIWSPY */
8153
NULL, /* SIOCGIWTHRSPY */
8154
NULL, /* SIOCWIWTHRSPY */
8155
ipw2100_wx_set_wap, /* SIOCSIWAP */
8156
ipw2100_wx_get_wap, /* SIOCGIWAP */
8157
ipw2100_wx_set_mlme, /* SIOCSIWMLME */
8158
NULL, /* SIOCGIWAPLIST -- deprecated */
8159
ipw2100_wx_set_scan, /* SIOCSIWSCAN */
8160
ipw2100_wx_get_scan, /* SIOCGIWSCAN */
8161
ipw2100_wx_set_essid, /* SIOCSIWESSID */
8162
ipw2100_wx_get_essid, /* SIOCGIWESSID */
8163
ipw2100_wx_set_nick, /* SIOCSIWNICKN */
8164
ipw2100_wx_get_nick, /* SIOCGIWNICKN */
8165
NULL, /* -- hole -- */
8166
NULL, /* -- hole -- */
8167
ipw2100_wx_set_rate, /* SIOCSIWRATE */
8168
ipw2100_wx_get_rate, /* SIOCGIWRATE */
8169
ipw2100_wx_set_rts, /* SIOCSIWRTS */
8170
ipw2100_wx_get_rts, /* SIOCGIWRTS */
8171
ipw2100_wx_set_frag, /* SIOCSIWFRAG */
8172
ipw2100_wx_get_frag, /* SIOCGIWFRAG */
8173
ipw2100_wx_set_txpow, /* SIOCSIWTXPOW */
8174
ipw2100_wx_get_txpow, /* SIOCGIWTXPOW */
8175
ipw2100_wx_set_retry, /* SIOCSIWRETRY */
8176
ipw2100_wx_get_retry, /* SIOCGIWRETRY */
8177
ipw2100_wx_set_encode, /* SIOCSIWENCODE */
8178
ipw2100_wx_get_encode, /* SIOCGIWENCODE */
8179
ipw2100_wx_set_power, /* SIOCSIWPOWER */
8180
ipw2100_wx_get_power, /* SIOCGIWPOWER */
8181
NULL, /* -- hole -- */
8182
NULL, /* -- hole -- */
8183
ipw2100_wx_set_genie, /* SIOCSIWGENIE */
8184
ipw2100_wx_get_genie, /* SIOCGIWGENIE */
8185
ipw2100_wx_set_auth, /* SIOCSIWAUTH */
8186
ipw2100_wx_get_auth, /* SIOCGIWAUTH */
8187
ipw2100_wx_set_encodeext, /* SIOCSIWENCODEEXT */
8188
ipw2100_wx_get_encodeext, /* SIOCGIWENCODEEXT */
8189
NULL, /* SIOCSIWPMKSA */
8192
#define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
8193
#define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
8194
#define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
8195
#define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
8196
#define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
8197
#define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
8198
#define IPW2100_PRIV_SET_CRC_CHECK SIOCIWFIRSTPRIV+6
8199
#define IPW2100_PRIV_GET_CRC_CHECK SIOCIWFIRSTPRIV+7
8201
static const struct iw_priv_args ipw2100_private_args[] = {
8203
#ifdef CONFIG_IPW2100_MONITOR
8205
IPW2100_PRIV_SET_MONITOR,
8206
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
8209
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
8210
#endif /* CONFIG_IPW2100_MONITOR */
8213
IPW2100_PRIV_SET_POWER,
8214
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"},
8216
IPW2100_PRIV_GET_POWER,
8217
0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING,
8220
IPW2100_PRIV_SET_LONGPREAMBLE,
8221
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"},
8223
IPW2100_PRIV_GET_LONGPREAMBLE,
8224
0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"},
8225
#ifdef CONFIG_IPW2100_MONITOR
8227
IPW2100_PRIV_SET_CRC_CHECK,
8228
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_crc_check"},
8230
IPW2100_PRIV_GET_CRC_CHECK,
8231
0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_crc_check"},
8232
#endif /* CONFIG_IPW2100_MONITOR */
8235
static iw_handler ipw2100_private_handler[] = {
8236
#ifdef CONFIG_IPW2100_MONITOR
8237
ipw2100_wx_set_promisc,
8239
#else /* CONFIG_IPW2100_MONITOR */
8242
#endif /* CONFIG_IPW2100_MONITOR */
8243
ipw2100_wx_set_powermode,
8244
ipw2100_wx_get_powermode,
8245
ipw2100_wx_set_preamble,
8246
ipw2100_wx_get_preamble,
8247
#ifdef CONFIG_IPW2100_MONITOR
8248
ipw2100_wx_set_crc_check,
8249
ipw2100_wx_get_crc_check,
8250
#else /* CONFIG_IPW2100_MONITOR */
8253
#endif /* CONFIG_IPW2100_MONITOR */
8257
* Get wireless statistics.
8258
* Called by /proc/net/wireless
8259
* Also called by SIOCGIWSTATS
8261
static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev)
8276
struct ipw2100_priv *priv = libipw_priv(dev);
8277
struct iw_statistics *wstats;
8278
u32 rssi, tx_retries, missed_beacons, tx_failures;
8279
u32 ord_len = sizeof(u32);
8282
return (struct iw_statistics *)NULL;
8284
wstats = &priv->wstats;
8286
/* if hw is disabled, then ipw2100_get_ordinal() can't be called.
8287
* ipw2100_wx_wireless_stats seems to be called before fw is
8288
* initialized. STATUS_ASSOCIATED will only be set if the hw is up
8289
* and associated; if not associcated, the values are all meaningless
8290
* anyway, so set them all to NULL and INVALID */
8291
if (!(priv->status & STATUS_ASSOCIATED)) {
8292
wstats->miss.beacon = 0;
8293
wstats->discard.retries = 0;
8294
wstats->qual.qual = 0;
8295
wstats->qual.level = 0;
8296
wstats->qual.noise = 0;
8297
wstats->qual.updated = 7;
8298
wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
8299
IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
8303
if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS,
8304
&missed_beacons, &ord_len))
8305
goto fail_get_ordinal;
8307
/* If we don't have a connection the quality and level is 0 */
8308
if (!(priv->status & STATUS_ASSOCIATED)) {
8309
wstats->qual.qual = 0;
8310
wstats->qual.level = 0;
8312
if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR,
8314
goto fail_get_ordinal;
8315
wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8317
rssi_qual = rssi * POOR / 10;
8319
rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR;
8321
rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR;
8323
rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) /
8326
rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) /
8329
if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES,
8330
&tx_retries, &ord_len))
8331
goto fail_get_ordinal;
8333
if (tx_retries > 75)
8334
tx_qual = (90 - tx_retries) * POOR / 15;
8335
else if (tx_retries > 70)
8336
tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
8337
else if (tx_retries > 65)
8338
tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
8339
else if (tx_retries > 50)
8340
tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
8343
tx_qual = (50 - tx_retries) *
8344
(PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
8346
if (missed_beacons > 50)
8347
beacon_qual = (60 - missed_beacons) * POOR / 10;
8348
else if (missed_beacons > 40)
8349
beacon_qual = (50 - missed_beacons) * (FAIR - POOR) /
8351
else if (missed_beacons > 32)
8352
beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) /
8354
else if (missed_beacons > 20)
8355
beacon_qual = (32 - missed_beacons) *
8356
(VERY_GOOD - GOOD) / 20 + GOOD;
8358
beacon_qual = (20 - missed_beacons) *
8359
(PERFECT - VERY_GOOD) / 20 + VERY_GOOD;
8361
quality = min(tx_qual, rssi_qual);
8362
quality = min(beacon_qual, quality);
8364
#ifdef CONFIG_IPW2100_DEBUG
8365
if (beacon_qual == quality)
8366
IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
8367
else if (tx_qual == quality)
8368
IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
8369
else if (quality != 100)
8370
IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
8372
IPW_DEBUG_WX("Quality not clamped.\n");
8375
wstats->qual.qual = quality;
8376
wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
8379
wstats->qual.noise = 0;
8380
wstats->qual.updated = 7;
8381
wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
8383
/* FIXME: this is percent and not a # */
8384
wstats->miss.beacon = missed_beacons;
8386
if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES,
8387
&tx_failures, &ord_len))
8388
goto fail_get_ordinal;
8389
wstats->discard.retries = tx_failures;
8394
IPW_DEBUG_WX("failed querying ordinals.\n");
8396
return (struct iw_statistics *)NULL;
8399
static struct iw_handler_def ipw2100_wx_handler_def = {
8400
.standard = ipw2100_wx_handlers,
8401
.num_standard = ARRAY_SIZE(ipw2100_wx_handlers),
8402
.num_private = ARRAY_SIZE(ipw2100_private_handler),
8403
.num_private_args = ARRAY_SIZE(ipw2100_private_args),
8404
.private = (iw_handler *) ipw2100_private_handler,
8405
.private_args = (struct iw_priv_args *)ipw2100_private_args,
8406
.get_wireless_stats = ipw2100_wx_wireless_stats,
8409
static void ipw2100_wx_event_work(struct work_struct *work)
8411
struct ipw2100_priv *priv =
8412
container_of(work, struct ipw2100_priv, wx_event_work.work);
8413
union iwreq_data wrqu;
8414
unsigned int len = ETH_ALEN;
8416
if (priv->status & STATUS_STOPPING)
8419
mutex_lock(&priv->action_mutex);
8421
IPW_DEBUG_WX("enter\n");
8423
mutex_unlock(&priv->action_mutex);
8425
wrqu.ap_addr.sa_family = ARPHRD_ETHER;
8427
/* Fetch BSSID from the hardware */
8428
if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) ||
8429
priv->status & STATUS_RF_KILL_MASK ||
8430
ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
8431
&priv->bssid, &len)) {
8432
memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
8434
/* We now have the BSSID, so can finish setting to the full
8435
* associated state */
8436
memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
8437
memcpy(priv->ieee->bssid, priv->bssid, ETH_ALEN);
8438
priv->status &= ~STATUS_ASSOCIATING;
8439
priv->status |= STATUS_ASSOCIATED;
8440
netif_carrier_on(priv->net_dev);
8441
netif_wake_queue(priv->net_dev);
8444
if (!(priv->status & STATUS_ASSOCIATED)) {
8445
IPW_DEBUG_WX("Configuring ESSID\n");
8446
mutex_lock(&priv->action_mutex);
8447
/* This is a disassociation event, so kick the firmware to
8448
* look for another AP */
8449
if (priv->config & CFG_STATIC_ESSID)
8450
ipw2100_set_essid(priv, priv->essid, priv->essid_len,
8453
ipw2100_set_essid(priv, NULL, 0, 0);
8454
mutex_unlock(&priv->action_mutex);
8457
wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
8460
#define IPW2100_FW_MAJOR_VERSION 1
8461
#define IPW2100_FW_MINOR_VERSION 3
8463
#define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
8464
#define IPW2100_FW_MAJOR(x) (x & 0xff)
8466
#define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
8467
IPW2100_FW_MAJOR_VERSION)
8469
#define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
8470
"." __stringify(IPW2100_FW_MINOR_VERSION)
8472
#define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
8476
BINARY FIRMWARE HEADER FORMAT
8480
2 2 mode == 0:BSS,1:IBSS,2:MONITOR
8483
C fw_len firmware data
8484
12 + fw_len uc_len microcode data
8488
struct ipw2100_fw_header {
8491
unsigned int fw_size;
8492
unsigned int uc_size;
8493
} __attribute__ ((packed));
8495
static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw)
8497
struct ipw2100_fw_header *h =
8498
(struct ipw2100_fw_header *)fw->fw_entry->data;
8500
if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) {
8501
printk(KERN_WARNING DRV_NAME ": Firmware image not compatible "
8502
"(detected version id of %u). "
8503
"See Documentation/networking/README.ipw2100\n",
8508
fw->version = h->version;
8509
fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header);
8510
fw->fw.size = h->fw_size;
8511
fw->uc.data = fw->fw.data + h->fw_size;
8512
fw->uc.size = h->uc_size;
8517
static int ipw2100_get_firmware(struct ipw2100_priv *priv,
8518
struct ipw2100_fw *fw)
8523
IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
8524
priv->net_dev->name);
8526
switch (priv->ieee->iw_mode) {
8528
fw_name = IPW2100_FW_NAME("-i");
8530
#ifdef CONFIG_IPW2100_MONITOR
8531
case IW_MODE_MONITOR:
8532
fw_name = IPW2100_FW_NAME("-p");
8537
fw_name = IPW2100_FW_NAME("");
8541
rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev);
8544
printk(KERN_ERR DRV_NAME ": "
8545
"%s: Firmware '%s' not available or load failed.\n",
8546
priv->net_dev->name, fw_name);
8549
IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data,
8550
fw->fw_entry->size);
8552
ipw2100_mod_firmware_load(fw);
8557
MODULE_FIRMWARE(IPW2100_FW_NAME("-i"));
8558
#ifdef CONFIG_IPW2100_MONITOR
8559
MODULE_FIRMWARE(IPW2100_FW_NAME("-p"));
8561
MODULE_FIRMWARE(IPW2100_FW_NAME(""));
8563
static void ipw2100_release_firmware(struct ipw2100_priv *priv,
8564
struct ipw2100_fw *fw)
8568
release_firmware(fw->fw_entry);
8569
fw->fw_entry = NULL;
8572
static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
8575
char ver[MAX_FW_VERSION_LEN];
8576
u32 len = MAX_FW_VERSION_LEN;
8579
/* firmware version is an ascii string (max len of 14) */
8580
if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM, ver, &len))
8585
for (i = 0; i < len; i++)
8591
static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
8595
u32 len = sizeof(ver);
8596
/* microcode version is a 32 bit integer */
8597
if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION, &ver, &len))
8599
return snprintf(buf, max, "%08X", ver);
8603
* On exit, the firmware will have been freed from the fw list
8605
static int ipw2100_fw_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
8607
/* firmware is constructed of N contiguous entries, each entry is
8611
* 0 4 address to write to
8612
* 4 2 length of data run
8618
const unsigned char *firmware_data = fw->fw.data;
8619
unsigned int firmware_data_left = fw->fw.size;
8621
while (firmware_data_left > 0) {
8622
addr = *(u32 *) (firmware_data);
8624
firmware_data_left -= 4;
8626
len = *(u16 *) (firmware_data);
8628
firmware_data_left -= 2;
8631
printk(KERN_ERR DRV_NAME ": "
8632
"Invalid firmware run-length of %d bytes\n",
8637
write_nic_memory(priv->net_dev, addr, len, firmware_data);
8638
firmware_data += len;
8639
firmware_data_left -= len;
8645
struct symbol_alive_response {
8654
u16 clock_settle_time; // 1us LSB
8655
u16 powerup_settle_time; // 1us LSB
8656
u16 hop_settle_time; // 1us LSB
8657
u8 date[3]; // month, day, year
8658
u8 time[2]; // hours, minutes
8662
static int ipw2100_ucode_download(struct ipw2100_priv *priv,
8663
struct ipw2100_fw *fw)
8665
struct net_device *dev = priv->net_dev;
8666
const unsigned char *microcode_data = fw->uc.data;
8667
unsigned int microcode_data_left = fw->uc.size;
8668
void __iomem *reg = (void __iomem *)dev->base_addr;
8670
struct symbol_alive_response response;
8674
/* Symbol control */
8675
write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8677
write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8681
write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8683
write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
8686
/* EN_CS_ACCESS bit to reset control store pointer */
8687
write_nic_byte(dev, 0x210000, 0x40);
8689
write_nic_byte(dev, 0x210000, 0x0);
8691
write_nic_byte(dev, 0x210000, 0x40);
8694
/* copy microcode from buffer into Symbol */
8696
while (microcode_data_left > 0) {
8697
write_nic_byte(dev, 0x210010, *microcode_data++);
8698
write_nic_byte(dev, 0x210010, *microcode_data++);
8699
microcode_data_left -= 2;
8702
/* EN_CS_ACCESS bit to reset the control store pointer */
8703
write_nic_byte(dev, 0x210000, 0x0);
8706
/* Enable System (Reg 0)
8707
* first enable causes garbage in RX FIFO */
8708
write_nic_byte(dev, 0x210000, 0x0);
8710
write_nic_byte(dev, 0x210000, 0x80);
8713
/* Reset External Baseband Reg */
8714
write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
8716
write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
8719
/* HW Config (Reg 5) */
8720
write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8722
write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
8725
/* Enable System (Reg 0)
8726
* second enable should be OK */
8727
write_nic_byte(dev, 0x210000, 0x00); // clear enable system
8729
write_nic_byte(dev, 0x210000, 0x80); // set enable system
8731
/* check Symbol is enabled - upped this from 5 as it wasn't always
8732
* catching the update */
8733
for (i = 0; i < 10; i++) {
8736
/* check Dino is enabled bit */
8737
read_nic_byte(dev, 0x210000, &data);
8743
printk(KERN_ERR DRV_NAME ": %s: Error initializing Symbol\n",
8748
/* Get Symbol alive response */
8749
for (i = 0; i < 30; i++) {
8750
/* Read alive response structure */
8752
j < (sizeof(struct symbol_alive_response) >> 1); j++)
8753
read_nic_word(dev, 0x210004, ((u16 *) & response) + j);
8755
if ((response.cmd_id == 1) && (response.ucode_valid == 0x1))
8761
printk(KERN_ERR DRV_NAME
8762
": %s: No response from Symbol - hw not alive\n",
8764
printk_buf(IPW_DL_ERROR, (u8 *) & response, sizeof(response));