1 /******************************************************************************
3 Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved.
5 802.11 status code portion of this file from ethereal-0.10.6:
6 Copyright 2000, Axis Communications AB
7 Ethereal - Network traffic analyzer
8 By Gerald Combs <gerald@ethereal.com>
9 Copyright 1998 Gerald Combs
11 This program is free software; you can redistribute it and/or modify it
12 under the terms of version 2 of the GNU General Public License as
13 published by the Free Software Foundation.
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59
22 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 The full GNU General Public License is included in this distribution in the
28 James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 ******************************************************************************/
34 #include <linux/version.h>
43 #ifdef CONFIG_IPW2200_DEBUG
49 #ifdef CONFIG_IPW2200_MONITOR
55 #ifdef CONFIG_IPW2200_PROMISCUOUS
61 #ifdef CONFIG_IPW2200_RADIOTAP
67 #ifdef CONFIG_IPW2200_QOS
73 #define IPW2200_VERSION "1.1.2" VK VD VM VP VR VQ
74 #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
75 #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
76 #define DRV_VERSION IPW2200_VERSION
78 #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
80 MODULE_DESCRIPTION(DRV_DESCRIPTION);
81 MODULE_VERSION(DRV_VERSION);
82 MODULE_AUTHOR(DRV_COPYRIGHT);
83 MODULE_LICENSE("GPL");
85 static int cmdlog = 0;
86 #ifdef CONFIG_IPW2200_DEBUG
89 static int channel = 0;
92 static u32 ipw_debug_level;
93 static int associate = 1;
94 static int auto_create = 1;
96 static int disable = 0;
97 static int bt_coexist = 0;
98 static int hwcrypto = 0;
99 static int roaming = 1;
100 static const char ipw_modes[] = {
103 static int antenna = CFG_SYS_ANTENNA_BOTH;
105 #ifdef CONFIG_IPW2200_PROMISCUOUS
106 static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */
110 #ifdef CONFIG_IPW2200_QOS
111 static int qos_enable = 0;
112 static int qos_burst_enable = 0;
113 static int qos_no_ack_mask = 0;
114 static int burst_duration_CCK = 0;
115 static int burst_duration_OFDM = 0;
117 static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
118 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
119 QOS_TX3_CW_MIN_OFDM},
120 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
121 QOS_TX3_CW_MAX_OFDM},
122 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
123 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
124 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
125 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
128 static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
129 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
131 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
133 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
134 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
135 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
136 QOS_TX3_TXOP_LIMIT_CCK}
139 static struct ieee80211_qos_parameters def_parameters_OFDM = {
140 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
141 DEF_TX3_CW_MIN_OFDM},
142 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
143 DEF_TX3_CW_MAX_OFDM},
144 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
145 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
146 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
147 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
150 static struct ieee80211_qos_parameters def_parameters_CCK = {
151 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
153 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
155 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
156 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
157 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
158 DEF_TX3_TXOP_LIMIT_CCK}
161 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
163 static int from_priority_to_tx_queue[] = {
164 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
165 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
168 static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
170 static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
172 static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
174 #endif /* CONFIG_IPW2200_QOS */
176 static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
177 static void ipw_remove_current_network(struct ipw_priv *priv);
178 static void ipw_rx(struct ipw_priv *priv);
179 static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
180 struct clx2_tx_queue *txq, int qindex);
181 static int ipw_queue_reset(struct ipw_priv *priv);
183 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
186 static void ipw_tx_queue_free(struct ipw_priv *);
188 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
189 static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
190 static void ipw_rx_queue_replenish(void *);
191 static int ipw_up(struct ipw_priv *);
192 static void ipw_bg_up(void *);
193 static void ipw_down(struct ipw_priv *);
194 static void ipw_bg_down(void *);
195 static int ipw_config(struct ipw_priv *);
196 static int init_supported_rates(struct ipw_priv *priv,
197 struct ipw_supported_rates *prates);
198 static void ipw_set_hwcrypto_keys(struct ipw_priv *);
199 static void ipw_send_wep_keys(struct ipw_priv *, int);
201 static int snprint_line(char *buf, size_t count,
202 const u8 * data, u32 len, u32 ofs)
207 out = snprintf(buf, count, "%08X", ofs);
209 for (l = 0, i = 0; i < 2; i++) {
210 out += snprintf(buf + out, count - out, " ");
211 for (j = 0; j < 8 && l < len; j++, l++)
212 out += snprintf(buf + out, count - out, "%02X ",
215 out += snprintf(buf + out, count - out, " ");
218 out += snprintf(buf + out, count - out, " ");
219 for (l = 0, i = 0; i < 2; i++) {
220 out += snprintf(buf + out, count - out, " ");
221 for (j = 0; j < 8 && l < len; j++, l++) {
222 c = data[(i * 8 + j)];
223 if (!isascii(c) || !isprint(c))
226 out += snprintf(buf + out, count - out, "%c", c);
230 out += snprintf(buf + out, count - out, " ");
236 static void printk_buf(int level, const u8 * data, u32 len)
240 if (!(ipw_debug_level & level))
244 snprint_line(line, sizeof(line), &data[ofs],
246 printk(KERN_DEBUG "%s\n", line);
248 len -= min(len, 16U);
252 static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
258 while (size && len) {
259 out = snprint_line(output, size, &data[ofs],
260 min_t(size_t, len, 16U), ofs);
265 len -= min_t(size_t, len, 16U);
271 /* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
272 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
273 #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
275 /* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
276 static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
277 #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
279 /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
280 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
281 static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
283 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
284 __LINE__, (u32) (b), (u32) (c));
285 _ipw_write_reg8(a, b, c);
288 /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
289 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
290 static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
292 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
293 __LINE__, (u32) (b), (u32) (c));
294 _ipw_write_reg16(a, b, c);
297 /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
298 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
299 static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
301 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
302 __LINE__, (u32) (b), (u32) (c));
303 _ipw_write_reg32(a, b, c);
306 /* 8-bit direct write (low 4K) */
307 #define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
309 /* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
310 #define ipw_write8(ipw, ofs, val) \
311 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
312 _ipw_write8(ipw, ofs, val)
314 /* 16-bit direct write (low 4K) */
315 #define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
317 /* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
318 #define ipw_write16(ipw, ofs, val) \
319 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
320 _ipw_write16(ipw, ofs, val)
322 /* 32-bit direct write (low 4K) */
323 #define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
325 /* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
326 #define ipw_write32(ipw, ofs, val) \
327 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
328 _ipw_write32(ipw, ofs, val)
330 /* 8-bit direct read (low 4K) */
331 #define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
333 /* 8-bit direct read (low 4K), with debug wrapper */
334 static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
336 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
337 return _ipw_read8(ipw, ofs);
340 /* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
341 #define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
343 /* 16-bit direct read (low 4K) */
344 #define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
346 /* 16-bit direct read (low 4K), with debug wrapper */
347 static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
349 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
350 return _ipw_read16(ipw, ofs);
353 /* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
354 #define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
356 /* 32-bit direct read (low 4K) */
357 #define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
359 /* 32-bit direct read (low 4K), with debug wrapper */
360 static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
362 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
363 return _ipw_read32(ipw, ofs);
366 /* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
367 #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
369 /* multi-byte read (above 4K), with debug wrapper */
370 static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
371 static inline void __ipw_read_indirect(const char *f, int l,
372 struct ipw_priv *a, u32 b, u8 * c, int d)
374 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
376 _ipw_read_indirect(a, b, c, d);
379 /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
380 #define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
382 /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
383 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
385 #define ipw_write_indirect(a, b, c, d) \
386 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
387 _ipw_write_indirect(a, b, c, d)
389 /* 32-bit indirect write (above 4K) */
390 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
392 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
393 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
394 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
397 /* 8-bit indirect write (above 4K) */
398 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
400 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
401 u32 dif_len = reg - aligned_addr;
403 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
404 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
405 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
408 /* 16-bit indirect write (above 4K) */
409 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
411 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
412 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
414 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
415 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
416 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
419 /* 8-bit indirect read (above 4K) */
420 static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
423 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
424 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
425 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
426 return (word >> ((reg & 0x3) * 8)) & 0xff;
429 /* 32-bit indirect read (above 4K) */
430 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
434 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
436 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
437 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
438 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
442 /* General purpose, no alignment requirement, iterative (multi-byte) read, */
443 /* for area above 1st 4K of SRAM/reg space */
444 static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
447 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
448 u32 dif_len = addr - aligned_addr;
451 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
457 /* Read the first dword (or portion) byte by byte */
458 if (unlikely(dif_len)) {
459 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
460 /* Start reading at aligned_addr + dif_len */
461 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
462 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
466 /* Read all of the middle dwords as dwords, with auto-increment */
467 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
468 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
469 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
471 /* Read the last dword (or portion) byte by byte */
473 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
474 for (i = 0; num > 0; i++, num--)
475 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
479 /* General purpose, no alignment requirement, iterative (multi-byte) write, */
480 /* for area above 1st 4K of SRAM/reg space */
481 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
484 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
485 u32 dif_len = addr - aligned_addr;
488 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
494 /* Write the first dword (or portion) byte by byte */
495 if (unlikely(dif_len)) {
496 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
497 /* Start writing at aligned_addr + dif_len */
498 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
499 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
503 /* Write all of the middle dwords as dwords, with auto-increment */
504 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
505 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
506 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
508 /* Write the last dword (or portion) byte by byte */
510 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
511 for (i = 0; num > 0; i++, num--, buf++)
512 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
516 /* General purpose, no alignment requirement, iterative (multi-byte) write, */
517 /* for 1st 4K of SRAM/regs space */
518 static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
521 memcpy_toio((priv->hw_base + addr), buf, num);
524 /* Set bit(s) in low 4K of SRAM/regs */
525 static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
527 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
530 /* Clear bit(s) in low 4K of SRAM/regs */
531 static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
533 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
536 static inline void __ipw_enable_interrupts(struct ipw_priv *priv)
538 if (priv->status & STATUS_INT_ENABLED)
540 priv->status |= STATUS_INT_ENABLED;
541 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
544 static inline void __ipw_disable_interrupts(struct ipw_priv *priv)
546 if (!(priv->status & STATUS_INT_ENABLED))
548 priv->status &= ~STATUS_INT_ENABLED;
549 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
552 static inline void ipw_enable_interrupts(struct ipw_priv *priv)
556 spin_lock_irqsave(&priv->irq_lock, flags);
557 __ipw_enable_interrupts(priv);
558 spin_unlock_irqrestore(&priv->irq_lock, flags);
561 static inline void ipw_disable_interrupts(struct ipw_priv *priv)
565 spin_lock_irqsave(&priv->irq_lock, flags);
566 __ipw_disable_interrupts(priv);
567 spin_unlock_irqrestore(&priv->irq_lock, flags);
570 #ifdef CONFIG_IPW2200_DEBUG
571 static char *ipw_error_desc(u32 val)
574 case IPW_FW_ERROR_OK:
576 case IPW_FW_ERROR_FAIL:
578 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
579 return "MEMORY_UNDERFLOW";
580 case IPW_FW_ERROR_MEMORY_OVERFLOW:
581 return "MEMORY_OVERFLOW";
582 case IPW_FW_ERROR_BAD_PARAM:
584 case IPW_FW_ERROR_BAD_CHECKSUM:
585 return "BAD_CHECKSUM";
586 case IPW_FW_ERROR_NMI_INTERRUPT:
587 return "NMI_INTERRUPT";
588 case IPW_FW_ERROR_BAD_DATABASE:
589 return "BAD_DATABASE";
590 case IPW_FW_ERROR_ALLOC_FAIL:
592 case IPW_FW_ERROR_DMA_UNDERRUN:
593 return "DMA_UNDERRUN";
594 case IPW_FW_ERROR_DMA_STATUS:
596 case IPW_FW_ERROR_DINO_ERROR:
598 case IPW_FW_ERROR_EEPROM_ERROR:
599 return "EEPROM_ERROR";
600 case IPW_FW_ERROR_SYSASSERT:
602 case IPW_FW_ERROR_FATAL_ERROR:
603 return "FATAL_ERROR";
605 return "UNKNOWN_ERROR";
609 static void ipw_dump_error_log(struct ipw_priv *priv,
610 struct ipw_fw_error *error)
615 IPW_ERROR("Error allocating and capturing error log. "
616 "Nothing to dump.\n");
620 IPW_ERROR("Start IPW Error Log Dump:\n");
621 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
622 error->status, error->config);
624 for (i = 0; i < error->elem_len; i++)
625 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
626 ipw_error_desc(error->elem[i].desc),
628 error->elem[i].blink1,
629 error->elem[i].blink2,
630 error->elem[i].link1,
631 error->elem[i].link2, error->elem[i].data);
632 for (i = 0; i < error->log_len; i++)
633 IPW_ERROR("%i\t0x%08x\t%i\n",
635 error->log[i].data, error->log[i].event);
639 static inline int ipw_is_init(struct ipw_priv *priv)
641 return (priv->status & STATUS_INIT) ? 1 : 0;
644 static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
646 u32 addr, field_info, field_len, field_count, total_len;
648 IPW_DEBUG_ORD("ordinal = %i\n", ord);
650 if (!priv || !val || !len) {
651 IPW_DEBUG_ORD("Invalid argument\n");
655 /* verify device ordinal tables have been initialized */
656 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
657 IPW_DEBUG_ORD("Access ordinals before initialization\n");
661 switch (IPW_ORD_TABLE_ID_MASK & ord) {
662 case IPW_ORD_TABLE_0_MASK:
664 * TABLE 0: Direct access to a table of 32 bit values
666 * This is a very simple table with the data directly
667 * read from the table
670 /* remove the table id from the ordinal */
671 ord &= IPW_ORD_TABLE_VALUE_MASK;
674 if (ord > priv->table0_len) {
675 IPW_DEBUG_ORD("ordinal value (%i) longer then "
676 "max (%i)\n", ord, priv->table0_len);
680 /* verify we have enough room to store the value */
681 if (*len < sizeof(u32)) {
682 IPW_DEBUG_ORD("ordinal buffer length too small, "
683 "need %zd\n", sizeof(u32));
687 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
688 ord, priv->table0_addr + (ord << 2));
692 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
695 case IPW_ORD_TABLE_1_MASK:
697 * TABLE 1: Indirect access to a table of 32 bit values
699 * This is a fairly large table of u32 values each
700 * representing starting addr for the data (which is
704 /* remove the table id from the ordinal */
705 ord &= IPW_ORD_TABLE_VALUE_MASK;
708 if (ord > priv->table1_len) {
709 IPW_DEBUG_ORD("ordinal value too long\n");
713 /* verify we have enough room to store the value */
714 if (*len < sizeof(u32)) {
715 IPW_DEBUG_ORD("ordinal buffer length too small, "
716 "need %zd\n", sizeof(u32));
721 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
725 case IPW_ORD_TABLE_2_MASK:
727 * TABLE 2: Indirect access to a table of variable sized values
729 * This table consist of six values, each containing
730 * - dword containing the starting offset of the data
731 * - dword containing the lengh in the first 16bits
732 * and the count in the second 16bits
735 /* remove the table id from the ordinal */
736 ord &= IPW_ORD_TABLE_VALUE_MASK;
739 if (ord > priv->table2_len) {
740 IPW_DEBUG_ORD("ordinal value too long\n");
744 /* get the address of statistic */
745 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
747 /* get the second DW of statistics ;
748 * two 16-bit words - first is length, second is count */
751 priv->table2_addr + (ord << 3) +
754 /* get each entry length */
755 field_len = *((u16 *) & field_info);
757 /* get number of entries */
758 field_count = *(((u16 *) & field_info) + 1);
760 /* abort if not enought memory */
761 total_len = field_len * field_count;
762 if (total_len > *len) {
771 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
772 "field_info = 0x%08x\n",
773 addr, total_len, field_info);
774 ipw_read_indirect(priv, addr, val, total_len);
778 IPW_DEBUG_ORD("Invalid ordinal!\n");
786 static void ipw_init_ordinals(struct ipw_priv *priv)
788 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
789 priv->table0_len = ipw_read32(priv, priv->table0_addr);
791 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
792 priv->table0_addr, priv->table0_len);
794 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
795 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
797 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
798 priv->table1_addr, priv->table1_len);
800 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
801 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
802 priv->table2_len &= 0x0000ffff; /* use first two bytes */
804 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
805 priv->table2_addr, priv->table2_len);
809 static u32 ipw_register_toggle(u32 reg)
811 reg &= ~IPW_START_STANDBY;
812 if (reg & IPW_GATE_ODMA)
813 reg &= ~IPW_GATE_ODMA;
814 if (reg & IPW_GATE_IDMA)
815 reg &= ~IPW_GATE_IDMA;
816 if (reg & IPW_GATE_ADMA)
817 reg &= ~IPW_GATE_ADMA;
823 * - On radio ON, turn on any LEDs that require to be on during start
824 * - On initialization, start unassociated blink
825 * - On association, disable unassociated blink
826 * - On disassociation, start unassociated blink
827 * - On radio OFF, turn off any LEDs started during radio on
830 #define LD_TIME_LINK_ON msecs_to_jiffies(300)
831 #define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
832 #define LD_TIME_ACT_ON msecs_to_jiffies(250)
834 static void ipw_led_link_on(struct ipw_priv *priv)
839 /* If configured to not use LEDs, or nic_type is 1,
840 * then we don't toggle a LINK led */
841 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
844 spin_lock_irqsave(&priv->lock, flags);
846 if (!(priv->status & STATUS_RF_KILL_MASK) &&
847 !(priv->status & STATUS_LED_LINK_ON)) {
848 IPW_DEBUG_LED("Link LED On\n");
849 led = ipw_read_reg32(priv, IPW_EVENT_REG);
850 led |= priv->led_association_on;
852 led = ipw_register_toggle(led);
854 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
855 ipw_write_reg32(priv, IPW_EVENT_REG, led);
857 priv->status |= STATUS_LED_LINK_ON;
859 /* If we aren't associated, schedule turning the LED off */
860 if (!(priv->status & STATUS_ASSOCIATED))
861 queue_delayed_work(priv->workqueue,
866 spin_unlock_irqrestore(&priv->lock, flags);
869 static void ipw_bg_led_link_on(void *data)
871 struct ipw_priv *priv = data;
872 mutex_lock(&priv->mutex);
873 ipw_led_link_on(data);
874 mutex_unlock(&priv->mutex);
877 static void ipw_led_link_off(struct ipw_priv *priv)
882 /* If configured not to use LEDs, or nic type is 1,
883 * then we don't goggle the LINK led. */
884 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
887 spin_lock_irqsave(&priv->lock, flags);
889 if (priv->status & STATUS_LED_LINK_ON) {
890 led = ipw_read_reg32(priv, IPW_EVENT_REG);
891 led &= priv->led_association_off;
892 led = ipw_register_toggle(led);
894 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
895 ipw_write_reg32(priv, IPW_EVENT_REG, led);
897 IPW_DEBUG_LED("Link LED Off\n");
899 priv->status &= ~STATUS_LED_LINK_ON;
901 /* If we aren't associated and the radio is on, schedule
902 * turning the LED on (blink while unassociated) */
903 if (!(priv->status & STATUS_RF_KILL_MASK) &&
904 !(priv->status & STATUS_ASSOCIATED))
905 queue_delayed_work(priv->workqueue, &priv->led_link_on,
910 spin_unlock_irqrestore(&priv->lock, flags);
913 static void ipw_bg_led_link_off(void *data)
915 struct ipw_priv *priv = data;
916 mutex_lock(&priv->mutex);
917 ipw_led_link_off(data);
918 mutex_unlock(&priv->mutex);
921 static void __ipw_led_activity_on(struct ipw_priv *priv)
925 if (priv->config & CFG_NO_LED)
928 if (priv->status & STATUS_RF_KILL_MASK)
931 if (!(priv->status & STATUS_LED_ACT_ON)) {
932 led = ipw_read_reg32(priv, IPW_EVENT_REG);
933 led |= priv->led_activity_on;
935 led = ipw_register_toggle(led);
937 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
938 ipw_write_reg32(priv, IPW_EVENT_REG, led);
940 IPW_DEBUG_LED("Activity LED On\n");
942 priv->status |= STATUS_LED_ACT_ON;
944 cancel_delayed_work(&priv->led_act_off);
945 queue_delayed_work(priv->workqueue, &priv->led_act_off,
948 /* Reschedule LED off for full time period */
949 cancel_delayed_work(&priv->led_act_off);
950 queue_delayed_work(priv->workqueue, &priv->led_act_off,
956 void ipw_led_activity_on(struct ipw_priv *priv)
959 spin_lock_irqsave(&priv->lock, flags);
960 __ipw_led_activity_on(priv);
961 spin_unlock_irqrestore(&priv->lock, flags);
965 static void ipw_led_activity_off(struct ipw_priv *priv)
970 if (priv->config & CFG_NO_LED)
973 spin_lock_irqsave(&priv->lock, flags);
975 if (priv->status & STATUS_LED_ACT_ON) {
976 led = ipw_read_reg32(priv, IPW_EVENT_REG);
977 led &= priv->led_activity_off;
979 led = ipw_register_toggle(led);
981 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
982 ipw_write_reg32(priv, IPW_EVENT_REG, led);
984 IPW_DEBUG_LED("Activity LED Off\n");
986 priv->status &= ~STATUS_LED_ACT_ON;
989 spin_unlock_irqrestore(&priv->lock, flags);
992 static void ipw_bg_led_activity_off(void *data)
994 struct ipw_priv *priv = data;
995 mutex_lock(&priv->mutex);
996 ipw_led_activity_off(data);
997 mutex_unlock(&priv->mutex);
1000 static void ipw_led_band_on(struct ipw_priv *priv)
1002 unsigned long flags;
1005 /* Only nic type 1 supports mode LEDs */
1006 if (priv->config & CFG_NO_LED ||
1007 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
1010 spin_lock_irqsave(&priv->lock, flags);
1012 led = ipw_read_reg32(priv, IPW_EVENT_REG);
1013 if (priv->assoc_network->mode == IEEE_A) {
1014 led |= priv->led_ofdm_on;
1015 led &= priv->led_association_off;
1016 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
1017 } else if (priv->assoc_network->mode == IEEE_G) {
1018 led |= priv->led_ofdm_on;
1019 led |= priv->led_association_on;
1020 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
1022 led &= priv->led_ofdm_off;
1023 led |= priv->led_association_on;
1024 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
1027 led = ipw_register_toggle(led);
1029 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
1030 ipw_write_reg32(priv, IPW_EVENT_REG, led);
1032 spin_unlock_irqrestore(&priv->lock, flags);
1035 static void ipw_led_band_off(struct ipw_priv *priv)
1037 unsigned long flags;
1040 /* Only nic type 1 supports mode LEDs */
1041 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
1044 spin_lock_irqsave(&priv->lock, flags);
1046 led = ipw_read_reg32(priv, IPW_EVENT_REG);
1047 led &= priv->led_ofdm_off;
1048 led &= priv->led_association_off;
1050 led = ipw_register_toggle(led);
1052 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
1053 ipw_write_reg32(priv, IPW_EVENT_REG, led);
1055 spin_unlock_irqrestore(&priv->lock, flags);
1058 static void ipw_led_radio_on(struct ipw_priv *priv)
1060 ipw_led_link_on(priv);
1063 static void ipw_led_radio_off(struct ipw_priv *priv)
1065 ipw_led_activity_off(priv);
1066 ipw_led_link_off(priv);
1069 static void ipw_led_link_up(struct ipw_priv *priv)
1071 /* Set the Link Led on for all nic types */
1072 ipw_led_link_on(priv);
1075 static void ipw_led_link_down(struct ipw_priv *priv)
1077 ipw_led_activity_off(priv);
1078 ipw_led_link_off(priv);
1080 if (priv->status & STATUS_RF_KILL_MASK)
1081 ipw_led_radio_off(priv);
1084 static void ipw_led_init(struct ipw_priv *priv)
1086 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1088 /* Set the default PINs for the link and activity leds */
1089 priv->led_activity_on = IPW_ACTIVITY_LED;
1090 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
1092 priv->led_association_on = IPW_ASSOCIATED_LED;
1093 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
1095 /* Set the default PINs for the OFDM leds */
1096 priv->led_ofdm_on = IPW_OFDM_LED;
1097 priv->led_ofdm_off = ~(IPW_OFDM_LED);
1099 switch (priv->nic_type) {
1100 case EEPROM_NIC_TYPE_1:
1101 /* In this NIC type, the LEDs are reversed.... */
1102 priv->led_activity_on = IPW_ASSOCIATED_LED;
1103 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1104 priv->led_association_on = IPW_ACTIVITY_LED;
1105 priv->led_association_off = ~(IPW_ACTIVITY_LED);
1107 if (!(priv->config & CFG_NO_LED))
1108 ipw_led_band_on(priv);
1110 /* And we don't blink link LEDs for this nic, so
1111 * just return here */
1114 case EEPROM_NIC_TYPE_3:
1115 case EEPROM_NIC_TYPE_2:
1116 case EEPROM_NIC_TYPE_4:
1117 case EEPROM_NIC_TYPE_0:
1121 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1123 priv->nic_type = EEPROM_NIC_TYPE_0;
1127 if (!(priv->config & CFG_NO_LED)) {
1128 if (priv->status & STATUS_ASSOCIATED)
1129 ipw_led_link_on(priv);
1131 ipw_led_link_off(priv);
1135 static void ipw_led_shutdown(struct ipw_priv *priv)
1137 ipw_led_activity_off(priv);
1138 ipw_led_link_off(priv);
1139 ipw_led_band_off(priv);
1140 cancel_delayed_work(&priv->led_link_on);
1141 cancel_delayed_work(&priv->led_link_off);
1142 cancel_delayed_work(&priv->led_act_off);
1146 * The following adds a new attribute to the sysfs representation
1147 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1148 * used for controling the debug level.
1150 * See the level definitions in ipw for details.
1152 static ssize_t show_debug_level(struct device_driver *d, char *buf)
1154 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1157 static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1160 char *p = (char *)buf;
1163 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1165 if (p[0] == 'x' || p[0] == 'X')
1167 val = simple_strtoul(p, &p, 16);
1169 val = simple_strtoul(p, &p, 10);
1171 printk(KERN_INFO DRV_NAME
1172 ": %s is not in hex or decimal form.\n", buf);
1174 ipw_debug_level = val;
1176 return strnlen(buf, count);
1179 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
1180 show_debug_level, store_debug_level);
1182 static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1184 /* length = 1st dword in log */
1185 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1188 static void ipw_capture_event_log(struct ipw_priv *priv,
1189 u32 log_len, struct ipw_event *log)
1194 base = ipw_read32(priv, IPW_EVENT_LOG);
1195 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1196 (u8 *) log, sizeof(*log) * log_len);
1200 static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1202 struct ipw_fw_error *error;
1203 u32 log_len = ipw_get_event_log_len(priv);
1204 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1205 u32 elem_len = ipw_read_reg32(priv, base);
1207 error = kmalloc(sizeof(*error) +
1208 sizeof(*error->elem) * elem_len +
1209 sizeof(*error->log) * log_len, GFP_ATOMIC);
1211 IPW_ERROR("Memory allocation for firmware error log "
1215 error->jiffies = jiffies;
1216 error->status = priv->status;
1217 error->config = priv->config;
1218 error->elem_len = elem_len;
1219 error->log_len = log_len;
1220 error->elem = (struct ipw_error_elem *)error->payload;
1221 error->log = (struct ipw_event *)(error->elem + elem_len);
1223 ipw_capture_event_log(priv, log_len, error->log);
1226 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1227 sizeof(*error->elem) * elem_len);
1232 static void ipw_free_error_log(struct ipw_fw_error *error)
1238 static ssize_t show_event_log(struct device *d,
1239 struct device_attribute *attr, char *buf)
1241 struct ipw_priv *priv = dev_get_drvdata(d);
1242 u32 log_len = ipw_get_event_log_len(priv);
1243 struct ipw_event log[log_len];
1246 ipw_capture_event_log(priv, log_len, log);
1248 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1249 for (i = 0; i < log_len; i++)
1250 len += snprintf(buf + len, PAGE_SIZE - len,
1252 log[i].time, log[i].event, log[i].data);
1253 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1257 static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1259 static ssize_t show_error(struct device *d,
1260 struct device_attribute *attr, char *buf)
1262 struct ipw_priv *priv = dev_get_drvdata(d);
1266 len += snprintf(buf + len, PAGE_SIZE - len,
1267 "%08lX%08X%08X%08X",
1268 priv->error->jiffies,
1269 priv->error->status,
1270 priv->error->config, priv->error->elem_len);
1271 for (i = 0; i < priv->error->elem_len; i++)
1272 len += snprintf(buf + len, PAGE_SIZE - len,
1273 "\n%08X%08X%08X%08X%08X%08X%08X",
1274 priv->error->elem[i].time,
1275 priv->error->elem[i].desc,
1276 priv->error->elem[i].blink1,
1277 priv->error->elem[i].blink2,
1278 priv->error->elem[i].link1,
1279 priv->error->elem[i].link2,
1280 priv->error->elem[i].data);
1282 len += snprintf(buf + len, PAGE_SIZE - len,
1283 "\n%08X", priv->error->log_len);
1284 for (i = 0; i < priv->error->log_len; i++)
1285 len += snprintf(buf + len, PAGE_SIZE - len,
1287 priv->error->log[i].time,
1288 priv->error->log[i].event,
1289 priv->error->log[i].data);
1290 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1294 static ssize_t clear_error(struct device *d,
1295 struct device_attribute *attr,
1296 const char *buf, size_t count)
1298 struct ipw_priv *priv = dev_get_drvdata(d);
1300 ipw_free_error_log(priv->error);
1306 static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1308 static ssize_t show_cmd_log(struct device *d,
1309 struct device_attribute *attr, char *buf)
1311 struct ipw_priv *priv = dev_get_drvdata(d);
1315 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1316 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1317 i = (i + 1) % priv->cmdlog_len) {
1319 snprintf(buf + len, PAGE_SIZE - len,
1320 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1321 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1322 priv->cmdlog[i].cmd.len);
1324 snprintk_buf(buf + len, PAGE_SIZE - len,
1325 (u8 *) priv->cmdlog[i].cmd.param,
1326 priv->cmdlog[i].cmd.len);
1327 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1329 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1333 static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1335 #ifdef CONFIG_IPW2200_PROMISCUOUS
1336 static void ipw_prom_free(struct ipw_priv *priv);
1337 static int ipw_prom_alloc(struct ipw_priv *priv);
1338 static ssize_t store_rtap_iface(struct device *d,
1339 struct device_attribute *attr,
1340 const char *buf, size_t count)
1342 struct ipw_priv *priv = dev_get_drvdata(d);
1353 if (netif_running(priv->prom_net_dev)) {
1354 IPW_WARNING("Interface is up. Cannot unregister.\n");
1358 ipw_prom_free(priv);
1366 rc = ipw_prom_alloc(priv);
1376 IPW_ERROR("Failed to register promiscuous network "
1377 "device (error %d).\n", rc);
1383 static ssize_t show_rtap_iface(struct device *d,
1384 struct device_attribute *attr,
1387 struct ipw_priv *priv = dev_get_drvdata(d);
1389 return sprintf(buf, "%s", priv->prom_net_dev->name);
1398 static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1401 static ssize_t store_rtap_filter(struct device *d,
1402 struct device_attribute *attr,
1403 const char *buf, size_t count)
1405 struct ipw_priv *priv = dev_get_drvdata(d);
1407 if (!priv->prom_priv) {
1408 IPW_ERROR("Attempting to set filter without "
1409 "rtap_iface enabled.\n");
1413 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1415 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1416 BIT_ARG16(priv->prom_priv->filter));
1421 static ssize_t show_rtap_filter(struct device *d,
1422 struct device_attribute *attr,
1425 struct ipw_priv *priv = dev_get_drvdata(d);
1426 return sprintf(buf, "0x%04X",
1427 priv->prom_priv ? priv->prom_priv->filter : 0);
1430 static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1434 static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1437 struct ipw_priv *priv = dev_get_drvdata(d);
1438 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1441 static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1442 const char *buf, size_t count)
1444 struct ipw_priv *priv = dev_get_drvdata(d);
1445 #ifdef CONFIG_IPW2200_DEBUG
1446 struct net_device *dev = priv->net_dev;
1448 char buffer[] = "00000000";
1450 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1454 IPW_DEBUG_INFO("enter\n");
1456 strncpy(buffer, buf, len);
1459 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1461 if (p[0] == 'x' || p[0] == 'X')
1463 val = simple_strtoul(p, &p, 16);
1465 val = simple_strtoul(p, &p, 10);
1467 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1469 priv->ieee->scan_age = val;
1470 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1473 IPW_DEBUG_INFO("exit\n");
1477 static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1479 static ssize_t show_led(struct device *d, struct device_attribute *attr,
1482 struct ipw_priv *priv = dev_get_drvdata(d);
1483 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1486 static ssize_t store_led(struct device *d, struct device_attribute *attr,
1487 const char *buf, size_t count)
1489 struct ipw_priv *priv = dev_get_drvdata(d);
1491 IPW_DEBUG_INFO("enter\n");
1497 IPW_DEBUG_LED("Disabling LED control.\n");
1498 priv->config |= CFG_NO_LED;
1499 ipw_led_shutdown(priv);
1501 IPW_DEBUG_LED("Enabling LED control.\n");
1502 priv->config &= ~CFG_NO_LED;
1506 IPW_DEBUG_INFO("exit\n");
1510 static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1512 static ssize_t show_status(struct device *d,
1513 struct device_attribute *attr, char *buf)
1515 struct ipw_priv *p = d->driver_data;
1516 return sprintf(buf, "0x%08x\n", (int)p->status);
1519 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1521 static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1524 struct ipw_priv *p = d->driver_data;
1525 return sprintf(buf, "0x%08x\n", (int)p->config);
1528 static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1530 static ssize_t show_nic_type(struct device *d,
1531 struct device_attribute *attr, char *buf)
1533 struct ipw_priv *priv = d->driver_data;
1534 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
1537 static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1539 static ssize_t show_ucode_version(struct device *d,
1540 struct device_attribute *attr, char *buf)
1542 u32 len = sizeof(u32), tmp = 0;
1543 struct ipw_priv *p = d->driver_data;
1545 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
1548 return sprintf(buf, "0x%08x\n", tmp);
1551 static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
1553 static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1556 u32 len = sizeof(u32), tmp = 0;
1557 struct ipw_priv *p = d->driver_data;
1559 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
1562 return sprintf(buf, "0x%08x\n", tmp);
1565 static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
1568 * Add a device attribute to view/control the delay between eeprom
1571 static ssize_t show_eeprom_delay(struct device *d,
1572 struct device_attribute *attr, char *buf)
1574 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
1575 return sprintf(buf, "%i\n", n);
1577 static ssize_t store_eeprom_delay(struct device *d,
1578 struct device_attribute *attr,
1579 const char *buf, size_t count)
1581 struct ipw_priv *p = d->driver_data;
1582 sscanf(buf, "%i", &p->eeprom_delay);
1583 return strnlen(buf, count);
1586 static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1587 show_eeprom_delay, store_eeprom_delay);
1589 static ssize_t show_command_event_reg(struct device *d,
1590 struct device_attribute *attr, char *buf)
1593 struct ipw_priv *p = d->driver_data;
1595 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
1596 return sprintf(buf, "0x%08x\n", reg);
1598 static ssize_t store_command_event_reg(struct device *d,
1599 struct device_attribute *attr,
1600 const char *buf, size_t count)
1603 struct ipw_priv *p = d->driver_data;
1605 sscanf(buf, "%x", ®);
1606 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
1607 return strnlen(buf, count);
1610 static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1611 show_command_event_reg, store_command_event_reg);
1613 static ssize_t show_mem_gpio_reg(struct device *d,
1614 struct device_attribute *attr, char *buf)
1617 struct ipw_priv *p = d->driver_data;
1619 reg = ipw_read_reg32(p, 0x301100);
1620 return sprintf(buf, "0x%08x\n", reg);
1622 static ssize_t store_mem_gpio_reg(struct device *d,
1623 struct device_attribute *attr,
1624 const char *buf, size_t count)
1627 struct ipw_priv *p = d->driver_data;
1629 sscanf(buf, "%x", ®);
1630 ipw_write_reg32(p, 0x301100, reg);
1631 return strnlen(buf, count);
1634 static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1635 show_mem_gpio_reg, store_mem_gpio_reg);
1637 static ssize_t show_indirect_dword(struct device *d,
1638 struct device_attribute *attr, char *buf)
1641 struct ipw_priv *priv = d->driver_data;
1643 if (priv->status & STATUS_INDIRECT_DWORD)
1644 reg = ipw_read_reg32(priv, priv->indirect_dword);
1648 return sprintf(buf, "0x%08x\n", reg);
1650 static ssize_t store_indirect_dword(struct device *d,
1651 struct device_attribute *attr,
1652 const char *buf, size_t count)
1654 struct ipw_priv *priv = d->driver_data;
1656 sscanf(buf, "%x", &priv->indirect_dword);
1657 priv->status |= STATUS_INDIRECT_DWORD;
1658 return strnlen(buf, count);
1661 static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1662 show_indirect_dword, store_indirect_dword);
1664 static ssize_t show_indirect_byte(struct device *d,
1665 struct device_attribute *attr, char *buf)
1668 struct ipw_priv *priv = d->driver_data;
1670 if (priv->status & STATUS_INDIRECT_BYTE)
1671 reg = ipw_read_reg8(priv, priv->indirect_byte);
1675 return sprintf(buf, "0x%02x\n", reg);
1677 static ssize_t store_indirect_byte(struct device *d,
1678 struct device_attribute *attr,
1679 const char *buf, size_t count)
1681 struct ipw_priv *priv = d->driver_data;
1683 sscanf(buf, "%x", &priv->indirect_byte);
1684 priv->status |= STATUS_INDIRECT_BYTE;
1685 return strnlen(buf, count);
1688 static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
1689 show_indirect_byte, store_indirect_byte);
1691 static ssize_t show_direct_dword(struct device *d,
1692 struct device_attribute *attr, char *buf)
1695 struct ipw_priv *priv = d->driver_data;
1697 if (priv->status & STATUS_DIRECT_DWORD)
1698 reg = ipw_read32(priv, priv->direct_dword);
1702 return sprintf(buf, "0x%08x\n", reg);
1704 static ssize_t store_direct_dword(struct device *d,
1705 struct device_attribute *attr,
1706 const char *buf, size_t count)
1708 struct ipw_priv *priv = d->driver_data;
1710 sscanf(buf, "%x", &priv->direct_dword);
1711 priv->status |= STATUS_DIRECT_DWORD;
1712 return strnlen(buf, count);
1715 static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1716 show_direct_dword, store_direct_dword);
1718 static int rf_kill_active(struct ipw_priv *priv)
1720 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1721 priv->status |= STATUS_RF_KILL_HW;
1723 priv->status &= ~STATUS_RF_KILL_HW;
1725 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1728 static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
1731 /* 0 - RF kill not enabled
1732 1 - SW based RF kill active (sysfs)
1733 2 - HW based RF kill active
1734 3 - Both HW and SW baed RF kill active */
1735 struct ipw_priv *priv = d->driver_data;
1736 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
1737 (rf_kill_active(priv) ? 0x2 : 0x0);
1738 return sprintf(buf, "%i\n", val);
1741 static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1743 if ((disable_radio ? 1 : 0) ==
1744 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
1747 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1748 disable_radio ? "OFF" : "ON");
1750 if (disable_radio) {
1751 priv->status |= STATUS_RF_KILL_SW;
1753 if (priv->workqueue)
1754 cancel_delayed_work(&priv->request_scan);
1755 queue_work(priv->workqueue, &priv->down);
1757 priv->status &= ~STATUS_RF_KILL_SW;
1758 if (rf_kill_active(priv)) {
1759 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1760 "disabled by HW switch\n");
1761 /* Make sure the RF_KILL check timer is running */
1762 cancel_delayed_work(&priv->rf_kill);
1763 queue_delayed_work(priv->workqueue, &priv->rf_kill,
1766 queue_work(priv->workqueue, &priv->up);
1772 static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1773 const char *buf, size_t count)
1775 struct ipw_priv *priv = d->driver_data;
1777 ipw_radio_kill_sw(priv, buf[0] == '1');
1782 static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
1784 static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1787 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1788 int pos = 0, len = 0;
1789 if (priv->config & CFG_SPEED_SCAN) {
1790 while (priv->speed_scan[pos] != 0)
1791 len += sprintf(&buf[len], "%d ",
1792 priv->speed_scan[pos++]);
1793 return len + sprintf(&buf[len], "\n");
1796 return sprintf(buf, "0\n");
1799 static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1800 const char *buf, size_t count)
1802 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1803 int channel, pos = 0;
1804 const char *p = buf;
1806 /* list of space separated channels to scan, optionally ending with 0 */
1807 while ((channel = simple_strtol(p, NULL, 0))) {
1808 if (pos == MAX_SPEED_SCAN - 1) {
1809 priv->speed_scan[pos] = 0;
1813 if (ieee80211_is_valid_channel(priv->ieee, channel))
1814 priv->speed_scan[pos++] = channel;
1816 IPW_WARNING("Skipping invalid channel request: %d\n",
1821 while (*p == ' ' || *p == '\t')
1826 priv->config &= ~CFG_SPEED_SCAN;
1828 priv->speed_scan_pos = 0;
1829 priv->config |= CFG_SPEED_SCAN;
1835 static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1838 static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1841 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1842 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1845 static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1846 const char *buf, size_t count)
1848 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1850 priv->config |= CFG_NET_STATS;
1852 priv->config &= ~CFG_NET_STATS;
1857 static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1858 show_net_stats, store_net_stats);
1860 static void notify_wx_assoc_event(struct ipw_priv *priv)
1862 union iwreq_data wrqu;
1863 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1864 if (priv->status & STATUS_ASSOCIATED)
1865 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1867 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1868 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1871 static void ipw_irq_tasklet(struct ipw_priv *priv)
1873 u32 inta, inta_mask, handled = 0;
1874 unsigned long flags;
1877 spin_lock_irqsave(&priv->irq_lock, flags);
1879 inta = ipw_read32(priv, IPW_INTA_RW);
1880 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1881 inta &= (IPW_INTA_MASK_ALL & inta_mask);
1883 /* Add any cached INTA values that need to be handled */
1884 inta |= priv->isr_inta;
1886 spin_unlock_irqrestore(&priv->irq_lock, flags);
1888 spin_lock_irqsave(&priv->lock, flags);
1890 /* handle all the justifications for the interrupt */
1891 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
1893 handled |= IPW_INTA_BIT_RX_TRANSFER;
1896 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
1897 IPW_DEBUG_HC("Command completed.\n");
1898 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
1899 priv->status &= ~STATUS_HCMD_ACTIVE;
1900 wake_up_interruptible(&priv->wait_command_queue);
1901 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
1904 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
1905 IPW_DEBUG_TX("TX_QUEUE_1\n");
1906 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
1907 handled |= IPW_INTA_BIT_TX_QUEUE_1;
1910 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
1911 IPW_DEBUG_TX("TX_QUEUE_2\n");
1912 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
1913 handled |= IPW_INTA_BIT_TX_QUEUE_2;
1916 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
1917 IPW_DEBUG_TX("TX_QUEUE_3\n");
1918 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
1919 handled |= IPW_INTA_BIT_TX_QUEUE_3;
1922 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
1923 IPW_DEBUG_TX("TX_QUEUE_4\n");
1924 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
1925 handled |= IPW_INTA_BIT_TX_QUEUE_4;
1928 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
1929 IPW_WARNING("STATUS_CHANGE\n");
1930 handled |= IPW_INTA_BIT_STATUS_CHANGE;
1933 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
1934 IPW_WARNING("TX_PERIOD_EXPIRED\n");
1935 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
1938 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
1939 IPW_WARNING("HOST_CMD_DONE\n");
1940 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
1943 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
1944 IPW_WARNING("FW_INITIALIZATION_DONE\n");
1945 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
1948 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
1949 IPW_WARNING("PHY_OFF_DONE\n");
1950 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
1953 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
1954 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1955 priv->status |= STATUS_RF_KILL_HW;
1956 wake_up_interruptible(&priv->wait_command_queue);
1957 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1958 cancel_delayed_work(&priv->request_scan);
1959 schedule_work(&priv->link_down);
1960 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
1961 handled |= IPW_INTA_BIT_RF_KILL_DONE;
1964 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
1965 IPW_WARNING("Firmware error detected. Restarting.\n");
1967 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
1968 #ifdef CONFIG_IPW2200_DEBUG
1969 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1970 struct ipw_fw_error *error =
1971 ipw_alloc_error_log(priv);
1972 ipw_dump_error_log(priv, error);
1974 ipw_free_error_log(error);
1978 priv->error = ipw_alloc_error_log(priv);
1980 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
1982 IPW_DEBUG_FW("Error allocating sysfs 'error' "
1984 #ifdef CONFIG_IPW2200_DEBUG
1985 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1986 ipw_dump_error_log(priv, priv->error);
1990 /* XXX: If hardware encryption is for WPA/WPA2,
1991 * we have to notify the supplicant. */
1992 if (priv->ieee->sec.encrypt) {
1993 priv->status &= ~STATUS_ASSOCIATED;
1994 notify_wx_assoc_event(priv);
1997 /* Keep the restart process from trying to send host
1998 * commands by clearing the INIT status bit */
1999 priv->status &= ~STATUS_INIT;
2001 /* Cancel currently queued command. */
2002 priv->status &= ~STATUS_HCMD_ACTIVE;
2003 wake_up_interruptible(&priv->wait_command_queue);
2005 queue_work(priv->workqueue, &priv->adapter_restart);
2006 handled |= IPW_INTA_BIT_FATAL_ERROR;
2009 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
2010 IPW_ERROR("Parity error\n");
2011 handled |= IPW_INTA_BIT_PARITY_ERROR;
2014 if (handled != inta) {
2015 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
2018 spin_unlock_irqrestore(&priv->lock, flags);
2020 /* enable all interrupts */
2021 ipw_enable_interrupts(priv);
2024 #define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2025 static char *get_cmd_string(u8 cmd)
2028 IPW_CMD(HOST_COMPLETE);
2029 IPW_CMD(POWER_DOWN);
2030 IPW_CMD(SYSTEM_CONFIG);
2031 IPW_CMD(MULTICAST_ADDRESS);
2033 IPW_CMD(ADAPTER_ADDRESS);
2035 IPW_CMD(RTS_THRESHOLD);
2036 IPW_CMD(FRAG_THRESHOLD);
2037 IPW_CMD(POWER_MODE);
2039 IPW_CMD(TGI_TX_KEY);
2040 IPW_CMD(SCAN_REQUEST);
2041 IPW_CMD(SCAN_REQUEST_EXT);
2043 IPW_CMD(SUPPORTED_RATES);
2044 IPW_CMD(SCAN_ABORT);
2046 IPW_CMD(QOS_PARAMETERS);
2047 IPW_CMD(DINO_CONFIG);
2048 IPW_CMD(RSN_CAPABILITIES);
2050 IPW_CMD(CARD_DISABLE);
2051 IPW_CMD(SEED_NUMBER);
2053 IPW_CMD(COUNTRY_INFO);
2054 IPW_CMD(AIRONET_INFO);
2055 IPW_CMD(AP_TX_POWER);
2057 IPW_CMD(CCX_VER_INFO);
2058 IPW_CMD(SET_CALIBRATION);
2059 IPW_CMD(SENSITIVITY_CALIB);
2060 IPW_CMD(RETRY_LIMIT);
2061 IPW_CMD(IPW_PRE_POWER_DOWN);
2062 IPW_CMD(VAP_BEACON_TEMPLATE);
2063 IPW_CMD(VAP_DTIM_PERIOD);
2064 IPW_CMD(EXT_SUPPORTED_RATES);
2065 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2066 IPW_CMD(VAP_QUIET_INTERVALS);
2067 IPW_CMD(VAP_CHANNEL_SWITCH);
2068 IPW_CMD(VAP_MANDATORY_CHANNELS);
2069 IPW_CMD(VAP_CELL_PWR_LIMIT);
2070 IPW_CMD(VAP_CF_PARAM_SET);
2071 IPW_CMD(VAP_SET_BEACONING_STATE);
2072 IPW_CMD(MEASUREMENT);
2073 IPW_CMD(POWER_CAPABILITY);
2074 IPW_CMD(SUPPORTED_CHANNELS);
2075 IPW_CMD(TPC_REPORT);
2077 IPW_CMD(PRODUCTION_COMMAND);
2083 #define HOST_COMPLETE_TIMEOUT HZ
2085 static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
2088 unsigned long flags;
2090 spin_lock_irqsave(&priv->lock, flags);
2091 if (priv->status & STATUS_HCMD_ACTIVE) {
2092 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2093 get_cmd_string(cmd->cmd));
2094 spin_unlock_irqrestore(&priv->lock, flags);
2098 priv->status |= STATUS_HCMD_ACTIVE;
2101 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2102 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2103 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2104 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2106 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2109 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2110 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2113 #ifndef DEBUG_CMD_WEP_KEY
2114 if (cmd->cmd == IPW_CMD_WEP_KEY)
2115 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2118 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2120 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
2122 priv->status &= ~STATUS_HCMD_ACTIVE;
2123 IPW_ERROR("Failed to send %s: Reason %d\n",
2124 get_cmd_string(cmd->cmd), rc);
2125 spin_unlock_irqrestore(&priv->lock, flags);
2128 spin_unlock_irqrestore(&priv->lock, flags);
2130 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2132 status & STATUS_HCMD_ACTIVE),
2133 HOST_COMPLETE_TIMEOUT);
2135 spin_lock_irqsave(&priv->lock, flags);
2136 if (priv->status & STATUS_HCMD_ACTIVE) {
2137 IPW_ERROR("Failed to send %s: Command timed out.\n",
2138 get_cmd_string(cmd->cmd));
2139 priv->status &= ~STATUS_HCMD_ACTIVE;
2140 spin_unlock_irqrestore(&priv->lock, flags);
2144 spin_unlock_irqrestore(&priv->lock, flags);
2148 if (priv->status & STATUS_RF_KILL_HW) {
2149 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2150 get_cmd_string(cmd->cmd));
2157 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2158 priv->cmdlog_pos %= priv->cmdlog_len;
2163 static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
2165 struct host_cmd cmd = {
2169 return __ipw_send_cmd(priv, &cmd);
2172 static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2175 struct host_cmd cmd = {
2181 return __ipw_send_cmd(priv, &cmd);
2184 static int ipw_send_host_complete(struct ipw_priv *priv)
2187 IPW_ERROR("Invalid args\n");
2191 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
2194 static int ipw_send_system_config(struct ipw_priv *priv)
2196 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2197 sizeof(priv->sys_config),
2201 static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
2203 if (!priv || !ssid) {
2204 IPW_ERROR("Invalid args\n");
2208 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
2212 static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
2214 if (!priv || !mac) {
2215 IPW_ERROR("Invalid args\n");
2219 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2220 priv->net_dev->name, MAC_ARG(mac));
2222 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
2226 * NOTE: This must be executed from our workqueue as it results in udelay
2227 * being called which may corrupt the keyboard if executed on default
2230 static void ipw_adapter_restart(void *adapter)
2232 struct ipw_priv *priv = adapter;
2234 if (priv->status & STATUS_RF_KILL_MASK)
2239 if (priv->assoc_network &&
2240 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2241 ipw_remove_current_network(priv);
2244 IPW_ERROR("Failed to up device\n");
2249 static void ipw_bg_adapter_restart(void *data)
2251 struct ipw_priv *priv = data;
2252 mutex_lock(&priv->mutex);
2253 ipw_adapter_restart(data);
2254 mutex_unlock(&priv->mutex);
2257 #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2259 static void ipw_scan_check(void *data)
2261 struct ipw_priv *priv = data;
2262 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2263 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
2264 "adapter after (%dms).\n",
2265 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
2266 queue_work(priv->workqueue, &priv->adapter_restart);
2270 static void ipw_bg_scan_check(void *data)
2272 struct ipw_priv *priv = data;
2273 mutex_lock(&priv->mutex);
2274 ipw_scan_check(data);
2275 mutex_unlock(&priv->mutex);
2278 static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2279 struct ipw_scan_request_ext *request)
2281 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
2282 sizeof(*request), request);
2285 static int ipw_send_scan_abort(struct ipw_priv *priv)
2288 IPW_ERROR("Invalid args\n");
2292 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
2295 static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2297 struct ipw_sensitivity_calib calib = {
2298 .beacon_rssi_raw = sens,
2301 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
2305 static int ipw_send_associate(struct ipw_priv *priv,
2306 struct ipw_associate *associate)
2308 struct ipw_associate tmp_associate;
2310 if (!priv || !associate) {
2311 IPW_ERROR("Invalid args\n");
2315 memcpy(&tmp_associate, associate, sizeof(*associate));
2316 tmp_associate.policy_support =
2317 cpu_to_le16(tmp_associate.policy_support);
2318 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2319 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2320 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2321 tmp_associate.listen_interval =
2322 cpu_to_le16(tmp_associate.listen_interval);
2323 tmp_associate.beacon_interval =
2324 cpu_to_le16(tmp_associate.beacon_interval);
2325 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2327 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
2331 static int ipw_send_supported_rates(struct ipw_priv *priv,
2332 struct ipw_supported_rates *rates)
2334 if (!priv || !rates) {
2335 IPW_ERROR("Invalid args\n");
2339 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
2343 static int ipw_set_random_seed(struct ipw_priv *priv)
2348 IPW_ERROR("Invalid args\n");
2352 get_random_bytes(&val, sizeof(val));
2354 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
2357 static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2360 IPW_ERROR("Invalid args\n");
2364 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off),
2368 static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
2370 if (!priv || !power) {
2371 IPW_ERROR("Invalid args\n");
2375 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
2378 static int ipw_set_tx_power(struct ipw_priv *priv)
2380 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
2381 struct ipw_tx_power tx_power;
2385 memset(&tx_power, 0, sizeof(tx_power));
2387 /* configure device for 'G' band */
2388 tx_power.ieee_mode = IPW_G_MODE;
2389 tx_power.num_channels = geo->bg_channels;
2390 for (i = 0; i < geo->bg_channels; i++) {
2391 max_power = geo->bg[i].max_power;
2392 tx_power.channels_tx_power[i].channel_number =
2394 tx_power.channels_tx_power[i].tx_power = max_power ?
2395 min(max_power, priv->tx_power) : priv->tx_power;
2397 if (ipw_send_tx_power(priv, &tx_power))
2400 /* configure device to also handle 'B' band */
2401 tx_power.ieee_mode = IPW_B_MODE;
2402 if (ipw_send_tx_power(priv, &tx_power))
2405 /* configure device to also handle 'A' band */
2406 if (priv->ieee->abg_true) {
2407 tx_power.ieee_mode = IPW_A_MODE;
2408 tx_power.num_channels = geo->a_channels;
2409 for (i = 0; i < tx_power.num_channels; i++) {
2410 max_power = geo->a[i].max_power;
2411 tx_power.channels_tx_power[i].channel_number =
2413 tx_power.channels_tx_power[i].tx_power = max_power ?
2414 min(max_power, priv->tx_power) : priv->tx_power;
2416 if (ipw_send_tx_power(priv, &tx_power))
2422 static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2424 struct ipw_rts_threshold rts_threshold = {
2425 .rts_threshold = rts,
2429 IPW_ERROR("Invalid args\n");
2433 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2434 sizeof(rts_threshold), &rts_threshold);
2437 static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2439 struct ipw_frag_threshold frag_threshold = {
2440 .frag_threshold = frag,
2444 IPW_ERROR("Invalid args\n");
2448 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2449 sizeof(frag_threshold), &frag_threshold);
2452 static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2457 IPW_ERROR("Invalid args\n");
2461 /* If on battery, set to 3, if AC set to CAM, else user
2464 case IPW_POWER_BATTERY:
2465 param = IPW_POWER_INDEX_3;
2468 param = IPW_POWER_MODE_CAM;
2475 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
2479 static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2481 struct ipw_retry_limit retry_limit = {
2482 .short_retry_limit = slimit,
2483 .long_retry_limit = llimit
2487 IPW_ERROR("Invalid args\n");
2491 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
2496 * The IPW device contains a Microwire compatible EEPROM that stores
2497 * various data like the MAC address. Usually the firmware has exclusive
2498 * access to the eeprom, but during device initialization (before the
2499 * device driver has sent the HostComplete command to the firmware) the
2500 * device driver has read access to the EEPROM by way of indirect addressing
2501 * through a couple of memory mapped registers.
2503 * The following is a simplified implementation for pulling data out of the
2504 * the eeprom, along with some helper functions to find information in
2505 * the per device private data's copy of the eeprom.
2507 * NOTE: To better understand how these functions work (i.e what is a chip
2508 * select and why do have to keep driving the eeprom clock?), read
2509 * just about any data sheet for a Microwire compatible EEPROM.
2512 /* write a 32 bit value into the indirect accessor register */
2513 static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2515 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
2517 /* the eeprom requires some time to complete the operation */
2518 udelay(p->eeprom_delay);
2523 /* perform a chip select operation */
2524 static void eeprom_cs(struct ipw_priv *priv)
2526 eeprom_write_reg(priv, 0);
2527 eeprom_write_reg(priv, EEPROM_BIT_CS);
2528 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2529 eeprom_write_reg(priv, EEPROM_BIT_CS);
2532 /* perform a chip select operation */
2533 static void eeprom_disable_cs(struct ipw_priv *priv)
2535 eeprom_write_reg(priv, EEPROM_BIT_CS);
2536 eeprom_write_reg(priv, 0);
2537 eeprom_write_reg(priv, EEPROM_BIT_SK);
2540 /* push a single bit down to the eeprom */
2541 static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
2543 int d = (bit ? EEPROM_BIT_DI : 0);
2544 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2545 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
2548 /* push an opcode followed by an address down to the eeprom */
2549 static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
2554 eeprom_write_bit(priv, 1);
2555 eeprom_write_bit(priv, op & 2);
2556 eeprom_write_bit(priv, op & 1);
2557 for (i = 7; i >= 0; i--) {
2558 eeprom_write_bit(priv, addr & (1 << i));
2562 /* pull 16 bits off the eeprom, one bit at a time */
2563 static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
2568 /* Send READ Opcode */
2569 eeprom_op(priv, EEPROM_CMD_READ, addr);
2571 /* Send dummy bit */
2572 eeprom_write_reg(priv, EEPROM_BIT_CS);
2574 /* Read the byte off the eeprom one bit at a time */
2575 for (i = 0; i < 16; i++) {
2577 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2578 eeprom_write_reg(priv, EEPROM_BIT_CS);
2579 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2580 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
2583 /* Send another dummy bit */
2584 eeprom_write_reg(priv, 0);
2585 eeprom_disable_cs(priv);
2590 /* helper function for pulling the mac address out of the private */
2591 /* data's copy of the eeprom data */
2592 static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
2594 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
2598 * Either the device driver (i.e. the host) or the firmware can
2599 * load eeprom data into the designated region in SRAM. If neither
2600 * happens then the FW will shutdown with a fatal error.
2602 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2603 * bit needs region of shared SRAM needs to be non-zero.
2605 static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2608 u16 *eeprom = (u16 *) priv->eeprom;
2610 IPW_DEBUG_TRACE(">>\n");
2612 /* read entire contents of eeprom into private buffer */
2613 for (i = 0; i < 128; i++)
2614 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
2617 If the data looks correct, then copy it to our private
2618 copy. Otherwise let the firmware know to perform the operation
2621 if (priv->eeprom[EEPROM_VERSION] != 0) {
2622 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2624 /* write the eeprom data to sram */
2625 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
2626 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
2628 /* Do not load eeprom data on fatal error or suspend */
2629 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2631 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2633 /* Load eeprom data on fatal error or suspend */
2634 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2637 IPW_DEBUG_TRACE("<<\n");
2640 static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
2645 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
2647 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
2650 static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2652 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
2653 CB_NUMBER_OF_ELEMENTS_SMALL *
2654 sizeof(struct command_block));
2657 static int ipw_fw_dma_enable(struct ipw_priv *priv)
2658 { /* start dma engine but no transfers yet */
2660 IPW_DEBUG_FW(">> : \n");
2663 ipw_fw_dma_reset_command_blocks(priv);
2665 /* Write CB base address */
2666 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
2668 IPW_DEBUG_FW("<< : \n");
2672 static void ipw_fw_dma_abort(struct ipw_priv *priv)
2676 IPW_DEBUG_FW(">> :\n");
2678 //set the Stop and Abort bit
2679 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
2680 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2681 priv->sram_desc.last_cb_index = 0;
2683 IPW_DEBUG_FW("<< \n");
2686 static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2687 struct command_block *cb)
2690 IPW_SHARED_SRAM_DMA_CONTROL +
2691 (sizeof(struct command_block) * index);
2692 IPW_DEBUG_FW(">> :\n");
2694 ipw_write_indirect(priv, address, (u8 *) cb,
2695 (int)sizeof(struct command_block));
2697 IPW_DEBUG_FW("<< :\n");
2702 static int ipw_fw_dma_kick(struct ipw_priv *priv)
2707 IPW_DEBUG_FW(">> :\n");
2709 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
2710 ipw_fw_dma_write_command_block(priv, index,
2711 &priv->sram_desc.cb_list[index]);
2713 /* Enable the DMA in the CSR register */
2714 ipw_clear_bit(priv, IPW_RESET_REG,
2715 IPW_RESET_REG_MASTER_DISABLED |
2716 IPW_RESET_REG_STOP_MASTER);
2718 /* Set the Start bit. */
2719 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
2720 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2722 IPW_DEBUG_FW("<< :\n");
2726 static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2729 u32 register_value = 0;
2730 u32 cb_fields_address = 0;
2732 IPW_DEBUG_FW(">> :\n");
2733 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2734 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
2736 /* Read the DMA Controlor register */
2737 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2738 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
2740 /* Print the CB values */
2741 cb_fields_address = address;
2742 register_value = ipw_read_reg32(priv, cb_fields_address);
2743 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
2745 cb_fields_address += sizeof(u32);
2746 register_value = ipw_read_reg32(priv, cb_fields_address);
2747 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
2749 cb_fields_address += sizeof(u32);
2750 register_value = ipw_read_reg32(priv, cb_fields_address);
2751 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2754 cb_fields_address += sizeof(u32);
2755 register_value = ipw_read_reg32(priv, cb_fields_address);
2756 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
2758 IPW_DEBUG_FW(">> :\n");
2761 static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2763 u32 current_cb_address = 0;
2764 u32 current_cb_index = 0;
2766 IPW_DEBUG_FW("<< :\n");
2767 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2769 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
2770 sizeof(struct command_block);
2772 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
2773 current_cb_index, current_cb_address);
2775 IPW_DEBUG_FW(">> :\n");
2776 return current_cb_index;
2780 static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2784 int interrupt_enabled, int is_last)
2787 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
2788 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2790 struct command_block *cb;
2791 u32 last_cb_element = 0;
2793 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2794 src_address, dest_address, length);
2796 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2799 last_cb_element = priv->sram_desc.last_cb_index;
2800 cb = &priv->sram_desc.cb_list[last_cb_element];
2801 priv->sram_desc.last_cb_index++;
2803 /* Calculate the new CB control word */
2804 if (interrupt_enabled)
2805 control |= CB_INT_ENABLED;
2808 control |= CB_LAST_VALID;
2812 /* Calculate the CB Element's checksum value */
2813 cb->status = control ^ src_address ^ dest_address;
2815 /* Copy the Source and Destination addresses */
2816 cb->dest_addr = dest_address;
2817 cb->source_addr = src_address;
2819 /* Copy the Control Word last */
2820 cb->control = control;
2825 static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
2826 u32 src_phys, u32 dest_address, u32 length)
2828 u32 bytes_left = length;
2830 u32 dest_offset = 0;
2832 IPW_DEBUG_FW(">> \n");
2833 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2834 src_phys, dest_address, length);
2835 while (bytes_left > CB_MAX_LENGTH) {
2836 status = ipw_fw_dma_add_command_block(priv,
2837 src_phys + src_offset,
2840 CB_MAX_LENGTH, 0, 0);
2842 IPW_DEBUG_FW_INFO(": Failed\n");
2845 IPW_DEBUG_FW_INFO(": Added new cb\n");
2847 src_offset += CB_MAX_LENGTH;
2848 dest_offset += CB_MAX_LENGTH;
2849 bytes_left -= CB_MAX_LENGTH;
2852 /* add the buffer tail */
2853 if (bytes_left > 0) {
2855 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2856 dest_address + dest_offset,
2859 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2863 (": Adding new cb - the buffer tail\n");
2866 IPW_DEBUG_FW("<< \n");
2870 static int ipw_fw_dma_wait(struct ipw_priv *priv)
2872 u32 current_index = 0, previous_index;
2875 IPW_DEBUG_FW(">> : \n");
2877 current_index = ipw_fw_dma_command_block_index(priv);
2878 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
2879 (int)priv->sram_desc.last_cb_index);
2881 while (current_index < priv->sram_desc.last_cb_index) {
2883 previous_index = current_index;
2884 current_index = ipw_fw_dma_command_block_index(priv);
2886 if (previous_index < current_index) {
2890 if (++watchdog > 400) {
2891 IPW_DEBUG_FW_INFO("Timeout\n");
2892 ipw_fw_dma_dump_command_block(priv);
2893 ipw_fw_dma_abort(priv);
2898 ipw_fw_dma_abort(priv);
2900 /*Disable the DMA in the CSR register */
2901 ipw_set_bit(priv, IPW_RESET_REG,
2902 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
2904 IPW_DEBUG_FW("<< dmaWaitSync \n");
2908 static void ipw_remove_current_network(struct ipw_priv *priv)
2910 struct list_head *element, *safe;
2911 struct ieee80211_network *network = NULL;
2912 unsigned long flags;
2914 spin_lock_irqsave(&priv->ieee->lock, flags);
2915 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2916 network = list_entry(element, struct ieee80211_network, list);
2917 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2919 list_add_tail(&network->list,
2920 &priv->ieee->network_free_list);
2923 spin_unlock_irqrestore(&priv->ieee->lock, flags);
2927 * Check that card is still alive.
2928 * Reads debug register from domain0.
2929 * If card is present, pre-defined value should
2933 * @return 1 if card is present, 0 otherwise
2935 static inline int ipw_alive(struct ipw_priv *priv)
2937 return ipw_read32(priv, 0x90) == 0xd55555d5;
2940 /* timeout in msec, attempted in 10-msec quanta */
2941 static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2947 if ((ipw_read32(priv, addr) & mask) == mask)
2951 } while (i < timeout);
2956 /* These functions load the firmware and micro code for the operation of
2957 * the ipw hardware. It assumes the buffer has all the bits for the
2958 * image and the caller is handling the memory allocation and clean up.
2961 static int ipw_stop_master(struct ipw_priv *priv)
2965 IPW_DEBUG_TRACE(">> \n");
2966 /* stop master. typical delay - 0 */
2967 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
2969 /* timeout is in msec, polled in 10-msec quanta */
2970 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2971 IPW_RESET_REG_MASTER_DISABLED, 100);
2973 IPW_ERROR("wait for stop master failed after 100ms\n");
2977 IPW_DEBUG_INFO("stop master %dms\n", rc);
2982 static void ipw_arc_release(struct ipw_priv *priv)
2984 IPW_DEBUG_TRACE(">> \n");
2987 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
2989 /* no one knows timing, for safety add some delay */
2998 static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
3000 int rc = 0, i, addr;
3004 image = (u16 *) data;
3006 IPW_DEBUG_TRACE(">> \n");
3008 rc = ipw_stop_master(priv);
3013 // spin_lock_irqsave(&priv->lock, flags);
3015 for (addr = IPW_SHARED_LOWER_BOUND;
3016 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
3017 ipw_write32(priv, addr, 0);
3020 /* no ucode (yet) */
3021 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3022 /* destroy DMA queues */
3023 /* reset sequence */
3025 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
3026 ipw_arc_release(priv);
3027 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
3031 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
3034 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
3037 /* enable ucode store */
3038 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3039 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
3045 * Do NOT set indirect address register once and then
3046 * store data to indirect data register in the loop.
3047 * It seems very reasonable, but in this case DINO do not
3048 * accept ucode. It is essential to set address each time.
3050 /* load new ipw uCode */
3051 for (i = 0; i < len / 2; i++)
3052 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
3053 cpu_to_le16(image[i]));
3056 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3057 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
3059 /* this is where the igx / win driver deveates from the VAP driver. */
3061 /* wait for alive response */
3062 for (i = 0; i < 100; i++) {
3063 /* poll for incoming data */
3064 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
3065 if (cr & DINO_RXFIFO_DATA)
3070 if (cr & DINO_RXFIFO_DATA) {
3071 /* alive_command_responce size is NOT multiple of 4 */
3072 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
3074 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
3075 response_buffer[i] =
3076 le32_to_cpu(ipw_read_reg32(priv,
3077 IPW_BASEBAND_RX_FIFO_READ));
3078 memcpy(&priv->dino_alive, response_buffer,
3079 sizeof(priv->dino_alive));
3080 if (priv->dino_alive.alive_command == 1
3081 && priv->dino_alive.ucode_valid == 1) {
3084 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3085 "of %02d/%02d/%02d %02d:%02d\n",
3086 priv->dino_alive.software_revision,
3087 priv->dino_alive.software_revision,
3088 priv->dino_alive.device_identifier,
3089 priv->dino_alive.device_identifier,
3090 priv->dino_alive.time_stamp[0],
3091 priv->dino_alive.time_stamp[1],
3092 priv->dino_alive.time_stamp[2],
3093 priv->dino_alive.time_stamp[3],
3094 priv->dino_alive.time_stamp[4]);
3096 IPW_DEBUG_INFO("Microcode is not alive\n");
3100 IPW_DEBUG_INFO("No alive response from DINO\n");
3104 /* disable DINO, otherwise for some reason
3105 firmware have problem getting alive resp. */
3106 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3108 // spin_unlock_irqrestore(&priv->lock, flags);
3113 static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
3117 struct fw_chunk *chunk;
3118 dma_addr_t shared_phys;
3121 IPW_DEBUG_TRACE("<< : \n");
3122 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
3127 memmove(shared_virt, data, len);
3130 rc = ipw_fw_dma_enable(priv);
3132 if (priv->sram_desc.last_cb_index > 0) {
3133 /* the DMA is already ready this would be a bug. */
3139 chunk = (struct fw_chunk *)(data + offset);
3140 offset += sizeof(struct fw_chunk);
3141 /* build DMA packet and queue up for sending */
3142 /* dma to chunk->address, the chunk->length bytes from data +
3145 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
3146 le32_to_cpu(chunk->address),
3147 le32_to_cpu(chunk->length));
3149 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3153 offset += le32_to_cpu(chunk->length);
3154 } while (offset < len);
3156 /* Run the DMA and wait for the answer */
3157 rc = ipw_fw_dma_kick(priv);
3159 IPW_ERROR("dmaKick Failed\n");
3163 rc = ipw_fw_dma_wait(priv);
3165 IPW_ERROR("dmaWaitSync Failed\n");
3169 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
3174 static int ipw_stop_nic(struct ipw_priv *priv)
3179 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
3181 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3182 IPW_RESET_REG_MASTER_DISABLED, 500);
3184 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
3188 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
3193 static void ipw_start_nic(struct ipw_priv *priv)
3195 IPW_DEBUG_TRACE(">>\n");
3197 /* prvHwStartNic release ARC */
3198 ipw_clear_bit(priv, IPW_RESET_REG,
3199 IPW_RESET_REG_MASTER_DISABLED |
3200 IPW_RESET_REG_STOP_MASTER |
3201 CBD_RESET_REG_PRINCETON_RESET);
3203 /* enable power management */
3204 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3205 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
3207 IPW_DEBUG_TRACE("<<\n");
3210 static int ipw_init_nic(struct ipw_priv *priv)
3214 IPW_DEBUG_TRACE(">>\n");
3217 /* set "initialization complete" bit to move adapter to D0 state */
3218 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3220 /* low-level PLL activation */
3221 ipw_write32(priv, IPW_READ_INT_REGISTER,
3222 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
3224 /* wait for clock stabilization */
3225 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3226 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
3228 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3230 /* assert SW reset */
3231 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
3235 /* set "initialization complete" bit to move adapter to D0 state */
3236 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3238 IPW_DEBUG_TRACE(">>\n");
3242 /* Call this function from process context, it will sleep in request_firmware.
3243 * Probe is an ok place to call this from.
3245 static int ipw_reset_nic(struct ipw_priv *priv)
3248 unsigned long flags;
3250 IPW_DEBUG_TRACE(">>\n");
3252 rc = ipw_init_nic(priv);
3254 spin_lock_irqsave(&priv->lock, flags);
3255 /* Clear the 'host command active' bit... */
3256 priv->status &= ~STATUS_HCMD_ACTIVE;
3257 wake_up_interruptible(&priv->wait_command_queue);
3258 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3259 wake_up_interruptible(&priv->wait_state);
3260 spin_unlock_irqrestore(&priv->lock, flags);
3262 IPW_DEBUG_TRACE("<<\n");
3275 static int ipw_get_fw(struct ipw_priv *priv,
3276 const struct firmware **raw, const char *name)
3281 /* ask firmware_class module to get the boot firmware off disk */
3282 rc = request_firmware(raw, name, &priv->pci_dev->dev);
3284 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
3288 if ((*raw)->size < sizeof(*fw)) {
3289 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
3293 fw = (void *)(*raw)->data;
3295 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3296 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
3297 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3298 name, (*raw)->size);
3302 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
3304 le32_to_cpu(fw->ver) >> 16,
3305 le32_to_cpu(fw->ver) & 0xff,
3306 (*raw)->size - sizeof(*fw));
3310 #define IPW_RX_BUF_SIZE (3000)
3312 static void ipw_rx_queue_reset(struct ipw_priv *priv,
3313 struct ipw_rx_queue *rxq)
3315 unsigned long flags;
3318 spin_lock_irqsave(&rxq->lock, flags);
3320 INIT_LIST_HEAD(&rxq->rx_free);
3321 INIT_LIST_HEAD(&rxq->rx_used);
3323 /* Fill the rx_used queue with _all_ of the Rx buffers */
3324 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3325 /* In the reset function, these buffers may have been allocated
3326 * to an SKB, so we need to unmap and free potential storage */
3327 if (rxq->pool[i].skb != NULL) {
3328 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
3329 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
3330 dev_kfree_skb(rxq->pool[i].skb);
3331 rxq->pool[i].skb = NULL;
3333 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3336 /* Set us so that we have processed and used all buffers, but have
3337 * not restocked the Rx queue with fresh buffers */
3338 rxq->read = rxq->write = 0;
3339 rxq->processed = RX_QUEUE_SIZE - 1;
3340 rxq->free_count = 0;
3341 spin_unlock_irqrestore(&rxq->lock, flags);
3345 static int fw_loaded = 0;
3346 static const struct firmware *raw = NULL;
3348 static void free_firmware(void)
3351 release_firmware(raw);
3357 #define free_firmware() do {} while (0)
3360 static int ipw_load(struct ipw_priv *priv)
3363 const struct firmware *raw = NULL;
3366 u8 *boot_img, *ucode_img, *fw_img;
3368 int rc = 0, retries = 3;
3370 switch (priv->ieee->iw_mode) {
3372 name = "ipw2200-ibss.fw";
3374 #ifdef CONFIG_IPW2200_MONITOR
3375 case IW_MODE_MONITOR:
3376 name = "ipw2200-sniffer.fw";
3380 name = "ipw2200-bss.fw";
3392 rc = ipw_get_fw(priv, &raw, name);
3399 fw = (void *)raw->data;
3400 boot_img = &fw->data[0];
3401 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3402 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3403 le32_to_cpu(fw->ucode_size)];
3409 priv->rxq = ipw_rx_queue_alloc(priv);
3411 ipw_rx_queue_reset(priv, priv->rxq);
3413 IPW_ERROR("Unable to initialize Rx queue\n");
3418 /* Ensure interrupts are disabled */
3419 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3420 priv->status &= ~STATUS_INT_ENABLED;
3422 /* ack pending interrupts */
3423 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3427 rc = ipw_reset_nic(priv);
3429 IPW_ERROR("Unable to reset NIC\n");
3433 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3434 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
3436 /* DMA the initial boot firmware into the device */
3437 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
3439 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
3443 /* kick start the device */
3444 ipw_start_nic(priv);
3446 /* wait for the device to finish its initial startup sequence */
3447 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3448 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3450 IPW_ERROR("device failed to boot initial fw image\n");
3453 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3455 /* ack fw init done interrupt */
3456 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3458 /* DMA the ucode into the device */
3459 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
3461 IPW_ERROR("Unable to load ucode: %d\n", rc);
3468 /* DMA bss firmware into the device */
3469 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
3471 IPW_ERROR("Unable to load firmware: %d\n", rc);
3478 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3480 rc = ipw_queue_reset(priv);
3482 IPW_ERROR("Unable to initialize queues\n");
3486 /* Ensure interrupts are disabled */
3487 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3488 /* ack pending interrupts */
3489 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3491 /* kick start the device */
3492 ipw_start_nic(priv);
3494 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
3496 IPW_WARNING("Parity error. Retrying init.\n");
3501 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3506 /* wait for the device */
3507 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3508 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3510 IPW_ERROR("device failed to start within 500ms\n");
3513 IPW_DEBUG_INFO("device response after %dms\n", rc);
3515 /* ack fw init done interrupt */
3516 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3518 /* read eeprom data and initialize the eeprom region of sram */
3519 priv->eeprom_delay = 1;
3520 ipw_eeprom_init_sram(priv);
3522 /* enable interrupts */
3523 ipw_enable_interrupts(priv);
3525 /* Ensure our queue has valid packets */
3526 ipw_rx_queue_replenish(priv);
3528 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
3530 /* ack pending interrupts */
3531 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3534 release_firmware(raw);
3540 ipw_rx_queue_free(priv, priv->rxq);
3543 ipw_tx_queue_free(priv);
3545 release_firmware(raw);
3557 * Theory of operation
3559 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3560 * 2 empty entries always kept in the buffer to protect from overflow.
3562 * For Tx queue, there are low mark and high mark limits. If, after queuing
3563 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3564 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
3567 * The IPW operates with six queues, one receive queue in the device's
3568 * sram, one transmit queue for sending commands to the device firmware,
3569 * and four transmit queues for data.
3571 * The four transmit queues allow for performing quality of service (qos)
3572 * transmissions as per the 802.11 protocol. Currently Linux does not
3573 * provide a mechanism to the user for utilizing prioritized queues, so
3574 * we only utilize the first data transmit queue (queue1).
3578 * Driver allocates buffers of this size for Rx
3581 static inline int ipw_queue_space(const struct clx2_queue *q)
3583 int s = q->last_used - q->first_empty;
3586 s -= 2; /* keep some reserve to not confuse empty and full situations */
3592 static inline int ipw_queue_inc_wrap(int index, int n_bd)
3594 return (++index == n_bd) ? 0 : index;
3598 * Initialize common DMA queue structure
3600 * @param q queue to init
3601 * @param count Number of BD's to allocate. Should be power of 2
3602 * @param read_register Address for 'read' register
3603 * (not offset within BAR, full address)
3604 * @param write_register Address for 'write' register
3605 * (not offset within BAR, full address)
3606 * @param base_register Address for 'base' register
3607 * (not offset within BAR, full address)
3608 * @param size Address for 'size' register
3609 * (not offset within BAR, full address)
3611 static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
3612 int count, u32 read, u32 write, u32 base, u32 size)
3616 q->low_mark = q->n_bd / 4;
3617 if (q->low_mark < 4)
3620 q->high_mark = q->n_bd / 8;
3621 if (q->high_mark < 2)
3624 q->first_empty = q->last_used = 0;
3628 ipw_write32(priv, base, q->dma_addr);
3629 ipw_write32(priv, size, count);
3630 ipw_write32(priv, read, 0);
3631 ipw_write32(priv, write, 0);
3633 _ipw_read32(priv, 0x90);
3636 static int ipw_queue_tx_init(struct ipw_priv *priv,
3637 struct clx2_tx_queue *q,
3638 int count, u32 read, u32 write, u32 base, u32 size)
3640 struct pci_dev *dev = priv->pci_dev;
3642 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3644 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3649 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
3651 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
3652 sizeof(q->bd[0]) * count);
3658 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3663 * Free one TFD, those at index [txq->q.last_used].
3664 * Do NOT advance any indexes
3669 static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3670 struct clx2_tx_queue *txq)
3672 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3673 struct pci_dev *dev = priv->pci_dev;
3677 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3678 /* nothing to cleanup after for host commands */
3682 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3683 IPW_ERROR("Too many chunks: %i\n",
3684 le32_to_cpu(bd->u.data.num_chunks));
3685 /** @todo issue fatal error, it is quite serious situation */
3689 /* unmap chunks if any */
3690 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3691 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3692 le16_to_cpu(bd->u.data.chunk_len[i]),
3694 if (txq->txb[txq->q.last_used]) {
3695 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3696 txq->txb[txq->q.last_used] = NULL;
3702 * Deallocate DMA queue.
3704 * Empty queue by removing and destroying all BD's.
3710 static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
3712 struct clx2_queue *q = &txq->q;
3713 struct pci_dev *dev = priv->pci_dev;
3718 /* first, empty all BD's */
3719 for (; q->first_empty != q->last_used;
3720 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3721 ipw_queue_tx_free_tfd(priv, txq);
3724 /* free buffers belonging to queue itself */
3725 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
3729 /* 0 fill whole structure */
3730 memset(txq, 0, sizeof(*txq));
3734 * Destroy all DMA queues and structures
3738 static void ipw_tx_queue_free(struct ipw_priv *priv)
3741 ipw_queue_tx_free(priv, &priv->txq_cmd);
3744 ipw_queue_tx_free(priv, &priv->txq[0]);
3745 ipw_queue_tx_free(priv, &priv->txq[1]);
3746 ipw_queue_tx_free(priv, &priv->txq[2]);
3747 ipw_queue_tx_free(priv, &priv->txq[3]);
3750 static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
3752 /* First 3 bytes are manufacturer */
3753 bssid[0] = priv->mac_addr[0];
3754 bssid[1] = priv->mac_addr[1];
3755 bssid[2] = priv->mac_addr[2];
3757 /* Last bytes are random */
3758 get_random_bytes(&bssid[3], ETH_ALEN - 3);
3760 bssid[0] &= 0xfe; /* clear multicast bit */
3761 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
3764 static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
3766 struct ipw_station_entry entry;
3769 for (i = 0; i < priv->num_stations; i++) {
3770 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3771 /* Another node is active in network */
3772 priv->missed_adhoc_beacons = 0;
3773 if (!(priv->config & CFG_STATIC_CHANNEL))
3774 /* when other nodes drop out, we drop out */
3775 priv->config &= ~CFG_ADHOC_PERSIST;
3781 if (i == MAX_STATIONS)
3782 return IPW_INVALID_STATION;
3784 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3787 entry.support_mode = 0;
3788 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3789 memcpy(priv->stations[i], bssid, ETH_ALEN);
3790 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
3791 &entry, sizeof(entry));
3792 priv->num_stations++;
3797 static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
3801 for (i = 0; i < priv->num_stations; i++)
3802 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
3805 return IPW_INVALID_STATION;
3808 static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3812 if (priv->status & STATUS_ASSOCIATING) {
3813 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3814 queue_work(priv->workqueue, &priv->disassociate);
3818 if (!(priv->status & STATUS_ASSOCIATED)) {
3819 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3823 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3825 MAC_ARG(priv->assoc_request.bssid),
3826 priv->assoc_request.channel);
3828 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3829 priv->status |= STATUS_DISASSOCIATING;
3832 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3834 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
3836 err = ipw_send_associate(priv, &priv->assoc_request);
3838 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3845 static int ipw_disassociate(void *data)
3847 struct ipw_priv *priv = data;
3848 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3850 ipw_send_disassociate(data, 0);
3854 static void ipw_bg_disassociate(void *data)
3856 struct ipw_priv *priv = data;
3857 mutex_lock(&priv->mutex);
3858 ipw_disassociate(data);
3859 mutex_unlock(&priv->mutex);
3862 static void ipw_system_config(void *data)
3864 struct ipw_priv *priv = data;
3866 #ifdef CONFIG_IPW2200_PROMISCUOUS
3867 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
3868 priv->sys_config.accept_all_data_frames = 1;
3869 priv->sys_config.accept_non_directed_frames = 1;
3870 priv->sys_config.accept_all_mgmt_bcpr = 1;
3871 priv->sys_config.accept_all_mgmt_frames = 1;
3875 ipw_send_system_config(priv);
3878 struct ipw_status_code {
3883 static const struct ipw_status_code ipw_status_codes[] = {
3884 {0x00, "Successful"},
3885 {0x01, "Unspecified failure"},
3886 {0x0A, "Cannot support all requested capabilities in the "
3887 "Capability information field"},
3888 {0x0B, "Reassociation denied due to inability to confirm that "
3889 "association exists"},
3890 {0x0C, "Association denied due to reason outside the scope of this "
3893 "Responding station does not support the specified authentication "
3896 "Received an Authentication frame with authentication sequence "
3897 "transaction sequence number out of expected sequence"},
3898 {0x0F, "Authentication rejected because of challenge failure"},
3899 {0x10, "Authentication rejected due to timeout waiting for next "
3900 "frame in sequence"},
3901 {0x11, "Association denied because AP is unable to handle additional "
3902 "associated stations"},
3904 "Association denied due to requesting station not supporting all "
3905 "of the datarates in the BSSBasicServiceSet Parameter"},
3907 "Association denied due to requesting station not supporting "
3908 "short preamble operation"},
3910 "Association denied due to requesting station not supporting "
3913 "Association denied due to requesting station not supporting "
3916 "Association denied due to requesting station not supporting "
3917 "short slot operation"},
3919 "Association denied due to requesting station not supporting "
3920 "DSSS-OFDM operation"},
3921 {0x28, "Invalid Information Element"},
3922 {0x29, "Group Cipher is not valid"},
3923 {0x2A, "Pairwise Cipher is not valid"},
3924 {0x2B, "AKMP is not valid"},
3925 {0x2C, "Unsupported RSN IE version"},
3926 {0x2D, "Invalid RSN IE Capabilities"},
3927 {0x2E, "Cipher suite is rejected per security policy"},
3930 #ifdef CONFIG_IPW2200_DEBUG
3931 static const char *ipw_get_status_code(u16 status)
3934 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
3935 if (ipw_status_codes[i].status == (status & 0xff))
3936 return ipw_status_codes[i].reason;
3937 return "Unknown status value.";
3941 static void inline average_init(struct average *avg)
3943 memset(avg, 0, sizeof(*avg));
3946 #define DEPTH_RSSI 8
3947 #define DEPTH_NOISE 16
3948 static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
3950 return ((depth-1)*prev_avg + val)/depth;
3953 static void average_add(struct average *avg, s16 val)
3955 avg->sum -= avg->entries[avg->pos];
3957 avg->entries[avg->pos++] = val;
3958 if (unlikely(avg->pos == AVG_ENTRIES)) {
3964 static s16 average_value(struct average *avg)
3966 if (!unlikely(avg->init)) {
3968 return avg->sum / avg->pos;
3972 return avg->sum / AVG_ENTRIES;
3975 static void ipw_reset_stats(struct ipw_priv *priv)
3977 u32 len = sizeof(u32);
3981 average_init(&priv->average_missed_beacons);
3982 priv->exp_avg_rssi = -60;
3983 priv->exp_avg_noise = -85 + 0x100;
3985 priv->last_rate = 0;
3986 priv->last_missed_beacons = 0;
3987 priv->last_rx_packets = 0;
3988 priv->last_tx_packets = 0;
3989 priv->last_tx_failures = 0;
3991 /* Firmware managed, reset only when NIC is restarted, so we have to
3992 * normalize on the current value */
3993 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
3994 &priv->last_rx_err, &len);
3995 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
3996 &priv->last_tx_failures, &len);
3998 /* Driver managed, reset with each association */
3999 priv->missed_adhoc_beacons = 0;
4000 priv->missed_beacons = 0;
4001 priv->tx_packets = 0;
4002 priv->rx_packets = 0;
4006 static u32 ipw_get_max_rate(struct ipw_priv *priv)
4009 u32 mask = priv->rates_mask;
4010 /* If currently associated in B mode, restrict the maximum
4011 * rate match to B rates */
4012 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
4013 mask &= IEEE80211_CCK_RATES_MASK;
4015 /* TODO: Verify that the rate is supported by the current rates
4018 while (i && !(mask & i))
4021 case IEEE80211_CCK_RATE_1MB_MASK:
4023 case IEEE80211_CCK_RATE_2MB_MASK:
4025 case IEEE80211_CCK_RATE_5MB_MASK:
4027 case IEEE80211_OFDM_RATE_6MB_MASK:
4029 case IEEE80211_OFDM_RATE_9MB_MASK:
4031 case IEEE80211_CCK_RATE_11MB_MASK:
4033 case IEEE80211_OFDM_RATE_12MB_MASK:
4035 case IEEE80211_OFDM_RATE_18MB_MASK:
4037 case IEEE80211_OFDM_RATE_24MB_MASK:
4039 case IEEE80211_OFDM_RATE_36MB_MASK:
4041 case IEEE80211_OFDM_RATE_48MB_MASK:
4043 case IEEE80211_OFDM_RATE_54MB_MASK:
4047 if (priv->ieee->mode == IEEE_B)
4053 static u32 ipw_get_current_rate(struct ipw_priv *priv)
4055 u32 rate, len = sizeof(rate);
4058 if (!(priv->status & STATUS_ASSOCIATED))
4061 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
4062 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
4065 IPW_DEBUG_INFO("failed querying ordinals.\n");
4069 return ipw_get_max_rate(priv);
4072 case IPW_TX_RATE_1MB:
4074 case IPW_TX_RATE_2MB:
4076 case IPW_TX_RATE_5MB:
4078 case IPW_TX_RATE_6MB:
4080 case IPW_TX_RATE_9MB:
4082 case IPW_TX_RATE_11MB:
4084 case IPW_TX_RATE_12MB:
4086 case IPW_TX_RATE_18MB:
4088 case IPW_TX_RATE_24MB:
4090 case IPW_TX_RATE_36MB:
4092 case IPW_TX_RATE_48MB:
4094 case IPW_TX_RATE_54MB:
4101 #define IPW_STATS_INTERVAL (2 * HZ)
4102 static void ipw_gather_stats(struct ipw_priv *priv)
4104 u32 rx_err, rx_err_delta, rx_packets_delta;
4105 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4106 u32 missed_beacons_percent, missed_beacons_delta;
4108 u32 len = sizeof(u32);
4110 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
4114 if (!(priv->status & STATUS_ASSOCIATED)) {
4119 /* Update the statistics */
4120 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
4121 &priv->missed_beacons, &len);
4122 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
4123 priv->last_missed_beacons = priv->missed_beacons;
4124 if (priv->assoc_request.beacon_interval) {
4125 missed_beacons_percent = missed_beacons_delta *
4126 (HZ * priv->assoc_request.beacon_interval) /
4127 (IPW_STATS_INTERVAL * 10);
4129 missed_beacons_percent = 0;
4131 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4133 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4134 rx_err_delta = rx_err - priv->last_rx_err;
4135 priv->last_rx_err = rx_err;
4137 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4138 tx_failures_delta = tx_failures - priv->last_tx_failures;
4139 priv->last_tx_failures = tx_failures;
4141 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4142 priv->last_rx_packets = priv->rx_packets;
4144 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4145 priv->last_tx_packets = priv->tx_packets;
4147 /* Calculate quality based on the following:
4149 * Missed beacon: 100% = 0, 0% = 70% missed
4150 * Rate: 60% = 1Mbs, 100% = Max
4151 * Rx and Tx errors represent a straight % of total Rx/Tx
4152 * RSSI: 100% = > -50, 0% = < -80
4153 * Rx errors: 100% = 0, 0% = 50% missed
4155 * The lowest computed quality is used.
4158 #define BEACON_THRESHOLD 5
4159 beacon_quality = 100 - missed_beacons_percent;
4160 if (beacon_quality < BEACON_THRESHOLD)
4163 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
4164 (100 - BEACON_THRESHOLD);
4165 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
4166 beacon_quality, missed_beacons_percent);
4168 priv->last_rate = ipw_get_current_rate(priv);
4169 max_rate = ipw_get_max_rate(priv);
4170 rate_quality = priv->last_rate * 40 / max_rate + 60;
4171 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4172 rate_quality, priv->last_rate / 1000000);
4174 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
4175 rx_quality = 100 - (rx_err_delta * 100) /
4176 (rx_packets_delta + rx_err_delta);
4179 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4180 rx_quality, rx_err_delta, rx_packets_delta);
4182 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
4183 tx_quality = 100 - (tx_failures_delta * 100) /
4184 (tx_packets_delta + tx_failures_delta);
4187 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4188 tx_quality, tx_failures_delta, tx_packets_delta);
4190 rssi = priv->exp_avg_rssi;
4193 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4194 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4195 (priv->ieee->perfect_rssi - rssi) *
4196 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4197 62 * (priv->ieee->perfect_rssi - rssi))) /
4198 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4199 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4200 if (signal_quality > 100)
4201 signal_quality = 100;
4202 else if (signal_quality < 1)
4205 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
4206 signal_quality, rssi);
4208 quality = min(beacon_quality,
4210 min(tx_quality, min(rx_quality, signal_quality))));
4211 if (quality == beacon_quality)
4212 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4214 if (quality == rate_quality)
4215 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4217 if (quality == tx_quality)
4218 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4220 if (quality == rx_quality)
4221 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4223 if (quality == signal_quality)
4224 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4227 priv->quality = quality;
4229 queue_delayed_work(priv->workqueue, &priv->gather_stats,
4230 IPW_STATS_INTERVAL);
4233 static void ipw_bg_gather_stats(void *data)
4235 struct ipw_priv *priv = data;
4236 mutex_lock(&priv->mutex);
4237 ipw_gather_stats(data);
4238 mutex_unlock(&priv->mutex);
4241 /* Missed beacon behavior:
4242 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4243 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4244 * Above disassociate threshold, give up and stop scanning.
4245 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
4246 static void ipw_handle_missed_beacon(struct ipw_priv *priv,
4249 priv->notif_missed_beacons = missed_count;
4251 if (missed_count > priv->disassociate_threshold &&
4252 priv->status & STATUS_ASSOCIATED) {
4253 /* If associated and we've hit the missed
4254 * beacon threshold, disassociate, turn
4255 * off roaming, and abort any active scans */
4256 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4257 IPW_DL_STATE | IPW_DL_ASSOC,
4258 "Missed beacon: %d - disassociate\n", missed_count);
4259 priv->status &= ~STATUS_ROAMING;
4260 if (priv->status & STATUS_SCANNING) {
4261 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4263 "Aborting scan with missed beacon.\n");
4264 queue_work(priv->workqueue, &priv->abort_scan);
4267 queue_work(priv->workqueue, &priv->disassociate);
4271 if (priv->status & STATUS_ROAMING) {
4272 /* If we are currently roaming, then just
4273 * print a debug statement... */
4274 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4275 "Missed beacon: %d - roam in progress\n",
4281 (missed_count > priv->roaming_threshold &&
4282 missed_count <= priv->disassociate_threshold)) {
4283 /* If we are not already roaming, set the ROAM
4284 * bit in the status and kick off a scan.
4285 * This can happen several times before we reach
4286 * disassociate_threshold. */
4287 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4288 "Missed beacon: %d - initiate "
4289 "roaming\n", missed_count);
4290 if (!(priv->status & STATUS_ROAMING)) {
4291 priv->status |= STATUS_ROAMING;
4292 if (!(priv->status & STATUS_SCANNING))
4293 queue_work(priv->workqueue,
4294 &priv->request_scan);
4299 if (priv->status & STATUS_SCANNING) {
4300 /* Stop scan to keep fw from getting
4301 * stuck (only if we aren't roaming --
4302 * otherwise we'll never scan more than 2 or 3
4304 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4305 "Aborting scan with missed beacon.\n");
4306 queue_work(priv->workqueue, &priv->abort_scan);
4309 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
4313 * Handle host notification packet.
4314 * Called from interrupt routine
4316 static void ipw_rx_notification(struct ipw_priv *priv,
4317 struct ipw_rx_notification *notif)
4319 notif->size = le16_to_cpu(notif->size);
4321 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
4323 switch (notif->subtype) {
4324 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4325 struct notif_association *assoc = ¬if->u.assoc;
4327 switch (assoc->state) {
4328 case CMAS_ASSOCIATED:{
4329 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4331 "associated: '%s' " MAC_FMT
4333 escape_essid(priv->essid,
4335 MAC_ARG(priv->bssid));
4337 switch (priv->ieee->iw_mode) {
4339 memcpy(priv->ieee->bssid,
4340 priv->bssid, ETH_ALEN);
4344 memcpy(priv->ieee->bssid,
4345 priv->bssid, ETH_ALEN);
4347 /* clear out the station table */
4348 priv->num_stations = 0;
4351 ("queueing adhoc check\n");
4352 queue_delayed_work(priv->
4362 priv->status &= ~STATUS_ASSOCIATING;
4363 priv->status |= STATUS_ASSOCIATED;
4364 queue_work(priv->workqueue,
4365 &priv->system_config);
4367 #ifdef CONFIG_IPW2200_QOS
4368 #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4369 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4370 if ((priv->status & STATUS_AUTH) &&
4371 (IPW_GET_PACKET_STYPE(¬if->u.raw)
4372 == IEEE80211_STYPE_ASSOC_RESP)) {
4375 ieee80211_assoc_response)
4377 && (notif->size <= 2314)) {
4390 ieee80211_rx_mgt(priv->
4395 ¬if->u.raw, &stats);
4400 schedule_work(&priv->link_up);
4405 case CMAS_AUTHENTICATED:{
4407 status & (STATUS_ASSOCIATED |
4409 #ifdef CONFIG_IPW2200_DEBUG
4410 struct notif_authenticate *auth
4412 IPW_DEBUG(IPW_DL_NOTIF |
4415 "deauthenticated: '%s' "
4417 ": (0x%04X) - %s \n",
4422 MAC_ARG(priv->bssid),
4423 ntohs(auth->status),
4430 ~(STATUS_ASSOCIATING |
4434 schedule_work(&priv->link_down);
4438 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4440 "authenticated: '%s' " MAC_FMT
4442 escape_essid(priv->essid,
4444 MAC_ARG(priv->bssid));
4449 if (priv->status & STATUS_AUTH) {
4451 ieee80211_assoc_response
4455 ieee80211_assoc_response
4457 IPW_DEBUG(IPW_DL_NOTIF |
4460 "association failed (0x%04X): %s\n",
4461 ntohs(resp->status),
4467 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4469 "disassociated: '%s' " MAC_FMT
4471 escape_essid(priv->essid,
4473 MAC_ARG(priv->bssid));
4476 ~(STATUS_DISASSOCIATING |
4477 STATUS_ASSOCIATING |
4478 STATUS_ASSOCIATED | STATUS_AUTH);
4479 if (priv->assoc_network
4480 && (priv->assoc_network->
4482 WLAN_CAPABILITY_IBSS))
4483 ipw_remove_current_network
4486 schedule_work(&priv->link_down);
4491 case CMAS_RX_ASSOC_RESP:
4495 IPW_ERROR("assoc: unknown (%d)\n",
4503 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4504 struct notif_authenticate *auth = ¬if->u.auth;
4505 switch (auth->state) {
4506 case CMAS_AUTHENTICATED:
4507 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4508 "authenticated: '%s' " MAC_FMT " \n",
4509 escape_essid(priv->essid,
4511 MAC_ARG(priv->bssid));
4512 priv->status |= STATUS_AUTH;
4516 if (priv->status & STATUS_AUTH) {
4517 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4519 "authentication failed (0x%04X): %s\n",
4520 ntohs(auth->status),
4521 ipw_get_status_code(ntohs
4525 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4527 "deauthenticated: '%s' " MAC_FMT "\n",
4528 escape_essid(priv->essid,
4530 MAC_ARG(priv->bssid));
4532 priv->status &= ~(STATUS_ASSOCIATING |
4536 schedule_work(&priv->link_down);
4539 case CMAS_TX_AUTH_SEQ_1:
4540 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4541 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4543 case CMAS_RX_AUTH_SEQ_2:
4544 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4545 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4547 case CMAS_AUTH_SEQ_1_PASS:
4548 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4549 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4551 case CMAS_AUTH_SEQ_1_FAIL:
4552 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4553 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4555 case CMAS_TX_AUTH_SEQ_3:
4556 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4557 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4559 case CMAS_RX_AUTH_SEQ_4:
4560 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4561 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4563 case CMAS_AUTH_SEQ_2_PASS:
4564 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4565 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4567 case CMAS_AUTH_SEQ_2_FAIL:
4568 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4569 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4572 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4573 IPW_DL_ASSOC, "TX_ASSOC\n");
4575 case CMAS_RX_ASSOC_RESP:
4576 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4577 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
4580 case CMAS_ASSOCIATED:
4581 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4582 IPW_DL_ASSOC, "ASSOCIATED\n");
4585 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4592 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4593 struct notif_channel_result *x =
4594 ¬if->u.channel_result;
4596 if (notif->size == sizeof(*x)) {
4597 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4600 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4601 "(should be %zd)\n",
4602 notif->size, sizeof(*x));
4607 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4608 struct notif_scan_complete *x = ¬if->u.scan_complete;
4609 if (notif->size == sizeof(*x)) {
4611 ("Scan completed: type %d, %d channels, "
4612 "%d status\n", x->scan_type,
4613 x->num_channels, x->status);
4615 IPW_ERROR("Scan completed of wrong size %d "
4616 "(should be %zd)\n",
4617 notif->size, sizeof(*x));
4621 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4623 wake_up_interruptible(&priv->wait_state);
4624 cancel_delayed_work(&priv->scan_check);
4626 if (priv->status & STATUS_EXIT_PENDING)
4629 priv->ieee->scans++;
4631 #ifdef CONFIG_IPW2200_MONITOR
4632 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
4633 priv->status |= STATUS_SCAN_FORCED;
4634 queue_work(priv->workqueue,
4635 &priv->request_scan);
4638 priv->status &= ~STATUS_SCAN_FORCED;
4639 #endif /* CONFIG_IPW2200_MONITOR */
4641 if (!(priv->status & (STATUS_ASSOCIATED |
4642 STATUS_ASSOCIATING |
4644 STATUS_DISASSOCIATING)))
4645 queue_work(priv->workqueue, &priv->associate);
4646 else if (priv->status & STATUS_ROAMING) {
4647 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4648 /* If a scan completed and we are in roam mode, then
4649 * the scan that completed was the one requested as a
4650 * result of entering roam... so, schedule the
4652 queue_work(priv->workqueue,
4655 /* Don't schedule if we aborted the scan */
4656 priv->status &= ~STATUS_ROAMING;
4657 } else if (priv->status & STATUS_SCAN_PENDING)
4658 queue_work(priv->workqueue,
4659 &priv->request_scan);
4660 else if (priv->config & CFG_BACKGROUND_SCAN
4661 && priv->status & STATUS_ASSOCIATED)
4662 queue_delayed_work(priv->workqueue,
4663 &priv->request_scan, HZ);
4665 /* Send an empty event to user space.
4666 * We don't send the received data on the event because
4667 * it would require us to do complex transcoding, and
4668 * we want to minimise the work done in the irq handler
4669 * Use a request to extract the data.
4670 * Also, we generate this even for any scan, regardless
4671 * on how the scan was initiated. User space can just
4672 * sync on periodic scan to get fresh data...
4674 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) {
4675 union iwreq_data wrqu;
4677 wrqu.data.length = 0;
4678 wrqu.data.flags = 0;
4679 wireless_send_event(priv->net_dev, SIOCGIWSCAN,
4685 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4686 struct notif_frag_length *x = ¬if->u.frag_len;
4688 if (notif->size == sizeof(*x))
4689 IPW_ERROR("Frag length: %d\n",
4690 le16_to_cpu(x->frag_length));
4692 IPW_ERROR("Frag length of wrong size %d "
4693 "(should be %zd)\n",
4694 notif->size, sizeof(*x));
4698 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4699 struct notif_link_deterioration *x =
4700 ¬if->u.link_deterioration;
4702 if (notif->size == sizeof(*x)) {
4703 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4704 "link deterioration: type %d, cnt %d\n",
4705 x->silence_notification_type,
4707 memcpy(&priv->last_link_deterioration, x,
4710 IPW_ERROR("Link Deterioration of wrong size %d "
4711 "(should be %zd)\n",
4712 notif->size, sizeof(*x));
4717 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4718 IPW_ERROR("Dino config\n");
4720 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
4721 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
4726 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4727 struct notif_beacon_state *x = ¬if->u.beacon_state;
4728 if (notif->size != sizeof(*x)) {
4730 ("Beacon state of wrong size %d (should "
4731 "be %zd)\n", notif->size, sizeof(*x));
4735 if (le32_to_cpu(x->state) ==
4736 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4737 ipw_handle_missed_beacon(priv,
4744 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4745 struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key;
4746 if (notif->size == sizeof(*x)) {
4747 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4748 "0x%02x station %d\n",
4749 x->key_state, x->security_type,
4755 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4756 notif->size, sizeof(*x));
4760 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4761 struct notif_calibration *x = ¬if->u.calibration;
4763 if (notif->size == sizeof(*x)) {
4764 memcpy(&priv->calib, x, sizeof(*x));
4765 IPW_DEBUG_INFO("TODO: Calibration\n");
4770 ("Calibration of wrong size %d (should be %zd)\n",
4771 notif->size, sizeof(*x));
4775 case HOST_NOTIFICATION_NOISE_STATS:{
4776 if (notif->size == sizeof(u32)) {
4777 priv->exp_avg_noise =
4778 exponential_average(priv->exp_avg_noise,
4779 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4785 ("Noise stat is wrong size %d (should be %zd)\n",
4786 notif->size, sizeof(u32));
4791 IPW_DEBUG_NOTIF("Unknown notification: "
4792 "subtype=%d,flags=0x%2x,size=%d\n",
4793 notif->subtype, notif->flags, notif->size);
4798 * Destroys all DMA structures and initialise them again
4801 * @return error code
4803 static int ipw_queue_reset(struct ipw_priv *priv)
4806 /** @todo customize queue sizes */
4807 int nTx = 64, nTxCmd = 8;
4808 ipw_tx_queue_free(priv);
4810 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
4811 IPW_TX_CMD_QUEUE_READ_INDEX,
4812 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4813 IPW_TX_CMD_QUEUE_BD_BASE,
4814 IPW_TX_CMD_QUEUE_BD_SIZE);
4816 IPW_ERROR("Tx Cmd queue init failed\n");
4820 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
4821 IPW_TX_QUEUE_0_READ_INDEX,
4822 IPW_TX_QUEUE_0_WRITE_INDEX,
4823 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
4825 IPW_ERROR("Tx 0 queue init failed\n");
4828 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
4829 IPW_TX_QUEUE_1_READ_INDEX,
4830 IPW_TX_QUEUE_1_WRITE_INDEX,
4831 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
4833 IPW_ERROR("Tx 1 queue init failed\n");
4836 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
4837 IPW_TX_QUEUE_2_READ_INDEX,
4838 IPW_TX_QUEUE_2_WRITE_INDEX,
4839 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
4841 IPW_ERROR("Tx 2 queue init failed\n");
4844 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
4845 IPW_TX_QUEUE_3_READ_INDEX,
4846 IPW_TX_QUEUE_3_WRITE_INDEX,
4847 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
4849 IPW_ERROR("Tx 3 queue init failed\n");
4853 priv->rx_bufs_min = 0;
4854 priv->rx_pend_max = 0;
4858 ipw_tx_queue_free(priv);
4863 * Reclaim Tx queue entries no more used by NIC.
4865 * When FW adwances 'R' index, all entries between old and
4866 * new 'R' index need to be reclaimed. As result, some free space
4867 * forms. If there is enough free space (> low mark), wake Tx queue.
4869 * @note Need to protect against garbage in 'R' index
4873 * @return Number of used entries remains in the queue
4875 static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
4876 struct clx2_tx_queue *txq, int qindex)
4880 struct clx2_queue *q = &txq->q;
4882 hw_tail = ipw_read32(priv, q->reg_r);
4883 if (hw_tail >= q->n_bd) {
4885 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4889 for (; q->last_used != hw_tail;
4890 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4891 ipw_queue_tx_free_tfd(priv, txq);
4895 if ((ipw_queue_space(q) > q->low_mark) &&
4897 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4898 netif_wake_queue(priv->net_dev);
4899 used = q->first_empty - q->last_used;
4906 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4909 struct clx2_tx_queue *txq = &priv->txq_cmd;
4910 struct clx2_queue *q = &txq->q;
4911 struct tfd_frame *tfd;
4913 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4914 IPW_ERROR("No space for Tx\n");
4918 tfd = &txq->bd[q->first_empty];
4919 txq->txb[q->first_empty] = NULL;
4921 memset(tfd, 0, sizeof(*tfd));
4922 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4923 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4925 tfd->u.cmd.index = hcmd;
4926 tfd->u.cmd.length = len;
4927 memcpy(tfd->u.cmd.payload, buf, len);
4928 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4929 ipw_write32(priv, q->reg_w, q->first_empty);
4930 _ipw_read32(priv, 0x90);
4936 * Rx theory of operation
4938 * The host allocates 32 DMA target addresses and passes the host address
4939 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
4943 * The host/firmware share two index registers for managing the Rx buffers.
4945 * The READ index maps to the first position that the firmware may be writing
4946 * to -- the driver can read up to (but not including) this position and get
4948 * The READ index is managed by the firmware once the card is enabled.
4950 * The WRITE index maps to the last position the driver has read from -- the
4951 * position preceding WRITE is the last slot the firmware can place a packet.
4953 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
4956 * During initialization the host sets up the READ queue position to the first
4957 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4959 * When the firmware places a packet in a buffer it will advance the READ index
4960 * and fire the RX interrupt. The driver can then query the READ index and
4961 * process as many packets as possible, moving the WRITE index forward as it
4962 * resets the Rx queue buffers with new memory.
4964 * The management in the driver is as follows:
4965 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
4966 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
4967 * to replensish the ipw->rxq->rx_free.
4968 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4969 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4970 * 'processed' and 'read' driver indexes as well)
4971 * + A received packet is processed and handed to the kernel network stack,
4972 * detached from the ipw->rxq. The driver 'processed' index is updated.
4973 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
4974 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4975 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
4976 * were enough free buffers and RX_STALLED is set it is cleared.
4981 * ipw_rx_queue_alloc() Allocates rx_free
4982 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4983 * ipw_rx_queue_restock
4984 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4985 * queue, updates firmware pointers, and updates
4986 * the WRITE index. If insufficient rx_free buffers
4987 * are available, schedules ipw_rx_queue_replenish
4989 * -- enable interrupts --
4990 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
4991 * READ INDEX, detaching the SKB from the pool.
4992 * Moves the packet buffer from queue to rx_used.
4993 * Calls ipw_rx_queue_restock to refill any empty
5000 * If there are slots in the RX queue that need to be restocked,
5001 * and we have free pre-allocated buffers, fill the ranks as much
5002 * as we can pulling from rx_free.
5004 * This moves the 'write' index forward to catch up with 'processed', and
5005 * also updates the memory address in the firmware to reference the new
5008 static void ipw_rx_queue_restock(struct ipw_priv *priv)
5010 struct ipw_rx_queue *rxq = priv->rxq;
5011 struct list_head *element;
5012 struct ipw_rx_mem_buffer *rxb;
5013 unsigned long flags;
5016 spin_lock_irqsave(&rxq->lock, flags);
5018 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
5019 element = rxq->rx_free.next;
5020 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5023 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
5025 rxq->queue[rxq->write] = rxb;
5026 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5029 spin_unlock_irqrestore(&rxq->lock, flags);
5031 /* If the pre-allocated buffer pool is dropping low, schedule to
5033 if (rxq->free_count <= RX_LOW_WATERMARK)
5034 queue_work(priv->workqueue, &priv->rx_replenish);
5036 /* If we've added more space for the firmware to place data, tell it */
5037 if (write != rxq->write)
5038 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
5042 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
5043 * Also restock the Rx queue via ipw_rx_queue_restock.
5045 * This is called as a scheduled work item (except for during intialization)
5047 static void ipw_rx_queue_replenish(void *data)
5049 struct ipw_priv *priv = data;
5050 struct ipw_rx_queue *rxq = priv->rxq;
5051 struct list_head *element;
5052 struct ipw_rx_mem_buffer *rxb;
5053 unsigned long flags;
5055 spin_lock_irqsave(&rxq->lock, flags);
5056 while (!list_empty(&rxq->rx_used)) {
5057 element = rxq->rx_used.next;
5058 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5059 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
5061 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5062 priv->net_dev->name);
5063 /* We don't reschedule replenish work here -- we will
5064 * call the restock method and if it still needs
5065 * more buffers it will schedule replenish */
5070 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
5072 pci_map_single(priv->pci_dev, rxb->skb->data,
5073 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
5075 list_add_tail(&rxb->list, &rxq->rx_free);
5078 spin_unlock_irqrestore(&rxq->lock, flags);
5080 ipw_rx_queue_restock(priv);
5083 static void ipw_bg_rx_queue_replenish(void *data)
5085 struct ipw_priv *priv = data;
5086 mutex_lock(&priv->mutex);
5087 ipw_rx_queue_replenish(data);
5088 mutex_unlock(&priv->mutex);
5091 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
5092 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
5093 * This free routine walks the list of POOL entries and if SKB is set to
5094 * non NULL it is unmapped and freed
5096 static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
5103 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5104 if (rxq->pool[i].skb != NULL) {
5105 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
5106 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
5107 dev_kfree_skb(rxq->pool[i].skb);
5114 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5116 struct ipw_rx_queue *rxq;
5119 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
5120 if (unlikely(!rxq)) {
5121 IPW_ERROR("memory allocation failed\n");
5124 spin_lock_init(&rxq->lock);
5125 INIT_LIST_HEAD(&rxq->rx_free);
5126 INIT_LIST_HEAD(&rxq->rx_used);
5128 /* Fill the rx_used queue with _all_ of the Rx buffers */
5129 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
5130 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5132 /* Set us so that we have processed and used all buffers, but have
5133 * not restocked the Rx queue with fresh buffers */
5134 rxq->read = rxq->write = 0;
5135 rxq->processed = RX_QUEUE_SIZE - 1;
5136 rxq->free_count = 0;
5141 static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5143 rate &= ~IEEE80211_BASIC_RATE_MASK;
5144 if (ieee_mode == IEEE_A) {
5146 case IEEE80211_OFDM_RATE_6MB:
5147 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
5149 case IEEE80211_OFDM_RATE_9MB:
5150 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
5152 case IEEE80211_OFDM_RATE_12MB:
5154 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
5155 case IEEE80211_OFDM_RATE_18MB:
5157 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
5158 case IEEE80211_OFDM_RATE_24MB:
5160 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
5161 case IEEE80211_OFDM_RATE_36MB:
5163 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
5164 case IEEE80211_OFDM_RATE_48MB:
5166 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
5167 case IEEE80211_OFDM_RATE_54MB:
5169 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5177 case IEEE80211_CCK_RATE_1MB:
5178 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
5179 case IEEE80211_CCK_RATE_2MB:
5180 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
5181 case IEEE80211_CCK_RATE_5MB:
5182 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
5183 case IEEE80211_CCK_RATE_11MB:
5184 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
5187 /* If we are limited to B modulations, bail at this point */
5188 if (ieee_mode == IEEE_B)
5193 case IEEE80211_OFDM_RATE_6MB:
5194 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
5195 case IEEE80211_OFDM_RATE_9MB:
5196 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
5197 case IEEE80211_OFDM_RATE_12MB:
5198 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
5199 case IEEE80211_OFDM_RATE_18MB:
5200 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
5201 case IEEE80211_OFDM_RATE_24MB:
5202 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
5203 case IEEE80211_OFDM_RATE_36MB:
5204 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
5205 case IEEE80211_OFDM_RATE_48MB:
5206 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
5207 case IEEE80211_OFDM_RATE_54MB:
5208 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5214 static int ipw_compatible_rates(struct ipw_priv *priv,
5215 const struct ieee80211_network *network,
5216 struct ipw_supported_rates *rates)
5220 memset(rates, 0, sizeof(*rates));
5221 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
5222 rates->num_rates = 0;
5223 for (i = 0; i < num_rates; i++) {
5224 if (!ipw_is_rate_in_mask(priv, network->mode,
5225 network->rates[i])) {
5227 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
5228 IPW_DEBUG_SCAN("Adding masked mandatory "
5231 rates->supported_rates[rates->num_rates++] =
5236 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5237 network->rates[i], priv->rates_mask);
5241 rates->supported_rates[rates->num_rates++] = network->rates[i];
5244 num_rates = min(network->rates_ex_len,
5245 (u8) (IPW_MAX_RATES - num_rates));
5246 for (i = 0; i < num_rates; i++) {
5247 if (!ipw_is_rate_in_mask(priv, network->mode,
5248 network->rates_ex[i])) {
5249 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
5250 IPW_DEBUG_SCAN("Adding masked mandatory "
5252 network->rates_ex[i]);
5253 rates->supported_rates[rates->num_rates++] =
5258 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5259 network->rates_ex[i], priv->rates_mask);
5263 rates->supported_rates[rates->num_rates++] =
5264 network->rates_ex[i];
5270 static void ipw_copy_rates(struct ipw_supported_rates *dest,
5271 const struct ipw_supported_rates *src)
5274 for (i = 0; i < src->num_rates; i++)
5275 dest->supported_rates[i] = src->supported_rates[i];
5276 dest->num_rates = src->num_rates;
5279 /* TODO: Look at sniffed packets in the air to determine if the basic rate
5280 * mask should ever be used -- right now all callers to add the scan rates are
5281 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5282 static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
5283 u8 modulation, u32 rate_mask)
5285 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
5286 IEEE80211_BASIC_RATE_MASK : 0;
5288 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
5289 rates->supported_rates[rates->num_rates++] =
5290 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
5292 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
5293 rates->supported_rates[rates->num_rates++] =
5294 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
5296 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
5297 rates->supported_rates[rates->num_rates++] = basic_mask |
5298 IEEE80211_CCK_RATE_5MB;
5300 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
5301 rates->supported_rates[rates->num_rates++] = basic_mask |
5302 IEEE80211_CCK_RATE_11MB;
5305 static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
5306 u8 modulation, u32 rate_mask)
5308 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
5309 IEEE80211_BASIC_RATE_MASK : 0;
5311 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
5312 rates->supported_rates[rates->num_rates++] = basic_mask |
5313 IEEE80211_OFDM_RATE_6MB;
5315 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
5316 rates->supported_rates[rates->num_rates++] =
5317 IEEE80211_OFDM_RATE_9MB;
5319 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
5320 rates->supported_rates[rates->num_rates++] = basic_mask |
5321 IEEE80211_OFDM_RATE_12MB;
5323 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
5324 rates->supported_rates[rates->num_rates++] =
5325 IEEE80211_OFDM_RATE_18MB;
5327 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
5328 rates->supported_rates[rates->num_rates++] = basic_mask |
5329 IEEE80211_OFDM_RATE_24MB;
5331 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
5332 rates->supported_rates[rates->num_rates++] =
5333 IEEE80211_OFDM_RATE_36MB;
5335 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
5336 rates->supported_rates[rates->num_rates++] =
5337 IEEE80211_OFDM_RATE_48MB;
5339 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
5340 rates->supported_rates[rates->num_rates++] =
5341 IEEE80211_OFDM_RATE_54MB;
5344 struct ipw_network_match {
5345 struct ieee80211_network *network;
5346 struct ipw_supported_rates rates;
5349 static int ipw_find_adhoc_network(struct ipw_priv *priv,
5350 struct ipw_network_match *match,
5351 struct ieee80211_network *network,
5354 struct ipw_supported_rates rates;
5356 /* Verify that this network's capability is compatible with the
5357 * current mode (AdHoc or Infrastructure) */
5358 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5359 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5360 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5361 "capability mismatch.\n",
5362 escape_essid(network->ssid, network->ssid_len),
5363 MAC_ARG(network->bssid));
5367 /* If we do not have an ESSID for this AP, we can not associate with
5369 if (network->flags & NETWORK_EMPTY_ESSID) {
5370 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5371 "because of hidden ESSID.\n",
5372 escape_essid(network->ssid, network->ssid_len),
5373 MAC_ARG(network->bssid));
5377 if (unlikely(roaming)) {
5378 /* If we are roaming, then ensure check if this is a valid
5379 * network to try and roam to */
5380 if ((network->ssid_len != match->network->ssid_len) ||
5381 memcmp(network->ssid, match->network->ssid,
5382 network->ssid_len)) {
5383 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5384 "because of non-network ESSID.\n",
5385 escape_essid(network->ssid,
5387 MAC_ARG(network->bssid));
5391 /* If an ESSID has been configured then compare the broadcast
5393 if ((priv->config & CFG_STATIC_ESSID) &&
5394 ((network->ssid_len != priv->essid_len) ||
5395 memcmp(network->ssid, priv->essid,
5396 min(network->ssid_len, priv->essid_len)))) {
5397 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5400 escape_essid(network->ssid, network->ssid_len),
5402 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5403 "because of ESSID mismatch: '%s'.\n",
5404 escaped, MAC_ARG(network->bssid),
5405 escape_essid(priv->essid,
5411 /* If the old network rate is better than this one, don't bother
5412 * testing everything else. */
5414 if (network->time_stamp[0] < match->network->time_stamp[0]) {
5415 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5416 "current network.\n",
5417 escape_essid(match->network->ssid,
5418 match->network->ssid_len));
5420 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
5421 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5422 "current network.\n",
5423 escape_essid(match->network->ssid,
5424 match->network->ssid_len));
5428 /* Now go through and see if the requested network is valid... */
5429 if (priv->ieee->scan_age != 0 &&
5430 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5431 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5432 "because of age: %ums.\n",
5433 escape_essid(network->ssid, network->ssid_len),
5434 MAC_ARG(network->bssid),
5435 jiffies_to_msecs(jiffies -
5436 network->last_scanned));
5440 if ((priv->config & CFG_STATIC_CHANNEL) &&
5441 (network->channel != priv->channel)) {
5442 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5443 "because of channel mismatch: %d != %d.\n",
5444 escape_essid(network->ssid, network->ssid_len),
5445 MAC_ARG(network->bssid),
5446 network->channel, priv->channel);
5450 /* Verify privacy compatability */
5451 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5452 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5453 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5454 "because of privacy mismatch: %s != %s.\n",
5455 escape_essid(network->ssid, network->ssid_len),
5456 MAC_ARG(network->bssid),
5458 capability & CAP_PRIVACY_ON ? "on" : "off",
5460 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5465 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5466 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5467 "because of the same BSSID match: " MAC_FMT
5468 ".\n", escape_essid(network->ssid,
5470 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5474 /* Filter out any incompatible freq / mode combinations */
5475 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5476 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5477 "because of invalid frequency/mode "
5479 escape_essid(network->ssid, network->ssid_len),
5480 MAC_ARG(network->bssid));
5484 /* Ensure that the rates supported by the driver are compatible with
5485 * this AP, including verification of basic rates (mandatory) */
5486 if (!ipw_compatible_rates(priv, network, &rates)) {
5487 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5488 "because configured rate mask excludes "
5489 "AP mandatory rate.\n",
5490 escape_essid(network->ssid, network->ssid_len),
5491 MAC_ARG(network->bssid));
5495 if (rates.num_rates == 0) {
5496 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5497 "because of no compatible rates.\n",
5498 escape_essid(network->ssid, network->ssid_len),
5499 MAC_ARG(network->bssid));
5503 /* TODO: Perform any further minimal comparititive tests. We do not
5504 * want to put too much policy logic here; intelligent scan selection
5505 * should occur within a generic IEEE 802.11 user space tool. */
5507 /* Set up 'new' AP to this network */
5508 ipw_copy_rates(&match->rates, &rates);
5509 match->network = network;
5510 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5511 escape_essid(network->ssid, network->ssid_len),
5512 MAC_ARG(network->bssid));
5517 static void ipw_merge_adhoc_network(void *data)
5519 struct ipw_priv *priv = data;
5520 struct ieee80211_network *network = NULL;
5521 struct ipw_network_match match = {
5522 .network = priv->assoc_network
5525 if ((priv->status & STATUS_ASSOCIATED) &&
5526 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5527 /* First pass through ROAM process -- look for a better
5529 unsigned long flags;
5531 spin_lock_irqsave(&priv->ieee->lock, flags);
5532 list_for_each_entry(network, &priv->ieee->network_list, list) {
5533 if (network != priv->assoc_network)
5534 ipw_find_adhoc_network(priv, &match, network,
5537 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5539 if (match.network == priv->assoc_network) {
5540 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5545 mutex_lock(&priv->mutex);
5546 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5547 IPW_DEBUG_MERGE("remove network %s\n",
5548 escape_essid(priv->essid,
5550 ipw_remove_current_network(priv);
5553 ipw_disassociate(priv);
5554 priv->assoc_network = match.network;
5555 mutex_unlock(&priv->mutex);
5560 static int ipw_best_network(struct ipw_priv *priv,
5561 struct ipw_network_match *match,
5562 struct ieee80211_network *network, int roaming)
5564 struct ipw_supported_rates rates;
5566 /* Verify that this network's capability is compatible with the
5567 * current mode (AdHoc or Infrastructure) */
5568 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
5569 !(network->capability & WLAN_CAPABILITY_ESS)) ||
5570 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5571 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5572 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
5573 "capability mismatch.\n",
5574 escape_essid(network->ssid, network->ssid_len),
5575 MAC_ARG(network->bssid));
5579 /* If we do not have an ESSID for this AP, we can not associate with
5581 if (network->flags & NETWORK_EMPTY_ESSID) {
5582 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5583 "because of hidden ESSID.\n",
5584 escape_essid(network->ssid, network->ssid_len),
5585 MAC_ARG(network->bssid));
5589 if (unlikely(roaming)) {
5590 /* If we are roaming, then ensure check if this is a valid
5591 * network to try and roam to */
5592 if ((network->ssid_len != match->network->ssid_len) ||
5593 memcmp(network->ssid, match->network->ssid,
5594 network->ssid_len)) {
5595 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5596 "because of non-network ESSID.\n",
5597 escape_essid(network->ssid,
5599 MAC_ARG(network->bssid));
5603 /* If an ESSID has been configured then compare the broadcast
5605 if ((priv->config & CFG_STATIC_ESSID) &&
5606 ((network->ssid_len != priv->essid_len) ||
5607 memcmp(network->ssid, priv->essid,
5608 min(network->ssid_len, priv->essid_len)))) {
5609 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5611 escape_essid(network->ssid, network->ssid_len),
5613 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5614 "because of ESSID mismatch: '%s'.\n",
5615 escaped, MAC_ARG(network->bssid),
5616 escape_essid(priv->essid,
5622 /* If the old network rate is better than this one, don't bother
5623 * testing everything else. */
5624 if (match->network && match->network->stats.rssi > network->stats.rssi) {
5625 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5627 escape_essid(network->ssid, network->ssid_len),
5629 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5630 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5631 escaped, MAC_ARG(network->bssid),
5632 escape_essid(match->network->ssid,
5633 match->network->ssid_len),
5634 MAC_ARG(match->network->bssid));
5638 /* If this network has already had an association attempt within the
5639 * last 3 seconds, do not try and associate again... */
5640 if (network->last_associate &&
5641 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
5642 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5643 "because of storming (%ums since last "
5644 "assoc attempt).\n",
5645 escape_essid(network->ssid, network->ssid_len),
5646 MAC_ARG(network->bssid),
5647 jiffies_to_msecs(jiffies -
5648 network->last_associate));
5652 /* Now go through and see if the requested network is valid... */
5653 if (priv->ieee->scan_age != 0 &&
5654 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5655 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5656 "because of age: %ums.\n",
5657 escape_essid(network->ssid, network->ssid_len),
5658 MAC_ARG(network->bssid),
5659 jiffies_to_msecs(jiffies -
5660 network->last_scanned));
5664 if ((priv->config & CFG_STATIC_CHANNEL) &&
5665 (network->channel != priv->channel)) {
5666 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5667 "because of channel mismatch: %d != %d.\n",
5668 escape_essid(network->ssid, network->ssid_len),
5669 MAC_ARG(network->bssid),
5670 network->channel, priv->channel);
5674 /* Verify privacy compatability */
5675 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5676 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5677 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5678 "because of privacy mismatch: %s != %s.\n",
5679 escape_essid(network->ssid, network->ssid_len),
5680 MAC_ARG(network->bssid),
5681 priv->capability & CAP_PRIVACY_ON ? "on" :
5683 network->capability &
5684 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
5688 if ((priv->config & CFG_STATIC_BSSID) &&
5689 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5690 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5691 "because of BSSID mismatch: " MAC_FMT ".\n",
5692 escape_essid(network->ssid, network->ssid_len),
5693 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5697 /* Filter out any incompatible freq / mode combinations */
5698 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5699 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5700 "because of invalid frequency/mode "
5702 escape_essid(network->ssid, network->ssid_len),
5703 MAC_ARG(network->bssid));
5707 /* Filter out invalid channel in current GEO */
5708 if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) {
5709 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5710 "because of invalid channel in current GEO\n",
5711 escape_essid(network->ssid, network->ssid_len),
5712 MAC_ARG(network->bssid));
5716 /* Ensure that the rates supported by the driver are compatible with
5717 * this AP, including verification of basic rates (mandatory) */
5718 if (!ipw_compatible_rates(priv, network, &rates)) {
5719 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5720 "because configured rate mask excludes "
5721 "AP mandatory rate.\n",
5722 escape_essid(network->ssid, network->ssid_len),
5723 MAC_ARG(network->bssid));
5727 if (rates.num_rates == 0) {
5728 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5729 "because of no compatible rates.\n",
5730 escape_essid(network->ssid, network->ssid_len),
5731 MAC_ARG(network->bssid));
5735 /* TODO: Perform any further minimal comparititive tests. We do not
5736 * want to put too much policy logic here; intelligent scan selection
5737 * should occur within a generic IEEE 802.11 user space tool. */
5739 /* Set up 'new' AP to this network */
5740 ipw_copy_rates(&match->rates, &rates);
5741 match->network = network;
5743 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5744 escape_essid(network->ssid, network->ssid_len),
5745 MAC_ARG(network->bssid));
5750 static void ipw_adhoc_create(struct ipw_priv *priv,
5751 struct ieee80211_network *network)
5753 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
5757 * For the purposes of scanning, we can set our wireless mode
5758 * to trigger scans across combinations of bands, but when it
5759 * comes to creating a new ad-hoc network, we have tell the FW
5760 * exactly which band to use.
5762 * We also have the possibility of an invalid channel for the
5763 * chossen band. Attempting to create a new ad-hoc network
5764 * with an invalid channel for wireless mode will trigger a
5768 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
5769 case IEEE80211_52GHZ_BAND:
5770 network->mode = IEEE_A;
5771 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
5773 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5774 IPW_WARNING("Overriding invalid channel\n");
5775 priv->channel = geo->a[0].channel;
5779 case IEEE80211_24GHZ_BAND:
5780 if (priv->ieee->mode & IEEE_G)
5781 network->mode = IEEE_G;
5783 network->mode = IEEE_B;
5784 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
5786 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5787 IPW_WARNING("Overriding invalid channel\n");
5788 priv->channel = geo->bg[0].channel;
5793 IPW_WARNING("Overriding invalid channel\n");
5794 if (priv->ieee->mode & IEEE_A) {
5795 network->mode = IEEE_A;
5796 priv->channel = geo->a[0].channel;
5797 } else if (priv->ieee->mode & IEEE_G) {
5798 network->mode = IEEE_G;
5799 priv->channel = geo->bg[0].channel;
5801 network->mode = IEEE_B;
5802 priv->channel = geo->bg[0].channel;
5807 network->channel = priv->channel;
5808 priv->config |= CFG_ADHOC_PERSIST;
5809 ipw_create_bssid(priv, network->bssid);
5810 network->ssid_len = priv->essid_len;
5811 memcpy(network->ssid, priv->essid, priv->essid_len);
5812 memset(&network->stats, 0, sizeof(network->stats));
5813 network->capability = WLAN_CAPABILITY_IBSS;
5814 if (!(priv->config & CFG_PREAMBLE_LONG))
5815 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
5816 if (priv->capability & CAP_PRIVACY_ON)
5817 network->capability |= WLAN_CAPABILITY_PRIVACY;
5818 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
5819 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
5820 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
5821 memcpy(network->rates_ex,
5822 &priv->rates.supported_rates[network->rates_len],
5823 network->rates_ex_len);
5824 network->last_scanned = 0;
5826 network->last_associate = 0;
5827 network->time_stamp[0] = 0;
5828 network->time_stamp[1] = 0;
5829 network->beacon_interval = 100; /* Default */
5830 network->listen_interval = 10; /* Default */
5831 network->atim_window = 0; /* Default */
5832 network->wpa_ie_len = 0;
5833 network->rsn_ie_len = 0;
5836 static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5838 struct ipw_tgi_tx_key key;
5840 if (!(priv->ieee->sec.flags & (1 << index)))
5844 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5845 key.security_type = type;
5846 key.station_index = 0; /* always 0 for BSS */
5848 /* 0 for new key; previous value of counter (after fatal error) */
5849 key.tx_counter[0] = 0;
5850 key.tx_counter[1] = 0;
5852 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
5855 static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
5857 struct ipw_wep_key key;
5860 key.cmd_id = DINO_CMD_WEP_KEY;
5863 /* Note: AES keys cannot be set for multiple times.
5864 * Only set it at the first time. */
5865 for (i = 0; i < 4; i++) {
5866 key.key_index = i | type;
5867 if (!(priv->ieee->sec.flags & (1 << i))) {
5872 key.key_size = priv->ieee->sec.key_sizes[i];
5873 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
5875 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
5879 static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5881 if (priv->ieee->host_encrypt)
5886 priv->sys_config.disable_unicast_decryption = 0;
5887 priv->ieee->host_decrypt = 0;
5890 priv->sys_config.disable_unicast_decryption = 1;
5891 priv->ieee->host_decrypt = 1;
5894 priv->sys_config.disable_unicast_decryption = 0;
5895 priv->ieee->host_decrypt = 0;
5898 priv->sys_config.disable_unicast_decryption = 1;
5905 static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5907 if (priv->ieee->host_encrypt)
5912 priv->sys_config.disable_multicast_decryption = 0;
5915 priv->sys_config.disable_multicast_decryption = 1;
5918 priv->sys_config.disable_multicast_decryption = 0;
5921 priv->sys_config.disable_multicast_decryption = 1;
5928 static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5930 switch (priv->ieee->sec.level) {
5932 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5933 ipw_send_tgi_tx_key(priv,
5934 DCT_FLAG_EXT_SECURITY_CCM,
5935 priv->ieee->sec.active_key);
5937 if (!priv->ieee->host_mc_decrypt)
5938 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
5941 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5942 ipw_send_tgi_tx_key(priv,
5943 DCT_FLAG_EXT_SECURITY_TKIP,
5944 priv->ieee->sec.active_key);
5947 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
5948 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5949 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
5957 static void ipw_adhoc_check(void *data)
5959 struct ipw_priv *priv = data;
5961 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
5962 !(priv->config & CFG_ADHOC_PERSIST)) {
5963 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5964 IPW_DL_STATE | IPW_DL_ASSOC,
5965 "Missed beacon: %d - disassociate\n",
5966 priv->missed_adhoc_beacons);
5967 ipw_remove_current_network(priv);
5968 ipw_disassociate(priv);
5972 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
5973 priv->assoc_request.beacon_interval);
5976 static void ipw_bg_adhoc_check(void *data)
5978 struct ipw_priv *priv = data;
5979 mutex_lock(&priv->mutex);
5980 ipw_adhoc_check(data);
5981 mutex_unlock(&priv->mutex);
5984 #ifdef CONFIG_IPW2200_DEBUG
5985 static void ipw_debug_config(struct ipw_priv *priv)
5987 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5988 "[CFG 0x%08X]\n", priv->config);
5989 if (priv->config & CFG_STATIC_CHANNEL)
5990 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
5992 IPW_DEBUG_INFO("Channel unlocked.\n");
5993 if (priv->config & CFG_STATIC_ESSID)
5994 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
5995 escape_essid(priv->essid, priv->essid_len));
5997 IPW_DEBUG_INFO("ESSID unlocked.\n");
5998 if (priv->config & CFG_STATIC_BSSID)
5999 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
6000 MAC_ARG(priv->bssid));
6002 IPW_DEBUG_INFO("BSSID unlocked.\n");
6003 if (priv->capability & CAP_PRIVACY_ON)
6004 IPW_DEBUG_INFO("PRIVACY on\n");
6006 IPW_DEBUG_INFO("PRIVACY off\n");
6007 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
6010 #define ipw_debug_config(x) do {} while (0)
6013 static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
6015 /* TODO: Verify that this works... */
6016 struct ipw_fixed_rate fr = {
6017 .tx_rates = priv->rates_mask
6022 /* Identify 'current FW band' and match it with the fixed
6025 switch (priv->ieee->freq_band) {
6026 case IEEE80211_52GHZ_BAND: /* A only */
6028 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
6029 /* Invalid fixed rate mask */
6031 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
6036 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
6039 default: /* 2.4Ghz or Mixed */
6041 if (mode == IEEE_B) {
6042 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
6043 /* Invalid fixed rate mask */
6045 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
6052 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
6053 IEEE80211_OFDM_RATES_MASK)) {
6054 /* Invalid fixed rate mask */
6056 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
6061 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
6062 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
6063 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
6066 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
6067 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
6068 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
6071 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
6072 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
6073 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
6076 fr.tx_rates |= mask;
6080 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
6081 ipw_write_reg32(priv, reg, *(u32 *) & fr);
6084 static void ipw_abort_scan(struct ipw_priv *priv)
6088 if (priv->status & STATUS_SCAN_ABORTING) {
6089 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6092 priv->status |= STATUS_SCAN_ABORTING;
6094 err = ipw_send_scan_abort(priv);
6096 IPW_DEBUG_HC("Request to abort scan failed.\n");
6099 static void ipw_add_scan_channels(struct ipw_priv *priv,
6100 struct ipw_scan_request_ext *scan,
6103 int channel_index = 0;
6104 const struct ieee80211_geo *geo;
6107 geo = ieee80211_get_geo(priv->ieee);
6109 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
6110 int start = channel_index;
6111 for (i = 0; i < geo->a_channels; i++) {
6112 if ((priv->status & STATUS_ASSOCIATED) &&
6113 geo->a[i].channel == priv->channel)
6116 scan->channels_list[channel_index] = geo->a[i].channel;
6117 ipw_set_scan_type(scan, channel_index,
6119 flags & IEEE80211_CH_PASSIVE_ONLY ?
6120 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6124 if (start != channel_index) {
6125 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6126 (channel_index - start);
6131 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
6132 int start = channel_index;
6133 if (priv->config & CFG_SPEED_SCAN) {
6135 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
6136 /* nop out the list */
6141 while (channel_index < IPW_SCAN_CHANNELS) {
6143 priv->speed_scan[priv->speed_scan_pos];
6145 priv->speed_scan_pos = 0;
6146 channel = priv->speed_scan[0];
6148 if ((priv->status & STATUS_ASSOCIATED) &&
6149 channel == priv->channel) {
6150 priv->speed_scan_pos++;
6154 /* If this channel has already been
6155 * added in scan, break from loop
6156 * and this will be the first channel
6159 if (channels[channel - 1] != 0)
6162 channels[channel - 1] = 1;
6163 priv->speed_scan_pos++;
6165 scan->channels_list[channel_index] = channel;
6167 ieee80211_channel_to_index(priv->ieee, channel);
6168 ipw_set_scan_type(scan, channel_index,
6171 IEEE80211_CH_PASSIVE_ONLY ?
6172 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6176 for (i = 0; i < geo->bg_channels; i++) {
6177 if ((priv->status & STATUS_ASSOCIATED) &&
6178 geo->bg[i].channel == priv->channel)
6181 scan->channels_list[channel_index] =
6183 ipw_set_scan_type(scan, channel_index,
6186 IEEE80211_CH_PASSIVE_ONLY ?
6187 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6192 if (start != channel_index) {
6193 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6194 (channel_index - start);
6199 static int ipw_request_scan(struct ipw_priv *priv)
6201 struct ipw_scan_request_ext scan;
6202 int err = 0, scan_type;
6204 if (!(priv->status & STATUS_INIT) ||
6205 (priv->status & STATUS_EXIT_PENDING))
6208 mutex_lock(&priv->mutex);
6210 if (priv->status & STATUS_SCANNING) {
6211 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
6212 priv->status |= STATUS_SCAN_PENDING;
6216 if (!(priv->status & STATUS_SCAN_FORCED) &&
6217 priv->status & STATUS_SCAN_ABORTING) {
6218 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6219 priv->status |= STATUS_SCAN_PENDING;
6223 if (priv->status & STATUS_RF_KILL_MASK) {
6224 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6225 priv->status |= STATUS_SCAN_PENDING;
6229 memset(&scan, 0, sizeof(scan));
6231 if (priv->config & CFG_SPEED_SCAN)
6232 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6235 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6238 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6240 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
6242 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
6244 #ifdef CONFIG_IPW2200_MONITOR
6245 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
6249 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
6250 case IEEE80211_52GHZ_BAND:
6251 band = (u8) (IPW_A_MODE << 6) | 1;
6252 channel = priv->channel;
6255 case IEEE80211_24GHZ_BAND:
6256 band = (u8) (IPW_B_MODE << 6) | 1;
6257 channel = priv->channel;
6261 band = (u8) (IPW_B_MODE << 6) | 1;
6266 scan.channels_list[0] = band;
6267 scan.channels_list[1] = channel;
6268 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
6270 /* NOTE: The card will sit on this channel for this time
6271 * period. Scan aborts are timing sensitive and frequently
6272 * result in firmware restarts. As such, it is best to
6273 * set a small dwell_time here and just keep re-issuing
6274 * scans. Otherwise fast channel hopping will not actually
6277 * TODO: Move SPEED SCAN support to all modes and bands */
6278 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6281 #endif /* CONFIG_IPW2200_MONITOR */
6282 /* If we are roaming, then make this a directed scan for the
6283 * current network. Otherwise, ensure that every other scan
6284 * is a fast channel hop scan */
6285 if ((priv->status & STATUS_ROAMING)
6286 || (!(priv->status & STATUS_ASSOCIATED)
6287 && (priv->config & CFG_STATIC_ESSID)
6288 && (le32_to_cpu(scan.full_scan_index) % 2))) {
6289 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6291 IPW_DEBUG_HC("Attempt to send SSID command "
6296 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6298 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
6300 ipw_add_scan_channels(priv, &scan, scan_type);
6301 #ifdef CONFIG_IPW2200_MONITOR
6305 err = ipw_send_scan_request_ext(priv, &scan);
6307 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
6311 priv->status |= STATUS_SCANNING;
6312 priv->status &= ~STATUS_SCAN_PENDING;
6313 queue_delayed_work(priv->workqueue, &priv->scan_check,
6314 IPW_SCAN_CHECK_WATCHDOG);
6316 mutex_unlock(&priv->mutex);
6320 static void ipw_bg_abort_scan(void *data)
6322 struct ipw_priv *priv = data;
6323 mutex_lock(&priv->mutex);
6324 ipw_abort_scan(data);
6325 mutex_unlock(&priv->mutex);
6328 static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6330 /* This is called when wpa_supplicant loads and closes the driver
6332 priv->ieee->wpa_enabled = value;
6336 static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6338 struct ieee80211_device *ieee = priv->ieee;
6339 struct ieee80211_security sec = {
6340 .flags = SEC_AUTH_MODE,
6344 if (value & IW_AUTH_ALG_SHARED_KEY) {
6345 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6347 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
6348 sec.auth_mode = WLAN_AUTH_OPEN;
6350 } else if (value & IW_AUTH_ALG_LEAP) {
6351 sec.auth_mode = WLAN_AUTH_LEAP;
6356 if (ieee->set_security)
6357 ieee->set_security(ieee->dev, &sec);
6364 static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6367 /* make sure WPA is enabled */
6368 ipw_wpa_enable(priv, 1);
6371 static int ipw_set_rsn_capa(struct ipw_priv *priv,
6372 char *capabilities, int length)
6374 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6376 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
6385 static int ipw_wx_set_genie(struct net_device *dev,
6386 struct iw_request_info *info,
6387 union iwreq_data *wrqu, char *extra)
6389 struct ipw_priv *priv = ieee80211_priv(dev);
6390 struct ieee80211_device *ieee = priv->ieee;
6394 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6395 (wrqu->data.length && extra == NULL))
6398 //mutex_lock(&priv->mutex);
6400 //if (!ieee->wpa_enabled) {
6401 // err = -EOPNOTSUPP;
6405 if (wrqu->data.length) {
6406 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6412 memcpy(buf, extra, wrqu->data.length);
6413 kfree(ieee->wpa_ie);
6415 ieee->wpa_ie_len = wrqu->data.length;
6417 kfree(ieee->wpa_ie);
6418 ieee->wpa_ie = NULL;
6419 ieee->wpa_ie_len = 0;
6422 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6424 //mutex_unlock(&priv->mutex);
6429 static int ipw_wx_get_genie(struct net_device *dev,
6430 struct iw_request_info *info,
6431 union iwreq_data *wrqu, char *extra)
6433 struct ipw_priv *priv = ieee80211_priv(dev);
6434 struct ieee80211_device *ieee = priv->ieee;
6437 //mutex_lock(&priv->mutex);
6439 //if (!ieee->wpa_enabled) {
6440 // err = -EOPNOTSUPP;
6444 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6445 wrqu->data.length = 0;
6449 if (wrqu->data.length < ieee->wpa_ie_len) {
6454 wrqu->data.length = ieee->wpa_ie_len;
6455 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6458 //mutex_unlock(&priv->mutex);
6462 static int wext_cipher2level(int cipher)
6465 case IW_AUTH_CIPHER_NONE:
6467 case IW_AUTH_CIPHER_WEP40:
6468 case IW_AUTH_CIPHER_WEP104:
6470 case IW_AUTH_CIPHER_TKIP:
6472 case IW_AUTH_CIPHER_CCMP:
6480 static int ipw_wx_set_auth(struct net_device *dev,
6481 struct iw_request_info *info,
6482 union iwreq_data *wrqu, char *extra)
6484 struct ipw_priv *priv = ieee80211_priv(dev);
6485 struct ieee80211_device *ieee = priv->ieee;
6486 struct iw_param *param = &wrqu->param;
6487 struct ieee80211_crypt_data *crypt;
6488 unsigned long flags;
6491 switch (param->flags & IW_AUTH_INDEX) {
6492 case IW_AUTH_WPA_VERSION:
6494 case IW_AUTH_CIPHER_PAIRWISE:
6495 ipw_set_hw_decrypt_unicast(priv,
6496 wext_cipher2level(param->value));
6498 case IW_AUTH_CIPHER_GROUP:
6499 ipw_set_hw_decrypt_multicast(priv,
6500 wext_cipher2level(param->value));
6502 case IW_AUTH_KEY_MGMT:
6504 * ipw2200 does not use these parameters
6508 case IW_AUTH_TKIP_COUNTERMEASURES:
6509 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6510 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
6513 flags = crypt->ops->get_flags(crypt->priv);
6516 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6518 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6520 crypt->ops->set_flags(flags, crypt->priv);
6524 case IW_AUTH_DROP_UNENCRYPTED:{
6527 * wpa_supplicant calls set_wpa_enabled when the driver
6528 * is loaded and unloaded, regardless of if WPA is being
6529 * used. No other calls are made which can be used to
6530 * determine if encryption will be used or not prior to
6531 * association being expected. If encryption is not being
6532 * used, drop_unencrypted is set to false, else true -- we
6533 * can use this to determine if the CAP_PRIVACY_ON bit should
6536 struct ieee80211_security sec = {
6537 .flags = SEC_ENABLED,
6538 .enabled = param->value,
6540 priv->ieee->drop_unencrypted = param->value;
6541 /* We only change SEC_LEVEL for open mode. Others
6542 * are set by ipw_wpa_set_encryption.
6544 if (!param->value) {
6545 sec.flags |= SEC_LEVEL;
6546 sec.level = SEC_LEVEL_0;
6548 sec.flags |= SEC_LEVEL;
6549 sec.level = SEC_LEVEL_1;
6551 if (priv->ieee->set_security)
6552 priv->ieee->set_security(priv->ieee->dev, &sec);
6556 case IW_AUTH_80211_AUTH_ALG:
6557 ret = ipw_wpa_set_auth_algs(priv, param->value);
6560 case IW_AUTH_WPA_ENABLED:
6561 ret = ipw_wpa_enable(priv, param->value);
6562 ipw_disassociate(priv);
6565 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6566 ieee->ieee802_1x = param->value;
6569 //case IW_AUTH_ROAMING_CONTROL:
6570 case IW_AUTH_PRIVACY_INVOKED:
6571 ieee->privacy_invoked = param->value;
6581 static int ipw_wx_get_auth(struct net_device *dev,
6582 struct iw_request_info *info,
6583 union iwreq_data *wrqu, char *extra)
6585 struct ipw_priv *priv = ieee80211_priv(dev);
6586 struct ieee80211_device *ieee = priv->ieee;
6587 struct ieee80211_crypt_data *crypt;
6588 struct iw_param *param = &wrqu->param;
6591 switch (param->flags & IW_AUTH_INDEX) {
6592 case IW_AUTH_WPA_VERSION:
6593 case IW_AUTH_CIPHER_PAIRWISE:
6594 case IW_AUTH_CIPHER_GROUP:
6595 case IW_AUTH_KEY_MGMT:
6597 * wpa_supplicant will control these internally
6602 case IW_AUTH_TKIP_COUNTERMEASURES:
6603 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6604 if (!crypt || !crypt->ops->get_flags)
6607 param->value = (crypt->ops->get_flags(crypt->priv) &
6608 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6612 case IW_AUTH_DROP_UNENCRYPTED:
6613 param->value = ieee->drop_unencrypted;
6616 case IW_AUTH_80211_AUTH_ALG:
6617 param->value = ieee->sec.auth_mode;
6620 case IW_AUTH_WPA_ENABLED:
6621 param->value = ieee->wpa_enabled;
6624 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6625 param->value = ieee->ieee802_1x;
6628 case IW_AUTH_ROAMING_CONTROL:
6629 case IW_AUTH_PRIVACY_INVOKED:
6630 param->value = ieee->privacy_invoked;
6639 /* SIOCSIWENCODEEXT */
6640 static int ipw_wx_set_encodeext(struct net_device *dev,
6641 struct iw_request_info *info,
6642 union iwreq_data *wrqu, char *extra)
6644 struct ipw_priv *priv = ieee80211_priv(dev);
6645 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6648 if (ext->alg == IW_ENCODE_ALG_TKIP) {
6649 /* IPW HW can't build TKIP MIC,
6650 host decryption still needed */
6651 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6652 priv->ieee->host_mc_decrypt = 1;
6654 priv->ieee->host_encrypt = 0;
6655 priv->ieee->host_encrypt_msdu = 1;
6656 priv->ieee->host_decrypt = 1;
6659 priv->ieee->host_encrypt = 0;
6660 priv->ieee->host_encrypt_msdu = 0;
6661 priv->ieee->host_decrypt = 0;
6662 priv->ieee->host_mc_decrypt = 0;
6666 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6669 /* SIOCGIWENCODEEXT */
6670 static int ipw_wx_get_encodeext(struct net_device *dev,
6671 struct iw_request_info *info,
6672 union iwreq_data *wrqu, char *extra)
6674 struct ipw_priv *priv = ieee80211_priv(dev);
6675 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6679 static int ipw_wx_set_mlme(struct net_device *dev,
6680 struct iw_request_info *info,
6681 union iwreq_data *wrqu, char *extra)
6683 struct ipw_priv *priv = ieee80211_priv(dev);
6684 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6687 reason = cpu_to_le16(mlme->reason_code);
6689 switch (mlme->cmd) {
6690 case IW_MLME_DEAUTH:
6694 case IW_MLME_DISASSOC:
6695 ipw_disassociate(priv);
6704 #ifdef CONFIG_IPW2200_QOS
6708 * get the modulation type of the current network or
6709 * the card current mode
6711 static u8 ipw_qos_current_mode(struct ipw_priv * priv)
6715 if (priv->status & STATUS_ASSOCIATED) {
6716 unsigned long flags;
6718 spin_lock_irqsave(&priv->ieee->lock, flags);
6719 mode = priv->assoc_network->mode;
6720 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6722 mode = priv->ieee->mode;
6724 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6729 * Handle management frame beacon and probe response
6731 static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6733 struct ieee80211_network *network)
6735 u32 size = sizeof(struct ieee80211_qos_parameters);
6737 if (network->capability & WLAN_CAPABILITY_IBSS)
6738 network->qos_data.active = network->qos_data.supported;
6740 if (network->flags & NETWORK_HAS_QOS_MASK) {
6741 if (active_network &&
6742 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
6743 network->qos_data.active = network->qos_data.supported;
6745 if ((network->qos_data.active == 1) && (active_network == 1) &&
6746 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6747 (network->qos_data.old_param_count !=
6748 network->qos_data.param_count)) {
6749 network->qos_data.old_param_count =
6750 network->qos_data.param_count;
6751 schedule_work(&priv->qos_activate);
6752 IPW_DEBUG_QOS("QoS parameters change call "
6756 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6757 memcpy(&network->qos_data.parameters,
6758 &def_parameters_CCK, size);
6760 memcpy(&network->qos_data.parameters,
6761 &def_parameters_OFDM, size);
6763 if ((network->qos_data.active == 1) && (active_network == 1)) {
6764 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6765 schedule_work(&priv->qos_activate);
6768 network->qos_data.active = 0;
6769 network->qos_data.supported = 0;
6771 if ((priv->status & STATUS_ASSOCIATED) &&
6772 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6773 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6774 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6775 !(network->flags & NETWORK_EMPTY_ESSID))
6776 if ((network->ssid_len ==
6777 priv->assoc_network->ssid_len) &&
6778 !memcmp(network->ssid,
6779 priv->assoc_network->ssid,
6780 network->ssid_len)) {
6781 queue_work(priv->workqueue,
6782 &priv->merge_networks);
6790 * This function set up the firmware to support QoS. It sends
6791 * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6793 static int ipw_qos_activate(struct ipw_priv *priv,
6794 struct ieee80211_qos_data *qos_network_data)
6797 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6798 struct ieee80211_qos_parameters *active_one = NULL;
6799 u32 size = sizeof(struct ieee80211_qos_parameters);
6804 type = ipw_qos_current_mode(priv);
6806 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6807 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6808 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6809 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6811 if (qos_network_data == NULL) {
6812 if (type == IEEE_B) {
6813 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6814 active_one = &def_parameters_CCK;
6816 active_one = &def_parameters_OFDM;
6818 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6819 burst_duration = ipw_qos_get_burst_duration(priv);
6820 for (i = 0; i < QOS_QUEUE_NUM; i++)
6821 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6822 (u16) burst_duration;
6823 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6824 if (type == IEEE_B) {
6825 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6827 if (priv->qos_data.qos_enable == 0)
6828 active_one = &def_parameters_CCK;
6830 active_one = priv->qos_data.def_qos_parm_CCK;
6832 if (priv->qos_data.qos_enable == 0)
6833 active_one = &def_parameters_OFDM;
6835 active_one = priv->qos_data.def_qos_parm_OFDM;
6837 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6839 unsigned long flags;
6842 spin_lock_irqsave(&priv->ieee->lock, flags);
6843 active_one = &(qos_network_data->parameters);
6844 qos_network_data->old_param_count =
6845 qos_network_data->param_count;
6846 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6847 active = qos_network_data->supported;
6848 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6851 burst_duration = ipw_qos_get_burst_duration(priv);
6852 for (i = 0; i < QOS_QUEUE_NUM; i++)
6853 qos_parameters[QOS_PARAM_SET_ACTIVE].
6854 tx_op_limit[i] = (u16) burst_duration;
6858 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
6859 err = ipw_send_qos_params_command(priv,
6860 (struct ieee80211_qos_parameters *)
6861 &(qos_parameters[0]));
6863 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6869 * send IPW_CMD_WME_INFO to the firmware
6871 static int ipw_qos_set_info_element(struct ipw_priv *priv)
6874 struct ieee80211_qos_information_element qos_info;
6879 qos_info.elementID = QOS_ELEMENT_ID;
6880 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6882 qos_info.version = QOS_VERSION_1;
6883 qos_info.ac_info = 0;
6885 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6886 qos_info.qui_type = QOS_OUI_TYPE;
6887 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6889 ret = ipw_send_qos_info_command(priv, &qos_info);
6891 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6897 * Set the QoS parameter with the association request structure
6899 static int ipw_qos_association(struct ipw_priv *priv,
6900 struct ieee80211_network *network)
6903 struct ieee80211_qos_data *qos_data = NULL;
6904 struct ieee80211_qos_data ibss_data = {
6909 switch (priv->ieee->iw_mode) {
6911 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
6913 qos_data = &ibss_data;
6917 qos_data = &network->qos_data;
6925 err = ipw_qos_activate(priv, qos_data);
6927 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6931 if (priv->qos_data.qos_enable && qos_data->supported) {
6932 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6933 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6934 return ipw_qos_set_info_element(priv);
6941 * handling the beaconing responces. if we get different QoS setting
6942 * of the network from the the associated setting adjust the QoS
6945 static int ipw_qos_association_resp(struct ipw_priv *priv,
6946 struct ieee80211_network *network)
6949 unsigned long flags;
6950 u32 size = sizeof(struct ieee80211_qos_parameters);
6951 int set_qos_param = 0;
6953 if ((priv == NULL) || (network == NULL) ||
6954 (priv->assoc_network == NULL))
6957 if (!(priv->status & STATUS_ASSOCIATED))
6960 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
6963 spin_lock_irqsave(&priv->ieee->lock, flags);
6964 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
6965 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
6966 sizeof(struct ieee80211_qos_data));
6967 priv->assoc_network->qos_data.active = 1;
6968 if ((network->qos_data.old_param_count !=
6969 network->qos_data.param_count)) {
6971 network->qos_data.old_param_count =
6972 network->qos_data.param_count;
6976 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
6977 memcpy(&priv->assoc_network->qos_data.parameters,
6978 &def_parameters_CCK, size);
6980 memcpy(&priv->assoc_network->qos_data.parameters,
6981 &def_parameters_OFDM, size);
6982 priv->assoc_network->qos_data.active = 0;
6983 priv->assoc_network->qos_data.supported = 0;
6987 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6989 if (set_qos_param == 1)
6990 schedule_work(&priv->qos_activate);
6995 static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7002 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
7003 ret = priv->qos_data.burst_duration_CCK;
7005 ret = priv->qos_data.burst_duration_OFDM;
7011 * Initialize the setting of QoS global
7013 static void ipw_qos_init(struct ipw_priv *priv, int enable,
7014 int burst_enable, u32 burst_duration_CCK,
7015 u32 burst_duration_OFDM)
7017 priv->qos_data.qos_enable = enable;
7019 if (priv->qos_data.qos_enable) {
7020 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7021 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7022 IPW_DEBUG_QOS("QoS is enabled\n");
7024 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7025 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7026 IPW_DEBUG_QOS("QoS is not enabled\n");
7029 priv->qos_data.burst_enable = burst_enable;
7032 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7033 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7035 priv->qos_data.burst_duration_CCK = 0;
7036 priv->qos_data.burst_duration_OFDM = 0;
7041 * map the packet priority to the right TX Queue
7043 static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7045 if (priority > 7 || !priv->qos_data.qos_enable)
7048 return from_priority_to_tx_queue[priority] - 1;
7051 static int ipw_is_qos_active(struct net_device *dev,
7052 struct sk_buff *skb)
7054 struct ipw_priv *priv = ieee80211_priv(dev);
7055 struct ieee80211_qos_data *qos_data = NULL;
7056 int active, supported;
7057 u8 *daddr = skb->data + ETH_ALEN;
7058 int unicast = !is_multicast_ether_addr(daddr);
7060 if (!(priv->status & STATUS_ASSOCIATED))
7063 qos_data = &priv->assoc_network->qos_data;
7065 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7067 qos_data->active = 0;
7069 qos_data->active = qos_data->supported;
7071 active = qos_data->active;
7072 supported = qos_data->supported;
7073 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7075 priv->qos_data.qos_enable, active, supported, unicast);
7076 if (active && priv->qos_data.qos_enable)
7083 * add QoS parameter to the TX command
7085 static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7087 struct tfd_data *tfd)
7089 int tx_queue_id = 0;
7092 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7093 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7095 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7096 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
7097 tfd->tfd.tfd_26.mchdr.qos_ctrl |= CTRL_QOS_NO_ACK;
7103 * background support to run QoS activate functionality
7105 static void ipw_bg_qos_activate(void *data)
7107 struct ipw_priv *priv = data;
7112 mutex_lock(&priv->mutex);
7114 if (priv->status & STATUS_ASSOCIATED)
7115 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7117 mutex_unlock(&priv->mutex);
7120 static int ipw_handle_probe_response(struct net_device *dev,
7121 struct ieee80211_probe_response *resp,
7122 struct ieee80211_network *network)
7124 struct ipw_priv *priv = ieee80211_priv(dev);
7125 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7126 (network == priv->assoc_network));
7128 ipw_qos_handle_probe_response(priv, active_network, network);
7133 static int ipw_handle_beacon(struct net_device *dev,
7134 struct ieee80211_beacon *resp,
7135 struct ieee80211_network *network)
7137 struct ipw_priv *priv = ieee80211_priv(dev);
7138 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7139 (network == priv->assoc_network));
7141 ipw_qos_handle_probe_response(priv, active_network, network);
7146 static int ipw_handle_assoc_response(struct net_device *dev,
7147 struct ieee80211_assoc_response *resp,
7148 struct ieee80211_network *network)
7150 struct ipw_priv *priv = ieee80211_priv(dev);
7151 ipw_qos_association_resp(priv, network);
7155 static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7158 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7159 sizeof(*qos_param) * 3, qos_param);
7162 static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7165 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7169 #endif /* CONFIG_IPW2200_QOS */
7171 static int ipw_associate_network(struct ipw_priv *priv,
7172 struct ieee80211_network *network,
7173 struct ipw_supported_rates *rates, int roaming)
7177 if (priv->config & CFG_FIXED_RATE)
7178 ipw_set_fixed_rate(priv, network->mode);
7180 if (!(priv->config & CFG_STATIC_ESSID)) {
7181 priv->essid_len = min(network->ssid_len,
7182 (u8) IW_ESSID_MAX_SIZE);
7183 memcpy(priv->essid, network->ssid, priv->essid_len);
7186 network->last_associate = jiffies;
7188 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7189 priv->assoc_request.channel = network->channel;
7190 priv->assoc_request.auth_key = 0;
7192 if ((priv->capability & CAP_PRIVACY_ON) &&
7193 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
7194 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
7195 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7197 if (priv->ieee->sec.level == SEC_LEVEL_1)
7198 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
7200 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7201 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7202 priv->assoc_request.auth_type = AUTH_LEAP;
7204 priv->assoc_request.auth_type = AUTH_OPEN;
7206 if (priv->ieee->wpa_ie_len) {
7207 priv->assoc_request.policy_support = 0x02; /* RSN active */
7208 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7209 priv->ieee->wpa_ie_len);
7213 * It is valid for our ieee device to support multiple modes, but
7214 * when it comes to associating to a given network we have to choose
7217 if (network->mode & priv->ieee->mode & IEEE_A)
7218 priv->assoc_request.ieee_mode = IPW_A_MODE;
7219 else if (network->mode & priv->ieee->mode & IEEE_G)
7220 priv->assoc_request.ieee_mode = IPW_G_MODE;
7221 else if (network->mode & priv->ieee->mode & IEEE_B)
7222 priv->assoc_request.ieee_mode = IPW_B_MODE;
7224 priv->assoc_request.capability = network->capability;
7225 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7226 && !(priv->config & CFG_PREAMBLE_LONG)) {
7227 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7229 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7231 /* Clear the short preamble if we won't be supporting it */
7232 priv->assoc_request.capability &=
7233 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7236 /* Clear capability bits that aren't used in Ad Hoc */
7237 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7238 priv->assoc_request.capability &=
7239 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7241 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
7242 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
7243 roaming ? "Rea" : "A",
7244 escape_essid(priv->essid, priv->essid_len),
7246 ipw_modes[priv->assoc_request.ieee_mode],
7248 (priv->assoc_request.preamble_length ==
7249 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7250 network->capability &
7251 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
7252 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
7253 priv->capability & CAP_PRIVACY_ON ?
7254 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
7256 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
7257 priv->capability & CAP_PRIVACY_ON ?
7258 '1' + priv->ieee->sec.active_key : '.',
7259 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
7261 priv->assoc_request.beacon_interval = network->beacon_interval;
7262 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
7263 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
7264 priv->assoc_request.assoc_type = HC_IBSS_START;
7265 priv->assoc_request.assoc_tsf_msw = 0;
7266 priv->assoc_request.assoc_tsf_lsw = 0;
7268 if (unlikely(roaming))
7269 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7271 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7272 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7273 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7276 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
7278 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7279 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7280 priv->assoc_request.atim_window = network->atim_window;
7282 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
7283 priv->assoc_request.atim_window = 0;
7286 priv->assoc_request.listen_interval = network->listen_interval;
7288 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7290 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7294 rates->ieee_mode = priv->assoc_request.ieee_mode;
7295 rates->purpose = IPW_RATE_CONNECT;
7296 ipw_send_supported_rates(priv, rates);
7298 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7299 priv->sys_config.dot11g_auto_detection = 1;
7301 priv->sys_config.dot11g_auto_detection = 0;
7303 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7304 priv->sys_config.answer_broadcast_ssid_probe = 1;
7306 priv->sys_config.answer_broadcast_ssid_probe = 0;
7308 err = ipw_send_system_config(priv);
7310 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7314 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
7315 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
7317 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7322 * If preemption is enabled, it is possible for the association
7323 * to complete before we return from ipw_send_associate. Therefore
7324 * we have to be sure and update our priviate data first.
7326 priv->channel = network->channel;
7327 memcpy(priv->bssid, network->bssid, ETH_ALEN);
7328 priv->status |= STATUS_ASSOCIATING;
7329 priv->status &= ~STATUS_SECURITY_UPDATED;
7331 priv->assoc_network = network;
7333 #ifdef CONFIG_IPW2200_QOS
7334 ipw_qos_association(priv, network);
7337 err = ipw_send_associate(priv, &priv->assoc_request);
7339 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7343 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
7344 escape_essid(priv->essid, priv->essid_len),
7345 MAC_ARG(priv->bssid));
7350 static void ipw_roam(void *data)
7352 struct ipw_priv *priv = data;
7353 struct ieee80211_network *network = NULL;
7354 struct ipw_network_match match = {
7355 .network = priv->assoc_network
7358 /* The roaming process is as follows:
7360 * 1. Missed beacon threshold triggers the roaming process by
7361 * setting the status ROAM bit and requesting a scan.
7362 * 2. When the scan completes, it schedules the ROAM work
7363 * 3. The ROAM work looks at all of the known networks for one that
7364 * is a better network than the currently associated. If none
7365 * found, the ROAM process is over (ROAM bit cleared)
7366 * 4. If a better network is found, a disassociation request is
7368 * 5. When the disassociation completes, the roam work is again
7369 * scheduled. The second time through, the driver is no longer
7370 * associated, and the newly selected network is sent an
7371 * association request.
7372 * 6. At this point ,the roaming process is complete and the ROAM
7373 * status bit is cleared.
7376 /* If we are no longer associated, and the roaming bit is no longer
7377 * set, then we are not actively roaming, so just return */
7378 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7381 if (priv->status & STATUS_ASSOCIATED) {
7382 /* First pass through ROAM process -- look for a better
7384 unsigned long flags;
7385 u8 rssi = priv->assoc_network->stats.rssi;
7386 priv->assoc_network->stats.rssi = -128;
7387 spin_lock_irqsave(&priv->ieee->lock, flags);
7388 list_for_each_entry(network, &priv->ieee->network_list, list) {
7389 if (network != priv->assoc_network)
7390 ipw_best_network(priv, &match, network, 1);
7392 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7393 priv->assoc_network->stats.rssi = rssi;
7395 if (match.network == priv->assoc_network) {
7396 IPW_DEBUG_ASSOC("No better APs in this network to "
7398 priv->status &= ~STATUS_ROAMING;
7399 ipw_debug_config(priv);
7403 ipw_send_disassociate(priv, 1);
7404 priv->assoc_network = match.network;
7409 /* Second pass through ROAM process -- request association */
7410 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7411 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7412 priv->status &= ~STATUS_ROAMING;
7415 static void ipw_bg_roam(void *data)
7417 struct ipw_priv *priv = data;
7418 mutex_lock(&priv->mutex);
7420 mutex_unlock(&priv->mutex);
7423 static int ipw_associate(void *data)
7425 struct ipw_priv *priv = data;
7427 struct ieee80211_network *network = NULL;
7428 struct ipw_network_match match = {
7431 struct ipw_supported_rates *rates;
7432 struct list_head *element;
7433 unsigned long flags;
7435 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7436 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7440 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
7441 IPW_DEBUG_ASSOC("Not attempting association (already in "
7446 if (priv->status & STATUS_DISASSOCIATING) {
7447 IPW_DEBUG_ASSOC("Not attempting association (in "
7448 "disassociating)\n ");
7449 queue_work(priv->workqueue, &priv->associate);
7453 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
7454 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7459 if (!(priv->config & CFG_ASSOCIATE) &&
7460 !(priv->config & (CFG_STATIC_ESSID |
7461 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
7462 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
7466 /* Protect our use of the network_list */
7467 spin_lock_irqsave(&priv->ieee->lock, flags);
7468 list_for_each_entry(network, &priv->ieee->network_list, list)
7469 ipw_best_network(priv, &match, network, 0);
7471 network = match.network;
7472 rates = &match.rates;
7474 if (network == NULL &&
7475 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7476 priv->config & CFG_ADHOC_CREATE &&
7477 priv->config & CFG_STATIC_ESSID &&
7478 priv->config & CFG_STATIC_CHANNEL &&
7479 !list_empty(&priv->ieee->network_free_list)) {
7480 element = priv->ieee->network_free_list.next;
7481 network = list_entry(element, struct ieee80211_network, list);
7482 ipw_adhoc_create(priv, network);
7483 rates = &priv->rates;
7485 list_add_tail(&network->list, &priv->ieee->network_list);
7487 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7489 /* If we reached the end of the list, then we don't have any valid
7492 ipw_debug_config(priv);
7494 if (!(priv->status & STATUS_SCANNING)) {
7495 if (!(priv->config & CFG_SPEED_SCAN))
7496 queue_delayed_work(priv->workqueue,
7497 &priv->request_scan,
7500 queue_work(priv->workqueue,
7501 &priv->request_scan);
7507 ipw_associate_network(priv, network, rates, 0);
7512 static void ipw_bg_associate(void *data)
7514 struct ipw_priv *priv = data;
7515 mutex_lock(&priv->mutex);
7516 ipw_associate(data);
7517 mutex_unlock(&priv->mutex);
7520 static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7521 struct sk_buff *skb)
7523 struct ieee80211_hdr *hdr;
7526 hdr = (struct ieee80211_hdr *)skb->data;
7527 fc = le16_to_cpu(hdr->frame_ctl);
7528 if (!(fc & IEEE80211_FCTL_PROTECTED))
7531 fc &= ~IEEE80211_FCTL_PROTECTED;
7532 hdr->frame_ctl = cpu_to_le16(fc);
7533 switch (priv->ieee->sec.level) {
7535 /* Remove CCMP HDR */
7536 memmove(skb->data + IEEE80211_3ADDR_LEN,
7537 skb->data + IEEE80211_3ADDR_LEN + 8,
7538 skb->len - IEEE80211_3ADDR_LEN - 8);
7539 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
7545 memmove(skb->data + IEEE80211_3ADDR_LEN,
7546 skb->data + IEEE80211_3ADDR_LEN + 4,
7547 skb->len - IEEE80211_3ADDR_LEN - 4);
7548 skb_trim(skb, skb->len - 8); /* IV + ICV */
7553 printk(KERN_ERR "Unknow security level %d\n",
7554 priv->ieee->sec.level);
7559 static void ipw_handle_data_packet(struct ipw_priv *priv,
7560 struct ipw_rx_mem_buffer *rxb,
7561 struct ieee80211_rx_stats *stats)
7563 struct ieee80211_hdr_4addr *hdr;
7564 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7566 /* We received data from the HW, so stop the watchdog */
7567 priv->net_dev->trans_start = jiffies;
7569 /* We only process data packets if the
7570 * interface is open */
7571 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7572 skb_tailroom(rxb->skb))) {
7573 priv->ieee->stats.rx_errors++;
7574 priv->wstats.discard.misc++;
7575 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7577 } else if (unlikely(!netif_running(priv->net_dev))) {
7578 priv->ieee->stats.rx_dropped++;
7579 priv->wstats.discard.misc++;
7580 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7584 /* Advance skb->data to the start of the actual payload */
7585 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
7587 /* Set the size of the skb to the size of the frame */
7588 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
7590 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7592 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
7593 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7594 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
7595 (is_multicast_ether_addr(hdr->addr1) ?
7596 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
7597 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7599 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7600 priv->ieee->stats.rx_errors++;
7601 else { /* ieee80211_rx succeeded, so it now owns the SKB */
7603 __ipw_led_activity_on(priv);
7607 #ifdef CONFIG_IPW2200_RADIOTAP
7608 static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7609 struct ipw_rx_mem_buffer *rxb,
7610 struct ieee80211_rx_stats *stats)
7612 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7613 struct ipw_rx_frame *frame = &pkt->u.frame;
7615 /* initial pull of some data */
7616 u16 received_channel = frame->received_channel;
7617 u8 antennaAndPhy = frame->antennaAndPhy;
7618 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7619 u16 pktrate = frame->rate;
7621 /* Magic struct that slots into the radiotap header -- no reason
7622 * to build this manually element by element, we can write it much
7623 * more efficiently than we can parse it. ORDER MATTERS HERE */
7624 struct ipw_rt_hdr *ipw_rt;
7626 short len = le16_to_cpu(pkt->u.frame.length);
7628 /* We received data from the HW, so stop the watchdog */
7629 priv->net_dev->trans_start = jiffies;
7631 /* We only process data packets if the
7632 * interface is open */
7633 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7634 skb_tailroom(rxb->skb))) {
7635 priv->ieee->stats.rx_errors++;
7636 priv->wstats.discard.misc++;
7637 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7639 } else if (unlikely(!netif_running(priv->net_dev))) {
7640 priv->ieee->stats.rx_dropped++;
7641 priv->wstats.discard.misc++;
7642 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7646 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7648 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7649 /* FIXME: Should alloc bigger skb instead */
7650 priv->ieee->stats.rx_dropped++;
7651 priv->wstats.discard.misc++;
7652 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7656 /* copy the frame itself */
7657 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7658 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7660 /* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7661 * part of our real header, saves a little time.
7663 * No longer necessary since we fill in all our data. Purge before merging
7665 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7666 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7669 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7671 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7672 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7673 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7675 /* Big bitfield of all the fields we provide in radiotap */
7676 ipw_rt->rt_hdr.it_present =
7677 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7678 (1 << IEEE80211_RADIOTAP_TSFT) |
7679 (1 << IEEE80211_RADIOTAP_RATE) |
7680 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7681 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7682 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
7683 (1 << IEEE80211_RADIOTAP_ANTENNA));
7685 /* Zero the flags, we'll add to them as we go */
7686 ipw_rt->rt_flags = 0;
7688 /* Convert signal to DBM */
7689 ipw_rt->rt_dbmsignal = antsignal;
7691 /* Convert the channel data and set the flags */
7692 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7693 if (received_channel > 14) { /* 802.11a */
7694 ipw_rt->rt_chbitmask =
7695 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7696 } else if (antennaAndPhy & 32) { /* 802.11b */
7697 ipw_rt->rt_chbitmask =
7698 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7699 } else { /* 802.11g */
7700 ipw_rt->rt_chbitmask =
7701 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7704 /* set the rate in multiples of 500k/s */
7706 case IPW_TX_RATE_1MB:
7707 ipw_rt->rt_rate = 2;
7709 case IPW_TX_RATE_2MB:
7710 ipw_rt->rt_rate = 4;
7712 case IPW_TX_RATE_5MB:
7713 ipw_rt->rt_rate = 10;
7715 case IPW_TX_RATE_6MB:
7716 ipw_rt->rt_rate = 12;
7718 case IPW_TX_RATE_9MB:
7719 ipw_rt->rt_rate = 18;
7721 case IPW_TX_RATE_11MB:
7722 ipw_rt->rt_rate = 22;
7724 case IPW_TX_RATE_12MB:
7725 ipw_rt->rt_rate = 24;
7727 case IPW_TX_RATE_18MB:
7728 ipw_rt->rt_rate = 36;
7730 case IPW_TX_RATE_24MB:
7731 ipw_rt->rt_rate = 48;
7733 case IPW_TX_RATE_36MB:
7734 ipw_rt->rt_rate = 72;
7736 case IPW_TX_RATE_48MB:
7737 ipw_rt->rt_rate = 96;
7739 case IPW_TX_RATE_54MB:
7740 ipw_rt->rt_rate = 108;
7743 ipw_rt->rt_rate = 0;
7747 /* antenna number */
7748 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7750 /* set the preamble flag if we have it */
7751 if ((antennaAndPhy & 64))
7752 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7754 /* Set the size of the skb to the size of the frame */
7755 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
7757 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7759 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7760 priv->ieee->stats.rx_errors++;
7761 else { /* ieee80211_rx succeeded, so it now owns the SKB */
7763 /* no LED during capture */
7768 #ifdef CONFIG_IPW2200_PROMISCUOUS
7769 #define ieee80211_is_probe_response(fc) \
7770 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7771 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7773 #define ieee80211_is_management(fc) \
7774 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7776 #define ieee80211_is_control(fc) \
7777 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7779 #define ieee80211_is_data(fc) \
7780 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
7782 #define ieee80211_is_assoc_request(fc) \
7783 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
7785 #define ieee80211_is_reassoc_request(fc) \
7786 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
7788 static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
7789 struct ipw_rx_mem_buffer *rxb,
7790 struct ieee80211_rx_stats *stats)
7792 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7793 struct ipw_rx_frame *frame = &pkt->u.frame;
7794 struct ipw_rt_hdr *ipw_rt;
7796 /* First cache any information we need before we overwrite
7797 * the information provided in the skb from the hardware */
7798 struct ieee80211_hdr *hdr;
7799 u16 channel = frame->received_channel;
7800 u8 phy_flags = frame->antennaAndPhy;
7801 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
7802 s8 noise = frame->noise;
7803 u8 rate = frame->rate;
7804 short len = le16_to_cpu(pkt->u.frame.length);
7806 struct sk_buff *skb;
7808 u16 filter = priv->prom_priv->filter;
7810 /* If the filter is set to not include Rx frames then return */
7811 if (filter & IPW_PROM_NO_RX)
7814 /* We received data from the HW, so stop the watchdog */
7815 priv->prom_net_dev->trans_start = jiffies;
7817 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
7818 priv->prom_priv->ieee->stats.rx_errors++;
7819 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7823 /* We only process data packets if the interface is open */
7824 if (unlikely(!netif_running(priv->prom_net_dev))) {
7825 priv->prom_priv->ieee->stats.rx_dropped++;
7826 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7830 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7832 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7833 /* FIXME: Should alloc bigger skb instead */
7834 priv->prom_priv->ieee->stats.rx_dropped++;
7835 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7839 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
7840 if (ieee80211_is_management(hdr->frame_ctl)) {
7841 if (filter & IPW_PROM_NO_MGMT)
7843 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
7845 } else if (ieee80211_is_control(hdr->frame_ctl)) {
7846 if (filter & IPW_PROM_NO_CTL)
7848 if (filter & IPW_PROM_CTL_HEADER_ONLY)
7850 } else if (ieee80211_is_data(hdr->frame_ctl)) {
7851 if (filter & IPW_PROM_NO_DATA)
7853 if (filter & IPW_PROM_DATA_HEADER_ONLY)
7857 /* Copy the SKB since this is for the promiscuous side */
7858 skb = skb_copy(rxb->skb, GFP_ATOMIC);
7860 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
7864 /* copy the frame data to write after where the radiotap header goes */
7865 ipw_rt = (void *)skb->data;
7868 len = ieee80211_get_hdrlen(hdr->frame_ctl);
7870 memcpy(ipw_rt->payload, hdr, len);
7872 /* Zero the radiotap static buffer ... We only need to zero the bytes
7873 * NOT part of our real header, saves a little time.
7875 * No longer necessary since we fill in all our data. Purge before
7876 * merging patch officially.
7877 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7878 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7881 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7882 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7883 ipw_rt->rt_hdr.it_len = sizeof(*ipw_rt); /* total header+data */
7885 /* Set the size of the skb to the size of the frame */
7886 skb_put(skb, ipw_rt->rt_hdr.it_len + len);
7888 /* Big bitfield of all the fields we provide in radiotap */
7889 ipw_rt->rt_hdr.it_present =
7890 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7891 (1 << IEEE80211_RADIOTAP_TSFT) |
7892 (1 << IEEE80211_RADIOTAP_RATE) |
7893 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7894 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7895 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
7896 (1 << IEEE80211_RADIOTAP_ANTENNA));
7898 /* Zero the flags, we'll add to them as we go */
7899 ipw_rt->rt_flags = 0;
7901 ipw_rt->rt_tsf = tsf;
7903 /* Convert to DBM */
7904 ipw_rt->rt_dbmsignal = signal;
7905 ipw_rt->rt_dbmnoise = noise;
7907 /* Convert the channel data and set the flags */
7908 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
7909 if (channel > 14) { /* 802.11a */
7910 ipw_rt->rt_chbitmask =
7911 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7912 } else if (phy_flags & (1 << 5)) { /* 802.11b */
7913 ipw_rt->rt_chbitmask =
7914 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7915 } else { /* 802.11g */
7916 ipw_rt->rt_chbitmask =
7917 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7920 /* set the rate in multiples of 500k/s */
7922 case IPW_TX_RATE_1MB:
7923 ipw_rt->rt_rate = 2;
7925 case IPW_TX_RATE_2MB:
7926 ipw_rt->rt_rate = 4;
7928 case IPW_TX_RATE_5MB:
7929 ipw_rt->rt_rate = 10;
7931 case IPW_TX_RATE_6MB:
7932 ipw_rt->rt_rate = 12;
7934 case IPW_TX_RATE_9MB:
7935 ipw_rt->rt_rate = 18;
7937 case IPW_TX_RATE_11MB:
7938 ipw_rt->rt_rate = 22;
7940 case IPW_TX_RATE_12MB:
7941 ipw_rt->rt_rate = 24;
7943 case IPW_TX_RATE_18MB:
7944 ipw_rt->rt_rate = 36;
7946 case IPW_TX_RATE_24MB:
7947 ipw_rt->rt_rate = 48;
7949 case IPW_TX_RATE_36MB:
7950 ipw_rt->rt_rate = 72;
7952 case IPW_TX_RATE_48MB:
7953 ipw_rt->rt_rate = 96;
7955 case IPW_TX_RATE_54MB:
7956 ipw_rt->rt_rate = 108;
7959 ipw_rt->rt_rate = 0;
7963 /* antenna number */
7964 ipw_rt->rt_antenna = (phy_flags & 3);
7966 /* set the preamble flag if we have it */
7967 if (phy_flags & (1 << 6))
7968 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7970 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
7972 if (!ieee80211_rx(priv->prom_priv->ieee, skb, stats)) {
7973 priv->prom_priv->ieee->stats.rx_errors++;
7974 dev_kfree_skb_any(skb);
7979 static int is_network_packet(struct ipw_priv *priv,
7980 struct ieee80211_hdr_4addr *header)
7982 /* Filter incoming packets to determine if they are targetted toward
7983 * this network, discarding packets coming from ourselves */
7984 switch (priv->ieee->iw_mode) {
7985 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
7986 /* packets from our adapter are dropped (echo) */
7987 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7990 /* {broad,multi}cast packets to our BSSID go through */
7991 if (is_multicast_ether_addr(header->addr1))
7992 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
7994 /* packets to our adapter go through */
7995 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7998 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
7999 /* packets from our adapter are dropped (echo) */
8000 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
8003 /* {broad,multi}cast packets to our BSS go through */
8004 if (is_multicast_ether_addr(header->addr1))
8005 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
8007 /* packets to our adapter go through */
8008 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8015 #define IPW_PACKET_RETRY_TIME HZ
8017 static int is_duplicate_packet(struct ipw_priv *priv,
8018 struct ieee80211_hdr_4addr *header)
8020 u16 sc = le16_to_cpu(header->seq_ctl);
8021 u16 seq = WLAN_GET_SEQ_SEQ(sc);
8022 u16 frag = WLAN_GET_SEQ_FRAG(sc);
8023 u16 *last_seq, *last_frag;
8024 unsigned long *last_time;
8026 switch (priv->ieee->iw_mode) {
8029 struct list_head *p;
8030 struct ipw_ibss_seq *entry = NULL;
8031 u8 *mac = header->addr2;
8032 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8034 __list_for_each(p, &priv->ibss_mac_hash[index]) {
8036 list_entry(p, struct ipw_ibss_seq, list);
8037 if (!memcmp(entry->mac, mac, ETH_ALEN))
8040 if (p == &priv->ibss_mac_hash[index]) {
8041 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
8044 ("Cannot malloc new mac entry\n");
8047 memcpy(entry->mac, mac, ETH_ALEN);
8048 entry->seq_num = seq;
8049 entry->frag_num = frag;
8050 entry->packet_time = jiffies;
8051 list_add(&entry->list,
8052 &priv->ibss_mac_hash[index]);
8055 last_seq = &entry->seq_num;
8056 last_frag = &entry->frag_num;
8057 last_time = &entry->packet_time;
8061 last_seq = &priv->last_seq_num;
8062 last_frag = &priv->last_frag_num;
8063 last_time = &priv->last_packet_time;
8068 if ((*last_seq == seq) &&
8069 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8070 if (*last_frag == frag)
8072 if (*last_frag + 1 != frag)
8073 /* out-of-order fragment */
8079 *last_time = jiffies;
8083 /* Comment this line now since we observed the card receives
8084 * duplicate packets but the FCTL_RETRY bit is not set in the
8085 * IBSS mode with fragmentation enabled.
8086 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
8090 static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8091 struct ipw_rx_mem_buffer *rxb,
8092 struct ieee80211_rx_stats *stats)
8094 struct sk_buff *skb = rxb->skb;
8095 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
8096 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
8097 (skb->data + IPW_RX_FRAME_SIZE);
8099 ieee80211_rx_mgt(priv->ieee, header, stats);
8101 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8102 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8103 IEEE80211_STYPE_PROBE_RESP) ||
8104 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8105 IEEE80211_STYPE_BEACON))) {
8106 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8107 ipw_add_station(priv, header->addr2);
8110 if (priv->config & CFG_NET_STATS) {
8111 IPW_DEBUG_HC("sending stat packet\n");
8113 /* Set the size of the skb to the size of the full
8114 * ipw header and 802.11 frame */
8115 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8118 /* Advance past the ipw packet header to the 802.11 frame */
8119 skb_pull(skb, IPW_RX_FRAME_SIZE);
8121 /* Push the ieee80211_rx_stats before the 802.11 frame */
8122 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8124 skb->dev = priv->ieee->dev;
8126 /* Point raw at the ieee80211_stats */
8127 skb->mac.raw = skb->data;
8129 skb->pkt_type = PACKET_OTHERHOST;
8130 skb->protocol = __constant_htons(ETH_P_80211_STATS);
8131 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8138 * Main entry function for recieving a packet with 80211 headers. This
8139 * should be called when ever the FW has notified us that there is a new
8140 * skb in the recieve queue.
8142 static void ipw_rx(struct ipw_priv *priv)
8144 struct ipw_rx_mem_buffer *rxb;
8145 struct ipw_rx_packet *pkt;
8146 struct ieee80211_hdr_4addr *header;
8150 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8151 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
8152 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
8155 rxb = priv->rxq->queue[i];
8156 if (unlikely(rxb == NULL)) {
8157 printk(KERN_CRIT "Queue not allocated!\n");
8160 priv->rxq->queue[i] = NULL;
8162 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
8164 PCI_DMA_FROMDEVICE);
8166 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8167 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8168 pkt->header.message_type,
8169 pkt->header.rx_seq_num, pkt->header.control_bits);
8171 switch (pkt->header.message_type) {
8172 case RX_FRAME_TYPE: /* 802.11 frame */ {
8173 struct ieee80211_rx_stats stats = {
8175 le16_to_cpu(pkt->u.frame.rssi_dbm) -
8178 le16_to_cpu(pkt->u.frame.rssi_dbm) -
8179 IPW_RSSI_TO_DBM + 0x100,
8181 le16_to_cpu(pkt->u.frame.noise),
8182 .rate = pkt->u.frame.rate,
8183 .mac_time = jiffies,
8185 pkt->u.frame.received_channel,
8188 control & (1 << 0)) ?
8189 IEEE80211_24GHZ_BAND :
8190 IEEE80211_52GHZ_BAND,
8191 .len = le16_to_cpu(pkt->u.frame.length),
8194 if (stats.rssi != 0)
8195 stats.mask |= IEEE80211_STATMASK_RSSI;
8196 if (stats.signal != 0)
8197 stats.mask |= IEEE80211_STATMASK_SIGNAL;
8198 if (stats.noise != 0)
8199 stats.mask |= IEEE80211_STATMASK_NOISE;
8200 if (stats.rate != 0)
8201 stats.mask |= IEEE80211_STATMASK_RATE;
8205 #ifdef CONFIG_IPW2200_PROMISCUOUS
8206 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8207 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8210 #ifdef CONFIG_IPW2200_MONITOR
8211 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
8212 #ifdef CONFIG_IPW2200_RADIOTAP
8214 ipw_handle_data_packet_monitor(priv,
8218 ipw_handle_data_packet(priv, rxb,
8226 (struct ieee80211_hdr_4addr *)(rxb->skb->
8229 /* TODO: Check Ad-Hoc dest/source and make sure
8230 * that we are actually parsing these packets
8231 * correctly -- we should probably use the
8232 * frame control of the packet and disregard
8233 * the current iw_mode */
8236 is_network_packet(priv, header);
8237 if (network_packet && priv->assoc_network) {
8238 priv->assoc_network->stats.rssi =
8240 priv->exp_avg_rssi =
8241 exponential_average(priv->exp_avg_rssi,
8242 stats.rssi, DEPTH_RSSI);
8245 IPW_DEBUG_RX("Frame: len=%u\n",
8246 le16_to_cpu(pkt->u.frame.length));
8248 if (le16_to_cpu(pkt->u.frame.length) <
8249 ieee80211_get_hdrlen(le16_to_cpu(
8250 header->frame_ctl))) {
8252 ("Received packet is too small. "
8254 priv->ieee->stats.rx_errors++;
8255 priv->wstats.discard.misc++;
8259 switch (WLAN_FC_GET_TYPE
8260 (le16_to_cpu(header->frame_ctl))) {
8262 case IEEE80211_FTYPE_MGMT:
8263 ipw_handle_mgmt_packet(priv, rxb,
8267 case IEEE80211_FTYPE_CTL:
8270 case IEEE80211_FTYPE_DATA:
8271 if (unlikely(!network_packet ||
8272 is_duplicate_packet(priv,
8275 IPW_DEBUG_DROP("Dropping: "
8288 ipw_handle_data_packet(priv, rxb,
8296 case RX_HOST_NOTIFICATION_TYPE:{
8298 ("Notification: subtype=%02X flags=%02X size=%d\n",
8299 pkt->u.notification.subtype,
8300 pkt->u.notification.flags,
8301 pkt->u.notification.size);
8302 ipw_rx_notification(priv, &pkt->u.notification);
8307 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8308 pkt->header.message_type);
8312 /* For now we just don't re-use anything. We can tweak this
8313 * later to try and re-use notification packets and SKBs that
8314 * fail to Rx correctly */
8315 if (rxb->skb != NULL) {
8316 dev_kfree_skb_any(rxb->skb);
8320 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
8321 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
8322 list_add_tail(&rxb->list, &priv->rxq->rx_used);
8324 i = (i + 1) % RX_QUEUE_SIZE;
8327 /* Backtrack one entry */
8328 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
8330 ipw_rx_queue_restock(priv);
8333 #define DEFAULT_RTS_THRESHOLD 2304U
8334 #define MIN_RTS_THRESHOLD 1U
8335 #define MAX_RTS_THRESHOLD 2304U
8336 #define DEFAULT_BEACON_INTERVAL 100U
8337 #define DEFAULT_SHORT_RETRY_LIMIT 7U
8338 #define DEFAULT_LONG_RETRY_LIMIT 4U
8342 * @option: options to control different reset behaviour
8343 * 0 = reset everything except the 'disable' module_param
8344 * 1 = reset everything and print out driver info (for probe only)
8345 * 2 = reset everything
8347 static int ipw_sw_reset(struct ipw_priv *priv, int option)
8349 int band, modulation;
8350 int old_mode = priv->ieee->iw_mode;
8352 /* Initialize module parameter values here */
8355 /* We default to disabling the LED code as right now it causes
8356 * too many systems to lock up... */
8358 priv->config |= CFG_NO_LED;
8361 priv->config |= CFG_ASSOCIATE;
8363 IPW_DEBUG_INFO("Auto associate disabled.\n");
8366 priv->config |= CFG_ADHOC_CREATE;
8368 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8370 priv->config &= ~CFG_STATIC_ESSID;
8371 priv->essid_len = 0;
8372 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8374 if (disable && option) {
8375 priv->status |= STATUS_RF_KILL_SW;
8376 IPW_DEBUG_INFO("Radio disabled.\n");
8380 priv->config |= CFG_STATIC_CHANNEL;
8381 priv->channel = channel;
8382 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8383 /* TODO: Validate that provided channel is in range */
8385 #ifdef CONFIG_IPW2200_QOS
8386 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8387 burst_duration_CCK, burst_duration_OFDM);
8388 #endif /* CONFIG_IPW2200_QOS */
8392 priv->ieee->iw_mode = IW_MODE_ADHOC;
8393 priv->net_dev->type = ARPHRD_ETHER;
8396 #ifdef CONFIG_IPW2200_MONITOR
8398 priv->ieee->iw_mode = IW_MODE_MONITOR;
8399 #ifdef CONFIG_IPW2200_RADIOTAP
8400 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8402 priv->net_dev->type = ARPHRD_IEEE80211;
8408 priv->net_dev->type = ARPHRD_ETHER;
8409 priv->ieee->iw_mode = IW_MODE_INFRA;
8414 priv->ieee->host_encrypt = 0;
8415 priv->ieee->host_encrypt_msdu = 0;
8416 priv->ieee->host_decrypt = 0;
8417 priv->ieee->host_mc_decrypt = 0;
8419 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
8421 /* IPW2200/2915 is abled to do hardware fragmentation. */
8422 priv->ieee->host_open_frag = 0;
8424 if ((priv->pci_dev->device == 0x4223) ||
8425 (priv->pci_dev->device == 0x4224)) {
8427 printk(KERN_INFO DRV_NAME
8428 ": Detected Intel PRO/Wireless 2915ABG Network "
8430 priv->ieee->abg_true = 1;
8431 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8432 modulation = IEEE80211_OFDM_MODULATION |
8433 IEEE80211_CCK_MODULATION;
8434 priv->adapter = IPW_2915ABG;
8435 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
8438 printk(KERN_INFO DRV_NAME
8439 ": Detected Intel PRO/Wireless 2200BG Network "
8442 priv->ieee->abg_true = 0;
8443 band = IEEE80211_24GHZ_BAND;
8444 modulation = IEEE80211_OFDM_MODULATION |
8445 IEEE80211_CCK_MODULATION;
8446 priv->adapter = IPW_2200BG;
8447 priv->ieee->mode = IEEE_G | IEEE_B;
8450 priv->ieee->freq_band = band;
8451 priv->ieee->modulation = modulation;
8453 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
8455 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8456 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8458 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8459 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8460 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
8462 /* If power management is turned on, default to AC mode */
8463 priv->power_mode = IPW_POWER_AC;
8464 priv->tx_power = IPW_TX_POWER_DEFAULT;
8466 return old_mode == priv->ieee->iw_mode;
8470 * This file defines the Wireless Extension handlers. It does not
8471 * define any methods of hardware manipulation and relies on the
8472 * functions defined in ipw_main to provide the HW interaction.
8474 * The exception to this is the use of the ipw_get_ordinal()
8475 * function used to poll the hardware vs. making unecessary calls.
8479 static int ipw_wx_get_name(struct net_device *dev,
8480 struct iw_request_info *info,
8481 union iwreq_data *wrqu, char *extra)
8483 struct ipw_priv *priv = ieee80211_priv(dev);
8484 mutex_lock(&priv->mutex);
8485 if (priv->status & STATUS_RF_KILL_MASK)
8486 strcpy(wrqu->name, "radio off");
8487 else if (!(priv->status & STATUS_ASSOCIATED))
8488 strcpy(wrqu->name, "unassociated");
8490 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8491 ipw_modes[priv->assoc_request.ieee_mode]);
8492 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
8493 mutex_unlock(&priv->mutex);
8497 static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8500 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8501 priv->config &= ~CFG_STATIC_CHANNEL;
8502 IPW_DEBUG_ASSOC("Attempting to associate with new "
8504 ipw_associate(priv);
8508 priv->config |= CFG_STATIC_CHANNEL;
8510 if (priv->channel == channel) {
8511 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8516 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8517 priv->channel = channel;
8519 #ifdef CONFIG_IPW2200_MONITOR
8520 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
8522 if (priv->status & STATUS_SCANNING) {
8523 IPW_DEBUG_SCAN("Scan abort triggered due to "
8524 "channel change.\n");
8525 ipw_abort_scan(priv);
8528 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8531 if (priv->status & STATUS_SCANNING)
8532 IPW_DEBUG_SCAN("Still scanning...\n");
8534 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8539 #endif /* CONFIG_IPW2200_MONITOR */
8541 /* Network configuration changed -- force [re]association */
8542 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8543 if (!ipw_disassociate(priv))
8544 ipw_associate(priv);
8549 static int ipw_wx_set_freq(struct net_device *dev,
8550 struct iw_request_info *info,
8551 union iwreq_data *wrqu, char *extra)
8553 struct ipw_priv *priv = ieee80211_priv(dev);
8554 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
8555 struct iw_freq *fwrq = &wrqu->freq;
8561 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
8562 mutex_lock(&priv->mutex);
8563 ret = ipw_set_channel(priv, 0);
8564 mutex_unlock(&priv->mutex);
8567 /* if setting by freq convert to channel */
8569 channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
8575 if (!(band = ieee80211_is_valid_channel(priv->ieee, channel)))
8578 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
8579 i = ieee80211_channel_to_index(priv->ieee, channel);
8583 flags = (band == IEEE80211_24GHZ_BAND) ?
8584 geo->bg[i].flags : geo->a[i].flags;
8585 if (flags & IEEE80211_CH_PASSIVE_ONLY) {
8586 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8591 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
8592 mutex_lock(&priv->mutex);
8593 ret = ipw_set_channel(priv, channel);
8594 mutex_unlock(&priv->mutex);
8598 static int ipw_wx_get_freq(struct net_device *dev,
8599 struct iw_request_info *info,
8600 union iwreq_data *wrqu, char *extra)
8602 struct ipw_priv *priv = ieee80211_priv(dev);
8606 /* If we are associated, trying to associate, or have a statically
8607 * configured CHANNEL then return that; otherwise return ANY */
8608 mutex_lock(&priv->mutex);
8609 if (priv->config & CFG_STATIC_CHANNEL ||
8610 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8611 wrqu->freq.m = priv->channel;
8615 mutex_unlock(&priv->mutex);
8616 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8620 static int ipw_wx_set_mode(struct net_device *dev,
8621 struct iw_request_info *info,
8622 union iwreq_data *wrqu, char *extra)
8624 struct ipw_priv *priv = ieee80211_priv(dev);
8627 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8629 switch (wrqu->mode) {
8630 #ifdef CONFIG_IPW2200_MONITOR
8631 case IW_MODE_MONITOR:
8637 wrqu->mode = IW_MODE_INFRA;
8642 if (wrqu->mode == priv->ieee->iw_mode)
8645 mutex_lock(&priv->mutex);
8647 ipw_sw_reset(priv, 0);
8649 #ifdef CONFIG_IPW2200_MONITOR
8650 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
8651 priv->net_dev->type = ARPHRD_ETHER;
8653 if (wrqu->mode == IW_MODE_MONITOR)
8654 #ifdef CONFIG_IPW2200_RADIOTAP
8655 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8657 priv->net_dev->type = ARPHRD_IEEE80211;
8659 #endif /* CONFIG_IPW2200_MONITOR */
8661 /* Free the existing firmware and reset the fw_loaded
8662 * flag so ipw_load() will bring in the new firmawre */
8665 priv->ieee->iw_mode = wrqu->mode;
8667 queue_work(priv->workqueue, &priv->adapter_restart);
8668 mutex_unlock(&priv->mutex);
8672 static int ipw_wx_get_mode(struct net_device *dev,
8673 struct iw_request_info *info,
8674 union iwreq_data *wrqu, char *extra)
8676 struct ipw_priv *priv = ieee80211_priv(dev);
8677 mutex_lock(&priv->mutex);
8678 wrqu->mode = priv->ieee->iw_mode;
8679 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
8680 mutex_unlock(&priv->mutex);
8684 /* Values are in microsecond */
8685 static const s32 timeout_duration[] = {
8693 static const s32 period_duration[] = {
8701 static int ipw_wx_get_range(struct net_device *dev,
8702 struct iw_request_info *info,
8703 union iwreq_data *wrqu, char *extra)
8705 struct ipw_priv *priv = ieee80211_priv(dev);
8706 struct iw_range *range = (struct iw_range *)extra;
8707 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
8710 wrqu->data.length = sizeof(*range);
8711 memset(range, 0, sizeof(*range));
8713 /* 54Mbs == ~27 Mb/s real (802.11g) */
8714 range->throughput = 27 * 1000 * 1000;
8716 range->max_qual.qual = 100;
8717 /* TODO: Find real max RSSI and stick here */
8718 range->max_qual.level = 0;
8719 range->max_qual.noise = 0;
8720 range->max_qual.updated = 7; /* Updated all three */
8722 range->avg_qual.qual = 70;
8723 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
8724 range->avg_qual.level = 0; /* FIXME to real average level */
8725 range->avg_qual.noise = 0;
8726 range->avg_qual.updated = 7; /* Updated all three */
8727 mutex_lock(&priv->mutex);
8728 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
8730 for (i = 0; i < range->num_bitrates; i++)
8731 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
8734 range->max_rts = DEFAULT_RTS_THRESHOLD;
8735 range->min_frag = MIN_FRAG_THRESHOLD;
8736 range->max_frag = MAX_FRAG_THRESHOLD;
8738 range->encoding_size[0] = 5;
8739 range->encoding_size[1] = 13;
8740 range->num_encoding_sizes = 2;
8741 range->max_encoding_tokens = WEP_KEYS;
8743 /* Set the Wireless Extension versions */
8744 range->we_version_compiled = WIRELESS_EXT;
8745 range->we_version_source = 18;
8748 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
8749 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8750 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8751 (geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8754 range->freq[i].i = geo->bg[j].channel;
8755 range->freq[i].m = geo->bg[j].freq * 100000;
8756 range->freq[i].e = 1;
8761 if (priv->ieee->mode & IEEE_A) {
8762 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8763 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8764 (geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8767 range->freq[i].i = geo->a[j].channel;
8768 range->freq[i].m = geo->a[j].freq * 100000;
8769 range->freq[i].e = 1;
8774 range->num_channels = i;
8775 range->num_frequency = i;
8777 mutex_unlock(&priv->mutex);
8779 /* Event capability (kernel + driver) */
8780 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8781 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
8782 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
8783 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
8784 range->event_capa[1] = IW_EVENT_CAPA_K_1;
8786 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8787 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8789 IPW_DEBUG_WX("GET Range\n");
8793 static int ipw_wx_set_wap(struct net_device *dev,
8794 struct iw_request_info *info,
8795 union iwreq_data *wrqu, char *extra)
8797 struct ipw_priv *priv = ieee80211_priv(dev);
8799 static const unsigned char any[] = {
8800 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8802 static const unsigned char off[] = {
8803 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8806 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
8808 mutex_lock(&priv->mutex);
8809 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8810 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8811 /* we disable mandatory BSSID association */
8812 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8813 priv->config &= ~CFG_STATIC_BSSID;
8814 IPW_DEBUG_ASSOC("Attempting to associate with new "
8816 ipw_associate(priv);
8817 mutex_unlock(&priv->mutex);
8821 priv->config |= CFG_STATIC_BSSID;
8822 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8823 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
8824 mutex_unlock(&priv->mutex);
8828 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8829 MAC_ARG(wrqu->ap_addr.sa_data));
8831 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8833 /* Network configuration changed -- force [re]association */
8834 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8835 if (!ipw_disassociate(priv))
8836 ipw_associate(priv);
8838 mutex_unlock(&priv->mutex);
8842 static int ipw_wx_get_wap(struct net_device *dev,
8843 struct iw_request_info *info,
8844 union iwreq_data *wrqu, char *extra)
8846 struct ipw_priv *priv = ieee80211_priv(dev);
8847 /* If we are associated, trying to associate, or have a statically
8848 * configured BSSID then return that; otherwise return ANY */
8849 mutex_lock(&priv->mutex);
8850 if (priv->config & CFG_STATIC_BSSID ||
8851 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8852 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
8853 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
8855 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8857 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8858 MAC_ARG(wrqu->ap_addr.sa_data));
8859 mutex_unlock(&priv->mutex);
8863 static int ipw_wx_set_essid(struct net_device *dev,
8864 struct iw_request_info *info,
8865 union iwreq_data *wrqu, char *extra)
8867 struct ipw_priv *priv = ieee80211_priv(dev);
8868 char *essid = ""; /* ANY */
8870 mutex_lock(&priv->mutex);
8871 if (wrqu->essid.flags && wrqu->essid.length) {
8872 length = wrqu->essid.length - 1;
8876 IPW_DEBUG_WX("Setting ESSID to ANY\n");
8877 if ((priv->config & CFG_STATIC_ESSID) &&
8878 !(priv->status & (STATUS_ASSOCIATED |
8879 STATUS_ASSOCIATING))) {
8880 IPW_DEBUG_ASSOC("Attempting to associate with new "
8882 priv->config &= ~CFG_STATIC_ESSID;
8883 ipw_associate(priv);
8885 mutex_unlock(&priv->mutex);
8889 length = min(length, IW_ESSID_MAX_SIZE);
8891 priv->config |= CFG_STATIC_ESSID;
8893 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8894 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
8895 mutex_unlock(&priv->mutex);
8899 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8902 priv->essid_len = length;
8903 memcpy(priv->essid, essid, priv->essid_len);
8905 /* Network configuration changed -- force [re]association */
8906 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8907 if (!ipw_disassociate(priv))
8908 ipw_associate(priv);
8910 mutex_unlock(&priv->mutex);
8914 static int ipw_wx_get_essid(struct net_device *dev,
8915 struct iw_request_info *info,
8916 union iwreq_data *wrqu, char *extra)
8918 struct ipw_priv *priv = ieee80211_priv(dev);
8920 /* If we are associated, trying to associate, or have a statically
8921 * configured ESSID then return that; otherwise return ANY */
8922 mutex_lock(&priv->mutex);
8923 if (priv->config & CFG_STATIC_ESSID ||
8924 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8925 IPW_DEBUG_WX("Getting essid: '%s'\n",
8926 escape_essid(priv->essid, priv->essid_len));
8927 memcpy(extra, priv->essid, priv->essid_len);
8928 wrqu->essid.length = priv->essid_len;
8929 wrqu->essid.flags = 1; /* active */
8931 IPW_DEBUG_WX("Getting essid: ANY\n");
8932 wrqu->essid.length = 0;
8933 wrqu->essid.flags = 0; /* active */
8935 mutex_unlock(&priv->mutex);
8939 static int ipw_wx_set_nick(struct net_device *dev,
8940 struct iw_request_info *info,
8941 union iwreq_data *wrqu, char *extra)
8943 struct ipw_priv *priv = ieee80211_priv(dev);
8945 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8946 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8948 mutex_lock(&priv->mutex);
8949 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
8950 memset(priv->nick, 0, sizeof(priv->nick));
8951 memcpy(priv->nick, extra, wrqu->data.length);
8952 IPW_DEBUG_TRACE("<<\n");
8953 mutex_unlock(&priv->mutex);
8958 static int ipw_wx_get_nick(struct net_device *dev,
8959 struct iw_request_info *info,
8960 union iwreq_data *wrqu, char *extra)
8962 struct ipw_priv *priv = ieee80211_priv(dev);
8963 IPW_DEBUG_WX("Getting nick\n");
8964 mutex_lock(&priv->mutex);
8965 wrqu->data.length = strlen(priv->nick) + 1;
8966 memcpy(extra, priv->nick, wrqu->data.length);
8967 wrqu->data.flags = 1; /* active */
8968 mutex_unlock(&priv->mutex);
8972 static int ipw_wx_set_sens(struct net_device *dev,
8973 struct iw_request_info *info,
8974 union iwreq_data *wrqu, char *extra)
8976 struct ipw_priv *priv = ieee80211_priv(dev);
8979 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
8980 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
8981 mutex_lock(&priv->mutex);
8983 if (wrqu->sens.fixed == 0)
8985 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8986 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8989 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
8990 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
8995 priv->roaming_threshold = wrqu->sens.value;
8996 priv->disassociate_threshold = 3*wrqu->sens.value;
8998 mutex_unlock(&priv->mutex);
9002 static int ipw_wx_get_sens(struct net_device *dev,
9003 struct iw_request_info *info,
9004 union iwreq_data *wrqu, char *extra)
9006 struct ipw_priv *priv = ieee80211_priv(dev);
9007 mutex_lock(&priv->mutex);
9008 wrqu->sens.fixed = 1;
9009 wrqu->sens.value = priv->roaming_threshold;
9010 mutex_unlock(&priv->mutex);
9012 IPW_DEBUG_WX("GET roaming threshold -> %s %d \n",
9013 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9018 static int ipw_wx_set_rate(struct net_device *dev,
9019 struct iw_request_info *info,
9020 union iwreq_data *wrqu, char *extra)
9022 /* TODO: We should use semaphores or locks for access to priv */
9023 struct ipw_priv *priv = ieee80211_priv(dev);
9024 u32 target_rate = wrqu->bitrate.value;
9027 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
9028 /* value = X, fixed = 1 means only rate X */
9029 /* value = X, fixed = 0 means all rates lower equal X */
9031 if (target_rate == -1) {
9033 mask = IEEE80211_DEFAULT_RATES_MASK;
9034 /* Now we should reassociate */
9039 fixed = wrqu->bitrate.fixed;
9041 if (target_rate == 1000000 || !fixed)
9042 mask |= IEEE80211_CCK_RATE_1MB_MASK;
9043 if (target_rate == 1000000)
9046 if (target_rate == 2000000 || !fixed)
9047 mask |= IEEE80211_CCK_RATE_2MB_MASK;
9048 if (target_rate == 2000000)
9051 if (target_rate == 5500000 || !fixed)
9052 mask |= IEEE80211_CCK_RATE_5MB_MASK;
9053 if (target_rate == 5500000)
9056 if (target_rate == 6000000 || !fixed)
9057 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
9058 if (target_rate == 6000000)
9061 if (target_rate == 9000000 || !fixed)
9062 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
9063 if (target_rate == 9000000)
9066 if (target_rate == 11000000 || !fixed)
9067 mask |= IEEE80211_CCK_RATE_11MB_MASK;
9068 if (target_rate == 11000000)
9071 if (target_rate == 12000000 || !fixed)
9072 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
9073 if (target_rate == 12000000)
9076 if (target_rate == 18000000 || !fixed)
9077 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
9078 if (target_rate == 18000000)
9081 if (target_rate == 24000000 || !fixed)
9082 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
9083 if (target_rate == 24000000)
9086 if (target_rate == 36000000 || !fixed)
9087 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
9088 if (target_rate == 36000000)
9091 if (target_rate == 48000000 || !fixed)
9092 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
9093 if (target_rate == 48000000)
9096 if (target_rate == 54000000 || !fixed)
9097 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
9098 if (target_rate == 54000000)
9101 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9105 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9106 mask, fixed ? "fixed" : "sub-rates");
9107 mutex_lock(&priv->mutex);
9108 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
9109 priv->config &= ~CFG_FIXED_RATE;
9110 ipw_set_fixed_rate(priv, priv->ieee->mode);
9112 priv->config |= CFG_FIXED_RATE;
9114 if (priv->rates_mask == mask) {
9115 IPW_DEBUG_WX("Mask set to current mask.\n");
9116 mutex_unlock(&priv->mutex);
9120 priv->rates_mask = mask;
9122 /* Network configuration changed -- force [re]association */
9123 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9124 if (!ipw_disassociate(priv))
9125 ipw_associate(priv);
9127 mutex_unlock(&priv->mutex);
9131 static int ipw_wx_get_rate(struct net_device *dev,
9132 struct iw_request_info *info,
9133 union iwreq_data *wrqu, char *extra)
9135 struct ipw_priv *priv = ieee80211_priv(dev);
9136 mutex_lock(&priv->mutex);
9137 wrqu->bitrate.value = priv->last_rate;
9138 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
9139 mutex_unlock(&priv->mutex);
9140 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
9144 static int ipw_wx_set_rts(struct net_device *dev,
9145 struct iw_request_info *info,
9146 union iwreq_data *wrqu, char *extra)
9148 struct ipw_priv *priv = ieee80211_priv(dev);
9149 mutex_lock(&priv->mutex);
9150 if (wrqu->rts.disabled)
9151 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9153 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
9154 wrqu->rts.value > MAX_RTS_THRESHOLD) {
9155 mutex_unlock(&priv->mutex);
9158 priv->rts_threshold = wrqu->rts.value;
9161 ipw_send_rts_threshold(priv, priv->rts_threshold);
9162 mutex_unlock(&priv->mutex);
9163 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
9167 static int ipw_wx_get_rts(struct net_device *dev,
9168 struct iw_request_info *info,
9169 union iwreq_data *wrqu, char *extra)
9171 struct ipw_priv *priv = ieee80211_priv(dev);
9172 mutex_lock(&priv->mutex);
9173 wrqu->rts.value = priv->rts_threshold;
9174 wrqu->rts.fixed = 0; /* no auto select */
9175 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
9176 mutex_unlock(&priv->mutex);
9177 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
9181 static int ipw_wx_set_txpow(struct net_device *dev,
9182 struct iw_request_info *info,
9183 union iwreq_data *wrqu, char *extra)
9185 struct ipw_priv *priv = ieee80211_priv(dev);
9188 mutex_lock(&priv->mutex);
9189 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
9194 if (!wrqu->power.fixed)
9195 wrqu->power.value = IPW_TX_POWER_DEFAULT;
9197 if (wrqu->power.flags != IW_TXPOW_DBM) {
9202 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
9203 (wrqu->power.value < IPW_TX_POWER_MIN)) {
9208 priv->tx_power = wrqu->power.value;
9209 err = ipw_set_tx_power(priv);
9211 mutex_unlock(&priv->mutex);
9215 static int ipw_wx_get_txpow(struct net_device *dev,
9216 struct iw_request_info *info,
9217 union iwreq_data *wrqu, char *extra)
9219 struct ipw_priv *priv = ieee80211_priv(dev);
9220 mutex_lock(&priv->mutex);
9221 wrqu->power.value = priv->tx_power;
9222 wrqu->power.fixed = 1;
9223 wrqu->power.flags = IW_TXPOW_DBM;
9224 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
9225 mutex_unlock(&priv->mutex);
9227 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
9228 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9233 static int ipw_wx_set_frag(struct net_device *dev,
9234 struct iw_request_info *info,
9235 union iwreq_data *wrqu, char *extra)
9237 struct ipw_priv *priv = ieee80211_priv(dev);
9238 mutex_lock(&priv->mutex);
9239 if (wrqu->frag.disabled)
9240 priv->ieee->fts = DEFAULT_FTS;
9242 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
9243 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
9244 mutex_unlock(&priv->mutex);
9248 priv->ieee->fts = wrqu->frag.value & ~0x1;
9251 ipw_send_frag_threshold(priv, wrqu->frag.value);
9252 mutex_unlock(&priv->mutex);
9253 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
9257 static int ipw_wx_get_frag(struct net_device *dev,
9258 struct iw_request_info *info,
9259 union iwreq_data *wrqu, char *extra)
9261 struct ipw_priv *priv = ieee80211_priv(dev);
9262 mutex_lock(&priv->mutex);
9263 wrqu->frag.value = priv->ieee->fts;
9264 wrqu->frag.fixed = 0; /* no auto select */
9265 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
9266 mutex_unlock(&priv->mutex);
9267 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
9272 static int ipw_wx_set_retry(struct net_device *dev,
9273 struct iw_request_info *info,
9274 union iwreq_data *wrqu, char *extra)
9276 struct ipw_priv *priv = ieee80211_priv(dev);
9278 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9281 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9284 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
9287 mutex_lock(&priv->mutex);
9288 if (wrqu->retry.flags & IW_RETRY_MIN)
9289 priv->short_retry_limit = (u8) wrqu->retry.value;
9290 else if (wrqu->retry.flags & IW_RETRY_MAX)
9291 priv->long_retry_limit = (u8) wrqu->retry.value;
9293 priv->short_retry_limit = (u8) wrqu->retry.value;
9294 priv->long_retry_limit = (u8) wrqu->retry.value;
9297 ipw_send_retry_limit(priv, priv->short_retry_limit,
9298 priv->long_retry_limit);
9299 mutex_unlock(&priv->mutex);
9300 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9301 priv->short_retry_limit, priv->long_retry_limit);
9305 static int ipw_wx_get_retry(struct net_device *dev,
9306 struct iw_request_info *info,
9307 union iwreq_data *wrqu, char *extra)
9309 struct ipw_priv *priv = ieee80211_priv(dev);
9311 mutex_lock(&priv->mutex);
9312 wrqu->retry.disabled = 0;
9314 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
9315 mutex_unlock(&priv->mutex);
9319 if (wrqu->retry.flags & IW_RETRY_MAX) {
9320 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
9321 wrqu->retry.value = priv->long_retry_limit;
9322 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
9323 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
9324 wrqu->retry.value = priv->short_retry_limit;
9326 wrqu->retry.flags = IW_RETRY_LIMIT;
9327 wrqu->retry.value = priv->short_retry_limit;
9329 mutex_unlock(&priv->mutex);
9331 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9336 static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
9339 struct ipw_scan_request_ext scan;
9340 int err = 0, scan_type;
9342 if (!(priv->status & STATUS_INIT) ||
9343 (priv->status & STATUS_EXIT_PENDING))
9346 mutex_lock(&priv->mutex);
9348 if (priv->status & STATUS_RF_KILL_MASK) {
9349 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
9350 priv->status |= STATUS_SCAN_PENDING;
9354 IPW_DEBUG_HC("starting request direct scan!\n");
9356 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
9357 /* We should not sleep here; otherwise we will block most
9358 * of the system (for instance, we hold rtnl_lock when we
9364 memset(&scan, 0, sizeof(scan));
9366 if (priv->config & CFG_SPEED_SCAN)
9367 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9370 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9373 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
9375 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
9376 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
9378 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
9380 err = ipw_send_ssid(priv, essid, essid_len);
9382 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
9385 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
9387 ipw_add_scan_channels(priv, &scan, scan_type);
9389 err = ipw_send_scan_request_ext(priv, &scan);
9391 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
9395 priv->status |= STATUS_SCANNING;
9398 mutex_unlock(&priv->mutex);
9402 static int ipw_wx_set_scan(struct net_device *dev,
9403 struct iw_request_info *info,
9404 union iwreq_data *wrqu, char *extra)
9406 struct ipw_priv *priv = ieee80211_priv(dev);
9407 struct iw_scan_req *req = NULL;
9408 if (wrqu->data.length
9409 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9410 req = (struct iw_scan_req *)extra;
9411 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9412 ipw_request_direct_scan(priv, req->essid,
9418 IPW_DEBUG_WX("Start scan\n");
9420 queue_work(priv->workqueue, &priv->request_scan);
9425 static int ipw_wx_get_scan(struct net_device *dev,
9426 struct iw_request_info *info,
9427 union iwreq_data *wrqu, char *extra)
9429 struct ipw_priv *priv = ieee80211_priv(dev);
9430 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9433 static int ipw_wx_set_encode(struct net_device *dev,
9434 struct iw_request_info *info,
9435 union iwreq_data *wrqu, char *key)
9437 struct ipw_priv *priv = ieee80211_priv(dev);
9439 u32 cap = priv->capability;
9441 mutex_lock(&priv->mutex);
9442 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
9444 /* In IBSS mode, we need to notify the firmware to update
9445 * the beacon info after we changed the capability. */
9446 if (cap != priv->capability &&
9447 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9448 priv->status & STATUS_ASSOCIATED)
9449 ipw_disassociate(priv);
9451 mutex_unlock(&priv->mutex);
9455 static int ipw_wx_get_encode(struct net_device *dev,
9456 struct iw_request_info *info,
9457 union iwreq_data *wrqu, char *key)
9459 struct ipw_priv *priv = ieee80211_priv(dev);
9460 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9463 static int ipw_wx_set_power(struct net_device *dev,
9464 struct iw_request_info *info,
9465 union iwreq_data *wrqu, char *extra)
9467 struct ipw_priv *priv = ieee80211_priv(dev);
9469 mutex_lock(&priv->mutex);
9470 if (wrqu->power.disabled) {
9471 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9472 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9474 IPW_DEBUG_WX("failed setting power mode.\n");
9475 mutex_unlock(&priv->mutex);
9478 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
9479 mutex_unlock(&priv->mutex);
9483 switch (wrqu->power.flags & IW_POWER_MODE) {
9484 case IW_POWER_ON: /* If not specified */
9485 case IW_POWER_MODE: /* If set all mask */
9486 case IW_POWER_ALL_R: /* If explicitely state all */
9488 default: /* Otherwise we don't support it */
9489 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9491 mutex_unlock(&priv->mutex);
9495 /* If the user hasn't specified a power management mode yet, default
9497 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
9498 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
9500 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9501 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9503 IPW_DEBUG_WX("failed setting power mode.\n");
9504 mutex_unlock(&priv->mutex);
9508 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
9509 mutex_unlock(&priv->mutex);
9513 static int ipw_wx_get_power(struct net_device *dev,
9514 struct iw_request_info *info,
9515 union iwreq_data *wrqu, char *extra)
9517 struct ipw_priv *priv = ieee80211_priv(dev);
9518 mutex_lock(&priv->mutex);
9519 if (!(priv->power_mode & IPW_POWER_ENABLED))
9520 wrqu->power.disabled = 1;
9522 wrqu->power.disabled = 0;
9524 mutex_unlock(&priv->mutex);
9525 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
9530 static int ipw_wx_set_powermode(struct net_device *dev,
9531 struct iw_request_info *info,
9532 union iwreq_data *wrqu, char *extra)
9534 struct ipw_priv *priv = ieee80211_priv(dev);
9535 int mode = *(int *)extra;
9537 mutex_lock(&priv->mutex);
9538 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9539 mode = IPW_POWER_AC;
9540 priv->power_mode = mode;
9542 priv->power_mode = IPW_POWER_ENABLED | mode;
9545 if (priv->power_mode != mode) {
9546 err = ipw_send_power_mode(priv, mode);
9549 IPW_DEBUG_WX("failed setting power mode.\n");
9550 mutex_unlock(&priv->mutex);
9554 mutex_unlock(&priv->mutex);
9558 #define MAX_WX_STRING 80
9559 static int ipw_wx_get_powermode(struct net_device *dev,
9560 struct iw_request_info *info,
9561 union iwreq_data *wrqu, char *extra)
9563 struct ipw_priv *priv = ieee80211_priv(dev);
9564 int level = IPW_POWER_LEVEL(priv->power_mode);
9567 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9571 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9573 case IPW_POWER_BATTERY:
9574 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9577 p += snprintf(p, MAX_WX_STRING - (p - extra),
9578 "(Timeout %dms, Period %dms)",
9579 timeout_duration[level - 1] / 1000,
9580 period_duration[level - 1] / 1000);
9583 if (!(priv->power_mode & IPW_POWER_ENABLED))
9584 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
9586 wrqu->data.length = p - extra + 1;
9591 static int ipw_wx_set_wireless_mode(struct net_device *dev,
9592 struct iw_request_info *info,
9593 union iwreq_data *wrqu, char *extra)
9595 struct ipw_priv *priv = ieee80211_priv(dev);
9596 int mode = *(int *)extra;
9597 u8 band = 0, modulation = 0;
9599 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
9600 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
9603 mutex_lock(&priv->mutex);
9604 if (priv->adapter == IPW_2915ABG) {
9605 priv->ieee->abg_true = 1;
9606 if (mode & IEEE_A) {
9607 band |= IEEE80211_52GHZ_BAND;
9608 modulation |= IEEE80211_OFDM_MODULATION;
9610 priv->ieee->abg_true = 0;
9612 if (mode & IEEE_A) {
9613 IPW_WARNING("Attempt to set 2200BG into "
9615 mutex_unlock(&priv->mutex);
9619 priv->ieee->abg_true = 0;
9622 if (mode & IEEE_B) {
9623 band |= IEEE80211_24GHZ_BAND;
9624 modulation |= IEEE80211_CCK_MODULATION;
9626 priv->ieee->abg_true = 0;
9628 if (mode & IEEE_G) {
9629 band |= IEEE80211_24GHZ_BAND;
9630 modulation |= IEEE80211_OFDM_MODULATION;
9632 priv->ieee->abg_true = 0;
9634 priv->ieee->mode = mode;
9635 priv->ieee->freq_band = band;
9636 priv->ieee->modulation = modulation;
9637 init_supported_rates(priv, &priv->rates);
9639 /* Network configuration changed -- force [re]association */
9640 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9641 if (!ipw_disassociate(priv)) {
9642 ipw_send_supported_rates(priv, &priv->rates);
9643 ipw_associate(priv);
9646 /* Update the band LEDs */
9647 ipw_led_band_on(priv);
9649 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
9650 mode & IEEE_A ? 'a' : '.',
9651 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
9652 mutex_unlock(&priv->mutex);
9656 static int ipw_wx_get_wireless_mode(struct net_device *dev,
9657 struct iw_request_info *info,
9658 union iwreq_data *wrqu, char *extra)
9660 struct ipw_priv *priv = ieee80211_priv(dev);
9661 mutex_lock(&priv->mutex);
9662 switch (priv->ieee->mode) {
9664 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9667 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9669 case IEEE_A | IEEE_B:
9670 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9673 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9675 case IEEE_A | IEEE_G:
9676 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9678 case IEEE_B | IEEE_G:
9679 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9681 case IEEE_A | IEEE_B | IEEE_G:
9682 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9685 strncpy(extra, "unknown", MAX_WX_STRING);
9689 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9691 wrqu->data.length = strlen(extra) + 1;
9692 mutex_unlock(&priv->mutex);
9697 static int ipw_wx_set_preamble(struct net_device *dev,
9698 struct iw_request_info *info,
9699 union iwreq_data *wrqu, char *extra)
9701 struct ipw_priv *priv = ieee80211_priv(dev);
9702 int mode = *(int *)extra;
9703 mutex_lock(&priv->mutex);
9704 /* Switching from SHORT -> LONG requires a disassociation */
9706 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9707 priv->config |= CFG_PREAMBLE_LONG;
9709 /* Network configuration changed -- force [re]association */
9711 ("[re]association triggered due to preamble change.\n");
9712 if (!ipw_disassociate(priv))
9713 ipw_associate(priv);
9719 priv->config &= ~CFG_PREAMBLE_LONG;
9722 mutex_unlock(&priv->mutex);
9726 mutex_unlock(&priv->mutex);
9730 static int ipw_wx_get_preamble(struct net_device *dev,
9731 struct iw_request_info *info,
9732 union iwreq_data *wrqu, char *extra)
9734 struct ipw_priv *priv = ieee80211_priv(dev);
9735 mutex_lock(&priv->mutex);
9736 if (priv->config & CFG_PREAMBLE_LONG)
9737 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9739 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
9740 mutex_unlock(&priv->mutex);
9744 #ifdef CONFIG_IPW2200_MONITOR
9745 static int ipw_wx_set_monitor(struct net_device *dev,
9746 struct iw_request_info *info,
9747 union iwreq_data *wrqu, char *extra)
9749 struct ipw_priv *priv = ieee80211_priv(dev);
9750 int *parms = (int *)extra;
9751 int enable = (parms[0] > 0);
9752 mutex_lock(&priv->mutex);
9753 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
9755 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9756 #ifdef CONFIG_IPW2200_RADIOTAP
9757 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9759 priv->net_dev->type = ARPHRD_IEEE80211;
9761 queue_work(priv->workqueue, &priv->adapter_restart);
9764 ipw_set_channel(priv, parms[1]);
9766 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9767 mutex_unlock(&priv->mutex);
9770 priv->net_dev->type = ARPHRD_ETHER;
9771 queue_work(priv->workqueue, &priv->adapter_restart);
9773 mutex_unlock(&priv->mutex);
9777 #endif // CONFIG_IPW2200_MONITOR
9779 static int ipw_wx_reset(struct net_device *dev,
9780 struct iw_request_info *info,
9781 union iwreq_data *wrqu, char *extra)
9783 struct ipw_priv *priv = ieee80211_priv(dev);
9784 IPW_DEBUG_WX("RESET\n");
9785 queue_work(priv->workqueue, &priv->adapter_restart);
9789 static int ipw_wx_sw_reset(struct net_device *dev,
9790 struct iw_request_info *info,
9791 union iwreq_data *wrqu, char *extra)
9793 struct ipw_priv *priv = ieee80211_priv(dev);
9794 union iwreq_data wrqu_sec = {
9796 .flags = IW_ENCODE_DISABLED,
9801 IPW_DEBUG_WX("SW_RESET\n");
9803 mutex_lock(&priv->mutex);
9805 ret = ipw_sw_reset(priv, 2);
9808 ipw_adapter_restart(priv);
9811 /* The SW reset bit might have been toggled on by the 'disable'
9812 * module parameter, so take appropriate action */
9813 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9815 mutex_unlock(&priv->mutex);
9816 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
9817 mutex_lock(&priv->mutex);
9819 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9820 /* Configuration likely changed -- force [re]association */
9821 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9823 if (!ipw_disassociate(priv))
9824 ipw_associate(priv);
9827 mutex_unlock(&priv->mutex);
9832 /* Rebase the WE IOCTLs to zero for the handler array */
9833 #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
9834 static iw_handler ipw_wx_handlers[] = {
9835 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9836 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9837 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9838 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9839 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
9840 IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens,
9841 IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens,
9842 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9843 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9844 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9845 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9846 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9847 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9848 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9849 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9850 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9851 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9852 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9853 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9854 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9855 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9856 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9857 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9858 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9859 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9860 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9861 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9862 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9863 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9864 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
9865 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9866 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9867 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9868 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
9869 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9870 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9871 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9872 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9873 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9874 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9875 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
9879 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9883 IPW_PRIV_SET_PREAMBLE,
9884 IPW_PRIV_GET_PREAMBLE,
9887 #ifdef CONFIG_IPW2200_MONITOR
9888 IPW_PRIV_SET_MONITOR,
9892 static struct iw_priv_args ipw_priv_args[] = {
9894 .cmd = IPW_PRIV_SET_POWER,
9895 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9896 .name = "set_power"},
9898 .cmd = IPW_PRIV_GET_POWER,
9899 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9900 .name = "get_power"},
9902 .cmd = IPW_PRIV_SET_MODE,
9903 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9904 .name = "set_mode"},
9906 .cmd = IPW_PRIV_GET_MODE,
9907 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9908 .name = "get_mode"},
9910 .cmd = IPW_PRIV_SET_PREAMBLE,
9911 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9912 .name = "set_preamble"},
9914 .cmd = IPW_PRIV_GET_PREAMBLE,
9915 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9916 .name = "get_preamble"},
9919 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
9922 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9923 #ifdef CONFIG_IPW2200_MONITOR
9925 IPW_PRIV_SET_MONITOR,
9926 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9927 #endif /* CONFIG_IPW2200_MONITOR */
9930 static iw_handler ipw_priv_handler[] = {
9931 ipw_wx_set_powermode,
9932 ipw_wx_get_powermode,
9933 ipw_wx_set_wireless_mode,
9934 ipw_wx_get_wireless_mode,
9935 ipw_wx_set_preamble,
9936 ipw_wx_get_preamble,
9939 #ifdef CONFIG_IPW2200_MONITOR
9944 static struct iw_handler_def ipw_wx_handler_def = {
9945 .standard = ipw_wx_handlers,
9946 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9947 .num_private = ARRAY_SIZE(ipw_priv_handler),
9948 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9949 .private = ipw_priv_handler,
9950 .private_args = ipw_priv_args,
9951 .get_wireless_stats = ipw_get_wireless_stats,
9955 * Get wireless statistics.
9956 * Called by /proc/net/wireless
9957 * Also called by SIOCGIWSTATS
9959 static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
9961 struct ipw_priv *priv = ieee80211_priv(dev);
9962 struct iw_statistics *wstats;
9964 wstats = &priv->wstats;
9966 /* if hw is disabled, then ipw_get_ordinal() can't be called.
9967 * netdev->get_wireless_stats seems to be called before fw is
9968 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9969 * and associated; if not associcated, the values are all meaningless
9970 * anyway, so set them all to NULL and INVALID */
9971 if (!(priv->status & STATUS_ASSOCIATED)) {
9972 wstats->miss.beacon = 0;
9973 wstats->discard.retries = 0;
9974 wstats->qual.qual = 0;
9975 wstats->qual.level = 0;
9976 wstats->qual.noise = 0;
9977 wstats->qual.updated = 7;
9978 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
9979 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
9983 wstats->qual.qual = priv->quality;
9984 wstats->qual.level = priv->exp_avg_rssi;
9985 wstats->qual.noise = priv->exp_avg_noise;
9986 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
9987 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
9989 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9990 wstats->discard.retries = priv->last_tx_failures;
9991 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
9993 /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9994 goto fail_get_ordinal;
9995 wstats->discard.retries += tx_retry; */
10000 /* net device stuff */
10002 static void init_sys_config(struct ipw_sys_config *sys_config)
10004 memset(sys_config, 0, sizeof(struct ipw_sys_config));
10005 sys_config->bt_coexistence = 0;
10006 sys_config->answer_broadcast_ssid_probe = 0;
10007 sys_config->accept_all_data_frames = 0;
10008 sys_config->accept_non_directed_frames = 1;
10009 sys_config->exclude_unicast_unencrypted = 0;
10010 sys_config->disable_unicast_decryption = 1;
10011 sys_config->exclude_multicast_unencrypted = 0;
10012 sys_config->disable_multicast_decryption = 1;
10013 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
10014 antenna = CFG_SYS_ANTENNA_BOTH;
10015 sys_config->antenna_diversity = antenna;
10016 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
10017 sys_config->dot11g_auto_detection = 0;
10018 sys_config->enable_cts_to_self = 0;
10019 sys_config->bt_coexist_collision_thr = 0;
10020 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
10021 sys_config->silence_threshold = 0x1e;
10024 static int ipw_net_open(struct net_device *dev)
10026 struct ipw_priv *priv = ieee80211_priv(dev);
10027 IPW_DEBUG_INFO("dev->open\n");
10028 /* we should be verifying the device is ready to be opened */
10029 mutex_lock(&priv->mutex);
10030 if (!(priv->status & STATUS_RF_KILL_MASK) &&
10031 (priv->status & STATUS_ASSOCIATED))
10032 netif_start_queue(dev);
10033 mutex_unlock(&priv->mutex);
10037 static int ipw_net_stop(struct net_device *dev)
10039 IPW_DEBUG_INFO("dev->close\n");
10040 netif_stop_queue(dev);
10047 modify to send one tfd per fragment instead of using chunking. otherwise
10048 we need to heavily modify the ieee80211_skb_to_txb.
10051 static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
10054 struct ieee80211_hdr_3addrqos *hdr = (struct ieee80211_hdr_3addrqos *)
10055 txb->fragments[0]->data;
10057 struct tfd_frame *tfd;
10058 #ifdef CONFIG_IPW2200_QOS
10059 int tx_id = ipw_get_tx_queue_number(priv, pri);
10060 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10062 struct clx2_tx_queue *txq = &priv->txq[0];
10064 struct clx2_queue *q = &txq->q;
10065 u8 id, hdr_len, unicast;
10066 u16 remaining_bytes;
10069 hdr_len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
10070 switch (priv->ieee->iw_mode) {
10071 case IW_MODE_ADHOC:
10072 unicast = !is_multicast_ether_addr(hdr->addr1);
10073 id = ipw_find_station(priv, hdr->addr1);
10074 if (id == IPW_INVALID_STATION) {
10075 id = ipw_add_station(priv, hdr->addr1);
10076 if (id == IPW_INVALID_STATION) {
10077 IPW_WARNING("Attempt to send data to "
10078 "invalid cell: " MAC_FMT "\n",
10079 MAC_ARG(hdr->addr1));
10085 case IW_MODE_INFRA:
10087 unicast = !is_multicast_ether_addr(hdr->addr3);
10092 tfd = &txq->bd[q->first_empty];
10093 txq->txb[q->first_empty] = txb;
10094 memset(tfd, 0, sizeof(*tfd));
10095 tfd->u.data.station_number = id;
10097 tfd->control_flags.message_type = TX_FRAME_TYPE;
10098 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10100 tfd->u.data.cmd_id = DINO_CMD_TX;
10101 tfd->u.data.len = cpu_to_le16(txb->payload_size);
10102 remaining_bytes = txb->payload_size;
10104 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
10105 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
10107 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
10109 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10110 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
10112 fc = le16_to_cpu(hdr->frame_ctl);
10113 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
10115 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10117 if (likely(unicast))
10118 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10120 if (txb->encrypted && !priv->ieee->host_encrypt) {
10121 switch (priv->ieee->sec.level) {
10123 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10124 IEEE80211_FCTL_PROTECTED;
10125 /* XXX: ACK flag must be set for CCMP even if it
10126 * is a multicast/broadcast packet, because CCMP
10127 * group communication encrypted by GTK is
10128 * actually done by the AP. */
10130 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10132 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10133 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10134 tfd->u.data.key_index = 0;
10135 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10138 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10139 IEEE80211_FCTL_PROTECTED;
10140 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10141 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10142 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10145 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10146 IEEE80211_FCTL_PROTECTED;
10147 tfd->u.data.key_index = priv->ieee->tx_keyidx;
10148 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
10150 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10152 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10157 printk(KERN_ERR "Unknow security level %d\n",
10158 priv->ieee->sec.level);
10162 /* No hardware encryption */
10163 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10165 #ifdef CONFIG_IPW2200_QOS
10166 if (fc & IEEE80211_STYPE_QOS_DATA)
10167 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
10168 #endif /* CONFIG_IPW2200_QOS */
10171 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10173 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10174 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10175 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10176 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10177 i, le32_to_cpu(tfd->u.data.num_chunks),
10178 txb->fragments[i]->len - hdr_len);
10179 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
10180 i, tfd->u.data.num_chunks,
10181 txb->fragments[i]->len - hdr_len);
10182 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
10183 txb->fragments[i]->len - hdr_len);
10185 tfd->u.data.chunk_ptr[i] =
10186 cpu_to_le32(pci_map_single
10188 txb->fragments[i]->data + hdr_len,
10189 txb->fragments[i]->len - hdr_len,
10190 PCI_DMA_TODEVICE));
10191 tfd->u.data.chunk_len[i] =
10192 cpu_to_le16(txb->fragments[i]->len - hdr_len);
10195 if (i != txb->nr_frags) {
10196 struct sk_buff *skb;
10197 u16 remaining_bytes = 0;
10200 for (j = i; j < txb->nr_frags; j++)
10201 remaining_bytes += txb->fragments[j]->len - hdr_len;
10203 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10205 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10207 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
10208 for (j = i; j < txb->nr_frags; j++) {
10209 int size = txb->fragments[j]->len - hdr_len;
10211 printk(KERN_INFO "Adding frag %d %d...\n",
10213 memcpy(skb_put(skb, size),
10214 txb->fragments[j]->data + hdr_len, size);
10216 dev_kfree_skb_any(txb->fragments[i]);
10217 txb->fragments[i] = skb;
10218 tfd->u.data.chunk_ptr[i] =
10219 cpu_to_le32(pci_map_single
10220 (priv->pci_dev, skb->data,
10221 tfd->u.data.chunk_len[i],
10222 PCI_DMA_TODEVICE));
10224 tfd->u.data.num_chunks =
10225 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
10231 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10232 ipw_write32(priv, q->reg_w, q->first_empty);
10234 if (ipw_queue_space(q) < q->high_mark)
10235 netif_stop_queue(priv->net_dev);
10237 return NETDEV_TX_OK;
10240 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
10241 ieee80211_txb_free(txb);
10242 return NETDEV_TX_OK;
10245 static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10247 struct ipw_priv *priv = ieee80211_priv(dev);
10248 #ifdef CONFIG_IPW2200_QOS
10249 int tx_id = ipw_get_tx_queue_number(priv, pri);
10250 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10252 struct clx2_tx_queue *txq = &priv->txq[0];
10253 #endif /* CONFIG_IPW2200_QOS */
10255 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
10261 #ifdef CONFIG_IPW2200_PROMISCUOUS
10262 static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
10263 struct ieee80211_txb *txb)
10265 struct ieee80211_rx_stats dummystats;
10266 struct ieee80211_hdr *hdr;
10268 u16 filter = priv->prom_priv->filter;
10271 if (filter & IPW_PROM_NO_TX)
10274 memset(&dummystats, 0, sizeof(dummystats));
10276 /* Filtering of fragment chains is done agains the first fragment */
10277 hdr = (void *)txb->fragments[0]->data;
10278 if (ieee80211_is_management(hdr->frame_ctl)) {
10279 if (filter & IPW_PROM_NO_MGMT)
10281 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10283 } else if (ieee80211_is_control(hdr->frame_ctl)) {
10284 if (filter & IPW_PROM_NO_CTL)
10286 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10288 } else if (ieee80211_is_data(hdr->frame_ctl)) {
10289 if (filter & IPW_PROM_NO_DATA)
10291 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10295 for(n=0; n<txb->nr_frags; ++n) {
10296 struct sk_buff *src = txb->fragments[n];
10297 struct sk_buff *dst;
10298 struct ieee80211_radiotap_header *rt_hdr;
10302 hdr = (void *)src->data;
10303 len = ieee80211_get_hdrlen(hdr->frame_ctl);
10308 len + IEEE80211_RADIOTAP_HDRLEN, GFP_ATOMIC);
10309 if (!dst) continue;
10311 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10313 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10314 rt_hdr->it_pad = 0;
10315 rt_hdr->it_present = 0; /* after all, it's just an idea */
10316 rt_hdr->it_present |= (1 << IEEE80211_RADIOTAP_CHANNEL);
10318 *(u16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
10319 ieee80211chan2mhz(priv->channel));
10320 if (priv->channel > 14) /* 802.11a */
10321 *(u16*)skb_put(dst, sizeof(u16)) =
10322 cpu_to_le16(IEEE80211_CHAN_OFDM |
10323 IEEE80211_CHAN_5GHZ);
10324 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
10325 *(u16*)skb_put(dst, sizeof(u16)) =
10326 cpu_to_le16(IEEE80211_CHAN_CCK |
10327 IEEE80211_CHAN_2GHZ);
10329 *(u16*)skb_put(dst, sizeof(u16)) =
10330 cpu_to_le16(IEEE80211_CHAN_OFDM |
10331 IEEE80211_CHAN_2GHZ);
10333 rt_hdr->it_len = dst->len;
10335 memcpy(skb_put(dst, len), src->data, len);
10337 if (!ieee80211_rx(priv->prom_priv->ieee, dst, &dummystats))
10338 dev_kfree_skb_any(dst);
10343 static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
10344 struct net_device *dev, int pri)
10346 struct ipw_priv *priv = ieee80211_priv(dev);
10347 unsigned long flags;
10350 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
10351 spin_lock_irqsave(&priv->lock, flags);
10353 if (!(priv->status & STATUS_ASSOCIATED)) {
10354 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
10355 priv->ieee->stats.tx_carrier_errors++;
10356 netif_stop_queue(dev);
10360 #ifdef CONFIG_IPW2200_PROMISCUOUS
10361 if (rtap_iface && netif_running(priv->prom_net_dev))
10362 ipw_handle_promiscuous_tx(priv, txb);
10365 ret = ipw_tx_skb(priv, txb, pri);
10366 if (ret == NETDEV_TX_OK)
10367 __ipw_led_activity_on(priv);
10368 spin_unlock_irqrestore(&priv->lock, flags);
10373 spin_unlock_irqrestore(&priv->lock, flags);
10377 static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
10379 struct ipw_priv *priv = ieee80211_priv(dev);
10381 priv->ieee->stats.tx_packets = priv->tx_packets;
10382 priv->ieee->stats.rx_packets = priv->rx_packets;
10383 return &priv->ieee->stats;
10386 static void ipw_net_set_multicast_list(struct net_device *dev)
10391 static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10393 struct ipw_priv *priv = ieee80211_priv(dev);
10394 struct sockaddr *addr = p;
10395 if (!is_valid_ether_addr(addr->sa_data))
10396 return -EADDRNOTAVAIL;
10397 mutex_lock(&priv->mutex);
10398 priv->config |= CFG_CUSTOM_MAC;
10399 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
10400 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
10401 priv->net_dev->name, MAC_ARG(priv->mac_addr));
10402 queue_work(priv->workqueue, &priv->adapter_restart);
10403 mutex_unlock(&priv->mutex);
10407 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
10408 struct ethtool_drvinfo *info)
10410 struct ipw_priv *p = ieee80211_priv(dev);
10415 strcpy(info->driver, DRV_NAME);
10416 strcpy(info->version, DRV_VERSION);
10418 len = sizeof(vers);
10419 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10420 len = sizeof(date);
10421 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10423 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
10425 strcpy(info->bus_info, pci_name(p->pci_dev));
10426 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
10429 static u32 ipw_ethtool_get_link(struct net_device *dev)
10431 struct ipw_priv *priv = ieee80211_priv(dev);
10432 return (priv->status & STATUS_ASSOCIATED) != 0;
10435 static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10437 return IPW_EEPROM_IMAGE_SIZE;
10440 static int ipw_ethtool_get_eeprom(struct net_device *dev,
10441 struct ethtool_eeprom *eeprom, u8 * bytes)
10443 struct ipw_priv *p = ieee80211_priv(dev);
10445 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
10447 mutex_lock(&p->mutex);
10448 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
10449 mutex_unlock(&p->mutex);
10453 static int ipw_ethtool_set_eeprom(struct net_device *dev,
10454 struct ethtool_eeprom *eeprom, u8 * bytes)
10456 struct ipw_priv *p = ieee80211_priv(dev);
10459 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
10461 mutex_lock(&p->mutex);
10462 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
10463 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10464 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
10465 mutex_unlock(&p->mutex);
10469 static struct ethtool_ops ipw_ethtool_ops = {
10470 .get_link = ipw_ethtool_get_link,
10471 .get_drvinfo = ipw_ethtool_get_drvinfo,
10472 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10473 .get_eeprom = ipw_ethtool_get_eeprom,
10474 .set_eeprom = ipw_ethtool_set_eeprom,
10477 static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
10479 struct ipw_priv *priv = data;
10480 u32 inta, inta_mask;
10485 spin_lock(&priv->irq_lock);
10487 if (!(priv->status & STATUS_INT_ENABLED)) {
10492 inta = ipw_read32(priv, IPW_INTA_RW);
10493 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
10495 if (inta == 0xFFFFFFFF) {
10496 /* Hardware disappeared */
10497 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10501 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
10502 /* Shared interrupt */
10506 /* tell the device to stop sending interrupts */
10507 __ipw_disable_interrupts(priv);
10509 /* ack current interrupts */
10510 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10511 ipw_write32(priv, IPW_INTA_RW, inta);
10513 /* Cache INTA value for our tasklet */
10514 priv->isr_inta = inta;
10516 tasklet_schedule(&priv->irq_tasklet);
10518 spin_unlock(&priv->irq_lock);
10520 return IRQ_HANDLED;
10522 spin_unlock(&priv->irq_lock);
10526 static void ipw_rf_kill(void *adapter)
10528 struct ipw_priv *priv = adapter;
10529 unsigned long flags;
10531 spin_lock_irqsave(&priv->lock, flags);
10533 if (rf_kill_active(priv)) {
10534 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10535 if (priv->workqueue)
10536 queue_delayed_work(priv->workqueue,
10537 &priv->rf_kill, 2 * HZ);
10541 /* RF Kill is now disabled, so bring the device back up */
10543 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10544 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10547 /* we can not do an adapter restart while inside an irq lock */
10548 queue_work(priv->workqueue, &priv->adapter_restart);
10550 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10554 spin_unlock_irqrestore(&priv->lock, flags);
10557 static void ipw_bg_rf_kill(void *data)
10559 struct ipw_priv *priv = data;
10560 mutex_lock(&priv->mutex);
10562 mutex_unlock(&priv->mutex);
10565 static void ipw_link_up(struct ipw_priv *priv)
10567 priv->last_seq_num = -1;
10568 priv->last_frag_num = -1;
10569 priv->last_packet_time = 0;
10571 netif_carrier_on(priv->net_dev);
10572 if (netif_queue_stopped(priv->net_dev)) {
10573 IPW_DEBUG_NOTIF("waking queue\n");
10574 netif_wake_queue(priv->net_dev);
10576 IPW_DEBUG_NOTIF("starting queue\n");
10577 netif_start_queue(priv->net_dev);
10580 cancel_delayed_work(&priv->request_scan);
10581 ipw_reset_stats(priv);
10582 /* Ensure the rate is updated immediately */
10583 priv->last_rate = ipw_get_current_rate(priv);
10584 ipw_gather_stats(priv);
10585 ipw_led_link_up(priv);
10586 notify_wx_assoc_event(priv);
10588 if (priv->config & CFG_BACKGROUND_SCAN)
10589 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10592 static void ipw_bg_link_up(void *data)
10594 struct ipw_priv *priv = data;
10595 mutex_lock(&priv->mutex);
10597 mutex_unlock(&priv->mutex);
10600 static void ipw_link_down(struct ipw_priv *priv)
10602 ipw_led_link_down(priv);
10603 netif_carrier_off(priv->net_dev);
10604 netif_stop_queue(priv->net_dev);
10605 notify_wx_assoc_event(priv);
10607 /* Cancel any queued work ... */
10608 cancel_delayed_work(&priv->request_scan);
10609 cancel_delayed_work(&priv->adhoc_check);
10610 cancel_delayed_work(&priv->gather_stats);
10612 ipw_reset_stats(priv);
10614 if (!(priv->status & STATUS_EXIT_PENDING)) {
10615 /* Queue up another scan... */
10616 queue_work(priv->workqueue, &priv->request_scan);
10620 static void ipw_bg_link_down(void *data)
10622 struct ipw_priv *priv = data;
10623 mutex_lock(&priv->mutex);
10624 ipw_link_down(data);
10625 mutex_unlock(&priv->mutex);
10628 static int ipw_setup_deferred_work(struct ipw_priv *priv)
10632 priv->workqueue = create_workqueue(DRV_NAME);
10633 init_waitqueue_head(&priv->wait_command_queue);
10634 init_waitqueue_head(&priv->wait_state);
10636 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10637 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10638 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
10639 INIT_WORK(&priv->system_config, ipw_system_config, priv);
10640 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10641 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10642 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10643 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10644 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
10645 INIT_WORK(&priv->request_scan,
10646 (void (*)(void *))ipw_request_scan, priv);
10647 INIT_WORK(&priv->gather_stats,
10648 (void (*)(void *))ipw_bg_gather_stats, priv);
10649 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10650 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10651 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10652 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10653 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10654 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
10656 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
10658 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10660 INIT_WORK(&priv->merge_networks,
10661 (void (*)(void *))ipw_merge_adhoc_network, priv);
10663 #ifdef CONFIG_IPW2200_QOS
10664 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10666 #endif /* CONFIG_IPW2200_QOS */
10668 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10669 ipw_irq_tasklet, (unsigned long)priv);
10674 static void shim__set_security(struct net_device *dev,
10675 struct ieee80211_security *sec)
10677 struct ipw_priv *priv = ieee80211_priv(dev);
10679 for (i = 0; i < 4; i++) {
10680 if (sec->flags & (1 << i)) {
10681 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
10682 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
10683 if (sec->key_sizes[i] == 0)
10684 priv->ieee->sec.flags &= ~(1 << i);
10686 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
10687 sec->key_sizes[i]);
10688 priv->ieee->sec.flags |= (1 << i);
10690 priv->status |= STATUS_SECURITY_UPDATED;
10691 } else if (sec->level != SEC_LEVEL_1)
10692 priv->ieee->sec.flags &= ~(1 << i);
10695 if (sec->flags & SEC_ACTIVE_KEY) {
10696 if (sec->active_key <= 3) {
10697 priv->ieee->sec.active_key = sec->active_key;
10698 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
10700 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
10701 priv->status |= STATUS_SECURITY_UPDATED;
10703 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
10705 if ((sec->flags & SEC_AUTH_MODE) &&
10706 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10707 priv->ieee->sec.auth_mode = sec->auth_mode;
10708 priv->ieee->sec.flags |= SEC_AUTH_MODE;
10709 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10710 priv->capability |= CAP_SHARED_KEY;
10712 priv->capability &= ~CAP_SHARED_KEY;
10713 priv->status |= STATUS_SECURITY_UPDATED;
10716 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10717 priv->ieee->sec.flags |= SEC_ENABLED;
10718 priv->ieee->sec.enabled = sec->enabled;
10719 priv->status |= STATUS_SECURITY_UPDATED;
10721 priv->capability |= CAP_PRIVACY_ON;
10723 priv->capability &= ~CAP_PRIVACY_ON;
10726 if (sec->flags & SEC_ENCRYPT)
10727 priv->ieee->sec.encrypt = sec->encrypt;
10729 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10730 priv->ieee->sec.level = sec->level;
10731 priv->ieee->sec.flags |= SEC_LEVEL;
10732 priv->status |= STATUS_SECURITY_UPDATED;
10735 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10736 ipw_set_hwcrypto_keys(priv);
10738 /* To match current functionality of ipw2100 (which works well w/
10739 * various supplicants, we don't force a disassociate if the
10740 * privacy capability changes ... */
10742 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
10743 (((priv->assoc_request.capability &
10744 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
10745 (!(priv->assoc_request.capability &
10746 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
10747 IPW_DEBUG_ASSOC("Disassociating due to capability "
10749 ipw_disassociate(priv);
10754 static int init_supported_rates(struct ipw_priv *priv,
10755 struct ipw_supported_rates *rates)
10757 /* TODO: Mask out rates based on priv->rates_mask */
10759 memset(rates, 0, sizeof(*rates));
10760 /* configure supported rates */
10761 switch (priv->ieee->freq_band) {
10762 case IEEE80211_52GHZ_BAND:
10763 rates->ieee_mode = IPW_A_MODE;
10764 rates->purpose = IPW_RATE_CAPABILITIES;
10765 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10766 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10769 default: /* Mixed or 2.4Ghz */
10770 rates->ieee_mode = IPW_G_MODE;
10771 rates->purpose = IPW_RATE_CAPABILITIES;
10772 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10773 IEEE80211_CCK_DEFAULT_RATES_MASK);
10774 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10775 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10776 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10784 static int ipw_config(struct ipw_priv *priv)
10786 /* This is only called from ipw_up, which resets/reloads the firmware
10787 so, we don't need to first disable the card before we configure
10789 if (ipw_set_tx_power(priv))
10792 /* initialize adapter address */
10793 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10796 /* set basic system config settings */
10797 init_sys_config(&priv->sys_config);
10799 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10800 * Does not support BT priority yet (don't abort or defer our Tx) */
10802 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
10804 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10805 priv->sys_config.bt_coexistence
10806 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
10807 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10808 priv->sys_config.bt_coexistence
10809 |= CFG_BT_COEXISTENCE_OOB;
10812 #ifdef CONFIG_IPW2200_PROMISCUOUS
10813 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10814 priv->sys_config.accept_all_data_frames = 1;
10815 priv->sys_config.accept_non_directed_frames = 1;
10816 priv->sys_config.accept_all_mgmt_bcpr = 1;
10817 priv->sys_config.accept_all_mgmt_frames = 1;
10821 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10822 priv->sys_config.answer_broadcast_ssid_probe = 1;
10824 priv->sys_config.answer_broadcast_ssid_probe = 0;
10826 if (ipw_send_system_config(priv))
10829 init_supported_rates(priv, &priv->rates);
10830 if (ipw_send_supported_rates(priv, &priv->rates))
10833 /* Set request-to-send threshold */
10834 if (priv->rts_threshold) {
10835 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10838 #ifdef CONFIG_IPW2200_QOS
10839 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10840 ipw_qos_activate(priv, NULL);
10841 #endif /* CONFIG_IPW2200_QOS */
10843 if (ipw_set_random_seed(priv))
10846 /* final state transition to the RUN state */
10847 if (ipw_send_host_complete(priv))
10850 priv->status |= STATUS_INIT;
10852 ipw_led_init(priv);
10853 ipw_led_radio_on(priv);
10854 priv->notif_missed_beacons = 0;
10856 /* Set hardware WEP key if it is configured. */
10857 if ((priv->capability & CAP_PRIVACY_ON) &&
10858 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10859 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10860 ipw_set_hwcrypto_keys(priv);
10871 * These tables have been tested in conjunction with the
10872 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10874 * Altering this values, using it on other hardware, or in geographies
10875 * not intended for resale of the above mentioned Intel adapters has
10878 * Remember to update the table in README.ipw2200 when changing this
10882 static const struct ieee80211_geo ipw_geos[] = {
10886 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10887 {2427, 4}, {2432, 5}, {2437, 6},
10888 {2442, 7}, {2447, 8}, {2452, 9},
10889 {2457, 10}, {2462, 11}},
10892 { /* Custom US/Canada */
10895 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10896 {2427, 4}, {2432, 5}, {2437, 6},
10897 {2442, 7}, {2447, 8}, {2452, 9},
10898 {2457, 10}, {2462, 11}},
10904 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10905 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10906 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10907 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10910 { /* Rest of World */
10913 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10914 {2427, 4}, {2432, 5}, {2437, 6},
10915 {2442, 7}, {2447, 8}, {2452, 9},
10916 {2457, 10}, {2462, 11}, {2467, 12},
10920 { /* Custom USA & Europe & High */
10923 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10924 {2427, 4}, {2432, 5}, {2437, 6},
10925 {2442, 7}, {2447, 8}, {2452, 9},
10926 {2457, 10}, {2462, 11}},
10932 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10933 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10934 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10935 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10943 { /* Custom NA & Europe */
10946 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10947 {2427, 4}, {2432, 5}, {2437, 6},
10948 {2442, 7}, {2447, 8}, {2452, 9},
10949 {2457, 10}, {2462, 11}},
10955 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10956 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10957 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10958 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10959 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10960 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10961 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10962 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10963 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10966 { /* Custom Japan */
10969 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10970 {2427, 4}, {2432, 5}, {2437, 6},
10971 {2442, 7}, {2447, 8}, {2452, 9},
10972 {2457, 10}, {2462, 11}},
10974 .a = {{5170, 34}, {5190, 38},
10975 {5210, 42}, {5230, 46}},
10981 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10982 {2427, 4}, {2432, 5}, {2437, 6},
10983 {2442, 7}, {2447, 8}, {2452, 9},
10984 {2457, 10}, {2462, 11}},
10990 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10991 {2427, 4}, {2432, 5}, {2437, 6},
10992 {2442, 7}, {2447, 8}, {2452, 9},
10993 {2457, 10}, {2462, 11}, {2467, 12},
11000 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11001 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11002 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11003 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11004 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
11005 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
11006 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
11007 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
11008 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
11009 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
11010 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
11011 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
11012 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
11013 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
11014 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
11017 { /* Custom Japan */
11020 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11021 {2427, 4}, {2432, 5}, {2437, 6},
11022 {2442, 7}, {2447, 8}, {2452, 9},
11023 {2457, 10}, {2462, 11}, {2467, 12},
11024 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
11026 .a = {{5170, 34}, {5190, 38},
11027 {5210, 42}, {5230, 46}},
11030 { /* Rest of World */
11033 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11034 {2427, 4}, {2432, 5}, {2437, 6},
11035 {2442, 7}, {2447, 8}, {2452, 9},
11036 {2457, 10}, {2462, 11}, {2467, 12},
11037 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
11038 IEEE80211_CH_PASSIVE_ONLY}},
11044 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11045 {2427, 4}, {2432, 5}, {2437, 6},
11046 {2442, 7}, {2447, 8}, {2452, 9},
11047 {2457, 10}, {2462, 11},
11048 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
11049 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
11051 .a = {{5745, 149}, {5765, 153},
11052 {5785, 157}, {5805, 161}},
11055 { /* Custom Europe */
11058 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11059 {2427, 4}, {2432, 5}, {2437, 6},
11060 {2442, 7}, {2447, 8}, {2452, 9},
11061 {2457, 10}, {2462, 11},
11062 {2467, 12}, {2472, 13}},
11064 .a = {{5180, 36}, {5200, 40},
11065 {5220, 44}, {5240, 48}},
11071 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11072 {2427, 4}, {2432, 5}, {2437, 6},
11073 {2442, 7}, {2447, 8}, {2452, 9},
11074 {2457, 10}, {2462, 11},
11075 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
11076 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
11078 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
11079 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
11080 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
11081 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
11082 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11083 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11084 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11085 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11086 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
11087 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
11088 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
11089 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
11090 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
11091 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
11092 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
11093 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
11094 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
11095 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
11096 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
11097 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11098 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11099 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11100 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11101 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11107 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11108 {2427, 4}, {2432, 5}, {2437, 6},
11109 {2442, 7}, {2447, 8}, {2452, 9},
11110 {2457, 10}, {2462, 11}},
11112 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
11113 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
11114 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
11115 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
11116 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11117 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11118 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11119 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11120 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11121 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11122 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11123 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11124 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11128 #define MAX_HW_RESTARTS 5
11129 static int ipw_up(struct ipw_priv *priv)
11133 if (priv->status & STATUS_EXIT_PENDING)
11136 if (cmdlog && !priv->cmdlog) {
11137 priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
11139 if (priv->cmdlog == NULL) {
11140 IPW_ERROR("Error allocating %d command log entries.\n",
11144 memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
11145 priv->cmdlog_len = cmdlog;
11149 for (i = 0; i < MAX_HW_RESTARTS; i++) {
11150 /* Load the microcode, firmware, and eeprom.
11151 * Also start the clocks. */
11152 rc = ipw_load(priv);
11154 IPW_ERROR("Unable to load firmware: %d\n", rc);
11158 ipw_init_ordinals(priv);
11159 if (!(priv->config & CFG_CUSTOM_MAC))
11160 eeprom_parse_mac(priv, priv->mac_addr);
11161 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
11163 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11164 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11165 ipw_geos[j].name, 3))
11168 if (j == ARRAY_SIZE(ipw_geos)) {
11169 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11170 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11171 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11172 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
11175 if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
11176 IPW_WARNING("Could not set geography.");
11180 if (priv->status & STATUS_RF_KILL_SW) {
11181 IPW_WARNING("Radio disabled by module parameter.\n");
11183 } else if (rf_kill_active(priv)) {
11184 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11185 "Kill switch must be turned off for "
11186 "wireless networking to work.\n");
11187 queue_delayed_work(priv->workqueue, &priv->rf_kill,
11192 rc = ipw_config(priv);
11194 IPW_DEBUG_INFO("Configured device on count %i\n", i);
11196 /* If configure to try and auto-associate, kick
11198 queue_work(priv->workqueue, &priv->request_scan);
11203 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
11204 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11205 i, MAX_HW_RESTARTS);
11207 /* We had an error bringing up the hardware, so take it
11208 * all the way back down so we can try again */
11212 /* tried to restart and config the device for as long as our
11213 * patience could withstand */
11214 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
11219 static void ipw_bg_up(void *data)
11221 struct ipw_priv *priv = data;
11222 mutex_lock(&priv->mutex);
11224 mutex_unlock(&priv->mutex);
11227 static void ipw_deinit(struct ipw_priv *priv)
11231 if (priv->status & STATUS_SCANNING) {
11232 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11233 ipw_abort_scan(priv);
11236 if (priv->status & STATUS_ASSOCIATED) {
11237 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11238 ipw_disassociate(priv);
11241 ipw_led_shutdown(priv);
11243 /* Wait up to 1s for status to change to not scanning and not
11244 * associated (disassociation can take a while for a ful 802.11
11246 for (i = 1000; i && (priv->status &
11247 (STATUS_DISASSOCIATING |
11248 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11251 if (priv->status & (STATUS_DISASSOCIATING |
11252 STATUS_ASSOCIATED | STATUS_SCANNING))
11253 IPW_DEBUG_INFO("Still associated or scanning...\n");
11255 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11257 /* Attempt to disable the card */
11258 ipw_send_card_disable(priv, 0);
11260 priv->status &= ~STATUS_INIT;
11263 static void ipw_down(struct ipw_priv *priv)
11265 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11267 priv->status |= STATUS_EXIT_PENDING;
11269 if (ipw_is_init(priv))
11272 /* Wipe out the EXIT_PENDING status bit if we are not actually
11273 * exiting the module */
11275 priv->status &= ~STATUS_EXIT_PENDING;
11277 /* tell the device to stop sending interrupts */
11278 ipw_disable_interrupts(priv);
11280 /* Clear all bits but the RF Kill */
11281 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
11282 netif_carrier_off(priv->net_dev);
11283 netif_stop_queue(priv->net_dev);
11285 ipw_stop_nic(priv);
11287 ipw_led_radio_off(priv);
11290 static void ipw_bg_down(void *data)
11292 struct ipw_priv *priv = data;
11293 mutex_lock(&priv->mutex);
11295 mutex_unlock(&priv->mutex);
11298 /* Called by register_netdev() */
11299 static int ipw_net_init(struct net_device *dev)
11301 struct ipw_priv *priv = ieee80211_priv(dev);
11302 mutex_lock(&priv->mutex);
11304 if (ipw_up(priv)) {
11305 mutex_unlock(&priv->mutex);
11309 mutex_unlock(&priv->mutex);
11313 /* PCI driver stuff */
11314 static struct pci_device_id card_ids[] = {
11315 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11316 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11317 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11318 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11319 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11320 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11321 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11322 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11323 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11324 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11325 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11326 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11327 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11328 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11329 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11330 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11331 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
11332 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
11333 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
11334 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
11335 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
11336 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
11338 /* required last entry */
11342 MODULE_DEVICE_TABLE(pci, card_ids);
11344 static struct attribute *ipw_sysfs_entries[] = {
11345 &dev_attr_rf_kill.attr,
11346 &dev_attr_direct_dword.attr,
11347 &dev_attr_indirect_byte.attr,
11348 &dev_attr_indirect_dword.attr,
11349 &dev_attr_mem_gpio_reg.attr,
11350 &dev_attr_command_event_reg.attr,
11351 &dev_attr_nic_type.attr,
11352 &dev_attr_status.attr,
11353 &dev_attr_cfg.attr,
11354 &dev_attr_error.attr,
11355 &dev_attr_event_log.attr,
11356 &dev_attr_cmd_log.attr,
11357 &dev_attr_eeprom_delay.attr,
11358 &dev_attr_ucode_version.attr,
11359 &dev_attr_rtc.attr,
11360 &dev_attr_scan_age.attr,
11361 &dev_attr_led.attr,
11362 &dev_attr_speed_scan.attr,
11363 &dev_attr_net_stats.attr,
11364 #ifdef CONFIG_IPW2200_PROMISCUOUS
11365 &dev_attr_rtap_iface.attr,
11366 &dev_attr_rtap_filter.attr,
11371 static struct attribute_group ipw_attribute_group = {
11372 .name = NULL, /* put in device directory */
11373 .attrs = ipw_sysfs_entries,
11376 #ifdef CONFIG_IPW2200_PROMISCUOUS
11377 static int ipw_prom_open(struct net_device *dev)
11379 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11380 struct ipw_priv *priv = prom_priv->priv;
11382 IPW_DEBUG_INFO("prom dev->open\n");
11383 netif_carrier_off(dev);
11384 netif_stop_queue(dev);
11386 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11387 priv->sys_config.accept_all_data_frames = 1;
11388 priv->sys_config.accept_non_directed_frames = 1;
11389 priv->sys_config.accept_all_mgmt_bcpr = 1;
11390 priv->sys_config.accept_all_mgmt_frames = 1;
11392 ipw_send_system_config(priv);
11398 static int ipw_prom_stop(struct net_device *dev)
11400 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11401 struct ipw_priv *priv = prom_priv->priv;
11403 IPW_DEBUG_INFO("prom dev->stop\n");
11405 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11406 priv->sys_config.accept_all_data_frames = 0;
11407 priv->sys_config.accept_non_directed_frames = 0;
11408 priv->sys_config.accept_all_mgmt_bcpr = 0;
11409 priv->sys_config.accept_all_mgmt_frames = 0;
11411 ipw_send_system_config(priv);
11417 static int ipw_prom_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
11419 IPW_DEBUG_INFO("prom dev->xmit\n");
11420 netif_stop_queue(dev);
11421 return -EOPNOTSUPP;
11424 static struct net_device_stats *ipw_prom_get_stats(struct net_device *dev)
11426 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11427 return &prom_priv->ieee->stats;
11430 static int ipw_prom_alloc(struct ipw_priv *priv)
11434 if (priv->prom_net_dev)
11437 priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv));
11438 if (priv->prom_net_dev == NULL)
11441 priv->prom_priv = ieee80211_priv(priv->prom_net_dev);
11442 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11443 priv->prom_priv->priv = priv;
11445 strcpy(priv->prom_net_dev->name, "rtap%d");
11447 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
11448 priv->prom_net_dev->open = ipw_prom_open;
11449 priv->prom_net_dev->stop = ipw_prom_stop;
11450 priv->prom_net_dev->get_stats = ipw_prom_get_stats;
11451 priv->prom_net_dev->hard_start_xmit = ipw_prom_hard_start_xmit;
11453 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
11455 rc = register_netdev(priv->prom_net_dev);
11457 free_ieee80211(priv->prom_net_dev);
11458 priv->prom_net_dev = NULL;
11465 static void ipw_prom_free(struct ipw_priv *priv)
11467 if (!priv->prom_net_dev)
11470 unregister_netdev(priv->prom_net_dev);
11471 free_ieee80211(priv->prom_net_dev);
11473 priv->prom_net_dev = NULL;
11479 static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
11482 struct net_device *net_dev;
11483 void __iomem *base;
11485 struct ipw_priv *priv;
11488 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
11489 if (net_dev == NULL) {
11494 priv = ieee80211_priv(net_dev);
11495 priv->ieee = netdev_priv(net_dev);
11497 priv->net_dev = net_dev;
11498 priv->pci_dev = pdev;
11499 #ifdef CONFIG_IPW2200_DEBUG
11500 ipw_debug_level = debug;
11502 spin_lock_init(&priv->irq_lock);
11503 spin_lock_init(&priv->lock);
11504 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11505 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
11507 mutex_init(&priv->mutex);
11508 if (pci_enable_device(pdev)) {
11510 goto out_free_ieee80211;
11513 pci_set_master(pdev);
11515 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
11517 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
11519 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11520 goto out_pci_disable_device;
11523 pci_set_drvdata(pdev, priv);
11525 err = pci_request_regions(pdev, DRV_NAME);
11527 goto out_pci_disable_device;
11529 /* We disable the RETRY_TIMEOUT register (0x41) to keep
11530 * PCI Tx retries from interfering with C3 CPU state */
11531 pci_read_config_dword(pdev, 0x40, &val);
11532 if ((val & 0x0000ff00) != 0)
11533 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11535 length = pci_resource_len(pdev, 0);
11536 priv->hw_len = length;
11538 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
11541 goto out_pci_release_regions;
11544 priv->hw_base = base;
11545 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11546 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11548 err = ipw_setup_deferred_work(priv);
11550 IPW_ERROR("Unable to setup deferred work\n");
11554 ipw_sw_reset(priv, 1);
11556 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
11558 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11559 goto out_destroy_workqueue;
11562 SET_MODULE_OWNER(net_dev);
11563 SET_NETDEV_DEV(net_dev, &pdev->dev);
11565 mutex_lock(&priv->mutex);
11567 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11568 priv->ieee->set_security = shim__set_security;
11569 priv->ieee->is_queue_full = ipw_net_is_queue_full;
11571 #ifdef CONFIG_IPW2200_QOS
11572 priv->ieee->is_qos_active = ipw_is_qos_active;
11573 priv->ieee->handle_probe_response = ipw_handle_beacon;
11574 priv->ieee->handle_beacon = ipw_handle_probe_response;
11575 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
11576 #endif /* CONFIG_IPW2200_QOS */
11578 priv->ieee->perfect_rssi = -20;
11579 priv->ieee->worst_rssi = -85;
11581 net_dev->open = ipw_net_open;
11582 net_dev->stop = ipw_net_stop;
11583 net_dev->init = ipw_net_init;
11584 net_dev->get_stats = ipw_net_get_stats;
11585 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11586 net_dev->set_mac_address = ipw_net_set_mac_address;
11587 priv->wireless_data.spy_data = &priv->ieee->spy_data;
11588 net_dev->wireless_data = &priv->wireless_data;
11589 net_dev->wireless_handlers = &ipw_wx_handler_def;
11590 net_dev->ethtool_ops = &ipw_ethtool_ops;
11591 net_dev->irq = pdev->irq;
11592 net_dev->base_addr = (unsigned long)priv->hw_base;
11593 net_dev->mem_start = pci_resource_start(pdev, 0);
11594 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11596 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11598 IPW_ERROR("failed to create sysfs device attributes\n");
11599 mutex_unlock(&priv->mutex);
11600 goto out_release_irq;
11603 mutex_unlock(&priv->mutex);
11604 err = register_netdev(net_dev);
11606 IPW_ERROR("failed to register network device\n");
11607 goto out_remove_sysfs;
11610 #ifdef CONFIG_IPW2200_PROMISCUOUS
11612 err = ipw_prom_alloc(priv);
11614 IPW_ERROR("Failed to register promiscuous network "
11615 "device (error %d).\n", err);
11616 unregister_netdev(priv->net_dev);
11617 goto out_remove_sysfs;
11622 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11623 "channels, %d 802.11a channels)\n",
11624 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11625 priv->ieee->geo.a_channels);
11630 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11632 free_irq(pdev->irq, priv);
11633 out_destroy_workqueue:
11634 destroy_workqueue(priv->workqueue);
11635 priv->workqueue = NULL;
11637 iounmap(priv->hw_base);
11638 out_pci_release_regions:
11639 pci_release_regions(pdev);
11640 out_pci_disable_device:
11641 pci_disable_device(pdev);
11642 pci_set_drvdata(pdev, NULL);
11643 out_free_ieee80211:
11644 free_ieee80211(priv->net_dev);
11649 static void ipw_pci_remove(struct pci_dev *pdev)
11651 struct ipw_priv *priv = pci_get_drvdata(pdev);
11652 struct list_head *p, *q;
11658 mutex_lock(&priv->mutex);
11660 priv->status |= STATUS_EXIT_PENDING;
11662 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11664 mutex_unlock(&priv->mutex);
11666 unregister_netdev(priv->net_dev);
11669 ipw_rx_queue_free(priv, priv->rxq);
11672 ipw_tx_queue_free(priv);
11674 if (priv->cmdlog) {
11675 kfree(priv->cmdlog);
11676 priv->cmdlog = NULL;
11678 /* ipw_down will ensure that there is no more pending work
11679 * in the workqueue's, so we can safely remove them now. */
11680 cancel_delayed_work(&priv->adhoc_check);
11681 cancel_delayed_work(&priv->gather_stats);
11682 cancel_delayed_work(&priv->request_scan);
11683 cancel_delayed_work(&priv->rf_kill);
11684 cancel_delayed_work(&priv->scan_check);
11685 destroy_workqueue(priv->workqueue);
11686 priv->workqueue = NULL;
11688 /* Free MAC hash list for ADHOC */
11689 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11690 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
11692 kfree(list_entry(p, struct ipw_ibss_seq, list));
11697 ipw_free_error_log(priv->error);
11698 priv->error = NULL;
11701 #ifdef CONFIG_IPW2200_PROMISCUOUS
11702 ipw_prom_free(priv);
11705 free_irq(pdev->irq, priv);
11706 iounmap(priv->hw_base);
11707 pci_release_regions(pdev);
11708 pci_disable_device(pdev);
11709 pci_set_drvdata(pdev, NULL);
11710 free_ieee80211(priv->net_dev);
11715 static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
11717 struct ipw_priv *priv = pci_get_drvdata(pdev);
11718 struct net_device *dev = priv->net_dev;
11720 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11722 /* Take down the device; powers it off, etc. */
11725 /* Remove the PRESENT state of the device */
11726 netif_device_detach(dev);
11728 pci_save_state(pdev);
11729 pci_disable_device(pdev);
11730 pci_set_power_state(pdev, pci_choose_state(pdev, state));
11735 static int ipw_pci_resume(struct pci_dev *pdev)
11737 struct ipw_priv *priv = pci_get_drvdata(pdev);
11738 struct net_device *dev = priv->net_dev;
11741 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11743 pci_set_power_state(pdev, PCI_D0);
11744 pci_enable_device(pdev);
11745 pci_restore_state(pdev);
11748 * Suspend/Resume resets the PCI configuration space, so we have to
11749 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11750 * from interfering with C3 CPU state. pci_restore_state won't help
11751 * here since it only restores the first 64 bytes pci config header.
11753 pci_read_config_dword(pdev, 0x40, &val);
11754 if ((val & 0x0000ff00) != 0)
11755 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11757 /* Set the device back into the PRESENT state; this will also wake
11758 * the queue of needed */
11759 netif_device_attach(dev);
11761 /* Bring the device back up */
11762 queue_work(priv->workqueue, &priv->up);
11768 /* driver initialization stuff */
11769 static struct pci_driver ipw_driver = {
11771 .id_table = card_ids,
11772 .probe = ipw_pci_probe,
11773 .remove = __devexit_p(ipw_pci_remove),
11775 .suspend = ipw_pci_suspend,
11776 .resume = ipw_pci_resume,
11780 static int __init ipw_init(void)
11784 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11785 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11787 ret = pci_module_init(&ipw_driver);
11789 IPW_ERROR("Unable to initialize PCI module\n");
11793 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
11795 IPW_ERROR("Unable to create driver sysfs file\n");
11796 pci_unregister_driver(&ipw_driver);
11803 static void __exit ipw_exit(void)
11805 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11806 pci_unregister_driver(&ipw_driver);
11809 module_param(disable, int, 0444);
11810 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11812 module_param(associate, int, 0444);
11813 MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11815 module_param(auto_create, int, 0444);
11816 MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11818 module_param(led, int, 0444);
11819 MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
11821 #ifdef CONFIG_IPW2200_DEBUG
11822 module_param(debug, int, 0444);
11823 MODULE_PARM_DESC(debug, "debug output mask");
11826 module_param(channel, int, 0444);
11827 MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
11829 #ifdef CONFIG_IPW2200_PROMISCUOUS
11830 module_param(rtap_iface, int, 0444);
11831 MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
11834 #ifdef CONFIG_IPW2200_QOS
11835 module_param(qos_enable, int, 0444);
11836 MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
11838 module_param(qos_burst_enable, int, 0444);
11839 MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11841 module_param(qos_no_ack_mask, int, 0444);
11842 MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11844 module_param(burst_duration_CCK, int, 0444);
11845 MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11847 module_param(burst_duration_OFDM, int, 0444);
11848 MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11849 #endif /* CONFIG_IPW2200_QOS */
11851 #ifdef CONFIG_IPW2200_MONITOR
11852 module_param(mode, int, 0444);
11853 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11855 module_param(mode, int, 0444);
11856 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11859 module_param(bt_coexist, int, 0444);
11860 MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
11862 module_param(hwcrypto, int, 0444);
11863 MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
11865 module_param(cmdlog, int, 0444);
11866 MODULE_PARM_DESC(cmdlog,
11867 "allocate a ring buffer for logging firmware commands");
11869 module_param(roaming, int, 0444);
11870 MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
11872 module_param(antenna, int, 0444);
11873 MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
11875 module_exit(ipw_exit);
11876 module_init(ipw_init);