1
/******************************************************************************
3
Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved.
5
802.11 status code portion of this file from ethereal-0.10.6:
6
Copyright 2000, Axis Communications AB
7
Ethereal - Network traffic analyzer
8
By Gerald Combs <gerald@ethereal.com>
9
Copyright 1998 Gerald Combs
11
This program is free software; you can redistribute it and/or modify it
12
under the terms of version 2 of the GNU General Public License as
13
published by the Free Software Foundation.
15
This program is distributed in the hope that it will be useful, but WITHOUT
16
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20
You should have received a copy of the GNU General Public License along with
21
this program; if not, write to the Free Software Foundation, Inc., 59
22
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
The full GNU General Public License is included in this distribution in the
28
James P. Ketrenos <ipw2100-admin@linux.intel.com>
29
Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31
******************************************************************************/
34
#include <linux/version.h>
43
#ifdef CONFIG_IPW2200_DEBUG
49
#ifdef CONFIG_IPW2200_MONITOR
55
#ifdef CONFIG_IPW2200_PROMISCUOUS
61
#ifdef CONFIG_IPW2200_RADIOTAP
67
#ifdef CONFIG_IPW2200_QOS
73
#define IPW2200_VERSION "1.2.1" VK VD VM VP VR VQ
74
#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
75
#define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
76
#define DRV_VERSION IPW2200_VERSION
78
#define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
80
MODULE_DESCRIPTION(DRV_DESCRIPTION);
81
MODULE_VERSION(DRV_VERSION);
82
MODULE_AUTHOR(DRV_COPYRIGHT);
83
MODULE_LICENSE("GPL");
85
static int cmdlog = 0;
87
static int channel = 0;
90
static u32 ipw_debug_level;
91
static int associate = 1;
92
static int auto_create = 1;
94
static int disable = 0;
95
static int bt_coexist = 0;
96
static int hwcrypto = 0;
97
static int roaming = 1;
98
static const char ipw_modes[] = {
101
static int antenna = CFG_SYS_ANTENNA_BOTH;
103
#ifdef CONFIG_IPW2200_PROMISCUOUS
104
static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */
108
#ifdef CONFIG_IPW2200_QOS
109
static int qos_enable = 0;
110
static int qos_burst_enable = 0;
111
static int qos_no_ack_mask = 0;
112
static int burst_duration_CCK = 0;
113
static int burst_duration_OFDM = 0;
115
static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
116
{QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
117
QOS_TX3_CW_MIN_OFDM},
118
{QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
119
QOS_TX3_CW_MAX_OFDM},
120
{QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
121
{QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
122
{QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
123
QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
126
static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
127
{QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
129
{QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
131
{QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
132
{QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
133
{QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
134
QOS_TX3_TXOP_LIMIT_CCK}
137
static struct ieee80211_qos_parameters def_parameters_OFDM = {
138
{DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
139
DEF_TX3_CW_MIN_OFDM},
140
{DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
141
DEF_TX3_CW_MAX_OFDM},
142
{DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
143
{DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
144
{DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
145
DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
148
static struct ieee80211_qos_parameters def_parameters_CCK = {
149
{DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
151
{DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
153
{DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
154
{DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
155
{DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
156
DEF_TX3_TXOP_LIMIT_CCK}
159
static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
161
static int from_priority_to_tx_queue[] = {
162
IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
163
IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
166
static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
168
static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
170
static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
172
#endif /* CONFIG_IPW2200_QOS */
174
static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
175
static void ipw_remove_current_network(struct ipw_priv *priv);
176
static void ipw_rx(struct ipw_priv *priv);
177
static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
178
struct clx2_tx_queue *txq, int qindex);
179
static int ipw_queue_reset(struct ipw_priv *priv);
181
static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
184
static void ipw_tx_queue_free(struct ipw_priv *);
186
static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
187
static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
188
static void ipw_rx_queue_replenish(void *);
189
static int ipw_up(struct ipw_priv *);
190
static void ipw_down(struct ipw_priv *);
191
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
192
static void ipw_bg_up(void *work);
193
static void ipw_bg_down(void *work);
195
static void ipw_bg_up(struct work_struct *work);
196
static void ipw_bg_down(struct work_struct *work);
198
static int ipw_config(struct ipw_priv *);
199
static int init_supported_rates(struct ipw_priv *priv,
200
struct ipw_supported_rates *prates);
201
static void ipw_set_hwcrypto_keys(struct ipw_priv *);
202
static void ipw_send_wep_keys(struct ipw_priv *, int);
204
static inline int ipw_is_multicast_ether_addr(const u8 * addr)
206
return (0x01 & addr[0]);
209
static int snprint_line(char *buf, size_t count,
210
const u8 * data, u32 len, u32 ofs)
215
out = snprintf(buf, count, "%08X", ofs);
217
for (l = 0, i = 0; i < 2; i++) {
218
out += snprintf(buf + out, count - out, " ");
219
for (j = 0; j < 8 && l < len; j++, l++)
220
out += snprintf(buf + out, count - out, "%02X ",
223
out += snprintf(buf + out, count - out, " ");
226
out += snprintf(buf + out, count - out, " ");
227
for (l = 0, i = 0; i < 2; i++) {
228
out += snprintf(buf + out, count - out, " ");
229
for (j = 0; j < 8 && l < len; j++, l++) {
230
c = data[(i * 8 + j)];
231
if (!isascii(c) || !isprint(c))
234
out += snprintf(buf + out, count - out, "%c", c);
238
out += snprintf(buf + out, count - out, " ");
244
static void printk_buf(int level, const u8 * data, u32 len)
248
if (!(ipw_debug_level & level))
252
snprint_line(line, sizeof(line), &data[ofs],
254
printk(KERN_DEBUG "%s\n", line);
256
len -= min(len, 16U);
260
static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
266
while (size && len) {
267
out = snprint_line(output, size, &data[ofs],
268
min_t(size_t, len, 16U), ofs);
273
len -= min_t(size_t, len, 16U);
279
/* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
280
static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
281
#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
283
/* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
284
static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
285
#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
287
/* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
288
static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
289
static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
291
IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
292
__LINE__, (u32) (b), (u32) (c));
293
_ipw_write_reg8(a, b, c);
296
/* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
297
static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
298
static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
300
IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
301
__LINE__, (u32) (b), (u32) (c));
302
_ipw_write_reg16(a, b, c);
305
/* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
306
static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
307
static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
309
IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
310
__LINE__, (u32) (b), (u32) (c));
311
_ipw_write_reg32(a, b, c);
314
/* 8-bit direct write (low 4K) */
315
#define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
317
/* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
318
#define ipw_write8(ipw, ofs, val) \
319
IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
320
_ipw_write8(ipw, ofs, val)
322
/* 16-bit direct write (low 4K) */
323
#define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
325
/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
326
#define ipw_write16(ipw, ofs, val) \
327
IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
328
_ipw_write16(ipw, ofs, val)
330
/* 32-bit direct write (low 4K) */
331
#define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
333
/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
334
#define ipw_write32(ipw, ofs, val) \
335
IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
336
_ipw_write32(ipw, ofs, val)
338
/* 8-bit direct read (low 4K) */
339
#define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
341
/* 8-bit direct read (low 4K), with debug wrapper */
342
static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
344
IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
345
return _ipw_read8(ipw, ofs);
348
/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
349
#define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
351
/* 16-bit direct read (low 4K) */
352
#define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
354
/* 16-bit direct read (low 4K), with debug wrapper */
355
static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
357
IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
358
return _ipw_read16(ipw, ofs);
361
/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
362
#define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
364
/* 32-bit direct read (low 4K) */
365
#define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
367
/* 32-bit direct read (low 4K), with debug wrapper */
368
static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
370
IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
371
return _ipw_read32(ipw, ofs);
374
/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
375
#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
377
/* multi-byte read (above 4K), with debug wrapper */
378
static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
379
static inline void __ipw_read_indirect(const char *f, int l,
380
struct ipw_priv *a, u32 b, u8 * c, int d)
382
IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
384
_ipw_read_indirect(a, b, c, d);
387
/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
388
#define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
390
/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
391
static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
393
#define ipw_write_indirect(a, b, c, d) \
394
IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
395
_ipw_write_indirect(a, b, c, d)
397
/* 32-bit indirect write (above 4K) */
398
static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
400
IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
401
_ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
402
_ipw_write32(priv, IPW_INDIRECT_DATA, value);
405
/* 8-bit indirect write (above 4K) */
406
static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
408
u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
409
u32 dif_len = reg - aligned_addr;
411
IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
412
_ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
413
_ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
416
/* 16-bit indirect write (above 4K) */
417
static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
419
u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
420
u32 dif_len = (reg - aligned_addr) & (~0x1ul);
422
IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
423
_ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
424
_ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
427
/* 8-bit indirect read (above 4K) */
428
static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
431
_ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
432
IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
433
word = _ipw_read32(priv, IPW_INDIRECT_DATA);
434
return (word >> ((reg & 0x3) * 8)) & 0xff;
437
/* 32-bit indirect read (above 4K) */
438
static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
442
IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
444
_ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
445
value = _ipw_read32(priv, IPW_INDIRECT_DATA);
446
IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
450
/* General purpose, no alignment requirement, iterative (multi-byte) read, */
451
/* for area above 1st 4K of SRAM/reg space */
452
static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
455
u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
456
u32 dif_len = addr - aligned_addr;
459
IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
465
/* Read the first dword (or portion) byte by byte */
466
if (unlikely(dif_len)) {
467
_ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
468
/* Start reading at aligned_addr + dif_len */
469
for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
470
*buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
474
/* Read all of the middle dwords as dwords, with auto-increment */
475
_ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
476
for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
477
*(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
479
/* Read the last dword (or portion) byte by byte */
481
_ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
482
for (i = 0; num > 0; i++, num--)
483
*buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
487
/* General purpose, no alignment requirement, iterative (multi-byte) write, */
488
/* for area above 1st 4K of SRAM/reg space */
489
static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
492
u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
493
u32 dif_len = addr - aligned_addr;
496
IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
502
/* Write the first dword (or portion) byte by byte */
503
if (unlikely(dif_len)) {
504
_ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
505
/* Start writing at aligned_addr + dif_len */
506
for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
507
_ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
511
/* Write all of the middle dwords as dwords, with auto-increment */
512
_ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
513
for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
514
_ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
516
/* Write the last dword (or portion) byte by byte */
518
_ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
519
for (i = 0; num > 0; i++, num--, buf++)
520
_ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
524
/* General purpose, no alignment requirement, iterative (multi-byte) write, */
525
/* for 1st 4K of SRAM/regs space */
526
static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
529
memcpy_toio((priv->hw_base + addr), buf, num);
532
/* Set bit(s) in low 4K of SRAM/regs */
533
static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
535
ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
538
/* Clear bit(s) in low 4K of SRAM/regs */
539
static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
541
ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
544
static inline void __ipw_enable_interrupts(struct ipw_priv *priv)
546
if (priv->status & STATUS_INT_ENABLED)
548
priv->status |= STATUS_INT_ENABLED;
549
ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
552
static inline void __ipw_disable_interrupts(struct ipw_priv *priv)
554
if (!(priv->status & STATUS_INT_ENABLED))
556
priv->status &= ~STATUS_INT_ENABLED;
557
ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
560
static inline void ipw_enable_interrupts(struct ipw_priv *priv)
564
spin_lock_irqsave(&priv->irq_lock, flags);
565
__ipw_enable_interrupts(priv);
566
spin_unlock_irqrestore(&priv->irq_lock, flags);
569
static inline void ipw_disable_interrupts(struct ipw_priv *priv)
573
spin_lock_irqsave(&priv->irq_lock, flags);
574
__ipw_disable_interrupts(priv);
575
spin_unlock_irqrestore(&priv->irq_lock, flags);
578
static char *ipw_error_desc(u32 val)
581
case IPW_FW_ERROR_OK:
583
case IPW_FW_ERROR_FAIL:
585
case IPW_FW_ERROR_MEMORY_UNDERFLOW:
586
return "MEMORY_UNDERFLOW";
587
case IPW_FW_ERROR_MEMORY_OVERFLOW:
588
return "MEMORY_OVERFLOW";
589
case IPW_FW_ERROR_BAD_PARAM:
591
case IPW_FW_ERROR_BAD_CHECKSUM:
592
return "BAD_CHECKSUM";
593
case IPW_FW_ERROR_NMI_INTERRUPT:
594
return "NMI_INTERRUPT";
595
case IPW_FW_ERROR_BAD_DATABASE:
596
return "BAD_DATABASE";
597
case IPW_FW_ERROR_ALLOC_FAIL:
599
case IPW_FW_ERROR_DMA_UNDERRUN:
600
return "DMA_UNDERRUN";
601
case IPW_FW_ERROR_DMA_STATUS:
603
case IPW_FW_ERROR_DINO_ERROR:
605
case IPW_FW_ERROR_EEPROM_ERROR:
606
return "EEPROM_ERROR";
607
case IPW_FW_ERROR_SYSASSERT:
609
case IPW_FW_ERROR_FATAL_ERROR:
610
return "FATAL_ERROR";
612
return "UNKNOWN_ERROR";
616
static void ipw_dump_error_log(struct ipw_priv *priv,
617
struct ipw_fw_error *error)
622
IPW_ERROR("Error allocating and capturing error log. "
623
"Nothing to dump.\n");
627
IPW_ERROR("Start IPW Error Log Dump:\n");
628
IPW_ERROR("Status: 0x%08X, Config: %08X\n",
629
error->status, error->config);
631
for (i = 0; i < error->elem_len; i++)
632
IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
633
ipw_error_desc(error->elem[i].desc),
635
error->elem[i].blink1,
636
error->elem[i].blink2,
637
error->elem[i].link1,
638
error->elem[i].link2, error->elem[i].data);
639
for (i = 0; i < error->log_len; i++)
640
IPW_ERROR("%i\t0x%08x\t%i\n",
642
error->log[i].data, error->log[i].event);
645
static inline int ipw_is_init(struct ipw_priv *priv)
647
return (priv->status & STATUS_INIT) ? 1 : 0;
652
static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
654
u32 addr, field_info, field_len, field_count, total_len;
656
IPW_DEBUG_ORD("ordinal = %i\n", ord);
658
if (!priv || !val || !len) {
659
IPW_DEBUG_ORD("Invalid argument\n");
663
/* verify device ordinal tables have been initialized */
664
if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
665
IPW_DEBUG_ORD("Access ordinals before initialization\n");
669
switch (IPW_ORD_TABLE_ID_MASK & ord) {
670
case IPW_ORD_TABLE_0_MASK:
672
* TABLE 0: Direct access to a table of 32 bit values
674
* This is a very simple table with the data directly
675
* read from the table
678
/* remove the table id from the ordinal */
679
ord &= IPW_ORD_TABLE_VALUE_MASK;
682
if (ord > priv->table0_len) {
683
IPW_DEBUG_ORD("ordinal value (%i) longer then "
684
"max (%i)\n", ord, priv->table0_len);
688
/* verify we have enough room to store the value */
689
if (*len < sizeof(u32)) {
690
IPW_DEBUG_ORD("ordinal buffer length too small, "
691
"need %zd\n", sizeof(u32));
695
IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
696
ord, priv->table0_addr + (ord << 2));
700
*((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
703
case IPW_ORD_TABLE_1_MASK:
705
* TABLE 1: Indirect access to a table of 32 bit values
707
* This is a fairly large table of u32 values each
708
* representing starting addr for the data (which is
712
/* remove the table id from the ordinal */
713
ord &= IPW_ORD_TABLE_VALUE_MASK;
716
if (ord > priv->table1_len) {
717
IPW_DEBUG_ORD("ordinal value too long\n");
721
/* verify we have enough room to store the value */
722
if (*len < sizeof(u32)) {
723
IPW_DEBUG_ORD("ordinal buffer length too small, "
724
"need %zd\n", sizeof(u32));
729
ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
733
case IPW_ORD_TABLE_2_MASK:
735
* TABLE 2: Indirect access to a table of variable sized values
737
* This table consist of six values, each containing
738
* - dword containing the starting offset of the data
739
* - dword containing the lengh in the first 16bits
740
* and the count in the second 16bits
743
/* remove the table id from the ordinal */
744
ord &= IPW_ORD_TABLE_VALUE_MASK;
747
if (ord > priv->table2_len) {
748
IPW_DEBUG_ORD("ordinal value too long\n");
752
/* get the address of statistic */
753
addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
755
/* get the second DW of statistics ;
756
* two 16-bit words - first is length, second is count */
759
priv->table2_addr + (ord << 3) +
762
/* get each entry length */
763
field_len = *((u16 *) & field_info);
765
/* get number of entries */
766
field_count = *(((u16 *) & field_info) + 1);
768
/* abort if not enought memory */
769
total_len = field_len * field_count;
770
if (total_len > *len) {
779
IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
780
"field_info = 0x%08x\n",
781
addr, total_len, field_info);
782
ipw_read_indirect(priv, addr, val, total_len);
786
IPW_DEBUG_ORD("Invalid ordinal!\n");
794
static void ipw_init_ordinals(struct ipw_priv *priv)
796
priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
797
priv->table0_len = ipw_read32(priv, priv->table0_addr);
799
IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
800
priv->table0_addr, priv->table0_len);
802
priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
803
priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
805
IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
806
priv->table1_addr, priv->table1_len);
808
priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
809
priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
810
priv->table2_len &= 0x0000ffff; /* use first two bytes */
812
IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
813
priv->table2_addr, priv->table2_len);
817
static u32 ipw_register_toggle(u32 reg)
819
reg &= ~IPW_START_STANDBY;
820
if (reg & IPW_GATE_ODMA)
821
reg &= ~IPW_GATE_ODMA;
822
if (reg & IPW_GATE_IDMA)
823
reg &= ~IPW_GATE_IDMA;
824
if (reg & IPW_GATE_ADMA)
825
reg &= ~IPW_GATE_ADMA;
831
* - On radio ON, turn on any LEDs that require to be on during start
832
* - On initialization, start unassociated blink
833
* - On association, disable unassociated blink
834
* - On disassociation, start unassociated blink
835
* - On radio OFF, turn off any LEDs started during radio on
838
#define LD_TIME_LINK_ON msecs_to_jiffies(300)
839
#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
840
#define LD_TIME_ACT_ON msecs_to_jiffies(250)
842
static void ipw_led_link_on(struct ipw_priv *priv)
847
/* If configured to not use LEDs, or nic_type is 1,
848
* then we don't toggle a LINK led */
849
if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
852
spin_lock_irqsave(&priv->lock, flags);
854
if (!(priv->status & STATUS_RF_KILL_MASK) &&
855
!(priv->status & STATUS_LED_LINK_ON)) {
856
IPW_DEBUG_LED("Link LED On\n");
857
led = ipw_read_reg32(priv, IPW_EVENT_REG);
858
led |= priv->led_association_on;
860
led = ipw_register_toggle(led);
862
IPW_DEBUG_LED("Reg: 0x%08X\n", led);
863
ipw_write_reg32(priv, IPW_EVENT_REG, led);
865
priv->status |= STATUS_LED_LINK_ON;
867
/* If we aren't associated, schedule turning the LED off */
868
if (!(priv->status & STATUS_ASSOCIATED))
869
queue_delayed_work(priv->workqueue,
874
spin_unlock_irqrestore(&priv->lock, flags);
877
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
878
static void ipw_bg_led_link_on(void *work)
880
struct ipw_priv *priv = work;
882
static void ipw_bg_led_link_on(struct work_struct *work)
884
struct ipw_priv *priv =
885
container_of(work, struct ipw_priv, led_link_on.work);
887
mutex_lock(&priv->mutex);
888
ipw_led_link_on(priv);
889
mutex_unlock(&priv->mutex);
892
static void ipw_led_link_off(struct ipw_priv *priv)
897
/* If configured not to use LEDs, or nic type is 1,
898
* then we don't goggle the LINK led. */
899
if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
902
spin_lock_irqsave(&priv->lock, flags);
904
if (priv->status & STATUS_LED_LINK_ON) {
905
led = ipw_read_reg32(priv, IPW_EVENT_REG);
906
led &= priv->led_association_off;
907
led = ipw_register_toggle(led);
909
IPW_DEBUG_LED("Reg: 0x%08X\n", led);
910
ipw_write_reg32(priv, IPW_EVENT_REG, led);
912
IPW_DEBUG_LED("Link LED Off\n");
914
priv->status &= ~STATUS_LED_LINK_ON;
916
/* If we aren't associated and the radio is on, schedule
917
* turning the LED on (blink while unassociated) */
918
if (!(priv->status & STATUS_RF_KILL_MASK) &&
919
!(priv->status & STATUS_ASSOCIATED))
920
queue_delayed_work(priv->workqueue, &priv->led_link_on,
925
spin_unlock_irqrestore(&priv->lock, flags);
928
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
929
static void ipw_bg_led_link_off(void *work)
931
struct ipw_priv *priv = work;
933
static void ipw_bg_led_link_off(struct work_struct *work)
935
struct ipw_priv *priv =
936
container_of(work, struct ipw_priv, led_link_off.work);
938
mutex_lock(&priv->mutex);
939
ipw_led_link_off(priv);
940
mutex_unlock(&priv->mutex);
943
static void __ipw_led_activity_on(struct ipw_priv *priv)
947
if (priv->config & CFG_NO_LED)
950
if (priv->status & STATUS_RF_KILL_MASK)
953
if (!(priv->status & STATUS_LED_ACT_ON)) {
954
led = ipw_read_reg32(priv, IPW_EVENT_REG);
955
led |= priv->led_activity_on;
957
led = ipw_register_toggle(led);
959
IPW_DEBUG_LED("Reg: 0x%08X\n", led);
960
ipw_write_reg32(priv, IPW_EVENT_REG, led);
962
IPW_DEBUG_LED("Activity LED On\n");
964
priv->status |= STATUS_LED_ACT_ON;
966
cancel_delayed_work(&priv->led_act_off);
967
queue_delayed_work(priv->workqueue, &priv->led_act_off,
970
/* Reschedule LED off for full time period */
971
cancel_delayed_work(&priv->led_act_off);
972
queue_delayed_work(priv->workqueue, &priv->led_act_off,
978
void ipw_led_activity_on(struct ipw_priv *priv)
981
spin_lock_irqsave(&priv->lock, flags);
982
__ipw_led_activity_on(priv);
983
spin_unlock_irqrestore(&priv->lock, flags);
987
static void ipw_led_activity_off(struct ipw_priv *priv)
992
if (priv->config & CFG_NO_LED)
995
spin_lock_irqsave(&priv->lock, flags);
997
if (priv->status & STATUS_LED_ACT_ON) {
998
led = ipw_read_reg32(priv, IPW_EVENT_REG);
999
led &= priv->led_activity_off;
1001
led = ipw_register_toggle(led);
1003
IPW_DEBUG_LED("Reg: 0x%08X\n", led);
1004
ipw_write_reg32(priv, IPW_EVENT_REG, led);
1006
IPW_DEBUG_LED("Activity LED Off\n");
1008
priv->status &= ~STATUS_LED_ACT_ON;
1011
spin_unlock_irqrestore(&priv->lock, flags);
1014
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
1015
static void ipw_bg_led_activity_off(void *work)
1017
struct ipw_priv *priv = work;
1019
static void ipw_bg_led_activity_off(struct work_struct *work)
1021
struct ipw_priv *priv =
1022
container_of(work, struct ipw_priv, led_act_off.work);
1024
mutex_lock(&priv->mutex);
1025
ipw_led_activity_off(priv);
1026
mutex_unlock(&priv->mutex);
1029
static void ipw_led_band_on(struct ipw_priv *priv)
1031
unsigned long flags;
1034
/* Only nic type 1 supports mode LEDs */
1035
if (priv->config & CFG_NO_LED ||
1036
priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
1039
spin_lock_irqsave(&priv->lock, flags);
1041
led = ipw_read_reg32(priv, IPW_EVENT_REG);
1042
if (priv->assoc_network->mode == IEEE_A) {
1043
led |= priv->led_ofdm_on;
1044
led &= priv->led_association_off;
1045
IPW_DEBUG_LED("Mode LED On: 802.11a\n");
1046
} else if (priv->assoc_network->mode == IEEE_G) {
1047
led |= priv->led_ofdm_on;
1048
led |= priv->led_association_on;
1049
IPW_DEBUG_LED("Mode LED On: 802.11g\n");
1051
led &= priv->led_ofdm_off;
1052
led |= priv->led_association_on;
1053
IPW_DEBUG_LED("Mode LED On: 802.11b\n");
1056
led = ipw_register_toggle(led);
1058
IPW_DEBUG_LED("Reg: 0x%08X\n", led);
1059
ipw_write_reg32(priv, IPW_EVENT_REG, led);
1061
spin_unlock_irqrestore(&priv->lock, flags);
1064
static void ipw_led_band_off(struct ipw_priv *priv)
1066
unsigned long flags;
1069
/* Only nic type 1 supports mode LEDs */
1070
if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
1073
spin_lock_irqsave(&priv->lock, flags);
1075
led = ipw_read_reg32(priv, IPW_EVENT_REG);
1076
led &= priv->led_ofdm_off;
1077
led &= priv->led_association_off;
1079
led = ipw_register_toggle(led);
1081
IPW_DEBUG_LED("Reg: 0x%08X\n", led);
1082
ipw_write_reg32(priv, IPW_EVENT_REG, led);
1084
spin_unlock_irqrestore(&priv->lock, flags);
1087
static void ipw_led_radio_on(struct ipw_priv *priv)
1089
ipw_led_link_on(priv);
1092
static void ipw_led_radio_off(struct ipw_priv *priv)
1094
ipw_led_activity_off(priv);
1095
ipw_led_link_off(priv);
1098
static void ipw_led_link_up(struct ipw_priv *priv)
1100
/* Set the Link Led on for all nic types */
1101
ipw_led_link_on(priv);
1104
static void ipw_led_link_down(struct ipw_priv *priv)
1106
ipw_led_activity_off(priv);
1107
ipw_led_link_off(priv);
1109
if (priv->status & STATUS_RF_KILL_MASK)
1110
ipw_led_radio_off(priv);
1113
static void ipw_led_init(struct ipw_priv *priv)
1115
priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1117
/* Set the default PINs for the link and activity leds */
1118
priv->led_activity_on = IPW_ACTIVITY_LED;
1119
priv->led_activity_off = ~(IPW_ACTIVITY_LED);
1121
priv->led_association_on = IPW_ASSOCIATED_LED;
1122
priv->led_association_off = ~(IPW_ASSOCIATED_LED);
1124
/* Set the default PINs for the OFDM leds */
1125
priv->led_ofdm_on = IPW_OFDM_LED;
1126
priv->led_ofdm_off = ~(IPW_OFDM_LED);
1128
switch (priv->nic_type) {
1129
case EEPROM_NIC_TYPE_1:
1130
/* In this NIC type, the LEDs are reversed.... */
1131
priv->led_activity_on = IPW_ASSOCIATED_LED;
1132
priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1133
priv->led_association_on = IPW_ACTIVITY_LED;
1134
priv->led_association_off = ~(IPW_ACTIVITY_LED);
1136
if (!(priv->config & CFG_NO_LED))
1137
ipw_led_band_on(priv);
1139
/* And we don't blink link LEDs for this nic, so
1140
* just return here */
1143
case EEPROM_NIC_TYPE_3:
1144
case EEPROM_NIC_TYPE_2:
1145
case EEPROM_NIC_TYPE_4:
1146
case EEPROM_NIC_TYPE_0:
1150
IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1152
priv->nic_type = EEPROM_NIC_TYPE_0;
1156
if (!(priv->config & CFG_NO_LED)) {
1157
if (priv->status & STATUS_ASSOCIATED)
1158
ipw_led_link_on(priv);
1160
ipw_led_link_off(priv);
1164
static void ipw_led_shutdown(struct ipw_priv *priv)
1166
ipw_led_activity_off(priv);
1167
ipw_led_link_off(priv);
1168
ipw_led_band_off(priv);
1169
cancel_delayed_work(&priv->led_link_on);
1170
cancel_delayed_work(&priv->led_link_off);
1171
cancel_delayed_work(&priv->led_act_off);
1175
* The following adds a new attribute to the sysfs representation
1176
* of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1177
* used for controling the debug level.
1179
* See the level definitions in ipw for details.
1181
static ssize_t show_debug_level(struct device_driver *d, char *buf)
1183
return sprintf(buf, "0x%08X\n", ipw_debug_level);
1186
static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1189
char *p = (char *)buf;
1192
if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1194
if (p[0] == 'x' || p[0] == 'X')
1196
val = simple_strtoul(p, &p, 16);
1198
val = simple_strtoul(p, &p, 10);
1200
printk(KERN_INFO DRV_NAME
1201
": %s is not in hex or decimal form.\n", buf);
1203
ipw_debug_level = val;
1205
return strnlen(buf, count);
1208
static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
1209
show_debug_level, store_debug_level);
1211
static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1213
/* length = 1st dword in log */
1214
return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1217
static void ipw_capture_event_log(struct ipw_priv *priv,
1218
u32 log_len, struct ipw_event *log)
1223
base = ipw_read32(priv, IPW_EVENT_LOG);
1224
ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1225
(u8 *) log, sizeof(*log) * log_len);
1229
static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1231
struct ipw_fw_error *error;
1232
u32 log_len = ipw_get_event_log_len(priv);
1233
u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1234
u32 elem_len = ipw_read_reg32(priv, base);
1236
error = kmalloc(sizeof(*error) +
1237
sizeof(*error->elem) * elem_len +
1238
sizeof(*error->log) * log_len, GFP_ATOMIC);
1240
IPW_ERROR("Memory allocation for firmware error log "
1244
error->jiffies = jiffies;
1245
error->status = priv->status;
1246
error->config = priv->config;
1247
error->elem_len = elem_len;
1248
error->log_len = log_len;
1249
error->elem = (struct ipw_error_elem *)error->payload;
1250
error->log = (struct ipw_event *)(error->elem + elem_len);
1252
ipw_capture_event_log(priv, log_len, error->log);
1255
ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1256
sizeof(*error->elem) * elem_len);
1261
static ssize_t show_event_log(struct device *d,
1262
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1263
struct device_attribute *attr,
1267
struct ipw_priv *priv = dev_get_drvdata(d);
1268
u32 log_len = ipw_get_event_log_len(priv);
1269
struct ipw_event log[log_len];
1272
ipw_capture_event_log(priv, log_len, log);
1274
len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1275
for (i = 0; i < log_len; i++)
1276
len += snprintf(buf + len, PAGE_SIZE - len,
1278
log[i].time, log[i].event, log[i].data);
1279
len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1283
static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1285
static ssize_t show_error(struct device *d,
1286
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1287
struct device_attribute *attr,
1291
struct ipw_priv *priv = dev_get_drvdata(d);
1295
len += snprintf(buf + len, PAGE_SIZE - len,
1296
"%08lX%08X%08X%08X",
1297
priv->error->jiffies,
1298
priv->error->status,
1299
priv->error->config, priv->error->elem_len);
1300
for (i = 0; i < priv->error->elem_len; i++)
1301
len += snprintf(buf + len, PAGE_SIZE - len,
1302
"\n%08X%08X%08X%08X%08X%08X%08X",
1303
priv->error->elem[i].time,
1304
priv->error->elem[i].desc,
1305
priv->error->elem[i].blink1,
1306
priv->error->elem[i].blink2,
1307
priv->error->elem[i].link1,
1308
priv->error->elem[i].link2,
1309
priv->error->elem[i].data);
1311
len += snprintf(buf + len, PAGE_SIZE - len,
1312
"\n%08X", priv->error->log_len);
1313
for (i = 0; i < priv->error->log_len; i++)
1314
len += snprintf(buf + len, PAGE_SIZE - len,
1316
priv->error->log[i].time,
1317
priv->error->log[i].event,
1318
priv->error->log[i].data);
1319
len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1323
static ssize_t clear_error(struct device *d,
1324
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1325
struct device_attribute *attr,
1327
const char *buf, size_t count)
1329
struct ipw_priv *priv = dev_get_drvdata(d);
1336
static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1338
static ssize_t show_cmd_log(struct device *d,
1339
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1340
struct device_attribute *attr,
1344
struct ipw_priv *priv = dev_get_drvdata(d);
1348
for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1349
(i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1350
i = (i + 1) % priv->cmdlog_len) {
1352
snprintf(buf + len, PAGE_SIZE - len,
1353
"\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1354
priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1355
priv->cmdlog[i].cmd.len);
1357
snprintk_buf(buf + len, PAGE_SIZE - len,
1358
(u8 *) priv->cmdlog[i].cmd.param,
1359
priv->cmdlog[i].cmd.len);
1360
len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1362
len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1366
static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1368
#ifdef CONFIG_IPW2200_PROMISCUOUS
1369
static void ipw_prom_free(struct ipw_priv *priv);
1370
static int ipw_prom_alloc(struct ipw_priv *priv);
1371
static ssize_t store_rtap_iface(struct device *d,
1372
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1373
struct device_attribute *attr,
1375
const char *buf, size_t count)
1377
struct ipw_priv *priv = dev_get_drvdata(d);
1388
if (netif_running(priv->prom_net_dev)) {
1389
IPW_WARNING("Interface is up. Cannot unregister.\n");
1393
ipw_prom_free(priv);
1401
rc = ipw_prom_alloc(priv);
1411
IPW_ERROR("Failed to register promiscuous network "
1412
"device (error %d).\n", rc);
1418
static ssize_t show_rtap_iface(struct device *d,
1419
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1420
struct device_attribute *attr,
1424
struct ipw_priv *priv = dev_get_drvdata(d);
1426
return sprintf(buf, "%s", priv->prom_net_dev->name);
1435
static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1438
static ssize_t store_rtap_filter(struct device *d,
1439
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1440
struct device_attribute *attr,
1442
const char *buf, size_t count)
1444
struct ipw_priv *priv = dev_get_drvdata(d);
1446
if (!priv->prom_priv) {
1447
IPW_ERROR("Attempting to set filter without "
1448
"rtap_iface enabled.\n");
1452
priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1454
IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1455
BIT_ARG16(priv->prom_priv->filter));
1460
static ssize_t show_rtap_filter(struct device *d,
1461
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1462
struct device_attribute *attr,
1466
struct ipw_priv *priv = dev_get_drvdata(d);
1467
return sprintf(buf, "0x%04X",
1468
priv->prom_priv ? priv->prom_priv->filter : 0);
1471
static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1475
static ssize_t show_scan_age(struct device *d,
1476
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1477
struct device_attribute *attr,
1481
struct ipw_priv *priv = dev_get_drvdata(d);
1482
return sprintf(buf, "%d\n", priv->ieee->scan_age);
1485
static ssize_t store_scan_age(struct device *d,
1486
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1487
struct device_attribute *attr,
1489
const char *buf, size_t count)
1491
struct ipw_priv *priv = dev_get_drvdata(d);
1492
struct net_device *dev = priv->net_dev;
1493
char buffer[] = "00000000";
1495
(sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1499
IPW_DEBUG_INFO("enter\n");
1501
strncpy(buffer, buf, len);
1504
if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1506
if (p[0] == 'x' || p[0] == 'X')
1508
val = simple_strtoul(p, &p, 16);
1510
val = simple_strtoul(p, &p, 10);
1512
IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1514
priv->ieee->scan_age = val;
1515
IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1518
IPW_DEBUG_INFO("exit\n");
1522
static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1524
static ssize_t show_led(struct device *d,
1525
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1526
struct device_attribute *attr,
1530
struct ipw_priv *priv = dev_get_drvdata(d);
1531
return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1534
static ssize_t store_led(struct device *d,
1535
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1536
struct device_attribute *attr,
1538
const char *buf, size_t count)
1540
struct ipw_priv *priv = dev_get_drvdata(d);
1542
IPW_DEBUG_INFO("enter\n");
1548
IPW_DEBUG_LED("Disabling LED control.\n");
1549
priv->config |= CFG_NO_LED;
1550
ipw_led_shutdown(priv);
1552
IPW_DEBUG_LED("Enabling LED control.\n");
1553
priv->config &= ~CFG_NO_LED;
1557
IPW_DEBUG_INFO("exit\n");
1561
static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1563
static ssize_t show_status(struct device *d,
1564
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1565
struct device_attribute *attr,
1569
struct ipw_priv *p = d->driver_data;
1570
return sprintf(buf, "0x%08x\n", (int)p->status);
1573
static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1575
static ssize_t show_cfg(struct device *d,
1576
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1577
struct device_attribute *attr,
1581
struct ipw_priv *p = d->driver_data;
1582
return sprintf(buf, "0x%08x\n", (int)p->config);
1585
static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1587
static ssize_t show_nic_type(struct device *d,
1588
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1589
struct device_attribute *attr,
1593
struct ipw_priv *priv = d->driver_data;
1594
return sprintf(buf, "TYPE: %d\n", priv->nic_type);
1597
static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1599
static ssize_t show_ucode_version(struct device *d,
1600
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1601
struct device_attribute *attr,
1605
u32 len = sizeof(u32), tmp = 0;
1606
struct ipw_priv *p = d->driver_data;
1608
if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
1611
return sprintf(buf, "0x%08x\n", tmp);
1614
static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
1616
static ssize_t show_rtc(struct device *d,
1617
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1618
struct device_attribute *attr,
1622
u32 len = sizeof(u32), tmp = 0;
1623
struct ipw_priv *p = d->driver_data;
1625
if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
1628
return sprintf(buf, "0x%08x\n", tmp);
1631
static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
1634
* Add a device attribute to view/control the delay between eeprom
1637
static ssize_t show_eeprom_delay(struct device *d,
1638
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1639
struct device_attribute *attr,
1643
int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
1644
return sprintf(buf, "%i\n", n);
1646
static ssize_t store_eeprom_delay(struct device *d,
1647
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1648
struct device_attribute *attr,
1650
const char *buf, size_t count)
1652
struct ipw_priv *p = d->driver_data;
1653
sscanf(buf, "%i", &p->eeprom_delay);
1654
return strnlen(buf, count);
1657
static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1658
show_eeprom_delay, store_eeprom_delay);
1660
static ssize_t show_command_event_reg(struct device *d,
1661
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1662
struct device_attribute *attr,
1667
struct ipw_priv *p = d->driver_data;
1669
reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
1670
return sprintf(buf, "0x%08x\n", reg);
1672
static ssize_t store_command_event_reg(struct device *d,
1673
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1674
struct device_attribute *attr,
1676
const char *buf, size_t count)
1679
struct ipw_priv *p = d->driver_data;
1681
sscanf(buf, "%x", ®);
1682
ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
1683
return strnlen(buf, count);
1686
static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1687
show_command_event_reg, store_command_event_reg);
1689
static ssize_t show_mem_gpio_reg(struct device *d,
1690
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1691
struct device_attribute *attr,
1696
struct ipw_priv *p = d->driver_data;
1698
reg = ipw_read_reg32(p, 0x301100);
1699
return sprintf(buf, "0x%08x\n", reg);
1701
static ssize_t store_mem_gpio_reg(struct device *d,
1702
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1703
struct device_attribute *attr,
1705
const char *buf, size_t count)
1708
struct ipw_priv *p = d->driver_data;
1710
sscanf(buf, "%x", ®);
1711
ipw_write_reg32(p, 0x301100, reg);
1712
return strnlen(buf, count);
1715
static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1716
show_mem_gpio_reg, store_mem_gpio_reg);
1718
static ssize_t show_indirect_dword(struct device *d,
1719
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1720
struct device_attribute *attr,
1725
struct ipw_priv *priv = d->driver_data;
1727
if (priv->status & STATUS_INDIRECT_DWORD)
1728
reg = ipw_read_reg32(priv, priv->indirect_dword);
1732
return sprintf(buf, "0x%08x\n", reg);
1734
static ssize_t store_indirect_dword(struct device *d,
1735
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1736
struct device_attribute *attr,
1738
const char *buf, size_t count)
1740
struct ipw_priv *priv = d->driver_data;
1742
sscanf(buf, "%x", &priv->indirect_dword);
1743
priv->status |= STATUS_INDIRECT_DWORD;
1744
return strnlen(buf, count);
1747
static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1748
show_indirect_dword, store_indirect_dword);
1750
static ssize_t show_indirect_byte(struct device *d,
1751
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1752
struct device_attribute *attr,
1757
struct ipw_priv *priv = d->driver_data;
1759
if (priv->status & STATUS_INDIRECT_BYTE)
1760
reg = ipw_read_reg8(priv, priv->indirect_byte);
1764
return sprintf(buf, "0x%02x\n", reg);
1766
static ssize_t store_indirect_byte(struct device *d,
1767
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1768
struct device_attribute *attr,
1770
const char *buf, size_t count)
1772
struct ipw_priv *priv = d->driver_data;
1774
sscanf(buf, "%x", &priv->indirect_byte);
1775
priv->status |= STATUS_INDIRECT_BYTE;
1776
return strnlen(buf, count);
1779
static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
1780
show_indirect_byte, store_indirect_byte);
1782
static ssize_t show_direct_dword(struct device *d,
1783
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1784
struct device_attribute *attr,
1789
struct ipw_priv *priv = d->driver_data;
1791
if (priv->status & STATUS_DIRECT_DWORD)
1792
reg = ipw_read32(priv, priv->direct_dword);
1796
return sprintf(buf, "0x%08x\n", reg);
1798
static ssize_t store_direct_dword(struct device *d,
1799
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1800
struct device_attribute *attr,
1802
const char *buf, size_t count)
1804
struct ipw_priv *priv = d->driver_data;
1806
sscanf(buf, "%x", &priv->direct_dword);
1807
priv->status |= STATUS_DIRECT_DWORD;
1808
return strnlen(buf, count);
1811
static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1812
show_direct_dword, store_direct_dword);
1814
static int rf_kill_active(struct ipw_priv *priv)
1816
if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1817
priv->status |= STATUS_RF_KILL_HW;
1819
priv->status &= ~STATUS_RF_KILL_HW;
1821
return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1824
static ssize_t show_rf_kill(struct device *d,
1825
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1826
struct device_attribute *attr,
1830
/* 0 - RF kill not enabled
1831
1 - SW based RF kill active (sysfs)
1832
2 - HW based RF kill active
1833
3 - Both HW and SW baed RF kill active */
1834
struct ipw_priv *priv = d->driver_data;
1835
int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
1836
(rf_kill_active(priv) ? 0x2 : 0x0);
1837
return sprintf(buf, "%i\n", val);
1840
static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1842
if ((disable_radio ? 1 : 0) ==
1843
((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
1846
IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1847
disable_radio ? "OFF" : "ON");
1849
if (disable_radio) {
1850
priv->status |= STATUS_RF_KILL_SW;
1852
if (priv->workqueue)
1853
cancel_delayed_work(&priv->request_scan);
1854
queue_work(priv->workqueue, &priv->down);
1856
priv->status &= ~STATUS_RF_KILL_SW;
1857
if (rf_kill_active(priv)) {
1858
IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1859
"disabled by HW switch\n");
1860
/* Make sure the RF_KILL check timer is running */
1861
cancel_delayed_work(&priv->rf_kill);
1862
queue_delayed_work(priv->workqueue, &priv->rf_kill,
1865
queue_work(priv->workqueue, &priv->up);
1871
static ssize_t store_rf_kill(struct device *d,
1872
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1873
struct device_attribute *attr,
1875
const char *buf, size_t count)
1877
struct ipw_priv *priv = d->driver_data;
1879
ipw_radio_kill_sw(priv, buf[0] == '1');
1884
static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
1886
static ssize_t show_speed_scan(struct device *d,
1887
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1888
struct device_attribute *attr,
1892
struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1893
int pos = 0, len = 0;
1894
if (priv->config & CFG_SPEED_SCAN) {
1895
while (priv->speed_scan[pos] != 0)
1896
len += sprintf(&buf[len], "%d ",
1897
priv->speed_scan[pos++]);
1898
return len + sprintf(&buf[len], "\n");
1901
return sprintf(buf, "0\n");
1904
static ssize_t store_speed_scan(struct device *d,
1905
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1906
struct device_attribute *attr,
1908
const char *buf, size_t count)
1910
struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1911
int channel, pos = 0;
1912
const char *p = buf;
1914
/* list of space separated channels to scan, optionally ending with 0 */
1915
while ((channel = simple_strtol(p, NULL, 0))) {
1916
if (pos == MAX_SPEED_SCAN - 1) {
1917
priv->speed_scan[pos] = 0;
1921
if (ipw_is_valid_channel(priv->ieee, channel))
1922
priv->speed_scan[pos++] = channel;
1924
IPW_WARNING("Skipping invalid channel request: %d\n",
1929
while (*p == ' ' || *p == '\t')
1934
priv->config &= ~CFG_SPEED_SCAN;
1936
priv->speed_scan_pos = 0;
1937
priv->config |= CFG_SPEED_SCAN;
1943
static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1946
static ssize_t show_net_stats(struct device *d,
1947
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1948
struct device_attribute *attr,
1952
struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1953
return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1956
static ssize_t store_net_stats(struct device *d,
1957
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12)
1958
struct device_attribute *attr,
1960
const char *buf, size_t count)
1962
struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1964
priv->config |= CFG_NET_STATS;
1966
priv->config &= ~CFG_NET_STATS;
1971
static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1972
show_net_stats, store_net_stats);
1974
static void notify_wx_assoc_event(struct ipw_priv *priv)
1976
union iwreq_data wrqu;
1977
wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1978
if (priv->status & STATUS_ASSOCIATED)
1979
memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1981
memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1982
wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1985
static void ipw_irq_tasklet(struct ipw_priv *priv)
1987
u32 inta, inta_mask, handled = 0;
1988
unsigned long flags;
1991
spin_lock_irqsave(&priv->irq_lock, flags);
1993
inta = ipw_read32(priv, IPW_INTA_RW);
1994
inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1995
inta &= (IPW_INTA_MASK_ALL & inta_mask);
1997
/* Add any cached INTA values that need to be handled */
1998
inta |= priv->isr_inta;
2000
spin_unlock_irqrestore(&priv->irq_lock, flags);
2002
spin_lock_irqsave(&priv->lock, flags);
2004
/* handle all the justifications for the interrupt */
2005
if (inta & IPW_INTA_BIT_RX_TRANSFER) {
2007
handled |= IPW_INTA_BIT_RX_TRANSFER;
2010
if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
2011
IPW_DEBUG_HC("Command completed.\n");
2012
rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
2013
priv->status &= ~STATUS_HCMD_ACTIVE;
2014
wake_up_interruptible(&priv->wait_command_queue);
2015
handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
2018
if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
2019
IPW_DEBUG_TX("TX_QUEUE_1\n");
2020
rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
2021
handled |= IPW_INTA_BIT_TX_QUEUE_1;
2024
if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
2025
IPW_DEBUG_TX("TX_QUEUE_2\n");
2026
rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
2027
handled |= IPW_INTA_BIT_TX_QUEUE_2;
2030
if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
2031
IPW_DEBUG_TX("TX_QUEUE_3\n");
2032
rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
2033
handled |= IPW_INTA_BIT_TX_QUEUE_3;
2036
if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
2037
IPW_DEBUG_TX("TX_QUEUE_4\n");
2038
rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
2039
handled |= IPW_INTA_BIT_TX_QUEUE_4;
2042
if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
2043
IPW_WARNING("STATUS_CHANGE\n");
2044
handled |= IPW_INTA_BIT_STATUS_CHANGE;
2047
if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
2048
IPW_WARNING("TX_PERIOD_EXPIRED\n");
2049
handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
2052
if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
2053
IPW_WARNING("HOST_CMD_DONE\n");
2054
handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
2057
if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
2058
IPW_WARNING("FW_INITIALIZATION_DONE\n");
2059
handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
2062
if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
2063
IPW_WARNING("PHY_OFF_DONE\n");
2064
handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
2067
if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
2068
IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
2069
priv->status |= STATUS_RF_KILL_HW;
2070
wake_up_interruptible(&priv->wait_command_queue);
2071
priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
2072
cancel_delayed_work(&priv->request_scan);
2073
schedule_work(&priv->link_down);
2074
queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
2075
handled |= IPW_INTA_BIT_RF_KILL_DONE;
2078
if (inta & IPW_INTA_BIT_FATAL_ERROR) {
2079
IPW_WARNING("Firmware error detected. Restarting.\n");
2081
IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
2082
if (ipw_debug_level & IPW_DL_FW_ERRORS) {
2083
struct ipw_fw_error *error =
2084
ipw_alloc_error_log(priv);
2085
ipw_dump_error_log(priv, error);
2089
priv->error = ipw_alloc_error_log(priv);
2091
IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
2093
IPW_DEBUG_FW("Error allocating sysfs 'error' "
2095
if (ipw_debug_level & IPW_DL_FW_ERRORS)
2096
ipw_dump_error_log(priv, priv->error);
2099
/* XXX: If hardware encryption is for WPA/WPA2,
2100
* we have to notify the supplicant. */
2101
if (priv->ieee->sec.encrypt) {
2102
priv->status &= ~STATUS_ASSOCIATED;
2103
notify_wx_assoc_event(priv);
2106
/* Keep the restart process from trying to send host
2107
* commands by clearing the INIT status bit */
2108
priv->status &= ~STATUS_INIT;
2110
/* Cancel currently queued command. */
2111
priv->status &= ~STATUS_HCMD_ACTIVE;
2112
wake_up_interruptible(&priv->wait_command_queue);
2114
queue_work(priv->workqueue, &priv->adapter_restart);
2115
handled |= IPW_INTA_BIT_FATAL_ERROR;
2118
if (inta & IPW_INTA_BIT_PARITY_ERROR) {
2119
IPW_ERROR("Parity error\n");
2120
handled |= IPW_INTA_BIT_PARITY_ERROR;
2123
if (handled != inta) {
2124
IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
2127
spin_unlock_irqrestore(&priv->lock, flags);
2129
/* enable all interrupts */
2130
ipw_enable_interrupts(priv);
2133
#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2134
static char *get_cmd_string(u8 cmd)
2137
IPW_CMD(HOST_COMPLETE);
2138
IPW_CMD(POWER_DOWN);
2139
IPW_CMD(SYSTEM_CONFIG);
2140
IPW_CMD(MULTICAST_ADDRESS);
2142
IPW_CMD(ADAPTER_ADDRESS);
2144
IPW_CMD(RTS_THRESHOLD);
2145
IPW_CMD(FRAG_THRESHOLD);
2146
IPW_CMD(POWER_MODE);
2148
IPW_CMD(TGI_TX_KEY);
2149
IPW_CMD(SCAN_REQUEST);
2150
IPW_CMD(SCAN_REQUEST_EXT);
2152
IPW_CMD(SUPPORTED_RATES);
2153
IPW_CMD(SCAN_ABORT);
2155
IPW_CMD(QOS_PARAMETERS);
2156
IPW_CMD(DINO_CONFIG);
2157
IPW_CMD(RSN_CAPABILITIES);
2159
IPW_CMD(CARD_DISABLE);
2160
IPW_CMD(SEED_NUMBER);
2162
IPW_CMD(COUNTRY_INFO);
2163
IPW_CMD(AIRONET_INFO);
2164
IPW_CMD(AP_TX_POWER);
2166
IPW_CMD(CCX_VER_INFO);
2167
IPW_CMD(SET_CALIBRATION);
2168
IPW_CMD(SENSITIVITY_CALIB);
2169
IPW_CMD(RETRY_LIMIT);
2170
IPW_CMD(IPW_PRE_POWER_DOWN);
2171
IPW_CMD(VAP_BEACON_TEMPLATE);
2172
IPW_CMD(VAP_DTIM_PERIOD);
2173
IPW_CMD(EXT_SUPPORTED_RATES);
2174
IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2175
IPW_CMD(VAP_QUIET_INTERVALS);
2176
IPW_CMD(VAP_CHANNEL_SWITCH);
2177
IPW_CMD(VAP_MANDATORY_CHANNELS);
2178
IPW_CMD(VAP_CELL_PWR_LIMIT);
2179
IPW_CMD(VAP_CF_PARAM_SET);
2180
IPW_CMD(VAP_SET_BEACONING_STATE);
2181
IPW_CMD(MEASUREMENT);
2182
IPW_CMD(POWER_CAPABILITY);
2183
IPW_CMD(SUPPORTED_CHANNELS);
2184
IPW_CMD(TPC_REPORT);
2186
IPW_CMD(PRODUCTION_COMMAND);
2192
#define HOST_COMPLETE_TIMEOUT HZ
2194
static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
2197
unsigned long flags;
2199
spin_lock_irqsave(&priv->lock, flags);
2200
if (priv->status & STATUS_HCMD_ACTIVE) {
2201
IPW_ERROR("Failed to send %s: Already sending a command.\n",
2202
get_cmd_string(cmd->cmd));
2203
spin_unlock_irqrestore(&priv->lock, flags);
2207
priv->status |= STATUS_HCMD_ACTIVE;
2210
priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2211
priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2212
priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2213
memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2215
priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2218
IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2219
get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2222
#ifndef DEBUG_CMD_WEP_KEY
2223
if (cmd->cmd == IPW_CMD_WEP_KEY)
2224
IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2227
printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2229
rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
2231
priv->status &= ~STATUS_HCMD_ACTIVE;
2232
IPW_ERROR("Failed to send %s: Reason %d\n",
2233
get_cmd_string(cmd->cmd), rc);
2234
spin_unlock_irqrestore(&priv->lock, flags);
2237
spin_unlock_irqrestore(&priv->lock, flags);
2239
rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2241
status & STATUS_HCMD_ACTIVE),
2242
HOST_COMPLETE_TIMEOUT);
2244
spin_lock_irqsave(&priv->lock, flags);
2245
if (priv->status & STATUS_HCMD_ACTIVE) {
2246
IPW_ERROR("Failed to send %s: Command timed out.\n",
2247
get_cmd_string(cmd->cmd));
2248
priv->status &= ~STATUS_HCMD_ACTIVE;
2249
spin_unlock_irqrestore(&priv->lock, flags);
2253
spin_unlock_irqrestore(&priv->lock, flags);
2257
if (priv->status & STATUS_RF_KILL_HW) {
2258
IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2259
get_cmd_string(cmd->cmd));
2266
priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2267
priv->cmdlog_pos %= priv->cmdlog_len;
2272
static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
2274
struct host_cmd cmd = {
2278
return __ipw_send_cmd(priv, &cmd);
2281
static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2284
struct host_cmd cmd = {
2290
return __ipw_send_cmd(priv, &cmd);
2293
static int ipw_send_host_complete(struct ipw_priv *priv)
2296
IPW_ERROR("Invalid args\n");
2300
return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
2303
static int ipw_send_system_config(struct ipw_priv *priv)
2305
return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2306
sizeof(priv->sys_config),
2310
static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
2312
if (!priv || !ssid) {
2313
IPW_ERROR("Invalid args\n");
2317
return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
2321
static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
2323
if (!priv || !mac) {
2324
IPW_ERROR("Invalid args\n");
2328
IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2329
priv->net_dev->name, MAC_ARG(mac));
2331
return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
2335
* NOTE: This must be executed from our workqueue as it results in udelay
2336
* being called which may corrupt the keyboard if executed on default
2339
static void ipw_adapter_restart(void *adapter)
2341
struct ipw_priv *priv = adapter;
2343
if (priv->status & STATUS_RF_KILL_MASK)
2348
if (priv->assoc_network &&
2349
(priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2350
ipw_remove_current_network(priv);
2353
IPW_ERROR("Failed to up device\n");
2358
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
2359
static void ipw_bg_adapter_restart(void *work)
2361
struct ipw_priv *priv = work;
2363
static void ipw_bg_adapter_restart(struct work_struct *work)
2365
struct ipw_priv *priv =
2366
container_of(work, struct ipw_priv, adapter_restart);
2368
mutex_lock(&priv->mutex);
2369
ipw_adapter_restart(priv);
2370
mutex_unlock(&priv->mutex);
2373
#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2375
static void ipw_scan_check(void *data)
2377
struct ipw_priv *priv = data;
2378
if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2379
IPW_DEBUG_SCAN("Scan completion watchdog resetting "
2380
"adapter after (%dms).\n",
2381
jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
2382
queue_work(priv->workqueue, &priv->adapter_restart);
2386
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
2387
static void ipw_bg_scan_check(void *work)
2389
struct ipw_priv *priv = work;
2391
static void ipw_bg_scan_check(struct work_struct *work)
2393
struct ipw_priv *priv =
2394
container_of(work, struct ipw_priv, scan_check.work);
2396
mutex_lock(&priv->mutex);
2397
ipw_scan_check(priv);
2398
mutex_unlock(&priv->mutex);
2401
static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2402
struct ipw_scan_request_ext *request)
2404
return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
2405
sizeof(*request), request);
2408
static int ipw_send_scan_abort(struct ipw_priv *priv)
2411
IPW_ERROR("Invalid args\n");
2415
return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
2418
static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2420
struct ipw_sensitivity_calib calib = {
2421
.beacon_rssi_raw = cpu_to_le16(sens),
2424
return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
2428
static int ipw_send_associate(struct ipw_priv *priv,
2429
struct ipw_associate *associate)
2431
struct ipw_associate tmp_associate;
2433
if (!priv || !associate) {
2434
IPW_ERROR("Invalid args\n");
2438
memcpy(&tmp_associate, associate, sizeof(*associate));
2439
tmp_associate.policy_support =
2440
cpu_to_le16(tmp_associate.policy_support);
2441
tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2442
tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2443
tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2444
tmp_associate.listen_interval =
2445
cpu_to_le16(tmp_associate.listen_interval);
2446
tmp_associate.beacon_interval =
2447
cpu_to_le16(tmp_associate.beacon_interval);
2448
tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2450
return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
2454
static int ipw_send_supported_rates(struct ipw_priv *priv,
2455
struct ipw_supported_rates *rates)
2457
if (!priv || !rates) {
2458
IPW_ERROR("Invalid args\n");
2462
return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
2466
static int ipw_set_random_seed(struct ipw_priv *priv)
2471
IPW_ERROR("Invalid args\n");
2475
get_random_bytes(&val, sizeof(val));
2477
return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
2480
static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2483
IPW_ERROR("Invalid args\n");
2487
phy_off = cpu_to_le32(phy_off);
2488
return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off),
2492
static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
2494
if (!priv || !power) {
2495
IPW_ERROR("Invalid args\n");
2499
return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
2502
static int ipw_set_tx_power(struct ipw_priv *priv)
2504
const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
2505
struct ipw_tx_power tx_power;
2509
memset(&tx_power, 0, sizeof(tx_power));
2511
/* configure device for 'G' band */
2512
tx_power.ieee_mode = IPW_G_MODE;
2513
tx_power.num_channels = geo->bg_channels;
2514
for (i = 0; i < geo->bg_channels; i++) {
2515
max_power = geo->bg[i].max_power;
2516
tx_power.channels_tx_power[i].channel_number =
2518
tx_power.channels_tx_power[i].tx_power = max_power ?
2519
min(max_power, priv->tx_power) : priv->tx_power;
2521
if (ipw_send_tx_power(priv, &tx_power))
2524
/* configure device to also handle 'B' band */
2525
tx_power.ieee_mode = IPW_B_MODE;
2526
if (ipw_send_tx_power(priv, &tx_power))
2529
/* configure device to also handle 'A' band */
2530
if (priv->ieee->abg_true) {
2531
tx_power.ieee_mode = IPW_A_MODE;
2532
tx_power.num_channels = geo->a_channels;
2533
for (i = 0; i < tx_power.num_channels; i++) {
2534
max_power = geo->a[i].max_power;
2535
tx_power.channels_tx_power[i].channel_number =
2537
tx_power.channels_tx_power[i].tx_power = max_power ?
2538
min(max_power, priv->tx_power) : priv->tx_power;
2540
if (ipw_send_tx_power(priv, &tx_power))
2546
static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2548
struct ipw_rts_threshold rts_threshold = {
2549
.rts_threshold = cpu_to_le16(rts),
2553
IPW_ERROR("Invalid args\n");
2557
return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2558
sizeof(rts_threshold), &rts_threshold);
2561
static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2563
struct ipw_frag_threshold frag_threshold = {
2564
.frag_threshold = cpu_to_le16(frag),
2568
IPW_ERROR("Invalid args\n");
2572
return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2573
sizeof(frag_threshold), &frag_threshold);
2576
static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2581
IPW_ERROR("Invalid args\n");
2585
/* If on battery, set to 3, if AC set to CAM, else user
2588
case IPW_POWER_BATTERY:
2589
param = IPW_POWER_INDEX_3;
2592
param = IPW_POWER_MODE_CAM;
2599
param = cpu_to_le32(mode);
2600
return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
2604
static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2606
struct ipw_retry_limit retry_limit = {
2607
.short_retry_limit = slimit,
2608
.long_retry_limit = llimit
2612
IPW_ERROR("Invalid args\n");
2616
return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
2621
* The IPW device contains a Microwire compatible EEPROM that stores
2622
* various data like the MAC address. Usually the firmware has exclusive
2623
* access to the eeprom, but during device initialization (before the
2624
* device driver has sent the HostComplete command to the firmware) the
2625
* device driver has read access to the EEPROM by way of indirect addressing
2626
* through a couple of memory mapped registers.
2628
* The following is a simplified implementation for pulling data out of the
2629
* the eeprom, along with some helper functions to find information in
2630
* the per device private data's copy of the eeprom.
2632
* NOTE: To better understand how these functions work (i.e what is a chip
2633
* select and why do have to keep driving the eeprom clock?), read
2634
* just about any data sheet for a Microwire compatible EEPROM.
2637
/* write a 32 bit value into the indirect accessor register */
2638
static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2640
ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
2642
/* the eeprom requires some time to complete the operation */
2643
udelay(p->eeprom_delay);
2648
/* perform a chip select operation */
2649
static void eeprom_cs(struct ipw_priv *priv)
2651
eeprom_write_reg(priv, 0);
2652
eeprom_write_reg(priv, EEPROM_BIT_CS);
2653
eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2654
eeprom_write_reg(priv, EEPROM_BIT_CS);
2657
/* perform a chip select operation */
2658
static void eeprom_disable_cs(struct ipw_priv *priv)
2660
eeprom_write_reg(priv, EEPROM_BIT_CS);
2661
eeprom_write_reg(priv, 0);
2662
eeprom_write_reg(priv, EEPROM_BIT_SK);
2665
/* push a single bit down to the eeprom */
2666
static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
2668
int d = (bit ? EEPROM_BIT_DI : 0);
2669
eeprom_write_reg(p, EEPROM_BIT_CS | d);
2670
eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
2673
/* push an opcode followed by an address down to the eeprom */
2674
static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
2679
eeprom_write_bit(priv, 1);
2680
eeprom_write_bit(priv, op & 2);
2681
eeprom_write_bit(priv, op & 1);
2682
for (i = 7; i >= 0; i--) {
2683
eeprom_write_bit(priv, addr & (1 << i));
2687
/* pull 16 bits off the eeprom, one bit at a time */
2688
static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
2693
/* Send READ Opcode */
2694
eeprom_op(priv, EEPROM_CMD_READ, addr);
2696
/* Send dummy bit */
2697
eeprom_write_reg(priv, EEPROM_BIT_CS);
2699
/* Read the byte off the eeprom one bit at a time */
2700
for (i = 0; i < 16; i++) {
2702
eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2703
eeprom_write_reg(priv, EEPROM_BIT_CS);
2704
data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2705
r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
2708
/* Send another dummy bit */
2709
eeprom_write_reg(priv, 0);
2710
eeprom_disable_cs(priv);
2715
/* helper function for pulling the mac address out of the private */
2716
/* data's copy of the eeprom data */
2717
static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
2719
memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
2723
* Either the device driver (i.e. the host) or the firmware can
2724
* load eeprom data into the designated region in SRAM. If neither
2725
* happens then the FW will shutdown with a fatal error.
2727
* In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2728
* bit needs region of shared SRAM needs to be non-zero.
2730
static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2733
u16 *eeprom = (u16 *) priv->eeprom;
2735
IPW_DEBUG_TRACE(">>\n");
2737
/* read entire contents of eeprom into private buffer */
2738
for (i = 0; i < 128; i++)
2739
eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
2742
If the data looks correct, then copy it to our private
2743
copy. Otherwise let the firmware know to perform the operation
2746
if (priv->eeprom[EEPROM_VERSION] != 0) {
2747
IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2749
/* write the eeprom data to sram */
2750
for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
2751
ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
2753
/* Do not load eeprom data on fatal error or suspend */
2754
ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2756
IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2758
/* Load eeprom data on fatal error or suspend */
2759
ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2762
IPW_DEBUG_TRACE("<<\n");
2765
static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
2770
_ipw_write32(priv, IPW_AUTOINC_ADDR, start);
2772
_ipw_write32(priv, IPW_AUTOINC_DATA, 0);
2775
static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2777
ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
2778
CB_NUMBER_OF_ELEMENTS_SMALL *
2779
sizeof(struct command_block));
2782
static int ipw_fw_dma_enable(struct ipw_priv *priv)
2783
{ /* start dma engine but no transfers yet */
2785
IPW_DEBUG_FW(">> : \n");
2788
ipw_fw_dma_reset_command_blocks(priv);
2790
/* Write CB base address */
2791
ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
2793
IPW_DEBUG_FW("<< : \n");
2797
static void ipw_fw_dma_abort(struct ipw_priv *priv)
2801
IPW_DEBUG_FW(">> :\n");
2803
/* set the Stop and Abort bit */
2804
control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
2805
ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2806
priv->sram_desc.last_cb_index = 0;
2808
IPW_DEBUG_FW("<< \n");
2811
static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2812
struct command_block *cb)
2815
IPW_SHARED_SRAM_DMA_CONTROL +
2816
(sizeof(struct command_block) * index);
2817
IPW_DEBUG_FW(">> :\n");
2819
ipw_write_indirect(priv, address, (u8 *) cb,
2820
(int)sizeof(struct command_block));
2822
IPW_DEBUG_FW("<< :\n");
2827
static int ipw_fw_dma_kick(struct ipw_priv *priv)
2832
IPW_DEBUG_FW(">> :\n");
2834
for (index = 0; index < priv->sram_desc.last_cb_index; index++)
2835
ipw_fw_dma_write_command_block(priv, index,
2836
&priv->sram_desc.cb_list[index]);
2838
/* Enable the DMA in the CSR register */
2839
ipw_clear_bit(priv, IPW_RESET_REG,
2840
IPW_RESET_REG_MASTER_DISABLED |
2841
IPW_RESET_REG_STOP_MASTER);
2843
/* Set the Start bit. */
2844
control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
2845
ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2847
IPW_DEBUG_FW("<< :\n");
2851
static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2854
u32 register_value = 0;
2855
u32 cb_fields_address = 0;
2857
IPW_DEBUG_FW(">> :\n");
2858
address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2859
IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
2861
/* Read the DMA Controlor register */
2862
register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2863
IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
2865
/* Print the CB values */
2866
cb_fields_address = address;
2867
register_value = ipw_read_reg32(priv, cb_fields_address);
2868
IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
2870
cb_fields_address += sizeof(u32);
2871
register_value = ipw_read_reg32(priv, cb_fields_address);
2872
IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
2874
cb_fields_address += sizeof(u32);
2875
register_value = ipw_read_reg32(priv, cb_fields_address);
2876
IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2879
cb_fields_address += sizeof(u32);
2880
register_value = ipw_read_reg32(priv, cb_fields_address);
2881
IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
2883
IPW_DEBUG_FW(">> :\n");
2886
static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2888
u32 current_cb_address = 0;
2889
u32 current_cb_index = 0;
2891
IPW_DEBUG_FW("<< :\n");
2892
current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2894
current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
2895
sizeof(struct command_block);
2897
IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
2898
current_cb_index, current_cb_address);
2900
IPW_DEBUG_FW(">> :\n");
2901
return current_cb_index;
2905
static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2909
int interrupt_enabled, int is_last)
2912
u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
2913
CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2915
struct command_block *cb;
2916
u32 last_cb_element = 0;
2918
IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2919
src_address, dest_address, length);
2921
if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2924
last_cb_element = priv->sram_desc.last_cb_index;
2925
cb = &priv->sram_desc.cb_list[last_cb_element];
2926
priv->sram_desc.last_cb_index++;
2928
/* Calculate the new CB control word */
2929
if (interrupt_enabled)
2930
control |= CB_INT_ENABLED;
2933
control |= CB_LAST_VALID;
2937
/* Calculate the CB Element's checksum value */
2938
cb->status = control ^ src_address ^ dest_address;
2940
/* Copy the Source and Destination addresses */
2941
cb->dest_addr = dest_address;
2942
cb->source_addr = src_address;
2944
/* Copy the Control Word last */
2945
cb->control = control;
2950
static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
2951
u32 src_phys, u32 dest_address, u32 length)
2953
u32 bytes_left = length;
2955
u32 dest_offset = 0;
2957
IPW_DEBUG_FW(">> \n");
2958
IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2959
src_phys, dest_address, length);
2960
while (bytes_left > CB_MAX_LENGTH) {
2961
status = ipw_fw_dma_add_command_block(priv,
2962
src_phys + src_offset,
2965
CB_MAX_LENGTH, 0, 0);
2967
IPW_DEBUG_FW_INFO(": Failed\n");
2970
IPW_DEBUG_FW_INFO(": Added new cb\n");
2972
src_offset += CB_MAX_LENGTH;
2973
dest_offset += CB_MAX_LENGTH;
2974
bytes_left -= CB_MAX_LENGTH;
2977
/* add the buffer tail */
2978
if (bytes_left > 0) {
2980
ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2981
dest_address + dest_offset,
2984
IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2988
(": Adding new cb - the buffer tail\n");
2991
IPW_DEBUG_FW("<< \n");
2995
static int ipw_fw_dma_wait(struct ipw_priv *priv)
2997
u32 current_index = 0, previous_index;
3000
IPW_DEBUG_FW(">> : \n");
3002
current_index = ipw_fw_dma_command_block_index(priv);
3003
IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
3004
(int)priv->sram_desc.last_cb_index);
3006
while (current_index < priv->sram_desc.last_cb_index) {
3008
previous_index = current_index;
3009
current_index = ipw_fw_dma_command_block_index(priv);
3011
if (previous_index < current_index) {
3015
if (++watchdog > 400) {
3016
IPW_DEBUG_FW_INFO("Timeout\n");
3017
ipw_fw_dma_dump_command_block(priv);
3018
ipw_fw_dma_abort(priv);
3023
ipw_fw_dma_abort(priv);
3025
/*Disable the DMA in the CSR register */
3026
ipw_set_bit(priv, IPW_RESET_REG,
3027
IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
3029
IPW_DEBUG_FW("<< dmaWaitSync \n");
3033
static void ipw_remove_current_network(struct ipw_priv *priv)
3035
struct list_head *element, *safe;
3036
struct ieee80211_network *network = NULL;
3037
unsigned long flags;
3039
spin_lock_irqsave(&priv->ieee->lock, flags);
3040
list_for_each_safe(element, safe, &priv->ieee->network_list) {
3041
network = list_entry(element, struct ieee80211_network, list);
3042
if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
3044
list_add_tail(&network->list,
3045
&priv->ieee->network_free_list);
3048
spin_unlock_irqrestore(&priv->ieee->lock, flags);
3052
* Check that card is still alive.
3053
* Reads debug register from domain0.
3054
* If card is present, pre-defined value should
3058
* @return 1 if card is present, 0 otherwise
3060
static inline int ipw_alive(struct ipw_priv *priv)
3062
return ipw_read32(priv, 0x90) == 0xd55555d5;
3065
/* timeout in msec, attempted in 10-msec quanta */
3066
static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
3072
if ((ipw_read32(priv, addr) & mask) == mask)
3076
} while (i < timeout);
3081
/* These functions load the firmware and micro code for the operation of
3082
* the ipw hardware. It assumes the buffer has all the bits for the
3083
* image and the caller is handling the memory allocation and clean up.
3086
static int ipw_stop_master(struct ipw_priv *priv)
3090
IPW_DEBUG_TRACE(">> \n");
3091
/* stop master. typical delay - 0 */
3092
ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
3094
/* timeout is in msec, polled in 10-msec quanta */
3095
rc = ipw_poll_bit(priv, IPW_RESET_REG,
3096
IPW_RESET_REG_MASTER_DISABLED, 100);
3098
IPW_ERROR("wait for stop master failed after 100ms\n");
3102
IPW_DEBUG_INFO("stop master %dms\n", rc);
3107
static void ipw_arc_release(struct ipw_priv *priv)
3109
IPW_DEBUG_TRACE(">> \n");
3112
ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
3114
/* no one knows timing, for safety add some delay */
3123
static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
3125
int rc = 0, i, addr;
3129
image = (u16 *) data;
3131
IPW_DEBUG_TRACE(">> \n");
3133
rc = ipw_stop_master(priv);
3138
for (addr = IPW_SHARED_LOWER_BOUND;
3139
addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
3140
ipw_write32(priv, addr, 0);
3143
/* no ucode (yet) */
3144
memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3145
/* destroy DMA queues */
3146
/* reset sequence */
3148
ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
3149
ipw_arc_release(priv);
3150
ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
3154
ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
3157
ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
3160
/* enable ucode store */
3161
ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3162
ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
3168
* Do NOT set indirect address register once and then
3169
* store data to indirect data register in the loop.
3170
* It seems very reasonable, but in this case DINO do not
3171
* accept ucode. It is essential to set address each time.
3173
/* load new ipw uCode */
3174
for (i = 0; i < len / 2; i++)
3175
ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
3176
cpu_to_le16(image[i]));
3179
ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3180
ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
3182
/* this is where the igx / win driver deveates from the VAP driver. */
3184
/* wait for alive response */
3185
for (i = 0; i < 100; i++) {
3186
/* poll for incoming data */
3187
cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
3188
if (cr & DINO_RXFIFO_DATA)
3193
if (cr & DINO_RXFIFO_DATA) {
3194
/* alive_command_responce size is NOT multiple of 4 */
3195
u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
3197
for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
3198
response_buffer[i] =
3199
le32_to_cpu(ipw_read_reg32(priv,
3200
IPW_BASEBAND_RX_FIFO_READ));
3201
memcpy(&priv->dino_alive, response_buffer,
3202
sizeof(priv->dino_alive));
3203
if (priv->dino_alive.alive_command == 1
3204
&& priv->dino_alive.ucode_valid == 1) {
3207
("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3208
"of %02d/%02d/%02d %02d:%02d\n",
3209
priv->dino_alive.software_revision,
3210
priv->dino_alive.software_revision,
3211
priv->dino_alive.device_identifier,
3212
priv->dino_alive.device_identifier,
3213
priv->dino_alive.time_stamp[0],
3214
priv->dino_alive.time_stamp[1],
3215
priv->dino_alive.time_stamp[2],
3216
priv->dino_alive.time_stamp[3],
3217
priv->dino_alive.time_stamp[4]);
3219
IPW_DEBUG_INFO("Microcode is not alive\n");
3223
IPW_DEBUG_INFO("No alive response from DINO\n");
3227
/* disable DINO, otherwise for some reason
3228
firmware have problem getting alive resp. */
3229
ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3234
static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
3238
struct fw_chunk *chunk;
3239
dma_addr_t shared_phys;
3242
IPW_DEBUG_TRACE("<< : \n");
3243
shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
3248
memmove(shared_virt, data, len);
3251
rc = ipw_fw_dma_enable(priv);
3253
if (priv->sram_desc.last_cb_index > 0) {
3254
/* the DMA is already ready this would be a bug. */
3260
chunk = (struct fw_chunk *)(data + offset);
3261
offset += sizeof(struct fw_chunk);
3262
/* build DMA packet and queue up for sending */
3263
/* dma to chunk->address, the chunk->length bytes from data +
3266
rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
3267
le32_to_cpu(chunk->address),
3268
le32_to_cpu(chunk->length));
3270
IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3274
offset += le32_to_cpu(chunk->length);
3275
} while (offset < len);
3277
/* Run the DMA and wait for the answer */
3278
rc = ipw_fw_dma_kick(priv);
3280
IPW_ERROR("dmaKick Failed\n");
3284
rc = ipw_fw_dma_wait(priv);
3286
IPW_ERROR("dmaWaitSync Failed\n");
3290
pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
3295
static int ipw_stop_nic(struct ipw_priv *priv)
3300
ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
3302
rc = ipw_poll_bit(priv, IPW_RESET_REG,
3303
IPW_RESET_REG_MASTER_DISABLED, 500);
3305
IPW_ERROR("wait for reg master disabled failed after 500ms\n");
3309
ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
3314
static void ipw_start_nic(struct ipw_priv *priv)
3316
IPW_DEBUG_TRACE(">>\n");
3318
/* prvHwStartNic release ARC */
3319
ipw_clear_bit(priv, IPW_RESET_REG,
3320
IPW_RESET_REG_MASTER_DISABLED |
3321
IPW_RESET_REG_STOP_MASTER |
3322
CBD_RESET_REG_PRINCETON_RESET);
3324
/* enable power management */
3325
ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3326
IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
3328
IPW_DEBUG_TRACE("<<\n");
3331
static int ipw_init_nic(struct ipw_priv *priv)
3335
IPW_DEBUG_TRACE(">>\n");
3338
/* set "initialization complete" bit to move adapter to D0 state */
3339
ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3341
/* low-level PLL activation */
3342
ipw_write32(priv, IPW_READ_INT_REGISTER,
3343
IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
3345
/* wait for clock stabilization */
3346
rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3347
IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
3349
IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3351
/* assert SW reset */
3352
ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
3356
/* set "initialization complete" bit to move adapter to D0 state */
3357
ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3359
IPW_DEBUG_TRACE(">>\n");
3363
/* Call this function from process context, it will sleep in request_firmware.
3364
* Probe is an ok place to call this from.
3366
static int ipw_reset_nic(struct ipw_priv *priv)
3369
unsigned long flags;
3371
IPW_DEBUG_TRACE(">>\n");
3373
rc = ipw_init_nic(priv);
3375
spin_lock_irqsave(&priv->lock, flags);
3376
/* Clear the 'host command active' bit... */
3377
priv->status &= ~STATUS_HCMD_ACTIVE;
3378
wake_up_interruptible(&priv->wait_command_queue);
3379
priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3380
wake_up_interruptible(&priv->wait_state);
3381
spin_unlock_irqrestore(&priv->lock, flags);
3383
IPW_DEBUG_TRACE("<<\n");
3396
static int ipw_get_fw(struct ipw_priv *priv,
3397
const struct firmware **raw, const char *name)
3402
/* ask firmware_class module to get the boot firmware off disk */
3403
rc = request_firmware(raw, name, &priv->pci_dev->dev);
3405
IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
3409
if ((*raw)->size < sizeof(*fw)) {
3410
IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
3414
fw = (void *)(*raw)->data;
3416
if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3417
le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
3418
IPW_ERROR("%s is too small or corrupt (%zd)\n",
3419
name, (*raw)->size);
3423
IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
3425
le32_to_cpu(fw->ver) >> 16,
3426
le32_to_cpu(fw->ver) & 0xff,
3427
(*raw)->size - sizeof(*fw));
3431
#define IPW_RX_BUF_SIZE (3000)
3433
static void ipw_rx_queue_reset(struct ipw_priv *priv,
3434
struct ipw_rx_queue *rxq)
3436
unsigned long flags;
3439
spin_lock_irqsave(&rxq->lock, flags);
3441
INIT_LIST_HEAD(&rxq->rx_free);
3442
INIT_LIST_HEAD(&rxq->rx_used);
3444
/* Fill the rx_used queue with _all_ of the Rx buffers */
3445
for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3446
/* In the reset function, these buffers may have been allocated
3447
* to an SKB, so we need to unmap and free potential storage */
3448
if (rxq->pool[i].skb != NULL) {
3449
pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
3450
IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
3451
dev_kfree_skb(rxq->pool[i].skb);
3452
rxq->pool[i].skb = NULL;
3454
list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3457
/* Set us so that we have processed and used all buffers, but have
3458
* not restocked the Rx queue with fresh buffers */
3459
rxq->read = rxq->write = 0;
3460
rxq->processed = RX_QUEUE_SIZE - 1;
3461
rxq->free_count = 0;
3462
spin_unlock_irqrestore(&rxq->lock, flags);
3466
static int fw_loaded = 0;
3467
static const struct firmware *raw = NULL;
3469
static void free_firmware(void)
3472
release_firmware(raw);
3478
#define free_firmware() do {} while (0)
3481
static int ipw_load(struct ipw_priv *priv)
3484
const struct firmware *raw = NULL;
3487
u8 *boot_img, *ucode_img, *fw_img;
3489
int rc = 0, retries = 3;
3491
switch (priv->ieee->iw_mode) {
3493
name = "ipw2200-ibss.fw";
3495
#ifdef CONFIG_IPW2200_MONITOR
3496
case IW_MODE_MONITOR:
3497
name = "ipw2200-sniffer.fw";
3501
name = "ipw2200-bss.fw";
3513
rc = ipw_get_fw(priv, &raw, name);
3520
fw = (void *)raw->data;
3521
boot_img = &fw->data[0];
3522
ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3523
fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3524
le32_to_cpu(fw->ucode_size)];
3530
priv->rxq = ipw_rx_queue_alloc(priv);
3532
ipw_rx_queue_reset(priv, priv->rxq);
3534
IPW_ERROR("Unable to initialize Rx queue\n");
3539
/* Ensure interrupts are disabled */
3540
ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3541
priv->status &= ~STATUS_INT_ENABLED;
3543
/* ack pending interrupts */
3544
ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3548
rc = ipw_reset_nic(priv);
3550
IPW_ERROR("Unable to reset NIC\n");
3554
ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3555
IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
3557
/* DMA the initial boot firmware into the device */
3558
rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
3560
IPW_ERROR("Unable to load boot firmware: %d\n", rc);
3564
/* kick start the device */
3565
ipw_start_nic(priv);
3567
/* wait for the device to finish its initial startup sequence */
3568
rc = ipw_poll_bit(priv, IPW_INTA_RW,
3569
IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3571
IPW_ERROR("device failed to boot initial fw image\n");
3574
IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3576
/* ack fw init done interrupt */
3577
ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3579
/* DMA the ucode into the device */
3580
rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
3582
IPW_ERROR("Unable to load ucode: %d\n", rc);
3589
/* DMA bss firmware into the device */
3590
rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
3592
IPW_ERROR("Unable to load firmware: %d\n", rc);
3599
ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3601
rc = ipw_queue_reset(priv);
3603
IPW_ERROR("Unable to initialize queues\n");
3607
/* Ensure interrupts are disabled */
3608
ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3609
/* ack pending interrupts */
3610
ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3612
/* kick start the device */
3613
ipw_start_nic(priv);
3615
if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
3617
IPW_WARNING("Parity error. Retrying init.\n");
3622
IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3627
/* wait for the device */
3628
rc = ipw_poll_bit(priv, IPW_INTA_RW,
3629
IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3631
IPW_ERROR("device failed to start within 500ms\n");
3634
IPW_DEBUG_INFO("device response after %dms\n", rc);
3636
/* ack fw init done interrupt */
3637
ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3639
/* read eeprom data and initialize the eeprom region of sram */
3640
priv->eeprom_delay = 1;
3641
ipw_eeprom_init_sram(priv);
3643
/* enable interrupts */
3644
ipw_enable_interrupts(priv);
3646
/* Ensure our queue has valid packets */
3647
ipw_rx_queue_replenish(priv);
3649
ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
3651
/* ack pending interrupts */
3652
ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3655
release_firmware(raw);
3661
ipw_rx_queue_free(priv, priv->rxq);
3664
ipw_tx_queue_free(priv);
3666
release_firmware(raw);
3678
* Theory of operation
3680
* A queue is a circular buffers with 'Read' and 'Write' pointers.
3681
* 2 empty entries always kept in the buffer to protect from overflow.
3683
* For Tx queue, there are low mark and high mark limits. If, after queuing
3684
* the packet for Tx, free space become < low mark, Tx queue stopped. When
3685
* reclaiming packets (on 'tx done IRQ), if free space become > high mark,
3688
* The IPW operates with six queues, one receive queue in the device's
3689
* sram, one transmit queue for sending commands to the device firmware,
3690
* and four transmit queues for data.
3692
* The four transmit queues allow for performing quality of service (qos)
3693
* transmissions as per the 802.11 protocol. Currently Linux does not
3694
* provide a mechanism to the user for utilizing prioritized queues, so
3695
* we only utilize the first data transmit queue (queue1).
3699
* Driver allocates buffers of this size for Rx
3702
static inline int ipw_queue_space(const struct clx2_queue *q)
3704
int s = q->last_used - q->first_empty;
3707
s -= 2; /* keep some reserve to not confuse empty and full situations */
3713
static inline int ipw_queue_inc_wrap(int index, int n_bd)
3715
return (++index == n_bd) ? 0 : index;
3719
* Initialize common DMA queue structure
3721
* @param q queue to init
3722
* @param count Number of BD's to allocate. Should be power of 2
3723
* @param read_register Address for 'read' register
3724
* (not offset within BAR, full address)
3725
* @param write_register Address for 'write' register
3726
* (not offset within BAR, full address)
3727
* @param base_register Address for 'base' register
3728
* (not offset within BAR, full address)
3729
* @param size Address for 'size' register
3730
* (not offset within BAR, full address)
3732
static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
3733
int count, u32 read, u32 write, u32 base, u32 size)
3737
q->low_mark = q->n_bd / 4;
3738
if (q->low_mark < 4)
3741
q->high_mark = q->n_bd / 8;
3742
if (q->high_mark < 2)
3745
q->first_empty = q->last_used = 0;
3749
ipw_write32(priv, base, q->dma_addr);
3750
ipw_write32(priv, size, count);
3751
ipw_write32(priv, read, 0);
3752
ipw_write32(priv, write, 0);
3754
_ipw_read32(priv, 0x90);
3757
static int ipw_queue_tx_init(struct ipw_priv *priv,
3758
struct clx2_tx_queue *q,
3759
int count, u32 read, u32 write, u32 base, u32 size)
3761
struct pci_dev *dev = priv->pci_dev;
3763
q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3765
IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3770
pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
3772
IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
3773
sizeof(q->bd[0]) * count);
3779
ipw_queue_init(priv, &q->q, count, read, write, base, size);
3784
* Free one TFD, those at index [txq->q.last_used].
3785
* Do NOT advance any indexes
3790
static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3791
struct clx2_tx_queue *txq)
3793
struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3794
struct pci_dev *dev = priv->pci_dev;
3798
if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3799
/* nothing to cleanup after for host commands */
3803
if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3804
IPW_ERROR("Too many chunks: %i\n",
3805
le32_to_cpu(bd->u.data.num_chunks));
3806
/** @todo issue fatal error, it is quite serious situation */
3810
/* unmap chunks if any */
3811
for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3812
pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3813
le16_to_cpu(bd->u.data.chunk_len[i]),
3815
if (txq->txb[txq->q.last_used]) {
3816
ieee80211_txb_free(txq->txb[txq->q.last_used]);
3817
txq->txb[txq->q.last_used] = NULL;
3823
* Deallocate DMA queue.
3825
* Empty queue by removing and destroying all BD's.
3831
static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
3833
struct clx2_queue *q = &txq->q;
3834
struct pci_dev *dev = priv->pci_dev;
3839
/* first, empty all BD's */
3840
for (; q->first_empty != q->last_used;
3841
q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3842
ipw_queue_tx_free_tfd(priv, txq);
3845
/* free buffers belonging to queue itself */
3846
pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
3850
/* 0 fill whole structure */
3851
memset(txq, 0, sizeof(*txq));
3855
* Destroy all DMA queues and structures
3859
static void ipw_tx_queue_free(struct ipw_priv *priv)
3862
ipw_queue_tx_free(priv, &priv->txq_cmd);
3865
ipw_queue_tx_free(priv, &priv->txq[0]);
3866
ipw_queue_tx_free(priv, &priv->txq[1]);
3867
ipw_queue_tx_free(priv, &priv->txq[2]);
3868
ipw_queue_tx_free(priv, &priv->txq[3]);
3871
static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
3873
/* First 3 bytes are manufacturer */
3874
bssid[0] = priv->mac_addr[0];
3875
bssid[1] = priv->mac_addr[1];
3876
bssid[2] = priv->mac_addr[2];
3878
/* Last bytes are random */
3879
get_random_bytes(&bssid[3], ETH_ALEN - 3);
3881
bssid[0] &= 0xfe; /* clear multicast bit */
3882
bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
3885
static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
3887
struct ipw_station_entry entry;
3890
for (i = 0; i < priv->num_stations; i++) {
3891
if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3892
/* Another node is active in network */
3893
priv->missed_adhoc_beacons = 0;
3894
if (!(priv->config & CFG_STATIC_CHANNEL))
3895
/* when other nodes drop out, we drop out */
3896
priv->config &= ~CFG_ADHOC_PERSIST;
3902
if (i == MAX_STATIONS)
3903
return IPW_INVALID_STATION;
3905
IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3908
entry.support_mode = 0;
3909
memcpy(entry.mac_addr, bssid, ETH_ALEN);
3910
memcpy(priv->stations[i], bssid, ETH_ALEN);
3911
ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
3912
&entry, sizeof(entry));
3913
priv->num_stations++;
3918
static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
3922
for (i = 0; i < priv->num_stations; i++)
3923
if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
3926
return IPW_INVALID_STATION;
3929
static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3933
if (priv->status & STATUS_ASSOCIATING) {
3934
IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3935
queue_work(priv->workqueue, &priv->disassociate);
3939
if (!(priv->status & STATUS_ASSOCIATED)) {
3940
IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3944
IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3946
MAC_ARG(priv->assoc_request.bssid),
3947
priv->assoc_request.channel);
3949
priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3950
priv->status |= STATUS_DISASSOCIATING;
3953
priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3955
priv->assoc_request.assoc_type = HC_DISASSOCIATE;
3957
err = ipw_send_associate(priv, &priv->assoc_request);
3959
IPW_DEBUG_HC("Attempt to send [dis]associate command "
3966
static int ipw_disassociate(void *data)
3968
struct ipw_priv *priv = data;
3969
if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3971
ipw_send_disassociate(data, 0);
3975
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
3976
static void ipw_bg_disassociate(void *work)
3978
struct ipw_priv *priv = work;
3980
static void ipw_bg_disassociate(struct work_struct *work)
3982
struct ipw_priv *priv =
3983
container_of(work, struct ipw_priv, disassociate);
3985
mutex_lock(&priv->mutex);
3986
ipw_disassociate(priv);
3987
mutex_unlock(&priv->mutex);
3990
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
3991
static void ipw_system_config(void *work)
3993
struct ipw_priv *priv = work;
3995
static void ipw_system_config(struct work_struct *work)
3997
struct ipw_priv *priv =
3998
container_of(work, struct ipw_priv, system_config);
4001
#ifdef CONFIG_IPW2200_PROMISCUOUS
4002
if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
4003
priv->sys_config.accept_all_data_frames = 1;
4004
priv->sys_config.accept_non_directed_frames = 1;
4005
priv->sys_config.accept_all_mgmt_bcpr = 1;
4006
priv->sys_config.accept_all_mgmt_frames = 1;
4010
ipw_send_system_config(priv);
4013
struct ipw_status_code {
4018
static const struct ipw_status_code ipw_status_codes[] = {
4019
{0x00, "Successful"},
4020
{0x01, "Unspecified failure"},
4021
{0x0A, "Cannot support all requested capabilities in the "
4022
"Capability information field"},
4023
{0x0B, "Reassociation denied due to inability to confirm that "
4024
"association exists"},
4025
{0x0C, "Association denied due to reason outside the scope of this "
4028
"Responding station does not support the specified authentication "
4031
"Received an Authentication frame with authentication sequence "
4032
"transaction sequence number out of expected sequence"},
4033
{0x0F, "Authentication rejected because of challenge failure"},
4034
{0x10, "Authentication rejected due to timeout waiting for next "
4035
"frame in sequence"},
4036
{0x11, "Association denied because AP is unable to handle additional "
4037
"associated stations"},
4039
"Association denied due to requesting station not supporting all "
4040
"of the datarates in the BSSBasicServiceSet Parameter"},
4042
"Association denied due to requesting station not supporting "
4043
"short preamble operation"},
4045
"Association denied due to requesting station not supporting "
4048
"Association denied due to requesting station not supporting "
4051
"Association denied due to requesting station not supporting "
4052
"short slot operation"},
4054
"Association denied due to requesting station not supporting "
4055
"DSSS-OFDM operation"},
4056
{0x28, "Invalid Information Element"},
4057
{0x29, "Group Cipher is not valid"},
4058
{0x2A, "Pairwise Cipher is not valid"},
4059
{0x2B, "AKMP is not valid"},
4060
{0x2C, "Unsupported RSN IE version"},
4061
{0x2D, "Invalid RSN IE Capabilities"},
4062
{0x2E, "Cipher suite is rejected per security policy"},
4065
static const char *ipw_get_status_code(u16 status)
4068
for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
4069
if (ipw_status_codes[i].status == (status & 0xff))
4070
return ipw_status_codes[i].reason;
4071
return "Unknown status value.";
4074
static void inline average_init(struct average *avg)
4076
memset(avg, 0, sizeof(*avg));
4079
#define DEPTH_RSSI 8
4080
#define DEPTH_NOISE 16
4081
static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
4083
return ((depth-1)*prev_avg + val)/depth;
4086
static void average_add(struct average *avg, s16 val)
4088
avg->sum -= avg->entries[avg->pos];
4090
avg->entries[avg->pos++] = val;
4091
if (unlikely(avg->pos == AVG_ENTRIES)) {
4097
static s16 average_value(struct average *avg)
4099
if (!unlikely(avg->init)) {
4101
return avg->sum / avg->pos;
4105
return avg->sum / AVG_ENTRIES;
4108
static void ipw_reset_stats(struct ipw_priv *priv)
4110
u32 len = sizeof(u32);
4114
average_init(&priv->average_missed_beacons);
4115
priv->exp_avg_rssi = -60;
4116
priv->exp_avg_noise = -85 + 0x100;
4118
priv->last_rate = 0;
4119
priv->last_missed_beacons = 0;
4120
priv->last_rx_packets = 0;
4121
priv->last_tx_packets = 0;
4122
priv->last_tx_failures = 0;
4124
/* Firmware managed, reset only when NIC is restarted, so we have to
4125
* normalize on the current value */
4126
ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
4127
&priv->last_rx_err, &len);
4128
ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
4129
&priv->last_tx_failures, &len);
4131
/* Driver managed, reset with each association */
4132
priv->missed_adhoc_beacons = 0;
4133
priv->missed_beacons = 0;
4134
priv->tx_packets = 0;
4135
priv->rx_packets = 0;
4139
static u32 ipw_get_max_rate(struct ipw_priv *priv)
4142
u32 mask = priv->rates_mask;
4143
/* If currently associated in B mode, restrict the maximum
4144
* rate match to B rates */
4145
if (priv->assoc_request.ieee_mode == IPW_B_MODE)
4146
mask &= IEEE80211_CCK_RATES_MASK;
4148
/* TODO: Verify that the rate is supported by the current rates
4151
while (i && !(mask & i))
4154
case IEEE80211_CCK_RATE_1MB_MASK:
4156
case IEEE80211_CCK_RATE_2MB_MASK:
4158
case IEEE80211_CCK_RATE_5MB_MASK:
4160
case IEEE80211_OFDM_RATE_6MB_MASK:
4162
case IEEE80211_OFDM_RATE_9MB_MASK:
4164
case IEEE80211_CCK_RATE_11MB_MASK:
4166
case IEEE80211_OFDM_RATE_12MB_MASK:
4168
case IEEE80211_OFDM_RATE_18MB_MASK:
4170
case IEEE80211_OFDM_RATE_24MB_MASK:
4172
case IEEE80211_OFDM_RATE_36MB_MASK:
4174
case IEEE80211_OFDM_RATE_48MB_MASK:
4176
case IEEE80211_OFDM_RATE_54MB_MASK:
4180
if (priv->ieee->mode == IEEE_B)
4186
static u32 ipw_get_current_rate(struct ipw_priv *priv)
4188
u32 rate, len = sizeof(rate);
4191
if (!(priv->status & STATUS_ASSOCIATED))
4194
if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
4195
err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
4198
IPW_DEBUG_INFO("failed querying ordinals.\n");
4202
return ipw_get_max_rate(priv);
4205
case IPW_TX_RATE_1MB:
4207
case IPW_TX_RATE_2MB:
4209
case IPW_TX_RATE_5MB:
4211
case IPW_TX_RATE_6MB:
4213
case IPW_TX_RATE_9MB:
4215
case IPW_TX_RATE_11MB:
4217
case IPW_TX_RATE_12MB:
4219
case IPW_TX_RATE_18MB:
4221
case IPW_TX_RATE_24MB:
4223
case IPW_TX_RATE_36MB:
4225
case IPW_TX_RATE_48MB:
4227
case IPW_TX_RATE_54MB:
4234
#define IPW_STATS_INTERVAL (2 * HZ)
4235
static void ipw_gather_stats(struct ipw_priv *priv)
4237
u32 rx_err, rx_err_delta, rx_packets_delta;
4238
u32 tx_failures, tx_failures_delta, tx_packets_delta;
4239
u32 missed_beacons_percent, missed_beacons_delta;
4241
u32 len = sizeof(u32);
4243
u32 beacon_quality, signal_quality, tx_quality, rx_quality,
4247
if (!(priv->status & STATUS_ASSOCIATED)) {
4252
/* Update the statistics */
4253
ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
4254
&priv->missed_beacons, &len);
4255
missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
4256
priv->last_missed_beacons = priv->missed_beacons;
4257
if (priv->assoc_request.beacon_interval) {
4258
missed_beacons_percent = missed_beacons_delta *
4259
(HZ * priv->assoc_request.beacon_interval) /
4260
(IPW_STATS_INTERVAL * 10);
4262
missed_beacons_percent = 0;
4264
average_add(&priv->average_missed_beacons, missed_beacons_percent);
4266
ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4267
rx_err_delta = rx_err - priv->last_rx_err;
4268
priv->last_rx_err = rx_err;
4270
ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4271
tx_failures_delta = tx_failures - priv->last_tx_failures;
4272
priv->last_tx_failures = tx_failures;
4274
rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4275
priv->last_rx_packets = priv->rx_packets;
4277
tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4278
priv->last_tx_packets = priv->tx_packets;
4280
/* Calculate quality based on the following:
4282
* Missed beacon: 100% = 0, 0% = 70% missed
4283
* Rate: 60% = 1Mbs, 100% = Max
4284
* Rx and Tx errors represent a straight % of total Rx/Tx
4285
* RSSI: 100% = > -50, 0% = < -80
4286
* Rx errors: 100% = 0, 0% = 50% missed
4288
* The lowest computed quality is used.
4291
#define BEACON_THRESHOLD 5
4292
beacon_quality = 100 - missed_beacons_percent;
4293
if (beacon_quality < BEACON_THRESHOLD)
4296
beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
4297
(100 - BEACON_THRESHOLD);
4298
IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
4299
beacon_quality, missed_beacons_percent);
4301
priv->last_rate = ipw_get_current_rate(priv);
4302
max_rate = ipw_get_max_rate(priv);
4303
rate_quality = priv->last_rate * 40 / max_rate + 60;
4304
IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4305
rate_quality, priv->last_rate / 1000000);
4307
if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
4308
rx_quality = 100 - (rx_err_delta * 100) /
4309
(rx_packets_delta + rx_err_delta);
4312
IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4313
rx_quality, rx_err_delta, rx_packets_delta);
4315
if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
4316
tx_quality = 100 - (tx_failures_delta * 100) /
4317
(tx_packets_delta + tx_failures_delta);
4320
IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4321
tx_quality, tx_failures_delta, tx_packets_delta);
4323
rssi = priv->exp_avg_rssi;
4326
(priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4327
(priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4328
(priv->ieee->perfect_rssi - rssi) *
4329
(15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4330
62 * (priv->ieee->perfect_rssi - rssi))) /
4331
((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4332
(priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4333
if (signal_quality > 100)
4334
signal_quality = 100;
4335
else if (signal_quality < 1)
4338
IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
4339
signal_quality, rssi);
4341
quality = min(beacon_quality,
4343
min(tx_quality, min(rx_quality, signal_quality))));
4344
if (quality == beacon_quality)
4345
IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4347
if (quality == rate_quality)
4348
IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4350
if (quality == tx_quality)
4351
IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4353
if (quality == rx_quality)
4354
IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4356
if (quality == signal_quality)
4357
IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4360
priv->quality = quality;
4362
queue_delayed_work(priv->workqueue, &priv->gather_stats,
4363
IPW_STATS_INTERVAL);
4366
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
4367
static void ipw_bg_gather_stats(void *work)
4369
struct ipw_priv *priv = work;
4371
static void ipw_bg_gather_stats(struct work_struct *work)
4373
struct ipw_priv *priv =
4374
container_of(work, struct ipw_priv, gather_stats.work);
4376
mutex_lock(&priv->mutex);
4377
ipw_gather_stats(priv);
4378
mutex_unlock(&priv->mutex);
4381
/* Missed beacon behavior:
4382
* 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4383
* roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4384
* Above disassociate threshold, give up and stop scanning.
4385
* Roaming is disabled if disassociate_threshold <= roaming_threshold */
4386
static void ipw_handle_missed_beacon(struct ipw_priv *priv,
4389
priv->notif_missed_beacons = missed_count;
4391
if (missed_count > priv->disassociate_threshold &&
4392
priv->status & STATUS_ASSOCIATED) {
4393
/* If associated and we've hit the missed
4394
* beacon threshold, disassociate, turn
4395
* off roaming, and abort any active scans */
4396
IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4397
IPW_DL_STATE | IPW_DL_ASSOC,
4398
"Missed beacon: %d - disassociate\n", missed_count);
4399
priv->status &= ~STATUS_ROAMING;
4400
if (priv->status & STATUS_SCANNING) {
4401
IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4403
"Aborting scan with missed beacon.\n");
4404
queue_work(priv->workqueue, &priv->abort_scan);
4407
queue_work(priv->workqueue, &priv->disassociate);
4411
if (priv->status & STATUS_ROAMING) {
4412
/* If we are currently roaming, then just
4413
* print a debug statement... */
4414
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4415
"Missed beacon: %d - roam in progress\n",
4421
(missed_count > priv->roaming_threshold &&
4422
missed_count <= priv->disassociate_threshold)) {
4423
/* If we are not already roaming, set the ROAM
4424
* bit in the status and kick off a scan.
4425
* This can happen several times before we reach
4426
* disassociate_threshold. */
4427
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4428
"Missed beacon: %d - initiate "
4429
"roaming\n", missed_count);
4430
if (!(priv->status & STATUS_ROAMING)) {
4431
priv->status |= STATUS_ROAMING;
4432
if (!(priv->status & STATUS_SCANNING))
4433
queue_delayed_work(priv->workqueue,
4434
&priv->request_scan, 0);
4439
if (priv->status & STATUS_SCANNING) {
4440
/* Stop scan to keep fw from getting
4441
* stuck (only if we aren't roaming --
4442
* otherwise we'll never scan more than 2 or 3
4444
IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4445
"Aborting scan with missed beacon.\n");
4446
queue_work(priv->workqueue, &priv->abort_scan);
4449
IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
4453
* Handle host notification packet.
4454
* Called from interrupt routine
4456
static void ipw_rx_notification(struct ipw_priv *priv,
4457
struct ipw_rx_notification *notif)
4459
notif->size = le16_to_cpu(notif->size);
4461
IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
4463
switch (notif->subtype) {
4464
case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4465
struct notif_association *assoc = ¬if->u.assoc;
4467
switch (assoc->state) {
4468
case CMAS_ASSOCIATED:{
4469
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4471
"associated: '%s' " MAC_FMT
4473
escape_essid(priv->essid,
4475
MAC_ARG(priv->bssid));
4477
switch (priv->ieee->iw_mode) {
4479
memcpy(priv->ieee->bssid,
4480
priv->bssid, ETH_ALEN);
4484
memcpy(priv->ieee->bssid,
4485
priv->bssid, ETH_ALEN);
4487
/* clear out the station table */
4488
priv->num_stations = 0;
4491
("queueing adhoc check\n");
4492
queue_delayed_work(priv->
4502
priv->status &= ~STATUS_ASSOCIATING;
4503
priv->status |= STATUS_ASSOCIATED;
4504
queue_work(priv->workqueue,
4505
&priv->system_config);
4507
#ifdef CONFIG_IPW2200_QOS
4508
#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4509
le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4510
if ((priv->status & STATUS_AUTH) &&
4511
(IPW_GET_PACKET_STYPE(¬if->u.raw)
4512
== IEEE80211_STYPE_ASSOC_RESP)) {
4515
ieee80211_assoc_response)
4517
&& (notif->size <= 2314)) {
4530
ieee80211_rx_mgt(priv->
4535
¬if->u.raw, &stats);
4540
schedule_work(&priv->link_up);
4545
case CMAS_AUTHENTICATED:{
4547
status & (STATUS_ASSOCIATED |
4549
struct notif_authenticate *auth
4551
IPW_DEBUG(IPW_DL_NOTIF |
4554
"deauthenticated: '%s' "
4556
": (0x%04X) - %s \n",
4561
MAC_ARG(priv->bssid),
4562
ntohs(auth->status),
4568
~(STATUS_ASSOCIATING |
4572
schedule_work(&priv->link_down);
4576
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4578
"authenticated: '%s' " MAC_FMT
4580
escape_essid(priv->essid,
4582
MAC_ARG(priv->bssid));
4587
if (priv->status & STATUS_AUTH) {
4589
ieee80211_assoc_response
4593
ieee80211_assoc_response
4595
IPW_DEBUG(IPW_DL_NOTIF |
4598
"association failed (0x%04X): %s\n",
4599
ntohs(resp->status),
4605
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4607
"disassociated: '%s' " MAC_FMT
4609
escape_essid(priv->essid,
4611
MAC_ARG(priv->bssid));
4614
~(STATUS_DISASSOCIATING |
4615
STATUS_ASSOCIATING |
4616
STATUS_ASSOCIATED | STATUS_AUTH);
4617
if (priv->assoc_network
4618
&& (priv->assoc_network->
4620
WLAN_CAPABILITY_IBSS))
4621
ipw_remove_current_network
4624
schedule_work(&priv->link_down);
4629
case CMAS_RX_ASSOC_RESP:
4633
IPW_ERROR("assoc: unknown (%d)\n",
4641
case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4642
struct notif_authenticate *auth = ¬if->u.auth;
4643
switch (auth->state) {
4644
case CMAS_AUTHENTICATED:
4645
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4646
"authenticated: '%s' " MAC_FMT " \n",
4647
escape_essid(priv->essid,
4649
MAC_ARG(priv->bssid));
4650
priv->status |= STATUS_AUTH;
4654
if (priv->status & STATUS_AUTH) {
4655
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4657
"authentication failed (0x%04X): %s\n",
4658
ntohs(auth->status),
4659
ipw_get_status_code(ntohs
4663
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4665
"deauthenticated: '%s' " MAC_FMT "\n",
4666
escape_essid(priv->essid,
4668
MAC_ARG(priv->bssid));
4670
priv->status &= ~(STATUS_ASSOCIATING |
4674
schedule_work(&priv->link_down);
4677
case CMAS_TX_AUTH_SEQ_1:
4678
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4679
IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4681
case CMAS_RX_AUTH_SEQ_2:
4682
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4683
IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4685
case CMAS_AUTH_SEQ_1_PASS:
4686
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4687
IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4689
case CMAS_AUTH_SEQ_1_FAIL:
4690
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4691
IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4693
case CMAS_TX_AUTH_SEQ_3:
4694
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4695
IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4697
case CMAS_RX_AUTH_SEQ_4:
4698
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4699
IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4701
case CMAS_AUTH_SEQ_2_PASS:
4702
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4703
IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4705
case CMAS_AUTH_SEQ_2_FAIL:
4706
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4707
IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4710
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4711
IPW_DL_ASSOC, "TX_ASSOC\n");
4713
case CMAS_RX_ASSOC_RESP:
4714
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4715
IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
4718
case CMAS_ASSOCIATED:
4719
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4720
IPW_DL_ASSOC, "ASSOCIATED\n");
4723
IPW_DEBUG_NOTIF("auth: failure - %d\n",
4730
case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4731
struct notif_channel_result *x =
4732
¬if->u.channel_result;
4734
if (notif->size == sizeof(*x)) {
4735
IPW_DEBUG_SCAN("Scan result for channel %d\n",
4738
IPW_DEBUG_SCAN("Scan result of wrong size %d "
4739
"(should be %zd)\n",
4740
notif->size, sizeof(*x));
4745
case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4746
struct notif_scan_complete *x = ¬if->u.scan_complete;
4747
if (notif->size == sizeof(*x)) {
4749
("Scan completed: type %d, %d channels, "
4750
"%d status\n", x->scan_type,
4751
x->num_channels, x->status);
4753
IPW_ERROR("Scan completed of wrong size %d "
4754
"(should be %zd)\n",
4755
notif->size, sizeof(*x));
4759
~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4761
wake_up_interruptible(&priv->wait_state);
4762
cancel_delayed_work(&priv->scan_check);
4764
if (priv->status & STATUS_EXIT_PENDING)
4767
priv->ieee->scans++;
4769
#ifdef CONFIG_IPW2200_MONITOR
4770
if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
4771
priv->status |= STATUS_SCAN_FORCED;
4772
queue_delayed_work(priv->workqueue,
4773
&priv->request_scan, 0);
4776
priv->status &= ~STATUS_SCAN_FORCED;
4777
#endif /* CONFIG_IPW2200_MONITOR */
4779
if (!(priv->status & (STATUS_ASSOCIATED |
4780
STATUS_ASSOCIATING |
4782
STATUS_DISASSOCIATING)))
4783
queue_work(priv->workqueue, &priv->associate);
4784
else if (priv->status & STATUS_ROAMING) {
4785
if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4786
/* If a scan completed and we are in roam mode, then
4787
* the scan that completed was the one requested as a
4788
* result of entering roam... so, schedule the
4790
queue_work(priv->workqueue,
4793
/* Don't schedule if we aborted the scan */
4794
priv->status &= ~STATUS_ROAMING;
4795
} else if (priv->status & STATUS_SCAN_PENDING)
4796
queue_delayed_work(priv->workqueue,
4797
&priv->request_scan, 0);
4798
else if (priv->config & CFG_BACKGROUND_SCAN
4799
&& priv->status & STATUS_ASSOCIATED)
4800
queue_delayed_work(priv->workqueue,
4801
&priv->request_scan, HZ);
4803
/* Send an empty event to user space.
4804
* We don't send the received data on the event because
4805
* it would require us to do complex transcoding, and
4806
* we want to minimise the work done in the irq handler
4807
* Use a request to extract the data.
4808
* Also, we generate this even for any scan, regardless
4809
* on how the scan was initiated. User space can just
4810
* sync on periodic scan to get fresh data...
4812
if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) {
4813
union iwreq_data wrqu;
4815
wrqu.data.length = 0;
4816
wrqu.data.flags = 0;
4817
wireless_send_event(priv->net_dev, SIOCGIWSCAN,
4823
case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4824
struct notif_frag_length *x = ¬if->u.frag_len;
4826
if (notif->size == sizeof(*x))
4827
IPW_ERROR("Frag length: %d\n",
4828
le16_to_cpu(x->frag_length));
4830
IPW_ERROR("Frag length of wrong size %d "
4831
"(should be %zd)\n",
4832
notif->size, sizeof(*x));
4836
case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4837
struct notif_link_deterioration *x =
4838
¬if->u.link_deterioration;
4840
if (notif->size == sizeof(*x)) {
4841
IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4842
"link deterioration: type %d, cnt %d\n",
4843
x->silence_notification_type,
4845
memcpy(&priv->last_link_deterioration, x,
4848
IPW_ERROR("Link Deterioration of wrong size %d "
4849
"(should be %zd)\n",
4850
notif->size, sizeof(*x));
4855
case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4856
IPW_ERROR("Dino config\n");
4858
&& priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
4859
IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
4864
case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4865
struct notif_beacon_state *x = ¬if->u.beacon_state;
4866
if (notif->size != sizeof(*x)) {
4868
("Beacon state of wrong size %d (should "
4869
"be %zd)\n", notif->size, sizeof(*x));
4873
if (le32_to_cpu(x->state) ==
4874
HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4875
ipw_handle_missed_beacon(priv,
4882
case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4883
struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key;
4884
if (notif->size == sizeof(*x)) {
4885
IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4886
"0x%02x station %d\n",
4887
x->key_state, x->security_type,
4893
("TGi Tx Key of wrong size %d (should be %zd)\n",
4894
notif->size, sizeof(*x));
4898
case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4899
struct notif_calibration *x = ¬if->u.calibration;
4901
if (notif->size == sizeof(*x)) {
4902
memcpy(&priv->calib, x, sizeof(*x));
4903
IPW_DEBUG_INFO("TODO: Calibration\n");
4908
("Calibration of wrong size %d (should be %zd)\n",
4909
notif->size, sizeof(*x));
4913
case HOST_NOTIFICATION_NOISE_STATS:{
4914
if (notif->size == sizeof(u32)) {
4915
priv->exp_avg_noise =
4916
exponential_average(priv->exp_avg_noise,
4917
(u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4923
("Noise stat is wrong size %d (should be %zd)\n",
4924
notif->size, sizeof(u32));
4929
IPW_DEBUG_NOTIF("Unknown notification: "
4930
"subtype=%d,flags=0x%2x,size=%d\n",
4931
notif->subtype, notif->flags, notif->size);
4936
* Destroys all DMA structures and initialise them again
4939
* @return error code
4941
static int ipw_queue_reset(struct ipw_priv *priv)
4944
/** @todo customize queue sizes */
4945
int nTx = 64, nTxCmd = 8;
4946
ipw_tx_queue_free(priv);
4948
rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
4949
IPW_TX_CMD_QUEUE_READ_INDEX,
4950
IPW_TX_CMD_QUEUE_WRITE_INDEX,
4951
IPW_TX_CMD_QUEUE_BD_BASE,
4952
IPW_TX_CMD_QUEUE_BD_SIZE);
4954
IPW_ERROR("Tx Cmd queue init failed\n");
4958
rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
4959
IPW_TX_QUEUE_0_READ_INDEX,
4960
IPW_TX_QUEUE_0_WRITE_INDEX,
4961
IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
4963
IPW_ERROR("Tx 0 queue init failed\n");
4966
rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
4967
IPW_TX_QUEUE_1_READ_INDEX,
4968
IPW_TX_QUEUE_1_WRITE_INDEX,
4969
IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
4971
IPW_ERROR("Tx 1 queue init failed\n");
4974
rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
4975
IPW_TX_QUEUE_2_READ_INDEX,
4976
IPW_TX_QUEUE_2_WRITE_INDEX,
4977
IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
4979
IPW_ERROR("Tx 2 queue init failed\n");
4982
rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
4983
IPW_TX_QUEUE_3_READ_INDEX,
4984
IPW_TX_QUEUE_3_WRITE_INDEX,
4985
IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
4987
IPW_ERROR("Tx 3 queue init failed\n");
4991
priv->rx_bufs_min = 0;
4992
priv->rx_pend_max = 0;
4996
ipw_tx_queue_free(priv);
5001
* Reclaim Tx queue entries no more used by NIC.
5003
* When FW adwances 'R' index, all entries between old and
5004
* new 'R' index need to be reclaimed. As result, some free space
5005
* forms. If there is enough free space (> low mark), wake Tx queue.
5007
* @note Need to protect against garbage in 'R' index
5011
* @return Number of used entries remains in the queue
5013
static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
5014
struct clx2_tx_queue *txq, int qindex)
5018
struct clx2_queue *q = &txq->q;
5020
hw_tail = ipw_read32(priv, q->reg_r);
5021
if (hw_tail >= q->n_bd) {
5023
("Read index for DMA queue (%d) is out of range [0-%d)\n",
5027
for (; q->last_used != hw_tail;
5028
q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
5029
ipw_queue_tx_free_tfd(priv, txq);
5033
if ((ipw_queue_space(q) > q->low_mark) &&
5035
(priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
5036
netif_wake_queue(priv->net_dev);
5037
used = q->first_empty - q->last_used;
5044
static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
5047
struct clx2_tx_queue *txq = &priv->txq_cmd;
5048
struct clx2_queue *q = &txq->q;
5049
struct tfd_frame *tfd;
5051
if (ipw_queue_space(q) < (sync ? 1 : 2)) {
5052
IPW_ERROR("No space for Tx\n");
5056
tfd = &txq->bd[q->first_empty];
5057
txq->txb[q->first_empty] = NULL;
5059
memset(tfd, 0, sizeof(*tfd));
5060
tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
5061
tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
5063
tfd->u.cmd.index = hcmd;
5064
tfd->u.cmd.length = len;
5065
memcpy(tfd->u.cmd.payload, buf, len);
5066
q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
5067
ipw_write32(priv, q->reg_w, q->first_empty);
5068
_ipw_read32(priv, 0x90);
5074
* Rx theory of operation
5076
* The host allocates 32 DMA target addresses and passes the host address
5077
* to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
5081
* The host/firmware share two index registers for managing the Rx buffers.
5083
* The READ index maps to the first position that the firmware may be writing
5084
* to -- the driver can read up to (but not including) this position and get
5086
* The READ index is managed by the firmware once the card is enabled.
5088
* The WRITE index maps to the last position the driver has read from -- the
5089
* position preceding WRITE is the last slot the firmware can place a packet.
5091
* The queue is empty (no good data) if WRITE = READ - 1, and is full if
5094
* During initialization the host sets up the READ queue position to the first
5095
* INDEX position, and WRITE to the last (READ - 1 wrapped)
5097
* When the firmware places a packet in a buffer it will advance the READ index
5098
* and fire the RX interrupt. The driver can then query the READ index and
5099
* process as many packets as possible, moving the WRITE index forward as it
5100
* resets the Rx queue buffers with new memory.
5102
* The management in the driver is as follows:
5103
* + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
5104
* ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
5105
* to replensish the ipw->rxq->rx_free.
5106
* + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
5107
* ipw->rxq is replenished and the READ INDEX is updated (updating the
5108
* 'processed' and 'read' driver indexes as well)
5109
* + A received packet is processed and handed to the kernel network stack,
5110
* detached from the ipw->rxq. The driver 'processed' index is updated.
5111
* + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
5112
* list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
5113
* INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
5114
* were enough free buffers and RX_STALLED is set it is cleared.
5119
* ipw_rx_queue_alloc() Allocates rx_free
5120
* ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
5121
* ipw_rx_queue_restock
5122
* ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
5123
* queue, updates firmware pointers, and updates
5124
* the WRITE index. If insufficient rx_free buffers
5125
* are available, schedules ipw_rx_queue_replenish
5127
* -- enable interrupts --
5128
* ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
5129
* READ INDEX, detaching the SKB from the pool.
5130
* Moves the packet buffer from queue to rx_used.
5131
* Calls ipw_rx_queue_restock to refill any empty
5138
* If there are slots in the RX queue that need to be restocked,
5139
* and we have free pre-allocated buffers, fill the ranks as much
5140
* as we can pulling from rx_free.
5142
* This moves the 'write' index forward to catch up with 'processed', and
5143
* also updates the memory address in the firmware to reference the new
5146
static void ipw_rx_queue_restock(struct ipw_priv *priv)
5148
struct ipw_rx_queue *rxq = priv->rxq;
5149
struct list_head *element;
5150
struct ipw_rx_mem_buffer *rxb;
5151
unsigned long flags;
5154
spin_lock_irqsave(&rxq->lock, flags);
5156
while ((rxq->write != rxq->processed) && (rxq->free_count)) {
5157
element = rxq->rx_free.next;
5158
rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5161
ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
5163
rxq->queue[rxq->write] = rxb;
5164
rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5167
spin_unlock_irqrestore(&rxq->lock, flags);
5169
/* If the pre-allocated buffer pool is dropping low, schedule to
5171
if (rxq->free_count <= RX_LOW_WATERMARK)
5172
queue_work(priv->workqueue, &priv->rx_replenish);
5174
/* If we've added more space for the firmware to place data, tell it */
5175
if (write != rxq->write)
5176
ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
5180
* Move all used packet from rx_used to rx_free, allocating a new SKB for each.
5181
* Also restock the Rx queue via ipw_rx_queue_restock.
5183
* This is called as a scheduled work item (except for during intialization)
5185
static void ipw_rx_queue_replenish(void *data)
5187
struct ipw_priv *priv = data;
5188
struct ipw_rx_queue *rxq = priv->rxq;
5189
struct list_head *element;
5190
struct ipw_rx_mem_buffer *rxb;
5191
unsigned long flags;
5193
spin_lock_irqsave(&rxq->lock, flags);
5194
while (!list_empty(&rxq->rx_used)) {
5195
element = rxq->rx_used.next;
5196
rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5197
rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
5199
printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5200
priv->net_dev->name);
5201
/* We don't reschedule replenish work here -- we will
5202
* call the restock method and if it still needs
5203
* more buffers it will schedule replenish */
5209
pci_map_single(priv->pci_dev, rxb->skb->data,
5210
IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
5212
list_add_tail(&rxb->list, &rxq->rx_free);
5215
spin_unlock_irqrestore(&rxq->lock, flags);
5217
ipw_rx_queue_restock(priv);
5220
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
5221
static void ipw_bg_rx_queue_replenish(void *work)
5223
struct ipw_priv *priv = work;
5225
static void ipw_bg_rx_queue_replenish(struct work_struct *work)
5227
struct ipw_priv *priv =
5228
container_of(work, struct ipw_priv, rx_replenish);
5230
mutex_lock(&priv->mutex);
5231
ipw_rx_queue_replenish(priv);
5232
mutex_unlock(&priv->mutex);
5235
/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
5236
* If an SKB has been detached, the POOL needs to have its SKB set to NULL
5237
* This free routine walks the list of POOL entries and if SKB is set to
5238
* non NULL it is unmapped and freed
5240
static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
5247
for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5248
if (rxq->pool[i].skb != NULL) {
5249
pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
5250
IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
5251
dev_kfree_skb(rxq->pool[i].skb);
5258
static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5260
struct ipw_rx_queue *rxq;
5263
rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
5264
if (unlikely(!rxq)) {
5265
IPW_ERROR("memory allocation failed\n");
5268
spin_lock_init(&rxq->lock);
5269
INIT_LIST_HEAD(&rxq->rx_free);
5270
INIT_LIST_HEAD(&rxq->rx_used);
5272
/* Fill the rx_used queue with _all_ of the Rx buffers */
5273
for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
5274
list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5276
/* Set us so that we have processed and used all buffers, but have
5277
* not restocked the Rx queue with fresh buffers */
5278
rxq->read = rxq->write = 0;
5279
rxq->processed = RX_QUEUE_SIZE - 1;
5280
rxq->free_count = 0;
5285
static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5287
rate &= ~IEEE80211_BASIC_RATE_MASK;
5288
if (ieee_mode == IEEE_A) {
5290
case IEEE80211_OFDM_RATE_6MB:
5291
return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
5293
case IEEE80211_OFDM_RATE_9MB:
5294
return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
5296
case IEEE80211_OFDM_RATE_12MB:
5298
rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
5299
case IEEE80211_OFDM_RATE_18MB:
5301
rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
5302
case IEEE80211_OFDM_RATE_24MB:
5304
rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
5305
case IEEE80211_OFDM_RATE_36MB:
5307
rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
5308
case IEEE80211_OFDM_RATE_48MB:
5310
rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
5311
case IEEE80211_OFDM_RATE_54MB:
5313
rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5321
case IEEE80211_CCK_RATE_1MB:
5322
return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
5323
case IEEE80211_CCK_RATE_2MB:
5324
return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
5325
case IEEE80211_CCK_RATE_5MB:
5326
return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
5327
case IEEE80211_CCK_RATE_11MB:
5328
return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
5331
/* If we are limited to B modulations, bail at this point */
5332
if (ieee_mode == IEEE_B)
5337
case IEEE80211_OFDM_RATE_6MB:
5338
return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
5339
case IEEE80211_OFDM_RATE_9MB:
5340
return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
5341
case IEEE80211_OFDM_RATE_12MB:
5342
return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
5343
case IEEE80211_OFDM_RATE_18MB:
5344
return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
5345
case IEEE80211_OFDM_RATE_24MB:
5346
return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
5347
case IEEE80211_OFDM_RATE_36MB:
5348
return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
5349
case IEEE80211_OFDM_RATE_48MB:
5350
return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
5351
case IEEE80211_OFDM_RATE_54MB:
5352
return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5358
static int ipw_compatible_rates(struct ipw_priv *priv,
5359
const struct ieee80211_network *network,
5360
struct ipw_supported_rates *rates)
5364
memset(rates, 0, sizeof(*rates));
5365
num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
5366
rates->num_rates = 0;
5367
for (i = 0; i < num_rates; i++) {
5368
if (!ipw_is_rate_in_mask(priv, network->mode,
5369
network->rates[i])) {
5371
if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
5372
IPW_DEBUG_SCAN("Adding masked mandatory "
5375
rates->supported_rates[rates->num_rates++] =
5380
IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5381
network->rates[i], priv->rates_mask);
5385
rates->supported_rates[rates->num_rates++] = network->rates[i];
5388
num_rates = min(network->rates_ex_len,
5389
(u8) (IPW_MAX_RATES - num_rates));
5390
for (i = 0; i < num_rates; i++) {
5391
if (!ipw_is_rate_in_mask(priv, network->mode,
5392
network->rates_ex[i])) {
5393
if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
5394
IPW_DEBUG_SCAN("Adding masked mandatory "
5396
network->rates_ex[i]);
5397
rates->supported_rates[rates->num_rates++] =
5402
IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5403
network->rates_ex[i], priv->rates_mask);
5407
rates->supported_rates[rates->num_rates++] =
5408
network->rates_ex[i];
5414
static void ipw_copy_rates(struct ipw_supported_rates *dest,
5415
const struct ipw_supported_rates *src)
5418
for (i = 0; i < src->num_rates; i++)
5419
dest->supported_rates[i] = src->supported_rates[i];
5420
dest->num_rates = src->num_rates;
5423
/* TODO: Look at sniffed packets in the air to determine if the basic rate
5424
* mask should ever be used -- right now all callers to add the scan rates are
5425
* set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5426
static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
5427
u8 modulation, u32 rate_mask)
5429
u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
5430
IEEE80211_BASIC_RATE_MASK : 0;
5432
if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
5433
rates->supported_rates[rates->num_rates++] =
5434
IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
5436
if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
5437
rates->supported_rates[rates->num_rates++] =
5438
IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
5440
if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
5441
rates->supported_rates[rates->num_rates++] = basic_mask |
5442
IEEE80211_CCK_RATE_5MB;
5444
if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
5445
rates->supported_rates[rates->num_rates++] = basic_mask |
5446
IEEE80211_CCK_RATE_11MB;
5449
static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
5450
u8 modulation, u32 rate_mask)
5452
u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
5453
IEEE80211_BASIC_RATE_MASK : 0;
5455
if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
5456
rates->supported_rates[rates->num_rates++] = basic_mask |
5457
IEEE80211_OFDM_RATE_6MB;
5459
if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
5460
rates->supported_rates[rates->num_rates++] =
5461
IEEE80211_OFDM_RATE_9MB;
5463
if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
5464
rates->supported_rates[rates->num_rates++] = basic_mask |
5465
IEEE80211_OFDM_RATE_12MB;
5467
if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
5468
rates->supported_rates[rates->num_rates++] =
5469
IEEE80211_OFDM_RATE_18MB;
5471
if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
5472
rates->supported_rates[rates->num_rates++] = basic_mask |
5473
IEEE80211_OFDM_RATE_24MB;
5475
if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
5476
rates->supported_rates[rates->num_rates++] =
5477
IEEE80211_OFDM_RATE_36MB;
5479
if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
5480
rates->supported_rates[rates->num_rates++] =
5481
IEEE80211_OFDM_RATE_48MB;
5483
if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
5484
rates->supported_rates[rates->num_rates++] =
5485
IEEE80211_OFDM_RATE_54MB;
5488
struct ipw_network_match {
5489
struct ieee80211_network *network;
5490
struct ipw_supported_rates rates;
5493
static int ipw_find_adhoc_network(struct ipw_priv *priv,
5494
struct ipw_network_match *match,
5495
struct ieee80211_network *network,
5498
struct ipw_supported_rates rates;
5500
/* Verify that this network's capability is compatible with the
5501
* current mode (AdHoc or Infrastructure) */
5502
if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5503
!(network->capability & WLAN_CAPABILITY_IBSS))) {
5504
IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5505
"capability mismatch.\n",
5506
escape_essid(network->ssid, network->ssid_len),
5507
MAC_ARG(network->bssid));
5511
/* If we do not have an ESSID for this AP, we can not associate with
5513
if (network->flags & NETWORK_EMPTY_ESSID) {
5514
IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5515
"because of hidden ESSID.\n",
5516
escape_essid(network->ssid, network->ssid_len),
5517
MAC_ARG(network->bssid));
5521
if (unlikely(roaming)) {
5522
/* If we are roaming, then ensure check if this is a valid
5523
* network to try and roam to */
5524
if ((network->ssid_len != match->network->ssid_len) ||
5525
memcmp(network->ssid, match->network->ssid,
5526
network->ssid_len)) {
5527
IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5528
"because of non-network ESSID.\n",
5529
escape_essid(network->ssid,
5531
MAC_ARG(network->bssid));
5535
/* If an ESSID has been configured then compare the broadcast
5537
if ((priv->config & CFG_STATIC_ESSID) &&
5538
((network->ssid_len != priv->essid_len) ||
5539
memcmp(network->ssid, priv->essid,
5540
min(network->ssid_len, priv->essid_len)))) {
5541
char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5544
escape_essid(network->ssid, network->ssid_len),
5546
IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5547
"because of ESSID mismatch: '%s'.\n",
5548
escaped, MAC_ARG(network->bssid),
5549
escape_essid(priv->essid,
5555
/* If the old network rate is better than this one, don't bother
5556
* testing everything else. */
5558
if (network->time_stamp[0] < match->network->time_stamp[0]) {
5559
IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5560
"current network.\n",
5561
escape_essid(match->network->ssid,
5562
match->network->ssid_len));
5564
} else if (network->time_stamp[1] < match->network->time_stamp[1]) {
5565
IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5566
"current network.\n",
5567
escape_essid(match->network->ssid,
5568
match->network->ssid_len));
5572
/* Now go through and see if the requested network is valid... */
5573
if (priv->ieee->scan_age != 0 &&
5574
time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5575
IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5576
"because of age: %ums.\n",
5577
escape_essid(network->ssid, network->ssid_len),
5578
MAC_ARG(network->bssid),
5579
jiffies_to_msecs(jiffies -
5580
network->last_scanned));
5584
if ((priv->config & CFG_STATIC_CHANNEL) &&
5585
(network->channel != priv->channel)) {
5586
IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5587
"because of channel mismatch: %d != %d.\n",
5588
escape_essid(network->ssid, network->ssid_len),
5589
MAC_ARG(network->bssid),
5590
network->channel, priv->channel);
5594
/* Verify privacy compatability */
5595
if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5596
((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5597
IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5598
"because of privacy mismatch: %s != %s.\n",
5599
escape_essid(network->ssid, network->ssid_len),
5600
MAC_ARG(network->bssid),
5602
capability & CAP_PRIVACY_ON ? "on" : "off",
5604
capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5609
if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5610
IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5611
"because of the same BSSID match: " MAC_FMT
5612
".\n", escape_essid(network->ssid,
5614
MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5618
/* Filter out any incompatible freq / mode combinations */
5619
if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5620
IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5621
"because of invalid frequency/mode "
5623
escape_essid(network->ssid, network->ssid_len),
5624
MAC_ARG(network->bssid));
5628
/* Ensure that the rates supported by the driver are compatible with
5629
* this AP, including verification of basic rates (mandatory) */
5630
if (!ipw_compatible_rates(priv, network, &rates)) {
5631
IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5632
"because configured rate mask excludes "
5633
"AP mandatory rate.\n",
5634
escape_essid(network->ssid, network->ssid_len),
5635
MAC_ARG(network->bssid));
5639
if (rates.num_rates == 0) {
5640
IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5641
"because of no compatible rates.\n",
5642
escape_essid(network->ssid, network->ssid_len),
5643
MAC_ARG(network->bssid));
5647
/* TODO: Perform any further minimal comparititive tests. We do not
5648
* want to put too much policy logic here; intelligent scan selection
5649
* should occur within a generic IEEE 802.11 user space tool. */
5651
/* Set up 'new' AP to this network */
5652
ipw_copy_rates(&match->rates, &rates);
5653
match->network = network;
5654
IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5655
escape_essid(network->ssid, network->ssid_len),
5656
MAC_ARG(network->bssid));
5661
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
5662
static void ipw_merge_adhoc_network(void *work)
5664
struct ipw_priv *priv = work;
5666
static void ipw_merge_adhoc_network(struct work_struct *work)
5668
struct ipw_priv *priv =
5669
container_of(work, struct ipw_priv, merge_networks);
5671
struct ieee80211_network *network = NULL;
5672
struct ipw_network_match match = {
5673
.network = priv->assoc_network
5676
if ((priv->status & STATUS_ASSOCIATED) &&
5677
(priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5678
/* First pass through ROAM process -- look for a better
5680
unsigned long flags;
5682
spin_lock_irqsave(&priv->ieee->lock, flags);
5683
list_for_each_entry(network, &priv->ieee->network_list, list) {
5684
if (network != priv->assoc_network)
5685
ipw_find_adhoc_network(priv, &match, network,
5688
spin_unlock_irqrestore(&priv->ieee->lock, flags);
5690
if (match.network == priv->assoc_network) {
5691
IPW_DEBUG_MERGE("No better ADHOC in this network to "
5696
mutex_lock(&priv->mutex);
5697
if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5698
IPW_DEBUG_MERGE("remove network %s\n",
5699
escape_essid(priv->essid,
5701
ipw_remove_current_network(priv);
5704
ipw_disassociate(priv);
5705
priv->assoc_network = match.network;
5706
mutex_unlock(&priv->mutex);
5711
static int ipw_best_network(struct ipw_priv *priv,
5712
struct ipw_network_match *match,
5713
struct ieee80211_network *network, int roaming)
5715
struct ipw_supported_rates rates;
5717
/* Verify that this network's capability is compatible with the
5718
* current mode (AdHoc or Infrastructure) */
5719
if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
5720
!(network->capability & WLAN_CAPABILITY_ESS)) ||
5721
(priv->ieee->iw_mode == IW_MODE_ADHOC &&
5722
!(network->capability & WLAN_CAPABILITY_IBSS))) {
5723
IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
5724
"capability mismatch.\n",
5725
escape_essid(network->ssid, network->ssid_len),
5726
MAC_ARG(network->bssid));
5730
/* If we do not have an ESSID for this AP, we can not associate with
5732
if (network->flags & NETWORK_EMPTY_ESSID) {
5733
IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5734
"because of hidden ESSID.\n",
5735
escape_essid(network->ssid, network->ssid_len),
5736
MAC_ARG(network->bssid));
5740
if (unlikely(roaming)) {
5741
/* If we are roaming, then ensure check if this is a valid
5742
* network to try and roam to */
5743
if ((network->ssid_len != match->network->ssid_len) ||
5744
memcmp(network->ssid, match->network->ssid,
5745
network->ssid_len)) {
5746
IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5747
"because of non-network ESSID.\n",
5748
escape_essid(network->ssid,
5750
MAC_ARG(network->bssid));
5754
/* If an ESSID has been configured then compare the broadcast
5756
if ((priv->config & CFG_STATIC_ESSID) &&
5757
((network->ssid_len != priv->essid_len) ||
5758
memcmp(network->ssid, priv->essid,
5759
min(network->ssid_len, priv->essid_len)))) {
5760
char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5762
escape_essid(network->ssid, network->ssid_len),
5764
IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5765
"because of ESSID mismatch: '%s'.\n",
5766
escaped, MAC_ARG(network->bssid),
5767
escape_essid(priv->essid,
5773
/* If the old network rate is better than this one, don't bother
5774
* testing everything else. */
5775
if (match->network && match->network->stats.rssi > network->stats.rssi) {
5776
char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5778
escape_essid(network->ssid, network->ssid_len),
5780
IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5781
"'%s (" MAC_FMT ")' has a stronger signal.\n",
5782
escaped, MAC_ARG(network->bssid),
5783
escape_essid(match->network->ssid,
5784
match->network->ssid_len),
5785
MAC_ARG(match->network->bssid));
5789
/* If this network has already had an association attempt within the
5790
* last 3 seconds, do not try and associate again... */
5791
if (network->last_associate &&
5792
time_after(network->last_associate + (HZ * 3UL), jiffies)) {
5793
IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5794
"because of storming (%ums since last "
5795
"assoc attempt).\n",
5796
escape_essid(network->ssid, network->ssid_len),
5797
MAC_ARG(network->bssid),
5798
jiffies_to_msecs(jiffies -
5799
network->last_associate));
5803
/* Now go through and see if the requested network is valid... */
5804
if (priv->ieee->scan_age != 0 &&
5805
time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5806
IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5807
"because of age: %ums.\n",
5808
escape_essid(network->ssid, network->ssid_len),
5809
MAC_ARG(network->bssid),
5810
jiffies_to_msecs(jiffies -
5811
network->last_scanned));
5815
if ((priv->config & CFG_STATIC_CHANNEL) &&
5816
(network->channel != priv->channel)) {
5817
IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5818
"because of channel mismatch: %d != %d.\n",
5819
escape_essid(network->ssid, network->ssid_len),
5820
MAC_ARG(network->bssid),
5821
network->channel, priv->channel);
5825
/* Verify privacy compatability */
5826
if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5827
((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5828
IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5829
"because of privacy mismatch: %s != %s.\n",
5830
escape_essid(network->ssid, network->ssid_len),
5831
MAC_ARG(network->bssid),
5832
priv->capability & CAP_PRIVACY_ON ? "on" :
5834
network->capability &
5835
WLAN_CAPABILITY_PRIVACY ? "on" : "off");
5839
if ((priv->config & CFG_STATIC_BSSID) &&
5840
memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5841
IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5842
"because of BSSID mismatch: " MAC_FMT ".\n",
5843
escape_essid(network->ssid, network->ssid_len),
5844
MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5848
/* Filter out any incompatible freq / mode combinations */
5849
if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5850
IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5851
"because of invalid frequency/mode "
5853
escape_essid(network->ssid, network->ssid_len),
5854
MAC_ARG(network->bssid));
5858
/* Filter out invalid channel in current GEO */
5859
if (!ipw_is_valid_channel(priv->ieee, network->channel)) {
5860
IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5861
"because of invalid channel in current GEO\n",
5862
escape_essid(network->ssid, network->ssid_len),
5863
MAC_ARG(network->bssid));
5867
/* Ensure that the rates supported by the driver are compatible with
5868
* this AP, including verification of basic rates (mandatory) */
5869
if (!ipw_compatible_rates(priv, network, &rates)) {
5870
IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5871
"because configured rate mask excludes "
5872
"AP mandatory rate.\n",
5873
escape_essid(network->ssid, network->ssid_len),
5874
MAC_ARG(network->bssid));
5878
if (rates.num_rates == 0) {
5879
IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5880
"because of no compatible rates.\n",
5881
escape_essid(network->ssid, network->ssid_len),
5882
MAC_ARG(network->bssid));
5886
/* TODO: Perform any further minimal comparititive tests. We do not
5887
* want to put too much policy logic here; intelligent scan selection
5888
* should occur within a generic IEEE 802.11 user space tool. */
5890
/* Set up 'new' AP to this network */
5891
ipw_copy_rates(&match->rates, &rates);
5892
match->network = network;
5894
IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5895
escape_essid(network->ssid, network->ssid_len),
5896
MAC_ARG(network->bssid));
5901
static void ipw_adhoc_create(struct ipw_priv *priv,
5902
struct ieee80211_network *network)
5904
const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
5908
* For the purposes of scanning, we can set our wireless mode
5909
* to trigger scans across combinations of bands, but when it
5910
* comes to creating a new ad-hoc network, we have tell the FW
5911
* exactly which band to use.
5913
* We also have the possibility of an invalid channel for the
5914
* chossen band. Attempting to create a new ad-hoc network
5915
* with an invalid channel for wireless mode will trigger a
5919
switch (ipw_is_valid_channel(priv->ieee, priv->channel)) {
5920
case IEEE80211_52GHZ_BAND:
5921
network->mode = IEEE_A;
5922
i = ipw_channel_to_index(priv->ieee, priv->channel);
5924
if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5925
IPW_WARNING("Overriding invalid channel\n");
5926
priv->channel = geo->a[0].channel;
5930
case IEEE80211_24GHZ_BAND:
5931
if (priv->ieee->mode & IEEE_G)
5932
network->mode = IEEE_G;
5934
network->mode = IEEE_B;
5935
i = ipw_channel_to_index(priv->ieee, priv->channel);
5937
if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5938
IPW_WARNING("Overriding invalid channel\n");
5939
priv->channel = geo->bg[0].channel;
5944
IPW_WARNING("Overriding invalid channel\n");
5945
if (priv->ieee->mode & IEEE_A) {
5946
network->mode = IEEE_A;
5947
priv->channel = geo->a[0].channel;
5948
} else if (priv->ieee->mode & IEEE_G) {
5949
network->mode = IEEE_G;
5950
priv->channel = geo->bg[0].channel;
5952
network->mode = IEEE_B;
5953
priv->channel = geo->bg[0].channel;
5958
network->channel = priv->channel;
5959
priv->config |= CFG_ADHOC_PERSIST;
5960
ipw_create_bssid(priv, network->bssid);
5961
network->ssid_len = priv->essid_len;
5962
memcpy(network->ssid, priv->essid, priv->essid_len);
5963
memset(&network->stats, 0, sizeof(network->stats));
5964
network->capability = WLAN_CAPABILITY_IBSS;
5965
if (!(priv->config & CFG_PREAMBLE_LONG))
5966
network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
5967
if (priv->capability & CAP_PRIVACY_ON)
5968
network->capability |= WLAN_CAPABILITY_PRIVACY;
5969
network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
5970
memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
5971
network->rates_ex_len = priv->rates.num_rates - network->rates_len;
5972
memcpy(network->rates_ex,
5973
&priv->rates.supported_rates[network->rates_len],
5974
network->rates_ex_len);
5975
network->last_scanned = 0;
5977
network->last_associate = 0;
5978
network->time_stamp[0] = 0;
5979
network->time_stamp[1] = 0;
5980
network->beacon_interval = 100; /* Default */
5981
network->listen_interval = 10; /* Default */
5982
network->atim_window = 0; /* Default */
5983
network->wpa_ie_len = 0;
5984
network->rsn_ie_len = 0;
5987
static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5989
struct ipw_tgi_tx_key key;
5991
if (!(priv->ieee->sec.flags & (1 << index)))
5995
memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5996
key.security_type = type;
5997
key.station_index = 0; /* always 0 for BSS */
5999
/* 0 for new key; previous value of counter (after fatal error) */
6000
key.tx_counter[0] = cpu_to_le32(0);
6001
key.tx_counter[1] = cpu_to_le32(0);
6003
ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
6006
static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
6008
struct ipw_wep_key key;
6011
key.cmd_id = DINO_CMD_WEP_KEY;
6014
/* Note: AES keys cannot be set for multiple times.
6015
* Only set it at the first time. */
6016
for (i = 0; i < 4; i++) {
6017
key.key_index = i | type;
6018
if (!(priv->ieee->sec.flags & (1 << i))) {
6023
key.key_size = priv->ieee->sec.key_sizes[i];
6024
memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
6026
ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
6030
static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
6032
if (priv->ieee->host_encrypt)
6037
priv->sys_config.disable_unicast_decryption = 0;
6038
priv->ieee->host_decrypt = 0;
6041
priv->sys_config.disable_unicast_decryption = 1;
6042
priv->ieee->host_decrypt = 1;
6045
priv->sys_config.disable_unicast_decryption = 0;
6046
priv->ieee->host_decrypt = 0;
6049
priv->sys_config.disable_unicast_decryption = 1;
6056
static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
6058
if (priv->ieee->host_encrypt)
6063
priv->sys_config.disable_multicast_decryption = 0;
6066
priv->sys_config.disable_multicast_decryption = 1;
6069
priv->sys_config.disable_multicast_decryption = 0;
6072
priv->sys_config.disable_multicast_decryption = 1;
6079
static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
6081
switch (priv->ieee->sec.level) {
6083
if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6084
ipw_send_tgi_tx_key(priv,
6085
DCT_FLAG_EXT_SECURITY_CCM,
6086
priv->ieee->sec.active_key);
6088
if (!priv->ieee->host_mc_decrypt)
6089
ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
6092
if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6093
ipw_send_tgi_tx_key(priv,
6094
DCT_FLAG_EXT_SECURITY_TKIP,
6095
priv->ieee->sec.active_key);
6098
ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
6099
ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
6100
ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
6108
static void ipw_adhoc_check(void *data)
6110
struct ipw_priv *priv = data;
6112
if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
6113
!(priv->config & CFG_ADHOC_PERSIST)) {
6114
IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
6115
IPW_DL_STATE | IPW_DL_ASSOC,
6116
"Missed beacon: %d - disassociate\n",
6117
priv->missed_adhoc_beacons);
6118
ipw_remove_current_network(priv);
6119
ipw_disassociate(priv);
6123
queue_delayed_work(priv->workqueue, &priv->adhoc_check,
6124
priv->assoc_request.beacon_interval);
6127
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
6128
static void ipw_bg_adhoc_check(void *work)
6130
struct ipw_priv *priv = work;
6132
static void ipw_bg_adhoc_check(struct work_struct *work)
6134
struct ipw_priv *priv =
6135
container_of(work, struct ipw_priv, adhoc_check.work);
6137
mutex_lock(&priv->mutex);
6138
ipw_adhoc_check(priv);
6139
mutex_unlock(&priv->mutex);
6142
static void ipw_debug_config(struct ipw_priv *priv)
6144
IPW_DEBUG_INFO("Scan completed, no valid APs matched "
6145
"[CFG 0x%08X]\n", priv->config);
6146
if (priv->config & CFG_STATIC_CHANNEL)
6147
IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
6149
IPW_DEBUG_INFO("Channel unlocked.\n");
6150
if (priv->config & CFG_STATIC_ESSID)
6151
IPW_DEBUG_INFO("ESSID locked to '%s'\n",
6152
escape_essid(priv->essid, priv->essid_len));
6154
IPW_DEBUG_INFO("ESSID unlocked.\n");
6155
if (priv->config & CFG_STATIC_BSSID)
6156
IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
6157
MAC_ARG(priv->bssid));
6159
IPW_DEBUG_INFO("BSSID unlocked.\n");
6160
if (priv->capability & CAP_PRIVACY_ON)
6161
IPW_DEBUG_INFO("PRIVACY on\n");
6163
IPW_DEBUG_INFO("PRIVACY off\n");
6164
IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
6167
static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
6169
/* TODO: Verify that this works... */
6170
struct ipw_fixed_rate fr = {
6171
.tx_rates = priv->rates_mask
6176
/* Identify 'current FW band' and match it with the fixed
6179
switch (priv->ieee->freq_band) {
6180
case IEEE80211_52GHZ_BAND: /* A only */
6182
if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
6183
/* Invalid fixed rate mask */
6185
("invalid fixed rate mask in ipw_set_fixed_rate\n");
6190
fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
6193
default: /* 2.4Ghz or Mixed */
6195
if (mode == IEEE_B) {
6196
if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
6197
/* Invalid fixed rate mask */
6199
("invalid fixed rate mask in ipw_set_fixed_rate\n");
6206
if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
6207
IEEE80211_OFDM_RATES_MASK)) {
6208
/* Invalid fixed rate mask */
6210
("invalid fixed rate mask in ipw_set_fixed_rate\n");
6215
if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
6216
mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
6217
fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
6220
if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
6221
mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
6222
fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
6225
if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
6226
mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
6227
fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
6230
fr.tx_rates |= mask;
6234
reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
6235
ipw_write_reg32(priv, reg, *(u32 *) & fr);
6238
static void ipw_abort_scan(struct ipw_priv *priv)
6242
if (priv->status & STATUS_SCAN_ABORTING) {
6243
IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6246
priv->status |= STATUS_SCAN_ABORTING;
6248
err = ipw_send_scan_abort(priv);
6250
IPW_DEBUG_HC("Request to abort scan failed.\n");
6253
static void ipw_add_scan_channels(struct ipw_priv *priv,
6254
struct ipw_scan_request_ext *scan,
6257
int channel_index = 0;
6258
const struct ieee80211_geo *geo;
6261
geo = ipw_get_geo(priv->ieee);
6263
if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
6264
int start = channel_index;
6265
for (i = 0; i < geo->a_channels; i++) {
6266
if ((priv->status & STATUS_ASSOCIATED) &&
6267
geo->a[i].channel == priv->channel)
6270
scan->channels_list[channel_index] = geo->a[i].channel;
6271
ipw_set_scan_type(scan, channel_index,
6273
flags & IEEE80211_CH_PASSIVE_ONLY ?
6274
IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6278
if (start != channel_index) {
6279
scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6280
(channel_index - start);
6285
if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
6286
int start = channel_index;
6287
if (priv->config & CFG_SPEED_SCAN) {
6289
u8 channels[IEEE80211_24GHZ_CHANNELS] = {
6290
/* nop out the list */
6295
while (channel_index < IPW_SCAN_CHANNELS) {
6297
priv->speed_scan[priv->speed_scan_pos];
6299
priv->speed_scan_pos = 0;
6300
channel = priv->speed_scan[0];
6302
if ((priv->status & STATUS_ASSOCIATED) &&
6303
channel == priv->channel) {
6304
priv->speed_scan_pos++;
6308
/* If this channel has already been
6309
* added in scan, break from loop
6310
* and this will be the first channel
6313
if (channels[channel - 1] != 0)
6316
channels[channel - 1] = 1;
6317
priv->speed_scan_pos++;
6319
scan->channels_list[channel_index] = channel;
6321
ipw_channel_to_index(priv->ieee, channel);
6322
ipw_set_scan_type(scan, channel_index,
6325
IEEE80211_CH_PASSIVE_ONLY ?
6326
IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6330
for (i = 0; i < geo->bg_channels; i++) {
6331
if ((priv->status & STATUS_ASSOCIATED) &&
6332
geo->bg[i].channel == priv->channel)
6335
scan->channels_list[channel_index] =
6337
ipw_set_scan_type(scan, channel_index,
6340
IEEE80211_CH_PASSIVE_ONLY ?
6341
IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6346
if (start != channel_index) {
6347
scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6348
(channel_index - start);
6353
static int ipw_request_scan_helper(struct ipw_priv *priv, int type)
6355
struct ipw_scan_request_ext scan;
6356
int err = 0, scan_type;
6358
if (!(priv->status & STATUS_INIT) ||
6359
(priv->status & STATUS_EXIT_PENDING))
6362
mutex_lock(&priv->mutex);
6364
if (priv->status & STATUS_SCANNING) {
6365
IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
6366
priv->status |= STATUS_SCAN_PENDING;
6370
if (!(priv->status & STATUS_SCAN_FORCED) &&
6371
priv->status & STATUS_SCAN_ABORTING) {
6372
IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6373
priv->status |= STATUS_SCAN_PENDING;
6377
if (priv->status & STATUS_RF_KILL_MASK) {
6378
IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6379
priv->status |= STATUS_SCAN_PENDING;
6383
memset(&scan, 0, sizeof(scan));
6384
scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
6386
if (type == IW_SCAN_TYPE_PASSIVE) {
6387
IPW_DEBUG_WX("use passive scanning\n");
6388
scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN;
6389
scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6391
ipw_add_scan_channels(priv, &scan, scan_type);
6395
/* Use active scan by default. */
6396
if (priv->config & CFG_SPEED_SCAN)
6397
scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6400
scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6403
scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6406
scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
6408
#ifdef CONFIG_IPW2200_MONITOR
6409
if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
6413
switch (ipw_is_valid_channel(priv->ieee, priv->channel)) {
6414
case IEEE80211_52GHZ_BAND:
6415
band = (u8) (IPW_A_MODE << 6) | 1;
6416
channel = priv->channel;
6419
case IEEE80211_24GHZ_BAND:
6420
band = (u8) (IPW_B_MODE << 6) | 1;
6421
channel = priv->channel;
6425
band = (u8) (IPW_B_MODE << 6) | 1;
6430
scan.channels_list[0] = band;
6431
scan.channels_list[1] = channel;
6432
ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
6434
/* NOTE: The card will sit on this channel for this time
6435
* period. Scan aborts are timing sensitive and frequently
6436
* result in firmware restarts. As such, it is best to
6437
* set a small dwell_time here and just keep re-issuing
6438
* scans. Otherwise fast channel hopping will not actually
6441
* TODO: Move SPEED SCAN support to all modes and bands */
6442
scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6445
#endif /* CONFIG_IPW2200_MONITOR */
6446
/* If we are roaming, then make this a directed scan for the
6447
* current network. Otherwise, ensure that every other scan
6448
* is a fast channel hop scan */
6449
if ((priv->status & STATUS_ROAMING)
6450
|| (!(priv->status & STATUS_ASSOCIATED)
6451
&& (priv->config & CFG_STATIC_ESSID)
6452
&& (le32_to_cpu(scan.full_scan_index) % 2))) {
6453
err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6455
IPW_DEBUG_HC("Attempt to send SSID command "
6460
scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6462
scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
6464
ipw_add_scan_channels(priv, &scan, scan_type);
6465
#ifdef CONFIG_IPW2200_MONITOR
6470
err = ipw_send_scan_request_ext(priv, &scan);
6472
IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
6476
priv->status |= STATUS_SCANNING;
6477
priv->status &= ~STATUS_SCAN_PENDING;
6478
queue_delayed_work(priv->workqueue, &priv->scan_check,
6479
IPW_SCAN_CHECK_WATCHDOG);
6481
mutex_unlock(&priv->mutex);
6485
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
6486
static void ipw_request_passive_scan(void *work)
6488
struct ipw_priv *priv = work;
6490
static void ipw_request_passive_scan(struct work_struct *work)
6492
struct ipw_priv *priv =
6493
container_of(work, struct ipw_priv, request_passive_scan);
6495
ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE);
6498
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
6499
static void ipw_request_scan(void *work)
6501
struct ipw_priv *priv = work;
6503
static void ipw_request_scan(struct work_struct *work)
6505
struct ipw_priv *priv =
6506
container_of(work, struct ipw_priv, request_scan.work);
6508
ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE);
6511
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
6512
static void ipw_bg_abort_scan(void *work)
6514
struct ipw_priv *priv = work;
6516
static void ipw_bg_abort_scan(struct work_struct *work)
6518
struct ipw_priv *priv =
6519
container_of(work, struct ipw_priv, abort_scan);
6521
mutex_lock(&priv->mutex);
6522
ipw_abort_scan(priv);
6523
mutex_unlock(&priv->mutex);
6526
static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6528
/* This is called when wpa_supplicant loads and closes the driver
6530
priv->ieee->wpa_enabled = value;
6534
static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6536
struct ieee80211_device *ieee = priv->ieee;
6537
struct ieee80211_security sec = {
6538
.flags = SEC_AUTH_MODE,
6542
if (value & IW_AUTH_ALG_SHARED_KEY) {
6543
sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6545
} else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
6546
sec.auth_mode = WLAN_AUTH_OPEN;
6548
} else if (value & IW_AUTH_ALG_LEAP) {
6549
sec.auth_mode = WLAN_AUTH_LEAP;
6554
if (ieee->set_security)
6555
ieee->set_security(ieee->dev, &sec);
6562
static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6565
/* make sure WPA is enabled */
6566
ipw_wpa_enable(priv, 1);
6569
static int ipw_set_rsn_capa(struct ipw_priv *priv,
6570
char *capabilities, int length)
6572
IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6574
return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
6578
#if WIRELESS_EXT > 17
6584
static int ipw_wx_set_genie(struct net_device *dev,
6585
struct iw_request_info *info,
6586
union iwreq_data *wrqu, char *extra)
6588
struct ipw_priv *priv = ieee80211_priv(dev);
6589
struct ieee80211_device *ieee = priv->ieee;
6593
if (wrqu->data.length > MAX_WPA_IE_LEN ||
6594
(wrqu->data.length && extra == NULL))
6597
if (wrqu->data.length) {
6598
buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6604
memcpy(buf, extra, wrqu->data.length);
6605
kfree(ieee->wpa_ie);
6607
ieee->wpa_ie_len = wrqu->data.length;
6609
kfree(ieee->wpa_ie);
6610
ieee->wpa_ie = NULL;
6611
ieee->wpa_ie_len = 0;
6614
ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6620
static int ipw_wx_get_genie(struct net_device *dev,
6621
struct iw_request_info *info,
6622
union iwreq_data *wrqu, char *extra)
6624
struct ipw_priv *priv = ieee80211_priv(dev);
6625
struct ieee80211_device *ieee = priv->ieee;
6628
if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6629
wrqu->data.length = 0;
6633
if (wrqu->data.length < ieee->wpa_ie_len) {
6638
wrqu->data.length = ieee->wpa_ie_len;
6639
memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6645
static int wext_cipher2level(int cipher)
6648
case IW_AUTH_CIPHER_NONE:
6650
case IW_AUTH_CIPHER_WEP40:
6651
case IW_AUTH_CIPHER_WEP104:
6653
case IW_AUTH_CIPHER_TKIP:
6655
case IW_AUTH_CIPHER_CCMP:
6663
static int ipw_wx_set_auth(struct net_device *dev,
6664
struct iw_request_info *info,
6665
union iwreq_data *wrqu, char *extra)
6667
struct ipw_priv *priv = ieee80211_priv(dev);
6668
struct ieee80211_device *ieee = priv->ieee;
6669
struct iw_param *param = &wrqu->param;
6670
struct ieee80211_crypt_data *crypt;
6671
unsigned long flags;
6674
switch (param->flags & IW_AUTH_INDEX) {
6675
case IW_AUTH_WPA_VERSION:
6677
case IW_AUTH_CIPHER_PAIRWISE:
6678
ipw_set_hw_decrypt_unicast(priv,
6679
wext_cipher2level(param->value));
6681
case IW_AUTH_CIPHER_GROUP:
6682
ipw_set_hw_decrypt_multicast(priv,
6683
wext_cipher2level(param->value));
6685
case IW_AUTH_KEY_MGMT:
6687
* ipw2200 does not use these parameters
6691
case IW_AUTH_TKIP_COUNTERMEASURES:
6692
crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6693
if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
6696
flags = crypt->ops->get_flags(crypt->priv);
6699
flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6701
flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6703
crypt->ops->set_flags(flags, crypt->priv);
6707
case IW_AUTH_DROP_UNENCRYPTED:{
6710
* wpa_supplicant calls set_wpa_enabled when the driver
6711
* is loaded and unloaded, regardless of if WPA is being
6712
* used. No other calls are made which can be used to
6713
* determine if encryption will be used or not prior to
6714
* association being expected. If encryption is not being
6715
* used, drop_unencrypted is set to false, else true -- we
6716
* can use this to determine if the CAP_PRIVACY_ON bit should
6719
struct ieee80211_security sec = {
6720
.flags = SEC_ENABLED,
6721
.enabled = param->value,
6723
priv->ieee->drop_unencrypted = param->value;
6724
/* We only change SEC_LEVEL for open mode. Others
6725
* are set by ipw_wpa_set_encryption.
6727
if (!param->value) {
6728
sec.flags |= SEC_LEVEL;
6729
sec.level = SEC_LEVEL_0;
6731
sec.flags |= SEC_LEVEL;
6732
sec.level = SEC_LEVEL_1;
6734
if (priv->ieee->set_security)
6735
priv->ieee->set_security(priv->ieee->dev, &sec);
6739
case IW_AUTH_80211_AUTH_ALG:
6740
ret = ipw_wpa_set_auth_algs(priv, param->value);
6743
case IW_AUTH_WPA_ENABLED:
6744
ret = ipw_wpa_enable(priv, param->value);
6745
ipw_disassociate(priv);
6748
case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6749
ieee->ieee802_1x = param->value;
6752
case IW_AUTH_PRIVACY_INVOKED:
6753
ieee->privacy_invoked = param->value;
6763
static int ipw_wx_get_auth(struct net_device *dev,
6764
struct iw_request_info *info,
6765
union iwreq_data *wrqu, char *extra)
6767
struct ipw_priv *priv = ieee80211_priv(dev);
6768
struct ieee80211_device *ieee = priv->ieee;
6769
struct ieee80211_crypt_data *crypt;
6770
struct iw_param *param = &wrqu->param;
6773
switch (param->flags & IW_AUTH_INDEX) {
6774
case IW_AUTH_WPA_VERSION:
6775
case IW_AUTH_CIPHER_PAIRWISE:
6776
case IW_AUTH_CIPHER_GROUP:
6777
case IW_AUTH_KEY_MGMT:
6779
* wpa_supplicant will control these internally
6784
case IW_AUTH_TKIP_COUNTERMEASURES:
6785
crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6786
if (!crypt || !crypt->ops->get_flags)
6789
param->value = (crypt->ops->get_flags(crypt->priv) &
6790
IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6794
case IW_AUTH_DROP_UNENCRYPTED:
6795
param->value = ieee->drop_unencrypted;
6798
case IW_AUTH_80211_AUTH_ALG:
6799
param->value = ieee->sec.auth_mode;
6802
case IW_AUTH_WPA_ENABLED:
6803
param->value = ieee->wpa_enabled;
6806
case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6807
param->value = ieee->ieee802_1x;
6810
case IW_AUTH_ROAMING_CONTROL:
6811
case IW_AUTH_PRIVACY_INVOKED:
6812
param->value = ieee->privacy_invoked;
6821
/* SIOCSIWENCODEEXT */
6822
static int ipw_wx_set_encodeext(struct net_device *dev,
6823
struct iw_request_info *info,
6824
union iwreq_data *wrqu, char *extra)
6826
struct ipw_priv *priv = ieee80211_priv(dev);
6827
struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6830
if (ext->alg == IW_ENCODE_ALG_TKIP) {
6831
/* IPW HW can't build TKIP MIC,
6832
host decryption still needed */
6833
if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6834
priv->ieee->host_mc_decrypt = 1;
6836
priv->ieee->host_encrypt = 0;
6837
priv->ieee->host_encrypt_msdu = 1;
6838
priv->ieee->host_decrypt = 1;
6841
priv->ieee->host_encrypt = 0;
6842
priv->ieee->host_encrypt_msdu = 0;
6843
priv->ieee->host_decrypt = 0;
6844
priv->ieee->host_mc_decrypt = 0;
6848
return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6851
/* SIOCGIWENCODEEXT */
6852
static int ipw_wx_get_encodeext(struct net_device *dev,
6853
struct iw_request_info *info,
6854
union iwreq_data *wrqu, char *extra)
6856
struct ipw_priv *priv = ieee80211_priv(dev);
6857
return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6861
static int ipw_wx_set_mlme(struct net_device *dev,
6862
struct iw_request_info *info,
6863
union iwreq_data *wrqu, char *extra)
6865
struct ipw_priv *priv = ieee80211_priv(dev);
6866
struct iw_mlme *mlme = (struct iw_mlme *)extra;
6869
reason = cpu_to_le16(mlme->reason_code);
6871
switch (mlme->cmd) {
6872
case IW_MLME_DEAUTH:
6873
/* silently ignore */
6876
case IW_MLME_DISASSOC:
6877
ipw_disassociate(priv);
6887
#ifdef CONFIG_IPW2200_QOS
6891
* get the modulation type of the current network or
6892
* the card current mode
6894
static u8 ipw_qos_current_mode(struct ipw_priv * priv)
6898
if (priv->status & STATUS_ASSOCIATED) {
6899
unsigned long flags;
6901
spin_lock_irqsave(&priv->ieee->lock, flags);
6902
mode = priv->assoc_network->mode;
6903
spin_unlock_irqrestore(&priv->ieee->lock, flags);
6905
mode = priv->ieee->mode;
6907
IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6912
* Handle management frame beacon and probe response
6914
static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6916
struct ieee80211_network *network)
6918
u32 size = sizeof(struct ieee80211_qos_parameters);
6920
if (network->capability & WLAN_CAPABILITY_IBSS)
6921
network->qos_data.active = network->qos_data.supported;
6923
if (network->flags & NETWORK_HAS_QOS_MASK) {
6924
if (active_network &&
6925
(network->flags & NETWORK_HAS_QOS_PARAMETERS))
6926
network->qos_data.active = network->qos_data.supported;
6928
if ((network->qos_data.active == 1) && (active_network == 1) &&
6929
(network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6930
(network->qos_data.old_param_count !=
6931
network->qos_data.param_count)) {
6932
network->qos_data.old_param_count =
6933
network->qos_data.param_count;
6934
schedule_work(&priv->qos_activate);
6935
IPW_DEBUG_QOS("QoS parameters change call "
6939
if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6940
memcpy(&network->qos_data.parameters,
6941
&def_parameters_CCK, size);
6943
memcpy(&network->qos_data.parameters,
6944
&def_parameters_OFDM, size);
6946
if ((network->qos_data.active == 1) && (active_network == 1)) {
6947
IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6948
schedule_work(&priv->qos_activate);
6951
network->qos_data.active = 0;
6952
network->qos_data.supported = 0;
6954
if ((priv->status & STATUS_ASSOCIATED) &&
6955
(priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6956
if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6957
if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6958
!(network->flags & NETWORK_EMPTY_ESSID))
6959
if ((network->ssid_len ==
6960
priv->assoc_network->ssid_len) &&
6961
!memcmp(network->ssid,
6962
priv->assoc_network->ssid,
6963
network->ssid_len)) {
6964
queue_work(priv->workqueue,
6965
&priv->merge_networks);
6973
* This function set up the firmware to support QoS. It sends
6974
* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6976
static int ipw_qos_activate(struct ipw_priv *priv,
6977
struct ieee80211_qos_data *qos_network_data)
6980
struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6981
struct ieee80211_qos_parameters *active_one = NULL;
6982
u32 size = sizeof(struct ieee80211_qos_parameters);
6987
type = ipw_qos_current_mode(priv);
6989
active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6990
memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6991
active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6992
memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6994
if (qos_network_data == NULL) {
6995
if (type == IEEE_B) {
6996
IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6997
active_one = &def_parameters_CCK;
6999
active_one = &def_parameters_OFDM;
7001
memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
7002
burst_duration = ipw_qos_get_burst_duration(priv);
7003
for (i = 0; i < QOS_QUEUE_NUM; i++)
7004
qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
7005
(u16)burst_duration;
7006
} else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7007
if (type == IEEE_B) {
7008
IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
7010
if (priv->qos_data.qos_enable == 0)
7011
active_one = &def_parameters_CCK;
7013
active_one = priv->qos_data.def_qos_parm_CCK;
7015
if (priv->qos_data.qos_enable == 0)
7016
active_one = &def_parameters_OFDM;
7018
active_one = priv->qos_data.def_qos_parm_OFDM;
7020
memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
7022
unsigned long flags;
7025
spin_lock_irqsave(&priv->ieee->lock, flags);
7026
active_one = &(qos_network_data->parameters);
7027
qos_network_data->old_param_count =
7028
qos_network_data->param_count;
7029
memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
7030
active = qos_network_data->supported;
7031
spin_unlock_irqrestore(&priv->ieee->lock, flags);
7034
burst_duration = ipw_qos_get_burst_duration(priv);
7035
for (i = 0; i < QOS_QUEUE_NUM; i++)
7036
qos_parameters[QOS_PARAM_SET_ACTIVE].
7037
tx_op_limit[i] = (u16)burst_duration;
7041
IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
7042
for (i = 0; i < 3; i++) {
7044
for (j = 0; j < QOS_QUEUE_NUM; j++) {
7045
qos_parameters[i].cw_min[j] = cpu_to_le16(qos_parameters[i].cw_min[j]);
7046
qos_parameters[i].cw_max[j] = cpu_to_le16(qos_parameters[i].cw_max[j]);
7047
qos_parameters[i].tx_op_limit[j] = cpu_to_le16(qos_parameters[i].tx_op_limit[j]);
7051
err = ipw_send_qos_params_command(priv,
7052
(struct ieee80211_qos_parameters *)
7053
&(qos_parameters[0]));
7055
IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7061
* send IPW_CMD_WME_INFO to the firmware
7063
static int ipw_qos_set_info_element(struct ipw_priv *priv)
7066
struct ieee80211_qos_information_element qos_info;
7071
qos_info.elementID = QOS_ELEMENT_ID;
7072
qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
7074
qos_info.version = QOS_VERSION_1;
7075
qos_info.ac_info = 0;
7077
memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
7078
qos_info.qui_type = QOS_OUI_TYPE;
7079
qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
7081
ret = ipw_send_qos_info_command(priv, &qos_info);
7083
IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7089
* Set the QoS parameter with the association request structure
7091
static int ipw_qos_association(struct ipw_priv *priv,
7092
struct ieee80211_network *network)
7095
struct ieee80211_qos_data *qos_data = NULL;
7096
struct ieee80211_qos_data ibss_data = {
7101
switch (priv->ieee->iw_mode) {
7103
BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
7105
qos_data = &ibss_data;
7109
qos_data = &network->qos_data;
7117
err = ipw_qos_activate(priv, qos_data);
7119
priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
7123
if (priv->qos_data.qos_enable && qos_data->supported) {
7124
IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7125
priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
7126
return ipw_qos_set_info_element(priv);
7133
* handling the beaconing responses. if we get different QoS setting
7134
* off the network from the associated setting, adjust the QoS
7137
static int ipw_qos_association_resp(struct ipw_priv *priv,
7138
struct ieee80211_network *network)
7141
unsigned long flags;
7142
u32 size = sizeof(struct ieee80211_qos_parameters);
7143
int set_qos_param = 0;
7145
if ((priv == NULL) || (network == NULL) ||
7146
(priv->assoc_network == NULL))
7149
if (!(priv->status & STATUS_ASSOCIATED))
7152
if ((priv->ieee->iw_mode != IW_MODE_INFRA))
7155
spin_lock_irqsave(&priv->ieee->lock, flags);
7156
if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
7157
memcpy(&priv->assoc_network->qos_data, &network->qos_data,
7158
sizeof(struct ieee80211_qos_data));
7159
priv->assoc_network->qos_data.active = 1;
7160
if ((network->qos_data.old_param_count !=
7161
network->qos_data.param_count)) {
7163
network->qos_data.old_param_count =
7164
network->qos_data.param_count;
7168
if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7169
memcpy(&priv->assoc_network->qos_data.parameters,
7170
&def_parameters_CCK, size);
7172
memcpy(&priv->assoc_network->qos_data.parameters,
7173
&def_parameters_OFDM, size);
7174
priv->assoc_network->qos_data.active = 0;
7175
priv->assoc_network->qos_data.supported = 0;
7179
spin_unlock_irqrestore(&priv->ieee->lock, flags);
7181
if (set_qos_param == 1)
7182
schedule_work(&priv->qos_activate);
7187
static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7194
if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
7195
ret = priv->qos_data.burst_duration_CCK;
7197
ret = priv->qos_data.burst_duration_OFDM;
7203
* Initialize the setting of QoS global
7205
static void ipw_qos_init(struct ipw_priv *priv, int enable,
7206
int burst_enable, u32 burst_duration_CCK,
7207
u32 burst_duration_OFDM)
7209
priv->qos_data.qos_enable = enable;
7211
if (priv->qos_data.qos_enable) {
7212
priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7213
priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7214
IPW_DEBUG_QOS("QoS is enabled\n");
7216
priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7217
priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7218
IPW_DEBUG_QOS("QoS is not enabled\n");
7221
priv->qos_data.burst_enable = burst_enable;
7224
priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7225
priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7227
priv->qos_data.burst_duration_CCK = 0;
7228
priv->qos_data.burst_duration_OFDM = 0;
7233
* map the packet priority to the right TX Queue
7235
static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7237
if (priority > 7 || !priv->qos_data.qos_enable)
7240
return from_priority_to_tx_queue[priority] - 1;
7243
static int ipw_is_qos_active(struct net_device *dev,
7244
struct sk_buff *skb)
7246
struct ipw_priv *priv = ieee80211_priv(dev);
7247
struct ieee80211_qos_data *qos_data = NULL;
7248
int active, supported;
7249
u8 *daddr = skb->data + ETH_ALEN;
7250
int unicast = !ipw_is_multicast_ether_addr(daddr);
7252
if (!(priv->status & STATUS_ASSOCIATED))
7255
qos_data = &priv->assoc_network->qos_data;
7257
if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7259
qos_data->active = 0;
7261
qos_data->active = qos_data->supported;
7263
active = qos_data->active;
7264
supported = qos_data->supported;
7265
IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7267
priv->qos_data.qos_enable, active, supported, unicast);
7268
if (active && priv->qos_data.qos_enable)
7275
* add QoS parameter to the TX command
7277
static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7279
struct tfd_data *tfd)
7281
int tx_queue_id = 0;
7284
tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7285
tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7287
if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7288
tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
7289
tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK);
7295
* background support to run QoS activate functionality
7297
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
7298
static void ipw_bg_qos_activate(void *work)
7300
struct ipw_priv *priv = work;
7302
static void ipw_bg_qos_activate(struct work_struct *work)
7304
struct ipw_priv *priv =
7305
container_of(work, struct ipw_priv, qos_activate);
7311
mutex_lock(&priv->mutex);
7313
if (priv->status & STATUS_ASSOCIATED)
7314
ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7316
mutex_unlock(&priv->mutex);
7319
static int ipw_handle_probe_response(struct net_device *dev,
7320
struct ieee80211_probe_response *resp,
7321
struct ieee80211_network *network)
7323
struct ipw_priv *priv = ieee80211_priv(dev);
7324
int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7325
(network == priv->assoc_network));
7327
ipw_qos_handle_probe_response(priv, active_network, network);
7332
static int ipw_handle_beacon(struct net_device *dev,
7333
struct ieee80211_beacon *resp,
7334
struct ieee80211_network *network)
7336
struct ipw_priv *priv = ieee80211_priv(dev);
7337
int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7338
(network == priv->assoc_network));
7340
ipw_qos_handle_probe_response(priv, active_network, network);
7345
static int ipw_handle_assoc_response(struct net_device *dev,
7346
struct ieee80211_assoc_response *resp,
7347
struct ieee80211_network *network)
7349
struct ipw_priv *priv = ieee80211_priv(dev);
7350
ipw_qos_association_resp(priv, network);
7354
static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7357
return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7358
sizeof(*qos_param) * 3, qos_param);
7361
static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7364
return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7368
#endif /* CONFIG_IPW2200_QOS */
7370
static int ipw_associate_network(struct ipw_priv *priv,
7371
struct ieee80211_network *network,
7372
struct ipw_supported_rates *rates, int roaming)
7376
if (priv->config & CFG_FIXED_RATE)
7377
ipw_set_fixed_rate(priv, network->mode);
7379
if (!(priv->config & CFG_STATIC_ESSID)) {
7380
priv->essid_len = min(network->ssid_len,
7381
(u8) IW_ESSID_MAX_SIZE);
7382
memcpy(priv->essid, network->ssid, priv->essid_len);
7385
network->last_associate = jiffies;
7387
memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7388
priv->assoc_request.channel = network->channel;
7389
priv->assoc_request.auth_key = 0;
7391
if ((priv->capability & CAP_PRIVACY_ON) &&
7392
(priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
7393
priv->assoc_request.auth_type = AUTH_SHARED_KEY;
7394
priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7396
if (priv->ieee->sec.level == SEC_LEVEL_1)
7397
ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
7399
} else if ((priv->capability & CAP_PRIVACY_ON) &&
7400
(priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7401
priv->assoc_request.auth_type = AUTH_LEAP;
7403
priv->assoc_request.auth_type = AUTH_OPEN;
7405
if (priv->ieee->wpa_ie_len) {
7406
priv->assoc_request.policy_support = 0x02; /* RSN active */
7407
ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7408
priv->ieee->wpa_ie_len);
7412
* It is valid for our ieee device to support multiple modes, but
7413
* when it comes to associating to a given network we have to choose
7416
if (network->mode & priv->ieee->mode & IEEE_A)
7417
priv->assoc_request.ieee_mode = IPW_A_MODE;
7418
else if (network->mode & priv->ieee->mode & IEEE_G)
7419
priv->assoc_request.ieee_mode = IPW_G_MODE;
7420
else if (network->mode & priv->ieee->mode & IEEE_B)
7421
priv->assoc_request.ieee_mode = IPW_B_MODE;
7423
priv->assoc_request.capability = network->capability;
7424
if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7425
&& !(priv->config & CFG_PREAMBLE_LONG)) {
7426
priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7428
priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7430
/* Clear the short preamble if we won't be supporting it */
7431
priv->assoc_request.capability &=
7432
~WLAN_CAPABILITY_SHORT_PREAMBLE;
7435
/* Clear capability bits that aren't used in Ad Hoc */
7436
if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7437
priv->assoc_request.capability &=
7438
~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7440
IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
7441
"802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
7442
roaming ? "Rea" : "A",
7443
escape_essid(priv->essid, priv->essid_len),
7445
ipw_modes[priv->assoc_request.ieee_mode],
7447
(priv->assoc_request.preamble_length ==
7448
DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7449
network->capability &
7450
WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
7451
priv->capability & CAP_PRIVACY_ON ? "on " : "off",
7452
priv->capability & CAP_PRIVACY_ON ?
7453
(priv->capability & CAP_SHARED_KEY ? "(shared)" :
7455
priv->capability & CAP_PRIVACY_ON ? " key=" : "",
7456
priv->capability & CAP_PRIVACY_ON ?
7457
'1' + priv->ieee->sec.active_key : '.',
7458
priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
7460
priv->assoc_request.beacon_interval = network->beacon_interval;
7461
if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
7462
(network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
7463
priv->assoc_request.assoc_type = HC_IBSS_START;
7464
priv->assoc_request.assoc_tsf_msw = 0;
7465
priv->assoc_request.assoc_tsf_lsw = 0;
7467
if (unlikely(roaming))
7468
priv->assoc_request.assoc_type = HC_REASSOCIATE;
7470
priv->assoc_request.assoc_type = HC_ASSOCIATE;
7471
priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7472
priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7475
memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
7477
if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7478
memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7479
priv->assoc_request.atim_window = network->atim_window;
7481
memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
7482
priv->assoc_request.atim_window = 0;
7485
priv->assoc_request.listen_interval = network->listen_interval;
7487
err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7489
IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7493
rates->ieee_mode = priv->assoc_request.ieee_mode;
7494
rates->purpose = IPW_RATE_CONNECT;
7495
ipw_send_supported_rates(priv, rates);
7497
if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7498
priv->sys_config.dot11g_auto_detection = 1;
7500
priv->sys_config.dot11g_auto_detection = 0;
7502
if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7503
priv->sys_config.answer_broadcast_ssid_probe = 1;
7505
priv->sys_config.answer_broadcast_ssid_probe = 0;
7507
err = ipw_send_system_config(priv);
7509
IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7513
IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
7514
err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
7516
IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7521
* If preemption is enabled, it is possible for the association
7522
* to complete before we return from ipw_send_associate. Therefore
7523
* we have to be sure and update our priviate data first.
7525
priv->channel = network->channel;
7526
memcpy(priv->bssid, network->bssid, ETH_ALEN);
7527
priv->status |= STATUS_ASSOCIATING;
7528
priv->status &= ~STATUS_SECURITY_UPDATED;
7530
priv->assoc_network = network;
7532
#ifdef CONFIG_IPW2200_QOS
7533
ipw_qos_association(priv, network);
7536
err = ipw_send_associate(priv, &priv->assoc_request);
7538
IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7542
IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
7543
escape_essid(priv->essid, priv->essid_len),
7544
MAC_ARG(priv->bssid));
7549
static void ipw_roam(void *data)
7551
struct ipw_priv *priv = data;
7552
struct ieee80211_network *network = NULL;
7553
struct ipw_network_match match = {
7554
.network = priv->assoc_network
7557
/* The roaming process is as follows:
7559
* 1. Missed beacon threshold triggers the roaming process by
7560
* setting the status ROAM bit and requesting a scan.
7561
* 2. When the scan completes, it schedules the ROAM work
7562
* 3. The ROAM work looks at all of the known networks for one that
7563
* is a better network than the currently associated. If none
7564
* found, the ROAM process is over (ROAM bit cleared)
7565
* 4. If a better network is found, a disassociation request is
7567
* 5. When the disassociation completes, the roam work is again
7568
* scheduled. The second time through, the driver is no longer
7569
* associated, and the newly selected network is sent an
7570
* association request.
7571
* 6. At this point ,the roaming process is complete and the ROAM
7572
* status bit is cleared.
7575
/* If we are no longer associated, and the roaming bit is no longer
7576
* set, then we are not actively roaming, so just return */
7577
if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7580
if (priv->status & STATUS_ASSOCIATED) {
7581
/* First pass through ROAM process -- look for a better
7583
unsigned long flags;
7584
u8 rssi = priv->assoc_network->stats.rssi;
7585
priv->assoc_network->stats.rssi = -128;
7586
spin_lock_irqsave(&priv->ieee->lock, flags);
7587
list_for_each_entry(network, &priv->ieee->network_list, list) {
7588
if (network != priv->assoc_network)
7589
ipw_best_network(priv, &match, network, 1);
7591
spin_unlock_irqrestore(&priv->ieee->lock, flags);
7592
priv->assoc_network->stats.rssi = rssi;
7594
if (match.network == priv->assoc_network) {
7595
IPW_DEBUG_ASSOC("No better APs in this network to "
7597
priv->status &= ~STATUS_ROAMING;
7598
ipw_debug_config(priv);
7602
ipw_send_disassociate(priv, 1);
7603
priv->assoc_network = match.network;
7608
/* Second pass through ROAM process -- request association */
7609
ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7610
ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7611
priv->status &= ~STATUS_ROAMING;
7614
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
7615
static void ipw_bg_roam(void *work)
7617
struct ipw_priv *priv = work;
7619
static void ipw_bg_roam(struct work_struct *work)
7621
struct ipw_priv *priv =
7622
container_of(work, struct ipw_priv, roam);
7624
mutex_lock(&priv->mutex);
7626
mutex_unlock(&priv->mutex);
7629
static int ipw_associate(void *data)
7631
struct ipw_priv *priv = data;
7633
struct ieee80211_network *network = NULL;
7634
struct ipw_network_match match = {
7637
struct ipw_supported_rates *rates;
7638
struct list_head *element;
7639
unsigned long flags;
7641
if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7642
IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7646
if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
7647
IPW_DEBUG_ASSOC("Not attempting association (already in "
7652
if (priv->status & STATUS_DISASSOCIATING) {
7653
IPW_DEBUG_ASSOC("Not attempting association (in "
7654
"disassociating)\n ");
7655
queue_work(priv->workqueue, &priv->associate);
7659
if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
7660
IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7665
if (!(priv->config & CFG_ASSOCIATE) &&
7666
!(priv->config & (CFG_STATIC_ESSID |
7667
CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
7668
IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
7672
/* Protect our use of the network_list */
7673
spin_lock_irqsave(&priv->ieee->lock, flags);
7674
list_for_each_entry(network, &priv->ieee->network_list, list)
7675
ipw_best_network(priv, &match, network, 0);
7677
network = match.network;
7678
rates = &match.rates;
7680
if (network == NULL &&
7681
priv->ieee->iw_mode == IW_MODE_ADHOC &&
7682
priv->config & CFG_ADHOC_CREATE &&
7683
priv->config & CFG_STATIC_ESSID &&
7684
priv->config & CFG_STATIC_CHANNEL &&
7685
!list_empty(&priv->ieee->network_free_list)) {
7686
element = priv->ieee->network_free_list.next;
7687
network = list_entry(element, struct ieee80211_network, list);
7688
ipw_adhoc_create(priv, network);
7689
rates = &priv->rates;
7691
list_add_tail(&network->list, &priv->ieee->network_list);
7693
spin_unlock_irqrestore(&priv->ieee->lock, flags);
7695
/* If we reached the end of the list, then we don't have any valid
7698
ipw_debug_config(priv);
7700
if (!(priv->status & STATUS_SCANNING)) {
7701
if (!(priv->config & CFG_SPEED_SCAN))
7702
queue_delayed_work(priv->workqueue,
7703
&priv->request_scan,
7706
queue_delayed_work(priv->workqueue,
7707
&priv->request_scan, 0);
7713
ipw_associate_network(priv, network, rates, 0);
7718
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
7719
static void ipw_bg_associate(void *work)
7721
struct ipw_priv *priv = work;
7723
static void ipw_bg_associate(struct work_struct *work)
7725
struct ipw_priv *priv =
7726
container_of(work, struct ipw_priv, associate);
7728
mutex_lock(&priv->mutex);
7729
ipw_associate(priv);
7730
mutex_unlock(&priv->mutex);
7733
static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7734
struct sk_buff *skb)
7736
struct ieee80211_hdr *hdr;
7739
hdr = (struct ieee80211_hdr *)skb->data;
7740
fc = le16_to_cpu(hdr->frame_ctl);
7741
if (!(fc & IEEE80211_FCTL_PROTECTED))
7744
fc &= ~IEEE80211_FCTL_PROTECTED;
7745
hdr->frame_ctl = cpu_to_le16(fc);
7746
switch (priv->ieee->sec.level) {
7748
/* Remove CCMP HDR */
7749
memmove(skb->data + IEEE80211_3ADDR_LEN,
7750
skb->data + IEEE80211_3ADDR_LEN + 8,
7751
skb->len - IEEE80211_3ADDR_LEN - 8);
7752
skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
7758
memmove(skb->data + IEEE80211_3ADDR_LEN,
7759
skb->data + IEEE80211_3ADDR_LEN + 4,
7760
skb->len - IEEE80211_3ADDR_LEN - 4);
7761
skb_trim(skb, skb->len - 8); /* IV + ICV */
7766
printk(KERN_ERR "Unknow security level %d\n",
7767
priv->ieee->sec.level);
7772
static void ipw_handle_data_packet(struct ipw_priv *priv,
7773
struct ipw_rx_mem_buffer *rxb,
7774
struct ieee80211_rx_stats *stats)
7776
struct ieee80211_hdr_4addr *hdr;
7777
struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7779
/* We received data from the HW, so stop the watchdog */
7780
priv->net_dev->trans_start = jiffies;
7782
/* We only process data packets if the
7783
* interface is open */
7784
if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7785
skb_tailroom(rxb->skb))) {
7786
priv->ieee->stats.rx_errors++;
7787
priv->wstats.discard.misc++;
7788
IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7790
} else if (unlikely(!netif_running(priv->net_dev))) {
7791
priv->ieee->stats.rx_dropped++;
7792
priv->wstats.discard.misc++;
7793
IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7797
/* Advance skb->data to the start of the actual payload */
7798
skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
7800
/* Set the size of the skb to the size of the frame */
7801
skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
7803
IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7805
/* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
7806
hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7807
if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
7808
(ipw_is_multicast_ether_addr(hdr->addr1) ?
7809
!priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
7810
ipw_rebuild_decrypted_skb(priv, rxb->skb);
7812
if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7813
priv->ieee->stats.rx_errors++;
7814
else { /* ieee80211_rx succeeded, so it now owns the SKB */
7816
__ipw_led_activity_on(priv);
7820
#ifdef CONFIG_IPW2200_RADIOTAP
7821
static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7822
struct ipw_rx_mem_buffer *rxb,
7823
struct ieee80211_rx_stats *stats)
7825
struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7826
struct ipw_rx_frame *frame = &pkt->u.frame;
7828
/* initial pull of some data */
7829
u16 received_channel = frame->received_channel;
7830
u8 antennaAndPhy = frame->antennaAndPhy;
7831
s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7832
u16 pktrate = frame->rate;
7834
/* Magic struct that slots into the radiotap header -- no reason
7835
* to build this manually element by element, we can write it much
7836
* more efficiently than we can parse it. ORDER MATTERS HERE */
7837
struct ipw_rt_hdr *ipw_rt;
7839
short len = le16_to_cpu(pkt->u.frame.length);
7841
/* We received data from the HW, so stop the watchdog */
7842
priv->net_dev->trans_start = jiffies;
7844
/* We only process data packets if the
7845
* interface is open */
7846
if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7847
skb_tailroom(rxb->skb))) {
7848
priv->ieee->stats.rx_errors++;
7849
priv->wstats.discard.misc++;
7850
IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7852
} else if (unlikely(!netif_running(priv->net_dev))) {
7853
priv->ieee->stats.rx_dropped++;
7854
priv->wstats.discard.misc++;
7855
IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7859
/* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7861
if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7862
/* FIXME: Should alloc bigger skb instead */
7863
priv->ieee->stats.rx_dropped++;
7864
priv->wstats.discard.misc++;
7865
IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7869
/* copy the frame itself */
7870
memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7871
rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7873
/* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7874
* part of our real header, saves a little time.
7876
* No longer necessary since we fill in all our data. Purge before merging
7878
* memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7879
* IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7882
ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7884
ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7885
ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7886
ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7888
/* Big bitfield of all the fields we provide in radiotap */
7889
ipw_rt->rt_hdr.it_present =
7890
((1 << IEEE80211_RADIOTAP_TSFT) |
7891
(1 << IEEE80211_RADIOTAP_FLAGS) |
7892
(1 << IEEE80211_RADIOTAP_RATE) |
7893
(1 << IEEE80211_RADIOTAP_CHANNEL) |
7894
(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7895
(1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
7896
(1 << IEEE80211_RADIOTAP_ANTENNA));
7898
/* Zero the flags, we'll add to them as we go */
7899
ipw_rt->rt_flags = 0;
7900
ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
7901
frame->parent_tsf[2] << 16 |
7902
frame->parent_tsf[1] << 8 |
7903
frame->parent_tsf[0]);
7905
/* Convert signal to DBM */
7906
ipw_rt->rt_dbmsignal = antsignal;
7907
ipw_rt->rt_dbmnoise = frame->noise;
7909
/* Convert the channel data and set the flags */
7910
ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7911
if (received_channel > 14) { /* 802.11a */
7912
ipw_rt->rt_chbitmask =
7913
cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7914
} else if (antennaAndPhy & 32) { /* 802.11b */
7915
ipw_rt->rt_chbitmask =
7916
cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7917
} else { /* 802.11g */
7918
ipw_rt->rt_chbitmask =
7919
(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7922
/* set the rate in multiples of 500k/s */
7924
case IPW_TX_RATE_1MB:
7925
ipw_rt->rt_rate = 2;
7927
case IPW_TX_RATE_2MB:
7928
ipw_rt->rt_rate = 4;
7930
case IPW_TX_RATE_5MB:
7931
ipw_rt->rt_rate = 10;
7933
case IPW_TX_RATE_6MB:
7934
ipw_rt->rt_rate = 12;
7936
case IPW_TX_RATE_9MB:
7937
ipw_rt->rt_rate = 18;
7939
case IPW_TX_RATE_11MB:
7940
ipw_rt->rt_rate = 22;
7942
case IPW_TX_RATE_12MB:
7943
ipw_rt->rt_rate = 24;
7945
case IPW_TX_RATE_18MB:
7946
ipw_rt->rt_rate = 36;
7948
case IPW_TX_RATE_24MB:
7949
ipw_rt->rt_rate = 48;
7951
case IPW_TX_RATE_36MB:
7952
ipw_rt->rt_rate = 72;
7954
case IPW_TX_RATE_48MB:
7955
ipw_rt->rt_rate = 96;
7957
case IPW_TX_RATE_54MB:
7958
ipw_rt->rt_rate = 108;
7961
ipw_rt->rt_rate = 0;
7965
/* antenna number */
7966
ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7968
/* set the preamble flag if we have it */
7969
if ((antennaAndPhy & 64))
7970
ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7972
/* Set the size of the skb to the size of the frame */
7973
skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
7975
IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7977
if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7978
priv->ieee->stats.rx_errors++;
7979
else { /* ieee80211_rx succeeded, so it now owns the SKB */
7981
/* no LED during capture */
7986
#ifdef CONFIG_IPW2200_PROMISCUOUS
7987
#define ieee80211_is_probe_response(fc) \
7988
((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7989
(fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7991
#define ieee80211_is_management(fc) \
7992
((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7994
#define ieee80211_is_control(fc) \
7995
((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7997
#define ieee80211_is_data(fc) \
7998
((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
8000
#define ieee80211_is_assoc_request(fc) \
8001
((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
8003
#define ieee80211_is_reassoc_request(fc) \
8004
((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
8006
static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
8007
struct ipw_rx_mem_buffer *rxb,
8008
struct ieee80211_rx_stats *stats)
8010
struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
8011
struct ipw_rx_frame *frame = &pkt->u.frame;
8012
struct ipw_rt_hdr *ipw_rt;
8014
/* First cache any information we need before we overwrite
8015
* the information provided in the skb from the hardware */
8016
struct ieee80211_hdr *hdr;
8017
u16 channel = frame->received_channel;
8018
u8 phy_flags = frame->antennaAndPhy;
8019
s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
8020
s8 noise = frame->noise;
8021
u8 rate = frame->rate;
8022
short len = le16_to_cpu(pkt->u.frame.length);
8023
struct sk_buff *skb;
8025
u16 filter = priv->prom_priv->filter;
8027
/* If the filter is set to not include Rx frames then return */
8028
if (filter & IPW_PROM_NO_RX)
8031
/* We received data from the HW, so stop the watchdog */
8032
priv->prom_net_dev->trans_start = jiffies;
8034
if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
8035
priv->prom_priv->ieee->stats.rx_errors++;
8036
IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
8040
/* We only process data packets if the interface is open */
8041
if (unlikely(!netif_running(priv->prom_net_dev))) {
8042
priv->prom_priv->ieee->stats.rx_dropped++;
8043
IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
8047
/* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
8049
if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
8050
/* FIXME: Should alloc bigger skb instead */
8051
priv->prom_priv->ieee->stats.rx_dropped++;
8052
IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
8056
hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
8057
if (ieee80211_is_management(le16_to_cpu(hdr->frame_ctl))) {
8058
if (filter & IPW_PROM_NO_MGMT)
8060
if (filter & IPW_PROM_MGMT_HEADER_ONLY)
8062
} else if (ieee80211_is_control(le16_to_cpu(hdr->frame_ctl))) {
8063
if (filter & IPW_PROM_NO_CTL)
8065
if (filter & IPW_PROM_CTL_HEADER_ONLY)
8067
} else if (ieee80211_is_data(le16_to_cpu(hdr->frame_ctl))) {
8068
if (filter & IPW_PROM_NO_DATA)
8070
if (filter & IPW_PROM_DATA_HEADER_ONLY)
8074
/* Copy the SKB since this is for the promiscuous side */
8075
skb = skb_copy(rxb->skb, GFP_ATOMIC);
8077
IPW_ERROR("skb_clone failed for promiscuous copy.\n");
8081
/* copy the frame data to write after where the radiotap header goes */
8082
ipw_rt = (void *)skb->data;
8085
len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
8087
memcpy(ipw_rt->payload, hdr, len);
8089
/* Zero the radiotap static buffer ... We only need to zero the bytes
8090
* NOT part of our real header, saves a little time.
8092
* No longer necessary since we fill in all our data. Purge before
8093
* merging patch officially.
8094
* memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
8095
* IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
8098
ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
8099
ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
8100
ipw_rt->rt_hdr.it_len = sizeof(*ipw_rt); /* total header+data */
8102
/* Set the size of the skb to the size of the frame */
8103
skb_put(skb, ipw_rt->rt_hdr.it_len + len);
8105
/* Big bitfield of all the fields we provide in radiotap */
8106
ipw_rt->rt_hdr.it_present =
8107
((1 << IEEE80211_RADIOTAP_TSFT) |
8108
(1 << IEEE80211_RADIOTAP_FLAGS) |
8109
(1 << IEEE80211_RADIOTAP_RATE) |
8110
(1 << IEEE80211_RADIOTAP_CHANNEL) |
8111
(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
8112
(1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
8113
(1 << IEEE80211_RADIOTAP_ANTENNA));
8115
/* Zero the flags, we'll add to them as we go */
8116
ipw_rt->rt_flags = 0;
8117
ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
8118
frame->parent_tsf[2] << 16 |
8119
frame->parent_tsf[1] << 8 |
8120
frame->parent_tsf[0]);
8122
/* Convert to DBM */
8123
ipw_rt->rt_dbmsignal = signal;
8124
ipw_rt->rt_dbmnoise = noise;
8126
/* Convert the channel data and set the flags */
8127
ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
8128
if (channel > 14) { /* 802.11a */
8129
ipw_rt->rt_chbitmask =
8130
cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
8131
} else if (phy_flags & (1 << 5)) { /* 802.11b */
8132
ipw_rt->rt_chbitmask =
8133
cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
8134
} else { /* 802.11g */
8135
ipw_rt->rt_chbitmask =
8136
(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
8139
/* set the rate in multiples of 500k/s */
8141
case IPW_TX_RATE_1MB:
8142
ipw_rt->rt_rate = 2;
8144
case IPW_TX_RATE_2MB:
8145
ipw_rt->rt_rate = 4;
8147
case IPW_TX_RATE_5MB:
8148
ipw_rt->rt_rate = 10;
8150
case IPW_TX_RATE_6MB:
8151
ipw_rt->rt_rate = 12;
8153
case IPW_TX_RATE_9MB:
8154
ipw_rt->rt_rate = 18;
8156
case IPW_TX_RATE_11MB:
8157
ipw_rt->rt_rate = 22;
8159
case IPW_TX_RATE_12MB:
8160
ipw_rt->rt_rate = 24;
8162
case IPW_TX_RATE_18MB:
8163
ipw_rt->rt_rate = 36;
8165
case IPW_TX_RATE_24MB:
8166
ipw_rt->rt_rate = 48;
8168
case IPW_TX_RATE_36MB:
8169
ipw_rt->rt_rate = 72;
8171
case IPW_TX_RATE_48MB:
8172
ipw_rt->rt_rate = 96;
8174
case IPW_TX_RATE_54MB:
8175
ipw_rt->rt_rate = 108;
8178
ipw_rt->rt_rate = 0;
8182
/* antenna number */
8183
ipw_rt->rt_antenna = (phy_flags & 3);
8185
/* set the preamble flag if we have it */
8186
if (phy_flags & (1 << 6))
8187
ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
8189
IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
8191
if (!ieee80211_rx(priv->prom_priv->ieee, skb, stats)) {
8192
priv->prom_priv->ieee->stats.rx_errors++;
8193
dev_kfree_skb_any(skb);
8198
static int is_network_packet(struct ipw_priv *priv,
8199
struct ieee80211_hdr_4addr *header)
8201
/* Filter incoming packets to determine if they are targetted toward
8202
* this network, discarding packets coming from ourselves */
8203
switch (priv->ieee->iw_mode) {
8204
case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
8205
/* packets from our adapter are dropped (echo) */
8206
if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
8209
/* {broad,multi}cast packets to our BSSID go through */
8210
if (ipw_is_multicast_ether_addr(header->addr1))
8211
return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
8213
/* packets to our adapter go through */
8214
return !memcmp(header->addr1, priv->net_dev->dev_addr,
8217
case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
8218
/* packets from our adapter are dropped (echo) */
8219
if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
8222
/* {broad,multi}cast packets to our BSS go through */
8223
if (ipw_is_multicast_ether_addr(header->addr1))
8224
return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
8226
/* packets to our adapter go through */
8227
return !memcmp(header->addr1, priv->net_dev->dev_addr,
8234
#define IPW_PACKET_RETRY_TIME HZ
8236
static int is_duplicate_packet(struct ipw_priv *priv,
8237
struct ieee80211_hdr_4addr *header)
8239
u16 sc = le16_to_cpu(header->seq_ctl);
8240
u16 seq = WLAN_GET_SEQ_SEQ(sc);
8241
u16 frag = WLAN_GET_SEQ_FRAG(sc);
8242
u16 *last_seq, *last_frag;
8243
unsigned long *last_time;
8245
switch (priv->ieee->iw_mode) {
8248
struct list_head *p;
8249
struct ipw_ibss_seq *entry = NULL;
8250
u8 *mac = header->addr2;
8251
int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8253
__list_for_each(p, &priv->ibss_mac_hash[index]) {
8255
list_entry(p, struct ipw_ibss_seq, list);
8256
if (!memcmp(entry->mac, mac, ETH_ALEN))
8259
if (p == &priv->ibss_mac_hash[index]) {
8260
entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
8263
("Cannot malloc new mac entry\n");
8266
memcpy(entry->mac, mac, ETH_ALEN);
8267
entry->seq_num = seq;
8268
entry->frag_num = frag;
8269
entry->packet_time = jiffies;
8270
list_add(&entry->list,
8271
&priv->ibss_mac_hash[index]);
8274
last_seq = &entry->seq_num;
8275
last_frag = &entry->frag_num;
8276
last_time = &entry->packet_time;
8280
last_seq = &priv->last_seq_num;
8281
last_frag = &priv->last_frag_num;
8282
last_time = &priv->last_packet_time;
8287
if ((*last_seq == seq) &&
8288
time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8289
if (*last_frag == frag)
8291
if (*last_frag + 1 != frag)
8292
/* out-of-order fragment */
8298
*last_time = jiffies;
8302
/* Comment this line now since we observed the card receives
8303
* duplicate packets but the FCTL_RETRY bit is not set in the
8304
* IBSS mode with fragmentation enabled.
8305
BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
8309
static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8310
struct ipw_rx_mem_buffer *rxb,
8311
struct ieee80211_rx_stats *stats)
8313
struct sk_buff *skb = rxb->skb;
8314
struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
8315
struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
8316
(skb->data + IPW_RX_FRAME_SIZE);
8318
ieee80211_rx_mgt(priv->ieee, header, stats);
8320
if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8321
((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8322
IEEE80211_STYPE_PROBE_RESP) ||
8323
(WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8324
IEEE80211_STYPE_BEACON))) {
8325
if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8326
ipw_add_station(priv, header->addr2);
8329
if (priv->config & CFG_NET_STATS) {
8330
IPW_DEBUG_HC("sending stat packet\n");
8332
/* Set the size of the skb to the size of the full
8333
* ipw header and 802.11 frame */
8334
skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8337
/* Advance past the ipw packet header to the 802.11 frame */
8338
skb_pull(skb, IPW_RX_FRAME_SIZE);
8340
/* Push the ieee80211_rx_stats before the 802.11 frame */
8341
memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8343
skb->dev = priv->ieee->dev;
8345
/* Point raw at the ieee80211_stats */
8346
skb->mac.raw = skb->data;
8348
skb->pkt_type = PACKET_OTHERHOST;
8349
skb->protocol = __constant_htons(ETH_P_80211_STATS);
8350
memset(skb->cb, 0, sizeof(rxb->skb->cb));
8357
* Main entry function for recieving a packet with 80211 headers. This
8358
* should be called when ever the FW has notified us that there is a new
8359
* skb in the recieve queue.
8361
static void ipw_rx(struct ipw_priv *priv)
8363
struct ipw_rx_mem_buffer *rxb;
8364
struct ipw_rx_packet *pkt;
8365
struct ieee80211_hdr_4addr *header;
8369
r = ipw_read32(priv, IPW_RX_READ_INDEX);
8370
w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
8371
i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
8374
rxb = priv->rxq->queue[i];
8375
if (unlikely(rxb == NULL)) {
8376
printk(KERN_CRIT "Queue not allocated!\n");
8379
priv->rxq->queue[i] = NULL;
8381
pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
8383
PCI_DMA_FROMDEVICE);
8385
pkt = (struct ipw_rx_packet *)rxb->skb->data;
8386
IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8387
pkt->header.message_type,
8388
pkt->header.rx_seq_num, pkt->header.control_bits);
8390
switch (pkt->header.message_type) {
8391
case RX_FRAME_TYPE: /* 802.11 frame */ {
8392
struct ieee80211_rx_stats stats = {
8393
.rssi = pkt->u.frame.rssi_dbm -
8396
le16_to_cpu(pkt->u.frame.rssi_dbm) -
8397
IPW_RSSI_TO_DBM + 0x100,
8399
le16_to_cpu(pkt->u.frame.noise),
8400
.rate = pkt->u.frame.rate,
8401
.mac_time = jiffies,
8403
pkt->u.frame.received_channel,
8406
control & (1 << 0)) ?
8407
IEEE80211_24GHZ_BAND :
8408
IEEE80211_52GHZ_BAND,
8409
.len = le16_to_cpu(pkt->u.frame.length),
8412
if (stats.rssi != 0)
8413
stats.mask |= IEEE80211_STATMASK_RSSI;
8414
if (stats.signal != 0)
8415
stats.mask |= IEEE80211_STATMASK_SIGNAL;
8416
if (stats.noise != 0)
8417
stats.mask |= IEEE80211_STATMASK_NOISE;
8418
if (stats.rate != 0)
8419
stats.mask |= IEEE80211_STATMASK_RATE;
8423
#ifdef CONFIG_IPW2200_PROMISCUOUS
8424
if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8425
ipw_handle_promiscuous_rx(priv, rxb, &stats);
8428
#ifdef CONFIG_IPW2200_MONITOR
8429
if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
8430
#ifdef CONFIG_IPW2200_RADIOTAP
8432
ipw_handle_data_packet_monitor(priv,
8436
ipw_handle_data_packet(priv, rxb,
8444
(struct ieee80211_hdr_4addr *)(rxb->skb->
8447
/* TODO: Check Ad-Hoc dest/source and make sure
8448
* that we are actually parsing these packets
8449
* correctly -- we should probably use the
8450
* frame control of the packet and disregard
8451
* the current iw_mode */
8454
is_network_packet(priv, header);
8455
if (network_packet && priv->assoc_network) {
8456
priv->assoc_network->stats.rssi =
8458
priv->exp_avg_rssi =
8459
exponential_average(priv->exp_avg_rssi,
8460
stats.rssi, DEPTH_RSSI);
8463
IPW_DEBUG_RX("Frame: len=%u\n",
8464
le16_to_cpu(pkt->u.frame.length));
8466
if (le16_to_cpu(pkt->u.frame.length) <
8467
ieee80211_get_hdrlen(le16_to_cpu(
8468
header->frame_ctl))) {
8470
("Received packet is too small. "
8472
priv->ieee->stats.rx_errors++;
8473
priv->wstats.discard.misc++;
8477
switch (WLAN_FC_GET_TYPE
8478
(le16_to_cpu(header->frame_ctl))) {
8480
case IEEE80211_FTYPE_MGMT:
8481
ipw_handle_mgmt_packet(priv, rxb,
8485
case IEEE80211_FTYPE_CTL:
8488
case IEEE80211_FTYPE_DATA:
8489
if (unlikely(!network_packet ||
8490
is_duplicate_packet(priv,
8493
IPW_DEBUG_DROP("Dropping: "
8506
ipw_handle_data_packet(priv, rxb,
8514
case RX_HOST_NOTIFICATION_TYPE:{
8516
("Notification: subtype=%02X flags=%02X size=%d\n",
8517
pkt->u.notification.subtype,
8518
pkt->u.notification.flags,
8519
le16_to_cpu(pkt->u.notification.size));
8520
ipw_rx_notification(priv, &pkt->u.notification);
8525
IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8526
pkt->header.message_type);
8530
/* For now we just don't re-use anything. We can tweak this
8531
* later to try and re-use notification packets and SKBs that
8532
* fail to Rx correctly */
8533
if (rxb->skb != NULL) {
8534
dev_kfree_skb_any(rxb->skb);
8538
pci_unmap_single(priv->pci_dev, rxb->dma_addr,
8539
IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
8540
list_add_tail(&rxb->list, &priv->rxq->rx_used);
8542
i = (i + 1) % RX_QUEUE_SIZE;
8545
/* Backtrack one entry */
8546
priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
8548
ipw_rx_queue_restock(priv);
8551
#define DEFAULT_RTS_THRESHOLD 2304U
8552
#define MIN_RTS_THRESHOLD 1U
8553
#define MAX_RTS_THRESHOLD 2304U
8554
#define DEFAULT_BEACON_INTERVAL 100U
8555
#define DEFAULT_SHORT_RETRY_LIMIT 7U
8556
#define DEFAULT_LONG_RETRY_LIMIT 4U
8560
* @option: options to control different reset behaviour
8561
* 0 = reset everything except the 'disable' module_param
8562
* 1 = reset everything and print out driver info (for probe only)
8563
* 2 = reset everything
8565
static int ipw_sw_reset(struct ipw_priv *priv, int option)
8567
int band, modulation;
8568
int old_mode = priv->ieee->iw_mode;
8570
/* Initialize module parameter values here */
8573
/* We default to disabling the LED code as right now it causes
8574
* too many systems to lock up... */
8576
priv->config |= CFG_NO_LED;
8579
priv->config |= CFG_ASSOCIATE;
8581
IPW_DEBUG_INFO("Auto associate disabled.\n");
8584
priv->config |= CFG_ADHOC_CREATE;
8586
IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8588
priv->config &= ~CFG_STATIC_ESSID;
8589
priv->essid_len = 0;
8590
memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8592
if (disable && option) {
8593
priv->status |= STATUS_RF_KILL_SW;
8594
IPW_DEBUG_INFO("Radio disabled.\n");
8598
priv->config |= CFG_STATIC_CHANNEL;
8599
priv->channel = channel;
8600
IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8601
/* TODO: Validate that provided channel is in range */
8603
#ifdef CONFIG_IPW2200_QOS
8604
ipw_qos_init(priv, qos_enable, qos_burst_enable,
8605
burst_duration_CCK, burst_duration_OFDM);
8606
#endif /* CONFIG_IPW2200_QOS */
8610
priv->ieee->iw_mode = IW_MODE_ADHOC;
8611
priv->net_dev->type = ARPHRD_ETHER;
8614
#ifdef CONFIG_IPW2200_MONITOR
8616
priv->ieee->iw_mode = IW_MODE_MONITOR;
8617
#ifdef CONFIG_IPW2200_RADIOTAP
8618
priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8620
priv->net_dev->type = ARPHRD_IEEE80211;
8626
priv->net_dev->type = ARPHRD_ETHER;
8627
priv->ieee->iw_mode = IW_MODE_INFRA;
8632
priv->ieee->host_encrypt = 0;
8633
priv->ieee->host_encrypt_msdu = 0;
8634
priv->ieee->host_decrypt = 0;
8635
priv->ieee->host_mc_decrypt = 0;
8637
IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
8639
/* IPW2200/2915 is abled to do hardware fragmentation. */
8640
priv->ieee->host_open_frag = 0;
8642
if ((priv->pci_dev->device == 0x4223) ||
8643
(priv->pci_dev->device == 0x4224)) {
8645
printk(KERN_INFO DRV_NAME
8646
": Detected Intel PRO/Wireless 2915ABG Network "
8648
priv->ieee->abg_true = 1;
8649
band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8650
modulation = IEEE80211_OFDM_MODULATION |
8651
IEEE80211_CCK_MODULATION;
8652
priv->adapter = IPW_2915ABG;
8653
priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
8656
printk(KERN_INFO DRV_NAME
8657
": Detected Intel PRO/Wireless 2200BG Network "
8660
priv->ieee->abg_true = 0;
8661
band = IEEE80211_24GHZ_BAND;
8662
modulation = IEEE80211_OFDM_MODULATION |
8663
IEEE80211_CCK_MODULATION;
8664
priv->adapter = IPW_2200BG;
8665
priv->ieee->mode = IEEE_G | IEEE_B;
8668
priv->ieee->freq_band = band;
8669
priv->ieee->modulation = modulation;
8671
priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
8673
priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8674
priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8676
priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8677
priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8678
priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
8680
/* If power management is turned on, default to AC mode */
8681
priv->power_mode = IPW_POWER_AC;
8682
priv->tx_power = IPW_TX_POWER_DEFAULT;
8684
return old_mode == priv->ieee->iw_mode;
8688
* This file defines the Wireless Extension handlers. It does not
8689
* define any methods of hardware manipulation and relies on the
8690
* functions defined in ipw_main to provide the HW interaction.
8692
* The exception to this is the use of the ipw_get_ordinal()
8693
* function used to poll the hardware vs. making unecessary calls.
8697
static int ipw_wx_get_name(struct net_device *dev,
8698
struct iw_request_info *info,
8699
union iwreq_data *wrqu, char *extra)
8701
struct ipw_priv *priv = ieee80211_priv(dev);
8702
mutex_lock(&priv->mutex);
8703
if (priv->status & STATUS_RF_KILL_MASK)
8704
strcpy(wrqu->name, "radio off");
8705
else if (!(priv->status & STATUS_ASSOCIATED))
8706
strcpy(wrqu->name, "unassociated");
8708
snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8709
ipw_modes[priv->assoc_request.ieee_mode]);
8710
IPW_DEBUG_WX("Name: %s\n", wrqu->name);
8711
mutex_unlock(&priv->mutex);
8715
static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8718
IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8719
priv->config &= ~CFG_STATIC_CHANNEL;
8720
IPW_DEBUG_ASSOC("Attempting to associate with new "
8722
ipw_associate(priv);
8726
priv->config |= CFG_STATIC_CHANNEL;
8728
if (priv->channel == channel) {
8729
IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8734
IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8735
priv->channel = channel;
8737
#ifdef CONFIG_IPW2200_MONITOR
8738
if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
8740
if (priv->status & STATUS_SCANNING) {
8741
IPW_DEBUG_SCAN("Scan abort triggered due to "
8742
"channel change.\n");
8743
ipw_abort_scan(priv);
8746
for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8749
if (priv->status & STATUS_SCANNING)
8750
IPW_DEBUG_SCAN("Still scanning...\n");
8752
IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8757
#endif /* CONFIG_IPW2200_MONITOR */
8759
/* Network configuration changed -- force [re]association */
8760
IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8761
if (!ipw_disassociate(priv))
8762
ipw_associate(priv);
8767
static int ipw_wx_set_freq(struct net_device *dev,
8768
struct iw_request_info *info,
8769
union iwreq_data *wrqu, char *extra)
8771
struct ipw_priv *priv = ieee80211_priv(dev);
8772
const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
8773
struct iw_freq *fwrq = &wrqu->freq;
8779
IPW_DEBUG_WX("SET Freq/Channel -> any\n");
8780
mutex_lock(&priv->mutex);
8781
ret = ipw_set_channel(priv, 0);
8782
mutex_unlock(&priv->mutex);
8785
/* if setting by freq convert to channel */
8787
channel = ipw_freq_to_channel(priv->ieee, fwrq->m);
8793
if (!(band = ipw_is_valid_channel(priv->ieee, channel)))
8796
if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
8797
i = ipw_channel_to_index(priv->ieee, channel);
8801
flags = (band == IEEE80211_24GHZ_BAND) ?
8802
geo->bg[i].flags : geo->a[i].flags;
8803
if (flags & IEEE80211_CH_PASSIVE_ONLY) {
8804
IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8809
IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
8810
mutex_lock(&priv->mutex);
8811
ret = ipw_set_channel(priv, channel);
8812
mutex_unlock(&priv->mutex);
8816
static int ipw_wx_get_freq(struct net_device *dev,
8817
struct iw_request_info *info,
8818
union iwreq_data *wrqu, char *extra)
8820
struct ipw_priv *priv = ieee80211_priv(dev);
8824
/* If we are associated, trying to associate, or have a statically
8825
* configured CHANNEL then return that; otherwise return ANY */
8826
mutex_lock(&priv->mutex);
8827
if (priv->config & CFG_STATIC_CHANNEL ||
8828
priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) {
8831
i = ipw_channel_to_index(priv->ieee, priv->channel);
8835
switch (ipw_is_valid_channel(priv->ieee, priv->channel)) {
8836
case IEEE80211_52GHZ_BAND:
8837
wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000;
8840
case IEEE80211_24GHZ_BAND:
8841
wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000;
8850
mutex_unlock(&priv->mutex);
8851
IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8855
static int ipw_wx_set_mode(struct net_device *dev,
8856
struct iw_request_info *info,
8857
union iwreq_data *wrqu, char *extra)
8859
struct ipw_priv *priv = ieee80211_priv(dev);
8862
IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8864
switch (wrqu->mode) {
8865
#ifdef CONFIG_IPW2200_MONITOR
8866
case IW_MODE_MONITOR:
8872
wrqu->mode = IW_MODE_INFRA;
8877
if (wrqu->mode == priv->ieee->iw_mode)
8880
mutex_lock(&priv->mutex);
8882
ipw_sw_reset(priv, 0);
8884
#ifdef CONFIG_IPW2200_MONITOR
8885
if (priv->ieee->iw_mode == IW_MODE_MONITOR)
8886
priv->net_dev->type = ARPHRD_ETHER;
8888
if (wrqu->mode == IW_MODE_MONITOR)
8889
#ifdef CONFIG_IPW2200_RADIOTAP
8890
priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8892
priv->net_dev->type = ARPHRD_IEEE80211;
8894
#endif /* CONFIG_IPW2200_MONITOR */
8896
/* Free the existing firmware and reset the fw_loaded
8897
* flag so ipw_load() will bring in the new firmawre */
8900
priv->ieee->iw_mode = wrqu->mode;
8902
queue_work(priv->workqueue, &priv->adapter_restart);
8903
mutex_unlock(&priv->mutex);
8907
static int ipw_wx_get_mode(struct net_device *dev,
8908
struct iw_request_info *info,
8909
union iwreq_data *wrqu, char *extra)
8911
struct ipw_priv *priv = ieee80211_priv(dev);
8912
mutex_lock(&priv->mutex);
8913
wrqu->mode = priv->ieee->iw_mode;
8914
IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
8915
mutex_unlock(&priv->mutex);
8919
/* Values are in microsecond */
8920
static const s32 timeout_duration[] = {
8928
static const s32 period_duration[] = {
8936
static int ipw_wx_get_range(struct net_device *dev,
8937
struct iw_request_info *info,
8938
union iwreq_data *wrqu, char *extra)
8940
struct ipw_priv *priv = ieee80211_priv(dev);
8941
struct iw_range *range = (struct iw_range *)extra;
8942
const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
8945
wrqu->data.length = sizeof(*range);
8946
memset(range, 0, sizeof(*range));
8948
/* 54Mbs == ~27 Mb/s real (802.11g) */
8949
range->throughput = 27 * 1000 * 1000;
8951
range->max_qual.qual = 100;
8952
/* TODO: Find real max RSSI and stick here */
8953
range->max_qual.level = 0;
8954
range->max_qual.noise = 0;
8955
range->max_qual.updated = 7; /* Updated all three */
8957
range->avg_qual.qual = 70;
8958
/* TODO: Find real 'good' to 'bad' threshol value for RSSI */
8959
range->avg_qual.level = 0; /* FIXME to real average level */
8960
range->avg_qual.noise = 0;
8961
range->avg_qual.updated = 7; /* Updated all three */
8962
mutex_lock(&priv->mutex);
8963
range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
8965
for (i = 0; i < range->num_bitrates; i++)
8966
range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
8969
range->max_rts = DEFAULT_RTS_THRESHOLD;
8970
range->min_frag = MIN_FRAG_THRESHOLD;
8971
range->max_frag = MAX_FRAG_THRESHOLD;
8973
range->encoding_size[0] = 5;
8974
range->encoding_size[1] = 13;
8975
range->num_encoding_sizes = 2;
8976
range->max_encoding_tokens = WEP_KEYS;
8978
/* Set the Wireless Extension versions */
8979
range->we_version_compiled = WIRELESS_EXT;
8980
range->we_version_source = 18;
8983
if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
8984
for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8985
if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8986
(geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8989
range->freq[i].i = geo->bg[j].channel;
8990
range->freq[i].m = geo->bg[j].freq * 100000;
8991
range->freq[i].e = 1;
8996
if (priv->ieee->mode & IEEE_A) {
8997
for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8998
if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8999
(geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY))
9002
range->freq[i].i = geo->a[j].channel;
9003
range->freq[i].m = geo->a[j].freq * 100000;
9004
range->freq[i].e = 1;
9009
range->num_channels = i;
9010
range->num_frequency = i;
9012
mutex_unlock(&priv->mutex);
9014
#if WIRELESS_EXT >= 17
9015
/* Event capability (kernel + driver) */
9016
range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
9017
IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
9018
IW_EVENT_CAPA_MASK(SIOCGIWAP) |
9019
IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
9020
range->event_capa[1] = IW_EVENT_CAPA_K_1;
9022
#if WIRELESS_EXT >= 18
9023
range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
9024
IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
9028
IPW_DEBUG_WX("GET Range\n");
9032
static int ipw_wx_set_wap(struct net_device *dev,
9033
struct iw_request_info *info,
9034
union iwreq_data *wrqu, char *extra)
9036
struct ipw_priv *priv = ieee80211_priv(dev);
9038
static const unsigned char any[] = {
9039
0xff, 0xff, 0xff, 0xff, 0xff, 0xff
9041
static const unsigned char off[] = {
9042
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9045
if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
9047
mutex_lock(&priv->mutex);
9048
if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
9049
!memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9050
/* we disable mandatory BSSID association */
9051
IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
9052
priv->config &= ~CFG_STATIC_BSSID;
9053
IPW_DEBUG_ASSOC("Attempting to associate with new "
9055
ipw_associate(priv);
9056
mutex_unlock(&priv->mutex);
9060
priv->config |= CFG_STATIC_BSSID;
9061
if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9062
IPW_DEBUG_WX("BSSID set to current BSSID.\n");
9063
mutex_unlock(&priv->mutex);
9067
IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
9068
MAC_ARG(wrqu->ap_addr.sa_data));
9070
memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
9072
/* Network configuration changed -- force [re]association */
9073
IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
9074
if (!ipw_disassociate(priv))
9075
ipw_associate(priv);
9077
mutex_unlock(&priv->mutex);
9081
static int ipw_wx_get_wap(struct net_device *dev,
9082
struct iw_request_info *info,
9083
union iwreq_data *wrqu, char *extra)
9085
struct ipw_priv *priv = ieee80211_priv(dev);
9086
/* If we are associated, trying to associate, or have a statically
9087
* configured BSSID then return that; otherwise return ANY */
9088
mutex_lock(&priv->mutex);
9089
if (priv->config & CFG_STATIC_BSSID ||
9090
priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9091
wrqu->ap_addr.sa_family = ARPHRD_ETHER;
9092
memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
9094
memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
9096
IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
9097
MAC_ARG(wrqu->ap_addr.sa_data));
9098
mutex_unlock(&priv->mutex);
9102
static int ipw_wx_set_essid(struct net_device *dev,
9103
struct iw_request_info *info,
9104
union iwreq_data *wrqu, char *extra)
9106
struct ipw_priv *priv = ieee80211_priv(dev);
9109
mutex_lock(&priv->mutex);
9111
if (!wrqu->essid.flags)
9113
IPW_DEBUG_WX("Setting ESSID to ANY\n");
9114
ipw_disassociate(priv);
9115
priv->config &= ~CFG_STATIC_ESSID;
9116
ipw_associate(priv);
9117
mutex_unlock(&priv->mutex);
9121
length = min((int) (wrqu->essid.length - IW_ESSID_FIX),
9124
priv->config |= CFG_STATIC_ESSID;
9126
if (priv->essid_len == length && !memcmp(priv->essid, extra, length)
9127
&& (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
9128
IPW_DEBUG_WX("ESSID set to current ESSID.\n");
9129
mutex_unlock(&priv->mutex);
9133
IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(extra, length),
9136
priv->essid_len = length;
9137
memcpy(priv->essid, extra, priv->essid_len);
9139
/* Network configuration changed -- force [re]association */
9140
IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
9141
if (!ipw_disassociate(priv))
9142
ipw_associate(priv);
9144
mutex_unlock(&priv->mutex);
9148
static int ipw_wx_get_essid(struct net_device *dev,
9149
struct iw_request_info *info,
9150
union iwreq_data *wrqu, char *extra)
9152
struct ipw_priv *priv = ieee80211_priv(dev);
9154
/* If we are associated, trying to associate, or have a statically
9155
* configured ESSID then return that; otherwise return ANY */
9156
mutex_lock(&priv->mutex);
9157
if (priv->config & CFG_STATIC_ESSID ||
9158
priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9159
IPW_DEBUG_WX("Getting essid: '%s'\n",
9160
escape_essid(priv->essid, priv->essid_len));
9161
memcpy(extra, priv->essid, priv->essid_len);
9162
wrqu->essid.length = priv->essid_len;
9163
wrqu->essid.flags = 1; /* active */
9165
IPW_DEBUG_WX("Getting essid: ANY\n");
9166
wrqu->essid.length = 0;
9167
wrqu->essid.flags = 0; /* active */
9169
mutex_unlock(&priv->mutex);
9173
static int ipw_wx_set_nick(struct net_device *dev,
9174
struct iw_request_info *info,
9175
union iwreq_data *wrqu, char *extra)
9177
struct ipw_priv *priv = ieee80211_priv(dev);
9179
IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
9180
if (wrqu->data.length > IW_ESSID_MAX_SIZE)
9182
mutex_lock(&priv->mutex);
9183
wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
9184
memset(priv->nick, 0, sizeof(priv->nick));
9185
memcpy(priv->nick, extra, wrqu->data.length);
9186
IPW_DEBUG_TRACE("<<\n");
9187
mutex_unlock(&priv->mutex);
9192
static int ipw_wx_get_nick(struct net_device *dev,
9193
struct iw_request_info *info,
9194
union iwreq_data *wrqu, char *extra)
9196
struct ipw_priv *priv = ieee80211_priv(dev);
9197
IPW_DEBUG_WX("Getting nick\n");
9198
mutex_lock(&priv->mutex);
9199
wrqu->data.length = strlen(priv->nick);
9200
memcpy(extra, priv->nick, wrqu->data.length);
9201
wrqu->data.flags = 1; /* active */
9202
mutex_unlock(&priv->mutex);
9206
static int ipw_wx_set_sens(struct net_device *dev,
9207
struct iw_request_info *info,
9208
union iwreq_data *wrqu, char *extra)
9210
struct ipw_priv *priv = ieee80211_priv(dev);
9213
IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
9214
IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
9215
mutex_lock(&priv->mutex);
9217
if (wrqu->sens.fixed == 0)
9219
priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
9220
priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
9223
if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
9224
(wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
9229
priv->roaming_threshold = wrqu->sens.value;
9230
priv->disassociate_threshold = 3*wrqu->sens.value;
9232
mutex_unlock(&priv->mutex);
9236
static int ipw_wx_get_sens(struct net_device *dev,
9237
struct iw_request_info *info,
9238
union iwreq_data *wrqu, char *extra)
9240
struct ipw_priv *priv = ieee80211_priv(dev);
9241
mutex_lock(&priv->mutex);
9242
wrqu->sens.fixed = 1;
9243
wrqu->sens.value = priv->roaming_threshold;
9244
mutex_unlock(&priv->mutex);
9246
IPW_DEBUG_WX("GET roaming threshold -> %s %d \n",
9247
wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9252
static int ipw_wx_set_rate(struct net_device *dev,
9253
struct iw_request_info *info,
9254
union iwreq_data *wrqu, char *extra)
9256
/* TODO: We should use semaphores or locks for access to priv */
9257
struct ipw_priv *priv = ieee80211_priv(dev);
9258
u32 target_rate = wrqu->bitrate.value;
9261
/* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
9262
/* value = X, fixed = 1 means only rate X */
9263
/* value = X, fixed = 0 means all rates lower equal X */
9265
if (target_rate == -1) {
9267
mask = IEEE80211_DEFAULT_RATES_MASK;
9268
/* Now we should reassociate */
9273
fixed = wrqu->bitrate.fixed;
9275
if (target_rate == 1000000 || !fixed)
9276
mask |= IEEE80211_CCK_RATE_1MB_MASK;
9277
if (target_rate == 1000000)
9280
if (target_rate == 2000000 || !fixed)
9281
mask |= IEEE80211_CCK_RATE_2MB_MASK;
9282
if (target_rate == 2000000)
9285
if (target_rate == 5500000 || !fixed)
9286
mask |= IEEE80211_CCK_RATE_5MB_MASK;
9287
if (target_rate == 5500000)
9290
if (target_rate == 6000000 || !fixed)
9291
mask |= IEEE80211_OFDM_RATE_6MB_MASK;
9292
if (target_rate == 6000000)
9295
if (target_rate == 9000000 || !fixed)
9296
mask |= IEEE80211_OFDM_RATE_9MB_MASK;
9297
if (target_rate == 9000000)
9300
if (target_rate == 11000000 || !fixed)
9301
mask |= IEEE80211_CCK_RATE_11MB_MASK;
9302
if (target_rate == 11000000)
9305
if (target_rate == 12000000 || !fixed)
9306
mask |= IEEE80211_OFDM_RATE_12MB_MASK;
9307
if (target_rate == 12000000)
9310
if (target_rate == 18000000 || !fixed)
9311
mask |= IEEE80211_OFDM_RATE_18MB_MASK;
9312
if (target_rate == 18000000)
9315
if (target_rate == 24000000 || !fixed)
9316
mask |= IEEE80211_OFDM_RATE_24MB_MASK;
9317
if (target_rate == 24000000)
9320
if (target_rate == 36000000 || !fixed)
9321
mask |= IEEE80211_OFDM_RATE_36MB_MASK;
9322
if (target_rate == 36000000)
9325
if (target_rate == 48000000 || !fixed)
9326
mask |= IEEE80211_OFDM_RATE_48MB_MASK;
9327
if (target_rate == 48000000)
9330
if (target_rate == 54000000 || !fixed)
9331
mask |= IEEE80211_OFDM_RATE_54MB_MASK;
9332
if (target_rate == 54000000)
9335
IPW_DEBUG_WX("invalid rate specified, returning error\n");
9339
IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9340
mask, fixed ? "fixed" : "sub-rates");
9341
mutex_lock(&priv->mutex);
9342
if (mask == IEEE80211_DEFAULT_RATES_MASK) {
9343
priv->config &= ~CFG_FIXED_RATE;
9344
ipw_set_fixed_rate(priv, priv->ieee->mode);
9346
priv->config |= CFG_FIXED_RATE;
9348
if (priv->rates_mask == mask) {
9349
IPW_DEBUG_WX("Mask set to current mask.\n");
9350
mutex_unlock(&priv->mutex);
9354
priv->rates_mask = mask;
9356
/* Network configuration changed -- force [re]association */
9357
IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9358
if (!ipw_disassociate(priv))
9359
ipw_associate(priv);
9361
mutex_unlock(&priv->mutex);
9365
static int ipw_wx_get_rate(struct net_device *dev,
9366
struct iw_request_info *info,
9367
union iwreq_data *wrqu, char *extra)
9369
struct ipw_priv *priv = ieee80211_priv(dev);
9370
mutex_lock(&priv->mutex);
9371
wrqu->bitrate.value = priv->last_rate;
9372
wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
9373
mutex_unlock(&priv->mutex);
9374
IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
9378
static int ipw_wx_set_rts(struct net_device *dev,
9379
struct iw_request_info *info,
9380
union iwreq_data *wrqu, char *extra)
9382
struct ipw_priv *priv = ieee80211_priv(dev);
9383
mutex_lock(&priv->mutex);
9384
if (wrqu->rts.disabled)
9385
priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9387
if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
9388
wrqu->rts.value > MAX_RTS_THRESHOLD) {
9389
mutex_unlock(&priv->mutex);
9392
priv->rts_threshold = wrqu->rts.value;
9395
ipw_send_rts_threshold(priv, priv->rts_threshold);
9396
mutex_unlock(&priv->mutex);
9397
IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
9401
static int ipw_wx_get_rts(struct net_device *dev,
9402
struct iw_request_info *info,
9403
union iwreq_data *wrqu, char *extra)
9405
struct ipw_priv *priv = ieee80211_priv(dev);
9406
mutex_lock(&priv->mutex);
9407
wrqu->rts.value = priv->rts_threshold;
9408
wrqu->rts.fixed = 0; /* no auto select */
9409
wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
9410
mutex_unlock(&priv->mutex);
9411
IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
9415
static int ipw_wx_set_txpow(struct net_device *dev,
9416
struct iw_request_info *info,
9417
union iwreq_data *wrqu, char *extra)
9419
struct ipw_priv *priv = ieee80211_priv(dev);
9422
mutex_lock(&priv->mutex);
9423
if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
9428
if (!wrqu->power.fixed)
9429
wrqu->power.value = IPW_TX_POWER_DEFAULT;
9431
if (wrqu->power.flags != IW_TXPOW_DBM) {
9436
if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
9437
(wrqu->power.value < IPW_TX_POWER_MIN)) {
9442
priv->tx_power = wrqu->power.value;
9443
err = ipw_set_tx_power(priv);
9445
mutex_unlock(&priv->mutex);
9449
static int ipw_wx_get_txpow(struct net_device *dev,
9450
struct iw_request_info *info,
9451
union iwreq_data *wrqu, char *extra)
9453
struct ipw_priv *priv = ieee80211_priv(dev);
9454
mutex_lock(&priv->mutex);
9455
wrqu->power.value = priv->tx_power;
9456
wrqu->power.fixed = 1;
9457
wrqu->power.flags = IW_TXPOW_DBM;
9458
wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
9459
mutex_unlock(&priv->mutex);
9461
IPW_DEBUG_WX("GET TX Power -> %s %d \n",
9462
wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9467
static int ipw_wx_set_frag(struct net_device *dev,
9468
struct iw_request_info *info,
9469
union iwreq_data *wrqu, char *extra)
9471
struct ipw_priv *priv = ieee80211_priv(dev);
9472
mutex_lock(&priv->mutex);
9473
if (wrqu->frag.disabled)
9474
priv->ieee->fts = DEFAULT_FTS;
9476
if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
9477
wrqu->frag.value > MAX_FRAG_THRESHOLD) {
9478
mutex_unlock(&priv->mutex);
9482
priv->ieee->fts = wrqu->frag.value & ~0x1;
9485
ipw_send_frag_threshold(priv, wrqu->frag.value);
9486
mutex_unlock(&priv->mutex);
9487
IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
9491
static int ipw_wx_get_frag(struct net_device *dev,
9492
struct iw_request_info *info,
9493
union iwreq_data *wrqu, char *extra)
9495
struct ipw_priv *priv = ieee80211_priv(dev);
9496
mutex_lock(&priv->mutex);
9497
wrqu->frag.value = priv->ieee->fts;
9498
wrqu->frag.fixed = 0; /* no auto select */
9499
wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
9500
mutex_unlock(&priv->mutex);
9501
IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
9506
static int ipw_wx_set_retry(struct net_device *dev,
9507
struct iw_request_info *info,
9508
union iwreq_data *wrqu, char *extra)
9510
struct ipw_priv *priv = ieee80211_priv(dev);
9512
if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9515
if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9518
if (wrqu->retry.value < 0 || wrqu->retry.value >= 255)
9521
mutex_lock(&priv->mutex);
9522
if (wrqu->retry.flags & IW_RETRY_SHORT)
9523
priv->short_retry_limit = (u8) wrqu->retry.value;
9524
else if (wrqu->retry.flags & IW_RETRY_LONG)
9525
priv->long_retry_limit = (u8) wrqu->retry.value;
9527
priv->short_retry_limit = (u8) wrqu->retry.value;
9528
priv->long_retry_limit = (u8) wrqu->retry.value;
9531
ipw_send_retry_limit(priv, priv->short_retry_limit,
9532
priv->long_retry_limit);
9533
mutex_unlock(&priv->mutex);
9534
IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9535
priv->short_retry_limit, priv->long_retry_limit);
9539
static int ipw_wx_get_retry(struct net_device *dev,
9540
struct iw_request_info *info,
9541
union iwreq_data *wrqu, char *extra)
9543
struct ipw_priv *priv = ieee80211_priv(dev);
9545
mutex_lock(&priv->mutex);
9546
wrqu->retry.disabled = 0;
9548
if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
9549
mutex_unlock(&priv->mutex);
9553
if (wrqu->retry.flags & IW_RETRY_LONG) {
9554
wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
9555
wrqu->retry.value = priv->long_retry_limit;
9556
} else if (wrqu->retry.flags & IW_RETRY_SHORT) {
9557
wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
9558
wrqu->retry.value = priv->short_retry_limit;
9560
wrqu->retry.flags = IW_RETRY_LIMIT;
9561
wrqu->retry.value = priv->short_retry_limit;
9563
mutex_unlock(&priv->mutex);
9565
IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9570
#if WIRELESS_EXT > 17
9571
static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
9574
struct ipw_scan_request_ext scan;
9575
int err = 0, scan_type;
9577
if (!(priv->status & STATUS_INIT) ||
9578
(priv->status & STATUS_EXIT_PENDING))
9581
mutex_lock(&priv->mutex);
9583
if (priv->status & STATUS_RF_KILL_MASK) {
9584
IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
9585
priv->status |= STATUS_SCAN_PENDING;
9589
IPW_DEBUG_HC("starting request direct scan!\n");
9591
if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
9592
/* We should not sleep here; otherwise we will block most
9593
* of the system (for instance, we hold rtnl_lock when we
9599
memset(&scan, 0, sizeof(scan));
9601
if (priv->config & CFG_SPEED_SCAN)
9602
scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9605
scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9608
scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
9610
scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
9611
scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
9613
scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
9615
err = ipw_send_ssid(priv, essid, essid_len);
9617
IPW_DEBUG_HC("Attempt to send SSID command failed\n");
9620
scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
9622
ipw_add_scan_channels(priv, &scan, scan_type);
9624
err = ipw_send_scan_request_ext(priv, &scan);
9626
IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
9630
priv->status |= STATUS_SCANNING;
9633
mutex_unlock(&priv->mutex);
9636
#endif /* WIRELESS_EXT > 17 */
9638
static int ipw_wx_set_scan(struct net_device *dev,
9639
struct iw_request_info *info,
9640
union iwreq_data *wrqu, char *extra)
9642
struct ipw_priv *priv = ieee80211_priv(dev);
9643
#if WIRELESS_EXT > 17
9644
struct iw_scan_req *req = (struct iw_scan_req *)extra;
9646
if (wrqu->data.length == sizeof(struct iw_scan_req)) {
9647
if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9648
ipw_request_direct_scan(priv, req->essid,
9652
if (req->scan_type == IW_SCAN_TYPE_PASSIVE) {
9653
queue_work(priv->workqueue,
9654
&priv->request_passive_scan);
9659
IPW_DEBUG_WX("Start scan\n");
9661
queue_delayed_work(priv->workqueue, &priv->request_scan, 0);
9666
static int ipw_wx_get_scan(struct net_device *dev,
9667
struct iw_request_info *info,
9668
union iwreq_data *wrqu, char *extra)
9670
struct ipw_priv *priv = ieee80211_priv(dev);
9671
return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9674
static int ipw_wx_set_encode(struct net_device *dev,
9675
struct iw_request_info *info,
9676
union iwreq_data *wrqu, char *key)
9678
struct ipw_priv *priv = ieee80211_priv(dev);
9680
u32 cap = priv->capability;
9682
mutex_lock(&priv->mutex);
9683
ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
9685
/* In IBSS mode, we need to notify the firmware to update
9686
* the beacon info after we changed the capability. */
9687
if (cap != priv->capability &&
9688
priv->ieee->iw_mode == IW_MODE_ADHOC &&
9689
priv->status & STATUS_ASSOCIATED)
9690
ipw_disassociate(priv);
9692
mutex_unlock(&priv->mutex);
9696
static int ipw_wx_get_encode(struct net_device *dev,
9697
struct iw_request_info *info,
9698
union iwreq_data *wrqu, char *key)
9700
struct ipw_priv *priv = ieee80211_priv(dev);
9701
return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9704
static int ipw_wx_set_power(struct net_device *dev,
9705
struct iw_request_info *info,
9706
union iwreq_data *wrqu, char *extra)
9708
struct ipw_priv *priv = ieee80211_priv(dev);
9710
mutex_lock(&priv->mutex);
9711
if (wrqu->power.disabled) {
9712
priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9713
err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9715
IPW_DEBUG_WX("failed setting power mode.\n");
9716
mutex_unlock(&priv->mutex);
9719
IPW_DEBUG_WX("SET Power Management Mode -> off\n");
9720
mutex_unlock(&priv->mutex);
9724
switch (wrqu->power.flags & IW_POWER_MODE) {
9725
case IW_POWER_ON: /* If not specified */
9726
case IW_POWER_MODE: /* If set all mask */
9727
case IW_POWER_ALL_R: /* If explicitely state all */
9729
default: /* Otherwise we don't support it */
9730
IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9732
mutex_unlock(&priv->mutex);
9736
/* If the user hasn't specified a power management mode yet, default
9738
if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
9739
priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
9741
priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9742
err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9744
IPW_DEBUG_WX("failed setting power mode.\n");
9745
mutex_unlock(&priv->mutex);
9749
IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
9750
mutex_unlock(&priv->mutex);
9754
static int ipw_wx_get_power(struct net_device *dev,
9755
struct iw_request_info *info,
9756
union iwreq_data *wrqu, char *extra)
9758
struct ipw_priv *priv = ieee80211_priv(dev);
9759
mutex_lock(&priv->mutex);
9760
if (!(priv->power_mode & IPW_POWER_ENABLED))
9761
wrqu->power.disabled = 1;
9763
wrqu->power.disabled = 0;
9765
mutex_unlock(&priv->mutex);
9766
IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
9771
static int ipw_wx_set_powermode(struct net_device *dev,
9772
struct iw_request_info *info,
9773
union iwreq_data *wrqu, char *extra)
9775
struct ipw_priv *priv = ieee80211_priv(dev);
9776
int mode = *(int *)extra;
9778
mutex_lock(&priv->mutex);
9779
if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9780
mode = IPW_POWER_AC;
9781
priv->power_mode = mode;
9783
priv->power_mode = IPW_POWER_ENABLED | mode;
9786
if (priv->power_mode != mode) {
9787
err = ipw_send_power_mode(priv, mode);
9790
IPW_DEBUG_WX("failed setting power mode.\n");
9791
mutex_unlock(&priv->mutex);
9795
mutex_unlock(&priv->mutex);
9799
#define MAX_WX_STRING 80
9800
static int ipw_wx_get_powermode(struct net_device *dev,
9801
struct iw_request_info *info,
9802
union iwreq_data *wrqu, char *extra)
9804
struct ipw_priv *priv = ieee80211_priv(dev);
9805
int level = IPW_POWER_LEVEL(priv->power_mode);
9808
p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9812
p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9814
case IPW_POWER_BATTERY:
9815
p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9818
p += snprintf(p, MAX_WX_STRING - (p - extra),
9819
"(Timeout %dms, Period %dms)",
9820
timeout_duration[level - 1] / 1000,
9821
period_duration[level - 1] / 1000);
9824
if (!(priv->power_mode & IPW_POWER_ENABLED))
9825
p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
9827
wrqu->data.length = p - extra + 1;
9832
static int ipw_wx_set_wireless_mode(struct net_device *dev,
9833
struct iw_request_info *info,
9834
union iwreq_data *wrqu, char *extra)
9836
struct ipw_priv *priv = ieee80211_priv(dev);
9837
int mode = *(int *)extra;
9838
u8 band = 0, modulation = 0;
9840
if (mode == 0 || mode & ~IEEE_MODE_MASK) {
9841
IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
9844
mutex_lock(&priv->mutex);
9845
if (priv->adapter == IPW_2915ABG) {
9846
priv->ieee->abg_true = 1;
9847
if (mode & IEEE_A) {
9848
band |= IEEE80211_52GHZ_BAND;
9849
modulation |= IEEE80211_OFDM_MODULATION;
9851
priv->ieee->abg_true = 0;
9853
if (mode & IEEE_A) {
9854
IPW_WARNING("Attempt to set 2200BG into "
9856
mutex_unlock(&priv->mutex);
9860
priv->ieee->abg_true = 0;
9863
if (mode & IEEE_B) {
9864
band |= IEEE80211_24GHZ_BAND;
9865
modulation |= IEEE80211_CCK_MODULATION;
9867
priv->ieee->abg_true = 0;
9869
if (mode & IEEE_G) {
9870
band |= IEEE80211_24GHZ_BAND;
9871
modulation |= IEEE80211_OFDM_MODULATION;
9873
priv->ieee->abg_true = 0;
9875
priv->ieee->mode = mode;
9876
priv->ieee->freq_band = band;
9877
priv->ieee->modulation = modulation;
9878
init_supported_rates(priv, &priv->rates);
9880
/* Network configuration changed -- force [re]association */
9881
IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9882
if (!ipw_disassociate(priv)) {
9883
ipw_send_supported_rates(priv, &priv->rates);
9884
ipw_associate(priv);
9887
/* Update the band LEDs */
9888
ipw_led_band_on(priv);
9890
IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
9891
mode & IEEE_A ? 'a' : '.',
9892
mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
9893
mutex_unlock(&priv->mutex);
9897
static int ipw_wx_get_wireless_mode(struct net_device *dev,
9898
struct iw_request_info *info,
9899
union iwreq_data *wrqu, char *extra)
9901
struct ipw_priv *priv = ieee80211_priv(dev);
9902
mutex_lock(&priv->mutex);
9903
switch (priv->ieee->mode) {
9905
strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9908
strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9910
case IEEE_A | IEEE_B:
9911
strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9914
strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9916
case IEEE_A | IEEE_G:
9917
strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9919
case IEEE_B | IEEE_G:
9920
strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9922
case IEEE_A | IEEE_B | IEEE_G:
9923
strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9926
strncpy(extra, "unknown", MAX_WX_STRING);
9930
IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9932
wrqu->data.length = strlen(extra) + 1;
9933
mutex_unlock(&priv->mutex);
9938
static int ipw_wx_set_preamble(struct net_device *dev,
9939
struct iw_request_info *info,
9940
union iwreq_data *wrqu, char *extra)
9942
struct ipw_priv *priv = ieee80211_priv(dev);
9943
int mode = *(int *)extra;
9944
mutex_lock(&priv->mutex);
9945
/* Switching from SHORT -> LONG requires a disassociation */
9947
if (!(priv->config & CFG_PREAMBLE_LONG)) {
9948
priv->config |= CFG_PREAMBLE_LONG;
9950
/* Network configuration changed -- force [re]association */
9952
("[re]association triggered due to preamble change.\n");
9953
if (!ipw_disassociate(priv))
9954
ipw_associate(priv);
9960
priv->config &= ~CFG_PREAMBLE_LONG;
9963
mutex_unlock(&priv->mutex);
9967
mutex_unlock(&priv->mutex);
9971
static int ipw_wx_get_preamble(struct net_device *dev,
9972
struct iw_request_info *info,
9973
union iwreq_data *wrqu, char *extra)
9975
struct ipw_priv *priv = ieee80211_priv(dev);
9976
mutex_lock(&priv->mutex);
9977
if (priv->config & CFG_PREAMBLE_LONG)
9978
snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9980
snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
9981
mutex_unlock(&priv->mutex);
9985
#ifdef CONFIG_IPW2200_MONITOR
9986
static int ipw_wx_set_monitor(struct net_device *dev,
9987
struct iw_request_info *info,
9988
union iwreq_data *wrqu, char *extra)
9990
struct ipw_priv *priv = ieee80211_priv(dev);
9991
int *parms = (int *)extra;
9992
int enable = (parms[0] > 0);
9993
mutex_lock(&priv->mutex);
9994
IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
9996
if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9997
#ifdef CONFIG_IPW2200_RADIOTAP
9998
priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
10000
priv->net_dev->type = ARPHRD_IEEE80211;
10002
queue_work(priv->workqueue, &priv->adapter_restart);
10005
ipw_set_channel(priv, parms[1]);
10007
if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
10008
mutex_unlock(&priv->mutex);
10011
priv->net_dev->type = ARPHRD_ETHER;
10012
queue_work(priv->workqueue, &priv->adapter_restart);
10014
mutex_unlock(&priv->mutex);
10018
#endif /* CONFIG_IPW2200_MONITOR */
10020
static int ipw_wx_reset(struct net_device *dev,
10021
struct iw_request_info *info,
10022
union iwreq_data *wrqu, char *extra)
10024
struct ipw_priv *priv = ieee80211_priv(dev);
10025
IPW_DEBUG_WX("RESET\n");
10026
queue_work(priv->workqueue, &priv->adapter_restart);
10030
static int ipw_wx_sw_reset(struct net_device *dev,
10031
struct iw_request_info *info,
10032
union iwreq_data *wrqu, char *extra)
10034
struct ipw_priv *priv = ieee80211_priv(dev);
10035
union iwreq_data wrqu_sec = {
10037
.flags = IW_ENCODE_DISABLED,
10042
IPW_DEBUG_WX("SW_RESET\n");
10044
mutex_lock(&priv->mutex);
10046
ret = ipw_sw_reset(priv, 2);
10049
ipw_adapter_restart(priv);
10052
/* The SW reset bit might have been toggled on by the 'disable'
10053
* module parameter, so take appropriate action */
10054
ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
10056
mutex_unlock(&priv->mutex);
10057
ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
10058
mutex_lock(&priv->mutex);
10060
if (!(priv->status & STATUS_RF_KILL_MASK)) {
10061
/* Configuration likely changed -- force [re]association */
10062
IPW_DEBUG_ASSOC("[re]association triggered due to sw "
10064
if (!ipw_disassociate(priv))
10065
ipw_associate(priv);
10068
mutex_unlock(&priv->mutex);
10073
/* Rebase the WE IOCTLs to zero for the handler array */
10074
#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
10075
static iw_handler ipw_wx_handlers[] = {
10076
IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
10077
IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
10078
IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
10079
IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
10080
IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
10081
IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens,
10082
IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens,
10083
IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
10084
IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
10085
IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
10086
IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
10087
IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
10088
IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
10089
IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
10090
IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
10091
IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
10092
IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
10093
IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
10094
IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
10095
IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
10096
IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
10097
IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
10098
IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
10099
IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
10100
IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
10101
IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
10102
IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
10103
IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
10104
IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
10105
IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
10106
IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
10107
IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
10108
IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
10109
IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
10110
#if WIRELESS_EXT > 17
10111
IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
10112
IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
10113
IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
10114
IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
10115
IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
10116
IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
10117
IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
10122
IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
10123
IPW_PRIV_GET_POWER,
10126
IPW_PRIV_SET_PREAMBLE,
10127
IPW_PRIV_GET_PREAMBLE,
10130
#ifdef CONFIG_IPW2200_MONITOR
10131
IPW_PRIV_SET_MONITOR,
10135
static struct iw_priv_args ipw_priv_args[] = {
10137
.cmd = IPW_PRIV_SET_POWER,
10138
.set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10139
.name = "set_power"},
10141
.cmd = IPW_PRIV_GET_POWER,
10142
.get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10143
.name = "get_power"},
10145
.cmd = IPW_PRIV_SET_MODE,
10146
.set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10147
.name = "set_mode"},
10149
.cmd = IPW_PRIV_GET_MODE,
10150
.get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10151
.name = "get_mode"},
10153
.cmd = IPW_PRIV_SET_PREAMBLE,
10154
.set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10155
.name = "set_preamble"},
10157
.cmd = IPW_PRIV_GET_PREAMBLE,
10158
.get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
10159
.name = "get_preamble"},
10162
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
10165
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
10166
#ifdef CONFIG_IPW2200_MONITOR
10168
IPW_PRIV_SET_MONITOR,
10169
IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
10170
#endif /* CONFIG_IPW2200_MONITOR */
10173
static iw_handler ipw_priv_handler[] = {
10174
ipw_wx_set_powermode,
10175
ipw_wx_get_powermode,
10176
ipw_wx_set_wireless_mode,
10177
ipw_wx_get_wireless_mode,
10178
ipw_wx_set_preamble,
10179
ipw_wx_get_preamble,
10182
#ifdef CONFIG_IPW2200_MONITOR
10183
ipw_wx_set_monitor,
10187
static struct iw_handler_def ipw_wx_handler_def = {
10188
.standard = ipw_wx_handlers,
10189
.num_standard = ARRAY_SIZE(ipw_wx_handlers),
10190
.num_private = ARRAY_SIZE(ipw_priv_handler),
10191
.num_private_args = ARRAY_SIZE(ipw_priv_args),
10192
.private = ipw_priv_handler,
10193
.private_args = ipw_priv_args,
10194
#if WIRELESS_EXT >= 17
10195
.get_wireless_stats = ipw_get_wireless_stats,
10200
* Get wireless statistics.
10201
* Called by /proc/net/wireless
10202
* Also called by SIOCGIWSTATS
10204
static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
10206
struct ipw_priv *priv = ieee80211_priv(dev);
10207
struct iw_statistics *wstats;
10209
wstats = &priv->wstats;
10211
/* if hw is disabled, then ipw_get_ordinal() can't be called.
10212
* netdev->get_wireless_stats seems to be called before fw is
10213
* initialized. STATUS_ASSOCIATED will only be set if the hw is up
10214
* and associated; if not associcated, the values are all meaningless
10215
* anyway, so set them all to NULL and INVALID */
10216
if (!(priv->status & STATUS_ASSOCIATED)) {
10217
wstats->miss.beacon = 0;
10218
wstats->discard.retries = 0;
10219
wstats->qual.qual = 0;
10220
wstats->qual.level = 0;
10221
wstats->qual.noise = 0;
10222
wstats->qual.updated = 7;
10223
wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
10224
IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
10228
wstats->qual.qual = priv->quality;
10229
wstats->qual.level = priv->exp_avg_rssi;
10230
wstats->qual.noise = priv->exp_avg_noise;
10231
wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
10232
IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
10234
wstats->miss.beacon = average_value(&priv->average_missed_beacons);
10235
wstats->discard.retries = priv->last_tx_failures;
10236
wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
10238
/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
10239
goto fail_get_ordinal;
10240
wstats->discard.retries += tx_retry; */
10245
/* net device stuff */
10247
static void init_sys_config(struct ipw_sys_config *sys_config)
10249
memset(sys_config, 0, sizeof(struct ipw_sys_config));
10250
sys_config->bt_coexistence = 0;
10251
sys_config->answer_broadcast_ssid_probe = 0;
10252
sys_config->accept_all_data_frames = 0;
10253
sys_config->accept_non_directed_frames = 1;
10254
sys_config->exclude_unicast_unencrypted = 0;
10255
sys_config->disable_unicast_decryption = 1;
10256
sys_config->exclude_multicast_unencrypted = 0;
10257
sys_config->disable_multicast_decryption = 1;
10258
if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
10259
antenna = CFG_SYS_ANTENNA_BOTH;
10260
sys_config->antenna_diversity = antenna;
10261
sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
10262
sys_config->dot11g_auto_detection = 0;
10263
sys_config->enable_cts_to_self = 0;
10264
sys_config->bt_coexist_collision_thr = 0;
10265
sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */
10266
sys_config->silence_threshold = 0x1e;
10269
static int ipw_net_open(struct net_device *dev)
10271
struct ipw_priv *priv = ieee80211_priv(dev);
10272
IPW_DEBUG_INFO("dev->open\n");
10273
/* we should be verifying the device is ready to be opened */
10274
mutex_lock(&priv->mutex);
10275
if (!(priv->status & STATUS_RF_KILL_MASK) &&
10276
(priv->status & STATUS_ASSOCIATED))
10277
netif_start_queue(dev);
10278
mutex_unlock(&priv->mutex);
10282
static int ipw_net_stop(struct net_device *dev)
10284
IPW_DEBUG_INFO("dev->close\n");
10285
netif_stop_queue(dev);
10292
modify to send one tfd per fragment instead of using chunking. otherwise
10293
we need to heavily modify the ieee80211_skb_to_txb.
10296
static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
10299
struct ieee80211_hdr_3addrqos *hdr = (struct ieee80211_hdr_3addrqos *)
10300
txb->fragments[0]->data;
10302
struct tfd_frame *tfd;
10303
#ifdef CONFIG_IPW2200_QOS
10304
int tx_id = ipw_get_tx_queue_number(priv, pri);
10305
struct clx2_tx_queue *txq = &priv->txq[tx_id];
10307
struct clx2_tx_queue *txq = &priv->txq[0];
10309
struct clx2_queue *q = &txq->q;
10310
u8 id, hdr_len, unicast;
10311
u16 remaining_bytes;
10314
hdr_len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
10315
switch (priv->ieee->iw_mode) {
10316
case IW_MODE_ADHOC:
10317
unicast = !ipw_is_multicast_ether_addr(hdr->addr1);
10318
id = ipw_find_station(priv, hdr->addr1);
10319
if (id == IPW_INVALID_STATION) {
10320
id = ipw_add_station(priv, hdr->addr1);
10321
if (id == IPW_INVALID_STATION) {
10322
IPW_WARNING("Attempt to send data to "
10323
"invalid cell: " MAC_FMT "\n",
10324
MAC_ARG(hdr->addr1));
10330
case IW_MODE_INFRA:
10332
unicast = !ipw_is_multicast_ether_addr(hdr->addr3);
10337
tfd = &txq->bd[q->first_empty];
10338
txq->txb[q->first_empty] = txb;
10339
memset(tfd, 0, sizeof(*tfd));
10340
tfd->u.data.station_number = id;
10342
tfd->control_flags.message_type = TX_FRAME_TYPE;
10343
tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10345
tfd->u.data.cmd_id = DINO_CMD_TX;
10346
tfd->u.data.len = cpu_to_le16(txb->payload_size);
10347
remaining_bytes = txb->payload_size;
10349
if (priv->assoc_request.ieee_mode == IPW_B_MODE)
10350
tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
10352
tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
10354
if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10355
tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
10357
fc = le16_to_cpu(hdr->frame_ctl);
10358
hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
10360
memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10362
if (likely(unicast))
10363
tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10365
if (txb->encrypted && !priv->ieee->host_encrypt) {
10366
switch (priv->ieee->sec.level) {
10368
tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10369
cpu_to_le16(IEEE80211_FCTL_PROTECTED);
10370
/* XXX: ACK flag must be set for CCMP even if it
10371
* is a multicast/broadcast packet, because CCMP
10372
* group communication encrypted by GTK is
10373
* actually done by the AP. */
10375
tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10377
tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10378
tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10379
tfd->u.data.key_index = 0;
10380
tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10383
tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10384
cpu_to_le16(IEEE80211_FCTL_PROTECTED);
10385
tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10386
tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10387
tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10390
tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10391
cpu_to_le16(IEEE80211_FCTL_PROTECTED);
10392
tfd->u.data.key_index = priv->ieee->tx_keyidx;
10393
if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
10395
tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10397
tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10402
printk(KERN_ERR "Unknow security level %d\n",
10403
priv->ieee->sec.level);
10407
/* No hardware encryption */
10408
tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10410
#ifdef CONFIG_IPW2200_QOS
10411
if (fc & IEEE80211_STYPE_QOS_DATA)
10412
ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
10413
#endif /* CONFIG_IPW2200_QOS */
10416
tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10418
IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10419
txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10420
for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10421
IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10422
i, le32_to_cpu(tfd->u.data.num_chunks),
10423
txb->fragments[i]->len - hdr_len);
10424
IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
10425
i, tfd->u.data.num_chunks,
10426
txb->fragments[i]->len - hdr_len);
10427
printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
10428
txb->fragments[i]->len - hdr_len);
10430
tfd->u.data.chunk_ptr[i] =
10431
cpu_to_le32(pci_map_single
10433
txb->fragments[i]->data + hdr_len,
10434
txb->fragments[i]->len - hdr_len,
10435
PCI_DMA_TODEVICE));
10436
tfd->u.data.chunk_len[i] =
10437
cpu_to_le16(txb->fragments[i]->len - hdr_len);
10440
if (i != txb->nr_frags) {
10441
struct sk_buff *skb;
10442
u16 remaining_bytes = 0;
10445
for (j = i; j < txb->nr_frags; j++)
10446
remaining_bytes += txb->fragments[j]->len - hdr_len;
10448
printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10450
skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10452
tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
10453
for (j = i; j < txb->nr_frags; j++) {
10454
int size = txb->fragments[j]->len - hdr_len;
10456
printk(KERN_INFO "Adding frag %d %d...\n",
10458
memcpy(skb_put(skb, size),
10459
txb->fragments[j]->data + hdr_len, size);
10461
dev_kfree_skb_any(txb->fragments[i]);
10462
txb->fragments[i] = skb;
10463
tfd->u.data.chunk_ptr[i] =
10464
cpu_to_le32(pci_map_single
10465
(priv->pci_dev, skb->data,
10466
tfd->u.data.chunk_len[i],
10467
PCI_DMA_TODEVICE));
10469
tfd->u.data.num_chunks =
10470
cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
10476
q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10477
ipw_write32(priv, q->reg_w, q->first_empty);
10479
if (ipw_queue_space(q) < q->high_mark)
10480
netif_stop_queue(priv->net_dev);
10482
return NETDEV_TX_OK;
10485
IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
10486
ieee80211_txb_free(txb);
10487
return NETDEV_TX_OK;
10490
static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10492
struct ipw_priv *priv = ieee80211_priv(dev);
10493
#ifdef CONFIG_IPW2200_QOS
10494
int tx_id = ipw_get_tx_queue_number(priv, pri);
10495
struct clx2_tx_queue *txq = &priv->txq[tx_id];
10497
struct clx2_tx_queue *txq = &priv->txq[0];
10498
#endif /* CONFIG_IPW2200_QOS */
10500
if (ipw_queue_space(&txq->q) < txq->q.high_mark)
10506
#ifdef CONFIG_IPW2200_PROMISCUOUS
10507
static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
10508
struct ieee80211_txb *txb)
10510
struct ieee80211_rx_stats dummystats;
10511
struct ieee80211_hdr *hdr;
10513
u16 filter = priv->prom_priv->filter;
10516
if (filter & IPW_PROM_NO_TX)
10519
memset(&dummystats, 0, sizeof(dummystats));
10521
/* Filtering of fragment chains is done agains the first fragment */
10522
hdr = (void *)txb->fragments[0]->data;
10523
if (ieee80211_is_management(le16_to_cpu(hdr->frame_ctl))) {
10524
if (filter & IPW_PROM_NO_MGMT)
10526
if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10528
} else if (ieee80211_is_control(le16_to_cpu(hdr->frame_ctl))) {
10529
if (filter & IPW_PROM_NO_CTL)
10531
if (filter & IPW_PROM_CTL_HEADER_ONLY)
10533
} else if (ieee80211_is_data(le16_to_cpu(hdr->frame_ctl))) {
10534
if (filter & IPW_PROM_NO_DATA)
10536
if (filter & IPW_PROM_DATA_HEADER_ONLY)
10540
for(n=0; n<txb->nr_frags; ++n) {
10541
struct sk_buff *src = txb->fragments[n];
10542
struct sk_buff *dst;
10543
struct ieee80211_radiotap_header *rt_hdr;
10547
hdr = (void *)src->data;
10548
len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
10553
len + IEEE80211_RADIOTAP_HDRLEN, GFP_ATOMIC);
10554
if (!dst) continue;
10556
rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10558
rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10559
rt_hdr->it_pad = 0;
10560
rt_hdr->it_present = 0; /* after all, it's just an idea */
10561
rt_hdr->it_present |= (1 << IEEE80211_RADIOTAP_CHANNEL);
10563
*(u16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
10564
ieee80211chan2mhz(priv->channel));
10565
if (priv->channel > 14) /* 802.11a */
10566
*(u16*)skb_put(dst, sizeof(u16)) =
10567
cpu_to_le16(IEEE80211_CHAN_OFDM |
10568
IEEE80211_CHAN_5GHZ);
10569
else if (priv->ieee->mode == IEEE_B) /* 802.11b */
10570
*(u16*)skb_put(dst, sizeof(u16)) =
10571
cpu_to_le16(IEEE80211_CHAN_CCK |
10572
IEEE80211_CHAN_2GHZ);
10574
*(u16*)skb_put(dst, sizeof(u16)) =
10575
cpu_to_le16(IEEE80211_CHAN_OFDM |
10576
IEEE80211_CHAN_2GHZ);
10578
rt_hdr->it_len = dst->len;
10580
memcpy(skb_put(dst, len), src->data, len);
10582
if (!ieee80211_rx(priv->prom_priv->ieee, dst, &dummystats))
10583
dev_kfree_skb_any(dst);
10588
static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
10589
struct net_device *dev, int pri)
10591
struct ipw_priv *priv = ieee80211_priv(dev);
10592
unsigned long flags;
10595
IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
10596
spin_lock_irqsave(&priv->lock, flags);
10598
if (!(priv->status & STATUS_ASSOCIATED)) {
10599
IPW_DEBUG_INFO("Tx attempt while not associated.\n");
10600
priv->ieee->stats.tx_carrier_errors++;
10601
netif_stop_queue(dev);
10605
#ifdef CONFIG_IPW2200_PROMISCUOUS
10606
if (rtap_iface && netif_running(priv->prom_net_dev))
10607
ipw_handle_promiscuous_tx(priv, txb);
10610
ret = ipw_tx_skb(priv, txb, pri);
10611
if (ret == NETDEV_TX_OK)
10612
__ipw_led_activity_on(priv);
10613
spin_unlock_irqrestore(&priv->lock, flags);
10618
spin_unlock_irqrestore(&priv->lock, flags);
10622
static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
10624
struct ipw_priv *priv = ieee80211_priv(dev);
10626
priv->ieee->stats.tx_packets = priv->tx_packets;
10627
priv->ieee->stats.rx_packets = priv->rx_packets;
10628
return &priv->ieee->stats;
10631
static void ipw_net_set_multicast_list(struct net_device *dev)
10636
static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10638
struct ipw_priv *priv = ieee80211_priv(dev);
10639
struct sockaddr *addr = p;
10640
if (!is_valid_ether_addr(addr->sa_data))
10641
return -EADDRNOTAVAIL;
10642
mutex_lock(&priv->mutex);
10643
priv->config |= CFG_CUSTOM_MAC;
10644
memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
10645
printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
10646
priv->net_dev->name, MAC_ARG(priv->mac_addr));
10647
queue_work(priv->workqueue, &priv->adapter_restart);
10648
mutex_unlock(&priv->mutex);
10652
static void ipw_ethtool_get_drvinfo(struct net_device *dev,
10653
struct ethtool_drvinfo *info)
10655
struct ipw_priv *p = ieee80211_priv(dev);
10660
strcpy(info->driver, DRV_NAME);
10661
strcpy(info->version, DRV_VERSION);
10663
len = sizeof(vers);
10664
ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10665
len = sizeof(date);
10666
ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10668
snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
10670
strcpy(info->bus_info, pci_name(p->pci_dev));
10671
info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
10674
static u32 ipw_ethtool_get_link(struct net_device *dev)
10676
struct ipw_priv *priv = ieee80211_priv(dev);
10677
return (priv->status & STATUS_ASSOCIATED) != 0;
10680
static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10682
return IPW_EEPROM_IMAGE_SIZE;
10685
static int ipw_ethtool_get_eeprom(struct net_device *dev,
10686
struct ethtool_eeprom *eeprom, u8 * bytes)
10688
struct ipw_priv *p = ieee80211_priv(dev);
10690
if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
10692
mutex_lock(&p->mutex);
10693
memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
10694
mutex_unlock(&p->mutex);
10698
static int ipw_ethtool_set_eeprom(struct net_device *dev,
10699
struct ethtool_eeprom *eeprom, u8 * bytes)
10701
struct ipw_priv *p = ieee80211_priv(dev);
10704
if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
10706
mutex_lock(&p->mutex);
10707
memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
10708
for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10709
ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
10710
mutex_unlock(&p->mutex);
10714
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
10715
static struct ethtool_ops ipw_ethtool_ops = {
10717
static const struct ethtool_ops ipw_ethtool_ops = {
10719
.get_link = ipw_ethtool_get_link,
10720
.get_drvinfo = ipw_ethtool_get_drvinfo,
10721
.get_eeprom_len = ipw_ethtool_get_eeprom_len,
10722
.get_eeprom = ipw_ethtool_get_eeprom,
10723
.set_eeprom = ipw_ethtool_set_eeprom,
10726
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
10727
static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
10729
static irqreturn_t ipw_isr(int irq, void *data)
10732
struct ipw_priv *priv = data;
10733
u32 inta, inta_mask;
10738
spin_lock(&priv->irq_lock);
10740
if (!(priv->status & STATUS_INT_ENABLED)) {
10745
inta = ipw_read32(priv, IPW_INTA_RW);
10746
inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
10748
if (inta == 0xFFFFFFFF) {
10749
/* Hardware disappeared */
10750
IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10754
if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
10755
/* Shared interrupt */
10759
/* tell the device to stop sending interrupts */
10760
__ipw_disable_interrupts(priv);
10762
/* ack current interrupts */
10763
inta &= (IPW_INTA_MASK_ALL & inta_mask);
10764
ipw_write32(priv, IPW_INTA_RW, inta);
10766
/* Cache INTA value for our tasklet */
10767
priv->isr_inta = inta;
10769
tasklet_schedule(&priv->irq_tasklet);
10771
spin_unlock(&priv->irq_lock);
10773
return IRQ_HANDLED;
10775
spin_unlock(&priv->irq_lock);
10779
static void ipw_rf_kill(void *adapter)
10781
struct ipw_priv *priv = adapter;
10782
unsigned long flags;
10784
spin_lock_irqsave(&priv->lock, flags);
10786
if (rf_kill_active(priv)) {
10787
IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10788
if (priv->workqueue)
10789
queue_delayed_work(priv->workqueue,
10790
&priv->rf_kill, 2 * HZ);
10794
/* RF Kill is now disabled, so bring the device back up */
10796
if (!(priv->status & STATUS_RF_KILL_MASK)) {
10797
IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10800
/* we can not do an adapter restart while inside an irq lock */
10801
queue_work(priv->workqueue, &priv->adapter_restart);
10803
IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10807
spin_unlock_irqrestore(&priv->lock, flags);
10810
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
10811
static void ipw_bg_rf_kill(void *work)
10813
struct ipw_priv *priv = work;
10815
static void ipw_bg_rf_kill(struct work_struct *work)
10817
struct ipw_priv *priv =
10818
container_of(work, struct ipw_priv, rf_kill.work);
10820
mutex_lock(&priv->mutex);
10822
mutex_unlock(&priv->mutex);
10825
static void ipw_link_up(struct ipw_priv *priv)
10827
priv->last_seq_num = -1;
10828
priv->last_frag_num = -1;
10829
priv->last_packet_time = 0;
10831
netif_carrier_on(priv->net_dev);
10832
if (netif_queue_stopped(priv->net_dev)) {
10833
IPW_DEBUG_NOTIF("waking queue\n");
10834
netif_wake_queue(priv->net_dev);
10836
IPW_DEBUG_NOTIF("starting queue\n");
10837
netif_start_queue(priv->net_dev);
10840
cancel_delayed_work(&priv->request_scan);
10841
ipw_reset_stats(priv);
10842
/* Ensure the rate is updated immediately */
10843
priv->last_rate = ipw_get_current_rate(priv);
10844
ipw_gather_stats(priv);
10845
ipw_led_link_up(priv);
10846
notify_wx_assoc_event(priv);
10848
if (priv->config & CFG_BACKGROUND_SCAN)
10849
queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10852
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
10853
static void ipw_bg_link_up(void *work)
10855
struct ipw_priv *priv = work;
10857
static void ipw_bg_link_up(struct work_struct *work)
10859
struct ipw_priv *priv =
10860
container_of(work, struct ipw_priv, link_up);
10862
mutex_lock(&priv->mutex);
10864
mutex_unlock(&priv->mutex);
10867
static void ipw_link_down(struct ipw_priv *priv)
10869
ipw_led_link_down(priv);
10870
netif_carrier_off(priv->net_dev);
10871
netif_stop_queue(priv->net_dev);
10872
notify_wx_assoc_event(priv);
10874
/* Cancel any queued work ... */
10875
cancel_delayed_work(&priv->request_scan);
10876
cancel_delayed_work(&priv->adhoc_check);
10877
cancel_delayed_work(&priv->gather_stats);
10879
ipw_reset_stats(priv);
10881
if (!(priv->status & STATUS_EXIT_PENDING)) {
10882
/* Queue up another scan... */
10883
queue_delayed_work(priv->workqueue, &priv->request_scan, 0);
10887
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
10888
static void ipw_bg_link_down(void *work)
10890
struct ipw_priv *priv = work;
10892
static void ipw_bg_link_down(struct work_struct *work)
10894
struct ipw_priv *priv =
10895
container_of(work, struct ipw_priv, link_down);
10897
mutex_lock(&priv->mutex);
10898
ipw_link_down(priv);
10899
mutex_unlock(&priv->mutex);
10902
static int ipw_setup_deferred_work(struct ipw_priv *priv)
10906
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) && defined (PF_SYNCTHREAD)
10907
priv->workqueue = create_workqueue(DRV_NAME, 0);
10909
priv->workqueue = create_workqueue(DRV_NAME);
10911
init_waitqueue_head(&priv->wait_command_queue);
10912
init_waitqueue_head(&priv->wait_state);
10914
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
10915
INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10916
INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10917
INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
10918
INIT_WORK(&priv->system_config, ipw_system_config, priv);
10919
INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10920
INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10921
INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10922
INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10923
INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
10924
INIT_WORK(&priv->request_scan,
10925
(void (*)(void *))ipw_request_scan, priv);
10926
INIT_WORK(&priv->request_passive_scan,
10927
(void (*)(void *))ipw_request_passive_scan, priv);
10928
INIT_WORK(&priv->gather_stats,
10929
(void (*)(void *))ipw_bg_gather_stats, priv);
10930
INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10931
INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10932
INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10933
INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10934
INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10935
INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
10937
INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
10939
INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10941
INIT_WORK(&priv->merge_networks,
10942
(void (*)(void *))ipw_merge_adhoc_network, priv);
10944
# ifdef CONFIG_IPW2200_QOS
10945
INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10947
# endif /* CONFIG_IPW2200_QOS */
10950
INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check);
10951
INIT_WORK(&priv->associate, ipw_bg_associate);
10952
INIT_WORK(&priv->disassociate, ipw_bg_disassociate);
10953
INIT_WORK(&priv->system_config, ipw_system_config);
10954
INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish);
10955
INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart);
10956
INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill);
10957
INIT_WORK(&priv->up, ipw_bg_up);
10958
INIT_WORK(&priv->down, ipw_bg_down);
10959
INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan);
10960
INIT_WORK(&priv->request_passive_scan, ipw_request_passive_scan);
10961
INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats);
10962
INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan);
10963
INIT_WORK(&priv->roam, ipw_bg_roam);
10964
INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check);
10965
INIT_WORK(&priv->link_up, ipw_bg_link_up);
10966
INIT_WORK(&priv->link_down, ipw_bg_link_down);
10967
INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on);
10968
INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off);
10969
INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off);
10970
INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network);
10972
# ifdef CONFIG_IPW2200_QOS
10973
INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate);
10974
# endif /* CONFIG_IPW2200_QOS */
10976
#endif /* LINUX_VERSION_CODE < 2.6.20 */
10978
tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10979
ipw_irq_tasklet, (unsigned long)priv);
10984
static void shim__set_security(struct net_device *dev,
10985
struct ieee80211_security *sec)
10987
struct ipw_priv *priv = ieee80211_priv(dev);
10989
for (i = 0; i < 4; i++) {
10990
if (sec->flags & (1 << i)) {
10991
priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
10992
priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
10993
if (sec->key_sizes[i] == 0)
10994
priv->ieee->sec.flags &= ~(1 << i);
10996
memcpy(priv->ieee->sec.keys[i], sec->keys[i],
10997
sec->key_sizes[i]);
10998
priv->ieee->sec.flags |= (1 << i);
11000
priv->status |= STATUS_SECURITY_UPDATED;
11001
} else if (sec->level != SEC_LEVEL_1)
11002
priv->ieee->sec.flags &= ~(1 << i);
11005
if (sec->flags & SEC_ACTIVE_KEY) {
11006
if (sec->active_key <= 3) {
11007
priv->ieee->sec.active_key = sec->active_key;
11008
priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
11010
priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
11011
priv->status |= STATUS_SECURITY_UPDATED;
11013
priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
11015
if ((sec->flags & SEC_AUTH_MODE) &&
11016
(priv->ieee->sec.auth_mode != sec->auth_mode)) {
11017
priv->ieee->sec.auth_mode = sec->auth_mode;
11018
priv->ieee->sec.flags |= SEC_AUTH_MODE;
11019
if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
11020
priv->capability |= CAP_SHARED_KEY;
11022
priv->capability &= ~CAP_SHARED_KEY;
11023
priv->status |= STATUS_SECURITY_UPDATED;
11026
if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
11027
priv->ieee->sec.flags |= SEC_ENABLED;
11028
priv->ieee->sec.enabled = sec->enabled;
11029
priv->status |= STATUS_SECURITY_UPDATED;
11031
priv->capability |= CAP_PRIVACY_ON;
11033
priv->capability &= ~CAP_PRIVACY_ON;
11036
if (sec->flags & SEC_ENCRYPT)
11037
priv->ieee->sec.encrypt = sec->encrypt;
11039
if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
11040
priv->ieee->sec.level = sec->level;
11041
priv->ieee->sec.flags |= SEC_LEVEL;
11042
priv->status |= STATUS_SECURITY_UPDATED;
11045
if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
11046
ipw_set_hwcrypto_keys(priv);
11048
/* To match current functionality of ipw2100 (which works well w/
11049
* various supplicants, we don't force a disassociate if the
11050
* privacy capability changes ... */
11052
if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
11053
(((priv->assoc_request.capability &
11054
WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
11055
(!(priv->assoc_request.capability &
11056
WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
11057
IPW_DEBUG_ASSOC("Disassociating due to capability "
11059
ipw_disassociate(priv);
11064
static int init_supported_rates(struct ipw_priv *priv,
11065
struct ipw_supported_rates *rates)
11067
/* TODO: Mask out rates based on priv->rates_mask */
11069
memset(rates, 0, sizeof(*rates));
11070
/* configure supported rates */
11071
switch (priv->ieee->freq_band) {
11072
case IEEE80211_52GHZ_BAND:
11073
rates->ieee_mode = IPW_A_MODE;
11074
rates->purpose = IPW_RATE_CAPABILITIES;
11075
ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
11076
IEEE80211_OFDM_DEFAULT_RATES_MASK);
11079
default: /* Mixed or 2.4Ghz */
11080
rates->ieee_mode = IPW_G_MODE;
11081
rates->purpose = IPW_RATE_CAPABILITIES;
11082
ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
11083
IEEE80211_CCK_DEFAULT_RATES_MASK);
11084
if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
11085
ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
11086
IEEE80211_OFDM_DEFAULT_RATES_MASK);
11094
static int ipw_config(struct ipw_priv *priv)
11096
/* This is only called from ipw_up, which resets/reloads the firmware
11097
so, we don't need to first disable the card before we configure
11099
if (ipw_set_tx_power(priv))
11102
/* initialize adapter address */
11103
if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
11106
/* set basic system config settings */
11107
init_sys_config(&priv->sys_config);
11109
/* Support Bluetooth if we have BT h/w on board, and user wants to.
11110
* Does not support BT priority yet (don't abort or defer our Tx) */
11112
unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
11114
if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
11115
priv->sys_config.bt_coexistence
11116
|= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
11117
if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
11118
priv->sys_config.bt_coexistence
11119
|= CFG_BT_COEXISTENCE_OOB;
11122
#ifdef CONFIG_IPW2200_PROMISCUOUS
11123
if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
11124
priv->sys_config.accept_all_data_frames = 1;
11125
priv->sys_config.accept_non_directed_frames = 1;
11126
priv->sys_config.accept_all_mgmt_bcpr = 1;
11127
priv->sys_config.accept_all_mgmt_frames = 1;
11131
if (priv->ieee->iw_mode == IW_MODE_ADHOC)
11132
priv->sys_config.answer_broadcast_ssid_probe = 1;
11134
priv->sys_config.answer_broadcast_ssid_probe = 0;
11136
if (ipw_send_system_config(priv))
11139
init_supported_rates(priv, &priv->rates);
11140
if (ipw_send_supported_rates(priv, &priv->rates))
11143
/* Set request-to-send threshold */
11144
if (priv->rts_threshold) {
11145
if (ipw_send_rts_threshold(priv, priv->rts_threshold))
11148
#ifdef CONFIG_IPW2200_QOS
11149
IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
11150
ipw_qos_activate(priv, NULL);
11151
#endif /* CONFIG_IPW2200_QOS */
11153
if (ipw_set_random_seed(priv))
11156
/* final state transition to the RUN state */
11157
if (ipw_send_host_complete(priv))
11160
priv->status |= STATUS_INIT;
11162
ipw_led_init(priv);
11163
ipw_led_radio_on(priv);
11164
priv->notif_missed_beacons = 0;
11166
/* Set hardware WEP key if it is configured. */
11167
if ((priv->capability & CAP_PRIVACY_ON) &&
11168
(priv->ieee->sec.level == SEC_LEVEL_1) &&
11169
!(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
11170
ipw_set_hwcrypto_keys(priv);
11181
* These tables have been tested in conjunction with the
11182
* Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
11184
* Altering this values, using it on other hardware, or in geographies
11185
* not intended for resale of the above mentioned Intel adapters has
11188
* Remember to update the table in README.ipw2200 when changing this
11192
static const struct ieee80211_geo ipw_geos[] = {
11196
.bg = {{2412, 1}, {2417, 2}, {2422, 3},
11197
{2427, 4}, {2432, 5}, {2437, 6},
11198
{2442, 7}, {2447, 8}, {2452, 9},
11199
{2457, 10}, {2462, 11}},
11202
{ /* Custom US/Canada */
11205
.bg = {{2412, 1}, {2417, 2}, {2422, 3},
11206
{2427, 4}, {2432, 5}, {2437, 6},
11207
{2442, 7}, {2447, 8}, {2452, 9},
11208
{2457, 10}, {2462, 11}},
11214
{5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11215
{5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11216
{5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11217
{5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
11220
{ /* Rest of World */
11223
.bg = {{2412, 1}, {2417, 2}, {2422, 3},
11224
{2427, 4}, {2432, 5}, {2437, 6},
11225
{2442, 7}, {2447, 8}, {2452, 9},
11226
{2457, 10}, {2462, 11}, {2467, 12},
11230
{ /* Custom USA & Europe & High */
11233
.bg = {{2412, 1}, {2417, 2}, {2422, 3},
11234
{2427, 4}, {2432, 5}, {2437, 6},
11235
{2442, 7}, {2447, 8}, {2452, 9},
11236
{2457, 10}, {2462, 11}},
11242
{5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11243
{5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11244
{5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11245
{5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11253
{ /* Custom NA & Europe */
11256
.bg = {{2412, 1}, {2417, 2}, {2422, 3},
11257
{2427, 4}, {2432, 5}, {2437, 6},
11258
{2442, 7}, {2447, 8}, {2452, 9},
11259
{2457, 10}, {2462, 11}},
11265
{5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11266
{5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11267
{5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11268
{5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11269
{5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11270
{5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11271
{5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11272
{5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11273
{5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11276
{ /* Custom Japan */
11279
.bg = {{2412, 1}, {2417, 2}, {2422, 3},
11280
{2427, 4}, {2432, 5}, {2437, 6},
11281
{2442, 7}, {2447, 8}, {2452, 9},
11282
{2457, 10}, {2462, 11}},
11284
.a = {{5170, 34}, {5190, 38},
11285
{5210, 42}, {5230, 46}},
11291
.bg = {{2412, 1}, {2417, 2}, {2422, 3},
11292
{2427, 4}, {2432, 5}, {2437, 6},
11293
{2442, 7}, {2447, 8}, {2452, 9},
11294
{2457, 10}, {2462, 11}},
11300
.bg = {{2412, 1}, {2417, 2}, {2422, 3},
11301
{2427, 4}, {2432, 5}, {2437, 6},
11302
{2442, 7}, {2447, 8}, {2452, 9},
11303
{2457, 10}, {2462, 11}, {2467, 12},
11310
{5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11311
{5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11312
{5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11313
{5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11314
{5500, 100, IEEE80211_CH_PASSIVE_ONLY},
11315
{5520, 104, IEEE80211_CH_PASSIVE_ONLY},
11316
{5540, 108, IEEE80211_CH_PASSIVE_ONLY},
11317
{5560, 112, IEEE80211_CH_PASSIVE_ONLY},
11318
{5580, 116, IEEE80211_CH_PASSIVE_ONLY},
11319
{5600, 120, IEEE80211_CH_PASSIVE_ONLY},
11320
{5620, 124, IEEE80211_CH_PASSIVE_ONLY},
11321
{5640, 128, IEEE80211_CH_PASSIVE_ONLY},
11322
{5660, 132, IEEE80211_CH_PASSIVE_ONLY},
11323
{5680, 136, IEEE80211_CH_PASSIVE_ONLY},
11324
{5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
11327
{ /* Custom Japan */
11330
.bg = {{2412, 1}, {2417, 2}, {2422, 3},
11331
{2427, 4}, {2432, 5}, {2437, 6},
11332
{2442, 7}, {2447, 8}, {2452, 9},
11333
{2457, 10}, {2462, 11}, {2467, 12},
11334
{2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
11336
.a = {{5170, 34}, {5190, 38},
11337
{5210, 42}, {5230, 46}},
11340
{ /* Rest of World */
11343
.bg = {{2412, 1}, {2417, 2}, {2422, 3},
11344
{2427, 4}, {2432, 5}, {2437, 6},
11345
{2442, 7}, {2447, 8}, {2452, 9},
11346
{2457, 10}, {2462, 11}, {2467, 12},
11347
{2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
11348
IEEE80211_CH_PASSIVE_ONLY}},
11354
.bg = {{2412, 1}, {2417, 2}, {2422, 3},
11355
{2427, 4}, {2432, 5}, {2437, 6},
11356
{2442, 7}, {2447, 8}, {2452, 9},
11357
{2457, 10}, {2462, 11},
11358
{2467, 12, IEEE80211_CH_PASSIVE_ONLY},
11359
{2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
11361
.a = {{5745, 149}, {5765, 153},
11362
{5785, 157}, {5805, 161}},
11365
{ /* Custom Europe */
11368
.bg = {{2412, 1}, {2417, 2}, {2422, 3},
11369
{2427, 4}, {2432, 5}, {2437, 6},
11370
{2442, 7}, {2447, 8}, {2452, 9},
11371
{2457, 10}, {2462, 11},
11372
{2467, 12}, {2472, 13}},
11374
.a = {{5180, 36}, {5200, 40},
11375
{5220, 44}, {5240, 48}},
11381
.bg = {{2412, 1}, {2417, 2}, {2422, 3},
11382
{2427, 4}, {2432, 5}, {2437, 6},
11383
{2442, 7}, {2447, 8}, {2452, 9},
11384
{2457, 10}, {2462, 11},
11385
{2467, 12, IEEE80211_CH_PASSIVE_ONLY},
11386
{2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
11388
.a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
11389
{5200, 40, IEEE80211_CH_PASSIVE_ONLY},
11390
{5220, 44, IEEE80211_CH_PASSIVE_ONLY},
11391
{5240, 48, IEEE80211_CH_PASSIVE_ONLY},
11392
{5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11393
{5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11394
{5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11395
{5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11396
{5500, 100, IEEE80211_CH_PASSIVE_ONLY},
11397
{5520, 104, IEEE80211_CH_PASSIVE_ONLY},
11398
{5540, 108, IEEE80211_CH_PASSIVE_ONLY},
11399
{5560, 112, IEEE80211_CH_PASSIVE_ONLY},
11400
{5580, 116, IEEE80211_CH_PASSIVE_ONLY},
11401
{5600, 120, IEEE80211_CH_PASSIVE_ONLY},
11402
{5620, 124, IEEE80211_CH_PASSIVE_ONLY},
11403
{5640, 128, IEEE80211_CH_PASSIVE_ONLY},
11404
{5660, 132, IEEE80211_CH_PASSIVE_ONLY},
11405
{5680, 136, IEEE80211_CH_PASSIVE_ONLY},
11406
{5700, 140, IEEE80211_CH_PASSIVE_ONLY},
11407
{5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11408
{5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11409
{5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11410
{5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11411
{5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11417
.bg = {{2412, 1}, {2417, 2}, {2422, 3},
11418
{2427, 4}, {2432, 5}, {2437, 6},
11419
{2442, 7}, {2447, 8}, {2452, 9},
11420
{2457, 10}, {2462, 11}},
11422
.a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
11423
{5200, 40, IEEE80211_CH_PASSIVE_ONLY},
11424
{5220, 44, IEEE80211_CH_PASSIVE_ONLY},
11425
{5240, 48, IEEE80211_CH_PASSIVE_ONLY},
11426
{5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11427
{5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11428
{5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11429
{5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11430
{5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11431
{5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11432
{5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11433
{5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11434
{5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11438
#define MAX_HW_RESTARTS 5
11439
static int ipw_up(struct ipw_priv *priv)
11443
if (priv->status & STATUS_EXIT_PENDING)
11446
if (cmdlog && !priv->cmdlog) {
11447
priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog),
11449
if (priv->cmdlog == NULL) {
11450
IPW_ERROR("Error allocating %d command log entries.\n",
11454
priv->cmdlog_len = cmdlog;
11458
for (i = 0; i < MAX_HW_RESTARTS; i++) {
11459
/* Load the microcode, firmware, and eeprom.
11460
* Also start the clocks. */
11461
rc = ipw_load(priv);
11463
IPW_ERROR("Unable to load firmware: %d\n", rc);
11467
ipw_init_ordinals(priv);
11468
if (!(priv->config & CFG_CUSTOM_MAC))
11469
eeprom_parse_mac(priv, priv->mac_addr);
11470
memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
11472
for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11473
if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11474
ipw_geos[j].name, 3))
11477
if (j == ARRAY_SIZE(ipw_geos)) {
11478
IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11479
priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11480
priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11481
priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
11484
if (ipw_set_geo(priv->ieee, &ipw_geos[j])) {
11485
IPW_WARNING("Could not set geography.");
11489
if (priv->status & STATUS_RF_KILL_SW) {
11490
IPW_WARNING("Radio disabled by module parameter.\n");
11492
} else if (rf_kill_active(priv)) {
11493
IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11494
"Kill switch must be turned off for "
11495
"wireless networking to work.\n");
11496
queue_delayed_work(priv->workqueue, &priv->rf_kill,
11501
rc = ipw_config(priv);
11503
IPW_DEBUG_INFO("Configured device on count %i\n", i);
11505
/* If configure to try and auto-associate, kick
11507
queue_delayed_work(priv->workqueue,
11508
&priv->request_scan, 0);
11513
IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
11514
IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11515
i, MAX_HW_RESTARTS);
11517
/* We had an error bringing up the hardware, so take it
11518
* all the way back down so we can try again */
11522
/* tried to restart and config the device for as long as our
11523
* patience could withstand */
11524
IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
11529
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
11530
static void ipw_bg_up(void *work)
11532
struct ipw_priv *priv = work;
11534
static void ipw_bg_up(struct work_struct *work)
11536
struct ipw_priv *priv =
11537
container_of(work, struct ipw_priv, up);
11539
mutex_lock(&priv->mutex);
11541
mutex_unlock(&priv->mutex);
11544
static void ipw_deinit(struct ipw_priv *priv)
11548
if (priv->status & STATUS_SCANNING) {
11549
IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11550
ipw_abort_scan(priv);
11553
if (priv->status & STATUS_ASSOCIATED) {
11554
IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11555
ipw_disassociate(priv);
11558
ipw_led_shutdown(priv);
11560
/* Wait up to 1s for status to change to not scanning and not
11561
* associated (disassociation can take a while for a ful 802.11
11563
for (i = 1000; i && (priv->status &
11564
(STATUS_DISASSOCIATING |
11565
STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11568
if (priv->status & (STATUS_DISASSOCIATING |
11569
STATUS_ASSOCIATED | STATUS_SCANNING))
11570
IPW_DEBUG_INFO("Still associated or scanning...\n");
11572
IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11574
/* Attempt to disable the card */
11575
ipw_send_card_disable(priv, 0);
11577
priv->status &= ~STATUS_INIT;
11580
static void ipw_down(struct ipw_priv *priv)
11582
int exit_pending = priv->status & STATUS_EXIT_PENDING;
11584
priv->status |= STATUS_EXIT_PENDING;
11586
if (ipw_is_init(priv))
11589
/* Wipe out the EXIT_PENDING status bit if we are not actually
11590
* exiting the module */
11592
priv->status &= ~STATUS_EXIT_PENDING;
11594
/* tell the device to stop sending interrupts */
11595
ipw_disable_interrupts(priv);
11597
/* Clear all bits but the RF Kill */
11598
priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
11599
netif_carrier_off(priv->net_dev);
11600
netif_stop_queue(priv->net_dev);
11602
ipw_stop_nic(priv);
11604
ipw_led_radio_off(priv);
11607
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
11608
static void ipw_bg_down(void *work)
11610
struct ipw_priv *priv = work;
11612
static void ipw_bg_down(struct work_struct *work)
11614
struct ipw_priv *priv =
11615
container_of(work, struct ipw_priv, down);
11617
mutex_lock(&priv->mutex);
11619
mutex_unlock(&priv->mutex);
11622
/* Called by register_netdev() */
11623
static int ipw_net_init(struct net_device *dev)
11625
struct ipw_priv *priv = ieee80211_priv(dev);
11626
mutex_lock(&priv->mutex);
11628
if (ipw_up(priv)) {
11629
mutex_unlock(&priv->mutex);
11633
mutex_unlock(&priv->mutex);
11637
/* PCI driver stuff */
11638
static struct pci_device_id card_ids[] = {
11639
{PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11640
{PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11641
{PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11642
{PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11643
{PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11644
{PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11645
{PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11646
{PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11647
{PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11648
{PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11649
{PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11650
{PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11651
{PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11652
{PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11653
{PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11654
{PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11655
{PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
11656
{PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
11657
{PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
11658
{PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
11659
{PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
11660
{PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
11662
/* required last entry */
11666
MODULE_DEVICE_TABLE(pci, card_ids);
11668
static struct attribute *ipw_sysfs_entries[] = {
11669
&dev_attr_rf_kill.attr,
11670
&dev_attr_direct_dword.attr,
11671
&dev_attr_indirect_byte.attr,
11672
&dev_attr_indirect_dword.attr,
11673
&dev_attr_mem_gpio_reg.attr,
11674
&dev_attr_command_event_reg.attr,
11675
&dev_attr_nic_type.attr,
11676
&dev_attr_status.attr,
11677
&dev_attr_cfg.attr,
11678
&dev_attr_error.attr,
11679
&dev_attr_event_log.attr,
11680
&dev_attr_cmd_log.attr,
11681
&dev_attr_eeprom_delay.attr,
11682
&dev_attr_ucode_version.attr,
11683
&dev_attr_rtc.attr,
11684
&dev_attr_scan_age.attr,
11685
&dev_attr_led.attr,
11686
&dev_attr_speed_scan.attr,
11687
&dev_attr_net_stats.attr,
11688
#ifdef CONFIG_IPW2200_PROMISCUOUS
11689
&dev_attr_rtap_iface.attr,
11690
&dev_attr_rtap_filter.attr,
11695
static struct attribute_group ipw_attribute_group = {
11696
.name = NULL, /* put in device directory */
11697
.attrs = ipw_sysfs_entries,
11700
#ifdef CONFIG_IPW2200_PROMISCUOUS
11701
static int ipw_prom_open(struct net_device *dev)
11703
struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11704
struct ipw_priv *priv = prom_priv->priv;
11706
IPW_DEBUG_INFO("prom dev->open\n");
11707
netif_carrier_off(dev);
11708
netif_stop_queue(dev);
11710
if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11711
priv->sys_config.accept_all_data_frames = 1;
11712
priv->sys_config.accept_non_directed_frames = 1;
11713
priv->sys_config.accept_all_mgmt_bcpr = 1;
11714
priv->sys_config.accept_all_mgmt_frames = 1;
11716
ipw_send_system_config(priv);
11722
static int ipw_prom_stop(struct net_device *dev)
11724
struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11725
struct ipw_priv *priv = prom_priv->priv;
11727
IPW_DEBUG_INFO("prom dev->stop\n");
11729
if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11730
priv->sys_config.accept_all_data_frames = 0;
11731
priv->sys_config.accept_non_directed_frames = 0;
11732
priv->sys_config.accept_all_mgmt_bcpr = 0;
11733
priv->sys_config.accept_all_mgmt_frames = 0;
11735
ipw_send_system_config(priv);
11741
static int ipw_prom_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
11743
IPW_DEBUG_INFO("prom dev->xmit\n");
11744
netif_stop_queue(dev);
11745
return -EOPNOTSUPP;
11748
static struct net_device_stats *ipw_prom_get_stats(struct net_device *dev)
11750
struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11751
return &prom_priv->ieee->stats;
11754
static int ipw_prom_alloc(struct ipw_priv *priv)
11758
if (priv->prom_net_dev)
11761
priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv));
11762
if (priv->prom_net_dev == NULL)
11765
priv->prom_priv = ieee80211_priv(priv->prom_net_dev);
11766
priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11767
priv->prom_priv->priv = priv;
11769
strcpy(priv->prom_net_dev->name, "rtap%d");
11771
priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
11772
priv->prom_net_dev->open = ipw_prom_open;
11773
priv->prom_net_dev->stop = ipw_prom_stop;
11774
priv->prom_net_dev->get_stats = ipw_prom_get_stats;
11775
priv->prom_net_dev->hard_start_xmit = ipw_prom_hard_start_xmit;
11777
priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
11779
rc = register_netdev(priv->prom_net_dev);
11781
free_ieee80211(priv->prom_net_dev);
11782
priv->prom_net_dev = NULL;
11789
static void ipw_prom_free(struct ipw_priv *priv)
11791
if (!priv->prom_net_dev)
11794
unregister_netdev(priv->prom_net_dev);
11795
free_ieee80211(priv->prom_net_dev);
11797
priv->prom_net_dev = NULL;
11803
static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
11806
struct net_device *net_dev;
11807
void __iomem *base;
11809
struct ipw_priv *priv;
11812
net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
11813
if (net_dev == NULL) {
11818
priv = ieee80211_priv(net_dev);
11819
priv->ieee = netdev_priv(net_dev);
11821
priv->net_dev = net_dev;
11822
priv->pci_dev = pdev;
11823
ipw_debug_level = debug;
11824
spin_lock_init(&priv->irq_lock);
11825
spin_lock_init(&priv->lock);
11826
for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11827
INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
11829
mutex_init(&priv->mutex);
11830
if (pci_enable_device(pdev)) {
11832
goto out_free_ieee80211;
11835
pci_set_master(pdev);
11837
err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
11839
err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
11841
printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11842
goto out_pci_disable_device;
11845
pci_set_drvdata(pdev, priv);
11847
err = pci_request_regions(pdev, DRV_NAME);
11849
goto out_pci_disable_device;
11851
/* We disable the RETRY_TIMEOUT register (0x41) to keep
11852
* PCI Tx retries from interfering with C3 CPU state */
11853
pci_read_config_dword(pdev, 0x40, &val);
11854
if ((val & 0x0000ff00) != 0)
11855
pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11857
length = pci_resource_len(pdev, 0);
11858
priv->hw_len = length;
11860
base = ioremap_nocache(pci_resource_start(pdev, 0), length);
11863
goto out_pci_release_regions;
11866
priv->hw_base = base;
11867
IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11868
IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11870
err = ipw_setup_deferred_work(priv);
11872
IPW_ERROR("Unable to setup deferred work\n");
11876
ipw_sw_reset(priv, 1);
11878
err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv);
11880
IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11881
goto out_destroy_workqueue;
11884
SET_MODULE_OWNER(net_dev);
11885
SET_NETDEV_DEV(net_dev, &pdev->dev);
11887
mutex_lock(&priv->mutex);
11889
priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11890
priv->ieee->set_security = shim__set_security;
11891
priv->ieee->is_queue_full = ipw_net_is_queue_full;
11893
#ifdef CONFIG_IPW2200_QOS
11894
priv->ieee->is_qos_active = ipw_is_qos_active;
11895
priv->ieee->handle_probe_response = ipw_handle_beacon;
11896
priv->ieee->handle_beacon = ipw_handle_probe_response;
11897
priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
11898
#endif /* CONFIG_IPW2200_QOS */
11900
priv->ieee->perfect_rssi = -20;
11901
priv->ieee->worst_rssi = -85;
11903
net_dev->open = ipw_net_open;
11904
net_dev->stop = ipw_net_stop;
11905
net_dev->init = ipw_net_init;
11906
#if WIRELESS_EXT < 18
11907
net_dev->do_ioctl = ipw_ioctl;
11909
net_dev->get_stats = ipw_net_get_stats;
11910
net_dev->set_multicast_list = ipw_net_set_multicast_list;
11911
net_dev->set_mac_address = ipw_net_set_mac_address;
11912
#if IW_HANDLER_VERSION >= 6
11913
priv->wireless_data.spy_data = &priv->ieee->spy_data;
11914
net_dev->wireless_data = &priv->wireless_data;
11916
net_dev->get_wireless_stats = ipw_get_wireless_stats;
11917
#if WIRELESS_EXT == 16
11918
ipw_wx_handler_def.spy_offset = offsetof(struct ieee80211_device,
11922
net_dev->wireless_handlers = &ipw_wx_handler_def;
11923
net_dev->ethtool_ops = &ipw_ethtool_ops;
11924
net_dev->irq = pdev->irq;
11925
net_dev->base_addr = (unsigned long)priv->hw_base;
11926
net_dev->mem_start = pci_resource_start(pdev, 0);
11927
net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11929
err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11931
IPW_ERROR("failed to create sysfs device attributes\n");
11932
mutex_unlock(&priv->mutex);
11933
goto out_release_irq;
11936
mutex_unlock(&priv->mutex);
11937
err = register_netdev(net_dev);
11939
IPW_ERROR("failed to register network device\n");
11940
goto out_remove_sysfs;
11943
#ifdef CONFIG_IPW2200_PROMISCUOUS
11945
err = ipw_prom_alloc(priv);
11947
IPW_ERROR("Failed to register promiscuous network "
11948
"device (error %d).\n", err);
11949
unregister_netdev(priv->net_dev);
11950
goto out_remove_sysfs;
11955
printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11956
"channels, %d 802.11a channels)\n",
11957
priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11958
priv->ieee->geo.a_channels);
11963
sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11965
free_irq(pdev->irq, priv);
11966
out_destroy_workqueue:
11967
destroy_workqueue(priv->workqueue);
11968
priv->workqueue = NULL;
11970
iounmap(priv->hw_base);
11971
out_pci_release_regions:
11972
pci_release_regions(pdev);
11973
out_pci_disable_device:
11974
pci_disable_device(pdev);
11975
pci_set_drvdata(pdev, NULL);
11976
out_free_ieee80211:
11977
free_ieee80211(priv->net_dev);
11982
static void ipw_pci_remove(struct pci_dev *pdev)
11984
struct ipw_priv *priv = pci_get_drvdata(pdev);
11985
struct list_head *p, *q;
11991
mutex_lock(&priv->mutex);
11993
priv->status |= STATUS_EXIT_PENDING;
11995
sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11997
mutex_unlock(&priv->mutex);
11999
unregister_netdev(priv->net_dev);
12002
ipw_rx_queue_free(priv, priv->rxq);
12005
ipw_tx_queue_free(priv);
12007
if (priv->cmdlog) {
12008
kfree(priv->cmdlog);
12009
priv->cmdlog = NULL;
12011
/* ipw_down will ensure that there is no more pending work
12012
* in the workqueue's, so we can safely remove them now. */
12013
cancel_delayed_work(&priv->adhoc_check);
12014
cancel_delayed_work(&priv->gather_stats);
12015
cancel_delayed_work(&priv->request_scan);
12016
cancel_delayed_work(&priv->rf_kill);
12017
cancel_delayed_work(&priv->scan_check);
12018
destroy_workqueue(priv->workqueue);
12019
priv->workqueue = NULL;
12021
/* Free MAC hash list for ADHOC */
12022
for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
12023
list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
12025
kfree(list_entry(p, struct ipw_ibss_seq, list));
12029
kfree(priv->error);
12030
priv->error = NULL;
12032
#ifdef CONFIG_IPW2200_PROMISCUOUS
12033
ipw_prom_free(priv);
12036
free_irq(pdev->irq, priv);
12037
iounmap(priv->hw_base);
12038
pci_release_regions(pdev);
12039
pci_disable_device(pdev);
12040
pci_set_drvdata(pdev, NULL);
12041
free_ieee80211(priv->net_dev);
12046
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
12047
static int ipw_pci_suspend(struct pci_dev *pdev, u32 state)
12049
static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
12052
struct ipw_priv *priv = pci_get_drvdata(pdev);
12053
struct net_device *dev = priv->net_dev;
12055
printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
12057
/* Take down the device; powers it off, etc. */
12060
/* Remove the PRESENT state of the device */
12061
netif_device_detach(dev);
12063
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
12064
pci_save_state(pdev, priv->pm_state);
12066
pci_save_state(pdev);
12068
pci_disable_device(pdev);
12070
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
12071
pci_set_power_state(pdev, state);
12073
pci_set_power_state(pdev, pci_choose_state(pdev, state));
12079
static int ipw_pci_resume(struct pci_dev *pdev)
12081
struct ipw_priv *priv = pci_get_drvdata(pdev);
12082
struct net_device *dev = priv->net_dev;
12086
printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
12088
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
12089
pci_set_power_state(pdev, 0);
12091
pci_set_power_state(pdev, PCI_D0);
12093
err = pci_enable_device(pdev);
12095
printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
12099
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
12100
pci_restore_state(pdev, priv->pm_state);
12102
pci_restore_state(pdev);
12106
* Suspend/Resume resets the PCI configuration space, so we have to
12107
* re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
12108
* from interfering with C3 CPU state. pci_restore_state won't help
12109
* here since it only restores the first 64 bytes pci config header.
12111
pci_read_config_dword(pdev, 0x40, &val);
12112
if ((val & 0x0000ff00) != 0)
12113
pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
12115
/* Set the device back into the PRESENT state; this will also wake
12116
* the queue of needed */
12117
netif_device_attach(dev);
12119
/* Bring the device back up */
12120
queue_work(priv->workqueue, &priv->up);
12126
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,11)
12127
static void ipw_pci_shutdown(struct pci_dev *pdev)
12129
struct ipw_priv *priv = pci_get_drvdata(pdev);
12131
/* Take down the device; powers it off, etc. */
12134
pci_disable_device(pdev);
12138
/* driver initialization stuff */
12139
static struct pci_driver ipw_driver = {
12141
.id_table = card_ids,
12142
.probe = ipw_pci_probe,
12143
.remove = __devexit_p(ipw_pci_remove),
12145
.suspend = ipw_pci_suspend,
12146
.resume = ipw_pci_resume,
12148
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,11)
12149
.shutdown = ipw_pci_shutdown,
12153
static int __init ipw_init(void)
12157
printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
12158
printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
12160
ret = pci_register_driver(&ipw_driver);
12162
IPW_ERROR("Unable to initialize PCI module\n");
12166
ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
12168
IPW_ERROR("Unable to create driver sysfs file\n");
12169
pci_unregister_driver(&ipw_driver);
12176
static void __exit ipw_exit(void)
12178
driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
12179
pci_unregister_driver(&ipw_driver);
12182
module_param(disable, int, 0444);
12183
MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
12185
module_param(associate, int, 0444);
12186
MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
12188
module_param(auto_create, int, 0444);
12189
MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
12191
module_param(led, int, 0444);
12192
MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
12194
module_param(debug, int, 0444);
12195
MODULE_PARM_DESC(debug, "debug output mask");
12197
module_param(channel, int, 0444);
12198
MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
12200
#ifdef CONFIG_IPW2200_PROMISCUOUS
12201
module_param(rtap_iface, int, 0444);
12202
MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
12205
#ifdef CONFIG_IPW2200_QOS
12206
module_param(qos_enable, int, 0444);
12207
MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
12209
module_param(qos_burst_enable, int, 0444);
12210
MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
12212
module_param(qos_no_ack_mask, int, 0444);
12213
MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
12215
module_param(burst_duration_CCK, int, 0444);
12216
MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
12218
module_param(burst_duration_OFDM, int, 0444);
12219
MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
12220
#endif /* CONFIG_IPW2200_QOS */
12222
#ifdef CONFIG_IPW2200_MONITOR
12223
module_param(mode, int, 0444);
12224
MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
12226
module_param(mode, int, 0444);
12227
MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
12230
module_param(bt_coexist, int, 0444);
12231
MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
12233
module_param(hwcrypto, int, 0444);
12234
MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
12236
module_param(cmdlog, int, 0444);
12237
MODULE_PARM_DESC(cmdlog,
12238
"allocate a ring buffer for logging firmware commands");
12240
module_param(roaming, int, 0444);
12241
MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
12243
module_param(antenna, int, 0444);
12244
MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
12246
module_exit(ipw_exit);
12247
module_init(ipw_init);