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 = 0;
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);
1976 inta &= (IPW_INTA_MASK_ALL & inta_mask);
1978 /* Add any cached INTA values that need to be handled */
1979 inta |= priv->isr_inta;
1981 spin_unlock_irqrestore(&priv->irq_lock, flags);
1983 spin_lock_irqsave(&priv->lock, flags);
1985 /* handle all the justifications for the interrupt */
1986 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
1988 handled |= IPW_INTA_BIT_RX_TRANSFER;
1991 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
1992 IPW_DEBUG_HC("Command completed.\n");
1993 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
1994 priv->status &= ~STATUS_HCMD_ACTIVE;
1995 wake_up_interruptible(&priv->wait_command_queue);
1996 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
1999 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
2000 IPW_DEBUG_TX("TX_QUEUE_1\n");
2001 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
2002 handled |= IPW_INTA_BIT_TX_QUEUE_1;
2005 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
2006 IPW_DEBUG_TX("TX_QUEUE_2\n");
2007 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
2008 handled |= IPW_INTA_BIT_TX_QUEUE_2;
2011 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
2012 IPW_DEBUG_TX("TX_QUEUE_3\n");
2013 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
2014 handled |= IPW_INTA_BIT_TX_QUEUE_3;
2017 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
2018 IPW_DEBUG_TX("TX_QUEUE_4\n");
2019 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
2020 handled |= IPW_INTA_BIT_TX_QUEUE_4;
2023 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
2024 IPW_WARNING("STATUS_CHANGE\n");
2025 handled |= IPW_INTA_BIT_STATUS_CHANGE;
2028 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
2029 IPW_WARNING("TX_PERIOD_EXPIRED\n");
2030 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
2033 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
2034 IPW_WARNING("HOST_CMD_DONE\n");
2035 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
2038 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
2039 IPW_WARNING("FW_INITIALIZATION_DONE\n");
2040 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
2043 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
2044 IPW_WARNING("PHY_OFF_DONE\n");
2045 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
2048 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
2049 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
2050 priv->status |= STATUS_RF_KILL_HW;
2051 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
2052 wake_up_interruptible(&priv->wait_command_queue);
2053 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
2054 cancel_delayed_work(&priv->request_scan);
2055 cancel_delayed_work(&priv->request_direct_scan);
2056 cancel_delayed_work(&priv->request_passive_scan);
2057 cancel_delayed_work(&priv->scan_event);
2058 schedule_work(&priv->link_down);
2059 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
2060 handled |= IPW_INTA_BIT_RF_KILL_DONE;
2063 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
2064 IPW_WARNING("Firmware error detected. Restarting.\n");
2066 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
2067 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
2068 struct ipw_fw_error *error =
2069 ipw_alloc_error_log(priv);
2070 ipw_dump_error_log(priv, error);
2074 priv->error = ipw_alloc_error_log(priv);
2076 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
2078 IPW_DEBUG_FW("Error allocating sysfs 'error' "
2080 if (ipw_debug_level & IPW_DL_FW_ERRORS)
2081 ipw_dump_error_log(priv, priv->error);
2084 /* XXX: If hardware encryption is for WPA/WPA2,
2085 * we have to notify the supplicant. */
2086 if (priv->ieee->sec.encrypt) {
2087 priv->status &= ~STATUS_ASSOCIATED;
2088 notify_wx_assoc_event(priv);
2091 /* Keep the restart process from trying to send host
2092 * commands by clearing the INIT status bit */
2093 priv->status &= ~STATUS_INIT;
2095 /* Cancel currently queued command. */
2096 priv->status &= ~STATUS_HCMD_ACTIVE;
2097 wake_up_interruptible(&priv->wait_command_queue);
2099 queue_work(priv->workqueue, &priv->adapter_restart);
2100 handled |= IPW_INTA_BIT_FATAL_ERROR;
2103 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
2104 IPW_ERROR("Parity error\n");
2105 handled |= IPW_INTA_BIT_PARITY_ERROR;
2108 if (handled != inta) {
2109 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
2112 spin_unlock_irqrestore(&priv->lock, flags);
2114 /* enable all interrupts */
2115 ipw_enable_interrupts(priv);
2118 #define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2119 static char *get_cmd_string(u8 cmd)
2122 IPW_CMD(HOST_COMPLETE);
2123 IPW_CMD(POWER_DOWN);
2124 IPW_CMD(SYSTEM_CONFIG);
2125 IPW_CMD(MULTICAST_ADDRESS);
2127 IPW_CMD(ADAPTER_ADDRESS);
2129 IPW_CMD(RTS_THRESHOLD);
2130 IPW_CMD(FRAG_THRESHOLD);
2131 IPW_CMD(POWER_MODE);
2133 IPW_CMD(TGI_TX_KEY);
2134 IPW_CMD(SCAN_REQUEST);
2135 IPW_CMD(SCAN_REQUEST_EXT);
2137 IPW_CMD(SUPPORTED_RATES);
2138 IPW_CMD(SCAN_ABORT);
2140 IPW_CMD(QOS_PARAMETERS);
2141 IPW_CMD(DINO_CONFIG);
2142 IPW_CMD(RSN_CAPABILITIES);
2144 IPW_CMD(CARD_DISABLE);
2145 IPW_CMD(SEED_NUMBER);
2147 IPW_CMD(COUNTRY_INFO);
2148 IPW_CMD(AIRONET_INFO);
2149 IPW_CMD(AP_TX_POWER);
2151 IPW_CMD(CCX_VER_INFO);
2152 IPW_CMD(SET_CALIBRATION);
2153 IPW_CMD(SENSITIVITY_CALIB);
2154 IPW_CMD(RETRY_LIMIT);
2155 IPW_CMD(IPW_PRE_POWER_DOWN);
2156 IPW_CMD(VAP_BEACON_TEMPLATE);
2157 IPW_CMD(VAP_DTIM_PERIOD);
2158 IPW_CMD(EXT_SUPPORTED_RATES);
2159 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2160 IPW_CMD(VAP_QUIET_INTERVALS);
2161 IPW_CMD(VAP_CHANNEL_SWITCH);
2162 IPW_CMD(VAP_MANDATORY_CHANNELS);
2163 IPW_CMD(VAP_CELL_PWR_LIMIT);
2164 IPW_CMD(VAP_CF_PARAM_SET);
2165 IPW_CMD(VAP_SET_BEACONING_STATE);
2166 IPW_CMD(MEASUREMENT);
2167 IPW_CMD(POWER_CAPABILITY);
2168 IPW_CMD(SUPPORTED_CHANNELS);
2169 IPW_CMD(TPC_REPORT);
2171 IPW_CMD(PRODUCTION_COMMAND);
2177 #define HOST_COMPLETE_TIMEOUT HZ
2179 static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
2182 unsigned long flags;
2184 spin_lock_irqsave(&priv->lock, flags);
2185 if (priv->status & STATUS_HCMD_ACTIVE) {
2186 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2187 get_cmd_string(cmd->cmd));
2188 spin_unlock_irqrestore(&priv->lock, flags);
2192 priv->status |= STATUS_HCMD_ACTIVE;
2195 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2196 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2197 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2198 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2200 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2203 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2204 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2207 #ifndef DEBUG_CMD_WEP_KEY
2208 if (cmd->cmd == IPW_CMD_WEP_KEY)
2209 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2212 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2214 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
2216 priv->status &= ~STATUS_HCMD_ACTIVE;
2217 IPW_ERROR("Failed to send %s: Reason %d\n",
2218 get_cmd_string(cmd->cmd), rc);
2219 spin_unlock_irqrestore(&priv->lock, flags);
2222 spin_unlock_irqrestore(&priv->lock, flags);
2224 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2226 status & STATUS_HCMD_ACTIVE),
2227 HOST_COMPLETE_TIMEOUT);
2229 spin_lock_irqsave(&priv->lock, flags);
2230 if (priv->status & STATUS_HCMD_ACTIVE) {
2231 IPW_ERROR("Failed to send %s: Command timed out.\n",
2232 get_cmd_string(cmd->cmd));
2233 priv->status &= ~STATUS_HCMD_ACTIVE;
2234 spin_unlock_irqrestore(&priv->lock, flags);
2238 spin_unlock_irqrestore(&priv->lock, flags);
2242 if (priv->status & STATUS_RF_KILL_HW) {
2243 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2244 get_cmd_string(cmd->cmd));
2251 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2252 priv->cmdlog_pos %= priv->cmdlog_len;
2257 static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
2259 struct host_cmd cmd = {
2263 return __ipw_send_cmd(priv, &cmd);
2266 static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2269 struct host_cmd cmd = {
2275 return __ipw_send_cmd(priv, &cmd);
2278 static int ipw_send_host_complete(struct ipw_priv *priv)
2281 IPW_ERROR("Invalid args\n");
2285 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
2288 static int ipw_send_system_config(struct ipw_priv *priv)
2290 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2291 sizeof(priv->sys_config),
2295 static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
2297 if (!priv || !ssid) {
2298 IPW_ERROR("Invalid args\n");
2302 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
2306 static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
2308 if (!priv || !mac) {
2309 IPW_ERROR("Invalid args\n");
2313 IPW_DEBUG_INFO("%s: Setting MAC to %pM\n",
2314 priv->net_dev->name, mac);
2316 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
2320 * NOTE: This must be executed from our workqueue as it results in udelay
2321 * being called which may corrupt the keyboard if executed on default
2324 static void ipw_adapter_restart(void *adapter)
2326 struct ipw_priv *priv = adapter;
2328 if (priv->status & STATUS_RF_KILL_MASK)
2333 if (priv->assoc_network &&
2334 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2335 ipw_remove_current_network(priv);
2338 IPW_ERROR("Failed to up device\n");
2343 static void ipw_bg_adapter_restart(struct work_struct *work)
2345 struct ipw_priv *priv =
2346 container_of(work, struct ipw_priv, adapter_restart);
2347 mutex_lock(&priv->mutex);
2348 ipw_adapter_restart(priv);
2349 mutex_unlock(&priv->mutex);
2352 #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2354 static void ipw_scan_check(void *data)
2356 struct ipw_priv *priv = data;
2357 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2358 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
2359 "adapter after (%dms).\n",
2360 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
2361 queue_work(priv->workqueue, &priv->adapter_restart);
2365 static void ipw_bg_scan_check(struct work_struct *work)
2367 struct ipw_priv *priv =
2368 container_of(work, struct ipw_priv, scan_check.work);
2369 mutex_lock(&priv->mutex);
2370 ipw_scan_check(priv);
2371 mutex_unlock(&priv->mutex);
2374 static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2375 struct ipw_scan_request_ext *request)
2377 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
2378 sizeof(*request), request);
2381 static int ipw_send_scan_abort(struct ipw_priv *priv)
2384 IPW_ERROR("Invalid args\n");
2388 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
2391 static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2393 struct ipw_sensitivity_calib calib = {
2394 .beacon_rssi_raw = cpu_to_le16(sens),
2397 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
2401 static int ipw_send_associate(struct ipw_priv *priv,
2402 struct ipw_associate *associate)
2404 if (!priv || !associate) {
2405 IPW_ERROR("Invalid args\n");
2409 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate),
2413 static int ipw_send_supported_rates(struct ipw_priv *priv,
2414 struct ipw_supported_rates *rates)
2416 if (!priv || !rates) {
2417 IPW_ERROR("Invalid args\n");
2421 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
2425 static int ipw_set_random_seed(struct ipw_priv *priv)
2430 IPW_ERROR("Invalid args\n");
2434 get_random_bytes(&val, sizeof(val));
2436 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
2439 static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2441 __le32 v = cpu_to_le32(phy_off);
2443 IPW_ERROR("Invalid args\n");
2447 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(v), &v);
2450 static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
2452 if (!priv || !power) {
2453 IPW_ERROR("Invalid args\n");
2457 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
2460 static int ipw_set_tx_power(struct ipw_priv *priv)
2462 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
2463 struct ipw_tx_power tx_power;
2467 memset(&tx_power, 0, sizeof(tx_power));
2469 /* configure device for 'G' band */
2470 tx_power.ieee_mode = IPW_G_MODE;
2471 tx_power.num_channels = geo->bg_channels;
2472 for (i = 0; i < geo->bg_channels; i++) {
2473 max_power = geo->bg[i].max_power;
2474 tx_power.channels_tx_power[i].channel_number =
2476 tx_power.channels_tx_power[i].tx_power = max_power ?
2477 min(max_power, priv->tx_power) : priv->tx_power;
2479 if (ipw_send_tx_power(priv, &tx_power))
2482 /* configure device to also handle 'B' band */
2483 tx_power.ieee_mode = IPW_B_MODE;
2484 if (ipw_send_tx_power(priv, &tx_power))
2487 /* configure device to also handle 'A' band */
2488 if (priv->ieee->abg_true) {
2489 tx_power.ieee_mode = IPW_A_MODE;
2490 tx_power.num_channels = geo->a_channels;
2491 for (i = 0; i < tx_power.num_channels; i++) {
2492 max_power = geo->a[i].max_power;
2493 tx_power.channels_tx_power[i].channel_number =
2495 tx_power.channels_tx_power[i].tx_power = max_power ?
2496 min(max_power, priv->tx_power) : priv->tx_power;
2498 if (ipw_send_tx_power(priv, &tx_power))
2504 static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2506 struct ipw_rts_threshold rts_threshold = {
2507 .rts_threshold = cpu_to_le16(rts),
2511 IPW_ERROR("Invalid args\n");
2515 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2516 sizeof(rts_threshold), &rts_threshold);
2519 static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2521 struct ipw_frag_threshold frag_threshold = {
2522 .frag_threshold = cpu_to_le16(frag),
2526 IPW_ERROR("Invalid args\n");
2530 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2531 sizeof(frag_threshold), &frag_threshold);
2534 static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2539 IPW_ERROR("Invalid args\n");
2543 /* If on battery, set to 3, if AC set to CAM, else user
2546 case IPW_POWER_BATTERY:
2547 param = cpu_to_le32(IPW_POWER_INDEX_3);
2550 param = cpu_to_le32(IPW_POWER_MODE_CAM);
2553 param = cpu_to_le32(mode);
2557 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
2561 static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2563 struct ipw_retry_limit retry_limit = {
2564 .short_retry_limit = slimit,
2565 .long_retry_limit = llimit
2569 IPW_ERROR("Invalid args\n");
2573 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
2578 * The IPW device contains a Microwire compatible EEPROM that stores
2579 * various data like the MAC address. Usually the firmware has exclusive
2580 * access to the eeprom, but during device initialization (before the
2581 * device driver has sent the HostComplete command to the firmware) the
2582 * device driver has read access to the EEPROM by way of indirect addressing
2583 * through a couple of memory mapped registers.
2585 * The following is a simplified implementation for pulling data out of the
2586 * the eeprom, along with some helper functions to find information in
2587 * the per device private data's copy of the eeprom.
2589 * NOTE: To better understand how these functions work (i.e what is a chip
2590 * select and why do have to keep driving the eeprom clock?), read
2591 * just about any data sheet for a Microwire compatible EEPROM.
2594 /* write a 32 bit value into the indirect accessor register */
2595 static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2597 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
2599 /* the eeprom requires some time to complete the operation */
2600 udelay(p->eeprom_delay);
2605 /* perform a chip select operation */
2606 static void eeprom_cs(struct ipw_priv *priv)
2608 eeprom_write_reg(priv, 0);
2609 eeprom_write_reg(priv, EEPROM_BIT_CS);
2610 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2611 eeprom_write_reg(priv, EEPROM_BIT_CS);
2614 /* perform a chip select operation */
2615 static void eeprom_disable_cs(struct ipw_priv *priv)
2617 eeprom_write_reg(priv, EEPROM_BIT_CS);
2618 eeprom_write_reg(priv, 0);
2619 eeprom_write_reg(priv, EEPROM_BIT_SK);
2622 /* push a single bit down to the eeprom */
2623 static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
2625 int d = (bit ? EEPROM_BIT_DI : 0);
2626 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2627 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
2630 /* push an opcode followed by an address down to the eeprom */
2631 static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
2636 eeprom_write_bit(priv, 1);
2637 eeprom_write_bit(priv, op & 2);
2638 eeprom_write_bit(priv, op & 1);
2639 for (i = 7; i >= 0; i--) {
2640 eeprom_write_bit(priv, addr & (1 << i));
2644 /* pull 16 bits off the eeprom, one bit at a time */
2645 static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
2650 /* Send READ Opcode */
2651 eeprom_op(priv, EEPROM_CMD_READ, addr);
2653 /* Send dummy bit */
2654 eeprom_write_reg(priv, EEPROM_BIT_CS);
2656 /* Read the byte off the eeprom one bit at a time */
2657 for (i = 0; i < 16; i++) {
2659 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2660 eeprom_write_reg(priv, EEPROM_BIT_CS);
2661 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2662 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
2665 /* Send another dummy bit */
2666 eeprom_write_reg(priv, 0);
2667 eeprom_disable_cs(priv);
2672 /* helper function for pulling the mac address out of the private */
2673 /* data's copy of the eeprom data */
2674 static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
2676 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
2680 * Either the device driver (i.e. the host) or the firmware can
2681 * load eeprom data into the designated region in SRAM. If neither
2682 * happens then the FW will shutdown with a fatal error.
2684 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2685 * bit needs region of shared SRAM needs to be non-zero.
2687 static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2690 __le16 *eeprom = (__le16 *) priv->eeprom;
2692 IPW_DEBUG_TRACE(">>\n");
2694 /* read entire contents of eeprom into private buffer */
2695 for (i = 0; i < 128; i++)
2696 eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i));
2699 If the data looks correct, then copy it to our private
2700 copy. Otherwise let the firmware know to perform the operation
2703 if (priv->eeprom[EEPROM_VERSION] != 0) {
2704 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2706 /* write the eeprom data to sram */
2707 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
2708 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
2710 /* Do not load eeprom data on fatal error or suspend */
2711 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2713 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2715 /* Load eeprom data on fatal error or suspend */
2716 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2719 IPW_DEBUG_TRACE("<<\n");
2722 static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
2727 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
2729 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
2732 static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2734 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
2735 CB_NUMBER_OF_ELEMENTS_SMALL *
2736 sizeof(struct command_block));
2739 static int ipw_fw_dma_enable(struct ipw_priv *priv)
2740 { /* start dma engine but no transfers yet */
2742 IPW_DEBUG_FW(">> : \n");
2745 ipw_fw_dma_reset_command_blocks(priv);
2747 /* Write CB base address */
2748 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
2750 IPW_DEBUG_FW("<< : \n");
2754 static void ipw_fw_dma_abort(struct ipw_priv *priv)
2758 IPW_DEBUG_FW(">> :\n");
2760 /* set the Stop and Abort bit */
2761 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
2762 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2763 priv->sram_desc.last_cb_index = 0;
2765 IPW_DEBUG_FW("<< \n");
2768 static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2769 struct command_block *cb)
2772 IPW_SHARED_SRAM_DMA_CONTROL +
2773 (sizeof(struct command_block) * index);
2774 IPW_DEBUG_FW(">> :\n");
2776 ipw_write_indirect(priv, address, (u8 *) cb,
2777 (int)sizeof(struct command_block));
2779 IPW_DEBUG_FW("<< :\n");
2784 static int ipw_fw_dma_kick(struct ipw_priv *priv)
2789 IPW_DEBUG_FW(">> :\n");
2791 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
2792 ipw_fw_dma_write_command_block(priv, index,
2793 &priv->sram_desc.cb_list[index]);
2795 /* Enable the DMA in the CSR register */
2796 ipw_clear_bit(priv, IPW_RESET_REG,
2797 IPW_RESET_REG_MASTER_DISABLED |
2798 IPW_RESET_REG_STOP_MASTER);
2800 /* Set the Start bit. */
2801 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
2802 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2804 IPW_DEBUG_FW("<< :\n");
2808 static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2811 u32 register_value = 0;
2812 u32 cb_fields_address = 0;
2814 IPW_DEBUG_FW(">> :\n");
2815 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2816 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
2818 /* Read the DMA Controlor register */
2819 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2820 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
2822 /* Print the CB values */
2823 cb_fields_address = address;
2824 register_value = ipw_read_reg32(priv, cb_fields_address);
2825 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
2827 cb_fields_address += sizeof(u32);
2828 register_value = ipw_read_reg32(priv, cb_fields_address);
2829 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
2831 cb_fields_address += sizeof(u32);
2832 register_value = ipw_read_reg32(priv, cb_fields_address);
2833 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2836 cb_fields_address += sizeof(u32);
2837 register_value = ipw_read_reg32(priv, cb_fields_address);
2838 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
2840 IPW_DEBUG_FW(">> :\n");
2843 static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2845 u32 current_cb_address = 0;
2846 u32 current_cb_index = 0;
2848 IPW_DEBUG_FW("<< :\n");
2849 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2851 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
2852 sizeof(struct command_block);
2854 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
2855 current_cb_index, current_cb_address);
2857 IPW_DEBUG_FW(">> :\n");
2858 return current_cb_index;
2862 static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2866 int interrupt_enabled, int is_last)
2869 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
2870 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2872 struct command_block *cb;
2873 u32 last_cb_element = 0;
2875 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2876 src_address, dest_address, length);
2878 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2881 last_cb_element = priv->sram_desc.last_cb_index;
2882 cb = &priv->sram_desc.cb_list[last_cb_element];
2883 priv->sram_desc.last_cb_index++;
2885 /* Calculate the new CB control word */
2886 if (interrupt_enabled)
2887 control |= CB_INT_ENABLED;
2890 control |= CB_LAST_VALID;
2894 /* Calculate the CB Element's checksum value */
2895 cb->status = control ^ src_address ^ dest_address;
2897 /* Copy the Source and Destination addresses */
2898 cb->dest_addr = dest_address;
2899 cb->source_addr = src_address;
2901 /* Copy the Control Word last */
2902 cb->control = control;
2907 static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address,
2908 int nr, u32 dest_address, u32 len)
2913 IPW_DEBUG_FW(">> \n");
2914 IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n",
2915 nr, dest_address, len);
2917 for (i = 0; i < nr; i++) {
2918 size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH);
2919 ret = ipw_fw_dma_add_command_block(priv, src_address[i],
2921 i * CB_MAX_LENGTH, size,
2924 IPW_DEBUG_FW_INFO(": Failed\n");
2927 IPW_DEBUG_FW_INFO(": Added new cb\n");
2930 IPW_DEBUG_FW("<< \n");
2934 static int ipw_fw_dma_wait(struct ipw_priv *priv)
2936 u32 current_index = 0, previous_index;
2939 IPW_DEBUG_FW(">> : \n");
2941 current_index = ipw_fw_dma_command_block_index(priv);
2942 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
2943 (int)priv->sram_desc.last_cb_index);
2945 while (current_index < priv->sram_desc.last_cb_index) {
2947 previous_index = current_index;
2948 current_index = ipw_fw_dma_command_block_index(priv);
2950 if (previous_index < current_index) {
2954 if (++watchdog > 400) {
2955 IPW_DEBUG_FW_INFO("Timeout\n");
2956 ipw_fw_dma_dump_command_block(priv);
2957 ipw_fw_dma_abort(priv);
2962 ipw_fw_dma_abort(priv);
2964 /*Disable the DMA in the CSR register */
2965 ipw_set_bit(priv, IPW_RESET_REG,
2966 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
2968 IPW_DEBUG_FW("<< dmaWaitSync \n");
2972 static void ipw_remove_current_network(struct ipw_priv *priv)
2974 struct list_head *element, *safe;
2975 struct libipw_network *network = NULL;
2976 unsigned long flags;
2978 spin_lock_irqsave(&priv->ieee->lock, flags);
2979 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2980 network = list_entry(element, struct libipw_network, list);
2981 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2983 list_add_tail(&network->list,
2984 &priv->ieee->network_free_list);
2987 spin_unlock_irqrestore(&priv->ieee->lock, flags);
2991 * Check that card is still alive.
2992 * Reads debug register from domain0.
2993 * If card is present, pre-defined value should
2997 * @return 1 if card is present, 0 otherwise
2999 static inline int ipw_alive(struct ipw_priv *priv)
3001 return ipw_read32(priv, 0x90) == 0xd55555d5;
3004 /* timeout in msec, attempted in 10-msec quanta */
3005 static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
3011 if ((ipw_read32(priv, addr) & mask) == mask)
3015 } while (i < timeout);
3020 /* These functions load the firmware and micro code for the operation of
3021 * the ipw hardware. It assumes the buffer has all the bits for the
3022 * image and the caller is handling the memory allocation and clean up.
3025 static int ipw_stop_master(struct ipw_priv *priv)
3029 IPW_DEBUG_TRACE(">> \n");
3030 /* stop master. typical delay - 0 */
3031 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
3033 /* timeout is in msec, polled in 10-msec quanta */
3034 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3035 IPW_RESET_REG_MASTER_DISABLED, 100);
3037 IPW_ERROR("wait for stop master failed after 100ms\n");
3041 IPW_DEBUG_INFO("stop master %dms\n", rc);
3046 static void ipw_arc_release(struct ipw_priv *priv)
3048 IPW_DEBUG_TRACE(">> \n");
3051 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
3053 /* no one knows timing, for safety add some delay */
3062 static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
3064 int rc = 0, i, addr;
3068 image = (__le16 *) data;
3070 IPW_DEBUG_TRACE(">> \n");
3072 rc = ipw_stop_master(priv);
3077 for (addr = IPW_SHARED_LOWER_BOUND;
3078 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
3079 ipw_write32(priv, addr, 0);
3082 /* no ucode (yet) */
3083 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3084 /* destroy DMA queues */
3085 /* reset sequence */
3087 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
3088 ipw_arc_release(priv);
3089 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
3093 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
3096 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
3099 /* enable ucode store */
3100 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3101 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
3107 * Do NOT set indirect address register once and then
3108 * store data to indirect data register in the loop.
3109 * It seems very reasonable, but in this case DINO do not
3110 * accept ucode. It is essential to set address each time.
3112 /* load new ipw uCode */
3113 for (i = 0; i < len / 2; i++)
3114 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
3115 le16_to_cpu(image[i]));
3118 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3119 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
3121 /* this is where the igx / win driver deveates from the VAP driver. */
3123 /* wait for alive response */
3124 for (i = 0; i < 100; i++) {
3125 /* poll for incoming data */
3126 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
3127 if (cr & DINO_RXFIFO_DATA)
3132 if (cr & DINO_RXFIFO_DATA) {
3133 /* alive_command_responce size is NOT multiple of 4 */
3134 __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
3136 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
3137 response_buffer[i] =
3138 cpu_to_le32(ipw_read_reg32(priv,
3139 IPW_BASEBAND_RX_FIFO_READ));
3140 memcpy(&priv->dino_alive, response_buffer,
3141 sizeof(priv->dino_alive));
3142 if (priv->dino_alive.alive_command == 1
3143 && priv->dino_alive.ucode_valid == 1) {
3146 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3147 "of %02d/%02d/%02d %02d:%02d\n",
3148 priv->dino_alive.software_revision,
3149 priv->dino_alive.software_revision,
3150 priv->dino_alive.device_identifier,
3151 priv->dino_alive.device_identifier,
3152 priv->dino_alive.time_stamp[0],
3153 priv->dino_alive.time_stamp[1],
3154 priv->dino_alive.time_stamp[2],
3155 priv->dino_alive.time_stamp[3],
3156 priv->dino_alive.time_stamp[4]);
3158 IPW_DEBUG_INFO("Microcode is not alive\n");
3162 IPW_DEBUG_INFO("No alive response from DINO\n");
3166 /* disable DINO, otherwise for some reason
3167 firmware have problem getting alive resp. */
3168 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3173 static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
3177 struct fw_chunk *chunk;
3180 struct pci_pool *pool;
3184 IPW_DEBUG_TRACE("<< : \n");
3186 virts = kmalloc(sizeof(void *) * CB_NUMBER_OF_ELEMENTS_SMALL,
3191 phys = kmalloc(sizeof(dma_addr_t) * CB_NUMBER_OF_ELEMENTS_SMALL,
3197 pool = pci_pool_create("ipw2200", priv->pci_dev, CB_MAX_LENGTH, 0, 0);
3199 IPW_ERROR("pci_pool_create failed\n");
3206 ret = ipw_fw_dma_enable(priv);
3208 /* the DMA is already ready this would be a bug. */
3209 BUG_ON(priv->sram_desc.last_cb_index > 0);
3217 chunk = (struct fw_chunk *)(data + offset);
3218 offset += sizeof(struct fw_chunk);
3219 chunk_len = le32_to_cpu(chunk->length);
3220 start = data + offset;
3222 nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH;
3223 for (i = 0; i < nr; i++) {
3224 virts[total_nr] = pci_pool_alloc(pool, GFP_KERNEL,
3226 if (!virts[total_nr]) {
3230 size = min_t(u32, chunk_len - i * CB_MAX_LENGTH,
3232 memcpy(virts[total_nr], start, size);
3235 /* We don't support fw chunk larger than 64*8K */
3236 BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL);
3239 /* build DMA packet and queue up for sending */
3240 /* dma to chunk->address, the chunk->length bytes from data +
3243 ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr],
3244 nr, le32_to_cpu(chunk->address),
3247 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3251 offset += chunk_len;
3252 } while (offset < len);
3254 /* Run the DMA and wait for the answer */
3255 ret = ipw_fw_dma_kick(priv);
3257 IPW_ERROR("dmaKick Failed\n");
3261 ret = ipw_fw_dma_wait(priv);
3263 IPW_ERROR("dmaWaitSync Failed\n");
3267 for (i = 0; i < total_nr; i++)
3268 pci_pool_free(pool, virts[i], phys[i]);
3270 pci_pool_destroy(pool);
3278 static int ipw_stop_nic(struct ipw_priv *priv)
3283 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
3285 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3286 IPW_RESET_REG_MASTER_DISABLED, 500);
3288 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
3292 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
3297 static void ipw_start_nic(struct ipw_priv *priv)
3299 IPW_DEBUG_TRACE(">>\n");
3301 /* prvHwStartNic release ARC */
3302 ipw_clear_bit(priv, IPW_RESET_REG,
3303 IPW_RESET_REG_MASTER_DISABLED |
3304 IPW_RESET_REG_STOP_MASTER |
3305 CBD_RESET_REG_PRINCETON_RESET);
3307 /* enable power management */
3308 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3309 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
3311 IPW_DEBUG_TRACE("<<\n");
3314 static int ipw_init_nic(struct ipw_priv *priv)
3318 IPW_DEBUG_TRACE(">>\n");
3321 /* set "initialization complete" bit to move adapter to D0 state */
3322 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3324 /* low-level PLL activation */
3325 ipw_write32(priv, IPW_READ_INT_REGISTER,
3326 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
3328 /* wait for clock stabilization */
3329 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3330 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
3332 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3334 /* assert SW reset */
3335 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
3339 /* set "initialization complete" bit to move adapter to D0 state */
3340 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3342 IPW_DEBUG_TRACE(">>\n");
3346 /* Call this function from process context, it will sleep in request_firmware.
3347 * Probe is an ok place to call this from.
3349 static int ipw_reset_nic(struct ipw_priv *priv)
3352 unsigned long flags;
3354 IPW_DEBUG_TRACE(">>\n");
3356 rc = ipw_init_nic(priv);
3358 spin_lock_irqsave(&priv->lock, flags);
3359 /* Clear the 'host command active' bit... */
3360 priv->status &= ~STATUS_HCMD_ACTIVE;
3361 wake_up_interruptible(&priv->wait_command_queue);
3362 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3363 wake_up_interruptible(&priv->wait_state);
3364 spin_unlock_irqrestore(&priv->lock, flags);
3366 IPW_DEBUG_TRACE("<<\n");
3379 static int ipw_get_fw(struct ipw_priv *priv,
3380 const struct firmware **raw, const char *name)
3385 /* ask firmware_class module to get the boot firmware off disk */
3386 rc = request_firmware(raw, name, &priv->pci_dev->dev);
3388 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
3392 if ((*raw)->size < sizeof(*fw)) {
3393 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
3397 fw = (void *)(*raw)->data;
3399 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3400 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
3401 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3402 name, (*raw)->size);
3406 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
3408 le32_to_cpu(fw->ver) >> 16,
3409 le32_to_cpu(fw->ver) & 0xff,
3410 (*raw)->size - sizeof(*fw));
3414 #define IPW_RX_BUF_SIZE (3000)
3416 static void ipw_rx_queue_reset(struct ipw_priv *priv,
3417 struct ipw_rx_queue *rxq)
3419 unsigned long flags;
3422 spin_lock_irqsave(&rxq->lock, flags);
3424 INIT_LIST_HEAD(&rxq->rx_free);
3425 INIT_LIST_HEAD(&rxq->rx_used);
3427 /* Fill the rx_used queue with _all_ of the Rx buffers */
3428 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3429 /* In the reset function, these buffers may have been allocated
3430 * to an SKB, so we need to unmap and free potential storage */
3431 if (rxq->pool[i].skb != NULL) {
3432 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
3433 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
3434 dev_kfree_skb(rxq->pool[i].skb);
3435 rxq->pool[i].skb = NULL;
3437 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3440 /* Set us so that we have processed and used all buffers, but have
3441 * not restocked the Rx queue with fresh buffers */
3442 rxq->read = rxq->write = 0;
3443 rxq->free_count = 0;
3444 spin_unlock_irqrestore(&rxq->lock, flags);
3448 static int fw_loaded = 0;
3449 static const struct firmware *raw = NULL;
3451 static void free_firmware(void)
3454 release_firmware(raw);
3460 #define free_firmware() do {} while (0)
3463 static int ipw_load(struct ipw_priv *priv)
3466 const struct firmware *raw = NULL;
3469 u8 *boot_img, *ucode_img, *fw_img;
3471 int rc = 0, retries = 3;
3473 switch (priv->ieee->iw_mode) {
3475 name = "ipw2200-ibss.fw";
3477 #ifdef CONFIG_IPW2200_MONITOR
3478 case IW_MODE_MONITOR:
3479 name = "ipw2200-sniffer.fw";
3483 name = "ipw2200-bss.fw";
3495 rc = ipw_get_fw(priv, &raw, name);
3502 fw = (void *)raw->data;
3503 boot_img = &fw->data[0];
3504 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3505 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3506 le32_to_cpu(fw->ucode_size)];
3512 priv->rxq = ipw_rx_queue_alloc(priv);
3514 ipw_rx_queue_reset(priv, priv->rxq);
3516 IPW_ERROR("Unable to initialize Rx queue\n");
3521 /* Ensure interrupts are disabled */
3522 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3523 priv->status &= ~STATUS_INT_ENABLED;
3525 /* ack pending interrupts */
3526 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3530 rc = ipw_reset_nic(priv);
3532 IPW_ERROR("Unable to reset NIC\n");
3536 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3537 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
3539 /* DMA the initial boot firmware into the device */
3540 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
3542 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
3546 /* kick start the device */
3547 ipw_start_nic(priv);
3549 /* wait for the device to finish its initial startup sequence */
3550 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3551 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3553 IPW_ERROR("device failed to boot initial fw image\n");
3556 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3558 /* ack fw init done interrupt */
3559 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3561 /* DMA the ucode into the device */
3562 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
3564 IPW_ERROR("Unable to load ucode: %d\n", rc);
3571 /* DMA bss firmware into the device */
3572 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
3574 IPW_ERROR("Unable to load firmware: %d\n", rc);
3581 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3583 rc = ipw_queue_reset(priv);
3585 IPW_ERROR("Unable to initialize queues\n");
3589 /* Ensure interrupts are disabled */
3590 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3591 /* ack pending interrupts */
3592 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3594 /* kick start the device */
3595 ipw_start_nic(priv);
3597 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
3599 IPW_WARNING("Parity error. Retrying init.\n");
3604 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3609 /* wait for the device */
3610 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3611 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3613 IPW_ERROR("device failed to start within 500ms\n");
3616 IPW_DEBUG_INFO("device response after %dms\n", rc);
3618 /* ack fw init done interrupt */
3619 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3621 /* read eeprom data and initialize the eeprom region of sram */
3622 priv->eeprom_delay = 1;
3623 ipw_eeprom_init_sram(priv);
3625 /* enable interrupts */
3626 ipw_enable_interrupts(priv);
3628 /* Ensure our queue has valid packets */
3629 ipw_rx_queue_replenish(priv);
3631 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
3633 /* ack pending interrupts */
3634 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3637 release_firmware(raw);
3643 ipw_rx_queue_free(priv, priv->rxq);
3646 ipw_tx_queue_free(priv);
3648 release_firmware(raw);
3660 * Theory of operation
3662 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3663 * 2 empty entries always kept in the buffer to protect from overflow.
3665 * For Tx queue, there are low mark and high mark limits. If, after queuing
3666 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3667 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
3670 * The IPW operates with six queues, one receive queue in the device's
3671 * sram, one transmit queue for sending commands to the device firmware,
3672 * and four transmit queues for data.
3674 * The four transmit queues allow for performing quality of service (qos)
3675 * transmissions as per the 802.11 protocol. Currently Linux does not
3676 * provide a mechanism to the user for utilizing prioritized queues, so
3677 * we only utilize the first data transmit queue (queue1).
3681 * Driver allocates buffers of this size for Rx
3685 * ipw_rx_queue_space - Return number of free slots available in queue.
3687 static int ipw_rx_queue_space(const struct ipw_rx_queue *q)
3689 int s = q->read - q->write;
3692 /* keep some buffer to not confuse full and empty queue */
3699 static inline int ipw_tx_queue_space(const struct clx2_queue *q)
3701 int s = q->last_used - q->first_empty;
3704 s -= 2; /* keep some reserve to not confuse empty and full situations */
3710 static inline int ipw_queue_inc_wrap(int index, int n_bd)
3712 return (++index == n_bd) ? 0 : index;
3716 * Initialize common DMA queue structure
3718 * @param q queue to init
3719 * @param count Number of BD's to allocate. Should be power of 2
3720 * @param read_register Address for 'read' register
3721 * (not offset within BAR, full address)
3722 * @param write_register Address for 'write' register
3723 * (not offset within BAR, full address)
3724 * @param base_register Address for 'base' register
3725 * (not offset within BAR, full address)
3726 * @param size Address for 'size' register
3727 * (not offset within BAR, full address)
3729 static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
3730 int count, u32 read, u32 write, u32 base, u32 size)
3734 q->low_mark = q->n_bd / 4;
3735 if (q->low_mark < 4)
3738 q->high_mark = q->n_bd / 8;
3739 if (q->high_mark < 2)
3742 q->first_empty = q->last_used = 0;
3746 ipw_write32(priv, base, q->dma_addr);
3747 ipw_write32(priv, size, count);
3748 ipw_write32(priv, read, 0);
3749 ipw_write32(priv, write, 0);
3751 _ipw_read32(priv, 0x90);
3754 static int ipw_queue_tx_init(struct ipw_priv *priv,
3755 struct clx2_tx_queue *q,
3756 int count, u32 read, u32 write, u32 base, u32 size)
3758 struct pci_dev *dev = priv->pci_dev;
3760 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3762 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3767 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
3769 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
3770 sizeof(q->bd[0]) * count);
3776 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3781 * Free one TFD, those at index [txq->q.last_used].
3782 * Do NOT advance any indexes
3787 static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3788 struct clx2_tx_queue *txq)
3790 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3791 struct pci_dev *dev = priv->pci_dev;
3795 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3796 /* nothing to cleanup after for host commands */
3800 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3801 IPW_ERROR("Too many chunks: %i\n",
3802 le32_to_cpu(bd->u.data.num_chunks));
3803 /** @todo issue fatal error, it is quite serious situation */
3807 /* unmap chunks if any */
3808 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3809 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3810 le16_to_cpu(bd->u.data.chunk_len[i]),
3812 if (txq->txb[txq->q.last_used]) {
3813 libipw_txb_free(txq->txb[txq->q.last_used]);
3814 txq->txb[txq->q.last_used] = NULL;
3820 * Deallocate DMA queue.
3822 * Empty queue by removing and destroying all BD's.
3828 static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
3830 struct clx2_queue *q = &txq->q;
3831 struct pci_dev *dev = priv->pci_dev;
3836 /* first, empty all BD's */
3837 for (; q->first_empty != q->last_used;
3838 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3839 ipw_queue_tx_free_tfd(priv, txq);
3842 /* free buffers belonging to queue itself */
3843 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
3847 /* 0 fill whole structure */
3848 memset(txq, 0, sizeof(*txq));
3852 * Destroy all DMA queues and structures
3856 static void ipw_tx_queue_free(struct ipw_priv *priv)
3859 ipw_queue_tx_free(priv, &priv->txq_cmd);
3862 ipw_queue_tx_free(priv, &priv->txq[0]);
3863 ipw_queue_tx_free(priv, &priv->txq[1]);
3864 ipw_queue_tx_free(priv, &priv->txq[2]);
3865 ipw_queue_tx_free(priv, &priv->txq[3]);
3868 static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
3870 /* First 3 bytes are manufacturer */
3871 bssid[0] = priv->mac_addr[0];
3872 bssid[1] = priv->mac_addr[1];
3873 bssid[2] = priv->mac_addr[2];
3875 /* Last bytes are random */
3876 get_random_bytes(&bssid[3], ETH_ALEN - 3);
3878 bssid[0] &= 0xfe; /* clear multicast bit */
3879 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
3882 static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
3884 struct ipw_station_entry entry;
3887 for (i = 0; i < priv->num_stations; i++) {
3888 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3889 /* Another node is active in network */
3890 priv->missed_adhoc_beacons = 0;
3891 if (!(priv->config & CFG_STATIC_CHANNEL))
3892 /* when other nodes drop out, we drop out */
3893 priv->config &= ~CFG_ADHOC_PERSIST;
3899 if (i == MAX_STATIONS)
3900 return IPW_INVALID_STATION;
3902 IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid);
3905 entry.support_mode = 0;
3906 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3907 memcpy(priv->stations[i], bssid, ETH_ALEN);
3908 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
3909 &entry, sizeof(entry));
3910 priv->num_stations++;
3915 static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
3919 for (i = 0; i < priv->num_stations; i++)
3920 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
3923 return IPW_INVALID_STATION;
3926 static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3930 if (priv->status & STATUS_ASSOCIATING) {
3931 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3932 queue_work(priv->workqueue, &priv->disassociate);
3936 if (!(priv->status & STATUS_ASSOCIATED)) {
3937 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3941 IPW_DEBUG_ASSOC("Disassocation attempt from %pM "
3943 priv->assoc_request.bssid,
3944 priv->assoc_request.channel);
3946 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3947 priv->status |= STATUS_DISASSOCIATING;
3950 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3952 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
3954 err = ipw_send_associate(priv, &priv->assoc_request);
3956 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3963 static int ipw_disassociate(void *data)
3965 struct ipw_priv *priv = data;
3966 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3968 ipw_send_disassociate(data, 0);
3969 netif_carrier_off(priv->net_dev);
3973 static void ipw_bg_disassociate(struct work_struct *work)
3975 struct ipw_priv *priv =
3976 container_of(work, struct ipw_priv, disassociate);
3977 mutex_lock(&priv->mutex);
3978 ipw_disassociate(priv);
3979 mutex_unlock(&priv->mutex);
3982 static void ipw_system_config(struct work_struct *work)
3984 struct ipw_priv *priv =
3985 container_of(work, struct ipw_priv, system_config);
3987 #ifdef CONFIG_IPW2200_PROMISCUOUS
3988 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
3989 priv->sys_config.accept_all_data_frames = 1;
3990 priv->sys_config.accept_non_directed_frames = 1;
3991 priv->sys_config.accept_all_mgmt_bcpr = 1;
3992 priv->sys_config.accept_all_mgmt_frames = 1;
3996 ipw_send_system_config(priv);
3999 struct ipw_status_code {
4004 static const struct ipw_status_code ipw_status_codes[] = {
4005 {0x00, "Successful"},
4006 {0x01, "Unspecified failure"},
4007 {0x0A, "Cannot support all requested capabilities in the "
4008 "Capability information field"},
4009 {0x0B, "Reassociation denied due to inability to confirm that "
4010 "association exists"},
4011 {0x0C, "Association denied due to reason outside the scope of this "
4014 "Responding station does not support the specified authentication "
4017 "Received an Authentication frame with authentication sequence "
4018 "transaction sequence number out of expected sequence"},
4019 {0x0F, "Authentication rejected because of challenge failure"},
4020 {0x10, "Authentication rejected due to timeout waiting for next "
4021 "frame in sequence"},
4022 {0x11, "Association denied because AP is unable to handle additional "
4023 "associated stations"},
4025 "Association denied due to requesting station not supporting all "
4026 "of the datarates in the BSSBasicServiceSet Parameter"},
4028 "Association denied due to requesting station not supporting "
4029 "short preamble operation"},
4031 "Association denied due to requesting station not supporting "
4034 "Association denied due to requesting station not supporting "
4037 "Association denied due to requesting station not supporting "
4038 "short slot operation"},
4040 "Association denied due to requesting station not supporting "
4041 "DSSS-OFDM operation"},
4042 {0x28, "Invalid Information Element"},
4043 {0x29, "Group Cipher is not valid"},
4044 {0x2A, "Pairwise Cipher is not valid"},
4045 {0x2B, "AKMP is not valid"},
4046 {0x2C, "Unsupported RSN IE version"},
4047 {0x2D, "Invalid RSN IE Capabilities"},
4048 {0x2E, "Cipher suite is rejected per security policy"},
4051 static const char *ipw_get_status_code(u16 status)
4054 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
4055 if (ipw_status_codes[i].status == (status & 0xff))
4056 return ipw_status_codes[i].reason;
4057 return "Unknown status value.";
4060 static void inline average_init(struct average *avg)
4062 memset(avg, 0, sizeof(*avg));
4065 #define DEPTH_RSSI 8
4066 #define DEPTH_NOISE 16
4067 static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
4069 return ((depth-1)*prev_avg + val)/depth;
4072 static void average_add(struct average *avg, s16 val)
4074 avg->sum -= avg->entries[avg->pos];
4076 avg->entries[avg->pos++] = val;
4077 if (unlikely(avg->pos == AVG_ENTRIES)) {
4083 static s16 average_value(struct average *avg)
4085 if (!unlikely(avg->init)) {
4087 return avg->sum / avg->pos;
4091 return avg->sum / AVG_ENTRIES;
4094 static void ipw_reset_stats(struct ipw_priv *priv)
4096 u32 len = sizeof(u32);
4100 average_init(&priv->average_missed_beacons);
4101 priv->exp_avg_rssi = -60;
4102 priv->exp_avg_noise = -85 + 0x100;
4104 priv->last_rate = 0;
4105 priv->last_missed_beacons = 0;
4106 priv->last_rx_packets = 0;
4107 priv->last_tx_packets = 0;
4108 priv->last_tx_failures = 0;
4110 /* Firmware managed, reset only when NIC is restarted, so we have to
4111 * normalize on the current value */
4112 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
4113 &priv->last_rx_err, &len);
4114 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
4115 &priv->last_tx_failures, &len);
4117 /* Driver managed, reset with each association */
4118 priv->missed_adhoc_beacons = 0;
4119 priv->missed_beacons = 0;
4120 priv->tx_packets = 0;
4121 priv->rx_packets = 0;
4125 static u32 ipw_get_max_rate(struct ipw_priv *priv)
4128 u32 mask = priv->rates_mask;
4129 /* If currently associated in B mode, restrict the maximum
4130 * rate match to B rates */
4131 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
4132 mask &= LIBIPW_CCK_RATES_MASK;
4134 /* TODO: Verify that the rate is supported by the current rates
4137 while (i && !(mask & i))
4140 case LIBIPW_CCK_RATE_1MB_MASK:
4142 case LIBIPW_CCK_RATE_2MB_MASK:
4144 case LIBIPW_CCK_RATE_5MB_MASK:
4146 case LIBIPW_OFDM_RATE_6MB_MASK:
4148 case LIBIPW_OFDM_RATE_9MB_MASK:
4150 case LIBIPW_CCK_RATE_11MB_MASK:
4152 case LIBIPW_OFDM_RATE_12MB_MASK:
4154 case LIBIPW_OFDM_RATE_18MB_MASK:
4156 case LIBIPW_OFDM_RATE_24MB_MASK:
4158 case LIBIPW_OFDM_RATE_36MB_MASK:
4160 case LIBIPW_OFDM_RATE_48MB_MASK:
4162 case LIBIPW_OFDM_RATE_54MB_MASK:
4166 if (priv->ieee->mode == IEEE_B)
4172 static u32 ipw_get_current_rate(struct ipw_priv *priv)
4174 u32 rate, len = sizeof(rate);
4177 if (!(priv->status & STATUS_ASSOCIATED))
4180 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
4181 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
4184 IPW_DEBUG_INFO("failed querying ordinals.\n");
4188 return ipw_get_max_rate(priv);
4191 case IPW_TX_RATE_1MB:
4193 case IPW_TX_RATE_2MB:
4195 case IPW_TX_RATE_5MB:
4197 case IPW_TX_RATE_6MB:
4199 case IPW_TX_RATE_9MB:
4201 case IPW_TX_RATE_11MB:
4203 case IPW_TX_RATE_12MB:
4205 case IPW_TX_RATE_18MB:
4207 case IPW_TX_RATE_24MB:
4209 case IPW_TX_RATE_36MB:
4211 case IPW_TX_RATE_48MB:
4213 case IPW_TX_RATE_54MB:
4220 #define IPW_STATS_INTERVAL (2 * HZ)
4221 static void ipw_gather_stats(struct ipw_priv *priv)
4223 u32 rx_err, rx_err_delta, rx_packets_delta;
4224 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4225 u32 missed_beacons_percent, missed_beacons_delta;
4227 u32 len = sizeof(u32);
4229 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
4233 if (!(priv->status & STATUS_ASSOCIATED)) {
4238 /* Update the statistics */
4239 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
4240 &priv->missed_beacons, &len);
4241 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
4242 priv->last_missed_beacons = priv->missed_beacons;
4243 if (priv->assoc_request.beacon_interval) {
4244 missed_beacons_percent = missed_beacons_delta *
4245 (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) /
4246 (IPW_STATS_INTERVAL * 10);
4248 missed_beacons_percent = 0;
4250 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4252 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4253 rx_err_delta = rx_err - priv->last_rx_err;
4254 priv->last_rx_err = rx_err;
4256 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4257 tx_failures_delta = tx_failures - priv->last_tx_failures;
4258 priv->last_tx_failures = tx_failures;
4260 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4261 priv->last_rx_packets = priv->rx_packets;
4263 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4264 priv->last_tx_packets = priv->tx_packets;
4266 /* Calculate quality based on the following:
4268 * Missed beacon: 100% = 0, 0% = 70% missed
4269 * Rate: 60% = 1Mbs, 100% = Max
4270 * Rx and Tx errors represent a straight % of total Rx/Tx
4271 * RSSI: 100% = > -50, 0% = < -80
4272 * Rx errors: 100% = 0, 0% = 50% missed
4274 * The lowest computed quality is used.
4277 #define BEACON_THRESHOLD 5
4278 beacon_quality = 100 - missed_beacons_percent;
4279 if (beacon_quality < BEACON_THRESHOLD)
4282 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
4283 (100 - BEACON_THRESHOLD);
4284 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
4285 beacon_quality, missed_beacons_percent);
4287 priv->last_rate = ipw_get_current_rate(priv);
4288 max_rate = ipw_get_max_rate(priv);
4289 rate_quality = priv->last_rate * 40 / max_rate + 60;
4290 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4291 rate_quality, priv->last_rate / 1000000);
4293 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
4294 rx_quality = 100 - (rx_err_delta * 100) /
4295 (rx_packets_delta + rx_err_delta);
4298 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4299 rx_quality, rx_err_delta, rx_packets_delta);
4301 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
4302 tx_quality = 100 - (tx_failures_delta * 100) /
4303 (tx_packets_delta + tx_failures_delta);
4306 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4307 tx_quality, tx_failures_delta, tx_packets_delta);
4309 rssi = priv->exp_avg_rssi;
4312 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4313 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4314 (priv->ieee->perfect_rssi - rssi) *
4315 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4316 62 * (priv->ieee->perfect_rssi - rssi))) /
4317 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4318 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4319 if (signal_quality > 100)
4320 signal_quality = 100;
4321 else if (signal_quality < 1)
4324 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
4325 signal_quality, rssi);
4327 quality = min(rx_quality, signal_quality);
4328 quality = min(tx_quality, quality);
4329 quality = min(rate_quality, quality);
4330 quality = min(beacon_quality, quality);
4331 if (quality == beacon_quality)
4332 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4334 if (quality == rate_quality)
4335 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4337 if (quality == tx_quality)
4338 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4340 if (quality == rx_quality)
4341 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4343 if (quality == signal_quality)
4344 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4347 priv->quality = quality;
4349 queue_delayed_work(priv->workqueue, &priv->gather_stats,
4350 IPW_STATS_INTERVAL);
4353 static void ipw_bg_gather_stats(struct work_struct *work)
4355 struct ipw_priv *priv =
4356 container_of(work, struct ipw_priv, gather_stats.work);
4357 mutex_lock(&priv->mutex);
4358 ipw_gather_stats(priv);
4359 mutex_unlock(&priv->mutex);
4362 /* Missed beacon behavior:
4363 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4364 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4365 * Above disassociate threshold, give up and stop scanning.
4366 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
4367 static void ipw_handle_missed_beacon(struct ipw_priv *priv,
4370 priv->notif_missed_beacons = missed_count;
4372 if (missed_count > priv->disassociate_threshold &&
4373 priv->status & STATUS_ASSOCIATED) {
4374 /* If associated and we've hit the missed
4375 * beacon threshold, disassociate, turn
4376 * off roaming, and abort any active scans */
4377 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4378 IPW_DL_STATE | IPW_DL_ASSOC,
4379 "Missed beacon: %d - disassociate\n", missed_count);
4380 priv->status &= ~STATUS_ROAMING;
4381 if (priv->status & STATUS_SCANNING) {
4382 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4384 "Aborting scan with missed beacon.\n");
4385 queue_work(priv->workqueue, &priv->abort_scan);
4388 queue_work(priv->workqueue, &priv->disassociate);
4392 if (priv->status & STATUS_ROAMING) {
4393 /* If we are currently roaming, then just
4394 * print a debug statement... */
4395 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4396 "Missed beacon: %d - roam in progress\n",
4402 (missed_count > priv->roaming_threshold &&
4403 missed_count <= priv->disassociate_threshold)) {
4404 /* If we are not already roaming, set the ROAM
4405 * bit in the status and kick off a scan.
4406 * This can happen several times before we reach
4407 * disassociate_threshold. */
4408 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4409 "Missed beacon: %d - initiate "
4410 "roaming\n", missed_count);
4411 if (!(priv->status & STATUS_ROAMING)) {
4412 priv->status |= STATUS_ROAMING;
4413 if (!(priv->status & STATUS_SCANNING))
4414 queue_delayed_work(priv->workqueue,
4415 &priv->request_scan, 0);
4420 if (priv->status & STATUS_SCANNING &&
4421 missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) {
4422 /* Stop scan to keep fw from getting
4423 * stuck (only if we aren't roaming --
4424 * otherwise we'll never scan more than 2 or 3
4426 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4427 "Aborting scan with missed beacon.\n");
4428 queue_work(priv->workqueue, &priv->abort_scan);
4431 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
4434 static void ipw_scan_event(struct work_struct *work)
4436 union iwreq_data wrqu;
4438 struct ipw_priv *priv =
4439 container_of(work, struct ipw_priv, scan_event.work);
4441 wrqu.data.length = 0;
4442 wrqu.data.flags = 0;
4443 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4446 static void handle_scan_event(struct ipw_priv *priv)
4448 /* Only userspace-requested scan completion events go out immediately */
4449 if (!priv->user_requested_scan) {
4450 if (!delayed_work_pending(&priv->scan_event))
4451 queue_delayed_work(priv->workqueue, &priv->scan_event,
4452 round_jiffies_relative(msecs_to_jiffies(4000)));
4454 union iwreq_data wrqu;
4456 priv->user_requested_scan = 0;
4457 cancel_delayed_work(&priv->scan_event);
4459 wrqu.data.length = 0;
4460 wrqu.data.flags = 0;
4461 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4466 * Handle host notification packet.
4467 * Called from interrupt routine
4469 static void ipw_rx_notification(struct ipw_priv *priv,
4470 struct ipw_rx_notification *notif)
4472 DECLARE_SSID_BUF(ssid);
4473 u16 size = le16_to_cpu(notif->size);
4475 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size);
4477 switch (notif->subtype) {
4478 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4479 struct notif_association *assoc = ¬if->u.assoc;
4481 switch (assoc->state) {
4482 case CMAS_ASSOCIATED:{
4483 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4485 "associated: '%s' %pM \n",
4486 print_ssid(ssid, priv->essid,
4490 switch (priv->ieee->iw_mode) {
4492 memcpy(priv->ieee->bssid,
4493 priv->bssid, ETH_ALEN);
4497 memcpy(priv->ieee->bssid,
4498 priv->bssid, ETH_ALEN);
4500 /* clear out the station table */
4501 priv->num_stations = 0;
4504 ("queueing adhoc check\n");
4505 queue_delayed_work(priv->
4515 priv->status &= ~STATUS_ASSOCIATING;
4516 priv->status |= STATUS_ASSOCIATED;
4517 queue_work(priv->workqueue,
4518 &priv->system_config);
4520 #ifdef CONFIG_IPW2200_QOS
4521 #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4522 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control))
4523 if ((priv->status & STATUS_AUTH) &&
4524 (IPW_GET_PACKET_STYPE(¬if->u.raw)
4525 == IEEE80211_STYPE_ASSOC_RESP)) {
4528 libipw_assoc_response)
4530 && (size <= 2314)) {
4540 libipw_rx_mgt(priv->
4545 ¬if->u.raw, &stats);
4550 schedule_work(&priv->link_up);
4555 case CMAS_AUTHENTICATED:{
4557 status & (STATUS_ASSOCIATED |
4559 struct notif_authenticate *auth
4561 IPW_DEBUG(IPW_DL_NOTIF |
4564 "deauthenticated: '%s' "
4566 ": (0x%04X) - %s \n",
4573 le16_to_cpu(auth->status),
4579 ~(STATUS_ASSOCIATING |
4583 schedule_work(&priv->link_down);
4587 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4589 "authenticated: '%s' %pM\n",
4590 print_ssid(ssid, priv->essid,
4597 if (priv->status & STATUS_AUTH) {
4599 libipw_assoc_response
4603 libipw_assoc_response
4605 IPW_DEBUG(IPW_DL_NOTIF |
4608 "association failed (0x%04X): %s\n",
4609 le16_to_cpu(resp->status),
4615 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4617 "disassociated: '%s' %pM \n",
4618 print_ssid(ssid, priv->essid,
4623 ~(STATUS_DISASSOCIATING |
4624 STATUS_ASSOCIATING |
4625 STATUS_ASSOCIATED | STATUS_AUTH);
4626 if (priv->assoc_network
4627 && (priv->assoc_network->
4629 WLAN_CAPABILITY_IBSS))
4630 ipw_remove_current_network
4633 schedule_work(&priv->link_down);
4638 case CMAS_RX_ASSOC_RESP:
4642 IPW_ERROR("assoc: unknown (%d)\n",
4650 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4651 struct notif_authenticate *auth = ¬if->u.auth;
4652 switch (auth->state) {
4653 case CMAS_AUTHENTICATED:
4654 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4655 "authenticated: '%s' %pM \n",
4656 print_ssid(ssid, priv->essid,
4659 priv->status |= STATUS_AUTH;
4663 if (priv->status & STATUS_AUTH) {
4664 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4666 "authentication failed (0x%04X): %s\n",
4667 le16_to_cpu(auth->status),
4668 ipw_get_status_code(le16_to_cpu
4672 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4674 "deauthenticated: '%s' %pM\n",
4675 print_ssid(ssid, priv->essid,
4679 priv->status &= ~(STATUS_ASSOCIATING |
4683 schedule_work(&priv->link_down);
4686 case CMAS_TX_AUTH_SEQ_1:
4687 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4688 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4690 case CMAS_RX_AUTH_SEQ_2:
4691 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4692 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4694 case CMAS_AUTH_SEQ_1_PASS:
4695 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4696 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4698 case CMAS_AUTH_SEQ_1_FAIL:
4699 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4700 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4702 case CMAS_TX_AUTH_SEQ_3:
4703 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4704 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4706 case CMAS_RX_AUTH_SEQ_4:
4707 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4708 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4710 case CMAS_AUTH_SEQ_2_PASS:
4711 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4712 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4714 case CMAS_AUTH_SEQ_2_FAIL:
4715 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4716 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4719 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4720 IPW_DL_ASSOC, "TX_ASSOC\n");
4722 case CMAS_RX_ASSOC_RESP:
4723 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4724 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
4727 case CMAS_ASSOCIATED:
4728 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4729 IPW_DL_ASSOC, "ASSOCIATED\n");
4732 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4739 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4740 struct notif_channel_result *x =
4741 ¬if->u.channel_result;
4743 if (size == sizeof(*x)) {
4744 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4747 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4748 "(should be %zd)\n",
4754 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4755 struct notif_scan_complete *x = ¬if->u.scan_complete;
4756 if (size == sizeof(*x)) {
4758 ("Scan completed: type %d, %d channels, "
4759 "%d status\n", x->scan_type,
4760 x->num_channels, x->status);
4762 IPW_ERROR("Scan completed of wrong size %d "
4763 "(should be %zd)\n",
4768 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4770 wake_up_interruptible(&priv->wait_state);
4771 cancel_delayed_work(&priv->scan_check);
4773 if (priv->status & STATUS_EXIT_PENDING)
4776 priv->ieee->scans++;
4778 #ifdef CONFIG_IPW2200_MONITOR
4779 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
4780 priv->status |= STATUS_SCAN_FORCED;
4781 queue_delayed_work(priv->workqueue,
4782 &priv->request_scan, 0);
4785 priv->status &= ~STATUS_SCAN_FORCED;
4786 #endif /* CONFIG_IPW2200_MONITOR */
4788 /* Do queued direct scans first */
4789 if (priv->status & STATUS_DIRECT_SCAN_PENDING) {
4790 queue_delayed_work(priv->workqueue,
4791 &priv->request_direct_scan, 0);
4794 if (!(priv->status & (STATUS_ASSOCIATED |
4795 STATUS_ASSOCIATING |
4797 STATUS_DISASSOCIATING)))
4798 queue_work(priv->workqueue, &priv->associate);
4799 else if (priv->status & STATUS_ROAMING) {
4800 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4801 /* If a scan completed and we are in roam mode, then
4802 * the scan that completed was the one requested as a
4803 * result of entering roam... so, schedule the
4805 queue_work(priv->workqueue,
4808 /* Don't schedule if we aborted the scan */
4809 priv->status &= ~STATUS_ROAMING;
4810 } else if (priv->status & STATUS_SCAN_PENDING)
4811 queue_delayed_work(priv->workqueue,
4812 &priv->request_scan, 0);
4813 else if (priv->config & CFG_BACKGROUND_SCAN
4814 && priv->status & STATUS_ASSOCIATED)
4815 queue_delayed_work(priv->workqueue,
4816 &priv->request_scan,
4817 round_jiffies_relative(HZ));
4819 /* Send an empty event to user space.
4820 * We don't send the received data on the event because
4821 * it would require us to do complex transcoding, and
4822 * we want to minimise the work done in the irq handler
4823 * Use a request to extract the data.
4824 * Also, we generate this even for any scan, regardless
4825 * on how the scan was initiated. User space can just
4826 * sync on periodic scan to get fresh data...
4828 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4829 handle_scan_event(priv);
4833 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4834 struct notif_frag_length *x = ¬if->u.frag_len;
4836 if (size == sizeof(*x))
4837 IPW_ERROR("Frag length: %d\n",
4838 le16_to_cpu(x->frag_length));
4840 IPW_ERROR("Frag length of wrong size %d "
4841 "(should be %zd)\n",
4846 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4847 struct notif_link_deterioration *x =
4848 ¬if->u.link_deterioration;
4850 if (size == sizeof(*x)) {
4851 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4852 "link deterioration: type %d, cnt %d\n",
4853 x->silence_notification_type,
4855 memcpy(&priv->last_link_deterioration, x,
4858 IPW_ERROR("Link Deterioration of wrong size %d "
4859 "(should be %zd)\n",
4865 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4866 IPW_ERROR("Dino config\n");
4868 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
4869 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
4874 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4875 struct notif_beacon_state *x = ¬if->u.beacon_state;
4876 if (size != sizeof(*x)) {
4878 ("Beacon state of wrong size %d (should "
4879 "be %zd)\n", size, sizeof(*x));
4883 if (le32_to_cpu(x->state) ==
4884 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4885 ipw_handle_missed_beacon(priv,
4892 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4893 struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key;
4894 if (size == sizeof(*x)) {
4895 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4896 "0x%02x station %d\n",
4897 x->key_state, x->security_type,
4903 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4908 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4909 struct notif_calibration *x = ¬if->u.calibration;
4911 if (size == sizeof(*x)) {
4912 memcpy(&priv->calib, x, sizeof(*x));
4913 IPW_DEBUG_INFO("TODO: Calibration\n");
4918 ("Calibration of wrong size %d (should be %zd)\n",
4923 case HOST_NOTIFICATION_NOISE_STATS:{
4924 if (size == sizeof(u32)) {
4925 priv->exp_avg_noise =
4926 exponential_average(priv->exp_avg_noise,
4927 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4933 ("Noise stat is wrong size %d (should be %zd)\n",
4939 IPW_DEBUG_NOTIF("Unknown notification: "
4940 "subtype=%d,flags=0x%2x,size=%d\n",
4941 notif->subtype, notif->flags, size);
4946 * Destroys all DMA structures and initialise them again
4949 * @return error code
4951 static int ipw_queue_reset(struct ipw_priv *priv)
4954 /** @todo customize queue sizes */
4955 int nTx = 64, nTxCmd = 8;
4956 ipw_tx_queue_free(priv);
4958 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
4959 IPW_TX_CMD_QUEUE_READ_INDEX,
4960 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4961 IPW_TX_CMD_QUEUE_BD_BASE,
4962 IPW_TX_CMD_QUEUE_BD_SIZE);
4964 IPW_ERROR("Tx Cmd queue init failed\n");
4968 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
4969 IPW_TX_QUEUE_0_READ_INDEX,
4970 IPW_TX_QUEUE_0_WRITE_INDEX,
4971 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
4973 IPW_ERROR("Tx 0 queue init failed\n");
4976 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
4977 IPW_TX_QUEUE_1_READ_INDEX,
4978 IPW_TX_QUEUE_1_WRITE_INDEX,
4979 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
4981 IPW_ERROR("Tx 1 queue init failed\n");
4984 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
4985 IPW_TX_QUEUE_2_READ_INDEX,
4986 IPW_TX_QUEUE_2_WRITE_INDEX,
4987 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
4989 IPW_ERROR("Tx 2 queue init failed\n");
4992 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
4993 IPW_TX_QUEUE_3_READ_INDEX,
4994 IPW_TX_QUEUE_3_WRITE_INDEX,
4995 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
4997 IPW_ERROR("Tx 3 queue init failed\n");
5001 priv->rx_bufs_min = 0;
5002 priv->rx_pend_max = 0;
5006 ipw_tx_queue_free(priv);
5011 * Reclaim Tx queue entries no more used by NIC.
5013 * When FW advances 'R' index, all entries between old and
5014 * new 'R' index need to be reclaimed. As result, some free space
5015 * forms. If there is enough free space (> low mark), wake Tx queue.
5017 * @note Need to protect against garbage in 'R' index
5021 * @return Number of used entries remains in the queue
5023 static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
5024 struct clx2_tx_queue *txq, int qindex)
5028 struct clx2_queue *q = &txq->q;
5030 hw_tail = ipw_read32(priv, q->reg_r);
5031 if (hw_tail >= q->n_bd) {
5033 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
5037 for (; q->last_used != hw_tail;
5038 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
5039 ipw_queue_tx_free_tfd(priv, txq);
5043 if ((ipw_tx_queue_space(q) > q->low_mark) &&
5045 netif_wake_queue(priv->net_dev);
5046 used = q->first_empty - q->last_used;
5053 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
5056 struct clx2_tx_queue *txq = &priv->txq_cmd;
5057 struct clx2_queue *q = &txq->q;
5058 struct tfd_frame *tfd;
5060 if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) {
5061 IPW_ERROR("No space for Tx\n");
5065 tfd = &txq->bd[q->first_empty];
5066 txq->txb[q->first_empty] = NULL;
5068 memset(tfd, 0, sizeof(*tfd));
5069 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
5070 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
5072 tfd->u.cmd.index = hcmd;
5073 tfd->u.cmd.length = len;
5074 memcpy(tfd->u.cmd.payload, buf, len);
5075 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
5076 ipw_write32(priv, q->reg_w, q->first_empty);
5077 _ipw_read32(priv, 0x90);
5083 * Rx theory of operation
5085 * The host allocates 32 DMA target addresses and passes the host address
5086 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
5090 * The host/firmware share two index registers for managing the Rx buffers.
5092 * The READ index maps to the first position that the firmware may be writing
5093 * to -- the driver can read up to (but not including) this position and get
5095 * The READ index is managed by the firmware once the card is enabled.
5097 * The WRITE index maps to the last position the driver has read from -- the
5098 * position preceding WRITE is the last slot the firmware can place a packet.
5100 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
5103 * During initialization the host sets up the READ queue position to the first
5104 * INDEX position, and WRITE to the last (READ - 1 wrapped)
5106 * When the firmware places a packet in a buffer it will advance the READ index
5107 * and fire the RX interrupt. The driver can then query the READ index and
5108 * process as many packets as possible, moving the WRITE index forward as it
5109 * resets the Rx queue buffers with new memory.
5111 * The management in the driver is as follows:
5112 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
5113 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
5114 * to replensish the ipw->rxq->rx_free.
5115 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
5116 * ipw->rxq is replenished and the READ INDEX is updated (updating the
5117 * 'processed' and 'read' driver indexes as well)
5118 * + A received packet is processed and handed to the kernel network stack,
5119 * detached from the ipw->rxq. The driver 'processed' index is updated.
5120 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
5121 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
5122 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
5123 * were enough free buffers and RX_STALLED is set it is cleared.
5128 * ipw_rx_queue_alloc() Allocates rx_free
5129 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
5130 * ipw_rx_queue_restock
5131 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
5132 * queue, updates firmware pointers, and updates
5133 * the WRITE index. If insufficient rx_free buffers
5134 * are available, schedules ipw_rx_queue_replenish
5136 * -- enable interrupts --
5137 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
5138 * READ INDEX, detaching the SKB from the pool.
5139 * Moves the packet buffer from queue to rx_used.
5140 * Calls ipw_rx_queue_restock to refill any empty
5147 * If there are slots in the RX queue that need to be restocked,
5148 * and we have free pre-allocated buffers, fill the ranks as much
5149 * as we can pulling from rx_free.
5151 * This moves the 'write' index forward to catch up with 'processed', and
5152 * also updates the memory address in the firmware to reference the new
5155 static void ipw_rx_queue_restock(struct ipw_priv *priv)
5157 struct ipw_rx_queue *rxq = priv->rxq;
5158 struct list_head *element;
5159 struct ipw_rx_mem_buffer *rxb;
5160 unsigned long flags;
5163 spin_lock_irqsave(&rxq->lock, flags);
5165 while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
5166 element = rxq->rx_free.next;
5167 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5170 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
5172 rxq->queue[rxq->write] = rxb;
5173 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5176 spin_unlock_irqrestore(&rxq->lock, flags);
5178 /* If the pre-allocated buffer pool is dropping low, schedule to
5180 if (rxq->free_count <= RX_LOW_WATERMARK)
5181 queue_work(priv->workqueue, &priv->rx_replenish);
5183 /* If we've added more space for the firmware to place data, tell it */
5184 if (write != rxq->write)
5185 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
5189 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
5190 * Also restock the Rx queue via ipw_rx_queue_restock.
5192 * This is called as a scheduled work item (except for during intialization)
5194 static void ipw_rx_queue_replenish(void *data)
5196 struct ipw_priv *priv = data;
5197 struct ipw_rx_queue *rxq = priv->rxq;
5198 struct list_head *element;
5199 struct ipw_rx_mem_buffer *rxb;
5200 unsigned long flags;
5202 spin_lock_irqsave(&rxq->lock, flags);
5203 while (!list_empty(&rxq->rx_used)) {
5204 element = rxq->rx_used.next;
5205 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5206 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
5208 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5209 priv->net_dev->name);
5210 /* We don't reschedule replenish work here -- we will
5211 * call the restock method and if it still needs
5212 * more buffers it will schedule replenish */
5218 pci_map_single(priv->pci_dev, rxb->skb->data,
5219 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
5221 list_add_tail(&rxb->list, &rxq->rx_free);
5224 spin_unlock_irqrestore(&rxq->lock, flags);
5226 ipw_rx_queue_restock(priv);
5229 static void ipw_bg_rx_queue_replenish(struct work_struct *work)
5231 struct ipw_priv *priv =
5232 container_of(work, struct ipw_priv, rx_replenish);
5233 mutex_lock(&priv->mutex);
5234 ipw_rx_queue_replenish(priv);
5235 mutex_unlock(&priv->mutex);
5238 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
5239 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
5240 * This free routine walks the list of POOL entries and if SKB is set to
5241 * non NULL it is unmapped and freed
5243 static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
5250 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5251 if (rxq->pool[i].skb != NULL) {
5252 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
5253 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
5254 dev_kfree_skb(rxq->pool[i].skb);
5261 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5263 struct ipw_rx_queue *rxq;
5266 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
5267 if (unlikely(!rxq)) {
5268 IPW_ERROR("memory allocation failed\n");
5271 spin_lock_init(&rxq->lock);
5272 INIT_LIST_HEAD(&rxq->rx_free);
5273 INIT_LIST_HEAD(&rxq->rx_used);
5275 /* Fill the rx_used queue with _all_ of the Rx buffers */
5276 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
5277 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5279 /* Set us so that we have processed and used all buffers, but have
5280 * not restocked the Rx queue with fresh buffers */
5281 rxq->read = rxq->write = 0;
5282 rxq->free_count = 0;
5287 static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5289 rate &= ~LIBIPW_BASIC_RATE_MASK;
5290 if (ieee_mode == IEEE_A) {
5292 case LIBIPW_OFDM_RATE_6MB:
5293 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ?
5295 case LIBIPW_OFDM_RATE_9MB:
5296 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ?
5298 case LIBIPW_OFDM_RATE_12MB:
5300 rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5301 case LIBIPW_OFDM_RATE_18MB:
5303 rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5304 case LIBIPW_OFDM_RATE_24MB:
5306 rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5307 case LIBIPW_OFDM_RATE_36MB:
5309 rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5310 case LIBIPW_OFDM_RATE_48MB:
5312 rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5313 case LIBIPW_OFDM_RATE_54MB:
5315 rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
5323 case LIBIPW_CCK_RATE_1MB:
5324 return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0;
5325 case LIBIPW_CCK_RATE_2MB:
5326 return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0;
5327 case LIBIPW_CCK_RATE_5MB:
5328 return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0;
5329 case LIBIPW_CCK_RATE_11MB:
5330 return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0;
5333 /* If we are limited to B modulations, bail at this point */
5334 if (ieee_mode == IEEE_B)
5339 case LIBIPW_OFDM_RATE_6MB:
5340 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0;
5341 case LIBIPW_OFDM_RATE_9MB:
5342 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0;
5343 case LIBIPW_OFDM_RATE_12MB:
5344 return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5345 case LIBIPW_OFDM_RATE_18MB:
5346 return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5347 case LIBIPW_OFDM_RATE_24MB:
5348 return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5349 case LIBIPW_OFDM_RATE_36MB:
5350 return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5351 case LIBIPW_OFDM_RATE_48MB:
5352 return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5353 case LIBIPW_OFDM_RATE_54MB:
5354 return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
5360 static int ipw_compatible_rates(struct ipw_priv *priv,
5361 const struct libipw_network *network,
5362 struct ipw_supported_rates *rates)
5366 memset(rates, 0, sizeof(*rates));
5367 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
5368 rates->num_rates = 0;
5369 for (i = 0; i < num_rates; i++) {
5370 if (!ipw_is_rate_in_mask(priv, network->mode,
5371 network->rates[i])) {
5373 if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) {
5374 IPW_DEBUG_SCAN("Adding masked mandatory "
5377 rates->supported_rates[rates->num_rates++] =
5382 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5383 network->rates[i], priv->rates_mask);
5387 rates->supported_rates[rates->num_rates++] = network->rates[i];
5390 num_rates = min(network->rates_ex_len,
5391 (u8) (IPW_MAX_RATES - num_rates));
5392 for (i = 0; i < num_rates; i++) {
5393 if (!ipw_is_rate_in_mask(priv, network->mode,
5394 network->rates_ex[i])) {
5395 if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) {
5396 IPW_DEBUG_SCAN("Adding masked mandatory "
5398 network->rates_ex[i]);
5399 rates->supported_rates[rates->num_rates++] =
5404 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5405 network->rates_ex[i], priv->rates_mask);
5409 rates->supported_rates[rates->num_rates++] =
5410 network->rates_ex[i];
5416 static void ipw_copy_rates(struct ipw_supported_rates *dest,
5417 const struct ipw_supported_rates *src)
5420 for (i = 0; i < src->num_rates; i++)
5421 dest->supported_rates[i] = src->supported_rates[i];
5422 dest->num_rates = src->num_rates;
5425 /* TODO: Look at sniffed packets in the air to determine if the basic rate
5426 * mask should ever be used -- right now all callers to add the scan rates are
5427 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5428 static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
5429 u8 modulation, u32 rate_mask)
5431 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5432 LIBIPW_BASIC_RATE_MASK : 0;
5434 if (rate_mask & LIBIPW_CCK_RATE_1MB_MASK)
5435 rates->supported_rates[rates->num_rates++] =
5436 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB;
5438 if (rate_mask & LIBIPW_CCK_RATE_2MB_MASK)
5439 rates->supported_rates[rates->num_rates++] =
5440 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB;
5442 if (rate_mask & LIBIPW_CCK_RATE_5MB_MASK)
5443 rates->supported_rates[rates->num_rates++] = basic_mask |
5444 LIBIPW_CCK_RATE_5MB;
5446 if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK)
5447 rates->supported_rates[rates->num_rates++] = basic_mask |
5448 LIBIPW_CCK_RATE_11MB;
5451 static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
5452 u8 modulation, u32 rate_mask)
5454 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5455 LIBIPW_BASIC_RATE_MASK : 0;
5457 if (rate_mask & LIBIPW_OFDM_RATE_6MB_MASK)
5458 rates->supported_rates[rates->num_rates++] = basic_mask |
5459 LIBIPW_OFDM_RATE_6MB;
5461 if (rate_mask & LIBIPW_OFDM_RATE_9MB_MASK)
5462 rates->supported_rates[rates->num_rates++] =
5463 LIBIPW_OFDM_RATE_9MB;
5465 if (rate_mask & LIBIPW_OFDM_RATE_12MB_MASK)
5466 rates->supported_rates[rates->num_rates++] = basic_mask |
5467 LIBIPW_OFDM_RATE_12MB;
5469 if (rate_mask & LIBIPW_OFDM_RATE_18MB_MASK)
5470 rates->supported_rates[rates->num_rates++] =
5471 LIBIPW_OFDM_RATE_18MB;
5473 if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK)
5474 rates->supported_rates[rates->num_rates++] = basic_mask |
5475 LIBIPW_OFDM_RATE_24MB;
5477 if (rate_mask & LIBIPW_OFDM_RATE_36MB_MASK)
5478 rates->supported_rates[rates->num_rates++] =
5479 LIBIPW_OFDM_RATE_36MB;
5481 if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK)
5482 rates->supported_rates[rates->num_rates++] =
5483 LIBIPW_OFDM_RATE_48MB;
5485 if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK)
5486 rates->supported_rates[rates->num_rates++] =
5487 LIBIPW_OFDM_RATE_54MB;
5490 struct ipw_network_match {
5491 struct libipw_network *network;
5492 struct ipw_supported_rates rates;
5495 static int ipw_find_adhoc_network(struct ipw_priv *priv,
5496 struct ipw_network_match *match,
5497 struct libipw_network *network,
5500 struct ipw_supported_rates rates;
5501 DECLARE_SSID_BUF(ssid);
5503 /* Verify that this network's capability is compatible with the
5504 * current mode (AdHoc or Infrastructure) */
5505 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5506 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5507 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded due to "
5508 "capability mismatch.\n",
5509 print_ssid(ssid, network->ssid,
5515 if (unlikely(roaming)) {
5516 /* If we are roaming, then ensure check if this is a valid
5517 * network to try and roam to */
5518 if ((network->ssid_len != match->network->ssid_len) ||
5519 memcmp(network->ssid, match->network->ssid,
5520 network->ssid_len)) {
5521 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5522 "because of non-network ESSID.\n",
5523 print_ssid(ssid, network->ssid,
5529 /* If an ESSID has been configured then compare the broadcast
5531 if ((priv->config & CFG_STATIC_ESSID) &&
5532 ((network->ssid_len != priv->essid_len) ||
5533 memcmp(network->ssid, priv->essid,
5534 min(network->ssid_len, priv->essid_len)))) {
5535 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5538 print_ssid(ssid, network->ssid,
5541 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5542 "because of ESSID mismatch: '%s'.\n",
5543 escaped, network->bssid,
5544 print_ssid(ssid, priv->essid,
5550 /* If the old network rate is better than this one, don't bother
5551 * testing everything else. */
5553 if (network->time_stamp[0] < match->network->time_stamp[0]) {
5554 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5555 "current network.\n",
5556 print_ssid(ssid, match->network->ssid,
5557 match->network->ssid_len));
5559 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
5560 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5561 "current network.\n",
5562 print_ssid(ssid, match->network->ssid,
5563 match->network->ssid_len));
5567 /* Now go through and see if the requested network is valid... */
5568 if (priv->ieee->scan_age != 0 &&
5569 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5570 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5571 "because of age: %ums.\n",
5572 print_ssid(ssid, network->ssid,
5575 jiffies_to_msecs(jiffies -
5576 network->last_scanned));
5580 if ((priv->config & CFG_STATIC_CHANNEL) &&
5581 (network->channel != priv->channel)) {
5582 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5583 "because of channel mismatch: %d != %d.\n",
5584 print_ssid(ssid, network->ssid,
5587 network->channel, priv->channel);
5591 /* Verify privacy compatability */
5592 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5593 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5594 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5595 "because of privacy mismatch: %s != %s.\n",
5596 print_ssid(ssid, network->ssid,
5600 capability & CAP_PRIVACY_ON ? "on" : "off",
5602 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5607 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5608 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5609 "because of the same BSSID match: %pM"
5610 ".\n", print_ssid(ssid, network->ssid,
5617 /* Filter out any incompatible freq / mode combinations */
5618 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
5619 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5620 "because of invalid frequency/mode "
5622 print_ssid(ssid, network->ssid,
5628 /* Ensure that the rates supported by the driver are compatible with
5629 * this AP, including verification of basic rates (mandatory) */
5630 if (!ipw_compatible_rates(priv, network, &rates)) {
5631 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5632 "because configured rate mask excludes "
5633 "AP mandatory rate.\n",
5634 print_ssid(ssid, network->ssid,
5640 if (rates.num_rates == 0) {
5641 IPW_DEBUG_MERGE("Network '%s (%pM)' excluded "
5642 "because of no compatible rates.\n",
5643 print_ssid(ssid, network->ssid,
5649 /* TODO: Perform any further minimal comparititive tests. We do not
5650 * want to put too much policy logic here; intelligent scan selection
5651 * should occur within a generic IEEE 802.11 user space tool. */
5653 /* Set up 'new' AP to this network */
5654 ipw_copy_rates(&match->rates, &rates);
5655 match->network = network;
5656 IPW_DEBUG_MERGE("Network '%s (%pM)' is a viable match.\n",
5657 print_ssid(ssid, network->ssid, network->ssid_len),
5663 static void ipw_merge_adhoc_network(struct work_struct *work)
5665 DECLARE_SSID_BUF(ssid);
5666 struct ipw_priv *priv =
5667 container_of(work, struct ipw_priv, merge_networks);
5668 struct libipw_network *network = NULL;
5669 struct ipw_network_match match = {
5670 .network = priv->assoc_network
5673 if ((priv->status & STATUS_ASSOCIATED) &&
5674 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5675 /* First pass through ROAM process -- look for a better
5677 unsigned long flags;
5679 spin_lock_irqsave(&priv->ieee->lock, flags);
5680 list_for_each_entry(network, &priv->ieee->network_list, list) {
5681 if (network != priv->assoc_network)
5682 ipw_find_adhoc_network(priv, &match, network,
5685 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5687 if (match.network == priv->assoc_network) {
5688 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5693 mutex_lock(&priv->mutex);
5694 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5695 IPW_DEBUG_MERGE("remove network %s\n",
5696 print_ssid(ssid, priv->essid,
5698 ipw_remove_current_network(priv);
5701 ipw_disassociate(priv);
5702 priv->assoc_network = match.network;
5703 mutex_unlock(&priv->mutex);
5708 static int ipw_best_network(struct ipw_priv *priv,
5709 struct ipw_network_match *match,
5710 struct libipw_network *network, int roaming)
5712 struct ipw_supported_rates rates;
5713 DECLARE_SSID_BUF(ssid);
5715 /* Verify that this network's capability is compatible with the
5716 * current mode (AdHoc or Infrastructure) */
5717 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
5718 !(network->capability & WLAN_CAPABILITY_ESS)) ||
5719 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5720 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5721 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded due to "
5722 "capability mismatch.\n",
5723 print_ssid(ssid, network->ssid,
5729 if (unlikely(roaming)) {
5730 /* If we are roaming, then ensure check if this is a valid
5731 * network to try and roam to */
5732 if ((network->ssid_len != match->network->ssid_len) ||
5733 memcmp(network->ssid, match->network->ssid,
5734 network->ssid_len)) {
5735 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5736 "because of non-network ESSID.\n",
5737 print_ssid(ssid, network->ssid,
5743 /* If an ESSID has been configured then compare the broadcast
5745 if ((priv->config & CFG_STATIC_ESSID) &&
5746 ((network->ssid_len != priv->essid_len) ||
5747 memcmp(network->ssid, priv->essid,
5748 min(network->ssid_len, priv->essid_len)))) {
5749 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5751 print_ssid(ssid, network->ssid,
5754 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5755 "because of ESSID mismatch: '%s'.\n",
5756 escaped, network->bssid,
5757 print_ssid(ssid, priv->essid,
5763 /* If the old network rate is better than this one, don't bother
5764 * testing everything else. */
5765 if (match->network && match->network->stats.rssi > network->stats.rssi) {
5766 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5768 print_ssid(ssid, network->ssid, network->ssid_len),
5770 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded because "
5771 "'%s (%pM)' has a stronger signal.\n",
5772 escaped, network->bssid,
5773 print_ssid(ssid, match->network->ssid,
5774 match->network->ssid_len),
5775 match->network->bssid);
5779 /* If this network has already had an association attempt within the
5780 * last 3 seconds, do not try and associate again... */
5781 if (network->last_associate &&
5782 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
5783 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5784 "because of storming (%ums since last "
5785 "assoc attempt).\n",
5786 print_ssid(ssid, network->ssid,
5789 jiffies_to_msecs(jiffies -
5790 network->last_associate));
5794 /* Now go through and see if the requested network is valid... */
5795 if (priv->ieee->scan_age != 0 &&
5796 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5797 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5798 "because of age: %ums.\n",
5799 print_ssid(ssid, network->ssid,
5802 jiffies_to_msecs(jiffies -
5803 network->last_scanned));
5807 if ((priv->config & CFG_STATIC_CHANNEL) &&
5808 (network->channel != priv->channel)) {
5809 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5810 "because of channel mismatch: %d != %d.\n",
5811 print_ssid(ssid, network->ssid,
5814 network->channel, priv->channel);
5818 /* Verify privacy compatability */
5819 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5820 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5821 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5822 "because of privacy mismatch: %s != %s.\n",
5823 print_ssid(ssid, network->ssid,
5826 priv->capability & CAP_PRIVACY_ON ? "on" :
5828 network->capability &
5829 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
5833 if ((priv->config & CFG_STATIC_BSSID) &&
5834 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5835 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5836 "because of BSSID mismatch: %pM.\n",
5837 print_ssid(ssid, network->ssid,
5839 network->bssid, priv->bssid);
5843 /* Filter out any incompatible freq / mode combinations */
5844 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
5845 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5846 "because of invalid frequency/mode "
5848 print_ssid(ssid, network->ssid,
5854 /* Filter out invalid channel in current GEO */
5855 if (!libipw_is_valid_channel(priv->ieee, network->channel)) {
5856 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5857 "because of invalid channel in current GEO\n",
5858 print_ssid(ssid, network->ssid,
5864 /* Ensure that the rates supported by the driver are compatible with
5865 * this AP, including verification of basic rates (mandatory) */
5866 if (!ipw_compatible_rates(priv, network, &rates)) {
5867 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5868 "because configured rate mask excludes "
5869 "AP mandatory rate.\n",
5870 print_ssid(ssid, network->ssid,
5876 if (rates.num_rates == 0) {
5877 IPW_DEBUG_ASSOC("Network '%s (%pM)' excluded "
5878 "because of no compatible rates.\n",
5879 print_ssid(ssid, network->ssid,
5885 /* TODO: Perform any further minimal comparititive tests. We do not
5886 * want to put too much policy logic here; intelligent scan selection
5887 * should occur within a generic IEEE 802.11 user space tool. */
5889 /* Set up 'new' AP to this network */
5890 ipw_copy_rates(&match->rates, &rates);
5891 match->network = network;
5893 IPW_DEBUG_ASSOC("Network '%s (%pM)' is a viable match.\n",
5894 print_ssid(ssid, network->ssid, network->ssid_len),
5900 static void ipw_adhoc_create(struct ipw_priv *priv,
5901 struct libipw_network *network)
5903 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
5907 * For the purposes of scanning, we can set our wireless mode
5908 * to trigger scans across combinations of bands, but when it
5909 * comes to creating a new ad-hoc network, we have tell the FW
5910 * exactly which band to use.
5912 * We also have the possibility of an invalid channel for the
5913 * chossen band. Attempting to create a new ad-hoc network
5914 * with an invalid channel for wireless mode will trigger a
5918 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
5919 case LIBIPW_52GHZ_BAND:
5920 network->mode = IEEE_A;
5921 i = libipw_channel_to_index(priv->ieee, priv->channel);
5923 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
5924 IPW_WARNING("Overriding invalid channel\n");
5925 priv->channel = geo->a[0].channel;
5929 case LIBIPW_24GHZ_BAND:
5930 if (priv->ieee->mode & IEEE_G)
5931 network->mode = IEEE_G;
5933 network->mode = IEEE_B;
5934 i = libipw_channel_to_index(priv->ieee, priv->channel);
5936 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
5937 IPW_WARNING("Overriding invalid channel\n");
5938 priv->channel = geo->bg[0].channel;
5943 IPW_WARNING("Overriding invalid channel\n");
5944 if (priv->ieee->mode & IEEE_A) {
5945 network->mode = IEEE_A;
5946 priv->channel = geo->a[0].channel;
5947 } else if (priv->ieee->mode & IEEE_G) {
5948 network->mode = IEEE_G;
5949 priv->channel = geo->bg[0].channel;
5951 network->mode = IEEE_B;
5952 priv->channel = geo->bg[0].channel;
5957 network->channel = priv->channel;
5958 priv->config |= CFG_ADHOC_PERSIST;
5959 ipw_create_bssid(priv, network->bssid);
5960 network->ssid_len = priv->essid_len;
5961 memcpy(network->ssid, priv->essid, priv->essid_len);
5962 memset(&network->stats, 0, sizeof(network->stats));
5963 network->capability = WLAN_CAPABILITY_IBSS;
5964 if (!(priv->config & CFG_PREAMBLE_LONG))
5965 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
5966 if (priv->capability & CAP_PRIVACY_ON)
5967 network->capability |= WLAN_CAPABILITY_PRIVACY;
5968 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
5969 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
5970 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
5971 memcpy(network->rates_ex,
5972 &priv->rates.supported_rates[network->rates_len],
5973 network->rates_ex_len);
5974 network->last_scanned = 0;
5976 network->last_associate = 0;
5977 network->time_stamp[0] = 0;
5978 network->time_stamp[1] = 0;
5979 network->beacon_interval = 100; /* Default */
5980 network->listen_interval = 10; /* Default */
5981 network->atim_window = 0; /* Default */
5982 network->wpa_ie_len = 0;
5983 network->rsn_ie_len = 0;
5986 static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5988 struct ipw_tgi_tx_key key;
5990 if (!(priv->ieee->sec.flags & (1 << index)))
5994 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5995 key.security_type = type;
5996 key.station_index = 0; /* always 0 for BSS */
5998 /* 0 for new key; previous value of counter (after fatal error) */
5999 key.tx_counter[0] = cpu_to_le32(0);
6000 key.tx_counter[1] = cpu_to_le32(0);
6002 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
6005 static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
6007 struct ipw_wep_key key;
6010 key.cmd_id = DINO_CMD_WEP_KEY;
6013 /* Note: AES keys cannot be set for multiple times.
6014 * Only set it at the first time. */
6015 for (i = 0; i < 4; i++) {
6016 key.key_index = i | type;
6017 if (!(priv->ieee->sec.flags & (1 << i))) {
6022 key.key_size = priv->ieee->sec.key_sizes[i];
6023 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
6025 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
6029 static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
6031 if (priv->ieee->host_encrypt)
6036 priv->sys_config.disable_unicast_decryption = 0;
6037 priv->ieee->host_decrypt = 0;
6040 priv->sys_config.disable_unicast_decryption = 1;
6041 priv->ieee->host_decrypt = 1;
6044 priv->sys_config.disable_unicast_decryption = 0;
6045 priv->ieee->host_decrypt = 0;
6048 priv->sys_config.disable_unicast_decryption = 1;
6055 static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
6057 if (priv->ieee->host_encrypt)
6062 priv->sys_config.disable_multicast_decryption = 0;
6065 priv->sys_config.disable_multicast_decryption = 1;
6068 priv->sys_config.disable_multicast_decryption = 0;
6071 priv->sys_config.disable_multicast_decryption = 1;
6078 static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
6080 switch (priv->ieee->sec.level) {
6082 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6083 ipw_send_tgi_tx_key(priv,
6084 DCT_FLAG_EXT_SECURITY_CCM,
6085 priv->ieee->sec.active_key);
6087 if (!priv->ieee->host_mc_decrypt)
6088 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
6091 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
6092 ipw_send_tgi_tx_key(priv,
6093 DCT_FLAG_EXT_SECURITY_TKIP,
6094 priv->ieee->sec.active_key);
6097 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
6098 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
6099 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
6107 static void ipw_adhoc_check(void *data)
6109 struct ipw_priv *priv = data;
6111 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
6112 !(priv->config & CFG_ADHOC_PERSIST)) {
6113 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
6114 IPW_DL_STATE | IPW_DL_ASSOC,
6115 "Missed beacon: %d - disassociate\n",
6116 priv->missed_adhoc_beacons);
6117 ipw_remove_current_network(priv);
6118 ipw_disassociate(priv);
6122 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
6123 le16_to_cpu(priv->assoc_request.beacon_interval));
6126 static void ipw_bg_adhoc_check(struct work_struct *work)
6128 struct ipw_priv *priv =
6129 container_of(work, struct ipw_priv, adhoc_check.work);
6130 mutex_lock(&priv->mutex);
6131 ipw_adhoc_check(priv);
6132 mutex_unlock(&priv->mutex);
6135 static void ipw_debug_config(struct ipw_priv *priv)
6137 DECLARE_SSID_BUF(ssid);
6138 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
6139 "[CFG 0x%08X]\n", priv->config);
6140 if (priv->config & CFG_STATIC_CHANNEL)
6141 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
6143 IPW_DEBUG_INFO("Channel unlocked.\n");
6144 if (priv->config & CFG_STATIC_ESSID)
6145 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
6146 print_ssid(ssid, priv->essid, priv->essid_len));
6148 IPW_DEBUG_INFO("ESSID unlocked.\n");
6149 if (priv->config & CFG_STATIC_BSSID)
6150 IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid);
6152 IPW_DEBUG_INFO("BSSID unlocked.\n");
6153 if (priv->capability & CAP_PRIVACY_ON)
6154 IPW_DEBUG_INFO("PRIVACY on\n");
6156 IPW_DEBUG_INFO("PRIVACY off\n");
6157 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
6160 static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
6162 /* TODO: Verify that this works... */
6163 struct ipw_fixed_rate fr;
6166 u16 new_tx_rates = priv->rates_mask;
6168 /* Identify 'current FW band' and match it with the fixed
6171 switch (priv->ieee->freq_band) {
6172 case LIBIPW_52GHZ_BAND: /* A only */
6174 if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) {
6175 /* Invalid fixed rate mask */
6177 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
6182 new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A;
6185 default: /* 2.4Ghz or Mixed */
6187 if (mode == IEEE_B) {
6188 if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) {
6189 /* Invalid fixed rate mask */
6191 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
6198 if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK |
6199 LIBIPW_OFDM_RATES_MASK)) {
6200 /* Invalid fixed rate mask */
6202 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
6207 if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) {
6208 mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1);
6209 new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK;
6212 if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) {
6213 mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1);
6214 new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK;
6217 if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) {
6218 mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1);
6219 new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK;
6222 new_tx_rates |= mask;
6226 fr.tx_rates = cpu_to_le16(new_tx_rates);
6228 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
6229 ipw_write_reg32(priv, reg, *(u32 *) & fr);
6232 static void ipw_abort_scan(struct ipw_priv *priv)
6236 if (priv->status & STATUS_SCAN_ABORTING) {
6237 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6240 priv->status |= STATUS_SCAN_ABORTING;
6242 err = ipw_send_scan_abort(priv);
6244 IPW_DEBUG_HC("Request to abort scan failed.\n");
6247 static void ipw_add_scan_channels(struct ipw_priv *priv,
6248 struct ipw_scan_request_ext *scan,
6251 int channel_index = 0;
6252 const struct libipw_geo *geo;
6255 geo = libipw_get_geo(priv->ieee);
6257 if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) {
6258 int start = channel_index;
6259 for (i = 0; i < geo->a_channels; i++) {
6260 if ((priv->status & STATUS_ASSOCIATED) &&
6261 geo->a[i].channel == priv->channel)
6264 scan->channels_list[channel_index] = geo->a[i].channel;
6265 ipw_set_scan_type(scan, channel_index,
6267 flags & LIBIPW_CH_PASSIVE_ONLY ?
6268 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6272 if (start != channel_index) {
6273 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6274 (channel_index - start);
6279 if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) {
6280 int start = channel_index;
6281 if (priv->config & CFG_SPEED_SCAN) {
6283 u8 channels[LIBIPW_24GHZ_CHANNELS] = {
6284 /* nop out the list */
6289 while (channel_index < IPW_SCAN_CHANNELS - 1) {
6291 priv->speed_scan[priv->speed_scan_pos];
6293 priv->speed_scan_pos = 0;
6294 channel = priv->speed_scan[0];
6296 if ((priv->status & STATUS_ASSOCIATED) &&
6297 channel == priv->channel) {
6298 priv->speed_scan_pos++;
6302 /* If this channel has already been
6303 * added in scan, break from loop
6304 * and this will be the first channel
6307 if (channels[channel - 1] != 0)
6310 channels[channel - 1] = 1;
6311 priv->speed_scan_pos++;
6313 scan->channels_list[channel_index] = channel;
6315 libipw_channel_to_index(priv->ieee, channel);
6316 ipw_set_scan_type(scan, channel_index,
6319 LIBIPW_CH_PASSIVE_ONLY ?
6320 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6324 for (i = 0; i < geo->bg_channels; i++) {
6325 if ((priv->status & STATUS_ASSOCIATED) &&
6326 geo->bg[i].channel == priv->channel)
6329 scan->channels_list[channel_index] =
6331 ipw_set_scan_type(scan, channel_index,
6334 LIBIPW_CH_PASSIVE_ONLY ?
6335 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6340 if (start != channel_index) {
6341 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6342 (channel_index - start);
6347 static int ipw_passive_dwell_time(struct ipw_priv *priv)
6349 /* staying on passive channels longer than the DTIM interval during a
6350 * scan, while associated, causes the firmware to cancel the scan
6351 * without notification. Hence, don't stay on passive channels longer
6352 * than the beacon interval.
6354 if (priv->status & STATUS_ASSOCIATED
6355 && priv->assoc_network->beacon_interval > 10)
6356 return priv->assoc_network->beacon_interval - 10;
6361 static int ipw_request_scan_helper(struct ipw_priv *priv, int type, int direct)
6363 struct ipw_scan_request_ext scan;
6364 int err = 0, scan_type;
6366 if (!(priv->status & STATUS_INIT) ||
6367 (priv->status & STATUS_EXIT_PENDING))
6370 mutex_lock(&priv->mutex);
6372 if (direct && (priv->direct_scan_ssid_len == 0)) {
6373 IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n");
6374 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6378 if (priv->status & STATUS_SCANNING) {
6379 IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n");
6380 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6381 STATUS_SCAN_PENDING;
6385 if (!(priv->status & STATUS_SCAN_FORCED) &&
6386 priv->status & STATUS_SCAN_ABORTING) {
6387 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6388 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6389 STATUS_SCAN_PENDING;
6393 if (priv->status & STATUS_RF_KILL_MASK) {
6394 IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n");
6395 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6396 STATUS_SCAN_PENDING;
6400 memset(&scan, 0, sizeof(scan));
6401 scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee));
6403 if (type == IW_SCAN_TYPE_PASSIVE) {
6404 IPW_DEBUG_WX("use passive scanning\n");
6405 scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN;
6406 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6407 cpu_to_le16(ipw_passive_dwell_time(priv));
6408 ipw_add_scan_channels(priv, &scan, scan_type);
6412 /* Use active scan by default. */
6413 if (priv->config & CFG_SPEED_SCAN)
6414 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6417 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6420 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6423 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6424 cpu_to_le16(ipw_passive_dwell_time(priv));
6425 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
6427 #ifdef CONFIG_IPW2200_MONITOR
6428 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
6432 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
6433 case LIBIPW_52GHZ_BAND:
6434 band = (u8) (IPW_A_MODE << 6) | 1;
6435 channel = priv->channel;
6438 case LIBIPW_24GHZ_BAND:
6439 band = (u8) (IPW_B_MODE << 6) | 1;
6440 channel = priv->channel;
6444 band = (u8) (IPW_B_MODE << 6) | 1;
6449 scan.channels_list[0] = band;
6450 scan.channels_list[1] = channel;
6451 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
6453 /* NOTE: The card will sit on this channel for this time
6454 * period. Scan aborts are timing sensitive and frequently
6455 * result in firmware restarts. As such, it is best to
6456 * set a small dwell_time here and just keep re-issuing
6457 * scans. Otherwise fast channel hopping will not actually
6460 * TODO: Move SPEED SCAN support to all modes and bands */
6461 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6464 #endif /* CONFIG_IPW2200_MONITOR */
6465 /* Honor direct scans first, otherwise if we are roaming make
6466 * this a direct scan for the current network. Finally,
6467 * ensure that every other scan is a fast channel hop scan */
6469 err = ipw_send_ssid(priv, priv->direct_scan_ssid,
6470 priv->direct_scan_ssid_len);
6472 IPW_DEBUG_HC("Attempt to send SSID command "
6477 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6478 } else if ((priv->status & STATUS_ROAMING)
6479 || (!(priv->status & STATUS_ASSOCIATED)
6480 && (priv->config & CFG_STATIC_ESSID)
6481 && (le32_to_cpu(scan.full_scan_index) % 2))) {
6482 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6484 IPW_DEBUG_HC("Attempt to send SSID command "
6489 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6491 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
6493 ipw_add_scan_channels(priv, &scan, scan_type);
6494 #ifdef CONFIG_IPW2200_MONITOR
6499 err = ipw_send_scan_request_ext(priv, &scan);
6501 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
6505 priv->status |= STATUS_SCANNING;
6507 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6508 priv->direct_scan_ssid_len = 0;
6510 priv->status &= ~STATUS_SCAN_PENDING;
6512 queue_delayed_work(priv->workqueue, &priv->scan_check,
6513 IPW_SCAN_CHECK_WATCHDOG);
6515 mutex_unlock(&priv->mutex);
6519 static void ipw_request_passive_scan(struct work_struct *work)
6521 struct ipw_priv *priv =
6522 container_of(work, struct ipw_priv, request_passive_scan.work);
6523 ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0);
6526 static void ipw_request_scan(struct work_struct *work)
6528 struct ipw_priv *priv =
6529 container_of(work, struct ipw_priv, request_scan.work);
6530 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0);
6533 static void ipw_request_direct_scan(struct work_struct *work)
6535 struct ipw_priv *priv =
6536 container_of(work, struct ipw_priv, request_direct_scan.work);
6537 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1);
6540 static void ipw_bg_abort_scan(struct work_struct *work)
6542 struct ipw_priv *priv =
6543 container_of(work, struct ipw_priv, abort_scan);
6544 mutex_lock(&priv->mutex);
6545 ipw_abort_scan(priv);
6546 mutex_unlock(&priv->mutex);
6549 static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6551 /* This is called when wpa_supplicant loads and closes the driver
6553 priv->ieee->wpa_enabled = value;
6557 static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6559 struct libipw_device *ieee = priv->ieee;
6560 struct libipw_security sec = {
6561 .flags = SEC_AUTH_MODE,
6565 if (value & IW_AUTH_ALG_SHARED_KEY) {
6566 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6568 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
6569 sec.auth_mode = WLAN_AUTH_OPEN;
6571 } else if (value & IW_AUTH_ALG_LEAP) {
6572 sec.auth_mode = WLAN_AUTH_LEAP;
6577 if (ieee->set_security)
6578 ieee->set_security(ieee->dev, &sec);
6585 static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6588 /* make sure WPA is enabled */
6589 ipw_wpa_enable(priv, 1);
6592 static int ipw_set_rsn_capa(struct ipw_priv *priv,
6593 char *capabilities, int length)
6595 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6597 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
6606 static int ipw_wx_set_genie(struct net_device *dev,
6607 struct iw_request_info *info,
6608 union iwreq_data *wrqu, char *extra)
6610 struct ipw_priv *priv = libipw_priv(dev);
6611 struct libipw_device *ieee = priv->ieee;
6615 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6616 (wrqu->data.length && extra == NULL))
6619 if (wrqu->data.length) {
6620 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6626 memcpy(buf, extra, wrqu->data.length);
6627 kfree(ieee->wpa_ie);
6629 ieee->wpa_ie_len = wrqu->data.length;
6631 kfree(ieee->wpa_ie);
6632 ieee->wpa_ie = NULL;
6633 ieee->wpa_ie_len = 0;
6636 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6642 static int ipw_wx_get_genie(struct net_device *dev,
6643 struct iw_request_info *info,
6644 union iwreq_data *wrqu, char *extra)
6646 struct ipw_priv *priv = libipw_priv(dev);
6647 struct libipw_device *ieee = priv->ieee;
6650 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6651 wrqu->data.length = 0;
6655 if (wrqu->data.length < ieee->wpa_ie_len) {
6660 wrqu->data.length = ieee->wpa_ie_len;
6661 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6667 static int wext_cipher2level(int cipher)
6670 case IW_AUTH_CIPHER_NONE:
6672 case IW_AUTH_CIPHER_WEP40:
6673 case IW_AUTH_CIPHER_WEP104:
6675 case IW_AUTH_CIPHER_TKIP:
6677 case IW_AUTH_CIPHER_CCMP:
6685 static int ipw_wx_set_auth(struct net_device *dev,
6686 struct iw_request_info *info,
6687 union iwreq_data *wrqu, char *extra)
6689 struct ipw_priv *priv = libipw_priv(dev);
6690 struct libipw_device *ieee = priv->ieee;
6691 struct iw_param *param = &wrqu->param;
6692 struct lib80211_crypt_data *crypt;
6693 unsigned long flags;
6696 switch (param->flags & IW_AUTH_INDEX) {
6697 case IW_AUTH_WPA_VERSION:
6699 case IW_AUTH_CIPHER_PAIRWISE:
6700 ipw_set_hw_decrypt_unicast(priv,
6701 wext_cipher2level(param->value));
6703 case IW_AUTH_CIPHER_GROUP:
6704 ipw_set_hw_decrypt_multicast(priv,
6705 wext_cipher2level(param->value));
6707 case IW_AUTH_KEY_MGMT:
6709 * ipw2200 does not use these parameters
6713 case IW_AUTH_TKIP_COUNTERMEASURES:
6714 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
6715 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
6718 flags = crypt->ops->get_flags(crypt->priv);
6721 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6723 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6725 crypt->ops->set_flags(flags, crypt->priv);
6729 case IW_AUTH_DROP_UNENCRYPTED:{
6732 * wpa_supplicant calls set_wpa_enabled when the driver
6733 * is loaded and unloaded, regardless of if WPA is being
6734 * used. No other calls are made which can be used to
6735 * determine if encryption will be used or not prior to
6736 * association being expected. If encryption is not being
6737 * used, drop_unencrypted is set to false, else true -- we
6738 * can use this to determine if the CAP_PRIVACY_ON bit should
6741 struct libipw_security sec = {
6742 .flags = SEC_ENABLED,
6743 .enabled = param->value,
6745 priv->ieee->drop_unencrypted = param->value;
6746 /* We only change SEC_LEVEL for open mode. Others
6747 * are set by ipw_wpa_set_encryption.
6749 if (!param->value) {
6750 sec.flags |= SEC_LEVEL;
6751 sec.level = SEC_LEVEL_0;
6753 sec.flags |= SEC_LEVEL;
6754 sec.level = SEC_LEVEL_1;
6756 if (priv->ieee->set_security)
6757 priv->ieee->set_security(priv->ieee->dev, &sec);
6761 case IW_AUTH_80211_AUTH_ALG:
6762 ret = ipw_wpa_set_auth_algs(priv, param->value);
6765 case IW_AUTH_WPA_ENABLED:
6766 ret = ipw_wpa_enable(priv, param->value);
6767 ipw_disassociate(priv);
6770 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6771 ieee->ieee802_1x = param->value;
6774 case IW_AUTH_PRIVACY_INVOKED:
6775 ieee->privacy_invoked = param->value;
6785 static int ipw_wx_get_auth(struct net_device *dev,
6786 struct iw_request_info *info,
6787 union iwreq_data *wrqu, char *extra)
6789 struct ipw_priv *priv = libipw_priv(dev);
6790 struct libipw_device *ieee = priv->ieee;
6791 struct lib80211_crypt_data *crypt;
6792 struct iw_param *param = &wrqu->param;
6795 switch (param->flags & IW_AUTH_INDEX) {
6796 case IW_AUTH_WPA_VERSION:
6797 case IW_AUTH_CIPHER_PAIRWISE:
6798 case IW_AUTH_CIPHER_GROUP:
6799 case IW_AUTH_KEY_MGMT:
6801 * wpa_supplicant will control these internally
6806 case IW_AUTH_TKIP_COUNTERMEASURES:
6807 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
6808 if (!crypt || !crypt->ops->get_flags)
6811 param->value = (crypt->ops->get_flags(crypt->priv) &
6812 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6816 case IW_AUTH_DROP_UNENCRYPTED:
6817 param->value = ieee->drop_unencrypted;
6820 case IW_AUTH_80211_AUTH_ALG:
6821 param->value = ieee->sec.auth_mode;
6824 case IW_AUTH_WPA_ENABLED:
6825 param->value = ieee->wpa_enabled;
6828 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6829 param->value = ieee->ieee802_1x;
6832 case IW_AUTH_ROAMING_CONTROL:
6833 case IW_AUTH_PRIVACY_INVOKED:
6834 param->value = ieee->privacy_invoked;
6843 /* SIOCSIWENCODEEXT */
6844 static int ipw_wx_set_encodeext(struct net_device *dev,
6845 struct iw_request_info *info,
6846 union iwreq_data *wrqu, char *extra)
6848 struct ipw_priv *priv = libipw_priv(dev);
6849 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6852 if (ext->alg == IW_ENCODE_ALG_TKIP) {
6853 /* IPW HW can't build TKIP MIC,
6854 host decryption still needed */
6855 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6856 priv->ieee->host_mc_decrypt = 1;
6858 priv->ieee->host_encrypt = 0;
6859 priv->ieee->host_encrypt_msdu = 1;
6860 priv->ieee->host_decrypt = 1;
6863 priv->ieee->host_encrypt = 0;
6864 priv->ieee->host_encrypt_msdu = 0;
6865 priv->ieee->host_decrypt = 0;
6866 priv->ieee->host_mc_decrypt = 0;
6870 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6873 /* SIOCGIWENCODEEXT */
6874 static int ipw_wx_get_encodeext(struct net_device *dev,
6875 struct iw_request_info *info,
6876 union iwreq_data *wrqu, char *extra)
6878 struct ipw_priv *priv = libipw_priv(dev);
6879 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6883 static int ipw_wx_set_mlme(struct net_device *dev,
6884 struct iw_request_info *info,
6885 union iwreq_data *wrqu, char *extra)
6887 struct ipw_priv *priv = libipw_priv(dev);
6888 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6891 reason = cpu_to_le16(mlme->reason_code);
6893 switch (mlme->cmd) {
6894 case IW_MLME_DEAUTH:
6895 /* silently ignore */
6898 case IW_MLME_DISASSOC:
6899 ipw_disassociate(priv);
6908 #ifdef CONFIG_IPW2200_QOS
6912 * get the modulation type of the current network or
6913 * the card current mode
6915 static u8 ipw_qos_current_mode(struct ipw_priv * priv)
6919 if (priv->status & STATUS_ASSOCIATED) {
6920 unsigned long flags;
6922 spin_lock_irqsave(&priv->ieee->lock, flags);
6923 mode = priv->assoc_network->mode;
6924 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6926 mode = priv->ieee->mode;
6928 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6933 * Handle management frame beacon and probe response
6935 static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6937 struct libipw_network *network)
6939 u32 size = sizeof(struct libipw_qos_parameters);
6941 if (network->capability & WLAN_CAPABILITY_IBSS)
6942 network->qos_data.active = network->qos_data.supported;
6944 if (network->flags & NETWORK_HAS_QOS_MASK) {
6945 if (active_network &&
6946 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
6947 network->qos_data.active = network->qos_data.supported;
6949 if ((network->qos_data.active == 1) && (active_network == 1) &&
6950 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6951 (network->qos_data.old_param_count !=
6952 network->qos_data.param_count)) {
6953 network->qos_data.old_param_count =
6954 network->qos_data.param_count;
6955 schedule_work(&priv->qos_activate);
6956 IPW_DEBUG_QOS("QoS parameters change call "
6960 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6961 memcpy(&network->qos_data.parameters,
6962 &def_parameters_CCK, size);
6964 memcpy(&network->qos_data.parameters,
6965 &def_parameters_OFDM, size);
6967 if ((network->qos_data.active == 1) && (active_network == 1)) {
6968 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6969 schedule_work(&priv->qos_activate);
6972 network->qos_data.active = 0;
6973 network->qos_data.supported = 0;
6975 if ((priv->status & STATUS_ASSOCIATED) &&
6976 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6977 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6978 if (network->capability & WLAN_CAPABILITY_IBSS)
6979 if ((network->ssid_len ==
6980 priv->assoc_network->ssid_len) &&
6981 !memcmp(network->ssid,
6982 priv->assoc_network->ssid,
6983 network->ssid_len)) {
6984 queue_work(priv->workqueue,
6985 &priv->merge_networks);
6993 * This function set up the firmware to support QoS. It sends
6994 * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6996 static int ipw_qos_activate(struct ipw_priv *priv,
6997 struct libipw_qos_data *qos_network_data)
7000 struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS];
7001 struct libipw_qos_parameters *active_one = NULL;
7002 u32 size = sizeof(struct libipw_qos_parameters);
7007 type = ipw_qos_current_mode(priv);
7009 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
7010 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
7011 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
7012 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
7014 if (qos_network_data == NULL) {
7015 if (type == IEEE_B) {
7016 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
7017 active_one = &def_parameters_CCK;
7019 active_one = &def_parameters_OFDM;
7021 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
7022 burst_duration = ipw_qos_get_burst_duration(priv);
7023 for (i = 0; i < QOS_QUEUE_NUM; i++)
7024 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
7025 cpu_to_le16(burst_duration);
7026 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7027 if (type == IEEE_B) {
7028 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
7030 if (priv->qos_data.qos_enable == 0)
7031 active_one = &def_parameters_CCK;
7033 active_one = priv->qos_data.def_qos_parm_CCK;
7035 if (priv->qos_data.qos_enable == 0)
7036 active_one = &def_parameters_OFDM;
7038 active_one = priv->qos_data.def_qos_parm_OFDM;
7040 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
7042 unsigned long flags;
7045 spin_lock_irqsave(&priv->ieee->lock, flags);
7046 active_one = &(qos_network_data->parameters);
7047 qos_network_data->old_param_count =
7048 qos_network_data->param_count;
7049 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
7050 active = qos_network_data->supported;
7051 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7054 burst_duration = ipw_qos_get_burst_duration(priv);
7055 for (i = 0; i < QOS_QUEUE_NUM; i++)
7056 qos_parameters[QOS_PARAM_SET_ACTIVE].
7057 tx_op_limit[i] = cpu_to_le16(burst_duration);
7061 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
7062 err = ipw_send_qos_params_command(priv,
7063 (struct libipw_qos_parameters *)
7064 &(qos_parameters[0]));
7066 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
7072 * send IPW_CMD_WME_INFO to the firmware
7074 static int ipw_qos_set_info_element(struct ipw_priv *priv)
7077 struct libipw_qos_information_element qos_info;
7082 qos_info.elementID = QOS_ELEMENT_ID;
7083 qos_info.length = sizeof(struct libipw_qos_information_element) - 2;
7085 qos_info.version = QOS_VERSION_1;
7086 qos_info.ac_info = 0;
7088 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
7089 qos_info.qui_type = QOS_OUI_TYPE;
7090 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
7092 ret = ipw_send_qos_info_command(priv, &qos_info);
7094 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
7100 * Set the QoS parameter with the association request structure
7102 static int ipw_qos_association(struct ipw_priv *priv,
7103 struct libipw_network *network)
7106 struct libipw_qos_data *qos_data = NULL;
7107 struct libipw_qos_data ibss_data = {
7112 switch (priv->ieee->iw_mode) {
7114 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
7116 qos_data = &ibss_data;
7120 qos_data = &network->qos_data;
7128 err = ipw_qos_activate(priv, qos_data);
7130 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
7134 if (priv->qos_data.qos_enable && qos_data->supported) {
7135 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
7136 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
7137 return ipw_qos_set_info_element(priv);
7144 * handling the beaconing responses. if we get different QoS setting
7145 * off the network from the associated setting, adjust the QoS
7148 static int ipw_qos_association_resp(struct ipw_priv *priv,
7149 struct libipw_network *network)
7152 unsigned long flags;
7153 u32 size = sizeof(struct libipw_qos_parameters);
7154 int set_qos_param = 0;
7156 if ((priv == NULL) || (network == NULL) ||
7157 (priv->assoc_network == NULL))
7160 if (!(priv->status & STATUS_ASSOCIATED))
7163 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
7166 spin_lock_irqsave(&priv->ieee->lock, flags);
7167 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
7168 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
7169 sizeof(struct libipw_qos_data));
7170 priv->assoc_network->qos_data.active = 1;
7171 if ((network->qos_data.old_param_count !=
7172 network->qos_data.param_count)) {
7174 network->qos_data.old_param_count =
7175 network->qos_data.param_count;
7179 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7180 memcpy(&priv->assoc_network->qos_data.parameters,
7181 &def_parameters_CCK, size);
7183 memcpy(&priv->assoc_network->qos_data.parameters,
7184 &def_parameters_OFDM, size);
7185 priv->assoc_network->qos_data.active = 0;
7186 priv->assoc_network->qos_data.supported = 0;
7190 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7192 if (set_qos_param == 1)
7193 schedule_work(&priv->qos_activate);
7198 static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7205 if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION))
7206 ret = priv->qos_data.burst_duration_CCK;
7208 ret = priv->qos_data.burst_duration_OFDM;
7214 * Initialize the setting of QoS global
7216 static void ipw_qos_init(struct ipw_priv *priv, int enable,
7217 int burst_enable, u32 burst_duration_CCK,
7218 u32 burst_duration_OFDM)
7220 priv->qos_data.qos_enable = enable;
7222 if (priv->qos_data.qos_enable) {
7223 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7224 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7225 IPW_DEBUG_QOS("QoS is enabled\n");
7227 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7228 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7229 IPW_DEBUG_QOS("QoS is not enabled\n");
7232 priv->qos_data.burst_enable = burst_enable;
7235 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7236 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7238 priv->qos_data.burst_duration_CCK = 0;
7239 priv->qos_data.burst_duration_OFDM = 0;
7244 * map the packet priority to the right TX Queue
7246 static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7248 if (priority > 7 || !priv->qos_data.qos_enable)
7251 return from_priority_to_tx_queue[priority] - 1;
7254 static int ipw_is_qos_active(struct net_device *dev,
7255 struct sk_buff *skb)
7257 struct ipw_priv *priv = libipw_priv(dev);
7258 struct libipw_qos_data *qos_data = NULL;
7259 int active, supported;
7260 u8 *daddr = skb->data + ETH_ALEN;
7261 int unicast = !is_multicast_ether_addr(daddr);
7263 if (!(priv->status & STATUS_ASSOCIATED))
7266 qos_data = &priv->assoc_network->qos_data;
7268 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7270 qos_data->active = 0;
7272 qos_data->active = qos_data->supported;
7274 active = qos_data->active;
7275 supported = qos_data->supported;
7276 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7278 priv->qos_data.qos_enable, active, supported, unicast);
7279 if (active && priv->qos_data.qos_enable)
7286 * add QoS parameter to the TX command
7288 static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7290 struct tfd_data *tfd)
7292 int tx_queue_id = 0;
7295 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7296 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7298 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7299 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
7300 tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK);
7306 * background support to run QoS activate functionality
7308 static void ipw_bg_qos_activate(struct work_struct *work)
7310 struct ipw_priv *priv =
7311 container_of(work, struct ipw_priv, qos_activate);
7313 mutex_lock(&priv->mutex);
7315 if (priv->status & STATUS_ASSOCIATED)
7316 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7318 mutex_unlock(&priv->mutex);
7321 static int ipw_handle_probe_response(struct net_device *dev,
7322 struct libipw_probe_response *resp,
7323 struct libipw_network *network)
7325 struct ipw_priv *priv = libipw_priv(dev);
7326 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7327 (network == priv->assoc_network));
7329 ipw_qos_handle_probe_response(priv, active_network, network);
7334 static int ipw_handle_beacon(struct net_device *dev,
7335 struct libipw_beacon *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_assoc_response(struct net_device *dev,
7348 struct libipw_assoc_response *resp,
7349 struct libipw_network *network)
7351 struct ipw_priv *priv = libipw_priv(dev);
7352 ipw_qos_association_resp(priv, network);
7356 static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
7359 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7360 sizeof(*qos_param) * 3, qos_param);
7363 static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
7366 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7370 #endif /* CONFIG_IPW2200_QOS */
7372 static int ipw_associate_network(struct ipw_priv *priv,
7373 struct libipw_network *network,
7374 struct ipw_supported_rates *rates, int roaming)
7377 DECLARE_SSID_BUF(ssid);
7379 if (priv->config & CFG_FIXED_RATE)
7380 ipw_set_fixed_rate(priv, network->mode);
7382 if (!(priv->config & CFG_STATIC_ESSID)) {
7383 priv->essid_len = min(network->ssid_len,
7384 (u8) IW_ESSID_MAX_SIZE);
7385 memcpy(priv->essid, network->ssid, priv->essid_len);
7388 network->last_associate = jiffies;
7390 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7391 priv->assoc_request.channel = network->channel;
7392 priv->assoc_request.auth_key = 0;
7394 if ((priv->capability & CAP_PRIVACY_ON) &&
7395 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
7396 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
7397 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7399 if (priv->ieee->sec.level == SEC_LEVEL_1)
7400 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
7402 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7403 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7404 priv->assoc_request.auth_type = AUTH_LEAP;
7406 priv->assoc_request.auth_type = AUTH_OPEN;
7408 if (priv->ieee->wpa_ie_len) {
7409 priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */
7410 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7411 priv->ieee->wpa_ie_len);
7415 * It is valid for our ieee device to support multiple modes, but
7416 * when it comes to associating to a given network we have to choose
7419 if (network->mode & priv->ieee->mode & IEEE_A)
7420 priv->assoc_request.ieee_mode = IPW_A_MODE;
7421 else if (network->mode & priv->ieee->mode & IEEE_G)
7422 priv->assoc_request.ieee_mode = IPW_G_MODE;
7423 else if (network->mode & priv->ieee->mode & IEEE_B)
7424 priv->assoc_request.ieee_mode = IPW_B_MODE;
7426 priv->assoc_request.capability = cpu_to_le16(network->capability);
7427 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7428 && !(priv->config & CFG_PREAMBLE_LONG)) {
7429 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7431 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7433 /* Clear the short preamble if we won't be supporting it */
7434 priv->assoc_request.capability &=
7435 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
7438 /* Clear capability bits that aren't used in Ad Hoc */
7439 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7440 priv->assoc_request.capability &=
7441 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
7443 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
7444 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
7445 roaming ? "Rea" : "A",
7446 print_ssid(ssid, priv->essid, priv->essid_len),
7448 ipw_modes[priv->assoc_request.ieee_mode],
7450 (priv->assoc_request.preamble_length ==
7451 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7452 network->capability &
7453 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
7454 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
7455 priv->capability & CAP_PRIVACY_ON ?
7456 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
7458 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
7459 priv->capability & CAP_PRIVACY_ON ?
7460 '1' + priv->ieee->sec.active_key : '.',
7461 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
7463 priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval);
7464 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
7465 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
7466 priv->assoc_request.assoc_type = HC_IBSS_START;
7467 priv->assoc_request.assoc_tsf_msw = 0;
7468 priv->assoc_request.assoc_tsf_lsw = 0;
7470 if (unlikely(roaming))
7471 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7473 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7474 priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]);
7475 priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]);
7478 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
7480 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7481 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7482 priv->assoc_request.atim_window = cpu_to_le16(network->atim_window);
7484 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
7485 priv->assoc_request.atim_window = 0;
7488 priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval);
7490 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7492 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7496 rates->ieee_mode = priv->assoc_request.ieee_mode;
7497 rates->purpose = IPW_RATE_CONNECT;
7498 ipw_send_supported_rates(priv, rates);
7500 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7501 priv->sys_config.dot11g_auto_detection = 1;
7503 priv->sys_config.dot11g_auto_detection = 0;
7505 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7506 priv->sys_config.answer_broadcast_ssid_probe = 1;
7508 priv->sys_config.answer_broadcast_ssid_probe = 0;
7510 err = ipw_send_system_config(priv);
7512 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7516 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
7517 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
7519 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7524 * If preemption is enabled, it is possible for the association
7525 * to complete before we return from ipw_send_associate. Therefore
7526 * we have to be sure and update our priviate data first.
7528 priv->channel = network->channel;
7529 memcpy(priv->bssid, network->bssid, ETH_ALEN);
7530 priv->status |= STATUS_ASSOCIATING;
7531 priv->status &= ~STATUS_SECURITY_UPDATED;
7533 priv->assoc_network = network;
7535 #ifdef CONFIG_IPW2200_QOS
7536 ipw_qos_association(priv, network);
7539 err = ipw_send_associate(priv, &priv->assoc_request);
7541 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7545 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' %pM \n",
7546 print_ssid(ssid, priv->essid, priv->essid_len),
7552 static void ipw_roam(void *data)
7554 struct ipw_priv *priv = data;
7555 struct libipw_network *network = NULL;
7556 struct ipw_network_match match = {
7557 .network = priv->assoc_network
7560 /* The roaming process is as follows:
7562 * 1. Missed beacon threshold triggers the roaming process by
7563 * setting the status ROAM bit and requesting a scan.
7564 * 2. When the scan completes, it schedules the ROAM work
7565 * 3. The ROAM work looks at all of the known networks for one that
7566 * is a better network than the currently associated. If none
7567 * found, the ROAM process is over (ROAM bit cleared)
7568 * 4. If a better network is found, a disassociation request is
7570 * 5. When the disassociation completes, the roam work is again
7571 * scheduled. The second time through, the driver is no longer
7572 * associated, and the newly selected network is sent an
7573 * association request.
7574 * 6. At this point ,the roaming process is complete and the ROAM
7575 * status bit is cleared.
7578 /* If we are no longer associated, and the roaming bit is no longer
7579 * set, then we are not actively roaming, so just return */
7580 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7583 if (priv->status & STATUS_ASSOCIATED) {
7584 /* First pass through ROAM process -- look for a better
7586 unsigned long flags;
7587 u8 rssi = priv->assoc_network->stats.rssi;
7588 priv->assoc_network->stats.rssi = -128;
7589 spin_lock_irqsave(&priv->ieee->lock, flags);
7590 list_for_each_entry(network, &priv->ieee->network_list, list) {
7591 if (network != priv->assoc_network)
7592 ipw_best_network(priv, &match, network, 1);
7594 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7595 priv->assoc_network->stats.rssi = rssi;
7597 if (match.network == priv->assoc_network) {
7598 IPW_DEBUG_ASSOC("No better APs in this network to "
7600 priv->status &= ~STATUS_ROAMING;
7601 ipw_debug_config(priv);
7605 ipw_send_disassociate(priv, 1);
7606 priv->assoc_network = match.network;
7611 /* Second pass through ROAM process -- request association */
7612 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7613 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7614 priv->status &= ~STATUS_ROAMING;
7617 static void ipw_bg_roam(struct work_struct *work)
7619 struct ipw_priv *priv =
7620 container_of(work, struct ipw_priv, roam);
7621 mutex_lock(&priv->mutex);
7623 mutex_unlock(&priv->mutex);
7626 static int ipw_associate(void *data)
7628 struct ipw_priv *priv = data;
7630 struct libipw_network *network = NULL;
7631 struct ipw_network_match match = {
7634 struct ipw_supported_rates *rates;
7635 struct list_head *element;
7636 unsigned long flags;
7637 DECLARE_SSID_BUF(ssid);
7639 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7640 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7644 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
7645 IPW_DEBUG_ASSOC("Not attempting association (already in "
7650 if (priv->status & STATUS_DISASSOCIATING) {
7651 IPW_DEBUG_ASSOC("Not attempting association (in "
7652 "disassociating)\n ");
7653 queue_work(priv->workqueue, &priv->associate);
7657 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
7658 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7663 if (!(priv->config & CFG_ASSOCIATE) &&
7664 !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) {
7665 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
7669 /* Protect our use of the network_list */
7670 spin_lock_irqsave(&priv->ieee->lock, flags);
7671 list_for_each_entry(network, &priv->ieee->network_list, list)
7672 ipw_best_network(priv, &match, network, 0);
7674 network = match.network;
7675 rates = &match.rates;
7677 if (network == NULL &&
7678 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7679 priv->config & CFG_ADHOC_CREATE &&
7680 priv->config & CFG_STATIC_ESSID &&
7681 priv->config & CFG_STATIC_CHANNEL) {
7682 /* Use oldest network if the free list is empty */
7683 if (list_empty(&priv->ieee->network_free_list)) {
7684 struct libipw_network *oldest = NULL;
7685 struct libipw_network *target;
7687 list_for_each_entry(target, &priv->ieee->network_list, list) {
7688 if ((oldest == NULL) ||
7689 (target->last_scanned < oldest->last_scanned))
7693 /* If there are no more slots, expire the oldest */
7694 list_del(&oldest->list);
7696 IPW_DEBUG_ASSOC("Expired '%s' (%pM) from "
7698 print_ssid(ssid, target->ssid,
7701 list_add_tail(&target->list,
7702 &priv->ieee->network_free_list);
7705 element = priv->ieee->network_free_list.next;
7706 network = list_entry(element, struct libipw_network, list);
7707 ipw_adhoc_create(priv, network);
7708 rates = &priv->rates;
7710 list_add_tail(&network->list, &priv->ieee->network_list);
7712 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7714 /* If we reached the end of the list, then we don't have any valid
7717 ipw_debug_config(priv);
7719 if (!(priv->status & STATUS_SCANNING)) {
7720 if (!(priv->config & CFG_SPEED_SCAN))
7721 queue_delayed_work(priv->workqueue,
7722 &priv->request_scan,
7725 queue_delayed_work(priv->workqueue,
7726 &priv->request_scan, 0);
7732 ipw_associate_network(priv, network, rates, 0);
7737 static void ipw_bg_associate(struct work_struct *work)
7739 struct ipw_priv *priv =
7740 container_of(work, struct ipw_priv, associate);
7741 mutex_lock(&priv->mutex);
7742 ipw_associate(priv);
7743 mutex_unlock(&priv->mutex);
7746 static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7747 struct sk_buff *skb)
7749 struct ieee80211_hdr *hdr;
7752 hdr = (struct ieee80211_hdr *)skb->data;
7753 fc = le16_to_cpu(hdr->frame_control);
7754 if (!(fc & IEEE80211_FCTL_PROTECTED))
7757 fc &= ~IEEE80211_FCTL_PROTECTED;
7758 hdr->frame_control = cpu_to_le16(fc);
7759 switch (priv->ieee->sec.level) {
7761 /* Remove CCMP HDR */
7762 memmove(skb->data + LIBIPW_3ADDR_LEN,
7763 skb->data + LIBIPW_3ADDR_LEN + 8,
7764 skb->len - LIBIPW_3ADDR_LEN - 8);
7765 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
7771 memmove(skb->data + LIBIPW_3ADDR_LEN,
7772 skb->data + LIBIPW_3ADDR_LEN + 4,
7773 skb->len - LIBIPW_3ADDR_LEN - 4);
7774 skb_trim(skb, skb->len - 8); /* IV + ICV */
7779 printk(KERN_ERR "Unknown security level %d\n",
7780 priv->ieee->sec.level);
7785 static void ipw_handle_data_packet(struct ipw_priv *priv,
7786 struct ipw_rx_mem_buffer *rxb,
7787 struct libipw_rx_stats *stats)
7789 struct net_device *dev = priv->net_dev;
7790 struct libipw_hdr_4addr *hdr;
7791 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7793 /* We received data from the HW, so stop the watchdog */
7794 dev->trans_start = jiffies;
7796 /* We only process data packets if the
7797 * interface is open */
7798 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7799 skb_tailroom(rxb->skb))) {
7800 dev->stats.rx_errors++;
7801 priv->wstats.discard.misc++;
7802 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7804 } else if (unlikely(!netif_running(priv->net_dev))) {
7805 dev->stats.rx_dropped++;
7806 priv->wstats.discard.misc++;
7807 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7811 /* Advance skb->data to the start of the actual payload */
7812 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
7814 /* Set the size of the skb to the size of the frame */
7815 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
7817 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7819 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
7820 hdr = (struct libipw_hdr_4addr *)rxb->skb->data;
7821 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
7822 (is_multicast_ether_addr(hdr->addr1) ?
7823 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
7824 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7826 if (!libipw_rx(priv->ieee, rxb->skb, stats))
7827 dev->stats.rx_errors++;
7828 else { /* libipw_rx succeeded, so it now owns the SKB */
7830 __ipw_led_activity_on(priv);
7834 #ifdef CONFIG_IPW2200_RADIOTAP
7835 static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7836 struct ipw_rx_mem_buffer *rxb,
7837 struct libipw_rx_stats *stats)
7839 struct net_device *dev = priv->net_dev;
7840 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7841 struct ipw_rx_frame *frame = &pkt->u.frame;
7843 /* initial pull of some data */
7844 u16 received_channel = frame->received_channel;
7845 u8 antennaAndPhy = frame->antennaAndPhy;
7846 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7847 u16 pktrate = frame->rate;
7849 /* Magic struct that slots into the radiotap header -- no reason
7850 * to build this manually element by element, we can write it much
7851 * more efficiently than we can parse it. ORDER MATTERS HERE */
7852 struct ipw_rt_hdr *ipw_rt;
7854 short len = le16_to_cpu(pkt->u.frame.length);
7856 /* We received data from the HW, so stop the watchdog */
7857 dev->trans_start = jiffies;
7859 /* We only process data packets if the
7860 * interface is open */
7861 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7862 skb_tailroom(rxb->skb))) {
7863 dev->stats.rx_errors++;
7864 priv->wstats.discard.misc++;
7865 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7867 } else if (unlikely(!netif_running(priv->net_dev))) {
7868 dev->stats.rx_dropped++;
7869 priv->wstats.discard.misc++;
7870 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7874 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7876 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7877 /* FIXME: Should alloc bigger skb instead */
7878 dev->stats.rx_dropped++;
7879 priv->wstats.discard.misc++;
7880 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7884 /* copy the frame itself */
7885 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7886 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7888 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7890 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7891 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7892 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total header+data */
7894 /* Big bitfield of all the fields we provide in radiotap */
7895 ipw_rt->rt_hdr.it_present = cpu_to_le32(
7896 (1 << IEEE80211_RADIOTAP_TSFT) |
7897 (1 << IEEE80211_RADIOTAP_FLAGS) |
7898 (1 << IEEE80211_RADIOTAP_RATE) |
7899 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7900 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7901 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
7902 (1 << IEEE80211_RADIOTAP_ANTENNA));
7904 /* Zero the flags, we'll add to them as we go */
7905 ipw_rt->rt_flags = 0;
7906 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
7907 frame->parent_tsf[2] << 16 |
7908 frame->parent_tsf[1] << 8 |
7909 frame->parent_tsf[0]);
7911 /* Convert signal to DBM */
7912 ipw_rt->rt_dbmsignal = antsignal;
7913 ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise);
7915 /* Convert the channel data and set the flags */
7916 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7917 if (received_channel > 14) { /* 802.11a */
7918 ipw_rt->rt_chbitmask =
7919 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7920 } else if (antennaAndPhy & 32) { /* 802.11b */
7921 ipw_rt->rt_chbitmask =
7922 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7923 } else { /* 802.11g */
7924 ipw_rt->rt_chbitmask =
7925 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7928 /* set the rate in multiples of 500k/s */
7930 case IPW_TX_RATE_1MB:
7931 ipw_rt->rt_rate = 2;
7933 case IPW_TX_RATE_2MB:
7934 ipw_rt->rt_rate = 4;
7936 case IPW_TX_RATE_5MB:
7937 ipw_rt->rt_rate = 10;
7939 case IPW_TX_RATE_6MB:
7940 ipw_rt->rt_rate = 12;
7942 case IPW_TX_RATE_9MB:
7943 ipw_rt->rt_rate = 18;
7945 case IPW_TX_RATE_11MB:
7946 ipw_rt->rt_rate = 22;
7948 case IPW_TX_RATE_12MB:
7949 ipw_rt->rt_rate = 24;
7951 case IPW_TX_RATE_18MB:
7952 ipw_rt->rt_rate = 36;
7954 case IPW_TX_RATE_24MB:
7955 ipw_rt->rt_rate = 48;
7957 case IPW_TX_RATE_36MB:
7958 ipw_rt->rt_rate = 72;
7960 case IPW_TX_RATE_48MB:
7961 ipw_rt->rt_rate = 96;
7963 case IPW_TX_RATE_54MB:
7964 ipw_rt->rt_rate = 108;
7967 ipw_rt->rt_rate = 0;
7971 /* antenna number */
7972 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7974 /* set the preamble flag if we have it */
7975 if ((antennaAndPhy & 64))
7976 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7978 /* Set the size of the skb to the size of the frame */
7979 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
7981 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7983 if (!libipw_rx(priv->ieee, rxb->skb, stats))
7984 dev->stats.rx_errors++;
7985 else { /* libipw_rx succeeded, so it now owns the SKB */
7987 /* no LED during capture */
7992 #ifdef CONFIG_IPW2200_PROMISCUOUS
7993 #define libipw_is_probe_response(fc) \
7994 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7995 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7997 #define libipw_is_management(fc) \
7998 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
8000 #define libipw_is_control(fc) \
8001 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
8003 #define libipw_is_data(fc) \
8004 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
8006 #define libipw_is_assoc_request(fc) \
8007 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
8009 #define libipw_is_reassoc_request(fc) \
8010 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
8012 static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
8013 struct ipw_rx_mem_buffer *rxb,
8014 struct libipw_rx_stats *stats)
8016 struct net_device *dev = priv->prom_net_dev;
8017 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
8018 struct ipw_rx_frame *frame = &pkt->u.frame;
8019 struct ipw_rt_hdr *ipw_rt;
8021 /* First cache any information we need before we overwrite
8022 * the information provided in the skb from the hardware */
8023 struct ieee80211_hdr *hdr;
8024 u16 channel = frame->received_channel;
8025 u8 phy_flags = frame->antennaAndPhy;
8026 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
8027 s8 noise = (s8) le16_to_cpu(frame->noise);
8028 u8 rate = frame->rate;
8029 short len = le16_to_cpu(pkt->u.frame.length);
8030 struct sk_buff *skb;
8032 u16 filter = priv->prom_priv->filter;
8034 /* If the filter is set to not include Rx frames then return */
8035 if (filter & IPW_PROM_NO_RX)
8038 /* We received data from the HW, so stop the watchdog */
8039 dev->trans_start = jiffies;
8041 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
8042 dev->stats.rx_errors++;
8043 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
8047 /* We only process data packets if the interface is open */
8048 if (unlikely(!netif_running(dev))) {
8049 dev->stats.rx_dropped++;
8050 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
8054 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
8056 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
8057 /* FIXME: Should alloc bigger skb instead */
8058 dev->stats.rx_dropped++;
8059 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
8063 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
8064 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
8065 if (filter & IPW_PROM_NO_MGMT)
8067 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
8069 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
8070 if (filter & IPW_PROM_NO_CTL)
8072 if (filter & IPW_PROM_CTL_HEADER_ONLY)
8074 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
8075 if (filter & IPW_PROM_NO_DATA)
8077 if (filter & IPW_PROM_DATA_HEADER_ONLY)
8081 /* Copy the SKB since this is for the promiscuous side */
8082 skb = skb_copy(rxb->skb, GFP_ATOMIC);
8084 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
8088 /* copy the frame data to write after where the radiotap header goes */
8089 ipw_rt = (void *)skb->data;
8092 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
8094 memcpy(ipw_rt->payload, hdr, len);
8096 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
8097 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
8098 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*ipw_rt)); /* total header+data */
8100 /* Set the size of the skb to the size of the frame */
8101 skb_put(skb, sizeof(*ipw_rt) + len);
8103 /* Big bitfield of all the fields we provide in radiotap */
8104 ipw_rt->rt_hdr.it_present = cpu_to_le32(
8105 (1 << IEEE80211_RADIOTAP_TSFT) |
8106 (1 << IEEE80211_RADIOTAP_FLAGS) |
8107 (1 << IEEE80211_RADIOTAP_RATE) |
8108 (1 << IEEE80211_RADIOTAP_CHANNEL) |
8109 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
8110 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
8111 (1 << IEEE80211_RADIOTAP_ANTENNA));
8113 /* Zero the flags, we'll add to them as we go */
8114 ipw_rt->rt_flags = 0;
8115 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
8116 frame->parent_tsf[2] << 16 |
8117 frame->parent_tsf[1] << 8 |
8118 frame->parent_tsf[0]);
8120 /* Convert to DBM */
8121 ipw_rt->rt_dbmsignal = signal;
8122 ipw_rt->rt_dbmnoise = noise;
8124 /* Convert the channel data and set the flags */
8125 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
8126 if (channel > 14) { /* 802.11a */
8127 ipw_rt->rt_chbitmask =
8128 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
8129 } else if (phy_flags & (1 << 5)) { /* 802.11b */
8130 ipw_rt->rt_chbitmask =
8131 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
8132 } else { /* 802.11g */
8133 ipw_rt->rt_chbitmask =
8134 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
8137 /* set the rate in multiples of 500k/s */
8139 case IPW_TX_RATE_1MB:
8140 ipw_rt->rt_rate = 2;
8142 case IPW_TX_RATE_2MB:
8143 ipw_rt->rt_rate = 4;
8145 case IPW_TX_RATE_5MB:
8146 ipw_rt->rt_rate = 10;
8148 case IPW_TX_RATE_6MB:
8149 ipw_rt->rt_rate = 12;
8151 case IPW_TX_RATE_9MB:
8152 ipw_rt->rt_rate = 18;
8154 case IPW_TX_RATE_11MB:
8155 ipw_rt->rt_rate = 22;
8157 case IPW_TX_RATE_12MB:
8158 ipw_rt->rt_rate = 24;
8160 case IPW_TX_RATE_18MB:
8161 ipw_rt->rt_rate = 36;
8163 case IPW_TX_RATE_24MB:
8164 ipw_rt->rt_rate = 48;
8166 case IPW_TX_RATE_36MB:
8167 ipw_rt->rt_rate = 72;
8169 case IPW_TX_RATE_48MB:
8170 ipw_rt->rt_rate = 96;
8172 case IPW_TX_RATE_54MB:
8173 ipw_rt->rt_rate = 108;
8176 ipw_rt->rt_rate = 0;
8180 /* antenna number */
8181 ipw_rt->rt_antenna = (phy_flags & 3);
8183 /* set the preamble flag if we have it */
8184 if (phy_flags & (1 << 6))
8185 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
8187 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
8189 if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) {
8190 dev->stats.rx_errors++;
8191 dev_kfree_skb_any(skb);
8196 static int is_network_packet(struct ipw_priv *priv,
8197 struct libipw_hdr_4addr *header)
8199 /* Filter incoming packets to determine if they are targetted toward
8200 * this network, discarding packets coming from ourselves */
8201 switch (priv->ieee->iw_mode) {
8202 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
8203 /* packets from our adapter are dropped (echo) */
8204 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
8207 /* {broad,multi}cast packets to our BSSID go through */
8208 if (is_multicast_ether_addr(header->addr1))
8209 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
8211 /* packets to our adapter go through */
8212 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8215 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
8216 /* packets from our adapter are dropped (echo) */
8217 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
8220 /* {broad,multi}cast packets to our BSS go through */
8221 if (is_multicast_ether_addr(header->addr1))
8222 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
8224 /* packets to our adapter go through */
8225 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8232 #define IPW_PACKET_RETRY_TIME HZ
8234 static int is_duplicate_packet(struct ipw_priv *priv,
8235 struct libipw_hdr_4addr *header)
8237 u16 sc = le16_to_cpu(header->seq_ctl);
8238 u16 seq = WLAN_GET_SEQ_SEQ(sc);
8239 u16 frag = WLAN_GET_SEQ_FRAG(sc);
8240 u16 *last_seq, *last_frag;
8241 unsigned long *last_time;
8243 switch (priv->ieee->iw_mode) {
8246 struct list_head *p;
8247 struct ipw_ibss_seq *entry = NULL;
8248 u8 *mac = header->addr2;
8249 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8251 __list_for_each(p, &priv->ibss_mac_hash[index]) {
8253 list_entry(p, struct ipw_ibss_seq, list);
8254 if (!memcmp(entry->mac, mac, ETH_ALEN))
8257 if (p == &priv->ibss_mac_hash[index]) {
8258 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
8261 ("Cannot malloc new mac entry\n");
8264 memcpy(entry->mac, mac, ETH_ALEN);
8265 entry->seq_num = seq;
8266 entry->frag_num = frag;
8267 entry->packet_time = jiffies;
8268 list_add(&entry->list,
8269 &priv->ibss_mac_hash[index]);
8272 last_seq = &entry->seq_num;
8273 last_frag = &entry->frag_num;
8274 last_time = &entry->packet_time;
8278 last_seq = &priv->last_seq_num;
8279 last_frag = &priv->last_frag_num;
8280 last_time = &priv->last_packet_time;
8285 if ((*last_seq == seq) &&
8286 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8287 if (*last_frag == frag)
8289 if (*last_frag + 1 != frag)
8290 /* out-of-order fragment */
8296 *last_time = jiffies;
8300 /* Comment this line now since we observed the card receives
8301 * duplicate packets but the FCTL_RETRY bit is not set in the
8302 * IBSS mode with fragmentation enabled.
8303 BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */
8307 static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8308 struct ipw_rx_mem_buffer *rxb,
8309 struct libipw_rx_stats *stats)
8311 struct sk_buff *skb = rxb->skb;
8312 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
8313 struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *)
8314 (skb->data + IPW_RX_FRAME_SIZE);
8316 libipw_rx_mgt(priv->ieee, header, stats);
8318 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8319 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8320 IEEE80211_STYPE_PROBE_RESP) ||
8321 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8322 IEEE80211_STYPE_BEACON))) {
8323 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8324 ipw_add_station(priv, header->addr2);
8327 if (priv->config & CFG_NET_STATS) {
8328 IPW_DEBUG_HC("sending stat packet\n");
8330 /* Set the size of the skb to the size of the full
8331 * ipw header and 802.11 frame */
8332 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8335 /* Advance past the ipw packet header to the 802.11 frame */
8336 skb_pull(skb, IPW_RX_FRAME_SIZE);
8338 /* Push the libipw_rx_stats before the 802.11 frame */
8339 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8341 skb->dev = priv->ieee->dev;
8343 /* Point raw at the libipw_stats */
8344 skb_reset_mac_header(skb);
8346 skb->pkt_type = PACKET_OTHERHOST;
8347 skb->protocol = cpu_to_be16(ETH_P_80211_STATS);
8348 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8355 * Main entry function for recieving a packet with 80211 headers. This
8356 * should be called when ever the FW has notified us that there is a new
8357 * skb in the recieve queue.
8359 static void ipw_rx(struct ipw_priv *priv)
8361 struct ipw_rx_mem_buffer *rxb;
8362 struct ipw_rx_packet *pkt;
8363 struct libipw_hdr_4addr *header;
8368 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8369 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
8370 i = priv->rxq->read;
8372 if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2))
8376 rxb = priv->rxq->queue[i];
8377 if (unlikely(rxb == NULL)) {
8378 printk(KERN_CRIT "Queue not allocated!\n");
8381 priv->rxq->queue[i] = NULL;
8383 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
8385 PCI_DMA_FROMDEVICE);
8387 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8388 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8389 pkt->header.message_type,
8390 pkt->header.rx_seq_num, pkt->header.control_bits);
8392 switch (pkt->header.message_type) {
8393 case RX_FRAME_TYPE: /* 802.11 frame */ {
8394 struct libipw_rx_stats stats = {
8395 .rssi = pkt->u.frame.rssi_dbm -
8398 pkt->u.frame.rssi_dbm -
8399 IPW_RSSI_TO_DBM + 0x100,
8401 le16_to_cpu(pkt->u.frame.noise),
8402 .rate = pkt->u.frame.rate,
8403 .mac_time = jiffies,
8405 pkt->u.frame.received_channel,
8408 control & (1 << 0)) ?
8411 .len = le16_to_cpu(pkt->u.frame.length),
8414 if (stats.rssi != 0)
8415 stats.mask |= LIBIPW_STATMASK_RSSI;
8416 if (stats.signal != 0)
8417 stats.mask |= LIBIPW_STATMASK_SIGNAL;
8418 if (stats.noise != 0)
8419 stats.mask |= LIBIPW_STATMASK_NOISE;
8420 if (stats.rate != 0)
8421 stats.mask |= LIBIPW_STATMASK_RATE;
8425 #ifdef CONFIG_IPW2200_PROMISCUOUS
8426 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8427 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8430 #ifdef CONFIG_IPW2200_MONITOR
8431 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
8432 #ifdef CONFIG_IPW2200_RADIOTAP
8434 ipw_handle_data_packet_monitor(priv,
8438 ipw_handle_data_packet(priv, rxb,
8446 (struct libipw_hdr_4addr *)(rxb->skb->
8449 /* TODO: Check Ad-Hoc dest/source and make sure
8450 * that we are actually parsing these packets
8451 * correctly -- we should probably use the
8452 * frame control of the packet and disregard
8453 * the current iw_mode */
8456 is_network_packet(priv, header);
8457 if (network_packet && priv->assoc_network) {
8458 priv->assoc_network->stats.rssi =
8460 priv->exp_avg_rssi =
8461 exponential_average(priv->exp_avg_rssi,
8462 stats.rssi, DEPTH_RSSI);
8465 IPW_DEBUG_RX("Frame: len=%u\n",
8466 le16_to_cpu(pkt->u.frame.length));
8468 if (le16_to_cpu(pkt->u.frame.length) <
8469 libipw_get_hdrlen(le16_to_cpu(
8470 header->frame_ctl))) {
8472 ("Received packet is too small. "
8474 priv->net_dev->stats.rx_errors++;
8475 priv->wstats.discard.misc++;
8479 switch (WLAN_FC_GET_TYPE
8480 (le16_to_cpu(header->frame_ctl))) {
8482 case IEEE80211_FTYPE_MGMT:
8483 ipw_handle_mgmt_packet(priv, rxb,
8487 case IEEE80211_FTYPE_CTL:
8490 case IEEE80211_FTYPE_DATA:
8491 if (unlikely(!network_packet ||
8492 is_duplicate_packet(priv,
8495 IPW_DEBUG_DROP("Dropping: "
8505 ipw_handle_data_packet(priv, rxb,
8513 case RX_HOST_NOTIFICATION_TYPE:{
8515 ("Notification: subtype=%02X flags=%02X size=%d\n",
8516 pkt->u.notification.subtype,
8517 pkt->u.notification.flags,
8518 le16_to_cpu(pkt->u.notification.size));
8519 ipw_rx_notification(priv, &pkt->u.notification);
8524 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8525 pkt->header.message_type);
8529 /* For now we just don't re-use anything. We can tweak this
8530 * later to try and re-use notification packets and SKBs that
8531 * fail to Rx correctly */
8532 if (rxb->skb != NULL) {
8533 dev_kfree_skb_any(rxb->skb);
8537 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
8538 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
8539 list_add_tail(&rxb->list, &priv->rxq->rx_used);
8541 i = (i + 1) % RX_QUEUE_SIZE;
8543 /* If there are a lot of unsued frames, restock the Rx queue
8544 * so the ucode won't assert */
8546 priv->rxq->read = i;
8547 ipw_rx_queue_replenish(priv);
8551 /* Backtrack one entry */
8552 priv->rxq->read = i;
8553 ipw_rx_queue_restock(priv);
8556 #define DEFAULT_RTS_THRESHOLD 2304U
8557 #define MIN_RTS_THRESHOLD 1U
8558 #define MAX_RTS_THRESHOLD 2304U
8559 #define DEFAULT_BEACON_INTERVAL 100U
8560 #define DEFAULT_SHORT_RETRY_LIMIT 7U
8561 #define DEFAULT_LONG_RETRY_LIMIT 4U
8565 * @option: options to control different reset behaviour
8566 * 0 = reset everything except the 'disable' module_param
8567 * 1 = reset everything and print out driver info (for probe only)
8568 * 2 = reset everything
8570 static int ipw_sw_reset(struct ipw_priv *priv, int option)
8572 int band, modulation;
8573 int old_mode = priv->ieee->iw_mode;
8575 /* Initialize module parameter values here */
8578 /* We default to disabling the LED code as right now it causes
8579 * too many systems to lock up... */
8581 priv->config |= CFG_NO_LED;
8584 priv->config |= CFG_ASSOCIATE;
8586 IPW_DEBUG_INFO("Auto associate disabled.\n");
8589 priv->config |= CFG_ADHOC_CREATE;
8591 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8593 priv->config &= ~CFG_STATIC_ESSID;
8594 priv->essid_len = 0;
8595 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8597 if (disable && option) {
8598 priv->status |= STATUS_RF_KILL_SW;
8599 IPW_DEBUG_INFO("Radio disabled.\n");
8602 if (default_channel != 0) {
8603 priv->config |= CFG_STATIC_CHANNEL;
8604 priv->channel = default_channel;
8605 IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel);
8606 /* TODO: Validate that provided channel is in range */
8608 #ifdef CONFIG_IPW2200_QOS
8609 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8610 burst_duration_CCK, burst_duration_OFDM);
8611 #endif /* CONFIG_IPW2200_QOS */
8613 switch (network_mode) {
8615 priv->ieee->iw_mode = IW_MODE_ADHOC;
8616 priv->net_dev->type = ARPHRD_ETHER;
8619 #ifdef CONFIG_IPW2200_MONITOR
8621 priv->ieee->iw_mode = IW_MODE_MONITOR;
8622 #ifdef CONFIG_IPW2200_RADIOTAP
8623 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8625 priv->net_dev->type = ARPHRD_IEEE80211;
8631 priv->net_dev->type = ARPHRD_ETHER;
8632 priv->ieee->iw_mode = IW_MODE_INFRA;
8637 priv->ieee->host_encrypt = 0;
8638 priv->ieee->host_encrypt_msdu = 0;
8639 priv->ieee->host_decrypt = 0;
8640 priv->ieee->host_mc_decrypt = 0;
8642 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
8644 /* IPW2200/2915 is abled to do hardware fragmentation. */
8645 priv->ieee->host_open_frag = 0;
8647 if ((priv->pci_dev->device == 0x4223) ||
8648 (priv->pci_dev->device == 0x4224)) {
8650 printk(KERN_INFO DRV_NAME
8651 ": Detected Intel PRO/Wireless 2915ABG Network "
8653 priv->ieee->abg_true = 1;
8654 band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND;
8655 modulation = LIBIPW_OFDM_MODULATION |
8656 LIBIPW_CCK_MODULATION;
8657 priv->adapter = IPW_2915ABG;
8658 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
8661 printk(KERN_INFO DRV_NAME
8662 ": Detected Intel PRO/Wireless 2200BG Network "
8665 priv->ieee->abg_true = 0;
8666 band = LIBIPW_24GHZ_BAND;
8667 modulation = LIBIPW_OFDM_MODULATION |
8668 LIBIPW_CCK_MODULATION;
8669 priv->adapter = IPW_2200BG;
8670 priv->ieee->mode = IEEE_G | IEEE_B;
8673 priv->ieee->freq_band = band;
8674 priv->ieee->modulation = modulation;
8676 priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK;
8678 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8679 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8681 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8682 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8683 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
8685 /* If power management is turned on, default to AC mode */
8686 priv->power_mode = IPW_POWER_AC;
8687 priv->tx_power = IPW_TX_POWER_DEFAULT;
8689 return old_mode == priv->ieee->iw_mode;
8693 * This file defines the Wireless Extension handlers. It does not
8694 * define any methods of hardware manipulation and relies on the
8695 * functions defined in ipw_main to provide the HW interaction.
8697 * The exception to this is the use of the ipw_get_ordinal()
8698 * function used to poll the hardware vs. making unecessary calls.
8702 static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8705 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8706 priv->config &= ~CFG_STATIC_CHANNEL;
8707 IPW_DEBUG_ASSOC("Attempting to associate with new "
8709 ipw_associate(priv);
8713 priv->config |= CFG_STATIC_CHANNEL;
8715 if (priv->channel == channel) {
8716 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8721 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8722 priv->channel = channel;
8724 #ifdef CONFIG_IPW2200_MONITOR
8725 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
8727 if (priv->status & STATUS_SCANNING) {
8728 IPW_DEBUG_SCAN("Scan abort triggered due to "
8729 "channel change.\n");
8730 ipw_abort_scan(priv);
8733 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8736 if (priv->status & STATUS_SCANNING)
8737 IPW_DEBUG_SCAN("Still scanning...\n");
8739 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8744 #endif /* CONFIG_IPW2200_MONITOR */
8746 /* Network configuration changed -- force [re]association */
8747 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8748 if (!ipw_disassociate(priv))
8749 ipw_associate(priv);
8754 static int ipw_wx_set_freq(struct net_device *dev,
8755 struct iw_request_info *info,
8756 union iwreq_data *wrqu, char *extra)
8758 struct ipw_priv *priv = libipw_priv(dev);
8759 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
8760 struct iw_freq *fwrq = &wrqu->freq;
8766 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
8767 mutex_lock(&priv->mutex);
8768 ret = ipw_set_channel(priv, 0);
8769 mutex_unlock(&priv->mutex);
8772 /* if setting by freq convert to channel */
8774 channel = libipw_freq_to_channel(priv->ieee, fwrq->m);
8780 if (!(band = libipw_is_valid_channel(priv->ieee, channel)))
8783 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
8784 i = libipw_channel_to_index(priv->ieee, channel);
8788 flags = (band == LIBIPW_24GHZ_BAND) ?
8789 geo->bg[i].flags : geo->a[i].flags;
8790 if (flags & LIBIPW_CH_PASSIVE_ONLY) {
8791 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8796 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
8797 mutex_lock(&priv->mutex);
8798 ret = ipw_set_channel(priv, channel);
8799 mutex_unlock(&priv->mutex);
8803 static int ipw_wx_get_freq(struct net_device *dev,
8804 struct iw_request_info *info,
8805 union iwreq_data *wrqu, char *extra)
8807 struct ipw_priv *priv = libipw_priv(dev);
8811 /* If we are associated, trying to associate, or have a statically
8812 * configured CHANNEL then return that; otherwise return ANY */
8813 mutex_lock(&priv->mutex);
8814 if (priv->config & CFG_STATIC_CHANNEL ||
8815 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) {
8818 i = libipw_channel_to_index(priv->ieee, priv->channel);
8822 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
8823 case LIBIPW_52GHZ_BAND:
8824 wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000;
8827 case LIBIPW_24GHZ_BAND:
8828 wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000;
8837 mutex_unlock(&priv->mutex);
8838 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8842 static int ipw_wx_set_mode(struct net_device *dev,
8843 struct iw_request_info *info,
8844 union iwreq_data *wrqu, char *extra)
8846 struct ipw_priv *priv = libipw_priv(dev);
8849 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8851 switch (wrqu->mode) {
8852 #ifdef CONFIG_IPW2200_MONITOR
8853 case IW_MODE_MONITOR:
8859 wrqu->mode = IW_MODE_INFRA;
8864 if (wrqu->mode == priv->ieee->iw_mode)
8867 mutex_lock(&priv->mutex);
8869 ipw_sw_reset(priv, 0);
8871 #ifdef CONFIG_IPW2200_MONITOR
8872 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
8873 priv->net_dev->type = ARPHRD_ETHER;
8875 if (wrqu->mode == IW_MODE_MONITOR)
8876 #ifdef CONFIG_IPW2200_RADIOTAP
8877 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8879 priv->net_dev->type = ARPHRD_IEEE80211;
8881 #endif /* CONFIG_IPW2200_MONITOR */
8883 /* Free the existing firmware and reset the fw_loaded
8884 * flag so ipw_load() will bring in the new firmware */
8887 priv->ieee->iw_mode = wrqu->mode;
8889 queue_work(priv->workqueue, &priv->adapter_restart);
8890 mutex_unlock(&priv->mutex);
8894 static int ipw_wx_get_mode(struct net_device *dev,
8895 struct iw_request_info *info,
8896 union iwreq_data *wrqu, char *extra)
8898 struct ipw_priv *priv = libipw_priv(dev);
8899 mutex_lock(&priv->mutex);
8900 wrqu->mode = priv->ieee->iw_mode;
8901 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
8902 mutex_unlock(&priv->mutex);
8906 /* Values are in microsecond */
8907 static const s32 timeout_duration[] = {
8915 static const s32 period_duration[] = {
8923 static int ipw_wx_get_range(struct net_device *dev,
8924 struct iw_request_info *info,
8925 union iwreq_data *wrqu, char *extra)
8927 struct ipw_priv *priv = libipw_priv(dev);
8928 struct iw_range *range = (struct iw_range *)extra;
8929 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
8932 wrqu->data.length = sizeof(*range);
8933 memset(range, 0, sizeof(*range));
8935 /* 54Mbs == ~27 Mb/s real (802.11g) */
8936 range->throughput = 27 * 1000 * 1000;
8938 range->max_qual.qual = 100;
8939 /* TODO: Find real max RSSI and stick here */
8940 range->max_qual.level = 0;
8941 range->max_qual.noise = 0;
8942 range->max_qual.updated = 7; /* Updated all three */
8944 range->avg_qual.qual = 70;
8945 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
8946 range->avg_qual.level = 0; /* FIXME to real average level */
8947 range->avg_qual.noise = 0;
8948 range->avg_qual.updated = 7; /* Updated all three */
8949 mutex_lock(&priv->mutex);
8950 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
8952 for (i = 0; i < range->num_bitrates; i++)
8953 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
8956 range->max_rts = DEFAULT_RTS_THRESHOLD;
8957 range->min_frag = MIN_FRAG_THRESHOLD;
8958 range->max_frag = MAX_FRAG_THRESHOLD;
8960 range->encoding_size[0] = 5;
8961 range->encoding_size[1] = 13;
8962 range->num_encoding_sizes = 2;
8963 range->max_encoding_tokens = WEP_KEYS;
8965 /* Set the Wireless Extension versions */
8966 range->we_version_compiled = WIRELESS_EXT;
8967 range->we_version_source = 18;
8970 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
8971 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8972 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8973 (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY))
8976 range->freq[i].i = geo->bg[j].channel;
8977 range->freq[i].m = geo->bg[j].freq * 100000;
8978 range->freq[i].e = 1;
8983 if (priv->ieee->mode & IEEE_A) {
8984 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8985 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8986 (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY))
8989 range->freq[i].i = geo->a[j].channel;
8990 range->freq[i].m = geo->a[j].freq * 100000;
8991 range->freq[i].e = 1;
8996 range->num_channels = i;
8997 range->num_frequency = i;
8999 mutex_unlock(&priv->mutex);
9001 /* Event capability (kernel + driver) */
9002 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
9003 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
9004 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
9005 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
9006 range->event_capa[1] = IW_EVENT_CAPA_K_1;
9008 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
9009 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
9011 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE;
9013 IPW_DEBUG_WX("GET Range\n");
9017 static int ipw_wx_set_wap(struct net_device *dev,
9018 struct iw_request_info *info,
9019 union iwreq_data *wrqu, char *extra)
9021 struct ipw_priv *priv = libipw_priv(dev);
9023 static const unsigned char any[] = {
9024 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
9026 static const unsigned char off[] = {
9027 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
9030 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
9032 mutex_lock(&priv->mutex);
9033 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
9034 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9035 /* we disable mandatory BSSID association */
9036 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
9037 priv->config &= ~CFG_STATIC_BSSID;
9038 IPW_DEBUG_ASSOC("Attempting to associate with new "
9040 ipw_associate(priv);
9041 mutex_unlock(&priv->mutex);
9045 priv->config |= CFG_STATIC_BSSID;
9046 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
9047 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
9048 mutex_unlock(&priv->mutex);
9052 IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n",
9053 wrqu->ap_addr.sa_data);
9055 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
9057 /* Network configuration changed -- force [re]association */
9058 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
9059 if (!ipw_disassociate(priv))
9060 ipw_associate(priv);
9062 mutex_unlock(&priv->mutex);
9066 static int ipw_wx_get_wap(struct net_device *dev,
9067 struct iw_request_info *info,
9068 union iwreq_data *wrqu, char *extra)
9070 struct ipw_priv *priv = libipw_priv(dev);
9072 /* If we are associated, trying to associate, or have a statically
9073 * configured BSSID then return that; otherwise return ANY */
9074 mutex_lock(&priv->mutex);
9075 if (priv->config & CFG_STATIC_BSSID ||
9076 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9077 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
9078 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
9080 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
9082 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n",
9083 wrqu->ap_addr.sa_data);
9084 mutex_unlock(&priv->mutex);
9088 static int ipw_wx_set_essid(struct net_device *dev,
9089 struct iw_request_info *info,
9090 union iwreq_data *wrqu, char *extra)
9092 struct ipw_priv *priv = libipw_priv(dev);
9094 DECLARE_SSID_BUF(ssid);
9096 mutex_lock(&priv->mutex);
9098 if (!wrqu->essid.flags)
9100 IPW_DEBUG_WX("Setting ESSID to ANY\n");
9101 ipw_disassociate(priv);
9102 priv->config &= ~CFG_STATIC_ESSID;
9103 ipw_associate(priv);
9104 mutex_unlock(&priv->mutex);
9108 length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE);
9110 priv->config |= CFG_STATIC_ESSID;
9112 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)
9113 && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
9114 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
9115 mutex_unlock(&priv->mutex);
9119 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
9120 print_ssid(ssid, extra, length), length);
9122 priv->essid_len = length;
9123 memcpy(priv->essid, extra, priv->essid_len);
9125 /* Network configuration changed -- force [re]association */
9126 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
9127 if (!ipw_disassociate(priv))
9128 ipw_associate(priv);
9130 mutex_unlock(&priv->mutex);
9134 static int ipw_wx_get_essid(struct net_device *dev,
9135 struct iw_request_info *info,
9136 union iwreq_data *wrqu, char *extra)
9138 struct ipw_priv *priv = libipw_priv(dev);
9139 DECLARE_SSID_BUF(ssid);
9141 /* If we are associated, trying to associate, or have a statically
9142 * configured ESSID then return that; otherwise return ANY */
9143 mutex_lock(&priv->mutex);
9144 if (priv->config & CFG_STATIC_ESSID ||
9145 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
9146 IPW_DEBUG_WX("Getting essid: '%s'\n",
9147 print_ssid(ssid, priv->essid, priv->essid_len));
9148 memcpy(extra, priv->essid, priv->essid_len);
9149 wrqu->essid.length = priv->essid_len;
9150 wrqu->essid.flags = 1; /* active */
9152 IPW_DEBUG_WX("Getting essid: ANY\n");
9153 wrqu->essid.length = 0;
9154 wrqu->essid.flags = 0; /* active */
9156 mutex_unlock(&priv->mutex);
9160 static int ipw_wx_set_nick(struct net_device *dev,
9161 struct iw_request_info *info,
9162 union iwreq_data *wrqu, char *extra)
9164 struct ipw_priv *priv = libipw_priv(dev);
9166 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
9167 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
9169 mutex_lock(&priv->mutex);
9170 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
9171 memset(priv->nick, 0, sizeof(priv->nick));
9172 memcpy(priv->nick, extra, wrqu->data.length);
9173 IPW_DEBUG_TRACE("<<\n");
9174 mutex_unlock(&priv->mutex);
9179 static int ipw_wx_get_nick(struct net_device *dev,
9180 struct iw_request_info *info,
9181 union iwreq_data *wrqu, char *extra)
9183 struct ipw_priv *priv = libipw_priv(dev);
9184 IPW_DEBUG_WX("Getting nick\n");
9185 mutex_lock(&priv->mutex);
9186 wrqu->data.length = strlen(priv->nick);
9187 memcpy(extra, priv->nick, wrqu->data.length);
9188 wrqu->data.flags = 1; /* active */
9189 mutex_unlock(&priv->mutex);
9193 static int ipw_wx_set_sens(struct net_device *dev,
9194 struct iw_request_info *info,
9195 union iwreq_data *wrqu, char *extra)
9197 struct ipw_priv *priv = libipw_priv(dev);
9200 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
9201 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
9202 mutex_lock(&priv->mutex);
9204 if (wrqu->sens.fixed == 0)
9206 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
9207 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
9210 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
9211 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
9216 priv->roaming_threshold = wrqu->sens.value;
9217 priv->disassociate_threshold = 3*wrqu->sens.value;
9219 mutex_unlock(&priv->mutex);
9223 static int ipw_wx_get_sens(struct net_device *dev,
9224 struct iw_request_info *info,
9225 union iwreq_data *wrqu, char *extra)
9227 struct ipw_priv *priv = libipw_priv(dev);
9228 mutex_lock(&priv->mutex);
9229 wrqu->sens.fixed = 1;
9230 wrqu->sens.value = priv->roaming_threshold;
9231 mutex_unlock(&priv->mutex);
9233 IPW_DEBUG_WX("GET roaming threshold -> %s %d \n",
9234 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9239 static int ipw_wx_set_rate(struct net_device *dev,
9240 struct iw_request_info *info,
9241 union iwreq_data *wrqu, char *extra)
9243 /* TODO: We should use semaphores or locks for access to priv */
9244 struct ipw_priv *priv = libipw_priv(dev);
9245 u32 target_rate = wrqu->bitrate.value;
9248 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
9249 /* value = X, fixed = 1 means only rate X */
9250 /* value = X, fixed = 0 means all rates lower equal X */
9252 if (target_rate == -1) {
9254 mask = LIBIPW_DEFAULT_RATES_MASK;
9255 /* Now we should reassociate */
9260 fixed = wrqu->bitrate.fixed;
9262 if (target_rate == 1000000 || !fixed)
9263 mask |= LIBIPW_CCK_RATE_1MB_MASK;
9264 if (target_rate == 1000000)
9267 if (target_rate == 2000000 || !fixed)
9268 mask |= LIBIPW_CCK_RATE_2MB_MASK;
9269 if (target_rate == 2000000)
9272 if (target_rate == 5500000 || !fixed)
9273 mask |= LIBIPW_CCK_RATE_5MB_MASK;
9274 if (target_rate == 5500000)
9277 if (target_rate == 6000000 || !fixed)
9278 mask |= LIBIPW_OFDM_RATE_6MB_MASK;
9279 if (target_rate == 6000000)
9282 if (target_rate == 9000000 || !fixed)
9283 mask |= LIBIPW_OFDM_RATE_9MB_MASK;
9284 if (target_rate == 9000000)
9287 if (target_rate == 11000000 || !fixed)
9288 mask |= LIBIPW_CCK_RATE_11MB_MASK;
9289 if (target_rate == 11000000)
9292 if (target_rate == 12000000 || !fixed)
9293 mask |= LIBIPW_OFDM_RATE_12MB_MASK;
9294 if (target_rate == 12000000)
9297 if (target_rate == 18000000 || !fixed)
9298 mask |= LIBIPW_OFDM_RATE_18MB_MASK;
9299 if (target_rate == 18000000)
9302 if (target_rate == 24000000 || !fixed)
9303 mask |= LIBIPW_OFDM_RATE_24MB_MASK;
9304 if (target_rate == 24000000)
9307 if (target_rate == 36000000 || !fixed)
9308 mask |= LIBIPW_OFDM_RATE_36MB_MASK;
9309 if (target_rate == 36000000)
9312 if (target_rate == 48000000 || !fixed)
9313 mask |= LIBIPW_OFDM_RATE_48MB_MASK;
9314 if (target_rate == 48000000)
9317 if (target_rate == 54000000 || !fixed)
9318 mask |= LIBIPW_OFDM_RATE_54MB_MASK;
9319 if (target_rate == 54000000)
9322 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9326 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9327 mask, fixed ? "fixed" : "sub-rates");
9328 mutex_lock(&priv->mutex);
9329 if (mask == LIBIPW_DEFAULT_RATES_MASK) {
9330 priv->config &= ~CFG_FIXED_RATE;
9331 ipw_set_fixed_rate(priv, priv->ieee->mode);
9333 priv->config |= CFG_FIXED_RATE;
9335 if (priv->rates_mask == mask) {
9336 IPW_DEBUG_WX("Mask set to current mask.\n");
9337 mutex_unlock(&priv->mutex);
9341 priv->rates_mask = mask;
9343 /* Network configuration changed -- force [re]association */
9344 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9345 if (!ipw_disassociate(priv))
9346 ipw_associate(priv);
9348 mutex_unlock(&priv->mutex);
9352 static int ipw_wx_get_rate(struct net_device *dev,
9353 struct iw_request_info *info,
9354 union iwreq_data *wrqu, char *extra)
9356 struct ipw_priv *priv = libipw_priv(dev);
9357 mutex_lock(&priv->mutex);
9358 wrqu->bitrate.value = priv->last_rate;
9359 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
9360 mutex_unlock(&priv->mutex);
9361 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
9365 static int ipw_wx_set_rts(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 if (wrqu->rts.disabled || !wrqu->rts.fixed)
9372 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9374 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
9375 wrqu->rts.value > MAX_RTS_THRESHOLD) {
9376 mutex_unlock(&priv->mutex);
9379 priv->rts_threshold = wrqu->rts.value;
9382 ipw_send_rts_threshold(priv, priv->rts_threshold);
9383 mutex_unlock(&priv->mutex);
9384 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
9388 static int ipw_wx_get_rts(struct net_device *dev,
9389 struct iw_request_info *info,
9390 union iwreq_data *wrqu, char *extra)
9392 struct ipw_priv *priv = libipw_priv(dev);
9393 mutex_lock(&priv->mutex);
9394 wrqu->rts.value = priv->rts_threshold;
9395 wrqu->rts.fixed = 0; /* no auto select */
9396 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
9397 mutex_unlock(&priv->mutex);
9398 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
9402 static int ipw_wx_set_txpow(struct net_device *dev,
9403 struct iw_request_info *info,
9404 union iwreq_data *wrqu, char *extra)
9406 struct ipw_priv *priv = libipw_priv(dev);
9409 mutex_lock(&priv->mutex);
9410 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
9415 if (!wrqu->power.fixed)
9416 wrqu->power.value = IPW_TX_POWER_DEFAULT;
9418 if (wrqu->power.flags != IW_TXPOW_DBM) {
9423 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
9424 (wrqu->power.value < IPW_TX_POWER_MIN)) {
9429 priv->tx_power = wrqu->power.value;
9430 err = ipw_set_tx_power(priv);
9432 mutex_unlock(&priv->mutex);
9436 static int ipw_wx_get_txpow(struct net_device *dev,
9437 struct iw_request_info *info,
9438 union iwreq_data *wrqu, char *extra)
9440 struct ipw_priv *priv = libipw_priv(dev);
9441 mutex_lock(&priv->mutex);
9442 wrqu->power.value = priv->tx_power;
9443 wrqu->power.fixed = 1;
9444 wrqu->power.flags = IW_TXPOW_DBM;
9445 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
9446 mutex_unlock(&priv->mutex);
9448 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
9449 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9454 static int ipw_wx_set_frag(struct net_device *dev,
9455 struct iw_request_info *info,
9456 union iwreq_data *wrqu, char *extra)
9458 struct ipw_priv *priv = libipw_priv(dev);
9459 mutex_lock(&priv->mutex);
9460 if (wrqu->frag.disabled || !wrqu->frag.fixed)
9461 priv->ieee->fts = DEFAULT_FTS;
9463 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
9464 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
9465 mutex_unlock(&priv->mutex);
9469 priv->ieee->fts = wrqu->frag.value & ~0x1;
9472 ipw_send_frag_threshold(priv, wrqu->frag.value);
9473 mutex_unlock(&priv->mutex);
9474 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
9478 static int ipw_wx_get_frag(struct net_device *dev,
9479 struct iw_request_info *info,
9480 union iwreq_data *wrqu, char *extra)
9482 struct ipw_priv *priv = libipw_priv(dev);
9483 mutex_lock(&priv->mutex);
9484 wrqu->frag.value = priv->ieee->fts;
9485 wrqu->frag.fixed = 0; /* no auto select */
9486 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
9487 mutex_unlock(&priv->mutex);
9488 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
9493 static int ipw_wx_set_retry(struct net_device *dev,
9494 struct iw_request_info *info,
9495 union iwreq_data *wrqu, char *extra)
9497 struct ipw_priv *priv = libipw_priv(dev);
9499 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9502 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9505 if (wrqu->retry.value < 0 || wrqu->retry.value >= 255)
9508 mutex_lock(&priv->mutex);
9509 if (wrqu->retry.flags & IW_RETRY_SHORT)
9510 priv->short_retry_limit = (u8) wrqu->retry.value;
9511 else if (wrqu->retry.flags & IW_RETRY_LONG)
9512 priv->long_retry_limit = (u8) wrqu->retry.value;
9514 priv->short_retry_limit = (u8) wrqu->retry.value;
9515 priv->long_retry_limit = (u8) wrqu->retry.value;
9518 ipw_send_retry_limit(priv, priv->short_retry_limit,
9519 priv->long_retry_limit);
9520 mutex_unlock(&priv->mutex);
9521 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9522 priv->short_retry_limit, priv->long_retry_limit);
9526 static int ipw_wx_get_retry(struct net_device *dev,
9527 struct iw_request_info *info,
9528 union iwreq_data *wrqu, char *extra)
9530 struct ipw_priv *priv = libipw_priv(dev);
9532 mutex_lock(&priv->mutex);
9533 wrqu->retry.disabled = 0;
9535 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
9536 mutex_unlock(&priv->mutex);
9540 if (wrqu->retry.flags & IW_RETRY_LONG) {
9541 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
9542 wrqu->retry.value = priv->long_retry_limit;
9543 } else if (wrqu->retry.flags & IW_RETRY_SHORT) {
9544 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
9545 wrqu->retry.value = priv->short_retry_limit;
9547 wrqu->retry.flags = IW_RETRY_LIMIT;
9548 wrqu->retry.value = priv->short_retry_limit;
9550 mutex_unlock(&priv->mutex);
9552 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9557 static int ipw_wx_set_scan(struct net_device *dev,
9558 struct iw_request_info *info,
9559 union iwreq_data *wrqu, char *extra)
9561 struct ipw_priv *priv = libipw_priv(dev);
9562 struct iw_scan_req *req = (struct iw_scan_req *)extra;
9563 struct delayed_work *work = NULL;
9565 mutex_lock(&priv->mutex);
9567 priv->user_requested_scan = 1;
9569 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
9570 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9571 int len = min((int)req->essid_len,
9572 (int)sizeof(priv->direct_scan_ssid));
9573 memcpy(priv->direct_scan_ssid, req->essid, len);
9574 priv->direct_scan_ssid_len = len;
9575 work = &priv->request_direct_scan;
9576 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) {
9577 work = &priv->request_passive_scan;
9580 /* Normal active broadcast scan */
9581 work = &priv->request_scan;
9584 mutex_unlock(&priv->mutex);
9586 IPW_DEBUG_WX("Start scan\n");
9588 queue_delayed_work(priv->workqueue, work, 0);
9593 static int ipw_wx_get_scan(struct net_device *dev,
9594 struct iw_request_info *info,
9595 union iwreq_data *wrqu, char *extra)
9597 struct ipw_priv *priv = libipw_priv(dev);
9598 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
9601 static int ipw_wx_set_encode(struct net_device *dev,
9602 struct iw_request_info *info,
9603 union iwreq_data *wrqu, char *key)
9605 struct ipw_priv *priv = libipw_priv(dev);
9607 u32 cap = priv->capability;
9609 mutex_lock(&priv->mutex);
9610 ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key);
9612 /* In IBSS mode, we need to notify the firmware to update
9613 * the beacon info after we changed the capability. */
9614 if (cap != priv->capability &&
9615 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9616 priv->status & STATUS_ASSOCIATED)
9617 ipw_disassociate(priv);
9619 mutex_unlock(&priv->mutex);
9623 static int ipw_wx_get_encode(struct net_device *dev,
9624 struct iw_request_info *info,
9625 union iwreq_data *wrqu, char *key)
9627 struct ipw_priv *priv = libipw_priv(dev);
9628 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
9631 static int ipw_wx_set_power(struct net_device *dev,
9632 struct iw_request_info *info,
9633 union iwreq_data *wrqu, char *extra)
9635 struct ipw_priv *priv = libipw_priv(dev);
9637 mutex_lock(&priv->mutex);
9638 if (wrqu->power.disabled) {
9639 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9640 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9642 IPW_DEBUG_WX("failed setting power mode.\n");
9643 mutex_unlock(&priv->mutex);
9646 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
9647 mutex_unlock(&priv->mutex);
9651 switch (wrqu->power.flags & IW_POWER_MODE) {
9652 case IW_POWER_ON: /* If not specified */
9653 case IW_POWER_MODE: /* If set all mask */
9654 case IW_POWER_ALL_R: /* If explicitly state all */
9656 default: /* Otherwise we don't support it */
9657 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9659 mutex_unlock(&priv->mutex);
9663 /* If the user hasn't specified a power management mode yet, default
9665 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
9666 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
9668 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9670 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9672 IPW_DEBUG_WX("failed setting power mode.\n");
9673 mutex_unlock(&priv->mutex);
9677 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
9678 mutex_unlock(&priv->mutex);
9682 static int ipw_wx_get_power(struct net_device *dev,
9683 struct iw_request_info *info,
9684 union iwreq_data *wrqu, char *extra)
9686 struct ipw_priv *priv = libipw_priv(dev);
9687 mutex_lock(&priv->mutex);
9688 if (!(priv->power_mode & IPW_POWER_ENABLED))
9689 wrqu->power.disabled = 1;
9691 wrqu->power.disabled = 0;
9693 mutex_unlock(&priv->mutex);
9694 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
9699 static int ipw_wx_set_powermode(struct net_device *dev,
9700 struct iw_request_info *info,
9701 union iwreq_data *wrqu, char *extra)
9703 struct ipw_priv *priv = libipw_priv(dev);
9704 int mode = *(int *)extra;
9707 mutex_lock(&priv->mutex);
9708 if ((mode < 1) || (mode > IPW_POWER_LIMIT))
9709 mode = IPW_POWER_AC;
9711 if (IPW_POWER_LEVEL(priv->power_mode) != mode) {
9712 err = ipw_send_power_mode(priv, mode);
9714 IPW_DEBUG_WX("failed setting power mode.\n");
9715 mutex_unlock(&priv->mutex);
9718 priv->power_mode = IPW_POWER_ENABLED | mode;
9720 mutex_unlock(&priv->mutex);
9724 #define MAX_WX_STRING 80
9725 static int ipw_wx_get_powermode(struct net_device *dev,
9726 struct iw_request_info *info,
9727 union iwreq_data *wrqu, char *extra)
9729 struct ipw_priv *priv = libipw_priv(dev);
9730 int level = IPW_POWER_LEVEL(priv->power_mode);
9733 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9737 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9739 case IPW_POWER_BATTERY:
9740 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9743 p += snprintf(p, MAX_WX_STRING - (p - extra),
9744 "(Timeout %dms, Period %dms)",
9745 timeout_duration[level - 1] / 1000,
9746 period_duration[level - 1] / 1000);
9749 if (!(priv->power_mode & IPW_POWER_ENABLED))
9750 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
9752 wrqu->data.length = p - extra + 1;
9757 static int ipw_wx_set_wireless_mode(struct net_device *dev,
9758 struct iw_request_info *info,
9759 union iwreq_data *wrqu, char *extra)
9761 struct ipw_priv *priv = libipw_priv(dev);
9762 int mode = *(int *)extra;
9763 u8 band = 0, modulation = 0;
9765 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
9766 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
9769 mutex_lock(&priv->mutex);
9770 if (priv->adapter == IPW_2915ABG) {
9771 priv->ieee->abg_true = 1;
9772 if (mode & IEEE_A) {
9773 band |= LIBIPW_52GHZ_BAND;
9774 modulation |= LIBIPW_OFDM_MODULATION;
9776 priv->ieee->abg_true = 0;
9778 if (mode & IEEE_A) {
9779 IPW_WARNING("Attempt to set 2200BG into "
9781 mutex_unlock(&priv->mutex);
9785 priv->ieee->abg_true = 0;
9788 if (mode & IEEE_B) {
9789 band |= LIBIPW_24GHZ_BAND;
9790 modulation |= LIBIPW_CCK_MODULATION;
9792 priv->ieee->abg_true = 0;
9794 if (mode & IEEE_G) {
9795 band |= LIBIPW_24GHZ_BAND;
9796 modulation |= LIBIPW_OFDM_MODULATION;
9798 priv->ieee->abg_true = 0;
9800 priv->ieee->mode = mode;
9801 priv->ieee->freq_band = band;
9802 priv->ieee->modulation = modulation;
9803 init_supported_rates(priv, &priv->rates);
9805 /* Network configuration changed -- force [re]association */
9806 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9807 if (!ipw_disassociate(priv)) {
9808 ipw_send_supported_rates(priv, &priv->rates);
9809 ipw_associate(priv);
9812 /* Update the band LEDs */
9813 ipw_led_band_on(priv);
9815 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
9816 mode & IEEE_A ? 'a' : '.',
9817 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
9818 mutex_unlock(&priv->mutex);
9822 static int ipw_wx_get_wireless_mode(struct net_device *dev,
9823 struct iw_request_info *info,
9824 union iwreq_data *wrqu, char *extra)
9826 struct ipw_priv *priv = libipw_priv(dev);
9827 mutex_lock(&priv->mutex);
9828 switch (priv->ieee->mode) {
9830 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9833 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9835 case IEEE_A | IEEE_B:
9836 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9839 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9841 case IEEE_A | IEEE_G:
9842 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9844 case IEEE_B | IEEE_G:
9845 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9847 case IEEE_A | IEEE_B | IEEE_G:
9848 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9851 strncpy(extra, "unknown", MAX_WX_STRING);
9855 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9857 wrqu->data.length = strlen(extra) + 1;
9858 mutex_unlock(&priv->mutex);
9863 static int ipw_wx_set_preamble(struct net_device *dev,
9864 struct iw_request_info *info,
9865 union iwreq_data *wrqu, char *extra)
9867 struct ipw_priv *priv = libipw_priv(dev);
9868 int mode = *(int *)extra;
9869 mutex_lock(&priv->mutex);
9870 /* Switching from SHORT -> LONG requires a disassociation */
9872 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9873 priv->config |= CFG_PREAMBLE_LONG;
9875 /* Network configuration changed -- force [re]association */
9877 ("[re]association triggered due to preamble change.\n");
9878 if (!ipw_disassociate(priv))
9879 ipw_associate(priv);
9885 priv->config &= ~CFG_PREAMBLE_LONG;
9888 mutex_unlock(&priv->mutex);
9892 mutex_unlock(&priv->mutex);
9896 static int ipw_wx_get_preamble(struct net_device *dev,
9897 struct iw_request_info *info,
9898 union iwreq_data *wrqu, char *extra)
9900 struct ipw_priv *priv = libipw_priv(dev);
9901 mutex_lock(&priv->mutex);
9902 if (priv->config & CFG_PREAMBLE_LONG)
9903 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9905 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
9906 mutex_unlock(&priv->mutex);
9910 #ifdef CONFIG_IPW2200_MONITOR
9911 static int ipw_wx_set_monitor(struct net_device *dev,
9912 struct iw_request_info *info,
9913 union iwreq_data *wrqu, char *extra)
9915 struct ipw_priv *priv = libipw_priv(dev);
9916 int *parms = (int *)extra;
9917 int enable = (parms[0] > 0);
9918 mutex_lock(&priv->mutex);
9919 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
9921 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9922 #ifdef CONFIG_IPW2200_RADIOTAP
9923 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9925 priv->net_dev->type = ARPHRD_IEEE80211;
9927 queue_work(priv->workqueue, &priv->adapter_restart);
9930 ipw_set_channel(priv, parms[1]);
9932 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9933 mutex_unlock(&priv->mutex);
9936 priv->net_dev->type = ARPHRD_ETHER;
9937 queue_work(priv->workqueue, &priv->adapter_restart);
9939 mutex_unlock(&priv->mutex);
9943 #endif /* CONFIG_IPW2200_MONITOR */
9945 static int ipw_wx_reset(struct net_device *dev,
9946 struct iw_request_info *info,
9947 union iwreq_data *wrqu, char *extra)
9949 struct ipw_priv *priv = libipw_priv(dev);
9950 IPW_DEBUG_WX("RESET\n");
9951 queue_work(priv->workqueue, &priv->adapter_restart);
9955 static int ipw_wx_sw_reset(struct net_device *dev,
9956 struct iw_request_info *info,
9957 union iwreq_data *wrqu, char *extra)
9959 struct ipw_priv *priv = libipw_priv(dev);
9960 union iwreq_data wrqu_sec = {
9962 .flags = IW_ENCODE_DISABLED,
9967 IPW_DEBUG_WX("SW_RESET\n");
9969 mutex_lock(&priv->mutex);
9971 ret = ipw_sw_reset(priv, 2);
9974 ipw_adapter_restart(priv);
9977 /* The SW reset bit might have been toggled on by the 'disable'
9978 * module parameter, so take appropriate action */
9979 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9981 mutex_unlock(&priv->mutex);
9982 libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
9983 mutex_lock(&priv->mutex);
9985 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9986 /* Configuration likely changed -- force [re]association */
9987 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9989 if (!ipw_disassociate(priv))
9990 ipw_associate(priv);
9993 mutex_unlock(&priv->mutex);
9998 /* Rebase the WE IOCTLs to zero for the handler array */
9999 #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
10000 static iw_handler ipw_wx_handlers[] = {
10001 IW_IOCTL(SIOCGIWNAME) = (iw_handler) cfg80211_wext_giwname,
10002 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
10003 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
10004 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
10005 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
10006 IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens,
10007 IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens,
10008 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
10009 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
10010 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
10011 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
10012 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
10013 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
10014 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
10015 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
10016 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
10017 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
10018 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
10019 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
10020 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
10021 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
10022 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
10023 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
10024 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
10025 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
10026 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
10027 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
10028 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
10029 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
10030 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
10031 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
10032 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
10033 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
10034 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
10035 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
10036 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
10037 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
10038 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
10039 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
10040 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
10041 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
10045 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
10046 IPW_PRIV_GET_POWER,
10049 IPW_PRIV_SET_PREAMBLE,
10050 IPW_PRIV_GET_PREAMBLE,
10053 #ifdef CONFIG_IPW2200_MONITOR
10054 IPW_PRIV_SET_MONITOR,
10058 static struct iw_priv_args ipw_priv_args[] = {
10060 .cmd = IPW_PRIV_SET_POWER,
10061 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10062 .name = "set_power"},
10064 .cmd = IPW_PRIV_GET_POWER,
10065 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10066 .name = "get_power"},
10068 .cmd = IPW_PRIV_SET_MODE,
10069 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10070 .name = "set_mode"},
10072 .cmd = IPW_PRIV_GET_MODE,
10073 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
10074 .name = "get_mode"},
10076 .cmd = IPW_PRIV_SET_PREAMBLE,
10077 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
10078 .name = "set_preamble"},
10080 .cmd = IPW_PRIV_GET_PREAMBLE,
10081 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
10082 .name = "get_preamble"},
10085 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
10088 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
10089 #ifdef CONFIG_IPW2200_MONITOR
10091 IPW_PRIV_SET_MONITOR,
10092 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
10093 #endif /* CONFIG_IPW2200_MONITOR */
10096 static iw_handler ipw_priv_handler[] = {
10097 ipw_wx_set_powermode,
10098 ipw_wx_get_powermode,
10099 ipw_wx_set_wireless_mode,
10100 ipw_wx_get_wireless_mode,
10101 ipw_wx_set_preamble,
10102 ipw_wx_get_preamble,
10105 #ifdef CONFIG_IPW2200_MONITOR
10106 ipw_wx_set_monitor,
10110 static struct iw_handler_def ipw_wx_handler_def = {
10111 .standard = ipw_wx_handlers,
10112 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
10113 .num_private = ARRAY_SIZE(ipw_priv_handler),
10114 .num_private_args = ARRAY_SIZE(ipw_priv_args),
10115 .private = ipw_priv_handler,
10116 .private_args = ipw_priv_args,
10117 .get_wireless_stats = ipw_get_wireless_stats,
10121 * Get wireless statistics.
10122 * Called by /proc/net/wireless
10123 * Also called by SIOCGIWSTATS
10125 static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
10127 struct ipw_priv *priv = libipw_priv(dev);
10128 struct iw_statistics *wstats;
10130 wstats = &priv->wstats;
10132 /* if hw is disabled, then ipw_get_ordinal() can't be called.
10133 * netdev->get_wireless_stats seems to be called before fw is
10134 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
10135 * and associated; if not associcated, the values are all meaningless
10136 * anyway, so set them all to NULL and INVALID */
10137 if (!(priv->status & STATUS_ASSOCIATED)) {
10138 wstats->miss.beacon = 0;
10139 wstats->discard.retries = 0;
10140 wstats->qual.qual = 0;
10141 wstats->qual.level = 0;
10142 wstats->qual.noise = 0;
10143 wstats->qual.updated = 7;
10144 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
10145 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
10149 wstats->qual.qual = priv->quality;
10150 wstats->qual.level = priv->exp_avg_rssi;
10151 wstats->qual.noise = priv->exp_avg_noise;
10152 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
10153 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
10155 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
10156 wstats->discard.retries = priv->last_tx_failures;
10157 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
10159 /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
10160 goto fail_get_ordinal;
10161 wstats->discard.retries += tx_retry; */
10166 /* net device stuff */
10168 static void init_sys_config(struct ipw_sys_config *sys_config)
10170 memset(sys_config, 0, sizeof(struct ipw_sys_config));
10171 sys_config->bt_coexistence = 0;
10172 sys_config->answer_broadcast_ssid_probe = 0;
10173 sys_config->accept_all_data_frames = 0;
10174 sys_config->accept_non_directed_frames = 1;
10175 sys_config->exclude_unicast_unencrypted = 0;
10176 sys_config->disable_unicast_decryption = 1;
10177 sys_config->exclude_multicast_unencrypted = 0;
10178 sys_config->disable_multicast_decryption = 1;
10179 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
10180 antenna = CFG_SYS_ANTENNA_BOTH;
10181 sys_config->antenna_diversity = antenna;
10182 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
10183 sys_config->dot11g_auto_detection = 0;
10184 sys_config->enable_cts_to_self = 0;
10185 sys_config->bt_coexist_collision_thr = 0;
10186 sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */
10187 sys_config->silence_threshold = 0x1e;
10190 static int ipw_net_open(struct net_device *dev)
10192 IPW_DEBUG_INFO("dev->open\n");
10193 netif_start_queue(dev);
10197 static int ipw_net_stop(struct net_device *dev)
10199 IPW_DEBUG_INFO("dev->close\n");
10200 netif_stop_queue(dev);
10207 modify to send one tfd per fragment instead of using chunking. otherwise
10208 we need to heavily modify the libipw_skb_to_txb.
10211 static int ipw_tx_skb(struct ipw_priv *priv, struct libipw_txb *txb,
10214 struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *)
10215 txb->fragments[0]->data;
10217 struct tfd_frame *tfd;
10218 #ifdef CONFIG_IPW2200_QOS
10219 int tx_id = ipw_get_tx_queue_number(priv, pri);
10220 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10222 struct clx2_tx_queue *txq = &priv->txq[0];
10224 struct clx2_queue *q = &txq->q;
10225 u8 id, hdr_len, unicast;
10228 if (!(priv->status & STATUS_ASSOCIATED))
10231 hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
10232 switch (priv->ieee->iw_mode) {
10233 case IW_MODE_ADHOC:
10234 unicast = !is_multicast_ether_addr(hdr->addr1);
10235 id = ipw_find_station(priv, hdr->addr1);
10236 if (id == IPW_INVALID_STATION) {
10237 id = ipw_add_station(priv, hdr->addr1);
10238 if (id == IPW_INVALID_STATION) {
10239 IPW_WARNING("Attempt to send data to "
10240 "invalid cell: %pM\n",
10247 case IW_MODE_INFRA:
10249 unicast = !is_multicast_ether_addr(hdr->addr3);
10254 tfd = &txq->bd[q->first_empty];
10255 txq->txb[q->first_empty] = txb;
10256 memset(tfd, 0, sizeof(*tfd));
10257 tfd->u.data.station_number = id;
10259 tfd->control_flags.message_type = TX_FRAME_TYPE;
10260 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10262 tfd->u.data.cmd_id = DINO_CMD_TX;
10263 tfd->u.data.len = cpu_to_le16(txb->payload_size);
10265 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
10266 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
10268 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
10270 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10271 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
10273 fc = le16_to_cpu(hdr->frame_ctl);
10274 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
10276 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10278 if (likely(unicast))
10279 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10281 if (txb->encrypted && !priv->ieee->host_encrypt) {
10282 switch (priv->ieee->sec.level) {
10284 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10285 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
10286 /* XXX: ACK flag must be set for CCMP even if it
10287 * is a multicast/broadcast packet, because CCMP
10288 * group communication encrypted by GTK is
10289 * actually done by the AP. */
10291 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10293 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10294 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10295 tfd->u.data.key_index = 0;
10296 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10299 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10300 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
10301 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10302 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10303 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10306 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10307 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
10308 tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx;
10309 if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <=
10311 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10313 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10318 printk(KERN_ERR "Unknown security level %d\n",
10319 priv->ieee->sec.level);
10323 /* No hardware encryption */
10324 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10326 #ifdef CONFIG_IPW2200_QOS
10327 if (fc & IEEE80211_STYPE_QOS_DATA)
10328 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
10329 #endif /* CONFIG_IPW2200_QOS */
10332 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10334 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10335 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10336 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10337 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10338 i, le32_to_cpu(tfd->u.data.num_chunks),
10339 txb->fragments[i]->len - hdr_len);
10340 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
10341 i, tfd->u.data.num_chunks,
10342 txb->fragments[i]->len - hdr_len);
10343 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
10344 txb->fragments[i]->len - hdr_len);
10346 tfd->u.data.chunk_ptr[i] =
10347 cpu_to_le32(pci_map_single
10349 txb->fragments[i]->data + hdr_len,
10350 txb->fragments[i]->len - hdr_len,
10351 PCI_DMA_TODEVICE));
10352 tfd->u.data.chunk_len[i] =
10353 cpu_to_le16(txb->fragments[i]->len - hdr_len);
10356 if (i != txb->nr_frags) {
10357 struct sk_buff *skb;
10358 u16 remaining_bytes = 0;
10361 for (j = i; j < txb->nr_frags; j++)
10362 remaining_bytes += txb->fragments[j]->len - hdr_len;
10364 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10366 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10368 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
10369 for (j = i; j < txb->nr_frags; j++) {
10370 int size = txb->fragments[j]->len - hdr_len;
10372 printk(KERN_INFO "Adding frag %d %d...\n",
10374 memcpy(skb_put(skb, size),
10375 txb->fragments[j]->data + hdr_len, size);
10377 dev_kfree_skb_any(txb->fragments[i]);
10378 txb->fragments[i] = skb;
10379 tfd->u.data.chunk_ptr[i] =
10380 cpu_to_le32(pci_map_single
10381 (priv->pci_dev, skb->data,
10383 PCI_DMA_TODEVICE));
10385 le32_add_cpu(&tfd->u.data.num_chunks, 1);
10390 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10391 ipw_write32(priv, q->reg_w, q->first_empty);
10393 if (ipw_tx_queue_space(q) < q->high_mark)
10394 netif_stop_queue(priv->net_dev);
10396 return NETDEV_TX_OK;
10399 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
10400 libipw_txb_free(txb);
10401 return NETDEV_TX_OK;
10404 static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10406 struct ipw_priv *priv = libipw_priv(dev);
10407 #ifdef CONFIG_IPW2200_QOS
10408 int tx_id = ipw_get_tx_queue_number(priv, pri);
10409 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10411 struct clx2_tx_queue *txq = &priv->txq[0];
10412 #endif /* CONFIG_IPW2200_QOS */
10414 if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark)
10420 #ifdef CONFIG_IPW2200_PROMISCUOUS
10421 static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
10422 struct libipw_txb *txb)
10424 struct libipw_rx_stats dummystats;
10425 struct ieee80211_hdr *hdr;
10427 u16 filter = priv->prom_priv->filter;
10430 if (filter & IPW_PROM_NO_TX)
10433 memset(&dummystats, 0, sizeof(dummystats));
10435 /* Filtering of fragment chains is done agains the first fragment */
10436 hdr = (void *)txb->fragments[0]->data;
10437 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
10438 if (filter & IPW_PROM_NO_MGMT)
10440 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10442 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
10443 if (filter & IPW_PROM_NO_CTL)
10445 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10447 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
10448 if (filter & IPW_PROM_NO_DATA)
10450 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10454 for(n=0; n<txb->nr_frags; ++n) {
10455 struct sk_buff *src = txb->fragments[n];
10456 struct sk_buff *dst;
10457 struct ieee80211_radiotap_header *rt_hdr;
10461 hdr = (void *)src->data;
10462 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
10466 dst = alloc_skb(len + sizeof(*rt_hdr), GFP_ATOMIC);
10470 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10472 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10473 rt_hdr->it_pad = 0;
10474 rt_hdr->it_present = 0; /* after all, it's just an idea */
10475 rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL);
10477 *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
10478 ieee80211chan2mhz(priv->channel));
10479 if (priv->channel > 14) /* 802.11a */
10480 *(__le16*)skb_put(dst, sizeof(u16)) =
10481 cpu_to_le16(IEEE80211_CHAN_OFDM |
10482 IEEE80211_CHAN_5GHZ);
10483 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
10484 *(__le16*)skb_put(dst, sizeof(u16)) =
10485 cpu_to_le16(IEEE80211_CHAN_CCK |
10486 IEEE80211_CHAN_2GHZ);
10488 *(__le16*)skb_put(dst, sizeof(u16)) =
10489 cpu_to_le16(IEEE80211_CHAN_OFDM |
10490 IEEE80211_CHAN_2GHZ);
10492 rt_hdr->it_len = cpu_to_le16(dst->len);
10494 skb_copy_from_linear_data(src, skb_put(dst, len), len);
10496 if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats))
10497 dev_kfree_skb_any(dst);
10502 static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb,
10503 struct net_device *dev, int pri)
10505 struct ipw_priv *priv = libipw_priv(dev);
10506 unsigned long flags;
10509 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
10510 spin_lock_irqsave(&priv->lock, flags);
10512 #ifdef CONFIG_IPW2200_PROMISCUOUS
10513 if (rtap_iface && netif_running(priv->prom_net_dev))
10514 ipw_handle_promiscuous_tx(priv, txb);
10517 ret = ipw_tx_skb(priv, txb, pri);
10518 if (ret == NETDEV_TX_OK)
10519 __ipw_led_activity_on(priv);
10520 spin_unlock_irqrestore(&priv->lock, flags);
10525 static void ipw_net_set_multicast_list(struct net_device *dev)
10530 static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10532 struct ipw_priv *priv = libipw_priv(dev);
10533 struct sockaddr *addr = p;
10535 if (!is_valid_ether_addr(addr->sa_data))
10536 return -EADDRNOTAVAIL;
10537 mutex_lock(&priv->mutex);
10538 priv->config |= CFG_CUSTOM_MAC;
10539 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
10540 printk(KERN_INFO "%s: Setting MAC to %pM\n",
10541 priv->net_dev->name, priv->mac_addr);
10542 queue_work(priv->workqueue, &priv->adapter_restart);
10543 mutex_unlock(&priv->mutex);
10547 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
10548 struct ethtool_drvinfo *info)
10550 struct ipw_priv *p = libipw_priv(dev);
10555 strcpy(info->driver, DRV_NAME);
10556 strcpy(info->version, DRV_VERSION);
10558 len = sizeof(vers);
10559 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10560 len = sizeof(date);
10561 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10563 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
10565 strcpy(info->bus_info, pci_name(p->pci_dev));
10566 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
10569 static u32 ipw_ethtool_get_link(struct net_device *dev)
10571 struct ipw_priv *priv = libipw_priv(dev);
10572 return (priv->status & STATUS_ASSOCIATED) != 0;
10575 static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10577 return IPW_EEPROM_IMAGE_SIZE;
10580 static int ipw_ethtool_get_eeprom(struct net_device *dev,
10581 struct ethtool_eeprom *eeprom, u8 * bytes)
10583 struct ipw_priv *p = libipw_priv(dev);
10585 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
10587 mutex_lock(&p->mutex);
10588 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
10589 mutex_unlock(&p->mutex);
10593 static int ipw_ethtool_set_eeprom(struct net_device *dev,
10594 struct ethtool_eeprom *eeprom, u8 * bytes)
10596 struct ipw_priv *p = libipw_priv(dev);
10599 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
10601 mutex_lock(&p->mutex);
10602 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
10603 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10604 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
10605 mutex_unlock(&p->mutex);
10609 static const struct ethtool_ops ipw_ethtool_ops = {
10610 .get_link = ipw_ethtool_get_link,
10611 .get_drvinfo = ipw_ethtool_get_drvinfo,
10612 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10613 .get_eeprom = ipw_ethtool_get_eeprom,
10614 .set_eeprom = ipw_ethtool_set_eeprom,
10617 static irqreturn_t ipw_isr(int irq, void *data)
10619 struct ipw_priv *priv = data;
10620 u32 inta, inta_mask;
10625 spin_lock(&priv->irq_lock);
10627 if (!(priv->status & STATUS_INT_ENABLED)) {
10628 /* IRQ is disabled */
10632 inta = ipw_read32(priv, IPW_INTA_RW);
10633 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
10635 if (inta == 0xFFFFFFFF) {
10636 /* Hardware disappeared */
10637 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10641 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
10642 /* Shared interrupt */
10646 /* tell the device to stop sending interrupts */
10647 __ipw_disable_interrupts(priv);
10649 /* ack current interrupts */
10650 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10651 ipw_write32(priv, IPW_INTA_RW, inta);
10653 /* Cache INTA value for our tasklet */
10654 priv->isr_inta = inta;
10656 tasklet_schedule(&priv->irq_tasklet);
10658 spin_unlock(&priv->irq_lock);
10660 return IRQ_HANDLED;
10662 spin_unlock(&priv->irq_lock);
10666 static void ipw_rf_kill(void *adapter)
10668 struct ipw_priv *priv = adapter;
10669 unsigned long flags;
10671 spin_lock_irqsave(&priv->lock, flags);
10673 if (rf_kill_active(priv)) {
10674 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10675 if (priv->workqueue)
10676 queue_delayed_work(priv->workqueue,
10677 &priv->rf_kill, 2 * HZ);
10681 /* RF Kill is now disabled, so bring the device back up */
10683 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10684 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10687 /* we can not do an adapter restart while inside an irq lock */
10688 queue_work(priv->workqueue, &priv->adapter_restart);
10690 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10694 spin_unlock_irqrestore(&priv->lock, flags);
10697 static void ipw_bg_rf_kill(struct work_struct *work)
10699 struct ipw_priv *priv =
10700 container_of(work, struct ipw_priv, rf_kill.work);
10701 mutex_lock(&priv->mutex);
10703 mutex_unlock(&priv->mutex);
10706 static void ipw_link_up(struct ipw_priv *priv)
10708 priv->last_seq_num = -1;
10709 priv->last_frag_num = -1;
10710 priv->last_packet_time = 0;
10712 netif_carrier_on(priv->net_dev);
10714 cancel_delayed_work(&priv->request_scan);
10715 cancel_delayed_work(&priv->request_direct_scan);
10716 cancel_delayed_work(&priv->request_passive_scan);
10717 cancel_delayed_work(&priv->scan_event);
10718 ipw_reset_stats(priv);
10719 /* Ensure the rate is updated immediately */
10720 priv->last_rate = ipw_get_current_rate(priv);
10721 ipw_gather_stats(priv);
10722 ipw_led_link_up(priv);
10723 notify_wx_assoc_event(priv);
10725 if (priv->config & CFG_BACKGROUND_SCAN)
10726 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10729 static void ipw_bg_link_up(struct work_struct *work)
10731 struct ipw_priv *priv =
10732 container_of(work, struct ipw_priv, link_up);
10733 mutex_lock(&priv->mutex);
10735 mutex_unlock(&priv->mutex);
10738 static void ipw_link_down(struct ipw_priv *priv)
10740 ipw_led_link_down(priv);
10741 netif_carrier_off(priv->net_dev);
10742 notify_wx_assoc_event(priv);
10744 /* Cancel any queued work ... */
10745 cancel_delayed_work(&priv->request_scan);
10746 cancel_delayed_work(&priv->request_direct_scan);
10747 cancel_delayed_work(&priv->request_passive_scan);
10748 cancel_delayed_work(&priv->adhoc_check);
10749 cancel_delayed_work(&priv->gather_stats);
10751 ipw_reset_stats(priv);
10753 if (!(priv->status & STATUS_EXIT_PENDING)) {
10754 /* Queue up another scan... */
10755 queue_delayed_work(priv->workqueue, &priv->request_scan, 0);
10757 cancel_delayed_work(&priv->scan_event);
10760 static void ipw_bg_link_down(struct work_struct *work)
10762 struct ipw_priv *priv =
10763 container_of(work, struct ipw_priv, link_down);
10764 mutex_lock(&priv->mutex);
10765 ipw_link_down(priv);
10766 mutex_unlock(&priv->mutex);
10769 static int __devinit ipw_setup_deferred_work(struct ipw_priv *priv)
10773 priv->workqueue = create_workqueue(DRV_NAME);
10774 init_waitqueue_head(&priv->wait_command_queue);
10775 init_waitqueue_head(&priv->wait_state);
10777 INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check);
10778 INIT_WORK(&priv->associate, ipw_bg_associate);
10779 INIT_WORK(&priv->disassociate, ipw_bg_disassociate);
10780 INIT_WORK(&priv->system_config, ipw_system_config);
10781 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish);
10782 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart);
10783 INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill);
10784 INIT_WORK(&priv->up, ipw_bg_up);
10785 INIT_WORK(&priv->down, ipw_bg_down);
10786 INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan);
10787 INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan);
10788 INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan);
10789 INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event);
10790 INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats);
10791 INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan);
10792 INIT_WORK(&priv->roam, ipw_bg_roam);
10793 INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check);
10794 INIT_WORK(&priv->link_up, ipw_bg_link_up);
10795 INIT_WORK(&priv->link_down, ipw_bg_link_down);
10796 INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on);
10797 INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off);
10798 INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off);
10799 INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network);
10801 #ifdef CONFIG_IPW2200_QOS
10802 INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate);
10803 #endif /* CONFIG_IPW2200_QOS */
10805 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10806 ipw_irq_tasklet, (unsigned long)priv);
10811 static void shim__set_security(struct net_device *dev,
10812 struct libipw_security *sec)
10814 struct ipw_priv *priv = libipw_priv(dev);
10816 for (i = 0; i < 4; i++) {
10817 if (sec->flags & (1 << i)) {
10818 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
10819 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
10820 if (sec->key_sizes[i] == 0)
10821 priv->ieee->sec.flags &= ~(1 << i);
10823 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
10824 sec->key_sizes[i]);
10825 priv->ieee->sec.flags |= (1 << i);
10827 priv->status |= STATUS_SECURITY_UPDATED;
10828 } else if (sec->level != SEC_LEVEL_1)
10829 priv->ieee->sec.flags &= ~(1 << i);
10832 if (sec->flags & SEC_ACTIVE_KEY) {
10833 if (sec->active_key <= 3) {
10834 priv->ieee->sec.active_key = sec->active_key;
10835 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
10837 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
10838 priv->status |= STATUS_SECURITY_UPDATED;
10840 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
10842 if ((sec->flags & SEC_AUTH_MODE) &&
10843 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10844 priv->ieee->sec.auth_mode = sec->auth_mode;
10845 priv->ieee->sec.flags |= SEC_AUTH_MODE;
10846 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10847 priv->capability |= CAP_SHARED_KEY;
10849 priv->capability &= ~CAP_SHARED_KEY;
10850 priv->status |= STATUS_SECURITY_UPDATED;
10853 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10854 priv->ieee->sec.flags |= SEC_ENABLED;
10855 priv->ieee->sec.enabled = sec->enabled;
10856 priv->status |= STATUS_SECURITY_UPDATED;
10858 priv->capability |= CAP_PRIVACY_ON;
10860 priv->capability &= ~CAP_PRIVACY_ON;
10863 if (sec->flags & SEC_ENCRYPT)
10864 priv->ieee->sec.encrypt = sec->encrypt;
10866 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10867 priv->ieee->sec.level = sec->level;
10868 priv->ieee->sec.flags |= SEC_LEVEL;
10869 priv->status |= STATUS_SECURITY_UPDATED;
10872 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10873 ipw_set_hwcrypto_keys(priv);
10875 /* To match current functionality of ipw2100 (which works well w/
10876 * various supplicants, we don't force a disassociate if the
10877 * privacy capability changes ... */
10879 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
10880 (((priv->assoc_request.capability &
10881 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) ||
10882 (!(priv->assoc_request.capability &
10883 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) {
10884 IPW_DEBUG_ASSOC("Disassociating due to capability "
10886 ipw_disassociate(priv);
10891 static int init_supported_rates(struct ipw_priv *priv,
10892 struct ipw_supported_rates *rates)
10894 /* TODO: Mask out rates based on priv->rates_mask */
10896 memset(rates, 0, sizeof(*rates));
10897 /* configure supported rates */
10898 switch (priv->ieee->freq_band) {
10899 case LIBIPW_52GHZ_BAND:
10900 rates->ieee_mode = IPW_A_MODE;
10901 rates->purpose = IPW_RATE_CAPABILITIES;
10902 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10903 LIBIPW_OFDM_DEFAULT_RATES_MASK);
10906 default: /* Mixed or 2.4Ghz */
10907 rates->ieee_mode = IPW_G_MODE;
10908 rates->purpose = IPW_RATE_CAPABILITIES;
10909 ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION,
10910 LIBIPW_CCK_DEFAULT_RATES_MASK);
10911 if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) {
10912 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10913 LIBIPW_OFDM_DEFAULT_RATES_MASK);
10921 static int ipw_config(struct ipw_priv *priv)
10923 /* This is only called from ipw_up, which resets/reloads the firmware
10924 so, we don't need to first disable the card before we configure
10926 if (ipw_set_tx_power(priv))
10929 /* initialize adapter address */
10930 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10933 /* set basic system config settings */
10934 init_sys_config(&priv->sys_config);
10936 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10937 * Does not support BT priority yet (don't abort or defer our Tx) */
10939 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
10941 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10942 priv->sys_config.bt_coexistence
10943 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
10944 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10945 priv->sys_config.bt_coexistence
10946 |= CFG_BT_COEXISTENCE_OOB;
10949 #ifdef CONFIG_IPW2200_PROMISCUOUS
10950 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10951 priv->sys_config.accept_all_data_frames = 1;
10952 priv->sys_config.accept_non_directed_frames = 1;
10953 priv->sys_config.accept_all_mgmt_bcpr = 1;
10954 priv->sys_config.accept_all_mgmt_frames = 1;
10958 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10959 priv->sys_config.answer_broadcast_ssid_probe = 1;
10961 priv->sys_config.answer_broadcast_ssid_probe = 0;
10963 if (ipw_send_system_config(priv))
10966 init_supported_rates(priv, &priv->rates);
10967 if (ipw_send_supported_rates(priv, &priv->rates))
10970 /* Set request-to-send threshold */
10971 if (priv->rts_threshold) {
10972 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10975 #ifdef CONFIG_IPW2200_QOS
10976 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10977 ipw_qos_activate(priv, NULL);
10978 #endif /* CONFIG_IPW2200_QOS */
10980 if (ipw_set_random_seed(priv))
10983 /* final state transition to the RUN state */
10984 if (ipw_send_host_complete(priv))
10987 priv->status |= STATUS_INIT;
10989 ipw_led_init(priv);
10990 ipw_led_radio_on(priv);
10991 priv->notif_missed_beacons = 0;
10993 /* Set hardware WEP key if it is configured. */
10994 if ((priv->capability & CAP_PRIVACY_ON) &&
10995 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10996 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10997 ipw_set_hwcrypto_keys(priv);
11008 * These tables have been tested in conjunction with the
11009 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
11011 * Altering this values, using it on other hardware, or in geographies
11012 * not intended for resale of the above mentioned Intel adapters has
11015 * Remember to update the table in README.ipw2200 when changing this
11019 static const struct libipw_geo ipw_geos[] = {
11023 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11024 {2427, 4}, {2432, 5}, {2437, 6},
11025 {2442, 7}, {2447, 8}, {2452, 9},
11026 {2457, 10}, {2462, 11}},
11029 { /* Custom US/Canada */
11032 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11033 {2427, 4}, {2432, 5}, {2437, 6},
11034 {2442, 7}, {2447, 8}, {2452, 9},
11035 {2457, 10}, {2462, 11}},
11041 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11042 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11043 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11044 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}},
11047 { /* Rest of World */
11050 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11051 {2427, 4}, {2432, 5}, {2437, 6},
11052 {2442, 7}, {2447, 8}, {2452, 9},
11053 {2457, 10}, {2462, 11}, {2467, 12},
11057 { /* Custom USA & Europe & High */
11060 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11061 {2427, 4}, {2432, 5}, {2437, 6},
11062 {2442, 7}, {2447, 8}, {2452, 9},
11063 {2457, 10}, {2462, 11}},
11069 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11070 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11071 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11072 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11080 { /* Custom NA & Europe */
11083 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11084 {2427, 4}, {2432, 5}, {2437, 6},
11085 {2442, 7}, {2447, 8}, {2452, 9},
11086 {2457, 10}, {2462, 11}},
11092 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11093 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11094 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11095 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11096 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11097 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11098 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11099 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11100 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
11103 { /* Custom Japan */
11106 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11107 {2427, 4}, {2432, 5}, {2437, 6},
11108 {2442, 7}, {2447, 8}, {2452, 9},
11109 {2457, 10}, {2462, 11}},
11111 .a = {{5170, 34}, {5190, 38},
11112 {5210, 42}, {5230, 46}},
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}},
11127 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11128 {2427, 4}, {2432, 5}, {2437, 6},
11129 {2442, 7}, {2447, 8}, {2452, 9},
11130 {2457, 10}, {2462, 11}, {2467, 12},
11137 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11138 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11139 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11140 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11141 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11142 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11143 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11144 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11145 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11146 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11147 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11148 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11149 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11150 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11151 {5700, 140, LIBIPW_CH_PASSIVE_ONLY}},
11154 { /* Custom Japan */
11157 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11158 {2427, 4}, {2432, 5}, {2437, 6},
11159 {2442, 7}, {2447, 8}, {2452, 9},
11160 {2457, 10}, {2462, 11}, {2467, 12},
11161 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}},
11163 .a = {{5170, 34}, {5190, 38},
11164 {5210, 42}, {5230, 46}},
11167 { /* Rest of World */
11170 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11171 {2427, 4}, {2432, 5}, {2437, 6},
11172 {2442, 7}, {2447, 8}, {2452, 9},
11173 {2457, 10}, {2462, 11}, {2467, 12},
11174 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY |
11175 LIBIPW_CH_PASSIVE_ONLY}},
11181 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11182 {2427, 4}, {2432, 5}, {2437, 6},
11183 {2442, 7}, {2447, 8}, {2452, 9},
11184 {2457, 10}, {2462, 11},
11185 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11186 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
11188 .a = {{5745, 149}, {5765, 153},
11189 {5785, 157}, {5805, 161}},
11192 { /* Custom Europe */
11195 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11196 {2427, 4}, {2432, 5}, {2437, 6},
11197 {2442, 7}, {2447, 8}, {2452, 9},
11198 {2457, 10}, {2462, 11},
11199 {2467, 12}, {2472, 13}},
11201 .a = {{5180, 36}, {5200, 40},
11202 {5220, 44}, {5240, 48}},
11208 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11209 {2427, 4}, {2432, 5}, {2437, 6},
11210 {2442, 7}, {2447, 8}, {2452, 9},
11211 {2457, 10}, {2462, 11},
11212 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11213 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
11215 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11216 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11217 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11218 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11219 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11220 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11221 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11222 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11223 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11224 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11225 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11226 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11227 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11228 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11229 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11230 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11231 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11232 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11233 {5700, 140, LIBIPW_CH_PASSIVE_ONLY},
11234 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11235 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11236 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11237 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11238 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
11244 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11245 {2427, 4}, {2432, 5}, {2437, 6},
11246 {2442, 7}, {2447, 8}, {2452, 9},
11247 {2457, 10}, {2462, 11}},
11249 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11250 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11251 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11252 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11253 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11254 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11255 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11256 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11257 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11258 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11259 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11260 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11261 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
11265 #define MAX_HW_RESTARTS 5
11266 static int ipw_up(struct ipw_priv *priv)
11270 /* Age scan list entries found before suspend */
11271 if (priv->suspend_time) {
11272 libipw_networks_age(priv->ieee, priv->suspend_time);
11273 priv->suspend_time = 0;
11276 if (priv->status & STATUS_EXIT_PENDING)
11279 if (cmdlog && !priv->cmdlog) {
11280 priv->cmdlog = kcalloc(cmdlog, sizeof(*priv->cmdlog),
11282 if (priv->cmdlog == NULL) {
11283 IPW_ERROR("Error allocating %d command log entries.\n",
11287 priv->cmdlog_len = cmdlog;
11291 for (i = 0; i < MAX_HW_RESTARTS; i++) {
11292 /* Load the microcode, firmware, and eeprom.
11293 * Also start the clocks. */
11294 rc = ipw_load(priv);
11296 IPW_ERROR("Unable to load firmware: %d\n", rc);
11300 ipw_init_ordinals(priv);
11301 if (!(priv->config & CFG_CUSTOM_MAC))
11302 eeprom_parse_mac(priv, priv->mac_addr);
11303 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
11304 memcpy(priv->net_dev->perm_addr, priv->mac_addr, ETH_ALEN);
11306 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11307 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11308 ipw_geos[j].name, 3))
11311 if (j == ARRAY_SIZE(ipw_geos)) {
11312 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11313 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11314 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11315 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
11318 if (libipw_set_geo(priv->ieee, &ipw_geos[j])) {
11319 IPW_WARNING("Could not set geography.");
11323 if (priv->status & STATUS_RF_KILL_SW) {
11324 IPW_WARNING("Radio disabled by module parameter.\n");
11326 } else if (rf_kill_active(priv)) {
11327 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11328 "Kill switch must be turned off for "
11329 "wireless networking to work.\n");
11330 queue_delayed_work(priv->workqueue, &priv->rf_kill,
11335 rc = ipw_config(priv);
11337 IPW_DEBUG_INFO("Configured device on count %i\n", i);
11339 /* If configure to try and auto-associate, kick
11341 queue_delayed_work(priv->workqueue,
11342 &priv->request_scan, 0);
11347 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
11348 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11349 i, MAX_HW_RESTARTS);
11351 /* We had an error bringing up the hardware, so take it
11352 * all the way back down so we can try again */
11356 /* tried to restart and config the device for as long as our
11357 * patience could withstand */
11358 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
11363 static void ipw_bg_up(struct work_struct *work)
11365 struct ipw_priv *priv =
11366 container_of(work, struct ipw_priv, up);
11367 mutex_lock(&priv->mutex);
11369 mutex_unlock(&priv->mutex);
11372 static void ipw_deinit(struct ipw_priv *priv)
11376 if (priv->status & STATUS_SCANNING) {
11377 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11378 ipw_abort_scan(priv);
11381 if (priv->status & STATUS_ASSOCIATED) {
11382 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11383 ipw_disassociate(priv);
11386 ipw_led_shutdown(priv);
11388 /* Wait up to 1s for status to change to not scanning and not
11389 * associated (disassociation can take a while for a ful 802.11
11391 for (i = 1000; i && (priv->status &
11392 (STATUS_DISASSOCIATING |
11393 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11396 if (priv->status & (STATUS_DISASSOCIATING |
11397 STATUS_ASSOCIATED | STATUS_SCANNING))
11398 IPW_DEBUG_INFO("Still associated or scanning...\n");
11400 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11402 /* Attempt to disable the card */
11403 ipw_send_card_disable(priv, 0);
11405 priv->status &= ~STATUS_INIT;
11408 static void ipw_down(struct ipw_priv *priv)
11410 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11412 priv->status |= STATUS_EXIT_PENDING;
11414 if (ipw_is_init(priv))
11417 /* Wipe out the EXIT_PENDING status bit if we are not actually
11418 * exiting the module */
11420 priv->status &= ~STATUS_EXIT_PENDING;
11422 /* tell the device to stop sending interrupts */
11423 ipw_disable_interrupts(priv);
11425 /* Clear all bits but the RF Kill */
11426 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
11427 netif_carrier_off(priv->net_dev);
11429 ipw_stop_nic(priv);
11431 ipw_led_radio_off(priv);
11434 static void ipw_bg_down(struct work_struct *work)
11436 struct ipw_priv *priv =
11437 container_of(work, struct ipw_priv, down);
11438 mutex_lock(&priv->mutex);
11440 mutex_unlock(&priv->mutex);
11443 /* Called by register_netdev() */
11444 static int ipw_net_init(struct net_device *dev)
11447 struct ipw_priv *priv = libipw_priv(dev);
11448 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
11449 struct wireless_dev *wdev = &priv->ieee->wdev;
11450 mutex_lock(&priv->mutex);
11452 if (ipw_up(priv)) {
11457 memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
11459 /* fill-out priv->ieee->bg_band */
11460 if (geo->bg_channels) {
11461 struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
11463 bg_band->band = IEEE80211_BAND_2GHZ;
11464 bg_band->n_channels = geo->bg_channels;
11465 bg_band->channels =
11466 kzalloc(geo->bg_channels *
11467 sizeof(struct ieee80211_channel), GFP_KERNEL);
11468 /* translate geo->bg to bg_band.channels */
11469 for (i = 0; i < geo->bg_channels; i++) {
11470 bg_band->channels[i].band = IEEE80211_BAND_2GHZ;
11471 bg_band->channels[i].center_freq = geo->bg[i].freq;
11472 bg_band->channels[i].hw_value = geo->bg[i].channel;
11473 bg_band->channels[i].max_power = geo->bg[i].max_power;
11474 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11475 bg_band->channels[i].flags |=
11476 IEEE80211_CHAN_PASSIVE_SCAN;
11477 if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
11478 bg_band->channels[i].flags |=
11479 IEEE80211_CHAN_NO_IBSS;
11480 if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
11481 bg_band->channels[i].flags |=
11482 IEEE80211_CHAN_RADAR;
11483 /* No equivalent for LIBIPW_CH_80211H_RULES,
11484 LIBIPW_CH_UNIFORM_SPREADING, or
11485 LIBIPW_CH_B_ONLY... */
11487 /* point at bitrate info */
11488 bg_band->bitrates = ipw2200_bg_rates;
11489 bg_band->n_bitrates = ipw2200_num_bg_rates;
11491 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band;
11494 /* fill-out priv->ieee->a_band */
11495 if (geo->a_channels) {
11496 struct ieee80211_supported_band *a_band = &priv->ieee->a_band;
11498 a_band->band = IEEE80211_BAND_5GHZ;
11499 a_band->n_channels = geo->a_channels;
11501 kzalloc(geo->a_channels *
11502 sizeof(struct ieee80211_channel), GFP_KERNEL);
11503 /* translate geo->bg to a_band.channels */
11504 for (i = 0; i < geo->a_channels; i++) {
11505 a_band->channels[i].band = IEEE80211_BAND_2GHZ;
11506 a_band->channels[i].center_freq = geo->a[i].freq;
11507 a_band->channels[i].hw_value = geo->a[i].channel;
11508 a_band->channels[i].max_power = geo->a[i].max_power;
11509 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11510 a_band->channels[i].flags |=
11511 IEEE80211_CHAN_PASSIVE_SCAN;
11512 if (geo->a[i].flags & LIBIPW_CH_NO_IBSS)
11513 a_band->channels[i].flags |=
11514 IEEE80211_CHAN_NO_IBSS;
11515 if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)
11516 a_band->channels[i].flags |=
11517 IEEE80211_CHAN_RADAR;
11518 /* No equivalent for LIBIPW_CH_80211H_RULES,
11519 LIBIPW_CH_UNIFORM_SPREADING, or
11520 LIBIPW_CH_B_ONLY... */
11522 /* point at bitrate info */
11523 a_band->bitrates = ipw2200_a_rates;
11524 a_band->n_bitrates = ipw2200_num_a_rates;
11526 wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = a_band;
11529 set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
11531 /* With that information in place, we can now register the wiphy... */
11532 if (wiphy_register(wdev->wiphy)) {
11538 mutex_unlock(&priv->mutex);
11542 /* PCI driver stuff */
11543 static DEFINE_PCI_DEVICE_TABLE(card_ids) = {
11544 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11545 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11546 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11547 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11548 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11549 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11550 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11551 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11552 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11553 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11554 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11555 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11556 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11557 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11558 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11559 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11560 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
11561 {PCI_VDEVICE(INTEL, 0x104f), 0},
11562 {PCI_VDEVICE(INTEL, 0x4220), 0}, /* BG */
11563 {PCI_VDEVICE(INTEL, 0x4221), 0}, /* BG */
11564 {PCI_VDEVICE(INTEL, 0x4223), 0}, /* ABG */
11565 {PCI_VDEVICE(INTEL, 0x4224), 0}, /* ABG */
11567 /* required last entry */
11571 MODULE_DEVICE_TABLE(pci, card_ids);
11573 static struct attribute *ipw_sysfs_entries[] = {
11574 &dev_attr_rf_kill.attr,
11575 &dev_attr_direct_dword.attr,
11576 &dev_attr_indirect_byte.attr,
11577 &dev_attr_indirect_dword.attr,
11578 &dev_attr_mem_gpio_reg.attr,
11579 &dev_attr_command_event_reg.attr,
11580 &dev_attr_nic_type.attr,
11581 &dev_attr_status.attr,
11582 &dev_attr_cfg.attr,
11583 &dev_attr_error.attr,
11584 &dev_attr_event_log.attr,
11585 &dev_attr_cmd_log.attr,
11586 &dev_attr_eeprom_delay.attr,
11587 &dev_attr_ucode_version.attr,
11588 &dev_attr_rtc.attr,
11589 &dev_attr_scan_age.attr,
11590 &dev_attr_led.attr,
11591 &dev_attr_speed_scan.attr,
11592 &dev_attr_net_stats.attr,
11593 &dev_attr_channels.attr,
11594 #ifdef CONFIG_IPW2200_PROMISCUOUS
11595 &dev_attr_rtap_iface.attr,
11596 &dev_attr_rtap_filter.attr,
11601 static struct attribute_group ipw_attribute_group = {
11602 .name = NULL, /* put in device directory */
11603 .attrs = ipw_sysfs_entries,
11606 #ifdef CONFIG_IPW2200_PROMISCUOUS
11607 static int ipw_prom_open(struct net_device *dev)
11609 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
11610 struct ipw_priv *priv = prom_priv->priv;
11612 IPW_DEBUG_INFO("prom dev->open\n");
11613 netif_carrier_off(dev);
11615 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11616 priv->sys_config.accept_all_data_frames = 1;
11617 priv->sys_config.accept_non_directed_frames = 1;
11618 priv->sys_config.accept_all_mgmt_bcpr = 1;
11619 priv->sys_config.accept_all_mgmt_frames = 1;
11621 ipw_send_system_config(priv);
11627 static int ipw_prom_stop(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->stop\n");
11634 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11635 priv->sys_config.accept_all_data_frames = 0;
11636 priv->sys_config.accept_non_directed_frames = 0;
11637 priv->sys_config.accept_all_mgmt_bcpr = 0;
11638 priv->sys_config.accept_all_mgmt_frames = 0;
11640 ipw_send_system_config(priv);
11646 static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb,
11647 struct net_device *dev)
11649 IPW_DEBUG_INFO("prom dev->xmit\n");
11650 dev_kfree_skb(skb);
11651 return NETDEV_TX_OK;
11654 static const struct net_device_ops ipw_prom_netdev_ops = {
11655 .ndo_open = ipw_prom_open,
11656 .ndo_stop = ipw_prom_stop,
11657 .ndo_start_xmit = ipw_prom_hard_start_xmit,
11658 .ndo_change_mtu = libipw_change_mtu,
11659 .ndo_set_mac_address = eth_mac_addr,
11660 .ndo_validate_addr = eth_validate_addr,
11663 static int ipw_prom_alloc(struct ipw_priv *priv)
11667 if (priv->prom_net_dev)
11670 priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv), 1);
11671 if (priv->prom_net_dev == NULL)
11674 priv->prom_priv = libipw_priv(priv->prom_net_dev);
11675 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11676 priv->prom_priv->priv = priv;
11678 strcpy(priv->prom_net_dev->name, "rtap%d");
11679 memcpy(priv->prom_net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
11681 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
11682 priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops;
11684 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
11685 SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev);
11687 rc = register_netdev(priv->prom_net_dev);
11689 free_ieee80211(priv->prom_net_dev, 1);
11690 priv->prom_net_dev = NULL;
11697 static void ipw_prom_free(struct ipw_priv *priv)
11699 if (!priv->prom_net_dev)
11702 unregister_netdev(priv->prom_net_dev);
11703 free_ieee80211(priv->prom_net_dev, 1);
11705 priv->prom_net_dev = NULL;
11710 static const struct net_device_ops ipw_netdev_ops = {
11711 .ndo_init = ipw_net_init,
11712 .ndo_open = ipw_net_open,
11713 .ndo_stop = ipw_net_stop,
11714 .ndo_set_multicast_list = ipw_net_set_multicast_list,
11715 .ndo_set_mac_address = ipw_net_set_mac_address,
11716 .ndo_start_xmit = libipw_xmit,
11717 .ndo_change_mtu = libipw_change_mtu,
11718 .ndo_validate_addr = eth_validate_addr,
11721 static int __devinit ipw_pci_probe(struct pci_dev *pdev,
11722 const struct pci_device_id *ent)
11725 struct net_device *net_dev;
11726 void __iomem *base;
11728 struct ipw_priv *priv;
11731 net_dev = alloc_ieee80211(sizeof(struct ipw_priv), 0);
11732 if (net_dev == NULL) {
11737 priv = libipw_priv(net_dev);
11738 priv->ieee = netdev_priv(net_dev);
11740 priv->net_dev = net_dev;
11741 priv->pci_dev = pdev;
11742 ipw_debug_level = debug;
11743 spin_lock_init(&priv->irq_lock);
11744 spin_lock_init(&priv->lock);
11745 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11746 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
11748 mutex_init(&priv->mutex);
11749 if (pci_enable_device(pdev)) {
11751 goto out_free_ieee80211;
11754 pci_set_master(pdev);
11756 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
11758 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
11760 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11761 goto out_pci_disable_device;
11764 pci_set_drvdata(pdev, priv);
11766 err = pci_request_regions(pdev, DRV_NAME);
11768 goto out_pci_disable_device;
11770 /* We disable the RETRY_TIMEOUT register (0x41) to keep
11771 * PCI Tx retries from interfering with C3 CPU state */
11772 pci_read_config_dword(pdev, 0x40, &val);
11773 if ((val & 0x0000ff00) != 0)
11774 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11776 length = pci_resource_len(pdev, 0);
11777 priv->hw_len = length;
11779 base = pci_ioremap_bar(pdev, 0);
11782 goto out_pci_release_regions;
11785 priv->hw_base = base;
11786 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11787 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11789 err = ipw_setup_deferred_work(priv);
11791 IPW_ERROR("Unable to setup deferred work\n");
11795 ipw_sw_reset(priv, 1);
11797 err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv);
11799 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11800 goto out_destroy_workqueue;
11803 SET_NETDEV_DEV(net_dev, &pdev->dev);
11805 mutex_lock(&priv->mutex);
11807 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11808 priv->ieee->set_security = shim__set_security;
11809 priv->ieee->is_queue_full = ipw_net_is_queue_full;
11811 #ifdef CONFIG_IPW2200_QOS
11812 priv->ieee->is_qos_active = ipw_is_qos_active;
11813 priv->ieee->handle_probe_response = ipw_handle_beacon;
11814 priv->ieee->handle_beacon = ipw_handle_probe_response;
11815 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
11816 #endif /* CONFIG_IPW2200_QOS */
11818 priv->ieee->perfect_rssi = -20;
11819 priv->ieee->worst_rssi = -85;
11821 net_dev->netdev_ops = &ipw_netdev_ops;
11822 priv->wireless_data.spy_data = &priv->ieee->spy_data;
11823 net_dev->wireless_data = &priv->wireless_data;
11824 net_dev->wireless_handlers = &ipw_wx_handler_def;
11825 net_dev->ethtool_ops = &ipw_ethtool_ops;
11826 net_dev->irq = pdev->irq;
11827 net_dev->base_addr = (unsigned long)priv->hw_base;
11828 net_dev->mem_start = pci_resource_start(pdev, 0);
11829 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11831 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11833 IPW_ERROR("failed to create sysfs device attributes\n");
11834 mutex_unlock(&priv->mutex);
11835 goto out_release_irq;
11838 mutex_unlock(&priv->mutex);
11839 err = register_netdev(net_dev);
11841 IPW_ERROR("failed to register network device\n");
11842 goto out_remove_sysfs;
11845 #ifdef CONFIG_IPW2200_PROMISCUOUS
11847 err = ipw_prom_alloc(priv);
11849 IPW_ERROR("Failed to register promiscuous network "
11850 "device (error %d).\n", err);
11851 unregister_netdev(priv->net_dev);
11852 goto out_remove_sysfs;
11857 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11858 "channels, %d 802.11a channels)\n",
11859 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11860 priv->ieee->geo.a_channels);
11865 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11867 free_irq(pdev->irq, priv);
11868 out_destroy_workqueue:
11869 destroy_workqueue(priv->workqueue);
11870 priv->workqueue = NULL;
11872 iounmap(priv->hw_base);
11873 out_pci_release_regions:
11874 pci_release_regions(pdev);
11875 out_pci_disable_device:
11876 pci_disable_device(pdev);
11877 pci_set_drvdata(pdev, NULL);
11878 out_free_ieee80211:
11879 free_ieee80211(priv->net_dev, 0);
11884 static void __devexit ipw_pci_remove(struct pci_dev *pdev)
11886 struct ipw_priv *priv = pci_get_drvdata(pdev);
11887 struct list_head *p, *q;
11893 mutex_lock(&priv->mutex);
11895 priv->status |= STATUS_EXIT_PENDING;
11897 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11899 mutex_unlock(&priv->mutex);
11901 unregister_netdev(priv->net_dev);
11904 ipw_rx_queue_free(priv, priv->rxq);
11907 ipw_tx_queue_free(priv);
11909 if (priv->cmdlog) {
11910 kfree(priv->cmdlog);
11911 priv->cmdlog = NULL;
11913 /* ipw_down will ensure that there is no more pending work
11914 * in the workqueue's, so we can safely remove them now. */
11915 cancel_delayed_work(&priv->adhoc_check);
11916 cancel_delayed_work(&priv->gather_stats);
11917 cancel_delayed_work(&priv->request_scan);
11918 cancel_delayed_work(&priv->request_direct_scan);
11919 cancel_delayed_work(&priv->request_passive_scan);
11920 cancel_delayed_work(&priv->scan_event);
11921 cancel_delayed_work(&priv->rf_kill);
11922 cancel_delayed_work(&priv->scan_check);
11923 destroy_workqueue(priv->workqueue);
11924 priv->workqueue = NULL;
11926 /* Free MAC hash list for ADHOC */
11927 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11928 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
11930 kfree(list_entry(p, struct ipw_ibss_seq, list));
11934 kfree(priv->error);
11935 priv->error = NULL;
11937 #ifdef CONFIG_IPW2200_PROMISCUOUS
11938 ipw_prom_free(priv);
11941 free_irq(pdev->irq, priv);
11942 iounmap(priv->hw_base);
11943 pci_release_regions(pdev);
11944 pci_disable_device(pdev);
11945 pci_set_drvdata(pdev, NULL);
11946 /* wiphy_unregister needs to be here, before free_ieee80211 */
11947 wiphy_unregister(priv->ieee->wdev.wiphy);
11948 kfree(priv->ieee->a_band.channels);
11949 kfree(priv->ieee->bg_band.channels);
11950 free_ieee80211(priv->net_dev, 0);
11955 static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
11957 struct ipw_priv *priv = pci_get_drvdata(pdev);
11958 struct net_device *dev = priv->net_dev;
11960 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11962 /* Take down the device; powers it off, etc. */
11965 /* Remove the PRESENT state of the device */
11966 netif_device_detach(dev);
11968 pci_save_state(pdev);
11969 pci_disable_device(pdev);
11970 pci_set_power_state(pdev, pci_choose_state(pdev, state));
11972 priv->suspend_at = get_seconds();
11977 static int ipw_pci_resume(struct pci_dev *pdev)
11979 struct ipw_priv *priv = pci_get_drvdata(pdev);
11980 struct net_device *dev = priv->net_dev;
11984 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11986 pci_set_power_state(pdev, PCI_D0);
11987 err = pci_enable_device(pdev);
11989 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
11993 pci_restore_state(pdev);
11996 * Suspend/Resume resets the PCI configuration space, so we have to
11997 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11998 * from interfering with C3 CPU state. pci_restore_state won't help
11999 * here since it only restores the first 64 bytes pci config header.
12001 pci_read_config_dword(pdev, 0x40, &val);
12002 if ((val & 0x0000ff00) != 0)
12003 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
12005 /* Set the device back into the PRESENT state; this will also wake
12006 * the queue of needed */
12007 netif_device_attach(dev);
12009 priv->suspend_time = get_seconds() - priv->suspend_at;
12011 /* Bring the device back up */
12012 queue_work(priv->workqueue, &priv->up);
12018 static void ipw_pci_shutdown(struct pci_dev *pdev)
12020 struct ipw_priv *priv = pci_get_drvdata(pdev);
12022 /* Take down the device; powers it off, etc. */
12025 pci_disable_device(pdev);
12028 /* driver initialization stuff */
12029 static struct pci_driver ipw_driver = {
12031 .id_table = card_ids,
12032 .probe = ipw_pci_probe,
12033 .remove = __devexit_p(ipw_pci_remove),
12035 .suspend = ipw_pci_suspend,
12036 .resume = ipw_pci_resume,
12038 .shutdown = ipw_pci_shutdown,
12041 static int __init ipw_init(void)
12045 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
12046 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
12048 ret = pci_register_driver(&ipw_driver);
12050 IPW_ERROR("Unable to initialize PCI module\n");
12054 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
12056 IPW_ERROR("Unable to create driver sysfs file\n");
12057 pci_unregister_driver(&ipw_driver);
12064 static void __exit ipw_exit(void)
12066 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
12067 pci_unregister_driver(&ipw_driver);
12070 module_param(disable, int, 0444);
12071 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
12073 module_param(associate, int, 0444);
12074 MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
12076 module_param(auto_create, int, 0444);
12077 MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
12079 module_param_named(led, led_support, int, 0444);
12080 MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)");
12082 module_param(debug, int, 0444);
12083 MODULE_PARM_DESC(debug, "debug output mask");
12085 module_param_named(channel, default_channel, int, 0444);
12086 MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
12088 #ifdef CONFIG_IPW2200_PROMISCUOUS
12089 module_param(rtap_iface, int, 0444);
12090 MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
12093 #ifdef CONFIG_IPW2200_QOS
12094 module_param(qos_enable, int, 0444);
12095 MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
12097 module_param(qos_burst_enable, int, 0444);
12098 MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
12100 module_param(qos_no_ack_mask, int, 0444);
12101 MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
12103 module_param(burst_duration_CCK, int, 0444);
12104 MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
12106 module_param(burst_duration_OFDM, int, 0444);
12107 MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
12108 #endif /* CONFIG_IPW2200_QOS */
12110 #ifdef CONFIG_IPW2200_MONITOR
12111 module_param_named(mode, network_mode, int, 0444);
12112 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
12114 module_param_named(mode, network_mode, int, 0444);
12115 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
12118 module_param(bt_coexist, int, 0444);
12119 MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
12121 module_param(hwcrypto, int, 0444);
12122 MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
12124 module_param(cmdlog, int, 0444);
12125 MODULE_PARM_DESC(cmdlog,
12126 "allocate a ring buffer for logging firmware commands");
12128 module_param(roaming, int, 0444);
12129 MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
12131 module_param(antenna, int, 0444);
12132 MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
12134 module_exit(ipw_exit);
12135 module_init(ipw_init);