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>
36 #define IPW2200_VERSION "git-1.1.1"
37 #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
38 #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
39 #define DRV_VERSION IPW2200_VERSION
41 #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
43 MODULE_DESCRIPTION(DRV_DESCRIPTION);
44 MODULE_VERSION(DRV_VERSION);
45 MODULE_AUTHOR(DRV_COPYRIGHT);
46 MODULE_LICENSE("GPL");
48 static int cmdlog = 0;
49 #ifdef CONFIG_IPW2200_DEBUG
52 static int channel = 0;
55 static u32 ipw_debug_level;
56 static int associate = 1;
57 static int auto_create = 1;
59 static int disable = 0;
60 static int bt_coexist = 0;
61 static int hwcrypto = 0;
62 static int roaming = 1;
63 static const char ipw_modes[] = {
66 static int antenna = CFG_SYS_ANTENNA_BOTH;
68 #ifdef CONFIG_IPW2200_PROMISCUOUS
69 static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */
74 static int qos_enable = 0;
75 static int qos_burst_enable = 0;
76 static int qos_no_ack_mask = 0;
77 static int burst_duration_CCK = 0;
78 static int burst_duration_OFDM = 0;
80 static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
81 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
83 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
85 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
86 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
87 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
88 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
91 static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
92 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
94 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
96 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
97 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
98 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
99 QOS_TX3_TXOP_LIMIT_CCK}
102 static struct ieee80211_qos_parameters def_parameters_OFDM = {
103 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
104 DEF_TX3_CW_MIN_OFDM},
105 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
106 DEF_TX3_CW_MAX_OFDM},
107 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
108 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
109 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
110 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
113 static struct ieee80211_qos_parameters def_parameters_CCK = {
114 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
116 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
118 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
119 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
120 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
121 DEF_TX3_TXOP_LIMIT_CCK}
124 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
126 static int from_priority_to_tx_queue[] = {
127 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
128 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
131 static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
133 static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
135 static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
137 #endif /* CONFIG_IPW_QOS */
139 static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
140 static void ipw_remove_current_network(struct ipw_priv *priv);
141 static void ipw_rx(struct ipw_priv *priv);
142 static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
143 struct clx2_tx_queue *txq, int qindex);
144 static int ipw_queue_reset(struct ipw_priv *priv);
146 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
149 static void ipw_tx_queue_free(struct ipw_priv *);
151 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
152 static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
153 static void ipw_rx_queue_replenish(void *);
154 static int ipw_up(struct ipw_priv *);
155 static void ipw_bg_up(void *);
156 static void ipw_down(struct ipw_priv *);
157 static void ipw_bg_down(void *);
158 static int ipw_config(struct ipw_priv *);
159 static int init_supported_rates(struct ipw_priv *priv,
160 struct ipw_supported_rates *prates);
161 static void ipw_set_hwcrypto_keys(struct ipw_priv *);
162 static void ipw_send_wep_keys(struct ipw_priv *, int);
164 static int snprint_line(char *buf, size_t count,
165 const u8 * data, u32 len, u32 ofs)
170 out = snprintf(buf, count, "%08X", ofs);
172 for (l = 0, i = 0; i < 2; i++) {
173 out += snprintf(buf + out, count - out, " ");
174 for (j = 0; j < 8 && l < len; j++, l++)
175 out += snprintf(buf + out, count - out, "%02X ",
178 out += snprintf(buf + out, count - out, " ");
181 out += snprintf(buf + out, count - out, " ");
182 for (l = 0, i = 0; i < 2; i++) {
183 out += snprintf(buf + out, count - out, " ");
184 for (j = 0; j < 8 && l < len; j++, l++) {
185 c = data[(i * 8 + j)];
186 if (!isascii(c) || !isprint(c))
189 out += snprintf(buf + out, count - out, "%c", c);
193 out += snprintf(buf + out, count - out, " ");
199 static void printk_buf(int level, const u8 * data, u32 len)
203 if (!(ipw_debug_level & level))
207 snprint_line(line, sizeof(line), &data[ofs],
209 printk(KERN_DEBUG "%s\n", line);
211 len -= min(len, 16U);
215 static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
221 while (size && len) {
222 out = snprint_line(output, size, &data[ofs],
223 min_t(size_t, len, 16U), ofs);
228 len -= min_t(size_t, len, 16U);
234 /* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
235 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
236 #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
238 /* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
239 static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
240 #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
242 /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
243 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
244 static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
246 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
247 __LINE__, (u32) (b), (u32) (c));
248 _ipw_write_reg8(a, b, c);
251 /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
252 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
253 static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
255 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
256 __LINE__, (u32) (b), (u32) (c));
257 _ipw_write_reg16(a, b, c);
260 /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
261 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
262 static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
264 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
265 __LINE__, (u32) (b), (u32) (c));
266 _ipw_write_reg32(a, b, c);
269 /* 8-bit direct write (low 4K) */
270 #define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
272 /* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
273 #define ipw_write8(ipw, ofs, val) \
274 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
275 _ipw_write8(ipw, ofs, val)
277 /* 16-bit direct write (low 4K) */
278 #define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
280 /* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
281 #define ipw_write16(ipw, ofs, val) \
282 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
283 _ipw_write16(ipw, ofs, val)
285 /* 32-bit direct write (low 4K) */
286 #define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
288 /* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
289 #define ipw_write32(ipw, ofs, val) \
290 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
291 _ipw_write32(ipw, ofs, val)
293 /* 8-bit direct read (low 4K) */
294 #define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
296 /* 8-bit direct read (low 4K), with debug wrapper */
297 static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
299 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
300 return _ipw_read8(ipw, ofs);
303 /* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
304 #define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
306 /* 16-bit direct read (low 4K) */
307 #define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
309 /* 16-bit direct read (low 4K), with debug wrapper */
310 static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
312 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
313 return _ipw_read16(ipw, ofs);
316 /* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
317 #define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
319 /* 32-bit direct read (low 4K) */
320 #define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
322 /* 32-bit direct read (low 4K), with debug wrapper */
323 static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
325 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
326 return _ipw_read32(ipw, ofs);
329 /* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
330 #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
332 /* multi-byte read (above 4K), with debug wrapper */
333 static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
334 static inline void __ipw_read_indirect(const char *f, int l,
335 struct ipw_priv *a, u32 b, u8 * c, int d)
337 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
339 _ipw_read_indirect(a, b, c, d);
342 /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
343 #define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
345 /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
346 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
348 #define ipw_write_indirect(a, b, c, d) \
349 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
350 _ipw_write_indirect(a, b, c, d)
352 /* 32-bit indirect write (above 4K) */
353 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
355 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
356 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
357 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
360 /* 8-bit indirect write (above 4K) */
361 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
363 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
364 u32 dif_len = reg - aligned_addr;
366 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
367 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
368 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
371 /* 16-bit indirect write (above 4K) */
372 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
374 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
375 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
377 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
378 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
379 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
382 /* 8-bit indirect read (above 4K) */
383 static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
386 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
387 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
388 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
389 return (word >> ((reg & 0x3) * 8)) & 0xff;
392 /* 32-bit indirect read (above 4K) */
393 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
397 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
399 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
400 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
401 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
405 /* General purpose, no alignment requirement, iterative (multi-byte) read, */
406 /* for area above 1st 4K of SRAM/reg space */
407 static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
410 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
411 u32 dif_len = addr - aligned_addr;
414 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
420 /* Read the first dword (or portion) byte by byte */
421 if (unlikely(dif_len)) {
422 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
423 /* Start reading at aligned_addr + dif_len */
424 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
425 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
429 /* Read all of the middle dwords as dwords, with auto-increment */
430 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
431 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
432 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
434 /* Read the last dword (or portion) byte by byte */
436 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
437 for (i = 0; num > 0; i++, num--)
438 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
442 /* General purpose, no alignment requirement, iterative (multi-byte) write, */
443 /* for area above 1st 4K of SRAM/reg space */
444 static void _ipw_write_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 /* Write the first dword (or portion) byte by byte */
458 if (unlikely(dif_len)) {
459 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
460 /* Start writing at aligned_addr + dif_len */
461 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
462 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
466 /* Write 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 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
471 /* Write 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--, buf++)
475 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
479 /* General purpose, no alignment requirement, iterative (multi-byte) write, */
480 /* for 1st 4K of SRAM/regs space */
481 static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
484 memcpy_toio((priv->hw_base + addr), buf, num);
487 /* Set bit(s) in low 4K of SRAM/regs */
488 static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
490 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
493 /* Clear bit(s) in low 4K of SRAM/regs */
494 static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
496 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
499 static inline void ipw_enable_interrupts(struct ipw_priv *priv)
501 if (priv->status & STATUS_INT_ENABLED)
503 priv->status |= STATUS_INT_ENABLED;
504 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
507 static inline void ipw_disable_interrupts(struct ipw_priv *priv)
509 if (!(priv->status & STATUS_INT_ENABLED))
511 priv->status &= ~STATUS_INT_ENABLED;
512 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
515 #ifdef CONFIG_IPW2200_DEBUG
516 static char *ipw_error_desc(u32 val)
519 case IPW_FW_ERROR_OK:
521 case IPW_FW_ERROR_FAIL:
523 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
524 return "MEMORY_UNDERFLOW";
525 case IPW_FW_ERROR_MEMORY_OVERFLOW:
526 return "MEMORY_OVERFLOW";
527 case IPW_FW_ERROR_BAD_PARAM:
529 case IPW_FW_ERROR_BAD_CHECKSUM:
530 return "BAD_CHECKSUM";
531 case IPW_FW_ERROR_NMI_INTERRUPT:
532 return "NMI_INTERRUPT";
533 case IPW_FW_ERROR_BAD_DATABASE:
534 return "BAD_DATABASE";
535 case IPW_FW_ERROR_ALLOC_FAIL:
537 case IPW_FW_ERROR_DMA_UNDERRUN:
538 return "DMA_UNDERRUN";
539 case IPW_FW_ERROR_DMA_STATUS:
541 case IPW_FW_ERROR_DINO_ERROR:
543 case IPW_FW_ERROR_EEPROM_ERROR:
544 return "EEPROM_ERROR";
545 case IPW_FW_ERROR_SYSASSERT:
547 case IPW_FW_ERROR_FATAL_ERROR:
548 return "FATAL_ERROR";
550 return "UNKNOWN_ERROR";
554 static void ipw_dump_error_log(struct ipw_priv *priv,
555 struct ipw_fw_error *error)
560 IPW_ERROR("Error allocating and capturing error log. "
561 "Nothing to dump.\n");
565 IPW_ERROR("Start IPW Error Log Dump:\n");
566 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
567 error->status, error->config);
569 for (i = 0; i < error->elem_len; i++)
570 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
571 ipw_error_desc(error->elem[i].desc),
573 error->elem[i].blink1,
574 error->elem[i].blink2,
575 error->elem[i].link1,
576 error->elem[i].link2, error->elem[i].data);
577 for (i = 0; i < error->log_len; i++)
578 IPW_ERROR("%i\t0x%08x\t%i\n",
580 error->log[i].data, error->log[i].event);
584 static inline int ipw_is_init(struct ipw_priv *priv)
586 return (priv->status & STATUS_INIT) ? 1 : 0;
589 static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
591 u32 addr, field_info, field_len, field_count, total_len;
593 IPW_DEBUG_ORD("ordinal = %i\n", ord);
595 if (!priv || !val || !len) {
596 IPW_DEBUG_ORD("Invalid argument\n");
600 /* verify device ordinal tables have been initialized */
601 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
602 IPW_DEBUG_ORD("Access ordinals before initialization\n");
606 switch (IPW_ORD_TABLE_ID_MASK & ord) {
607 case IPW_ORD_TABLE_0_MASK:
609 * TABLE 0: Direct access to a table of 32 bit values
611 * This is a very simple table with the data directly
612 * read from the table
615 /* remove the table id from the ordinal */
616 ord &= IPW_ORD_TABLE_VALUE_MASK;
619 if (ord > priv->table0_len) {
620 IPW_DEBUG_ORD("ordinal value (%i) longer then "
621 "max (%i)\n", ord, priv->table0_len);
625 /* verify we have enough room to store the value */
626 if (*len < sizeof(u32)) {
627 IPW_DEBUG_ORD("ordinal buffer length too small, "
628 "need %zd\n", sizeof(u32));
632 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
633 ord, priv->table0_addr + (ord << 2));
637 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
640 case IPW_ORD_TABLE_1_MASK:
642 * TABLE 1: Indirect access to a table of 32 bit values
644 * This is a fairly large table of u32 values each
645 * representing starting addr for the data (which is
649 /* remove the table id from the ordinal */
650 ord &= IPW_ORD_TABLE_VALUE_MASK;
653 if (ord > priv->table1_len) {
654 IPW_DEBUG_ORD("ordinal value too long\n");
658 /* verify we have enough room to store the value */
659 if (*len < sizeof(u32)) {
660 IPW_DEBUG_ORD("ordinal buffer length too small, "
661 "need %zd\n", sizeof(u32));
666 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
670 case IPW_ORD_TABLE_2_MASK:
672 * TABLE 2: Indirect access to a table of variable sized values
674 * This table consist of six values, each containing
675 * - dword containing the starting offset of the data
676 * - dword containing the lengh in the first 16bits
677 * and the count in the second 16bits
680 /* remove the table id from the ordinal */
681 ord &= IPW_ORD_TABLE_VALUE_MASK;
684 if (ord > priv->table2_len) {
685 IPW_DEBUG_ORD("ordinal value too long\n");
689 /* get the address of statistic */
690 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
692 /* get the second DW of statistics ;
693 * two 16-bit words - first is length, second is count */
696 priv->table2_addr + (ord << 3) +
699 /* get each entry length */
700 field_len = *((u16 *) & field_info);
702 /* get number of entries */
703 field_count = *(((u16 *) & field_info) + 1);
705 /* abort if not enought memory */
706 total_len = field_len * field_count;
707 if (total_len > *len) {
716 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
717 "field_info = 0x%08x\n",
718 addr, total_len, field_info);
719 ipw_read_indirect(priv, addr, val, total_len);
723 IPW_DEBUG_ORD("Invalid ordinal!\n");
731 static void ipw_init_ordinals(struct ipw_priv *priv)
733 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
734 priv->table0_len = ipw_read32(priv, priv->table0_addr);
736 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
737 priv->table0_addr, priv->table0_len);
739 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
740 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
742 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
743 priv->table1_addr, priv->table1_len);
745 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
746 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
747 priv->table2_len &= 0x0000ffff; /* use first two bytes */
749 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
750 priv->table2_addr, priv->table2_len);
754 static u32 ipw_register_toggle(u32 reg)
756 reg &= ~IPW_START_STANDBY;
757 if (reg & IPW_GATE_ODMA)
758 reg &= ~IPW_GATE_ODMA;
759 if (reg & IPW_GATE_IDMA)
760 reg &= ~IPW_GATE_IDMA;
761 if (reg & IPW_GATE_ADMA)
762 reg &= ~IPW_GATE_ADMA;
768 * - On radio ON, turn on any LEDs that require to be on during start
769 * - On initialization, start unassociated blink
770 * - On association, disable unassociated blink
771 * - On disassociation, start unassociated blink
772 * - On radio OFF, turn off any LEDs started during radio on
775 #define LD_TIME_LINK_ON msecs_to_jiffies(300)
776 #define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
777 #define LD_TIME_ACT_ON msecs_to_jiffies(250)
779 static void ipw_led_link_on(struct ipw_priv *priv)
784 /* If configured to not use LEDs, or nic_type is 1,
785 * then we don't toggle a LINK led */
786 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
789 spin_lock_irqsave(&priv->lock, flags);
791 if (!(priv->status & STATUS_RF_KILL_MASK) &&
792 !(priv->status & STATUS_LED_LINK_ON)) {
793 IPW_DEBUG_LED("Link LED On\n");
794 led = ipw_read_reg32(priv, IPW_EVENT_REG);
795 led |= priv->led_association_on;
797 led = ipw_register_toggle(led);
799 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
800 ipw_write_reg32(priv, IPW_EVENT_REG, led);
802 priv->status |= STATUS_LED_LINK_ON;
804 /* If we aren't associated, schedule turning the LED off */
805 if (!(priv->status & STATUS_ASSOCIATED))
806 queue_delayed_work(priv->workqueue,
811 spin_unlock_irqrestore(&priv->lock, flags);
814 static void ipw_bg_led_link_on(void *data)
816 struct ipw_priv *priv = data;
817 mutex_lock(&priv->mutex);
818 ipw_led_link_on(data);
819 mutex_unlock(&priv->mutex);
822 static void ipw_led_link_off(struct ipw_priv *priv)
827 /* If configured not to use LEDs, or nic type is 1,
828 * then we don't goggle the LINK led. */
829 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
832 spin_lock_irqsave(&priv->lock, flags);
834 if (priv->status & STATUS_LED_LINK_ON) {
835 led = ipw_read_reg32(priv, IPW_EVENT_REG);
836 led &= priv->led_association_off;
837 led = ipw_register_toggle(led);
839 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
840 ipw_write_reg32(priv, IPW_EVENT_REG, led);
842 IPW_DEBUG_LED("Link LED Off\n");
844 priv->status &= ~STATUS_LED_LINK_ON;
846 /* If we aren't associated and the radio is on, schedule
847 * turning the LED on (blink while unassociated) */
848 if (!(priv->status & STATUS_RF_KILL_MASK) &&
849 !(priv->status & STATUS_ASSOCIATED))
850 queue_delayed_work(priv->workqueue, &priv->led_link_on,
855 spin_unlock_irqrestore(&priv->lock, flags);
858 static void ipw_bg_led_link_off(void *data)
860 struct ipw_priv *priv = data;
861 mutex_lock(&priv->mutex);
862 ipw_led_link_off(data);
863 mutex_unlock(&priv->mutex);
866 static void __ipw_led_activity_on(struct ipw_priv *priv)
870 if (priv->config & CFG_NO_LED)
873 if (priv->status & STATUS_RF_KILL_MASK)
876 if (!(priv->status & STATUS_LED_ACT_ON)) {
877 led = ipw_read_reg32(priv, IPW_EVENT_REG);
878 led |= priv->led_activity_on;
880 led = ipw_register_toggle(led);
882 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
883 ipw_write_reg32(priv, IPW_EVENT_REG, led);
885 IPW_DEBUG_LED("Activity LED On\n");
887 priv->status |= STATUS_LED_ACT_ON;
889 cancel_delayed_work(&priv->led_act_off);
890 queue_delayed_work(priv->workqueue, &priv->led_act_off,
893 /* Reschedule LED off for full time period */
894 cancel_delayed_work(&priv->led_act_off);
895 queue_delayed_work(priv->workqueue, &priv->led_act_off,
901 void ipw_led_activity_on(struct ipw_priv *priv)
904 spin_lock_irqsave(&priv->lock, flags);
905 __ipw_led_activity_on(priv);
906 spin_unlock_irqrestore(&priv->lock, flags);
910 static void ipw_led_activity_off(struct ipw_priv *priv)
915 if (priv->config & CFG_NO_LED)
918 spin_lock_irqsave(&priv->lock, flags);
920 if (priv->status & STATUS_LED_ACT_ON) {
921 led = ipw_read_reg32(priv, IPW_EVENT_REG);
922 led &= priv->led_activity_off;
924 led = ipw_register_toggle(led);
926 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
927 ipw_write_reg32(priv, IPW_EVENT_REG, led);
929 IPW_DEBUG_LED("Activity LED Off\n");
931 priv->status &= ~STATUS_LED_ACT_ON;
934 spin_unlock_irqrestore(&priv->lock, flags);
937 static void ipw_bg_led_activity_off(void *data)
939 struct ipw_priv *priv = data;
940 mutex_lock(&priv->mutex);
941 ipw_led_activity_off(data);
942 mutex_unlock(&priv->mutex);
945 static void ipw_led_band_on(struct ipw_priv *priv)
950 /* Only nic type 1 supports mode LEDs */
951 if (priv->config & CFG_NO_LED ||
952 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
955 spin_lock_irqsave(&priv->lock, flags);
957 led = ipw_read_reg32(priv, IPW_EVENT_REG);
958 if (priv->assoc_network->mode == IEEE_A) {
959 led |= priv->led_ofdm_on;
960 led &= priv->led_association_off;
961 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
962 } else if (priv->assoc_network->mode == IEEE_G) {
963 led |= priv->led_ofdm_on;
964 led |= priv->led_association_on;
965 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
967 led &= priv->led_ofdm_off;
968 led |= priv->led_association_on;
969 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
972 led = ipw_register_toggle(led);
974 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
975 ipw_write_reg32(priv, IPW_EVENT_REG, led);
977 spin_unlock_irqrestore(&priv->lock, flags);
980 static void ipw_led_band_off(struct ipw_priv *priv)
985 /* Only nic type 1 supports mode LEDs */
986 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
989 spin_lock_irqsave(&priv->lock, flags);
991 led = ipw_read_reg32(priv, IPW_EVENT_REG);
992 led &= priv->led_ofdm_off;
993 led &= priv->led_association_off;
995 led = ipw_register_toggle(led);
997 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
998 ipw_write_reg32(priv, IPW_EVENT_REG, led);
1000 spin_unlock_irqrestore(&priv->lock, flags);
1003 static void ipw_led_radio_on(struct ipw_priv *priv)
1005 ipw_led_link_on(priv);
1008 static void ipw_led_radio_off(struct ipw_priv *priv)
1010 ipw_led_activity_off(priv);
1011 ipw_led_link_off(priv);
1014 static void ipw_led_link_up(struct ipw_priv *priv)
1016 /* Set the Link Led on for all nic types */
1017 ipw_led_link_on(priv);
1020 static void ipw_led_link_down(struct ipw_priv *priv)
1022 ipw_led_activity_off(priv);
1023 ipw_led_link_off(priv);
1025 if (priv->status & STATUS_RF_KILL_MASK)
1026 ipw_led_radio_off(priv);
1029 static void ipw_led_init(struct ipw_priv *priv)
1031 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1033 /* Set the default PINs for the link and activity leds */
1034 priv->led_activity_on = IPW_ACTIVITY_LED;
1035 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
1037 priv->led_association_on = IPW_ASSOCIATED_LED;
1038 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
1040 /* Set the default PINs for the OFDM leds */
1041 priv->led_ofdm_on = IPW_OFDM_LED;
1042 priv->led_ofdm_off = ~(IPW_OFDM_LED);
1044 switch (priv->nic_type) {
1045 case EEPROM_NIC_TYPE_1:
1046 /* In this NIC type, the LEDs are reversed.... */
1047 priv->led_activity_on = IPW_ASSOCIATED_LED;
1048 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1049 priv->led_association_on = IPW_ACTIVITY_LED;
1050 priv->led_association_off = ~(IPW_ACTIVITY_LED);
1052 if (!(priv->config & CFG_NO_LED))
1053 ipw_led_band_on(priv);
1055 /* And we don't blink link LEDs for this nic, so
1056 * just return here */
1059 case EEPROM_NIC_TYPE_3:
1060 case EEPROM_NIC_TYPE_2:
1061 case EEPROM_NIC_TYPE_4:
1062 case EEPROM_NIC_TYPE_0:
1066 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1068 priv->nic_type = EEPROM_NIC_TYPE_0;
1072 if (!(priv->config & CFG_NO_LED)) {
1073 if (priv->status & STATUS_ASSOCIATED)
1074 ipw_led_link_on(priv);
1076 ipw_led_link_off(priv);
1080 static void ipw_led_shutdown(struct ipw_priv *priv)
1082 ipw_led_activity_off(priv);
1083 ipw_led_link_off(priv);
1084 ipw_led_band_off(priv);
1085 cancel_delayed_work(&priv->led_link_on);
1086 cancel_delayed_work(&priv->led_link_off);
1087 cancel_delayed_work(&priv->led_act_off);
1091 * The following adds a new attribute to the sysfs representation
1092 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1093 * used for controling the debug level.
1095 * See the level definitions in ipw for details.
1097 static ssize_t show_debug_level(struct device_driver *d, char *buf)
1099 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1102 static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1105 char *p = (char *)buf;
1108 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1110 if (p[0] == 'x' || p[0] == 'X')
1112 val = simple_strtoul(p, &p, 16);
1114 val = simple_strtoul(p, &p, 10);
1116 printk(KERN_INFO DRV_NAME
1117 ": %s is not in hex or decimal form.\n", buf);
1119 ipw_debug_level = val;
1121 return strnlen(buf, count);
1124 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
1125 show_debug_level, store_debug_level);
1127 static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1129 /* length = 1st dword in log */
1130 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1133 static void ipw_capture_event_log(struct ipw_priv *priv,
1134 u32 log_len, struct ipw_event *log)
1139 base = ipw_read32(priv, IPW_EVENT_LOG);
1140 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1141 (u8 *) log, sizeof(*log) * log_len);
1145 static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1147 struct ipw_fw_error *error;
1148 u32 log_len = ipw_get_event_log_len(priv);
1149 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1150 u32 elem_len = ipw_read_reg32(priv, base);
1152 error = kmalloc(sizeof(*error) +
1153 sizeof(*error->elem) * elem_len +
1154 sizeof(*error->log) * log_len, GFP_ATOMIC);
1156 IPW_ERROR("Memory allocation for firmware error log "
1160 error->jiffies = jiffies;
1161 error->status = priv->status;
1162 error->config = priv->config;
1163 error->elem_len = elem_len;
1164 error->log_len = log_len;
1165 error->elem = (struct ipw_error_elem *)error->payload;
1166 error->log = (struct ipw_event *)(error->elem + elem_len);
1168 ipw_capture_event_log(priv, log_len, error->log);
1171 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1172 sizeof(*error->elem) * elem_len);
1177 static void ipw_free_error_log(struct ipw_fw_error *error)
1183 static ssize_t show_event_log(struct device *d,
1184 struct device_attribute *attr, char *buf)
1186 struct ipw_priv *priv = dev_get_drvdata(d);
1187 u32 log_len = ipw_get_event_log_len(priv);
1188 struct ipw_event log[log_len];
1191 ipw_capture_event_log(priv, log_len, log);
1193 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1194 for (i = 0; i < log_len; i++)
1195 len += snprintf(buf + len, PAGE_SIZE - len,
1197 log[i].time, log[i].event, log[i].data);
1198 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1202 static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1204 static ssize_t show_error(struct device *d,
1205 struct device_attribute *attr, char *buf)
1207 struct ipw_priv *priv = dev_get_drvdata(d);
1211 len += snprintf(buf + len, PAGE_SIZE - len,
1212 "%08lX%08X%08X%08X",
1213 priv->error->jiffies,
1214 priv->error->status,
1215 priv->error->config, priv->error->elem_len);
1216 for (i = 0; i < priv->error->elem_len; i++)
1217 len += snprintf(buf + len, PAGE_SIZE - len,
1218 "\n%08X%08X%08X%08X%08X%08X%08X",
1219 priv->error->elem[i].time,
1220 priv->error->elem[i].desc,
1221 priv->error->elem[i].blink1,
1222 priv->error->elem[i].blink2,
1223 priv->error->elem[i].link1,
1224 priv->error->elem[i].link2,
1225 priv->error->elem[i].data);
1227 len += snprintf(buf + len, PAGE_SIZE - len,
1228 "\n%08X", priv->error->log_len);
1229 for (i = 0; i < priv->error->log_len; i++)
1230 len += snprintf(buf + len, PAGE_SIZE - len,
1232 priv->error->log[i].time,
1233 priv->error->log[i].event,
1234 priv->error->log[i].data);
1235 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1239 static ssize_t clear_error(struct device *d,
1240 struct device_attribute *attr,
1241 const char *buf, size_t count)
1243 struct ipw_priv *priv = dev_get_drvdata(d);
1245 ipw_free_error_log(priv->error);
1251 static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1253 static ssize_t show_cmd_log(struct device *d,
1254 struct device_attribute *attr, char *buf)
1256 struct ipw_priv *priv = dev_get_drvdata(d);
1260 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1261 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1262 i = (i + 1) % priv->cmdlog_len) {
1264 snprintf(buf + len, PAGE_SIZE - len,
1265 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1266 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1267 priv->cmdlog[i].cmd.len);
1269 snprintk_buf(buf + len, PAGE_SIZE - len,
1270 (u8 *) priv->cmdlog[i].cmd.param,
1271 priv->cmdlog[i].cmd.len);
1272 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1274 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1278 static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1280 #ifdef CONFIG_IPW2200_PROMISCUOUS
1281 static void ipw_prom_free(struct ipw_priv *priv);
1282 static int ipw_prom_alloc(struct ipw_priv *priv);
1283 static ssize_t store_rtap_iface(struct device *d,
1284 struct device_attribute *attr,
1285 const char *buf, size_t count)
1287 struct ipw_priv *priv = dev_get_drvdata(d);
1298 if (netif_running(priv->prom_net_dev)) {
1299 IPW_WARNING("Interface is up. Cannot unregister.\n");
1303 ipw_prom_free(priv);
1311 rc = ipw_prom_alloc(priv);
1321 IPW_ERROR("Failed to register promiscuous network "
1322 "device (error %d).\n", rc);
1328 static ssize_t show_rtap_iface(struct device *d,
1329 struct device_attribute *attr,
1332 struct ipw_priv *priv = dev_get_drvdata(d);
1334 return sprintf(buf, "%s", priv->prom_net_dev->name);
1343 static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1346 static ssize_t store_rtap_filter(struct device *d,
1347 struct device_attribute *attr,
1348 const char *buf, size_t count)
1350 struct ipw_priv *priv = dev_get_drvdata(d);
1352 if (!priv->prom_priv) {
1353 IPW_ERROR("Attempting to set filter without "
1354 "rtap_iface enabled.\n");
1358 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1360 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1361 BIT_ARG16(priv->prom_priv->filter));
1366 static ssize_t show_rtap_filter(struct device *d,
1367 struct device_attribute *attr,
1370 struct ipw_priv *priv = dev_get_drvdata(d);
1371 return sprintf(buf, "0x%04X",
1372 priv->prom_priv ? priv->prom_priv->filter : 0);
1375 static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1379 static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1382 struct ipw_priv *priv = dev_get_drvdata(d);
1383 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1386 static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1387 const char *buf, size_t count)
1389 struct ipw_priv *priv = dev_get_drvdata(d);
1390 #ifdef CONFIG_IPW2200_DEBUG
1391 struct net_device *dev = priv->net_dev;
1393 char buffer[] = "00000000";
1395 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1399 IPW_DEBUG_INFO("enter\n");
1401 strncpy(buffer, buf, len);
1404 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1406 if (p[0] == 'x' || p[0] == 'X')
1408 val = simple_strtoul(p, &p, 16);
1410 val = simple_strtoul(p, &p, 10);
1412 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1414 priv->ieee->scan_age = val;
1415 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1418 IPW_DEBUG_INFO("exit\n");
1422 static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1424 static ssize_t show_led(struct device *d, struct device_attribute *attr,
1427 struct ipw_priv *priv = dev_get_drvdata(d);
1428 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1431 static ssize_t store_led(struct device *d, struct device_attribute *attr,
1432 const char *buf, size_t count)
1434 struct ipw_priv *priv = dev_get_drvdata(d);
1436 IPW_DEBUG_INFO("enter\n");
1442 IPW_DEBUG_LED("Disabling LED control.\n");
1443 priv->config |= CFG_NO_LED;
1444 ipw_led_shutdown(priv);
1446 IPW_DEBUG_LED("Enabling LED control.\n");
1447 priv->config &= ~CFG_NO_LED;
1451 IPW_DEBUG_INFO("exit\n");
1455 static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1457 static ssize_t show_status(struct device *d,
1458 struct device_attribute *attr, char *buf)
1460 struct ipw_priv *p = d->driver_data;
1461 return sprintf(buf, "0x%08x\n", (int)p->status);
1464 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1466 static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1469 struct ipw_priv *p = d->driver_data;
1470 return sprintf(buf, "0x%08x\n", (int)p->config);
1473 static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1475 static ssize_t show_nic_type(struct device *d,
1476 struct device_attribute *attr, char *buf)
1478 struct ipw_priv *priv = d->driver_data;
1479 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
1482 static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1484 static ssize_t show_ucode_version(struct device *d,
1485 struct device_attribute *attr, char *buf)
1487 u32 len = sizeof(u32), tmp = 0;
1488 struct ipw_priv *p = d->driver_data;
1490 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
1493 return sprintf(buf, "0x%08x\n", tmp);
1496 static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
1498 static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1501 u32 len = sizeof(u32), tmp = 0;
1502 struct ipw_priv *p = d->driver_data;
1504 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
1507 return sprintf(buf, "0x%08x\n", tmp);
1510 static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
1513 * Add a device attribute to view/control the delay between eeprom
1516 static ssize_t show_eeprom_delay(struct device *d,
1517 struct device_attribute *attr, char *buf)
1519 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
1520 return sprintf(buf, "%i\n", n);
1522 static ssize_t store_eeprom_delay(struct device *d,
1523 struct device_attribute *attr,
1524 const char *buf, size_t count)
1526 struct ipw_priv *p = d->driver_data;
1527 sscanf(buf, "%i", &p->eeprom_delay);
1528 return strnlen(buf, count);
1531 static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1532 show_eeprom_delay, store_eeprom_delay);
1534 static ssize_t show_command_event_reg(struct device *d,
1535 struct device_attribute *attr, char *buf)
1538 struct ipw_priv *p = d->driver_data;
1540 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
1541 return sprintf(buf, "0x%08x\n", reg);
1543 static ssize_t store_command_event_reg(struct device *d,
1544 struct device_attribute *attr,
1545 const char *buf, size_t count)
1548 struct ipw_priv *p = d->driver_data;
1550 sscanf(buf, "%x", ®);
1551 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
1552 return strnlen(buf, count);
1555 static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1556 show_command_event_reg, store_command_event_reg);
1558 static ssize_t show_mem_gpio_reg(struct device *d,
1559 struct device_attribute *attr, char *buf)
1562 struct ipw_priv *p = d->driver_data;
1564 reg = ipw_read_reg32(p, 0x301100);
1565 return sprintf(buf, "0x%08x\n", reg);
1567 static ssize_t store_mem_gpio_reg(struct device *d,
1568 struct device_attribute *attr,
1569 const char *buf, size_t count)
1572 struct ipw_priv *p = d->driver_data;
1574 sscanf(buf, "%x", ®);
1575 ipw_write_reg32(p, 0x301100, reg);
1576 return strnlen(buf, count);
1579 static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1580 show_mem_gpio_reg, store_mem_gpio_reg);
1582 static ssize_t show_indirect_dword(struct device *d,
1583 struct device_attribute *attr, char *buf)
1586 struct ipw_priv *priv = d->driver_data;
1588 if (priv->status & STATUS_INDIRECT_DWORD)
1589 reg = ipw_read_reg32(priv, priv->indirect_dword);
1593 return sprintf(buf, "0x%08x\n", reg);
1595 static ssize_t store_indirect_dword(struct device *d,
1596 struct device_attribute *attr,
1597 const char *buf, size_t count)
1599 struct ipw_priv *priv = d->driver_data;
1601 sscanf(buf, "%x", &priv->indirect_dword);
1602 priv->status |= STATUS_INDIRECT_DWORD;
1603 return strnlen(buf, count);
1606 static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1607 show_indirect_dword, store_indirect_dword);
1609 static ssize_t show_indirect_byte(struct device *d,
1610 struct device_attribute *attr, char *buf)
1613 struct ipw_priv *priv = d->driver_data;
1615 if (priv->status & STATUS_INDIRECT_BYTE)
1616 reg = ipw_read_reg8(priv, priv->indirect_byte);
1620 return sprintf(buf, "0x%02x\n", reg);
1622 static ssize_t store_indirect_byte(struct device *d,
1623 struct device_attribute *attr,
1624 const char *buf, size_t count)
1626 struct ipw_priv *priv = d->driver_data;
1628 sscanf(buf, "%x", &priv->indirect_byte);
1629 priv->status |= STATUS_INDIRECT_BYTE;
1630 return strnlen(buf, count);
1633 static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
1634 show_indirect_byte, store_indirect_byte);
1636 static ssize_t show_direct_dword(struct device *d,
1637 struct device_attribute *attr, char *buf)
1640 struct ipw_priv *priv = d->driver_data;
1642 if (priv->status & STATUS_DIRECT_DWORD)
1643 reg = ipw_read32(priv, priv->direct_dword);
1647 return sprintf(buf, "0x%08x\n", reg);
1649 static ssize_t store_direct_dword(struct device *d,
1650 struct device_attribute *attr,
1651 const char *buf, size_t count)
1653 struct ipw_priv *priv = d->driver_data;
1655 sscanf(buf, "%x", &priv->direct_dword);
1656 priv->status |= STATUS_DIRECT_DWORD;
1657 return strnlen(buf, count);
1660 static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1661 show_direct_dword, store_direct_dword);
1663 static int rf_kill_active(struct ipw_priv *priv)
1665 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1666 priv->status |= STATUS_RF_KILL_HW;
1668 priv->status &= ~STATUS_RF_KILL_HW;
1670 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1673 static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
1676 /* 0 - RF kill not enabled
1677 1 - SW based RF kill active (sysfs)
1678 2 - HW based RF kill active
1679 3 - Both HW and SW baed RF kill active */
1680 struct ipw_priv *priv = d->driver_data;
1681 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
1682 (rf_kill_active(priv) ? 0x2 : 0x0);
1683 return sprintf(buf, "%i\n", val);
1686 static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1688 if ((disable_radio ? 1 : 0) ==
1689 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
1692 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1693 disable_radio ? "OFF" : "ON");
1695 if (disable_radio) {
1696 priv->status |= STATUS_RF_KILL_SW;
1698 if (priv->workqueue)
1699 cancel_delayed_work(&priv->request_scan);
1700 queue_work(priv->workqueue, &priv->down);
1702 priv->status &= ~STATUS_RF_KILL_SW;
1703 if (rf_kill_active(priv)) {
1704 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1705 "disabled by HW switch\n");
1706 /* Make sure the RF_KILL check timer is running */
1707 cancel_delayed_work(&priv->rf_kill);
1708 queue_delayed_work(priv->workqueue, &priv->rf_kill,
1711 queue_work(priv->workqueue, &priv->up);
1717 static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1718 const char *buf, size_t count)
1720 struct ipw_priv *priv = d->driver_data;
1722 ipw_radio_kill_sw(priv, buf[0] == '1');
1727 static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
1729 static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1732 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1733 int pos = 0, len = 0;
1734 if (priv->config & CFG_SPEED_SCAN) {
1735 while (priv->speed_scan[pos] != 0)
1736 len += sprintf(&buf[len], "%d ",
1737 priv->speed_scan[pos++]);
1738 return len + sprintf(&buf[len], "\n");
1741 return sprintf(buf, "0\n");
1744 static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1745 const char *buf, size_t count)
1747 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1748 int channel, pos = 0;
1749 const char *p = buf;
1751 /* list of space separated channels to scan, optionally ending with 0 */
1752 while ((channel = simple_strtol(p, NULL, 0))) {
1753 if (pos == MAX_SPEED_SCAN - 1) {
1754 priv->speed_scan[pos] = 0;
1758 if (ieee80211_is_valid_channel(priv->ieee, channel))
1759 priv->speed_scan[pos++] = channel;
1761 IPW_WARNING("Skipping invalid channel request: %d\n",
1766 while (*p == ' ' || *p == '\t')
1771 priv->config &= ~CFG_SPEED_SCAN;
1773 priv->speed_scan_pos = 0;
1774 priv->config |= CFG_SPEED_SCAN;
1780 static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1783 static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1786 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1787 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1790 static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1791 const char *buf, size_t count)
1793 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1795 priv->config |= CFG_NET_STATS;
1797 priv->config &= ~CFG_NET_STATS;
1802 static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1803 show_net_stats, store_net_stats);
1805 static void notify_wx_assoc_event(struct ipw_priv *priv)
1807 union iwreq_data wrqu;
1808 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1809 if (priv->status & STATUS_ASSOCIATED)
1810 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1812 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1813 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1816 static void ipw_irq_tasklet(struct ipw_priv *priv)
1818 u32 inta, inta_mask, handled = 0;
1819 unsigned long flags;
1822 spin_lock_irqsave(&priv->lock, flags);
1824 inta = ipw_read32(priv, IPW_INTA_RW);
1825 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1826 inta &= (IPW_INTA_MASK_ALL & inta_mask);
1828 /* Add any cached INTA values that need to be handled */
1829 inta |= priv->isr_inta;
1831 /* handle all the justifications for the interrupt */
1832 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
1834 handled |= IPW_INTA_BIT_RX_TRANSFER;
1837 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
1838 IPW_DEBUG_HC("Command completed.\n");
1839 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
1840 priv->status &= ~STATUS_HCMD_ACTIVE;
1841 wake_up_interruptible(&priv->wait_command_queue);
1842 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
1845 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
1846 IPW_DEBUG_TX("TX_QUEUE_1\n");
1847 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
1848 handled |= IPW_INTA_BIT_TX_QUEUE_1;
1851 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
1852 IPW_DEBUG_TX("TX_QUEUE_2\n");
1853 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
1854 handled |= IPW_INTA_BIT_TX_QUEUE_2;
1857 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
1858 IPW_DEBUG_TX("TX_QUEUE_3\n");
1859 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
1860 handled |= IPW_INTA_BIT_TX_QUEUE_3;
1863 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
1864 IPW_DEBUG_TX("TX_QUEUE_4\n");
1865 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
1866 handled |= IPW_INTA_BIT_TX_QUEUE_4;
1869 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
1870 IPW_WARNING("STATUS_CHANGE\n");
1871 handled |= IPW_INTA_BIT_STATUS_CHANGE;
1874 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
1875 IPW_WARNING("TX_PERIOD_EXPIRED\n");
1876 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
1879 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
1880 IPW_WARNING("HOST_CMD_DONE\n");
1881 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
1884 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
1885 IPW_WARNING("FW_INITIALIZATION_DONE\n");
1886 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
1889 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
1890 IPW_WARNING("PHY_OFF_DONE\n");
1891 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
1894 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
1895 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1896 priv->status |= STATUS_RF_KILL_HW;
1897 wake_up_interruptible(&priv->wait_command_queue);
1898 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1899 cancel_delayed_work(&priv->request_scan);
1900 schedule_work(&priv->link_down);
1901 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
1902 handled |= IPW_INTA_BIT_RF_KILL_DONE;
1905 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
1906 IPW_WARNING("Firmware error detected. Restarting.\n");
1908 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
1909 #ifdef CONFIG_IPW2200_DEBUG
1910 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1911 struct ipw_fw_error *error =
1912 ipw_alloc_error_log(priv);
1913 ipw_dump_error_log(priv, error);
1915 ipw_free_error_log(error);
1919 priv->error = ipw_alloc_error_log(priv);
1921 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
1923 IPW_DEBUG_FW("Error allocating sysfs 'error' "
1925 #ifdef CONFIG_IPW2200_DEBUG
1926 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1927 ipw_dump_error_log(priv, priv->error);
1931 /* XXX: If hardware encryption is for WPA/WPA2,
1932 * we have to notify the supplicant. */
1933 if (priv->ieee->sec.encrypt) {
1934 priv->status &= ~STATUS_ASSOCIATED;
1935 notify_wx_assoc_event(priv);
1938 /* Keep the restart process from trying to send host
1939 * commands by clearing the INIT status bit */
1940 priv->status &= ~STATUS_INIT;
1942 /* Cancel currently queued command. */
1943 priv->status &= ~STATUS_HCMD_ACTIVE;
1944 wake_up_interruptible(&priv->wait_command_queue);
1946 queue_work(priv->workqueue, &priv->adapter_restart);
1947 handled |= IPW_INTA_BIT_FATAL_ERROR;
1950 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
1951 IPW_ERROR("Parity error\n");
1952 handled |= IPW_INTA_BIT_PARITY_ERROR;
1955 if (handled != inta) {
1956 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
1959 /* enable all interrupts */
1960 ipw_enable_interrupts(priv);
1962 spin_unlock_irqrestore(&priv->lock, flags);
1965 #define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1966 static char *get_cmd_string(u8 cmd)
1969 IPW_CMD(HOST_COMPLETE);
1970 IPW_CMD(POWER_DOWN);
1971 IPW_CMD(SYSTEM_CONFIG);
1972 IPW_CMD(MULTICAST_ADDRESS);
1974 IPW_CMD(ADAPTER_ADDRESS);
1976 IPW_CMD(RTS_THRESHOLD);
1977 IPW_CMD(FRAG_THRESHOLD);
1978 IPW_CMD(POWER_MODE);
1980 IPW_CMD(TGI_TX_KEY);
1981 IPW_CMD(SCAN_REQUEST);
1982 IPW_CMD(SCAN_REQUEST_EXT);
1984 IPW_CMD(SUPPORTED_RATES);
1985 IPW_CMD(SCAN_ABORT);
1987 IPW_CMD(QOS_PARAMETERS);
1988 IPW_CMD(DINO_CONFIG);
1989 IPW_CMD(RSN_CAPABILITIES);
1991 IPW_CMD(CARD_DISABLE);
1992 IPW_CMD(SEED_NUMBER);
1994 IPW_CMD(COUNTRY_INFO);
1995 IPW_CMD(AIRONET_INFO);
1996 IPW_CMD(AP_TX_POWER);
1998 IPW_CMD(CCX_VER_INFO);
1999 IPW_CMD(SET_CALIBRATION);
2000 IPW_CMD(SENSITIVITY_CALIB);
2001 IPW_CMD(RETRY_LIMIT);
2002 IPW_CMD(IPW_PRE_POWER_DOWN);
2003 IPW_CMD(VAP_BEACON_TEMPLATE);
2004 IPW_CMD(VAP_DTIM_PERIOD);
2005 IPW_CMD(EXT_SUPPORTED_RATES);
2006 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2007 IPW_CMD(VAP_QUIET_INTERVALS);
2008 IPW_CMD(VAP_CHANNEL_SWITCH);
2009 IPW_CMD(VAP_MANDATORY_CHANNELS);
2010 IPW_CMD(VAP_CELL_PWR_LIMIT);
2011 IPW_CMD(VAP_CF_PARAM_SET);
2012 IPW_CMD(VAP_SET_BEACONING_STATE);
2013 IPW_CMD(MEASUREMENT);
2014 IPW_CMD(POWER_CAPABILITY);
2015 IPW_CMD(SUPPORTED_CHANNELS);
2016 IPW_CMD(TPC_REPORT);
2018 IPW_CMD(PRODUCTION_COMMAND);
2024 #define HOST_COMPLETE_TIMEOUT HZ
2026 static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
2029 unsigned long flags;
2031 spin_lock_irqsave(&priv->lock, flags);
2032 if (priv->status & STATUS_HCMD_ACTIVE) {
2033 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2034 get_cmd_string(cmd->cmd));
2035 spin_unlock_irqrestore(&priv->lock, flags);
2039 priv->status |= STATUS_HCMD_ACTIVE;
2042 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2043 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2044 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2045 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2047 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2050 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2051 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2054 #ifndef DEBUG_CMD_WEP_KEY
2055 if (cmd->cmd == IPW_CMD_WEP_KEY)
2056 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2059 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2061 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
2063 priv->status &= ~STATUS_HCMD_ACTIVE;
2064 IPW_ERROR("Failed to send %s: Reason %d\n",
2065 get_cmd_string(cmd->cmd), rc);
2066 spin_unlock_irqrestore(&priv->lock, flags);
2069 spin_unlock_irqrestore(&priv->lock, flags);
2071 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2073 status & STATUS_HCMD_ACTIVE),
2074 HOST_COMPLETE_TIMEOUT);
2076 spin_lock_irqsave(&priv->lock, flags);
2077 if (priv->status & STATUS_HCMD_ACTIVE) {
2078 IPW_ERROR("Failed to send %s: Command timed out.\n",
2079 get_cmd_string(cmd->cmd));
2080 priv->status &= ~STATUS_HCMD_ACTIVE;
2081 spin_unlock_irqrestore(&priv->lock, flags);
2085 spin_unlock_irqrestore(&priv->lock, flags);
2089 if (priv->status & STATUS_RF_KILL_HW) {
2090 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2091 get_cmd_string(cmd->cmd));
2098 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2099 priv->cmdlog_pos %= priv->cmdlog_len;
2104 static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
2106 struct host_cmd cmd = {
2110 return __ipw_send_cmd(priv, &cmd);
2113 static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2116 struct host_cmd cmd = {
2122 return __ipw_send_cmd(priv, &cmd);
2125 static int ipw_send_host_complete(struct ipw_priv *priv)
2128 IPW_ERROR("Invalid args\n");
2132 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
2135 static int ipw_send_system_config(struct ipw_priv *priv)
2137 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2138 sizeof(priv->sys_config),
2142 static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
2144 if (!priv || !ssid) {
2145 IPW_ERROR("Invalid args\n");
2149 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
2153 static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
2155 if (!priv || !mac) {
2156 IPW_ERROR("Invalid args\n");
2160 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2161 priv->net_dev->name, MAC_ARG(mac));
2163 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
2167 * NOTE: This must be executed from our workqueue as it results in udelay
2168 * being called which may corrupt the keyboard if executed on default
2171 static void ipw_adapter_restart(void *adapter)
2173 struct ipw_priv *priv = adapter;
2175 if (priv->status & STATUS_RF_KILL_MASK)
2180 if (priv->assoc_network &&
2181 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2182 ipw_remove_current_network(priv);
2185 IPW_ERROR("Failed to up device\n");
2190 static void ipw_bg_adapter_restart(void *data)
2192 struct ipw_priv *priv = data;
2193 mutex_lock(&priv->mutex);
2194 ipw_adapter_restart(data);
2195 mutex_unlock(&priv->mutex);
2198 #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2200 static void ipw_scan_check(void *data)
2202 struct ipw_priv *priv = data;
2203 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2204 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
2205 "adapter after (%dms).\n",
2206 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
2207 queue_work(priv->workqueue, &priv->adapter_restart);
2211 static void ipw_bg_scan_check(void *data)
2213 struct ipw_priv *priv = data;
2214 mutex_lock(&priv->mutex);
2215 ipw_scan_check(data);
2216 mutex_unlock(&priv->mutex);
2219 static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2220 struct ipw_scan_request_ext *request)
2222 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
2223 sizeof(*request), request);
2226 static int ipw_send_scan_abort(struct ipw_priv *priv)
2229 IPW_ERROR("Invalid args\n");
2233 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
2236 static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2238 struct ipw_sensitivity_calib calib = {
2239 .beacon_rssi_raw = sens,
2242 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
2246 static int ipw_send_associate(struct ipw_priv *priv,
2247 struct ipw_associate *associate)
2249 struct ipw_associate tmp_associate;
2251 if (!priv || !associate) {
2252 IPW_ERROR("Invalid args\n");
2256 memcpy(&tmp_associate, associate, sizeof(*associate));
2257 tmp_associate.policy_support =
2258 cpu_to_le16(tmp_associate.policy_support);
2259 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2260 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2261 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2262 tmp_associate.listen_interval =
2263 cpu_to_le16(tmp_associate.listen_interval);
2264 tmp_associate.beacon_interval =
2265 cpu_to_le16(tmp_associate.beacon_interval);
2266 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2268 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
2272 static int ipw_send_supported_rates(struct ipw_priv *priv,
2273 struct ipw_supported_rates *rates)
2275 if (!priv || !rates) {
2276 IPW_ERROR("Invalid args\n");
2280 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
2284 static int ipw_set_random_seed(struct ipw_priv *priv)
2289 IPW_ERROR("Invalid args\n");
2293 get_random_bytes(&val, sizeof(val));
2295 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
2298 static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2301 IPW_ERROR("Invalid args\n");
2305 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off),
2309 static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
2311 if (!priv || !power) {
2312 IPW_ERROR("Invalid args\n");
2316 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
2319 static int ipw_set_tx_power(struct ipw_priv *priv)
2321 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
2322 struct ipw_tx_power tx_power;
2326 memset(&tx_power, 0, sizeof(tx_power));
2328 /* configure device for 'G' band */
2329 tx_power.ieee_mode = IPW_G_MODE;
2330 tx_power.num_channels = geo->bg_channels;
2331 for (i = 0; i < geo->bg_channels; i++) {
2332 max_power = geo->bg[i].max_power;
2333 tx_power.channels_tx_power[i].channel_number =
2335 tx_power.channels_tx_power[i].tx_power = max_power ?
2336 min(max_power, priv->tx_power) : priv->tx_power;
2338 if (ipw_send_tx_power(priv, &tx_power))
2341 /* configure device to also handle 'B' band */
2342 tx_power.ieee_mode = IPW_B_MODE;
2343 if (ipw_send_tx_power(priv, &tx_power))
2346 /* configure device to also handle 'A' band */
2347 if (priv->ieee->abg_true) {
2348 tx_power.ieee_mode = IPW_A_MODE;
2349 tx_power.num_channels = geo->a_channels;
2350 for (i = 0; i < tx_power.num_channels; i++) {
2351 max_power = geo->a[i].max_power;
2352 tx_power.channels_tx_power[i].channel_number =
2354 tx_power.channels_tx_power[i].tx_power = max_power ?
2355 min(max_power, priv->tx_power) : priv->tx_power;
2357 if (ipw_send_tx_power(priv, &tx_power))
2363 static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2365 struct ipw_rts_threshold rts_threshold = {
2366 .rts_threshold = rts,
2370 IPW_ERROR("Invalid args\n");
2374 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2375 sizeof(rts_threshold), &rts_threshold);
2378 static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2380 struct ipw_frag_threshold frag_threshold = {
2381 .frag_threshold = frag,
2385 IPW_ERROR("Invalid args\n");
2389 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2390 sizeof(frag_threshold), &frag_threshold);
2393 static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2398 IPW_ERROR("Invalid args\n");
2402 /* If on battery, set to 3, if AC set to CAM, else user
2405 case IPW_POWER_BATTERY:
2406 param = IPW_POWER_INDEX_3;
2409 param = IPW_POWER_MODE_CAM;
2416 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
2420 static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2422 struct ipw_retry_limit retry_limit = {
2423 .short_retry_limit = slimit,
2424 .long_retry_limit = llimit
2428 IPW_ERROR("Invalid args\n");
2432 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
2437 * The IPW device contains a Microwire compatible EEPROM that stores
2438 * various data like the MAC address. Usually the firmware has exclusive
2439 * access to the eeprom, but during device initialization (before the
2440 * device driver has sent the HostComplete command to the firmware) the
2441 * device driver has read access to the EEPROM by way of indirect addressing
2442 * through a couple of memory mapped registers.
2444 * The following is a simplified implementation for pulling data out of the
2445 * the eeprom, along with some helper functions to find information in
2446 * the per device private data's copy of the eeprom.
2448 * NOTE: To better understand how these functions work (i.e what is a chip
2449 * select and why do have to keep driving the eeprom clock?), read
2450 * just about any data sheet for a Microwire compatible EEPROM.
2453 /* write a 32 bit value into the indirect accessor register */
2454 static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2456 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
2458 /* the eeprom requires some time to complete the operation */
2459 udelay(p->eeprom_delay);
2464 /* perform a chip select operation */
2465 static void eeprom_cs(struct ipw_priv *priv)
2467 eeprom_write_reg(priv, 0);
2468 eeprom_write_reg(priv, EEPROM_BIT_CS);
2469 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2470 eeprom_write_reg(priv, EEPROM_BIT_CS);
2473 /* perform a chip select operation */
2474 static void eeprom_disable_cs(struct ipw_priv *priv)
2476 eeprom_write_reg(priv, EEPROM_BIT_CS);
2477 eeprom_write_reg(priv, 0);
2478 eeprom_write_reg(priv, EEPROM_BIT_SK);
2481 /* push a single bit down to the eeprom */
2482 static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
2484 int d = (bit ? EEPROM_BIT_DI : 0);
2485 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2486 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
2489 /* push an opcode followed by an address down to the eeprom */
2490 static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
2495 eeprom_write_bit(priv, 1);
2496 eeprom_write_bit(priv, op & 2);
2497 eeprom_write_bit(priv, op & 1);
2498 for (i = 7; i >= 0; i--) {
2499 eeprom_write_bit(priv, addr & (1 << i));
2503 /* pull 16 bits off the eeprom, one bit at a time */
2504 static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
2509 /* Send READ Opcode */
2510 eeprom_op(priv, EEPROM_CMD_READ, addr);
2512 /* Send dummy bit */
2513 eeprom_write_reg(priv, EEPROM_BIT_CS);
2515 /* Read the byte off the eeprom one bit at a time */
2516 for (i = 0; i < 16; i++) {
2518 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2519 eeprom_write_reg(priv, EEPROM_BIT_CS);
2520 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2521 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
2524 /* Send another dummy bit */
2525 eeprom_write_reg(priv, 0);
2526 eeprom_disable_cs(priv);
2531 /* helper function for pulling the mac address out of the private */
2532 /* data's copy of the eeprom data */
2533 static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
2535 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
2539 * Either the device driver (i.e. the host) or the firmware can
2540 * load eeprom data into the designated region in SRAM. If neither
2541 * happens then the FW will shutdown with a fatal error.
2543 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2544 * bit needs region of shared SRAM needs to be non-zero.
2546 static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2549 u16 *eeprom = (u16 *) priv->eeprom;
2551 IPW_DEBUG_TRACE(">>\n");
2553 /* read entire contents of eeprom into private buffer */
2554 for (i = 0; i < 128; i++)
2555 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
2558 If the data looks correct, then copy it to our private
2559 copy. Otherwise let the firmware know to perform the operation
2562 if (priv->eeprom[EEPROM_VERSION] != 0) {
2563 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2565 /* write the eeprom data to sram */
2566 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
2567 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
2569 /* Do not load eeprom data on fatal error or suspend */
2570 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2572 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2574 /* Load eeprom data on fatal error or suspend */
2575 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2578 IPW_DEBUG_TRACE("<<\n");
2581 static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
2586 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
2588 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
2591 static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2593 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
2594 CB_NUMBER_OF_ELEMENTS_SMALL *
2595 sizeof(struct command_block));
2598 static int ipw_fw_dma_enable(struct ipw_priv *priv)
2599 { /* start dma engine but no transfers yet */
2601 IPW_DEBUG_FW(">> : \n");
2604 ipw_fw_dma_reset_command_blocks(priv);
2606 /* Write CB base address */
2607 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
2609 IPW_DEBUG_FW("<< : \n");
2613 static void ipw_fw_dma_abort(struct ipw_priv *priv)
2617 IPW_DEBUG_FW(">> :\n");
2619 //set the Stop and Abort bit
2620 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
2621 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2622 priv->sram_desc.last_cb_index = 0;
2624 IPW_DEBUG_FW("<< \n");
2627 static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2628 struct command_block *cb)
2631 IPW_SHARED_SRAM_DMA_CONTROL +
2632 (sizeof(struct command_block) * index);
2633 IPW_DEBUG_FW(">> :\n");
2635 ipw_write_indirect(priv, address, (u8 *) cb,
2636 (int)sizeof(struct command_block));
2638 IPW_DEBUG_FW("<< :\n");
2643 static int ipw_fw_dma_kick(struct ipw_priv *priv)
2648 IPW_DEBUG_FW(">> :\n");
2650 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
2651 ipw_fw_dma_write_command_block(priv, index,
2652 &priv->sram_desc.cb_list[index]);
2654 /* Enable the DMA in the CSR register */
2655 ipw_clear_bit(priv, IPW_RESET_REG,
2656 IPW_RESET_REG_MASTER_DISABLED |
2657 IPW_RESET_REG_STOP_MASTER);
2659 /* Set the Start bit. */
2660 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
2661 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2663 IPW_DEBUG_FW("<< :\n");
2667 static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2670 u32 register_value = 0;
2671 u32 cb_fields_address = 0;
2673 IPW_DEBUG_FW(">> :\n");
2674 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2675 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
2677 /* Read the DMA Controlor register */
2678 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2679 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
2681 /* Print the CB values */
2682 cb_fields_address = address;
2683 register_value = ipw_read_reg32(priv, cb_fields_address);
2684 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
2686 cb_fields_address += sizeof(u32);
2687 register_value = ipw_read_reg32(priv, cb_fields_address);
2688 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
2690 cb_fields_address += sizeof(u32);
2691 register_value = ipw_read_reg32(priv, cb_fields_address);
2692 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2695 cb_fields_address += sizeof(u32);
2696 register_value = ipw_read_reg32(priv, cb_fields_address);
2697 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
2699 IPW_DEBUG_FW(">> :\n");
2702 static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2704 u32 current_cb_address = 0;
2705 u32 current_cb_index = 0;
2707 IPW_DEBUG_FW("<< :\n");
2708 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2710 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
2711 sizeof(struct command_block);
2713 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
2714 current_cb_index, current_cb_address);
2716 IPW_DEBUG_FW(">> :\n");
2717 return current_cb_index;
2721 static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2725 int interrupt_enabled, int is_last)
2728 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
2729 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2731 struct command_block *cb;
2732 u32 last_cb_element = 0;
2734 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2735 src_address, dest_address, length);
2737 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2740 last_cb_element = priv->sram_desc.last_cb_index;
2741 cb = &priv->sram_desc.cb_list[last_cb_element];
2742 priv->sram_desc.last_cb_index++;
2744 /* Calculate the new CB control word */
2745 if (interrupt_enabled)
2746 control |= CB_INT_ENABLED;
2749 control |= CB_LAST_VALID;
2753 /* Calculate the CB Element's checksum value */
2754 cb->status = control ^ src_address ^ dest_address;
2756 /* Copy the Source and Destination addresses */
2757 cb->dest_addr = dest_address;
2758 cb->source_addr = src_address;
2760 /* Copy the Control Word last */
2761 cb->control = control;
2766 static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
2767 u32 src_phys, u32 dest_address, u32 length)
2769 u32 bytes_left = length;
2771 u32 dest_offset = 0;
2773 IPW_DEBUG_FW(">> \n");
2774 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2775 src_phys, dest_address, length);
2776 while (bytes_left > CB_MAX_LENGTH) {
2777 status = ipw_fw_dma_add_command_block(priv,
2778 src_phys + src_offset,
2781 CB_MAX_LENGTH, 0, 0);
2783 IPW_DEBUG_FW_INFO(": Failed\n");
2786 IPW_DEBUG_FW_INFO(": Added new cb\n");
2788 src_offset += CB_MAX_LENGTH;
2789 dest_offset += CB_MAX_LENGTH;
2790 bytes_left -= CB_MAX_LENGTH;
2793 /* add the buffer tail */
2794 if (bytes_left > 0) {
2796 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2797 dest_address + dest_offset,
2800 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2804 (": Adding new cb - the buffer tail\n");
2807 IPW_DEBUG_FW("<< \n");
2811 static int ipw_fw_dma_wait(struct ipw_priv *priv)
2813 u32 current_index = 0, previous_index;
2816 IPW_DEBUG_FW(">> : \n");
2818 current_index = ipw_fw_dma_command_block_index(priv);
2819 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
2820 (int)priv->sram_desc.last_cb_index);
2822 while (current_index < priv->sram_desc.last_cb_index) {
2824 previous_index = current_index;
2825 current_index = ipw_fw_dma_command_block_index(priv);
2827 if (previous_index < current_index) {
2831 if (++watchdog > 400) {
2832 IPW_DEBUG_FW_INFO("Timeout\n");
2833 ipw_fw_dma_dump_command_block(priv);
2834 ipw_fw_dma_abort(priv);
2839 ipw_fw_dma_abort(priv);
2841 /*Disable the DMA in the CSR register */
2842 ipw_set_bit(priv, IPW_RESET_REG,
2843 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
2845 IPW_DEBUG_FW("<< dmaWaitSync \n");
2849 static void ipw_remove_current_network(struct ipw_priv *priv)
2851 struct list_head *element, *safe;
2852 struct ieee80211_network *network = NULL;
2853 unsigned long flags;
2855 spin_lock_irqsave(&priv->ieee->lock, flags);
2856 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2857 network = list_entry(element, struct ieee80211_network, list);
2858 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2860 list_add_tail(&network->list,
2861 &priv->ieee->network_free_list);
2864 spin_unlock_irqrestore(&priv->ieee->lock, flags);
2868 * Check that card is still alive.
2869 * Reads debug register from domain0.
2870 * If card is present, pre-defined value should
2874 * @return 1 if card is present, 0 otherwise
2876 static inline int ipw_alive(struct ipw_priv *priv)
2878 return ipw_read32(priv, 0x90) == 0xd55555d5;
2881 /* timeout in msec, attempted in 10-msec quanta */
2882 static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2888 if ((ipw_read32(priv, addr) & mask) == mask)
2892 } while (i < timeout);
2897 /* These functions load the firmware and micro code for the operation of
2898 * the ipw hardware. It assumes the buffer has all the bits for the
2899 * image and the caller is handling the memory allocation and clean up.
2902 static int ipw_stop_master(struct ipw_priv *priv)
2906 IPW_DEBUG_TRACE(">> \n");
2907 /* stop master. typical delay - 0 */
2908 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
2910 /* timeout is in msec, polled in 10-msec quanta */
2911 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2912 IPW_RESET_REG_MASTER_DISABLED, 100);
2914 IPW_ERROR("wait for stop master failed after 100ms\n");
2918 IPW_DEBUG_INFO("stop master %dms\n", rc);
2923 static void ipw_arc_release(struct ipw_priv *priv)
2925 IPW_DEBUG_TRACE(">> \n");
2928 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
2930 /* no one knows timing, for safety add some delay */
2939 static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
2941 int rc = 0, i, addr;
2945 image = (u16 *) data;
2947 IPW_DEBUG_TRACE(">> \n");
2949 rc = ipw_stop_master(priv);
2954 // spin_lock_irqsave(&priv->lock, flags);
2956 for (addr = IPW_SHARED_LOWER_BOUND;
2957 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
2958 ipw_write32(priv, addr, 0);
2961 /* no ucode (yet) */
2962 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2963 /* destroy DMA queues */
2964 /* reset sequence */
2966 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
2967 ipw_arc_release(priv);
2968 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
2972 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
2975 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
2978 /* enable ucode store */
2979 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
2980 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
2986 * Do NOT set indirect address register once and then
2987 * store data to indirect data register in the loop.
2988 * It seems very reasonable, but in this case DINO do not
2989 * accept ucode. It is essential to set address each time.
2991 /* load new ipw uCode */
2992 for (i = 0; i < len / 2; i++)
2993 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
2994 cpu_to_le16(image[i]));
2997 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2998 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
3000 /* this is where the igx / win driver deveates from the VAP driver. */
3002 /* wait for alive response */
3003 for (i = 0; i < 100; i++) {
3004 /* poll for incoming data */
3005 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
3006 if (cr & DINO_RXFIFO_DATA)
3011 if (cr & DINO_RXFIFO_DATA) {
3012 /* alive_command_responce size is NOT multiple of 4 */
3013 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
3015 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
3016 response_buffer[i] =
3017 le32_to_cpu(ipw_read_reg32(priv,
3018 IPW_BASEBAND_RX_FIFO_READ));
3019 memcpy(&priv->dino_alive, response_buffer,
3020 sizeof(priv->dino_alive));
3021 if (priv->dino_alive.alive_command == 1
3022 && priv->dino_alive.ucode_valid == 1) {
3025 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3026 "of %02d/%02d/%02d %02d:%02d\n",
3027 priv->dino_alive.software_revision,
3028 priv->dino_alive.software_revision,
3029 priv->dino_alive.device_identifier,
3030 priv->dino_alive.device_identifier,
3031 priv->dino_alive.time_stamp[0],
3032 priv->dino_alive.time_stamp[1],
3033 priv->dino_alive.time_stamp[2],
3034 priv->dino_alive.time_stamp[3],
3035 priv->dino_alive.time_stamp[4]);
3037 IPW_DEBUG_INFO("Microcode is not alive\n");
3041 IPW_DEBUG_INFO("No alive response from DINO\n");
3045 /* disable DINO, otherwise for some reason
3046 firmware have problem getting alive resp. */
3047 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3049 // spin_unlock_irqrestore(&priv->lock, flags);
3054 static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
3058 struct fw_chunk *chunk;
3059 dma_addr_t shared_phys;
3062 IPW_DEBUG_TRACE("<< : \n");
3063 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
3068 memmove(shared_virt, data, len);
3071 rc = ipw_fw_dma_enable(priv);
3073 if (priv->sram_desc.last_cb_index > 0) {
3074 /* the DMA is already ready this would be a bug. */
3080 chunk = (struct fw_chunk *)(data + offset);
3081 offset += sizeof(struct fw_chunk);
3082 /* build DMA packet and queue up for sending */
3083 /* dma to chunk->address, the chunk->length bytes from data +
3086 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
3087 le32_to_cpu(chunk->address),
3088 le32_to_cpu(chunk->length));
3090 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3094 offset += le32_to_cpu(chunk->length);
3095 } while (offset < len);
3097 /* Run the DMA and wait for the answer */
3098 rc = ipw_fw_dma_kick(priv);
3100 IPW_ERROR("dmaKick Failed\n");
3104 rc = ipw_fw_dma_wait(priv);
3106 IPW_ERROR("dmaWaitSync Failed\n");
3110 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
3115 static int ipw_stop_nic(struct ipw_priv *priv)
3120 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
3122 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3123 IPW_RESET_REG_MASTER_DISABLED, 500);
3125 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
3129 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
3134 static void ipw_start_nic(struct ipw_priv *priv)
3136 IPW_DEBUG_TRACE(">>\n");
3138 /* prvHwStartNic release ARC */
3139 ipw_clear_bit(priv, IPW_RESET_REG,
3140 IPW_RESET_REG_MASTER_DISABLED |
3141 IPW_RESET_REG_STOP_MASTER |
3142 CBD_RESET_REG_PRINCETON_RESET);
3144 /* enable power management */
3145 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3146 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
3148 IPW_DEBUG_TRACE("<<\n");
3151 static int ipw_init_nic(struct ipw_priv *priv)
3155 IPW_DEBUG_TRACE(">>\n");
3158 /* set "initialization complete" bit to move adapter to D0 state */
3159 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3161 /* low-level PLL activation */
3162 ipw_write32(priv, IPW_READ_INT_REGISTER,
3163 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
3165 /* wait for clock stabilization */
3166 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3167 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
3169 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3171 /* assert SW reset */
3172 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
3176 /* set "initialization complete" bit to move adapter to D0 state */
3177 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3179 IPW_DEBUG_TRACE(">>\n");
3183 /* Call this function from process context, it will sleep in request_firmware.
3184 * Probe is an ok place to call this from.
3186 static int ipw_reset_nic(struct ipw_priv *priv)
3189 unsigned long flags;
3191 IPW_DEBUG_TRACE(">>\n");
3193 rc = ipw_init_nic(priv);
3195 spin_lock_irqsave(&priv->lock, flags);
3196 /* Clear the 'host command active' bit... */
3197 priv->status &= ~STATUS_HCMD_ACTIVE;
3198 wake_up_interruptible(&priv->wait_command_queue);
3199 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3200 wake_up_interruptible(&priv->wait_state);
3201 spin_unlock_irqrestore(&priv->lock, flags);
3203 IPW_DEBUG_TRACE("<<\n");
3216 static int ipw_get_fw(struct ipw_priv *priv,
3217 const struct firmware **raw, const char *name)
3222 /* ask firmware_class module to get the boot firmware off disk */
3223 rc = request_firmware(raw, name, &priv->pci_dev->dev);
3225 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
3229 if ((*raw)->size < sizeof(*fw)) {
3230 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
3234 fw = (void *)(*raw)->data;
3236 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3237 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
3238 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3239 name, (*raw)->size);
3243 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
3245 le32_to_cpu(fw->ver) >> 16,
3246 le32_to_cpu(fw->ver) & 0xff,
3247 (*raw)->size - sizeof(*fw));
3251 #define IPW_RX_BUF_SIZE (3000)
3253 static void ipw_rx_queue_reset(struct ipw_priv *priv,
3254 struct ipw_rx_queue *rxq)
3256 unsigned long flags;
3259 spin_lock_irqsave(&rxq->lock, flags);
3261 INIT_LIST_HEAD(&rxq->rx_free);
3262 INIT_LIST_HEAD(&rxq->rx_used);
3264 /* Fill the rx_used queue with _all_ of the Rx buffers */
3265 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3266 /* In the reset function, these buffers may have been allocated
3267 * to an SKB, so we need to unmap and free potential storage */
3268 if (rxq->pool[i].skb != NULL) {
3269 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
3270 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
3271 dev_kfree_skb(rxq->pool[i].skb);
3272 rxq->pool[i].skb = NULL;
3274 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3277 /* Set us so that we have processed and used all buffers, but have
3278 * not restocked the Rx queue with fresh buffers */
3279 rxq->read = rxq->write = 0;
3280 rxq->processed = RX_QUEUE_SIZE - 1;
3281 rxq->free_count = 0;
3282 spin_unlock_irqrestore(&rxq->lock, flags);
3286 static int fw_loaded = 0;
3287 static const struct firmware *raw = NULL;
3289 static void free_firmware(void)
3292 release_firmware(raw);
3298 #define free_firmware() do {} while (0)
3301 static int ipw_load(struct ipw_priv *priv)
3304 const struct firmware *raw = NULL;
3307 u8 *boot_img, *ucode_img, *fw_img;
3309 int rc = 0, retries = 3;
3311 switch (priv->ieee->iw_mode) {
3313 name = "ipw2200-ibss.fw";
3315 #ifdef CONFIG_IPW2200_MONITOR
3316 case IW_MODE_MONITOR:
3317 name = "ipw2200-sniffer.fw";
3321 name = "ipw2200-bss.fw";
3333 rc = ipw_get_fw(priv, &raw, name);
3340 fw = (void *)raw->data;
3341 boot_img = &fw->data[0];
3342 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3343 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3344 le32_to_cpu(fw->ucode_size)];
3350 priv->rxq = ipw_rx_queue_alloc(priv);
3352 ipw_rx_queue_reset(priv, priv->rxq);
3354 IPW_ERROR("Unable to initialize Rx queue\n");
3359 /* Ensure interrupts are disabled */
3360 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3361 priv->status &= ~STATUS_INT_ENABLED;
3363 /* ack pending interrupts */
3364 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3368 rc = ipw_reset_nic(priv);
3370 IPW_ERROR("Unable to reset NIC\n");
3374 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3375 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
3377 /* DMA the initial boot firmware into the device */
3378 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
3380 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
3384 /* kick start the device */
3385 ipw_start_nic(priv);
3387 /* wait for the device to finish its initial startup sequence */
3388 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3389 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3391 IPW_ERROR("device failed to boot initial fw image\n");
3394 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3396 /* ack fw init done interrupt */
3397 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3399 /* DMA the ucode into the device */
3400 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
3402 IPW_ERROR("Unable to load ucode: %d\n", rc);
3409 /* DMA bss firmware into the device */
3410 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
3412 IPW_ERROR("Unable to load firmware: %d\n", rc);
3419 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3421 rc = ipw_queue_reset(priv);
3423 IPW_ERROR("Unable to initialize queues\n");
3427 /* Ensure interrupts are disabled */
3428 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3429 /* ack pending interrupts */
3430 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3432 /* kick start the device */
3433 ipw_start_nic(priv);
3435 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
3437 IPW_WARNING("Parity error. Retrying init.\n");
3442 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3447 /* wait for the device */
3448 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3449 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3451 IPW_ERROR("device failed to start within 500ms\n");
3454 IPW_DEBUG_INFO("device response after %dms\n", rc);
3456 /* ack fw init done interrupt */
3457 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3459 /* read eeprom data and initialize the eeprom region of sram */
3460 priv->eeprom_delay = 1;
3461 ipw_eeprom_init_sram(priv);
3463 /* enable interrupts */
3464 ipw_enable_interrupts(priv);
3466 /* Ensure our queue has valid packets */
3467 ipw_rx_queue_replenish(priv);
3469 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
3471 /* ack pending interrupts */
3472 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3475 release_firmware(raw);
3481 ipw_rx_queue_free(priv, priv->rxq);
3484 ipw_tx_queue_free(priv);
3486 release_firmware(raw);
3498 * Theory of operation
3500 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3501 * 2 empty entries always kept in the buffer to protect from overflow.
3503 * For Tx queue, there are low mark and high mark limits. If, after queuing
3504 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3505 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
3508 * The IPW operates with six queues, one receive queue in the device's
3509 * sram, one transmit queue for sending commands to the device firmware,
3510 * and four transmit queues for data.
3512 * The four transmit queues allow for performing quality of service (qos)
3513 * transmissions as per the 802.11 protocol. Currently Linux does not
3514 * provide a mechanism to the user for utilizing prioritized queues, so
3515 * we only utilize the first data transmit queue (queue1).
3519 * Driver allocates buffers of this size for Rx
3522 static inline int ipw_queue_space(const struct clx2_queue *q)
3524 int s = q->last_used - q->first_empty;
3527 s -= 2; /* keep some reserve to not confuse empty and full situations */
3533 static inline int ipw_queue_inc_wrap(int index, int n_bd)
3535 return (++index == n_bd) ? 0 : index;
3539 * Initialize common DMA queue structure
3541 * @param q queue to init
3542 * @param count Number of BD's to allocate. Should be power of 2
3543 * @param read_register Address for 'read' register
3544 * (not offset within BAR, full address)
3545 * @param write_register Address for 'write' register
3546 * (not offset within BAR, full address)
3547 * @param base_register Address for 'base' register
3548 * (not offset within BAR, full address)
3549 * @param size Address for 'size' register
3550 * (not offset within BAR, full address)
3552 static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
3553 int count, u32 read, u32 write, u32 base, u32 size)
3557 q->low_mark = q->n_bd / 4;
3558 if (q->low_mark < 4)
3561 q->high_mark = q->n_bd / 8;
3562 if (q->high_mark < 2)
3565 q->first_empty = q->last_used = 0;
3569 ipw_write32(priv, base, q->dma_addr);
3570 ipw_write32(priv, size, count);
3571 ipw_write32(priv, read, 0);
3572 ipw_write32(priv, write, 0);
3574 _ipw_read32(priv, 0x90);
3577 static int ipw_queue_tx_init(struct ipw_priv *priv,
3578 struct clx2_tx_queue *q,
3579 int count, u32 read, u32 write, u32 base, u32 size)
3581 struct pci_dev *dev = priv->pci_dev;
3583 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3585 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3590 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
3592 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
3593 sizeof(q->bd[0]) * count);
3599 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3604 * Free one TFD, those at index [txq->q.last_used].
3605 * Do NOT advance any indexes
3610 static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3611 struct clx2_tx_queue *txq)
3613 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3614 struct pci_dev *dev = priv->pci_dev;
3618 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3619 /* nothing to cleanup after for host commands */
3623 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3624 IPW_ERROR("Too many chunks: %i\n",
3625 le32_to_cpu(bd->u.data.num_chunks));
3626 /** @todo issue fatal error, it is quite serious situation */
3630 /* unmap chunks if any */
3631 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3632 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3633 le16_to_cpu(bd->u.data.chunk_len[i]),
3635 if (txq->txb[txq->q.last_used]) {
3636 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3637 txq->txb[txq->q.last_used] = NULL;
3643 * Deallocate DMA queue.
3645 * Empty queue by removing and destroying all BD's.
3651 static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
3653 struct clx2_queue *q = &txq->q;
3654 struct pci_dev *dev = priv->pci_dev;
3659 /* first, empty all BD's */
3660 for (; q->first_empty != q->last_used;
3661 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3662 ipw_queue_tx_free_tfd(priv, txq);
3665 /* free buffers belonging to queue itself */
3666 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
3670 /* 0 fill whole structure */
3671 memset(txq, 0, sizeof(*txq));
3675 * Destroy all DMA queues and structures
3679 static void ipw_tx_queue_free(struct ipw_priv *priv)
3682 ipw_queue_tx_free(priv, &priv->txq_cmd);
3685 ipw_queue_tx_free(priv, &priv->txq[0]);
3686 ipw_queue_tx_free(priv, &priv->txq[1]);
3687 ipw_queue_tx_free(priv, &priv->txq[2]);
3688 ipw_queue_tx_free(priv, &priv->txq[3]);
3691 static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
3693 /* First 3 bytes are manufacturer */
3694 bssid[0] = priv->mac_addr[0];
3695 bssid[1] = priv->mac_addr[1];
3696 bssid[2] = priv->mac_addr[2];
3698 /* Last bytes are random */
3699 get_random_bytes(&bssid[3], ETH_ALEN - 3);
3701 bssid[0] &= 0xfe; /* clear multicast bit */
3702 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
3705 static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
3707 struct ipw_station_entry entry;
3710 for (i = 0; i < priv->num_stations; i++) {
3711 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3712 /* Another node is active in network */
3713 priv->missed_adhoc_beacons = 0;
3714 if (!(priv->config & CFG_STATIC_CHANNEL))
3715 /* when other nodes drop out, we drop out */
3716 priv->config &= ~CFG_ADHOC_PERSIST;
3722 if (i == MAX_STATIONS)
3723 return IPW_INVALID_STATION;
3725 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3728 entry.support_mode = 0;
3729 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3730 memcpy(priv->stations[i], bssid, ETH_ALEN);
3731 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
3732 &entry, sizeof(entry));
3733 priv->num_stations++;
3738 static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
3742 for (i = 0; i < priv->num_stations; i++)
3743 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
3746 return IPW_INVALID_STATION;
3749 static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3753 if (priv->status & STATUS_ASSOCIATING) {
3754 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3755 queue_work(priv->workqueue, &priv->disassociate);
3759 if (!(priv->status & STATUS_ASSOCIATED)) {
3760 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3764 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3766 MAC_ARG(priv->assoc_request.bssid),
3767 priv->assoc_request.channel);
3769 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3770 priv->status |= STATUS_DISASSOCIATING;
3773 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3775 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
3777 err = ipw_send_associate(priv, &priv->assoc_request);
3779 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3786 static int ipw_disassociate(void *data)
3788 struct ipw_priv *priv = data;
3789 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3791 ipw_send_disassociate(data, 0);
3795 static void ipw_bg_disassociate(void *data)
3797 struct ipw_priv *priv = data;
3798 mutex_lock(&priv->mutex);
3799 ipw_disassociate(data);
3800 mutex_unlock(&priv->mutex);
3803 static void ipw_system_config(void *data)
3805 struct ipw_priv *priv = data;
3807 #ifdef CONFIG_IPW2200_PROMISCUOUS
3808 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
3809 priv->sys_config.accept_all_data_frames = 1;
3810 priv->sys_config.accept_non_directed_frames = 1;
3811 priv->sys_config.accept_all_mgmt_bcpr = 1;
3812 priv->sys_config.accept_all_mgmt_frames = 1;
3816 ipw_send_system_config(priv);
3819 struct ipw_status_code {
3824 static const struct ipw_status_code ipw_status_codes[] = {
3825 {0x00, "Successful"},
3826 {0x01, "Unspecified failure"},
3827 {0x0A, "Cannot support all requested capabilities in the "
3828 "Capability information field"},
3829 {0x0B, "Reassociation denied due to inability to confirm that "
3830 "association exists"},
3831 {0x0C, "Association denied due to reason outside the scope of this "
3834 "Responding station does not support the specified authentication "
3837 "Received an Authentication frame with authentication sequence "
3838 "transaction sequence number out of expected sequence"},
3839 {0x0F, "Authentication rejected because of challenge failure"},
3840 {0x10, "Authentication rejected due to timeout waiting for next "
3841 "frame in sequence"},
3842 {0x11, "Association denied because AP is unable to handle additional "
3843 "associated stations"},
3845 "Association denied due to requesting station not supporting all "
3846 "of the datarates in the BSSBasicServiceSet Parameter"},
3848 "Association denied due to requesting station not supporting "
3849 "short preamble operation"},
3851 "Association denied due to requesting station not supporting "
3854 "Association denied due to requesting station not supporting "
3857 "Association denied due to requesting station not supporting "
3858 "short slot operation"},
3860 "Association denied due to requesting station not supporting "
3861 "DSSS-OFDM operation"},
3862 {0x28, "Invalid Information Element"},
3863 {0x29, "Group Cipher is not valid"},
3864 {0x2A, "Pairwise Cipher is not valid"},
3865 {0x2B, "AKMP is not valid"},
3866 {0x2C, "Unsupported RSN IE version"},
3867 {0x2D, "Invalid RSN IE Capabilities"},
3868 {0x2E, "Cipher suite is rejected per security policy"},
3871 #ifdef CONFIG_IPW2200_DEBUG
3872 static const char *ipw_get_status_code(u16 status)
3875 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
3876 if (ipw_status_codes[i].status == (status & 0xff))
3877 return ipw_status_codes[i].reason;
3878 return "Unknown status value.";
3882 static void inline average_init(struct average *avg)
3884 memset(avg, 0, sizeof(*avg));
3887 #define DEPTH_RSSI 8
3888 #define DEPTH_NOISE 16
3889 static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
3891 return ((depth-1)*prev_avg + val)/depth;
3894 static void average_add(struct average *avg, s16 val)
3896 avg->sum -= avg->entries[avg->pos];
3898 avg->entries[avg->pos++] = val;
3899 if (unlikely(avg->pos == AVG_ENTRIES)) {
3905 static s16 average_value(struct average *avg)
3907 if (!unlikely(avg->init)) {
3909 return avg->sum / avg->pos;
3913 return avg->sum / AVG_ENTRIES;
3916 static void ipw_reset_stats(struct ipw_priv *priv)
3918 u32 len = sizeof(u32);
3922 average_init(&priv->average_missed_beacons);
3923 priv->exp_avg_rssi = -60;
3924 priv->exp_avg_noise = -85 + 0x100;
3926 priv->last_rate = 0;
3927 priv->last_missed_beacons = 0;
3928 priv->last_rx_packets = 0;
3929 priv->last_tx_packets = 0;
3930 priv->last_tx_failures = 0;
3932 /* Firmware managed, reset only when NIC is restarted, so we have to
3933 * normalize on the current value */
3934 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
3935 &priv->last_rx_err, &len);
3936 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
3937 &priv->last_tx_failures, &len);
3939 /* Driver managed, reset with each association */
3940 priv->missed_adhoc_beacons = 0;
3941 priv->missed_beacons = 0;
3942 priv->tx_packets = 0;
3943 priv->rx_packets = 0;
3947 static u32 ipw_get_max_rate(struct ipw_priv *priv)
3950 u32 mask = priv->rates_mask;
3951 /* If currently associated in B mode, restrict the maximum
3952 * rate match to B rates */
3953 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3954 mask &= IEEE80211_CCK_RATES_MASK;
3956 /* TODO: Verify that the rate is supported by the current rates
3959 while (i && !(mask & i))
3962 case IEEE80211_CCK_RATE_1MB_MASK:
3964 case IEEE80211_CCK_RATE_2MB_MASK:
3966 case IEEE80211_CCK_RATE_5MB_MASK:
3968 case IEEE80211_OFDM_RATE_6MB_MASK:
3970 case IEEE80211_OFDM_RATE_9MB_MASK:
3972 case IEEE80211_CCK_RATE_11MB_MASK:
3974 case IEEE80211_OFDM_RATE_12MB_MASK:
3976 case IEEE80211_OFDM_RATE_18MB_MASK:
3978 case IEEE80211_OFDM_RATE_24MB_MASK:
3980 case IEEE80211_OFDM_RATE_36MB_MASK:
3982 case IEEE80211_OFDM_RATE_48MB_MASK:
3984 case IEEE80211_OFDM_RATE_54MB_MASK:
3988 if (priv->ieee->mode == IEEE_B)
3994 static u32 ipw_get_current_rate(struct ipw_priv *priv)
3996 u32 rate, len = sizeof(rate);
3999 if (!(priv->status & STATUS_ASSOCIATED))
4002 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
4003 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
4006 IPW_DEBUG_INFO("failed querying ordinals.\n");
4010 return ipw_get_max_rate(priv);
4013 case IPW_TX_RATE_1MB:
4015 case IPW_TX_RATE_2MB:
4017 case IPW_TX_RATE_5MB:
4019 case IPW_TX_RATE_6MB:
4021 case IPW_TX_RATE_9MB:
4023 case IPW_TX_RATE_11MB:
4025 case IPW_TX_RATE_12MB:
4027 case IPW_TX_RATE_18MB:
4029 case IPW_TX_RATE_24MB:
4031 case IPW_TX_RATE_36MB:
4033 case IPW_TX_RATE_48MB:
4035 case IPW_TX_RATE_54MB:
4042 #define IPW_STATS_INTERVAL (2 * HZ)
4043 static void ipw_gather_stats(struct ipw_priv *priv)
4045 u32 rx_err, rx_err_delta, rx_packets_delta;
4046 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4047 u32 missed_beacons_percent, missed_beacons_delta;
4049 u32 len = sizeof(u32);
4051 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
4055 if (!(priv->status & STATUS_ASSOCIATED)) {
4060 /* Update the statistics */
4061 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
4062 &priv->missed_beacons, &len);
4063 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
4064 priv->last_missed_beacons = priv->missed_beacons;
4065 if (priv->assoc_request.beacon_interval) {
4066 missed_beacons_percent = missed_beacons_delta *
4067 (HZ * priv->assoc_request.beacon_interval) /
4068 (IPW_STATS_INTERVAL * 10);
4070 missed_beacons_percent = 0;
4072 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4074 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4075 rx_err_delta = rx_err - priv->last_rx_err;
4076 priv->last_rx_err = rx_err;
4078 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4079 tx_failures_delta = tx_failures - priv->last_tx_failures;
4080 priv->last_tx_failures = tx_failures;
4082 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4083 priv->last_rx_packets = priv->rx_packets;
4085 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4086 priv->last_tx_packets = priv->tx_packets;
4088 /* Calculate quality based on the following:
4090 * Missed beacon: 100% = 0, 0% = 70% missed
4091 * Rate: 60% = 1Mbs, 100% = Max
4092 * Rx and Tx errors represent a straight % of total Rx/Tx
4093 * RSSI: 100% = > -50, 0% = < -80
4094 * Rx errors: 100% = 0, 0% = 50% missed
4096 * The lowest computed quality is used.
4099 #define BEACON_THRESHOLD 5
4100 beacon_quality = 100 - missed_beacons_percent;
4101 if (beacon_quality < BEACON_THRESHOLD)
4104 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
4105 (100 - BEACON_THRESHOLD);
4106 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
4107 beacon_quality, missed_beacons_percent);
4109 priv->last_rate = ipw_get_current_rate(priv);
4110 max_rate = ipw_get_max_rate(priv);
4111 rate_quality = priv->last_rate * 40 / max_rate + 60;
4112 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4113 rate_quality, priv->last_rate / 1000000);
4115 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
4116 rx_quality = 100 - (rx_err_delta * 100) /
4117 (rx_packets_delta + rx_err_delta);
4120 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4121 rx_quality, rx_err_delta, rx_packets_delta);
4123 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
4124 tx_quality = 100 - (tx_failures_delta * 100) /
4125 (tx_packets_delta + tx_failures_delta);
4128 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4129 tx_quality, tx_failures_delta, tx_packets_delta);
4131 rssi = priv->exp_avg_rssi;
4134 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4135 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4136 (priv->ieee->perfect_rssi - rssi) *
4137 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4138 62 * (priv->ieee->perfect_rssi - rssi))) /
4139 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4140 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4141 if (signal_quality > 100)
4142 signal_quality = 100;
4143 else if (signal_quality < 1)
4146 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
4147 signal_quality, rssi);
4149 quality = min(beacon_quality,
4151 min(tx_quality, min(rx_quality, signal_quality))));
4152 if (quality == beacon_quality)
4153 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4155 if (quality == rate_quality)
4156 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4158 if (quality == tx_quality)
4159 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4161 if (quality == rx_quality)
4162 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4164 if (quality == signal_quality)
4165 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4168 priv->quality = quality;
4170 queue_delayed_work(priv->workqueue, &priv->gather_stats,
4171 IPW_STATS_INTERVAL);
4174 static void ipw_bg_gather_stats(void *data)
4176 struct ipw_priv *priv = data;
4177 mutex_lock(&priv->mutex);
4178 ipw_gather_stats(data);
4179 mutex_unlock(&priv->mutex);
4182 /* Missed beacon behavior:
4183 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4184 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4185 * Above disassociate threshold, give up and stop scanning.
4186 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
4187 static void ipw_handle_missed_beacon(struct ipw_priv *priv,
4190 priv->notif_missed_beacons = missed_count;
4192 if (missed_count > priv->disassociate_threshold &&
4193 priv->status & STATUS_ASSOCIATED) {
4194 /* If associated and we've hit the missed
4195 * beacon threshold, disassociate, turn
4196 * off roaming, and abort any active scans */
4197 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4198 IPW_DL_STATE | IPW_DL_ASSOC,
4199 "Missed beacon: %d - disassociate\n", missed_count);
4200 priv->status &= ~STATUS_ROAMING;
4201 if (priv->status & STATUS_SCANNING) {
4202 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4204 "Aborting scan with missed beacon.\n");
4205 queue_work(priv->workqueue, &priv->abort_scan);
4208 queue_work(priv->workqueue, &priv->disassociate);
4212 if (priv->status & STATUS_ROAMING) {
4213 /* If we are currently roaming, then just
4214 * print a debug statement... */
4215 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4216 "Missed beacon: %d - roam in progress\n",
4222 (missed_count > priv->roaming_threshold &&
4223 missed_count <= priv->disassociate_threshold)) {
4224 /* If we are not already roaming, set the ROAM
4225 * bit in the status and kick off a scan.
4226 * This can happen several times before we reach
4227 * disassociate_threshold. */
4228 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4229 "Missed beacon: %d - initiate "
4230 "roaming\n", missed_count);
4231 if (!(priv->status & STATUS_ROAMING)) {
4232 priv->status |= STATUS_ROAMING;
4233 if (!(priv->status & STATUS_SCANNING))
4234 queue_work(priv->workqueue,
4235 &priv->request_scan);
4240 if (priv->status & STATUS_SCANNING) {
4241 /* Stop scan to keep fw from getting
4242 * stuck (only if we aren't roaming --
4243 * otherwise we'll never scan more than 2 or 3
4245 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4246 "Aborting scan with missed beacon.\n");
4247 queue_work(priv->workqueue, &priv->abort_scan);
4250 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
4254 * Handle host notification packet.
4255 * Called from interrupt routine
4257 static void ipw_rx_notification(struct ipw_priv *priv,
4258 struct ipw_rx_notification *notif)
4260 notif->size = le16_to_cpu(notif->size);
4262 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
4264 switch (notif->subtype) {
4265 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4266 struct notif_association *assoc = ¬if->u.assoc;
4268 switch (assoc->state) {
4269 case CMAS_ASSOCIATED:{
4270 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4272 "associated: '%s' " MAC_FMT
4274 escape_essid(priv->essid,
4276 MAC_ARG(priv->bssid));
4278 switch (priv->ieee->iw_mode) {
4280 memcpy(priv->ieee->bssid,
4281 priv->bssid, ETH_ALEN);
4285 memcpy(priv->ieee->bssid,
4286 priv->bssid, ETH_ALEN);
4288 /* clear out the station table */
4289 priv->num_stations = 0;
4292 ("queueing adhoc check\n");
4293 queue_delayed_work(priv->
4303 priv->status &= ~STATUS_ASSOCIATING;
4304 priv->status |= STATUS_ASSOCIATED;
4305 queue_work(priv->workqueue,
4306 &priv->system_config);
4308 #ifdef CONFIG_IPW_QOS
4309 #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4310 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4311 if ((priv->status & STATUS_AUTH) &&
4312 (IPW_GET_PACKET_STYPE(¬if->u.raw)
4313 == IEEE80211_STYPE_ASSOC_RESP)) {
4316 ieee80211_assoc_response)
4318 && (notif->size <= 2314)) {
4331 ieee80211_rx_mgt(priv->
4336 ¬if->u.raw, &stats);
4341 schedule_work(&priv->link_up);
4346 case CMAS_AUTHENTICATED:{
4348 status & (STATUS_ASSOCIATED |
4350 #ifdef CONFIG_IPW2200_DEBUG
4351 struct notif_authenticate *auth
4353 IPW_DEBUG(IPW_DL_NOTIF |
4356 "deauthenticated: '%s' "
4358 ": (0x%04X) - %s \n",
4363 MAC_ARG(priv->bssid),
4364 ntohs(auth->status),
4371 ~(STATUS_ASSOCIATING |
4375 schedule_work(&priv->link_down);
4379 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4381 "authenticated: '%s' " MAC_FMT
4383 escape_essid(priv->essid,
4385 MAC_ARG(priv->bssid));
4390 if (priv->status & STATUS_AUTH) {
4392 ieee80211_assoc_response
4396 ieee80211_assoc_response
4398 IPW_DEBUG(IPW_DL_NOTIF |
4401 "association failed (0x%04X): %s\n",
4402 ntohs(resp->status),
4408 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4410 "disassociated: '%s' " MAC_FMT
4412 escape_essid(priv->essid,
4414 MAC_ARG(priv->bssid));
4417 ~(STATUS_DISASSOCIATING |
4418 STATUS_ASSOCIATING |
4419 STATUS_ASSOCIATED | STATUS_AUTH);
4420 if (priv->assoc_network
4421 && (priv->assoc_network->
4423 WLAN_CAPABILITY_IBSS))
4424 ipw_remove_current_network
4427 schedule_work(&priv->link_down);
4432 case CMAS_RX_ASSOC_RESP:
4436 IPW_ERROR("assoc: unknown (%d)\n",
4444 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4445 struct notif_authenticate *auth = ¬if->u.auth;
4446 switch (auth->state) {
4447 case CMAS_AUTHENTICATED:
4448 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4449 "authenticated: '%s' " MAC_FMT " \n",
4450 escape_essid(priv->essid,
4452 MAC_ARG(priv->bssid));
4453 priv->status |= STATUS_AUTH;
4457 if (priv->status & STATUS_AUTH) {
4458 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4460 "authentication failed (0x%04X): %s\n",
4461 ntohs(auth->status),
4462 ipw_get_status_code(ntohs
4466 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4468 "deauthenticated: '%s' " MAC_FMT "\n",
4469 escape_essid(priv->essid,
4471 MAC_ARG(priv->bssid));
4473 priv->status &= ~(STATUS_ASSOCIATING |
4477 schedule_work(&priv->link_down);
4480 case CMAS_TX_AUTH_SEQ_1:
4481 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4482 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4484 case CMAS_RX_AUTH_SEQ_2:
4485 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4486 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4488 case CMAS_AUTH_SEQ_1_PASS:
4489 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4490 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4492 case CMAS_AUTH_SEQ_1_FAIL:
4493 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4494 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4496 case CMAS_TX_AUTH_SEQ_3:
4497 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4498 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4500 case CMAS_RX_AUTH_SEQ_4:
4501 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4502 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4504 case CMAS_AUTH_SEQ_2_PASS:
4505 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4506 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4508 case CMAS_AUTH_SEQ_2_FAIL:
4509 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4510 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4513 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4514 IPW_DL_ASSOC, "TX_ASSOC\n");
4516 case CMAS_RX_ASSOC_RESP:
4517 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4518 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
4521 case CMAS_ASSOCIATED:
4522 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4523 IPW_DL_ASSOC, "ASSOCIATED\n");
4526 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4533 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4534 struct notif_channel_result *x =
4535 ¬if->u.channel_result;
4537 if (notif->size == sizeof(*x)) {
4538 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4541 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4542 "(should be %zd)\n",
4543 notif->size, sizeof(*x));
4548 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4549 struct notif_scan_complete *x = ¬if->u.scan_complete;
4550 if (notif->size == sizeof(*x)) {
4552 ("Scan completed: type %d, %d channels, "
4553 "%d status\n", x->scan_type,
4554 x->num_channels, x->status);
4556 IPW_ERROR("Scan completed of wrong size %d "
4557 "(should be %zd)\n",
4558 notif->size, sizeof(*x));
4562 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4564 wake_up_interruptible(&priv->wait_state);
4565 cancel_delayed_work(&priv->scan_check);
4567 if (priv->status & STATUS_EXIT_PENDING)
4570 priv->ieee->scans++;
4572 #ifdef CONFIG_IPW2200_MONITOR
4573 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
4574 priv->status |= STATUS_SCAN_FORCED;
4575 queue_work(priv->workqueue,
4576 &priv->request_scan);
4579 priv->status &= ~STATUS_SCAN_FORCED;
4580 #endif /* CONFIG_IPW2200_MONITOR */
4582 if (!(priv->status & (STATUS_ASSOCIATED |
4583 STATUS_ASSOCIATING |
4585 STATUS_DISASSOCIATING)))
4586 queue_work(priv->workqueue, &priv->associate);
4587 else if (priv->status & STATUS_ROAMING) {
4588 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4589 /* If a scan completed and we are in roam mode, then
4590 * the scan that completed was the one requested as a
4591 * result of entering roam... so, schedule the
4593 queue_work(priv->workqueue,
4596 /* Don't schedule if we aborted the scan */
4597 priv->status &= ~STATUS_ROAMING;
4598 } else if (priv->status & STATUS_SCAN_PENDING)
4599 queue_work(priv->workqueue,
4600 &priv->request_scan);
4601 else if (priv->config & CFG_BACKGROUND_SCAN
4602 && priv->status & STATUS_ASSOCIATED)
4603 queue_delayed_work(priv->workqueue,
4604 &priv->request_scan, HZ);
4606 /* Send an empty event to user space.
4607 * We don't send the received data on the event because
4608 * it would require us to do complex transcoding, and
4609 * we want to minimise the work done in the irq handler
4610 * Use a request to extract the data.
4611 * Also, we generate this even for any scan, regardless
4612 * on how the scan was initiated. User space can just
4613 * sync on periodic scan to get fresh data...
4615 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) {
4616 union iwreq_data wrqu;
4618 wrqu.data.length = 0;
4619 wrqu.data.flags = 0;
4620 wireless_send_event(priv->net_dev, SIOCGIWSCAN,
4626 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4627 struct notif_frag_length *x = ¬if->u.frag_len;
4629 if (notif->size == sizeof(*x))
4630 IPW_ERROR("Frag length: %d\n",
4631 le16_to_cpu(x->frag_length));
4633 IPW_ERROR("Frag length of wrong size %d "
4634 "(should be %zd)\n",
4635 notif->size, sizeof(*x));
4639 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4640 struct notif_link_deterioration *x =
4641 ¬if->u.link_deterioration;
4643 if (notif->size == sizeof(*x)) {
4644 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4645 "link deterioration: type %d, cnt %d\n",
4646 x->silence_notification_type,
4648 memcpy(&priv->last_link_deterioration, x,
4651 IPW_ERROR("Link Deterioration of wrong size %d "
4652 "(should be %zd)\n",
4653 notif->size, sizeof(*x));
4658 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4659 IPW_ERROR("Dino config\n");
4661 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
4662 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
4667 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4668 struct notif_beacon_state *x = ¬if->u.beacon_state;
4669 if (notif->size != sizeof(*x)) {
4671 ("Beacon state of wrong size %d (should "
4672 "be %zd)\n", notif->size, sizeof(*x));
4676 if (le32_to_cpu(x->state) ==
4677 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4678 ipw_handle_missed_beacon(priv,
4685 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4686 struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key;
4687 if (notif->size == sizeof(*x)) {
4688 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4689 "0x%02x station %d\n",
4690 x->key_state, x->security_type,
4696 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4697 notif->size, sizeof(*x));
4701 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4702 struct notif_calibration *x = ¬if->u.calibration;
4704 if (notif->size == sizeof(*x)) {
4705 memcpy(&priv->calib, x, sizeof(*x));
4706 IPW_DEBUG_INFO("TODO: Calibration\n");
4711 ("Calibration of wrong size %d (should be %zd)\n",
4712 notif->size, sizeof(*x));
4716 case HOST_NOTIFICATION_NOISE_STATS:{
4717 if (notif->size == sizeof(u32)) {
4718 priv->exp_avg_noise =
4719 exponential_average(priv->exp_avg_noise,
4720 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4726 ("Noise stat is wrong size %d (should be %zd)\n",
4727 notif->size, sizeof(u32));
4732 IPW_DEBUG_NOTIF("Unknown notification: "
4733 "subtype=%d,flags=0x%2x,size=%d\n",
4734 notif->subtype, notif->flags, notif->size);
4739 * Destroys all DMA structures and initialise them again
4742 * @return error code
4744 static int ipw_queue_reset(struct ipw_priv *priv)
4747 /** @todo customize queue sizes */
4748 int nTx = 64, nTxCmd = 8;
4749 ipw_tx_queue_free(priv);
4751 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
4752 IPW_TX_CMD_QUEUE_READ_INDEX,
4753 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4754 IPW_TX_CMD_QUEUE_BD_BASE,
4755 IPW_TX_CMD_QUEUE_BD_SIZE);
4757 IPW_ERROR("Tx Cmd queue init failed\n");
4761 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
4762 IPW_TX_QUEUE_0_READ_INDEX,
4763 IPW_TX_QUEUE_0_WRITE_INDEX,
4764 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
4766 IPW_ERROR("Tx 0 queue init failed\n");
4769 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
4770 IPW_TX_QUEUE_1_READ_INDEX,
4771 IPW_TX_QUEUE_1_WRITE_INDEX,
4772 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
4774 IPW_ERROR("Tx 1 queue init failed\n");
4777 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
4778 IPW_TX_QUEUE_2_READ_INDEX,
4779 IPW_TX_QUEUE_2_WRITE_INDEX,
4780 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
4782 IPW_ERROR("Tx 2 queue init failed\n");
4785 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
4786 IPW_TX_QUEUE_3_READ_INDEX,
4787 IPW_TX_QUEUE_3_WRITE_INDEX,
4788 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
4790 IPW_ERROR("Tx 3 queue init failed\n");
4794 priv->rx_bufs_min = 0;
4795 priv->rx_pend_max = 0;
4799 ipw_tx_queue_free(priv);
4804 * Reclaim Tx queue entries no more used by NIC.
4806 * When FW adwances 'R' index, all entries between old and
4807 * new 'R' index need to be reclaimed. As result, some free space
4808 * forms. If there is enough free space (> low mark), wake Tx queue.
4810 * @note Need to protect against garbage in 'R' index
4814 * @return Number of used entries remains in the queue
4816 static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
4817 struct clx2_tx_queue *txq, int qindex)
4821 struct clx2_queue *q = &txq->q;
4823 hw_tail = ipw_read32(priv, q->reg_r);
4824 if (hw_tail >= q->n_bd) {
4826 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4830 for (; q->last_used != hw_tail;
4831 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4832 ipw_queue_tx_free_tfd(priv, txq);
4836 if ((ipw_queue_space(q) > q->low_mark) &&
4838 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4839 netif_wake_queue(priv->net_dev);
4840 used = q->first_empty - q->last_used;
4847 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4850 struct clx2_tx_queue *txq = &priv->txq_cmd;
4851 struct clx2_queue *q = &txq->q;
4852 struct tfd_frame *tfd;
4854 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4855 IPW_ERROR("No space for Tx\n");
4859 tfd = &txq->bd[q->first_empty];
4860 txq->txb[q->first_empty] = NULL;
4862 memset(tfd, 0, sizeof(*tfd));
4863 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4864 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4866 tfd->u.cmd.index = hcmd;
4867 tfd->u.cmd.length = len;
4868 memcpy(tfd->u.cmd.payload, buf, len);
4869 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4870 ipw_write32(priv, q->reg_w, q->first_empty);
4871 _ipw_read32(priv, 0x90);
4877 * Rx theory of operation
4879 * The host allocates 32 DMA target addresses and passes the host address
4880 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
4884 * The host/firmware share two index registers for managing the Rx buffers.
4886 * The READ index maps to the first position that the firmware may be writing
4887 * to -- the driver can read up to (but not including) this position and get
4889 * The READ index is managed by the firmware once the card is enabled.
4891 * The WRITE index maps to the last position the driver has read from -- the
4892 * position preceding WRITE is the last slot the firmware can place a packet.
4894 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
4897 * During initialization the host sets up the READ queue position to the first
4898 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4900 * When the firmware places a packet in a buffer it will advance the READ index
4901 * and fire the RX interrupt. The driver can then query the READ index and
4902 * process as many packets as possible, moving the WRITE index forward as it
4903 * resets the Rx queue buffers with new memory.
4905 * The management in the driver is as follows:
4906 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
4907 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
4908 * to replensish the ipw->rxq->rx_free.
4909 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4910 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4911 * 'processed' and 'read' driver indexes as well)
4912 * + A received packet is processed and handed to the kernel network stack,
4913 * detached from the ipw->rxq. The driver 'processed' index is updated.
4914 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
4915 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4916 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
4917 * were enough free buffers and RX_STALLED is set it is cleared.
4922 * ipw_rx_queue_alloc() Allocates rx_free
4923 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4924 * ipw_rx_queue_restock
4925 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4926 * queue, updates firmware pointers, and updates
4927 * the WRITE index. If insufficient rx_free buffers
4928 * are available, schedules ipw_rx_queue_replenish
4930 * -- enable interrupts --
4931 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
4932 * READ INDEX, detaching the SKB from the pool.
4933 * Moves the packet buffer from queue to rx_used.
4934 * Calls ipw_rx_queue_restock to refill any empty
4941 * If there are slots in the RX queue that need to be restocked,
4942 * and we have free pre-allocated buffers, fill the ranks as much
4943 * as we can pulling from rx_free.
4945 * This moves the 'write' index forward to catch up with 'processed', and
4946 * also updates the memory address in the firmware to reference the new
4949 static void ipw_rx_queue_restock(struct ipw_priv *priv)
4951 struct ipw_rx_queue *rxq = priv->rxq;
4952 struct list_head *element;
4953 struct ipw_rx_mem_buffer *rxb;
4954 unsigned long flags;
4957 spin_lock_irqsave(&rxq->lock, flags);
4959 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4960 element = rxq->rx_free.next;
4961 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4964 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
4966 rxq->queue[rxq->write] = rxb;
4967 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4970 spin_unlock_irqrestore(&rxq->lock, flags);
4972 /* If the pre-allocated buffer pool is dropping low, schedule to
4974 if (rxq->free_count <= RX_LOW_WATERMARK)
4975 queue_work(priv->workqueue, &priv->rx_replenish);
4977 /* If we've added more space for the firmware to place data, tell it */
4978 if (write != rxq->write)
4979 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
4983 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
4984 * Also restock the Rx queue via ipw_rx_queue_restock.
4986 * This is called as a scheduled work item (except for during intialization)
4988 static void ipw_rx_queue_replenish(void *data)
4990 struct ipw_priv *priv = data;
4991 struct ipw_rx_queue *rxq = priv->rxq;
4992 struct list_head *element;
4993 struct ipw_rx_mem_buffer *rxb;
4994 unsigned long flags;
4996 spin_lock_irqsave(&rxq->lock, flags);
4997 while (!list_empty(&rxq->rx_used)) {
4998 element = rxq->rx_used.next;
4999 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5000 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
5002 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5003 priv->net_dev->name);
5004 /* We don't reschedule replenish work here -- we will
5005 * call the restock method and if it still needs
5006 * more buffers it will schedule replenish */
5011 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
5013 pci_map_single(priv->pci_dev, rxb->skb->data,
5014 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
5016 list_add_tail(&rxb->list, &rxq->rx_free);
5019 spin_unlock_irqrestore(&rxq->lock, flags);
5021 ipw_rx_queue_restock(priv);
5024 static void ipw_bg_rx_queue_replenish(void *data)
5026 struct ipw_priv *priv = data;
5027 mutex_lock(&priv->mutex);
5028 ipw_rx_queue_replenish(data);
5029 mutex_unlock(&priv->mutex);
5032 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
5033 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
5034 * This free routine walks the list of POOL entries and if SKB is set to
5035 * non NULL it is unmapped and freed
5037 static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
5044 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5045 if (rxq->pool[i].skb != NULL) {
5046 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
5047 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
5048 dev_kfree_skb(rxq->pool[i].skb);
5055 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5057 struct ipw_rx_queue *rxq;
5060 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
5061 if (unlikely(!rxq)) {
5062 IPW_ERROR("memory allocation failed\n");
5065 spin_lock_init(&rxq->lock);
5066 INIT_LIST_HEAD(&rxq->rx_free);
5067 INIT_LIST_HEAD(&rxq->rx_used);
5069 /* Fill the rx_used queue with _all_ of the Rx buffers */
5070 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
5071 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5073 /* Set us so that we have processed and used all buffers, but have
5074 * not restocked the Rx queue with fresh buffers */
5075 rxq->read = rxq->write = 0;
5076 rxq->processed = RX_QUEUE_SIZE - 1;
5077 rxq->free_count = 0;
5082 static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5084 rate &= ~IEEE80211_BASIC_RATE_MASK;
5085 if (ieee_mode == IEEE_A) {
5087 case IEEE80211_OFDM_RATE_6MB:
5088 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
5090 case IEEE80211_OFDM_RATE_9MB:
5091 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
5093 case IEEE80211_OFDM_RATE_12MB:
5095 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
5096 case IEEE80211_OFDM_RATE_18MB:
5098 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
5099 case IEEE80211_OFDM_RATE_24MB:
5101 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
5102 case IEEE80211_OFDM_RATE_36MB:
5104 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
5105 case IEEE80211_OFDM_RATE_48MB:
5107 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
5108 case IEEE80211_OFDM_RATE_54MB:
5110 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5118 case IEEE80211_CCK_RATE_1MB:
5119 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
5120 case IEEE80211_CCK_RATE_2MB:
5121 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
5122 case IEEE80211_CCK_RATE_5MB:
5123 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
5124 case IEEE80211_CCK_RATE_11MB:
5125 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
5128 /* If we are limited to B modulations, bail at this point */
5129 if (ieee_mode == IEEE_B)
5134 case IEEE80211_OFDM_RATE_6MB:
5135 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
5136 case IEEE80211_OFDM_RATE_9MB:
5137 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
5138 case IEEE80211_OFDM_RATE_12MB:
5139 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
5140 case IEEE80211_OFDM_RATE_18MB:
5141 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
5142 case IEEE80211_OFDM_RATE_24MB:
5143 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
5144 case IEEE80211_OFDM_RATE_36MB:
5145 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
5146 case IEEE80211_OFDM_RATE_48MB:
5147 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
5148 case IEEE80211_OFDM_RATE_54MB:
5149 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5155 static int ipw_compatible_rates(struct ipw_priv *priv,
5156 const struct ieee80211_network *network,
5157 struct ipw_supported_rates *rates)
5161 memset(rates, 0, sizeof(*rates));
5162 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
5163 rates->num_rates = 0;
5164 for (i = 0; i < num_rates; i++) {
5165 if (!ipw_is_rate_in_mask(priv, network->mode,
5166 network->rates[i])) {
5168 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
5169 IPW_DEBUG_SCAN("Adding masked mandatory "
5172 rates->supported_rates[rates->num_rates++] =
5177 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5178 network->rates[i], priv->rates_mask);
5182 rates->supported_rates[rates->num_rates++] = network->rates[i];
5185 num_rates = min(network->rates_ex_len,
5186 (u8) (IPW_MAX_RATES - num_rates));
5187 for (i = 0; i < num_rates; i++) {
5188 if (!ipw_is_rate_in_mask(priv, network->mode,
5189 network->rates_ex[i])) {
5190 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
5191 IPW_DEBUG_SCAN("Adding masked mandatory "
5193 network->rates_ex[i]);
5194 rates->supported_rates[rates->num_rates++] =
5199 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5200 network->rates_ex[i], priv->rates_mask);
5204 rates->supported_rates[rates->num_rates++] =
5205 network->rates_ex[i];
5211 static void ipw_copy_rates(struct ipw_supported_rates *dest,
5212 const struct ipw_supported_rates *src)
5215 for (i = 0; i < src->num_rates; i++)
5216 dest->supported_rates[i] = src->supported_rates[i];
5217 dest->num_rates = src->num_rates;
5220 /* TODO: Look at sniffed packets in the air to determine if the basic rate
5221 * mask should ever be used -- right now all callers to add the scan rates are
5222 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5223 static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
5224 u8 modulation, u32 rate_mask)
5226 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
5227 IEEE80211_BASIC_RATE_MASK : 0;
5229 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
5230 rates->supported_rates[rates->num_rates++] =
5231 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
5233 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
5234 rates->supported_rates[rates->num_rates++] =
5235 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
5237 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
5238 rates->supported_rates[rates->num_rates++] = basic_mask |
5239 IEEE80211_CCK_RATE_5MB;
5241 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
5242 rates->supported_rates[rates->num_rates++] = basic_mask |
5243 IEEE80211_CCK_RATE_11MB;
5246 static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
5247 u8 modulation, u32 rate_mask)
5249 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
5250 IEEE80211_BASIC_RATE_MASK : 0;
5252 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
5253 rates->supported_rates[rates->num_rates++] = basic_mask |
5254 IEEE80211_OFDM_RATE_6MB;
5256 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
5257 rates->supported_rates[rates->num_rates++] =
5258 IEEE80211_OFDM_RATE_9MB;
5260 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
5261 rates->supported_rates[rates->num_rates++] = basic_mask |
5262 IEEE80211_OFDM_RATE_12MB;
5264 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
5265 rates->supported_rates[rates->num_rates++] =
5266 IEEE80211_OFDM_RATE_18MB;
5268 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
5269 rates->supported_rates[rates->num_rates++] = basic_mask |
5270 IEEE80211_OFDM_RATE_24MB;
5272 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
5273 rates->supported_rates[rates->num_rates++] =
5274 IEEE80211_OFDM_RATE_36MB;
5276 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
5277 rates->supported_rates[rates->num_rates++] =
5278 IEEE80211_OFDM_RATE_48MB;
5280 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
5281 rates->supported_rates[rates->num_rates++] =
5282 IEEE80211_OFDM_RATE_54MB;
5285 struct ipw_network_match {
5286 struct ieee80211_network *network;
5287 struct ipw_supported_rates rates;
5290 static int ipw_find_adhoc_network(struct ipw_priv *priv,
5291 struct ipw_network_match *match,
5292 struct ieee80211_network *network,
5295 struct ipw_supported_rates rates;
5297 /* Verify that this network's capability is compatible with the
5298 * current mode (AdHoc or Infrastructure) */
5299 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5300 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5301 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5302 "capability mismatch.\n",
5303 escape_essid(network->ssid, network->ssid_len),
5304 MAC_ARG(network->bssid));
5308 /* If we do not have an ESSID for this AP, we can not associate with
5310 if (network->flags & NETWORK_EMPTY_ESSID) {
5311 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5312 "because of hidden ESSID.\n",
5313 escape_essid(network->ssid, network->ssid_len),
5314 MAC_ARG(network->bssid));
5318 if (unlikely(roaming)) {
5319 /* If we are roaming, then ensure check if this is a valid
5320 * network to try and roam to */
5321 if ((network->ssid_len != match->network->ssid_len) ||
5322 memcmp(network->ssid, match->network->ssid,
5323 network->ssid_len)) {
5324 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5325 "because of non-network ESSID.\n",
5326 escape_essid(network->ssid,
5328 MAC_ARG(network->bssid));
5332 /* If an ESSID has been configured then compare the broadcast
5334 if ((priv->config & CFG_STATIC_ESSID) &&
5335 ((network->ssid_len != priv->essid_len) ||
5336 memcmp(network->ssid, priv->essid,
5337 min(network->ssid_len, priv->essid_len)))) {
5338 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5341 escape_essid(network->ssid, network->ssid_len),
5343 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5344 "because of ESSID mismatch: '%s'.\n",
5345 escaped, MAC_ARG(network->bssid),
5346 escape_essid(priv->essid,
5352 /* If the old network rate is better than this one, don't bother
5353 * testing everything else. */
5355 if (network->time_stamp[0] < match->network->time_stamp[0]) {
5356 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5357 "current network.\n",
5358 escape_essid(match->network->ssid,
5359 match->network->ssid_len));
5361 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
5362 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5363 "current network.\n",
5364 escape_essid(match->network->ssid,
5365 match->network->ssid_len));
5369 /* Now go through and see if the requested network is valid... */
5370 if (priv->ieee->scan_age != 0 &&
5371 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5372 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5373 "because of age: %ums.\n",
5374 escape_essid(network->ssid, network->ssid_len),
5375 MAC_ARG(network->bssid),
5376 jiffies_to_msecs(jiffies -
5377 network->last_scanned));
5381 if ((priv->config & CFG_STATIC_CHANNEL) &&
5382 (network->channel != priv->channel)) {
5383 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5384 "because of channel mismatch: %d != %d.\n",
5385 escape_essid(network->ssid, network->ssid_len),
5386 MAC_ARG(network->bssid),
5387 network->channel, priv->channel);
5391 /* Verify privacy compatability */
5392 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5393 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5394 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5395 "because of privacy mismatch: %s != %s.\n",
5396 escape_essid(network->ssid, network->ssid_len),
5397 MAC_ARG(network->bssid),
5399 capability & CAP_PRIVACY_ON ? "on" : "off",
5401 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5406 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5407 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5408 "because of the same BSSID match: " MAC_FMT
5409 ".\n", escape_essid(network->ssid,
5411 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5415 /* Filter out any incompatible freq / mode combinations */
5416 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5417 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5418 "because of invalid frequency/mode "
5420 escape_essid(network->ssid, network->ssid_len),
5421 MAC_ARG(network->bssid));
5425 /* Ensure that the rates supported by the driver are compatible with
5426 * this AP, including verification of basic rates (mandatory) */
5427 if (!ipw_compatible_rates(priv, network, &rates)) {
5428 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5429 "because configured rate mask excludes "
5430 "AP mandatory rate.\n",
5431 escape_essid(network->ssid, network->ssid_len),
5432 MAC_ARG(network->bssid));
5436 if (rates.num_rates == 0) {
5437 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5438 "because of no compatible rates.\n",
5439 escape_essid(network->ssid, network->ssid_len),
5440 MAC_ARG(network->bssid));
5444 /* TODO: Perform any further minimal comparititive tests. We do not
5445 * want to put too much policy logic here; intelligent scan selection
5446 * should occur within a generic IEEE 802.11 user space tool. */
5448 /* Set up 'new' AP to this network */
5449 ipw_copy_rates(&match->rates, &rates);
5450 match->network = network;
5451 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5452 escape_essid(network->ssid, network->ssid_len),
5453 MAC_ARG(network->bssid));
5458 static void ipw_merge_adhoc_network(void *data)
5460 struct ipw_priv *priv = data;
5461 struct ieee80211_network *network = NULL;
5462 struct ipw_network_match match = {
5463 .network = priv->assoc_network
5466 if ((priv->status & STATUS_ASSOCIATED) &&
5467 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5468 /* First pass through ROAM process -- look for a better
5470 unsigned long flags;
5472 spin_lock_irqsave(&priv->ieee->lock, flags);
5473 list_for_each_entry(network, &priv->ieee->network_list, list) {
5474 if (network != priv->assoc_network)
5475 ipw_find_adhoc_network(priv, &match, network,
5478 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5480 if (match.network == priv->assoc_network) {
5481 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5486 mutex_lock(&priv->mutex);
5487 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5488 IPW_DEBUG_MERGE("remove network %s\n",
5489 escape_essid(priv->essid,
5491 ipw_remove_current_network(priv);
5494 ipw_disassociate(priv);
5495 priv->assoc_network = match.network;
5496 mutex_unlock(&priv->mutex);
5501 static int ipw_best_network(struct ipw_priv *priv,
5502 struct ipw_network_match *match,
5503 struct ieee80211_network *network, int roaming)
5505 struct ipw_supported_rates rates;
5507 /* Verify that this network's capability is compatible with the
5508 * current mode (AdHoc or Infrastructure) */
5509 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
5510 !(network->capability & WLAN_CAPABILITY_ESS)) ||
5511 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5512 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5513 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
5514 "capability mismatch.\n",
5515 escape_essid(network->ssid, network->ssid_len),
5516 MAC_ARG(network->bssid));
5520 /* If we do not have an ESSID for this AP, we can not associate with
5522 if (network->flags & NETWORK_EMPTY_ESSID) {
5523 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5524 "because of hidden ESSID.\n",
5525 escape_essid(network->ssid, network->ssid_len),
5526 MAC_ARG(network->bssid));
5530 if (unlikely(roaming)) {
5531 /* If we are roaming, then ensure check if this is a valid
5532 * network to try and roam to */
5533 if ((network->ssid_len != match->network->ssid_len) ||
5534 memcmp(network->ssid, match->network->ssid,
5535 network->ssid_len)) {
5536 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5537 "because of non-network ESSID.\n",
5538 escape_essid(network->ssid,
5540 MAC_ARG(network->bssid));
5544 /* If an ESSID has been configured then compare the broadcast
5546 if ((priv->config & CFG_STATIC_ESSID) &&
5547 ((network->ssid_len != priv->essid_len) ||
5548 memcmp(network->ssid, priv->essid,
5549 min(network->ssid_len, priv->essid_len)))) {
5550 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5552 escape_essid(network->ssid, network->ssid_len),
5554 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5555 "because of ESSID mismatch: '%s'.\n",
5556 escaped, MAC_ARG(network->bssid),
5557 escape_essid(priv->essid,
5563 /* If the old network rate is better than this one, don't bother
5564 * testing everything else. */
5565 if (match->network && match->network->stats.rssi > network->stats.rssi) {
5566 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5568 escape_essid(network->ssid, network->ssid_len),
5570 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5571 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5572 escaped, MAC_ARG(network->bssid),
5573 escape_essid(match->network->ssid,
5574 match->network->ssid_len),
5575 MAC_ARG(match->network->bssid));
5579 /* If this network has already had an association attempt within the
5580 * last 3 seconds, do not try and associate again... */
5581 if (network->last_associate &&
5582 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
5583 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5584 "because of storming (%ums since last "
5585 "assoc attempt).\n",
5586 escape_essid(network->ssid, network->ssid_len),
5587 MAC_ARG(network->bssid),
5588 jiffies_to_msecs(jiffies -
5589 network->last_associate));
5593 /* Now go through and see if the requested network is valid... */
5594 if (priv->ieee->scan_age != 0 &&
5595 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5596 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5597 "because of age: %ums.\n",
5598 escape_essid(network->ssid, network->ssid_len),
5599 MAC_ARG(network->bssid),
5600 jiffies_to_msecs(jiffies -
5601 network->last_scanned));
5605 if ((priv->config & CFG_STATIC_CHANNEL) &&
5606 (network->channel != priv->channel)) {
5607 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5608 "because of channel mismatch: %d != %d.\n",
5609 escape_essid(network->ssid, network->ssid_len),
5610 MAC_ARG(network->bssid),
5611 network->channel, priv->channel);
5615 /* Verify privacy compatability */
5616 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5617 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5618 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5619 "because of privacy mismatch: %s != %s.\n",
5620 escape_essid(network->ssid, network->ssid_len),
5621 MAC_ARG(network->bssid),
5622 priv->capability & CAP_PRIVACY_ON ? "on" :
5624 network->capability &
5625 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
5629 if ((priv->config & CFG_STATIC_BSSID) &&
5630 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5631 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5632 "because of BSSID mismatch: " MAC_FMT ".\n",
5633 escape_essid(network->ssid, network->ssid_len),
5634 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5638 /* Filter out any incompatible freq / mode combinations */
5639 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5640 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5641 "because of invalid frequency/mode "
5643 escape_essid(network->ssid, network->ssid_len),
5644 MAC_ARG(network->bssid));
5648 /* Filter out invalid channel in current GEO */
5649 if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) {
5650 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5651 "because of invalid channel in current GEO\n",
5652 escape_essid(network->ssid, network->ssid_len),
5653 MAC_ARG(network->bssid));
5657 /* Ensure that the rates supported by the driver are compatible with
5658 * this AP, including verification of basic rates (mandatory) */
5659 if (!ipw_compatible_rates(priv, network, &rates)) {
5660 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5661 "because configured rate mask excludes "
5662 "AP mandatory rate.\n",
5663 escape_essid(network->ssid, network->ssid_len),
5664 MAC_ARG(network->bssid));
5668 if (rates.num_rates == 0) {
5669 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5670 "because of no compatible rates.\n",
5671 escape_essid(network->ssid, network->ssid_len),
5672 MAC_ARG(network->bssid));
5676 /* TODO: Perform any further minimal comparititive tests. We do not
5677 * want to put too much policy logic here; intelligent scan selection
5678 * should occur within a generic IEEE 802.11 user space tool. */
5680 /* Set up 'new' AP to this network */
5681 ipw_copy_rates(&match->rates, &rates);
5682 match->network = network;
5684 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5685 escape_essid(network->ssid, network->ssid_len),
5686 MAC_ARG(network->bssid));
5691 static void ipw_adhoc_create(struct ipw_priv *priv,
5692 struct ieee80211_network *network)
5694 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
5698 * For the purposes of scanning, we can set our wireless mode
5699 * to trigger scans across combinations of bands, but when it
5700 * comes to creating a new ad-hoc network, we have tell the FW
5701 * exactly which band to use.
5703 * We also have the possibility of an invalid channel for the
5704 * chossen band. Attempting to create a new ad-hoc network
5705 * with an invalid channel for wireless mode will trigger a
5709 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
5710 case IEEE80211_52GHZ_BAND:
5711 network->mode = IEEE_A;
5712 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
5714 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5715 IPW_WARNING("Overriding invalid channel\n");
5716 priv->channel = geo->a[0].channel;
5720 case IEEE80211_24GHZ_BAND:
5721 if (priv->ieee->mode & IEEE_G)
5722 network->mode = IEEE_G;
5724 network->mode = IEEE_B;
5725 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
5727 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5728 IPW_WARNING("Overriding invalid channel\n");
5729 priv->channel = geo->bg[0].channel;
5734 IPW_WARNING("Overriding invalid channel\n");
5735 if (priv->ieee->mode & IEEE_A) {
5736 network->mode = IEEE_A;
5737 priv->channel = geo->a[0].channel;
5738 } else if (priv->ieee->mode & IEEE_G) {
5739 network->mode = IEEE_G;
5740 priv->channel = geo->bg[0].channel;
5742 network->mode = IEEE_B;
5743 priv->channel = geo->bg[0].channel;
5748 network->channel = priv->channel;
5749 priv->config |= CFG_ADHOC_PERSIST;
5750 ipw_create_bssid(priv, network->bssid);
5751 network->ssid_len = priv->essid_len;
5752 memcpy(network->ssid, priv->essid, priv->essid_len);
5753 memset(&network->stats, 0, sizeof(network->stats));
5754 network->capability = WLAN_CAPABILITY_IBSS;
5755 if (!(priv->config & CFG_PREAMBLE_LONG))
5756 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
5757 if (priv->capability & CAP_PRIVACY_ON)
5758 network->capability |= WLAN_CAPABILITY_PRIVACY;
5759 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
5760 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
5761 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
5762 memcpy(network->rates_ex,
5763 &priv->rates.supported_rates[network->rates_len],
5764 network->rates_ex_len);
5765 network->last_scanned = 0;
5767 network->last_associate = 0;
5768 network->time_stamp[0] = 0;
5769 network->time_stamp[1] = 0;
5770 network->beacon_interval = 100; /* Default */
5771 network->listen_interval = 10; /* Default */
5772 network->atim_window = 0; /* Default */
5773 network->wpa_ie_len = 0;
5774 network->rsn_ie_len = 0;
5777 static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5779 struct ipw_tgi_tx_key key;
5781 if (!(priv->ieee->sec.flags & (1 << index)))
5785 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5786 key.security_type = type;
5787 key.station_index = 0; /* always 0 for BSS */
5789 /* 0 for new key; previous value of counter (after fatal error) */
5790 key.tx_counter[0] = 0;
5791 key.tx_counter[1] = 0;
5793 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
5796 static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
5798 struct ipw_wep_key key;
5801 key.cmd_id = DINO_CMD_WEP_KEY;
5804 /* Note: AES keys cannot be set for multiple times.
5805 * Only set it at the first time. */
5806 for (i = 0; i < 4; i++) {
5807 key.key_index = i | type;
5808 if (!(priv->ieee->sec.flags & (1 << i))) {
5813 key.key_size = priv->ieee->sec.key_sizes[i];
5814 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
5816 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
5820 static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5822 if (priv->ieee->host_encrypt)
5827 priv->sys_config.disable_unicast_decryption = 0;
5828 priv->ieee->host_decrypt = 0;
5831 priv->sys_config.disable_unicast_decryption = 1;
5832 priv->ieee->host_decrypt = 1;
5835 priv->sys_config.disable_unicast_decryption = 0;
5836 priv->ieee->host_decrypt = 0;
5839 priv->sys_config.disable_unicast_decryption = 1;
5846 static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5848 if (priv->ieee->host_encrypt)
5853 priv->sys_config.disable_multicast_decryption = 0;
5856 priv->sys_config.disable_multicast_decryption = 1;
5859 priv->sys_config.disable_multicast_decryption = 0;
5862 priv->sys_config.disable_multicast_decryption = 1;
5869 static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5871 switch (priv->ieee->sec.level) {
5873 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5874 ipw_send_tgi_tx_key(priv,
5875 DCT_FLAG_EXT_SECURITY_CCM,
5876 priv->ieee->sec.active_key);
5878 if (!priv->ieee->host_mc_decrypt)
5879 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
5882 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5883 ipw_send_tgi_tx_key(priv,
5884 DCT_FLAG_EXT_SECURITY_TKIP,
5885 priv->ieee->sec.active_key);
5888 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
5889 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5890 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
5898 static void ipw_adhoc_check(void *data)
5900 struct ipw_priv *priv = data;
5902 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
5903 !(priv->config & CFG_ADHOC_PERSIST)) {
5904 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5905 IPW_DL_STATE | IPW_DL_ASSOC,
5906 "Missed beacon: %d - disassociate\n",
5907 priv->missed_adhoc_beacons);
5908 ipw_remove_current_network(priv);
5909 ipw_disassociate(priv);
5913 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
5914 priv->assoc_request.beacon_interval);
5917 static void ipw_bg_adhoc_check(void *data)
5919 struct ipw_priv *priv = data;
5920 mutex_lock(&priv->mutex);
5921 ipw_adhoc_check(data);
5922 mutex_unlock(&priv->mutex);
5925 #ifdef CONFIG_IPW2200_DEBUG
5926 static void ipw_debug_config(struct ipw_priv *priv)
5928 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5929 "[CFG 0x%08X]\n", priv->config);
5930 if (priv->config & CFG_STATIC_CHANNEL)
5931 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
5933 IPW_DEBUG_INFO("Channel unlocked.\n");
5934 if (priv->config & CFG_STATIC_ESSID)
5935 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
5936 escape_essid(priv->essid, priv->essid_len));
5938 IPW_DEBUG_INFO("ESSID unlocked.\n");
5939 if (priv->config & CFG_STATIC_BSSID)
5940 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5941 MAC_ARG(priv->bssid));
5943 IPW_DEBUG_INFO("BSSID unlocked.\n");
5944 if (priv->capability & CAP_PRIVACY_ON)
5945 IPW_DEBUG_INFO("PRIVACY on\n");
5947 IPW_DEBUG_INFO("PRIVACY off\n");
5948 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5951 #define ipw_debug_config(x) do {} while (0)
5954 static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
5956 /* TODO: Verify that this works... */
5957 struct ipw_fixed_rate fr = {
5958 .tx_rates = priv->rates_mask
5963 /* Identify 'current FW band' and match it with the fixed
5966 switch (priv->ieee->freq_band) {
5967 case IEEE80211_52GHZ_BAND: /* A only */
5969 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5970 /* Invalid fixed rate mask */
5972 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5977 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5980 default: /* 2.4Ghz or Mixed */
5982 if (mode == IEEE_B) {
5983 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
5984 /* Invalid fixed rate mask */
5986 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5993 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5994 IEEE80211_OFDM_RATES_MASK)) {
5995 /* Invalid fixed rate mask */
5997 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
6002 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
6003 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
6004 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
6007 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
6008 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
6009 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
6012 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
6013 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
6014 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
6017 fr.tx_rates |= mask;
6021 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
6022 ipw_write_reg32(priv, reg, *(u32 *) & fr);
6025 static void ipw_abort_scan(struct ipw_priv *priv)
6029 if (priv->status & STATUS_SCAN_ABORTING) {
6030 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6033 priv->status |= STATUS_SCAN_ABORTING;
6035 err = ipw_send_scan_abort(priv);
6037 IPW_DEBUG_HC("Request to abort scan failed.\n");
6040 static void ipw_add_scan_channels(struct ipw_priv *priv,
6041 struct ipw_scan_request_ext *scan,
6044 int channel_index = 0;
6045 const struct ieee80211_geo *geo;
6048 geo = ieee80211_get_geo(priv->ieee);
6050 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
6051 int start = channel_index;
6052 for (i = 0; i < geo->a_channels; i++) {
6053 if ((priv->status & STATUS_ASSOCIATED) &&
6054 geo->a[i].channel == priv->channel)
6057 scan->channels_list[channel_index] = geo->a[i].channel;
6058 ipw_set_scan_type(scan, channel_index,
6060 flags & IEEE80211_CH_PASSIVE_ONLY ?
6061 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6065 if (start != channel_index) {
6066 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6067 (channel_index - start);
6072 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
6073 int start = channel_index;
6074 if (priv->config & CFG_SPEED_SCAN) {
6076 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
6077 /* nop out the list */
6082 while (channel_index < IPW_SCAN_CHANNELS) {
6084 priv->speed_scan[priv->speed_scan_pos];
6086 priv->speed_scan_pos = 0;
6087 channel = priv->speed_scan[0];
6089 if ((priv->status & STATUS_ASSOCIATED) &&
6090 channel == priv->channel) {
6091 priv->speed_scan_pos++;
6095 /* If this channel has already been
6096 * added in scan, break from loop
6097 * and this will be the first channel
6100 if (channels[channel - 1] != 0)
6103 channels[channel - 1] = 1;
6104 priv->speed_scan_pos++;
6106 scan->channels_list[channel_index] = channel;
6108 ieee80211_channel_to_index(priv->ieee, channel);
6109 ipw_set_scan_type(scan, channel_index,
6112 IEEE80211_CH_PASSIVE_ONLY ?
6113 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6117 for (i = 0; i < geo->bg_channels; i++) {
6118 if ((priv->status & STATUS_ASSOCIATED) &&
6119 geo->bg[i].channel == priv->channel)
6122 scan->channels_list[channel_index] =
6124 ipw_set_scan_type(scan, channel_index,
6127 IEEE80211_CH_PASSIVE_ONLY ?
6128 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6133 if (start != channel_index) {
6134 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6135 (channel_index - start);
6140 static int ipw_request_scan(struct ipw_priv *priv)
6142 struct ipw_scan_request_ext scan;
6143 int err = 0, scan_type;
6145 if (!(priv->status & STATUS_INIT) ||
6146 (priv->status & STATUS_EXIT_PENDING))
6149 mutex_lock(&priv->mutex);
6151 if (priv->status & STATUS_SCANNING) {
6152 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
6153 priv->status |= STATUS_SCAN_PENDING;
6157 if (!(priv->status & STATUS_SCAN_FORCED) &&
6158 priv->status & STATUS_SCAN_ABORTING) {
6159 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6160 priv->status |= STATUS_SCAN_PENDING;
6164 if (priv->status & STATUS_RF_KILL_MASK) {
6165 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6166 priv->status |= STATUS_SCAN_PENDING;
6170 memset(&scan, 0, sizeof(scan));
6172 if (priv->config & CFG_SPEED_SCAN)
6173 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6176 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6179 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6181 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
6183 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
6185 #ifdef CONFIG_IPW2200_MONITOR
6186 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
6190 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
6191 case IEEE80211_52GHZ_BAND:
6192 band = (u8) (IPW_A_MODE << 6) | 1;
6193 channel = priv->channel;
6196 case IEEE80211_24GHZ_BAND:
6197 band = (u8) (IPW_B_MODE << 6) | 1;
6198 channel = priv->channel;
6202 band = (u8) (IPW_B_MODE << 6) | 1;
6207 scan.channels_list[0] = band;
6208 scan.channels_list[1] = channel;
6209 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
6211 /* NOTE: The card will sit on this channel for this time
6212 * period. Scan aborts are timing sensitive and frequently
6213 * result in firmware restarts. As such, it is best to
6214 * set a small dwell_time here and just keep re-issuing
6215 * scans. Otherwise fast channel hopping will not actually
6218 * TODO: Move SPEED SCAN support to all modes and bands */
6219 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6222 #endif /* CONFIG_IPW2200_MONITOR */
6223 /* If we are roaming, then make this a directed scan for the
6224 * current network. Otherwise, ensure that every other scan
6225 * is a fast channel hop scan */
6226 if ((priv->status & STATUS_ROAMING)
6227 || (!(priv->status & STATUS_ASSOCIATED)
6228 && (priv->config & CFG_STATIC_ESSID)
6229 && (le32_to_cpu(scan.full_scan_index) % 2))) {
6230 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6232 IPW_DEBUG_HC("Attempt to send SSID command "
6237 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6239 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
6241 ipw_add_scan_channels(priv, &scan, scan_type);
6242 #ifdef CONFIG_IPW2200_MONITOR
6246 err = ipw_send_scan_request_ext(priv, &scan);
6248 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
6252 priv->status |= STATUS_SCANNING;
6253 priv->status &= ~STATUS_SCAN_PENDING;
6254 queue_delayed_work(priv->workqueue, &priv->scan_check,
6255 IPW_SCAN_CHECK_WATCHDOG);
6257 mutex_unlock(&priv->mutex);
6261 static void ipw_bg_abort_scan(void *data)
6263 struct ipw_priv *priv = data;
6264 mutex_lock(&priv->mutex);
6265 ipw_abort_scan(data);
6266 mutex_unlock(&priv->mutex);
6269 static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6271 /* This is called when wpa_supplicant loads and closes the driver
6273 priv->ieee->wpa_enabled = value;
6277 static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6279 struct ieee80211_device *ieee = priv->ieee;
6280 struct ieee80211_security sec = {
6281 .flags = SEC_AUTH_MODE,
6285 if (value & IW_AUTH_ALG_SHARED_KEY) {
6286 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6288 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
6289 sec.auth_mode = WLAN_AUTH_OPEN;
6291 } else if (value & IW_AUTH_ALG_LEAP) {
6292 sec.auth_mode = WLAN_AUTH_LEAP;
6297 if (ieee->set_security)
6298 ieee->set_security(ieee->dev, &sec);
6305 static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6308 /* make sure WPA is enabled */
6309 ipw_wpa_enable(priv, 1);
6311 ipw_disassociate(priv);
6314 static int ipw_set_rsn_capa(struct ipw_priv *priv,
6315 char *capabilities, int length)
6317 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6319 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
6328 static int ipw_wx_set_genie(struct net_device *dev,
6329 struct iw_request_info *info,
6330 union iwreq_data *wrqu, char *extra)
6332 struct ipw_priv *priv = ieee80211_priv(dev);
6333 struct ieee80211_device *ieee = priv->ieee;
6337 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6338 (wrqu->data.length && extra == NULL))
6341 //mutex_lock(&priv->mutex);
6343 //if (!ieee->wpa_enabled) {
6344 // err = -EOPNOTSUPP;
6348 if (wrqu->data.length) {
6349 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6355 memcpy(buf, extra, wrqu->data.length);
6356 kfree(ieee->wpa_ie);
6358 ieee->wpa_ie_len = wrqu->data.length;
6360 kfree(ieee->wpa_ie);
6361 ieee->wpa_ie = NULL;
6362 ieee->wpa_ie_len = 0;
6365 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6367 //mutex_unlock(&priv->mutex);
6372 static int ipw_wx_get_genie(struct net_device *dev,
6373 struct iw_request_info *info,
6374 union iwreq_data *wrqu, char *extra)
6376 struct ipw_priv *priv = ieee80211_priv(dev);
6377 struct ieee80211_device *ieee = priv->ieee;
6380 //mutex_lock(&priv->mutex);
6382 //if (!ieee->wpa_enabled) {
6383 // err = -EOPNOTSUPP;
6387 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6388 wrqu->data.length = 0;
6392 if (wrqu->data.length < ieee->wpa_ie_len) {
6397 wrqu->data.length = ieee->wpa_ie_len;
6398 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6401 //mutex_unlock(&priv->mutex);
6405 static int wext_cipher2level(int cipher)
6408 case IW_AUTH_CIPHER_NONE:
6410 case IW_AUTH_CIPHER_WEP40:
6411 case IW_AUTH_CIPHER_WEP104:
6413 case IW_AUTH_CIPHER_TKIP:
6415 case IW_AUTH_CIPHER_CCMP:
6423 static int ipw_wx_set_auth(struct net_device *dev,
6424 struct iw_request_info *info,
6425 union iwreq_data *wrqu, char *extra)
6427 struct ipw_priv *priv = ieee80211_priv(dev);
6428 struct ieee80211_device *ieee = priv->ieee;
6429 struct iw_param *param = &wrqu->param;
6430 struct ieee80211_crypt_data *crypt;
6431 unsigned long flags;
6434 switch (param->flags & IW_AUTH_INDEX) {
6435 case IW_AUTH_WPA_VERSION:
6437 case IW_AUTH_CIPHER_PAIRWISE:
6438 ipw_set_hw_decrypt_unicast(priv,
6439 wext_cipher2level(param->value));
6441 case IW_AUTH_CIPHER_GROUP:
6442 ipw_set_hw_decrypt_multicast(priv,
6443 wext_cipher2level(param->value));
6445 case IW_AUTH_KEY_MGMT:
6447 * ipw2200 does not use these parameters
6451 case IW_AUTH_TKIP_COUNTERMEASURES:
6452 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6453 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
6456 flags = crypt->ops->get_flags(crypt->priv);
6459 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6461 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6463 crypt->ops->set_flags(flags, crypt->priv);
6467 case IW_AUTH_DROP_UNENCRYPTED:{
6470 * wpa_supplicant calls set_wpa_enabled when the driver
6471 * is loaded and unloaded, regardless of if WPA is being
6472 * used. No other calls are made which can be used to
6473 * determine if encryption will be used or not prior to
6474 * association being expected. If encryption is not being
6475 * used, drop_unencrypted is set to false, else true -- we
6476 * can use this to determine if the CAP_PRIVACY_ON bit should
6479 struct ieee80211_security sec = {
6480 .flags = SEC_ENABLED,
6481 .enabled = param->value,
6483 priv->ieee->drop_unencrypted = param->value;
6484 /* We only change SEC_LEVEL for open mode. Others
6485 * are set by ipw_wpa_set_encryption.
6487 if (!param->value) {
6488 sec.flags |= SEC_LEVEL;
6489 sec.level = SEC_LEVEL_0;
6491 sec.flags |= SEC_LEVEL;
6492 sec.level = SEC_LEVEL_1;
6494 if (priv->ieee->set_security)
6495 priv->ieee->set_security(priv->ieee->dev, &sec);
6499 case IW_AUTH_80211_AUTH_ALG:
6500 ret = ipw_wpa_set_auth_algs(priv, param->value);
6503 case IW_AUTH_WPA_ENABLED:
6504 ret = ipw_wpa_enable(priv, param->value);
6507 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6508 ieee->ieee802_1x = param->value;
6511 //case IW_AUTH_ROAMING_CONTROL:
6512 case IW_AUTH_PRIVACY_INVOKED:
6513 ieee->privacy_invoked = param->value;
6523 static int ipw_wx_get_auth(struct net_device *dev,
6524 struct iw_request_info *info,
6525 union iwreq_data *wrqu, char *extra)
6527 struct ipw_priv *priv = ieee80211_priv(dev);
6528 struct ieee80211_device *ieee = priv->ieee;
6529 struct ieee80211_crypt_data *crypt;
6530 struct iw_param *param = &wrqu->param;
6533 switch (param->flags & IW_AUTH_INDEX) {
6534 case IW_AUTH_WPA_VERSION:
6535 case IW_AUTH_CIPHER_PAIRWISE:
6536 case IW_AUTH_CIPHER_GROUP:
6537 case IW_AUTH_KEY_MGMT:
6539 * wpa_supplicant will control these internally
6544 case IW_AUTH_TKIP_COUNTERMEASURES:
6545 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6546 if (!crypt || !crypt->ops->get_flags)
6549 param->value = (crypt->ops->get_flags(crypt->priv) &
6550 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6554 case IW_AUTH_DROP_UNENCRYPTED:
6555 param->value = ieee->drop_unencrypted;
6558 case IW_AUTH_80211_AUTH_ALG:
6559 param->value = ieee->sec.auth_mode;
6562 case IW_AUTH_WPA_ENABLED:
6563 param->value = ieee->wpa_enabled;
6566 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6567 param->value = ieee->ieee802_1x;
6570 case IW_AUTH_ROAMING_CONTROL:
6571 case IW_AUTH_PRIVACY_INVOKED:
6572 param->value = ieee->privacy_invoked;
6581 /* SIOCSIWENCODEEXT */
6582 static int ipw_wx_set_encodeext(struct net_device *dev,
6583 struct iw_request_info *info,
6584 union iwreq_data *wrqu, char *extra)
6586 struct ipw_priv *priv = ieee80211_priv(dev);
6587 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6590 if (ext->alg == IW_ENCODE_ALG_TKIP) {
6591 /* IPW HW can't build TKIP MIC,
6592 host decryption still needed */
6593 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6594 priv->ieee->host_mc_decrypt = 1;
6596 priv->ieee->host_encrypt = 0;
6597 priv->ieee->host_encrypt_msdu = 1;
6598 priv->ieee->host_decrypt = 1;
6601 priv->ieee->host_encrypt = 0;
6602 priv->ieee->host_encrypt_msdu = 0;
6603 priv->ieee->host_decrypt = 0;
6604 priv->ieee->host_mc_decrypt = 0;
6608 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6611 /* SIOCGIWENCODEEXT */
6612 static int ipw_wx_get_encodeext(struct net_device *dev,
6613 struct iw_request_info *info,
6614 union iwreq_data *wrqu, char *extra)
6616 struct ipw_priv *priv = ieee80211_priv(dev);
6617 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6621 static int ipw_wx_set_mlme(struct net_device *dev,
6622 struct iw_request_info *info,
6623 union iwreq_data *wrqu, char *extra)
6625 struct ipw_priv *priv = ieee80211_priv(dev);
6626 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6629 reason = cpu_to_le16(mlme->reason_code);
6631 switch (mlme->cmd) {
6632 case IW_MLME_DEAUTH:
6636 case IW_MLME_DISASSOC:
6637 ipw_disassociate(priv);
6646 #ifdef CONFIG_IPW_QOS
6650 * get the modulation type of the current network or
6651 * the card current mode
6653 static u8 ipw_qos_current_mode(struct ipw_priv * priv)
6657 if (priv->status & STATUS_ASSOCIATED) {
6658 unsigned long flags;
6660 spin_lock_irqsave(&priv->ieee->lock, flags);
6661 mode = priv->assoc_network->mode;
6662 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6664 mode = priv->ieee->mode;
6666 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6671 * Handle management frame beacon and probe response
6673 static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6675 struct ieee80211_network *network)
6677 u32 size = sizeof(struct ieee80211_qos_parameters);
6679 if (network->capability & WLAN_CAPABILITY_IBSS)
6680 network->qos_data.active = network->qos_data.supported;
6682 if (network->flags & NETWORK_HAS_QOS_MASK) {
6683 if (active_network &&
6684 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
6685 network->qos_data.active = network->qos_data.supported;
6687 if ((network->qos_data.active == 1) && (active_network == 1) &&
6688 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6689 (network->qos_data.old_param_count !=
6690 network->qos_data.param_count)) {
6691 network->qos_data.old_param_count =
6692 network->qos_data.param_count;
6693 schedule_work(&priv->qos_activate);
6694 IPW_DEBUG_QOS("QoS parameters change call "
6698 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6699 memcpy(&network->qos_data.parameters,
6700 &def_parameters_CCK, size);
6702 memcpy(&network->qos_data.parameters,
6703 &def_parameters_OFDM, size);
6705 if ((network->qos_data.active == 1) && (active_network == 1)) {
6706 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6707 schedule_work(&priv->qos_activate);
6710 network->qos_data.active = 0;
6711 network->qos_data.supported = 0;
6713 if ((priv->status & STATUS_ASSOCIATED) &&
6714 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6715 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6716 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6717 !(network->flags & NETWORK_EMPTY_ESSID))
6718 if ((network->ssid_len ==
6719 priv->assoc_network->ssid_len) &&
6720 !memcmp(network->ssid,
6721 priv->assoc_network->ssid,
6722 network->ssid_len)) {
6723 queue_work(priv->workqueue,
6724 &priv->merge_networks);
6732 * This function set up the firmware to support QoS. It sends
6733 * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6735 static int ipw_qos_activate(struct ipw_priv *priv,
6736 struct ieee80211_qos_data *qos_network_data)
6739 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6740 struct ieee80211_qos_parameters *active_one = NULL;
6741 u32 size = sizeof(struct ieee80211_qos_parameters);
6746 type = ipw_qos_current_mode(priv);
6748 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6749 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6750 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6751 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6753 if (qos_network_data == NULL) {
6754 if (type == IEEE_B) {
6755 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6756 active_one = &def_parameters_CCK;
6758 active_one = &def_parameters_OFDM;
6760 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6761 burst_duration = ipw_qos_get_burst_duration(priv);
6762 for (i = 0; i < QOS_QUEUE_NUM; i++)
6763 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6764 (u16) burst_duration;
6765 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6766 if (type == IEEE_B) {
6767 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6769 if (priv->qos_data.qos_enable == 0)
6770 active_one = &def_parameters_CCK;
6772 active_one = priv->qos_data.def_qos_parm_CCK;
6774 if (priv->qos_data.qos_enable == 0)
6775 active_one = &def_parameters_OFDM;
6777 active_one = priv->qos_data.def_qos_parm_OFDM;
6779 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6781 unsigned long flags;
6784 spin_lock_irqsave(&priv->ieee->lock, flags);
6785 active_one = &(qos_network_data->parameters);
6786 qos_network_data->old_param_count =
6787 qos_network_data->param_count;
6788 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6789 active = qos_network_data->supported;
6790 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6793 burst_duration = ipw_qos_get_burst_duration(priv);
6794 for (i = 0; i < QOS_QUEUE_NUM; i++)
6795 qos_parameters[QOS_PARAM_SET_ACTIVE].
6796 tx_op_limit[i] = (u16) burst_duration;
6800 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
6801 err = ipw_send_qos_params_command(priv,
6802 (struct ieee80211_qos_parameters *)
6803 &(qos_parameters[0]));
6805 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6811 * send IPW_CMD_WME_INFO to the firmware
6813 static int ipw_qos_set_info_element(struct ipw_priv *priv)
6816 struct ieee80211_qos_information_element qos_info;
6821 qos_info.elementID = QOS_ELEMENT_ID;
6822 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6824 qos_info.version = QOS_VERSION_1;
6825 qos_info.ac_info = 0;
6827 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6828 qos_info.qui_type = QOS_OUI_TYPE;
6829 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6831 ret = ipw_send_qos_info_command(priv, &qos_info);
6833 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6839 * Set the QoS parameter with the association request structure
6841 static int ipw_qos_association(struct ipw_priv *priv,
6842 struct ieee80211_network *network)
6845 struct ieee80211_qos_data *qos_data = NULL;
6846 struct ieee80211_qos_data ibss_data = {
6851 switch (priv->ieee->iw_mode) {
6853 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
6855 qos_data = &ibss_data;
6859 qos_data = &network->qos_data;
6867 err = ipw_qos_activate(priv, qos_data);
6869 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6873 if (priv->qos_data.qos_enable && qos_data->supported) {
6874 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6875 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6876 return ipw_qos_set_info_element(priv);
6883 * handling the beaconing responces. if we get different QoS setting
6884 * of the network from the the associated setting adjust the QoS
6887 static int ipw_qos_association_resp(struct ipw_priv *priv,
6888 struct ieee80211_network *network)
6891 unsigned long flags;
6892 u32 size = sizeof(struct ieee80211_qos_parameters);
6893 int set_qos_param = 0;
6895 if ((priv == NULL) || (network == NULL) ||
6896 (priv->assoc_network == NULL))
6899 if (!(priv->status & STATUS_ASSOCIATED))
6902 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
6905 spin_lock_irqsave(&priv->ieee->lock, flags);
6906 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
6907 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
6908 sizeof(struct ieee80211_qos_data));
6909 priv->assoc_network->qos_data.active = 1;
6910 if ((network->qos_data.old_param_count !=
6911 network->qos_data.param_count)) {
6913 network->qos_data.old_param_count =
6914 network->qos_data.param_count;
6918 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
6919 memcpy(&priv->assoc_network->qos_data.parameters,
6920 &def_parameters_CCK, size);
6922 memcpy(&priv->assoc_network->qos_data.parameters,
6923 &def_parameters_OFDM, size);
6924 priv->assoc_network->qos_data.active = 0;
6925 priv->assoc_network->qos_data.supported = 0;
6929 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6931 if (set_qos_param == 1)
6932 schedule_work(&priv->qos_activate);
6937 static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
6944 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
6945 ret = priv->qos_data.burst_duration_CCK;
6947 ret = priv->qos_data.burst_duration_OFDM;
6953 * Initialize the setting of QoS global
6955 static void ipw_qos_init(struct ipw_priv *priv, int enable,
6956 int burst_enable, u32 burst_duration_CCK,
6957 u32 burst_duration_OFDM)
6959 priv->qos_data.qos_enable = enable;
6961 if (priv->qos_data.qos_enable) {
6962 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
6963 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
6964 IPW_DEBUG_QOS("QoS is enabled\n");
6966 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
6967 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
6968 IPW_DEBUG_QOS("QoS is not enabled\n");
6971 priv->qos_data.burst_enable = burst_enable;
6974 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
6975 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
6977 priv->qos_data.burst_duration_CCK = 0;
6978 priv->qos_data.burst_duration_OFDM = 0;
6983 * map the packet priority to the right TX Queue
6985 static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
6987 if (priority > 7 || !priv->qos_data.qos_enable)
6990 return from_priority_to_tx_queue[priority] - 1;
6993 static int ipw_is_qos_active(struct net_device *dev,
6994 struct sk_buff *skb)
6996 struct ipw_priv *priv = ieee80211_priv(dev);
6997 struct ieee80211_qos_data *qos_data = NULL;
6998 int active, supported;
6999 u8 *daddr = skb->data + ETH_ALEN;
7000 int unicast = !is_multicast_ether_addr(daddr);
7002 if (!(priv->status & STATUS_ASSOCIATED))
7005 qos_data = &priv->assoc_network->qos_data;
7007 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7009 qos_data->active = 0;
7011 qos_data->active = qos_data->supported;
7013 active = qos_data->active;
7014 supported = qos_data->supported;
7015 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7017 priv->qos_data.qos_enable, active, supported, unicast);
7018 if (active && priv->qos_data.qos_enable)
7025 * add QoS parameter to the TX command
7027 static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7029 struct tfd_data *tfd)
7031 int tx_queue_id = 0;
7034 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7035 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7037 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7038 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
7039 tfd->tfd.tfd_26.mchdr.qos_ctrl |= CTRL_QOS_NO_ACK;
7045 * background support to run QoS activate functionality
7047 static void ipw_bg_qos_activate(void *data)
7049 struct ipw_priv *priv = data;
7054 mutex_lock(&priv->mutex);
7056 if (priv->status & STATUS_ASSOCIATED)
7057 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7059 mutex_unlock(&priv->mutex);
7062 static int ipw_handle_probe_response(struct net_device *dev,
7063 struct ieee80211_probe_response *resp,
7064 struct ieee80211_network *network)
7066 struct ipw_priv *priv = ieee80211_priv(dev);
7067 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7068 (network == priv->assoc_network));
7070 ipw_qos_handle_probe_response(priv, active_network, network);
7075 static int ipw_handle_beacon(struct net_device *dev,
7076 struct ieee80211_beacon *resp,
7077 struct ieee80211_network *network)
7079 struct ipw_priv *priv = ieee80211_priv(dev);
7080 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7081 (network == priv->assoc_network));
7083 ipw_qos_handle_probe_response(priv, active_network, network);
7088 static int ipw_handle_assoc_response(struct net_device *dev,
7089 struct ieee80211_assoc_response *resp,
7090 struct ieee80211_network *network)
7092 struct ipw_priv *priv = ieee80211_priv(dev);
7093 ipw_qos_association_resp(priv, network);
7097 static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7100 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7101 sizeof(*qos_param) * 3, qos_param);
7104 static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7107 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7111 #endif /* CONFIG_IPW_QOS */
7113 static int ipw_associate_network(struct ipw_priv *priv,
7114 struct ieee80211_network *network,
7115 struct ipw_supported_rates *rates, int roaming)
7119 if (priv->config & CFG_FIXED_RATE)
7120 ipw_set_fixed_rate(priv, network->mode);
7122 if (!(priv->config & CFG_STATIC_ESSID)) {
7123 priv->essid_len = min(network->ssid_len,
7124 (u8) IW_ESSID_MAX_SIZE);
7125 memcpy(priv->essid, network->ssid, priv->essid_len);
7128 network->last_associate = jiffies;
7130 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7131 priv->assoc_request.channel = network->channel;
7132 priv->assoc_request.auth_key = 0;
7134 if ((priv->capability & CAP_PRIVACY_ON) &&
7135 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
7136 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
7137 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7139 if (priv->ieee->sec.level == SEC_LEVEL_1)
7140 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
7142 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7143 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7144 priv->assoc_request.auth_type = AUTH_LEAP;
7146 priv->assoc_request.auth_type = AUTH_OPEN;
7148 if (priv->ieee->wpa_ie_len) {
7149 priv->assoc_request.policy_support = 0x02; /* RSN active */
7150 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7151 priv->ieee->wpa_ie_len);
7155 * It is valid for our ieee device to support multiple modes, but
7156 * when it comes to associating to a given network we have to choose
7159 if (network->mode & priv->ieee->mode & IEEE_A)
7160 priv->assoc_request.ieee_mode = IPW_A_MODE;
7161 else if (network->mode & priv->ieee->mode & IEEE_G)
7162 priv->assoc_request.ieee_mode = IPW_G_MODE;
7163 else if (network->mode & priv->ieee->mode & IEEE_B)
7164 priv->assoc_request.ieee_mode = IPW_B_MODE;
7166 priv->assoc_request.capability = network->capability;
7167 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7168 && !(priv->config & CFG_PREAMBLE_LONG)) {
7169 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7171 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7173 /* Clear the short preamble if we won't be supporting it */
7174 priv->assoc_request.capability &=
7175 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7178 /* Clear capability bits that aren't used in Ad Hoc */
7179 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7180 priv->assoc_request.capability &=
7181 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7183 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
7184 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
7185 roaming ? "Rea" : "A",
7186 escape_essid(priv->essid, priv->essid_len),
7188 ipw_modes[priv->assoc_request.ieee_mode],
7190 (priv->assoc_request.preamble_length ==
7191 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7192 network->capability &
7193 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
7194 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
7195 priv->capability & CAP_PRIVACY_ON ?
7196 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
7198 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
7199 priv->capability & CAP_PRIVACY_ON ?
7200 '1' + priv->ieee->sec.active_key : '.',
7201 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
7203 priv->assoc_request.beacon_interval = network->beacon_interval;
7204 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
7205 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
7206 priv->assoc_request.assoc_type = HC_IBSS_START;
7207 priv->assoc_request.assoc_tsf_msw = 0;
7208 priv->assoc_request.assoc_tsf_lsw = 0;
7210 if (unlikely(roaming))
7211 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7213 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7214 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7215 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7218 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
7220 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7221 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7222 priv->assoc_request.atim_window = network->atim_window;
7224 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
7225 priv->assoc_request.atim_window = 0;
7228 priv->assoc_request.listen_interval = network->listen_interval;
7230 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7232 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7236 rates->ieee_mode = priv->assoc_request.ieee_mode;
7237 rates->purpose = IPW_RATE_CONNECT;
7238 ipw_send_supported_rates(priv, rates);
7240 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7241 priv->sys_config.dot11g_auto_detection = 1;
7243 priv->sys_config.dot11g_auto_detection = 0;
7245 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7246 priv->sys_config.answer_broadcast_ssid_probe = 1;
7248 priv->sys_config.answer_broadcast_ssid_probe = 0;
7250 err = ipw_send_system_config(priv);
7252 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7256 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
7257 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
7259 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7264 * If preemption is enabled, it is possible for the association
7265 * to complete before we return from ipw_send_associate. Therefore
7266 * we have to be sure and update our priviate data first.
7268 priv->channel = network->channel;
7269 memcpy(priv->bssid, network->bssid, ETH_ALEN);
7270 priv->status |= STATUS_ASSOCIATING;
7271 priv->status &= ~STATUS_SECURITY_UPDATED;
7273 priv->assoc_network = network;
7275 #ifdef CONFIG_IPW_QOS
7276 ipw_qos_association(priv, network);
7279 err = ipw_send_associate(priv, &priv->assoc_request);
7281 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7285 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
7286 escape_essid(priv->essid, priv->essid_len),
7287 MAC_ARG(priv->bssid));
7292 static void ipw_roam(void *data)
7294 struct ipw_priv *priv = data;
7295 struct ieee80211_network *network = NULL;
7296 struct ipw_network_match match = {
7297 .network = priv->assoc_network
7300 /* The roaming process is as follows:
7302 * 1. Missed beacon threshold triggers the roaming process by
7303 * setting the status ROAM bit and requesting a scan.
7304 * 2. When the scan completes, it schedules the ROAM work
7305 * 3. The ROAM work looks at all of the known networks for one that
7306 * is a better network than the currently associated. If none
7307 * found, the ROAM process is over (ROAM bit cleared)
7308 * 4. If a better network is found, a disassociation request is
7310 * 5. When the disassociation completes, the roam work is again
7311 * scheduled. The second time through, the driver is no longer
7312 * associated, and the newly selected network is sent an
7313 * association request.
7314 * 6. At this point ,the roaming process is complete and the ROAM
7315 * status bit is cleared.
7318 /* If we are no longer associated, and the roaming bit is no longer
7319 * set, then we are not actively roaming, so just return */
7320 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7323 if (priv->status & STATUS_ASSOCIATED) {
7324 /* First pass through ROAM process -- look for a better
7326 unsigned long flags;
7327 u8 rssi = priv->assoc_network->stats.rssi;
7328 priv->assoc_network->stats.rssi = -128;
7329 spin_lock_irqsave(&priv->ieee->lock, flags);
7330 list_for_each_entry(network, &priv->ieee->network_list, list) {
7331 if (network != priv->assoc_network)
7332 ipw_best_network(priv, &match, network, 1);
7334 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7335 priv->assoc_network->stats.rssi = rssi;
7337 if (match.network == priv->assoc_network) {
7338 IPW_DEBUG_ASSOC("No better APs in this network to "
7340 priv->status &= ~STATUS_ROAMING;
7341 ipw_debug_config(priv);
7345 ipw_send_disassociate(priv, 1);
7346 priv->assoc_network = match.network;
7351 /* Second pass through ROAM process -- request association */
7352 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7353 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7354 priv->status &= ~STATUS_ROAMING;
7357 static void ipw_bg_roam(void *data)
7359 struct ipw_priv *priv = data;
7360 mutex_lock(&priv->mutex);
7362 mutex_unlock(&priv->mutex);
7365 static int ipw_associate(void *data)
7367 struct ipw_priv *priv = data;
7369 struct ieee80211_network *network = NULL;
7370 struct ipw_network_match match = {
7373 struct ipw_supported_rates *rates;
7374 struct list_head *element;
7375 unsigned long flags;
7377 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7378 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7382 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
7383 IPW_DEBUG_ASSOC("Not attempting association (already in "
7388 if (priv->status & STATUS_DISASSOCIATING) {
7389 IPW_DEBUG_ASSOC("Not attempting association (in "
7390 "disassociating)\n ");
7391 queue_work(priv->workqueue, &priv->associate);
7395 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
7396 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7401 if (!(priv->config & CFG_ASSOCIATE) &&
7402 !(priv->config & (CFG_STATIC_ESSID |
7403 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
7404 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
7408 /* Protect our use of the network_list */
7409 spin_lock_irqsave(&priv->ieee->lock, flags);
7410 list_for_each_entry(network, &priv->ieee->network_list, list)
7411 ipw_best_network(priv, &match, network, 0);
7413 network = match.network;
7414 rates = &match.rates;
7416 if (network == NULL &&
7417 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7418 priv->config & CFG_ADHOC_CREATE &&
7419 priv->config & CFG_STATIC_ESSID &&
7420 priv->config & CFG_STATIC_CHANNEL &&
7421 !list_empty(&priv->ieee->network_free_list)) {
7422 element = priv->ieee->network_free_list.next;
7423 network = list_entry(element, struct ieee80211_network, list);
7424 ipw_adhoc_create(priv, network);
7425 rates = &priv->rates;
7427 list_add_tail(&network->list, &priv->ieee->network_list);
7429 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7431 /* If we reached the end of the list, then we don't have any valid
7434 ipw_debug_config(priv);
7436 if (!(priv->status & STATUS_SCANNING)) {
7437 if (!(priv->config & CFG_SPEED_SCAN))
7438 queue_delayed_work(priv->workqueue,
7439 &priv->request_scan,
7442 queue_work(priv->workqueue,
7443 &priv->request_scan);
7449 ipw_associate_network(priv, network, rates, 0);
7454 static void ipw_bg_associate(void *data)
7456 struct ipw_priv *priv = data;
7457 mutex_lock(&priv->mutex);
7458 ipw_associate(data);
7459 mutex_unlock(&priv->mutex);
7462 static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7463 struct sk_buff *skb)
7465 struct ieee80211_hdr *hdr;
7468 hdr = (struct ieee80211_hdr *)skb->data;
7469 fc = le16_to_cpu(hdr->frame_ctl);
7470 if (!(fc & IEEE80211_FCTL_PROTECTED))
7473 fc &= ~IEEE80211_FCTL_PROTECTED;
7474 hdr->frame_ctl = cpu_to_le16(fc);
7475 switch (priv->ieee->sec.level) {
7477 /* Remove CCMP HDR */
7478 memmove(skb->data + IEEE80211_3ADDR_LEN,
7479 skb->data + IEEE80211_3ADDR_LEN + 8,
7480 skb->len - IEEE80211_3ADDR_LEN - 8);
7481 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
7487 memmove(skb->data + IEEE80211_3ADDR_LEN,
7488 skb->data + IEEE80211_3ADDR_LEN + 4,
7489 skb->len - IEEE80211_3ADDR_LEN - 4);
7490 skb_trim(skb, skb->len - 8); /* IV + ICV */
7495 printk(KERN_ERR "Unknow security level %d\n",
7496 priv->ieee->sec.level);
7501 static void ipw_handle_data_packet(struct ipw_priv *priv,
7502 struct ipw_rx_mem_buffer *rxb,
7503 struct ieee80211_rx_stats *stats)
7505 struct ieee80211_hdr_4addr *hdr;
7506 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7508 /* We received data from the HW, so stop the watchdog */
7509 priv->net_dev->trans_start = jiffies;
7511 /* We only process data packets if the
7512 * interface is open */
7513 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7514 skb_tailroom(rxb->skb))) {
7515 priv->ieee->stats.rx_errors++;
7516 priv->wstats.discard.misc++;
7517 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7519 } else if (unlikely(!netif_running(priv->net_dev))) {
7520 priv->ieee->stats.rx_dropped++;
7521 priv->wstats.discard.misc++;
7522 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7526 /* Advance skb->data to the start of the actual payload */
7527 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
7529 /* Set the size of the skb to the size of the frame */
7530 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
7532 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7534 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
7535 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7536 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
7537 (is_multicast_ether_addr(hdr->addr1) ?
7538 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
7539 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7541 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7542 priv->ieee->stats.rx_errors++;
7543 else { /* ieee80211_rx succeeded, so it now owns the SKB */
7545 __ipw_led_activity_on(priv);
7549 #ifdef CONFIG_IEEE80211_RADIOTAP
7550 static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7551 struct ipw_rx_mem_buffer *rxb,
7552 struct ieee80211_rx_stats *stats)
7554 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7555 struct ipw_rx_frame *frame = &pkt->u.frame;
7557 /* initial pull of some data */
7558 u16 received_channel = frame->received_channel;
7559 u8 antennaAndPhy = frame->antennaAndPhy;
7560 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7561 u16 pktrate = frame->rate;
7563 /* Magic struct that slots into the radiotap header -- no reason
7564 * to build this manually element by element, we can write it much
7565 * more efficiently than we can parse it. ORDER MATTERS HERE */
7566 struct ipw_rt_hdr *ipw_rt;
7568 short len = le16_to_cpu(pkt->u.frame.length);
7570 /* We received data from the HW, so stop the watchdog */
7571 priv->net_dev->trans_start = jiffies;
7573 /* We only process data packets if the
7574 * interface is open */
7575 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7576 skb_tailroom(rxb->skb))) {
7577 priv->ieee->stats.rx_errors++;
7578 priv->wstats.discard.misc++;
7579 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7581 } else if (unlikely(!netif_running(priv->net_dev))) {
7582 priv->ieee->stats.rx_dropped++;
7583 priv->wstats.discard.misc++;
7584 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7588 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7590 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7591 /* FIXME: Should alloc bigger skb instead */
7592 priv->ieee->stats.rx_dropped++;
7593 priv->wstats.discard.misc++;
7594 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7598 /* copy the frame itself */
7599 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7600 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7602 /* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7603 * part of our real header, saves a little time.
7605 * No longer necessary since we fill in all our data. Purge before merging
7607 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7608 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7611 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7613 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7614 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7615 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7617 /* Big bitfield of all the fields we provide in radiotap */
7618 ipw_rt->rt_hdr.it_present =
7619 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7620 (1 << IEEE80211_RADIOTAP_TSFT) |
7621 (1 << IEEE80211_RADIOTAP_RATE) |
7622 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7623 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7624 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
7625 (1 << IEEE80211_RADIOTAP_ANTENNA));
7627 /* Zero the flags, we'll add to them as we go */
7628 ipw_rt->rt_flags = 0;
7630 /* Convert signal to DBM */
7631 ipw_rt->rt_dbmsignal = antsignal;
7633 /* Convert the channel data and set the flags */
7634 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7635 if (received_channel > 14) { /* 802.11a */
7636 ipw_rt->rt_chbitmask =
7637 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7638 } else if (antennaAndPhy & 32) { /* 802.11b */
7639 ipw_rt->rt_chbitmask =
7640 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7641 } else { /* 802.11g */
7642 ipw_rt->rt_chbitmask =
7643 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7646 /* set the rate in multiples of 500k/s */
7648 case IPW_TX_RATE_1MB:
7649 ipw_rt->rt_rate = 2;
7651 case IPW_TX_RATE_2MB:
7652 ipw_rt->rt_rate = 4;
7654 case IPW_TX_RATE_5MB:
7655 ipw_rt->rt_rate = 10;
7657 case IPW_TX_RATE_6MB:
7658 ipw_rt->rt_rate = 12;
7660 case IPW_TX_RATE_9MB:
7661 ipw_rt->rt_rate = 18;
7663 case IPW_TX_RATE_11MB:
7664 ipw_rt->rt_rate = 22;
7666 case IPW_TX_RATE_12MB:
7667 ipw_rt->rt_rate = 24;
7669 case IPW_TX_RATE_18MB:
7670 ipw_rt->rt_rate = 36;
7672 case IPW_TX_RATE_24MB:
7673 ipw_rt->rt_rate = 48;
7675 case IPW_TX_RATE_36MB:
7676 ipw_rt->rt_rate = 72;
7678 case IPW_TX_RATE_48MB:
7679 ipw_rt->rt_rate = 96;
7681 case IPW_TX_RATE_54MB:
7682 ipw_rt->rt_rate = 108;
7685 ipw_rt->rt_rate = 0;
7689 /* antenna number */
7690 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7692 /* set the preamble flag if we have it */
7693 if ((antennaAndPhy & 64))
7694 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7696 /* Set the size of the skb to the size of the frame */
7697 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
7699 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7701 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7702 priv->ieee->stats.rx_errors++;
7703 else { /* ieee80211_rx succeeded, so it now owns the SKB */
7705 /* no LED during capture */
7710 #ifdef CONFIG_IPW2200_PROMISCUOUS
7711 #define ieee80211_is_probe_response(fc) \
7712 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7713 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7715 #define ieee80211_is_management(fc) \
7716 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7718 #define ieee80211_is_control(fc) \
7719 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7721 #define ieee80211_is_data(fc) \
7722 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
7724 #define ieee80211_is_assoc_request(fc) \
7725 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
7727 #define ieee80211_is_reassoc_request(fc) \
7728 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
7730 static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
7731 struct ipw_rx_mem_buffer *rxb,
7732 struct ieee80211_rx_stats *stats)
7734 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7735 struct ipw_rx_frame *frame = &pkt->u.frame;
7736 struct ipw_rt_hdr *ipw_rt;
7738 /* First cache any information we need before we overwrite
7739 * the information provided in the skb from the hardware */
7740 struct ieee80211_hdr *hdr;
7741 u16 channel = frame->received_channel;
7742 u8 phy_flags = frame->antennaAndPhy;
7743 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
7744 s8 noise = frame->noise;
7745 u8 rate = frame->rate;
7746 short len = le16_to_cpu(pkt->u.frame.length);
7748 struct sk_buff *skb;
7750 u16 filter = priv->prom_priv->filter;
7752 /* If the filter is set to not include Rx frames then return */
7753 if (filter & IPW_PROM_NO_RX)
7757 noise = priv->last_noise;
7759 /* We received data from the HW, so stop the watchdog */
7760 priv->prom_net_dev->trans_start = jiffies;
7762 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
7763 priv->prom_priv->ieee->stats.rx_errors++;
7764 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7768 /* We only process data packets if the interface is open */
7769 if (unlikely(!netif_running(priv->prom_net_dev))) {
7770 priv->prom_priv->ieee->stats.rx_dropped++;
7771 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7775 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7777 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7778 /* FIXME: Should alloc bigger skb instead */
7779 priv->prom_priv->ieee->stats.rx_dropped++;
7780 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7784 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
7785 if (ieee80211_is_management(hdr->frame_ctl)) {
7786 if (filter & IPW_PROM_NO_MGMT)
7788 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
7790 } else if (ieee80211_is_control(hdr->frame_ctl)) {
7791 if (filter & IPW_PROM_NO_CTL)
7793 if (filter & IPW_PROM_CTL_HEADER_ONLY)
7795 } else if (ieee80211_is_data(hdr->frame_ctl)) {
7796 if (filter & IPW_PROM_NO_DATA)
7798 if (filter & IPW_PROM_DATA_HEADER_ONLY)
7802 /* Copy the SKB since this is for the promiscuous side */
7803 skb = skb_copy(rxb->skb, GFP_ATOMIC);
7805 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
7809 /* copy the frame data to write after where the radiotap header goes */
7810 ipw_rt = (void *)skb->data;
7813 len = ieee80211_get_hdrlen(hdr->frame_ctl);
7815 memcpy(ipw_rt->payload, hdr, len);
7817 /* Zero the radiotap static buffer ... We only need to zero the bytes
7818 * NOT part of our real header, saves a little time.
7820 * No longer necessary since we fill in all our data. Purge before
7821 * merging patch officially.
7822 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7823 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7826 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7827 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7828 ipw_rt->rt_hdr.it_len = sizeof(*ipw_rt); /* total header+data */
7830 /* Set the size of the skb to the size of the frame */
7831 skb_put(skb, ipw_rt->rt_hdr.it_len + len);
7833 /* Big bitfield of all the fields we provide in radiotap */
7834 ipw_rt->rt_hdr.it_present =
7835 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7836 (1 << IEEE80211_RADIOTAP_TSFT) |
7837 (1 << IEEE80211_RADIOTAP_RATE) |
7838 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7839 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7840 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
7841 (1 << IEEE80211_RADIOTAP_ANTENNA));
7843 /* Zero the flags, we'll add to them as we go */
7844 ipw_rt->rt_flags = 0;
7846 ipw_rt->rt_tsf = tsf;
7848 /* Convert to DBM */
7849 ipw_rt->rt_dbmsignal = signal;
7850 ipw_rt->rt_dbmnoise = noise;
7852 /* Convert the channel data and set the flags */
7853 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
7854 if (channel > 14) { /* 802.11a */
7855 ipw_rt->rt_chbitmask =
7856 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7857 } else if (phy_flags & (1 << 5)) { /* 802.11b */
7858 ipw_rt->rt_chbitmask =
7859 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7860 } else { /* 802.11g */
7861 ipw_rt->rt_chbitmask =
7862 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7865 /* set the rate in multiples of 500k/s */
7867 case IPW_TX_RATE_1MB:
7868 ipw_rt->rt_rate = 2;
7870 case IPW_TX_RATE_2MB:
7871 ipw_rt->rt_rate = 4;
7873 case IPW_TX_RATE_5MB:
7874 ipw_rt->rt_rate = 10;
7876 case IPW_TX_RATE_6MB:
7877 ipw_rt->rt_rate = 12;
7879 case IPW_TX_RATE_9MB:
7880 ipw_rt->rt_rate = 18;
7882 case IPW_TX_RATE_11MB:
7883 ipw_rt->rt_rate = 22;
7885 case IPW_TX_RATE_12MB:
7886 ipw_rt->rt_rate = 24;
7888 case IPW_TX_RATE_18MB:
7889 ipw_rt->rt_rate = 36;
7891 case IPW_TX_RATE_24MB:
7892 ipw_rt->rt_rate = 48;
7894 case IPW_TX_RATE_36MB:
7895 ipw_rt->rt_rate = 72;
7897 case IPW_TX_RATE_48MB:
7898 ipw_rt->rt_rate = 96;
7900 case IPW_TX_RATE_54MB:
7901 ipw_rt->rt_rate = 108;
7904 ipw_rt->rt_rate = 0;
7908 /* antenna number */
7909 ipw_rt->rt_antenna = (phy_flags & 3);
7911 /* set the preamble flag if we have it */
7912 if (phy_flags & (1 << 6))
7913 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7915 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
7917 if (!ieee80211_rx(priv->prom_priv->ieee, skb, stats)) {
7918 priv->prom_priv->ieee->stats.rx_errors++;
7919 dev_kfree_skb_any(skb);
7924 static int is_network_packet(struct ipw_priv *priv,
7925 struct ieee80211_hdr_4addr *header)
7927 /* Filter incoming packets to determine if they are targetted toward
7928 * this network, discarding packets coming from ourselves */
7929 switch (priv->ieee->iw_mode) {
7930 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
7931 /* packets from our adapter are dropped (echo) */
7932 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7935 /* {broad,multi}cast packets to our BSSID go through */
7936 if (is_multicast_ether_addr(header->addr1))
7937 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
7939 /* packets to our adapter go through */
7940 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7943 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
7944 /* packets from our adapter are dropped (echo) */
7945 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7948 /* {broad,multi}cast packets to our BSS go through */
7949 if (is_multicast_ether_addr(header->addr1))
7950 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7952 /* packets to our adapter go through */
7953 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7960 #define IPW_PACKET_RETRY_TIME HZ
7962 static int is_duplicate_packet(struct ipw_priv *priv,
7963 struct ieee80211_hdr_4addr *header)
7965 u16 sc = le16_to_cpu(header->seq_ctl);
7966 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7967 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7968 u16 *last_seq, *last_frag;
7969 unsigned long *last_time;
7971 switch (priv->ieee->iw_mode) {
7974 struct list_head *p;
7975 struct ipw_ibss_seq *entry = NULL;
7976 u8 *mac = header->addr2;
7977 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
7979 __list_for_each(p, &priv->ibss_mac_hash[index]) {
7981 list_entry(p, struct ipw_ibss_seq, list);
7982 if (!memcmp(entry->mac, mac, ETH_ALEN))
7985 if (p == &priv->ibss_mac_hash[index]) {
7986 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
7989 ("Cannot malloc new mac entry\n");
7992 memcpy(entry->mac, mac, ETH_ALEN);
7993 entry->seq_num = seq;
7994 entry->frag_num = frag;
7995 entry->packet_time = jiffies;
7996 list_add(&entry->list,
7997 &priv->ibss_mac_hash[index]);
8000 last_seq = &entry->seq_num;
8001 last_frag = &entry->frag_num;
8002 last_time = &entry->packet_time;
8006 last_seq = &priv->last_seq_num;
8007 last_frag = &priv->last_frag_num;
8008 last_time = &priv->last_packet_time;
8013 if ((*last_seq == seq) &&
8014 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8015 if (*last_frag == frag)
8017 if (*last_frag + 1 != frag)
8018 /* out-of-order fragment */
8024 *last_time = jiffies;
8028 /* Comment this line now since we observed the card receives
8029 * duplicate packets but the FCTL_RETRY bit is not set in the
8030 * IBSS mode with fragmentation enabled.
8031 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
8035 static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8036 struct ipw_rx_mem_buffer *rxb,
8037 struct ieee80211_rx_stats *stats)
8039 struct sk_buff *skb = rxb->skb;
8040 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
8041 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
8042 (skb->data + IPW_RX_FRAME_SIZE);
8044 ieee80211_rx_mgt(priv->ieee, header, stats);
8046 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8047 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8048 IEEE80211_STYPE_PROBE_RESP) ||
8049 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8050 IEEE80211_STYPE_BEACON))) {
8051 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8052 ipw_add_station(priv, header->addr2);
8055 if (priv->config & CFG_NET_STATS) {
8056 IPW_DEBUG_HC("sending stat packet\n");
8058 /* Set the size of the skb to the size of the full
8059 * ipw header and 802.11 frame */
8060 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8063 /* Advance past the ipw packet header to the 802.11 frame */
8064 skb_pull(skb, IPW_RX_FRAME_SIZE);
8066 /* Push the ieee80211_rx_stats before the 802.11 frame */
8067 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8069 skb->dev = priv->ieee->dev;
8071 /* Point raw at the ieee80211_stats */
8072 skb->mac.raw = skb->data;
8074 skb->pkt_type = PACKET_OTHERHOST;
8075 skb->protocol = __constant_htons(ETH_P_80211_STATS);
8076 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8083 * Main entry function for recieving a packet with 80211 headers. This
8084 * should be called when ever the FW has notified us that there is a new
8085 * skb in the recieve queue.
8087 static void ipw_rx(struct ipw_priv *priv)
8089 struct ipw_rx_mem_buffer *rxb;
8090 struct ipw_rx_packet *pkt;
8091 struct ieee80211_hdr_4addr *header;
8095 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8096 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
8097 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
8100 rxb = priv->rxq->queue[i];
8101 if (unlikely(rxb == NULL)) {
8102 printk(KERN_CRIT "Queue not allocated!\n");
8105 priv->rxq->queue[i] = NULL;
8107 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
8109 PCI_DMA_FROMDEVICE);
8111 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8112 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8113 pkt->header.message_type,
8114 pkt->header.rx_seq_num, pkt->header.control_bits);
8116 switch (pkt->header.message_type) {
8117 case RX_FRAME_TYPE: /* 802.11 frame */ {
8118 struct ieee80211_rx_stats stats = {
8120 le16_to_cpu(pkt->u.frame.rssi_dbm) -
8123 le16_to_cpu(pkt->u.frame.rssi_dbm) -
8124 IPW_RSSI_TO_DBM + 0x100,
8126 le16_to_cpu(pkt->u.frame.noise),
8127 .rate = pkt->u.frame.rate,
8128 .mac_time = jiffies,
8130 pkt->u.frame.received_channel,
8133 control & (1 << 0)) ?
8134 IEEE80211_24GHZ_BAND :
8135 IEEE80211_52GHZ_BAND,
8136 .len = le16_to_cpu(pkt->u.frame.length),
8139 if (stats.rssi != 0)
8140 stats.mask |= IEEE80211_STATMASK_RSSI;
8141 if (stats.signal != 0)
8142 stats.mask |= IEEE80211_STATMASK_SIGNAL;
8143 if (stats.noise != 0)
8144 stats.mask |= IEEE80211_STATMASK_NOISE;
8145 if (stats.rate != 0)
8146 stats.mask |= IEEE80211_STATMASK_RATE;
8150 #ifdef CONFIG_IPW2200_PROMISCUOUS
8151 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8152 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8155 #ifdef CONFIG_IPW2200_MONITOR
8156 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
8157 #ifdef CONFIG_IEEE80211_RADIOTAP
8159 ipw_handle_data_packet_monitor(priv,
8163 ipw_handle_data_packet(priv, rxb,
8171 (struct ieee80211_hdr_4addr *)(rxb->skb->
8174 /* TODO: Check Ad-Hoc dest/source and make sure
8175 * that we are actually parsing these packets
8176 * correctly -- we should probably use the
8177 * frame control of the packet and disregard
8178 * the current iw_mode */
8181 is_network_packet(priv, header);
8182 if (network_packet && priv->assoc_network) {
8183 priv->assoc_network->stats.rssi =
8185 priv->exp_avg_rssi =
8186 exponential_average(priv->exp_avg_rssi,
8187 stats.rssi, DEPTH_RSSI);
8190 IPW_DEBUG_RX("Frame: len=%u\n",
8191 le16_to_cpu(pkt->u.frame.length));
8193 if (le16_to_cpu(pkt->u.frame.length) <
8194 ieee80211_get_hdrlen(le16_to_cpu(
8195 header->frame_ctl))) {
8197 ("Received packet is too small. "
8199 priv->ieee->stats.rx_errors++;
8200 priv->wstats.discard.misc++;
8204 switch (WLAN_FC_GET_TYPE
8205 (le16_to_cpu(header->frame_ctl))) {
8207 case IEEE80211_FTYPE_MGMT:
8208 ipw_handle_mgmt_packet(priv, rxb,
8212 case IEEE80211_FTYPE_CTL:
8215 case IEEE80211_FTYPE_DATA:
8216 if (unlikely(!network_packet ||
8217 is_duplicate_packet(priv,
8220 IPW_DEBUG_DROP("Dropping: "
8233 ipw_handle_data_packet(priv, rxb,
8241 case RX_HOST_NOTIFICATION_TYPE:{
8243 ("Notification: subtype=%02X flags=%02X size=%d\n",
8244 pkt->u.notification.subtype,
8245 pkt->u.notification.flags,
8246 pkt->u.notification.size);
8247 ipw_rx_notification(priv, &pkt->u.notification);
8252 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8253 pkt->header.message_type);
8257 /* For now we just don't re-use anything. We can tweak this
8258 * later to try and re-use notification packets and SKBs that
8259 * fail to Rx correctly */
8260 if (rxb->skb != NULL) {
8261 dev_kfree_skb_any(rxb->skb);
8265 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
8266 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
8267 list_add_tail(&rxb->list, &priv->rxq->rx_used);
8269 i = (i + 1) % RX_QUEUE_SIZE;
8272 /* Backtrack one entry */
8273 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
8275 ipw_rx_queue_restock(priv);
8278 #define DEFAULT_RTS_THRESHOLD 2304U
8279 #define MIN_RTS_THRESHOLD 1U
8280 #define MAX_RTS_THRESHOLD 2304U
8281 #define DEFAULT_BEACON_INTERVAL 100U
8282 #define DEFAULT_SHORT_RETRY_LIMIT 7U
8283 #define DEFAULT_LONG_RETRY_LIMIT 4U
8287 * @option: options to control different reset behaviour
8288 * 0 = reset everything except the 'disable' module_param
8289 * 1 = reset everything and print out driver info (for probe only)
8290 * 2 = reset everything
8292 static int ipw_sw_reset(struct ipw_priv *priv, int option)
8294 int band, modulation;
8295 int old_mode = priv->ieee->iw_mode;
8297 /* Initialize module parameter values here */
8300 /* We default to disabling the LED code as right now it causes
8301 * too many systems to lock up... */
8303 priv->config |= CFG_NO_LED;
8306 priv->config |= CFG_ASSOCIATE;
8308 IPW_DEBUG_INFO("Auto associate disabled.\n");
8311 priv->config |= CFG_ADHOC_CREATE;
8313 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8315 priv->config &= ~CFG_STATIC_ESSID;
8316 priv->essid_len = 0;
8317 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8319 if (disable && option) {
8320 priv->status |= STATUS_RF_KILL_SW;
8321 IPW_DEBUG_INFO("Radio disabled.\n");
8325 priv->config |= CFG_STATIC_CHANNEL;
8326 priv->channel = channel;
8327 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8328 /* TODO: Validate that provided channel is in range */
8330 #ifdef CONFIG_IPW_QOS
8331 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8332 burst_duration_CCK, burst_duration_OFDM);
8333 #endif /* CONFIG_IPW_QOS */
8337 priv->ieee->iw_mode = IW_MODE_ADHOC;
8338 priv->net_dev->type = ARPHRD_ETHER;
8341 #ifdef CONFIG_IPW2200_MONITOR
8343 priv->ieee->iw_mode = IW_MODE_MONITOR;
8344 #ifdef CONFIG_IEEE80211_RADIOTAP
8345 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8347 priv->net_dev->type = ARPHRD_IEEE80211;
8353 priv->net_dev->type = ARPHRD_ETHER;
8354 priv->ieee->iw_mode = IW_MODE_INFRA;
8359 priv->ieee->host_encrypt = 0;
8360 priv->ieee->host_encrypt_msdu = 0;
8361 priv->ieee->host_decrypt = 0;
8362 priv->ieee->host_mc_decrypt = 0;
8364 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
8366 /* IPW2200/2915 is abled to do hardware fragmentation. */
8367 priv->ieee->host_open_frag = 0;
8369 if ((priv->pci_dev->device == 0x4223) ||
8370 (priv->pci_dev->device == 0x4224)) {
8372 printk(KERN_INFO DRV_NAME
8373 ": Detected Intel PRO/Wireless 2915ABG Network "
8375 priv->ieee->abg_true = 1;
8376 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8377 modulation = IEEE80211_OFDM_MODULATION |
8378 IEEE80211_CCK_MODULATION;
8379 priv->adapter = IPW_2915ABG;
8380 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
8383 printk(KERN_INFO DRV_NAME
8384 ": Detected Intel PRO/Wireless 2200BG Network "
8387 priv->ieee->abg_true = 0;
8388 band = IEEE80211_24GHZ_BAND;
8389 modulation = IEEE80211_OFDM_MODULATION |
8390 IEEE80211_CCK_MODULATION;
8391 priv->adapter = IPW_2200BG;
8392 priv->ieee->mode = IEEE_G | IEEE_B;
8395 priv->ieee->freq_band = band;
8396 priv->ieee->modulation = modulation;
8398 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
8400 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8401 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8403 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8404 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8405 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
8407 /* If power management is turned on, default to AC mode */
8408 priv->power_mode = IPW_POWER_AC;
8409 priv->tx_power = IPW_TX_POWER_DEFAULT;
8411 return old_mode == priv->ieee->iw_mode;
8415 * This file defines the Wireless Extension handlers. It does not
8416 * define any methods of hardware manipulation and relies on the
8417 * functions defined in ipw_main to provide the HW interaction.
8419 * The exception to this is the use of the ipw_get_ordinal()
8420 * function used to poll the hardware vs. making unecessary calls.
8424 static int ipw_wx_get_name(struct net_device *dev,
8425 struct iw_request_info *info,
8426 union iwreq_data *wrqu, char *extra)
8428 struct ipw_priv *priv = ieee80211_priv(dev);
8429 mutex_lock(&priv->mutex);
8430 if (priv->status & STATUS_RF_KILL_MASK)
8431 strcpy(wrqu->name, "radio off");
8432 else if (!(priv->status & STATUS_ASSOCIATED))
8433 strcpy(wrqu->name, "unassociated");
8435 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8436 ipw_modes[priv->assoc_request.ieee_mode]);
8437 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
8438 mutex_unlock(&priv->mutex);
8442 static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8445 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8446 priv->config &= ~CFG_STATIC_CHANNEL;
8447 IPW_DEBUG_ASSOC("Attempting to associate with new "
8449 ipw_associate(priv);
8453 priv->config |= CFG_STATIC_CHANNEL;
8455 if (priv->channel == channel) {
8456 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8461 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8462 priv->channel = channel;
8464 #ifdef CONFIG_IPW2200_MONITOR
8465 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
8467 if (priv->status & STATUS_SCANNING) {
8468 IPW_DEBUG_SCAN("Scan abort triggered due to "
8469 "channel change.\n");
8470 ipw_abort_scan(priv);
8473 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8476 if (priv->status & STATUS_SCANNING)
8477 IPW_DEBUG_SCAN("Still scanning...\n");
8479 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8484 #endif /* CONFIG_IPW2200_MONITOR */
8486 /* Network configuration changed -- force [re]association */
8487 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8488 if (!ipw_disassociate(priv))
8489 ipw_associate(priv);
8494 static int ipw_wx_set_freq(struct net_device *dev,
8495 struct iw_request_info *info,
8496 union iwreq_data *wrqu, char *extra)
8498 struct ipw_priv *priv = ieee80211_priv(dev);
8499 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
8500 struct iw_freq *fwrq = &wrqu->freq;
8506 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
8507 mutex_lock(&priv->mutex);
8508 ret = ipw_set_channel(priv, 0);
8509 mutex_unlock(&priv->mutex);
8512 /* if setting by freq convert to channel */
8514 channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
8520 if (!(band = ieee80211_is_valid_channel(priv->ieee, channel)))
8523 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
8524 i = ieee80211_channel_to_index(priv->ieee, channel);
8528 flags = (band == IEEE80211_24GHZ_BAND) ?
8529 geo->bg[i].flags : geo->a[i].flags;
8530 if (flags & IEEE80211_CH_PASSIVE_ONLY) {
8531 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8536 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
8537 mutex_lock(&priv->mutex);
8538 ret = ipw_set_channel(priv, channel);
8539 mutex_unlock(&priv->mutex);
8543 static int ipw_wx_get_freq(struct net_device *dev,
8544 struct iw_request_info *info,
8545 union iwreq_data *wrqu, char *extra)
8547 struct ipw_priv *priv = ieee80211_priv(dev);
8551 /* If we are associated, trying to associate, or have a statically
8552 * configured CHANNEL then return that; otherwise return ANY */
8553 mutex_lock(&priv->mutex);
8554 if (priv->config & CFG_STATIC_CHANNEL ||
8555 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8556 wrqu->freq.m = priv->channel;
8560 mutex_unlock(&priv->mutex);
8561 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8565 static int ipw_wx_set_mode(struct net_device *dev,
8566 struct iw_request_info *info,
8567 union iwreq_data *wrqu, char *extra)
8569 struct ipw_priv *priv = ieee80211_priv(dev);
8572 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8574 switch (wrqu->mode) {
8575 #ifdef CONFIG_IPW2200_MONITOR
8576 case IW_MODE_MONITOR:
8582 wrqu->mode = IW_MODE_INFRA;
8587 if (wrqu->mode == priv->ieee->iw_mode)
8590 mutex_lock(&priv->mutex);
8592 ipw_sw_reset(priv, 0);
8594 #ifdef CONFIG_IPW2200_MONITOR
8595 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
8596 priv->net_dev->type = ARPHRD_ETHER;
8598 if (wrqu->mode == IW_MODE_MONITOR)
8599 #ifdef CONFIG_IEEE80211_RADIOTAP
8600 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8602 priv->net_dev->type = ARPHRD_IEEE80211;
8604 #endif /* CONFIG_IPW2200_MONITOR */
8606 /* Free the existing firmware and reset the fw_loaded
8607 * flag so ipw_load() will bring in the new firmawre */
8610 priv->ieee->iw_mode = wrqu->mode;
8612 queue_work(priv->workqueue, &priv->adapter_restart);
8613 mutex_unlock(&priv->mutex);
8617 static int ipw_wx_get_mode(struct net_device *dev,
8618 struct iw_request_info *info,
8619 union iwreq_data *wrqu, char *extra)
8621 struct ipw_priv *priv = ieee80211_priv(dev);
8622 mutex_lock(&priv->mutex);
8623 wrqu->mode = priv->ieee->iw_mode;
8624 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
8625 mutex_unlock(&priv->mutex);
8629 /* Values are in microsecond */
8630 static const s32 timeout_duration[] = {
8638 static const s32 period_duration[] = {
8646 static int ipw_wx_get_range(struct net_device *dev,
8647 struct iw_request_info *info,
8648 union iwreq_data *wrqu, char *extra)
8650 struct ipw_priv *priv = ieee80211_priv(dev);
8651 struct iw_range *range = (struct iw_range *)extra;
8652 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
8655 wrqu->data.length = sizeof(*range);
8656 memset(range, 0, sizeof(*range));
8658 /* 54Mbs == ~27 Mb/s real (802.11g) */
8659 range->throughput = 27 * 1000 * 1000;
8661 range->max_qual.qual = 100;
8662 /* TODO: Find real max RSSI and stick here */
8663 range->max_qual.level = 0;
8664 range->max_qual.noise = 0;
8665 range->max_qual.updated = 7; /* Updated all three */
8667 range->avg_qual.qual = 70;
8668 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
8669 range->avg_qual.level = 0; /* FIXME to real average level */
8670 range->avg_qual.noise = 0;
8671 range->avg_qual.updated = 7; /* Updated all three */
8672 mutex_lock(&priv->mutex);
8673 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
8675 for (i = 0; i < range->num_bitrates; i++)
8676 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
8679 range->max_rts = DEFAULT_RTS_THRESHOLD;
8680 range->min_frag = MIN_FRAG_THRESHOLD;
8681 range->max_frag = MAX_FRAG_THRESHOLD;
8683 range->encoding_size[0] = 5;
8684 range->encoding_size[1] = 13;
8685 range->num_encoding_sizes = 2;
8686 range->max_encoding_tokens = WEP_KEYS;
8688 /* Set the Wireless Extension versions */
8689 range->we_version_compiled = WIRELESS_EXT;
8690 range->we_version_source = 18;
8693 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
8694 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8695 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8696 (geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8699 range->freq[i].i = geo->bg[j].channel;
8700 range->freq[i].m = geo->bg[j].freq * 100000;
8701 range->freq[i].e = 1;
8706 if (priv->ieee->mode & IEEE_A) {
8707 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8708 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8709 (geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8712 range->freq[i].i = geo->a[j].channel;
8713 range->freq[i].m = geo->a[j].freq * 100000;
8714 range->freq[i].e = 1;
8719 range->num_channels = i;
8720 range->num_frequency = i;
8722 mutex_unlock(&priv->mutex);
8724 /* Event capability (kernel + driver) */
8725 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8726 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
8727 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
8728 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
8729 range->event_capa[1] = IW_EVENT_CAPA_K_1;
8731 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8732 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8734 IPW_DEBUG_WX("GET Range\n");
8738 static int ipw_wx_set_wap(struct net_device *dev,
8739 struct iw_request_info *info,
8740 union iwreq_data *wrqu, char *extra)
8742 struct ipw_priv *priv = ieee80211_priv(dev);
8744 static const unsigned char any[] = {
8745 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8747 static const unsigned char off[] = {
8748 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8751 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
8753 mutex_lock(&priv->mutex);
8754 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8755 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8756 /* we disable mandatory BSSID association */
8757 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8758 priv->config &= ~CFG_STATIC_BSSID;
8759 IPW_DEBUG_ASSOC("Attempting to associate with new "
8761 ipw_associate(priv);
8762 mutex_unlock(&priv->mutex);
8766 priv->config |= CFG_STATIC_BSSID;
8767 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8768 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
8769 mutex_unlock(&priv->mutex);
8773 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8774 MAC_ARG(wrqu->ap_addr.sa_data));
8776 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8778 /* Network configuration changed -- force [re]association */
8779 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8780 if (!ipw_disassociate(priv))
8781 ipw_associate(priv);
8783 mutex_unlock(&priv->mutex);
8787 static int ipw_wx_get_wap(struct net_device *dev,
8788 struct iw_request_info *info,
8789 union iwreq_data *wrqu, char *extra)
8791 struct ipw_priv *priv = ieee80211_priv(dev);
8792 /* If we are associated, trying to associate, or have a statically
8793 * configured BSSID then return that; otherwise return ANY */
8794 mutex_lock(&priv->mutex);
8795 if (priv->config & CFG_STATIC_BSSID ||
8796 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8797 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
8798 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
8800 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8802 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8803 MAC_ARG(wrqu->ap_addr.sa_data));
8804 mutex_unlock(&priv->mutex);
8808 static int ipw_wx_set_essid(struct net_device *dev,
8809 struct iw_request_info *info,
8810 union iwreq_data *wrqu, char *extra)
8812 struct ipw_priv *priv = ieee80211_priv(dev);
8813 char *essid = ""; /* ANY */
8815 mutex_lock(&priv->mutex);
8816 if (wrqu->essid.flags && wrqu->essid.length) {
8817 length = wrqu->essid.length - 1;
8821 IPW_DEBUG_WX("Setting ESSID to ANY\n");
8822 if ((priv->config & CFG_STATIC_ESSID) &&
8823 !(priv->status & (STATUS_ASSOCIATED |
8824 STATUS_ASSOCIATING))) {
8825 IPW_DEBUG_ASSOC("Attempting to associate with new "
8827 priv->config &= ~CFG_STATIC_ESSID;
8828 ipw_associate(priv);
8830 mutex_unlock(&priv->mutex);
8834 length = min(length, IW_ESSID_MAX_SIZE);
8836 priv->config |= CFG_STATIC_ESSID;
8838 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8839 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
8840 mutex_unlock(&priv->mutex);
8844 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8847 priv->essid_len = length;
8848 memcpy(priv->essid, essid, priv->essid_len);
8850 /* Network configuration changed -- force [re]association */
8851 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8852 if (!ipw_disassociate(priv))
8853 ipw_associate(priv);
8855 mutex_unlock(&priv->mutex);
8859 static int ipw_wx_get_essid(struct net_device *dev,
8860 struct iw_request_info *info,
8861 union iwreq_data *wrqu, char *extra)
8863 struct ipw_priv *priv = ieee80211_priv(dev);
8865 /* If we are associated, trying to associate, or have a statically
8866 * configured ESSID then return that; otherwise return ANY */
8867 mutex_lock(&priv->mutex);
8868 if (priv->config & CFG_STATIC_ESSID ||
8869 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8870 IPW_DEBUG_WX("Getting essid: '%s'\n",
8871 escape_essid(priv->essid, priv->essid_len));
8872 memcpy(extra, priv->essid, priv->essid_len);
8873 wrqu->essid.length = priv->essid_len;
8874 wrqu->essid.flags = 1; /* active */
8876 IPW_DEBUG_WX("Getting essid: ANY\n");
8877 wrqu->essid.length = 0;
8878 wrqu->essid.flags = 0; /* active */
8880 mutex_unlock(&priv->mutex);
8884 static int ipw_wx_set_nick(struct net_device *dev,
8885 struct iw_request_info *info,
8886 union iwreq_data *wrqu, char *extra)
8888 struct ipw_priv *priv = ieee80211_priv(dev);
8890 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8891 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8893 mutex_lock(&priv->mutex);
8894 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
8895 memset(priv->nick, 0, sizeof(priv->nick));
8896 memcpy(priv->nick, extra, wrqu->data.length);
8897 IPW_DEBUG_TRACE("<<\n");
8898 mutex_unlock(&priv->mutex);
8903 static int ipw_wx_get_nick(struct net_device *dev,
8904 struct iw_request_info *info,
8905 union iwreq_data *wrqu, char *extra)
8907 struct ipw_priv *priv = ieee80211_priv(dev);
8908 IPW_DEBUG_WX("Getting nick\n");
8909 mutex_lock(&priv->mutex);
8910 wrqu->data.length = strlen(priv->nick) + 1;
8911 memcpy(extra, priv->nick, wrqu->data.length);
8912 wrqu->data.flags = 1; /* active */
8913 mutex_unlock(&priv->mutex);
8917 static int ipw_wx_set_sens(struct net_device *dev,
8918 struct iw_request_info *info,
8919 union iwreq_data *wrqu, char *extra)
8921 struct ipw_priv *priv = ieee80211_priv(dev);
8924 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
8925 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
8926 mutex_lock(&priv->mutex);
8928 if (wrqu->sens.fixed == 0)
8930 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8931 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8934 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
8935 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
8940 priv->roaming_threshold = wrqu->sens.value;
8941 priv->disassociate_threshold = 3*wrqu->sens.value;
8943 mutex_unlock(&priv->mutex);
8947 static int ipw_wx_get_sens(struct net_device *dev,
8948 struct iw_request_info *info,
8949 union iwreq_data *wrqu, char *extra)
8951 struct ipw_priv *priv = ieee80211_priv(dev);
8952 mutex_lock(&priv->mutex);
8953 wrqu->sens.fixed = 1;
8954 wrqu->sens.value = priv->roaming_threshold;
8955 mutex_unlock(&priv->mutex);
8957 IPW_DEBUG_WX("GET roaming threshold -> %s %d \n",
8958 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
8963 static int ipw_wx_set_rate(struct net_device *dev,
8964 struct iw_request_info *info,
8965 union iwreq_data *wrqu, char *extra)
8967 /* TODO: We should use semaphores or locks for access to priv */
8968 struct ipw_priv *priv = ieee80211_priv(dev);
8969 u32 target_rate = wrqu->bitrate.value;
8972 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8973 /* value = X, fixed = 1 means only rate X */
8974 /* value = X, fixed = 0 means all rates lower equal X */
8976 if (target_rate == -1) {
8978 mask = IEEE80211_DEFAULT_RATES_MASK;
8979 /* Now we should reassociate */
8984 fixed = wrqu->bitrate.fixed;
8986 if (target_rate == 1000000 || !fixed)
8987 mask |= IEEE80211_CCK_RATE_1MB_MASK;
8988 if (target_rate == 1000000)
8991 if (target_rate == 2000000 || !fixed)
8992 mask |= IEEE80211_CCK_RATE_2MB_MASK;
8993 if (target_rate == 2000000)
8996 if (target_rate == 5500000 || !fixed)
8997 mask |= IEEE80211_CCK_RATE_5MB_MASK;
8998 if (target_rate == 5500000)
9001 if (target_rate == 6000000 || !fixed)
9002 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
9003 if (target_rate == 6000000)
9006 if (target_rate == 9000000 || !fixed)
9007 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
9008 if (target_rate == 9000000)
9011 if (target_rate == 11000000 || !fixed)
9012 mask |= IEEE80211_CCK_RATE_11MB_MASK;
9013 if (target_rate == 11000000)
9016 if (target_rate == 12000000 || !fixed)
9017 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
9018 if (target_rate == 12000000)
9021 if (target_rate == 18000000 || !fixed)
9022 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
9023 if (target_rate == 18000000)
9026 if (target_rate == 24000000 || !fixed)
9027 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
9028 if (target_rate == 24000000)
9031 if (target_rate == 36000000 || !fixed)
9032 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
9033 if (target_rate == 36000000)
9036 if (target_rate == 48000000 || !fixed)
9037 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
9038 if (target_rate == 48000000)
9041 if (target_rate == 54000000 || !fixed)
9042 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
9043 if (target_rate == 54000000)
9046 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9050 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9051 mask, fixed ? "fixed" : "sub-rates");
9052 mutex_lock(&priv->mutex);
9053 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
9054 priv->config &= ~CFG_FIXED_RATE;
9055 ipw_set_fixed_rate(priv, priv->ieee->mode);
9057 priv->config |= CFG_FIXED_RATE;
9059 if (priv->rates_mask == mask) {
9060 IPW_DEBUG_WX("Mask set to current mask.\n");
9061 mutex_unlock(&priv->mutex);
9065 priv->rates_mask = mask;
9067 /* Network configuration changed -- force [re]association */
9068 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9069 if (!ipw_disassociate(priv))
9070 ipw_associate(priv);
9072 mutex_unlock(&priv->mutex);
9076 static int ipw_wx_get_rate(struct net_device *dev,
9077 struct iw_request_info *info,
9078 union iwreq_data *wrqu, char *extra)
9080 struct ipw_priv *priv = ieee80211_priv(dev);
9081 mutex_lock(&priv->mutex);
9082 wrqu->bitrate.value = priv->last_rate;
9083 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
9084 mutex_unlock(&priv->mutex);
9085 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
9089 static int ipw_wx_set_rts(struct net_device *dev,
9090 struct iw_request_info *info,
9091 union iwreq_data *wrqu, char *extra)
9093 struct ipw_priv *priv = ieee80211_priv(dev);
9094 mutex_lock(&priv->mutex);
9095 if (wrqu->rts.disabled)
9096 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9098 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
9099 wrqu->rts.value > MAX_RTS_THRESHOLD) {
9100 mutex_unlock(&priv->mutex);
9103 priv->rts_threshold = wrqu->rts.value;
9106 ipw_send_rts_threshold(priv, priv->rts_threshold);
9107 mutex_unlock(&priv->mutex);
9108 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
9112 static int ipw_wx_get_rts(struct net_device *dev,
9113 struct iw_request_info *info,
9114 union iwreq_data *wrqu, char *extra)
9116 struct ipw_priv *priv = ieee80211_priv(dev);
9117 mutex_lock(&priv->mutex);
9118 wrqu->rts.value = priv->rts_threshold;
9119 wrqu->rts.fixed = 0; /* no auto select */
9120 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
9121 mutex_unlock(&priv->mutex);
9122 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
9126 static int ipw_wx_set_txpow(struct net_device *dev,
9127 struct iw_request_info *info,
9128 union iwreq_data *wrqu, char *extra)
9130 struct ipw_priv *priv = ieee80211_priv(dev);
9133 mutex_lock(&priv->mutex);
9134 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
9139 if (!wrqu->power.fixed)
9140 wrqu->power.value = IPW_TX_POWER_DEFAULT;
9142 if (wrqu->power.flags != IW_TXPOW_DBM) {
9147 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
9148 (wrqu->power.value < IPW_TX_POWER_MIN)) {
9153 priv->tx_power = wrqu->power.value;
9154 err = ipw_set_tx_power(priv);
9156 mutex_unlock(&priv->mutex);
9160 static int ipw_wx_get_txpow(struct net_device *dev,
9161 struct iw_request_info *info,
9162 union iwreq_data *wrqu, char *extra)
9164 struct ipw_priv *priv = ieee80211_priv(dev);
9165 mutex_lock(&priv->mutex);
9166 wrqu->power.value = priv->tx_power;
9167 wrqu->power.fixed = 1;
9168 wrqu->power.flags = IW_TXPOW_DBM;
9169 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
9170 mutex_unlock(&priv->mutex);
9172 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
9173 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9178 static int ipw_wx_set_frag(struct net_device *dev,
9179 struct iw_request_info *info,
9180 union iwreq_data *wrqu, char *extra)
9182 struct ipw_priv *priv = ieee80211_priv(dev);
9183 mutex_lock(&priv->mutex);
9184 if (wrqu->frag.disabled)
9185 priv->ieee->fts = DEFAULT_FTS;
9187 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
9188 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
9189 mutex_unlock(&priv->mutex);
9193 priv->ieee->fts = wrqu->frag.value & ~0x1;
9196 ipw_send_frag_threshold(priv, wrqu->frag.value);
9197 mutex_unlock(&priv->mutex);
9198 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
9202 static int ipw_wx_get_frag(struct net_device *dev,
9203 struct iw_request_info *info,
9204 union iwreq_data *wrqu, char *extra)
9206 struct ipw_priv *priv = ieee80211_priv(dev);
9207 mutex_lock(&priv->mutex);
9208 wrqu->frag.value = priv->ieee->fts;
9209 wrqu->frag.fixed = 0; /* no auto select */
9210 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
9211 mutex_unlock(&priv->mutex);
9212 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
9217 static int ipw_wx_set_retry(struct net_device *dev,
9218 struct iw_request_info *info,
9219 union iwreq_data *wrqu, char *extra)
9221 struct ipw_priv *priv = ieee80211_priv(dev);
9223 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9226 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9229 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
9232 mutex_lock(&priv->mutex);
9233 if (wrqu->retry.flags & IW_RETRY_MIN)
9234 priv->short_retry_limit = (u8) wrqu->retry.value;
9235 else if (wrqu->retry.flags & IW_RETRY_MAX)
9236 priv->long_retry_limit = (u8) wrqu->retry.value;
9238 priv->short_retry_limit = (u8) wrqu->retry.value;
9239 priv->long_retry_limit = (u8) wrqu->retry.value;
9242 ipw_send_retry_limit(priv, priv->short_retry_limit,
9243 priv->long_retry_limit);
9244 mutex_unlock(&priv->mutex);
9245 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9246 priv->short_retry_limit, priv->long_retry_limit);
9250 static int ipw_wx_get_retry(struct net_device *dev,
9251 struct iw_request_info *info,
9252 union iwreq_data *wrqu, char *extra)
9254 struct ipw_priv *priv = ieee80211_priv(dev);
9256 mutex_lock(&priv->mutex);
9257 wrqu->retry.disabled = 0;
9259 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
9260 mutex_unlock(&priv->mutex);
9264 if (wrqu->retry.flags & IW_RETRY_MAX) {
9265 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
9266 wrqu->retry.value = priv->long_retry_limit;
9267 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
9268 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
9269 wrqu->retry.value = priv->short_retry_limit;
9271 wrqu->retry.flags = IW_RETRY_LIMIT;
9272 wrqu->retry.value = priv->short_retry_limit;
9274 mutex_unlock(&priv->mutex);
9276 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9281 static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
9284 struct ipw_scan_request_ext scan;
9285 int err = 0, scan_type;
9287 if (!(priv->status & STATUS_INIT) ||
9288 (priv->status & STATUS_EXIT_PENDING))
9291 mutex_lock(&priv->mutex);
9293 if (priv->status & STATUS_RF_KILL_MASK) {
9294 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
9295 priv->status |= STATUS_SCAN_PENDING;
9299 IPW_DEBUG_HC("starting request direct scan!\n");
9301 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
9302 /* We should not sleep here; otherwise we will block most
9303 * of the system (for instance, we hold rtnl_lock when we
9309 memset(&scan, 0, sizeof(scan));
9311 if (priv->config & CFG_SPEED_SCAN)
9312 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9315 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9318 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
9320 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
9321 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
9323 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
9325 err = ipw_send_ssid(priv, essid, essid_len);
9327 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
9330 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
9332 ipw_add_scan_channels(priv, &scan, scan_type);
9334 err = ipw_send_scan_request_ext(priv, &scan);
9336 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
9340 priv->status |= STATUS_SCANNING;
9343 mutex_unlock(&priv->mutex);
9347 static int ipw_wx_set_scan(struct net_device *dev,
9348 struct iw_request_info *info,
9349 union iwreq_data *wrqu, char *extra)
9351 struct ipw_priv *priv = ieee80211_priv(dev);
9352 struct iw_scan_req *req = NULL;
9353 if (wrqu->data.length
9354 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9355 req = (struct iw_scan_req *)extra;
9356 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9357 ipw_request_direct_scan(priv, req->essid,
9363 IPW_DEBUG_WX("Start scan\n");
9365 queue_work(priv->workqueue, &priv->request_scan);
9370 static int ipw_wx_get_scan(struct net_device *dev,
9371 struct iw_request_info *info,
9372 union iwreq_data *wrqu, char *extra)
9374 struct ipw_priv *priv = ieee80211_priv(dev);
9375 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9378 static int ipw_wx_set_encode(struct net_device *dev,
9379 struct iw_request_info *info,
9380 union iwreq_data *wrqu, char *key)
9382 struct ipw_priv *priv = ieee80211_priv(dev);
9384 u32 cap = priv->capability;
9386 mutex_lock(&priv->mutex);
9387 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
9389 /* In IBSS mode, we need to notify the firmware to update
9390 * the beacon info after we changed the capability. */
9391 if (cap != priv->capability &&
9392 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9393 priv->status & STATUS_ASSOCIATED)
9394 ipw_disassociate(priv);
9396 mutex_unlock(&priv->mutex);
9400 static int ipw_wx_get_encode(struct net_device *dev,
9401 struct iw_request_info *info,
9402 union iwreq_data *wrqu, char *key)
9404 struct ipw_priv *priv = ieee80211_priv(dev);
9405 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9408 static int ipw_wx_set_power(struct net_device *dev,
9409 struct iw_request_info *info,
9410 union iwreq_data *wrqu, char *extra)
9412 struct ipw_priv *priv = ieee80211_priv(dev);
9414 mutex_lock(&priv->mutex);
9415 if (wrqu->power.disabled) {
9416 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9417 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9419 IPW_DEBUG_WX("failed setting power mode.\n");
9420 mutex_unlock(&priv->mutex);
9423 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
9424 mutex_unlock(&priv->mutex);
9428 switch (wrqu->power.flags & IW_POWER_MODE) {
9429 case IW_POWER_ON: /* If not specified */
9430 case IW_POWER_MODE: /* If set all mask */
9431 case IW_POWER_ALL_R: /* If explicitely state all */
9433 default: /* Otherwise we don't support it */
9434 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9436 mutex_unlock(&priv->mutex);
9440 /* If the user hasn't specified a power management mode yet, default
9442 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
9443 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
9445 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9446 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9448 IPW_DEBUG_WX("failed setting power mode.\n");
9449 mutex_unlock(&priv->mutex);
9453 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
9454 mutex_unlock(&priv->mutex);
9458 static int ipw_wx_get_power(struct net_device *dev,
9459 struct iw_request_info *info,
9460 union iwreq_data *wrqu, char *extra)
9462 struct ipw_priv *priv = ieee80211_priv(dev);
9463 mutex_lock(&priv->mutex);
9464 if (!(priv->power_mode & IPW_POWER_ENABLED))
9465 wrqu->power.disabled = 1;
9467 wrqu->power.disabled = 0;
9469 mutex_unlock(&priv->mutex);
9470 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
9475 static int ipw_wx_set_powermode(struct net_device *dev,
9476 struct iw_request_info *info,
9477 union iwreq_data *wrqu, char *extra)
9479 struct ipw_priv *priv = ieee80211_priv(dev);
9480 int mode = *(int *)extra;
9482 mutex_lock(&priv->mutex);
9483 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9484 mode = IPW_POWER_AC;
9485 priv->power_mode = mode;
9487 priv->power_mode = IPW_POWER_ENABLED | mode;
9490 if (priv->power_mode != mode) {
9491 err = ipw_send_power_mode(priv, mode);
9494 IPW_DEBUG_WX("failed setting power mode.\n");
9495 mutex_unlock(&priv->mutex);
9499 mutex_unlock(&priv->mutex);
9503 #define MAX_WX_STRING 80
9504 static int ipw_wx_get_powermode(struct net_device *dev,
9505 struct iw_request_info *info,
9506 union iwreq_data *wrqu, char *extra)
9508 struct ipw_priv *priv = ieee80211_priv(dev);
9509 int level = IPW_POWER_LEVEL(priv->power_mode);
9512 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9516 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9518 case IPW_POWER_BATTERY:
9519 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9522 p += snprintf(p, MAX_WX_STRING - (p - extra),
9523 "(Timeout %dms, Period %dms)",
9524 timeout_duration[level - 1] / 1000,
9525 period_duration[level - 1] / 1000);
9528 if (!(priv->power_mode & IPW_POWER_ENABLED))
9529 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
9531 wrqu->data.length = p - extra + 1;
9536 static int ipw_wx_set_wireless_mode(struct net_device *dev,
9537 struct iw_request_info *info,
9538 union iwreq_data *wrqu, char *extra)
9540 struct ipw_priv *priv = ieee80211_priv(dev);
9541 int mode = *(int *)extra;
9542 u8 band = 0, modulation = 0;
9544 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
9545 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
9548 mutex_lock(&priv->mutex);
9549 if (priv->adapter == IPW_2915ABG) {
9550 priv->ieee->abg_true = 1;
9551 if (mode & IEEE_A) {
9552 band |= IEEE80211_52GHZ_BAND;
9553 modulation |= IEEE80211_OFDM_MODULATION;
9555 priv->ieee->abg_true = 0;
9557 if (mode & IEEE_A) {
9558 IPW_WARNING("Attempt to set 2200BG into "
9560 mutex_unlock(&priv->mutex);
9564 priv->ieee->abg_true = 0;
9567 if (mode & IEEE_B) {
9568 band |= IEEE80211_24GHZ_BAND;
9569 modulation |= IEEE80211_CCK_MODULATION;
9571 priv->ieee->abg_true = 0;
9573 if (mode & IEEE_G) {
9574 band |= IEEE80211_24GHZ_BAND;
9575 modulation |= IEEE80211_OFDM_MODULATION;
9577 priv->ieee->abg_true = 0;
9579 priv->ieee->mode = mode;
9580 priv->ieee->freq_band = band;
9581 priv->ieee->modulation = modulation;
9582 init_supported_rates(priv, &priv->rates);
9584 /* Network configuration changed -- force [re]association */
9585 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9586 if (!ipw_disassociate(priv)) {
9587 ipw_send_supported_rates(priv, &priv->rates);
9588 ipw_associate(priv);
9591 /* Update the band LEDs */
9592 ipw_led_band_on(priv);
9594 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
9595 mode & IEEE_A ? 'a' : '.',
9596 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
9597 mutex_unlock(&priv->mutex);
9601 static int ipw_wx_get_wireless_mode(struct net_device *dev,
9602 struct iw_request_info *info,
9603 union iwreq_data *wrqu, char *extra)
9605 struct ipw_priv *priv = ieee80211_priv(dev);
9606 mutex_lock(&priv->mutex);
9607 switch (priv->ieee->mode) {
9609 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9612 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9614 case IEEE_A | IEEE_B:
9615 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9618 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9620 case IEEE_A | IEEE_G:
9621 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9623 case IEEE_B | IEEE_G:
9624 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9626 case IEEE_A | IEEE_B | IEEE_G:
9627 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9630 strncpy(extra, "unknown", MAX_WX_STRING);
9634 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9636 wrqu->data.length = strlen(extra) + 1;
9637 mutex_unlock(&priv->mutex);
9642 static int ipw_wx_set_preamble(struct net_device *dev,
9643 struct iw_request_info *info,
9644 union iwreq_data *wrqu, char *extra)
9646 struct ipw_priv *priv = ieee80211_priv(dev);
9647 int mode = *(int *)extra;
9648 mutex_lock(&priv->mutex);
9649 /* Switching from SHORT -> LONG requires a disassociation */
9651 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9652 priv->config |= CFG_PREAMBLE_LONG;
9654 /* Network configuration changed -- force [re]association */
9656 ("[re]association triggered due to preamble change.\n");
9657 if (!ipw_disassociate(priv))
9658 ipw_associate(priv);
9664 priv->config &= ~CFG_PREAMBLE_LONG;
9667 mutex_unlock(&priv->mutex);
9671 mutex_unlock(&priv->mutex);
9675 static int ipw_wx_get_preamble(struct net_device *dev,
9676 struct iw_request_info *info,
9677 union iwreq_data *wrqu, char *extra)
9679 struct ipw_priv *priv = ieee80211_priv(dev);
9680 mutex_lock(&priv->mutex);
9681 if (priv->config & CFG_PREAMBLE_LONG)
9682 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9684 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
9685 mutex_unlock(&priv->mutex);
9689 #ifdef CONFIG_IPW2200_MONITOR
9690 static int ipw_wx_set_monitor(struct net_device *dev,
9691 struct iw_request_info *info,
9692 union iwreq_data *wrqu, char *extra)
9694 struct ipw_priv *priv = ieee80211_priv(dev);
9695 int *parms = (int *)extra;
9696 int enable = (parms[0] > 0);
9697 mutex_lock(&priv->mutex);
9698 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
9700 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9701 #ifdef CONFIG_IEEE80211_RADIOTAP
9702 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9704 priv->net_dev->type = ARPHRD_IEEE80211;
9706 queue_work(priv->workqueue, &priv->adapter_restart);
9709 ipw_set_channel(priv, parms[1]);
9711 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9712 mutex_unlock(&priv->mutex);
9715 priv->net_dev->type = ARPHRD_ETHER;
9716 queue_work(priv->workqueue, &priv->adapter_restart);
9718 mutex_unlock(&priv->mutex);
9722 #endif // CONFIG_IPW2200_MONITOR
9724 static int ipw_wx_reset(struct net_device *dev,
9725 struct iw_request_info *info,
9726 union iwreq_data *wrqu, char *extra)
9728 struct ipw_priv *priv = ieee80211_priv(dev);
9729 IPW_DEBUG_WX("RESET\n");
9730 queue_work(priv->workqueue, &priv->adapter_restart);
9734 static int ipw_wx_sw_reset(struct net_device *dev,
9735 struct iw_request_info *info,
9736 union iwreq_data *wrqu, char *extra)
9738 struct ipw_priv *priv = ieee80211_priv(dev);
9739 union iwreq_data wrqu_sec = {
9741 .flags = IW_ENCODE_DISABLED,
9746 IPW_DEBUG_WX("SW_RESET\n");
9748 mutex_lock(&priv->mutex);
9750 ret = ipw_sw_reset(priv, 2);
9753 ipw_adapter_restart(priv);
9756 /* The SW reset bit might have been toggled on by the 'disable'
9757 * module parameter, so take appropriate action */
9758 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9760 mutex_unlock(&priv->mutex);
9761 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
9762 mutex_lock(&priv->mutex);
9764 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9765 /* Configuration likely changed -- force [re]association */
9766 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9768 if (!ipw_disassociate(priv))
9769 ipw_associate(priv);
9772 mutex_unlock(&priv->mutex);
9777 /* Rebase the WE IOCTLs to zero for the handler array */
9778 #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
9779 static iw_handler ipw_wx_handlers[] = {
9780 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9781 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9782 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9783 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9784 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
9785 IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens,
9786 IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens,
9787 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9788 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9789 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9790 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9791 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9792 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9793 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9794 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9795 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9796 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9797 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9798 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9799 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9800 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9801 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9802 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9803 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9804 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9805 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9806 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9807 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9808 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9809 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
9810 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9811 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9812 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9813 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
9814 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9815 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9816 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9817 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9818 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9819 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9820 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
9824 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9828 IPW_PRIV_SET_PREAMBLE,
9829 IPW_PRIV_GET_PREAMBLE,
9832 #ifdef CONFIG_IPW2200_MONITOR
9833 IPW_PRIV_SET_MONITOR,
9837 static struct iw_priv_args ipw_priv_args[] = {
9839 .cmd = IPW_PRIV_SET_POWER,
9840 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9841 .name = "set_power"},
9843 .cmd = IPW_PRIV_GET_POWER,
9844 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9845 .name = "get_power"},
9847 .cmd = IPW_PRIV_SET_MODE,
9848 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9849 .name = "set_mode"},
9851 .cmd = IPW_PRIV_GET_MODE,
9852 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9853 .name = "get_mode"},
9855 .cmd = IPW_PRIV_SET_PREAMBLE,
9856 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9857 .name = "set_preamble"},
9859 .cmd = IPW_PRIV_GET_PREAMBLE,
9860 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9861 .name = "get_preamble"},
9864 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
9867 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9868 #ifdef CONFIG_IPW2200_MONITOR
9870 IPW_PRIV_SET_MONITOR,
9871 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9872 #endif /* CONFIG_IPW2200_MONITOR */
9875 static iw_handler ipw_priv_handler[] = {
9876 ipw_wx_set_powermode,
9877 ipw_wx_get_powermode,
9878 ipw_wx_set_wireless_mode,
9879 ipw_wx_get_wireless_mode,
9880 ipw_wx_set_preamble,
9881 ipw_wx_get_preamble,
9884 #ifdef CONFIG_IPW2200_MONITOR
9889 static struct iw_handler_def ipw_wx_handler_def = {
9890 .standard = ipw_wx_handlers,
9891 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9892 .num_private = ARRAY_SIZE(ipw_priv_handler),
9893 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9894 .private = ipw_priv_handler,
9895 .private_args = ipw_priv_args,
9896 .get_wireless_stats = ipw_get_wireless_stats,
9900 * Get wireless statistics.
9901 * Called by /proc/net/wireless
9902 * Also called by SIOCGIWSTATS
9904 static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
9906 struct ipw_priv *priv = ieee80211_priv(dev);
9907 struct iw_statistics *wstats;
9909 wstats = &priv->wstats;
9911 /* if hw is disabled, then ipw_get_ordinal() can't be called.
9912 * netdev->get_wireless_stats seems to be called before fw is
9913 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9914 * and associated; if not associcated, the values are all meaningless
9915 * anyway, so set them all to NULL and INVALID */
9916 if (!(priv->status & STATUS_ASSOCIATED)) {
9917 wstats->miss.beacon = 0;
9918 wstats->discard.retries = 0;
9919 wstats->qual.qual = 0;
9920 wstats->qual.level = 0;
9921 wstats->qual.noise = 0;
9922 wstats->qual.updated = 7;
9923 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
9924 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
9928 wstats->qual.qual = priv->quality;
9929 wstats->qual.level = priv->exp_avg_rssi;
9930 wstats->qual.noise = priv->exp_avg_noise;
9931 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
9932 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
9934 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9935 wstats->discard.retries = priv->last_tx_failures;
9936 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
9938 /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9939 goto fail_get_ordinal;
9940 wstats->discard.retries += tx_retry; */
9945 /* net device stuff */
9947 static void init_sys_config(struct ipw_sys_config *sys_config)
9949 memset(sys_config, 0, sizeof(struct ipw_sys_config));
9950 sys_config->bt_coexistence = 0;
9951 sys_config->answer_broadcast_ssid_probe = 0;
9952 sys_config->accept_all_data_frames = 0;
9953 sys_config->accept_non_directed_frames = 1;
9954 sys_config->exclude_unicast_unencrypted = 0;
9955 sys_config->disable_unicast_decryption = 1;
9956 sys_config->exclude_multicast_unencrypted = 0;
9957 sys_config->disable_multicast_decryption = 1;
9958 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
9959 antenna = CFG_SYS_ANTENNA_BOTH;
9960 sys_config->antenna_diversity = antenna;
9961 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
9962 sys_config->dot11g_auto_detection = 0;
9963 sys_config->enable_cts_to_self = 0;
9964 sys_config->bt_coexist_collision_thr = 0;
9965 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
9966 sys_config->silence_threshold = 0x1e;
9969 static int ipw_net_open(struct net_device *dev)
9971 struct ipw_priv *priv = ieee80211_priv(dev);
9972 IPW_DEBUG_INFO("dev->open\n");
9973 /* we should be verifying the device is ready to be opened */
9974 mutex_lock(&priv->mutex);
9975 if (!(priv->status & STATUS_RF_KILL_MASK) &&
9976 (priv->status & STATUS_ASSOCIATED))
9977 netif_start_queue(dev);
9978 mutex_unlock(&priv->mutex);
9982 static int ipw_net_stop(struct net_device *dev)
9984 IPW_DEBUG_INFO("dev->close\n");
9985 netif_stop_queue(dev);
9992 modify to send one tfd per fragment instead of using chunking. otherwise
9993 we need to heavily modify the ieee80211_skb_to_txb.
9996 static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
9999 struct ieee80211_hdr_3addrqos *hdr = (struct ieee80211_hdr_3addrqos *)
10000 txb->fragments[0]->data;
10002 struct tfd_frame *tfd;
10003 #ifdef CONFIG_IPW_QOS
10004 int tx_id = ipw_get_tx_queue_number(priv, pri);
10005 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10007 struct clx2_tx_queue *txq = &priv->txq[0];
10009 struct clx2_queue *q = &txq->q;
10010 u8 id, hdr_len, unicast;
10011 u16 remaining_bytes;
10014 hdr_len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
10015 switch (priv->ieee->iw_mode) {
10016 case IW_MODE_ADHOC:
10017 unicast = !is_multicast_ether_addr(hdr->addr1);
10018 id = ipw_find_station(priv, hdr->addr1);
10019 if (id == IPW_INVALID_STATION) {
10020 id = ipw_add_station(priv, hdr->addr1);
10021 if (id == IPW_INVALID_STATION) {
10022 IPW_WARNING("Attempt to send data to "
10023 "invalid cell: " MAC_FMT "\n",
10024 MAC_ARG(hdr->addr1));
10030 case IW_MODE_INFRA:
10032 unicast = !is_multicast_ether_addr(hdr->addr3);
10037 tfd = &txq->bd[q->first_empty];
10038 txq->txb[q->first_empty] = txb;
10039 memset(tfd, 0, sizeof(*tfd));
10040 tfd->u.data.station_number = id;
10042 tfd->control_flags.message_type = TX_FRAME_TYPE;
10043 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10045 tfd->u.data.cmd_id = DINO_CMD_TX;
10046 tfd->u.data.len = cpu_to_le16(txb->payload_size);
10047 remaining_bytes = txb->payload_size;
10049 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
10050 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
10052 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
10054 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10055 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
10057 fc = le16_to_cpu(hdr->frame_ctl);
10058 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
10060 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10062 if (likely(unicast))
10063 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10065 if (txb->encrypted && !priv->ieee->host_encrypt) {
10066 switch (priv->ieee->sec.level) {
10068 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10069 IEEE80211_FCTL_PROTECTED;
10070 /* XXX: ACK flag must be set for CCMP even if it
10071 * is a multicast/broadcast packet, because CCMP
10072 * group communication encrypted by GTK is
10073 * actually done by the AP. */
10075 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10077 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10078 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10079 tfd->u.data.key_index = 0;
10080 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10083 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10084 IEEE80211_FCTL_PROTECTED;
10085 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10086 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10087 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10090 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10091 IEEE80211_FCTL_PROTECTED;
10092 tfd->u.data.key_index = priv->ieee->tx_keyidx;
10093 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
10095 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10097 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10102 printk(KERN_ERR "Unknow security level %d\n",
10103 priv->ieee->sec.level);
10107 /* No hardware encryption */
10108 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10110 #ifdef CONFIG_IPW_QOS
10111 if (fc & IEEE80211_STYPE_QOS_DATA)
10112 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
10113 #endif /* CONFIG_IPW_QOS */
10116 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10118 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10119 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10120 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10121 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10122 i, le32_to_cpu(tfd->u.data.num_chunks),
10123 txb->fragments[i]->len - hdr_len);
10124 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
10125 i, tfd->u.data.num_chunks,
10126 txb->fragments[i]->len - hdr_len);
10127 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
10128 txb->fragments[i]->len - hdr_len);
10130 tfd->u.data.chunk_ptr[i] =
10131 cpu_to_le32(pci_map_single
10133 txb->fragments[i]->data + hdr_len,
10134 txb->fragments[i]->len - hdr_len,
10135 PCI_DMA_TODEVICE));
10136 tfd->u.data.chunk_len[i] =
10137 cpu_to_le16(txb->fragments[i]->len - hdr_len);
10140 if (i != txb->nr_frags) {
10141 struct sk_buff *skb;
10142 u16 remaining_bytes = 0;
10145 for (j = i; j < txb->nr_frags; j++)
10146 remaining_bytes += txb->fragments[j]->len - hdr_len;
10148 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10150 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10152 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
10153 for (j = i; j < txb->nr_frags; j++) {
10154 int size = txb->fragments[j]->len - hdr_len;
10156 printk(KERN_INFO "Adding frag %d %d...\n",
10158 memcpy(skb_put(skb, size),
10159 txb->fragments[j]->data + hdr_len, size);
10161 dev_kfree_skb_any(txb->fragments[i]);
10162 txb->fragments[i] = skb;
10163 tfd->u.data.chunk_ptr[i] =
10164 cpu_to_le32(pci_map_single
10165 (priv->pci_dev, skb->data,
10166 tfd->u.data.chunk_len[i],
10167 PCI_DMA_TODEVICE));
10169 tfd->u.data.num_chunks =
10170 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
10176 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10177 ipw_write32(priv, q->reg_w, q->first_empty);
10179 if (ipw_queue_space(q) < q->high_mark)
10180 netif_stop_queue(priv->net_dev);
10182 return NETDEV_TX_OK;
10185 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
10186 ieee80211_txb_free(txb);
10187 return NETDEV_TX_OK;
10190 static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10192 struct ipw_priv *priv = ieee80211_priv(dev);
10193 #ifdef CONFIG_IPW_QOS
10194 int tx_id = ipw_get_tx_queue_number(priv, pri);
10195 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10197 struct clx2_tx_queue *txq = &priv->txq[0];
10198 #endif /* CONFIG_IPW_QOS */
10200 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
10206 #ifdef CONFIG_IPW2200_PROMISCUOUS
10207 static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
10208 struct ieee80211_txb *txb)
10210 struct ieee80211_rx_stats dummystats;
10211 struct ieee80211_hdr *hdr;
10213 u16 filter = priv->prom_priv->filter;
10216 if (filter & IPW_PROM_NO_TX)
10219 memset(&dummystats, 0, sizeof(dummystats));
10221 /* Filtering of fragment chains is done agains the first fragment */
10222 hdr = (void *)txb->fragments[0]->data;
10223 if (ieee80211_is_management(hdr->frame_ctl)) {
10224 if (filter & IPW_PROM_NO_MGMT)
10226 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10228 } else if (ieee80211_is_control(hdr->frame_ctl)) {
10229 if (filter & IPW_PROM_NO_CTL)
10231 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10233 } else if (ieee80211_is_data(hdr->frame_ctl)) {
10234 if (filter & IPW_PROM_NO_DATA)
10236 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10240 for(n=0; n<txb->nr_frags; ++n) {
10241 struct sk_buff *src = txb->fragments[n];
10242 struct sk_buff *dst;
10243 struct ieee80211_radiotap_header *rt_hdr;
10247 hdr = (void *)src->data;
10248 len = ieee80211_get_hdrlen(hdr->frame_ctl);
10253 len + IEEE80211_RADIOTAP_HDRLEN, GFP_ATOMIC);
10254 if (!dst) continue;
10256 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10258 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10259 rt_hdr->it_pad = 0;
10260 rt_hdr->it_present = 0; /* after all, it's just an idea */
10261 rt_hdr->it_present |= (1 << IEEE80211_RADIOTAP_CHANNEL);
10263 *(u16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
10264 ieee80211chan2mhz(priv->channel));
10265 if (priv->channel > 14) /* 802.11a */
10266 *(u16*)skb_put(dst, sizeof(u16)) =
10267 cpu_to_le16(IEEE80211_CHAN_OFDM |
10268 IEEE80211_CHAN_5GHZ);
10269 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
10270 *(u16*)skb_put(dst, sizeof(u16)) =
10271 cpu_to_le16(IEEE80211_CHAN_CCK |
10272 IEEE80211_CHAN_2GHZ);
10274 *(u16*)skb_put(dst, sizeof(u16)) =
10275 cpu_to_le16(IEEE80211_CHAN_OFDM |
10276 IEEE80211_CHAN_2GHZ);
10278 rt_hdr->it_len = dst->len;
10280 memcpy(skb_put(dst, len), src->data, len);
10282 if (!ieee80211_rx(priv->prom_priv->ieee, dst, &dummystats))
10283 dev_kfree_skb_any(dst);
10288 static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
10289 struct net_device *dev, int pri)
10291 struct ipw_priv *priv = ieee80211_priv(dev);
10292 unsigned long flags;
10295 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
10296 spin_lock_irqsave(&priv->lock, flags);
10298 if (!(priv->status & STATUS_ASSOCIATED)) {
10299 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
10300 priv->ieee->stats.tx_carrier_errors++;
10301 netif_stop_queue(dev);
10305 #ifdef CONFIG_IPW2200_PROMISCUOUS
10306 if (rtap_iface && netif_running(priv->prom_net_dev))
10307 ipw_handle_promiscuous_tx(priv, txb);
10310 ret = ipw_tx_skb(priv, txb, pri);
10311 if (ret == NETDEV_TX_OK)
10312 __ipw_led_activity_on(priv);
10313 spin_unlock_irqrestore(&priv->lock, flags);
10318 spin_unlock_irqrestore(&priv->lock, flags);
10322 static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
10324 struct ipw_priv *priv = ieee80211_priv(dev);
10326 priv->ieee->stats.tx_packets = priv->tx_packets;
10327 priv->ieee->stats.rx_packets = priv->rx_packets;
10328 return &priv->ieee->stats;
10331 static void ipw_net_set_multicast_list(struct net_device *dev)
10336 static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10338 struct ipw_priv *priv = ieee80211_priv(dev);
10339 struct sockaddr *addr = p;
10340 if (!is_valid_ether_addr(addr->sa_data))
10341 return -EADDRNOTAVAIL;
10342 mutex_lock(&priv->mutex);
10343 priv->config |= CFG_CUSTOM_MAC;
10344 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
10345 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
10346 priv->net_dev->name, MAC_ARG(priv->mac_addr));
10347 queue_work(priv->workqueue, &priv->adapter_restart);
10348 mutex_unlock(&priv->mutex);
10352 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
10353 struct ethtool_drvinfo *info)
10355 struct ipw_priv *p = ieee80211_priv(dev);
10360 strcpy(info->driver, DRV_NAME);
10361 strcpy(info->version, DRV_VERSION);
10363 len = sizeof(vers);
10364 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10365 len = sizeof(date);
10366 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10368 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
10370 strcpy(info->bus_info, pci_name(p->pci_dev));
10371 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
10374 static u32 ipw_ethtool_get_link(struct net_device *dev)
10376 struct ipw_priv *priv = ieee80211_priv(dev);
10377 return (priv->status & STATUS_ASSOCIATED) != 0;
10380 static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10382 return IPW_EEPROM_IMAGE_SIZE;
10385 static int ipw_ethtool_get_eeprom(struct net_device *dev,
10386 struct ethtool_eeprom *eeprom, u8 * bytes)
10388 struct ipw_priv *p = ieee80211_priv(dev);
10390 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
10392 mutex_lock(&p->mutex);
10393 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
10394 mutex_unlock(&p->mutex);
10398 static int ipw_ethtool_set_eeprom(struct net_device *dev,
10399 struct ethtool_eeprom *eeprom, u8 * bytes)
10401 struct ipw_priv *p = ieee80211_priv(dev);
10404 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
10406 mutex_lock(&p->mutex);
10407 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
10408 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10409 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
10410 mutex_unlock(&p->mutex);
10414 static struct ethtool_ops ipw_ethtool_ops = {
10415 .get_link = ipw_ethtool_get_link,
10416 .get_drvinfo = ipw_ethtool_get_drvinfo,
10417 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10418 .get_eeprom = ipw_ethtool_get_eeprom,
10419 .set_eeprom = ipw_ethtool_set_eeprom,
10422 static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
10424 struct ipw_priv *priv = data;
10425 u32 inta, inta_mask;
10430 spin_lock(&priv->lock);
10432 if (!(priv->status & STATUS_INT_ENABLED)) {
10437 inta = ipw_read32(priv, IPW_INTA_RW);
10438 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
10440 if (inta == 0xFFFFFFFF) {
10441 /* Hardware disappeared */
10442 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10446 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
10447 /* Shared interrupt */
10451 /* tell the device to stop sending interrupts */
10452 ipw_disable_interrupts(priv);
10454 /* ack current interrupts */
10455 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10456 ipw_write32(priv, IPW_INTA_RW, inta);
10458 /* Cache INTA value for our tasklet */
10459 priv->isr_inta = inta;
10461 tasklet_schedule(&priv->irq_tasklet);
10463 spin_unlock(&priv->lock);
10465 return IRQ_HANDLED;
10467 spin_unlock(&priv->lock);
10471 static void ipw_rf_kill(void *adapter)
10473 struct ipw_priv *priv = adapter;
10474 unsigned long flags;
10476 spin_lock_irqsave(&priv->lock, flags);
10478 if (rf_kill_active(priv)) {
10479 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10480 if (priv->workqueue)
10481 queue_delayed_work(priv->workqueue,
10482 &priv->rf_kill, 2 * HZ);
10486 /* RF Kill is now disabled, so bring the device back up */
10488 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10489 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10492 /* we can not do an adapter restart while inside an irq lock */
10493 queue_work(priv->workqueue, &priv->adapter_restart);
10495 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10499 spin_unlock_irqrestore(&priv->lock, flags);
10502 static void ipw_bg_rf_kill(void *data)
10504 struct ipw_priv *priv = data;
10505 mutex_lock(&priv->mutex);
10507 mutex_unlock(&priv->mutex);
10510 static void ipw_link_up(struct ipw_priv *priv)
10512 priv->last_seq_num = -1;
10513 priv->last_frag_num = -1;
10514 priv->last_packet_time = 0;
10516 netif_carrier_on(priv->net_dev);
10517 if (netif_queue_stopped(priv->net_dev)) {
10518 IPW_DEBUG_NOTIF("waking queue\n");
10519 netif_wake_queue(priv->net_dev);
10521 IPW_DEBUG_NOTIF("starting queue\n");
10522 netif_start_queue(priv->net_dev);
10525 cancel_delayed_work(&priv->request_scan);
10526 ipw_reset_stats(priv);
10527 /* Ensure the rate is updated immediately */
10528 priv->last_rate = ipw_get_current_rate(priv);
10529 ipw_gather_stats(priv);
10530 ipw_led_link_up(priv);
10531 notify_wx_assoc_event(priv);
10533 if (priv->config & CFG_BACKGROUND_SCAN)
10534 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10537 static void ipw_bg_link_up(void *data)
10539 struct ipw_priv *priv = data;
10540 mutex_lock(&priv->mutex);
10542 mutex_unlock(&priv->mutex);
10545 static void ipw_link_down(struct ipw_priv *priv)
10547 ipw_led_link_down(priv);
10548 netif_carrier_off(priv->net_dev);
10549 netif_stop_queue(priv->net_dev);
10550 notify_wx_assoc_event(priv);
10552 /* Cancel any queued work ... */
10553 cancel_delayed_work(&priv->request_scan);
10554 cancel_delayed_work(&priv->adhoc_check);
10555 cancel_delayed_work(&priv->gather_stats);
10557 ipw_reset_stats(priv);
10559 if (!(priv->status & STATUS_EXIT_PENDING)) {
10560 /* Queue up another scan... */
10561 queue_work(priv->workqueue, &priv->request_scan);
10565 static void ipw_bg_link_down(void *data)
10567 struct ipw_priv *priv = data;
10568 mutex_lock(&priv->mutex);
10569 ipw_link_down(data);
10570 mutex_unlock(&priv->mutex);
10573 static int ipw_setup_deferred_work(struct ipw_priv *priv)
10577 priv->workqueue = create_workqueue(DRV_NAME);
10578 init_waitqueue_head(&priv->wait_command_queue);
10579 init_waitqueue_head(&priv->wait_state);
10581 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10582 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10583 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
10584 INIT_WORK(&priv->system_config, ipw_system_config, priv);
10585 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10586 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10587 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10588 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10589 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
10590 INIT_WORK(&priv->request_scan,
10591 (void (*)(void *))ipw_request_scan, priv);
10592 INIT_WORK(&priv->gather_stats,
10593 (void (*)(void *))ipw_bg_gather_stats, priv);
10594 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10595 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10596 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10597 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10598 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10599 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
10601 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
10603 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10605 INIT_WORK(&priv->merge_networks,
10606 (void (*)(void *))ipw_merge_adhoc_network, priv);
10608 #ifdef CONFIG_IPW_QOS
10609 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10611 #endif /* CONFIG_IPW_QOS */
10613 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10614 ipw_irq_tasklet, (unsigned long)priv);
10619 static void shim__set_security(struct net_device *dev,
10620 struct ieee80211_security *sec)
10622 struct ipw_priv *priv = ieee80211_priv(dev);
10624 for (i = 0; i < 4; i++) {
10625 if (sec->flags & (1 << i)) {
10626 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
10627 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
10628 if (sec->key_sizes[i] == 0)
10629 priv->ieee->sec.flags &= ~(1 << i);
10631 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
10632 sec->key_sizes[i]);
10633 priv->ieee->sec.flags |= (1 << i);
10635 priv->status |= STATUS_SECURITY_UPDATED;
10636 } else if (sec->level != SEC_LEVEL_1)
10637 priv->ieee->sec.flags &= ~(1 << i);
10640 if (sec->flags & SEC_ACTIVE_KEY) {
10641 if (sec->active_key <= 3) {
10642 priv->ieee->sec.active_key = sec->active_key;
10643 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
10645 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
10646 priv->status |= STATUS_SECURITY_UPDATED;
10648 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
10650 if ((sec->flags & SEC_AUTH_MODE) &&
10651 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10652 priv->ieee->sec.auth_mode = sec->auth_mode;
10653 priv->ieee->sec.flags |= SEC_AUTH_MODE;
10654 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10655 priv->capability |= CAP_SHARED_KEY;
10657 priv->capability &= ~CAP_SHARED_KEY;
10658 priv->status |= STATUS_SECURITY_UPDATED;
10661 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10662 priv->ieee->sec.flags |= SEC_ENABLED;
10663 priv->ieee->sec.enabled = sec->enabled;
10664 priv->status |= STATUS_SECURITY_UPDATED;
10666 priv->capability |= CAP_PRIVACY_ON;
10668 priv->capability &= ~CAP_PRIVACY_ON;
10671 if (sec->flags & SEC_ENCRYPT)
10672 priv->ieee->sec.encrypt = sec->encrypt;
10674 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10675 priv->ieee->sec.level = sec->level;
10676 priv->ieee->sec.flags |= SEC_LEVEL;
10677 priv->status |= STATUS_SECURITY_UPDATED;
10680 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10681 ipw_set_hwcrypto_keys(priv);
10683 /* To match current functionality of ipw2100 (which works well w/
10684 * various supplicants, we don't force a disassociate if the
10685 * privacy capability changes ... */
10687 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
10688 (((priv->assoc_request.capability &
10689 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
10690 (!(priv->assoc_request.capability &
10691 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
10692 IPW_DEBUG_ASSOC("Disassociating due to capability "
10694 ipw_disassociate(priv);
10699 static int init_supported_rates(struct ipw_priv *priv,
10700 struct ipw_supported_rates *rates)
10702 /* TODO: Mask out rates based on priv->rates_mask */
10704 memset(rates, 0, sizeof(*rates));
10705 /* configure supported rates */
10706 switch (priv->ieee->freq_band) {
10707 case IEEE80211_52GHZ_BAND:
10708 rates->ieee_mode = IPW_A_MODE;
10709 rates->purpose = IPW_RATE_CAPABILITIES;
10710 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10711 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10714 default: /* Mixed or 2.4Ghz */
10715 rates->ieee_mode = IPW_G_MODE;
10716 rates->purpose = IPW_RATE_CAPABILITIES;
10717 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10718 IEEE80211_CCK_DEFAULT_RATES_MASK);
10719 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10720 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10721 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10729 static int ipw_config(struct ipw_priv *priv)
10731 /* This is only called from ipw_up, which resets/reloads the firmware
10732 so, we don't need to first disable the card before we configure
10734 if (ipw_set_tx_power(priv))
10737 /* initialize adapter address */
10738 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10741 /* set basic system config settings */
10742 init_sys_config(&priv->sys_config);
10744 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10745 * Does not support BT priority yet (don't abort or defer our Tx) */
10747 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
10749 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10750 priv->sys_config.bt_coexistence
10751 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
10752 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10753 priv->sys_config.bt_coexistence
10754 |= CFG_BT_COEXISTENCE_OOB;
10757 #ifdef CONFIG_IPW2200_PROMISCUOUS
10758 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10759 priv->sys_config.accept_all_data_frames = 1;
10760 priv->sys_config.accept_non_directed_frames = 1;
10761 priv->sys_config.accept_all_mgmt_bcpr = 1;
10762 priv->sys_config.accept_all_mgmt_frames = 1;
10766 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10767 priv->sys_config.answer_broadcast_ssid_probe = 1;
10769 priv->sys_config.answer_broadcast_ssid_probe = 0;
10771 if (ipw_send_system_config(priv))
10774 init_supported_rates(priv, &priv->rates);
10775 if (ipw_send_supported_rates(priv, &priv->rates))
10778 /* Set request-to-send threshold */
10779 if (priv->rts_threshold) {
10780 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10783 #ifdef CONFIG_IPW_QOS
10784 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10785 ipw_qos_activate(priv, NULL);
10786 #endif /* CONFIG_IPW_QOS */
10788 if (ipw_set_random_seed(priv))
10791 /* final state transition to the RUN state */
10792 if (ipw_send_host_complete(priv))
10795 priv->status |= STATUS_INIT;
10797 ipw_led_init(priv);
10798 ipw_led_radio_on(priv);
10799 priv->notif_missed_beacons = 0;
10801 /* Set hardware WEP key if it is configured. */
10802 if ((priv->capability & CAP_PRIVACY_ON) &&
10803 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10804 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10805 ipw_set_hwcrypto_keys(priv);
10816 * These tables have been tested in conjunction with the
10817 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10819 * Altering this values, using it on other hardware, or in geographies
10820 * not intended for resale of the above mentioned Intel adapters has
10823 * Remember to update the table in README.ipw2200 when changing this
10827 static const struct ieee80211_geo ipw_geos[] = {
10831 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10832 {2427, 4}, {2432, 5}, {2437, 6},
10833 {2442, 7}, {2447, 8}, {2452, 9},
10834 {2457, 10}, {2462, 11}},
10837 { /* Custom US/Canada */
10840 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10841 {2427, 4}, {2432, 5}, {2437, 6},
10842 {2442, 7}, {2447, 8}, {2452, 9},
10843 {2457, 10}, {2462, 11}},
10849 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10850 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10851 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10852 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10855 { /* Rest of World */
10858 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10859 {2427, 4}, {2432, 5}, {2437, 6},
10860 {2442, 7}, {2447, 8}, {2452, 9},
10861 {2457, 10}, {2462, 11}, {2467, 12},
10865 { /* Custom USA & Europe & High */
10868 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10869 {2427, 4}, {2432, 5}, {2437, 6},
10870 {2442, 7}, {2447, 8}, {2452, 9},
10871 {2457, 10}, {2462, 11}},
10877 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10878 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10879 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10880 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10888 { /* Custom NA & Europe */
10891 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10892 {2427, 4}, {2432, 5}, {2437, 6},
10893 {2442, 7}, {2447, 8}, {2452, 9},
10894 {2457, 10}, {2462, 11}},
10900 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10901 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10902 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10903 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10904 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10905 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10906 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10907 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10908 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10911 { /* Custom Japan */
10914 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10915 {2427, 4}, {2432, 5}, {2437, 6},
10916 {2442, 7}, {2447, 8}, {2452, 9},
10917 {2457, 10}, {2462, 11}},
10919 .a = {{5170, 34}, {5190, 38},
10920 {5210, 42}, {5230, 46}},
10926 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10927 {2427, 4}, {2432, 5}, {2437, 6},
10928 {2442, 7}, {2447, 8}, {2452, 9},
10929 {2457, 10}, {2462, 11}},
10935 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10936 {2427, 4}, {2432, 5}, {2437, 6},
10937 {2442, 7}, {2447, 8}, {2452, 9},
10938 {2457, 10}, {2462, 11}, {2467, 12},
10945 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10946 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10947 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10948 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10949 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10950 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10951 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10952 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10953 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10954 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10955 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10956 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10957 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10958 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10959 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10962 { /* Custom Japan */
10965 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10966 {2427, 4}, {2432, 5}, {2437, 6},
10967 {2442, 7}, {2447, 8}, {2452, 9},
10968 {2457, 10}, {2462, 11}, {2467, 12},
10969 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10971 .a = {{5170, 34}, {5190, 38},
10972 {5210, 42}, {5230, 46}},
10975 { /* Rest of World */
10978 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10979 {2427, 4}, {2432, 5}, {2437, 6},
10980 {2442, 7}, {2447, 8}, {2452, 9},
10981 {2457, 10}, {2462, 11}, {2467, 12},
10982 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
10983 IEEE80211_CH_PASSIVE_ONLY}},
10989 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10990 {2427, 4}, {2432, 5}, {2437, 6},
10991 {2442, 7}, {2447, 8}, {2452, 9},
10992 {2457, 10}, {2462, 11},
10993 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10994 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10996 .a = {{5745, 149}, {5765, 153},
10997 {5785, 157}, {5805, 161}},
11000 { /* Custom Europe */
11003 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11004 {2427, 4}, {2432, 5}, {2437, 6},
11005 {2442, 7}, {2447, 8}, {2452, 9},
11006 {2457, 10}, {2462, 11},
11007 {2467, 12}, {2472, 13}},
11009 .a = {{5180, 36}, {5200, 40},
11010 {5220, 44}, {5240, 48}},
11016 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11017 {2427, 4}, {2432, 5}, {2437, 6},
11018 {2442, 7}, {2447, 8}, {2452, 9},
11019 {2457, 10}, {2462, 11},
11020 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
11021 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
11023 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
11024 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
11025 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
11026 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
11027 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11028 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11029 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11030 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11031 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
11032 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
11033 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
11034 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
11035 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
11036 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
11037 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
11038 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
11039 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
11040 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
11041 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
11042 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11043 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11044 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11045 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11046 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11052 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11053 {2427, 4}, {2432, 5}, {2437, 6},
11054 {2442, 7}, {2447, 8}, {2452, 9},
11055 {2457, 10}, {2462, 11}},
11057 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
11058 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
11059 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
11060 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
11061 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11062 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11063 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11064 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11065 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11066 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11067 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11068 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11069 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11073 #define MAX_HW_RESTARTS 5
11074 static int ipw_up(struct ipw_priv *priv)
11078 if (priv->status & STATUS_EXIT_PENDING)
11081 if (cmdlog && !priv->cmdlog) {
11082 priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
11084 if (priv->cmdlog == NULL) {
11085 IPW_ERROR("Error allocating %d command log entries.\n",
11089 memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
11090 priv->cmdlog_len = cmdlog;
11094 for (i = 0; i < MAX_HW_RESTARTS; i++) {
11095 /* Load the microcode, firmware, and eeprom.
11096 * Also start the clocks. */
11097 rc = ipw_load(priv);
11099 IPW_ERROR("Unable to load firmware: %d\n", rc);
11103 ipw_init_ordinals(priv);
11104 if (!(priv->config & CFG_CUSTOM_MAC))
11105 eeprom_parse_mac(priv, priv->mac_addr);
11106 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
11108 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11109 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11110 ipw_geos[j].name, 3))
11113 if (j == ARRAY_SIZE(ipw_geos)) {
11114 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11115 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11116 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11117 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
11120 if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
11121 IPW_WARNING("Could not set geography.");
11125 if (priv->status & STATUS_RF_KILL_SW) {
11126 IPW_WARNING("Radio disabled by module parameter.\n");
11128 } else if (rf_kill_active(priv)) {
11129 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11130 "Kill switch must be turned off for "
11131 "wireless networking to work.\n");
11132 queue_delayed_work(priv->workqueue, &priv->rf_kill,
11137 rc = ipw_config(priv);
11139 IPW_DEBUG_INFO("Configured device on count %i\n", i);
11141 /* If configure to try and auto-associate, kick
11143 queue_work(priv->workqueue, &priv->request_scan);
11148 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
11149 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11150 i, MAX_HW_RESTARTS);
11152 /* We had an error bringing up the hardware, so take it
11153 * all the way back down so we can try again */
11157 /* tried to restart and config the device for as long as our
11158 * patience could withstand */
11159 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
11164 static void ipw_bg_up(void *data)
11166 struct ipw_priv *priv = data;
11167 mutex_lock(&priv->mutex);
11169 mutex_unlock(&priv->mutex);
11172 static void ipw_deinit(struct ipw_priv *priv)
11176 if (priv->status & STATUS_SCANNING) {
11177 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11178 ipw_abort_scan(priv);
11181 if (priv->status & STATUS_ASSOCIATED) {
11182 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11183 ipw_disassociate(priv);
11186 ipw_led_shutdown(priv);
11188 /* Wait up to 1s for status to change to not scanning and not
11189 * associated (disassociation can take a while for a ful 802.11
11191 for (i = 1000; i && (priv->status &
11192 (STATUS_DISASSOCIATING |
11193 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11196 if (priv->status & (STATUS_DISASSOCIATING |
11197 STATUS_ASSOCIATED | STATUS_SCANNING))
11198 IPW_DEBUG_INFO("Still associated or scanning...\n");
11200 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11202 /* Attempt to disable the card */
11203 ipw_send_card_disable(priv, 0);
11205 priv->status &= ~STATUS_INIT;
11208 static void ipw_down(struct ipw_priv *priv)
11210 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11212 priv->status |= STATUS_EXIT_PENDING;
11214 if (ipw_is_init(priv))
11217 /* Wipe out the EXIT_PENDING status bit if we are not actually
11218 * exiting the module */
11220 priv->status &= ~STATUS_EXIT_PENDING;
11222 /* tell the device to stop sending interrupts */
11223 ipw_disable_interrupts(priv);
11225 /* Clear all bits but the RF Kill */
11226 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
11227 netif_carrier_off(priv->net_dev);
11228 netif_stop_queue(priv->net_dev);
11230 ipw_stop_nic(priv);
11232 ipw_led_radio_off(priv);
11235 static void ipw_bg_down(void *data)
11237 struct ipw_priv *priv = data;
11238 mutex_lock(&priv->mutex);
11240 mutex_unlock(&priv->mutex);
11243 /* Called by register_netdev() */
11244 static int ipw_net_init(struct net_device *dev)
11246 struct ipw_priv *priv = ieee80211_priv(dev);
11247 mutex_lock(&priv->mutex);
11249 if (ipw_up(priv)) {
11250 mutex_unlock(&priv->mutex);
11254 mutex_unlock(&priv->mutex);
11258 /* PCI driver stuff */
11259 static struct pci_device_id card_ids[] = {
11260 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11261 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11262 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11263 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11264 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11265 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11266 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11267 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11268 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11269 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11270 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11271 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11272 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11273 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11274 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11275 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11276 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
11277 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
11278 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
11279 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
11280 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
11281 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
11283 /* required last entry */
11287 MODULE_DEVICE_TABLE(pci, card_ids);
11289 static struct attribute *ipw_sysfs_entries[] = {
11290 &dev_attr_rf_kill.attr,
11291 &dev_attr_direct_dword.attr,
11292 &dev_attr_indirect_byte.attr,
11293 &dev_attr_indirect_dword.attr,
11294 &dev_attr_mem_gpio_reg.attr,
11295 &dev_attr_command_event_reg.attr,
11296 &dev_attr_nic_type.attr,
11297 &dev_attr_status.attr,
11298 &dev_attr_cfg.attr,
11299 &dev_attr_error.attr,
11300 &dev_attr_event_log.attr,
11301 &dev_attr_cmd_log.attr,
11302 &dev_attr_eeprom_delay.attr,
11303 &dev_attr_ucode_version.attr,
11304 &dev_attr_rtc.attr,
11305 &dev_attr_scan_age.attr,
11306 &dev_attr_led.attr,
11307 &dev_attr_speed_scan.attr,
11308 &dev_attr_net_stats.attr,
11309 #ifdef CONFIG_IPW2200_PROMISCUOUS
11310 &dev_attr_rtap_iface.attr,
11311 &dev_attr_rtap_filter.attr,
11316 static struct attribute_group ipw_attribute_group = {
11317 .name = NULL, /* put in device directory */
11318 .attrs = ipw_sysfs_entries,
11321 #ifdef CONFIG_IPW2200_PROMISCUOUS
11322 static int ipw_prom_open(struct net_device *dev)
11324 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11325 struct ipw_priv *priv = prom_priv->priv;
11327 IPW_DEBUG_INFO("prom dev->open\n");
11328 netif_carrier_off(dev);
11329 netif_stop_queue(dev);
11331 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11332 priv->sys_config.accept_all_data_frames = 1;
11333 priv->sys_config.accept_non_directed_frames = 1;
11334 priv->sys_config.accept_all_mgmt_bcpr = 1;
11335 priv->sys_config.accept_all_mgmt_frames = 1;
11337 ipw_send_system_config(priv);
11343 static int ipw_prom_stop(struct net_device *dev)
11345 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11346 struct ipw_priv *priv = prom_priv->priv;
11348 IPW_DEBUG_INFO("prom dev->stop\n");
11350 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11351 priv->sys_config.accept_all_data_frames = 0;
11352 priv->sys_config.accept_non_directed_frames = 0;
11353 priv->sys_config.accept_all_mgmt_bcpr = 0;
11354 priv->sys_config.accept_all_mgmt_frames = 0;
11356 ipw_send_system_config(priv);
11362 static int ipw_prom_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
11364 IPW_DEBUG_INFO("prom dev->xmit\n");
11365 netif_stop_queue(dev);
11366 return -EOPNOTSUPP;
11369 static struct net_device_stats *ipw_prom_get_stats(struct net_device *dev)
11371 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11372 return &prom_priv->ieee->stats;
11375 static int ipw_prom_alloc(struct ipw_priv *priv)
11379 if (priv->prom_net_dev)
11382 priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv));
11383 if (priv->prom_net_dev == NULL)
11386 priv->prom_priv = ieee80211_priv(priv->prom_net_dev);
11387 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11388 priv->prom_priv->priv = priv;
11390 strcpy(priv->prom_net_dev->name, "rtap%d");
11392 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
11393 priv->prom_net_dev->open = ipw_prom_open;
11394 priv->prom_net_dev->stop = ipw_prom_stop;
11395 priv->prom_net_dev->get_stats = ipw_prom_get_stats;
11396 priv->prom_net_dev->hard_start_xmit = ipw_prom_hard_start_xmit;
11398 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
11400 rc = register_netdev(priv->prom_net_dev);
11402 free_ieee80211(priv->prom_net_dev);
11403 priv->prom_net_dev = NULL;
11410 static void ipw_prom_free(struct ipw_priv *priv)
11412 if (!priv->prom_net_dev)
11415 unregister_netdev(priv->prom_net_dev);
11416 free_ieee80211(priv->prom_net_dev);
11418 priv->prom_net_dev = NULL;
11424 static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
11427 struct net_device *net_dev;
11428 void __iomem *base;
11430 struct ipw_priv *priv;
11433 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
11434 if (net_dev == NULL) {
11439 priv = ieee80211_priv(net_dev);
11440 priv->ieee = netdev_priv(net_dev);
11442 priv->net_dev = net_dev;
11443 priv->pci_dev = pdev;
11444 #ifdef CONFIG_IPW2200_DEBUG
11445 ipw_debug_level = debug;
11447 spin_lock_init(&priv->lock);
11448 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11449 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
11451 mutex_init(&priv->mutex);
11452 if (pci_enable_device(pdev)) {
11454 goto out_free_ieee80211;
11457 pci_set_master(pdev);
11459 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
11461 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
11463 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11464 goto out_pci_disable_device;
11467 pci_set_drvdata(pdev, priv);
11469 err = pci_request_regions(pdev, DRV_NAME);
11471 goto out_pci_disable_device;
11473 /* We disable the RETRY_TIMEOUT register (0x41) to keep
11474 * PCI Tx retries from interfering with C3 CPU state */
11475 pci_read_config_dword(pdev, 0x40, &val);
11476 if ((val & 0x0000ff00) != 0)
11477 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11479 length = pci_resource_len(pdev, 0);
11480 priv->hw_len = length;
11482 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
11485 goto out_pci_release_regions;
11488 priv->hw_base = base;
11489 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11490 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11492 err = ipw_setup_deferred_work(priv);
11494 IPW_ERROR("Unable to setup deferred work\n");
11498 ipw_sw_reset(priv, 1);
11500 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
11502 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11503 goto out_destroy_workqueue;
11506 SET_MODULE_OWNER(net_dev);
11507 SET_NETDEV_DEV(net_dev, &pdev->dev);
11509 mutex_lock(&priv->mutex);
11511 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11512 priv->ieee->set_security = shim__set_security;
11513 priv->ieee->is_queue_full = ipw_net_is_queue_full;
11515 #ifdef CONFIG_IPW_QOS
11516 priv->ieee->is_qos_active = ipw_is_qos_active;
11517 priv->ieee->handle_probe_response = ipw_handle_beacon;
11518 priv->ieee->handle_beacon = ipw_handle_probe_response;
11519 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
11520 #endif /* CONFIG_IPW_QOS */
11522 priv->ieee->perfect_rssi = -20;
11523 priv->ieee->worst_rssi = -85;
11525 net_dev->open = ipw_net_open;
11526 net_dev->stop = ipw_net_stop;
11527 net_dev->init = ipw_net_init;
11528 net_dev->get_stats = ipw_net_get_stats;
11529 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11530 net_dev->set_mac_address = ipw_net_set_mac_address;
11531 priv->wireless_data.spy_data = &priv->ieee->spy_data;
11532 net_dev->wireless_data = &priv->wireless_data;
11533 net_dev->wireless_handlers = &ipw_wx_handler_def;
11534 net_dev->ethtool_ops = &ipw_ethtool_ops;
11535 net_dev->irq = pdev->irq;
11536 net_dev->base_addr = (unsigned long)priv->hw_base;
11537 net_dev->mem_start = pci_resource_start(pdev, 0);
11538 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11540 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11542 IPW_ERROR("failed to create sysfs device attributes\n");
11543 mutex_unlock(&priv->mutex);
11544 goto out_release_irq;
11547 mutex_unlock(&priv->mutex);
11548 err = register_netdev(net_dev);
11550 IPW_ERROR("failed to register network device\n");
11551 goto out_remove_sysfs;
11554 #ifdef CONFIG_IPW2200_PROMISCUOUS
11556 err = ipw_prom_alloc(priv);
11558 IPW_ERROR("Failed to register promiscuous network "
11559 "device (error %d).\n", err);
11560 unregister_netdev(priv->net_dev);
11561 goto out_remove_sysfs;
11566 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11567 "channels, %d 802.11a channels)\n",
11568 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11569 priv->ieee->geo.a_channels);
11574 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11576 free_irq(pdev->irq, priv);
11577 out_destroy_workqueue:
11578 destroy_workqueue(priv->workqueue);
11579 priv->workqueue = NULL;
11581 iounmap(priv->hw_base);
11582 out_pci_release_regions:
11583 pci_release_regions(pdev);
11584 out_pci_disable_device:
11585 pci_disable_device(pdev);
11586 pci_set_drvdata(pdev, NULL);
11587 out_free_ieee80211:
11588 free_ieee80211(priv->net_dev);
11593 static void ipw_pci_remove(struct pci_dev *pdev)
11595 struct ipw_priv *priv = pci_get_drvdata(pdev);
11596 struct list_head *p, *q;
11602 mutex_lock(&priv->mutex);
11604 priv->status |= STATUS_EXIT_PENDING;
11606 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11608 mutex_unlock(&priv->mutex);
11610 unregister_netdev(priv->net_dev);
11613 ipw_rx_queue_free(priv, priv->rxq);
11616 ipw_tx_queue_free(priv);
11618 if (priv->cmdlog) {
11619 kfree(priv->cmdlog);
11620 priv->cmdlog = NULL;
11622 /* ipw_down will ensure that there is no more pending work
11623 * in the workqueue's, so we can safely remove them now. */
11624 cancel_delayed_work(&priv->adhoc_check);
11625 cancel_delayed_work(&priv->gather_stats);
11626 cancel_delayed_work(&priv->request_scan);
11627 cancel_delayed_work(&priv->rf_kill);
11628 cancel_delayed_work(&priv->scan_check);
11629 destroy_workqueue(priv->workqueue);
11630 priv->workqueue = NULL;
11632 /* Free MAC hash list for ADHOC */
11633 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11634 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
11636 kfree(list_entry(p, struct ipw_ibss_seq, list));
11641 ipw_free_error_log(priv->error);
11642 priv->error = NULL;
11645 #ifdef CONFIG_IPW2200_PROMISCUOUS
11646 ipw_prom_free(priv);
11649 free_irq(pdev->irq, priv);
11650 iounmap(priv->hw_base);
11651 pci_release_regions(pdev);
11652 pci_disable_device(pdev);
11653 pci_set_drvdata(pdev, NULL);
11654 free_ieee80211(priv->net_dev);
11659 static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
11661 struct ipw_priv *priv = pci_get_drvdata(pdev);
11662 struct net_device *dev = priv->net_dev;
11664 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11666 /* Take down the device; powers it off, etc. */
11669 /* Remove the PRESENT state of the device */
11670 netif_device_detach(dev);
11672 pci_save_state(pdev);
11673 pci_disable_device(pdev);
11674 pci_set_power_state(pdev, pci_choose_state(pdev, state));
11679 static int ipw_pci_resume(struct pci_dev *pdev)
11681 struct ipw_priv *priv = pci_get_drvdata(pdev);
11682 struct net_device *dev = priv->net_dev;
11685 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11687 pci_set_power_state(pdev, PCI_D0);
11688 pci_enable_device(pdev);
11689 pci_restore_state(pdev);
11692 * Suspend/Resume resets the PCI configuration space, so we have to
11693 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11694 * from interfering with C3 CPU state. pci_restore_state won't help
11695 * here since it only restores the first 64 bytes pci config header.
11697 pci_read_config_dword(pdev, 0x40, &val);
11698 if ((val & 0x0000ff00) != 0)
11699 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11701 /* Set the device back into the PRESENT state; this will also wake
11702 * the queue of needed */
11703 netif_device_attach(dev);
11705 /* Bring the device back up */
11706 queue_work(priv->workqueue, &priv->up);
11712 /* driver initialization stuff */
11713 static struct pci_driver ipw_driver = {
11715 .id_table = card_ids,
11716 .probe = ipw_pci_probe,
11717 .remove = __devexit_p(ipw_pci_remove),
11719 .suspend = ipw_pci_suspend,
11720 .resume = ipw_pci_resume,
11724 static int __init ipw_init(void)
11728 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11729 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11731 ret = pci_module_init(&ipw_driver);
11733 IPW_ERROR("Unable to initialize PCI module\n");
11737 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
11739 IPW_ERROR("Unable to create driver sysfs file\n");
11740 pci_unregister_driver(&ipw_driver);
11747 static void __exit ipw_exit(void)
11749 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11750 pci_unregister_driver(&ipw_driver);
11753 module_param(disable, int, 0444);
11754 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11756 module_param(associate, int, 0444);
11757 MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11759 module_param(auto_create, int, 0444);
11760 MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11762 module_param(led, int, 0444);
11763 MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
11765 #ifdef CONFIG_IPW2200_DEBUG
11766 module_param(debug, int, 0444);
11767 MODULE_PARM_DESC(debug, "debug output mask");
11770 module_param(channel, int, 0444);
11771 MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
11773 #ifdef CONFIG_IPW2200_PROMISCUOUS
11774 module_param(rtap_iface, int, 0444);
11775 MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
11778 #ifdef CONFIG_IPW_QOS
11779 module_param(qos_enable, int, 0444);
11780 MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
11782 module_param(qos_burst_enable, int, 0444);
11783 MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11785 module_param(qos_no_ack_mask, int, 0444);
11786 MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11788 module_param(burst_duration_CCK, int, 0444);
11789 MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11791 module_param(burst_duration_OFDM, int, 0444);
11792 MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11793 #endif /* CONFIG_IPW_QOS */
11795 #ifdef CONFIG_IPW2200_MONITOR
11796 module_param(mode, int, 0444);
11797 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11799 module_param(mode, int, 0444);
11800 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11803 module_param(bt_coexist, int, 0444);
11804 MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
11806 module_param(hwcrypto, int, 0444);
11807 MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
11809 module_param(cmdlog, int, 0444);
11810 MODULE_PARM_DESC(cmdlog,
11811 "allocate a ring buffer for logging firmware commands");
11813 module_param(roaming, int, 0444);
11814 MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
11816 module_param(antenna, int, 0444);
11817 MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
11819 module_exit(ipw_exit);
11820 module_init(ipw_init);