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 Intel Linux Wireless <ilw@linux.intel.com>
29 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 ******************************************************************************/
33 #include <linux/sched.h>
34 #include <linux/slab.h>
44 #ifdef CONFIG_IPW2200_DEBUG
50 #ifdef CONFIG_IPW2200_MONITOR
56 #ifdef CONFIG_IPW2200_PROMISCUOUS
62 #ifdef CONFIG_IPW2200_RADIOTAP
68 #ifdef CONFIG_IPW2200_QOS
74 #define IPW2200_VERSION "1.2.2" VK VD VM VP VR VQ
75 #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
76 #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
77 #define DRV_VERSION IPW2200_VERSION
79 #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
81 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
82 MODULE_VERSION(DRV_VERSION
);
83 MODULE_AUTHOR(DRV_COPYRIGHT
);
84 MODULE_LICENSE("GPL");
85 MODULE_FIRMWARE("ipw2200-ibss.fw");
86 #ifdef CONFIG_IPW2200_MONITOR
87 MODULE_FIRMWARE("ipw2200-sniffer.fw");
89 MODULE_FIRMWARE("ipw2200-bss.fw");
91 static int cmdlog
= 0;
93 static int default_channel
= 0;
94 static int network_mode
= 0;
96 static u32 ipw_debug_level
;
98 static int auto_create
= 1;
99 static int led_support
= 1;
100 static int disable
= 0;
101 static int bt_coexist
= 0;
102 static int hwcrypto
= 0;
103 static int roaming
= 1;
104 static const char ipw_modes
[] = {
107 static int antenna
= CFG_SYS_ANTENNA_BOTH
;
109 #ifdef CONFIG_IPW2200_PROMISCUOUS
110 static int rtap_iface
= 0; /* def: 0 -- do not create rtap interface */
113 static struct ieee80211_rate ipw2200_rates
[] = {
115 { .bitrate
= 20, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
116 { .bitrate
= 55, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
117 { .bitrate
= 110, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
128 #define ipw2200_a_rates (ipw2200_rates + 4)
129 #define ipw2200_num_a_rates 8
130 #define ipw2200_bg_rates (ipw2200_rates + 0)
131 #define ipw2200_num_bg_rates 12
133 #ifdef CONFIG_IPW2200_QOS
134 static int qos_enable
= 0;
135 static int qos_burst_enable
= 0;
136 static int qos_no_ack_mask
= 0;
137 static int burst_duration_CCK
= 0;
138 static int burst_duration_OFDM
= 0;
140 static struct libipw_qos_parameters def_qos_parameters_OFDM
= {
141 {QOS_TX0_CW_MIN_OFDM
, QOS_TX1_CW_MIN_OFDM
, QOS_TX2_CW_MIN_OFDM
,
142 QOS_TX3_CW_MIN_OFDM
},
143 {QOS_TX0_CW_MAX_OFDM
, QOS_TX1_CW_MAX_OFDM
, QOS_TX2_CW_MAX_OFDM
,
144 QOS_TX3_CW_MAX_OFDM
},
145 {QOS_TX0_AIFS
, QOS_TX1_AIFS
, QOS_TX2_AIFS
, QOS_TX3_AIFS
},
146 {QOS_TX0_ACM
, QOS_TX1_ACM
, QOS_TX2_ACM
, QOS_TX3_ACM
},
147 {QOS_TX0_TXOP_LIMIT_OFDM
, QOS_TX1_TXOP_LIMIT_OFDM
,
148 QOS_TX2_TXOP_LIMIT_OFDM
, QOS_TX3_TXOP_LIMIT_OFDM
}
151 static struct libipw_qos_parameters def_qos_parameters_CCK
= {
152 {QOS_TX0_CW_MIN_CCK
, QOS_TX1_CW_MIN_CCK
, QOS_TX2_CW_MIN_CCK
,
154 {QOS_TX0_CW_MAX_CCK
, QOS_TX1_CW_MAX_CCK
, QOS_TX2_CW_MAX_CCK
,
156 {QOS_TX0_AIFS
, QOS_TX1_AIFS
, QOS_TX2_AIFS
, QOS_TX3_AIFS
},
157 {QOS_TX0_ACM
, QOS_TX1_ACM
, QOS_TX2_ACM
, QOS_TX3_ACM
},
158 {QOS_TX0_TXOP_LIMIT_CCK
, QOS_TX1_TXOP_LIMIT_CCK
, QOS_TX2_TXOP_LIMIT_CCK
,
159 QOS_TX3_TXOP_LIMIT_CCK
}
162 static struct libipw_qos_parameters def_parameters_OFDM
= {
163 {DEF_TX0_CW_MIN_OFDM
, DEF_TX1_CW_MIN_OFDM
, DEF_TX2_CW_MIN_OFDM
,
164 DEF_TX3_CW_MIN_OFDM
},
165 {DEF_TX0_CW_MAX_OFDM
, DEF_TX1_CW_MAX_OFDM
, DEF_TX2_CW_MAX_OFDM
,
166 DEF_TX3_CW_MAX_OFDM
},
167 {DEF_TX0_AIFS
, DEF_TX1_AIFS
, DEF_TX2_AIFS
, DEF_TX3_AIFS
},
168 {DEF_TX0_ACM
, DEF_TX1_ACM
, DEF_TX2_ACM
, DEF_TX3_ACM
},
169 {DEF_TX0_TXOP_LIMIT_OFDM
, DEF_TX1_TXOP_LIMIT_OFDM
,
170 DEF_TX2_TXOP_LIMIT_OFDM
, DEF_TX3_TXOP_LIMIT_OFDM
}
173 static struct libipw_qos_parameters def_parameters_CCK
= {
174 {DEF_TX0_CW_MIN_CCK
, DEF_TX1_CW_MIN_CCK
, DEF_TX2_CW_MIN_CCK
,
176 {DEF_TX0_CW_MAX_CCK
, DEF_TX1_CW_MAX_CCK
, DEF_TX2_CW_MAX_CCK
,
178 {DEF_TX0_AIFS
, DEF_TX1_AIFS
, DEF_TX2_AIFS
, DEF_TX3_AIFS
},
179 {DEF_TX0_ACM
, DEF_TX1_ACM
, DEF_TX2_ACM
, DEF_TX3_ACM
},
180 {DEF_TX0_TXOP_LIMIT_CCK
, DEF_TX1_TXOP_LIMIT_CCK
, DEF_TX2_TXOP_LIMIT_CCK
,
181 DEF_TX3_TXOP_LIMIT_CCK
}
184 static u8 qos_oui
[QOS_OUI_LEN
] = { 0x00, 0x50, 0xF2 };
186 static int from_priority_to_tx_queue
[] = {
187 IPW_TX_QUEUE_1
, IPW_TX_QUEUE_2
, IPW_TX_QUEUE_2
, IPW_TX_QUEUE_1
,
188 IPW_TX_QUEUE_3
, IPW_TX_QUEUE_3
, IPW_TX_QUEUE_4
, IPW_TX_QUEUE_4
191 static u32
ipw_qos_get_burst_duration(struct ipw_priv
*priv
);
193 static int ipw_send_qos_params_command(struct ipw_priv
*priv
, struct libipw_qos_parameters
195 static int ipw_send_qos_info_command(struct ipw_priv
*priv
, struct libipw_qos_information_element
197 #endif /* CONFIG_IPW2200_QOS */
199 static struct iw_statistics
*ipw_get_wireless_stats(struct net_device
*dev
);
200 static void ipw_remove_current_network(struct ipw_priv
*priv
);
201 static void ipw_rx(struct ipw_priv
*priv
);
202 static int ipw_queue_tx_reclaim(struct ipw_priv
*priv
,
203 struct clx2_tx_queue
*txq
, int qindex
);
204 static int ipw_queue_reset(struct ipw_priv
*priv
);
206 static int ipw_queue_tx_hcmd(struct ipw_priv
*priv
, int hcmd
, void *buf
,
209 static void ipw_tx_queue_free(struct ipw_priv
*);
211 static struct ipw_rx_queue
*ipw_rx_queue_alloc(struct ipw_priv
*);
212 static void ipw_rx_queue_free(struct ipw_priv
*, struct ipw_rx_queue
*);
213 static void ipw_rx_queue_replenish(void *);
214 static int ipw_up(struct ipw_priv
*);
215 static void ipw_bg_up(struct work_struct
*work
);
216 static void ipw_down(struct ipw_priv
*);
217 static void ipw_bg_down(struct work_struct
*work
);
218 static int ipw_config(struct ipw_priv
*);
219 static int init_supported_rates(struct ipw_priv
*priv
,
220 struct ipw_supported_rates
*prates
);
221 static void ipw_set_hwcrypto_keys(struct ipw_priv
*);
222 static void ipw_send_wep_keys(struct ipw_priv
*, int);
224 static int snprint_line(char *buf
, size_t count
,
225 const u8
* data
, u32 len
, u32 ofs
)
230 out
= snprintf(buf
, count
, "%08X", ofs
);
232 for (l
= 0, i
= 0; i
< 2; i
++) {
233 out
+= snprintf(buf
+ out
, count
- out
, " ");
234 for (j
= 0; j
< 8 && l
< len
; j
++, l
++)
235 out
+= snprintf(buf
+ out
, count
- out
, "%02X ",
238 out
+= snprintf(buf
+ out
, count
- out
, " ");
241 out
+= snprintf(buf
+ out
, count
- out
, " ");
242 for (l
= 0, i
= 0; i
< 2; i
++) {
243 out
+= snprintf(buf
+ out
, count
- out
, " ");
244 for (j
= 0; j
< 8 && l
< len
; j
++, l
++) {
245 c
= data
[(i
* 8 + j
)];
246 if (!isascii(c
) || !isprint(c
))
249 out
+= snprintf(buf
+ out
, count
- out
, "%c", c
);
253 out
+= snprintf(buf
+ out
, count
- out
, " ");
259 static void printk_buf(int level
, const u8
* data
, u32 len
)
263 if (!(ipw_debug_level
& level
))
267 snprint_line(line
, sizeof(line
), &data
[ofs
],
269 printk(KERN_DEBUG
"%s\n", line
);
271 len
-= min(len
, 16U);
275 static int snprintk_buf(u8
* output
, size_t size
, const u8
* data
, size_t len
)
281 while (size
&& len
) {
282 out
= snprint_line(output
, size
, &data
[ofs
],
283 min_t(size_t, len
, 16U), ofs
);
288 len
-= min_t(size_t, len
, 16U);
294 /* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
295 static u32
_ipw_read_reg32(struct ipw_priv
*priv
, u32 reg
);
296 #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
298 /* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
299 static u8
_ipw_read_reg8(struct ipw_priv
*ipw
, u32 reg
);
300 #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
302 /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
303 static void _ipw_write_reg8(struct ipw_priv
*priv
, u32 reg
, u8 value
);
304 static inline void ipw_write_reg8(struct ipw_priv
*a
, u32 b
, u8 c
)
306 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__
,
307 __LINE__
, (u32
) (b
), (u32
) (c
));
308 _ipw_write_reg8(a
, b
, c
);
311 /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
312 static void _ipw_write_reg16(struct ipw_priv
*priv
, u32 reg
, u16 value
);
313 static inline void ipw_write_reg16(struct ipw_priv
*a
, u32 b
, u16 c
)
315 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__
,
316 __LINE__
, (u32
) (b
), (u32
) (c
));
317 _ipw_write_reg16(a
, b
, c
);
320 /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
321 static void _ipw_write_reg32(struct ipw_priv
*priv
, u32 reg
, u32 value
);
322 static inline void ipw_write_reg32(struct ipw_priv
*a
, u32 b
, u32 c
)
324 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__
,
325 __LINE__
, (u32
) (b
), (u32
) (c
));
326 _ipw_write_reg32(a
, b
, c
);
329 /* 8-bit direct write (low 4K) */
330 static inline void _ipw_write8(struct ipw_priv
*ipw
, unsigned long ofs
,
333 writeb(val
, ipw
->hw_base
+ ofs
);
336 /* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
337 #define ipw_write8(ipw, ofs, val) do { \
338 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, \
339 __LINE__, (u32)(ofs), (u32)(val)); \
340 _ipw_write8(ipw, ofs, val); \
343 /* 16-bit direct write (low 4K) */
344 static inline void _ipw_write16(struct ipw_priv
*ipw
, unsigned long ofs
,
347 writew(val
, ipw
->hw_base
+ ofs
);
350 /* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
351 #define ipw_write16(ipw, ofs, val) do { \
352 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, \
353 __LINE__, (u32)(ofs), (u32)(val)); \
354 _ipw_write16(ipw, ofs, val); \
357 /* 32-bit direct write (low 4K) */
358 static inline void _ipw_write32(struct ipw_priv
*ipw
, unsigned long ofs
,
361 writel(val
, ipw
->hw_base
+ ofs
);
364 /* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
365 #define ipw_write32(ipw, ofs, val) do { \
366 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, \
367 __LINE__, (u32)(ofs), (u32)(val)); \
368 _ipw_write32(ipw, ofs, val); \
371 /* 8-bit direct read (low 4K) */
372 static inline u8
_ipw_read8(struct ipw_priv
*ipw
, unsigned long ofs
)
374 return readb(ipw
->hw_base
+ ofs
);
377 /* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
378 #define ipw_read8(ipw, ofs) ({ \
379 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", __FILE__, __LINE__, \
381 _ipw_read8(ipw, ofs); \
384 /* 16-bit direct read (low 4K) */
385 static inline u16
_ipw_read16(struct ipw_priv
*ipw
, unsigned long ofs
)
387 return readw(ipw
->hw_base
+ ofs
);
390 /* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
391 #define ipw_read16(ipw, ofs) ({ \
392 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", __FILE__, __LINE__, \
394 _ipw_read16(ipw, ofs); \
397 /* 32-bit direct read (low 4K) */
398 static inline u32
_ipw_read32(struct ipw_priv
*ipw
, unsigned long ofs
)
400 return readl(ipw
->hw_base
+ ofs
);
403 /* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
404 #define ipw_read32(ipw, ofs) ({ \
405 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", __FILE__, __LINE__, \
407 _ipw_read32(ipw, ofs); \
410 static void _ipw_read_indirect(struct ipw_priv
*, u32
, u8
*, int);
411 /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
412 #define ipw_read_indirect(a, b, c, d) ({ \
413 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %u bytes\n", __FILE__, \
414 __LINE__, (u32)(b), (u32)(d)); \
415 _ipw_read_indirect(a, b, c, d); \
418 /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
419 static void _ipw_write_indirect(struct ipw_priv
*priv
, u32 addr
, u8
* data
,
421 #define ipw_write_indirect(a, b, c, d) do { \
422 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %u bytes\n", __FILE__, \
423 __LINE__, (u32)(b), (u32)(d)); \
424 _ipw_write_indirect(a, b, c, d); \
427 /* 32-bit indirect write (above 4K) */
428 static void _ipw_write_reg32(struct ipw_priv
*priv
, u32 reg
, u32 value
)
430 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv
, reg
, value
);
431 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, reg
);
432 _ipw_write32(priv
, IPW_INDIRECT_DATA
, value
);
435 /* 8-bit indirect write (above 4K) */
436 static void _ipw_write_reg8(struct ipw_priv
*priv
, u32 reg
, u8 value
)
438 u32 aligned_addr
= reg
& IPW_INDIRECT_ADDR_MASK
; /* dword align */
439 u32 dif_len
= reg
- aligned_addr
;
441 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg
, value
);
442 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, aligned_addr
);
443 _ipw_write8(priv
, IPW_INDIRECT_DATA
+ dif_len
, value
);
446 /* 16-bit indirect write (above 4K) */
447 static void _ipw_write_reg16(struct ipw_priv
*priv
, u32 reg
, u16 value
)
449 u32 aligned_addr
= reg
& IPW_INDIRECT_ADDR_MASK
; /* dword align */
450 u32 dif_len
= (reg
- aligned_addr
) & (~0x1ul
);
452 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg
, value
);
453 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, aligned_addr
);
454 _ipw_write16(priv
, IPW_INDIRECT_DATA
+ dif_len
, value
);
457 /* 8-bit indirect read (above 4K) */
458 static u8
_ipw_read_reg8(struct ipw_priv
*priv
, u32 reg
)
461 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, reg
& IPW_INDIRECT_ADDR_MASK
);
462 IPW_DEBUG_IO(" reg = 0x%8X :\n", reg
);
463 word
= _ipw_read32(priv
, IPW_INDIRECT_DATA
);
464 return (word
>> ((reg
& 0x3) * 8)) & 0xff;
467 /* 32-bit indirect read (above 4K) */
468 static u32
_ipw_read_reg32(struct ipw_priv
*priv
, u32 reg
)
472 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv
, reg
);
474 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, reg
);
475 value
= _ipw_read32(priv
, IPW_INDIRECT_DATA
);
476 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x\n", reg
, value
);
480 /* General purpose, no alignment requirement, iterative (multi-byte) read, */
481 /* for area above 1st 4K of SRAM/reg space */
482 static void _ipw_read_indirect(struct ipw_priv
*priv
, u32 addr
, u8
* buf
,
485 u32 aligned_addr
= addr
& IPW_INDIRECT_ADDR_MASK
; /* dword align */
486 u32 dif_len
= addr
- aligned_addr
;
489 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr
, buf
, num
);
495 /* Read the first dword (or portion) byte by byte */
496 if (unlikely(dif_len
)) {
497 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, aligned_addr
);
498 /* Start reading at aligned_addr + dif_len */
499 for (i
= dif_len
; ((i
< 4) && (num
> 0)); i
++, num
--)
500 *buf
++ = _ipw_read8(priv
, IPW_INDIRECT_DATA
+ i
);
504 /* Read all of the middle dwords as dwords, with auto-increment */
505 _ipw_write32(priv
, IPW_AUTOINC_ADDR
, aligned_addr
);
506 for (; num
>= 4; buf
+= 4, aligned_addr
+= 4, num
-= 4)
507 *(u32
*) buf
= _ipw_read32(priv
, IPW_AUTOINC_DATA
);
509 /* Read the last dword (or portion) byte by byte */
511 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, aligned_addr
);
512 for (i
= 0; num
> 0; i
++, num
--)
513 *buf
++ = ipw_read8(priv
, IPW_INDIRECT_DATA
+ i
);
517 /* General purpose, no alignment requirement, iterative (multi-byte) write, */
518 /* for area above 1st 4K of SRAM/reg space */
519 static void _ipw_write_indirect(struct ipw_priv
*priv
, u32 addr
, u8
* buf
,
522 u32 aligned_addr
= addr
& IPW_INDIRECT_ADDR_MASK
; /* dword align */
523 u32 dif_len
= addr
- aligned_addr
;
526 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr
, buf
, num
);
532 /* Write the first dword (or portion) byte by byte */
533 if (unlikely(dif_len
)) {
534 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, aligned_addr
);
535 /* Start writing at aligned_addr + dif_len */
536 for (i
= dif_len
; ((i
< 4) && (num
> 0)); i
++, num
--, buf
++)
537 _ipw_write8(priv
, IPW_INDIRECT_DATA
+ i
, *buf
);
541 /* Write all of the middle dwords as dwords, with auto-increment */
542 _ipw_write32(priv
, IPW_AUTOINC_ADDR
, aligned_addr
);
543 for (; num
>= 4; buf
+= 4, aligned_addr
+= 4, num
-= 4)
544 _ipw_write32(priv
, IPW_AUTOINC_DATA
, *(u32
*) buf
);
546 /* Write the last dword (or portion) byte by byte */
548 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, aligned_addr
);
549 for (i
= 0; num
> 0; i
++, num
--, buf
++)
550 _ipw_write8(priv
, IPW_INDIRECT_DATA
+ i
, *buf
);
554 /* General purpose, no alignment requirement, iterative (multi-byte) write, */
555 /* for 1st 4K of SRAM/regs space */
556 static void ipw_write_direct(struct ipw_priv
*priv
, u32 addr
, void *buf
,
559 memcpy_toio((priv
->hw_base
+ addr
), buf
, num
);
562 /* Set bit(s) in low 4K of SRAM/regs */
563 static inline void ipw_set_bit(struct ipw_priv
*priv
, u32 reg
, u32 mask
)
565 ipw_write32(priv
, reg
, ipw_read32(priv
, reg
) | mask
);
568 /* Clear bit(s) in low 4K of SRAM/regs */
569 static inline void ipw_clear_bit(struct ipw_priv
*priv
, u32 reg
, u32 mask
)
571 ipw_write32(priv
, reg
, ipw_read32(priv
, reg
) & ~mask
);
574 static inline void __ipw_enable_interrupts(struct ipw_priv
*priv
)
576 if (priv
->status
& STATUS_INT_ENABLED
)
578 priv
->status
|= STATUS_INT_ENABLED
;
579 ipw_write32(priv
, IPW_INTA_MASK_R
, IPW_INTA_MASK_ALL
);
582 static inline void __ipw_disable_interrupts(struct ipw_priv
*priv
)
584 if (!(priv
->status
& STATUS_INT_ENABLED
))
586 priv
->status
&= ~STATUS_INT_ENABLED
;
587 ipw_write32(priv
, IPW_INTA_MASK_R
, ~IPW_INTA_MASK_ALL
);
590 static inline void ipw_enable_interrupts(struct ipw_priv
*priv
)
594 spin_lock_irqsave(&priv
->irq_lock
, flags
);
595 __ipw_enable_interrupts(priv
);
596 spin_unlock_irqrestore(&priv
->irq_lock
, flags
);
599 static inline void ipw_disable_interrupts(struct ipw_priv
*priv
)
603 spin_lock_irqsave(&priv
->irq_lock
, flags
);
604 __ipw_disable_interrupts(priv
);
605 spin_unlock_irqrestore(&priv
->irq_lock
, flags
);
608 static char *ipw_error_desc(u32 val
)
611 case IPW_FW_ERROR_OK
:
613 case IPW_FW_ERROR_FAIL
:
615 case IPW_FW_ERROR_MEMORY_UNDERFLOW
:
616 return "MEMORY_UNDERFLOW";
617 case IPW_FW_ERROR_MEMORY_OVERFLOW
:
618 return "MEMORY_OVERFLOW";
619 case IPW_FW_ERROR_BAD_PARAM
:
621 case IPW_FW_ERROR_BAD_CHECKSUM
:
622 return "BAD_CHECKSUM";
623 case IPW_FW_ERROR_NMI_INTERRUPT
:
624 return "NMI_INTERRUPT";
625 case IPW_FW_ERROR_BAD_DATABASE
:
626 return "BAD_DATABASE";
627 case IPW_FW_ERROR_ALLOC_FAIL
:
629 case IPW_FW_ERROR_DMA_UNDERRUN
:
630 return "DMA_UNDERRUN";
631 case IPW_FW_ERROR_DMA_STATUS
:
633 case IPW_FW_ERROR_DINO_ERROR
:
635 case IPW_FW_ERROR_EEPROM_ERROR
:
636 return "EEPROM_ERROR";
637 case IPW_FW_ERROR_SYSASSERT
:
639 case IPW_FW_ERROR_FATAL_ERROR
:
640 return "FATAL_ERROR";
642 return "UNKNOWN_ERROR";
646 static void ipw_dump_error_log(struct ipw_priv
*priv
,
647 struct ipw_fw_error
*error
)
652 IPW_ERROR("Error allocating and capturing error log. "
653 "Nothing to dump.\n");
657 IPW_ERROR("Start IPW Error Log Dump:\n");
658 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
659 error
->status
, error
->config
);
661 for (i
= 0; i
< error
->elem_len
; i
++)
662 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
663 ipw_error_desc(error
->elem
[i
].desc
),
665 error
->elem
[i
].blink1
,
666 error
->elem
[i
].blink2
,
667 error
->elem
[i
].link1
,
668 error
->elem
[i
].link2
, error
->elem
[i
].data
);
669 for (i
= 0; i
< error
->log_len
; i
++)
670 IPW_ERROR("%i\t0x%08x\t%i\n",
672 error
->log
[i
].data
, error
->log
[i
].event
);
675 static inline int ipw_is_init(struct ipw_priv
*priv
)
677 return (priv
->status
& STATUS_INIT
) ? 1 : 0;
680 static int ipw_get_ordinal(struct ipw_priv
*priv
, u32 ord
, void *val
, u32
* len
)
682 u32 addr
, field_info
, field_len
, field_count
, total_len
;
684 IPW_DEBUG_ORD("ordinal = %i\n", ord
);
686 if (!priv
|| !val
|| !len
) {
687 IPW_DEBUG_ORD("Invalid argument\n");
691 /* verify device ordinal tables have been initialized */
692 if (!priv
->table0_addr
|| !priv
->table1_addr
|| !priv
->table2_addr
) {
693 IPW_DEBUG_ORD("Access ordinals before initialization\n");
697 switch (IPW_ORD_TABLE_ID_MASK
& ord
) {
698 case IPW_ORD_TABLE_0_MASK
:
700 * TABLE 0: Direct access to a table of 32 bit values
702 * This is a very simple table with the data directly
703 * read from the table
706 /* remove the table id from the ordinal */
707 ord
&= IPW_ORD_TABLE_VALUE_MASK
;
710 if (ord
> priv
->table0_len
) {
711 IPW_DEBUG_ORD("ordinal value (%i) longer then "
712 "max (%i)\n", ord
, priv
->table0_len
);
716 /* verify we have enough room to store the value */
717 if (*len
< sizeof(u32
)) {
718 IPW_DEBUG_ORD("ordinal buffer length too small, "
719 "need %zd\n", sizeof(u32
));
723 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
724 ord
, priv
->table0_addr
+ (ord
<< 2));
728 *((u32
*) val
) = ipw_read32(priv
, priv
->table0_addr
+ ord
);
731 case IPW_ORD_TABLE_1_MASK
:
733 * TABLE 1: Indirect access to a table of 32 bit values
735 * This is a fairly large table of u32 values each
736 * representing starting addr for the data (which is
740 /* remove the table id from the ordinal */
741 ord
&= IPW_ORD_TABLE_VALUE_MASK
;
744 if (ord
> priv
->table1_len
) {
745 IPW_DEBUG_ORD("ordinal value too long\n");
749 /* verify we have enough room to store the value */
750 if (*len
< sizeof(u32
)) {
751 IPW_DEBUG_ORD("ordinal buffer length too small, "
752 "need %zd\n", sizeof(u32
));
757 ipw_read_reg32(priv
, (priv
->table1_addr
+ (ord
<< 2)));
761 case IPW_ORD_TABLE_2_MASK
:
763 * TABLE 2: Indirect access to a table of variable sized values
765 * This table consist of six values, each containing
766 * - dword containing the starting offset of the data
767 * - dword containing the lengh in the first 16bits
768 * and the count in the second 16bits
771 /* remove the table id from the ordinal */
772 ord
&= IPW_ORD_TABLE_VALUE_MASK
;
775 if (ord
> priv
->table2_len
) {
776 IPW_DEBUG_ORD("ordinal value too long\n");
780 /* get the address of statistic */
781 addr
= ipw_read_reg32(priv
, priv
->table2_addr
+ (ord
<< 3));
783 /* get the second DW of statistics ;
784 * two 16-bit words - first is length, second is count */
787 priv
->table2_addr
+ (ord
<< 3) +
790 /* get each entry length */
791 field_len
= *((u16
*) & field_info
);
793 /* get number of entries */
794 field_count
= *(((u16
*) & field_info
) + 1);
796 /* abort if not enough memory */
797 total_len
= field_len
* field_count
;
798 if (total_len
> *len
) {
807 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
808 "field_info = 0x%08x\n",
809 addr
, total_len
, field_info
);
810 ipw_read_indirect(priv
, addr
, val
, total_len
);
814 IPW_DEBUG_ORD("Invalid ordinal!\n");
822 static void ipw_init_ordinals(struct ipw_priv
*priv
)
824 priv
->table0_addr
= IPW_ORDINALS_TABLE_LOWER
;
825 priv
->table0_len
= ipw_read32(priv
, priv
->table0_addr
);
827 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
828 priv
->table0_addr
, priv
->table0_len
);
830 priv
->table1_addr
= ipw_read32(priv
, IPW_ORDINALS_TABLE_1
);
831 priv
->table1_len
= ipw_read_reg32(priv
, priv
->table1_addr
);
833 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
834 priv
->table1_addr
, priv
->table1_len
);
836 priv
->table2_addr
= ipw_read32(priv
, IPW_ORDINALS_TABLE_2
);
837 priv
->table2_len
= ipw_read_reg32(priv
, priv
->table2_addr
);
838 priv
->table2_len
&= 0x0000ffff; /* use first two bytes */
840 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
841 priv
->table2_addr
, priv
->table2_len
);
845 static u32
ipw_register_toggle(u32 reg
)
847 reg
&= ~IPW_START_STANDBY
;
848 if (reg
& IPW_GATE_ODMA
)
849 reg
&= ~IPW_GATE_ODMA
;
850 if (reg
& IPW_GATE_IDMA
)
851 reg
&= ~IPW_GATE_IDMA
;
852 if (reg
& IPW_GATE_ADMA
)
853 reg
&= ~IPW_GATE_ADMA
;
859 * - On radio ON, turn on any LEDs that require to be on during start
860 * - On initialization, start unassociated blink
861 * - On association, disable unassociated blink
862 * - On disassociation, start unassociated blink
863 * - On radio OFF, turn off any LEDs started during radio on
866 #define LD_TIME_LINK_ON msecs_to_jiffies(300)
867 #define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
868 #define LD_TIME_ACT_ON msecs_to_jiffies(250)
870 static void ipw_led_link_on(struct ipw_priv
*priv
)
875 /* If configured to not use LEDs, or nic_type is 1,
876 * then we don't toggle a LINK led */
877 if (priv
->config
& CFG_NO_LED
|| priv
->nic_type
== EEPROM_NIC_TYPE_1
)
880 spin_lock_irqsave(&priv
->lock
, flags
);
882 if (!(priv
->status
& STATUS_RF_KILL_MASK
) &&
883 !(priv
->status
& STATUS_LED_LINK_ON
)) {
884 IPW_DEBUG_LED("Link LED On\n");
885 led
= ipw_read_reg32(priv
, IPW_EVENT_REG
);
886 led
|= priv
->led_association_on
;
888 led
= ipw_register_toggle(led
);
890 IPW_DEBUG_LED("Reg: 0x%08X\n", led
);
891 ipw_write_reg32(priv
, IPW_EVENT_REG
, led
);
893 priv
->status
|= STATUS_LED_LINK_ON
;
895 /* If we aren't associated, schedule turning the LED off */
896 if (!(priv
->status
& STATUS_ASSOCIATED
))
897 queue_delayed_work(priv
->workqueue
,
902 spin_unlock_irqrestore(&priv
->lock
, flags
);
905 static void ipw_bg_led_link_on(struct work_struct
*work
)
907 struct ipw_priv
*priv
=
908 container_of(work
, struct ipw_priv
, led_link_on
.work
);
909 mutex_lock(&priv
->mutex
);
910 ipw_led_link_on(priv
);
911 mutex_unlock(&priv
->mutex
);
914 static void ipw_led_link_off(struct ipw_priv
*priv
)
919 /* If configured not to use LEDs, or nic type is 1,
920 * then we don't goggle the LINK led. */
921 if (priv
->config
& CFG_NO_LED
|| priv
->nic_type
== EEPROM_NIC_TYPE_1
)
924 spin_lock_irqsave(&priv
->lock
, flags
);
926 if (priv
->status
& STATUS_LED_LINK_ON
) {
927 led
= ipw_read_reg32(priv
, IPW_EVENT_REG
);
928 led
&= priv
->led_association_off
;
929 led
= ipw_register_toggle(led
);
931 IPW_DEBUG_LED("Reg: 0x%08X\n", led
);
932 ipw_write_reg32(priv
, IPW_EVENT_REG
, led
);
934 IPW_DEBUG_LED("Link LED Off\n");
936 priv
->status
&= ~STATUS_LED_LINK_ON
;
938 /* If we aren't associated and the radio is on, schedule
939 * turning the LED on (blink while unassociated) */
940 if (!(priv
->status
& STATUS_RF_KILL_MASK
) &&
941 !(priv
->status
& STATUS_ASSOCIATED
))
942 queue_delayed_work(priv
->workqueue
, &priv
->led_link_on
,
947 spin_unlock_irqrestore(&priv
->lock
, flags
);
950 static void ipw_bg_led_link_off(struct work_struct
*work
)
952 struct ipw_priv
*priv
=
953 container_of(work
, struct ipw_priv
, led_link_off
.work
);
954 mutex_lock(&priv
->mutex
);
955 ipw_led_link_off(priv
);
956 mutex_unlock(&priv
->mutex
);
959 static void __ipw_led_activity_on(struct ipw_priv
*priv
)
963 if (priv
->config
& CFG_NO_LED
)
966 if (priv
->status
& STATUS_RF_KILL_MASK
)
969 if (!(priv
->status
& STATUS_LED_ACT_ON
)) {
970 led
= ipw_read_reg32(priv
, IPW_EVENT_REG
);
971 led
|= priv
->led_activity_on
;
973 led
= ipw_register_toggle(led
);
975 IPW_DEBUG_LED("Reg: 0x%08X\n", led
);
976 ipw_write_reg32(priv
, IPW_EVENT_REG
, led
);
978 IPW_DEBUG_LED("Activity LED On\n");
980 priv
->status
|= STATUS_LED_ACT_ON
;
982 cancel_delayed_work(&priv
->led_act_off
);
983 queue_delayed_work(priv
->workqueue
, &priv
->led_act_off
,
986 /* Reschedule LED off for full time period */
987 cancel_delayed_work(&priv
->led_act_off
);
988 queue_delayed_work(priv
->workqueue
, &priv
->led_act_off
,
994 void ipw_led_activity_on(struct ipw_priv
*priv
)
997 spin_lock_irqsave(&priv
->lock
, flags
);
998 __ipw_led_activity_on(priv
);
999 spin_unlock_irqrestore(&priv
->lock
, flags
);
1003 static void ipw_led_activity_off(struct ipw_priv
*priv
)
1005 unsigned long flags
;
1008 if (priv
->config
& CFG_NO_LED
)
1011 spin_lock_irqsave(&priv
->lock
, flags
);
1013 if (priv
->status
& STATUS_LED_ACT_ON
) {
1014 led
= ipw_read_reg32(priv
, IPW_EVENT_REG
);
1015 led
&= priv
->led_activity_off
;
1017 led
= ipw_register_toggle(led
);
1019 IPW_DEBUG_LED("Reg: 0x%08X\n", led
);
1020 ipw_write_reg32(priv
, IPW_EVENT_REG
, led
);
1022 IPW_DEBUG_LED("Activity LED Off\n");
1024 priv
->status
&= ~STATUS_LED_ACT_ON
;
1027 spin_unlock_irqrestore(&priv
->lock
, flags
);
1030 static void ipw_bg_led_activity_off(struct work_struct
*work
)
1032 struct ipw_priv
*priv
=
1033 container_of(work
, struct ipw_priv
, led_act_off
.work
);
1034 mutex_lock(&priv
->mutex
);
1035 ipw_led_activity_off(priv
);
1036 mutex_unlock(&priv
->mutex
);
1039 static void ipw_led_band_on(struct ipw_priv
*priv
)
1041 unsigned long flags
;
1044 /* Only nic type 1 supports mode LEDs */
1045 if (priv
->config
& CFG_NO_LED
||
1046 priv
->nic_type
!= EEPROM_NIC_TYPE_1
|| !priv
->assoc_network
)
1049 spin_lock_irqsave(&priv
->lock
, flags
);
1051 led
= ipw_read_reg32(priv
, IPW_EVENT_REG
);
1052 if (priv
->assoc_network
->mode
== IEEE_A
) {
1053 led
|= priv
->led_ofdm_on
;
1054 led
&= priv
->led_association_off
;
1055 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
1056 } else if (priv
->assoc_network
->mode
== IEEE_G
) {
1057 led
|= priv
->led_ofdm_on
;
1058 led
|= priv
->led_association_on
;
1059 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
1061 led
&= priv
->led_ofdm_off
;
1062 led
|= priv
->led_association_on
;
1063 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
1066 led
= ipw_register_toggle(led
);
1068 IPW_DEBUG_LED("Reg: 0x%08X\n", led
);
1069 ipw_write_reg32(priv
, IPW_EVENT_REG
, led
);
1071 spin_unlock_irqrestore(&priv
->lock
, flags
);
1074 static void ipw_led_band_off(struct ipw_priv
*priv
)
1076 unsigned long flags
;
1079 /* Only nic type 1 supports mode LEDs */
1080 if (priv
->config
& CFG_NO_LED
|| priv
->nic_type
!= EEPROM_NIC_TYPE_1
)
1083 spin_lock_irqsave(&priv
->lock
, flags
);
1085 led
= ipw_read_reg32(priv
, IPW_EVENT_REG
);
1086 led
&= priv
->led_ofdm_off
;
1087 led
&= priv
->led_association_off
;
1089 led
= ipw_register_toggle(led
);
1091 IPW_DEBUG_LED("Reg: 0x%08X\n", led
);
1092 ipw_write_reg32(priv
, IPW_EVENT_REG
, led
);
1094 spin_unlock_irqrestore(&priv
->lock
, flags
);
1097 static void ipw_led_radio_on(struct ipw_priv
*priv
)
1099 ipw_led_link_on(priv
);
1102 static void ipw_led_radio_off(struct ipw_priv
*priv
)
1104 ipw_led_activity_off(priv
);
1105 ipw_led_link_off(priv
);
1108 static void ipw_led_link_up(struct ipw_priv
*priv
)
1110 /* Set the Link Led on for all nic types */
1111 ipw_led_link_on(priv
);
1114 static void ipw_led_link_down(struct ipw_priv
*priv
)
1116 ipw_led_activity_off(priv
);
1117 ipw_led_link_off(priv
);
1119 if (priv
->status
& STATUS_RF_KILL_MASK
)
1120 ipw_led_radio_off(priv
);
1123 static void ipw_led_init(struct ipw_priv
*priv
)
1125 priv
->nic_type
= priv
->eeprom
[EEPROM_NIC_TYPE
];
1127 /* Set the default PINs for the link and activity leds */
1128 priv
->led_activity_on
= IPW_ACTIVITY_LED
;
1129 priv
->led_activity_off
= ~(IPW_ACTIVITY_LED
);
1131 priv
->led_association_on
= IPW_ASSOCIATED_LED
;
1132 priv
->led_association_off
= ~(IPW_ASSOCIATED_LED
);
1134 /* Set the default PINs for the OFDM leds */
1135 priv
->led_ofdm_on
= IPW_OFDM_LED
;
1136 priv
->led_ofdm_off
= ~(IPW_OFDM_LED
);
1138 switch (priv
->nic_type
) {
1139 case EEPROM_NIC_TYPE_1
:
1140 /* In this NIC type, the LEDs are reversed.... */
1141 priv
->led_activity_on
= IPW_ASSOCIATED_LED
;
1142 priv
->led_activity_off
= ~(IPW_ASSOCIATED_LED
);
1143 priv
->led_association_on
= IPW_ACTIVITY_LED
;
1144 priv
->led_association_off
= ~(IPW_ACTIVITY_LED
);
1146 if (!(priv
->config
& CFG_NO_LED
))
1147 ipw_led_band_on(priv
);
1149 /* And we don't blink link LEDs for this nic, so
1150 * just return here */
1153 case EEPROM_NIC_TYPE_3
:
1154 case EEPROM_NIC_TYPE_2
:
1155 case EEPROM_NIC_TYPE_4
:
1156 case EEPROM_NIC_TYPE_0
:
1160 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1162 priv
->nic_type
= EEPROM_NIC_TYPE_0
;
1166 if (!(priv
->config
& CFG_NO_LED
)) {
1167 if (priv
->status
& STATUS_ASSOCIATED
)
1168 ipw_led_link_on(priv
);
1170 ipw_led_link_off(priv
);
1174 static void ipw_led_shutdown(struct ipw_priv
*priv
)
1176 ipw_led_activity_off(priv
);
1177 ipw_led_link_off(priv
);
1178 ipw_led_band_off(priv
);
1179 cancel_delayed_work(&priv
->led_link_on
);
1180 cancel_delayed_work(&priv
->led_link_off
);
1181 cancel_delayed_work(&priv
->led_act_off
);
1185 * The following adds a new attribute to the sysfs representation
1186 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1187 * used for controling the debug level.
1189 * See the level definitions in ipw for details.
1191 static ssize_t
show_debug_level(struct device_driver
*d
, char *buf
)
1193 return sprintf(buf
, "0x%08X\n", ipw_debug_level
);
1196 static ssize_t
store_debug_level(struct device_driver
*d
, const char *buf
,
1199 char *p
= (char *)buf
;
1202 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
1204 if (p
[0] == 'x' || p
[0] == 'X')
1206 val
= simple_strtoul(p
, &p
, 16);
1208 val
= simple_strtoul(p
, &p
, 10);
1210 printk(KERN_INFO DRV_NAME
1211 ": %s is not in hex or decimal form.\n", buf
);
1213 ipw_debug_level
= val
;
1215 return strnlen(buf
, count
);
1218 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1219 show_debug_level
, store_debug_level
);
1221 static inline u32
ipw_get_event_log_len(struct ipw_priv
*priv
)
1223 /* length = 1st dword in log */
1224 return ipw_read_reg32(priv
, ipw_read32(priv
, IPW_EVENT_LOG
));
1227 static void ipw_capture_event_log(struct ipw_priv
*priv
,
1228 u32 log_len
, struct ipw_event
*log
)
1233 base
= ipw_read32(priv
, IPW_EVENT_LOG
);
1234 ipw_read_indirect(priv
, base
+ sizeof(base
) + sizeof(u32
),
1235 (u8
*) log
, sizeof(*log
) * log_len
);
1239 static struct ipw_fw_error
*ipw_alloc_error_log(struct ipw_priv
*priv
)
1241 struct ipw_fw_error
*error
;
1242 u32 log_len
= ipw_get_event_log_len(priv
);
1243 u32 base
= ipw_read32(priv
, IPW_ERROR_LOG
);
1244 u32 elem_len
= ipw_read_reg32(priv
, base
);
1246 error
= kmalloc(sizeof(*error
) +
1247 sizeof(*error
->elem
) * elem_len
+
1248 sizeof(*error
->log
) * log_len
, GFP_ATOMIC
);
1250 IPW_ERROR("Memory allocation for firmware error log "
1254 error
->jiffies
= jiffies
;
1255 error
->status
= priv
->status
;
1256 error
->config
= priv
->config
;
1257 error
->elem_len
= elem_len
;
1258 error
->log_len
= log_len
;
1259 error
->elem
= (struct ipw_error_elem
*)error
->payload
;
1260 error
->log
= (struct ipw_event
*)(error
->elem
+ elem_len
);
1262 ipw_capture_event_log(priv
, log_len
, error
->log
);
1265 ipw_read_indirect(priv
, base
+ sizeof(base
), (u8
*) error
->elem
,
1266 sizeof(*error
->elem
) * elem_len
);
1271 static ssize_t
show_event_log(struct device
*d
,
1272 struct device_attribute
*attr
, char *buf
)
1274 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1275 u32 log_len
= ipw_get_event_log_len(priv
);
1277 struct ipw_event
*log
;
1280 /* not using min() because of its strict type checking */
1281 log_size
= PAGE_SIZE
/ sizeof(*log
) > log_len
?
1282 sizeof(*log
) * log_len
: PAGE_SIZE
;
1283 log
= kzalloc(log_size
, GFP_KERNEL
);
1285 IPW_ERROR("Unable to allocate memory for log\n");
1288 log_len
= log_size
/ sizeof(*log
);
1289 ipw_capture_event_log(priv
, log_len
, log
);
1291 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
, "%08X", log_len
);
1292 for (i
= 0; i
< log_len
; i
++)
1293 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
,
1295 log
[i
].time
, log
[i
].event
, log
[i
].data
);
1296 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
, "\n");
1301 static DEVICE_ATTR(event_log
, S_IRUGO
, show_event_log
, NULL
);
1303 static ssize_t
show_error(struct device
*d
,
1304 struct device_attribute
*attr
, char *buf
)
1306 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1310 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
,
1311 "%08lX%08X%08X%08X",
1312 priv
->error
->jiffies
,
1313 priv
->error
->status
,
1314 priv
->error
->config
, priv
->error
->elem_len
);
1315 for (i
= 0; i
< priv
->error
->elem_len
; i
++)
1316 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
,
1317 "\n%08X%08X%08X%08X%08X%08X%08X",
1318 priv
->error
->elem
[i
].time
,
1319 priv
->error
->elem
[i
].desc
,
1320 priv
->error
->elem
[i
].blink1
,
1321 priv
->error
->elem
[i
].blink2
,
1322 priv
->error
->elem
[i
].link1
,
1323 priv
->error
->elem
[i
].link2
,
1324 priv
->error
->elem
[i
].data
);
1326 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
,
1327 "\n%08X", priv
->error
->log_len
);
1328 for (i
= 0; i
< priv
->error
->log_len
; i
++)
1329 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
,
1331 priv
->error
->log
[i
].time
,
1332 priv
->error
->log
[i
].event
,
1333 priv
->error
->log
[i
].data
);
1334 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
, "\n");
1338 static ssize_t
clear_error(struct device
*d
,
1339 struct device_attribute
*attr
,
1340 const char *buf
, size_t count
)
1342 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1349 static DEVICE_ATTR(error
, S_IRUGO
| S_IWUSR
, show_error
, clear_error
);
1351 static ssize_t
show_cmd_log(struct device
*d
,
1352 struct device_attribute
*attr
, char *buf
)
1354 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1358 for (i
= (priv
->cmdlog_pos
+ 1) % priv
->cmdlog_len
;
1359 (i
!= priv
->cmdlog_pos
) && (PAGE_SIZE
- len
);
1360 i
= (i
+ 1) % priv
->cmdlog_len
) {
1362 snprintf(buf
+ len
, PAGE_SIZE
- len
,
1363 "\n%08lX%08X%08X%08X\n", priv
->cmdlog
[i
].jiffies
,
1364 priv
->cmdlog
[i
].retcode
, priv
->cmdlog
[i
].cmd
.cmd
,
1365 priv
->cmdlog
[i
].cmd
.len
);
1367 snprintk_buf(buf
+ len
, PAGE_SIZE
- len
,
1368 (u8
*) priv
->cmdlog
[i
].cmd
.param
,
1369 priv
->cmdlog
[i
].cmd
.len
);
1370 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
, "\n");
1372 len
+= snprintf(buf
+ len
, PAGE_SIZE
- len
, "\n");
1376 static DEVICE_ATTR(cmd_log
, S_IRUGO
, show_cmd_log
, NULL
);
1378 #ifdef CONFIG_IPW2200_PROMISCUOUS
1379 static void ipw_prom_free(struct ipw_priv
*priv
);
1380 static int ipw_prom_alloc(struct ipw_priv
*priv
);
1381 static ssize_t
store_rtap_iface(struct device
*d
,
1382 struct device_attribute
*attr
,
1383 const char *buf
, size_t count
)
1385 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1396 if (netif_running(priv
->prom_net_dev
)) {
1397 IPW_WARNING("Interface is up. Cannot unregister.\n");
1401 ipw_prom_free(priv
);
1409 rc
= ipw_prom_alloc(priv
);
1419 IPW_ERROR("Failed to register promiscuous network "
1420 "device (error %d).\n", rc
);
1426 static ssize_t
show_rtap_iface(struct device
*d
,
1427 struct device_attribute
*attr
,
1430 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1432 return sprintf(buf
, "%s", priv
->prom_net_dev
->name
);
1441 static DEVICE_ATTR(rtap_iface
, S_IWUSR
| S_IRUSR
, show_rtap_iface
,
1444 static ssize_t
store_rtap_filter(struct device
*d
,
1445 struct device_attribute
*attr
,
1446 const char *buf
, size_t count
)
1448 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1450 if (!priv
->prom_priv
) {
1451 IPW_ERROR("Attempting to set filter without "
1452 "rtap_iface enabled.\n");
1456 priv
->prom_priv
->filter
= simple_strtol(buf
, NULL
, 0);
1458 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16
"\n",
1459 BIT_ARG16(priv
->prom_priv
->filter
));
1464 static ssize_t
show_rtap_filter(struct device
*d
,
1465 struct device_attribute
*attr
,
1468 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1469 return sprintf(buf
, "0x%04X",
1470 priv
->prom_priv
? priv
->prom_priv
->filter
: 0);
1473 static DEVICE_ATTR(rtap_filter
, S_IWUSR
| S_IRUSR
, show_rtap_filter
,
1477 static ssize_t
show_scan_age(struct device
*d
, struct device_attribute
*attr
,
1480 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1481 return sprintf(buf
, "%d\n", priv
->ieee
->scan_age
);
1484 static ssize_t
store_scan_age(struct device
*d
, struct device_attribute
*attr
,
1485 const char *buf
, size_t count
)
1487 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1488 struct net_device
*dev
= priv
->net_dev
;
1489 char buffer
[] = "00000000";
1491 (sizeof(buffer
) - 1) > count
? count
: sizeof(buffer
) - 1;
1495 IPW_DEBUG_INFO("enter\n");
1497 strncpy(buffer
, buf
, len
);
1500 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
1502 if (p
[0] == 'x' || p
[0] == 'X')
1504 val
= simple_strtoul(p
, &p
, 16);
1506 val
= simple_strtoul(p
, &p
, 10);
1508 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev
->name
);
1510 priv
->ieee
->scan_age
= val
;
1511 IPW_DEBUG_INFO("set scan_age = %u\n", priv
->ieee
->scan_age
);
1514 IPW_DEBUG_INFO("exit\n");
1518 static DEVICE_ATTR(scan_age
, S_IWUSR
| S_IRUGO
, show_scan_age
, store_scan_age
);
1520 static ssize_t
show_led(struct device
*d
, struct device_attribute
*attr
,
1523 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1524 return sprintf(buf
, "%d\n", (priv
->config
& CFG_NO_LED
) ? 0 : 1);
1527 static ssize_t
store_led(struct device
*d
, struct device_attribute
*attr
,
1528 const char *buf
, size_t count
)
1530 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1532 IPW_DEBUG_INFO("enter\n");
1538 IPW_DEBUG_LED("Disabling LED control.\n");
1539 priv
->config
|= CFG_NO_LED
;
1540 ipw_led_shutdown(priv
);
1542 IPW_DEBUG_LED("Enabling LED control.\n");
1543 priv
->config
&= ~CFG_NO_LED
;
1547 IPW_DEBUG_INFO("exit\n");
1551 static DEVICE_ATTR(led
, S_IWUSR
| S_IRUGO
, show_led
, store_led
);
1553 static ssize_t
show_status(struct device
*d
,
1554 struct device_attribute
*attr
, char *buf
)
1556 struct ipw_priv
*p
= dev_get_drvdata(d
);
1557 return sprintf(buf
, "0x%08x\n", (int)p
->status
);
1560 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
1562 static ssize_t
show_cfg(struct device
*d
, struct device_attribute
*attr
,
1565 struct ipw_priv
*p
= dev_get_drvdata(d
);
1566 return sprintf(buf
, "0x%08x\n", (int)p
->config
);
1569 static DEVICE_ATTR(cfg
, S_IRUGO
, show_cfg
, NULL
);
1571 static ssize_t
show_nic_type(struct device
*d
,
1572 struct device_attribute
*attr
, char *buf
)
1574 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1575 return sprintf(buf
, "TYPE: %d\n", priv
->nic_type
);
1578 static DEVICE_ATTR(nic_type
, S_IRUGO
, show_nic_type
, NULL
);
1580 static ssize_t
show_ucode_version(struct device
*d
,
1581 struct device_attribute
*attr
, char *buf
)
1583 u32 len
= sizeof(u32
), tmp
= 0;
1584 struct ipw_priv
*p
= dev_get_drvdata(d
);
1586 if (ipw_get_ordinal(p
, IPW_ORD_STAT_UCODE_VERSION
, &tmp
, &len
))
1589 return sprintf(buf
, "0x%08x\n", tmp
);
1592 static DEVICE_ATTR(ucode_version
, S_IWUSR
| S_IRUGO
, show_ucode_version
, NULL
);
1594 static ssize_t
show_rtc(struct device
*d
, struct device_attribute
*attr
,
1597 u32 len
= sizeof(u32
), tmp
= 0;
1598 struct ipw_priv
*p
= dev_get_drvdata(d
);
1600 if (ipw_get_ordinal(p
, IPW_ORD_STAT_RTC
, &tmp
, &len
))
1603 return sprintf(buf
, "0x%08x\n", tmp
);
1606 static DEVICE_ATTR(rtc
, S_IWUSR
| S_IRUGO
, show_rtc
, NULL
);
1609 * Add a device attribute to view/control the delay between eeprom
1612 static ssize_t
show_eeprom_delay(struct device
*d
,
1613 struct device_attribute
*attr
, char *buf
)
1615 struct ipw_priv
*p
= dev_get_drvdata(d
);
1616 int n
= p
->eeprom_delay
;
1617 return sprintf(buf
, "%i\n", n
);
1619 static ssize_t
store_eeprom_delay(struct device
*d
,
1620 struct device_attribute
*attr
,
1621 const char *buf
, size_t count
)
1623 struct ipw_priv
*p
= dev_get_drvdata(d
);
1624 sscanf(buf
, "%i", &p
->eeprom_delay
);
1625 return strnlen(buf
, count
);
1628 static DEVICE_ATTR(eeprom_delay
, S_IWUSR
| S_IRUGO
,
1629 show_eeprom_delay
, store_eeprom_delay
);
1631 static ssize_t
show_command_event_reg(struct device
*d
,
1632 struct device_attribute
*attr
, char *buf
)
1635 struct ipw_priv
*p
= dev_get_drvdata(d
);
1637 reg
= ipw_read_reg32(p
, IPW_INTERNAL_CMD_EVENT
);
1638 return sprintf(buf
, "0x%08x\n", reg
);
1640 static ssize_t
store_command_event_reg(struct device
*d
,
1641 struct device_attribute
*attr
,
1642 const char *buf
, size_t count
)
1645 struct ipw_priv
*p
= dev_get_drvdata(d
);
1647 sscanf(buf
, "%x", ®
);
1648 ipw_write_reg32(p
, IPW_INTERNAL_CMD_EVENT
, reg
);
1649 return strnlen(buf
, count
);
1652 static DEVICE_ATTR(command_event_reg
, S_IWUSR
| S_IRUGO
,
1653 show_command_event_reg
, store_command_event_reg
);
1655 static ssize_t
show_mem_gpio_reg(struct device
*d
,
1656 struct device_attribute
*attr
, char *buf
)
1659 struct ipw_priv
*p
= dev_get_drvdata(d
);
1661 reg
= ipw_read_reg32(p
, 0x301100);
1662 return sprintf(buf
, "0x%08x\n", reg
);
1664 static ssize_t
store_mem_gpio_reg(struct device
*d
,
1665 struct device_attribute
*attr
,
1666 const char *buf
, size_t count
)
1669 struct ipw_priv
*p
= dev_get_drvdata(d
);
1671 sscanf(buf
, "%x", ®
);
1672 ipw_write_reg32(p
, 0x301100, reg
);
1673 return strnlen(buf
, count
);
1676 static DEVICE_ATTR(mem_gpio_reg
, S_IWUSR
| S_IRUGO
,
1677 show_mem_gpio_reg
, store_mem_gpio_reg
);
1679 static ssize_t
show_indirect_dword(struct device
*d
,
1680 struct device_attribute
*attr
, char *buf
)
1683 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1685 if (priv
->status
& STATUS_INDIRECT_DWORD
)
1686 reg
= ipw_read_reg32(priv
, priv
->indirect_dword
);
1690 return sprintf(buf
, "0x%08x\n", reg
);
1692 static ssize_t
store_indirect_dword(struct device
*d
,
1693 struct device_attribute
*attr
,
1694 const char *buf
, size_t count
)
1696 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1698 sscanf(buf
, "%x", &priv
->indirect_dword
);
1699 priv
->status
|= STATUS_INDIRECT_DWORD
;
1700 return strnlen(buf
, count
);
1703 static DEVICE_ATTR(indirect_dword
, S_IWUSR
| S_IRUGO
,
1704 show_indirect_dword
, store_indirect_dword
);
1706 static ssize_t
show_indirect_byte(struct device
*d
,
1707 struct device_attribute
*attr
, char *buf
)
1710 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1712 if (priv
->status
& STATUS_INDIRECT_BYTE
)
1713 reg
= ipw_read_reg8(priv
, priv
->indirect_byte
);
1717 return sprintf(buf
, "0x%02x\n", reg
);
1719 static ssize_t
store_indirect_byte(struct device
*d
,
1720 struct device_attribute
*attr
,
1721 const char *buf
, size_t count
)
1723 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1725 sscanf(buf
, "%x", &priv
->indirect_byte
);
1726 priv
->status
|= STATUS_INDIRECT_BYTE
;
1727 return strnlen(buf
, count
);
1730 static DEVICE_ATTR(indirect_byte
, S_IWUSR
| S_IRUGO
,
1731 show_indirect_byte
, store_indirect_byte
);
1733 static ssize_t
show_direct_dword(struct device
*d
,
1734 struct device_attribute
*attr
, char *buf
)
1737 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1739 if (priv
->status
& STATUS_DIRECT_DWORD
)
1740 reg
= ipw_read32(priv
, priv
->direct_dword
);
1744 return sprintf(buf
, "0x%08x\n", reg
);
1746 static ssize_t
store_direct_dword(struct device
*d
,
1747 struct device_attribute
*attr
,
1748 const char *buf
, size_t count
)
1750 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1752 sscanf(buf
, "%x", &priv
->direct_dword
);
1753 priv
->status
|= STATUS_DIRECT_DWORD
;
1754 return strnlen(buf
, count
);
1757 static DEVICE_ATTR(direct_dword
, S_IWUSR
| S_IRUGO
,
1758 show_direct_dword
, store_direct_dword
);
1760 static int rf_kill_active(struct ipw_priv
*priv
)
1762 if (0 == (ipw_read32(priv
, 0x30) & 0x10000)) {
1763 priv
->status
|= STATUS_RF_KILL_HW
;
1764 wiphy_rfkill_set_hw_state(priv
->ieee
->wdev
.wiphy
, true);
1766 priv
->status
&= ~STATUS_RF_KILL_HW
;
1767 wiphy_rfkill_set_hw_state(priv
->ieee
->wdev
.wiphy
, false);
1770 return (priv
->status
& STATUS_RF_KILL_HW
) ? 1 : 0;
1773 static ssize_t
show_rf_kill(struct device
*d
, struct device_attribute
*attr
,
1776 /* 0 - RF kill not enabled
1777 1 - SW based RF kill active (sysfs)
1778 2 - HW based RF kill active
1779 3 - Both HW and SW baed RF kill active */
1780 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1781 int val
= ((priv
->status
& STATUS_RF_KILL_SW
) ? 0x1 : 0x0) |
1782 (rf_kill_active(priv
) ? 0x2 : 0x0);
1783 return sprintf(buf
, "%i\n", val
);
1786 static int ipw_radio_kill_sw(struct ipw_priv
*priv
, int disable_radio
)
1788 if ((disable_radio
? 1 : 0) ==
1789 ((priv
->status
& STATUS_RF_KILL_SW
) ? 1 : 0))
1792 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1793 disable_radio
? "OFF" : "ON");
1795 if (disable_radio
) {
1796 priv
->status
|= STATUS_RF_KILL_SW
;
1798 if (priv
->workqueue
) {
1799 cancel_delayed_work(&priv
->request_scan
);
1800 cancel_delayed_work(&priv
->request_direct_scan
);
1801 cancel_delayed_work(&priv
->request_passive_scan
);
1802 cancel_delayed_work(&priv
->scan_event
);
1804 queue_work(priv
->workqueue
, &priv
->down
);
1806 priv
->status
&= ~STATUS_RF_KILL_SW
;
1807 if (rf_kill_active(priv
)) {
1808 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1809 "disabled by HW switch\n");
1810 /* Make sure the RF_KILL check timer is running */
1811 cancel_delayed_work(&priv
->rf_kill
);
1812 queue_delayed_work(priv
->workqueue
, &priv
->rf_kill
,
1813 round_jiffies_relative(2 * HZ
));
1815 queue_work(priv
->workqueue
, &priv
->up
);
1821 static ssize_t
store_rf_kill(struct device
*d
, struct device_attribute
*attr
,
1822 const char *buf
, size_t count
)
1824 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1826 ipw_radio_kill_sw(priv
, buf
[0] == '1');
1831 static DEVICE_ATTR(rf_kill
, S_IWUSR
| S_IRUGO
, show_rf_kill
, store_rf_kill
);
1833 static ssize_t
show_speed_scan(struct device
*d
, struct device_attribute
*attr
,
1836 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1837 int pos
= 0, len
= 0;
1838 if (priv
->config
& CFG_SPEED_SCAN
) {
1839 while (priv
->speed_scan
[pos
] != 0)
1840 len
+= sprintf(&buf
[len
], "%d ",
1841 priv
->speed_scan
[pos
++]);
1842 return len
+ sprintf(&buf
[len
], "\n");
1845 return sprintf(buf
, "0\n");
1848 static ssize_t
store_speed_scan(struct device
*d
, struct device_attribute
*attr
,
1849 const char *buf
, size_t count
)
1851 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1852 int channel
, pos
= 0;
1853 const char *p
= buf
;
1855 /* list of space separated channels to scan, optionally ending with 0 */
1856 while ((channel
= simple_strtol(p
, NULL
, 0))) {
1857 if (pos
== MAX_SPEED_SCAN
- 1) {
1858 priv
->speed_scan
[pos
] = 0;
1862 if (libipw_is_valid_channel(priv
->ieee
, channel
))
1863 priv
->speed_scan
[pos
++] = channel
;
1865 IPW_WARNING("Skipping invalid channel request: %d\n",
1870 while (*p
== ' ' || *p
== '\t')
1875 priv
->config
&= ~CFG_SPEED_SCAN
;
1877 priv
->speed_scan_pos
= 0;
1878 priv
->config
|= CFG_SPEED_SCAN
;
1884 static DEVICE_ATTR(speed_scan
, S_IWUSR
| S_IRUGO
, show_speed_scan
,
1887 static ssize_t
show_net_stats(struct device
*d
, struct device_attribute
*attr
,
1890 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1891 return sprintf(buf
, "%c\n", (priv
->config
& CFG_NET_STATS
) ? '1' : '0');
1894 static ssize_t
store_net_stats(struct device
*d
, struct device_attribute
*attr
,
1895 const char *buf
, size_t count
)
1897 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1899 priv
->config
|= CFG_NET_STATS
;
1901 priv
->config
&= ~CFG_NET_STATS
;
1906 static DEVICE_ATTR(net_stats
, S_IWUSR
| S_IRUGO
,
1907 show_net_stats
, store_net_stats
);
1909 static ssize_t
show_channels(struct device
*d
,
1910 struct device_attribute
*attr
,
1913 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1914 const struct libipw_geo
*geo
= libipw_get_geo(priv
->ieee
);
1917 len
= sprintf(&buf
[len
],
1918 "Displaying %d channels in 2.4Ghz band "
1919 "(802.11bg):\n", geo
->bg_channels
);
1921 for (i
= 0; i
< geo
->bg_channels
; i
++) {
1922 len
+= sprintf(&buf
[len
], "%d: BSS%s%s, %s, Band %s.\n",
1924 geo
->bg
[i
].flags
& LIBIPW_CH_RADAR_DETECT
?
1925 " (radar spectrum)" : "",
1926 ((geo
->bg
[i
].flags
& LIBIPW_CH_NO_IBSS
) ||
1927 (geo
->bg
[i
].flags
& LIBIPW_CH_RADAR_DETECT
))
1929 geo
->bg
[i
].flags
& LIBIPW_CH_PASSIVE_ONLY
?
1930 "passive only" : "active/passive",
1931 geo
->bg
[i
].flags
& LIBIPW_CH_B_ONLY
?
1935 len
+= sprintf(&buf
[len
],
1936 "Displaying %d channels in 5.2Ghz band "
1937 "(802.11a):\n", geo
->a_channels
);
1938 for (i
= 0; i
< geo
->a_channels
; i
++) {
1939 len
+= sprintf(&buf
[len
], "%d: BSS%s%s, %s.\n",
1941 geo
->a
[i
].flags
& LIBIPW_CH_RADAR_DETECT
?
1942 " (radar spectrum)" : "",
1943 ((geo
->a
[i
].flags
& LIBIPW_CH_NO_IBSS
) ||
1944 (geo
->a
[i
].flags
& LIBIPW_CH_RADAR_DETECT
))
1946 geo
->a
[i
].flags
& LIBIPW_CH_PASSIVE_ONLY
?
1947 "passive only" : "active/passive");
1953 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
1955 static void notify_wx_assoc_event(struct ipw_priv
*priv
)
1957 union iwreq_data wrqu
;
1958 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1959 if (priv
->status
& STATUS_ASSOCIATED
)
1960 memcpy(wrqu
.ap_addr
.sa_data
, priv
->bssid
, ETH_ALEN
);
1962 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
1963 wireless_send_event(priv
->net_dev
, SIOCGIWAP
, &wrqu
, NULL
);
1966 static void ipw_irq_tasklet(struct ipw_priv
*priv
)
1968 u32 inta
, inta_mask
, handled
= 0;
1969 unsigned long flags
;
1972 spin_lock_irqsave(&priv
->irq_lock
, flags
);
1974 inta
= ipw_read32(priv
, IPW_INTA_RW
);
1975 inta_mask
= ipw_read32(priv
, IPW_INTA_MASK_R
);
1977 if (inta
== 0xFFFFFFFF) {
1978 /* Hardware disappeared */
1979 IPW_WARNING("TASKLET INTA == 0xFFFFFFFF\n");
1980 /* Only handle the cached INTA values */
1983 inta
&= (IPW_INTA_MASK_ALL
& inta_mask
);
1985 /* Add any cached INTA values that need to be handled */
1986 inta
|= priv
->isr_inta
;
1988 spin_unlock_irqrestore(&priv
->irq_lock
, flags
);
1990 spin_lock_irqsave(&priv
->lock
, flags
);
1992 /* handle all the justifications for the interrupt */
1993 if (inta
& IPW_INTA_BIT_RX_TRANSFER
) {
1995 handled
|= IPW_INTA_BIT_RX_TRANSFER
;
1998 if (inta
& IPW_INTA_BIT_TX_CMD_QUEUE
) {
1999 IPW_DEBUG_HC("Command completed.\n");
2000 rc
= ipw_queue_tx_reclaim(priv
, &priv
->txq_cmd
, -1);
2001 priv
->status
&= ~STATUS_HCMD_ACTIVE
;
2002 wake_up_interruptible(&priv
->wait_command_queue
);
2003 handled
|= IPW_INTA_BIT_TX_CMD_QUEUE
;
2006 if (inta
& IPW_INTA_BIT_TX_QUEUE_1
) {
2007 IPW_DEBUG_TX("TX_QUEUE_1\n");
2008 rc
= ipw_queue_tx_reclaim(priv
, &priv
->txq
[0], 0);
2009 handled
|= IPW_INTA_BIT_TX_QUEUE_1
;
2012 if (inta
& IPW_INTA_BIT_TX_QUEUE_2
) {
2013 IPW_DEBUG_TX("TX_QUEUE_2\n");
2014 rc
= ipw_queue_tx_reclaim(priv
, &priv
->txq
[1], 1);
2015 handled
|= IPW_INTA_BIT_TX_QUEUE_2
;
2018 if (inta
& IPW_INTA_BIT_TX_QUEUE_3
) {
2019 IPW_DEBUG_TX("TX_QUEUE_3\n");
2020 rc
= ipw_queue_tx_reclaim(priv
, &priv
->txq
[2], 2);
2021 handled
|= IPW_INTA_BIT_TX_QUEUE_3
;
2024 if (inta
& IPW_INTA_BIT_TX_QUEUE_4
) {
2025 IPW_DEBUG_TX("TX_QUEUE_4\n");
2026 rc
= ipw_queue_tx_reclaim(priv
, &priv
->txq
[3], 3);
2027 handled
|= IPW_INTA_BIT_TX_QUEUE_4
;
2030 if (inta
& IPW_INTA_BIT_STATUS_CHANGE
) {
2031 IPW_WARNING("STATUS_CHANGE\n");
2032 handled
|= IPW_INTA_BIT_STATUS_CHANGE
;
2035 if (inta
& IPW_INTA_BIT_BEACON_PERIOD_EXPIRED
) {
2036 IPW_WARNING("TX_PERIOD_EXPIRED\n");
2037 handled
|= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED
;
2040 if (inta
& IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE
) {
2041 IPW_WARNING("HOST_CMD_DONE\n");
2042 handled
|= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE
;
2045 if (inta
& IPW_INTA_BIT_FW_INITIALIZATION_DONE
) {
2046 IPW_WARNING("FW_INITIALIZATION_DONE\n");
2047 handled
|= IPW_INTA_BIT_FW_INITIALIZATION_DONE
;
2050 if (inta
& IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE
) {
2051 IPW_WARNING("PHY_OFF_DONE\n");
2052 handled
|= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE
;
2055 if (inta
& IPW_INTA_BIT_RF_KILL_DONE
) {
2056 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
2057 priv
->status
|= STATUS_RF_KILL_HW
;
2058 wiphy_rfkill_set_hw_state(priv
->ieee
->wdev
.wiphy
, true);
2059 wake_up_interruptible(&priv
->wait_command_queue
);
2060 priv
->status
&= ~(STATUS_ASSOCIATED
| STATUS_ASSOCIATING
);
2061 cancel_delayed_work(&priv
->request_scan
);
2062 cancel_delayed_work(&priv
->request_direct_scan
);
2063 cancel_delayed_work(&priv
->request_passive_scan
);
2064 cancel_delayed_work(&priv
->scan_event
);
2065 schedule_work(&priv
->link_down
);
2066 queue_delayed_work(priv
->workqueue
, &priv
->rf_kill
, 2 * HZ
);
2067 handled
|= IPW_INTA_BIT_RF_KILL_DONE
;
2070 if (inta
& IPW_INTA_BIT_FATAL_ERROR
) {
2071 IPW_WARNING("Firmware error detected. Restarting.\n");
2073 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
2074 if (ipw_debug_level
& IPW_DL_FW_ERRORS
) {
2075 struct ipw_fw_error
*error
=
2076 ipw_alloc_error_log(priv
);
2077 ipw_dump_error_log(priv
, error
);
2081 priv
->error
= ipw_alloc_error_log(priv
);
2083 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
2085 IPW_DEBUG_FW("Error allocating sysfs 'error' "
2087 if (ipw_debug_level
& IPW_DL_FW_ERRORS
)
2088 ipw_dump_error_log(priv
, priv
->error
);
2091 /* XXX: If hardware encryption is for WPA/WPA2,
2092 * we have to notify the supplicant. */
2093 if (priv
->ieee
->sec
.encrypt
) {
2094 priv
->status
&= ~STATUS_ASSOCIATED
;
2095 notify_wx_assoc_event(priv
);
2098 /* Keep the restart process from trying to send host
2099 * commands by clearing the INIT status bit */
2100 priv
->status
&= ~STATUS_INIT
;
2102 /* Cancel currently queued command. */
2103 priv
->status
&= ~STATUS_HCMD_ACTIVE
;
2104 wake_up_interruptible(&priv
->wait_command_queue
);
2106 queue_work(priv
->workqueue
, &priv
->adapter_restart
);
2107 handled
|= IPW_INTA_BIT_FATAL_ERROR
;
2110 if (inta
& IPW_INTA_BIT_PARITY_ERROR
) {
2111 IPW_ERROR("Parity error\n");
2112 handled
|= IPW_INTA_BIT_PARITY_ERROR
;
2115 if (handled
!= inta
) {
2116 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
2119 spin_unlock_irqrestore(&priv
->lock
, flags
);
2121 /* enable all interrupts */
2122 ipw_enable_interrupts(priv
);
2125 #define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2126 static char *get_cmd_string(u8 cmd
)
2129 IPW_CMD(HOST_COMPLETE
);
2130 IPW_CMD(POWER_DOWN
);
2131 IPW_CMD(SYSTEM_CONFIG
);
2132 IPW_CMD(MULTICAST_ADDRESS
);
2134 IPW_CMD(ADAPTER_ADDRESS
);
2136 IPW_CMD(RTS_THRESHOLD
);
2137 IPW_CMD(FRAG_THRESHOLD
);
2138 IPW_CMD(POWER_MODE
);
2140 IPW_CMD(TGI_TX_KEY
);
2141 IPW_CMD(SCAN_REQUEST
);
2142 IPW_CMD(SCAN_REQUEST_EXT
);
2144 IPW_CMD(SUPPORTED_RATES
);
2145 IPW_CMD(SCAN_ABORT
);
2147 IPW_CMD(QOS_PARAMETERS
);
2148 IPW_CMD(DINO_CONFIG
);
2149 IPW_CMD(RSN_CAPABILITIES
);
2151 IPW_CMD(CARD_DISABLE
);
2152 IPW_CMD(SEED_NUMBER
);
2154 IPW_CMD(COUNTRY_INFO
);
2155 IPW_CMD(AIRONET_INFO
);
2156 IPW_CMD(AP_TX_POWER
);
2158 IPW_CMD(CCX_VER_INFO
);
2159 IPW_CMD(SET_CALIBRATION
);
2160 IPW_CMD(SENSITIVITY_CALIB
);
2161 IPW_CMD(RETRY_LIMIT
);
2162 IPW_CMD(IPW_PRE_POWER_DOWN
);
2163 IPW_CMD(VAP_BEACON_TEMPLATE
);
2164 IPW_CMD(VAP_DTIM_PERIOD
);
2165 IPW_CMD(EXT_SUPPORTED_RATES
);
2166 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT
);
2167 IPW_CMD(VAP_QUIET_INTERVALS
);
2168 IPW_CMD(VAP_CHANNEL_SWITCH
);
2169 IPW_CMD(VAP_MANDATORY_CHANNELS
);
2170 IPW_CMD(VAP_CELL_PWR_LIMIT
);
2171 IPW_CMD(VAP_CF_PARAM_SET
);
2172 IPW_CMD(VAP_SET_BEACONING_STATE
);
2173 IPW_CMD(MEASUREMENT
);
2174 IPW_CMD(POWER_CAPABILITY
);
2175 IPW_CMD(SUPPORTED_CHANNELS
);
2176 IPW_CMD(TPC_REPORT
);
2178 IPW_CMD(PRODUCTION_COMMAND
);
2184 #define HOST_COMPLETE_TIMEOUT HZ
2186 static int __ipw_send_cmd(struct ipw_priv
*priv
, struct host_cmd
*cmd
)
2189 unsigned long flags
;
2191 spin_lock_irqsave(&priv
->lock
, flags
);
2192 if (priv
->status
& STATUS_HCMD_ACTIVE
) {
2193 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2194 get_cmd_string(cmd
->cmd
));
2195 spin_unlock_irqrestore(&priv
->lock
, flags
);
2199 priv
->status
|= STATUS_HCMD_ACTIVE
;
2202 priv
->cmdlog
[priv
->cmdlog_pos
].jiffies
= jiffies
;
2203 priv
->cmdlog
[priv
->cmdlog_pos
].cmd
.cmd
= cmd
->cmd
;
2204 priv
->cmdlog
[priv
->cmdlog_pos
].cmd
.len
= cmd
->len
;
2205 memcpy(priv
->cmdlog
[priv
->cmdlog_pos
].cmd
.param
, cmd
->param
,
2207 priv
->cmdlog
[priv
->cmdlog_pos
].retcode
= -1;
2210 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2211 get_cmd_string(cmd
->cmd
), cmd
->cmd
, cmd
->len
,
2214 #ifndef DEBUG_CMD_WEP_KEY
2215 if (cmd
->cmd
== IPW_CMD_WEP_KEY
)
2216 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2219 printk_buf(IPW_DL_HOST_COMMAND
, (u8
*) cmd
->param
, cmd
->len
);
2221 rc
= ipw_queue_tx_hcmd(priv
, cmd
->cmd
, cmd
->param
, cmd
->len
, 0);
2223 priv
->status
&= ~STATUS_HCMD_ACTIVE
;
2224 IPW_ERROR("Failed to send %s: Reason %d\n",
2225 get_cmd_string(cmd
->cmd
), rc
);
2226 spin_unlock_irqrestore(&priv
->lock
, flags
);
2229 spin_unlock_irqrestore(&priv
->lock
, flags
);
2231 rc
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
2233 status
& STATUS_HCMD_ACTIVE
),
2234 HOST_COMPLETE_TIMEOUT
);
2236 spin_lock_irqsave(&priv
->lock
, flags
);
2237 if (priv
->status
& STATUS_HCMD_ACTIVE
) {
2238 IPW_ERROR("Failed to send %s: Command timed out.\n",
2239 get_cmd_string(cmd
->cmd
));
2240 priv
->status
&= ~STATUS_HCMD_ACTIVE
;
2241 spin_unlock_irqrestore(&priv
->lock
, flags
);
2245 spin_unlock_irqrestore(&priv
->lock
, flags
);
2249 if (priv
->status
& STATUS_RF_KILL_HW
) {
2250 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2251 get_cmd_string(cmd
->cmd
));
2258 priv
->cmdlog
[priv
->cmdlog_pos
++].retcode
= rc
;
2259 priv
->cmdlog_pos
%= priv
->cmdlog_len
;
2264 static int ipw_send_cmd_simple(struct ipw_priv
*priv
, u8 command
)
2266 struct host_cmd cmd
= {
2270 return __ipw_send_cmd(priv
, &cmd
);
2273 static int ipw_send_cmd_pdu(struct ipw_priv
*priv
, u8 command
, u8 len
,
2276 struct host_cmd cmd
= {
2282 return __ipw_send_cmd(priv
, &cmd
);
2285 static int ipw_send_host_complete(struct ipw_priv
*priv
)
2288 IPW_ERROR("Invalid args\n");
2292 return ipw_send_cmd_simple(priv
, IPW_CMD_HOST_COMPLETE
);
2295 static int ipw_send_system_config(struct ipw_priv
*priv
)
2297 return ipw_send_cmd_pdu(priv
, IPW_CMD_SYSTEM_CONFIG
,
2298 sizeof(priv
->sys_config
),
2302 static int ipw_send_ssid(struct ipw_priv
*priv
, u8
* ssid
, int len
)
2304 if (!priv
|| !ssid
) {
2305 IPW_ERROR("Invalid args\n");
2309 return ipw_send_cmd_pdu(priv
, IPW_CMD_SSID
, min(len
, IW_ESSID_MAX_SIZE
),
2313 static int ipw_send_adapter_address(struct ipw_priv
*priv
, u8
* mac
)
2315 if (!priv
|| !mac
) {
2316 IPW_ERROR("Invalid args\n");
2320 IPW_DEBUG_INFO("%s: Setting MAC to %pM\n",
2321 priv
->net_dev
->name
, mac
);
2323 return ipw_send_cmd_pdu(priv
, IPW_CMD_ADAPTER_ADDRESS
, ETH_ALEN
, mac
);
2327 * NOTE: This must be executed from our workqueue as it results in udelay
2328 * being called which may corrupt the keyboard if executed on default
2331 static void ipw_adapter_restart(void *adapter
)
2333 struct ipw_priv
*priv
= adapter
;
2335 if (priv
->status
& STATUS_RF_KILL_MASK
)
2340 if (priv
->assoc_network
&&
2341 (priv
->assoc_network
->capability
& WLAN_CAPABILITY_IBSS
))
2342 ipw_remove_current_network(priv
);
2345 IPW_ERROR("Failed to up device\n");
2350 static void ipw_bg_adapter_restart(struct work_struct
*work
)
2352 struct ipw_priv
*priv
=
2353 container_of(work
, struct ipw_priv
, adapter_restart
);
2354 mutex_lock(&priv
->mutex
);
2355 ipw_adapter_restart(priv
);
2356 mutex_unlock(&priv
->mutex
);
2359 static void ipw_abort_scan(struct ipw_priv
*priv
);
2361 #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2363 static void ipw_scan_check(void *data
)
2365 struct ipw_priv
*priv
= data
;
2367 if (priv
->status
& STATUS_SCAN_ABORTING
) {
2368 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
2369 "adapter after (%dms).\n",
2370 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG
));
2371 queue_work(priv
->workqueue
, &priv
->adapter_restart
);
2372 } else if (priv
->status
& STATUS_SCANNING
) {
2373 IPW_DEBUG_SCAN("Scan completion watchdog aborting scan "
2375 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG
));
2376 ipw_abort_scan(priv
);
2377 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
, HZ
);
2381 static void ipw_bg_scan_check(struct work_struct
*work
)
2383 struct ipw_priv
*priv
=
2384 container_of(work
, struct ipw_priv
, scan_check
.work
);
2385 mutex_lock(&priv
->mutex
);
2386 ipw_scan_check(priv
);
2387 mutex_unlock(&priv
->mutex
);
2390 static int ipw_send_scan_request_ext(struct ipw_priv
*priv
,
2391 struct ipw_scan_request_ext
*request
)
2393 return ipw_send_cmd_pdu(priv
, IPW_CMD_SCAN_REQUEST_EXT
,
2394 sizeof(*request
), request
);
2397 static int ipw_send_scan_abort(struct ipw_priv
*priv
)
2400 IPW_ERROR("Invalid args\n");
2404 return ipw_send_cmd_simple(priv
, IPW_CMD_SCAN_ABORT
);
2407 static int ipw_set_sensitivity(struct ipw_priv
*priv
, u16 sens
)
2409 struct ipw_sensitivity_calib calib
= {
2410 .beacon_rssi_raw
= cpu_to_le16(sens
),
2413 return ipw_send_cmd_pdu(priv
, IPW_CMD_SENSITIVITY_CALIB
, sizeof(calib
),
2417 static int ipw_send_associate(struct ipw_priv
*priv
,
2418 struct ipw_associate
*associate
)
2420 if (!priv
|| !associate
) {
2421 IPW_ERROR("Invalid args\n");
2425 return ipw_send_cmd_pdu(priv
, IPW_CMD_ASSOCIATE
, sizeof(*associate
),
2429 static int ipw_send_supported_rates(struct ipw_priv
*priv
,
2430 struct ipw_supported_rates
*rates
)
2432 if (!priv
|| !rates
) {
2433 IPW_ERROR("Invalid args\n");
2437 return ipw_send_cmd_pdu(priv
, IPW_CMD_SUPPORTED_RATES
, sizeof(*rates
),
2441 static int ipw_set_random_seed(struct ipw_priv
*priv
)
2446 IPW_ERROR("Invalid args\n");
2450 get_random_bytes(&val
, sizeof(val
));
2452 return ipw_send_cmd_pdu(priv
, IPW_CMD_SEED_NUMBER
, sizeof(val
), &val
);
2455 static int ipw_send_card_disable(struct ipw_priv
*priv
, u32 phy_off
)
2457 __le32 v
= cpu_to_le32(phy_off
);
2459 IPW_ERROR("Invalid args\n");
2463 return ipw_send_cmd_pdu(priv
, IPW_CMD_CARD_DISABLE
, sizeof(v
), &v
);
2466 static int ipw_send_tx_power(struct ipw_priv
*priv
, struct ipw_tx_power
*power
)
2468 if (!priv
|| !power
) {
2469 IPW_ERROR("Invalid args\n");
2473 return ipw_send_cmd_pdu(priv
, IPW_CMD_TX_POWER
, sizeof(*power
), power
);
2476 static int ipw_set_tx_power(struct ipw_priv
*priv
)
2478 const struct libipw_geo
*geo
= libipw_get_geo(priv
->ieee
);
2479 struct ipw_tx_power tx_power
;
2483 memset(&tx_power
, 0, sizeof(tx_power
));
2485 /* configure device for 'G' band */
2486 tx_power
.ieee_mode
= IPW_G_MODE
;
2487 tx_power
.num_channels
= geo
->bg_channels
;
2488 for (i
= 0; i
< geo
->bg_channels
; i
++) {
2489 max_power
= geo
->bg
[i
].max_power
;
2490 tx_power
.channels_tx_power
[i
].channel_number
=
2492 tx_power
.channels_tx_power
[i
].tx_power
= max_power
?
2493 min(max_power
, priv
->tx_power
) : priv
->tx_power
;
2495 if (ipw_send_tx_power(priv
, &tx_power
))
2498 /* configure device to also handle 'B' band */
2499 tx_power
.ieee_mode
= IPW_B_MODE
;
2500 if (ipw_send_tx_power(priv
, &tx_power
))
2503 /* configure device to also handle 'A' band */
2504 if (priv
->ieee
->abg_true
) {
2505 tx_power
.ieee_mode
= IPW_A_MODE
;
2506 tx_power
.num_channels
= geo
->a_channels
;
2507 for (i
= 0; i
< tx_power
.num_channels
; i
++) {
2508 max_power
= geo
->a
[i
].max_power
;
2509 tx_power
.channels_tx_power
[i
].channel_number
=
2511 tx_power
.channels_tx_power
[i
].tx_power
= max_power
?
2512 min(max_power
, priv
->tx_power
) : priv
->tx_power
;
2514 if (ipw_send_tx_power(priv
, &tx_power
))
2520 static int ipw_send_rts_threshold(struct ipw_priv
*priv
, u16 rts
)
2522 struct ipw_rts_threshold rts_threshold
= {
2523 .rts_threshold
= cpu_to_le16(rts
),
2527 IPW_ERROR("Invalid args\n");
2531 return ipw_send_cmd_pdu(priv
, IPW_CMD_RTS_THRESHOLD
,
2532 sizeof(rts_threshold
), &rts_threshold
);
2535 static int ipw_send_frag_threshold(struct ipw_priv
*priv
, u16 frag
)
2537 struct ipw_frag_threshold frag_threshold
= {
2538 .frag_threshold
= cpu_to_le16(frag
),
2542 IPW_ERROR("Invalid args\n");
2546 return ipw_send_cmd_pdu(priv
, IPW_CMD_FRAG_THRESHOLD
,
2547 sizeof(frag_threshold
), &frag_threshold
);
2550 static int ipw_send_power_mode(struct ipw_priv
*priv
, u32 mode
)
2555 IPW_ERROR("Invalid args\n");
2559 /* If on battery, set to 3, if AC set to CAM, else user
2562 case IPW_POWER_BATTERY
:
2563 param
= cpu_to_le32(IPW_POWER_INDEX_3
);
2566 param
= cpu_to_le32(IPW_POWER_MODE_CAM
);
2569 param
= cpu_to_le32(mode
);
2573 return ipw_send_cmd_pdu(priv
, IPW_CMD_POWER_MODE
, sizeof(param
),
2577 static int ipw_send_retry_limit(struct ipw_priv
*priv
, u8 slimit
, u8 llimit
)
2579 struct ipw_retry_limit retry_limit
= {
2580 .short_retry_limit
= slimit
,
2581 .long_retry_limit
= llimit
2585 IPW_ERROR("Invalid args\n");
2589 return ipw_send_cmd_pdu(priv
, IPW_CMD_RETRY_LIMIT
, sizeof(retry_limit
),
2594 * The IPW device contains a Microwire compatible EEPROM that stores
2595 * various data like the MAC address. Usually the firmware has exclusive
2596 * access to the eeprom, but during device initialization (before the
2597 * device driver has sent the HostComplete command to the firmware) the
2598 * device driver has read access to the EEPROM by way of indirect addressing
2599 * through a couple of memory mapped registers.
2601 * The following is a simplified implementation for pulling data out of the
2602 * the eeprom, along with some helper functions to find information in
2603 * the per device private data's copy of the eeprom.
2605 * NOTE: To better understand how these functions work (i.e what is a chip
2606 * select and why do have to keep driving the eeprom clock?), read
2607 * just about any data sheet for a Microwire compatible EEPROM.
2610 /* write a 32 bit value into the indirect accessor register */
2611 static inline void eeprom_write_reg(struct ipw_priv
*p
, u32 data
)
2613 ipw_write_reg32(p
, FW_MEM_REG_EEPROM_ACCESS
, data
);
2615 /* the eeprom requires some time to complete the operation */
2616 udelay(p
->eeprom_delay
);
2619 /* perform a chip select operation */
2620 static void eeprom_cs(struct ipw_priv
*priv
)
2622 eeprom_write_reg(priv
, 0);
2623 eeprom_write_reg(priv
, EEPROM_BIT_CS
);
2624 eeprom_write_reg(priv
, EEPROM_BIT_CS
| EEPROM_BIT_SK
);
2625 eeprom_write_reg(priv
, EEPROM_BIT_CS
);
2628 /* perform a chip select operation */
2629 static void eeprom_disable_cs(struct ipw_priv
*priv
)
2631 eeprom_write_reg(priv
, EEPROM_BIT_CS
);
2632 eeprom_write_reg(priv
, 0);
2633 eeprom_write_reg(priv
, EEPROM_BIT_SK
);
2636 /* push a single bit down to the eeprom */
2637 static inline void eeprom_write_bit(struct ipw_priv
*p
, u8 bit
)
2639 int d
= (bit
? EEPROM_BIT_DI
: 0);
2640 eeprom_write_reg(p
, EEPROM_BIT_CS
| d
);
2641 eeprom_write_reg(p
, EEPROM_BIT_CS
| d
| EEPROM_BIT_SK
);
2644 /* push an opcode followed by an address down to the eeprom */
2645 static void eeprom_op(struct ipw_priv
*priv
, u8 op
, u8 addr
)
2650 eeprom_write_bit(priv
, 1);
2651 eeprom_write_bit(priv
, op
& 2);
2652 eeprom_write_bit(priv
, op
& 1);
2653 for (i
= 7; i
>= 0; i
--) {
2654 eeprom_write_bit(priv
, addr
& (1 << i
));
2658 /* pull 16 bits off the eeprom, one bit at a time */
2659 static u16
eeprom_read_u16(struct ipw_priv
*priv
, u8 addr
)
2664 /* Send READ Opcode */
2665 eeprom_op(priv
, EEPROM_CMD_READ
, addr
);
2667 /* Send dummy bit */
2668 eeprom_write_reg(priv
, EEPROM_BIT_CS
);
2670 /* Read the byte off the eeprom one bit at a time */
2671 for (i
= 0; i
< 16; i
++) {
2673 eeprom_write_reg(priv
, EEPROM_BIT_CS
| EEPROM_BIT_SK
);
2674 eeprom_write_reg(priv
, EEPROM_BIT_CS
);
2675 data
= ipw_read_reg32(priv
, FW_MEM_REG_EEPROM_ACCESS
);
2676 r
= (r
<< 1) | ((data
& EEPROM_BIT_DO
) ? 1 : 0);
2679 /* Send another dummy bit */
2680 eeprom_write_reg(priv
, 0);
2681 eeprom_disable_cs(priv
);
2686 /* helper function for pulling the mac address out of the private */
2687 /* data's copy of the eeprom data */
2688 static void eeprom_parse_mac(struct ipw_priv
*priv
, u8
* mac
)
2690 memcpy(mac
, &priv
->eeprom
[EEPROM_MAC_ADDRESS
], 6);
2694 * Either the device driver (i.e. the host) or the firmware can
2695 * load eeprom data into the designated region in SRAM. If neither
2696 * happens then the FW will shutdown with a fatal error.
2698 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2699 * bit needs region of shared SRAM needs to be non-zero.
2701 static void ipw_eeprom_init_sram(struct ipw_priv
*priv
)
2704 __le16
*eeprom
= (__le16
*) priv
->eeprom
;
2706 IPW_DEBUG_TRACE(">>\n");
2708 /* read entire contents of eeprom into private buffer */
2709 for (i
= 0; i
< 128; i
++)
2710 eeprom
[i
] = cpu_to_le16(eeprom_read_u16(priv
, (u8
) i
));
2713 If the data looks correct, then copy it to our private
2714 copy. Otherwise let the firmware know to perform the operation
2717 if (priv
->eeprom
[EEPROM_VERSION
] != 0) {
2718 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2720 /* write the eeprom data to sram */
2721 for (i
= 0; i
< IPW_EEPROM_IMAGE_SIZE
; i
++)
2722 ipw_write8(priv
, IPW_EEPROM_DATA
+ i
, priv
->eeprom
[i
]);
2724 /* Do not load eeprom data on fatal error or suspend */
2725 ipw_write32(priv
, IPW_EEPROM_LOAD_DISABLE
, 0);
2727 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2729 /* Load eeprom data on fatal error or suspend */
2730 ipw_write32(priv
, IPW_EEPROM_LOAD_DISABLE
, 1);
2733 IPW_DEBUG_TRACE("<<\n");
2736 static void ipw_zero_memory(struct ipw_priv
*priv
, u32 start
, u32 count
)
2741 _ipw_write32(priv
, IPW_AUTOINC_ADDR
, start
);
2743 _ipw_write32(priv
, IPW_AUTOINC_DATA
, 0);
2746 static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv
*priv
)
2748 ipw_zero_memory(priv
, IPW_SHARED_SRAM_DMA_CONTROL
,
2749 CB_NUMBER_OF_ELEMENTS_SMALL
*
2750 sizeof(struct command_block
));
2753 static int ipw_fw_dma_enable(struct ipw_priv
*priv
)
2754 { /* start dma engine but no transfers yet */
2756 IPW_DEBUG_FW(">> :\n");
2759 ipw_fw_dma_reset_command_blocks(priv
);
2761 /* Write CB base address */
2762 ipw_write_reg32(priv
, IPW_DMA_I_CB_BASE
, IPW_SHARED_SRAM_DMA_CONTROL
);
2764 IPW_DEBUG_FW("<< :\n");
2768 static void ipw_fw_dma_abort(struct ipw_priv
*priv
)
2772 IPW_DEBUG_FW(">> :\n");
2774 /* set the Stop and Abort bit */
2775 control
= DMA_CONTROL_SMALL_CB_CONST_VALUE
| DMA_CB_STOP_AND_ABORT
;
2776 ipw_write_reg32(priv
, IPW_DMA_I_DMA_CONTROL
, control
);
2777 priv
->sram_desc
.last_cb_index
= 0;
2779 IPW_DEBUG_FW("<<\n");
2782 static int ipw_fw_dma_write_command_block(struct ipw_priv
*priv
, int index
,
2783 struct command_block
*cb
)
2786 IPW_SHARED_SRAM_DMA_CONTROL
+
2787 (sizeof(struct command_block
) * index
);
2788 IPW_DEBUG_FW(">> :\n");
2790 ipw_write_indirect(priv
, address
, (u8
*) cb
,
2791 (int)sizeof(struct command_block
));
2793 IPW_DEBUG_FW("<< :\n");
2798 static int ipw_fw_dma_kick(struct ipw_priv
*priv
)
2803 IPW_DEBUG_FW(">> :\n");
2805 for (index
= 0; index
< priv
->sram_desc
.last_cb_index
; index
++)
2806 ipw_fw_dma_write_command_block(priv
, index
,
2807 &priv
->sram_desc
.cb_list
[index
]);
2809 /* Enable the DMA in the CSR register */
2810 ipw_clear_bit(priv
, IPW_RESET_REG
,
2811 IPW_RESET_REG_MASTER_DISABLED
|
2812 IPW_RESET_REG_STOP_MASTER
);
2814 /* Set the Start bit. */
2815 control
= DMA_CONTROL_SMALL_CB_CONST_VALUE
| DMA_CB_START
;
2816 ipw_write_reg32(priv
, IPW_DMA_I_DMA_CONTROL
, control
);
2818 IPW_DEBUG_FW("<< :\n");
2822 static void ipw_fw_dma_dump_command_block(struct ipw_priv
*priv
)
2825 u32 register_value
= 0;
2826 u32 cb_fields_address
= 0;
2828 IPW_DEBUG_FW(">> :\n");
2829 address
= ipw_read_reg32(priv
, IPW_DMA_I_CURRENT_CB
);
2830 IPW_DEBUG_FW_INFO("Current CB is 0x%x\n", address
);
2832 /* Read the DMA Controlor register */
2833 register_value
= ipw_read_reg32(priv
, IPW_DMA_I_DMA_CONTROL
);
2834 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x\n", register_value
);
2836 /* Print the CB values */
2837 cb_fields_address
= address
;
2838 register_value
= ipw_read_reg32(priv
, cb_fields_address
);
2839 IPW_DEBUG_FW_INFO("Current CB Control Field is 0x%x\n", register_value
);
2841 cb_fields_address
+= sizeof(u32
);
2842 register_value
= ipw_read_reg32(priv
, cb_fields_address
);
2843 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x\n", register_value
);
2845 cb_fields_address
+= sizeof(u32
);
2846 register_value
= ipw_read_reg32(priv
, cb_fields_address
);
2847 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x\n",
2850 cb_fields_address
+= sizeof(u32
);
2851 register_value
= ipw_read_reg32(priv
, cb_fields_address
);
2852 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x\n", register_value
);
2854 IPW_DEBUG_FW(">> :\n");
2857 static int ipw_fw_dma_command_block_index(struct ipw_priv
*priv
)
2859 u32 current_cb_address
= 0;
2860 u32 current_cb_index
= 0;
2862 IPW_DEBUG_FW("<< :\n");
2863 current_cb_address
= ipw_read_reg32(priv
, IPW_DMA_I_CURRENT_CB
);
2865 current_cb_index
= (current_cb_address
- IPW_SHARED_SRAM_DMA_CONTROL
) /
2866 sizeof(struct command_block
);
2868 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X\n",
2869 current_cb_index
, current_cb_address
);
2871 IPW_DEBUG_FW(">> :\n");
2872 return current_cb_index
;
2876 static int ipw_fw_dma_add_command_block(struct ipw_priv
*priv
,
2880 int interrupt_enabled
, int is_last
)
2883 u32 control
= CB_VALID
| CB_SRC_LE
| CB_DEST_LE
| CB_SRC_AUTOINC
|
2884 CB_SRC_IO_GATED
| CB_DEST_AUTOINC
| CB_SRC_SIZE_LONG
|
2886 struct command_block
*cb
;
2887 u32 last_cb_element
= 0;
2889 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2890 src_address
, dest_address
, length
);
2892 if (priv
->sram_desc
.last_cb_index
>= CB_NUMBER_OF_ELEMENTS_SMALL
)
2895 last_cb_element
= priv
->sram_desc
.last_cb_index
;
2896 cb
= &priv
->sram_desc
.cb_list
[last_cb_element
];
2897 priv
->sram_desc
.last_cb_index
++;
2899 /* Calculate the new CB control word */
2900 if (interrupt_enabled
)
2901 control
|= CB_INT_ENABLED
;
2904 control
|= CB_LAST_VALID
;
2908 /* Calculate the CB Element's checksum value */
2909 cb
->status
= control
^ src_address
^ dest_address
;
2911 /* Copy the Source and Destination addresses */
2912 cb
->dest_addr
= dest_address
;
2913 cb
->source_addr
= src_address
;
2915 /* Copy the Control Word last */
2916 cb
->control
= control
;
2921 static int ipw_fw_dma_add_buffer(struct ipw_priv
*priv
, dma_addr_t
*src_address
,
2922 int nr
, u32 dest_address
, u32 len
)
2927 IPW_DEBUG_FW(">>\n");
2928 IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n",
2929 nr
, dest_address
, len
);
2931 for (i
= 0; i
< nr
; i
++) {
2932 size
= min_t(u32
, len
- i
* CB_MAX_LENGTH
, CB_MAX_LENGTH
);
2933 ret
= ipw_fw_dma_add_command_block(priv
, src_address
[i
],
2935 i
* CB_MAX_LENGTH
, size
,
2938 IPW_DEBUG_FW_INFO(": Failed\n");
2941 IPW_DEBUG_FW_INFO(": Added new cb\n");
2944 IPW_DEBUG_FW("<<\n");
2948 static int ipw_fw_dma_wait(struct ipw_priv
*priv
)
2950 u32 current_index
= 0, previous_index
;
2953 IPW_DEBUG_FW(">> :\n");
2955 current_index
= ipw_fw_dma_command_block_index(priv
);
2956 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
2957 (int)priv
->sram_desc
.last_cb_index
);
2959 while (current_index
< priv
->sram_desc
.last_cb_index
) {
2961 previous_index
= current_index
;
2962 current_index
= ipw_fw_dma_command_block_index(priv
);
2964 if (previous_index
< current_index
) {
2968 if (++watchdog
> 400) {
2969 IPW_DEBUG_FW_INFO("Timeout\n");
2970 ipw_fw_dma_dump_command_block(priv
);
2971 ipw_fw_dma_abort(priv
);
2976 ipw_fw_dma_abort(priv
);
2978 /*Disable the DMA in the CSR register */
2979 ipw_set_bit(priv
, IPW_RESET_REG
,
2980 IPW_RESET_REG_MASTER_DISABLED
| IPW_RESET_REG_STOP_MASTER
);
2982 IPW_DEBUG_FW("<< dmaWaitSync\n");
2986 static void ipw_remove_current_network(struct ipw_priv
*priv
)
2988 struct list_head
*element
, *safe
;
2989 struct libipw_network
*network
= NULL
;
2990 unsigned long flags
;
2992 spin_lock_irqsave(&priv
->ieee
->lock
, flags
);
2993 list_for_each_safe(element
, safe
, &priv
->ieee
->network_list
) {
2994 network
= list_entry(element
, struct libipw_network
, list
);
2995 if (!memcmp(network
->bssid
, priv
->bssid
, ETH_ALEN
)) {
2997 list_add_tail(&network
->list
,
2998 &priv
->ieee
->network_free_list
);
3001 spin_unlock_irqrestore(&priv
->ieee
->lock
, flags
);
3005 * Check that card is still alive.
3006 * Reads debug register from domain0.
3007 * If card is present, pre-defined value should
3011 * @return 1 if card is present, 0 otherwise
3013 static inline int ipw_alive(struct ipw_priv
*priv
)
3015 return ipw_read32(priv
, 0x90) == 0xd55555d5;
3018 /* timeout in msec, attempted in 10-msec quanta */
3019 static int ipw_poll_bit(struct ipw_priv
*priv
, u32 addr
, u32 mask
,
3025 if ((ipw_read32(priv
, addr
) & mask
) == mask
)
3029 } while (i
< timeout
);
3034 /* These functions load the firmware and micro code for the operation of
3035 * the ipw hardware. It assumes the buffer has all the bits for the
3036 * image and the caller is handling the memory allocation and clean up.
3039 static int ipw_stop_master(struct ipw_priv
*priv
)
3043 IPW_DEBUG_TRACE(">>\n");
3044 /* stop master. typical delay - 0 */
3045 ipw_set_bit(priv
, IPW_RESET_REG
, IPW_RESET_REG_STOP_MASTER
);
3047 /* timeout is in msec, polled in 10-msec quanta */
3048 rc
= ipw_poll_bit(priv
, IPW_RESET_REG
,
3049 IPW_RESET_REG_MASTER_DISABLED
, 100);
3051 IPW_ERROR("wait for stop master failed after 100ms\n");
3055 IPW_DEBUG_INFO("stop master %dms\n", rc
);
3060 static void ipw_arc_release(struct ipw_priv
*priv
)
3062 IPW_DEBUG_TRACE(">>\n");
3065 ipw_clear_bit(priv
, IPW_RESET_REG
, CBD_RESET_REG_PRINCETON_RESET
);
3067 /* no one knows timing, for safety add some delay */
3076 static int ipw_load_ucode(struct ipw_priv
*priv
, u8
* data
, size_t len
)
3078 int rc
= 0, i
, addr
;
3082 image
= (__le16
*) data
;
3084 IPW_DEBUG_TRACE(">>\n");
3086 rc
= ipw_stop_master(priv
);
3091 for (addr
= IPW_SHARED_LOWER_BOUND
;
3092 addr
< IPW_REGISTER_DOMAIN1_END
; addr
+= 4) {
3093 ipw_write32(priv
, addr
, 0);
3096 /* no ucode (yet) */
3097 memset(&priv
->dino_alive
, 0, sizeof(priv
->dino_alive
));
3098 /* destroy DMA queues */
3099 /* reset sequence */
3101 ipw_write_reg32(priv
, IPW_MEM_HALT_AND_RESET
, IPW_BIT_HALT_RESET_ON
);
3102 ipw_arc_release(priv
);
3103 ipw_write_reg32(priv
, IPW_MEM_HALT_AND_RESET
, IPW_BIT_HALT_RESET_OFF
);
3107 ipw_write_reg32(priv
, IPW_INTERNAL_CMD_EVENT
, IPW_BASEBAND_POWER_DOWN
);
3110 ipw_write_reg32(priv
, IPW_INTERNAL_CMD_EVENT
, 0);
3113 /* enable ucode store */
3114 ipw_write_reg8(priv
, IPW_BASEBAND_CONTROL_STATUS
, 0x0);
3115 ipw_write_reg8(priv
, IPW_BASEBAND_CONTROL_STATUS
, DINO_ENABLE_CS
);
3121 * Do NOT set indirect address register once and then
3122 * store data to indirect data register in the loop.
3123 * It seems very reasonable, but in this case DINO do not
3124 * accept ucode. It is essential to set address each time.
3126 /* load new ipw uCode */
3127 for (i
= 0; i
< len
/ 2; i
++)
3128 ipw_write_reg16(priv
, IPW_BASEBAND_CONTROL_STORE
,
3129 le16_to_cpu(image
[i
]));
3132 ipw_write_reg8(priv
, IPW_BASEBAND_CONTROL_STATUS
, 0);
3133 ipw_write_reg8(priv
, IPW_BASEBAND_CONTROL_STATUS
, DINO_ENABLE_SYSTEM
);
3135 /* this is where the igx / win driver deveates from the VAP driver. */
3137 /* wait for alive response */
3138 for (i
= 0; i
< 100; i
++) {
3139 /* poll for incoming data */
3140 cr
= ipw_read_reg8(priv
, IPW_BASEBAND_CONTROL_STATUS
);
3141 if (cr
& DINO_RXFIFO_DATA
)
3146 if (cr
& DINO_RXFIFO_DATA
) {
3147 /* alive_command_responce size is NOT multiple of 4 */
3148 __le32 response_buffer
[(sizeof(priv
->dino_alive
) + 3) / 4];
3150 for (i
= 0; i
< ARRAY_SIZE(response_buffer
); i
++)
3151 response_buffer
[i
] =
3152 cpu_to_le32(ipw_read_reg32(priv
,
3153 IPW_BASEBAND_RX_FIFO_READ
));
3154 memcpy(&priv
->dino_alive
, response_buffer
,
3155 sizeof(priv
->dino_alive
));
3156 if (priv
->dino_alive
.alive_command
== 1
3157 && priv
->dino_alive
.ucode_valid
== 1) {
3160 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3161 "of %02d/%02d/%02d %02d:%02d\n",
3162 priv
->dino_alive
.software_revision
,
3163 priv
->dino_alive
.software_revision
,
3164 priv
->dino_alive
.device_identifier
,
3165 priv
->dino_alive
.device_identifier
,
3166 priv
->dino_alive
.time_stamp
[0],
3167 priv
->dino_alive
.time_stamp
[1],
3168 priv
->dino_alive
.time_stamp
[2],
3169 priv
->dino_alive
.time_stamp
[3],
3170 priv
->dino_alive
.time_stamp
[4]);
3172 IPW_DEBUG_INFO("Microcode is not alive\n");
3176 IPW_DEBUG_INFO("No alive response from DINO\n");
3180 /* disable DINO, otherwise for some reason
3181 firmware have problem getting alive resp. */
3182 ipw_write_reg8(priv
, IPW_BASEBAND_CONTROL_STATUS
, 0);
3187 static int ipw_load_firmware(struct ipw_priv
*priv
, u8
* data
, size_t len
)
3191 struct fw_chunk
*chunk
;
3194 struct pci_pool
*pool
;
3198 IPW_DEBUG_TRACE("<< :\n");
3200 virts
= kmalloc(sizeof(void *) * CB_NUMBER_OF_ELEMENTS_SMALL
,
3205 phys
= kmalloc(sizeof(dma_addr_t
) * CB_NUMBER_OF_ELEMENTS_SMALL
,
3211 pool
= pci_pool_create("ipw2200", priv
->pci_dev
, CB_MAX_LENGTH
, 0, 0);
3213 IPW_ERROR("pci_pool_create failed\n");
3220 ret
= ipw_fw_dma_enable(priv
);
3222 /* the DMA is already ready this would be a bug. */
3223 BUG_ON(priv
->sram_desc
.last_cb_index
> 0);
3231 chunk
= (struct fw_chunk
*)(data
+ offset
);
3232 offset
+= sizeof(struct fw_chunk
);
3233 chunk_len
= le32_to_cpu(chunk
->length
);
3234 start
= data
+ offset
;
3236 nr
= (chunk_len
+ CB_MAX_LENGTH
- 1) / CB_MAX_LENGTH
;
3237 for (i
= 0; i
< nr
; i
++) {
3238 virts
[total_nr
] = pci_pool_alloc(pool
, GFP_KERNEL
,
3240 if (!virts
[total_nr
]) {
3244 size
= min_t(u32
, chunk_len
- i
* CB_MAX_LENGTH
,
3246 memcpy(virts
[total_nr
], start
, size
);
3249 /* We don't support fw chunk larger than 64*8K */
3250 BUG_ON(total_nr
> CB_NUMBER_OF_ELEMENTS_SMALL
);
3253 /* build DMA packet and queue up for sending */
3254 /* dma to chunk->address, the chunk->length bytes from data +
3257 ret
= ipw_fw_dma_add_buffer(priv
, &phys
[total_nr
- nr
],
3258 nr
, le32_to_cpu(chunk
->address
),
3261 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3265 offset
+= chunk_len
;
3266 } while (offset
< len
);
3268 /* Run the DMA and wait for the answer */
3269 ret
= ipw_fw_dma_kick(priv
);
3271 IPW_ERROR("dmaKick Failed\n");
3275 ret
= ipw_fw_dma_wait(priv
);
3277 IPW_ERROR("dmaWaitSync Failed\n");
3281 for (i
= 0; i
< total_nr
; i
++)
3282 pci_pool_free(pool
, virts
[i
], phys
[i
]);
3284 pci_pool_destroy(pool
);
3292 static int ipw_stop_nic(struct ipw_priv
*priv
)
3297 ipw_write32(priv
, IPW_RESET_REG
, IPW_RESET_REG_STOP_MASTER
);
3299 rc
= ipw_poll_bit(priv
, IPW_RESET_REG
,
3300 IPW_RESET_REG_MASTER_DISABLED
, 500);
3302 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
3306 ipw_set_bit(priv
, IPW_RESET_REG
, CBD_RESET_REG_PRINCETON_RESET
);
3311 static void ipw_start_nic(struct ipw_priv
*priv
)
3313 IPW_DEBUG_TRACE(">>\n");
3315 /* prvHwStartNic release ARC */
3316 ipw_clear_bit(priv
, IPW_RESET_REG
,
3317 IPW_RESET_REG_MASTER_DISABLED
|
3318 IPW_RESET_REG_STOP_MASTER
|
3319 CBD_RESET_REG_PRINCETON_RESET
);
3321 /* enable power management */
3322 ipw_set_bit(priv
, IPW_GP_CNTRL_RW
,
3323 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY
);
3325 IPW_DEBUG_TRACE("<<\n");
3328 static int ipw_init_nic(struct ipw_priv
*priv
)
3332 IPW_DEBUG_TRACE(">>\n");
3335 /* set "initialization complete" bit to move adapter to D0 state */
3336 ipw_set_bit(priv
, IPW_GP_CNTRL_RW
, IPW_GP_CNTRL_BIT_INIT_DONE
);
3338 /* low-level PLL activation */
3339 ipw_write32(priv
, IPW_READ_INT_REGISTER
,
3340 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER
);
3342 /* wait for clock stabilization */
3343 rc
= ipw_poll_bit(priv
, IPW_GP_CNTRL_RW
,
3344 IPW_GP_CNTRL_BIT_CLOCK_READY
, 250);
3346 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3348 /* assert SW reset */
3349 ipw_set_bit(priv
, IPW_RESET_REG
, IPW_RESET_REG_SW_RESET
);
3353 /* set "initialization complete" bit to move adapter to D0 state */
3354 ipw_set_bit(priv
, IPW_GP_CNTRL_RW
, IPW_GP_CNTRL_BIT_INIT_DONE
);
3356 IPW_DEBUG_TRACE(">>\n");
3360 /* Call this function from process context, it will sleep in request_firmware.
3361 * Probe is an ok place to call this from.
3363 static int ipw_reset_nic(struct ipw_priv
*priv
)
3366 unsigned long flags
;
3368 IPW_DEBUG_TRACE(">>\n");
3370 rc
= ipw_init_nic(priv
);
3372 spin_lock_irqsave(&priv
->lock
, flags
);
3373 /* Clear the 'host command active' bit... */
3374 priv
->status
&= ~STATUS_HCMD_ACTIVE
;
3375 wake_up_interruptible(&priv
->wait_command_queue
);
3376 priv
->status
&= ~(STATUS_SCANNING
| STATUS_SCAN_ABORTING
);
3377 wake_up_interruptible(&priv
->wait_state
);
3378 spin_unlock_irqrestore(&priv
->lock
, flags
);
3380 IPW_DEBUG_TRACE("<<\n");
3393 static int ipw_get_fw(struct ipw_priv
*priv
,
3394 const struct firmware
**raw
, const char *name
)
3399 /* ask firmware_class module to get the boot firmware off disk */
3400 rc
= request_firmware(raw
, name
, &priv
->pci_dev
->dev
);
3402 IPW_ERROR("%s request_firmware failed: Reason %d\n", name
, rc
);
3406 if ((*raw
)->size
< sizeof(*fw
)) {
3407 IPW_ERROR("%s is too small (%zd)\n", name
, (*raw
)->size
);
3411 fw
= (void *)(*raw
)->data
;
3413 if ((*raw
)->size
< sizeof(*fw
) + le32_to_cpu(fw
->boot_size
) +
3414 le32_to_cpu(fw
->ucode_size
) + le32_to_cpu(fw
->fw_size
)) {
3415 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3416 name
, (*raw
)->size
);
3420 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
3422 le32_to_cpu(fw
->ver
) >> 16,
3423 le32_to_cpu(fw
->ver
) & 0xff,
3424 (*raw
)->size
- sizeof(*fw
));
3428 #define IPW_RX_BUF_SIZE (3000)
3430 static void ipw_rx_queue_reset(struct ipw_priv
*priv
,
3431 struct ipw_rx_queue
*rxq
)
3433 unsigned long flags
;
3436 spin_lock_irqsave(&rxq
->lock
, flags
);
3438 INIT_LIST_HEAD(&rxq
->rx_free
);
3439 INIT_LIST_HEAD(&rxq
->rx_used
);
3441 /* Fill the rx_used queue with _all_ of the Rx buffers */
3442 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++) {
3443 /* In the reset function, these buffers may have been allocated
3444 * to an SKB, so we need to unmap and free potential storage */
3445 if (rxq
->pool
[i
].skb
!= NULL
) {
3446 pci_unmap_single(priv
->pci_dev
, rxq
->pool
[i
].dma_addr
,
3447 IPW_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
3448 dev_kfree_skb(rxq
->pool
[i
].skb
);
3449 rxq
->pool
[i
].skb
= NULL
;
3451 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
3454 /* Set us so that we have processed and used all buffers, but have
3455 * not restocked the Rx queue with fresh buffers */
3456 rxq
->read
= rxq
->write
= 0;
3457 rxq
->free_count
= 0;
3458 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3462 static int fw_loaded
= 0;
3463 static const struct firmware
*raw
= NULL
;
3465 static void free_firmware(void)
3468 release_firmware(raw
);
3474 #define free_firmware() do {} while (0)
3477 static int ipw_load(struct ipw_priv
*priv
)
3480 const struct firmware
*raw
= NULL
;
3483 u8
*boot_img
, *ucode_img
, *fw_img
;
3485 int rc
= 0, retries
= 3;
3487 switch (priv
->ieee
->iw_mode
) {
3489 name
= "ipw2200-ibss.fw";
3491 #ifdef CONFIG_IPW2200_MONITOR
3492 case IW_MODE_MONITOR
:
3493 name
= "ipw2200-sniffer.fw";
3497 name
= "ipw2200-bss.fw";
3509 rc
= ipw_get_fw(priv
, &raw
, name
);
3516 fw
= (void *)raw
->data
;
3517 boot_img
= &fw
->data
[0];
3518 ucode_img
= &fw
->data
[le32_to_cpu(fw
->boot_size
)];
3519 fw_img
= &fw
->data
[le32_to_cpu(fw
->boot_size
) +
3520 le32_to_cpu(fw
->ucode_size
)];
3526 priv
->rxq
= ipw_rx_queue_alloc(priv
);
3528 ipw_rx_queue_reset(priv
, priv
->rxq
);
3530 IPW_ERROR("Unable to initialize Rx queue\n");
3535 /* Ensure interrupts are disabled */
3536 ipw_write32(priv
, IPW_INTA_MASK_R
, ~IPW_INTA_MASK_ALL
);
3537 priv
->status
&= ~STATUS_INT_ENABLED
;
3539 /* ack pending interrupts */
3540 ipw_write32(priv
, IPW_INTA_RW
, IPW_INTA_MASK_ALL
);
3544 rc
= ipw_reset_nic(priv
);
3546 IPW_ERROR("Unable to reset NIC\n");
3550 ipw_zero_memory(priv
, IPW_NIC_SRAM_LOWER_BOUND
,
3551 IPW_NIC_SRAM_UPPER_BOUND
- IPW_NIC_SRAM_LOWER_BOUND
);
3553 /* DMA the initial boot firmware into the device */
3554 rc
= ipw_load_firmware(priv
, boot_img
, le32_to_cpu(fw
->boot_size
));
3556 IPW_ERROR("Unable to load boot firmware: %d\n", rc
);
3560 /* kick start the device */
3561 ipw_start_nic(priv
);
3563 /* wait for the device to finish its initial startup sequence */
3564 rc
= ipw_poll_bit(priv
, IPW_INTA_RW
,
3565 IPW_INTA_BIT_FW_INITIALIZATION_DONE
, 500);
3567 IPW_ERROR("device failed to boot initial fw image\n");
3570 IPW_DEBUG_INFO("initial device response after %dms\n", rc
);
3572 /* ack fw init done interrupt */
3573 ipw_write32(priv
, IPW_INTA_RW
, IPW_INTA_BIT_FW_INITIALIZATION_DONE
);
3575 /* DMA the ucode into the device */
3576 rc
= ipw_load_ucode(priv
, ucode_img
, le32_to_cpu(fw
->ucode_size
));
3578 IPW_ERROR("Unable to load ucode: %d\n", rc
);
3585 /* DMA bss firmware into the device */
3586 rc
= ipw_load_firmware(priv
, fw_img
, le32_to_cpu(fw
->fw_size
));
3588 IPW_ERROR("Unable to load firmware: %d\n", rc
);
3595 ipw_write32(priv
, IPW_EEPROM_LOAD_DISABLE
, 0);
3597 rc
= ipw_queue_reset(priv
);
3599 IPW_ERROR("Unable to initialize queues\n");
3603 /* Ensure interrupts are disabled */
3604 ipw_write32(priv
, IPW_INTA_MASK_R
, ~IPW_INTA_MASK_ALL
);
3605 /* ack pending interrupts */
3606 ipw_write32(priv
, IPW_INTA_RW
, IPW_INTA_MASK_ALL
);
3608 /* kick start the device */
3609 ipw_start_nic(priv
);
3611 if (ipw_read32(priv
, IPW_INTA_RW
) & IPW_INTA_BIT_PARITY_ERROR
) {
3613 IPW_WARNING("Parity error. Retrying init.\n");
3618 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3623 /* wait for the device */
3624 rc
= ipw_poll_bit(priv
, IPW_INTA_RW
,
3625 IPW_INTA_BIT_FW_INITIALIZATION_DONE
, 500);
3627 IPW_ERROR("device failed to start within 500ms\n");
3630 IPW_DEBUG_INFO("device response after %dms\n", rc
);
3632 /* ack fw init done interrupt */
3633 ipw_write32(priv
, IPW_INTA_RW
, IPW_INTA_BIT_FW_INITIALIZATION_DONE
);
3635 /* read eeprom data and initialize the eeprom region of sram */
3636 priv
->eeprom_delay
= 1;
3637 ipw_eeprom_init_sram(priv
);
3639 /* enable interrupts */
3640 ipw_enable_interrupts(priv
);
3642 /* Ensure our queue has valid packets */
3643 ipw_rx_queue_replenish(priv
);
3645 ipw_write32(priv
, IPW_RX_READ_INDEX
, priv
->rxq
->read
);
3647 /* ack pending interrupts */
3648 ipw_write32(priv
, IPW_INTA_RW
, IPW_INTA_MASK_ALL
);
3651 release_firmware(raw
);
3657 ipw_rx_queue_free(priv
, priv
->rxq
);
3660 ipw_tx_queue_free(priv
);
3662 release_firmware(raw
);
3674 * Theory of operation
3676 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3677 * 2 empty entries always kept in the buffer to protect from overflow.
3679 * For Tx queue, there are low mark and high mark limits. If, after queuing
3680 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3681 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
3684 * The IPW operates with six queues, one receive queue in the device's
3685 * sram, one transmit queue for sending commands to the device firmware,
3686 * and four transmit queues for data.
3688 * The four transmit queues allow for performing quality of service (qos)
3689 * transmissions as per the 802.11 protocol. Currently Linux does not
3690 * provide a mechanism to the user for utilizing prioritized queues, so
3691 * we only utilize the first data transmit queue (queue1).
3695 * Driver allocates buffers of this size for Rx
3699 * ipw_rx_queue_space - Return number of free slots available in queue.
3701 static int ipw_rx_queue_space(const struct ipw_rx_queue
*q
)
3703 int s
= q
->read
- q
->write
;
3706 /* keep some buffer to not confuse full and empty queue */
3713 static inline int ipw_tx_queue_space(const struct clx2_queue
*q
)
3715 int s
= q
->last_used
- q
->first_empty
;
3718 s
-= 2; /* keep some reserve to not confuse empty and full situations */
3724 static inline int ipw_queue_inc_wrap(int index
, int n_bd
)
3726 return (++index
== n_bd
) ? 0 : index
;
3730 * Initialize common DMA queue structure
3732 * @param q queue to init
3733 * @param count Number of BD's to allocate. Should be power of 2
3734 * @param read_register Address for 'read' register
3735 * (not offset within BAR, full address)
3736 * @param write_register Address for 'write' register
3737 * (not offset within BAR, full address)
3738 * @param base_register Address for 'base' register
3739 * (not offset within BAR, full address)
3740 * @param size Address for 'size' register
3741 * (not offset within BAR, full address)
3743 static void ipw_queue_init(struct ipw_priv
*priv
, struct clx2_queue
*q
,
3744 int count
, u32 read
, u32 write
, u32 base
, u32 size
)
3748 q
->low_mark
= q
->n_bd
/ 4;
3749 if (q
->low_mark
< 4)
3752 q
->high_mark
= q
->n_bd
/ 8;
3753 if (q
->high_mark
< 2)
3756 q
->first_empty
= q
->last_used
= 0;
3760 ipw_write32(priv
, base
, q
->dma_addr
);
3761 ipw_write32(priv
, size
, count
);
3762 ipw_write32(priv
, read
, 0);
3763 ipw_write32(priv
, write
, 0);
3765 _ipw_read32(priv
, 0x90);
3768 static int ipw_queue_tx_init(struct ipw_priv
*priv
,
3769 struct clx2_tx_queue
*q
,
3770 int count
, u32 read
, u32 write
, u32 base
, u32 size
)
3772 struct pci_dev
*dev
= priv
->pci_dev
;
3774 q
->txb
= kmalloc(sizeof(q
->txb
[0]) * count
, GFP_KERNEL
);
3776 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3781 pci_alloc_consistent(dev
, sizeof(q
->bd
[0]) * count
, &q
->q
.dma_addr
);
3783 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
3784 sizeof(q
->bd
[0]) * count
);
3790 ipw_queue_init(priv
, &q
->q
, count
, read
, write
, base
, size
);
3795 * Free one TFD, those at index [txq->q.last_used].
3796 * Do NOT advance any indexes
3801 static void ipw_queue_tx_free_tfd(struct ipw_priv
*priv
,
3802 struct clx2_tx_queue
*txq
)
3804 struct tfd_frame
*bd
= &txq
->bd
[txq
->q
.last_used
];
3805 struct pci_dev
*dev
= priv
->pci_dev
;
3809 if (bd
->control_flags
.message_type
== TX_HOST_COMMAND_TYPE
)
3810 /* nothing to cleanup after for host commands */
3814 if (le32_to_cpu(bd
->u
.data
.num_chunks
) > NUM_TFD_CHUNKS
) {
3815 IPW_ERROR("Too many chunks: %i\n",
3816 le32_to_cpu(bd
->u
.data
.num_chunks
));
3817 /** @todo issue fatal error, it is quite serious situation */
3821 /* unmap chunks if any */
3822 for (i
= 0; i
< le32_to_cpu(bd
->u
.data
.num_chunks
); i
++) {
3823 pci_unmap_single(dev
, le32_to_cpu(bd
->u
.data
.chunk_ptr
[i
]),
3824 le16_to_cpu(bd
->u
.data
.chunk_len
[i
]),
3826 if (txq
->txb
[txq
->q
.last_used
]) {
3827 libipw_txb_free(txq
->txb
[txq
->q
.last_used
]);
3828 txq
->txb
[txq
->q
.last_used
] = NULL
;
3834 * Deallocate DMA queue.
3836 * Empty queue by removing and destroying all BD's.
3842 static void ipw_queue_tx_free(struct ipw_priv
*priv
, struct clx2_tx_queue
*txq
)
3844 struct clx2_queue
*q
= &txq
->q
;
3845 struct pci_dev
*dev
= priv
->pci_dev
;
3850 /* first, empty all BD's */
3851 for (; q
->first_empty
!= q
->last_used
;
3852 q
->last_used
= ipw_queue_inc_wrap(q
->last_used
, q
->n_bd
)) {
3853 ipw_queue_tx_free_tfd(priv
, txq
);
3856 /* free buffers belonging to queue itself */
3857 pci_free_consistent(dev
, sizeof(txq
->bd
[0]) * q
->n_bd
, txq
->bd
,
3861 /* 0 fill whole structure */
3862 memset(txq
, 0, sizeof(*txq
));
3866 * Destroy all DMA queues and structures
3870 static void ipw_tx_queue_free(struct ipw_priv
*priv
)
3873 ipw_queue_tx_free(priv
, &priv
->txq_cmd
);
3876 ipw_queue_tx_free(priv
, &priv
->txq
[0]);
3877 ipw_queue_tx_free(priv
, &priv
->txq
[1]);
3878 ipw_queue_tx_free(priv
, &priv
->txq
[2]);
3879 ipw_queue_tx_free(priv
, &priv
->txq
[3]);
3882 static void ipw_create_bssid(struct ipw_priv
*priv
, u8
* bssid
)
3884 /* First 3 bytes are manufacturer */
3885 bssid
[0] = priv
->mac_addr
[0];
3886 bssid
[1] = priv
->mac_addr
[1];
3887 bssid
[2] = priv
->mac_addr
[2];
3889 /* Last bytes are random */
3890 get_random_bytes(&bssid
[3], ETH_ALEN
- 3);
3892 bssid
[0] &= 0xfe; /* clear multicast bit */
3893 bssid
[0] |= 0x02; /* set local assignment bit (IEEE802) */
3896 static u8
ipw_add_station(struct ipw_priv
*priv
, u8
* bssid
)
3898 struct ipw_station_entry entry
;
3901 for (i
= 0; i
< priv
->num_stations
; i
++) {
3902 if (!memcmp(priv
->stations
[i
], bssid
, ETH_ALEN
)) {
3903 /* Another node is active in network */
3904 priv
->missed_adhoc_beacons
= 0;
3905 if (!(priv
->config
& CFG_STATIC_CHANNEL
))
3906 /* when other nodes drop out, we drop out */
3907 priv
->config
&= ~CFG_ADHOC_PERSIST
;
3913 if (i
== MAX_STATIONS
)
3914 return IPW_INVALID_STATION
;
3916 IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid
);
3919 entry
.support_mode
= 0;
3920 memcpy(entry
.mac_addr
, bssid
, ETH_ALEN
);
3921 memcpy(priv
->stations
[i
], bssid
, ETH_ALEN
);
3922 ipw_write_direct(priv
, IPW_STATION_TABLE_LOWER
+ i
* sizeof(entry
),
3923 &entry
, sizeof(entry
));
3924 priv
->num_stations
++;
3929 static u8
ipw_find_station(struct ipw_priv
*priv
, u8
* bssid
)
3933 for (i
= 0; i
< priv
->num_stations
; i
++)
3934 if (!memcmp(priv
->stations
[i
], bssid
, ETH_ALEN
))
3937 return IPW_INVALID_STATION
;
3940 static void ipw_send_disassociate(struct ipw_priv
*priv
, int quiet
)
3944 if (priv
->status
& STATUS_ASSOCIATING
) {
3945 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3946 queue_work(priv
->workqueue
, &priv
->disassociate
);
3950 if (!(priv
->status
& STATUS_ASSOCIATED
)) {
3951 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3955 IPW_DEBUG_ASSOC("Disassocation attempt from %pM "
3957 priv
->assoc_request
.bssid
,
3958 priv
->assoc_request
.channel
);
3960 priv
->status
&= ~(STATUS_ASSOCIATING
| STATUS_ASSOCIATED
);
3961 priv
->status
|= STATUS_DISASSOCIATING
;
3964 priv
->assoc_request
.assoc_type
= HC_DISASSOC_QUIET
;
3966 priv
->assoc_request
.assoc_type
= HC_DISASSOCIATE
;
3968 err
= ipw_send_associate(priv
, &priv
->assoc_request
);
3970 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3977 static int ipw_disassociate(void *data
)
3979 struct ipw_priv
*priv
= data
;
3980 if (!(priv
->status
& (STATUS_ASSOCIATED
| STATUS_ASSOCIATING
)))
3982 ipw_send_disassociate(data
, 0);
3983 netif_carrier_off(priv
->net_dev
);
3987 static void ipw_bg_disassociate(struct work_struct
*work
)
3989 struct ipw_priv
*priv
=
3990 container_of(work
, struct ipw_priv
, disassociate
);
3991 mutex_lock(&priv
->mutex
);
3992 ipw_disassociate(priv
);
3993 mutex_unlock(&priv
->mutex
);
3996 static void ipw_system_config(struct work_struct
*work
)
3998 struct ipw_priv
*priv
=
3999 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
&= LIBIPW_CCK_RATES_MASK
;
4148 /* TODO: Verify that the rate is supported by the current rates
4151 while (i
&& !(mask
& i
))
4154 case LIBIPW_CCK_RATE_1MB_MASK
:
4156 case LIBIPW_CCK_RATE_2MB_MASK
:
4158 case LIBIPW_CCK_RATE_5MB_MASK
:
4160 case LIBIPW_OFDM_RATE_6MB_MASK
:
4162 case LIBIPW_OFDM_RATE_9MB_MASK
:
4164 case LIBIPW_CCK_RATE_11MB_MASK
:
4166 case LIBIPW_OFDM_RATE_12MB_MASK
:
4168 case LIBIPW_OFDM_RATE_18MB_MASK
:
4170 case LIBIPW_OFDM_RATE_24MB_MASK
:
4172 case LIBIPW_OFDM_RATE_36MB_MASK
:
4174 case LIBIPW_OFDM_RATE_48MB_MASK
:
4176 case LIBIPW_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
* le16_to_cpu(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(rx_quality
, signal_quality
);
4342 quality
= min(tx_quality
, quality
);
4343 quality
= min(rate_quality
, quality
);
4344 quality
= min(beacon_quality
, quality
);
4345 if (quality
== beacon_quality
)
4346 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4348 if (quality
== rate_quality
)
4349 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4351 if (quality
== tx_quality
)
4352 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4354 if (quality
== rx_quality
)
4355 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4357 if (quality
== signal_quality
)
4358 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4361 priv
->quality
= quality
;
4363 queue_delayed_work(priv
->workqueue
, &priv
->gather_stats
,
4364 IPW_STATS_INTERVAL
);
4367 static void ipw_bg_gather_stats(struct work_struct
*work
)
4369 struct ipw_priv
*priv
=
4370 container_of(work
, struct ipw_priv
, gather_stats
.work
);
4371 mutex_lock(&priv
->mutex
);
4372 ipw_gather_stats(priv
);
4373 mutex_unlock(&priv
->mutex
);
4376 /* Missed beacon behavior:
4377 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4378 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4379 * Above disassociate threshold, give up and stop scanning.
4380 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
4381 static void ipw_handle_missed_beacon(struct ipw_priv
*priv
,
4384 priv
->notif_missed_beacons
= missed_count
;
4386 if (missed_count
> priv
->disassociate_threshold
&&
4387 priv
->status
& STATUS_ASSOCIATED
) {
4388 /* If associated and we've hit the missed
4389 * beacon threshold, disassociate, turn
4390 * off roaming, and abort any active scans */
4391 IPW_DEBUG(IPW_DL_INFO
| IPW_DL_NOTIF
|
4392 IPW_DL_STATE
| IPW_DL_ASSOC
,
4393 "Missed beacon: %d - disassociate\n", missed_count
);
4394 priv
->status
&= ~STATUS_ROAMING
;
4395 if (priv
->status
& STATUS_SCANNING
) {
4396 IPW_DEBUG(IPW_DL_INFO
| IPW_DL_NOTIF
|
4398 "Aborting scan with missed beacon.\n");
4399 queue_work(priv
->workqueue
, &priv
->abort_scan
);
4402 queue_work(priv
->workqueue
, &priv
->disassociate
);
4406 if (priv
->status
& STATUS_ROAMING
) {
4407 /* If we are currently roaming, then just
4408 * print a debug statement... */
4409 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
,
4410 "Missed beacon: %d - roam in progress\n",
4416 (missed_count
> priv
->roaming_threshold
&&
4417 missed_count
<= priv
->disassociate_threshold
)) {
4418 /* If we are not already roaming, set the ROAM
4419 * bit in the status and kick off a scan.
4420 * This can happen several times before we reach
4421 * disassociate_threshold. */
4422 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
,
4423 "Missed beacon: %d - initiate "
4424 "roaming\n", missed_count
);
4425 if (!(priv
->status
& STATUS_ROAMING
)) {
4426 priv
->status
|= STATUS_ROAMING
;
4427 if (!(priv
->status
& STATUS_SCANNING
))
4428 queue_delayed_work(priv
->workqueue
,
4429 &priv
->request_scan
, 0);
4434 if (priv
->status
& STATUS_SCANNING
&&
4435 missed_count
> IPW_MB_SCAN_CANCEL_THRESHOLD
) {
4436 /* Stop scan to keep fw from getting
4437 * stuck (only if we aren't roaming --
4438 * otherwise we'll never scan more than 2 or 3
4440 IPW_DEBUG(IPW_DL_INFO
| IPW_DL_NOTIF
| IPW_DL_STATE
,
4441 "Aborting scan with missed beacon.\n");
4442 queue_work(priv
->workqueue
, &priv
->abort_scan
);
4445 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count
);
4448 static void ipw_scan_event(struct work_struct
*work
)
4450 union iwreq_data wrqu
;
4452 struct ipw_priv
*priv
=
4453 container_of(work
, struct ipw_priv
, scan_event
.work
);
4455 wrqu
.data
.length
= 0;
4456 wrqu
.data
.flags
= 0;
4457 wireless_send_event(priv
->net_dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
4460 static void handle_scan_event(struct ipw_priv
*priv
)
4462 /* Only userspace-requested scan completion events go out immediately */
4463 if (!priv
->user_requested_scan
) {
4464 if (!delayed_work_pending(&priv
->scan_event
))
4465 queue_delayed_work(priv
->workqueue
, &priv
->scan_event
,
4466 round_jiffies_relative(msecs_to_jiffies(4000)));
4468 union iwreq_data wrqu
;
4470 priv
->user_requested_scan
= 0;
4471 cancel_delayed_work(&priv
->scan_event
);
4473 wrqu
.data
.length
= 0;
4474 wrqu
.data
.flags
= 0;
4475 wireless_send_event(priv
->net_dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
4480 * Handle host notification packet.
4481 * Called from interrupt routine
4483 static void ipw_rx_notification(struct ipw_priv
*priv
,
4484 struct ipw_rx_notification
*notif
)
4486 DECLARE_SSID_BUF(ssid
);
4487 u16 size
= le16_to_cpu(notif
->size
);
4489 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif
->subtype
, size
);
4491 switch (notif
->subtype
) {
4492 case HOST_NOTIFICATION_STATUS_ASSOCIATED
:{
4493 struct notif_association
*assoc
= ¬if
->u
.assoc
;
4495 switch (assoc
->state
) {
4496 case CMAS_ASSOCIATED
:{
4497 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4499 "associated: '%s' %pM\n",
4500 print_ssid(ssid
, priv
->essid
,
4504 switch (priv
->ieee
->iw_mode
) {
4506 memcpy(priv
->ieee
->bssid
,
4507 priv
->bssid
, ETH_ALEN
);
4511 memcpy(priv
->ieee
->bssid
,
4512 priv
->bssid
, ETH_ALEN
);
4514 /* clear out the station table */
4515 priv
->num_stations
= 0;
4518 ("queueing adhoc check\n");
4519 queue_delayed_work(priv
->
4529 priv
->status
&= ~STATUS_ASSOCIATING
;
4530 priv
->status
|= STATUS_ASSOCIATED
;
4531 queue_work(priv
->workqueue
,
4532 &priv
->system_config
);
4534 #ifdef CONFIG_IPW2200_QOS
4535 #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4536 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control))
4537 if ((priv
->status
& STATUS_AUTH
) &&
4538 (IPW_GET_PACKET_STYPE(¬if
->u
.raw
)
4539 == IEEE80211_STYPE_ASSOC_RESP
)) {
4542 libipw_assoc_response
)
4544 && (size
<= 2314)) {
4554 libipw_rx_mgt(priv
->
4559 ¬if
->u
.raw
, &stats
);
4564 schedule_work(&priv
->link_up
);
4569 case CMAS_AUTHENTICATED
:{
4571 status
& (STATUS_ASSOCIATED
|
4573 struct notif_authenticate
*auth
4575 IPW_DEBUG(IPW_DL_NOTIF
|
4578 "deauthenticated: '%s' "
4580 ": (0x%04X) - %s\n",
4587 le16_to_cpu(auth
->status
),
4593 ~(STATUS_ASSOCIATING
|
4597 schedule_work(&priv
->link_down
);
4601 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4603 "authenticated: '%s' %pM\n",
4604 print_ssid(ssid
, priv
->essid
,
4611 if (priv
->status
& STATUS_AUTH
) {
4613 libipw_assoc_response
4617 libipw_assoc_response
4619 IPW_DEBUG(IPW_DL_NOTIF
|
4622 "association failed (0x%04X): %s\n",
4623 le16_to_cpu(resp
->status
),
4629 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4631 "disassociated: '%s' %pM\n",
4632 print_ssid(ssid
, priv
->essid
,
4637 ~(STATUS_DISASSOCIATING
|
4638 STATUS_ASSOCIATING
|
4639 STATUS_ASSOCIATED
| STATUS_AUTH
);
4640 if (priv
->assoc_network
4641 && (priv
->assoc_network
->
4643 WLAN_CAPABILITY_IBSS
))
4644 ipw_remove_current_network
4647 schedule_work(&priv
->link_down
);
4652 case CMAS_RX_ASSOC_RESP
:
4656 IPW_ERROR("assoc: unknown (%d)\n",
4664 case HOST_NOTIFICATION_STATUS_AUTHENTICATE
:{
4665 struct notif_authenticate
*auth
= ¬if
->u
.auth
;
4666 switch (auth
->state
) {
4667 case CMAS_AUTHENTICATED
:
4668 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
,
4669 "authenticated: '%s' %pM\n",
4670 print_ssid(ssid
, priv
->essid
,
4673 priv
->status
|= STATUS_AUTH
;
4677 if (priv
->status
& STATUS_AUTH
) {
4678 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4680 "authentication failed (0x%04X): %s\n",
4681 le16_to_cpu(auth
->status
),
4682 ipw_get_status_code(le16_to_cpu
4686 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4688 "deauthenticated: '%s' %pM\n",
4689 print_ssid(ssid
, priv
->essid
,
4693 priv
->status
&= ~(STATUS_ASSOCIATING
|
4697 schedule_work(&priv
->link_down
);
4700 case CMAS_TX_AUTH_SEQ_1
:
4701 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4702 IPW_DL_ASSOC
, "AUTH_SEQ_1\n");
4704 case CMAS_RX_AUTH_SEQ_2
:
4705 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4706 IPW_DL_ASSOC
, "AUTH_SEQ_2\n");
4708 case CMAS_AUTH_SEQ_1_PASS
:
4709 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4710 IPW_DL_ASSOC
, "AUTH_SEQ_1_PASS\n");
4712 case CMAS_AUTH_SEQ_1_FAIL
:
4713 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4714 IPW_DL_ASSOC
, "AUTH_SEQ_1_FAIL\n");
4716 case CMAS_TX_AUTH_SEQ_3
:
4717 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4718 IPW_DL_ASSOC
, "AUTH_SEQ_3\n");
4720 case CMAS_RX_AUTH_SEQ_4
:
4721 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4722 IPW_DL_ASSOC
, "RX_AUTH_SEQ_4\n");
4724 case CMAS_AUTH_SEQ_2_PASS
:
4725 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4726 IPW_DL_ASSOC
, "AUTH_SEQ_2_PASS\n");
4728 case CMAS_AUTH_SEQ_2_FAIL
:
4729 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4730 IPW_DL_ASSOC
, "AUT_SEQ_2_FAIL\n");
4733 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4734 IPW_DL_ASSOC
, "TX_ASSOC\n");
4736 case CMAS_RX_ASSOC_RESP
:
4737 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4738 IPW_DL_ASSOC
, "RX_ASSOC_RESP\n");
4741 case CMAS_ASSOCIATED
:
4742 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4743 IPW_DL_ASSOC
, "ASSOCIATED\n");
4746 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4753 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT
:{
4754 struct notif_channel_result
*x
=
4755 ¬if
->u
.channel_result
;
4757 if (size
== sizeof(*x
)) {
4758 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4761 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4762 "(should be %zd)\n",
4768 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED
:{
4769 struct notif_scan_complete
*x
= ¬if
->u
.scan_complete
;
4770 if (size
== sizeof(*x
)) {
4772 ("Scan completed: type %d, %d channels, "
4773 "%d status\n", x
->scan_type
,
4774 x
->num_channels
, x
->status
);
4776 IPW_ERROR("Scan completed of wrong size %d "
4777 "(should be %zd)\n",
4782 ~(STATUS_SCANNING
| STATUS_SCAN_ABORTING
);
4784 wake_up_interruptible(&priv
->wait_state
);
4785 cancel_delayed_work(&priv
->scan_check
);
4787 if (priv
->status
& STATUS_EXIT_PENDING
)
4790 priv
->ieee
->scans
++;
4792 #ifdef CONFIG_IPW2200_MONITOR
4793 if (priv
->ieee
->iw_mode
== IW_MODE_MONITOR
) {
4794 priv
->status
|= STATUS_SCAN_FORCED
;
4795 queue_delayed_work(priv
->workqueue
,
4796 &priv
->request_scan
, 0);
4799 priv
->status
&= ~STATUS_SCAN_FORCED
;
4800 #endif /* CONFIG_IPW2200_MONITOR */
4802 /* Do queued direct scans first */
4803 if (priv
->status
& STATUS_DIRECT_SCAN_PENDING
) {
4804 queue_delayed_work(priv
->workqueue
,
4805 &priv
->request_direct_scan
, 0);
4808 if (!(priv
->status
& (STATUS_ASSOCIATED
|
4809 STATUS_ASSOCIATING
|
4811 STATUS_DISASSOCIATING
)))
4812 queue_work(priv
->workqueue
, &priv
->associate
);
4813 else if (priv
->status
& STATUS_ROAMING
) {
4814 if (x
->status
== SCAN_COMPLETED_STATUS_COMPLETE
)
4815 /* If a scan completed and we are in roam mode, then
4816 * the scan that completed was the one requested as a
4817 * result of entering roam... so, schedule the
4819 queue_work(priv
->workqueue
,
4822 /* Don't schedule if we aborted the scan */
4823 priv
->status
&= ~STATUS_ROAMING
;
4824 } else if (priv
->status
& STATUS_SCAN_PENDING
)
4825 queue_delayed_work(priv
->workqueue
,
4826 &priv
->request_scan
, 0);
4827 else if (priv
->config
& CFG_BACKGROUND_SCAN
4828 && priv
->status
& STATUS_ASSOCIATED
)
4829 queue_delayed_work(priv
->workqueue
,
4830 &priv
->request_scan
,
4831 round_jiffies_relative(HZ
));
4833 /* Send an empty event to user space.
4834 * We don't send the received data on the event because
4835 * it would require us to do complex transcoding, and
4836 * we want to minimise the work done in the irq handler
4837 * Use a request to extract the data.
4838 * Also, we generate this even for any scan, regardless
4839 * on how the scan was initiated. User space can just
4840 * sync on periodic scan to get fresh data...
4842 if (x
->status
== SCAN_COMPLETED_STATUS_COMPLETE
)
4843 handle_scan_event(priv
);
4847 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH
:{
4848 struct notif_frag_length
*x
= ¬if
->u
.frag_len
;
4850 if (size
== sizeof(*x
))
4851 IPW_ERROR("Frag length: %d\n",
4852 le16_to_cpu(x
->frag_length
));
4854 IPW_ERROR("Frag length of wrong size %d "
4855 "(should be %zd)\n",
4860 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION
:{
4861 struct notif_link_deterioration
*x
=
4862 ¬if
->u
.link_deterioration
;
4864 if (size
== sizeof(*x
)) {
4865 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
,
4866 "link deterioration: type %d, cnt %d\n",
4867 x
->silence_notification_type
,
4869 memcpy(&priv
->last_link_deterioration
, x
,
4872 IPW_ERROR("Link Deterioration of wrong size %d "
4873 "(should be %zd)\n",
4879 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE
:{
4880 IPW_ERROR("Dino config\n");
4882 && priv
->hcmd
->cmd
!= HOST_CMD_DINO_CONFIG
)
4883 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
4888 case HOST_NOTIFICATION_STATUS_BEACON_STATE
:{
4889 struct notif_beacon_state
*x
= ¬if
->u
.beacon_state
;
4890 if (size
!= sizeof(*x
)) {
4892 ("Beacon state of wrong size %d (should "
4893 "be %zd)\n", size
, sizeof(*x
));
4897 if (le32_to_cpu(x
->state
) ==
4898 HOST_NOTIFICATION_STATUS_BEACON_MISSING
)
4899 ipw_handle_missed_beacon(priv
,
4906 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY
:{
4907 struct notif_tgi_tx_key
*x
= ¬if
->u
.tgi_tx_key
;
4908 if (size
== sizeof(*x
)) {
4909 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4910 "0x%02x station %d\n",
4911 x
->key_state
, x
->security_type
,
4917 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4922 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS
:{
4923 struct notif_calibration
*x
= ¬if
->u
.calibration
;
4925 if (size
== sizeof(*x
)) {
4926 memcpy(&priv
->calib
, x
, sizeof(*x
));
4927 IPW_DEBUG_INFO("TODO: Calibration\n");
4932 ("Calibration of wrong size %d (should be %zd)\n",
4937 case HOST_NOTIFICATION_NOISE_STATS
:{
4938 if (size
== sizeof(u32
)) {
4939 priv
->exp_avg_noise
=
4940 exponential_average(priv
->exp_avg_noise
,
4941 (u8
) (le32_to_cpu(notif
->u
.noise
.value
) & 0xff),
4947 ("Noise stat is wrong size %d (should be %zd)\n",
4953 IPW_DEBUG_NOTIF("Unknown notification: "
4954 "subtype=%d,flags=0x%2x,size=%d\n",
4955 notif
->subtype
, notif
->flags
, size
);
4960 * Destroys all DMA structures and initialise them again
4963 * @return error code
4965 static int ipw_queue_reset(struct ipw_priv
*priv
)
4968 /** @todo customize queue sizes */
4969 int nTx
= 64, nTxCmd
= 8;
4970 ipw_tx_queue_free(priv
);
4972 rc
= ipw_queue_tx_init(priv
, &priv
->txq_cmd
, nTxCmd
,
4973 IPW_TX_CMD_QUEUE_READ_INDEX
,
4974 IPW_TX_CMD_QUEUE_WRITE_INDEX
,
4975 IPW_TX_CMD_QUEUE_BD_BASE
,
4976 IPW_TX_CMD_QUEUE_BD_SIZE
);
4978 IPW_ERROR("Tx Cmd queue init failed\n");
4982 rc
= ipw_queue_tx_init(priv
, &priv
->txq
[0], nTx
,
4983 IPW_TX_QUEUE_0_READ_INDEX
,
4984 IPW_TX_QUEUE_0_WRITE_INDEX
,
4985 IPW_TX_QUEUE_0_BD_BASE
, IPW_TX_QUEUE_0_BD_SIZE
);
4987 IPW_ERROR("Tx 0 queue init failed\n");
4990 rc
= ipw_queue_tx_init(priv
, &priv
->txq
[1], nTx
,
4991 IPW_TX_QUEUE_1_READ_INDEX
,
4992 IPW_TX_QUEUE_1_WRITE_INDEX
,
4993 IPW_TX_QUEUE_1_BD_BASE
, IPW_TX_QUEUE_1_BD_SIZE
);
4995 IPW_ERROR("Tx 1 queue init failed\n");
4998 rc
= ipw_queue_tx_init(priv
, &priv
->txq
[2], nTx
,
4999 IPW_TX_QUEUE_2_READ_INDEX
,
5000 IPW_TX_QUEUE_2_WRITE_INDEX
,
5001 IPW_TX_QUEUE_2_BD_BASE
, IPW_TX_QUEUE_2_BD_SIZE
);
5003 IPW_ERROR("Tx 2 queue init failed\n");
5006 rc
= ipw_queue_tx_init(priv
, &priv
->txq
[3], nTx
,
5007 IPW_TX_QUEUE_3_READ_INDEX
,
5008 IPW_TX_QUEUE_3_WRITE_INDEX
,
5009 IPW_TX_QUEUE_3_BD_BASE
, IPW_TX_QUEUE_3_BD_SIZE
);
5011 IPW_ERROR("Tx 3 queue init failed\n");
5015 priv
->rx_bufs_min
= 0;
5016 priv
->rx_pend_max
= 0;
5020 ipw_tx_queue_free(priv
);
5025 * Reclaim Tx queue entries no more used by NIC.
5027 * When FW advances 'R' index, all entries between old and
5028 * new 'R' index need to be reclaimed. As result, some free space
5029 * forms. If there is enough free space (> low mark), wake Tx queue.
5031 * @note Need to protect against garbage in 'R' index
5035 * @return Number of used entries remains in the queue
5037 static int ipw_queue_tx_reclaim(struct ipw_priv
*priv
,
5038 struct clx2_tx_queue
*txq
, int qindex
)
5042 struct clx2_queue
*q
= &txq
->q
;
5044 hw_tail
= ipw_read32(priv
, q
->reg_r
);
5045 if (hw_tail
>= q
->n_bd
) {
5047 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
5051 for (; q
->last_used
!= hw_tail
;
5052 q
->last_used
= ipw_queue_inc_wrap(q
->last_used
, q
->n_bd
)) {
5053 ipw_queue_tx_free_tfd(priv
, txq
);
5057 if ((ipw_tx_queue_space(q
) > q
->low_mark
) &&
5059 netif_wake_queue(priv
->net_dev
);
5060 used
= q
->first_empty
- q
->last_used
;
5067 static int ipw_queue_tx_hcmd(struct ipw_priv
*priv
, int hcmd
, void *buf
,
5070 struct clx2_tx_queue
*txq
= &priv
->txq_cmd
;
5071 struct clx2_queue
*q
= &txq
->q
;
5072 struct tfd_frame
*tfd
;
5074 if (ipw_tx_queue_space(q
) < (sync
? 1 : 2)) {
5075 IPW_ERROR("No space for Tx\n");
5079 tfd
= &txq
->bd
[q
->first_empty
];
5080 txq
->txb
[q
->first_empty
] = NULL
;
5082 memset(tfd
, 0, sizeof(*tfd
));
5083 tfd
->control_flags
.message_type
= TX_HOST_COMMAND_TYPE
;
5084 tfd
->control_flags
.control_bits
= TFD_NEED_IRQ_MASK
;
5086 tfd
->u
.cmd
.index
= hcmd
;
5087 tfd
->u
.cmd
.length
= len
;
5088 memcpy(tfd
->u
.cmd
.payload
, buf
, len
);
5089 q
->first_empty
= ipw_queue_inc_wrap(q
->first_empty
, q
->n_bd
);
5090 ipw_write32(priv
, q
->reg_w
, q
->first_empty
);
5091 _ipw_read32(priv
, 0x90);
5097 * Rx theory of operation
5099 * The host allocates 32 DMA target addresses and passes the host address
5100 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
5104 * The host/firmware share two index registers for managing the Rx buffers.
5106 * The READ index maps to the first position that the firmware may be writing
5107 * to -- the driver can read up to (but not including) this position and get
5109 * The READ index is managed by the firmware once the card is enabled.
5111 * The WRITE index maps to the last position the driver has read from -- the
5112 * position preceding WRITE is the last slot the firmware can place a packet.
5114 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
5117 * During initialization the host sets up the READ queue position to the first
5118 * INDEX position, and WRITE to the last (READ - 1 wrapped)
5120 * When the firmware places a packet in a buffer it will advance the READ index
5121 * and fire the RX interrupt. The driver can then query the READ index and
5122 * process as many packets as possible, moving the WRITE index forward as it
5123 * resets the Rx queue buffers with new memory.
5125 * The management in the driver is as follows:
5126 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
5127 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
5128 * to replensish the ipw->rxq->rx_free.
5129 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
5130 * ipw->rxq is replenished and the READ INDEX is updated (updating the
5131 * 'processed' and 'read' driver indexes as well)
5132 * + A received packet is processed and handed to the kernel network stack,
5133 * detached from the ipw->rxq. The driver 'processed' index is updated.
5134 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
5135 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
5136 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
5137 * were enough free buffers and RX_STALLED is set it is cleared.
5142 * ipw_rx_queue_alloc() Allocates rx_free
5143 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
5144 * ipw_rx_queue_restock
5145 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
5146 * queue, updates firmware pointers, and updates
5147 * the WRITE index. If insufficient rx_free buffers
5148 * are available, schedules ipw_rx_queue_replenish
5150 * -- enable interrupts --
5151 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
5152 * READ INDEX, detaching the SKB from the pool.
5153 * Moves the packet buffer from queue to rx_used.
5154 * Calls ipw_rx_queue_restock to refill any empty
5161 * If there are slots in the RX queue that need to be restocked,
5162 * and we have free pre-allocated buffers, fill the ranks as much
5163 * as we can pulling from rx_free.
5165 * This moves the 'write' index forward to catch up with 'processed', and
5166 * also updates the memory address in the firmware to reference the new
5169 static void ipw_rx_queue_restock(struct ipw_priv
*priv
)
5171 struct ipw_rx_queue
*rxq
= priv
->rxq
;
5172 struct list_head
*element
;
5173 struct ipw_rx_mem_buffer
*rxb
;
5174 unsigned long flags
;
5177 spin_lock_irqsave(&rxq
->lock
, flags
);
5179 while ((ipw_rx_queue_space(rxq
) > 0) && (rxq
->free_count
)) {
5180 element
= rxq
->rx_free
.next
;
5181 rxb
= list_entry(element
, struct ipw_rx_mem_buffer
, list
);
5184 ipw_write32(priv
, IPW_RFDS_TABLE_LOWER
+ rxq
->write
* RFD_SIZE
,
5186 rxq
->queue
[rxq
->write
] = rxb
;
5187 rxq
->write
= (rxq
->write
+ 1) % RX_QUEUE_SIZE
;
5190 spin_unlock_irqrestore(&rxq
->lock
, flags
);
5192 /* If the pre-allocated buffer pool is dropping low, schedule to
5194 if (rxq
->free_count
<= RX_LOW_WATERMARK
)
5195 queue_work(priv
->workqueue
, &priv
->rx_replenish
);
5197 /* If we've added more space for the firmware to place data, tell it */
5198 if (write
!= rxq
->write
)
5199 ipw_write32(priv
, IPW_RX_WRITE_INDEX
, rxq
->write
);
5203 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
5204 * Also restock the Rx queue via ipw_rx_queue_restock.
5206 * This is called as a scheduled work item (except for during intialization)
5208 static void ipw_rx_queue_replenish(void *data
)
5210 struct ipw_priv
*priv
= data
;
5211 struct ipw_rx_queue
*rxq
= priv
->rxq
;
5212 struct list_head
*element
;
5213 struct ipw_rx_mem_buffer
*rxb
;
5214 unsigned long flags
;
5216 spin_lock_irqsave(&rxq
->lock
, flags
);
5217 while (!list_empty(&rxq
->rx_used
)) {
5218 element
= rxq
->rx_used
.next
;
5219 rxb
= list_entry(element
, struct ipw_rx_mem_buffer
, list
);
5220 rxb
->skb
= alloc_skb(IPW_RX_BUF_SIZE
, GFP_ATOMIC
);
5222 printk(KERN_CRIT
"%s: Can not allocate SKB buffers.\n",
5223 priv
->net_dev
->name
);
5224 /* We don't reschedule replenish work here -- we will
5225 * call the restock method and if it still needs
5226 * more buffers it will schedule replenish */
5232 pci_map_single(priv
->pci_dev
, rxb
->skb
->data
,
5233 IPW_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
5235 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
5238 spin_unlock_irqrestore(&rxq
->lock
, flags
);
5240 ipw_rx_queue_restock(priv
);
5243 static void ipw_bg_rx_queue_replenish(struct work_struct
*work
)
5245 struct ipw_priv
*priv
=
5246 container_of(work
, struct ipw_priv
, rx_replenish
);
5247 mutex_lock(&priv
->mutex
);
5248 ipw_rx_queue_replenish(priv
);
5249 mutex_unlock(&priv
->mutex
);
5252 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
5253 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
5254 * This free routine walks the list of POOL entries and if SKB is set to
5255 * non NULL it is unmapped and freed
5257 static void ipw_rx_queue_free(struct ipw_priv
*priv
, struct ipw_rx_queue
*rxq
)
5264 for (i
= 0; i
< RX_QUEUE_SIZE
+ RX_FREE_BUFFERS
; i
++) {
5265 if (rxq
->pool
[i
].skb
!= NULL
) {
5266 pci_unmap_single(priv
->pci_dev
, rxq
->pool
[i
].dma_addr
,
5267 IPW_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
5268 dev_kfree_skb(rxq
->pool
[i
].skb
);
5275 static struct ipw_rx_queue
*ipw_rx_queue_alloc(struct ipw_priv
*priv
)
5277 struct ipw_rx_queue
*rxq
;
5280 rxq
= kzalloc(sizeof(*rxq
), GFP_KERNEL
);
5281 if (unlikely(!rxq
)) {
5282 IPW_ERROR("memory allocation failed\n");
5285 spin_lock_init(&rxq
->lock
);
5286 INIT_LIST_HEAD(&rxq
->rx_free
);
5287 INIT_LIST_HEAD(&rxq
->rx_used
);
5289 /* Fill the rx_used queue with _all_ of the Rx buffers */
5290 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++)
5291 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
5293 /* Set us so that we have processed and used all buffers, but have
5294 * not restocked the Rx queue with fresh buffers */
5295 rxq
->read
= rxq
->write
= 0;
5296 rxq
->free_count
= 0;
5301 static int ipw_is_rate_in_mask(struct ipw_priv
*priv
, int ieee_mode
, u8 rate
)
5303 rate
&= ~LIBIPW_BASIC_RATE_MASK
;
5304 if (ieee_mode
== IEEE_A
) {
5306 case LIBIPW_OFDM_RATE_6MB
:
5307 return priv
->rates_mask
& LIBIPW_OFDM_RATE_6MB_MASK
?
5309 case LIBIPW_OFDM_RATE_9MB
:
5310 return priv
->rates_mask
& LIBIPW_OFDM_RATE_9MB_MASK
?
5312 case LIBIPW_OFDM_RATE_12MB
:
5314 rates_mask
& LIBIPW_OFDM_RATE_12MB_MASK
? 1 : 0;
5315 case LIBIPW_OFDM_RATE_18MB
:
5317 rates_mask
& LIBIPW_OFDM_RATE_18MB_MASK
? 1 : 0;
5318 case LIBIPW_OFDM_RATE_24MB
:
5320 rates_mask
& LIBIPW_OFDM_RATE_24MB_MASK
? 1 : 0;
5321 case LIBIPW_OFDM_RATE_36MB
:
5323 rates_mask
& LIBIPW_OFDM_RATE_36MB_MASK
? 1 : 0;
5324 case LIBIPW_OFDM_RATE_48MB
:
5326 rates_mask
& LIBIPW_OFDM_RATE_48MB_MASK
? 1 : 0;
5327 case LIBIPW_OFDM_RATE_54MB
:
5329 rates_mask
& LIBIPW_OFDM_RATE_54MB_MASK
? 1 : 0;
5337 case LIBIPW_CCK_RATE_1MB
:
5338 return priv
->rates_mask
& LIBIPW_CCK_RATE_1MB_MASK
? 1 : 0;
5339 case LIBIPW_CCK_RATE_2MB
:
5340 return priv
->rates_mask
& LIBIPW_CCK_RATE_2MB_MASK
? 1 : 0;
5341 case LIBIPW_CCK_RATE_5MB
:
5342 return priv
->rates_mask
& LIBIPW_CCK_RATE_5MB_MASK
? 1 : 0;
5343 case LIBIPW_CCK_RATE_11MB
:
5344 return priv
->rates_mask
& LIBIPW_CCK_RATE_11MB_MASK
? 1 : 0;
5347 /* If we are limited to B modulations, bail at this point */
5348 if (ieee_mode
== IEEE_B
)
5353 case LIBIPW_OFDM_RATE_6MB
:
5354 return priv
->rates_mask
& LIBIPW_OFDM_RATE_6MB_MASK
? 1 : 0;
5355 case LIBIPW_OFDM_RATE_9MB
:
5356 return priv
->rates_mask
& LIBIPW_OFDM_RATE_9MB_MASK
? 1 : 0;
5357 case LIBIPW_OFDM_RATE_12MB
:
5358 return priv
->rates_mask
& LIBIPW_OFDM_RATE_12MB_MASK
? 1 : 0;
5359 case LIBIPW_OFDM_RATE_18MB
:
5360 return priv
->rates_mask
& LIBIPW_OFDM_RATE_18MB_MASK
? 1 : 0;
5361 case LIBIPW_OFDM_RATE_24MB
:
5362 return priv
->rates_mask
& LIBIPW_OFDM_RATE_24MB_MASK
? 1 : 0;
5363 case LIBIPW_OFDM_RATE_36MB
:
5364 return priv
->rates_mask
& LIBIPW_OFDM_RATE_36MB_MASK
? 1 : 0;
5365 case LIBIPW_OFDM_RATE_48MB
:
5366 return priv
->rates_mask
& LIBIPW_OFDM_RATE_48MB_MASK
? 1 : 0;
5367 case LIBIPW_OFDM_RATE_54MB
:
5368 return priv
->rates_mask
& LIBIPW_OFDM_RATE_54MB_MASK
? 1 : 0;
5374 static int ipw_compatible_rates(struct ipw_priv
*priv
,
5375 const struct libipw_network
*network
,
5376 struct ipw_supported_rates
*rates
)
5380 memset(rates
, 0, sizeof(*rates
));
5381 num_rates
= min(network
->rates_len
, (u8
) IPW_MAX_RATES
);
5382 rates
->num_rates
= 0;
5383 for (i
= 0; i
< num_rates
; i
++) {
5384 if (!ipw_is_rate_in_mask(priv
, network
->mode
,
5385 network
->rates
[i
])) {
5387 if (network
->rates
[i
] & LIBIPW_BASIC_RATE_MASK
) {
5388 IPW_DEBUG_SCAN("Adding masked mandatory "
5391 rates
->supported_rates
[rates
->num_rates
++] =
5396 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5397 network
->rates
[i
], priv
->rates_mask
);
5401 rates
->supported_rates
[rates
->num_rates
++] = network
->rates
[i
];
5404 num_rates
= min(network
->rates_ex_len
,
5405 (u8
) (IPW_MAX_RATES
- num_rates
));
5406 for (i
= 0; i
< num_rates
; i
++) {
5407 if (!ipw_is_rate_in_mask(priv
, network
->mode
,
5408 network
->rates_ex
[i
])) {
5409 if (network
->rates_ex
[i
] & LIBIPW_BASIC_RATE_MASK
) {
5410 IPW_DEBUG_SCAN("Adding masked mandatory "
5412 network
->rates_ex
[i
]);
5413 rates
->supported_rates
[rates
->num_rates
++] =
5418 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5419 network
->rates_ex
[i
], priv
->rates_mask
);
5423 rates
->supported_rates
[rates
->num_rates
++] =
5424 network
->rates_ex
[i
];
5430 static void ipw_copy_rates(struct ipw_supported_rates
*dest
,
5431 const struct ipw_supported_rates
*src
)
5434 for (i
= 0; i
< src
->num_rates
; i
++)
5435 dest
->supported_rates
[i
] = src
->supported_rates
[i
];
5436 dest
->num_rates
= src
->num_rates
;
5439 /* TODO: Look at sniffed packets in the air to determine if the basic rate
5440 * mask should ever be used -- right now all callers to add the scan rates are
5441 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5442 static void ipw_add_cck_scan_rates(struct ipw_supported_rates
*rates
,
5443 u8 modulation
, u32 rate_mask
)
5445 u8 basic_mask
= (LIBIPW_OFDM_MODULATION
== modulation
) ?
5446 LIBIPW_BASIC_RATE_MASK
: 0;
5448 if (rate_mask
& LIBIPW_CCK_RATE_1MB_MASK
)
5449 rates
->supported_rates
[rates
->num_rates
++] =
5450 LIBIPW_BASIC_RATE_MASK
| LIBIPW_CCK_RATE_1MB
;
5452 if (rate_mask
& LIBIPW_CCK_RATE_2MB_MASK
)
5453 rates
->supported_rates
[rates
->num_rates
++] =
5454 LIBIPW_BASIC_RATE_MASK
| LIBIPW_CCK_RATE_2MB
;
5456 if (rate_mask
& LIBIPW_CCK_RATE_5MB_MASK
)
5457 rates
->supported_rates
[rates
->num_rates
++] = basic_mask
|
5458 LIBIPW_CCK_RATE_5MB
;
5460 if (rate_mask
& LIBIPW_CCK_RATE_11MB_MASK
)
5461 rates
->supported_rates
[rates
->num_rates
++] = basic_mask
|
5462 LIBIPW_CCK_RATE_11MB
;
5465 static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates
*rates
,
5466 u8 modulation
, u32 rate_mask
)
5468 u8 basic_mask
= (LIBIPW_OFDM_MODULATION
== modulation
) ?
5469 LIBIPW_BASIC_RATE_MASK
: 0;
5471 if (rate_mask
& LIBIPW_OFDM_RATE_6MB_MASK
)
5472 rates
->supported_rates
[rates
->num_rates
++] = basic_mask
|
5473 LIBIPW_OFDM_RATE_6MB
;
5475 if (rate_mask
& LIBIPW_OFDM_RATE_9MB_MASK
)
5476 rates
->supported_rates
[rates
->num_rates
++] =
5477 LIBIPW_OFDM_RATE_9MB
;
5479 if (rate_mask
& LIBIPW_OFDM_RATE_12MB_MASK
)
5480 rates
->supported_rates
[rates
->num_rates
++] = basic_mask
|
5481 LIBIPW_OFDM_RATE_12MB
;
5483 if (rate_mask
& LIBIPW_OFDM_RATE_18MB_MASK
)
5484 rates
->supported_rates
[rates
->num_rates
++] =
5485 LIBIPW_OFDM_RATE_18MB
;
5487 if (rate_mask
& LIBIPW_OFDM_RATE_24MB_MASK
)
5488 rates
->supported_rates
[rates
->num_rates
++] = basic_mask
|
5489 LIBIPW_OFDM_RATE_24MB
;
5491 if (rate_mask
& LIBIPW_OFDM_RATE_36MB_MASK
)
5492 rates
->supported_rates
[rates
->num_rates
++] =
5493 LIBIPW_OFDM_RATE_36MB
;
5495 if (rate_mask
& LIBIPW_OFDM_RATE_48MB_MASK
)
5496 rates
->supported_rates
[rates
->num_rates
++] =
5497 LIBIPW_OFDM_RATE_48MB
;
5499 if (rate_mask
& LIBIPW_OFDM_RATE_54MB_MASK
)
5500 rates
->supported_rates
[rates
->num_rates
++] =
5501 LIBIPW_OFDM_RATE_54MB
;
5504 struct ipw_network_match
{
5505 struct libipw_network
*network
;
5506 struct ipw_supported_rates rates
;
5509 static int ipw_find_adhoc_network(struct ipw_priv
*priv
,
5510 struct ipw_network_match
*match
,
5511 struct libipw_network
*network
,
5514 struct ipw_supported_rates rates
;
5515 DECLARE_SSID_BUF(ssid
);
5517 /* Verify that this network's capability is compatible with the
5518 * current mode (AdHoc or Infrastructure) */
5519 if ((priv
->ieee
->iw_mode
== IW_MODE_ADHOC
&&
5520 !(network
->capability
& WLAN_CAPABILITY_IBSS
))) {
5521 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to "
5522 "capability mismatch.\n",
5523 print_ssid(ssid
, network
->ssid
,
5529 if (unlikely(roaming
)) {
5530 /* If we are roaming, then ensure check if this is a valid
5531 * network to try and roam to */
5532 if ((network
->ssid_len
!= match
->network
->ssid_len
) ||
5533 memcmp(network
->ssid
, match
->network
->ssid
,
5534 network
->ssid_len
)) {
5535 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5536 "because of non-network ESSID.\n",
5537 print_ssid(ssid
, network
->ssid
,
5543 /* If an ESSID has been configured then compare the broadcast
5545 if ((priv
->config
& CFG_STATIC_ESSID
) &&
5546 ((network
->ssid_len
!= priv
->essid_len
) ||
5547 memcmp(network
->ssid
, priv
->essid
,
5548 min(network
->ssid_len
, priv
->essid_len
)))) {
5549 char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
5552 print_ssid(ssid
, network
->ssid
,
5555 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5556 "because of ESSID mismatch: '%s'.\n",
5557 escaped
, network
->bssid
,
5558 print_ssid(ssid
, priv
->essid
,
5564 /* If the old network rate is better than this one, don't bother
5565 * testing everything else. */
5567 if (network
->time_stamp
[0] < match
->network
->time_stamp
[0]) {
5568 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5569 "current network.\n",
5570 print_ssid(ssid
, match
->network
->ssid
,
5571 match
->network
->ssid_len
));
5573 } else if (network
->time_stamp
[1] < match
->network
->time_stamp
[1]) {
5574 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5575 "current network.\n",
5576 print_ssid(ssid
, match
->network
->ssid
,
5577 match
->network
->ssid_len
));
5581 /* Now go through and see if the requested network is valid... */
5582 if (priv
->ieee
->scan_age
!= 0 &&
5583 time_after(jiffies
, network
->last_scanned
+ priv
->ieee
->scan_age
)) {
5584 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5585 "because of age: %ums.\n",
5586 print_ssid(ssid
, network
->ssid
,
5589 jiffies_to_msecs(jiffies
-
5590 network
->last_scanned
));
5594 if ((priv
->config
& CFG_STATIC_CHANNEL
) &&
5595 (network
->channel
!= priv
->channel
)) {
5596 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5597 "because of channel mismatch: %d != %d.\n",
5598 print_ssid(ssid
, network
->ssid
,
5601 network
->channel
, priv
->channel
);
5605 /* Verify privacy compatability */
5606 if (((priv
->capability
& CAP_PRIVACY_ON
) ? 1 : 0) !=
5607 ((network
->capability
& WLAN_CAPABILITY_PRIVACY
) ? 1 : 0)) {
5608 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5609 "because of privacy mismatch: %s != %s.\n",
5610 print_ssid(ssid
, network
->ssid
,
5614 capability
& CAP_PRIVACY_ON
? "on" : "off",
5616 capability
& WLAN_CAPABILITY_PRIVACY
? "on" :
5621 if (!memcmp(network
->bssid
, priv
->bssid
, ETH_ALEN
)) {
5622 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5623 "because of the same BSSID match: %pM"
5624 ".\n", print_ssid(ssid
, network
->ssid
,
5631 /* Filter out any incompatible freq / mode combinations */
5632 if (!libipw_is_valid_mode(priv
->ieee
, network
->mode
)) {
5633 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5634 "because of invalid frequency/mode "
5636 print_ssid(ssid
, network
->ssid
,
5642 /* Ensure that the rates supported by the driver are compatible with
5643 * this AP, including verification of basic rates (mandatory) */
5644 if (!ipw_compatible_rates(priv
, network
, &rates
)) {
5645 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5646 "because configured rate mask excludes "
5647 "AP mandatory rate.\n",
5648 print_ssid(ssid
, network
->ssid
,
5654 if (rates
.num_rates
== 0) {
5655 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5656 "because of no compatible rates.\n",
5657 print_ssid(ssid
, network
->ssid
,
5663 /* TODO: Perform any further minimal comparititive tests. We do not
5664 * want to put too much policy logic here; intelligent scan selection
5665 * should occur within a generic IEEE 802.11 user space tool. */
5667 /* Set up 'new' AP to this network */
5668 ipw_copy_rates(&match
->rates
, &rates
);
5669 match
->network
= network
;
5670 IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n",
5671 print_ssid(ssid
, network
->ssid
, network
->ssid_len
),
5677 static void ipw_merge_adhoc_network(struct work_struct
*work
)
5679 DECLARE_SSID_BUF(ssid
);
5680 struct ipw_priv
*priv
=
5681 container_of(work
, struct ipw_priv
, merge_networks
);
5682 struct libipw_network
*network
= NULL
;
5683 struct ipw_network_match match
= {
5684 .network
= priv
->assoc_network
5687 if ((priv
->status
& STATUS_ASSOCIATED
) &&
5688 (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
)) {
5689 /* First pass through ROAM process -- look for a better
5691 unsigned long flags
;
5693 spin_lock_irqsave(&priv
->ieee
->lock
, flags
);
5694 list_for_each_entry(network
, &priv
->ieee
->network_list
, list
) {
5695 if (network
!= priv
->assoc_network
)
5696 ipw_find_adhoc_network(priv
, &match
, network
,
5699 spin_unlock_irqrestore(&priv
->ieee
->lock
, flags
);
5701 if (match
.network
== priv
->assoc_network
) {
5702 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5707 mutex_lock(&priv
->mutex
);
5708 if ((priv
->ieee
->iw_mode
== IW_MODE_ADHOC
)) {
5709 IPW_DEBUG_MERGE("remove network %s\n",
5710 print_ssid(ssid
, priv
->essid
,
5712 ipw_remove_current_network(priv
);
5715 ipw_disassociate(priv
);
5716 priv
->assoc_network
= match
.network
;
5717 mutex_unlock(&priv
->mutex
);
5722 static int ipw_best_network(struct ipw_priv
*priv
,
5723 struct ipw_network_match
*match
,
5724 struct libipw_network
*network
, int roaming
)
5726 struct ipw_supported_rates rates
;
5727 DECLARE_SSID_BUF(ssid
);
5729 /* Verify that this network's capability is compatible with the
5730 * current mode (AdHoc or Infrastructure) */
5731 if ((priv
->ieee
->iw_mode
== IW_MODE_INFRA
&&
5732 !(network
->capability
& WLAN_CAPABILITY_ESS
)) ||
5733 (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
&&
5734 !(network
->capability
& WLAN_CAPABILITY_IBSS
))) {
5735 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to "
5736 "capability mismatch.\n",
5737 print_ssid(ssid
, network
->ssid
,
5743 if (unlikely(roaming
)) {
5744 /* If we are roaming, then ensure check if this is a valid
5745 * network to try and roam to */
5746 if ((network
->ssid_len
!= match
->network
->ssid_len
) ||
5747 memcmp(network
->ssid
, match
->network
->ssid
,
5748 network
->ssid_len
)) {
5749 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5750 "because of non-network ESSID.\n",
5751 print_ssid(ssid
, network
->ssid
,
5757 /* If an ESSID has been configured then compare the broadcast
5759 if ((priv
->config
& CFG_STATIC_ESSID
) &&
5760 ((network
->ssid_len
!= priv
->essid_len
) ||
5761 memcmp(network
->ssid
, priv
->essid
,
5762 min(network
->ssid_len
, priv
->essid_len
)))) {
5763 char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
5765 print_ssid(ssid
, network
->ssid
,
5768 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5769 "because of ESSID mismatch: '%s'.\n",
5770 escaped
, network
->bssid
,
5771 print_ssid(ssid
, priv
->essid
,
5777 /* If the old network rate is better than this one, don't bother
5778 * testing everything else. */
5779 if (match
->network
&& match
->network
->stats
.rssi
> network
->stats
.rssi
) {
5780 char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
5782 print_ssid(ssid
, network
->ssid
, network
->ssid_len
),
5784 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because "
5785 "'%s (%pM)' has a stronger signal.\n",
5786 escaped
, network
->bssid
,
5787 print_ssid(ssid
, match
->network
->ssid
,
5788 match
->network
->ssid_len
),
5789 match
->network
->bssid
);
5793 /* If this network has already had an association attempt within the
5794 * last 3 seconds, do not try and associate again... */
5795 if (network
->last_associate
&&
5796 time_after(network
->last_associate
+ (HZ
* 3UL), jiffies
)) {
5797 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5798 "because of storming (%ums since last "
5799 "assoc attempt).\n",
5800 print_ssid(ssid
, network
->ssid
,
5803 jiffies_to_msecs(jiffies
-
5804 network
->last_associate
));
5808 /* Now go through and see if the requested network is valid... */
5809 if (priv
->ieee
->scan_age
!= 0 &&
5810 time_after(jiffies
, network
->last_scanned
+ priv
->ieee
->scan_age
)) {
5811 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5812 "because of age: %ums.\n",
5813 print_ssid(ssid
, network
->ssid
,
5816 jiffies_to_msecs(jiffies
-
5817 network
->last_scanned
));
5821 if ((priv
->config
& CFG_STATIC_CHANNEL
) &&
5822 (network
->channel
!= priv
->channel
)) {
5823 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5824 "because of channel mismatch: %d != %d.\n",
5825 print_ssid(ssid
, network
->ssid
,
5828 network
->channel
, priv
->channel
);
5832 /* Verify privacy compatability */
5833 if (((priv
->capability
& CAP_PRIVACY_ON
) ? 1 : 0) !=
5834 ((network
->capability
& WLAN_CAPABILITY_PRIVACY
) ? 1 : 0)) {
5835 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5836 "because of privacy mismatch: %s != %s.\n",
5837 print_ssid(ssid
, network
->ssid
,
5840 priv
->capability
& CAP_PRIVACY_ON
? "on" :
5842 network
->capability
&
5843 WLAN_CAPABILITY_PRIVACY
? "on" : "off");
5847 if ((priv
->config
& CFG_STATIC_BSSID
) &&
5848 memcmp(network
->bssid
, priv
->bssid
, ETH_ALEN
)) {
5849 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5850 "because of BSSID mismatch: %pM.\n",
5851 print_ssid(ssid
, network
->ssid
,
5853 network
->bssid
, priv
->bssid
);
5857 /* Filter out any incompatible freq / mode combinations */
5858 if (!libipw_is_valid_mode(priv
->ieee
, network
->mode
)) {
5859 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5860 "because of invalid frequency/mode "
5862 print_ssid(ssid
, network
->ssid
,
5868 /* Filter out invalid channel in current GEO */
5869 if (!libipw_is_valid_channel(priv
->ieee
, network
->channel
)) {
5870 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5871 "because of invalid channel in current GEO\n",
5872 print_ssid(ssid
, network
->ssid
,
5878 /* Ensure that the rates supported by the driver are compatible with
5879 * this AP, including verification of basic rates (mandatory) */
5880 if (!ipw_compatible_rates(priv
, network
, &rates
)) {
5881 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5882 "because configured rate mask excludes "
5883 "AP mandatory rate.\n",
5884 print_ssid(ssid
, network
->ssid
,
5890 if (rates
.num_rates
== 0) {
5891 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5892 "because of no compatible rates.\n",
5893 print_ssid(ssid
, network
->ssid
,
5899 /* TODO: Perform any further minimal comparititive tests. We do not
5900 * want to put too much policy logic here; intelligent scan selection
5901 * should occur within a generic IEEE 802.11 user space tool. */
5903 /* Set up 'new' AP to this network */
5904 ipw_copy_rates(&match
->rates
, &rates
);
5905 match
->network
= network
;
5907 IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n",
5908 print_ssid(ssid
, network
->ssid
, network
->ssid_len
),
5914 static void ipw_adhoc_create(struct ipw_priv
*priv
,
5915 struct libipw_network
*network
)
5917 const struct libipw_geo
*geo
= libipw_get_geo(priv
->ieee
);
5921 * For the purposes of scanning, we can set our wireless mode
5922 * to trigger scans across combinations of bands, but when it
5923 * comes to creating a new ad-hoc network, we have tell the FW
5924 * exactly which band to use.
5926 * We also have the possibility of an invalid channel for the
5927 * chossen band. Attempting to create a new ad-hoc network
5928 * with an invalid channel for wireless mode will trigger a
5932 switch (libipw_is_valid_channel(priv
->ieee
, priv
->channel
)) {
5933 case LIBIPW_52GHZ_BAND
:
5934 network
->mode
= IEEE_A
;
5935 i
= libipw_channel_to_index(priv
->ieee
, priv
->channel
);
5937 if (geo
->a
[i
].flags
& LIBIPW_CH_PASSIVE_ONLY
) {
5938 IPW_WARNING("Overriding invalid channel\n");
5939 priv
->channel
= geo
->a
[0].channel
;
5943 case LIBIPW_24GHZ_BAND
:
5944 if (priv
->ieee
->mode
& IEEE_G
)
5945 network
->mode
= IEEE_G
;
5947 network
->mode
= IEEE_B
;
5948 i
= libipw_channel_to_index(priv
->ieee
, priv
->channel
);
5950 if (geo
->bg
[i
].flags
& LIBIPW_CH_PASSIVE_ONLY
) {
5951 IPW_WARNING("Overriding invalid channel\n");
5952 priv
->channel
= geo
->bg
[0].channel
;
5957 IPW_WARNING("Overriding invalid channel\n");
5958 if (priv
->ieee
->mode
& IEEE_A
) {
5959 network
->mode
= IEEE_A
;
5960 priv
->channel
= geo
->a
[0].channel
;
5961 } else if (priv
->ieee
->mode
& IEEE_G
) {
5962 network
->mode
= IEEE_G
;
5963 priv
->channel
= geo
->bg
[0].channel
;
5965 network
->mode
= IEEE_B
;
5966 priv
->channel
= geo
->bg
[0].channel
;
5971 network
->channel
= priv
->channel
;
5972 priv
->config
|= CFG_ADHOC_PERSIST
;
5973 ipw_create_bssid(priv
, network
->bssid
);
5974 network
->ssid_len
= priv
->essid_len
;
5975 memcpy(network
->ssid
, priv
->essid
, priv
->essid_len
);
5976 memset(&network
->stats
, 0, sizeof(network
->stats
));
5977 network
->capability
= WLAN_CAPABILITY_IBSS
;
5978 if (!(priv
->config
& CFG_PREAMBLE_LONG
))
5979 network
->capability
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
5980 if (priv
->capability
& CAP_PRIVACY_ON
)
5981 network
->capability
|= WLAN_CAPABILITY_PRIVACY
;
5982 network
->rates_len
= min(priv
->rates
.num_rates
, MAX_RATES_LENGTH
);
5983 memcpy(network
->rates
, priv
->rates
.supported_rates
, network
->rates_len
);
5984 network
->rates_ex_len
= priv
->rates
.num_rates
- network
->rates_len
;
5985 memcpy(network
->rates_ex
,
5986 &priv
->rates
.supported_rates
[network
->rates_len
],
5987 network
->rates_ex_len
);
5988 network
->last_scanned
= 0;
5990 network
->last_associate
= 0;
5991 network
->time_stamp
[0] = 0;
5992 network
->time_stamp
[1] = 0;
5993 network
->beacon_interval
= 100; /* Default */
5994 network
->listen_interval
= 10; /* Default */
5995 network
->atim_window
= 0; /* Default */
5996 network
->wpa_ie_len
= 0;
5997 network
->rsn_ie_len
= 0;
6000 static void ipw_send_tgi_tx_key(struct ipw_priv
*priv
, int type
, int index
)
6002 struct ipw_tgi_tx_key key
;
6004 if (!(priv
->ieee
->sec
.flags
& (1 << index
)))
6008 memcpy(key
.key
, priv
->ieee
->sec
.keys
[index
], SCM_TEMPORAL_KEY_LENGTH
);
6009 key
.security_type
= type
;
6010 key
.station_index
= 0; /* always 0 for BSS */
6012 /* 0 for new key; previous value of counter (after fatal error) */
6013 key
.tx_counter
[0] = cpu_to_le32(0);
6014 key
.tx_counter
[1] = cpu_to_le32(0);
6016 ipw_send_cmd_pdu(priv
, IPW_CMD_TGI_TX_KEY
, sizeof(key
), &key
);
6019 static void ipw_send_wep_keys(struct ipw_priv
*priv
, int type
)
6021 struct ipw_wep_key key
;
6024 key
.cmd_id
= DINO_CMD_WEP_KEY
;
6027 /* Note: AES keys cannot be set for multiple times.
6028 * Only set it at the first time. */
6029 for (i
= 0; i
< 4; i
++) {
6030 key
.key_index
= i
| type
;
6031 if (!(priv
->ieee
->sec
.flags
& (1 << i
))) {
6036 key
.key_size
= priv
->ieee
->sec
.key_sizes
[i
];
6037 memcpy(key
.key
, priv
->ieee
->sec
.keys
[i
], key
.key_size
);
6039 ipw_send_cmd_pdu(priv
, IPW_CMD_WEP_KEY
, sizeof(key
), &key
);
6043 static void ipw_set_hw_decrypt_unicast(struct ipw_priv
*priv
, int level
)
6045 if (priv
->ieee
->host_encrypt
)
6050 priv
->sys_config
.disable_unicast_decryption
= 0;
6051 priv
->ieee
->host_decrypt
= 0;
6054 priv
->sys_config
.disable_unicast_decryption
= 1;
6055 priv
->ieee
->host_decrypt
= 1;
6058 priv
->sys_config
.disable_unicast_decryption
= 0;
6059 priv
->ieee
->host_decrypt
= 0;
6062 priv
->sys_config
.disable_unicast_decryption
= 1;
6069 static void ipw_set_hw_decrypt_multicast(struct ipw_priv
*priv
, int level
)
6071 if (priv
->ieee
->host_encrypt
)
6076 priv
->sys_config
.disable_multicast_decryption
= 0;
6079 priv
->sys_config
.disable_multicast_decryption
= 1;
6082 priv
->sys_config
.disable_multicast_decryption
= 0;
6085 priv
->sys_config
.disable_multicast_decryption
= 1;
6092 static void ipw_set_hwcrypto_keys(struct ipw_priv
*priv
)
6094 switch (priv
->ieee
->sec
.level
) {
6096 if (priv
->ieee
->sec
.flags
& SEC_ACTIVE_KEY
)
6097 ipw_send_tgi_tx_key(priv
,
6098 DCT_FLAG_EXT_SECURITY_CCM
,
6099 priv
->ieee
->sec
.active_key
);
6101 if (!priv
->ieee
->host_mc_decrypt
)
6102 ipw_send_wep_keys(priv
, DCW_WEP_KEY_SEC_TYPE_CCM
);
6105 if (priv
->ieee
->sec
.flags
& SEC_ACTIVE_KEY
)
6106 ipw_send_tgi_tx_key(priv
,
6107 DCT_FLAG_EXT_SECURITY_TKIP
,
6108 priv
->ieee
->sec
.active_key
);
6111 ipw_send_wep_keys(priv
, DCW_WEP_KEY_SEC_TYPE_WEP
);
6112 ipw_set_hw_decrypt_unicast(priv
, priv
->ieee
->sec
.level
);
6113 ipw_set_hw_decrypt_multicast(priv
, priv
->ieee
->sec
.level
);
6121 static void ipw_adhoc_check(void *data
)
6123 struct ipw_priv
*priv
= data
;
6125 if (priv
->missed_adhoc_beacons
++ > priv
->disassociate_threshold
&&
6126 !(priv
->config
& CFG_ADHOC_PERSIST
)) {
6127 IPW_DEBUG(IPW_DL_INFO
| IPW_DL_NOTIF
|
6128 IPW_DL_STATE
| IPW_DL_ASSOC
,
6129 "Missed beacon: %d - disassociate\n",
6130 priv
->missed_adhoc_beacons
);
6131 ipw_remove_current_network(priv
);
6132 ipw_disassociate(priv
);
6136 queue_delayed_work(priv
->workqueue
, &priv
->adhoc_check
,
6137 le16_to_cpu(priv
->assoc_request
.beacon_interval
));
6140 static void ipw_bg_adhoc_check(struct work_struct
*work
)
6142 struct ipw_priv
*priv
=
6143 container_of(work
, struct ipw_priv
, adhoc_check
.work
);
6144 mutex_lock(&priv
->mutex
);
6145 ipw_adhoc_check(priv
);
6146 mutex_unlock(&priv
->mutex
);
6149 static void ipw_debug_config(struct ipw_priv
*priv
)
6151 DECLARE_SSID_BUF(ssid
);
6152 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
6153 "[CFG 0x%08X]\n", priv
->config
);
6154 if (priv
->config
& CFG_STATIC_CHANNEL
)
6155 IPW_DEBUG_INFO("Channel locked to %d\n", priv
->channel
);
6157 IPW_DEBUG_INFO("Channel unlocked.\n");
6158 if (priv
->config
& CFG_STATIC_ESSID
)
6159 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
6160 print_ssid(ssid
, priv
->essid
, priv
->essid_len
));
6162 IPW_DEBUG_INFO("ESSID unlocked.\n");
6163 if (priv
->config
& CFG_STATIC_BSSID
)
6164 IPW_DEBUG_INFO("BSSID locked to %pM\n", priv
->bssid
);
6166 IPW_DEBUG_INFO("BSSID unlocked.\n");
6167 if (priv
->capability
& CAP_PRIVACY_ON
)
6168 IPW_DEBUG_INFO("PRIVACY on\n");
6170 IPW_DEBUG_INFO("PRIVACY off\n");
6171 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv
->rates_mask
);
6174 static void ipw_set_fixed_rate(struct ipw_priv
*priv
, int mode
)
6176 /* TODO: Verify that this works... */
6177 struct ipw_fixed_rate fr
;
6180 u16 new_tx_rates
= priv
->rates_mask
;
6182 /* Identify 'current FW band' and match it with the fixed
6185 switch (priv
->ieee
->freq_band
) {
6186 case LIBIPW_52GHZ_BAND
: /* A only */
6188 if (priv
->rates_mask
& ~LIBIPW_OFDM_RATES_MASK
) {
6189 /* Invalid fixed rate mask */
6191 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
6196 new_tx_rates
>>= LIBIPW_OFDM_SHIFT_MASK_A
;
6199 default: /* 2.4Ghz or Mixed */
6201 if (mode
== IEEE_B
) {
6202 if (new_tx_rates
& ~LIBIPW_CCK_RATES_MASK
) {
6203 /* Invalid fixed rate mask */
6205 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
6212 if (new_tx_rates
& ~(LIBIPW_CCK_RATES_MASK
|
6213 LIBIPW_OFDM_RATES_MASK
)) {
6214 /* Invalid fixed rate mask */
6216 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
6221 if (LIBIPW_OFDM_RATE_6MB_MASK
& new_tx_rates
) {
6222 mask
|= (LIBIPW_OFDM_RATE_6MB_MASK
>> 1);
6223 new_tx_rates
&= ~LIBIPW_OFDM_RATE_6MB_MASK
;
6226 if (LIBIPW_OFDM_RATE_9MB_MASK
& new_tx_rates
) {
6227 mask
|= (LIBIPW_OFDM_RATE_9MB_MASK
>> 1);
6228 new_tx_rates
&= ~LIBIPW_OFDM_RATE_9MB_MASK
;
6231 if (LIBIPW_OFDM_RATE_12MB_MASK
& new_tx_rates
) {
6232 mask
|= (LIBIPW_OFDM_RATE_12MB_MASK
>> 1);
6233 new_tx_rates
&= ~LIBIPW_OFDM_RATE_12MB_MASK
;
6236 new_tx_rates
|= mask
;
6240 fr
.tx_rates
= cpu_to_le16(new_tx_rates
);
6242 reg
= ipw_read32(priv
, IPW_MEM_FIXED_OVERRIDE
);
6243 ipw_write_reg32(priv
, reg
, *(u32
*) & fr
);
6246 static void ipw_abort_scan(struct ipw_priv
*priv
)
6250 if (priv
->status
& STATUS_SCAN_ABORTING
) {
6251 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6254 priv
->status
|= STATUS_SCAN_ABORTING
;
6256 err
= ipw_send_scan_abort(priv
);
6258 IPW_DEBUG_HC("Request to abort scan failed.\n");
6261 static void ipw_add_scan_channels(struct ipw_priv
*priv
,
6262 struct ipw_scan_request_ext
*scan
,
6265 int channel_index
= 0;
6266 const struct libipw_geo
*geo
;
6269 geo
= libipw_get_geo(priv
->ieee
);
6271 if (priv
->ieee
->freq_band
& LIBIPW_52GHZ_BAND
) {
6272 int start
= channel_index
;
6273 for (i
= 0; i
< geo
->a_channels
; i
++) {
6274 if ((priv
->status
& STATUS_ASSOCIATED
) &&
6275 geo
->a
[i
].channel
== priv
->channel
)
6278 scan
->channels_list
[channel_index
] = geo
->a
[i
].channel
;
6279 ipw_set_scan_type(scan
, channel_index
,
6281 flags
& LIBIPW_CH_PASSIVE_ONLY
?
6282 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
:
6286 if (start
!= channel_index
) {
6287 scan
->channels_list
[start
] = (u8
) (IPW_A_MODE
<< 6) |
6288 (channel_index
- start
);
6293 if (priv
->ieee
->freq_band
& LIBIPW_24GHZ_BAND
) {
6294 int start
= channel_index
;
6295 if (priv
->config
& CFG_SPEED_SCAN
) {
6297 u8 channels
[LIBIPW_24GHZ_CHANNELS
] = {
6298 /* nop out the list */
6303 while (channel_index
< IPW_SCAN_CHANNELS
- 1) {
6305 priv
->speed_scan
[priv
->speed_scan_pos
];
6307 priv
->speed_scan_pos
= 0;
6308 channel
= priv
->speed_scan
[0];
6310 if ((priv
->status
& STATUS_ASSOCIATED
) &&
6311 channel
== priv
->channel
) {
6312 priv
->speed_scan_pos
++;
6316 /* If this channel has already been
6317 * added in scan, break from loop
6318 * and this will be the first channel
6321 if (channels
[channel
- 1] != 0)
6324 channels
[channel
- 1] = 1;
6325 priv
->speed_scan_pos
++;
6327 scan
->channels_list
[channel_index
] = channel
;
6329 libipw_channel_to_index(priv
->ieee
, channel
);
6330 ipw_set_scan_type(scan
, channel_index
,
6333 LIBIPW_CH_PASSIVE_ONLY
?
6334 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6338 for (i
= 0; i
< geo
->bg_channels
; i
++) {
6339 if ((priv
->status
& STATUS_ASSOCIATED
) &&
6340 geo
->bg
[i
].channel
== priv
->channel
)
6343 scan
->channels_list
[channel_index
] =
6345 ipw_set_scan_type(scan
, channel_index
,
6348 LIBIPW_CH_PASSIVE_ONLY
?
6349 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6354 if (start
!= channel_index
) {
6355 scan
->channels_list
[start
] = (u8
) (IPW_B_MODE
<< 6) |
6356 (channel_index
- start
);
6361 static int ipw_passive_dwell_time(struct ipw_priv
*priv
)
6363 /* staying on passive channels longer than the DTIM interval during a
6364 * scan, while associated, causes the firmware to cancel the scan
6365 * without notification. Hence, don't stay on passive channels longer
6366 * than the beacon interval.
6368 if (priv
->status
& STATUS_ASSOCIATED
6369 && priv
->assoc_network
->beacon_interval
> 10)
6370 return priv
->assoc_network
->beacon_interval
- 10;
6375 static int ipw_request_scan_helper(struct ipw_priv
*priv
, int type
, int direct
)
6377 struct ipw_scan_request_ext scan
;
6378 int err
= 0, scan_type
;
6380 if (!(priv
->status
& STATUS_INIT
) ||
6381 (priv
->status
& STATUS_EXIT_PENDING
))
6384 mutex_lock(&priv
->mutex
);
6386 if (direct
&& (priv
->direct_scan_ssid_len
== 0)) {
6387 IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n");
6388 priv
->status
&= ~STATUS_DIRECT_SCAN_PENDING
;
6392 if (priv
->status
& STATUS_SCANNING
) {
6393 IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n");
6394 priv
->status
|= direct
? STATUS_DIRECT_SCAN_PENDING
:
6395 STATUS_SCAN_PENDING
;
6399 if (!(priv
->status
& STATUS_SCAN_FORCED
) &&
6400 priv
->status
& STATUS_SCAN_ABORTING
) {
6401 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6402 priv
->status
|= direct
? STATUS_DIRECT_SCAN_PENDING
:
6403 STATUS_SCAN_PENDING
;
6407 if (priv
->status
& STATUS_RF_KILL_MASK
) {
6408 IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n");
6409 priv
->status
|= direct
? STATUS_DIRECT_SCAN_PENDING
:
6410 STATUS_SCAN_PENDING
;
6414 memset(&scan
, 0, sizeof(scan
));
6415 scan
.full_scan_index
= cpu_to_le32(libipw_get_scans(priv
->ieee
));
6417 if (type
== IW_SCAN_TYPE_PASSIVE
) {
6418 IPW_DEBUG_WX("use passive scanning\n");
6419 scan_type
= IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
;
6420 scan
.dwell_time
[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
] =
6421 cpu_to_le16(ipw_passive_dwell_time(priv
));
6422 ipw_add_scan_channels(priv
, &scan
, scan_type
);
6426 /* Use active scan by default. */
6427 if (priv
->config
& CFG_SPEED_SCAN
)
6428 scan
.dwell_time
[IPW_SCAN_ACTIVE_BROADCAST_SCAN
] =
6431 scan
.dwell_time
[IPW_SCAN_ACTIVE_BROADCAST_SCAN
] =
6434 scan
.dwell_time
[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN
] =
6437 scan
.dwell_time
[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
] =
6438 cpu_to_le16(ipw_passive_dwell_time(priv
));
6439 scan
.dwell_time
[IPW_SCAN_ACTIVE_DIRECT_SCAN
] = cpu_to_le16(20);
6441 #ifdef CONFIG_IPW2200_MONITOR
6442 if (priv
->ieee
->iw_mode
== IW_MODE_MONITOR
) {
6446 switch (libipw_is_valid_channel(priv
->ieee
, priv
->channel
)) {
6447 case LIBIPW_52GHZ_BAND
:
6448 band
= (u8
) (IPW_A_MODE
<< 6) | 1;
6449 channel
= priv
->channel
;
6452 case LIBIPW_24GHZ_BAND
:
6453 band
= (u8
) (IPW_B_MODE
<< 6) | 1;
6454 channel
= priv
->channel
;
6458 band
= (u8
) (IPW_B_MODE
<< 6) | 1;
6463 scan
.channels_list
[0] = band
;
6464 scan
.channels_list
[1] = channel
;
6465 ipw_set_scan_type(&scan
, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
);
6467 /* NOTE: The card will sit on this channel for this time
6468 * period. Scan aborts are timing sensitive and frequently
6469 * result in firmware restarts. As such, it is best to
6470 * set a small dwell_time here and just keep re-issuing
6471 * scans. Otherwise fast channel hopping will not actually
6474 * TODO: Move SPEED SCAN support to all modes and bands */
6475 scan
.dwell_time
[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
] =
6478 #endif /* CONFIG_IPW2200_MONITOR */
6479 /* Honor direct scans first, otherwise if we are roaming make
6480 * this a direct scan for the current network. Finally,
6481 * ensure that every other scan is a fast channel hop scan */
6483 err
= ipw_send_ssid(priv
, priv
->direct_scan_ssid
,
6484 priv
->direct_scan_ssid_len
);
6486 IPW_DEBUG_HC("Attempt to send SSID command "
6491 scan_type
= IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN
;
6492 } else if ((priv
->status
& STATUS_ROAMING
)
6493 || (!(priv
->status
& STATUS_ASSOCIATED
)
6494 && (priv
->config
& CFG_STATIC_ESSID
)
6495 && (le32_to_cpu(scan
.full_scan_index
) % 2))) {
6496 err
= ipw_send_ssid(priv
, priv
->essid
, priv
->essid_len
);
6498 IPW_DEBUG_HC("Attempt to send SSID command "
6503 scan_type
= IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN
;
6505 scan_type
= IPW_SCAN_ACTIVE_BROADCAST_SCAN
;
6507 ipw_add_scan_channels(priv
, &scan
, scan_type
);
6508 #ifdef CONFIG_IPW2200_MONITOR
6513 err
= ipw_send_scan_request_ext(priv
, &scan
);
6515 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err
);
6519 priv
->status
|= STATUS_SCANNING
;
6521 priv
->status
&= ~STATUS_DIRECT_SCAN_PENDING
;
6522 priv
->direct_scan_ssid_len
= 0;
6524 priv
->status
&= ~STATUS_SCAN_PENDING
;
6526 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
6527 IPW_SCAN_CHECK_WATCHDOG
);
6529 mutex_unlock(&priv
->mutex
);
6533 static void ipw_request_passive_scan(struct work_struct
*work
)
6535 struct ipw_priv
*priv
=
6536 container_of(work
, struct ipw_priv
, request_passive_scan
.work
);
6537 ipw_request_scan_helper(priv
, IW_SCAN_TYPE_PASSIVE
, 0);
6540 static void ipw_request_scan(struct work_struct
*work
)
6542 struct ipw_priv
*priv
=
6543 container_of(work
, struct ipw_priv
, request_scan
.work
);
6544 ipw_request_scan_helper(priv
, IW_SCAN_TYPE_ACTIVE
, 0);
6547 static void ipw_request_direct_scan(struct work_struct
*work
)
6549 struct ipw_priv
*priv
=
6550 container_of(work
, struct ipw_priv
, request_direct_scan
.work
);
6551 ipw_request_scan_helper(priv
, IW_SCAN_TYPE_ACTIVE
, 1);
6554 static void ipw_bg_abort_scan(struct work_struct
*work
)
6556 struct ipw_priv
*priv
=
6557 container_of(work
, struct ipw_priv
, abort_scan
);
6558 mutex_lock(&priv
->mutex
);
6559 ipw_abort_scan(priv
);
6560 mutex_unlock(&priv
->mutex
);
6563 static int ipw_wpa_enable(struct ipw_priv
*priv
, int value
)
6565 /* This is called when wpa_supplicant loads and closes the driver
6567 priv
->ieee
->wpa_enabled
= value
;
6571 static int ipw_wpa_set_auth_algs(struct ipw_priv
*priv
, int value
)
6573 struct libipw_device
*ieee
= priv
->ieee
;
6574 struct libipw_security sec
= {
6575 .flags
= SEC_AUTH_MODE
,
6579 if (value
& IW_AUTH_ALG_SHARED_KEY
) {
6580 sec
.auth_mode
= WLAN_AUTH_SHARED_KEY
;
6582 } else if (value
& IW_AUTH_ALG_OPEN_SYSTEM
) {
6583 sec
.auth_mode
= WLAN_AUTH_OPEN
;
6585 } else if (value
& IW_AUTH_ALG_LEAP
) {
6586 sec
.auth_mode
= WLAN_AUTH_LEAP
;
6591 if (ieee
->set_security
)
6592 ieee
->set_security(ieee
->dev
, &sec
);
6599 static void ipw_wpa_assoc_frame(struct ipw_priv
*priv
, char *wpa_ie
,
6602 /* make sure WPA is enabled */
6603 ipw_wpa_enable(priv
, 1);
6606 static int ipw_set_rsn_capa(struct ipw_priv
*priv
,
6607 char *capabilities
, int length
)
6609 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6611 return ipw_send_cmd_pdu(priv
, IPW_CMD_RSN_CAPABILITIES
, length
,
6620 static int ipw_wx_set_genie(struct net_device
*dev
,
6621 struct iw_request_info
*info
,
6622 union iwreq_data
*wrqu
, char *extra
)
6624 struct ipw_priv
*priv
= libipw_priv(dev
);
6625 struct libipw_device
*ieee
= priv
->ieee
;
6629 if (wrqu
->data
.length
> MAX_WPA_IE_LEN
||
6630 (wrqu
->data
.length
&& extra
== NULL
))
6633 if (wrqu
->data
.length
) {
6634 buf
= kmemdup(extra
, wrqu
->data
.length
, GFP_KERNEL
);
6640 kfree(ieee
->wpa_ie
);
6642 ieee
->wpa_ie_len
= wrqu
->data
.length
;
6644 kfree(ieee
->wpa_ie
);
6645 ieee
->wpa_ie
= NULL
;
6646 ieee
->wpa_ie_len
= 0;
6649 ipw_wpa_assoc_frame(priv
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
6655 static int ipw_wx_get_genie(struct net_device
*dev
,
6656 struct iw_request_info
*info
,
6657 union iwreq_data
*wrqu
, char *extra
)
6659 struct ipw_priv
*priv
= libipw_priv(dev
);
6660 struct libipw_device
*ieee
= priv
->ieee
;
6663 if (ieee
->wpa_ie_len
== 0 || ieee
->wpa_ie
== NULL
) {
6664 wrqu
->data
.length
= 0;
6668 if (wrqu
->data
.length
< ieee
->wpa_ie_len
) {
6673 wrqu
->data
.length
= ieee
->wpa_ie_len
;
6674 memcpy(extra
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
6680 static int wext_cipher2level(int cipher
)
6683 case IW_AUTH_CIPHER_NONE
:
6685 case IW_AUTH_CIPHER_WEP40
:
6686 case IW_AUTH_CIPHER_WEP104
:
6688 case IW_AUTH_CIPHER_TKIP
:
6690 case IW_AUTH_CIPHER_CCMP
:
6698 static int ipw_wx_set_auth(struct net_device
*dev
,
6699 struct iw_request_info
*info
,
6700 union iwreq_data
*wrqu
, char *extra
)
6702 struct ipw_priv
*priv
= libipw_priv(dev
);
6703 struct libipw_device
*ieee
= priv
->ieee
;
6704 struct iw_param
*param
= &wrqu
->param
;
6705 struct lib80211_crypt_data
*crypt
;
6706 unsigned long flags
;
6709 switch (param
->flags
& IW_AUTH_INDEX
) {
6710 case IW_AUTH_WPA_VERSION
:
6712 case IW_AUTH_CIPHER_PAIRWISE
:
6713 ipw_set_hw_decrypt_unicast(priv
,
6714 wext_cipher2level(param
->value
));
6716 case IW_AUTH_CIPHER_GROUP
:
6717 ipw_set_hw_decrypt_multicast(priv
,
6718 wext_cipher2level(param
->value
));
6720 case IW_AUTH_KEY_MGMT
:
6722 * ipw2200 does not use these parameters
6726 case IW_AUTH_TKIP_COUNTERMEASURES
:
6727 crypt
= priv
->ieee
->crypt_info
.crypt
[priv
->ieee
->crypt_info
.tx_keyidx
];
6728 if (!crypt
|| !crypt
->ops
->set_flags
|| !crypt
->ops
->get_flags
)
6731 flags
= crypt
->ops
->get_flags(crypt
->priv
);
6734 flags
|= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES
;
6736 flags
&= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES
;
6738 crypt
->ops
->set_flags(flags
, crypt
->priv
);
6742 case IW_AUTH_DROP_UNENCRYPTED
:{
6745 * wpa_supplicant calls set_wpa_enabled when the driver
6746 * is loaded and unloaded, regardless of if WPA is being
6747 * used. No other calls are made which can be used to
6748 * determine if encryption will be used or not prior to
6749 * association being expected. If encryption is not being
6750 * used, drop_unencrypted is set to false, else true -- we
6751 * can use this to determine if the CAP_PRIVACY_ON bit should
6754 struct libipw_security sec
= {
6755 .flags
= SEC_ENABLED
,
6756 .enabled
= param
->value
,
6758 priv
->ieee
->drop_unencrypted
= param
->value
;
6759 /* We only change SEC_LEVEL for open mode. Others
6760 * are set by ipw_wpa_set_encryption.
6762 if (!param
->value
) {
6763 sec
.flags
|= SEC_LEVEL
;
6764 sec
.level
= SEC_LEVEL_0
;
6766 sec
.flags
|= SEC_LEVEL
;
6767 sec
.level
= SEC_LEVEL_1
;
6769 if (priv
->ieee
->set_security
)
6770 priv
->ieee
->set_security(priv
->ieee
->dev
, &sec
);
6774 case IW_AUTH_80211_AUTH_ALG
:
6775 ret
= ipw_wpa_set_auth_algs(priv
, param
->value
);
6778 case IW_AUTH_WPA_ENABLED
:
6779 ret
= ipw_wpa_enable(priv
, param
->value
);
6780 ipw_disassociate(priv
);
6783 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
6784 ieee
->ieee802_1x
= param
->value
;
6787 case IW_AUTH_PRIVACY_INVOKED
:
6788 ieee
->privacy_invoked
= param
->value
;
6798 static int ipw_wx_get_auth(struct net_device
*dev
,
6799 struct iw_request_info
*info
,
6800 union iwreq_data
*wrqu
, char *extra
)
6802 struct ipw_priv
*priv
= libipw_priv(dev
);
6803 struct libipw_device
*ieee
= priv
->ieee
;
6804 struct lib80211_crypt_data
*crypt
;
6805 struct iw_param
*param
= &wrqu
->param
;
6808 switch (param
->flags
& IW_AUTH_INDEX
) {
6809 case IW_AUTH_WPA_VERSION
:
6810 case IW_AUTH_CIPHER_PAIRWISE
:
6811 case IW_AUTH_CIPHER_GROUP
:
6812 case IW_AUTH_KEY_MGMT
:
6814 * wpa_supplicant will control these internally
6819 case IW_AUTH_TKIP_COUNTERMEASURES
:
6820 crypt
= priv
->ieee
->crypt_info
.crypt
[priv
->ieee
->crypt_info
.tx_keyidx
];
6821 if (!crypt
|| !crypt
->ops
->get_flags
)
6824 param
->value
= (crypt
->ops
->get_flags(crypt
->priv
) &
6825 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES
) ? 1 : 0;
6829 case IW_AUTH_DROP_UNENCRYPTED
:
6830 param
->value
= ieee
->drop_unencrypted
;
6833 case IW_AUTH_80211_AUTH_ALG
:
6834 param
->value
= ieee
->sec
.auth_mode
;
6837 case IW_AUTH_WPA_ENABLED
:
6838 param
->value
= ieee
->wpa_enabled
;
6841 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
6842 param
->value
= ieee
->ieee802_1x
;
6845 case IW_AUTH_ROAMING_CONTROL
:
6846 case IW_AUTH_PRIVACY_INVOKED
:
6847 param
->value
= ieee
->privacy_invoked
;
6856 /* SIOCSIWENCODEEXT */
6857 static int ipw_wx_set_encodeext(struct net_device
*dev
,
6858 struct iw_request_info
*info
,
6859 union iwreq_data
*wrqu
, char *extra
)
6861 struct ipw_priv
*priv
= libipw_priv(dev
);
6862 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
6865 if (ext
->alg
== IW_ENCODE_ALG_TKIP
) {
6866 /* IPW HW can't build TKIP MIC,
6867 host decryption still needed */
6868 if (ext
->ext_flags
& IW_ENCODE_EXT_GROUP_KEY
)
6869 priv
->ieee
->host_mc_decrypt
= 1;
6871 priv
->ieee
->host_encrypt
= 0;
6872 priv
->ieee
->host_encrypt_msdu
= 1;
6873 priv
->ieee
->host_decrypt
= 1;
6876 priv
->ieee
->host_encrypt
= 0;
6877 priv
->ieee
->host_encrypt_msdu
= 0;
6878 priv
->ieee
->host_decrypt
= 0;
6879 priv
->ieee
->host_mc_decrypt
= 0;
6883 return libipw_wx_set_encodeext(priv
->ieee
, info
, wrqu
, extra
);
6886 /* SIOCGIWENCODEEXT */
6887 static int ipw_wx_get_encodeext(struct net_device
*dev
,
6888 struct iw_request_info
*info
,
6889 union iwreq_data
*wrqu
, char *extra
)
6891 struct ipw_priv
*priv
= libipw_priv(dev
);
6892 return libipw_wx_get_encodeext(priv
->ieee
, info
, wrqu
, extra
);
6896 static int ipw_wx_set_mlme(struct net_device
*dev
,
6897 struct iw_request_info
*info
,
6898 union iwreq_data
*wrqu
, char *extra
)
6900 struct ipw_priv
*priv
= libipw_priv(dev
);
6901 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
6904 reason
= cpu_to_le16(mlme
->reason_code
);
6906 switch (mlme
->cmd
) {
6907 case IW_MLME_DEAUTH
:
6908 /* silently ignore */
6911 case IW_MLME_DISASSOC
:
6912 ipw_disassociate(priv
);
6921 #ifdef CONFIG_IPW2200_QOS
6925 * get the modulation type of the current network or
6926 * the card current mode
6928 static u8
ipw_qos_current_mode(struct ipw_priv
* priv
)
6932 if (priv
->status
& STATUS_ASSOCIATED
) {
6933 unsigned long flags
;
6935 spin_lock_irqsave(&priv
->ieee
->lock
, flags
);
6936 mode
= priv
->assoc_network
->mode
;
6937 spin_unlock_irqrestore(&priv
->ieee
->lock
, flags
);
6939 mode
= priv
->ieee
->mode
;
6941 IPW_DEBUG_QOS("QoS network/card mode %d\n", mode
);
6946 * Handle management frame beacon and probe response
6948 static int ipw_qos_handle_probe_response(struct ipw_priv
*priv
,
6950 struct libipw_network
*network
)
6952 u32 size
= sizeof(struct libipw_qos_parameters
);
6954 if (network
->capability
& WLAN_CAPABILITY_IBSS
)
6955 network
->qos_data
.active
= network
->qos_data
.supported
;
6957 if (network
->flags
& NETWORK_HAS_QOS_MASK
) {
6958 if (active_network
&&
6959 (network
->flags
& NETWORK_HAS_QOS_PARAMETERS
))
6960 network
->qos_data
.active
= network
->qos_data
.supported
;
6962 if ((network
->qos_data
.active
== 1) && (active_network
== 1) &&
6963 (network
->flags
& NETWORK_HAS_QOS_PARAMETERS
) &&
6964 (network
->qos_data
.old_param_count
!=
6965 network
->qos_data
.param_count
)) {
6966 network
->qos_data
.old_param_count
=
6967 network
->qos_data
.param_count
;
6968 schedule_work(&priv
->qos_activate
);
6969 IPW_DEBUG_QOS("QoS parameters change call "
6973 if ((priv
->ieee
->mode
== IEEE_B
) || (network
->mode
== IEEE_B
))
6974 memcpy(&network
->qos_data
.parameters
,
6975 &def_parameters_CCK
, size
);
6977 memcpy(&network
->qos_data
.parameters
,
6978 &def_parameters_OFDM
, size
);
6980 if ((network
->qos_data
.active
== 1) && (active_network
== 1)) {
6981 IPW_DEBUG_QOS("QoS was disabled call qos_activate\n");
6982 schedule_work(&priv
->qos_activate
);
6985 network
->qos_data
.active
= 0;
6986 network
->qos_data
.supported
= 0;
6988 if ((priv
->status
& STATUS_ASSOCIATED
) &&
6989 (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
) && (active_network
== 0)) {
6990 if (memcmp(network
->bssid
, priv
->bssid
, ETH_ALEN
))
6991 if (network
->capability
& WLAN_CAPABILITY_IBSS
)
6992 if ((network
->ssid_len
==
6993 priv
->assoc_network
->ssid_len
) &&
6994 !memcmp(network
->ssid
,
6995 priv
->assoc_network
->ssid
,
6996 network
->ssid_len
)) {
6997 queue_work(priv
->workqueue
,
6998 &priv
->merge_networks
);
7006 * This function set up the firmware to support QoS. It sends
7007 * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
7009 static int ipw_qos_activate(struct ipw_priv
*priv
,
7010 struct libipw_qos_data
*qos_network_data
)
7013 struct libipw_qos_parameters qos_parameters
[QOS_QOS_SETS
];
7014 struct libipw_qos_parameters
*active_one
= NULL
;
7015 u32 size
= sizeof(struct libipw_qos_parameters
);
7020 type
= ipw_qos_current_mode(priv
);
7022 active_one
= &(qos_parameters
[QOS_PARAM_SET_DEF_CCK
]);
7023 memcpy(active_one
, priv
->qos_data
.def_qos_parm_CCK
, size
);
7024 active_one
= &(qos_parameters
[QOS_PARAM_SET_DEF_OFDM
]);
7025 memcpy(active_one
, priv
->qos_data
.def_qos_parm_OFDM
, size
);
7027 if (qos_network_data
== NULL
) {
7028 if (type
== IEEE_B
) {
7029 IPW_DEBUG_QOS("QoS activate network mode %d\n", type
);
7030 active_one
= &def_parameters_CCK
;
7032 active_one
= &def_parameters_OFDM
;
7034 memcpy(&qos_parameters
[QOS_PARAM_SET_ACTIVE
], active_one
, size
);
7035 burst_duration
= ipw_qos_get_burst_duration(priv
);
7036 for (i
= 0; i
< QOS_QUEUE_NUM
; i
++)
7037 qos_parameters
[QOS_PARAM_SET_ACTIVE
].tx_op_limit
[i
] =
7038 cpu_to_le16(burst_duration
);
7039 } else if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
) {
7040 if (type
== IEEE_B
) {
7041 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
7043 if (priv
->qos_data
.qos_enable
== 0)
7044 active_one
= &def_parameters_CCK
;
7046 active_one
= priv
->qos_data
.def_qos_parm_CCK
;
7048 if (priv
->qos_data
.qos_enable
== 0)
7049 active_one
= &def_parameters_OFDM
;
7051 active_one
= priv
->qos_data
.def_qos_parm_OFDM
;
7053 memcpy(&qos_parameters
[QOS_PARAM_SET_ACTIVE
], active_one
, size
);
7055 unsigned long flags
;
7058 spin_lock_irqsave(&priv
->ieee
->lock
, flags
);
7059 active_one
= &(qos_network_data
->parameters
);
7060 qos_network_data
->old_param_count
=
7061 qos_network_data
->param_count
;
7062 memcpy(&qos_parameters
[QOS_PARAM_SET_ACTIVE
], active_one
, size
);
7063 active
= qos_network_data
->supported
;
7064 spin_unlock_irqrestore(&priv
->ieee
->lock
, flags
);
7067 burst_duration
= ipw_qos_get_burst_duration(priv
);
7068 for (i
= 0; i
< QOS_QUEUE_NUM
; i
++)
7069 qos_parameters
[QOS_PARAM_SET_ACTIVE
].
7070 tx_op_limit
[i
] = cpu_to_le16(burst_duration
);
7074 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
7075 err
= ipw_send_qos_params_command(priv
,
7076 (struct libipw_qos_parameters
*)
7077 &(qos_parameters
[0]));
7079 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7085 * send IPW_CMD_WME_INFO to the firmware
7087 static int ipw_qos_set_info_element(struct ipw_priv
*priv
)
7090 struct libipw_qos_information_element qos_info
;
7095 qos_info
.elementID
= QOS_ELEMENT_ID
;
7096 qos_info
.length
= sizeof(struct libipw_qos_information_element
) - 2;
7098 qos_info
.version
= QOS_VERSION_1
;
7099 qos_info
.ac_info
= 0;
7101 memcpy(qos_info
.qui
, qos_oui
, QOS_OUI_LEN
);
7102 qos_info
.qui_type
= QOS_OUI_TYPE
;
7103 qos_info
.qui_subtype
= QOS_OUI_INFO_SUB_TYPE
;
7105 ret
= ipw_send_qos_info_command(priv
, &qos_info
);
7107 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7113 * Set the QoS parameter with the association request structure
7115 static int ipw_qos_association(struct ipw_priv
*priv
,
7116 struct libipw_network
*network
)
7119 struct libipw_qos_data
*qos_data
= NULL
;
7120 struct libipw_qos_data ibss_data
= {
7125 switch (priv
->ieee
->iw_mode
) {
7127 BUG_ON(!(network
->capability
& WLAN_CAPABILITY_IBSS
));
7129 qos_data
= &ibss_data
;
7133 qos_data
= &network
->qos_data
;
7141 err
= ipw_qos_activate(priv
, qos_data
);
7143 priv
->assoc_request
.policy_support
&= ~HC_QOS_SUPPORT_ASSOC
;
7147 if (priv
->qos_data
.qos_enable
&& qos_data
->supported
) {
7148 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7149 priv
->assoc_request
.policy_support
|= HC_QOS_SUPPORT_ASSOC
;
7150 return ipw_qos_set_info_element(priv
);
7157 * handling the beaconing responses. if we get different QoS setting
7158 * off the network from the associated setting, adjust the QoS
7161 static int ipw_qos_association_resp(struct ipw_priv
*priv
,
7162 struct libipw_network
*network
)
7165 unsigned long flags
;
7166 u32 size
= sizeof(struct libipw_qos_parameters
);
7167 int set_qos_param
= 0;
7169 if ((priv
== NULL
) || (network
== NULL
) ||
7170 (priv
->assoc_network
== NULL
))
7173 if (!(priv
->status
& STATUS_ASSOCIATED
))
7176 if ((priv
->ieee
->iw_mode
!= IW_MODE_INFRA
))
7179 spin_lock_irqsave(&priv
->ieee
->lock
, flags
);
7180 if (network
->flags
& NETWORK_HAS_QOS_PARAMETERS
) {
7181 memcpy(&priv
->assoc_network
->qos_data
, &network
->qos_data
,
7182 sizeof(struct libipw_qos_data
));
7183 priv
->assoc_network
->qos_data
.active
= 1;
7184 if ((network
->qos_data
.old_param_count
!=
7185 network
->qos_data
.param_count
)) {
7187 network
->qos_data
.old_param_count
=
7188 network
->qos_data
.param_count
;
7192 if ((network
->mode
== IEEE_B
) || (priv
->ieee
->mode
== IEEE_B
))
7193 memcpy(&priv
->assoc_network
->qos_data
.parameters
,
7194 &def_parameters_CCK
, size
);
7196 memcpy(&priv
->assoc_network
->qos_data
.parameters
,
7197 &def_parameters_OFDM
, size
);
7198 priv
->assoc_network
->qos_data
.active
= 0;
7199 priv
->assoc_network
->qos_data
.supported
= 0;
7203 spin_unlock_irqrestore(&priv
->ieee
->lock
, flags
);
7205 if (set_qos_param
== 1)
7206 schedule_work(&priv
->qos_activate
);
7211 static u32
ipw_qos_get_burst_duration(struct ipw_priv
*priv
)
7218 if (!(priv
->ieee
->modulation
& LIBIPW_OFDM_MODULATION
))
7219 ret
= priv
->qos_data
.burst_duration_CCK
;
7221 ret
= priv
->qos_data
.burst_duration_OFDM
;
7227 * Initialize the setting of QoS global
7229 static void ipw_qos_init(struct ipw_priv
*priv
, int enable
,
7230 int burst_enable
, u32 burst_duration_CCK
,
7231 u32 burst_duration_OFDM
)
7233 priv
->qos_data
.qos_enable
= enable
;
7235 if (priv
->qos_data
.qos_enable
) {
7236 priv
->qos_data
.def_qos_parm_CCK
= &def_qos_parameters_CCK
;
7237 priv
->qos_data
.def_qos_parm_OFDM
= &def_qos_parameters_OFDM
;
7238 IPW_DEBUG_QOS("QoS is enabled\n");
7240 priv
->qos_data
.def_qos_parm_CCK
= &def_parameters_CCK
;
7241 priv
->qos_data
.def_qos_parm_OFDM
= &def_parameters_OFDM
;
7242 IPW_DEBUG_QOS("QoS is not enabled\n");
7245 priv
->qos_data
.burst_enable
= burst_enable
;
7248 priv
->qos_data
.burst_duration_CCK
= burst_duration_CCK
;
7249 priv
->qos_data
.burst_duration_OFDM
= burst_duration_OFDM
;
7251 priv
->qos_data
.burst_duration_CCK
= 0;
7252 priv
->qos_data
.burst_duration_OFDM
= 0;
7257 * map the packet priority to the right TX Queue
7259 static int ipw_get_tx_queue_number(struct ipw_priv
*priv
, u16 priority
)
7261 if (priority
> 7 || !priv
->qos_data
.qos_enable
)
7264 return from_priority_to_tx_queue
[priority
] - 1;
7267 static int ipw_is_qos_active(struct net_device
*dev
,
7268 struct sk_buff
*skb
)
7270 struct ipw_priv
*priv
= libipw_priv(dev
);
7271 struct libipw_qos_data
*qos_data
= NULL
;
7272 int active
, supported
;
7273 u8
*daddr
= skb
->data
+ ETH_ALEN
;
7274 int unicast
= !is_multicast_ether_addr(daddr
);
7276 if (!(priv
->status
& STATUS_ASSOCIATED
))
7279 qos_data
= &priv
->assoc_network
->qos_data
;
7281 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
) {
7283 qos_data
->active
= 0;
7285 qos_data
->active
= qos_data
->supported
;
7287 active
= qos_data
->active
;
7288 supported
= qos_data
->supported
;
7289 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7291 priv
->qos_data
.qos_enable
, active
, supported
, unicast
);
7292 if (active
&& priv
->qos_data
.qos_enable
)
7299 * add QoS parameter to the TX command
7301 static int ipw_qos_set_tx_queue_command(struct ipw_priv
*priv
,
7303 struct tfd_data
*tfd
)
7305 int tx_queue_id
= 0;
7308 tx_queue_id
= from_priority_to_tx_queue
[priority
] - 1;
7309 tfd
->tx_flags_ext
|= DCT_FLAG_EXT_QOS_ENABLED
;
7311 if (priv
->qos_data
.qos_no_ack_mask
& (1UL << tx_queue_id
)) {
7312 tfd
->tx_flags
&= ~DCT_FLAG_ACK_REQD
;
7313 tfd
->tfd
.tfd_26
.mchdr
.qos_ctrl
|= cpu_to_le16(CTRL_QOS_NO_ACK
);
7319 * background support to run QoS activate functionality
7321 static void ipw_bg_qos_activate(struct work_struct
*work
)
7323 struct ipw_priv
*priv
=
7324 container_of(work
, struct ipw_priv
, qos_activate
);
7326 mutex_lock(&priv
->mutex
);
7328 if (priv
->status
& STATUS_ASSOCIATED
)
7329 ipw_qos_activate(priv
, &(priv
->assoc_network
->qos_data
));
7331 mutex_unlock(&priv
->mutex
);
7334 static int ipw_handle_probe_response(struct net_device
*dev
,
7335 struct libipw_probe_response
*resp
,
7336 struct libipw_network
*network
)
7338 struct ipw_priv
*priv
= libipw_priv(dev
);
7339 int active_network
= ((priv
->status
& STATUS_ASSOCIATED
) &&
7340 (network
== priv
->assoc_network
));
7342 ipw_qos_handle_probe_response(priv
, active_network
, network
);
7347 static int ipw_handle_beacon(struct net_device
*dev
,
7348 struct libipw_beacon
*resp
,
7349 struct libipw_network
*network
)
7351 struct ipw_priv
*priv
= libipw_priv(dev
);
7352 int active_network
= ((priv
->status
& STATUS_ASSOCIATED
) &&
7353 (network
== priv
->assoc_network
));
7355 ipw_qos_handle_probe_response(priv
, active_network
, network
);
7360 static int ipw_handle_assoc_response(struct net_device
*dev
,
7361 struct libipw_assoc_response
*resp
,
7362 struct libipw_network
*network
)
7364 struct ipw_priv
*priv
= libipw_priv(dev
);
7365 ipw_qos_association_resp(priv
, network
);
7369 static int ipw_send_qos_params_command(struct ipw_priv
*priv
, struct libipw_qos_parameters
7372 return ipw_send_cmd_pdu(priv
, IPW_CMD_QOS_PARAMETERS
,
7373 sizeof(*qos_param
) * 3, qos_param
);
7376 static int ipw_send_qos_info_command(struct ipw_priv
*priv
, struct libipw_qos_information_element
7379 return ipw_send_cmd_pdu(priv
, IPW_CMD_WME_INFO
, sizeof(*qos_param
),
7383 #endif /* CONFIG_IPW2200_QOS */
7385 static int ipw_associate_network(struct ipw_priv
*priv
,
7386 struct libipw_network
*network
,
7387 struct ipw_supported_rates
*rates
, int roaming
)
7390 DECLARE_SSID_BUF(ssid
);
7392 if (priv
->config
& CFG_FIXED_RATE
)
7393 ipw_set_fixed_rate(priv
, network
->mode
);
7395 if (!(priv
->config
& CFG_STATIC_ESSID
)) {
7396 priv
->essid_len
= min(network
->ssid_len
,
7397 (u8
) IW_ESSID_MAX_SIZE
);
7398 memcpy(priv
->essid
, network
->ssid
, priv
->essid_len
);
7401 network
->last_associate
= jiffies
;
7403 memset(&priv
->assoc_request
, 0, sizeof(priv
->assoc_request
));
7404 priv
->assoc_request
.channel
= network
->channel
;
7405 priv
->assoc_request
.auth_key
= 0;
7407 if ((priv
->capability
& CAP_PRIVACY_ON
) &&
7408 (priv
->ieee
->sec
.auth_mode
== WLAN_AUTH_SHARED_KEY
)) {
7409 priv
->assoc_request
.auth_type
= AUTH_SHARED_KEY
;
7410 priv
->assoc_request
.auth_key
= priv
->ieee
->sec
.active_key
;
7412 if (priv
->ieee
->sec
.level
== SEC_LEVEL_1
)
7413 ipw_send_wep_keys(priv
, DCW_WEP_KEY_SEC_TYPE_WEP
);
7415 } else if ((priv
->capability
& CAP_PRIVACY_ON
) &&
7416 (priv
->ieee
->sec
.auth_mode
== WLAN_AUTH_LEAP
))
7417 priv
->assoc_request
.auth_type
= AUTH_LEAP
;
7419 priv
->assoc_request
.auth_type
= AUTH_OPEN
;
7421 if (priv
->ieee
->wpa_ie_len
) {
7422 priv
->assoc_request
.policy_support
= cpu_to_le16(0x02); /* RSN active */
7423 ipw_set_rsn_capa(priv
, priv
->ieee
->wpa_ie
,
7424 priv
->ieee
->wpa_ie_len
);
7428 * It is valid for our ieee device to support multiple modes, but
7429 * when it comes to associating to a given network we have to choose
7432 if (network
->mode
& priv
->ieee
->mode
& IEEE_A
)
7433 priv
->assoc_request
.ieee_mode
= IPW_A_MODE
;
7434 else if (network
->mode
& priv
->ieee
->mode
& IEEE_G
)
7435 priv
->assoc_request
.ieee_mode
= IPW_G_MODE
;
7436 else if (network
->mode
& priv
->ieee
->mode
& IEEE_B
)
7437 priv
->assoc_request
.ieee_mode
= IPW_B_MODE
;
7439 priv
->assoc_request
.capability
= cpu_to_le16(network
->capability
);
7440 if ((network
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
7441 && !(priv
->config
& CFG_PREAMBLE_LONG
)) {
7442 priv
->assoc_request
.preamble_length
= DCT_FLAG_SHORT_PREAMBLE
;
7444 priv
->assoc_request
.preamble_length
= DCT_FLAG_LONG_PREAMBLE
;
7446 /* Clear the short preamble if we won't be supporting it */
7447 priv
->assoc_request
.capability
&=
7448 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE
);
7451 /* Clear capability bits that aren't used in Ad Hoc */
7452 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
)
7453 priv
->assoc_request
.capability
&=
7454 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME
);
7456 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
7457 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
7458 roaming
? "Rea" : "A",
7459 print_ssid(ssid
, priv
->essid
, priv
->essid_len
),
7461 ipw_modes
[priv
->assoc_request
.ieee_mode
],
7463 (priv
->assoc_request
.preamble_length
==
7464 DCT_FLAG_LONG_PREAMBLE
) ? "long" : "short",
7465 network
->capability
&
7466 WLAN_CAPABILITY_SHORT_PREAMBLE
? "short" : "long",
7467 priv
->capability
& CAP_PRIVACY_ON
? "on " : "off",
7468 priv
->capability
& CAP_PRIVACY_ON
?
7469 (priv
->capability
& CAP_SHARED_KEY
? "(shared)" :
7471 priv
->capability
& CAP_PRIVACY_ON
? " key=" : "",
7472 priv
->capability
& CAP_PRIVACY_ON
?
7473 '1' + priv
->ieee
->sec
.active_key
: '.',
7474 priv
->capability
& CAP_PRIVACY_ON
? '.' : ' ');
7476 priv
->assoc_request
.beacon_interval
= cpu_to_le16(network
->beacon_interval
);
7477 if ((priv
->ieee
->iw_mode
== IW_MODE_ADHOC
) &&
7478 (network
->time_stamp
[0] == 0) && (network
->time_stamp
[1] == 0)) {
7479 priv
->assoc_request
.assoc_type
= HC_IBSS_START
;
7480 priv
->assoc_request
.assoc_tsf_msw
= 0;
7481 priv
->assoc_request
.assoc_tsf_lsw
= 0;
7483 if (unlikely(roaming
))
7484 priv
->assoc_request
.assoc_type
= HC_REASSOCIATE
;
7486 priv
->assoc_request
.assoc_type
= HC_ASSOCIATE
;
7487 priv
->assoc_request
.assoc_tsf_msw
= cpu_to_le32(network
->time_stamp
[1]);
7488 priv
->assoc_request
.assoc_tsf_lsw
= cpu_to_le32(network
->time_stamp
[0]);
7491 memcpy(priv
->assoc_request
.bssid
, network
->bssid
, ETH_ALEN
);
7493 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
) {
7494 memset(&priv
->assoc_request
.dest
, 0xFF, ETH_ALEN
);
7495 priv
->assoc_request
.atim_window
= cpu_to_le16(network
->atim_window
);
7497 memcpy(priv
->assoc_request
.dest
, network
->bssid
, ETH_ALEN
);
7498 priv
->assoc_request
.atim_window
= 0;
7501 priv
->assoc_request
.listen_interval
= cpu_to_le16(network
->listen_interval
);
7503 err
= ipw_send_ssid(priv
, priv
->essid
, priv
->essid_len
);
7505 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7509 rates
->ieee_mode
= priv
->assoc_request
.ieee_mode
;
7510 rates
->purpose
= IPW_RATE_CONNECT
;
7511 ipw_send_supported_rates(priv
, rates
);
7513 if (priv
->assoc_request
.ieee_mode
== IPW_G_MODE
)
7514 priv
->sys_config
.dot11g_auto_detection
= 1;
7516 priv
->sys_config
.dot11g_auto_detection
= 0;
7518 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
)
7519 priv
->sys_config
.answer_broadcast_ssid_probe
= 1;
7521 priv
->sys_config
.answer_broadcast_ssid_probe
= 0;
7523 err
= ipw_send_system_config(priv
);
7525 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7529 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network
->stats
.rssi
);
7530 err
= ipw_set_sensitivity(priv
, network
->stats
.rssi
+ IPW_RSSI_TO_DBM
);
7532 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7537 * If preemption is enabled, it is possible for the association
7538 * to complete before we return from ipw_send_associate. Therefore
7539 * we have to be sure and update our priviate data first.
7541 priv
->channel
= network
->channel
;
7542 memcpy(priv
->bssid
, network
->bssid
, ETH_ALEN
);
7543 priv
->status
|= STATUS_ASSOCIATING
;
7544 priv
->status
&= ~STATUS_SECURITY_UPDATED
;
7546 priv
->assoc_network
= network
;
7548 #ifdef CONFIG_IPW2200_QOS
7549 ipw_qos_association(priv
, network
);
7552 err
= ipw_send_associate(priv
, &priv
->assoc_request
);
7554 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7558 IPW_DEBUG(IPW_DL_STATE
, "associating: '%s' %pM\n",
7559 print_ssid(ssid
, priv
->essid
, priv
->essid_len
),
7565 static void ipw_roam(void *data
)
7567 struct ipw_priv
*priv
= data
;
7568 struct libipw_network
*network
= NULL
;
7569 struct ipw_network_match match
= {
7570 .network
= priv
->assoc_network
7573 /* The roaming process is as follows:
7575 * 1. Missed beacon threshold triggers the roaming process by
7576 * setting the status ROAM bit and requesting a scan.
7577 * 2. When the scan completes, it schedules the ROAM work
7578 * 3. The ROAM work looks at all of the known networks for one that
7579 * is a better network than the currently associated. If none
7580 * found, the ROAM process is over (ROAM bit cleared)
7581 * 4. If a better network is found, a disassociation request is
7583 * 5. When the disassociation completes, the roam work is again
7584 * scheduled. The second time through, the driver is no longer
7585 * associated, and the newly selected network is sent an
7586 * association request.
7587 * 6. At this point ,the roaming process is complete and the ROAM
7588 * status bit is cleared.
7591 /* If we are no longer associated, and the roaming bit is no longer
7592 * set, then we are not actively roaming, so just return */
7593 if (!(priv
->status
& (STATUS_ASSOCIATED
| STATUS_ROAMING
)))
7596 if (priv
->status
& STATUS_ASSOCIATED
) {
7597 /* First pass through ROAM process -- look for a better
7599 unsigned long flags
;
7600 u8 rssi
= priv
->assoc_network
->stats
.rssi
;
7601 priv
->assoc_network
->stats
.rssi
= -128;
7602 spin_lock_irqsave(&priv
->ieee
->lock
, flags
);
7603 list_for_each_entry(network
, &priv
->ieee
->network_list
, list
) {
7604 if (network
!= priv
->assoc_network
)
7605 ipw_best_network(priv
, &match
, network
, 1);
7607 spin_unlock_irqrestore(&priv
->ieee
->lock
, flags
);
7608 priv
->assoc_network
->stats
.rssi
= rssi
;
7610 if (match
.network
== priv
->assoc_network
) {
7611 IPW_DEBUG_ASSOC("No better APs in this network to "
7613 priv
->status
&= ~STATUS_ROAMING
;
7614 ipw_debug_config(priv
);
7618 ipw_send_disassociate(priv
, 1);
7619 priv
->assoc_network
= match
.network
;
7624 /* Second pass through ROAM process -- request association */
7625 ipw_compatible_rates(priv
, priv
->assoc_network
, &match
.rates
);
7626 ipw_associate_network(priv
, priv
->assoc_network
, &match
.rates
, 1);
7627 priv
->status
&= ~STATUS_ROAMING
;
7630 static void ipw_bg_roam(struct work_struct
*work
)
7632 struct ipw_priv
*priv
=
7633 container_of(work
, struct ipw_priv
, roam
);
7634 mutex_lock(&priv
->mutex
);
7636 mutex_unlock(&priv
->mutex
);
7639 static int ipw_associate(void *data
)
7641 struct ipw_priv
*priv
= data
;
7643 struct libipw_network
*network
= NULL
;
7644 struct ipw_network_match match
= {
7647 struct ipw_supported_rates
*rates
;
7648 struct list_head
*element
;
7649 unsigned long flags
;
7650 DECLARE_SSID_BUF(ssid
);
7652 if (priv
->ieee
->iw_mode
== IW_MODE_MONITOR
) {
7653 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7657 if (priv
->status
& (STATUS_ASSOCIATED
| STATUS_ASSOCIATING
)) {
7658 IPW_DEBUG_ASSOC("Not attempting association (already in "
7663 if (priv
->status
& STATUS_DISASSOCIATING
) {
7664 IPW_DEBUG_ASSOC("Not attempting association (in "
7665 "disassociating)\n ");
7666 queue_work(priv
->workqueue
, &priv
->associate
);
7670 if (!ipw_is_init(priv
) || (priv
->status
& STATUS_SCANNING
)) {
7671 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7676 if (!(priv
->config
& CFG_ASSOCIATE
) &&
7677 !(priv
->config
& (CFG_STATIC_ESSID
| CFG_STATIC_BSSID
))) {
7678 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
7682 /* Protect our use of the network_list */
7683 spin_lock_irqsave(&priv
->ieee
->lock
, flags
);
7684 list_for_each_entry(network
, &priv
->ieee
->network_list
, list
)
7685 ipw_best_network(priv
, &match
, network
, 0);
7687 network
= match
.network
;
7688 rates
= &match
.rates
;
7690 if (network
== NULL
&&
7691 priv
->ieee
->iw_mode
== IW_MODE_ADHOC
&&
7692 priv
->config
& CFG_ADHOC_CREATE
&&
7693 priv
->config
& CFG_STATIC_ESSID
&&
7694 priv
->config
& CFG_STATIC_CHANNEL
) {
7695 /* Use oldest network if the free list is empty */
7696 if (list_empty(&priv
->ieee
->network_free_list
)) {
7697 struct libipw_network
*oldest
= NULL
;
7698 struct libipw_network
*target
;
7700 list_for_each_entry(target
, &priv
->ieee
->network_list
, list
) {
7701 if ((oldest
== NULL
) ||
7702 (target
->last_scanned
< oldest
->last_scanned
))
7706 /* If there are no more slots, expire the oldest */
7707 list_del(&oldest
->list
);
7709 IPW_DEBUG_ASSOC("Expired '%s' (%pM) from "
7711 print_ssid(ssid
, target
->ssid
,
7714 list_add_tail(&target
->list
,
7715 &priv
->ieee
->network_free_list
);
7718 element
= priv
->ieee
->network_free_list
.next
;
7719 network
= list_entry(element
, struct libipw_network
, list
);
7720 ipw_adhoc_create(priv
, network
);
7721 rates
= &priv
->rates
;
7723 list_add_tail(&network
->list
, &priv
->ieee
->network_list
);
7725 spin_unlock_irqrestore(&priv
->ieee
->lock
, flags
);
7727 /* If we reached the end of the list, then we don't have any valid
7730 ipw_debug_config(priv
);
7732 if (!(priv
->status
& STATUS_SCANNING
)) {
7733 if (!(priv
->config
& CFG_SPEED_SCAN
))
7734 queue_delayed_work(priv
->workqueue
,
7735 &priv
->request_scan
,
7738 queue_delayed_work(priv
->workqueue
,
7739 &priv
->request_scan
, 0);
7745 ipw_associate_network(priv
, network
, rates
, 0);
7750 static void ipw_bg_associate(struct work_struct
*work
)
7752 struct ipw_priv
*priv
=
7753 container_of(work
, struct ipw_priv
, associate
);
7754 mutex_lock(&priv
->mutex
);
7755 ipw_associate(priv
);
7756 mutex_unlock(&priv
->mutex
);
7759 static void ipw_rebuild_decrypted_skb(struct ipw_priv
*priv
,
7760 struct sk_buff
*skb
)
7762 struct ieee80211_hdr
*hdr
;
7765 hdr
= (struct ieee80211_hdr
*)skb
->data
;
7766 fc
= le16_to_cpu(hdr
->frame_control
);
7767 if (!(fc
& IEEE80211_FCTL_PROTECTED
))
7770 fc
&= ~IEEE80211_FCTL_PROTECTED
;
7771 hdr
->frame_control
= cpu_to_le16(fc
);
7772 switch (priv
->ieee
->sec
.level
) {
7774 /* Remove CCMP HDR */
7775 memmove(skb
->data
+ LIBIPW_3ADDR_LEN
,
7776 skb
->data
+ LIBIPW_3ADDR_LEN
+ 8,
7777 skb
->len
- LIBIPW_3ADDR_LEN
- 8);
7778 skb_trim(skb
, skb
->len
- 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
7784 memmove(skb
->data
+ LIBIPW_3ADDR_LEN
,
7785 skb
->data
+ LIBIPW_3ADDR_LEN
+ 4,
7786 skb
->len
- LIBIPW_3ADDR_LEN
- 4);
7787 skb_trim(skb
, skb
->len
- 8); /* IV + ICV */
7792 printk(KERN_ERR
"Unknown security level %d\n",
7793 priv
->ieee
->sec
.level
);
7798 static void ipw_handle_data_packet(struct ipw_priv
*priv
,
7799 struct ipw_rx_mem_buffer
*rxb
,
7800 struct libipw_rx_stats
*stats
)
7802 struct net_device
*dev
= priv
->net_dev
;
7803 struct libipw_hdr_4addr
*hdr
;
7804 struct ipw_rx_packet
*pkt
= (struct ipw_rx_packet
*)rxb
->skb
->data
;
7806 /* We received data from the HW, so stop the watchdog */
7807 dev
->trans_start
= jiffies
;
7809 /* We only process data packets if the
7810 * interface is open */
7811 if (unlikely((le16_to_cpu(pkt
->u
.frame
.length
) + IPW_RX_FRAME_SIZE
) >
7812 skb_tailroom(rxb
->skb
))) {
7813 dev
->stats
.rx_errors
++;
7814 priv
->wstats
.discard
.misc
++;
7815 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7817 } else if (unlikely(!netif_running(priv
->net_dev
))) {
7818 dev
->stats
.rx_dropped
++;
7819 priv
->wstats
.discard
.misc
++;
7820 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7824 /* Advance skb->data to the start of the actual payload */
7825 skb_reserve(rxb
->skb
, offsetof(struct ipw_rx_packet
, u
.frame
.data
));
7827 /* Set the size of the skb to the size of the frame */
7828 skb_put(rxb
->skb
, le16_to_cpu(pkt
->u
.frame
.length
));
7830 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb
->skb
->len
);
7832 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
7833 hdr
= (struct libipw_hdr_4addr
*)rxb
->skb
->data
;
7834 if (priv
->ieee
->iw_mode
!= IW_MODE_MONITOR
&&
7835 (is_multicast_ether_addr(hdr
->addr1
) ?
7836 !priv
->ieee
->host_mc_decrypt
: !priv
->ieee
->host_decrypt
))
7837 ipw_rebuild_decrypted_skb(priv
, rxb
->skb
);
7839 if (!libipw_rx(priv
->ieee
, rxb
->skb
, stats
))
7840 dev
->stats
.rx_errors
++;
7841 else { /* libipw_rx succeeded, so it now owns the SKB */
7843 __ipw_led_activity_on(priv
);
7847 #ifdef CONFIG_IPW2200_RADIOTAP
7848 static void ipw_handle_data_packet_monitor(struct ipw_priv
*priv
,
7849 struct ipw_rx_mem_buffer
*rxb
,
7850 struct libipw_rx_stats
*stats
)
7852 struct net_device
*dev
= priv
->net_dev
;
7853 struct ipw_rx_packet
*pkt
= (struct ipw_rx_packet
*)rxb
->skb
->data
;
7854 struct ipw_rx_frame
*frame
= &pkt
->u
.frame
;
7856 /* initial pull of some data */
7857 u16 received_channel
= frame
->received_channel
;
7858 u8 antennaAndPhy
= frame
->antennaAndPhy
;
7859 s8 antsignal
= frame
->rssi_dbm
- IPW_RSSI_TO_DBM
; /* call it signed anyhow */
7860 u16 pktrate
= frame
->rate
;
7862 /* Magic struct that slots into the radiotap header -- no reason
7863 * to build this manually element by element, we can write it much
7864 * more efficiently than we can parse it. ORDER MATTERS HERE */
7865 struct ipw_rt_hdr
*ipw_rt
;
7867 short len
= le16_to_cpu(pkt
->u
.frame
.length
);
7869 /* We received data from the HW, so stop the watchdog */
7870 dev
->trans_start
= jiffies
;
7872 /* We only process data packets if the
7873 * interface is open */
7874 if (unlikely((le16_to_cpu(pkt
->u
.frame
.length
) + IPW_RX_FRAME_SIZE
) >
7875 skb_tailroom(rxb
->skb
))) {
7876 dev
->stats
.rx_errors
++;
7877 priv
->wstats
.discard
.misc
++;
7878 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7880 } else if (unlikely(!netif_running(priv
->net_dev
))) {
7881 dev
->stats
.rx_dropped
++;
7882 priv
->wstats
.discard
.misc
++;
7883 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7887 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7889 if (len
> IPW_RX_BUF_SIZE
- sizeof(struct ipw_rt_hdr
)) {
7890 /* FIXME: Should alloc bigger skb instead */
7891 dev
->stats
.rx_dropped
++;
7892 priv
->wstats
.discard
.misc
++;
7893 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7897 /* copy the frame itself */
7898 memmove(rxb
->skb
->data
+ sizeof(struct ipw_rt_hdr
),
7899 rxb
->skb
->data
+ IPW_RX_FRAME_SIZE
, len
);
7901 ipw_rt
= (struct ipw_rt_hdr
*)rxb
->skb
->data
;
7903 ipw_rt
->rt_hdr
.it_version
= PKTHDR_RADIOTAP_VERSION
;
7904 ipw_rt
->rt_hdr
.it_pad
= 0; /* always good to zero */
7905 ipw_rt
->rt_hdr
.it_len
= cpu_to_le16(sizeof(struct ipw_rt_hdr
)); /* total header+data */
7907 /* Big bitfield of all the fields we provide in radiotap */
7908 ipw_rt
->rt_hdr
.it_present
= cpu_to_le32(
7909 (1 << IEEE80211_RADIOTAP_TSFT
) |
7910 (1 << IEEE80211_RADIOTAP_FLAGS
) |
7911 (1 << IEEE80211_RADIOTAP_RATE
) |
7912 (1 << IEEE80211_RADIOTAP_CHANNEL
) |
7913 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL
) |
7914 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE
) |
7915 (1 << IEEE80211_RADIOTAP_ANTENNA
));
7917 /* Zero the flags, we'll add to them as we go */
7918 ipw_rt
->rt_flags
= 0;
7919 ipw_rt
->rt_tsf
= (u64
)(frame
->parent_tsf
[3] << 24 |
7920 frame
->parent_tsf
[2] << 16 |
7921 frame
->parent_tsf
[1] << 8 |
7922 frame
->parent_tsf
[0]);
7924 /* Convert signal to DBM */
7925 ipw_rt
->rt_dbmsignal
= antsignal
;
7926 ipw_rt
->rt_dbmnoise
= (s8
) le16_to_cpu(frame
->noise
);
7928 /* Convert the channel data and set the flags */
7929 ipw_rt
->rt_channel
= cpu_to_le16(ieee80211chan2mhz(received_channel
));
7930 if (received_channel
> 14) { /* 802.11a */
7931 ipw_rt
->rt_chbitmask
=
7932 cpu_to_le16((IEEE80211_CHAN_OFDM
| IEEE80211_CHAN_5GHZ
));
7933 } else if (antennaAndPhy
& 32) { /* 802.11b */
7934 ipw_rt
->rt_chbitmask
=
7935 cpu_to_le16((IEEE80211_CHAN_CCK
| IEEE80211_CHAN_2GHZ
));
7936 } else { /* 802.11g */
7937 ipw_rt
->rt_chbitmask
=
7938 cpu_to_le16(IEEE80211_CHAN_OFDM
| IEEE80211_CHAN_2GHZ
);
7941 /* set the rate in multiples of 500k/s */
7943 case IPW_TX_RATE_1MB
:
7944 ipw_rt
->rt_rate
= 2;
7946 case IPW_TX_RATE_2MB
:
7947 ipw_rt
->rt_rate
= 4;
7949 case IPW_TX_RATE_5MB
:
7950 ipw_rt
->rt_rate
= 10;
7952 case IPW_TX_RATE_6MB
:
7953 ipw_rt
->rt_rate
= 12;
7955 case IPW_TX_RATE_9MB
:
7956 ipw_rt
->rt_rate
= 18;
7958 case IPW_TX_RATE_11MB
:
7959 ipw_rt
->rt_rate
= 22;
7961 case IPW_TX_RATE_12MB
:
7962 ipw_rt
->rt_rate
= 24;
7964 case IPW_TX_RATE_18MB
:
7965 ipw_rt
->rt_rate
= 36;
7967 case IPW_TX_RATE_24MB
:
7968 ipw_rt
->rt_rate
= 48;
7970 case IPW_TX_RATE_36MB
:
7971 ipw_rt
->rt_rate
= 72;
7973 case IPW_TX_RATE_48MB
:
7974 ipw_rt
->rt_rate
= 96;
7976 case IPW_TX_RATE_54MB
:
7977 ipw_rt
->rt_rate
= 108;
7980 ipw_rt
->rt_rate
= 0;
7984 /* antenna number */
7985 ipw_rt
->rt_antenna
= (antennaAndPhy
& 3); /* Is this right? */
7987 /* set the preamble flag if we have it */
7988 if ((antennaAndPhy
& 64))
7989 ipw_rt
->rt_flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
7991 /* Set the size of the skb to the size of the frame */
7992 skb_put(rxb
->skb
, len
+ sizeof(struct ipw_rt_hdr
));
7994 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb
->skb
->len
);
7996 if (!libipw_rx(priv
->ieee
, rxb
->skb
, stats
))
7997 dev
->stats
.rx_errors
++;
7998 else { /* libipw_rx succeeded, so it now owns the SKB */
8000 /* no LED during capture */
8005 #ifdef CONFIG_IPW2200_PROMISCUOUS
8006 #define libipw_is_probe_response(fc) \
8007 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
8008 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
8010 #define libipw_is_management(fc) \
8011 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
8013 #define libipw_is_control(fc) \
8014 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
8016 #define libipw_is_data(fc) \
8017 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
8019 #define libipw_is_assoc_request(fc) \
8020 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
8022 #define libipw_is_reassoc_request(fc) \
8023 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
8025 static void ipw_handle_promiscuous_rx(struct ipw_priv
*priv
,
8026 struct ipw_rx_mem_buffer
*rxb
,
8027 struct libipw_rx_stats
*stats
)
8029 struct net_device
*dev
= priv
->prom_net_dev
;
8030 struct ipw_rx_packet
*pkt
= (struct ipw_rx_packet
*)rxb
->skb
->data
;
8031 struct ipw_rx_frame
*frame
= &pkt
->u
.frame
;
8032 struct ipw_rt_hdr
*ipw_rt
;
8034 /* First cache any information we need before we overwrite
8035 * the information provided in the skb from the hardware */
8036 struct ieee80211_hdr
*hdr
;
8037 u16 channel
= frame
->received_channel
;
8038 u8 phy_flags
= frame
->antennaAndPhy
;
8039 s8 signal
= frame
->rssi_dbm
- IPW_RSSI_TO_DBM
;
8040 s8 noise
= (s8
) le16_to_cpu(frame
->noise
);
8041 u8 rate
= frame
->rate
;
8042 short len
= le16_to_cpu(pkt
->u
.frame
.length
);
8043 struct sk_buff
*skb
;
8045 u16 filter
= priv
->prom_priv
->filter
;
8047 /* If the filter is set to not include Rx frames then return */
8048 if (filter
& IPW_PROM_NO_RX
)
8051 /* We received data from the HW, so stop the watchdog */
8052 dev
->trans_start
= jiffies
;
8054 if (unlikely((len
+ IPW_RX_FRAME_SIZE
) > skb_tailroom(rxb
->skb
))) {
8055 dev
->stats
.rx_errors
++;
8056 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
8060 /* We only process data packets if the interface is open */
8061 if (unlikely(!netif_running(dev
))) {
8062 dev
->stats
.rx_dropped
++;
8063 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
8067 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
8069 if (len
> IPW_RX_BUF_SIZE
- sizeof(struct ipw_rt_hdr
)) {
8070 /* FIXME: Should alloc bigger skb instead */
8071 dev
->stats
.rx_dropped
++;
8072 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
8076 hdr
= (void *)rxb
->skb
->data
+ IPW_RX_FRAME_SIZE
;
8077 if (libipw_is_management(le16_to_cpu(hdr
->frame_control
))) {
8078 if (filter
& IPW_PROM_NO_MGMT
)
8080 if (filter
& IPW_PROM_MGMT_HEADER_ONLY
)
8082 } else if (libipw_is_control(le16_to_cpu(hdr
->frame_control
))) {
8083 if (filter
& IPW_PROM_NO_CTL
)
8085 if (filter
& IPW_PROM_CTL_HEADER_ONLY
)
8087 } else if (libipw_is_data(le16_to_cpu(hdr
->frame_control
))) {
8088 if (filter
& IPW_PROM_NO_DATA
)
8090 if (filter
& IPW_PROM_DATA_HEADER_ONLY
)
8094 /* Copy the SKB since this is for the promiscuous side */
8095 skb
= skb_copy(rxb
->skb
, GFP_ATOMIC
);
8097 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
8101 /* copy the frame data to write after where the radiotap header goes */
8102 ipw_rt
= (void *)skb
->data
;
8105 len
= libipw_get_hdrlen(le16_to_cpu(hdr
->frame_control
));
8107 memcpy(ipw_rt
->payload
, hdr
, len
);
8109 ipw_rt
->rt_hdr
.it_version
= PKTHDR_RADIOTAP_VERSION
;
8110 ipw_rt
->rt_hdr
.it_pad
= 0; /* always good to zero */
8111 ipw_rt
->rt_hdr
.it_len
= cpu_to_le16(sizeof(*ipw_rt
)); /* total header+data */
8113 /* Set the size of the skb to the size of the frame */
8114 skb_put(skb
, sizeof(*ipw_rt
) + len
);
8116 /* Big bitfield of all the fields we provide in radiotap */
8117 ipw_rt
->rt_hdr
.it_present
= cpu_to_le32(
8118 (1 << IEEE80211_RADIOTAP_TSFT
) |
8119 (1 << IEEE80211_RADIOTAP_FLAGS
) |
8120 (1 << IEEE80211_RADIOTAP_RATE
) |
8121 (1 << IEEE80211_RADIOTAP_CHANNEL
) |
8122 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL
) |
8123 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE
) |
8124 (1 << IEEE80211_RADIOTAP_ANTENNA
));
8126 /* Zero the flags, we'll add to them as we go */
8127 ipw_rt
->rt_flags
= 0;
8128 ipw_rt
->rt_tsf
= (u64
)(frame
->parent_tsf
[3] << 24 |
8129 frame
->parent_tsf
[2] << 16 |
8130 frame
->parent_tsf
[1] << 8 |
8131 frame
->parent_tsf
[0]);
8133 /* Convert to DBM */
8134 ipw_rt
->rt_dbmsignal
= signal
;
8135 ipw_rt
->rt_dbmnoise
= noise
;
8137 /* Convert the channel data and set the flags */
8138 ipw_rt
->rt_channel
= cpu_to_le16(ieee80211chan2mhz(channel
));
8139 if (channel
> 14) { /* 802.11a */
8140 ipw_rt
->rt_chbitmask
=
8141 cpu_to_le16((IEEE80211_CHAN_OFDM
| IEEE80211_CHAN_5GHZ
));
8142 } else if (phy_flags
& (1 << 5)) { /* 802.11b */
8143 ipw_rt
->rt_chbitmask
=
8144 cpu_to_le16((IEEE80211_CHAN_CCK
| IEEE80211_CHAN_2GHZ
));
8145 } else { /* 802.11g */
8146 ipw_rt
->rt_chbitmask
=
8147 cpu_to_le16(IEEE80211_CHAN_OFDM
| IEEE80211_CHAN_2GHZ
);
8150 /* set the rate in multiples of 500k/s */
8152 case IPW_TX_RATE_1MB
:
8153 ipw_rt
->rt_rate
= 2;
8155 case IPW_TX_RATE_2MB
:
8156 ipw_rt
->rt_rate
= 4;
8158 case IPW_TX_RATE_5MB
:
8159 ipw_rt
->rt_rate
= 10;
8161 case IPW_TX_RATE_6MB
:
8162 ipw_rt
->rt_rate
= 12;
8164 case IPW_TX_RATE_9MB
:
8165 ipw_rt
->rt_rate
= 18;
8167 case IPW_TX_RATE_11MB
:
8168 ipw_rt
->rt_rate
= 22;
8170 case IPW_TX_RATE_12MB
:
8171 ipw_rt
->rt_rate
= 24;
8173 case IPW_TX_RATE_18MB
:
8174 ipw_rt
->rt_rate
= 36;
8176 case IPW_TX_RATE_24MB
:
8177 ipw_rt
->rt_rate
= 48;
8179 case IPW_TX_RATE_36MB
:
8180 ipw_rt
->rt_rate
= 72;
8182 case IPW_TX_RATE_48MB
:
8183 ipw_rt
->rt_rate
= 96;
8185 case IPW_TX_RATE_54MB
:
8186 ipw_rt
->rt_rate
= 108;
8189 ipw_rt
->rt_rate
= 0;
8193 /* antenna number */
8194 ipw_rt
->rt_antenna
= (phy_flags
& 3);
8196 /* set the preamble flag if we have it */
8197 if (phy_flags
& (1 << 6))
8198 ipw_rt
->rt_flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
8200 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb
->len
);
8202 if (!libipw_rx(priv
->prom_priv
->ieee
, skb
, stats
)) {
8203 dev
->stats
.rx_errors
++;
8204 dev_kfree_skb_any(skb
);
8209 static int is_network_packet(struct ipw_priv
*priv
,
8210 struct libipw_hdr_4addr
*header
)
8212 /* Filter incoming packets to determine if they are targetted toward
8213 * this network, discarding packets coming from ourselves */
8214 switch (priv
->ieee
->iw_mode
) {
8215 case IW_MODE_ADHOC
: /* Header: Dest. | Source | BSSID */
8216 /* packets from our adapter are dropped (echo) */
8217 if (!memcmp(header
->addr2
, priv
->net_dev
->dev_addr
, ETH_ALEN
))
8220 /* {broad,multi}cast packets to our BSSID go through */
8221 if (is_multicast_ether_addr(header
->addr1
))
8222 return !memcmp(header
->addr3
, priv
->bssid
, ETH_ALEN
);
8224 /* packets to our adapter go through */
8225 return !memcmp(header
->addr1
, priv
->net_dev
->dev_addr
,
8228 case IW_MODE_INFRA
: /* Header: Dest. | BSSID | Source */
8229 /* packets from our adapter are dropped (echo) */
8230 if (!memcmp(header
->addr3
, priv
->net_dev
->dev_addr
, ETH_ALEN
))
8233 /* {broad,multi}cast packets to our BSS go through */
8234 if (is_multicast_ether_addr(header
->addr1
))
8235 return !memcmp(header
->addr2
, priv
->bssid
, ETH_ALEN
);
8237 /* packets to our adapter go through */
8238 return !memcmp(header
->addr1
, priv
->net_dev
->dev_addr
,
8245 #define IPW_PACKET_RETRY_TIME HZ
8247 static int is_duplicate_packet(struct ipw_priv
*priv
,
8248 struct libipw_hdr_4addr
*header
)
8250 u16 sc
= le16_to_cpu(header
->seq_ctl
);
8251 u16 seq
= WLAN_GET_SEQ_SEQ(sc
);
8252 u16 frag
= WLAN_GET_SEQ_FRAG(sc
);
8253 u16
*last_seq
, *last_frag
;
8254 unsigned long *last_time
;
8256 switch (priv
->ieee
->iw_mode
) {
8259 struct list_head
*p
;
8260 struct ipw_ibss_seq
*entry
= NULL
;
8261 u8
*mac
= header
->addr2
;
8262 int index
= mac
[5] % IPW_IBSS_MAC_HASH_SIZE
;
8264 __list_for_each(p
, &priv
->ibss_mac_hash
[index
]) {
8266 list_entry(p
, struct ipw_ibss_seq
, list
);
8267 if (!memcmp(entry
->mac
, mac
, ETH_ALEN
))
8270 if (p
== &priv
->ibss_mac_hash
[index
]) {
8271 entry
= kmalloc(sizeof(*entry
), GFP_ATOMIC
);
8274 ("Cannot malloc new mac entry\n");
8277 memcpy(entry
->mac
, mac
, ETH_ALEN
);
8278 entry
->seq_num
= seq
;
8279 entry
->frag_num
= frag
;
8280 entry
->packet_time
= jiffies
;
8281 list_add(&entry
->list
,
8282 &priv
->ibss_mac_hash
[index
]);
8285 last_seq
= &entry
->seq_num
;
8286 last_frag
= &entry
->frag_num
;
8287 last_time
= &entry
->packet_time
;
8291 last_seq
= &priv
->last_seq_num
;
8292 last_frag
= &priv
->last_frag_num
;
8293 last_time
= &priv
->last_packet_time
;
8298 if ((*last_seq
== seq
) &&
8299 time_after(*last_time
+ IPW_PACKET_RETRY_TIME
, jiffies
)) {
8300 if (*last_frag
== frag
)
8302 if (*last_frag
+ 1 != frag
)
8303 /* out-of-order fragment */
8309 *last_time
= jiffies
;
8313 /* Comment this line now since we observed the card receives
8314 * duplicate packets but the FCTL_RETRY bit is not set in the
8315 * IBSS mode with fragmentation enabled.
8316 BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */
8320 static void ipw_handle_mgmt_packet(struct ipw_priv
*priv
,
8321 struct ipw_rx_mem_buffer
*rxb
,
8322 struct libipw_rx_stats
*stats
)
8324 struct sk_buff
*skb
= rxb
->skb
;
8325 struct ipw_rx_packet
*pkt
= (struct ipw_rx_packet
*)skb
->data
;
8326 struct libipw_hdr_4addr
*header
= (struct libipw_hdr_4addr
*)
8327 (skb
->data
+ IPW_RX_FRAME_SIZE
);
8329 libipw_rx_mgt(priv
->ieee
, header
, stats
);
8331 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
&&
8332 ((WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
)) ==
8333 IEEE80211_STYPE_PROBE_RESP
) ||
8334 (WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
)) ==
8335 IEEE80211_STYPE_BEACON
))) {
8336 if (!memcmp(header
->addr3
, priv
->bssid
, ETH_ALEN
))
8337 ipw_add_station(priv
, header
->addr2
);
8340 if (priv
->config
& CFG_NET_STATS
) {
8341 IPW_DEBUG_HC("sending stat packet\n");
8343 /* Set the size of the skb to the size of the full
8344 * ipw header and 802.11 frame */
8345 skb_put(skb
, le16_to_cpu(pkt
->u
.frame
.length
) +
8348 /* Advance past the ipw packet header to the 802.11 frame */
8349 skb_pull(skb
, IPW_RX_FRAME_SIZE
);
8351 /* Push the libipw_rx_stats before the 802.11 frame */
8352 memcpy(skb_push(skb
, sizeof(*stats
)), stats
, sizeof(*stats
));
8354 skb
->dev
= priv
->ieee
->dev
;
8356 /* Point raw at the libipw_stats */
8357 skb_reset_mac_header(skb
);
8359 skb
->pkt_type
= PACKET_OTHERHOST
;
8360 skb
->protocol
= cpu_to_be16(ETH_P_80211_STATS
);
8361 memset(skb
->cb
, 0, sizeof(rxb
->skb
->cb
));
8368 * Main entry function for recieving a packet with 80211 headers. This
8369 * should be called when ever the FW has notified us that there is a new
8370 * skb in the recieve queue.
8372 static void ipw_rx(struct ipw_priv
*priv
)
8374 struct ipw_rx_mem_buffer
*rxb
;
8375 struct ipw_rx_packet
*pkt
;
8376 struct libipw_hdr_4addr
*header
;
8381 r
= ipw_read32(priv
, IPW_RX_READ_INDEX
);
8382 w
= ipw_read32(priv
, IPW_RX_WRITE_INDEX
);
8383 i
= priv
->rxq
->read
;
8385 if (ipw_rx_queue_space (priv
->rxq
) > (RX_QUEUE_SIZE
/ 2))
8389 rxb
= priv
->rxq
->queue
[i
];
8390 if (unlikely(rxb
== NULL
)) {
8391 printk(KERN_CRIT
"Queue not allocated!\n");
8394 priv
->rxq
->queue
[i
] = NULL
;
8396 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->dma_addr
,
8398 PCI_DMA_FROMDEVICE
);
8400 pkt
= (struct ipw_rx_packet
*)rxb
->skb
->data
;
8401 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8402 pkt
->header
.message_type
,
8403 pkt
->header
.rx_seq_num
, pkt
->header
.control_bits
);
8405 switch (pkt
->header
.message_type
) {
8406 case RX_FRAME_TYPE
: /* 802.11 frame */ {
8407 struct libipw_rx_stats stats
= {
8408 .rssi
= pkt
->u
.frame
.rssi_dbm
-
8411 pkt
->u
.frame
.rssi_dbm
-
8412 IPW_RSSI_TO_DBM
+ 0x100,
8414 le16_to_cpu(pkt
->u
.frame
.noise
),
8415 .rate
= pkt
->u
.frame
.rate
,
8416 .mac_time
= jiffies
,
8418 pkt
->u
.frame
.received_channel
,
8421 control
& (1 << 0)) ?
8424 .len
= le16_to_cpu(pkt
->u
.frame
.length
),
8427 if (stats
.rssi
!= 0)
8428 stats
.mask
|= LIBIPW_STATMASK_RSSI
;
8429 if (stats
.signal
!= 0)
8430 stats
.mask
|= LIBIPW_STATMASK_SIGNAL
;
8431 if (stats
.noise
!= 0)
8432 stats
.mask
|= LIBIPW_STATMASK_NOISE
;
8433 if (stats
.rate
!= 0)
8434 stats
.mask
|= LIBIPW_STATMASK_RATE
;
8438 #ifdef CONFIG_IPW2200_PROMISCUOUS
8439 if (priv
->prom_net_dev
&& netif_running(priv
->prom_net_dev
))
8440 ipw_handle_promiscuous_rx(priv
, rxb
, &stats
);
8443 #ifdef CONFIG_IPW2200_MONITOR
8444 if (priv
->ieee
->iw_mode
== IW_MODE_MONITOR
) {
8445 #ifdef CONFIG_IPW2200_RADIOTAP
8447 ipw_handle_data_packet_monitor(priv
,
8451 ipw_handle_data_packet(priv
, rxb
,
8459 (struct libipw_hdr_4addr
*)(rxb
->skb
->
8462 /* TODO: Check Ad-Hoc dest/source and make sure
8463 * that we are actually parsing these packets
8464 * correctly -- we should probably use the
8465 * frame control of the packet and disregard
8466 * the current iw_mode */
8469 is_network_packet(priv
, header
);
8470 if (network_packet
&& priv
->assoc_network
) {
8471 priv
->assoc_network
->stats
.rssi
=
8473 priv
->exp_avg_rssi
=
8474 exponential_average(priv
->exp_avg_rssi
,
8475 stats
.rssi
, DEPTH_RSSI
);
8478 IPW_DEBUG_RX("Frame: len=%u\n",
8479 le16_to_cpu(pkt
->u
.frame
.length
));
8481 if (le16_to_cpu(pkt
->u
.frame
.length
) <
8482 libipw_get_hdrlen(le16_to_cpu(
8483 header
->frame_ctl
))) {
8485 ("Received packet is too small. "
8487 priv
->net_dev
->stats
.rx_errors
++;
8488 priv
->wstats
.discard
.misc
++;
8492 switch (WLAN_FC_GET_TYPE
8493 (le16_to_cpu(header
->frame_ctl
))) {
8495 case IEEE80211_FTYPE_MGMT
:
8496 ipw_handle_mgmt_packet(priv
, rxb
,
8500 case IEEE80211_FTYPE_CTL
:
8503 case IEEE80211_FTYPE_DATA
:
8504 if (unlikely(!network_packet
||
8505 is_duplicate_packet(priv
,
8508 IPW_DEBUG_DROP("Dropping: "
8518 ipw_handle_data_packet(priv
, rxb
,
8526 case RX_HOST_NOTIFICATION_TYPE
:{
8528 ("Notification: subtype=%02X flags=%02X size=%d\n",
8529 pkt
->u
.notification
.subtype
,
8530 pkt
->u
.notification
.flags
,
8531 le16_to_cpu(pkt
->u
.notification
.size
));
8532 ipw_rx_notification(priv
, &pkt
->u
.notification
);
8537 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8538 pkt
->header
.message_type
);
8542 /* For now we just don't re-use anything. We can tweak this
8543 * later to try and re-use notification packets and SKBs that
8544 * fail to Rx correctly */
8545 if (rxb
->skb
!= NULL
) {
8546 dev_kfree_skb_any(rxb
->skb
);
8550 pci_unmap_single(priv
->pci_dev
, rxb
->dma_addr
,
8551 IPW_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
8552 list_add_tail(&rxb
->list
, &priv
->rxq
->rx_used
);
8554 i
= (i
+ 1) % RX_QUEUE_SIZE
;
8556 /* If there are a lot of unsued frames, restock the Rx queue
8557 * so the ucode won't assert */
8559 priv
->rxq
->read
= i
;
8560 ipw_rx_queue_replenish(priv
);
8564 /* Backtrack one entry */
8565 priv
->rxq
->read
= i
;
8566 ipw_rx_queue_restock(priv
);
8569 #define DEFAULT_RTS_THRESHOLD 2304U
8570 #define MIN_RTS_THRESHOLD 1U
8571 #define MAX_RTS_THRESHOLD 2304U
8572 #define DEFAULT_BEACON_INTERVAL 100U
8573 #define DEFAULT_SHORT_RETRY_LIMIT 7U
8574 #define DEFAULT_LONG_RETRY_LIMIT 4U
8578 * @option: options to control different reset behaviour
8579 * 0 = reset everything except the 'disable' module_param
8580 * 1 = reset everything and print out driver info (for probe only)
8581 * 2 = reset everything
8583 static int ipw_sw_reset(struct ipw_priv
*priv
, int option
)
8585 int band
, modulation
;
8586 int old_mode
= priv
->ieee
->iw_mode
;
8588 /* Initialize module parameter values here */
8591 /* We default to disabling the LED code as right now it causes
8592 * too many systems to lock up... */
8594 priv
->config
|= CFG_NO_LED
;
8597 priv
->config
|= CFG_ASSOCIATE
;
8599 IPW_DEBUG_INFO("Auto associate disabled.\n");
8602 priv
->config
|= CFG_ADHOC_CREATE
;
8604 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8606 priv
->config
&= ~CFG_STATIC_ESSID
;
8607 priv
->essid_len
= 0;
8608 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
8610 if (disable
&& option
) {
8611 priv
->status
|= STATUS_RF_KILL_SW
;
8612 IPW_DEBUG_INFO("Radio disabled.\n");
8615 if (default_channel
!= 0) {
8616 priv
->config
|= CFG_STATIC_CHANNEL
;
8617 priv
->channel
= default_channel
;
8618 IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel
);
8619 /* TODO: Validate that provided channel is in range */
8621 #ifdef CONFIG_IPW2200_QOS
8622 ipw_qos_init(priv
, qos_enable
, qos_burst_enable
,
8623 burst_duration_CCK
, burst_duration_OFDM
);
8624 #endif /* CONFIG_IPW2200_QOS */
8626 switch (network_mode
) {
8628 priv
->ieee
->iw_mode
= IW_MODE_ADHOC
;
8629 priv
->net_dev
->type
= ARPHRD_ETHER
;
8632 #ifdef CONFIG_IPW2200_MONITOR
8634 priv
->ieee
->iw_mode
= IW_MODE_MONITOR
;
8635 #ifdef CONFIG_IPW2200_RADIOTAP
8636 priv
->net_dev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
8638 priv
->net_dev
->type
= ARPHRD_IEEE80211
;
8644 priv
->net_dev
->type
= ARPHRD_ETHER
;
8645 priv
->ieee
->iw_mode
= IW_MODE_INFRA
;
8650 priv
->ieee
->host_encrypt
= 0;
8651 priv
->ieee
->host_encrypt_msdu
= 0;
8652 priv
->ieee
->host_decrypt
= 0;
8653 priv
->ieee
->host_mc_decrypt
= 0;
8655 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto
? "on" : "off");
8657 /* IPW2200/2915 is abled to do hardware fragmentation. */
8658 priv
->ieee
->host_open_frag
= 0;
8660 if ((priv
->pci_dev
->device
== 0x4223) ||
8661 (priv
->pci_dev
->device
== 0x4224)) {
8663 printk(KERN_INFO DRV_NAME
8664 ": Detected Intel PRO/Wireless 2915ABG Network "
8666 priv
->ieee
->abg_true
= 1;
8667 band
= LIBIPW_52GHZ_BAND
| LIBIPW_24GHZ_BAND
;
8668 modulation
= LIBIPW_OFDM_MODULATION
|
8669 LIBIPW_CCK_MODULATION
;
8670 priv
->adapter
= IPW_2915ABG
;
8671 priv
->ieee
->mode
= IEEE_A
| IEEE_G
| IEEE_B
;
8674 printk(KERN_INFO DRV_NAME
8675 ": Detected Intel PRO/Wireless 2200BG Network "
8678 priv
->ieee
->abg_true
= 0;
8679 band
= LIBIPW_24GHZ_BAND
;
8680 modulation
= LIBIPW_OFDM_MODULATION
|
8681 LIBIPW_CCK_MODULATION
;
8682 priv
->adapter
= IPW_2200BG
;
8683 priv
->ieee
->mode
= IEEE_G
| IEEE_B
;
8686 priv
->ieee
->freq_band
= band
;
8687 priv
->ieee
->modulation
= modulation
;
8689 priv
->rates_mask
= LIBIPW_DEFAULT_RATES_MASK
;
8691 priv
->disassociate_threshold
= IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT
;
8692 priv
->roaming_threshold
= IPW_MB_ROAMING_THRESHOLD_DEFAULT
;
8694 priv
->rts_threshold
= DEFAULT_RTS_THRESHOLD
;
8695 priv
->short_retry_limit
= DEFAULT_SHORT_RETRY_LIMIT
;
8696 priv
->long_retry_limit
= DEFAULT_LONG_RETRY_LIMIT
;
8698 /* If power management is turned on, default to AC mode */
8699 priv
->power_mode
= IPW_POWER_AC
;
8700 priv
->tx_power
= IPW_TX_POWER_DEFAULT
;
8702 return old_mode
== priv
->ieee
->iw_mode
;
8706 * This file defines the Wireless Extension handlers. It does not
8707 * define any methods of hardware manipulation and relies on the
8708 * functions defined in ipw_main to provide the HW interaction.
8710 * The exception to this is the use of the ipw_get_ordinal()
8711 * function used to poll the hardware vs. making unecessary calls.
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
= libipw_priv(dev
);
8772 const struct libipw_geo
*geo
= libipw_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
= libipw_freq_to_channel(priv
->ieee
, fwrq
->m
);
8793 if (!(band
= libipw_is_valid_channel(priv
->ieee
, channel
)))
8796 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
) {
8797 i
= libipw_channel_to_index(priv
->ieee
, channel
);
8801 flags
= (band
== LIBIPW_24GHZ_BAND
) ?
8802 geo
->bg
[i
].flags
: geo
->a
[i
].flags
;
8803 if (flags
& LIBIPW_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
= libipw_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
= libipw_channel_to_index(priv
->ieee
, priv
->channel
);
8835 switch (libipw_is_valid_channel(priv
->ieee
, priv
->channel
)) {
8836 case LIBIPW_52GHZ_BAND
:
8837 wrqu
->freq
.m
= priv
->ieee
->geo
.a
[i
].freq
* 100000;
8840 case LIBIPW_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
= libipw_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 firmware */
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
= libipw_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
= libipw_priv(dev
);
8941 struct iw_range
*range
= (struct iw_range
*)extra
;
8942 const struct libipw_geo
*geo
= libipw_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' threshold 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
& LIBIPW_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
& LIBIPW_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 /* Event capability (kernel + driver) */
9015 range
->event_capa
[0] = (IW_EVENT_CAPA_K_0
|
9016 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY
) |
9017 IW_EVENT_CAPA_MASK(SIOCGIWAP
) |
9018 IW_EVENT_CAPA_MASK(SIOCGIWSCAN
));
9019 range
->event_capa
[1] = IW_EVENT_CAPA_K_1
;
9021 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
9022 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
9024 range
->scan_capa
= IW_SCAN_CAPA_ESSID
| IW_SCAN_CAPA_TYPE
;
9026 IPW_DEBUG_WX("GET Range\n");
9030 static int ipw_wx_set_wap(struct net_device
*dev
,
9031 struct iw_request_info
*info
,
9032 union iwreq_data
*wrqu
, char *extra
)
9034 struct ipw_priv
*priv
= libipw_priv(dev
);
9036 static const unsigned char any
[] = {
9037 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
9039 static const unsigned char off
[] = {
9040 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9043 if (wrqu
->ap_addr
.sa_family
!= ARPHRD_ETHER
)
9045 mutex_lock(&priv
->mutex
);
9046 if (!memcmp(any
, wrqu
->ap_addr
.sa_data
, ETH_ALEN
) ||
9047 !memcmp(off
, wrqu
->ap_addr
.sa_data
, ETH_ALEN
)) {
9048 /* we disable mandatory BSSID association */
9049 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
9050 priv
->config
&= ~CFG_STATIC_BSSID
;
9051 IPW_DEBUG_ASSOC("Attempting to associate with new "
9053 ipw_associate(priv
);
9054 mutex_unlock(&priv
->mutex
);
9058 priv
->config
|= CFG_STATIC_BSSID
;
9059 if (!memcmp(priv
->bssid
, wrqu
->ap_addr
.sa_data
, ETH_ALEN
)) {
9060 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
9061 mutex_unlock(&priv
->mutex
);
9065 IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n",
9066 wrqu
->ap_addr
.sa_data
);
9068 memcpy(priv
->bssid
, wrqu
->ap_addr
.sa_data
, ETH_ALEN
);
9070 /* Network configuration changed -- force [re]association */
9071 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
9072 if (!ipw_disassociate(priv
))
9073 ipw_associate(priv
);
9075 mutex_unlock(&priv
->mutex
);
9079 static int ipw_wx_get_wap(struct net_device
*dev
,
9080 struct iw_request_info
*info
,
9081 union iwreq_data
*wrqu
, char *extra
)
9083 struct ipw_priv
*priv
= libipw_priv(dev
);
9085 /* If we are associated, trying to associate, or have a statically
9086 * configured BSSID then return that; otherwise return ANY */
9087 mutex_lock(&priv
->mutex
);
9088 if (priv
->config
& CFG_STATIC_BSSID
||
9089 priv
->status
& (STATUS_ASSOCIATED
| STATUS_ASSOCIATING
)) {
9090 wrqu
->ap_addr
.sa_family
= ARPHRD_ETHER
;
9091 memcpy(wrqu
->ap_addr
.sa_data
, priv
->bssid
, ETH_ALEN
);
9093 memset(wrqu
->ap_addr
.sa_data
, 0, ETH_ALEN
);
9095 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n",
9096 wrqu
->ap_addr
.sa_data
);
9097 mutex_unlock(&priv
->mutex
);
9101 static int ipw_wx_set_essid(struct net_device
*dev
,
9102 struct iw_request_info
*info
,
9103 union iwreq_data
*wrqu
, char *extra
)
9105 struct ipw_priv
*priv
= libipw_priv(dev
);
9107 DECLARE_SSID_BUF(ssid
);
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_MAX_SIZE
);
9123 priv
->config
|= CFG_STATIC_ESSID
;
9125 if (priv
->essid_len
== length
&& !memcmp(priv
->essid
, extra
, length
)
9126 && (priv
->status
& (STATUS_ASSOCIATED
| STATUS_ASSOCIATING
))) {
9127 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
9128 mutex_unlock(&priv
->mutex
);
9132 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
9133 print_ssid(ssid
, extra
, length
), length
);
9135 priv
->essid_len
= length
;
9136 memcpy(priv
->essid
, extra
, priv
->essid_len
);
9138 /* Network configuration changed -- force [re]association */
9139 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
9140 if (!ipw_disassociate(priv
))
9141 ipw_associate(priv
);
9143 mutex_unlock(&priv
->mutex
);
9147 static int ipw_wx_get_essid(struct net_device
*dev
,
9148 struct iw_request_info
*info
,
9149 union iwreq_data
*wrqu
, char *extra
)
9151 struct ipw_priv
*priv
= libipw_priv(dev
);
9152 DECLARE_SSID_BUF(ssid
);
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 print_ssid(ssid
, 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
= libipw_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
= libipw_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
= libipw_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
= libipw_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
= libipw_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
= LIBIPW_DEFAULT_RATES_MASK
;
9268 /* Now we should reassociate */
9273 fixed
= wrqu
->bitrate
.fixed
;
9275 if (target_rate
== 1000000 || !fixed
)
9276 mask
|= LIBIPW_CCK_RATE_1MB_MASK
;
9277 if (target_rate
== 1000000)
9280 if (target_rate
== 2000000 || !fixed
)
9281 mask
|= LIBIPW_CCK_RATE_2MB_MASK
;
9282 if (target_rate
== 2000000)
9285 if (target_rate
== 5500000 || !fixed
)
9286 mask
|= LIBIPW_CCK_RATE_5MB_MASK
;
9287 if (target_rate
== 5500000)
9290 if (target_rate
== 6000000 || !fixed
)
9291 mask
|= LIBIPW_OFDM_RATE_6MB_MASK
;
9292 if (target_rate
== 6000000)
9295 if (target_rate
== 9000000 || !fixed
)
9296 mask
|= LIBIPW_OFDM_RATE_9MB_MASK
;
9297 if (target_rate
== 9000000)
9300 if (target_rate
== 11000000 || !fixed
)
9301 mask
|= LIBIPW_CCK_RATE_11MB_MASK
;
9302 if (target_rate
== 11000000)
9305 if (target_rate
== 12000000 || !fixed
)
9306 mask
|= LIBIPW_OFDM_RATE_12MB_MASK
;
9307 if (target_rate
== 12000000)
9310 if (target_rate
== 18000000 || !fixed
)
9311 mask
|= LIBIPW_OFDM_RATE_18MB_MASK
;
9312 if (target_rate
== 18000000)
9315 if (target_rate
== 24000000 || !fixed
)
9316 mask
|= LIBIPW_OFDM_RATE_24MB_MASK
;
9317 if (target_rate
== 24000000)
9320 if (target_rate
== 36000000 || !fixed
)
9321 mask
|= LIBIPW_OFDM_RATE_36MB_MASK
;
9322 if (target_rate
== 36000000)
9325 if (target_rate
== 48000000 || !fixed
)
9326 mask
|= LIBIPW_OFDM_RATE_48MB_MASK
;
9327 if (target_rate
== 48000000)
9330 if (target_rate
== 54000000 || !fixed
)
9331 mask
|= LIBIPW_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
== LIBIPW_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
= libipw_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
= libipw_priv(dev
);
9383 mutex_lock(&priv
->mutex
);
9384 if (wrqu
->rts
.disabled
|| !wrqu
->rts
.fixed
)
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
= libipw_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
= libipw_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
= libipw_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
= libipw_priv(dev
);
9472 mutex_lock(&priv
->mutex
);
9473 if (wrqu
->frag
.disabled
|| !wrqu
->frag
.fixed
)
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
= libipw_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
= libipw_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
= libipw_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 static int ipw_wx_set_scan(struct net_device
*dev
,
9571 struct iw_request_info
*info
,
9572 union iwreq_data
*wrqu
, char *extra
)
9574 struct ipw_priv
*priv
= libipw_priv(dev
);
9575 struct iw_scan_req
*req
= (struct iw_scan_req
*)extra
;
9576 struct delayed_work
*work
= NULL
;
9578 mutex_lock(&priv
->mutex
);
9580 priv
->user_requested_scan
= 1;
9582 if (wrqu
->data
.length
== sizeof(struct iw_scan_req
)) {
9583 if (wrqu
->data
.flags
& IW_SCAN_THIS_ESSID
) {
9584 int len
= min((int)req
->essid_len
,
9585 (int)sizeof(priv
->direct_scan_ssid
));
9586 memcpy(priv
->direct_scan_ssid
, req
->essid
, len
);
9587 priv
->direct_scan_ssid_len
= len
;
9588 work
= &priv
->request_direct_scan
;
9589 } else if (req
->scan_type
== IW_SCAN_TYPE_PASSIVE
) {
9590 work
= &priv
->request_passive_scan
;
9593 /* Normal active broadcast scan */
9594 work
= &priv
->request_scan
;
9597 mutex_unlock(&priv
->mutex
);
9599 IPW_DEBUG_WX("Start scan\n");
9601 queue_delayed_work(priv
->workqueue
, work
, 0);
9606 static int ipw_wx_get_scan(struct net_device
*dev
,
9607 struct iw_request_info
*info
,
9608 union iwreq_data
*wrqu
, char *extra
)
9610 struct ipw_priv
*priv
= libipw_priv(dev
);
9611 return libipw_wx_get_scan(priv
->ieee
, info
, wrqu
, extra
);
9614 static int ipw_wx_set_encode(struct net_device
*dev
,
9615 struct iw_request_info
*info
,
9616 union iwreq_data
*wrqu
, char *key
)
9618 struct ipw_priv
*priv
= libipw_priv(dev
);
9620 u32 cap
= priv
->capability
;
9622 mutex_lock(&priv
->mutex
);
9623 ret
= libipw_wx_set_encode(priv
->ieee
, info
, wrqu
, key
);
9625 /* In IBSS mode, we need to notify the firmware to update
9626 * the beacon info after we changed the capability. */
9627 if (cap
!= priv
->capability
&&
9628 priv
->ieee
->iw_mode
== IW_MODE_ADHOC
&&
9629 priv
->status
& STATUS_ASSOCIATED
)
9630 ipw_disassociate(priv
);
9632 mutex_unlock(&priv
->mutex
);
9636 static int ipw_wx_get_encode(struct net_device
*dev
,
9637 struct iw_request_info
*info
,
9638 union iwreq_data
*wrqu
, char *key
)
9640 struct ipw_priv
*priv
= libipw_priv(dev
);
9641 return libipw_wx_get_encode(priv
->ieee
, info
, wrqu
, key
);
9644 static int ipw_wx_set_power(struct net_device
*dev
,
9645 struct iw_request_info
*info
,
9646 union iwreq_data
*wrqu
, char *extra
)
9648 struct ipw_priv
*priv
= libipw_priv(dev
);
9650 mutex_lock(&priv
->mutex
);
9651 if (wrqu
->power
.disabled
) {
9652 priv
->power_mode
= IPW_POWER_LEVEL(priv
->power_mode
);
9653 err
= ipw_send_power_mode(priv
, IPW_POWER_MODE_CAM
);
9655 IPW_DEBUG_WX("failed setting power mode.\n");
9656 mutex_unlock(&priv
->mutex
);
9659 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
9660 mutex_unlock(&priv
->mutex
);
9664 switch (wrqu
->power
.flags
& IW_POWER_MODE
) {
9665 case IW_POWER_ON
: /* If not specified */
9666 case IW_POWER_MODE
: /* If set all mask */
9667 case IW_POWER_ALL_R
: /* If explicitly state all */
9669 default: /* Otherwise we don't support it */
9670 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9672 mutex_unlock(&priv
->mutex
);
9676 /* If the user hasn't specified a power management mode yet, default
9678 if (IPW_POWER_LEVEL(priv
->power_mode
) == IPW_POWER_AC
)
9679 priv
->power_mode
= IPW_POWER_ENABLED
| IPW_POWER_BATTERY
;
9681 priv
->power_mode
= IPW_POWER_ENABLED
| priv
->power_mode
;
9683 err
= ipw_send_power_mode(priv
, IPW_POWER_LEVEL(priv
->power_mode
));
9685 IPW_DEBUG_WX("failed setting power mode.\n");
9686 mutex_unlock(&priv
->mutex
);
9690 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv
->power_mode
);
9691 mutex_unlock(&priv
->mutex
);
9695 static int ipw_wx_get_power(struct net_device
*dev
,
9696 struct iw_request_info
*info
,
9697 union iwreq_data
*wrqu
, char *extra
)
9699 struct ipw_priv
*priv
= libipw_priv(dev
);
9700 mutex_lock(&priv
->mutex
);
9701 if (!(priv
->power_mode
& IPW_POWER_ENABLED
))
9702 wrqu
->power
.disabled
= 1;
9704 wrqu
->power
.disabled
= 0;
9706 mutex_unlock(&priv
->mutex
);
9707 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv
->power_mode
);
9712 static int ipw_wx_set_powermode(struct net_device
*dev
,
9713 struct iw_request_info
*info
,
9714 union iwreq_data
*wrqu
, char *extra
)
9716 struct ipw_priv
*priv
= libipw_priv(dev
);
9717 int mode
= *(int *)extra
;
9720 mutex_lock(&priv
->mutex
);
9721 if ((mode
< 1) || (mode
> IPW_POWER_LIMIT
))
9722 mode
= IPW_POWER_AC
;
9724 if (IPW_POWER_LEVEL(priv
->power_mode
) != mode
) {
9725 err
= ipw_send_power_mode(priv
, mode
);
9727 IPW_DEBUG_WX("failed setting power mode.\n");
9728 mutex_unlock(&priv
->mutex
);
9731 priv
->power_mode
= IPW_POWER_ENABLED
| mode
;
9733 mutex_unlock(&priv
->mutex
);
9737 #define MAX_WX_STRING 80
9738 static int ipw_wx_get_powermode(struct net_device
*dev
,
9739 struct iw_request_info
*info
,
9740 union iwreq_data
*wrqu
, char *extra
)
9742 struct ipw_priv
*priv
= libipw_priv(dev
);
9743 int level
= IPW_POWER_LEVEL(priv
->power_mode
);
9746 p
+= snprintf(p
, MAX_WX_STRING
, "Power save level: %d ", level
);
9750 p
+= snprintf(p
, MAX_WX_STRING
- (p
- extra
), "(AC)");
9752 case IPW_POWER_BATTERY
:
9753 p
+= snprintf(p
, MAX_WX_STRING
- (p
- extra
), "(BATTERY)");
9756 p
+= snprintf(p
, MAX_WX_STRING
- (p
- extra
),
9757 "(Timeout %dms, Period %dms)",
9758 timeout_duration
[level
- 1] / 1000,
9759 period_duration
[level
- 1] / 1000);
9762 if (!(priv
->power_mode
& IPW_POWER_ENABLED
))
9763 p
+= snprintf(p
, MAX_WX_STRING
- (p
- extra
), " OFF");
9765 wrqu
->data
.length
= p
- extra
+ 1;
9770 static int ipw_wx_set_wireless_mode(struct net_device
*dev
,
9771 struct iw_request_info
*info
,
9772 union iwreq_data
*wrqu
, char *extra
)
9774 struct ipw_priv
*priv
= libipw_priv(dev
);
9775 int mode
= *(int *)extra
;
9776 u8 band
= 0, modulation
= 0;
9778 if (mode
== 0 || mode
& ~IEEE_MODE_MASK
) {
9779 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode
);
9782 mutex_lock(&priv
->mutex
);
9783 if (priv
->adapter
== IPW_2915ABG
) {
9784 priv
->ieee
->abg_true
= 1;
9785 if (mode
& IEEE_A
) {
9786 band
|= LIBIPW_52GHZ_BAND
;
9787 modulation
|= LIBIPW_OFDM_MODULATION
;
9789 priv
->ieee
->abg_true
= 0;
9791 if (mode
& IEEE_A
) {
9792 IPW_WARNING("Attempt to set 2200BG into "
9794 mutex_unlock(&priv
->mutex
);
9798 priv
->ieee
->abg_true
= 0;
9801 if (mode
& IEEE_B
) {
9802 band
|= LIBIPW_24GHZ_BAND
;
9803 modulation
|= LIBIPW_CCK_MODULATION
;
9805 priv
->ieee
->abg_true
= 0;
9807 if (mode
& IEEE_G
) {
9808 band
|= LIBIPW_24GHZ_BAND
;
9809 modulation
|= LIBIPW_OFDM_MODULATION
;
9811 priv
->ieee
->abg_true
= 0;
9813 priv
->ieee
->mode
= mode
;
9814 priv
->ieee
->freq_band
= band
;
9815 priv
->ieee
->modulation
= modulation
;
9816 init_supported_rates(priv
, &priv
->rates
);
9818 /* Network configuration changed -- force [re]association */
9819 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9820 if (!ipw_disassociate(priv
)) {
9821 ipw_send_supported_rates(priv
, &priv
->rates
);
9822 ipw_associate(priv
);
9825 /* Update the band LEDs */
9826 ipw_led_band_on(priv
);
9828 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
9829 mode
& IEEE_A
? 'a' : '.',
9830 mode
& IEEE_B
? 'b' : '.', mode
& IEEE_G
? 'g' : '.');
9831 mutex_unlock(&priv
->mutex
);
9835 static int ipw_wx_get_wireless_mode(struct net_device
*dev
,
9836 struct iw_request_info
*info
,
9837 union iwreq_data
*wrqu
, char *extra
)
9839 struct ipw_priv
*priv
= libipw_priv(dev
);
9840 mutex_lock(&priv
->mutex
);
9841 switch (priv
->ieee
->mode
) {
9843 strncpy(extra
, "802.11a (1)", MAX_WX_STRING
);
9846 strncpy(extra
, "802.11b (2)", MAX_WX_STRING
);
9848 case IEEE_A
| IEEE_B
:
9849 strncpy(extra
, "802.11ab (3)", MAX_WX_STRING
);
9852 strncpy(extra
, "802.11g (4)", MAX_WX_STRING
);
9854 case IEEE_A
| IEEE_G
:
9855 strncpy(extra
, "802.11ag (5)", MAX_WX_STRING
);
9857 case IEEE_B
| IEEE_G
:
9858 strncpy(extra
, "802.11bg (6)", MAX_WX_STRING
);
9860 case IEEE_A
| IEEE_B
| IEEE_G
:
9861 strncpy(extra
, "802.11abg (7)", MAX_WX_STRING
);
9864 strncpy(extra
, "unknown", MAX_WX_STRING
);
9868 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra
);
9870 wrqu
->data
.length
= strlen(extra
) + 1;
9871 mutex_unlock(&priv
->mutex
);
9876 static int ipw_wx_set_preamble(struct net_device
*dev
,
9877 struct iw_request_info
*info
,
9878 union iwreq_data
*wrqu
, char *extra
)
9880 struct ipw_priv
*priv
= libipw_priv(dev
);
9881 int mode
= *(int *)extra
;
9882 mutex_lock(&priv
->mutex
);
9883 /* Switching from SHORT -> LONG requires a disassociation */
9885 if (!(priv
->config
& CFG_PREAMBLE_LONG
)) {
9886 priv
->config
|= CFG_PREAMBLE_LONG
;
9888 /* Network configuration changed -- force [re]association */
9890 ("[re]association triggered due to preamble change.\n");
9891 if (!ipw_disassociate(priv
))
9892 ipw_associate(priv
);
9898 priv
->config
&= ~CFG_PREAMBLE_LONG
;
9901 mutex_unlock(&priv
->mutex
);
9905 mutex_unlock(&priv
->mutex
);
9909 static int ipw_wx_get_preamble(struct net_device
*dev
,
9910 struct iw_request_info
*info
,
9911 union iwreq_data
*wrqu
, char *extra
)
9913 struct ipw_priv
*priv
= libipw_priv(dev
);
9914 mutex_lock(&priv
->mutex
);
9915 if (priv
->config
& CFG_PREAMBLE_LONG
)
9916 snprintf(wrqu
->name
, IFNAMSIZ
, "long (1)");
9918 snprintf(wrqu
->name
, IFNAMSIZ
, "auto (0)");
9919 mutex_unlock(&priv
->mutex
);
9923 #ifdef CONFIG_IPW2200_MONITOR
9924 static int ipw_wx_set_monitor(struct net_device
*dev
,
9925 struct iw_request_info
*info
,
9926 union iwreq_data
*wrqu
, char *extra
)
9928 struct ipw_priv
*priv
= libipw_priv(dev
);
9929 int *parms
= (int *)extra
;
9930 int enable
= (parms
[0] > 0);
9931 mutex_lock(&priv
->mutex
);
9932 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable
, parms
[1]);
9934 if (priv
->ieee
->iw_mode
!= IW_MODE_MONITOR
) {
9935 #ifdef CONFIG_IPW2200_RADIOTAP
9936 priv
->net_dev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
9938 priv
->net_dev
->type
= ARPHRD_IEEE80211
;
9940 queue_work(priv
->workqueue
, &priv
->adapter_restart
);
9943 ipw_set_channel(priv
, parms
[1]);
9945 if (priv
->ieee
->iw_mode
!= IW_MODE_MONITOR
) {
9946 mutex_unlock(&priv
->mutex
);
9949 priv
->net_dev
->type
= ARPHRD_ETHER
;
9950 queue_work(priv
->workqueue
, &priv
->adapter_restart
);
9952 mutex_unlock(&priv
->mutex
);
9956 #endif /* CONFIG_IPW2200_MONITOR */
9958 static int ipw_wx_reset(struct net_device
*dev
,
9959 struct iw_request_info
*info
,
9960 union iwreq_data
*wrqu
, char *extra
)
9962 struct ipw_priv
*priv
= libipw_priv(dev
);
9963 IPW_DEBUG_WX("RESET\n");
9964 queue_work(priv
->workqueue
, &priv
->adapter_restart
);
9968 static int ipw_wx_sw_reset(struct net_device
*dev
,
9969 struct iw_request_info
*info
,
9970 union iwreq_data
*wrqu
, char *extra
)
9972 struct ipw_priv
*priv
= libipw_priv(dev
);
9973 union iwreq_data wrqu_sec
= {
9975 .flags
= IW_ENCODE_DISABLED
,
9980 IPW_DEBUG_WX("SW_RESET\n");
9982 mutex_lock(&priv
->mutex
);
9984 ret
= ipw_sw_reset(priv
, 2);
9987 ipw_adapter_restart(priv
);
9990 /* The SW reset bit might have been toggled on by the 'disable'
9991 * module parameter, so take appropriate action */
9992 ipw_radio_kill_sw(priv
, priv
->status
& STATUS_RF_KILL_SW
);
9994 mutex_unlock(&priv
->mutex
);
9995 libipw_wx_set_encode(priv
->ieee
, info
, &wrqu_sec
, NULL
);
9996 mutex_lock(&priv
->mutex
);
9998 if (!(priv
->status
& STATUS_RF_KILL_MASK
)) {
9999 /* Configuration likely changed -- force [re]association */
10000 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
10002 if (!ipw_disassociate(priv
))
10003 ipw_associate(priv
);
10006 mutex_unlock(&priv
->mutex
);
10011 /* Rebase the WE IOCTLs to zero for the handler array */
10012 static iw_handler ipw_wx_handlers
[] = {
10013 IW_HANDLER(SIOCGIWNAME
, (iw_handler
)cfg80211_wext_giwname
),
10014 IW_HANDLER(SIOCSIWFREQ
, ipw_wx_set_freq
),
10015 IW_HANDLER(SIOCGIWFREQ
, ipw_wx_get_freq
),
10016 IW_HANDLER(SIOCSIWMODE
, ipw_wx_set_mode
),
10017 IW_HANDLER(SIOCGIWMODE
, ipw_wx_get_mode
),
10018 IW_HANDLER(SIOCSIWSENS
, ipw_wx_set_sens
),
10019 IW_HANDLER(SIOCGIWSENS
, ipw_wx_get_sens
),
10020 IW_HANDLER(SIOCGIWRANGE
, ipw_wx_get_range
),
10021 IW_HANDLER(SIOCSIWAP
, ipw_wx_set_wap
),
10022 IW_HANDLER(SIOCGIWAP
, ipw_wx_get_wap
),
10023 IW_HANDLER(SIOCSIWSCAN
, ipw_wx_set_scan
),
10024 IW_HANDLER(SIOCGIWSCAN
, ipw_wx_get_scan
),
10025 IW_HANDLER(SIOCSIWESSID
, ipw_wx_set_essid
),
10026 IW_HANDLER(SIOCGIWESSID
, ipw_wx_get_essid
),
10027 IW_HANDLER(SIOCSIWNICKN
, ipw_wx_set_nick
),
10028 IW_HANDLER(SIOCGIWNICKN
, ipw_wx_get_nick
),
10029 IW_HANDLER(SIOCSIWRATE
, ipw_wx_set_rate
),
10030 IW_HANDLER(SIOCGIWRATE
, ipw_wx_get_rate
),
10031 IW_HANDLER(SIOCSIWRTS
, ipw_wx_set_rts
),
10032 IW_HANDLER(SIOCGIWRTS
, ipw_wx_get_rts
),
10033 IW_HANDLER(SIOCSIWFRAG
, ipw_wx_set_frag
),
10034 IW_HANDLER(SIOCGIWFRAG
, ipw_wx_get_frag
),
10035 IW_HANDLER(SIOCSIWTXPOW
, ipw_wx_set_txpow
),
10036 IW_HANDLER(SIOCGIWTXPOW
, ipw_wx_get_txpow
),
10037 IW_HANDLER(SIOCSIWRETRY
, ipw_wx_set_retry
),
10038 IW_HANDLER(SIOCGIWRETRY
, ipw_wx_get_retry
),
10039 IW_HANDLER(SIOCSIWENCODE
, ipw_wx_set_encode
),
10040 IW_HANDLER(SIOCGIWENCODE
, ipw_wx_get_encode
),
10041 IW_HANDLER(SIOCSIWPOWER
, ipw_wx_set_power
),
10042 IW_HANDLER(SIOCGIWPOWER
, ipw_wx_get_power
),
10043 IW_HANDLER(SIOCSIWSPY
, iw_handler_set_spy
),
10044 IW_HANDLER(SIOCGIWSPY
, iw_handler_get_spy
),
10045 IW_HANDLER(SIOCSIWTHRSPY
, iw_handler_set_thrspy
),
10046 IW_HANDLER(SIOCGIWTHRSPY
, iw_handler_get_thrspy
),
10047 IW_HANDLER(SIOCSIWGENIE
, ipw_wx_set_genie
),
10048 IW_HANDLER(SIOCGIWGENIE
, ipw_wx_get_genie
),
10049 IW_HANDLER(SIOCSIWMLME
, ipw_wx_set_mlme
),
10050 IW_HANDLER(SIOCSIWAUTH
, ipw_wx_set_auth
),
10051 IW_HANDLER(SIOCGIWAUTH
, ipw_wx_get_auth
),
10052 IW_HANDLER(SIOCSIWENCODEEXT
, ipw_wx_set_encodeext
),
10053 IW_HANDLER(SIOCGIWENCODEEXT
, ipw_wx_get_encodeext
),
10057 IPW_PRIV_SET_POWER
= SIOCIWFIRSTPRIV
,
10058 IPW_PRIV_GET_POWER
,
10061 IPW_PRIV_SET_PREAMBLE
,
10062 IPW_PRIV_GET_PREAMBLE
,
10065 #ifdef CONFIG_IPW2200_MONITOR
10066 IPW_PRIV_SET_MONITOR
,
10070 static struct iw_priv_args ipw_priv_args
[] = {
10072 .cmd
= IPW_PRIV_SET_POWER
,
10073 .set_args
= IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
10074 .name
= "set_power"},
10076 .cmd
= IPW_PRIV_GET_POWER
,
10077 .get_args
= IW_PRIV_TYPE_CHAR
| IW_PRIV_SIZE_FIXED
| MAX_WX_STRING
,
10078 .name
= "get_power"},
10080 .cmd
= IPW_PRIV_SET_MODE
,
10081 .set_args
= IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
10082 .name
= "set_mode"},
10084 .cmd
= IPW_PRIV_GET_MODE
,
10085 .get_args
= IW_PRIV_TYPE_CHAR
| IW_PRIV_SIZE_FIXED
| MAX_WX_STRING
,
10086 .name
= "get_mode"},
10088 .cmd
= IPW_PRIV_SET_PREAMBLE
,
10089 .set_args
= IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
10090 .name
= "set_preamble"},
10092 .cmd
= IPW_PRIV_GET_PREAMBLE
,
10093 .get_args
= IW_PRIV_TYPE_CHAR
| IW_PRIV_SIZE_FIXED
| IFNAMSIZ
,
10094 .name
= "get_preamble"},
10097 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 0, 0, "reset"},
10100 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 0, 0, "sw_reset"},
10101 #ifdef CONFIG_IPW2200_MONITOR
10103 IPW_PRIV_SET_MONITOR
,
10104 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 2, 0, "monitor"},
10105 #endif /* CONFIG_IPW2200_MONITOR */
10108 static iw_handler ipw_priv_handler
[] = {
10109 ipw_wx_set_powermode
,
10110 ipw_wx_get_powermode
,
10111 ipw_wx_set_wireless_mode
,
10112 ipw_wx_get_wireless_mode
,
10113 ipw_wx_set_preamble
,
10114 ipw_wx_get_preamble
,
10117 #ifdef CONFIG_IPW2200_MONITOR
10118 ipw_wx_set_monitor
,
10122 static struct iw_handler_def ipw_wx_handler_def
= {
10123 .standard
= ipw_wx_handlers
,
10124 .num_standard
= ARRAY_SIZE(ipw_wx_handlers
),
10125 .num_private
= ARRAY_SIZE(ipw_priv_handler
),
10126 .num_private_args
= ARRAY_SIZE(ipw_priv_args
),
10127 .private = ipw_priv_handler
,
10128 .private_args
= ipw_priv_args
,
10129 .get_wireless_stats
= ipw_get_wireless_stats
,
10133 * Get wireless statistics.
10134 * Called by /proc/net/wireless
10135 * Also called by SIOCGIWSTATS
10137 static struct iw_statistics
*ipw_get_wireless_stats(struct net_device
*dev
)
10139 struct ipw_priv
*priv
= libipw_priv(dev
);
10140 struct iw_statistics
*wstats
;
10142 wstats
= &priv
->wstats
;
10144 /* if hw is disabled, then ipw_get_ordinal() can't be called.
10145 * netdev->get_wireless_stats seems to be called before fw is
10146 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
10147 * and associated; if not associcated, the values are all meaningless
10148 * anyway, so set them all to NULL and INVALID */
10149 if (!(priv
->status
& STATUS_ASSOCIATED
)) {
10150 wstats
->miss
.beacon
= 0;
10151 wstats
->discard
.retries
= 0;
10152 wstats
->qual
.qual
= 0;
10153 wstats
->qual
.level
= 0;
10154 wstats
->qual
.noise
= 0;
10155 wstats
->qual
.updated
= 7;
10156 wstats
->qual
.updated
|= IW_QUAL_NOISE_INVALID
|
10157 IW_QUAL_QUAL_INVALID
| IW_QUAL_LEVEL_INVALID
;
10161 wstats
->qual
.qual
= priv
->quality
;
10162 wstats
->qual
.level
= priv
->exp_avg_rssi
;
10163 wstats
->qual
.noise
= priv
->exp_avg_noise
;
10164 wstats
->qual
.updated
= IW_QUAL_QUAL_UPDATED
| IW_QUAL_LEVEL_UPDATED
|
10165 IW_QUAL_NOISE_UPDATED
| IW_QUAL_DBM
;
10167 wstats
->miss
.beacon
= average_value(&priv
->average_missed_beacons
);
10168 wstats
->discard
.retries
= priv
->last_tx_failures
;
10169 wstats
->discard
.code
= priv
->ieee
->ieee_stats
.rx_discards_undecryptable
;
10171 /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
10172 goto fail_get_ordinal;
10173 wstats->discard.retries += tx_retry; */
10178 /* net device stuff */
10180 static void init_sys_config(struct ipw_sys_config
*sys_config
)
10182 memset(sys_config
, 0, sizeof(struct ipw_sys_config
));
10183 sys_config
->bt_coexistence
= 0;
10184 sys_config
->answer_broadcast_ssid_probe
= 0;
10185 sys_config
->accept_all_data_frames
= 0;
10186 sys_config
->accept_non_directed_frames
= 1;
10187 sys_config
->exclude_unicast_unencrypted
= 0;
10188 sys_config
->disable_unicast_decryption
= 1;
10189 sys_config
->exclude_multicast_unencrypted
= 0;
10190 sys_config
->disable_multicast_decryption
= 1;
10191 if (antenna
< CFG_SYS_ANTENNA_BOTH
|| antenna
> CFG_SYS_ANTENNA_B
)
10192 antenna
= CFG_SYS_ANTENNA_BOTH
;
10193 sys_config
->antenna_diversity
= antenna
;
10194 sys_config
->pass_crc_to_host
= 0; /* TODO: See if 1 gives us FCS */
10195 sys_config
->dot11g_auto_detection
= 0;
10196 sys_config
->enable_cts_to_self
= 0;
10197 sys_config
->bt_coexist_collision_thr
= 0;
10198 sys_config
->pass_noise_stats_to_host
= 1; /* 1 -- fix for 256 */
10199 sys_config
->silence_threshold
= 0x1e;
10202 static int ipw_net_open(struct net_device
*dev
)
10204 IPW_DEBUG_INFO("dev->open\n");
10205 netif_start_queue(dev
);
10209 static int ipw_net_stop(struct net_device
*dev
)
10211 IPW_DEBUG_INFO("dev->close\n");
10212 netif_stop_queue(dev
);
10219 modify to send one tfd per fragment instead of using chunking. otherwise
10220 we need to heavily modify the libipw_skb_to_txb.
10223 static int ipw_tx_skb(struct ipw_priv
*priv
, struct libipw_txb
*txb
,
10226 struct libipw_hdr_3addrqos
*hdr
= (struct libipw_hdr_3addrqos
*)
10227 txb
->fragments
[0]->data
;
10229 struct tfd_frame
*tfd
;
10230 #ifdef CONFIG_IPW2200_QOS
10231 int tx_id
= ipw_get_tx_queue_number(priv
, pri
);
10232 struct clx2_tx_queue
*txq
= &priv
->txq
[tx_id
];
10234 struct clx2_tx_queue
*txq
= &priv
->txq
[0];
10236 struct clx2_queue
*q
= &txq
->q
;
10237 u8 id
, hdr_len
, unicast
;
10240 if (!(priv
->status
& STATUS_ASSOCIATED
))
10243 hdr_len
= libipw_get_hdrlen(le16_to_cpu(hdr
->frame_ctl
));
10244 switch (priv
->ieee
->iw_mode
) {
10245 case IW_MODE_ADHOC
:
10246 unicast
= !is_multicast_ether_addr(hdr
->addr1
);
10247 id
= ipw_find_station(priv
, hdr
->addr1
);
10248 if (id
== IPW_INVALID_STATION
) {
10249 id
= ipw_add_station(priv
, hdr
->addr1
);
10250 if (id
== IPW_INVALID_STATION
) {
10251 IPW_WARNING("Attempt to send data to "
10252 "invalid cell: %pM\n",
10259 case IW_MODE_INFRA
:
10261 unicast
= !is_multicast_ether_addr(hdr
->addr3
);
10266 tfd
= &txq
->bd
[q
->first_empty
];
10267 txq
->txb
[q
->first_empty
] = txb
;
10268 memset(tfd
, 0, sizeof(*tfd
));
10269 tfd
->u
.data
.station_number
= id
;
10271 tfd
->control_flags
.message_type
= TX_FRAME_TYPE
;
10272 tfd
->control_flags
.control_bits
= TFD_NEED_IRQ_MASK
;
10274 tfd
->u
.data
.cmd_id
= DINO_CMD_TX
;
10275 tfd
->u
.data
.len
= cpu_to_le16(txb
->payload_size
);
10277 if (priv
->assoc_request
.ieee_mode
== IPW_B_MODE
)
10278 tfd
->u
.data
.tx_flags_ext
|= DCT_FLAG_EXT_MODE_CCK
;
10280 tfd
->u
.data
.tx_flags_ext
|= DCT_FLAG_EXT_MODE_OFDM
;
10282 if (priv
->assoc_request
.preamble_length
== DCT_FLAG_SHORT_PREAMBLE
)
10283 tfd
->u
.data
.tx_flags
|= DCT_FLAG_SHORT_PREAMBLE
;
10285 fc
= le16_to_cpu(hdr
->frame_ctl
);
10286 hdr
->frame_ctl
= cpu_to_le16(fc
& ~IEEE80211_FCTL_MOREFRAGS
);
10288 memcpy(&tfd
->u
.data
.tfd
.tfd_24
.mchdr
, hdr
, hdr_len
);
10290 if (likely(unicast
))
10291 tfd
->u
.data
.tx_flags
|= DCT_FLAG_ACK_REQD
;
10293 if (txb
->encrypted
&& !priv
->ieee
->host_encrypt
) {
10294 switch (priv
->ieee
->sec
.level
) {
10296 tfd
->u
.data
.tfd
.tfd_24
.mchdr
.frame_ctl
|=
10297 cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
10298 /* XXX: ACK flag must be set for CCMP even if it
10299 * is a multicast/broadcast packet, because CCMP
10300 * group communication encrypted by GTK is
10301 * actually done by the AP. */
10303 tfd
->u
.data
.tx_flags
|= DCT_FLAG_ACK_REQD
;
10305 tfd
->u
.data
.tx_flags
&= ~DCT_FLAG_NO_WEP
;
10306 tfd
->u
.data
.tx_flags_ext
|= DCT_FLAG_EXT_SECURITY_CCM
;
10307 tfd
->u
.data
.key_index
= 0;
10308 tfd
->u
.data
.key_index
|= DCT_WEP_INDEX_USE_IMMEDIATE
;
10311 tfd
->u
.data
.tfd
.tfd_24
.mchdr
.frame_ctl
|=
10312 cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
10313 tfd
->u
.data
.tx_flags
&= ~DCT_FLAG_NO_WEP
;
10314 tfd
->u
.data
.tx_flags_ext
|= DCT_FLAG_EXT_SECURITY_TKIP
;
10315 tfd
->u
.data
.key_index
= DCT_WEP_INDEX_USE_IMMEDIATE
;
10318 tfd
->u
.data
.tfd
.tfd_24
.mchdr
.frame_ctl
|=
10319 cpu_to_le16(IEEE80211_FCTL_PROTECTED
);
10320 tfd
->u
.data
.key_index
= priv
->ieee
->crypt_info
.tx_keyidx
;
10321 if (priv
->ieee
->sec
.key_sizes
[priv
->ieee
->crypt_info
.tx_keyidx
] <=
10323 tfd
->u
.data
.key_index
|= DCT_WEP_KEY_64Bit
;
10325 tfd
->u
.data
.key_index
|= DCT_WEP_KEY_128Bit
;
10330 printk(KERN_ERR
"Unknown security level %d\n",
10331 priv
->ieee
->sec
.level
);
10335 /* No hardware encryption */
10336 tfd
->u
.data
.tx_flags
|= DCT_FLAG_NO_WEP
;
10338 #ifdef CONFIG_IPW2200_QOS
10339 if (fc
& IEEE80211_STYPE_QOS_DATA
)
10340 ipw_qos_set_tx_queue_command(priv
, pri
, &(tfd
->u
.data
));
10341 #endif /* CONFIG_IPW2200_QOS */
10344 tfd
->u
.data
.num_chunks
= cpu_to_le32(min((u8
) (NUM_TFD_CHUNKS
- 2),
10346 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10347 txb
->nr_frags
, le32_to_cpu(tfd
->u
.data
.num_chunks
));
10348 for (i
= 0; i
< le32_to_cpu(tfd
->u
.data
.num_chunks
); i
++) {
10349 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10350 i
, le32_to_cpu(tfd
->u
.data
.num_chunks
),
10351 txb
->fragments
[i
]->len
- hdr_len
);
10352 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
10353 i
, tfd
->u
.data
.num_chunks
,
10354 txb
->fragments
[i
]->len
- hdr_len
);
10355 printk_buf(IPW_DL_TX
, txb
->fragments
[i
]->data
+ hdr_len
,
10356 txb
->fragments
[i
]->len
- hdr_len
);
10358 tfd
->u
.data
.chunk_ptr
[i
] =
10359 cpu_to_le32(pci_map_single
10361 txb
->fragments
[i
]->data
+ hdr_len
,
10362 txb
->fragments
[i
]->len
- hdr_len
,
10363 PCI_DMA_TODEVICE
));
10364 tfd
->u
.data
.chunk_len
[i
] =
10365 cpu_to_le16(txb
->fragments
[i
]->len
- hdr_len
);
10368 if (i
!= txb
->nr_frags
) {
10369 struct sk_buff
*skb
;
10370 u16 remaining_bytes
= 0;
10373 for (j
= i
; j
< txb
->nr_frags
; j
++)
10374 remaining_bytes
+= txb
->fragments
[j
]->len
- hdr_len
;
10376 printk(KERN_INFO
"Trying to reallocate for %d bytes\n",
10378 skb
= alloc_skb(remaining_bytes
, GFP_ATOMIC
);
10380 tfd
->u
.data
.chunk_len
[i
] = cpu_to_le16(remaining_bytes
);
10381 for (j
= i
; j
< txb
->nr_frags
; j
++) {
10382 int size
= txb
->fragments
[j
]->len
- hdr_len
;
10384 printk(KERN_INFO
"Adding frag %d %d...\n",
10386 memcpy(skb_put(skb
, size
),
10387 txb
->fragments
[j
]->data
+ hdr_len
, size
);
10389 dev_kfree_skb_any(txb
->fragments
[i
]);
10390 txb
->fragments
[i
] = skb
;
10391 tfd
->u
.data
.chunk_ptr
[i
] =
10392 cpu_to_le32(pci_map_single
10393 (priv
->pci_dev
, skb
->data
,
10395 PCI_DMA_TODEVICE
));
10397 le32_add_cpu(&tfd
->u
.data
.num_chunks
, 1);
10402 q
->first_empty
= ipw_queue_inc_wrap(q
->first_empty
, q
->n_bd
);
10403 ipw_write32(priv
, q
->reg_w
, q
->first_empty
);
10405 if (ipw_tx_queue_space(q
) < q
->high_mark
)
10406 netif_stop_queue(priv
->net_dev
);
10408 return NETDEV_TX_OK
;
10411 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
10412 libipw_txb_free(txb
);
10413 return NETDEV_TX_OK
;
10416 static int ipw_net_is_queue_full(struct net_device
*dev
, int pri
)
10418 struct ipw_priv
*priv
= libipw_priv(dev
);
10419 #ifdef CONFIG_IPW2200_QOS
10420 int tx_id
= ipw_get_tx_queue_number(priv
, pri
);
10421 struct clx2_tx_queue
*txq
= &priv
->txq
[tx_id
];
10423 struct clx2_tx_queue
*txq
= &priv
->txq
[0];
10424 #endif /* CONFIG_IPW2200_QOS */
10426 if (ipw_tx_queue_space(&txq
->q
) < txq
->q
.high_mark
)
10432 #ifdef CONFIG_IPW2200_PROMISCUOUS
10433 static void ipw_handle_promiscuous_tx(struct ipw_priv
*priv
,
10434 struct libipw_txb
*txb
)
10436 struct libipw_rx_stats dummystats
;
10437 struct ieee80211_hdr
*hdr
;
10439 u16 filter
= priv
->prom_priv
->filter
;
10442 if (filter
& IPW_PROM_NO_TX
)
10445 memset(&dummystats
, 0, sizeof(dummystats
));
10447 /* Filtering of fragment chains is done agains the first fragment */
10448 hdr
= (void *)txb
->fragments
[0]->data
;
10449 if (libipw_is_management(le16_to_cpu(hdr
->frame_control
))) {
10450 if (filter
& IPW_PROM_NO_MGMT
)
10452 if (filter
& IPW_PROM_MGMT_HEADER_ONLY
)
10454 } else if (libipw_is_control(le16_to_cpu(hdr
->frame_control
))) {
10455 if (filter
& IPW_PROM_NO_CTL
)
10457 if (filter
& IPW_PROM_CTL_HEADER_ONLY
)
10459 } else if (libipw_is_data(le16_to_cpu(hdr
->frame_control
))) {
10460 if (filter
& IPW_PROM_NO_DATA
)
10462 if (filter
& IPW_PROM_DATA_HEADER_ONLY
)
10466 for(n
=0; n
<txb
->nr_frags
; ++n
) {
10467 struct sk_buff
*src
= txb
->fragments
[n
];
10468 struct sk_buff
*dst
;
10469 struct ieee80211_radiotap_header
*rt_hdr
;
10473 hdr
= (void *)src
->data
;
10474 len
= libipw_get_hdrlen(le16_to_cpu(hdr
->frame_control
));
10478 dst
= alloc_skb(len
+ sizeof(*rt_hdr
), GFP_ATOMIC
);
10482 rt_hdr
= (void *)skb_put(dst
, sizeof(*rt_hdr
));
10484 rt_hdr
->it_version
= PKTHDR_RADIOTAP_VERSION
;
10485 rt_hdr
->it_pad
= 0;
10486 rt_hdr
->it_present
= 0; /* after all, it's just an idea */
10487 rt_hdr
->it_present
|= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL
);
10489 *(__le16
*)skb_put(dst
, sizeof(u16
)) = cpu_to_le16(
10490 ieee80211chan2mhz(priv
->channel
));
10491 if (priv
->channel
> 14) /* 802.11a */
10492 *(__le16
*)skb_put(dst
, sizeof(u16
)) =
10493 cpu_to_le16(IEEE80211_CHAN_OFDM
|
10494 IEEE80211_CHAN_5GHZ
);
10495 else if (priv
->ieee
->mode
== IEEE_B
) /* 802.11b */
10496 *(__le16
*)skb_put(dst
, sizeof(u16
)) =
10497 cpu_to_le16(IEEE80211_CHAN_CCK
|
10498 IEEE80211_CHAN_2GHZ
);
10500 *(__le16
*)skb_put(dst
, sizeof(u16
)) =
10501 cpu_to_le16(IEEE80211_CHAN_OFDM
|
10502 IEEE80211_CHAN_2GHZ
);
10504 rt_hdr
->it_len
= cpu_to_le16(dst
->len
);
10506 skb_copy_from_linear_data(src
, skb_put(dst
, len
), len
);
10508 if (!libipw_rx(priv
->prom_priv
->ieee
, dst
, &dummystats
))
10509 dev_kfree_skb_any(dst
);
10514 static netdev_tx_t
ipw_net_hard_start_xmit(struct libipw_txb
*txb
,
10515 struct net_device
*dev
, int pri
)
10517 struct ipw_priv
*priv
= libipw_priv(dev
);
10518 unsigned long flags
;
10521 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb
->payload_size
);
10522 spin_lock_irqsave(&priv
->lock
, flags
);
10524 #ifdef CONFIG_IPW2200_PROMISCUOUS
10525 if (rtap_iface
&& netif_running(priv
->prom_net_dev
))
10526 ipw_handle_promiscuous_tx(priv
, txb
);
10529 ret
= ipw_tx_skb(priv
, txb
, pri
);
10530 if (ret
== NETDEV_TX_OK
)
10531 __ipw_led_activity_on(priv
);
10532 spin_unlock_irqrestore(&priv
->lock
, flags
);
10537 static void ipw_net_set_multicast_list(struct net_device
*dev
)
10542 static int ipw_net_set_mac_address(struct net_device
*dev
, void *p
)
10544 struct ipw_priv
*priv
= libipw_priv(dev
);
10545 struct sockaddr
*addr
= p
;
10547 if (!is_valid_ether_addr(addr
->sa_data
))
10548 return -EADDRNOTAVAIL
;
10549 mutex_lock(&priv
->mutex
);
10550 priv
->config
|= CFG_CUSTOM_MAC
;
10551 memcpy(priv
->mac_addr
, addr
->sa_data
, ETH_ALEN
);
10552 printk(KERN_INFO
"%s: Setting MAC to %pM\n",
10553 priv
->net_dev
->name
, priv
->mac_addr
);
10554 queue_work(priv
->workqueue
, &priv
->adapter_restart
);
10555 mutex_unlock(&priv
->mutex
);
10559 static void ipw_ethtool_get_drvinfo(struct net_device
*dev
,
10560 struct ethtool_drvinfo
*info
)
10562 struct ipw_priv
*p
= libipw_priv(dev
);
10567 strcpy(info
->driver
, DRV_NAME
);
10568 strcpy(info
->version
, DRV_VERSION
);
10570 len
= sizeof(vers
);
10571 ipw_get_ordinal(p
, IPW_ORD_STAT_FW_VERSION
, vers
, &len
);
10572 len
= sizeof(date
);
10573 ipw_get_ordinal(p
, IPW_ORD_STAT_FW_DATE
, date
, &len
);
10575 snprintf(info
->fw_version
, sizeof(info
->fw_version
), "%s (%s)",
10577 strcpy(info
->bus_info
, pci_name(p
->pci_dev
));
10578 info
->eedump_len
= IPW_EEPROM_IMAGE_SIZE
;
10581 static u32
ipw_ethtool_get_link(struct net_device
*dev
)
10583 struct ipw_priv
*priv
= libipw_priv(dev
);
10584 return (priv
->status
& STATUS_ASSOCIATED
) != 0;
10587 static int ipw_ethtool_get_eeprom_len(struct net_device
*dev
)
10589 return IPW_EEPROM_IMAGE_SIZE
;
10592 static int ipw_ethtool_get_eeprom(struct net_device
*dev
,
10593 struct ethtool_eeprom
*eeprom
, u8
* bytes
)
10595 struct ipw_priv
*p
= libipw_priv(dev
);
10597 if (eeprom
->offset
+ eeprom
->len
> IPW_EEPROM_IMAGE_SIZE
)
10599 mutex_lock(&p
->mutex
);
10600 memcpy(bytes
, &p
->eeprom
[eeprom
->offset
], eeprom
->len
);
10601 mutex_unlock(&p
->mutex
);
10605 static int ipw_ethtool_set_eeprom(struct net_device
*dev
,
10606 struct ethtool_eeprom
*eeprom
, u8
* bytes
)
10608 struct ipw_priv
*p
= libipw_priv(dev
);
10611 if (eeprom
->offset
+ eeprom
->len
> IPW_EEPROM_IMAGE_SIZE
)
10613 mutex_lock(&p
->mutex
);
10614 memcpy(&p
->eeprom
[eeprom
->offset
], bytes
, eeprom
->len
);
10615 for (i
= 0; i
< IPW_EEPROM_IMAGE_SIZE
; i
++)
10616 ipw_write8(p
, i
+ IPW_EEPROM_DATA
, p
->eeprom
[i
]);
10617 mutex_unlock(&p
->mutex
);
10621 static const struct ethtool_ops ipw_ethtool_ops
= {
10622 .get_link
= ipw_ethtool_get_link
,
10623 .get_drvinfo
= ipw_ethtool_get_drvinfo
,
10624 .get_eeprom_len
= ipw_ethtool_get_eeprom_len
,
10625 .get_eeprom
= ipw_ethtool_get_eeprom
,
10626 .set_eeprom
= ipw_ethtool_set_eeprom
,
10629 static irqreturn_t
ipw_isr(int irq
, void *data
)
10631 struct ipw_priv
*priv
= data
;
10632 u32 inta
, inta_mask
;
10637 spin_lock(&priv
->irq_lock
);
10639 if (!(priv
->status
& STATUS_INT_ENABLED
)) {
10640 /* IRQ is disabled */
10644 inta
= ipw_read32(priv
, IPW_INTA_RW
);
10645 inta_mask
= ipw_read32(priv
, IPW_INTA_MASK_R
);
10647 if (inta
== 0xFFFFFFFF) {
10648 /* Hardware disappeared */
10649 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10653 if (!(inta
& (IPW_INTA_MASK_ALL
& inta_mask
))) {
10654 /* Shared interrupt */
10658 /* tell the device to stop sending interrupts */
10659 __ipw_disable_interrupts(priv
);
10661 /* ack current interrupts */
10662 inta
&= (IPW_INTA_MASK_ALL
& inta_mask
);
10663 ipw_write32(priv
, IPW_INTA_RW
, inta
);
10665 /* Cache INTA value for our tasklet */
10666 priv
->isr_inta
= inta
;
10668 tasklet_schedule(&priv
->irq_tasklet
);
10670 spin_unlock(&priv
->irq_lock
);
10672 return IRQ_HANDLED
;
10674 spin_unlock(&priv
->irq_lock
);
10678 static void ipw_rf_kill(void *adapter
)
10680 struct ipw_priv
*priv
= adapter
;
10681 unsigned long flags
;
10683 spin_lock_irqsave(&priv
->lock
, flags
);
10685 if (rf_kill_active(priv
)) {
10686 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10687 if (priv
->workqueue
)
10688 queue_delayed_work(priv
->workqueue
,
10689 &priv
->rf_kill
, 2 * HZ
);
10693 /* RF Kill is now disabled, so bring the device back up */
10695 if (!(priv
->status
& STATUS_RF_KILL_MASK
)) {
10696 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10699 /* we can not do an adapter restart while inside an irq lock */
10700 queue_work(priv
->workqueue
, &priv
->adapter_restart
);
10702 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10706 spin_unlock_irqrestore(&priv
->lock
, flags
);
10709 static void ipw_bg_rf_kill(struct work_struct
*work
)
10711 struct ipw_priv
*priv
=
10712 container_of(work
, struct ipw_priv
, rf_kill
.work
);
10713 mutex_lock(&priv
->mutex
);
10715 mutex_unlock(&priv
->mutex
);
10718 static void ipw_link_up(struct ipw_priv
*priv
)
10720 priv
->last_seq_num
= -1;
10721 priv
->last_frag_num
= -1;
10722 priv
->last_packet_time
= 0;
10724 netif_carrier_on(priv
->net_dev
);
10726 cancel_delayed_work(&priv
->request_scan
);
10727 cancel_delayed_work(&priv
->request_direct_scan
);
10728 cancel_delayed_work(&priv
->request_passive_scan
);
10729 cancel_delayed_work(&priv
->scan_event
);
10730 ipw_reset_stats(priv
);
10731 /* Ensure the rate is updated immediately */
10732 priv
->last_rate
= ipw_get_current_rate(priv
);
10733 ipw_gather_stats(priv
);
10734 ipw_led_link_up(priv
);
10735 notify_wx_assoc_event(priv
);
10737 if (priv
->config
& CFG_BACKGROUND_SCAN
)
10738 queue_delayed_work(priv
->workqueue
, &priv
->request_scan
, HZ
);
10741 static void ipw_bg_link_up(struct work_struct
*work
)
10743 struct ipw_priv
*priv
=
10744 container_of(work
, struct ipw_priv
, link_up
);
10745 mutex_lock(&priv
->mutex
);
10747 mutex_unlock(&priv
->mutex
);
10750 static void ipw_link_down(struct ipw_priv
*priv
)
10752 ipw_led_link_down(priv
);
10753 netif_carrier_off(priv
->net_dev
);
10754 notify_wx_assoc_event(priv
);
10756 /* Cancel any queued work ... */
10757 cancel_delayed_work(&priv
->request_scan
);
10758 cancel_delayed_work(&priv
->request_direct_scan
);
10759 cancel_delayed_work(&priv
->request_passive_scan
);
10760 cancel_delayed_work(&priv
->adhoc_check
);
10761 cancel_delayed_work(&priv
->gather_stats
);
10763 ipw_reset_stats(priv
);
10765 if (!(priv
->status
& STATUS_EXIT_PENDING
)) {
10766 /* Queue up another scan... */
10767 queue_delayed_work(priv
->workqueue
, &priv
->request_scan
, 0);
10769 cancel_delayed_work(&priv
->scan_event
);
10772 static void ipw_bg_link_down(struct work_struct
*work
)
10774 struct ipw_priv
*priv
=
10775 container_of(work
, struct ipw_priv
, link_down
);
10776 mutex_lock(&priv
->mutex
);
10777 ipw_link_down(priv
);
10778 mutex_unlock(&priv
->mutex
);
10781 static int __devinit
ipw_setup_deferred_work(struct ipw_priv
*priv
)
10785 priv
->workqueue
= create_workqueue(DRV_NAME
);
10786 init_waitqueue_head(&priv
->wait_command_queue
);
10787 init_waitqueue_head(&priv
->wait_state
);
10789 INIT_DELAYED_WORK(&priv
->adhoc_check
, ipw_bg_adhoc_check
);
10790 INIT_WORK(&priv
->associate
, ipw_bg_associate
);
10791 INIT_WORK(&priv
->disassociate
, ipw_bg_disassociate
);
10792 INIT_WORK(&priv
->system_config
, ipw_system_config
);
10793 INIT_WORK(&priv
->rx_replenish
, ipw_bg_rx_queue_replenish
);
10794 INIT_WORK(&priv
->adapter_restart
, ipw_bg_adapter_restart
);
10795 INIT_DELAYED_WORK(&priv
->rf_kill
, ipw_bg_rf_kill
);
10796 INIT_WORK(&priv
->up
, ipw_bg_up
);
10797 INIT_WORK(&priv
->down
, ipw_bg_down
);
10798 INIT_DELAYED_WORK(&priv
->request_scan
, ipw_request_scan
);
10799 INIT_DELAYED_WORK(&priv
->request_direct_scan
, ipw_request_direct_scan
);
10800 INIT_DELAYED_WORK(&priv
->request_passive_scan
, ipw_request_passive_scan
);
10801 INIT_DELAYED_WORK(&priv
->scan_event
, ipw_scan_event
);
10802 INIT_DELAYED_WORK(&priv
->gather_stats
, ipw_bg_gather_stats
);
10803 INIT_WORK(&priv
->abort_scan
, ipw_bg_abort_scan
);
10804 INIT_WORK(&priv
->roam
, ipw_bg_roam
);
10805 INIT_DELAYED_WORK(&priv
->scan_check
, ipw_bg_scan_check
);
10806 INIT_WORK(&priv
->link_up
, ipw_bg_link_up
);
10807 INIT_WORK(&priv
->link_down
, ipw_bg_link_down
);
10808 INIT_DELAYED_WORK(&priv
->led_link_on
, ipw_bg_led_link_on
);
10809 INIT_DELAYED_WORK(&priv
->led_link_off
, ipw_bg_led_link_off
);
10810 INIT_DELAYED_WORK(&priv
->led_act_off
, ipw_bg_led_activity_off
);
10811 INIT_WORK(&priv
->merge_networks
, ipw_merge_adhoc_network
);
10813 #ifdef CONFIG_IPW2200_QOS
10814 INIT_WORK(&priv
->qos_activate
, ipw_bg_qos_activate
);
10815 #endif /* CONFIG_IPW2200_QOS */
10817 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
10818 ipw_irq_tasklet
, (unsigned long)priv
);
10823 static void shim__set_security(struct net_device
*dev
,
10824 struct libipw_security
*sec
)
10826 struct ipw_priv
*priv
= libipw_priv(dev
);
10828 for (i
= 0; i
< 4; i
++) {
10829 if (sec
->flags
& (1 << i
)) {
10830 priv
->ieee
->sec
.encode_alg
[i
] = sec
->encode_alg
[i
];
10831 priv
->ieee
->sec
.key_sizes
[i
] = sec
->key_sizes
[i
];
10832 if (sec
->key_sizes
[i
] == 0)
10833 priv
->ieee
->sec
.flags
&= ~(1 << i
);
10835 memcpy(priv
->ieee
->sec
.keys
[i
], sec
->keys
[i
],
10836 sec
->key_sizes
[i
]);
10837 priv
->ieee
->sec
.flags
|= (1 << i
);
10839 priv
->status
|= STATUS_SECURITY_UPDATED
;
10840 } else if (sec
->level
!= SEC_LEVEL_1
)
10841 priv
->ieee
->sec
.flags
&= ~(1 << i
);
10844 if (sec
->flags
& SEC_ACTIVE_KEY
) {
10845 if (sec
->active_key
<= 3) {
10846 priv
->ieee
->sec
.active_key
= sec
->active_key
;
10847 priv
->ieee
->sec
.flags
|= SEC_ACTIVE_KEY
;
10849 priv
->ieee
->sec
.flags
&= ~SEC_ACTIVE_KEY
;
10850 priv
->status
|= STATUS_SECURITY_UPDATED
;
10852 priv
->ieee
->sec
.flags
&= ~SEC_ACTIVE_KEY
;
10854 if ((sec
->flags
& SEC_AUTH_MODE
) &&
10855 (priv
->ieee
->sec
.auth_mode
!= sec
->auth_mode
)) {
10856 priv
->ieee
->sec
.auth_mode
= sec
->auth_mode
;
10857 priv
->ieee
->sec
.flags
|= SEC_AUTH_MODE
;
10858 if (sec
->auth_mode
== WLAN_AUTH_SHARED_KEY
)
10859 priv
->capability
|= CAP_SHARED_KEY
;
10861 priv
->capability
&= ~CAP_SHARED_KEY
;
10862 priv
->status
|= STATUS_SECURITY_UPDATED
;
10865 if (sec
->flags
& SEC_ENABLED
&& priv
->ieee
->sec
.enabled
!= sec
->enabled
) {
10866 priv
->ieee
->sec
.flags
|= SEC_ENABLED
;
10867 priv
->ieee
->sec
.enabled
= sec
->enabled
;
10868 priv
->status
|= STATUS_SECURITY_UPDATED
;
10870 priv
->capability
|= CAP_PRIVACY_ON
;
10872 priv
->capability
&= ~CAP_PRIVACY_ON
;
10875 if (sec
->flags
& SEC_ENCRYPT
)
10876 priv
->ieee
->sec
.encrypt
= sec
->encrypt
;
10878 if (sec
->flags
& SEC_LEVEL
&& priv
->ieee
->sec
.level
!= sec
->level
) {
10879 priv
->ieee
->sec
.level
= sec
->level
;
10880 priv
->ieee
->sec
.flags
|= SEC_LEVEL
;
10881 priv
->status
|= STATUS_SECURITY_UPDATED
;
10884 if (!priv
->ieee
->host_encrypt
&& (sec
->flags
& SEC_ENCRYPT
))
10885 ipw_set_hwcrypto_keys(priv
);
10887 /* To match current functionality of ipw2100 (which works well w/
10888 * various supplicants, we don't force a disassociate if the
10889 * privacy capability changes ... */
10891 if ((priv
->status
& (STATUS_ASSOCIATED
| STATUS_ASSOCIATING
)) &&
10892 (((priv
->assoc_request
.capability
&
10893 cpu_to_le16(WLAN_CAPABILITY_PRIVACY
)) && !sec
->enabled
) ||
10894 (!(priv
->assoc_request
.capability
&
10895 cpu_to_le16(WLAN_CAPABILITY_PRIVACY
)) && sec
->enabled
))) {
10896 IPW_DEBUG_ASSOC("Disassociating due to capability "
10898 ipw_disassociate(priv
);
10903 static int init_supported_rates(struct ipw_priv
*priv
,
10904 struct ipw_supported_rates
*rates
)
10906 /* TODO: Mask out rates based on priv->rates_mask */
10908 memset(rates
, 0, sizeof(*rates
));
10909 /* configure supported rates */
10910 switch (priv
->ieee
->freq_band
) {
10911 case LIBIPW_52GHZ_BAND
:
10912 rates
->ieee_mode
= IPW_A_MODE
;
10913 rates
->purpose
= IPW_RATE_CAPABILITIES
;
10914 ipw_add_ofdm_scan_rates(rates
, LIBIPW_CCK_MODULATION
,
10915 LIBIPW_OFDM_DEFAULT_RATES_MASK
);
10918 default: /* Mixed or 2.4Ghz */
10919 rates
->ieee_mode
= IPW_G_MODE
;
10920 rates
->purpose
= IPW_RATE_CAPABILITIES
;
10921 ipw_add_cck_scan_rates(rates
, LIBIPW_CCK_MODULATION
,
10922 LIBIPW_CCK_DEFAULT_RATES_MASK
);
10923 if (priv
->ieee
->modulation
& LIBIPW_OFDM_MODULATION
) {
10924 ipw_add_ofdm_scan_rates(rates
, LIBIPW_CCK_MODULATION
,
10925 LIBIPW_OFDM_DEFAULT_RATES_MASK
);
10933 static int ipw_config(struct ipw_priv
*priv
)
10935 /* This is only called from ipw_up, which resets/reloads the firmware
10936 so, we don't need to first disable the card before we configure
10938 if (ipw_set_tx_power(priv
))
10941 /* initialize adapter address */
10942 if (ipw_send_adapter_address(priv
, priv
->net_dev
->dev_addr
))
10945 /* set basic system config settings */
10946 init_sys_config(&priv
->sys_config
);
10948 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10949 * Does not support BT priority yet (don't abort or defer our Tx) */
10951 unsigned char bt_caps
= priv
->eeprom
[EEPROM_SKU_CAPABILITY
];
10953 if (bt_caps
& EEPROM_SKU_CAP_BT_CHANNEL_SIG
)
10954 priv
->sys_config
.bt_coexistence
10955 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL
;
10956 if (bt_caps
& EEPROM_SKU_CAP_BT_OOB
)
10957 priv
->sys_config
.bt_coexistence
10958 |= CFG_BT_COEXISTENCE_OOB
;
10961 #ifdef CONFIG_IPW2200_PROMISCUOUS
10962 if (priv
->prom_net_dev
&& netif_running(priv
->prom_net_dev
)) {
10963 priv
->sys_config
.accept_all_data_frames
= 1;
10964 priv
->sys_config
.accept_non_directed_frames
= 1;
10965 priv
->sys_config
.accept_all_mgmt_bcpr
= 1;
10966 priv
->sys_config
.accept_all_mgmt_frames
= 1;
10970 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
)
10971 priv
->sys_config
.answer_broadcast_ssid_probe
= 1;
10973 priv
->sys_config
.answer_broadcast_ssid_probe
= 0;
10975 if (ipw_send_system_config(priv
))
10978 init_supported_rates(priv
, &priv
->rates
);
10979 if (ipw_send_supported_rates(priv
, &priv
->rates
))
10982 /* Set request-to-send threshold */
10983 if (priv
->rts_threshold
) {
10984 if (ipw_send_rts_threshold(priv
, priv
->rts_threshold
))
10987 #ifdef CONFIG_IPW2200_QOS
10988 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10989 ipw_qos_activate(priv
, NULL
);
10990 #endif /* CONFIG_IPW2200_QOS */
10992 if (ipw_set_random_seed(priv
))
10995 /* final state transition to the RUN state */
10996 if (ipw_send_host_complete(priv
))
10999 priv
->status
|= STATUS_INIT
;
11001 ipw_led_init(priv
);
11002 ipw_led_radio_on(priv
);
11003 priv
->notif_missed_beacons
= 0;
11005 /* Set hardware WEP key if it is configured. */
11006 if ((priv
->capability
& CAP_PRIVACY_ON
) &&
11007 (priv
->ieee
->sec
.level
== SEC_LEVEL_1
) &&
11008 !(priv
->ieee
->host_encrypt
|| priv
->ieee
->host_decrypt
))
11009 ipw_set_hwcrypto_keys(priv
);
11020 * These tables have been tested in conjunction with the
11021 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
11023 * Altering this values, using it on other hardware, or in geographies
11024 * not intended for resale of the above mentioned Intel adapters has
11027 * Remember to update the table in README.ipw2200 when changing this
11031 static const struct libipw_geo ipw_geos
[] = {
11035 .bg
= {{2412, 1}, {2417, 2}, {2422, 3},
11036 {2427, 4}, {2432, 5}, {2437, 6},
11037 {2442, 7}, {2447, 8}, {2452, 9},
11038 {2457, 10}, {2462, 11}},
11041 { /* Custom US/Canada */
11044 .bg
= {{2412, 1}, {2417, 2}, {2422, 3},
11045 {2427, 4}, {2432, 5}, {2437, 6},
11046 {2442, 7}, {2447, 8}, {2452, 9},
11047 {2457, 10}, {2462, 11}},
11053 {5260, 52, LIBIPW_CH_PASSIVE_ONLY
},
11054 {5280, 56, LIBIPW_CH_PASSIVE_ONLY
},
11055 {5300, 60, LIBIPW_CH_PASSIVE_ONLY
},
11056 {5320, 64, LIBIPW_CH_PASSIVE_ONLY
}},
11059 { /* Rest of World */
11062 .bg
= {{2412, 1}, {2417, 2}, {2422, 3},
11063 {2427, 4}, {2432, 5}, {2437, 6},
11064 {2442, 7}, {2447, 8}, {2452, 9},
11065 {2457, 10}, {2462, 11}, {2467, 12},
11069 { /* Custom USA & Europe & High */
11072 .bg
= {{2412, 1}, {2417, 2}, {2422, 3},
11073 {2427, 4}, {2432, 5}, {2437, 6},
11074 {2442, 7}, {2447, 8}, {2452, 9},
11075 {2457, 10}, {2462, 11}},
11081 {5260, 52, LIBIPW_CH_PASSIVE_ONLY
},
11082 {5280, 56, LIBIPW_CH_PASSIVE_ONLY
},
11083 {5300, 60, LIBIPW_CH_PASSIVE_ONLY
},
11084 {5320, 64, LIBIPW_CH_PASSIVE_ONLY
},
11092 { /* Custom NA & Europe */
11095 .bg
= {{2412, 1}, {2417, 2}, {2422, 3},
11096 {2427, 4}, {2432, 5}, {2437, 6},
11097 {2442, 7}, {2447, 8}, {2452, 9},
11098 {2457, 10}, {2462, 11}},
11104 {5260, 52, LIBIPW_CH_PASSIVE_ONLY
},
11105 {5280, 56, LIBIPW_CH_PASSIVE_ONLY
},
11106 {5300, 60, LIBIPW_CH_PASSIVE_ONLY
},
11107 {5320, 64, LIBIPW_CH_PASSIVE_ONLY
},
11108 {5745, 149, LIBIPW_CH_PASSIVE_ONLY
},
11109 {5765, 153, LIBIPW_CH_PASSIVE_ONLY
},
11110 {5785, 157, LIBIPW_CH_PASSIVE_ONLY
},
11111 {5805, 161, LIBIPW_CH_PASSIVE_ONLY
},
11112 {5825, 165, LIBIPW_CH_PASSIVE_ONLY
}},
11115 { /* Custom Japan */
11118 .bg
= {{2412, 1}, {2417, 2}, {2422, 3},
11119 {2427, 4}, {2432, 5}, {2437, 6},
11120 {2442, 7}, {2447, 8}, {2452, 9},
11121 {2457, 10}, {2462, 11}},
11123 .a
= {{5170, 34}, {5190, 38},
11124 {5210, 42}, {5230, 46}},
11130 .bg
= {{2412, 1}, {2417, 2}, {2422, 3},
11131 {2427, 4}, {2432, 5}, {2437, 6},
11132 {2442, 7}, {2447, 8}, {2452, 9},
11133 {2457, 10}, {2462, 11}},
11139 .bg
= {{2412, 1}, {2417, 2}, {2422, 3},
11140 {2427, 4}, {2432, 5}, {2437, 6},
11141 {2442, 7}, {2447, 8}, {2452, 9},
11142 {2457, 10}, {2462, 11}, {2467, 12},
11149 {5260, 52, LIBIPW_CH_PASSIVE_ONLY
},
11150 {5280, 56, LIBIPW_CH_PASSIVE_ONLY
},
11151 {5300, 60, LIBIPW_CH_PASSIVE_ONLY
},
11152 {5320, 64, LIBIPW_CH_PASSIVE_ONLY
},
11153 {5500, 100, LIBIPW_CH_PASSIVE_ONLY
},
11154 {5520, 104, LIBIPW_CH_PASSIVE_ONLY
},
11155 {5540, 108, LIBIPW_CH_PASSIVE_ONLY
},
11156 {5560, 112, LIBIPW_CH_PASSIVE_ONLY
},
11157 {5580, 116, LIBIPW_CH_PASSIVE_ONLY
},
11158 {5600, 120, LIBIPW_CH_PASSIVE_ONLY
},
11159 {5620, 124, LIBIPW_CH_PASSIVE_ONLY
},
11160 {5640, 128, LIBIPW_CH_PASSIVE_ONLY
},
11161 {5660, 132, LIBIPW_CH_PASSIVE_ONLY
},
11162 {5680, 136, LIBIPW_CH_PASSIVE_ONLY
},
11163 {5700, 140, LIBIPW_CH_PASSIVE_ONLY
}},
11166 { /* Custom Japan */
11169 .bg
= {{2412, 1}, {2417, 2}, {2422, 3},
11170 {2427, 4}, {2432, 5}, {2437, 6},
11171 {2442, 7}, {2447, 8}, {2452, 9},
11172 {2457, 10}, {2462, 11}, {2467, 12},
11173 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY
}},
11175 .a
= {{5170, 34}, {5190, 38},
11176 {5210, 42}, {5230, 46}},
11179 { /* Rest of World */
11182 .bg
= {{2412, 1}, {2417, 2}, {2422, 3},
11183 {2427, 4}, {2432, 5}, {2437, 6},
11184 {2442, 7}, {2447, 8}, {2452, 9},
11185 {2457, 10}, {2462, 11}, {2467, 12},
11186 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY
|
11187 LIBIPW_CH_PASSIVE_ONLY
}},
11193 .bg
= {{2412, 1}, {2417, 2}, {2422, 3},
11194 {2427, 4}, {2432, 5}, {2437, 6},
11195 {2442, 7}, {2447, 8}, {2452, 9},
11196 {2457, 10}, {2462, 11},
11197 {2467, 12, LIBIPW_CH_PASSIVE_ONLY
},
11198 {2472, 13, LIBIPW_CH_PASSIVE_ONLY
}},
11200 .a
= {{5745, 149}, {5765, 153},
11201 {5785, 157}, {5805, 161}},
11204 { /* Custom Europe */
11207 .bg
= {{2412, 1}, {2417, 2}, {2422, 3},
11208 {2427, 4}, {2432, 5}, {2437, 6},
11209 {2442, 7}, {2447, 8}, {2452, 9},
11210 {2457, 10}, {2462, 11},
11211 {2467, 12}, {2472, 13}},
11213 .a
= {{5180, 36}, {5200, 40},
11214 {5220, 44}, {5240, 48}},
11220 .bg
= {{2412, 1}, {2417, 2}, {2422, 3},
11221 {2427, 4}, {2432, 5}, {2437, 6},
11222 {2442, 7}, {2447, 8}, {2452, 9},
11223 {2457, 10}, {2462, 11},
11224 {2467, 12, LIBIPW_CH_PASSIVE_ONLY
},
11225 {2472, 13, LIBIPW_CH_PASSIVE_ONLY
}},
11227 .a
= {{5180, 36, LIBIPW_CH_PASSIVE_ONLY
},
11228 {5200, 40, LIBIPW_CH_PASSIVE_ONLY
},
11229 {5220, 44, LIBIPW_CH_PASSIVE_ONLY
},
11230 {5240, 48, LIBIPW_CH_PASSIVE_ONLY
},
11231 {5260, 52, LIBIPW_CH_PASSIVE_ONLY
},
11232 {5280, 56, LIBIPW_CH_PASSIVE_ONLY
},
11233 {5300, 60, LIBIPW_CH_PASSIVE_ONLY
},
11234 {5320, 64, LIBIPW_CH_PASSIVE_ONLY
},
11235 {5500, 100, LIBIPW_CH_PASSIVE_ONLY
},
11236 {5520, 104, LIBIPW_CH_PASSIVE_ONLY
},
11237 {5540, 108, LIBIPW_CH_PASSIVE_ONLY
},
11238 {5560, 112, LIBIPW_CH_PASSIVE_ONLY
},
11239 {5580, 116, LIBIPW_CH_PASSIVE_ONLY
},
11240 {5600, 120, LIBIPW_CH_PASSIVE_ONLY
},
11241 {5620, 124, LIBIPW_CH_PASSIVE_ONLY
},
11242 {5640, 128, LIBIPW_CH_PASSIVE_ONLY
},
11243 {5660, 132, LIBIPW_CH_PASSIVE_ONLY
},
11244 {5680, 136, LIBIPW_CH_PASSIVE_ONLY
},
11245 {5700, 140, LIBIPW_CH_PASSIVE_ONLY
},
11246 {5745, 149, LIBIPW_CH_PASSIVE_ONLY
},
11247 {5765, 153, LIBIPW_CH_PASSIVE_ONLY
},
11248 {5785, 157, LIBIPW_CH_PASSIVE_ONLY
},
11249 {5805, 161, LIBIPW_CH_PASSIVE_ONLY
},
11250 {5825, 165, LIBIPW_CH_PASSIVE_ONLY
}},
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}},
11261 .a
= {{5180, 36, LIBIPW_CH_PASSIVE_ONLY
},
11262 {5200, 40, LIBIPW_CH_PASSIVE_ONLY
},
11263 {5220, 44, LIBIPW_CH_PASSIVE_ONLY
},
11264 {5240, 48, LIBIPW_CH_PASSIVE_ONLY
},
11265 {5260, 52, LIBIPW_CH_PASSIVE_ONLY
},
11266 {5280, 56, LIBIPW_CH_PASSIVE_ONLY
},
11267 {5300, 60, LIBIPW_CH_PASSIVE_ONLY
},
11268 {5320, 64, LIBIPW_CH_PASSIVE_ONLY
},
11269 {5745, 149, LIBIPW_CH_PASSIVE_ONLY
},
11270 {5765, 153, LIBIPW_CH_PASSIVE_ONLY
},
11271 {5785, 157, LIBIPW_CH_PASSIVE_ONLY
},
11272 {5805, 161, LIBIPW_CH_PASSIVE_ONLY
},
11273 {5825, 165, LIBIPW_CH_PASSIVE_ONLY
}},
11277 #define MAX_HW_RESTARTS 5
11278 static int ipw_up(struct ipw_priv
*priv
)
11282 /* Age scan list entries found before suspend */
11283 if (priv
->suspend_time
) {
11284 libipw_networks_age(priv
->ieee
, priv
->suspend_time
);
11285 priv
->suspend_time
= 0;
11288 if (priv
->status
& STATUS_EXIT_PENDING
)
11291 if (cmdlog
&& !priv
->cmdlog
) {
11292 priv
->cmdlog
= kcalloc(cmdlog
, sizeof(*priv
->cmdlog
),
11294 if (priv
->cmdlog
== NULL
) {
11295 IPW_ERROR("Error allocating %d command log entries.\n",
11299 priv
->cmdlog_len
= cmdlog
;
11303 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
11304 /* Load the microcode, firmware, and eeprom.
11305 * Also start the clocks. */
11306 rc
= ipw_load(priv
);
11308 IPW_ERROR("Unable to load firmware: %d\n", rc
);
11312 ipw_init_ordinals(priv
);
11313 if (!(priv
->config
& CFG_CUSTOM_MAC
))
11314 eeprom_parse_mac(priv
, priv
->mac_addr
);
11315 memcpy(priv
->net_dev
->dev_addr
, priv
->mac_addr
, ETH_ALEN
);
11316 memcpy(priv
->net_dev
->perm_addr
, priv
->mac_addr
, ETH_ALEN
);
11318 for (j
= 0; j
< ARRAY_SIZE(ipw_geos
); j
++) {
11319 if (!memcmp(&priv
->eeprom
[EEPROM_COUNTRY_CODE
],
11320 ipw_geos
[j
].name
, 3))
11323 if (j
== ARRAY_SIZE(ipw_geos
)) {
11324 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11325 priv
->eeprom
[EEPROM_COUNTRY_CODE
+ 0],
11326 priv
->eeprom
[EEPROM_COUNTRY_CODE
+ 1],
11327 priv
->eeprom
[EEPROM_COUNTRY_CODE
+ 2]);
11330 if (libipw_set_geo(priv
->ieee
, &ipw_geos
[j
])) {
11331 IPW_WARNING("Could not set geography.");
11335 if (priv
->status
& STATUS_RF_KILL_SW
) {
11336 IPW_WARNING("Radio disabled by module parameter.\n");
11338 } else if (rf_kill_active(priv
)) {
11339 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11340 "Kill switch must be turned off for "
11341 "wireless networking to work.\n");
11342 queue_delayed_work(priv
->workqueue
, &priv
->rf_kill
,
11347 rc
= ipw_config(priv
);
11349 IPW_DEBUG_INFO("Configured device on count %i\n", i
);
11351 /* If configure to try and auto-associate, kick
11353 queue_delayed_work(priv
->workqueue
,
11354 &priv
->request_scan
, 0);
11359 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc
);
11360 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11361 i
, MAX_HW_RESTARTS
);
11363 /* We had an error bringing up the hardware, so take it
11364 * all the way back down so we can try again */
11368 /* tried to restart and config the device for as long as our
11369 * patience could withstand */
11370 IPW_ERROR("Unable to initialize device after %d attempts.\n", i
);
11375 static void ipw_bg_up(struct work_struct
*work
)
11377 struct ipw_priv
*priv
=
11378 container_of(work
, struct ipw_priv
, up
);
11379 mutex_lock(&priv
->mutex
);
11381 mutex_unlock(&priv
->mutex
);
11384 static void ipw_deinit(struct ipw_priv
*priv
)
11388 if (priv
->status
& STATUS_SCANNING
) {
11389 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11390 ipw_abort_scan(priv
);
11393 if (priv
->status
& STATUS_ASSOCIATED
) {
11394 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11395 ipw_disassociate(priv
);
11398 ipw_led_shutdown(priv
);
11400 /* Wait up to 1s for status to change to not scanning and not
11401 * associated (disassociation can take a while for a ful 802.11
11403 for (i
= 1000; i
&& (priv
->status
&
11404 (STATUS_DISASSOCIATING
|
11405 STATUS_ASSOCIATED
| STATUS_SCANNING
)); i
--)
11408 if (priv
->status
& (STATUS_DISASSOCIATING
|
11409 STATUS_ASSOCIATED
| STATUS_SCANNING
))
11410 IPW_DEBUG_INFO("Still associated or scanning...\n");
11412 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i
);
11414 /* Attempt to disable the card */
11415 ipw_send_card_disable(priv
, 0);
11417 priv
->status
&= ~STATUS_INIT
;
11420 static void ipw_down(struct ipw_priv
*priv
)
11422 int exit_pending
= priv
->status
& STATUS_EXIT_PENDING
;
11424 priv
->status
|= STATUS_EXIT_PENDING
;
11426 if (ipw_is_init(priv
))
11429 /* Wipe out the EXIT_PENDING status bit if we are not actually
11430 * exiting the module */
11432 priv
->status
&= ~STATUS_EXIT_PENDING
;
11434 /* tell the device to stop sending interrupts */
11435 ipw_disable_interrupts(priv
);
11437 /* Clear all bits but the RF Kill */
11438 priv
->status
&= STATUS_RF_KILL_MASK
| STATUS_EXIT_PENDING
;
11439 netif_carrier_off(priv
->net_dev
);
11441 ipw_stop_nic(priv
);
11443 ipw_led_radio_off(priv
);
11446 static void ipw_bg_down(struct work_struct
*work
)
11448 struct ipw_priv
*priv
=
11449 container_of(work
, struct ipw_priv
, down
);
11450 mutex_lock(&priv
->mutex
);
11452 mutex_unlock(&priv
->mutex
);
11455 /* Called by register_netdev() */
11456 static int ipw_net_init(struct net_device
*dev
)
11459 struct ipw_priv
*priv
= libipw_priv(dev
);
11460 const struct libipw_geo
*geo
= libipw_get_geo(priv
->ieee
);
11461 struct wireless_dev
*wdev
= &priv
->ieee
->wdev
;
11462 mutex_lock(&priv
->mutex
);
11464 if (ipw_up(priv
)) {
11469 memcpy(wdev
->wiphy
->perm_addr
, priv
->mac_addr
, ETH_ALEN
);
11471 /* fill-out priv->ieee->bg_band */
11472 if (geo
->bg_channels
) {
11473 struct ieee80211_supported_band
*bg_band
= &priv
->ieee
->bg_band
;
11475 bg_band
->band
= IEEE80211_BAND_2GHZ
;
11476 bg_band
->n_channels
= geo
->bg_channels
;
11477 bg_band
->channels
= kcalloc(geo
->bg_channels
,
11478 sizeof(struct ieee80211_channel
),
11480 if (!bg_band
->channels
) {
11484 /* translate geo->bg to bg_band.channels */
11485 for (i
= 0; i
< geo
->bg_channels
; i
++) {
11486 bg_band
->channels
[i
].band
= IEEE80211_BAND_2GHZ
;
11487 bg_band
->channels
[i
].center_freq
= geo
->bg
[i
].freq
;
11488 bg_band
->channels
[i
].hw_value
= geo
->bg
[i
].channel
;
11489 bg_band
->channels
[i
].max_power
= geo
->bg
[i
].max_power
;
11490 if (geo
->bg
[i
].flags
& LIBIPW_CH_PASSIVE_ONLY
)
11491 bg_band
->channels
[i
].flags
|=
11492 IEEE80211_CHAN_PASSIVE_SCAN
;
11493 if (geo
->bg
[i
].flags
& LIBIPW_CH_NO_IBSS
)
11494 bg_band
->channels
[i
].flags
|=
11495 IEEE80211_CHAN_NO_IBSS
;
11496 if (geo
->bg
[i
].flags
& LIBIPW_CH_RADAR_DETECT
)
11497 bg_band
->channels
[i
].flags
|=
11498 IEEE80211_CHAN_RADAR
;
11499 /* No equivalent for LIBIPW_CH_80211H_RULES,
11500 LIBIPW_CH_UNIFORM_SPREADING, or
11501 LIBIPW_CH_B_ONLY... */
11503 /* point at bitrate info */
11504 bg_band
->bitrates
= ipw2200_bg_rates
;
11505 bg_band
->n_bitrates
= ipw2200_num_bg_rates
;
11507 wdev
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = bg_band
;
11510 /* fill-out priv->ieee->a_band */
11511 if (geo
->a_channels
) {
11512 struct ieee80211_supported_band
*a_band
= &priv
->ieee
->a_band
;
11514 a_band
->band
= IEEE80211_BAND_5GHZ
;
11515 a_band
->n_channels
= geo
->a_channels
;
11516 a_band
->channels
= kcalloc(geo
->a_channels
,
11517 sizeof(struct ieee80211_channel
),
11519 if (!a_band
->channels
) {
11523 /* translate geo->bg to a_band.channels */
11524 for (i
= 0; i
< geo
->a_channels
; i
++) {
11525 a_band
->channels
[i
].band
= IEEE80211_BAND_2GHZ
;
11526 a_band
->channels
[i
].center_freq
= geo
->a
[i
].freq
;
11527 a_band
->channels
[i
].hw_value
= geo
->a
[i
].channel
;
11528 a_band
->channels
[i
].max_power
= geo
->a
[i
].max_power
;
11529 if (geo
->a
[i
].flags
& LIBIPW_CH_PASSIVE_ONLY
)
11530 a_band
->channels
[i
].flags
|=
11531 IEEE80211_CHAN_PASSIVE_SCAN
;
11532 if (geo
->a
[i
].flags
& LIBIPW_CH_NO_IBSS
)
11533 a_band
->channels
[i
].flags
|=
11534 IEEE80211_CHAN_NO_IBSS
;
11535 if (geo
->a
[i
].flags
& LIBIPW_CH_RADAR_DETECT
)
11536 a_band
->channels
[i
].flags
|=
11537 IEEE80211_CHAN_RADAR
;
11538 /* No equivalent for LIBIPW_CH_80211H_RULES,
11539 LIBIPW_CH_UNIFORM_SPREADING, or
11540 LIBIPW_CH_B_ONLY... */
11542 /* point at bitrate info */
11543 a_band
->bitrates
= ipw2200_a_rates
;
11544 a_band
->n_bitrates
= ipw2200_num_a_rates
;
11546 wdev
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] = a_band
;
11549 set_wiphy_dev(wdev
->wiphy
, &priv
->pci_dev
->dev
);
11551 /* With that information in place, we can now register the wiphy... */
11552 if (wiphy_register(wdev
->wiphy
)) {
11558 mutex_unlock(&priv
->mutex
);
11562 /* PCI driver stuff */
11563 static DEFINE_PCI_DEVICE_TABLE(card_ids
) = {
11564 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11565 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11566 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11567 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11568 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11569 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11570 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11571 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11572 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11573 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11574 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11575 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11576 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11577 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11578 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11579 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11580 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2762, 0, 0, 0},
11581 {PCI_VDEVICE(INTEL
, 0x104f), 0},
11582 {PCI_VDEVICE(INTEL
, 0x4220), 0}, /* BG */
11583 {PCI_VDEVICE(INTEL
, 0x4221), 0}, /* BG */
11584 {PCI_VDEVICE(INTEL
, 0x4223), 0}, /* ABG */
11585 {PCI_VDEVICE(INTEL
, 0x4224), 0}, /* ABG */
11587 /* required last entry */
11591 MODULE_DEVICE_TABLE(pci
, card_ids
);
11593 static struct attribute
*ipw_sysfs_entries
[] = {
11594 &dev_attr_rf_kill
.attr
,
11595 &dev_attr_direct_dword
.attr
,
11596 &dev_attr_indirect_byte
.attr
,
11597 &dev_attr_indirect_dword
.attr
,
11598 &dev_attr_mem_gpio_reg
.attr
,
11599 &dev_attr_command_event_reg
.attr
,
11600 &dev_attr_nic_type
.attr
,
11601 &dev_attr_status
.attr
,
11602 &dev_attr_cfg
.attr
,
11603 &dev_attr_error
.attr
,
11604 &dev_attr_event_log
.attr
,
11605 &dev_attr_cmd_log
.attr
,
11606 &dev_attr_eeprom_delay
.attr
,
11607 &dev_attr_ucode_version
.attr
,
11608 &dev_attr_rtc
.attr
,
11609 &dev_attr_scan_age
.attr
,
11610 &dev_attr_led
.attr
,
11611 &dev_attr_speed_scan
.attr
,
11612 &dev_attr_net_stats
.attr
,
11613 &dev_attr_channels
.attr
,
11614 #ifdef CONFIG_IPW2200_PROMISCUOUS
11615 &dev_attr_rtap_iface
.attr
,
11616 &dev_attr_rtap_filter
.attr
,
11621 static struct attribute_group ipw_attribute_group
= {
11622 .name
= NULL
, /* put in device directory */
11623 .attrs
= ipw_sysfs_entries
,
11626 #ifdef CONFIG_IPW2200_PROMISCUOUS
11627 static int ipw_prom_open(struct net_device
*dev
)
11629 struct ipw_prom_priv
*prom_priv
= libipw_priv(dev
);
11630 struct ipw_priv
*priv
= prom_priv
->priv
;
11632 IPW_DEBUG_INFO("prom dev->open\n");
11633 netif_carrier_off(dev
);
11635 if (priv
->ieee
->iw_mode
!= IW_MODE_MONITOR
) {
11636 priv
->sys_config
.accept_all_data_frames
= 1;
11637 priv
->sys_config
.accept_non_directed_frames
= 1;
11638 priv
->sys_config
.accept_all_mgmt_bcpr
= 1;
11639 priv
->sys_config
.accept_all_mgmt_frames
= 1;
11641 ipw_send_system_config(priv
);
11647 static int ipw_prom_stop(struct net_device
*dev
)
11649 struct ipw_prom_priv
*prom_priv
= libipw_priv(dev
);
11650 struct ipw_priv
*priv
= prom_priv
->priv
;
11652 IPW_DEBUG_INFO("prom dev->stop\n");
11654 if (priv
->ieee
->iw_mode
!= IW_MODE_MONITOR
) {
11655 priv
->sys_config
.accept_all_data_frames
= 0;
11656 priv
->sys_config
.accept_non_directed_frames
= 0;
11657 priv
->sys_config
.accept_all_mgmt_bcpr
= 0;
11658 priv
->sys_config
.accept_all_mgmt_frames
= 0;
11660 ipw_send_system_config(priv
);
11666 static netdev_tx_t
ipw_prom_hard_start_xmit(struct sk_buff
*skb
,
11667 struct net_device
*dev
)
11669 IPW_DEBUG_INFO("prom dev->xmit\n");
11670 dev_kfree_skb(skb
);
11671 return NETDEV_TX_OK
;
11674 static const struct net_device_ops ipw_prom_netdev_ops
= {
11675 .ndo_open
= ipw_prom_open
,
11676 .ndo_stop
= ipw_prom_stop
,
11677 .ndo_start_xmit
= ipw_prom_hard_start_xmit
,
11678 .ndo_change_mtu
= libipw_change_mtu
,
11679 .ndo_set_mac_address
= eth_mac_addr
,
11680 .ndo_validate_addr
= eth_validate_addr
,
11683 static int ipw_prom_alloc(struct ipw_priv
*priv
)
11687 if (priv
->prom_net_dev
)
11690 priv
->prom_net_dev
= alloc_libipw(sizeof(struct ipw_prom_priv
), 1);
11691 if (priv
->prom_net_dev
== NULL
)
11694 priv
->prom_priv
= libipw_priv(priv
->prom_net_dev
);
11695 priv
->prom_priv
->ieee
= netdev_priv(priv
->prom_net_dev
);
11696 priv
->prom_priv
->priv
= priv
;
11698 strcpy(priv
->prom_net_dev
->name
, "rtap%d");
11699 memcpy(priv
->prom_net_dev
->dev_addr
, priv
->mac_addr
, ETH_ALEN
);
11701 priv
->prom_net_dev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
11702 priv
->prom_net_dev
->netdev_ops
= &ipw_prom_netdev_ops
;
11704 priv
->prom_priv
->ieee
->iw_mode
= IW_MODE_MONITOR
;
11705 SET_NETDEV_DEV(priv
->prom_net_dev
, &priv
->pci_dev
->dev
);
11707 rc
= register_netdev(priv
->prom_net_dev
);
11709 free_libipw(priv
->prom_net_dev
, 1);
11710 priv
->prom_net_dev
= NULL
;
11717 static void ipw_prom_free(struct ipw_priv
*priv
)
11719 if (!priv
->prom_net_dev
)
11722 unregister_netdev(priv
->prom_net_dev
);
11723 free_libipw(priv
->prom_net_dev
, 1);
11725 priv
->prom_net_dev
= NULL
;
11730 static const struct net_device_ops ipw_netdev_ops
= {
11731 .ndo_init
= ipw_net_init
,
11732 .ndo_open
= ipw_net_open
,
11733 .ndo_stop
= ipw_net_stop
,
11734 .ndo_set_multicast_list
= ipw_net_set_multicast_list
,
11735 .ndo_set_mac_address
= ipw_net_set_mac_address
,
11736 .ndo_start_xmit
= libipw_xmit
,
11737 .ndo_change_mtu
= libipw_change_mtu
,
11738 .ndo_validate_addr
= eth_validate_addr
,
11741 static int __devinit
ipw_pci_probe(struct pci_dev
*pdev
,
11742 const struct pci_device_id
*ent
)
11745 struct net_device
*net_dev
;
11746 void __iomem
*base
;
11748 struct ipw_priv
*priv
;
11751 net_dev
= alloc_libipw(sizeof(struct ipw_priv
), 0);
11752 if (net_dev
== NULL
) {
11757 priv
= libipw_priv(net_dev
);
11758 priv
->ieee
= netdev_priv(net_dev
);
11760 priv
->net_dev
= net_dev
;
11761 priv
->pci_dev
= pdev
;
11762 ipw_debug_level
= debug
;
11763 spin_lock_init(&priv
->irq_lock
);
11764 spin_lock_init(&priv
->lock
);
11765 for (i
= 0; i
< IPW_IBSS_MAC_HASH_SIZE
; i
++)
11766 INIT_LIST_HEAD(&priv
->ibss_mac_hash
[i
]);
11768 mutex_init(&priv
->mutex
);
11769 if (pci_enable_device(pdev
)) {
11771 goto out_free_libipw
;
11774 pci_set_master(pdev
);
11776 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
11778 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
11780 printk(KERN_WARNING DRV_NAME
": No suitable DMA available.\n");
11781 goto out_pci_disable_device
;
11784 pci_set_drvdata(pdev
, priv
);
11786 err
= pci_request_regions(pdev
, DRV_NAME
);
11788 goto out_pci_disable_device
;
11790 /* We disable the RETRY_TIMEOUT register (0x41) to keep
11791 * PCI Tx retries from interfering with C3 CPU state */
11792 pci_read_config_dword(pdev
, 0x40, &val
);
11793 if ((val
& 0x0000ff00) != 0)
11794 pci_write_config_dword(pdev
, 0x40, val
& 0xffff00ff);
11796 length
= pci_resource_len(pdev
, 0);
11797 priv
->hw_len
= length
;
11799 base
= pci_ioremap_bar(pdev
, 0);
11802 goto out_pci_release_regions
;
11805 priv
->hw_base
= base
;
11806 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length
);
11807 IPW_DEBUG_INFO("pci_resource_base = %p\n", base
);
11809 err
= ipw_setup_deferred_work(priv
);
11811 IPW_ERROR("Unable to setup deferred work\n");
11815 ipw_sw_reset(priv
, 1);
11817 err
= request_irq(pdev
->irq
, ipw_isr
, IRQF_SHARED
, DRV_NAME
, priv
);
11819 IPW_ERROR("Error allocating IRQ %d\n", pdev
->irq
);
11820 goto out_destroy_workqueue
;
11823 SET_NETDEV_DEV(net_dev
, &pdev
->dev
);
11825 mutex_lock(&priv
->mutex
);
11827 priv
->ieee
->hard_start_xmit
= ipw_net_hard_start_xmit
;
11828 priv
->ieee
->set_security
= shim__set_security
;
11829 priv
->ieee
->is_queue_full
= ipw_net_is_queue_full
;
11831 #ifdef CONFIG_IPW2200_QOS
11832 priv
->ieee
->is_qos_active
= ipw_is_qos_active
;
11833 priv
->ieee
->handle_probe_response
= ipw_handle_beacon
;
11834 priv
->ieee
->handle_beacon
= ipw_handle_probe_response
;
11835 priv
->ieee
->handle_assoc_response
= ipw_handle_assoc_response
;
11836 #endif /* CONFIG_IPW2200_QOS */
11838 priv
->ieee
->perfect_rssi
= -20;
11839 priv
->ieee
->worst_rssi
= -85;
11841 net_dev
->netdev_ops
= &ipw_netdev_ops
;
11842 priv
->wireless_data
.spy_data
= &priv
->ieee
->spy_data
;
11843 net_dev
->wireless_data
= &priv
->wireless_data
;
11844 net_dev
->wireless_handlers
= &ipw_wx_handler_def
;
11845 net_dev
->ethtool_ops
= &ipw_ethtool_ops
;
11846 net_dev
->irq
= pdev
->irq
;
11847 net_dev
->base_addr
= (unsigned long)priv
->hw_base
;
11848 net_dev
->mem_start
= pci_resource_start(pdev
, 0);
11849 net_dev
->mem_end
= net_dev
->mem_start
+ pci_resource_len(pdev
, 0) - 1;
11851 err
= sysfs_create_group(&pdev
->dev
.kobj
, &ipw_attribute_group
);
11853 IPW_ERROR("failed to create sysfs device attributes\n");
11854 mutex_unlock(&priv
->mutex
);
11855 goto out_release_irq
;
11858 mutex_unlock(&priv
->mutex
);
11859 err
= register_netdev(net_dev
);
11861 IPW_ERROR("failed to register network device\n");
11862 goto out_remove_sysfs
;
11865 #ifdef CONFIG_IPW2200_PROMISCUOUS
11867 err
= ipw_prom_alloc(priv
);
11869 IPW_ERROR("Failed to register promiscuous network "
11870 "device (error %d).\n", err
);
11871 unregister_netdev(priv
->net_dev
);
11872 goto out_remove_sysfs
;
11877 printk(KERN_INFO DRV_NAME
": Detected geography %s (%d 802.11bg "
11878 "channels, %d 802.11a channels)\n",
11879 priv
->ieee
->geo
.name
, priv
->ieee
->geo
.bg_channels
,
11880 priv
->ieee
->geo
.a_channels
);
11885 sysfs_remove_group(&pdev
->dev
.kobj
, &ipw_attribute_group
);
11887 free_irq(pdev
->irq
, priv
);
11888 out_destroy_workqueue
:
11889 destroy_workqueue(priv
->workqueue
);
11890 priv
->workqueue
= NULL
;
11892 iounmap(priv
->hw_base
);
11893 out_pci_release_regions
:
11894 pci_release_regions(pdev
);
11895 out_pci_disable_device
:
11896 pci_disable_device(pdev
);
11897 pci_set_drvdata(pdev
, NULL
);
11899 free_libipw(priv
->net_dev
, 0);
11904 static void __devexit
ipw_pci_remove(struct pci_dev
*pdev
)
11906 struct ipw_priv
*priv
= pci_get_drvdata(pdev
);
11907 struct list_head
*p
, *q
;
11913 mutex_lock(&priv
->mutex
);
11915 priv
->status
|= STATUS_EXIT_PENDING
;
11917 sysfs_remove_group(&pdev
->dev
.kobj
, &ipw_attribute_group
);
11919 mutex_unlock(&priv
->mutex
);
11921 unregister_netdev(priv
->net_dev
);
11924 ipw_rx_queue_free(priv
, priv
->rxq
);
11927 ipw_tx_queue_free(priv
);
11929 if (priv
->cmdlog
) {
11930 kfree(priv
->cmdlog
);
11931 priv
->cmdlog
= NULL
;
11933 /* ipw_down will ensure that there is no more pending work
11934 * in the workqueue's, so we can safely remove them now. */
11935 cancel_delayed_work(&priv
->adhoc_check
);
11936 cancel_delayed_work(&priv
->gather_stats
);
11937 cancel_delayed_work(&priv
->request_scan
);
11938 cancel_delayed_work(&priv
->request_direct_scan
);
11939 cancel_delayed_work(&priv
->request_passive_scan
);
11940 cancel_delayed_work(&priv
->scan_event
);
11941 cancel_delayed_work(&priv
->rf_kill
);
11942 cancel_delayed_work(&priv
->scan_check
);
11943 destroy_workqueue(priv
->workqueue
);
11944 priv
->workqueue
= NULL
;
11946 /* Free MAC hash list for ADHOC */
11947 for (i
= 0; i
< IPW_IBSS_MAC_HASH_SIZE
; i
++) {
11948 list_for_each_safe(p
, q
, &priv
->ibss_mac_hash
[i
]) {
11950 kfree(list_entry(p
, struct ipw_ibss_seq
, list
));
11954 kfree(priv
->error
);
11955 priv
->error
= NULL
;
11957 #ifdef CONFIG_IPW2200_PROMISCUOUS
11958 ipw_prom_free(priv
);
11961 free_irq(pdev
->irq
, priv
);
11962 iounmap(priv
->hw_base
);
11963 pci_release_regions(pdev
);
11964 pci_disable_device(pdev
);
11965 pci_set_drvdata(pdev
, NULL
);
11966 /* wiphy_unregister needs to be here, before free_libipw */
11967 wiphy_unregister(priv
->ieee
->wdev
.wiphy
);
11968 kfree(priv
->ieee
->a_band
.channels
);
11969 kfree(priv
->ieee
->bg_band
.channels
);
11970 free_libipw(priv
->net_dev
, 0);
11975 static int ipw_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
11977 struct ipw_priv
*priv
= pci_get_drvdata(pdev
);
11978 struct net_device
*dev
= priv
->net_dev
;
11980 printk(KERN_INFO
"%s: Going into suspend...\n", dev
->name
);
11982 /* Take down the device; powers it off, etc. */
11985 /* Remove the PRESENT state of the device */
11986 netif_device_detach(dev
);
11988 pci_save_state(pdev
);
11989 pci_disable_device(pdev
);
11990 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
11992 priv
->suspend_at
= get_seconds();
11997 static int ipw_pci_resume(struct pci_dev
*pdev
)
11999 struct ipw_priv
*priv
= pci_get_drvdata(pdev
);
12000 struct net_device
*dev
= priv
->net_dev
;
12004 printk(KERN_INFO
"%s: Coming out of suspend...\n", dev
->name
);
12006 pci_set_power_state(pdev
, PCI_D0
);
12007 err
= pci_enable_device(pdev
);
12009 printk(KERN_ERR
"%s: pci_enable_device failed on resume\n",
12013 pci_restore_state(pdev
);
12016 * Suspend/Resume resets the PCI configuration space, so we have to
12017 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
12018 * from interfering with C3 CPU state. pci_restore_state won't help
12019 * here since it only restores the first 64 bytes pci config header.
12021 pci_read_config_dword(pdev
, 0x40, &val
);
12022 if ((val
& 0x0000ff00) != 0)
12023 pci_write_config_dword(pdev
, 0x40, val
& 0xffff00ff);
12025 /* Set the device back into the PRESENT state; this will also wake
12026 * the queue of needed */
12027 netif_device_attach(dev
);
12029 priv
->suspend_time
= get_seconds() - priv
->suspend_at
;
12031 /* Bring the device back up */
12032 queue_work(priv
->workqueue
, &priv
->up
);
12038 static void ipw_pci_shutdown(struct pci_dev
*pdev
)
12040 struct ipw_priv
*priv
= pci_get_drvdata(pdev
);
12042 /* Take down the device; powers it off, etc. */
12045 pci_disable_device(pdev
);
12048 /* driver initialization stuff */
12049 static struct pci_driver ipw_driver
= {
12051 .id_table
= card_ids
,
12052 .probe
= ipw_pci_probe
,
12053 .remove
= __devexit_p(ipw_pci_remove
),
12055 .suspend
= ipw_pci_suspend
,
12056 .resume
= ipw_pci_resume
,
12058 .shutdown
= ipw_pci_shutdown
,
12061 static int __init
ipw_init(void)
12065 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
12066 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
12068 ret
= pci_register_driver(&ipw_driver
);
12070 IPW_ERROR("Unable to initialize PCI module\n");
12074 ret
= driver_create_file(&ipw_driver
.driver
, &driver_attr_debug_level
);
12076 IPW_ERROR("Unable to create driver sysfs file\n");
12077 pci_unregister_driver(&ipw_driver
);
12084 static void __exit
ipw_exit(void)
12086 driver_remove_file(&ipw_driver
.driver
, &driver_attr_debug_level
);
12087 pci_unregister_driver(&ipw_driver
);
12090 module_param(disable
, int, 0444);
12091 MODULE_PARM_DESC(disable
, "manually disable the radio (default 0 [radio on])");
12093 module_param(associate
, int, 0444);
12094 MODULE_PARM_DESC(associate
, "auto associate when scanning (default off)");
12096 module_param(auto_create
, int, 0444);
12097 MODULE_PARM_DESC(auto_create
, "auto create adhoc network (default on)");
12099 module_param_named(led
, led_support
, int, 0444);
12100 MODULE_PARM_DESC(led
, "enable led control on some systems (default 1 on)");
12102 module_param(debug
, int, 0444);
12103 MODULE_PARM_DESC(debug
, "debug output mask");
12105 module_param_named(channel
, default_channel
, int, 0444);
12106 MODULE_PARM_DESC(channel
, "channel to limit associate to (default 0 [ANY])");
12108 #ifdef CONFIG_IPW2200_PROMISCUOUS
12109 module_param(rtap_iface
, int, 0444);
12110 MODULE_PARM_DESC(rtap_iface
, "create the rtap interface (1 - create, default 0)");
12113 #ifdef CONFIG_IPW2200_QOS
12114 module_param(qos_enable
, int, 0444);
12115 MODULE_PARM_DESC(qos_enable
, "enable all QoS functionalitis");
12117 module_param(qos_burst_enable
, int, 0444);
12118 MODULE_PARM_DESC(qos_burst_enable
, "enable QoS burst mode");
12120 module_param(qos_no_ack_mask
, int, 0444);
12121 MODULE_PARM_DESC(qos_no_ack_mask
, "mask Tx_Queue to no ack");
12123 module_param(burst_duration_CCK
, int, 0444);
12124 MODULE_PARM_DESC(burst_duration_CCK
, "set CCK burst value");
12126 module_param(burst_duration_OFDM
, int, 0444);
12127 MODULE_PARM_DESC(burst_duration_OFDM
, "set OFDM burst value");
12128 #endif /* CONFIG_IPW2200_QOS */
12130 #ifdef CONFIG_IPW2200_MONITOR
12131 module_param_named(mode
, network_mode
, int, 0444);
12132 MODULE_PARM_DESC(mode
, "network mode (0=BSS,1=IBSS,2=Monitor)");
12134 module_param_named(mode
, network_mode
, int, 0444);
12135 MODULE_PARM_DESC(mode
, "network mode (0=BSS,1=IBSS)");
12138 module_param(bt_coexist
, int, 0444);
12139 MODULE_PARM_DESC(bt_coexist
, "enable bluetooth coexistence (default off)");
12141 module_param(hwcrypto
, int, 0444);
12142 MODULE_PARM_DESC(hwcrypto
, "enable hardware crypto (default off)");
12144 module_param(cmdlog
, int, 0444);
12145 MODULE_PARM_DESC(cmdlog
,
12146 "allocate a ring buffer for logging firmware commands");
12148 module_param(roaming
, int, 0444);
12149 MODULE_PARM_DESC(roaming
, "enable roaming support (default on)");
12151 module_param(antenna
, int, 0444);
12152 MODULE_PARM_DESC(antenna
, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
12154 module_exit(ipw_exit
);
12155 module_init(ipw_init
);