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;
69 static int qos_enable = 0;
70 static int qos_burst_enable = 0;
71 static int qos_no_ack_mask = 0;
72 static int burst_duration_CCK = 0;
73 static int burst_duration_OFDM = 0;
75 static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
76 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
78 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
80 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
81 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
82 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
83 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
86 static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
87 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
89 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
91 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
92 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
93 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
94 QOS_TX3_TXOP_LIMIT_CCK}
97 static struct ieee80211_qos_parameters def_parameters_OFDM = {
98 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
100 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
101 DEF_TX3_CW_MAX_OFDM},
102 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
103 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
104 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
105 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
108 static struct ieee80211_qos_parameters def_parameters_CCK = {
109 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
111 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
113 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
114 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
115 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
116 DEF_TX3_TXOP_LIMIT_CCK}
119 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
121 static int from_priority_to_tx_queue[] = {
122 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
123 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
126 static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
128 static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
130 static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
132 #endif /* CONFIG_IPW_QOS */
134 static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
135 static void ipw_remove_current_network(struct ipw_priv *priv);
136 static void ipw_rx(struct ipw_priv *priv);
137 static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
138 struct clx2_tx_queue *txq, int qindex);
139 static int ipw_queue_reset(struct ipw_priv *priv);
141 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
144 static void ipw_tx_queue_free(struct ipw_priv *);
146 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
147 static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
148 static void ipw_rx_queue_replenish(void *);
149 static int ipw_up(struct ipw_priv *);
150 static void ipw_bg_up(void *);
151 static void ipw_down(struct ipw_priv *);
152 static void ipw_bg_down(void *);
153 static int ipw_config(struct ipw_priv *);
154 static int init_supported_rates(struct ipw_priv *priv,
155 struct ipw_supported_rates *prates);
156 static void ipw_set_hwcrypto_keys(struct ipw_priv *);
157 static void ipw_send_wep_keys(struct ipw_priv *, int);
159 static int snprint_line(char *buf, size_t count,
160 const u8 * data, u32 len, u32 ofs)
165 out = snprintf(buf, count, "%08X", ofs);
167 for (l = 0, i = 0; i < 2; i++) {
168 out += snprintf(buf + out, count - out, " ");
169 for (j = 0; j < 8 && l < len; j++, l++)
170 out += snprintf(buf + out, count - out, "%02X ",
173 out += snprintf(buf + out, count - out, " ");
176 out += snprintf(buf + out, count - out, " ");
177 for (l = 0, i = 0; i < 2; i++) {
178 out += snprintf(buf + out, count - out, " ");
179 for (j = 0; j < 8 && l < len; j++, l++) {
180 c = data[(i * 8 + j)];
181 if (!isascii(c) || !isprint(c))
184 out += snprintf(buf + out, count - out, "%c", c);
188 out += snprintf(buf + out, count - out, " ");
194 static void printk_buf(int level, const u8 * data, u32 len)
198 if (!(ipw_debug_level & level))
202 snprint_line(line, sizeof(line), &data[ofs],
204 printk(KERN_DEBUG "%s\n", line);
206 len -= min(len, 16U);
210 static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
216 while (size && len) {
217 out = snprint_line(output, size, &data[ofs],
218 min_t(size_t, len, 16U), ofs);
223 len -= min_t(size_t, len, 16U);
229 /* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
230 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
231 #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
233 /* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
234 static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
235 #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
237 /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
238 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
239 static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
241 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
242 __LINE__, (u32) (b), (u32) (c));
243 _ipw_write_reg8(a, b, c);
246 /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
247 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
248 static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
250 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
251 __LINE__, (u32) (b), (u32) (c));
252 _ipw_write_reg16(a, b, c);
255 /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
256 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
257 static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
259 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
260 __LINE__, (u32) (b), (u32) (c));
261 _ipw_write_reg32(a, b, c);
264 /* 8-bit direct write (low 4K) */
265 #define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
267 /* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
268 #define ipw_write8(ipw, ofs, val) \
269 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
270 _ipw_write8(ipw, ofs, val)
272 /* 16-bit direct write (low 4K) */
273 #define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
275 /* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
276 #define ipw_write16(ipw, ofs, val) \
277 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
278 _ipw_write16(ipw, ofs, val)
280 /* 32-bit direct write (low 4K) */
281 #define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
283 /* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
284 #define ipw_write32(ipw, ofs, val) \
285 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
286 _ipw_write32(ipw, ofs, val)
288 /* 8-bit direct read (low 4K) */
289 #define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
291 /* 8-bit direct read (low 4K), with debug wrapper */
292 static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
294 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
295 return _ipw_read8(ipw, ofs);
298 /* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
299 #define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
301 /* 16-bit direct read (low 4K) */
302 #define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
304 /* 16-bit direct read (low 4K), with debug wrapper */
305 static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
307 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
308 return _ipw_read16(ipw, ofs);
311 /* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
312 #define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
314 /* 32-bit direct read (low 4K) */
315 #define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
317 /* 32-bit direct read (low 4K), with debug wrapper */
318 static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
320 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
321 return _ipw_read32(ipw, ofs);
324 /* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
325 #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
327 /* multi-byte read (above 4K), with debug wrapper */
328 static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
329 static inline void __ipw_read_indirect(const char *f, int l,
330 struct ipw_priv *a, u32 b, u8 * c, int d)
332 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
334 _ipw_read_indirect(a, b, c, d);
337 /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
338 #define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
340 /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
341 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
343 #define ipw_write_indirect(a, b, c, d) \
344 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
345 _ipw_write_indirect(a, b, c, d)
347 /* 32-bit indirect write (above 4K) */
348 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
350 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
351 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
352 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
355 /* 8-bit indirect write (above 4K) */
356 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
358 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
359 u32 dif_len = reg - aligned_addr;
361 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
362 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
363 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
366 /* 16-bit indirect write (above 4K) */
367 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
369 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
370 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
372 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
373 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
374 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
377 /* 8-bit indirect read (above 4K) */
378 static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
381 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
382 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
383 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
384 return (word >> ((reg & 0x3) * 8)) & 0xff;
387 /* 32-bit indirect read (above 4K) */
388 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
392 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
394 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
395 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
396 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
400 /* General purpose, no alignment requirement, iterative (multi-byte) read, */
401 /* for area above 1st 4K of SRAM/reg space */
402 static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
405 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
406 u32 dif_len = addr - aligned_addr;
409 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
415 /* Read the first dword (or portion) byte by byte */
416 if (unlikely(dif_len)) {
417 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
418 /* Start reading at aligned_addr + dif_len */
419 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
420 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
424 /* Read all of the middle dwords as dwords, with auto-increment */
425 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
426 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
427 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
429 /* Read the last dword (or portion) byte by byte */
431 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
432 for (i = 0; num > 0; i++, num--)
433 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
437 /* General purpose, no alignment requirement, iterative (multi-byte) write, */
438 /* for area above 1st 4K of SRAM/reg space */
439 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
442 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
443 u32 dif_len = addr - aligned_addr;
446 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
452 /* Write the first dword (or portion) byte by byte */
453 if (unlikely(dif_len)) {
454 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
455 /* Start writing at aligned_addr + dif_len */
456 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
457 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
461 /* Write all of the middle dwords as dwords, with auto-increment */
462 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
463 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
464 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
466 /* Write the last dword (or portion) byte by byte */
468 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
469 for (i = 0; num > 0; i++, num--, buf++)
470 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
474 /* General purpose, no alignment requirement, iterative (multi-byte) write, */
475 /* for 1st 4K of SRAM/regs space */
476 static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
479 memcpy_toio((priv->hw_base + addr), buf, num);
482 /* Set bit(s) in low 4K of SRAM/regs */
483 static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
485 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
488 /* Clear bit(s) in low 4K of SRAM/regs */
489 static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
491 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
494 static inline void ipw_enable_interrupts(struct ipw_priv *priv)
496 if (priv->status & STATUS_INT_ENABLED)
498 priv->status |= STATUS_INT_ENABLED;
499 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
502 static inline void ipw_disable_interrupts(struct ipw_priv *priv)
504 if (!(priv->status & STATUS_INT_ENABLED))
506 priv->status &= ~STATUS_INT_ENABLED;
507 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
510 #ifdef CONFIG_IPW2200_DEBUG
511 static char *ipw_error_desc(u32 val)
514 case IPW_FW_ERROR_OK:
516 case IPW_FW_ERROR_FAIL:
518 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
519 return "MEMORY_UNDERFLOW";
520 case IPW_FW_ERROR_MEMORY_OVERFLOW:
521 return "MEMORY_OVERFLOW";
522 case IPW_FW_ERROR_BAD_PARAM:
524 case IPW_FW_ERROR_BAD_CHECKSUM:
525 return "BAD_CHECKSUM";
526 case IPW_FW_ERROR_NMI_INTERRUPT:
527 return "NMI_INTERRUPT";
528 case IPW_FW_ERROR_BAD_DATABASE:
529 return "BAD_DATABASE";
530 case IPW_FW_ERROR_ALLOC_FAIL:
532 case IPW_FW_ERROR_DMA_UNDERRUN:
533 return "DMA_UNDERRUN";
534 case IPW_FW_ERROR_DMA_STATUS:
536 case IPW_FW_ERROR_DINO_ERROR:
538 case IPW_FW_ERROR_EEPROM_ERROR:
539 return "EEPROM_ERROR";
540 case IPW_FW_ERROR_SYSASSERT:
542 case IPW_FW_ERROR_FATAL_ERROR:
543 return "FATAL_ERROR";
545 return "UNKNOWN_ERROR";
549 static void ipw_dump_error_log(struct ipw_priv *priv,
550 struct ipw_fw_error *error)
555 IPW_ERROR("Error allocating and capturing error log. "
556 "Nothing to dump.\n");
560 IPW_ERROR("Start IPW Error Log Dump:\n");
561 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
562 error->status, error->config);
564 for (i = 0; i < error->elem_len; i++)
565 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
566 ipw_error_desc(error->elem[i].desc),
568 error->elem[i].blink1,
569 error->elem[i].blink2,
570 error->elem[i].link1,
571 error->elem[i].link2, error->elem[i].data);
572 for (i = 0; i < error->log_len; i++)
573 IPW_ERROR("%i\t0x%08x\t%i\n",
575 error->log[i].data, error->log[i].event);
579 static inline int ipw_is_init(struct ipw_priv *priv)
581 return (priv->status & STATUS_INIT) ? 1 : 0;
584 static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
586 u32 addr, field_info, field_len, field_count, total_len;
588 IPW_DEBUG_ORD("ordinal = %i\n", ord);
590 if (!priv || !val || !len) {
591 IPW_DEBUG_ORD("Invalid argument\n");
595 /* verify device ordinal tables have been initialized */
596 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
597 IPW_DEBUG_ORD("Access ordinals before initialization\n");
601 switch (IPW_ORD_TABLE_ID_MASK & ord) {
602 case IPW_ORD_TABLE_0_MASK:
604 * TABLE 0: Direct access to a table of 32 bit values
606 * This is a very simple table with the data directly
607 * read from the table
610 /* remove the table id from the ordinal */
611 ord &= IPW_ORD_TABLE_VALUE_MASK;
614 if (ord > priv->table0_len) {
615 IPW_DEBUG_ORD("ordinal value (%i) longer then "
616 "max (%i)\n", ord, priv->table0_len);
620 /* verify we have enough room to store the value */
621 if (*len < sizeof(u32)) {
622 IPW_DEBUG_ORD("ordinal buffer length too small, "
623 "need %zd\n", sizeof(u32));
627 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
628 ord, priv->table0_addr + (ord << 2));
632 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
635 case IPW_ORD_TABLE_1_MASK:
637 * TABLE 1: Indirect access to a table of 32 bit values
639 * This is a fairly large table of u32 values each
640 * representing starting addr for the data (which is
644 /* remove the table id from the ordinal */
645 ord &= IPW_ORD_TABLE_VALUE_MASK;
648 if (ord > priv->table1_len) {
649 IPW_DEBUG_ORD("ordinal value too long\n");
653 /* verify we have enough room to store the value */
654 if (*len < sizeof(u32)) {
655 IPW_DEBUG_ORD("ordinal buffer length too small, "
656 "need %zd\n", sizeof(u32));
661 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
665 case IPW_ORD_TABLE_2_MASK:
667 * TABLE 2: Indirect access to a table of variable sized values
669 * This table consist of six values, each containing
670 * - dword containing the starting offset of the data
671 * - dword containing the lengh in the first 16bits
672 * and the count in the second 16bits
675 /* remove the table id from the ordinal */
676 ord &= IPW_ORD_TABLE_VALUE_MASK;
679 if (ord > priv->table2_len) {
680 IPW_DEBUG_ORD("ordinal value too long\n");
684 /* get the address of statistic */
685 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
687 /* get the second DW of statistics ;
688 * two 16-bit words - first is length, second is count */
691 priv->table2_addr + (ord << 3) +
694 /* get each entry length */
695 field_len = *((u16 *) & field_info);
697 /* get number of entries */
698 field_count = *(((u16 *) & field_info) + 1);
700 /* abort if not enought memory */
701 total_len = field_len * field_count;
702 if (total_len > *len) {
711 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
712 "field_info = 0x%08x\n",
713 addr, total_len, field_info);
714 ipw_read_indirect(priv, addr, val, total_len);
718 IPW_DEBUG_ORD("Invalid ordinal!\n");
726 static void ipw_init_ordinals(struct ipw_priv *priv)
728 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
729 priv->table0_len = ipw_read32(priv, priv->table0_addr);
731 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
732 priv->table0_addr, priv->table0_len);
734 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
735 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
737 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
738 priv->table1_addr, priv->table1_len);
740 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
741 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
742 priv->table2_len &= 0x0000ffff; /* use first two bytes */
744 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
745 priv->table2_addr, priv->table2_len);
749 static u32 ipw_register_toggle(u32 reg)
751 reg &= ~IPW_START_STANDBY;
752 if (reg & IPW_GATE_ODMA)
753 reg &= ~IPW_GATE_ODMA;
754 if (reg & IPW_GATE_IDMA)
755 reg &= ~IPW_GATE_IDMA;
756 if (reg & IPW_GATE_ADMA)
757 reg &= ~IPW_GATE_ADMA;
763 * - On radio ON, turn on any LEDs that require to be on during start
764 * - On initialization, start unassociated blink
765 * - On association, disable unassociated blink
766 * - On disassociation, start unassociated blink
767 * - On radio OFF, turn off any LEDs started during radio on
770 #define LD_TIME_LINK_ON msecs_to_jiffies(300)
771 #define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
772 #define LD_TIME_ACT_ON msecs_to_jiffies(250)
774 static void ipw_led_link_on(struct ipw_priv *priv)
779 /* If configured to not use LEDs, or nic_type is 1,
780 * then we don't toggle a LINK led */
781 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
784 spin_lock_irqsave(&priv->lock, flags);
786 if (!(priv->status & STATUS_RF_KILL_MASK) &&
787 !(priv->status & STATUS_LED_LINK_ON)) {
788 IPW_DEBUG_LED("Link LED On\n");
789 led = ipw_read_reg32(priv, IPW_EVENT_REG);
790 led |= priv->led_association_on;
792 led = ipw_register_toggle(led);
794 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
795 ipw_write_reg32(priv, IPW_EVENT_REG, led);
797 priv->status |= STATUS_LED_LINK_ON;
799 /* If we aren't associated, schedule turning the LED off */
800 if (!(priv->status & STATUS_ASSOCIATED))
801 queue_delayed_work(priv->workqueue,
806 spin_unlock_irqrestore(&priv->lock, flags);
809 static void ipw_bg_led_link_on(void *data)
811 struct ipw_priv *priv = data;
812 mutex_lock(&priv->mutex);
813 ipw_led_link_on(data);
814 mutex_unlock(&priv->mutex);
817 static void ipw_led_link_off(struct ipw_priv *priv)
822 /* If configured not to use LEDs, or nic type is 1,
823 * then we don't goggle the LINK led. */
824 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
827 spin_lock_irqsave(&priv->lock, flags);
829 if (priv->status & STATUS_LED_LINK_ON) {
830 led = ipw_read_reg32(priv, IPW_EVENT_REG);
831 led &= priv->led_association_off;
832 led = ipw_register_toggle(led);
834 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
835 ipw_write_reg32(priv, IPW_EVENT_REG, led);
837 IPW_DEBUG_LED("Link LED Off\n");
839 priv->status &= ~STATUS_LED_LINK_ON;
841 /* If we aren't associated and the radio is on, schedule
842 * turning the LED on (blink while unassociated) */
843 if (!(priv->status & STATUS_RF_KILL_MASK) &&
844 !(priv->status & STATUS_ASSOCIATED))
845 queue_delayed_work(priv->workqueue, &priv->led_link_on,
850 spin_unlock_irqrestore(&priv->lock, flags);
853 static void ipw_bg_led_link_off(void *data)
855 struct ipw_priv *priv = data;
856 mutex_lock(&priv->mutex);
857 ipw_led_link_off(data);
858 mutex_unlock(&priv->mutex);
861 static void __ipw_led_activity_on(struct ipw_priv *priv)
865 if (priv->config & CFG_NO_LED)
868 if (priv->status & STATUS_RF_KILL_MASK)
871 if (!(priv->status & STATUS_LED_ACT_ON)) {
872 led = ipw_read_reg32(priv, IPW_EVENT_REG);
873 led |= priv->led_activity_on;
875 led = ipw_register_toggle(led);
877 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
878 ipw_write_reg32(priv, IPW_EVENT_REG, led);
880 IPW_DEBUG_LED("Activity LED On\n");
882 priv->status |= STATUS_LED_ACT_ON;
884 cancel_delayed_work(&priv->led_act_off);
885 queue_delayed_work(priv->workqueue, &priv->led_act_off,
888 /* Reschedule LED off for full time period */
889 cancel_delayed_work(&priv->led_act_off);
890 queue_delayed_work(priv->workqueue, &priv->led_act_off,
896 void ipw_led_activity_on(struct ipw_priv *priv)
899 spin_lock_irqsave(&priv->lock, flags);
900 __ipw_led_activity_on(priv);
901 spin_unlock_irqrestore(&priv->lock, flags);
905 static void ipw_led_activity_off(struct ipw_priv *priv)
910 if (priv->config & CFG_NO_LED)
913 spin_lock_irqsave(&priv->lock, flags);
915 if (priv->status & STATUS_LED_ACT_ON) {
916 led = ipw_read_reg32(priv, IPW_EVENT_REG);
917 led &= priv->led_activity_off;
919 led = ipw_register_toggle(led);
921 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
922 ipw_write_reg32(priv, IPW_EVENT_REG, led);
924 IPW_DEBUG_LED("Activity LED Off\n");
926 priv->status &= ~STATUS_LED_ACT_ON;
929 spin_unlock_irqrestore(&priv->lock, flags);
932 static void ipw_bg_led_activity_off(void *data)
934 struct ipw_priv *priv = data;
935 mutex_lock(&priv->mutex);
936 ipw_led_activity_off(data);
937 mutex_unlock(&priv->mutex);
940 static void ipw_led_band_on(struct ipw_priv *priv)
945 /* Only nic type 1 supports mode LEDs */
946 if (priv->config & CFG_NO_LED ||
947 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
950 spin_lock_irqsave(&priv->lock, flags);
952 led = ipw_read_reg32(priv, IPW_EVENT_REG);
953 if (priv->assoc_network->mode == IEEE_A) {
954 led |= priv->led_ofdm_on;
955 led &= priv->led_association_off;
956 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
957 } else if (priv->assoc_network->mode == IEEE_G) {
958 led |= priv->led_ofdm_on;
959 led |= priv->led_association_on;
960 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
962 led &= priv->led_ofdm_off;
963 led |= priv->led_association_on;
964 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
967 led = ipw_register_toggle(led);
969 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
970 ipw_write_reg32(priv, IPW_EVENT_REG, led);
972 spin_unlock_irqrestore(&priv->lock, flags);
975 static void ipw_led_band_off(struct ipw_priv *priv)
980 /* Only nic type 1 supports mode LEDs */
981 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
984 spin_lock_irqsave(&priv->lock, flags);
986 led = ipw_read_reg32(priv, IPW_EVENT_REG);
987 led &= priv->led_ofdm_off;
988 led &= priv->led_association_off;
990 led = ipw_register_toggle(led);
992 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
993 ipw_write_reg32(priv, IPW_EVENT_REG, led);
995 spin_unlock_irqrestore(&priv->lock, flags);
998 static void ipw_led_radio_on(struct ipw_priv *priv)
1000 ipw_led_link_on(priv);
1003 static void ipw_led_radio_off(struct ipw_priv *priv)
1005 ipw_led_activity_off(priv);
1006 ipw_led_link_off(priv);
1009 static void ipw_led_link_up(struct ipw_priv *priv)
1011 /* Set the Link Led on for all nic types */
1012 ipw_led_link_on(priv);
1015 static void ipw_led_link_down(struct ipw_priv *priv)
1017 ipw_led_activity_off(priv);
1018 ipw_led_link_off(priv);
1020 if (priv->status & STATUS_RF_KILL_MASK)
1021 ipw_led_radio_off(priv);
1024 static void ipw_led_init(struct ipw_priv *priv)
1026 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1028 /* Set the default PINs for the link and activity leds */
1029 priv->led_activity_on = IPW_ACTIVITY_LED;
1030 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
1032 priv->led_association_on = IPW_ASSOCIATED_LED;
1033 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
1035 /* Set the default PINs for the OFDM leds */
1036 priv->led_ofdm_on = IPW_OFDM_LED;
1037 priv->led_ofdm_off = ~(IPW_OFDM_LED);
1039 switch (priv->nic_type) {
1040 case EEPROM_NIC_TYPE_1:
1041 /* In this NIC type, the LEDs are reversed.... */
1042 priv->led_activity_on = IPW_ASSOCIATED_LED;
1043 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1044 priv->led_association_on = IPW_ACTIVITY_LED;
1045 priv->led_association_off = ~(IPW_ACTIVITY_LED);
1047 if (!(priv->config & CFG_NO_LED))
1048 ipw_led_band_on(priv);
1050 /* And we don't blink link LEDs for this nic, so
1051 * just return here */
1054 case EEPROM_NIC_TYPE_3:
1055 case EEPROM_NIC_TYPE_2:
1056 case EEPROM_NIC_TYPE_4:
1057 case EEPROM_NIC_TYPE_0:
1061 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1063 priv->nic_type = EEPROM_NIC_TYPE_0;
1067 if (!(priv->config & CFG_NO_LED)) {
1068 if (priv->status & STATUS_ASSOCIATED)
1069 ipw_led_link_on(priv);
1071 ipw_led_link_off(priv);
1075 static void ipw_led_shutdown(struct ipw_priv *priv)
1077 ipw_led_activity_off(priv);
1078 ipw_led_link_off(priv);
1079 ipw_led_band_off(priv);
1080 cancel_delayed_work(&priv->led_link_on);
1081 cancel_delayed_work(&priv->led_link_off);
1082 cancel_delayed_work(&priv->led_act_off);
1086 * The following adds a new attribute to the sysfs representation
1087 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1088 * used for controling the debug level.
1090 * See the level definitions in ipw for details.
1092 static ssize_t show_debug_level(struct device_driver *d, char *buf)
1094 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1097 static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1100 char *p = (char *)buf;
1103 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1105 if (p[0] == 'x' || p[0] == 'X')
1107 val = simple_strtoul(p, &p, 16);
1109 val = simple_strtoul(p, &p, 10);
1111 printk(KERN_INFO DRV_NAME
1112 ": %s is not in hex or decimal form.\n", buf);
1114 ipw_debug_level = val;
1116 return strnlen(buf, count);
1119 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
1120 show_debug_level, store_debug_level);
1122 static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1124 /* length = 1st dword in log */
1125 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1128 static void ipw_capture_event_log(struct ipw_priv *priv,
1129 u32 log_len, struct ipw_event *log)
1134 base = ipw_read32(priv, IPW_EVENT_LOG);
1135 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1136 (u8 *) log, sizeof(*log) * log_len);
1140 static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1142 struct ipw_fw_error *error;
1143 u32 log_len = ipw_get_event_log_len(priv);
1144 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1145 u32 elem_len = ipw_read_reg32(priv, base);
1147 error = kmalloc(sizeof(*error) +
1148 sizeof(*error->elem) * elem_len +
1149 sizeof(*error->log) * log_len, GFP_ATOMIC);
1151 IPW_ERROR("Memory allocation for firmware error log "
1155 error->jiffies = jiffies;
1156 error->status = priv->status;
1157 error->config = priv->config;
1158 error->elem_len = elem_len;
1159 error->log_len = log_len;
1160 error->elem = (struct ipw_error_elem *)error->payload;
1161 error->log = (struct ipw_event *)(error->elem + elem_len);
1163 ipw_capture_event_log(priv, log_len, error->log);
1166 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1167 sizeof(*error->elem) * elem_len);
1172 static void ipw_free_error_log(struct ipw_fw_error *error)
1178 static ssize_t show_event_log(struct device *d,
1179 struct device_attribute *attr, char *buf)
1181 struct ipw_priv *priv = dev_get_drvdata(d);
1182 u32 log_len = ipw_get_event_log_len(priv);
1183 struct ipw_event log[log_len];
1186 ipw_capture_event_log(priv, log_len, log);
1188 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1189 for (i = 0; i < log_len; i++)
1190 len += snprintf(buf + len, PAGE_SIZE - len,
1192 log[i].time, log[i].event, log[i].data);
1193 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1197 static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1199 static ssize_t show_error(struct device *d,
1200 struct device_attribute *attr, char *buf)
1202 struct ipw_priv *priv = dev_get_drvdata(d);
1206 len += snprintf(buf + len, PAGE_SIZE - len,
1207 "%08lX%08X%08X%08X",
1208 priv->error->jiffies,
1209 priv->error->status,
1210 priv->error->config, priv->error->elem_len);
1211 for (i = 0; i < priv->error->elem_len; i++)
1212 len += snprintf(buf + len, PAGE_SIZE - len,
1213 "\n%08X%08X%08X%08X%08X%08X%08X",
1214 priv->error->elem[i].time,
1215 priv->error->elem[i].desc,
1216 priv->error->elem[i].blink1,
1217 priv->error->elem[i].blink2,
1218 priv->error->elem[i].link1,
1219 priv->error->elem[i].link2,
1220 priv->error->elem[i].data);
1222 len += snprintf(buf + len, PAGE_SIZE - len,
1223 "\n%08X", priv->error->log_len);
1224 for (i = 0; i < priv->error->log_len; i++)
1225 len += snprintf(buf + len, PAGE_SIZE - len,
1227 priv->error->log[i].time,
1228 priv->error->log[i].event,
1229 priv->error->log[i].data);
1230 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1234 static ssize_t clear_error(struct device *d,
1235 struct device_attribute *attr,
1236 const char *buf, size_t count)
1238 struct ipw_priv *priv = dev_get_drvdata(d);
1240 ipw_free_error_log(priv->error);
1246 static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1248 static ssize_t show_cmd_log(struct device *d,
1249 struct device_attribute *attr, char *buf)
1251 struct ipw_priv *priv = dev_get_drvdata(d);
1255 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1256 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1257 i = (i + 1) % priv->cmdlog_len) {
1259 snprintf(buf + len, PAGE_SIZE - len,
1260 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1261 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1262 priv->cmdlog[i].cmd.len);
1264 snprintk_buf(buf + len, PAGE_SIZE - len,
1265 (u8 *) priv->cmdlog[i].cmd.param,
1266 priv->cmdlog[i].cmd.len);
1267 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1269 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1273 static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1275 static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1278 struct ipw_priv *priv = dev_get_drvdata(d);
1279 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1282 static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1283 const char *buf, size_t count)
1285 struct ipw_priv *priv = dev_get_drvdata(d);
1286 #ifdef CONFIG_IPW2200_DEBUG
1287 struct net_device *dev = priv->net_dev;
1289 char buffer[] = "00000000";
1291 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1295 IPW_DEBUG_INFO("enter\n");
1297 strncpy(buffer, buf, len);
1300 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1302 if (p[0] == 'x' || p[0] == 'X')
1304 val = simple_strtoul(p, &p, 16);
1306 val = simple_strtoul(p, &p, 10);
1308 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1310 priv->ieee->scan_age = val;
1311 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1314 IPW_DEBUG_INFO("exit\n");
1318 static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1320 static ssize_t show_led(struct device *d, struct device_attribute *attr,
1323 struct ipw_priv *priv = dev_get_drvdata(d);
1324 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1327 static ssize_t store_led(struct device *d, struct device_attribute *attr,
1328 const char *buf, size_t count)
1330 struct ipw_priv *priv = dev_get_drvdata(d);
1332 IPW_DEBUG_INFO("enter\n");
1338 IPW_DEBUG_LED("Disabling LED control.\n");
1339 priv->config |= CFG_NO_LED;
1340 ipw_led_shutdown(priv);
1342 IPW_DEBUG_LED("Enabling LED control.\n");
1343 priv->config &= ~CFG_NO_LED;
1347 IPW_DEBUG_INFO("exit\n");
1351 static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1353 static ssize_t show_status(struct device *d,
1354 struct device_attribute *attr, char *buf)
1356 struct ipw_priv *p = d->driver_data;
1357 return sprintf(buf, "0x%08x\n", (int)p->status);
1360 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1362 static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1365 struct ipw_priv *p = d->driver_data;
1366 return sprintf(buf, "0x%08x\n", (int)p->config);
1369 static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1371 static ssize_t show_nic_type(struct device *d,
1372 struct device_attribute *attr, char *buf)
1374 struct ipw_priv *priv = d->driver_data;
1375 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
1378 static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1380 static ssize_t show_ucode_version(struct device *d,
1381 struct device_attribute *attr, char *buf)
1383 u32 len = sizeof(u32), tmp = 0;
1384 struct ipw_priv *p = d->driver_data;
1386 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
1389 return sprintf(buf, "0x%08x\n", tmp);
1392 static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
1394 static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1397 u32 len = sizeof(u32), tmp = 0;
1398 struct ipw_priv *p = d->driver_data;
1400 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
1403 return sprintf(buf, "0x%08x\n", tmp);
1406 static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
1409 * Add a device attribute to view/control the delay between eeprom
1412 static ssize_t show_eeprom_delay(struct device *d,
1413 struct device_attribute *attr, char *buf)
1415 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
1416 return sprintf(buf, "%i\n", n);
1418 static ssize_t store_eeprom_delay(struct device *d,
1419 struct device_attribute *attr,
1420 const char *buf, size_t count)
1422 struct ipw_priv *p = d->driver_data;
1423 sscanf(buf, "%i", &p->eeprom_delay);
1424 return strnlen(buf, count);
1427 static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1428 show_eeprom_delay, store_eeprom_delay);
1430 static ssize_t show_command_event_reg(struct device *d,
1431 struct device_attribute *attr, char *buf)
1434 struct ipw_priv *p = d->driver_data;
1436 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
1437 return sprintf(buf, "0x%08x\n", reg);
1439 static ssize_t store_command_event_reg(struct device *d,
1440 struct device_attribute *attr,
1441 const char *buf, size_t count)
1444 struct ipw_priv *p = d->driver_data;
1446 sscanf(buf, "%x", ®);
1447 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
1448 return strnlen(buf, count);
1451 static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1452 show_command_event_reg, store_command_event_reg);
1454 static ssize_t show_mem_gpio_reg(struct device *d,
1455 struct device_attribute *attr, char *buf)
1458 struct ipw_priv *p = d->driver_data;
1460 reg = ipw_read_reg32(p, 0x301100);
1461 return sprintf(buf, "0x%08x\n", reg);
1463 static ssize_t store_mem_gpio_reg(struct device *d,
1464 struct device_attribute *attr,
1465 const char *buf, size_t count)
1468 struct ipw_priv *p = d->driver_data;
1470 sscanf(buf, "%x", ®);
1471 ipw_write_reg32(p, 0x301100, reg);
1472 return strnlen(buf, count);
1475 static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1476 show_mem_gpio_reg, store_mem_gpio_reg);
1478 static ssize_t show_indirect_dword(struct device *d,
1479 struct device_attribute *attr, char *buf)
1482 struct ipw_priv *priv = d->driver_data;
1484 if (priv->status & STATUS_INDIRECT_DWORD)
1485 reg = ipw_read_reg32(priv, priv->indirect_dword);
1489 return sprintf(buf, "0x%08x\n", reg);
1491 static ssize_t store_indirect_dword(struct device *d,
1492 struct device_attribute *attr,
1493 const char *buf, size_t count)
1495 struct ipw_priv *priv = d->driver_data;
1497 sscanf(buf, "%x", &priv->indirect_dword);
1498 priv->status |= STATUS_INDIRECT_DWORD;
1499 return strnlen(buf, count);
1502 static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1503 show_indirect_dword, store_indirect_dword);
1505 static ssize_t show_indirect_byte(struct device *d,
1506 struct device_attribute *attr, char *buf)
1509 struct ipw_priv *priv = d->driver_data;
1511 if (priv->status & STATUS_INDIRECT_BYTE)
1512 reg = ipw_read_reg8(priv, priv->indirect_byte);
1516 return sprintf(buf, "0x%02x\n", reg);
1518 static ssize_t store_indirect_byte(struct device *d,
1519 struct device_attribute *attr,
1520 const char *buf, size_t count)
1522 struct ipw_priv *priv = d->driver_data;
1524 sscanf(buf, "%x", &priv->indirect_byte);
1525 priv->status |= STATUS_INDIRECT_BYTE;
1526 return strnlen(buf, count);
1529 static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
1530 show_indirect_byte, store_indirect_byte);
1532 static ssize_t show_direct_dword(struct device *d,
1533 struct device_attribute *attr, char *buf)
1536 struct ipw_priv *priv = d->driver_data;
1538 if (priv->status & STATUS_DIRECT_DWORD)
1539 reg = ipw_read32(priv, priv->direct_dword);
1543 return sprintf(buf, "0x%08x\n", reg);
1545 static ssize_t store_direct_dword(struct device *d,
1546 struct device_attribute *attr,
1547 const char *buf, size_t count)
1549 struct ipw_priv *priv = d->driver_data;
1551 sscanf(buf, "%x", &priv->direct_dword);
1552 priv->status |= STATUS_DIRECT_DWORD;
1553 return strnlen(buf, count);
1556 static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1557 show_direct_dword, store_direct_dword);
1559 static int rf_kill_active(struct ipw_priv *priv)
1561 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1562 priv->status |= STATUS_RF_KILL_HW;
1564 priv->status &= ~STATUS_RF_KILL_HW;
1566 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1569 static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
1572 /* 0 - RF kill not enabled
1573 1 - SW based RF kill active (sysfs)
1574 2 - HW based RF kill active
1575 3 - Both HW and SW baed RF kill active */
1576 struct ipw_priv *priv = d->driver_data;
1577 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
1578 (rf_kill_active(priv) ? 0x2 : 0x0);
1579 return sprintf(buf, "%i\n", val);
1582 static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1584 if ((disable_radio ? 1 : 0) ==
1585 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
1588 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1589 disable_radio ? "OFF" : "ON");
1591 if (disable_radio) {
1592 priv->status |= STATUS_RF_KILL_SW;
1594 if (priv->workqueue)
1595 cancel_delayed_work(&priv->request_scan);
1596 queue_work(priv->workqueue, &priv->down);
1598 priv->status &= ~STATUS_RF_KILL_SW;
1599 if (rf_kill_active(priv)) {
1600 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1601 "disabled by HW switch\n");
1602 /* Make sure the RF_KILL check timer is running */
1603 cancel_delayed_work(&priv->rf_kill);
1604 queue_delayed_work(priv->workqueue, &priv->rf_kill,
1607 queue_work(priv->workqueue, &priv->up);
1613 static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1614 const char *buf, size_t count)
1616 struct ipw_priv *priv = d->driver_data;
1618 ipw_radio_kill_sw(priv, buf[0] == '1');
1623 static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
1625 static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1628 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1629 int pos = 0, len = 0;
1630 if (priv->config & CFG_SPEED_SCAN) {
1631 while (priv->speed_scan[pos] != 0)
1632 len += sprintf(&buf[len], "%d ",
1633 priv->speed_scan[pos++]);
1634 return len + sprintf(&buf[len], "\n");
1637 return sprintf(buf, "0\n");
1640 static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1641 const char *buf, size_t count)
1643 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1644 int channel, pos = 0;
1645 const char *p = buf;
1647 /* list of space separated channels to scan, optionally ending with 0 */
1648 while ((channel = simple_strtol(p, NULL, 0))) {
1649 if (pos == MAX_SPEED_SCAN - 1) {
1650 priv->speed_scan[pos] = 0;
1654 if (ieee80211_is_valid_channel(priv->ieee, channel))
1655 priv->speed_scan[pos++] = channel;
1657 IPW_WARNING("Skipping invalid channel request: %d\n",
1662 while (*p == ' ' || *p == '\t')
1667 priv->config &= ~CFG_SPEED_SCAN;
1669 priv->speed_scan_pos = 0;
1670 priv->config |= CFG_SPEED_SCAN;
1676 static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1679 static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1682 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1683 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1686 static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1687 const char *buf, size_t count)
1689 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1691 priv->config |= CFG_NET_STATS;
1693 priv->config &= ~CFG_NET_STATS;
1698 static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1699 show_net_stats, store_net_stats);
1701 static void notify_wx_assoc_event(struct ipw_priv *priv)
1703 union iwreq_data wrqu;
1704 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1705 if (priv->status & STATUS_ASSOCIATED)
1706 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1708 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1709 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1712 static void ipw_irq_tasklet(struct ipw_priv *priv)
1714 u32 inta, inta_mask, handled = 0;
1715 unsigned long flags;
1718 spin_lock_irqsave(&priv->lock, flags);
1720 inta = ipw_read32(priv, IPW_INTA_RW);
1721 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1722 inta &= (IPW_INTA_MASK_ALL & inta_mask);
1724 /* Add any cached INTA values that need to be handled */
1725 inta |= priv->isr_inta;
1727 /* handle all the justifications for the interrupt */
1728 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
1730 handled |= IPW_INTA_BIT_RX_TRANSFER;
1733 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
1734 IPW_DEBUG_HC("Command completed.\n");
1735 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
1736 priv->status &= ~STATUS_HCMD_ACTIVE;
1737 wake_up_interruptible(&priv->wait_command_queue);
1738 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
1741 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
1742 IPW_DEBUG_TX("TX_QUEUE_1\n");
1743 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
1744 handled |= IPW_INTA_BIT_TX_QUEUE_1;
1747 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
1748 IPW_DEBUG_TX("TX_QUEUE_2\n");
1749 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
1750 handled |= IPW_INTA_BIT_TX_QUEUE_2;
1753 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
1754 IPW_DEBUG_TX("TX_QUEUE_3\n");
1755 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
1756 handled |= IPW_INTA_BIT_TX_QUEUE_3;
1759 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
1760 IPW_DEBUG_TX("TX_QUEUE_4\n");
1761 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
1762 handled |= IPW_INTA_BIT_TX_QUEUE_4;
1765 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
1766 IPW_WARNING("STATUS_CHANGE\n");
1767 handled |= IPW_INTA_BIT_STATUS_CHANGE;
1770 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
1771 IPW_WARNING("TX_PERIOD_EXPIRED\n");
1772 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
1775 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
1776 IPW_WARNING("HOST_CMD_DONE\n");
1777 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
1780 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
1781 IPW_WARNING("FW_INITIALIZATION_DONE\n");
1782 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
1785 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
1786 IPW_WARNING("PHY_OFF_DONE\n");
1787 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
1790 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
1791 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1792 priv->status |= STATUS_RF_KILL_HW;
1793 wake_up_interruptible(&priv->wait_command_queue);
1794 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1795 cancel_delayed_work(&priv->request_scan);
1796 schedule_work(&priv->link_down);
1797 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
1798 handled |= IPW_INTA_BIT_RF_KILL_DONE;
1801 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
1802 IPW_WARNING("Firmware error detected. Restarting.\n");
1804 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
1805 #ifdef CONFIG_IPW2200_DEBUG
1806 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1807 struct ipw_fw_error *error =
1808 ipw_alloc_error_log(priv);
1809 ipw_dump_error_log(priv, error);
1811 ipw_free_error_log(error);
1815 priv->error = ipw_alloc_error_log(priv);
1817 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
1819 IPW_DEBUG_FW("Error allocating sysfs 'error' "
1821 #ifdef CONFIG_IPW2200_DEBUG
1822 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1823 ipw_dump_error_log(priv, priv->error);
1827 /* XXX: If hardware encryption is for WPA/WPA2,
1828 * we have to notify the supplicant. */
1829 if (priv->ieee->sec.encrypt) {
1830 priv->status &= ~STATUS_ASSOCIATED;
1831 notify_wx_assoc_event(priv);
1834 /* Keep the restart process from trying to send host
1835 * commands by clearing the INIT status bit */
1836 priv->status &= ~STATUS_INIT;
1838 /* Cancel currently queued command. */
1839 priv->status &= ~STATUS_HCMD_ACTIVE;
1840 wake_up_interruptible(&priv->wait_command_queue);
1842 queue_work(priv->workqueue, &priv->adapter_restart);
1843 handled |= IPW_INTA_BIT_FATAL_ERROR;
1846 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
1847 IPW_ERROR("Parity error\n");
1848 handled |= IPW_INTA_BIT_PARITY_ERROR;
1851 if (handled != inta) {
1852 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
1855 /* enable all interrupts */
1856 ipw_enable_interrupts(priv);
1858 spin_unlock_irqrestore(&priv->lock, flags);
1861 #define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1862 static char *get_cmd_string(u8 cmd)
1865 IPW_CMD(HOST_COMPLETE);
1866 IPW_CMD(POWER_DOWN);
1867 IPW_CMD(SYSTEM_CONFIG);
1868 IPW_CMD(MULTICAST_ADDRESS);
1870 IPW_CMD(ADAPTER_ADDRESS);
1872 IPW_CMD(RTS_THRESHOLD);
1873 IPW_CMD(FRAG_THRESHOLD);
1874 IPW_CMD(POWER_MODE);
1876 IPW_CMD(TGI_TX_KEY);
1877 IPW_CMD(SCAN_REQUEST);
1878 IPW_CMD(SCAN_REQUEST_EXT);
1880 IPW_CMD(SUPPORTED_RATES);
1881 IPW_CMD(SCAN_ABORT);
1883 IPW_CMD(QOS_PARAMETERS);
1884 IPW_CMD(DINO_CONFIG);
1885 IPW_CMD(RSN_CAPABILITIES);
1887 IPW_CMD(CARD_DISABLE);
1888 IPW_CMD(SEED_NUMBER);
1890 IPW_CMD(COUNTRY_INFO);
1891 IPW_CMD(AIRONET_INFO);
1892 IPW_CMD(AP_TX_POWER);
1894 IPW_CMD(CCX_VER_INFO);
1895 IPW_CMD(SET_CALIBRATION);
1896 IPW_CMD(SENSITIVITY_CALIB);
1897 IPW_CMD(RETRY_LIMIT);
1898 IPW_CMD(IPW_PRE_POWER_DOWN);
1899 IPW_CMD(VAP_BEACON_TEMPLATE);
1900 IPW_CMD(VAP_DTIM_PERIOD);
1901 IPW_CMD(EXT_SUPPORTED_RATES);
1902 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
1903 IPW_CMD(VAP_QUIET_INTERVALS);
1904 IPW_CMD(VAP_CHANNEL_SWITCH);
1905 IPW_CMD(VAP_MANDATORY_CHANNELS);
1906 IPW_CMD(VAP_CELL_PWR_LIMIT);
1907 IPW_CMD(VAP_CF_PARAM_SET);
1908 IPW_CMD(VAP_SET_BEACONING_STATE);
1909 IPW_CMD(MEASUREMENT);
1910 IPW_CMD(POWER_CAPABILITY);
1911 IPW_CMD(SUPPORTED_CHANNELS);
1912 IPW_CMD(TPC_REPORT);
1914 IPW_CMD(PRODUCTION_COMMAND);
1920 #define HOST_COMPLETE_TIMEOUT HZ
1922 static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
1925 unsigned long flags;
1927 spin_lock_irqsave(&priv->lock, flags);
1928 if (priv->status & STATUS_HCMD_ACTIVE) {
1929 IPW_ERROR("Failed to send %s: Already sending a command.\n",
1930 get_cmd_string(cmd->cmd));
1931 spin_unlock_irqrestore(&priv->lock, flags);
1935 priv->status |= STATUS_HCMD_ACTIVE;
1938 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
1939 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
1940 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
1941 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
1943 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
1946 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
1947 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
1950 #ifndef DEBUG_CMD_WEP_KEY
1951 if (cmd->cmd == IPW_CMD_WEP_KEY)
1952 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
1955 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
1957 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
1959 priv->status &= ~STATUS_HCMD_ACTIVE;
1960 IPW_ERROR("Failed to send %s: Reason %d\n",
1961 get_cmd_string(cmd->cmd), rc);
1962 spin_unlock_irqrestore(&priv->lock, flags);
1965 spin_unlock_irqrestore(&priv->lock, flags);
1967 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1969 status & STATUS_HCMD_ACTIVE),
1970 HOST_COMPLETE_TIMEOUT);
1972 spin_lock_irqsave(&priv->lock, flags);
1973 if (priv->status & STATUS_HCMD_ACTIVE) {
1974 IPW_ERROR("Failed to send %s: Command timed out.\n",
1975 get_cmd_string(cmd->cmd));
1976 priv->status &= ~STATUS_HCMD_ACTIVE;
1977 spin_unlock_irqrestore(&priv->lock, flags);
1981 spin_unlock_irqrestore(&priv->lock, flags);
1985 if (priv->status & STATUS_RF_KILL_HW) {
1986 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
1987 get_cmd_string(cmd->cmd));
1994 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
1995 priv->cmdlog_pos %= priv->cmdlog_len;
2000 static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
2002 struct host_cmd cmd = {
2006 return __ipw_send_cmd(priv, &cmd);
2009 static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2012 struct host_cmd cmd = {
2018 return __ipw_send_cmd(priv, &cmd);
2021 static int ipw_send_host_complete(struct ipw_priv *priv)
2024 IPW_ERROR("Invalid args\n");
2028 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
2031 static int ipw_send_system_config(struct ipw_priv *priv,
2032 struct ipw_sys_config *config)
2034 if (!priv || !config) {
2035 IPW_ERROR("Invalid args\n");
2039 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, sizeof(*config),
2043 static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
2045 if (!priv || !ssid) {
2046 IPW_ERROR("Invalid args\n");
2050 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
2054 static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
2056 if (!priv || !mac) {
2057 IPW_ERROR("Invalid args\n");
2061 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2062 priv->net_dev->name, MAC_ARG(mac));
2064 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
2068 * NOTE: This must be executed from our workqueue as it results in udelay
2069 * being called which may corrupt the keyboard if executed on default
2072 static void ipw_adapter_restart(void *adapter)
2074 struct ipw_priv *priv = adapter;
2076 if (priv->status & STATUS_RF_KILL_MASK)
2081 if (priv->assoc_network &&
2082 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2083 ipw_remove_current_network(priv);
2086 IPW_ERROR("Failed to up device\n");
2091 static void ipw_bg_adapter_restart(void *data)
2093 struct ipw_priv *priv = data;
2094 mutex_lock(&priv->mutex);
2095 ipw_adapter_restart(data);
2096 mutex_unlock(&priv->mutex);
2099 #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2101 static void ipw_scan_check(void *data)
2103 struct ipw_priv *priv = data;
2104 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2105 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
2106 "adapter after (%dms).\n",
2107 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
2108 queue_work(priv->workqueue, &priv->adapter_restart);
2112 static void ipw_bg_scan_check(void *data)
2114 struct ipw_priv *priv = data;
2115 mutex_lock(&priv->mutex);
2116 ipw_scan_check(data);
2117 mutex_unlock(&priv->mutex);
2120 static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2121 struct ipw_scan_request_ext *request)
2123 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
2124 sizeof(*request), request);
2127 static int ipw_send_scan_abort(struct ipw_priv *priv)
2130 IPW_ERROR("Invalid args\n");
2134 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
2137 static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2139 struct ipw_sensitivity_calib calib = {
2140 .beacon_rssi_raw = sens,
2143 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
2147 static int ipw_send_associate(struct ipw_priv *priv,
2148 struct ipw_associate *associate)
2150 struct ipw_associate tmp_associate;
2152 if (!priv || !associate) {
2153 IPW_ERROR("Invalid args\n");
2157 memcpy(&tmp_associate, associate, sizeof(*associate));
2158 tmp_associate.policy_support =
2159 cpu_to_le16(tmp_associate.policy_support);
2160 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2161 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2162 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2163 tmp_associate.listen_interval =
2164 cpu_to_le16(tmp_associate.listen_interval);
2165 tmp_associate.beacon_interval =
2166 cpu_to_le16(tmp_associate.beacon_interval);
2167 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2169 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
2173 static int ipw_send_supported_rates(struct ipw_priv *priv,
2174 struct ipw_supported_rates *rates)
2176 if (!priv || !rates) {
2177 IPW_ERROR("Invalid args\n");
2181 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
2185 static int ipw_set_random_seed(struct ipw_priv *priv)
2190 IPW_ERROR("Invalid args\n");
2194 get_random_bytes(&val, sizeof(val));
2196 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
2199 static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2202 IPW_ERROR("Invalid args\n");
2206 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off),
2210 static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
2212 if (!priv || !power) {
2213 IPW_ERROR("Invalid args\n");
2217 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
2220 static int ipw_set_tx_power(struct ipw_priv *priv)
2222 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
2223 struct ipw_tx_power tx_power;
2227 memset(&tx_power, 0, sizeof(tx_power));
2229 /* configure device for 'G' band */
2230 tx_power.ieee_mode = IPW_G_MODE;
2231 tx_power.num_channels = geo->bg_channels;
2232 for (i = 0; i < geo->bg_channels; i++) {
2233 max_power = geo->bg[i].max_power;
2234 tx_power.channels_tx_power[i].channel_number =
2236 tx_power.channels_tx_power[i].tx_power = max_power ?
2237 min(max_power, priv->tx_power) : priv->tx_power;
2239 if (ipw_send_tx_power(priv, &tx_power))
2242 /* configure device to also handle 'B' band */
2243 tx_power.ieee_mode = IPW_B_MODE;
2244 if (ipw_send_tx_power(priv, &tx_power))
2247 /* configure device to also handle 'A' band */
2248 if (priv->ieee->abg_true) {
2249 tx_power.ieee_mode = IPW_A_MODE;
2250 tx_power.num_channels = geo->a_channels;
2251 for (i = 0; i < tx_power.num_channels; i++) {
2252 max_power = geo->a[i].max_power;
2253 tx_power.channels_tx_power[i].channel_number =
2255 tx_power.channels_tx_power[i].tx_power = max_power ?
2256 min(max_power, priv->tx_power) : priv->tx_power;
2258 if (ipw_send_tx_power(priv, &tx_power))
2264 static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2266 struct ipw_rts_threshold rts_threshold = {
2267 .rts_threshold = rts,
2271 IPW_ERROR("Invalid args\n");
2275 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2276 sizeof(rts_threshold), &rts_threshold);
2279 static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2281 struct ipw_frag_threshold frag_threshold = {
2282 .frag_threshold = frag,
2286 IPW_ERROR("Invalid args\n");
2290 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2291 sizeof(frag_threshold), &frag_threshold);
2294 static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2299 IPW_ERROR("Invalid args\n");
2303 /* If on battery, set to 3, if AC set to CAM, else user
2306 case IPW_POWER_BATTERY:
2307 param = IPW_POWER_INDEX_3;
2310 param = IPW_POWER_MODE_CAM;
2317 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
2321 static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2323 struct ipw_retry_limit retry_limit = {
2324 .short_retry_limit = slimit,
2325 .long_retry_limit = llimit
2329 IPW_ERROR("Invalid args\n");
2333 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
2338 * The IPW device contains a Microwire compatible EEPROM that stores
2339 * various data like the MAC address. Usually the firmware has exclusive
2340 * access to the eeprom, but during device initialization (before the
2341 * device driver has sent the HostComplete command to the firmware) the
2342 * device driver has read access to the EEPROM by way of indirect addressing
2343 * through a couple of memory mapped registers.
2345 * The following is a simplified implementation for pulling data out of the
2346 * the eeprom, along with some helper functions to find information in
2347 * the per device private data's copy of the eeprom.
2349 * NOTE: To better understand how these functions work (i.e what is a chip
2350 * select and why do have to keep driving the eeprom clock?), read
2351 * just about any data sheet for a Microwire compatible EEPROM.
2354 /* write a 32 bit value into the indirect accessor register */
2355 static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2357 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
2359 /* the eeprom requires some time to complete the operation */
2360 udelay(p->eeprom_delay);
2365 /* perform a chip select operation */
2366 static void eeprom_cs(struct ipw_priv *priv)
2368 eeprom_write_reg(priv, 0);
2369 eeprom_write_reg(priv, EEPROM_BIT_CS);
2370 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2371 eeprom_write_reg(priv, EEPROM_BIT_CS);
2374 /* perform a chip select operation */
2375 static void eeprom_disable_cs(struct ipw_priv *priv)
2377 eeprom_write_reg(priv, EEPROM_BIT_CS);
2378 eeprom_write_reg(priv, 0);
2379 eeprom_write_reg(priv, EEPROM_BIT_SK);
2382 /* push a single bit down to the eeprom */
2383 static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
2385 int d = (bit ? EEPROM_BIT_DI : 0);
2386 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2387 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
2390 /* push an opcode followed by an address down to the eeprom */
2391 static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
2396 eeprom_write_bit(priv, 1);
2397 eeprom_write_bit(priv, op & 2);
2398 eeprom_write_bit(priv, op & 1);
2399 for (i = 7; i >= 0; i--) {
2400 eeprom_write_bit(priv, addr & (1 << i));
2404 /* pull 16 bits off the eeprom, one bit at a time */
2405 static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
2410 /* Send READ Opcode */
2411 eeprom_op(priv, EEPROM_CMD_READ, addr);
2413 /* Send dummy bit */
2414 eeprom_write_reg(priv, EEPROM_BIT_CS);
2416 /* Read the byte off the eeprom one bit at a time */
2417 for (i = 0; i < 16; i++) {
2419 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2420 eeprom_write_reg(priv, EEPROM_BIT_CS);
2421 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2422 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
2425 /* Send another dummy bit */
2426 eeprom_write_reg(priv, 0);
2427 eeprom_disable_cs(priv);
2432 /* helper function for pulling the mac address out of the private */
2433 /* data's copy of the eeprom data */
2434 static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
2436 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
2440 * Either the device driver (i.e. the host) or the firmware can
2441 * load eeprom data into the designated region in SRAM. If neither
2442 * happens then the FW will shutdown with a fatal error.
2444 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2445 * bit needs region of shared SRAM needs to be non-zero.
2447 static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2450 u16 *eeprom = (u16 *) priv->eeprom;
2452 IPW_DEBUG_TRACE(">>\n");
2454 /* read entire contents of eeprom into private buffer */
2455 for (i = 0; i < 128; i++)
2456 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
2459 If the data looks correct, then copy it to our private
2460 copy. Otherwise let the firmware know to perform the operation
2463 if (priv->eeprom[EEPROM_VERSION] != 0) {
2464 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2466 /* write the eeprom data to sram */
2467 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
2468 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
2470 /* Do not load eeprom data on fatal error or suspend */
2471 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2473 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2475 /* Load eeprom data on fatal error or suspend */
2476 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2479 IPW_DEBUG_TRACE("<<\n");
2482 static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
2487 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
2489 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
2492 static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2494 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
2495 CB_NUMBER_OF_ELEMENTS_SMALL *
2496 sizeof(struct command_block));
2499 static int ipw_fw_dma_enable(struct ipw_priv *priv)
2500 { /* start dma engine but no transfers yet */
2502 IPW_DEBUG_FW(">> : \n");
2505 ipw_fw_dma_reset_command_blocks(priv);
2507 /* Write CB base address */
2508 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
2510 IPW_DEBUG_FW("<< : \n");
2514 static void ipw_fw_dma_abort(struct ipw_priv *priv)
2518 IPW_DEBUG_FW(">> :\n");
2520 //set the Stop and Abort bit
2521 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
2522 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2523 priv->sram_desc.last_cb_index = 0;
2525 IPW_DEBUG_FW("<< \n");
2528 static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2529 struct command_block *cb)
2532 IPW_SHARED_SRAM_DMA_CONTROL +
2533 (sizeof(struct command_block) * index);
2534 IPW_DEBUG_FW(">> :\n");
2536 ipw_write_indirect(priv, address, (u8 *) cb,
2537 (int)sizeof(struct command_block));
2539 IPW_DEBUG_FW("<< :\n");
2544 static int ipw_fw_dma_kick(struct ipw_priv *priv)
2549 IPW_DEBUG_FW(">> :\n");
2551 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
2552 ipw_fw_dma_write_command_block(priv, index,
2553 &priv->sram_desc.cb_list[index]);
2555 /* Enable the DMA in the CSR register */
2556 ipw_clear_bit(priv, IPW_RESET_REG,
2557 IPW_RESET_REG_MASTER_DISABLED |
2558 IPW_RESET_REG_STOP_MASTER);
2560 /* Set the Start bit. */
2561 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
2562 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2564 IPW_DEBUG_FW("<< :\n");
2568 static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2571 u32 register_value = 0;
2572 u32 cb_fields_address = 0;
2574 IPW_DEBUG_FW(">> :\n");
2575 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2576 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
2578 /* Read the DMA Controlor register */
2579 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2580 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
2582 /* Print the CB values */
2583 cb_fields_address = address;
2584 register_value = ipw_read_reg32(priv, cb_fields_address);
2585 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
2587 cb_fields_address += sizeof(u32);
2588 register_value = ipw_read_reg32(priv, cb_fields_address);
2589 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
2591 cb_fields_address += sizeof(u32);
2592 register_value = ipw_read_reg32(priv, cb_fields_address);
2593 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2596 cb_fields_address += sizeof(u32);
2597 register_value = ipw_read_reg32(priv, cb_fields_address);
2598 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
2600 IPW_DEBUG_FW(">> :\n");
2603 static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2605 u32 current_cb_address = 0;
2606 u32 current_cb_index = 0;
2608 IPW_DEBUG_FW("<< :\n");
2609 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2611 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
2612 sizeof(struct command_block);
2614 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
2615 current_cb_index, current_cb_address);
2617 IPW_DEBUG_FW(">> :\n");
2618 return current_cb_index;
2622 static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2626 int interrupt_enabled, int is_last)
2629 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
2630 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2632 struct command_block *cb;
2633 u32 last_cb_element = 0;
2635 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2636 src_address, dest_address, length);
2638 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2641 last_cb_element = priv->sram_desc.last_cb_index;
2642 cb = &priv->sram_desc.cb_list[last_cb_element];
2643 priv->sram_desc.last_cb_index++;
2645 /* Calculate the new CB control word */
2646 if (interrupt_enabled)
2647 control |= CB_INT_ENABLED;
2650 control |= CB_LAST_VALID;
2654 /* Calculate the CB Element's checksum value */
2655 cb->status = control ^ src_address ^ dest_address;
2657 /* Copy the Source and Destination addresses */
2658 cb->dest_addr = dest_address;
2659 cb->source_addr = src_address;
2661 /* Copy the Control Word last */
2662 cb->control = control;
2667 static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
2668 u32 src_phys, u32 dest_address, u32 length)
2670 u32 bytes_left = length;
2672 u32 dest_offset = 0;
2674 IPW_DEBUG_FW(">> \n");
2675 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2676 src_phys, dest_address, length);
2677 while (bytes_left > CB_MAX_LENGTH) {
2678 status = ipw_fw_dma_add_command_block(priv,
2679 src_phys + src_offset,
2682 CB_MAX_LENGTH, 0, 0);
2684 IPW_DEBUG_FW_INFO(": Failed\n");
2687 IPW_DEBUG_FW_INFO(": Added new cb\n");
2689 src_offset += CB_MAX_LENGTH;
2690 dest_offset += CB_MAX_LENGTH;
2691 bytes_left -= CB_MAX_LENGTH;
2694 /* add the buffer tail */
2695 if (bytes_left > 0) {
2697 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2698 dest_address + dest_offset,
2701 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2705 (": Adding new cb - the buffer tail\n");
2708 IPW_DEBUG_FW("<< \n");
2712 static int ipw_fw_dma_wait(struct ipw_priv *priv)
2714 u32 current_index = 0, previous_index;
2717 IPW_DEBUG_FW(">> : \n");
2719 current_index = ipw_fw_dma_command_block_index(priv);
2720 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
2721 (int)priv->sram_desc.last_cb_index);
2723 while (current_index < priv->sram_desc.last_cb_index) {
2725 previous_index = current_index;
2726 current_index = ipw_fw_dma_command_block_index(priv);
2728 if (previous_index < current_index) {
2732 if (++watchdog > 400) {
2733 IPW_DEBUG_FW_INFO("Timeout\n");
2734 ipw_fw_dma_dump_command_block(priv);
2735 ipw_fw_dma_abort(priv);
2740 ipw_fw_dma_abort(priv);
2742 /*Disable the DMA in the CSR register */
2743 ipw_set_bit(priv, IPW_RESET_REG,
2744 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
2746 IPW_DEBUG_FW("<< dmaWaitSync \n");
2750 static void ipw_remove_current_network(struct ipw_priv *priv)
2752 struct list_head *element, *safe;
2753 struct ieee80211_network *network = NULL;
2754 unsigned long flags;
2756 spin_lock_irqsave(&priv->ieee->lock, flags);
2757 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2758 network = list_entry(element, struct ieee80211_network, list);
2759 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2761 list_add_tail(&network->list,
2762 &priv->ieee->network_free_list);
2765 spin_unlock_irqrestore(&priv->ieee->lock, flags);
2769 * Check that card is still alive.
2770 * Reads debug register from domain0.
2771 * If card is present, pre-defined value should
2775 * @return 1 if card is present, 0 otherwise
2777 static inline int ipw_alive(struct ipw_priv *priv)
2779 return ipw_read32(priv, 0x90) == 0xd55555d5;
2782 /* timeout in msec, attempted in 10-msec quanta */
2783 static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2789 if ((ipw_read32(priv, addr) & mask) == mask)
2793 } while (i < timeout);
2798 /* These functions load the firmware and micro code for the operation of
2799 * the ipw hardware. It assumes the buffer has all the bits for the
2800 * image and the caller is handling the memory allocation and clean up.
2803 static int ipw_stop_master(struct ipw_priv *priv)
2807 IPW_DEBUG_TRACE(">> \n");
2808 /* stop master. typical delay - 0 */
2809 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
2811 /* timeout is in msec, polled in 10-msec quanta */
2812 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2813 IPW_RESET_REG_MASTER_DISABLED, 100);
2815 IPW_ERROR("wait for stop master failed after 100ms\n");
2819 IPW_DEBUG_INFO("stop master %dms\n", rc);
2824 static void ipw_arc_release(struct ipw_priv *priv)
2826 IPW_DEBUG_TRACE(">> \n");
2829 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
2831 /* no one knows timing, for safety add some delay */
2840 static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
2842 int rc = 0, i, addr;
2846 image = (u16 *) data;
2848 IPW_DEBUG_TRACE(">> \n");
2850 rc = ipw_stop_master(priv);
2855 // spin_lock_irqsave(&priv->lock, flags);
2857 for (addr = IPW_SHARED_LOWER_BOUND;
2858 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
2859 ipw_write32(priv, addr, 0);
2862 /* no ucode (yet) */
2863 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2864 /* destroy DMA queues */
2865 /* reset sequence */
2867 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
2868 ipw_arc_release(priv);
2869 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
2873 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
2876 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
2879 /* enable ucode store */
2880 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
2881 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
2887 * Do NOT set indirect address register once and then
2888 * store data to indirect data register in the loop.
2889 * It seems very reasonable, but in this case DINO do not
2890 * accept ucode. It is essential to set address each time.
2892 /* load new ipw uCode */
2893 for (i = 0; i < len / 2; i++)
2894 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
2895 cpu_to_le16(image[i]));
2898 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2899 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
2901 /* this is where the igx / win driver deveates from the VAP driver. */
2903 /* wait for alive response */
2904 for (i = 0; i < 100; i++) {
2905 /* poll for incoming data */
2906 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
2907 if (cr & DINO_RXFIFO_DATA)
2912 if (cr & DINO_RXFIFO_DATA) {
2913 /* alive_command_responce size is NOT multiple of 4 */
2914 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
2916 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
2917 response_buffer[i] =
2918 le32_to_cpu(ipw_read_reg32(priv,
2919 IPW_BASEBAND_RX_FIFO_READ));
2920 memcpy(&priv->dino_alive, response_buffer,
2921 sizeof(priv->dino_alive));
2922 if (priv->dino_alive.alive_command == 1
2923 && priv->dino_alive.ucode_valid == 1) {
2926 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2927 "of %02d/%02d/%02d %02d:%02d\n",
2928 priv->dino_alive.software_revision,
2929 priv->dino_alive.software_revision,
2930 priv->dino_alive.device_identifier,
2931 priv->dino_alive.device_identifier,
2932 priv->dino_alive.time_stamp[0],
2933 priv->dino_alive.time_stamp[1],
2934 priv->dino_alive.time_stamp[2],
2935 priv->dino_alive.time_stamp[3],
2936 priv->dino_alive.time_stamp[4]);
2938 IPW_DEBUG_INFO("Microcode is not alive\n");
2942 IPW_DEBUG_INFO("No alive response from DINO\n");
2946 /* disable DINO, otherwise for some reason
2947 firmware have problem getting alive resp. */
2948 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2950 // spin_unlock_irqrestore(&priv->lock, flags);
2955 static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
2959 struct fw_chunk *chunk;
2960 dma_addr_t shared_phys;
2963 IPW_DEBUG_TRACE("<< : \n");
2964 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
2969 memmove(shared_virt, data, len);
2972 rc = ipw_fw_dma_enable(priv);
2974 if (priv->sram_desc.last_cb_index > 0) {
2975 /* the DMA is already ready this would be a bug. */
2981 chunk = (struct fw_chunk *)(data + offset);
2982 offset += sizeof(struct fw_chunk);
2983 /* build DMA packet and queue up for sending */
2984 /* dma to chunk->address, the chunk->length bytes from data +
2987 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
2988 le32_to_cpu(chunk->address),
2989 le32_to_cpu(chunk->length));
2991 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
2995 offset += le32_to_cpu(chunk->length);
2996 } while (offset < len);
2998 /* Run the DMA and wait for the answer */
2999 rc = ipw_fw_dma_kick(priv);
3001 IPW_ERROR("dmaKick Failed\n");
3005 rc = ipw_fw_dma_wait(priv);
3007 IPW_ERROR("dmaWaitSync Failed\n");
3011 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
3016 static int ipw_stop_nic(struct ipw_priv *priv)
3021 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
3023 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3024 IPW_RESET_REG_MASTER_DISABLED, 500);
3026 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
3030 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
3035 static void ipw_start_nic(struct ipw_priv *priv)
3037 IPW_DEBUG_TRACE(">>\n");
3039 /* prvHwStartNic release ARC */
3040 ipw_clear_bit(priv, IPW_RESET_REG,
3041 IPW_RESET_REG_MASTER_DISABLED |
3042 IPW_RESET_REG_STOP_MASTER |
3043 CBD_RESET_REG_PRINCETON_RESET);
3045 /* enable power management */
3046 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3047 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
3049 IPW_DEBUG_TRACE("<<\n");
3052 static int ipw_init_nic(struct ipw_priv *priv)
3056 IPW_DEBUG_TRACE(">>\n");
3059 /* set "initialization complete" bit to move adapter to D0 state */
3060 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3062 /* low-level PLL activation */
3063 ipw_write32(priv, IPW_READ_INT_REGISTER,
3064 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
3066 /* wait for clock stabilization */
3067 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3068 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
3070 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3072 /* assert SW reset */
3073 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
3077 /* set "initialization complete" bit to move adapter to D0 state */
3078 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3080 IPW_DEBUG_TRACE(">>\n");
3084 /* Call this function from process context, it will sleep in request_firmware.
3085 * Probe is an ok place to call this from.
3087 static int ipw_reset_nic(struct ipw_priv *priv)
3090 unsigned long flags;
3092 IPW_DEBUG_TRACE(">>\n");
3094 rc = ipw_init_nic(priv);
3096 spin_lock_irqsave(&priv->lock, flags);
3097 /* Clear the 'host command active' bit... */
3098 priv->status &= ~STATUS_HCMD_ACTIVE;
3099 wake_up_interruptible(&priv->wait_command_queue);
3100 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3101 wake_up_interruptible(&priv->wait_state);
3102 spin_unlock_irqrestore(&priv->lock, flags);
3104 IPW_DEBUG_TRACE("<<\n");
3117 static int ipw_get_fw(struct ipw_priv *priv,
3118 const struct firmware **raw, const char *name)
3123 /* ask firmware_class module to get the boot firmware off disk */
3124 rc = request_firmware(raw, name, &priv->pci_dev->dev);
3126 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
3130 if ((*raw)->size < sizeof(*fw)) {
3131 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
3135 fw = (void *)(*raw)->data;
3137 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3138 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
3139 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3140 name, (*raw)->size);
3144 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
3146 le32_to_cpu(fw->ver) >> 16,
3147 le32_to_cpu(fw->ver) & 0xff,
3148 (*raw)->size - sizeof(*fw));
3152 #define IPW_RX_BUF_SIZE (3000)
3154 static void ipw_rx_queue_reset(struct ipw_priv *priv,
3155 struct ipw_rx_queue *rxq)
3157 unsigned long flags;
3160 spin_lock_irqsave(&rxq->lock, flags);
3162 INIT_LIST_HEAD(&rxq->rx_free);
3163 INIT_LIST_HEAD(&rxq->rx_used);
3165 /* Fill the rx_used queue with _all_ of the Rx buffers */
3166 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3167 /* In the reset function, these buffers may have been allocated
3168 * to an SKB, so we need to unmap and free potential storage */
3169 if (rxq->pool[i].skb != NULL) {
3170 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
3171 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
3172 dev_kfree_skb(rxq->pool[i].skb);
3173 rxq->pool[i].skb = NULL;
3175 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3178 /* Set us so that we have processed and used all buffers, but have
3179 * not restocked the Rx queue with fresh buffers */
3180 rxq->read = rxq->write = 0;
3181 rxq->processed = RX_QUEUE_SIZE - 1;
3182 rxq->free_count = 0;
3183 spin_unlock_irqrestore(&rxq->lock, flags);
3187 static int fw_loaded = 0;
3188 static const struct firmware *raw = NULL;
3190 static void free_firmware(void)
3193 release_firmware(raw);
3199 #define free_firmware() do {} while (0)
3202 static int ipw_load(struct ipw_priv *priv)
3205 const struct firmware *raw = NULL;
3208 u8 *boot_img, *ucode_img, *fw_img;
3210 int rc = 0, retries = 3;
3212 switch (priv->ieee->iw_mode) {
3214 name = "ipw2200-ibss.fw";
3216 #ifdef CONFIG_IPW2200_MONITOR
3217 case IW_MODE_MONITOR:
3218 name = "ipw2200-sniffer.fw";
3222 name = "ipw2200-bss.fw";
3234 rc = ipw_get_fw(priv, &raw, name);
3241 fw = (void *)raw->data;
3242 boot_img = &fw->data[0];
3243 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3244 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3245 le32_to_cpu(fw->ucode_size)];
3251 priv->rxq = ipw_rx_queue_alloc(priv);
3253 ipw_rx_queue_reset(priv, priv->rxq);
3255 IPW_ERROR("Unable to initialize Rx queue\n");
3260 /* Ensure interrupts are disabled */
3261 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3262 priv->status &= ~STATUS_INT_ENABLED;
3264 /* ack pending interrupts */
3265 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3269 rc = ipw_reset_nic(priv);
3271 IPW_ERROR("Unable to reset NIC\n");
3275 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3276 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
3278 /* DMA the initial boot firmware into the device */
3279 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
3281 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
3285 /* kick start the device */
3286 ipw_start_nic(priv);
3288 /* wait for the device to finish its initial startup sequence */
3289 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3290 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3292 IPW_ERROR("device failed to boot initial fw image\n");
3295 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3297 /* ack fw init done interrupt */
3298 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3300 /* DMA the ucode into the device */
3301 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
3303 IPW_ERROR("Unable to load ucode: %d\n", rc);
3310 /* DMA bss firmware into the device */
3311 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
3313 IPW_ERROR("Unable to load firmware: %d\n", rc);
3320 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3322 rc = ipw_queue_reset(priv);
3324 IPW_ERROR("Unable to initialize queues\n");
3328 /* Ensure interrupts are disabled */
3329 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3330 /* ack pending interrupts */
3331 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3333 /* kick start the device */
3334 ipw_start_nic(priv);
3336 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
3338 IPW_WARNING("Parity error. Retrying init.\n");
3343 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3348 /* wait for the device */
3349 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3350 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3352 IPW_ERROR("device failed to start within 500ms\n");
3355 IPW_DEBUG_INFO("device response after %dms\n", rc);
3357 /* ack fw init done interrupt */
3358 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3360 /* read eeprom data and initialize the eeprom region of sram */
3361 priv->eeprom_delay = 1;
3362 ipw_eeprom_init_sram(priv);
3364 /* enable interrupts */
3365 ipw_enable_interrupts(priv);
3367 /* Ensure our queue has valid packets */
3368 ipw_rx_queue_replenish(priv);
3370 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
3372 /* ack pending interrupts */
3373 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3376 release_firmware(raw);
3382 ipw_rx_queue_free(priv, priv->rxq);
3385 ipw_tx_queue_free(priv);
3387 release_firmware(raw);
3399 * Theory of operation
3401 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3402 * 2 empty entries always kept in the buffer to protect from overflow.
3404 * For Tx queue, there are low mark and high mark limits. If, after queuing
3405 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3406 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
3409 * The IPW operates with six queues, one receive queue in the device's
3410 * sram, one transmit queue for sending commands to the device firmware,
3411 * and four transmit queues for data.
3413 * The four transmit queues allow for performing quality of service (qos)
3414 * transmissions as per the 802.11 protocol. Currently Linux does not
3415 * provide a mechanism to the user for utilizing prioritized queues, so
3416 * we only utilize the first data transmit queue (queue1).
3420 * Driver allocates buffers of this size for Rx
3423 static inline int ipw_queue_space(const struct clx2_queue *q)
3425 int s = q->last_used - q->first_empty;
3428 s -= 2; /* keep some reserve to not confuse empty and full situations */
3434 static inline int ipw_queue_inc_wrap(int index, int n_bd)
3436 return (++index == n_bd) ? 0 : index;
3440 * Initialize common DMA queue structure
3442 * @param q queue to init
3443 * @param count Number of BD's to allocate. Should be power of 2
3444 * @param read_register Address for 'read' register
3445 * (not offset within BAR, full address)
3446 * @param write_register Address for 'write' register
3447 * (not offset within BAR, full address)
3448 * @param base_register Address for 'base' register
3449 * (not offset within BAR, full address)
3450 * @param size Address for 'size' register
3451 * (not offset within BAR, full address)
3453 static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
3454 int count, u32 read, u32 write, u32 base, u32 size)
3458 q->low_mark = q->n_bd / 4;
3459 if (q->low_mark < 4)
3462 q->high_mark = q->n_bd / 8;
3463 if (q->high_mark < 2)
3466 q->first_empty = q->last_used = 0;
3470 ipw_write32(priv, base, q->dma_addr);
3471 ipw_write32(priv, size, count);
3472 ipw_write32(priv, read, 0);
3473 ipw_write32(priv, write, 0);
3475 _ipw_read32(priv, 0x90);
3478 static int ipw_queue_tx_init(struct ipw_priv *priv,
3479 struct clx2_tx_queue *q,
3480 int count, u32 read, u32 write, u32 base, u32 size)
3482 struct pci_dev *dev = priv->pci_dev;
3484 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3486 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3491 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
3493 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
3494 sizeof(q->bd[0]) * count);
3500 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3505 * Free one TFD, those at index [txq->q.last_used].
3506 * Do NOT advance any indexes
3511 static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3512 struct clx2_tx_queue *txq)
3514 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3515 struct pci_dev *dev = priv->pci_dev;
3519 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3520 /* nothing to cleanup after for host commands */
3524 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3525 IPW_ERROR("Too many chunks: %i\n",
3526 le32_to_cpu(bd->u.data.num_chunks));
3527 /** @todo issue fatal error, it is quite serious situation */
3531 /* unmap chunks if any */
3532 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3533 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3534 le16_to_cpu(bd->u.data.chunk_len[i]),
3536 if (txq->txb[txq->q.last_used]) {
3537 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3538 txq->txb[txq->q.last_used] = NULL;
3544 * Deallocate DMA queue.
3546 * Empty queue by removing and destroying all BD's.
3552 static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
3554 struct clx2_queue *q = &txq->q;
3555 struct pci_dev *dev = priv->pci_dev;
3560 /* first, empty all BD's */
3561 for (; q->first_empty != q->last_used;
3562 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3563 ipw_queue_tx_free_tfd(priv, txq);
3566 /* free buffers belonging to queue itself */
3567 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
3571 /* 0 fill whole structure */
3572 memset(txq, 0, sizeof(*txq));
3576 * Destroy all DMA queues and structures
3580 static void ipw_tx_queue_free(struct ipw_priv *priv)
3583 ipw_queue_tx_free(priv, &priv->txq_cmd);
3586 ipw_queue_tx_free(priv, &priv->txq[0]);
3587 ipw_queue_tx_free(priv, &priv->txq[1]);
3588 ipw_queue_tx_free(priv, &priv->txq[2]);
3589 ipw_queue_tx_free(priv, &priv->txq[3]);
3592 static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
3594 /* First 3 bytes are manufacturer */
3595 bssid[0] = priv->mac_addr[0];
3596 bssid[1] = priv->mac_addr[1];
3597 bssid[2] = priv->mac_addr[2];
3599 /* Last bytes are random */
3600 get_random_bytes(&bssid[3], ETH_ALEN - 3);
3602 bssid[0] &= 0xfe; /* clear multicast bit */
3603 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
3606 static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
3608 struct ipw_station_entry entry;
3611 for (i = 0; i < priv->num_stations; i++) {
3612 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3613 /* Another node is active in network */
3614 priv->missed_adhoc_beacons = 0;
3615 if (!(priv->config & CFG_STATIC_CHANNEL))
3616 /* when other nodes drop out, we drop out */
3617 priv->config &= ~CFG_ADHOC_PERSIST;
3623 if (i == MAX_STATIONS)
3624 return IPW_INVALID_STATION;
3626 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3629 entry.support_mode = 0;
3630 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3631 memcpy(priv->stations[i], bssid, ETH_ALEN);
3632 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
3633 &entry, sizeof(entry));
3634 priv->num_stations++;
3639 static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
3643 for (i = 0; i < priv->num_stations; i++)
3644 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
3647 return IPW_INVALID_STATION;
3650 static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3654 if (priv->status & STATUS_ASSOCIATING) {
3655 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3656 queue_work(priv->workqueue, &priv->disassociate);
3660 if (!(priv->status & STATUS_ASSOCIATED)) {
3661 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3665 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3667 MAC_ARG(priv->assoc_request.bssid),
3668 priv->assoc_request.channel);
3670 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3671 priv->status |= STATUS_DISASSOCIATING;
3674 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3676 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
3678 err = ipw_send_associate(priv, &priv->assoc_request);
3680 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3687 static int ipw_disassociate(void *data)
3689 struct ipw_priv *priv = data;
3690 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3692 ipw_send_disassociate(data, 0);
3696 static void ipw_bg_disassociate(void *data)
3698 struct ipw_priv *priv = data;
3699 mutex_lock(&priv->mutex);
3700 ipw_disassociate(data);
3701 mutex_unlock(&priv->mutex);
3704 static void ipw_system_config(void *data)
3706 struct ipw_priv *priv = data;
3707 ipw_send_system_config(priv, &priv->sys_config);
3710 struct ipw_status_code {
3715 static const struct ipw_status_code ipw_status_codes[] = {
3716 {0x00, "Successful"},
3717 {0x01, "Unspecified failure"},
3718 {0x0A, "Cannot support all requested capabilities in the "
3719 "Capability information field"},
3720 {0x0B, "Reassociation denied due to inability to confirm that "
3721 "association exists"},
3722 {0x0C, "Association denied due to reason outside the scope of this "
3725 "Responding station does not support the specified authentication "
3728 "Received an Authentication frame with authentication sequence "
3729 "transaction sequence number out of expected sequence"},
3730 {0x0F, "Authentication rejected because of challenge failure"},
3731 {0x10, "Authentication rejected due to timeout waiting for next "
3732 "frame in sequence"},
3733 {0x11, "Association denied because AP is unable to handle additional "
3734 "associated stations"},
3736 "Association denied due to requesting station not supporting all "
3737 "of the datarates in the BSSBasicServiceSet Parameter"},
3739 "Association denied due to requesting station not supporting "
3740 "short preamble operation"},
3742 "Association denied due to requesting station not supporting "
3745 "Association denied due to requesting station not supporting "
3748 "Association denied due to requesting station not supporting "
3749 "short slot operation"},
3751 "Association denied due to requesting station not supporting "
3752 "DSSS-OFDM operation"},
3753 {0x28, "Invalid Information Element"},
3754 {0x29, "Group Cipher is not valid"},
3755 {0x2A, "Pairwise Cipher is not valid"},
3756 {0x2B, "AKMP is not valid"},
3757 {0x2C, "Unsupported RSN IE version"},
3758 {0x2D, "Invalid RSN IE Capabilities"},
3759 {0x2E, "Cipher suite is rejected per security policy"},
3762 #ifdef CONFIG_IPW2200_DEBUG
3763 static const char *ipw_get_status_code(u16 status)
3766 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
3767 if (ipw_status_codes[i].status == (status & 0xff))
3768 return ipw_status_codes[i].reason;
3769 return "Unknown status value.";
3773 static void inline average_init(struct average *avg)
3775 memset(avg, 0, sizeof(*avg));
3778 #define DEPTH_RSSI 8
3779 #define DEPTH_NOISE 16
3780 static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
3782 return ((depth-1)*prev_avg + val)/depth;
3785 static void average_add(struct average *avg, s16 val)
3787 avg->sum -= avg->entries[avg->pos];
3789 avg->entries[avg->pos++] = val;
3790 if (unlikely(avg->pos == AVG_ENTRIES)) {
3796 static s16 average_value(struct average *avg)
3798 if (!unlikely(avg->init)) {
3800 return avg->sum / avg->pos;
3804 return avg->sum / AVG_ENTRIES;
3807 static void ipw_reset_stats(struct ipw_priv *priv)
3809 u32 len = sizeof(u32);
3813 average_init(&priv->average_missed_beacons);
3814 priv->exp_avg_rssi = -60;
3815 priv->exp_avg_noise = -85 + 0x100;
3817 priv->last_rate = 0;
3818 priv->last_missed_beacons = 0;
3819 priv->last_rx_packets = 0;
3820 priv->last_tx_packets = 0;
3821 priv->last_tx_failures = 0;
3823 /* Firmware managed, reset only when NIC is restarted, so we have to
3824 * normalize on the current value */
3825 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
3826 &priv->last_rx_err, &len);
3827 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
3828 &priv->last_tx_failures, &len);
3830 /* Driver managed, reset with each association */
3831 priv->missed_adhoc_beacons = 0;
3832 priv->missed_beacons = 0;
3833 priv->tx_packets = 0;
3834 priv->rx_packets = 0;
3838 static u32 ipw_get_max_rate(struct ipw_priv *priv)
3841 u32 mask = priv->rates_mask;
3842 /* If currently associated in B mode, restrict the maximum
3843 * rate match to B rates */
3844 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3845 mask &= IEEE80211_CCK_RATES_MASK;
3847 /* TODO: Verify that the rate is supported by the current rates
3850 while (i && !(mask & i))
3853 case IEEE80211_CCK_RATE_1MB_MASK:
3855 case IEEE80211_CCK_RATE_2MB_MASK:
3857 case IEEE80211_CCK_RATE_5MB_MASK:
3859 case IEEE80211_OFDM_RATE_6MB_MASK:
3861 case IEEE80211_OFDM_RATE_9MB_MASK:
3863 case IEEE80211_CCK_RATE_11MB_MASK:
3865 case IEEE80211_OFDM_RATE_12MB_MASK:
3867 case IEEE80211_OFDM_RATE_18MB_MASK:
3869 case IEEE80211_OFDM_RATE_24MB_MASK:
3871 case IEEE80211_OFDM_RATE_36MB_MASK:
3873 case IEEE80211_OFDM_RATE_48MB_MASK:
3875 case IEEE80211_OFDM_RATE_54MB_MASK:
3879 if (priv->ieee->mode == IEEE_B)
3885 static u32 ipw_get_current_rate(struct ipw_priv *priv)
3887 u32 rate, len = sizeof(rate);
3890 if (!(priv->status & STATUS_ASSOCIATED))
3893 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
3894 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
3897 IPW_DEBUG_INFO("failed querying ordinals.\n");
3901 return ipw_get_max_rate(priv);
3904 case IPW_TX_RATE_1MB:
3906 case IPW_TX_RATE_2MB:
3908 case IPW_TX_RATE_5MB:
3910 case IPW_TX_RATE_6MB:
3912 case IPW_TX_RATE_9MB:
3914 case IPW_TX_RATE_11MB:
3916 case IPW_TX_RATE_12MB:
3918 case IPW_TX_RATE_18MB:
3920 case IPW_TX_RATE_24MB:
3922 case IPW_TX_RATE_36MB:
3924 case IPW_TX_RATE_48MB:
3926 case IPW_TX_RATE_54MB:
3933 #define IPW_STATS_INTERVAL (2 * HZ)
3934 static void ipw_gather_stats(struct ipw_priv *priv)
3936 u32 rx_err, rx_err_delta, rx_packets_delta;
3937 u32 tx_failures, tx_failures_delta, tx_packets_delta;
3938 u32 missed_beacons_percent, missed_beacons_delta;
3940 u32 len = sizeof(u32);
3942 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
3946 if (!(priv->status & STATUS_ASSOCIATED)) {
3951 /* Update the statistics */
3952 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
3953 &priv->missed_beacons, &len);
3954 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
3955 priv->last_missed_beacons = priv->missed_beacons;
3956 if (priv->assoc_request.beacon_interval) {
3957 missed_beacons_percent = missed_beacons_delta *
3958 (HZ * priv->assoc_request.beacon_interval) /
3959 (IPW_STATS_INTERVAL * 10);
3961 missed_beacons_percent = 0;
3963 average_add(&priv->average_missed_beacons, missed_beacons_percent);
3965 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
3966 rx_err_delta = rx_err - priv->last_rx_err;
3967 priv->last_rx_err = rx_err;
3969 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
3970 tx_failures_delta = tx_failures - priv->last_tx_failures;
3971 priv->last_tx_failures = tx_failures;
3973 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
3974 priv->last_rx_packets = priv->rx_packets;
3976 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
3977 priv->last_tx_packets = priv->tx_packets;
3979 /* Calculate quality based on the following:
3981 * Missed beacon: 100% = 0, 0% = 70% missed
3982 * Rate: 60% = 1Mbs, 100% = Max
3983 * Rx and Tx errors represent a straight % of total Rx/Tx
3984 * RSSI: 100% = > -50, 0% = < -80
3985 * Rx errors: 100% = 0, 0% = 50% missed
3987 * The lowest computed quality is used.
3990 #define BEACON_THRESHOLD 5
3991 beacon_quality = 100 - missed_beacons_percent;
3992 if (beacon_quality < BEACON_THRESHOLD)
3995 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
3996 (100 - BEACON_THRESHOLD);
3997 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
3998 beacon_quality, missed_beacons_percent);
4000 priv->last_rate = ipw_get_current_rate(priv);
4001 max_rate = ipw_get_max_rate(priv);
4002 rate_quality = priv->last_rate * 40 / max_rate + 60;
4003 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4004 rate_quality, priv->last_rate / 1000000);
4006 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
4007 rx_quality = 100 - (rx_err_delta * 100) /
4008 (rx_packets_delta + rx_err_delta);
4011 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4012 rx_quality, rx_err_delta, rx_packets_delta);
4014 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
4015 tx_quality = 100 - (tx_failures_delta * 100) /
4016 (tx_packets_delta + tx_failures_delta);
4019 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4020 tx_quality, tx_failures_delta, tx_packets_delta);
4022 rssi = priv->exp_avg_rssi;
4025 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4026 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4027 (priv->ieee->perfect_rssi - rssi) *
4028 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4029 62 * (priv->ieee->perfect_rssi - rssi))) /
4030 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4031 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4032 if (signal_quality > 100)
4033 signal_quality = 100;
4034 else if (signal_quality < 1)
4037 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
4038 signal_quality, rssi);
4040 quality = min(beacon_quality,
4042 min(tx_quality, min(rx_quality, signal_quality))));
4043 if (quality == beacon_quality)
4044 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4046 if (quality == rate_quality)
4047 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4049 if (quality == tx_quality)
4050 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4052 if (quality == rx_quality)
4053 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4055 if (quality == signal_quality)
4056 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4059 priv->quality = quality;
4061 queue_delayed_work(priv->workqueue, &priv->gather_stats,
4062 IPW_STATS_INTERVAL);
4065 static void ipw_bg_gather_stats(void *data)
4067 struct ipw_priv *priv = data;
4068 mutex_lock(&priv->mutex);
4069 ipw_gather_stats(data);
4070 mutex_unlock(&priv->mutex);
4073 /* Missed beacon behavior:
4074 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4075 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4076 * Above disassociate threshold, give up and stop scanning.
4077 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
4078 static void ipw_handle_missed_beacon(struct ipw_priv *priv,
4081 priv->notif_missed_beacons = missed_count;
4083 if (missed_count > priv->disassociate_threshold &&
4084 priv->status & STATUS_ASSOCIATED) {
4085 /* If associated and we've hit the missed
4086 * beacon threshold, disassociate, turn
4087 * off roaming, and abort any active scans */
4088 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4089 IPW_DL_STATE | IPW_DL_ASSOC,
4090 "Missed beacon: %d - disassociate\n", missed_count);
4091 priv->status &= ~STATUS_ROAMING;
4092 if (priv->status & STATUS_SCANNING) {
4093 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4095 "Aborting scan with missed beacon.\n");
4096 queue_work(priv->workqueue, &priv->abort_scan);
4099 queue_work(priv->workqueue, &priv->disassociate);
4103 if (priv->status & STATUS_ROAMING) {
4104 /* If we are currently roaming, then just
4105 * print a debug statement... */
4106 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4107 "Missed beacon: %d - roam in progress\n",
4113 (missed_count > priv->roaming_threshold &&
4114 missed_count <= priv->disassociate_threshold)) {
4115 /* If we are not already roaming, set the ROAM
4116 * bit in the status and kick off a scan.
4117 * This can happen several times before we reach
4118 * disassociate_threshold. */
4119 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4120 "Missed beacon: %d - initiate "
4121 "roaming\n", missed_count);
4122 if (!(priv->status & STATUS_ROAMING)) {
4123 priv->status |= STATUS_ROAMING;
4124 if (!(priv->status & STATUS_SCANNING))
4125 queue_work(priv->workqueue,
4126 &priv->request_scan);
4131 if (priv->status & STATUS_SCANNING) {
4132 /* Stop scan to keep fw from getting
4133 * stuck (only if we aren't roaming --
4134 * otherwise we'll never scan more than 2 or 3
4136 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4137 "Aborting scan with missed beacon.\n");
4138 queue_work(priv->workqueue, &priv->abort_scan);
4141 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
4145 * Handle host notification packet.
4146 * Called from interrupt routine
4148 static void ipw_rx_notification(struct ipw_priv *priv,
4149 struct ipw_rx_notification *notif)
4151 notif->size = le16_to_cpu(notif->size);
4153 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
4155 switch (notif->subtype) {
4156 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4157 struct notif_association *assoc = ¬if->u.assoc;
4159 switch (assoc->state) {
4160 case CMAS_ASSOCIATED:{
4161 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4163 "associated: '%s' " MAC_FMT
4165 escape_essid(priv->essid,
4167 MAC_ARG(priv->bssid));
4169 switch (priv->ieee->iw_mode) {
4171 memcpy(priv->ieee->bssid,
4172 priv->bssid, ETH_ALEN);
4176 memcpy(priv->ieee->bssid,
4177 priv->bssid, ETH_ALEN);
4179 /* clear out the station table */
4180 priv->num_stations = 0;
4183 ("queueing adhoc check\n");
4184 queue_delayed_work(priv->
4194 priv->status &= ~STATUS_ASSOCIATING;
4195 priv->status |= STATUS_ASSOCIATED;
4196 queue_work(priv->workqueue,
4197 &priv->system_config);
4199 #ifdef CONFIG_IPW_QOS
4200 #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4201 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4202 if ((priv->status & STATUS_AUTH) &&
4203 (IPW_GET_PACKET_STYPE(¬if->u.raw)
4204 == IEEE80211_STYPE_ASSOC_RESP)) {
4207 ieee80211_assoc_response)
4209 && (notif->size <= 2314)) {
4222 ieee80211_rx_mgt(priv->
4227 ¬if->u.raw, &stats);
4232 schedule_work(&priv->link_up);
4237 case CMAS_AUTHENTICATED:{
4239 status & (STATUS_ASSOCIATED |
4241 #ifdef CONFIG_IPW2200_DEBUG
4242 struct notif_authenticate *auth
4244 IPW_DEBUG(IPW_DL_NOTIF |
4247 "deauthenticated: '%s' "
4249 ": (0x%04X) - %s \n",
4254 MAC_ARG(priv->bssid),
4255 ntohs(auth->status),
4262 ~(STATUS_ASSOCIATING |
4266 schedule_work(&priv->link_down);
4270 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4272 "authenticated: '%s' " MAC_FMT
4274 escape_essid(priv->essid,
4276 MAC_ARG(priv->bssid));
4281 if (priv->status & STATUS_AUTH) {
4283 ieee80211_assoc_response
4287 ieee80211_assoc_response
4289 IPW_DEBUG(IPW_DL_NOTIF |
4292 "association failed (0x%04X): %s\n",
4293 ntohs(resp->status),
4299 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4301 "disassociated: '%s' " MAC_FMT
4303 escape_essid(priv->essid,
4305 MAC_ARG(priv->bssid));
4308 ~(STATUS_DISASSOCIATING |
4309 STATUS_ASSOCIATING |
4310 STATUS_ASSOCIATED | STATUS_AUTH);
4311 if (priv->assoc_network
4312 && (priv->assoc_network->
4314 WLAN_CAPABILITY_IBSS))
4315 ipw_remove_current_network
4318 schedule_work(&priv->link_down);
4323 case CMAS_RX_ASSOC_RESP:
4327 IPW_ERROR("assoc: unknown (%d)\n",
4335 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4336 struct notif_authenticate *auth = ¬if->u.auth;
4337 switch (auth->state) {
4338 case CMAS_AUTHENTICATED:
4339 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4340 "authenticated: '%s' " MAC_FMT " \n",
4341 escape_essid(priv->essid,
4343 MAC_ARG(priv->bssid));
4344 priv->status |= STATUS_AUTH;
4348 if (priv->status & STATUS_AUTH) {
4349 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4351 "authentication failed (0x%04X): %s\n",
4352 ntohs(auth->status),
4353 ipw_get_status_code(ntohs
4357 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4359 "deauthenticated: '%s' " MAC_FMT "\n",
4360 escape_essid(priv->essid,
4362 MAC_ARG(priv->bssid));
4364 priv->status &= ~(STATUS_ASSOCIATING |
4368 schedule_work(&priv->link_down);
4371 case CMAS_TX_AUTH_SEQ_1:
4372 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4373 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4375 case CMAS_RX_AUTH_SEQ_2:
4376 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4377 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4379 case CMAS_AUTH_SEQ_1_PASS:
4380 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4381 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4383 case CMAS_AUTH_SEQ_1_FAIL:
4384 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4385 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4387 case CMAS_TX_AUTH_SEQ_3:
4388 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4389 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4391 case CMAS_RX_AUTH_SEQ_4:
4392 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4393 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4395 case CMAS_AUTH_SEQ_2_PASS:
4396 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4397 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4399 case CMAS_AUTH_SEQ_2_FAIL:
4400 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4401 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4404 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4405 IPW_DL_ASSOC, "TX_ASSOC\n");
4407 case CMAS_RX_ASSOC_RESP:
4408 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4409 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
4412 case CMAS_ASSOCIATED:
4413 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4414 IPW_DL_ASSOC, "ASSOCIATED\n");
4417 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4424 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4425 struct notif_channel_result *x =
4426 ¬if->u.channel_result;
4428 if (notif->size == sizeof(*x)) {
4429 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4432 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4433 "(should be %zd)\n",
4434 notif->size, sizeof(*x));
4439 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4440 struct notif_scan_complete *x = ¬if->u.scan_complete;
4441 if (notif->size == sizeof(*x)) {
4443 ("Scan completed: type %d, %d channels, "
4444 "%d status\n", x->scan_type,
4445 x->num_channels, x->status);
4447 IPW_ERROR("Scan completed of wrong size %d "
4448 "(should be %zd)\n",
4449 notif->size, sizeof(*x));
4453 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4455 wake_up_interruptible(&priv->wait_state);
4456 cancel_delayed_work(&priv->scan_check);
4458 if (priv->status & STATUS_EXIT_PENDING)
4461 priv->ieee->scans++;
4463 #ifdef CONFIG_IPW2200_MONITOR
4464 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
4465 priv->status |= STATUS_SCAN_FORCED;
4466 queue_work(priv->workqueue,
4467 &priv->request_scan);
4470 priv->status &= ~STATUS_SCAN_FORCED;
4471 #endif /* CONFIG_IPW2200_MONITOR */
4473 if (!(priv->status & (STATUS_ASSOCIATED |
4474 STATUS_ASSOCIATING |
4476 STATUS_DISASSOCIATING)))
4477 queue_work(priv->workqueue, &priv->associate);
4478 else if (priv->status & STATUS_ROAMING) {
4479 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4480 /* If a scan completed and we are in roam mode, then
4481 * the scan that completed was the one requested as a
4482 * result of entering roam... so, schedule the
4484 queue_work(priv->workqueue,
4487 /* Don't schedule if we aborted the scan */
4488 priv->status &= ~STATUS_ROAMING;
4489 } else if (priv->status & STATUS_SCAN_PENDING)
4490 queue_work(priv->workqueue,
4491 &priv->request_scan);
4492 else if (priv->config & CFG_BACKGROUND_SCAN
4493 && priv->status & STATUS_ASSOCIATED)
4494 queue_delayed_work(priv->workqueue,
4495 &priv->request_scan, HZ);
4497 /* Send an empty event to user space.
4498 * We don't send the received data on the event because
4499 * it would require us to do complex transcoding, and
4500 * we want to minimise the work done in the irq handler
4501 * Use a request to extract the data.
4502 * Also, we generate this even for any scan, regardless
4503 * on how the scan was initiated. User space can just
4504 * sync on periodic scan to get fresh data...
4506 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) {
4507 union iwreq_data wrqu;
4509 wrqu.data.length = 0;
4510 wrqu.data.flags = 0;
4511 wireless_send_event(priv->net_dev, SIOCGIWSCAN,
4517 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4518 struct notif_frag_length *x = ¬if->u.frag_len;
4520 if (notif->size == sizeof(*x))
4521 IPW_ERROR("Frag length: %d\n",
4522 le16_to_cpu(x->frag_length));
4524 IPW_ERROR("Frag length of wrong size %d "
4525 "(should be %zd)\n",
4526 notif->size, sizeof(*x));
4530 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4531 struct notif_link_deterioration *x =
4532 ¬if->u.link_deterioration;
4534 if (notif->size == sizeof(*x)) {
4535 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4536 "link deterioration: type %d, cnt %d\n",
4537 x->silence_notification_type,
4539 memcpy(&priv->last_link_deterioration, x,
4542 IPW_ERROR("Link Deterioration of wrong size %d "
4543 "(should be %zd)\n",
4544 notif->size, sizeof(*x));
4549 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4550 IPW_ERROR("Dino config\n");
4552 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
4553 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
4558 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4559 struct notif_beacon_state *x = ¬if->u.beacon_state;
4560 if (notif->size != sizeof(*x)) {
4562 ("Beacon state of wrong size %d (should "
4563 "be %zd)\n", notif->size, sizeof(*x));
4567 if (le32_to_cpu(x->state) ==
4568 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4569 ipw_handle_missed_beacon(priv,
4576 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4577 struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key;
4578 if (notif->size == sizeof(*x)) {
4579 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4580 "0x%02x station %d\n",
4581 x->key_state, x->security_type,
4587 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4588 notif->size, sizeof(*x));
4592 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4593 struct notif_calibration *x = ¬if->u.calibration;
4595 if (notif->size == sizeof(*x)) {
4596 memcpy(&priv->calib, x, sizeof(*x));
4597 IPW_DEBUG_INFO("TODO: Calibration\n");
4602 ("Calibration of wrong size %d (should be %zd)\n",
4603 notif->size, sizeof(*x));
4607 case HOST_NOTIFICATION_NOISE_STATS:{
4608 if (notif->size == sizeof(u32)) {
4609 priv->exp_avg_noise =
4610 exponential_average(priv->exp_avg_noise,
4611 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4617 ("Noise stat is wrong size %d (should be %zd)\n",
4618 notif->size, sizeof(u32));
4623 IPW_DEBUG_NOTIF("Unknown notification: "
4624 "subtype=%d,flags=0x%2x,size=%d\n",
4625 notif->subtype, notif->flags, notif->size);
4630 * Destroys all DMA structures and initialise them again
4633 * @return error code
4635 static int ipw_queue_reset(struct ipw_priv *priv)
4638 /** @todo customize queue sizes */
4639 int nTx = 64, nTxCmd = 8;
4640 ipw_tx_queue_free(priv);
4642 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
4643 IPW_TX_CMD_QUEUE_READ_INDEX,
4644 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4645 IPW_TX_CMD_QUEUE_BD_BASE,
4646 IPW_TX_CMD_QUEUE_BD_SIZE);
4648 IPW_ERROR("Tx Cmd queue init failed\n");
4652 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
4653 IPW_TX_QUEUE_0_READ_INDEX,
4654 IPW_TX_QUEUE_0_WRITE_INDEX,
4655 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
4657 IPW_ERROR("Tx 0 queue init failed\n");
4660 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
4661 IPW_TX_QUEUE_1_READ_INDEX,
4662 IPW_TX_QUEUE_1_WRITE_INDEX,
4663 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
4665 IPW_ERROR("Tx 1 queue init failed\n");
4668 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
4669 IPW_TX_QUEUE_2_READ_INDEX,
4670 IPW_TX_QUEUE_2_WRITE_INDEX,
4671 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
4673 IPW_ERROR("Tx 2 queue init failed\n");
4676 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
4677 IPW_TX_QUEUE_3_READ_INDEX,
4678 IPW_TX_QUEUE_3_WRITE_INDEX,
4679 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
4681 IPW_ERROR("Tx 3 queue init failed\n");
4685 priv->rx_bufs_min = 0;
4686 priv->rx_pend_max = 0;
4690 ipw_tx_queue_free(priv);
4695 * Reclaim Tx queue entries no more used by NIC.
4697 * When FW adwances 'R' index, all entries between old and
4698 * new 'R' index need to be reclaimed. As result, some free space
4699 * forms. If there is enough free space (> low mark), wake Tx queue.
4701 * @note Need to protect against garbage in 'R' index
4705 * @return Number of used entries remains in the queue
4707 static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
4708 struct clx2_tx_queue *txq, int qindex)
4712 struct clx2_queue *q = &txq->q;
4714 hw_tail = ipw_read32(priv, q->reg_r);
4715 if (hw_tail >= q->n_bd) {
4717 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4721 for (; q->last_used != hw_tail;
4722 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4723 ipw_queue_tx_free_tfd(priv, txq);
4727 if ((ipw_queue_space(q) > q->low_mark) &&
4729 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4730 netif_wake_queue(priv->net_dev);
4731 used = q->first_empty - q->last_used;
4738 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4741 struct clx2_tx_queue *txq = &priv->txq_cmd;
4742 struct clx2_queue *q = &txq->q;
4743 struct tfd_frame *tfd;
4745 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4746 IPW_ERROR("No space for Tx\n");
4750 tfd = &txq->bd[q->first_empty];
4751 txq->txb[q->first_empty] = NULL;
4753 memset(tfd, 0, sizeof(*tfd));
4754 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4755 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4757 tfd->u.cmd.index = hcmd;
4758 tfd->u.cmd.length = len;
4759 memcpy(tfd->u.cmd.payload, buf, len);
4760 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4761 ipw_write32(priv, q->reg_w, q->first_empty);
4762 _ipw_read32(priv, 0x90);
4768 * Rx theory of operation
4770 * The host allocates 32 DMA target addresses and passes the host address
4771 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
4775 * The host/firmware share two index registers for managing the Rx buffers.
4777 * The READ index maps to the first position that the firmware may be writing
4778 * to -- the driver can read up to (but not including) this position and get
4780 * The READ index is managed by the firmware once the card is enabled.
4782 * The WRITE index maps to the last position the driver has read from -- the
4783 * position preceding WRITE is the last slot the firmware can place a packet.
4785 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
4788 * During initialization the host sets up the READ queue position to the first
4789 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4791 * When the firmware places a packet in a buffer it will advance the READ index
4792 * and fire the RX interrupt. The driver can then query the READ index and
4793 * process as many packets as possible, moving the WRITE index forward as it
4794 * resets the Rx queue buffers with new memory.
4796 * The management in the driver is as follows:
4797 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
4798 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
4799 * to replensish the ipw->rxq->rx_free.
4800 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4801 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4802 * 'processed' and 'read' driver indexes as well)
4803 * + A received packet is processed and handed to the kernel network stack,
4804 * detached from the ipw->rxq. The driver 'processed' index is updated.
4805 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
4806 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4807 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
4808 * were enough free buffers and RX_STALLED is set it is cleared.
4813 * ipw_rx_queue_alloc() Allocates rx_free
4814 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4815 * ipw_rx_queue_restock
4816 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4817 * queue, updates firmware pointers, and updates
4818 * the WRITE index. If insufficient rx_free buffers
4819 * are available, schedules ipw_rx_queue_replenish
4821 * -- enable interrupts --
4822 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
4823 * READ INDEX, detaching the SKB from the pool.
4824 * Moves the packet buffer from queue to rx_used.
4825 * Calls ipw_rx_queue_restock to refill any empty
4832 * If there are slots in the RX queue that need to be restocked,
4833 * and we have free pre-allocated buffers, fill the ranks as much
4834 * as we can pulling from rx_free.
4836 * This moves the 'write' index forward to catch up with 'processed', and
4837 * also updates the memory address in the firmware to reference the new
4840 static void ipw_rx_queue_restock(struct ipw_priv *priv)
4842 struct ipw_rx_queue *rxq = priv->rxq;
4843 struct list_head *element;
4844 struct ipw_rx_mem_buffer *rxb;
4845 unsigned long flags;
4848 spin_lock_irqsave(&rxq->lock, flags);
4850 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4851 element = rxq->rx_free.next;
4852 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4855 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
4857 rxq->queue[rxq->write] = rxb;
4858 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4861 spin_unlock_irqrestore(&rxq->lock, flags);
4863 /* If the pre-allocated buffer pool is dropping low, schedule to
4865 if (rxq->free_count <= RX_LOW_WATERMARK)
4866 queue_work(priv->workqueue, &priv->rx_replenish);
4868 /* If we've added more space for the firmware to place data, tell it */
4869 if (write != rxq->write)
4870 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
4874 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
4875 * Also restock the Rx queue via ipw_rx_queue_restock.
4877 * This is called as a scheduled work item (except for during intialization)
4879 static void ipw_rx_queue_replenish(void *data)
4881 struct ipw_priv *priv = data;
4882 struct ipw_rx_queue *rxq = priv->rxq;
4883 struct list_head *element;
4884 struct ipw_rx_mem_buffer *rxb;
4885 unsigned long flags;
4887 spin_lock_irqsave(&rxq->lock, flags);
4888 while (!list_empty(&rxq->rx_used)) {
4889 element = rxq->rx_used.next;
4890 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4891 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
4893 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
4894 priv->net_dev->name);
4895 /* We don't reschedule replenish work here -- we will
4896 * call the restock method and if it still needs
4897 * more buffers it will schedule replenish */
4902 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
4904 pci_map_single(priv->pci_dev, rxb->skb->data,
4905 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4907 list_add_tail(&rxb->list, &rxq->rx_free);
4910 spin_unlock_irqrestore(&rxq->lock, flags);
4912 ipw_rx_queue_restock(priv);
4915 static void ipw_bg_rx_queue_replenish(void *data)
4917 struct ipw_priv *priv = data;
4918 mutex_lock(&priv->mutex);
4919 ipw_rx_queue_replenish(data);
4920 mutex_unlock(&priv->mutex);
4923 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4924 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
4925 * This free routine walks the list of POOL entries and if SKB is set to
4926 * non NULL it is unmapped and freed
4928 static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
4935 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4936 if (rxq->pool[i].skb != NULL) {
4937 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
4938 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4939 dev_kfree_skb(rxq->pool[i].skb);
4946 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4948 struct ipw_rx_queue *rxq;
4951 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
4952 if (unlikely(!rxq)) {
4953 IPW_ERROR("memory allocation failed\n");
4956 spin_lock_init(&rxq->lock);
4957 INIT_LIST_HEAD(&rxq->rx_free);
4958 INIT_LIST_HEAD(&rxq->rx_used);
4960 /* Fill the rx_used queue with _all_ of the Rx buffers */
4961 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
4962 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4964 /* Set us so that we have processed and used all buffers, but have
4965 * not restocked the Rx queue with fresh buffers */
4966 rxq->read = rxq->write = 0;
4967 rxq->processed = RX_QUEUE_SIZE - 1;
4968 rxq->free_count = 0;
4973 static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
4975 rate &= ~IEEE80211_BASIC_RATE_MASK;
4976 if (ieee_mode == IEEE_A) {
4978 case IEEE80211_OFDM_RATE_6MB:
4979 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
4981 case IEEE80211_OFDM_RATE_9MB:
4982 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
4984 case IEEE80211_OFDM_RATE_12MB:
4986 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
4987 case IEEE80211_OFDM_RATE_18MB:
4989 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
4990 case IEEE80211_OFDM_RATE_24MB:
4992 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
4993 case IEEE80211_OFDM_RATE_36MB:
4995 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
4996 case IEEE80211_OFDM_RATE_48MB:
4998 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
4999 case IEEE80211_OFDM_RATE_54MB:
5001 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5009 case IEEE80211_CCK_RATE_1MB:
5010 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
5011 case IEEE80211_CCK_RATE_2MB:
5012 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
5013 case IEEE80211_CCK_RATE_5MB:
5014 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
5015 case IEEE80211_CCK_RATE_11MB:
5016 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
5019 /* If we are limited to B modulations, bail at this point */
5020 if (ieee_mode == IEEE_B)
5025 case IEEE80211_OFDM_RATE_6MB:
5026 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
5027 case IEEE80211_OFDM_RATE_9MB:
5028 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
5029 case IEEE80211_OFDM_RATE_12MB:
5030 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
5031 case IEEE80211_OFDM_RATE_18MB:
5032 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
5033 case IEEE80211_OFDM_RATE_24MB:
5034 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
5035 case IEEE80211_OFDM_RATE_36MB:
5036 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
5037 case IEEE80211_OFDM_RATE_48MB:
5038 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
5039 case IEEE80211_OFDM_RATE_54MB:
5040 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5046 static int ipw_compatible_rates(struct ipw_priv *priv,
5047 const struct ieee80211_network *network,
5048 struct ipw_supported_rates *rates)
5052 memset(rates, 0, sizeof(*rates));
5053 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
5054 rates->num_rates = 0;
5055 for (i = 0; i < num_rates; i++) {
5056 if (!ipw_is_rate_in_mask(priv, network->mode,
5057 network->rates[i])) {
5059 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
5060 IPW_DEBUG_SCAN("Adding masked mandatory "
5063 rates->supported_rates[rates->num_rates++] =
5068 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5069 network->rates[i], priv->rates_mask);
5073 rates->supported_rates[rates->num_rates++] = network->rates[i];
5076 num_rates = min(network->rates_ex_len,
5077 (u8) (IPW_MAX_RATES - num_rates));
5078 for (i = 0; i < num_rates; i++) {
5079 if (!ipw_is_rate_in_mask(priv, network->mode,
5080 network->rates_ex[i])) {
5081 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
5082 IPW_DEBUG_SCAN("Adding masked mandatory "
5084 network->rates_ex[i]);
5085 rates->supported_rates[rates->num_rates++] =
5090 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5091 network->rates_ex[i], priv->rates_mask);
5095 rates->supported_rates[rates->num_rates++] =
5096 network->rates_ex[i];
5102 static void ipw_copy_rates(struct ipw_supported_rates *dest,
5103 const struct ipw_supported_rates *src)
5106 for (i = 0; i < src->num_rates; i++)
5107 dest->supported_rates[i] = src->supported_rates[i];
5108 dest->num_rates = src->num_rates;
5111 /* TODO: Look at sniffed packets in the air to determine if the basic rate
5112 * mask should ever be used -- right now all callers to add the scan rates are
5113 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5114 static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
5115 u8 modulation, u32 rate_mask)
5117 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
5118 IEEE80211_BASIC_RATE_MASK : 0;
5120 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
5121 rates->supported_rates[rates->num_rates++] =
5122 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
5124 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
5125 rates->supported_rates[rates->num_rates++] =
5126 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
5128 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
5129 rates->supported_rates[rates->num_rates++] = basic_mask |
5130 IEEE80211_CCK_RATE_5MB;
5132 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
5133 rates->supported_rates[rates->num_rates++] = basic_mask |
5134 IEEE80211_CCK_RATE_11MB;
5137 static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
5138 u8 modulation, u32 rate_mask)
5140 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
5141 IEEE80211_BASIC_RATE_MASK : 0;
5143 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
5144 rates->supported_rates[rates->num_rates++] = basic_mask |
5145 IEEE80211_OFDM_RATE_6MB;
5147 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
5148 rates->supported_rates[rates->num_rates++] =
5149 IEEE80211_OFDM_RATE_9MB;
5151 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
5152 rates->supported_rates[rates->num_rates++] = basic_mask |
5153 IEEE80211_OFDM_RATE_12MB;
5155 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
5156 rates->supported_rates[rates->num_rates++] =
5157 IEEE80211_OFDM_RATE_18MB;
5159 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
5160 rates->supported_rates[rates->num_rates++] = basic_mask |
5161 IEEE80211_OFDM_RATE_24MB;
5163 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
5164 rates->supported_rates[rates->num_rates++] =
5165 IEEE80211_OFDM_RATE_36MB;
5167 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
5168 rates->supported_rates[rates->num_rates++] =
5169 IEEE80211_OFDM_RATE_48MB;
5171 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
5172 rates->supported_rates[rates->num_rates++] =
5173 IEEE80211_OFDM_RATE_54MB;
5176 struct ipw_network_match {
5177 struct ieee80211_network *network;
5178 struct ipw_supported_rates rates;
5181 static int ipw_find_adhoc_network(struct ipw_priv *priv,
5182 struct ipw_network_match *match,
5183 struct ieee80211_network *network,
5186 struct ipw_supported_rates rates;
5188 /* Verify that this network's capability is compatible with the
5189 * current mode (AdHoc or Infrastructure) */
5190 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5191 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5192 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5193 "capability mismatch.\n",
5194 escape_essid(network->ssid, network->ssid_len),
5195 MAC_ARG(network->bssid));
5199 /* If we do not have an ESSID for this AP, we can not associate with
5201 if (network->flags & NETWORK_EMPTY_ESSID) {
5202 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5203 "because of hidden ESSID.\n",
5204 escape_essid(network->ssid, network->ssid_len),
5205 MAC_ARG(network->bssid));
5209 if (unlikely(roaming)) {
5210 /* If we are roaming, then ensure check if this is a valid
5211 * network to try and roam to */
5212 if ((network->ssid_len != match->network->ssid_len) ||
5213 memcmp(network->ssid, match->network->ssid,
5214 network->ssid_len)) {
5215 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5216 "because of non-network ESSID.\n",
5217 escape_essid(network->ssid,
5219 MAC_ARG(network->bssid));
5223 /* If an ESSID has been configured then compare the broadcast
5225 if ((priv->config & CFG_STATIC_ESSID) &&
5226 ((network->ssid_len != priv->essid_len) ||
5227 memcmp(network->ssid, priv->essid,
5228 min(network->ssid_len, priv->essid_len)))) {
5229 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5232 escape_essid(network->ssid, network->ssid_len),
5234 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5235 "because of ESSID mismatch: '%s'.\n",
5236 escaped, MAC_ARG(network->bssid),
5237 escape_essid(priv->essid,
5243 /* If the old network rate is better than this one, don't bother
5244 * testing everything else. */
5246 if (network->time_stamp[0] < match->network->time_stamp[0]) {
5247 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5248 "current network.\n",
5249 escape_essid(match->network->ssid,
5250 match->network->ssid_len));
5252 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
5253 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5254 "current network.\n",
5255 escape_essid(match->network->ssid,
5256 match->network->ssid_len));
5260 /* Now go through and see if the requested network is valid... */
5261 if (priv->ieee->scan_age != 0 &&
5262 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5263 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5264 "because of age: %ums.\n",
5265 escape_essid(network->ssid, network->ssid_len),
5266 MAC_ARG(network->bssid),
5267 jiffies_to_msecs(jiffies -
5268 network->last_scanned));
5272 if ((priv->config & CFG_STATIC_CHANNEL) &&
5273 (network->channel != priv->channel)) {
5274 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5275 "because of channel mismatch: %d != %d.\n",
5276 escape_essid(network->ssid, network->ssid_len),
5277 MAC_ARG(network->bssid),
5278 network->channel, priv->channel);
5282 /* Verify privacy compatability */
5283 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5284 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5285 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5286 "because of privacy mismatch: %s != %s.\n",
5287 escape_essid(network->ssid, network->ssid_len),
5288 MAC_ARG(network->bssid),
5290 capability & CAP_PRIVACY_ON ? "on" : "off",
5292 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5297 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5298 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5299 "because of the same BSSID match: " MAC_FMT
5300 ".\n", escape_essid(network->ssid,
5302 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5306 /* Filter out any incompatible freq / mode combinations */
5307 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5308 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5309 "because of invalid frequency/mode "
5311 escape_essid(network->ssid, network->ssid_len),
5312 MAC_ARG(network->bssid));
5316 /* Ensure that the rates supported by the driver are compatible with
5317 * this AP, including verification of basic rates (mandatory) */
5318 if (!ipw_compatible_rates(priv, network, &rates)) {
5319 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5320 "because configured rate mask excludes "
5321 "AP mandatory rate.\n",
5322 escape_essid(network->ssid, network->ssid_len),
5323 MAC_ARG(network->bssid));
5327 if (rates.num_rates == 0) {
5328 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5329 "because of no compatible rates.\n",
5330 escape_essid(network->ssid, network->ssid_len),
5331 MAC_ARG(network->bssid));
5335 /* TODO: Perform any further minimal comparititive tests. We do not
5336 * want to put too much policy logic here; intelligent scan selection
5337 * should occur within a generic IEEE 802.11 user space tool. */
5339 /* Set up 'new' AP to this network */
5340 ipw_copy_rates(&match->rates, &rates);
5341 match->network = network;
5342 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5343 escape_essid(network->ssid, network->ssid_len),
5344 MAC_ARG(network->bssid));
5349 static void ipw_merge_adhoc_network(void *data)
5351 struct ipw_priv *priv = data;
5352 struct ieee80211_network *network = NULL;
5353 struct ipw_network_match match = {
5354 .network = priv->assoc_network
5357 if ((priv->status & STATUS_ASSOCIATED) &&
5358 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5359 /* First pass through ROAM process -- look for a better
5361 unsigned long flags;
5363 spin_lock_irqsave(&priv->ieee->lock, flags);
5364 list_for_each_entry(network, &priv->ieee->network_list, list) {
5365 if (network != priv->assoc_network)
5366 ipw_find_adhoc_network(priv, &match, network,
5369 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5371 if (match.network == priv->assoc_network) {
5372 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5377 mutex_lock(&priv->mutex);
5378 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5379 IPW_DEBUG_MERGE("remove network %s\n",
5380 escape_essid(priv->essid,
5382 ipw_remove_current_network(priv);
5385 ipw_disassociate(priv);
5386 priv->assoc_network = match.network;
5387 mutex_unlock(&priv->mutex);
5392 static int ipw_best_network(struct ipw_priv *priv,
5393 struct ipw_network_match *match,
5394 struct ieee80211_network *network, int roaming)
5396 struct ipw_supported_rates rates;
5398 /* Verify that this network's capability is compatible with the
5399 * current mode (AdHoc or Infrastructure) */
5400 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
5401 !(network->capability & WLAN_CAPABILITY_ESS)) ||
5402 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5403 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5404 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
5405 "capability mismatch.\n",
5406 escape_essid(network->ssid, network->ssid_len),
5407 MAC_ARG(network->bssid));
5411 /* If we do not have an ESSID for this AP, we can not associate with
5413 if (network->flags & NETWORK_EMPTY_ESSID) {
5414 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5415 "because of hidden ESSID.\n",
5416 escape_essid(network->ssid, network->ssid_len),
5417 MAC_ARG(network->bssid));
5421 if (unlikely(roaming)) {
5422 /* If we are roaming, then ensure check if this is a valid
5423 * network to try and roam to */
5424 if ((network->ssid_len != match->network->ssid_len) ||
5425 memcmp(network->ssid, match->network->ssid,
5426 network->ssid_len)) {
5427 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5428 "because of non-network ESSID.\n",
5429 escape_essid(network->ssid,
5431 MAC_ARG(network->bssid));
5435 /* If an ESSID has been configured then compare the broadcast
5437 if ((priv->config & CFG_STATIC_ESSID) &&
5438 ((network->ssid_len != priv->essid_len) ||
5439 memcmp(network->ssid, priv->essid,
5440 min(network->ssid_len, priv->essid_len)))) {
5441 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5443 escape_essid(network->ssid, network->ssid_len),
5445 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5446 "because of ESSID mismatch: '%s'.\n",
5447 escaped, MAC_ARG(network->bssid),
5448 escape_essid(priv->essid,
5454 /* If the old network rate is better than this one, don't bother
5455 * testing everything else. */
5456 if (match->network && match->network->stats.rssi > network->stats.rssi) {
5457 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5459 escape_essid(network->ssid, network->ssid_len),
5461 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5462 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5463 escaped, MAC_ARG(network->bssid),
5464 escape_essid(match->network->ssid,
5465 match->network->ssid_len),
5466 MAC_ARG(match->network->bssid));
5470 /* If this network has already had an association attempt within the
5471 * last 3 seconds, do not try and associate again... */
5472 if (network->last_associate &&
5473 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
5474 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5475 "because of storming (%ums since last "
5476 "assoc attempt).\n",
5477 escape_essid(network->ssid, network->ssid_len),
5478 MAC_ARG(network->bssid),
5479 jiffies_to_msecs(jiffies -
5480 network->last_associate));
5484 /* Now go through and see if the requested network is valid... */
5485 if (priv->ieee->scan_age != 0 &&
5486 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5487 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5488 "because of age: %ums.\n",
5489 escape_essid(network->ssid, network->ssid_len),
5490 MAC_ARG(network->bssid),
5491 jiffies_to_msecs(jiffies -
5492 network->last_scanned));
5496 if ((priv->config & CFG_STATIC_CHANNEL) &&
5497 (network->channel != priv->channel)) {
5498 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5499 "because of channel mismatch: %d != %d.\n",
5500 escape_essid(network->ssid, network->ssid_len),
5501 MAC_ARG(network->bssid),
5502 network->channel, priv->channel);
5506 /* Verify privacy compatability */
5507 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5508 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5509 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5510 "because of privacy mismatch: %s != %s.\n",
5511 escape_essid(network->ssid, network->ssid_len),
5512 MAC_ARG(network->bssid),
5513 priv->capability & CAP_PRIVACY_ON ? "on" :
5515 network->capability &
5516 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
5520 if ((priv->config & CFG_STATIC_BSSID) &&
5521 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5522 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5523 "because of BSSID mismatch: " MAC_FMT ".\n",
5524 escape_essid(network->ssid, network->ssid_len),
5525 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5529 /* Filter out any incompatible freq / mode combinations */
5530 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5531 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5532 "because of invalid frequency/mode "
5534 escape_essid(network->ssid, network->ssid_len),
5535 MAC_ARG(network->bssid));
5539 /* Filter out invalid channel in current GEO */
5540 if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) {
5541 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5542 "because of invalid channel in current GEO\n",
5543 escape_essid(network->ssid, network->ssid_len),
5544 MAC_ARG(network->bssid));
5548 /* Ensure that the rates supported by the driver are compatible with
5549 * this AP, including verification of basic rates (mandatory) */
5550 if (!ipw_compatible_rates(priv, network, &rates)) {
5551 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5552 "because configured rate mask excludes "
5553 "AP mandatory rate.\n",
5554 escape_essid(network->ssid, network->ssid_len),
5555 MAC_ARG(network->bssid));
5559 if (rates.num_rates == 0) {
5560 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5561 "because of no compatible rates.\n",
5562 escape_essid(network->ssid, network->ssid_len),
5563 MAC_ARG(network->bssid));
5567 /* TODO: Perform any further minimal comparititive tests. We do not
5568 * want to put too much policy logic here; intelligent scan selection
5569 * should occur within a generic IEEE 802.11 user space tool. */
5571 /* Set up 'new' AP to this network */
5572 ipw_copy_rates(&match->rates, &rates);
5573 match->network = network;
5575 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5576 escape_essid(network->ssid, network->ssid_len),
5577 MAC_ARG(network->bssid));
5582 static void ipw_adhoc_create(struct ipw_priv *priv,
5583 struct ieee80211_network *network)
5585 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
5589 * For the purposes of scanning, we can set our wireless mode
5590 * to trigger scans across combinations of bands, but when it
5591 * comes to creating a new ad-hoc network, we have tell the FW
5592 * exactly which band to use.
5594 * We also have the possibility of an invalid channel for the
5595 * chossen band. Attempting to create a new ad-hoc network
5596 * with an invalid channel for wireless mode will trigger a
5600 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
5601 case IEEE80211_52GHZ_BAND:
5602 network->mode = IEEE_A;
5603 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
5605 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5606 IPW_WARNING("Overriding invalid channel\n");
5607 priv->channel = geo->a[0].channel;
5611 case IEEE80211_24GHZ_BAND:
5612 if (priv->ieee->mode & IEEE_G)
5613 network->mode = IEEE_G;
5615 network->mode = IEEE_B;
5616 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
5618 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5619 IPW_WARNING("Overriding invalid channel\n");
5620 priv->channel = geo->bg[0].channel;
5625 IPW_WARNING("Overriding invalid channel\n");
5626 if (priv->ieee->mode & IEEE_A) {
5627 network->mode = IEEE_A;
5628 priv->channel = geo->a[0].channel;
5629 } else if (priv->ieee->mode & IEEE_G) {
5630 network->mode = IEEE_G;
5631 priv->channel = geo->bg[0].channel;
5633 network->mode = IEEE_B;
5634 priv->channel = geo->bg[0].channel;
5639 network->channel = priv->channel;
5640 priv->config |= CFG_ADHOC_PERSIST;
5641 ipw_create_bssid(priv, network->bssid);
5642 network->ssid_len = priv->essid_len;
5643 memcpy(network->ssid, priv->essid, priv->essid_len);
5644 memset(&network->stats, 0, sizeof(network->stats));
5645 network->capability = WLAN_CAPABILITY_IBSS;
5646 if (!(priv->config & CFG_PREAMBLE_LONG))
5647 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
5648 if (priv->capability & CAP_PRIVACY_ON)
5649 network->capability |= WLAN_CAPABILITY_PRIVACY;
5650 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
5651 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
5652 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
5653 memcpy(network->rates_ex,
5654 &priv->rates.supported_rates[network->rates_len],
5655 network->rates_ex_len);
5656 network->last_scanned = 0;
5658 network->last_associate = 0;
5659 network->time_stamp[0] = 0;
5660 network->time_stamp[1] = 0;
5661 network->beacon_interval = 100; /* Default */
5662 network->listen_interval = 10; /* Default */
5663 network->atim_window = 0; /* Default */
5664 network->wpa_ie_len = 0;
5665 network->rsn_ie_len = 0;
5668 static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5670 struct ipw_tgi_tx_key key;
5672 if (!(priv->ieee->sec.flags & (1 << index)))
5676 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5677 key.security_type = type;
5678 key.station_index = 0; /* always 0 for BSS */
5680 /* 0 for new key; previous value of counter (after fatal error) */
5681 key.tx_counter[0] = 0;
5682 key.tx_counter[1] = 0;
5684 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
5687 static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
5689 struct ipw_wep_key key;
5692 key.cmd_id = DINO_CMD_WEP_KEY;
5695 /* Note: AES keys cannot be set for multiple times.
5696 * Only set it at the first time. */
5697 for (i = 0; i < 4; i++) {
5698 key.key_index = i | type;
5699 if (!(priv->ieee->sec.flags & (1 << i))) {
5704 key.key_size = priv->ieee->sec.key_sizes[i];
5705 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
5707 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
5711 static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5713 if (priv->ieee->host_encrypt)
5718 priv->sys_config.disable_unicast_decryption = 0;
5719 priv->ieee->host_decrypt = 0;
5722 priv->sys_config.disable_unicast_decryption = 1;
5723 priv->ieee->host_decrypt = 1;
5726 priv->sys_config.disable_unicast_decryption = 0;
5727 priv->ieee->host_decrypt = 0;
5730 priv->sys_config.disable_unicast_decryption = 1;
5737 static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5739 if (priv->ieee->host_encrypt)
5744 priv->sys_config.disable_multicast_decryption = 0;
5747 priv->sys_config.disable_multicast_decryption = 1;
5750 priv->sys_config.disable_multicast_decryption = 0;
5753 priv->sys_config.disable_multicast_decryption = 1;
5760 static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5762 switch (priv->ieee->sec.level) {
5764 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5765 ipw_send_tgi_tx_key(priv,
5766 DCT_FLAG_EXT_SECURITY_CCM,
5767 priv->ieee->sec.active_key);
5769 if (!priv->ieee->host_mc_decrypt)
5770 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
5773 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5774 ipw_send_tgi_tx_key(priv,
5775 DCT_FLAG_EXT_SECURITY_TKIP,
5776 priv->ieee->sec.active_key);
5779 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
5780 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5781 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
5789 static void ipw_adhoc_check(void *data)
5791 struct ipw_priv *priv = data;
5793 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
5794 !(priv->config & CFG_ADHOC_PERSIST)) {
5795 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5796 IPW_DL_STATE | IPW_DL_ASSOC,
5797 "Missed beacon: %d - disassociate\n",
5798 priv->missed_adhoc_beacons);
5799 ipw_remove_current_network(priv);
5800 ipw_disassociate(priv);
5804 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
5805 priv->assoc_request.beacon_interval);
5808 static void ipw_bg_adhoc_check(void *data)
5810 struct ipw_priv *priv = data;
5811 mutex_lock(&priv->mutex);
5812 ipw_adhoc_check(data);
5813 mutex_unlock(&priv->mutex);
5816 #ifdef CONFIG_IPW2200_DEBUG
5817 static void ipw_debug_config(struct ipw_priv *priv)
5819 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5820 "[CFG 0x%08X]\n", priv->config);
5821 if (priv->config & CFG_STATIC_CHANNEL)
5822 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
5824 IPW_DEBUG_INFO("Channel unlocked.\n");
5825 if (priv->config & CFG_STATIC_ESSID)
5826 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
5827 escape_essid(priv->essid, priv->essid_len));
5829 IPW_DEBUG_INFO("ESSID unlocked.\n");
5830 if (priv->config & CFG_STATIC_BSSID)
5831 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5832 MAC_ARG(priv->bssid));
5834 IPW_DEBUG_INFO("BSSID unlocked.\n");
5835 if (priv->capability & CAP_PRIVACY_ON)
5836 IPW_DEBUG_INFO("PRIVACY on\n");
5838 IPW_DEBUG_INFO("PRIVACY off\n");
5839 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5842 #define ipw_debug_config(x) do {} while (0)
5845 static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
5847 /* TODO: Verify that this works... */
5848 struct ipw_fixed_rate fr = {
5849 .tx_rates = priv->rates_mask
5854 /* Identify 'current FW band' and match it with the fixed
5857 switch (priv->ieee->freq_band) {
5858 case IEEE80211_52GHZ_BAND: /* A only */
5860 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5861 /* Invalid fixed rate mask */
5863 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5868 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5871 default: /* 2.4Ghz or Mixed */
5873 if (mode == IEEE_B) {
5874 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
5875 /* Invalid fixed rate mask */
5877 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5884 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5885 IEEE80211_OFDM_RATES_MASK)) {
5886 /* Invalid fixed rate mask */
5888 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5893 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
5894 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
5895 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
5898 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
5899 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
5900 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
5903 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
5904 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
5905 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
5908 fr.tx_rates |= mask;
5912 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
5913 ipw_write_reg32(priv, reg, *(u32 *) & fr);
5916 static void ipw_abort_scan(struct ipw_priv *priv)
5920 if (priv->status & STATUS_SCAN_ABORTING) {
5921 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5924 priv->status |= STATUS_SCAN_ABORTING;
5926 err = ipw_send_scan_abort(priv);
5928 IPW_DEBUG_HC("Request to abort scan failed.\n");
5931 static void ipw_add_scan_channels(struct ipw_priv *priv,
5932 struct ipw_scan_request_ext *scan,
5935 int channel_index = 0;
5936 const struct ieee80211_geo *geo;
5939 geo = ieee80211_get_geo(priv->ieee);
5941 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
5942 int start = channel_index;
5943 for (i = 0; i < geo->a_channels; i++) {
5944 if ((priv->status & STATUS_ASSOCIATED) &&
5945 geo->a[i].channel == priv->channel)
5948 scan->channels_list[channel_index] = geo->a[i].channel;
5949 ipw_set_scan_type(scan, channel_index,
5951 flags & IEEE80211_CH_PASSIVE_ONLY ?
5952 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
5956 if (start != channel_index) {
5957 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
5958 (channel_index - start);
5963 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
5964 int start = channel_index;
5965 if (priv->config & CFG_SPEED_SCAN) {
5967 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
5968 /* nop out the list */
5973 while (channel_index < IPW_SCAN_CHANNELS) {
5975 priv->speed_scan[priv->speed_scan_pos];
5977 priv->speed_scan_pos = 0;
5978 channel = priv->speed_scan[0];
5980 if ((priv->status & STATUS_ASSOCIATED) &&
5981 channel == priv->channel) {
5982 priv->speed_scan_pos++;
5986 /* If this channel has already been
5987 * added in scan, break from loop
5988 * and this will be the first channel
5991 if (channels[channel - 1] != 0)
5994 channels[channel - 1] = 1;
5995 priv->speed_scan_pos++;
5997 scan->channels_list[channel_index] = channel;
5999 ieee80211_channel_to_index(priv->ieee, channel);
6000 ipw_set_scan_type(scan, channel_index,
6003 IEEE80211_CH_PASSIVE_ONLY ?
6004 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6008 for (i = 0; i < geo->bg_channels; i++) {
6009 if ((priv->status & STATUS_ASSOCIATED) &&
6010 geo->bg[i].channel == priv->channel)
6013 scan->channels_list[channel_index] =
6015 ipw_set_scan_type(scan, channel_index,
6018 IEEE80211_CH_PASSIVE_ONLY ?
6019 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6024 if (start != channel_index) {
6025 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6026 (channel_index - start);
6031 static int ipw_request_scan(struct ipw_priv *priv)
6033 struct ipw_scan_request_ext scan;
6034 int err = 0, scan_type;
6036 if (!(priv->status & STATUS_INIT) ||
6037 (priv->status & STATUS_EXIT_PENDING))
6040 mutex_lock(&priv->mutex);
6042 if (priv->status & STATUS_SCANNING) {
6043 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
6044 priv->status |= STATUS_SCAN_PENDING;
6048 if (!(priv->status & STATUS_SCAN_FORCED) &&
6049 priv->status & STATUS_SCAN_ABORTING) {
6050 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6051 priv->status |= STATUS_SCAN_PENDING;
6055 if (priv->status & STATUS_RF_KILL_MASK) {
6056 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6057 priv->status |= STATUS_SCAN_PENDING;
6061 memset(&scan, 0, sizeof(scan));
6063 if (priv->config & CFG_SPEED_SCAN)
6064 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6067 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6070 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6072 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
6074 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
6076 #ifdef CONFIG_IPW2200_MONITOR
6077 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
6081 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
6082 case IEEE80211_52GHZ_BAND:
6083 band = (u8) (IPW_A_MODE << 6) | 1;
6084 channel = priv->channel;
6087 case IEEE80211_24GHZ_BAND:
6088 band = (u8) (IPW_B_MODE << 6) | 1;
6089 channel = priv->channel;
6093 band = (u8) (IPW_B_MODE << 6) | 1;
6098 scan.channels_list[0] = band;
6099 scan.channels_list[1] = channel;
6100 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
6102 /* NOTE: The card will sit on this channel for this time
6103 * period. Scan aborts are timing sensitive and frequently
6104 * result in firmware restarts. As such, it is best to
6105 * set a small dwell_time here and just keep re-issuing
6106 * scans. Otherwise fast channel hopping will not actually
6109 * TODO: Move SPEED SCAN support to all modes and bands */
6110 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6113 #endif /* CONFIG_IPW2200_MONITOR */
6114 /* If we are roaming, then make this a directed scan for the
6115 * current network. Otherwise, ensure that every other scan
6116 * is a fast channel hop scan */
6117 if ((priv->status & STATUS_ROAMING)
6118 || (!(priv->status & STATUS_ASSOCIATED)
6119 && (priv->config & CFG_STATIC_ESSID)
6120 && (le32_to_cpu(scan.full_scan_index) % 2))) {
6121 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6123 IPW_DEBUG_HC("Attempt to send SSID command "
6128 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6130 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
6132 ipw_add_scan_channels(priv, &scan, scan_type);
6133 #ifdef CONFIG_IPW2200_MONITOR
6137 err = ipw_send_scan_request_ext(priv, &scan);
6139 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
6143 priv->status |= STATUS_SCANNING;
6144 priv->status &= ~STATUS_SCAN_PENDING;
6145 queue_delayed_work(priv->workqueue, &priv->scan_check,
6146 IPW_SCAN_CHECK_WATCHDOG);
6148 mutex_unlock(&priv->mutex);
6152 static void ipw_bg_abort_scan(void *data)
6154 struct ipw_priv *priv = data;
6155 mutex_lock(&priv->mutex);
6156 ipw_abort_scan(data);
6157 mutex_unlock(&priv->mutex);
6160 static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6162 /* This is called when wpa_supplicant loads and closes the driver
6164 priv->ieee->wpa_enabled = value;
6168 static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6170 struct ieee80211_device *ieee = priv->ieee;
6171 struct ieee80211_security sec = {
6172 .flags = SEC_AUTH_MODE,
6176 if (value & IW_AUTH_ALG_SHARED_KEY) {
6177 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6179 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
6180 sec.auth_mode = WLAN_AUTH_OPEN;
6182 } else if (value & IW_AUTH_ALG_LEAP) {
6183 sec.auth_mode = WLAN_AUTH_LEAP;
6188 if (ieee->set_security)
6189 ieee->set_security(ieee->dev, &sec);
6196 static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6199 /* make sure WPA is enabled */
6200 ipw_wpa_enable(priv, 1);
6202 ipw_disassociate(priv);
6205 static int ipw_set_rsn_capa(struct ipw_priv *priv,
6206 char *capabilities, int length)
6208 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6210 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
6219 static int ipw_wx_set_genie(struct net_device *dev,
6220 struct iw_request_info *info,
6221 union iwreq_data *wrqu, char *extra)
6223 struct ipw_priv *priv = ieee80211_priv(dev);
6224 struct ieee80211_device *ieee = priv->ieee;
6228 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6229 (wrqu->data.length && extra == NULL))
6232 //mutex_lock(&priv->mutex);
6234 //if (!ieee->wpa_enabled) {
6235 // err = -EOPNOTSUPP;
6239 if (wrqu->data.length) {
6240 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6246 memcpy(buf, extra, wrqu->data.length);
6247 kfree(ieee->wpa_ie);
6249 ieee->wpa_ie_len = wrqu->data.length;
6251 kfree(ieee->wpa_ie);
6252 ieee->wpa_ie = NULL;
6253 ieee->wpa_ie_len = 0;
6256 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6258 //mutex_unlock(&priv->mutex);
6263 static int ipw_wx_get_genie(struct net_device *dev,
6264 struct iw_request_info *info,
6265 union iwreq_data *wrqu, char *extra)
6267 struct ipw_priv *priv = ieee80211_priv(dev);
6268 struct ieee80211_device *ieee = priv->ieee;
6271 //mutex_lock(&priv->mutex);
6273 //if (!ieee->wpa_enabled) {
6274 // err = -EOPNOTSUPP;
6278 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6279 wrqu->data.length = 0;
6283 if (wrqu->data.length < ieee->wpa_ie_len) {
6288 wrqu->data.length = ieee->wpa_ie_len;
6289 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6292 //mutex_unlock(&priv->mutex);
6296 static int wext_cipher2level(int cipher)
6299 case IW_AUTH_CIPHER_NONE:
6301 case IW_AUTH_CIPHER_WEP40:
6302 case IW_AUTH_CIPHER_WEP104:
6304 case IW_AUTH_CIPHER_TKIP:
6306 case IW_AUTH_CIPHER_CCMP:
6314 static int ipw_wx_set_auth(struct net_device *dev,
6315 struct iw_request_info *info,
6316 union iwreq_data *wrqu, char *extra)
6318 struct ipw_priv *priv = ieee80211_priv(dev);
6319 struct ieee80211_device *ieee = priv->ieee;
6320 struct iw_param *param = &wrqu->param;
6321 struct ieee80211_crypt_data *crypt;
6322 unsigned long flags;
6325 switch (param->flags & IW_AUTH_INDEX) {
6326 case IW_AUTH_WPA_VERSION:
6328 case IW_AUTH_CIPHER_PAIRWISE:
6329 ipw_set_hw_decrypt_unicast(priv,
6330 wext_cipher2level(param->value));
6332 case IW_AUTH_CIPHER_GROUP:
6333 ipw_set_hw_decrypt_multicast(priv,
6334 wext_cipher2level(param->value));
6336 case IW_AUTH_KEY_MGMT:
6338 * ipw2200 does not use these parameters
6342 case IW_AUTH_TKIP_COUNTERMEASURES:
6343 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6344 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
6347 flags = crypt->ops->get_flags(crypt->priv);
6350 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6352 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6354 crypt->ops->set_flags(flags, crypt->priv);
6358 case IW_AUTH_DROP_UNENCRYPTED:{
6361 * wpa_supplicant calls set_wpa_enabled when the driver
6362 * is loaded and unloaded, regardless of if WPA is being
6363 * used. No other calls are made which can be used to
6364 * determine if encryption will be used or not prior to
6365 * association being expected. If encryption is not being
6366 * used, drop_unencrypted is set to false, else true -- we
6367 * can use this to determine if the CAP_PRIVACY_ON bit should
6370 struct ieee80211_security sec = {
6371 .flags = SEC_ENABLED,
6372 .enabled = param->value,
6374 priv->ieee->drop_unencrypted = param->value;
6375 /* We only change SEC_LEVEL for open mode. Others
6376 * are set by ipw_wpa_set_encryption.
6378 if (!param->value) {
6379 sec.flags |= SEC_LEVEL;
6380 sec.level = SEC_LEVEL_0;
6382 sec.flags |= SEC_LEVEL;
6383 sec.level = SEC_LEVEL_1;
6385 if (priv->ieee->set_security)
6386 priv->ieee->set_security(priv->ieee->dev, &sec);
6390 case IW_AUTH_80211_AUTH_ALG:
6391 ret = ipw_wpa_set_auth_algs(priv, param->value);
6394 case IW_AUTH_WPA_ENABLED:
6395 ret = ipw_wpa_enable(priv, param->value);
6398 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6399 ieee->ieee802_1x = param->value;
6402 //case IW_AUTH_ROAMING_CONTROL:
6403 case IW_AUTH_PRIVACY_INVOKED:
6404 ieee->privacy_invoked = param->value;
6414 static int ipw_wx_get_auth(struct net_device *dev,
6415 struct iw_request_info *info,
6416 union iwreq_data *wrqu, char *extra)
6418 struct ipw_priv *priv = ieee80211_priv(dev);
6419 struct ieee80211_device *ieee = priv->ieee;
6420 struct ieee80211_crypt_data *crypt;
6421 struct iw_param *param = &wrqu->param;
6424 switch (param->flags & IW_AUTH_INDEX) {
6425 case IW_AUTH_WPA_VERSION:
6426 case IW_AUTH_CIPHER_PAIRWISE:
6427 case IW_AUTH_CIPHER_GROUP:
6428 case IW_AUTH_KEY_MGMT:
6430 * wpa_supplicant will control these internally
6435 case IW_AUTH_TKIP_COUNTERMEASURES:
6436 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6437 if (!crypt || !crypt->ops->get_flags)
6440 param->value = (crypt->ops->get_flags(crypt->priv) &
6441 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6445 case IW_AUTH_DROP_UNENCRYPTED:
6446 param->value = ieee->drop_unencrypted;
6449 case IW_AUTH_80211_AUTH_ALG:
6450 param->value = ieee->sec.auth_mode;
6453 case IW_AUTH_WPA_ENABLED:
6454 param->value = ieee->wpa_enabled;
6457 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6458 param->value = ieee->ieee802_1x;
6461 case IW_AUTH_ROAMING_CONTROL:
6462 case IW_AUTH_PRIVACY_INVOKED:
6463 param->value = ieee->privacy_invoked;
6472 /* SIOCSIWENCODEEXT */
6473 static int ipw_wx_set_encodeext(struct net_device *dev,
6474 struct iw_request_info *info,
6475 union iwreq_data *wrqu, char *extra)
6477 struct ipw_priv *priv = ieee80211_priv(dev);
6478 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6481 if (ext->alg == IW_ENCODE_ALG_TKIP) {
6482 /* IPW HW can't build TKIP MIC,
6483 host decryption still needed */
6484 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6485 priv->ieee->host_mc_decrypt = 1;
6487 priv->ieee->host_encrypt = 0;
6488 priv->ieee->host_encrypt_msdu = 1;
6489 priv->ieee->host_decrypt = 1;
6492 priv->ieee->host_encrypt = 0;
6493 priv->ieee->host_encrypt_msdu = 0;
6494 priv->ieee->host_decrypt = 0;
6495 priv->ieee->host_mc_decrypt = 0;
6499 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6502 /* SIOCGIWENCODEEXT */
6503 static int ipw_wx_get_encodeext(struct net_device *dev,
6504 struct iw_request_info *info,
6505 union iwreq_data *wrqu, char *extra)
6507 struct ipw_priv *priv = ieee80211_priv(dev);
6508 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6512 static int ipw_wx_set_mlme(struct net_device *dev,
6513 struct iw_request_info *info,
6514 union iwreq_data *wrqu, char *extra)
6516 struct ipw_priv *priv = ieee80211_priv(dev);
6517 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6520 reason = cpu_to_le16(mlme->reason_code);
6522 switch (mlme->cmd) {
6523 case IW_MLME_DEAUTH:
6527 case IW_MLME_DISASSOC:
6528 ipw_disassociate(priv);
6537 #ifdef CONFIG_IPW_QOS
6541 * get the modulation type of the current network or
6542 * the card current mode
6544 static u8 ipw_qos_current_mode(struct ipw_priv * priv)
6548 if (priv->status & STATUS_ASSOCIATED) {
6549 unsigned long flags;
6551 spin_lock_irqsave(&priv->ieee->lock, flags);
6552 mode = priv->assoc_network->mode;
6553 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6555 mode = priv->ieee->mode;
6557 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6562 * Handle management frame beacon and probe response
6564 static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6566 struct ieee80211_network *network)
6568 u32 size = sizeof(struct ieee80211_qos_parameters);
6570 if (network->capability & WLAN_CAPABILITY_IBSS)
6571 network->qos_data.active = network->qos_data.supported;
6573 if (network->flags & NETWORK_HAS_QOS_MASK) {
6574 if (active_network &&
6575 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
6576 network->qos_data.active = network->qos_data.supported;
6578 if ((network->qos_data.active == 1) && (active_network == 1) &&
6579 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6580 (network->qos_data.old_param_count !=
6581 network->qos_data.param_count)) {
6582 network->qos_data.old_param_count =
6583 network->qos_data.param_count;
6584 schedule_work(&priv->qos_activate);
6585 IPW_DEBUG_QOS("QoS parameters change call "
6589 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6590 memcpy(&network->qos_data.parameters,
6591 &def_parameters_CCK, size);
6593 memcpy(&network->qos_data.parameters,
6594 &def_parameters_OFDM, size);
6596 if ((network->qos_data.active == 1) && (active_network == 1)) {
6597 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6598 schedule_work(&priv->qos_activate);
6601 network->qos_data.active = 0;
6602 network->qos_data.supported = 0;
6604 if ((priv->status & STATUS_ASSOCIATED) &&
6605 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6606 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6607 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6608 !(network->flags & NETWORK_EMPTY_ESSID))
6609 if ((network->ssid_len ==
6610 priv->assoc_network->ssid_len) &&
6611 !memcmp(network->ssid,
6612 priv->assoc_network->ssid,
6613 network->ssid_len)) {
6614 queue_work(priv->workqueue,
6615 &priv->merge_networks);
6623 * This function set up the firmware to support QoS. It sends
6624 * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6626 static int ipw_qos_activate(struct ipw_priv *priv,
6627 struct ieee80211_qos_data *qos_network_data)
6630 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6631 struct ieee80211_qos_parameters *active_one = NULL;
6632 u32 size = sizeof(struct ieee80211_qos_parameters);
6637 type = ipw_qos_current_mode(priv);
6639 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6640 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6641 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6642 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6644 if (qos_network_data == NULL) {
6645 if (type == IEEE_B) {
6646 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6647 active_one = &def_parameters_CCK;
6649 active_one = &def_parameters_OFDM;
6651 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6652 burst_duration = ipw_qos_get_burst_duration(priv);
6653 for (i = 0; i < QOS_QUEUE_NUM; i++)
6654 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6655 (u16) burst_duration;
6656 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6657 if (type == IEEE_B) {
6658 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6660 if (priv->qos_data.qos_enable == 0)
6661 active_one = &def_parameters_CCK;
6663 active_one = priv->qos_data.def_qos_parm_CCK;
6665 if (priv->qos_data.qos_enable == 0)
6666 active_one = &def_parameters_OFDM;
6668 active_one = priv->qos_data.def_qos_parm_OFDM;
6670 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6672 unsigned long flags;
6675 spin_lock_irqsave(&priv->ieee->lock, flags);
6676 active_one = &(qos_network_data->parameters);
6677 qos_network_data->old_param_count =
6678 qos_network_data->param_count;
6679 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6680 active = qos_network_data->supported;
6681 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6684 burst_duration = ipw_qos_get_burst_duration(priv);
6685 for (i = 0; i < QOS_QUEUE_NUM; i++)
6686 qos_parameters[QOS_PARAM_SET_ACTIVE].
6687 tx_op_limit[i] = (u16) burst_duration;
6691 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
6692 err = ipw_send_qos_params_command(priv,
6693 (struct ieee80211_qos_parameters *)
6694 &(qos_parameters[0]));
6696 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6702 * send IPW_CMD_WME_INFO to the firmware
6704 static int ipw_qos_set_info_element(struct ipw_priv *priv)
6707 struct ieee80211_qos_information_element qos_info;
6712 qos_info.elementID = QOS_ELEMENT_ID;
6713 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6715 qos_info.version = QOS_VERSION_1;
6716 qos_info.ac_info = 0;
6718 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6719 qos_info.qui_type = QOS_OUI_TYPE;
6720 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6722 ret = ipw_send_qos_info_command(priv, &qos_info);
6724 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6730 * Set the QoS parameter with the association request structure
6732 static int ipw_qos_association(struct ipw_priv *priv,
6733 struct ieee80211_network *network)
6736 struct ieee80211_qos_data *qos_data = NULL;
6737 struct ieee80211_qos_data ibss_data = {
6742 switch (priv->ieee->iw_mode) {
6744 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
6746 qos_data = &ibss_data;
6750 qos_data = &network->qos_data;
6758 err = ipw_qos_activate(priv, qos_data);
6760 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6764 if (priv->qos_data.qos_enable && qos_data->supported) {
6765 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6766 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6767 return ipw_qos_set_info_element(priv);
6774 * handling the beaconing responces. if we get different QoS setting
6775 * of the network from the the associated setting adjust the QoS
6778 static int ipw_qos_association_resp(struct ipw_priv *priv,
6779 struct ieee80211_network *network)
6782 unsigned long flags;
6783 u32 size = sizeof(struct ieee80211_qos_parameters);
6784 int set_qos_param = 0;
6786 if ((priv == NULL) || (network == NULL) ||
6787 (priv->assoc_network == NULL))
6790 if (!(priv->status & STATUS_ASSOCIATED))
6793 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
6796 spin_lock_irqsave(&priv->ieee->lock, flags);
6797 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
6798 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
6799 sizeof(struct ieee80211_qos_data));
6800 priv->assoc_network->qos_data.active = 1;
6801 if ((network->qos_data.old_param_count !=
6802 network->qos_data.param_count)) {
6804 network->qos_data.old_param_count =
6805 network->qos_data.param_count;
6809 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
6810 memcpy(&priv->assoc_network->qos_data.parameters,
6811 &def_parameters_CCK, size);
6813 memcpy(&priv->assoc_network->qos_data.parameters,
6814 &def_parameters_OFDM, size);
6815 priv->assoc_network->qos_data.active = 0;
6816 priv->assoc_network->qos_data.supported = 0;
6820 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6822 if (set_qos_param == 1)
6823 schedule_work(&priv->qos_activate);
6828 static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
6835 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
6836 ret = priv->qos_data.burst_duration_CCK;
6838 ret = priv->qos_data.burst_duration_OFDM;
6844 * Initialize the setting of QoS global
6846 static void ipw_qos_init(struct ipw_priv *priv, int enable,
6847 int burst_enable, u32 burst_duration_CCK,
6848 u32 burst_duration_OFDM)
6850 priv->qos_data.qos_enable = enable;
6852 if (priv->qos_data.qos_enable) {
6853 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
6854 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
6855 IPW_DEBUG_QOS("QoS is enabled\n");
6857 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
6858 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
6859 IPW_DEBUG_QOS("QoS is not enabled\n");
6862 priv->qos_data.burst_enable = burst_enable;
6865 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
6866 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
6868 priv->qos_data.burst_duration_CCK = 0;
6869 priv->qos_data.burst_duration_OFDM = 0;
6874 * map the packet priority to the right TX Queue
6876 static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
6878 if (priority > 7 || !priv->qos_data.qos_enable)
6881 return from_priority_to_tx_queue[priority] - 1;
6884 static int ipw_is_qos_active(struct net_device *dev,
6885 struct sk_buff *skb)
6887 struct ipw_priv *priv = ieee80211_priv(dev);
6888 struct ieee80211_qos_data *qos_data = NULL;
6889 int active, supported;
6890 u8 *daddr = skb->data + ETH_ALEN;
6891 int unicast = !is_multicast_ether_addr(daddr);
6893 if (!(priv->status & STATUS_ASSOCIATED))
6896 qos_data = &priv->assoc_network->qos_data;
6898 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6900 qos_data->active = 0;
6902 qos_data->active = qos_data->supported;
6904 active = qos_data->active;
6905 supported = qos_data->supported;
6906 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
6908 priv->qos_data.qos_enable, active, supported, unicast);
6909 if (active && priv->qos_data.qos_enable)
6916 * add QoS parameter to the TX command
6918 static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
6920 struct tfd_data *tfd)
6922 int tx_queue_id = 0;
6925 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
6926 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
6928 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
6929 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
6930 tfd->tfd.tfd_26.mchdr.qos_ctrl |= CTRL_QOS_NO_ACK;
6936 * background support to run QoS activate functionality
6938 static void ipw_bg_qos_activate(void *data)
6940 struct ipw_priv *priv = data;
6945 mutex_lock(&priv->mutex);
6947 if (priv->status & STATUS_ASSOCIATED)
6948 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
6950 mutex_unlock(&priv->mutex);
6953 static int ipw_handle_probe_response(struct net_device *dev,
6954 struct ieee80211_probe_response *resp,
6955 struct ieee80211_network *network)
6957 struct ipw_priv *priv = ieee80211_priv(dev);
6958 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
6959 (network == priv->assoc_network));
6961 ipw_qos_handle_probe_response(priv, active_network, network);
6966 static int ipw_handle_beacon(struct net_device *dev,
6967 struct ieee80211_beacon *resp,
6968 struct ieee80211_network *network)
6970 struct ipw_priv *priv = ieee80211_priv(dev);
6971 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
6972 (network == priv->assoc_network));
6974 ipw_qos_handle_probe_response(priv, active_network, network);
6979 static int ipw_handle_assoc_response(struct net_device *dev,
6980 struct ieee80211_assoc_response *resp,
6981 struct ieee80211_network *network)
6983 struct ipw_priv *priv = ieee80211_priv(dev);
6984 ipw_qos_association_resp(priv, network);
6988 static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
6991 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
6992 sizeof(*qos_param) * 3, qos_param);
6995 static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
6998 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7002 #endif /* CONFIG_IPW_QOS */
7004 static int ipw_associate_network(struct ipw_priv *priv,
7005 struct ieee80211_network *network,
7006 struct ipw_supported_rates *rates, int roaming)
7010 if (priv->config & CFG_FIXED_RATE)
7011 ipw_set_fixed_rate(priv, network->mode);
7013 if (!(priv->config & CFG_STATIC_ESSID)) {
7014 priv->essid_len = min(network->ssid_len,
7015 (u8) IW_ESSID_MAX_SIZE);
7016 memcpy(priv->essid, network->ssid, priv->essid_len);
7019 network->last_associate = jiffies;
7021 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7022 priv->assoc_request.channel = network->channel;
7023 priv->assoc_request.auth_key = 0;
7025 if ((priv->capability & CAP_PRIVACY_ON) &&
7026 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
7027 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
7028 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7030 if (priv->ieee->sec.level == SEC_LEVEL_1)
7031 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
7033 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7034 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7035 priv->assoc_request.auth_type = AUTH_LEAP;
7037 priv->assoc_request.auth_type = AUTH_OPEN;
7039 if (priv->ieee->wpa_ie_len) {
7040 priv->assoc_request.policy_support = 0x02; /* RSN active */
7041 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7042 priv->ieee->wpa_ie_len);
7046 * It is valid for our ieee device to support multiple modes, but
7047 * when it comes to associating to a given network we have to choose
7050 if (network->mode & priv->ieee->mode & IEEE_A)
7051 priv->assoc_request.ieee_mode = IPW_A_MODE;
7052 else if (network->mode & priv->ieee->mode & IEEE_G)
7053 priv->assoc_request.ieee_mode = IPW_G_MODE;
7054 else if (network->mode & priv->ieee->mode & IEEE_B)
7055 priv->assoc_request.ieee_mode = IPW_B_MODE;
7057 priv->assoc_request.capability = network->capability;
7058 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7059 && !(priv->config & CFG_PREAMBLE_LONG)) {
7060 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7062 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7064 /* Clear the short preamble if we won't be supporting it */
7065 priv->assoc_request.capability &=
7066 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7069 /* Clear capability bits that aren't used in Ad Hoc */
7070 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7071 priv->assoc_request.capability &=
7072 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7074 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
7075 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
7076 roaming ? "Rea" : "A",
7077 escape_essid(priv->essid, priv->essid_len),
7079 ipw_modes[priv->assoc_request.ieee_mode],
7081 (priv->assoc_request.preamble_length ==
7082 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7083 network->capability &
7084 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
7085 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
7086 priv->capability & CAP_PRIVACY_ON ?
7087 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
7089 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
7090 priv->capability & CAP_PRIVACY_ON ?
7091 '1' + priv->ieee->sec.active_key : '.',
7092 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
7094 priv->assoc_request.beacon_interval = network->beacon_interval;
7095 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
7096 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
7097 priv->assoc_request.assoc_type = HC_IBSS_START;
7098 priv->assoc_request.assoc_tsf_msw = 0;
7099 priv->assoc_request.assoc_tsf_lsw = 0;
7101 if (unlikely(roaming))
7102 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7104 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7105 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7106 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7109 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
7111 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7112 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7113 priv->assoc_request.atim_window = network->atim_window;
7115 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
7116 priv->assoc_request.atim_window = 0;
7119 priv->assoc_request.listen_interval = network->listen_interval;
7121 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7123 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7127 rates->ieee_mode = priv->assoc_request.ieee_mode;
7128 rates->purpose = IPW_RATE_CONNECT;
7129 ipw_send_supported_rates(priv, rates);
7131 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7132 priv->sys_config.dot11g_auto_detection = 1;
7134 priv->sys_config.dot11g_auto_detection = 0;
7136 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7137 priv->sys_config.answer_broadcast_ssid_probe = 1;
7139 priv->sys_config.answer_broadcast_ssid_probe = 0;
7141 err = ipw_send_system_config(priv, &priv->sys_config);
7143 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7147 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
7148 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
7150 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7155 * If preemption is enabled, it is possible for the association
7156 * to complete before we return from ipw_send_associate. Therefore
7157 * we have to be sure and update our priviate data first.
7159 priv->channel = network->channel;
7160 memcpy(priv->bssid, network->bssid, ETH_ALEN);
7161 priv->status |= STATUS_ASSOCIATING;
7162 priv->status &= ~STATUS_SECURITY_UPDATED;
7164 priv->assoc_network = network;
7166 #ifdef CONFIG_IPW_QOS
7167 ipw_qos_association(priv, network);
7170 err = ipw_send_associate(priv, &priv->assoc_request);
7172 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7176 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
7177 escape_essid(priv->essid, priv->essid_len),
7178 MAC_ARG(priv->bssid));
7183 static void ipw_roam(void *data)
7185 struct ipw_priv *priv = data;
7186 struct ieee80211_network *network = NULL;
7187 struct ipw_network_match match = {
7188 .network = priv->assoc_network
7191 /* The roaming process is as follows:
7193 * 1. Missed beacon threshold triggers the roaming process by
7194 * setting the status ROAM bit and requesting a scan.
7195 * 2. When the scan completes, it schedules the ROAM work
7196 * 3. The ROAM work looks at all of the known networks for one that
7197 * is a better network than the currently associated. If none
7198 * found, the ROAM process is over (ROAM bit cleared)
7199 * 4. If a better network is found, a disassociation request is
7201 * 5. When the disassociation completes, the roam work is again
7202 * scheduled. The second time through, the driver is no longer
7203 * associated, and the newly selected network is sent an
7204 * association request.
7205 * 6. At this point ,the roaming process is complete and the ROAM
7206 * status bit is cleared.
7209 /* If we are no longer associated, and the roaming bit is no longer
7210 * set, then we are not actively roaming, so just return */
7211 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7214 if (priv->status & STATUS_ASSOCIATED) {
7215 /* First pass through ROAM process -- look for a better
7217 unsigned long flags;
7218 u8 rssi = priv->assoc_network->stats.rssi;
7219 priv->assoc_network->stats.rssi = -128;
7220 spin_lock_irqsave(&priv->ieee->lock, flags);
7221 list_for_each_entry(network, &priv->ieee->network_list, list) {
7222 if (network != priv->assoc_network)
7223 ipw_best_network(priv, &match, network, 1);
7225 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7226 priv->assoc_network->stats.rssi = rssi;
7228 if (match.network == priv->assoc_network) {
7229 IPW_DEBUG_ASSOC("No better APs in this network to "
7231 priv->status &= ~STATUS_ROAMING;
7232 ipw_debug_config(priv);
7236 ipw_send_disassociate(priv, 1);
7237 priv->assoc_network = match.network;
7242 /* Second pass through ROAM process -- request association */
7243 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7244 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7245 priv->status &= ~STATUS_ROAMING;
7248 static void ipw_bg_roam(void *data)
7250 struct ipw_priv *priv = data;
7251 mutex_lock(&priv->mutex);
7253 mutex_unlock(&priv->mutex);
7256 static int ipw_associate(void *data)
7258 struct ipw_priv *priv = data;
7260 struct ieee80211_network *network = NULL;
7261 struct ipw_network_match match = {
7264 struct ipw_supported_rates *rates;
7265 struct list_head *element;
7266 unsigned long flags;
7268 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7269 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7273 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
7274 IPW_DEBUG_ASSOC("Not attempting association (already in "
7279 if (priv->status & STATUS_DISASSOCIATING) {
7280 IPW_DEBUG_ASSOC("Not attempting association (in "
7281 "disassociating)\n ");
7282 queue_work(priv->workqueue, &priv->associate);
7286 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
7287 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7292 if (!(priv->config & CFG_ASSOCIATE) &&
7293 !(priv->config & (CFG_STATIC_ESSID |
7294 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
7295 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
7299 /* Protect our use of the network_list */
7300 spin_lock_irqsave(&priv->ieee->lock, flags);
7301 list_for_each_entry(network, &priv->ieee->network_list, list)
7302 ipw_best_network(priv, &match, network, 0);
7304 network = match.network;
7305 rates = &match.rates;
7307 if (network == NULL &&
7308 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7309 priv->config & CFG_ADHOC_CREATE &&
7310 priv->config & CFG_STATIC_ESSID &&
7311 priv->config & CFG_STATIC_CHANNEL &&
7312 !list_empty(&priv->ieee->network_free_list)) {
7313 element = priv->ieee->network_free_list.next;
7314 network = list_entry(element, struct ieee80211_network, list);
7315 ipw_adhoc_create(priv, network);
7316 rates = &priv->rates;
7318 list_add_tail(&network->list, &priv->ieee->network_list);
7320 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7322 /* If we reached the end of the list, then we don't have any valid
7325 ipw_debug_config(priv);
7327 if (!(priv->status & STATUS_SCANNING)) {
7328 if (!(priv->config & CFG_SPEED_SCAN))
7329 queue_delayed_work(priv->workqueue,
7330 &priv->request_scan,
7333 queue_work(priv->workqueue,
7334 &priv->request_scan);
7340 ipw_associate_network(priv, network, rates, 0);
7345 static void ipw_bg_associate(void *data)
7347 struct ipw_priv *priv = data;
7348 mutex_lock(&priv->mutex);
7349 ipw_associate(data);
7350 mutex_unlock(&priv->mutex);
7353 static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7354 struct sk_buff *skb)
7356 struct ieee80211_hdr *hdr;
7359 hdr = (struct ieee80211_hdr *)skb->data;
7360 fc = le16_to_cpu(hdr->frame_ctl);
7361 if (!(fc & IEEE80211_FCTL_PROTECTED))
7364 fc &= ~IEEE80211_FCTL_PROTECTED;
7365 hdr->frame_ctl = cpu_to_le16(fc);
7366 switch (priv->ieee->sec.level) {
7368 /* Remove CCMP HDR */
7369 memmove(skb->data + IEEE80211_3ADDR_LEN,
7370 skb->data + IEEE80211_3ADDR_LEN + 8,
7371 skb->len - IEEE80211_3ADDR_LEN - 8);
7372 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
7378 memmove(skb->data + IEEE80211_3ADDR_LEN,
7379 skb->data + IEEE80211_3ADDR_LEN + 4,
7380 skb->len - IEEE80211_3ADDR_LEN - 4);
7381 skb_trim(skb, skb->len - 8); /* IV + ICV */
7386 printk(KERN_ERR "Unknow security level %d\n",
7387 priv->ieee->sec.level);
7392 static void ipw_handle_data_packet(struct ipw_priv *priv,
7393 struct ipw_rx_mem_buffer *rxb,
7394 struct ieee80211_rx_stats *stats)
7396 struct ieee80211_hdr_4addr *hdr;
7397 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7399 /* We received data from the HW, so stop the watchdog */
7400 priv->net_dev->trans_start = jiffies;
7402 /* We only process data packets if the
7403 * interface is open */
7404 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7405 skb_tailroom(rxb->skb))) {
7406 priv->ieee->stats.rx_errors++;
7407 priv->wstats.discard.misc++;
7408 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7410 } else if (unlikely(!netif_running(priv->net_dev))) {
7411 priv->ieee->stats.rx_dropped++;
7412 priv->wstats.discard.misc++;
7413 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7417 /* Advance skb->data to the start of the actual payload */
7418 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
7420 /* Set the size of the skb to the size of the frame */
7421 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
7423 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7425 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
7426 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7427 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
7428 (is_multicast_ether_addr(hdr->addr1) ?
7429 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
7430 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7432 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7433 priv->ieee->stats.rx_errors++;
7434 else { /* ieee80211_rx succeeded, so it now owns the SKB */
7436 __ipw_led_activity_on(priv);
7440 #ifdef CONFIG_IEEE80211_RADIOTAP
7441 static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7442 struct ipw_rx_mem_buffer *rxb,
7443 struct ieee80211_rx_stats *stats)
7445 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7446 struct ipw_rx_frame *frame = &pkt->u.frame;
7448 /* initial pull of some data */
7449 u16 received_channel = frame->received_channel;
7450 u8 antennaAndPhy = frame->antennaAndPhy;
7451 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7452 u16 pktrate = frame->rate;
7454 /* Magic struct that slots into the radiotap header -- no reason
7455 * to build this manually element by element, we can write it much
7456 * more efficiently than we can parse it. ORDER MATTERS HERE */
7458 struct ieee80211_radiotap_header rt_hdr;
7459 u8 rt_flags; /* radiotap packet flags */
7460 u8 rt_rate; /* rate in 500kb/s */
7461 u16 rt_channel; /* channel in mhz */
7462 u16 rt_chbitmask; /* channel bitfield */
7463 s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
7464 u8 rt_antenna; /* antenna number */
7467 short len = le16_to_cpu(pkt->u.frame.length);
7469 /* We received data from the HW, so stop the watchdog */
7470 priv->net_dev->trans_start = jiffies;
7472 /* We only process data packets if the
7473 * interface is open */
7474 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7475 skb_tailroom(rxb->skb))) {
7476 priv->ieee->stats.rx_errors++;
7477 priv->wstats.discard.misc++;
7478 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7480 } else if (unlikely(!netif_running(priv->net_dev))) {
7481 priv->ieee->stats.rx_dropped++;
7482 priv->wstats.discard.misc++;
7483 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7487 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7489 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7490 /* FIXME: Should alloc bigger skb instead */
7491 priv->ieee->stats.rx_dropped++;
7492 priv->wstats.discard.misc++;
7493 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7497 /* copy the frame itself */
7498 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7499 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7501 /* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7502 * part of our real header, saves a little time.
7504 * No longer necessary since we fill in all our data. Purge before merging
7506 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7507 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7510 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7512 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7513 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7514 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7516 /* Big bitfield of all the fields we provide in radiotap */
7517 ipw_rt->rt_hdr.it_present =
7518 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7519 (1 << IEEE80211_RADIOTAP_RATE) |
7520 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7521 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7522 (1 << IEEE80211_RADIOTAP_ANTENNA));
7524 /* Zero the flags, we'll add to them as we go */
7525 ipw_rt->rt_flags = 0;
7527 /* Convert signal to DBM */
7528 ipw_rt->rt_dbmsignal = antsignal;
7530 /* Convert the channel data and set the flags */
7531 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7532 if (received_channel > 14) { /* 802.11a */
7533 ipw_rt->rt_chbitmask =
7534 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7535 } else if (antennaAndPhy & 32) { /* 802.11b */
7536 ipw_rt->rt_chbitmask =
7537 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7538 } else { /* 802.11g */
7539 ipw_rt->rt_chbitmask =
7540 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7543 /* set the rate in multiples of 500k/s */
7545 case IPW_TX_RATE_1MB:
7546 ipw_rt->rt_rate = 2;
7548 case IPW_TX_RATE_2MB:
7549 ipw_rt->rt_rate = 4;
7551 case IPW_TX_RATE_5MB:
7552 ipw_rt->rt_rate = 10;
7554 case IPW_TX_RATE_6MB:
7555 ipw_rt->rt_rate = 12;
7557 case IPW_TX_RATE_9MB:
7558 ipw_rt->rt_rate = 18;
7560 case IPW_TX_RATE_11MB:
7561 ipw_rt->rt_rate = 22;
7563 case IPW_TX_RATE_12MB:
7564 ipw_rt->rt_rate = 24;
7566 case IPW_TX_RATE_18MB:
7567 ipw_rt->rt_rate = 36;
7569 case IPW_TX_RATE_24MB:
7570 ipw_rt->rt_rate = 48;
7572 case IPW_TX_RATE_36MB:
7573 ipw_rt->rt_rate = 72;
7575 case IPW_TX_RATE_48MB:
7576 ipw_rt->rt_rate = 96;
7578 case IPW_TX_RATE_54MB:
7579 ipw_rt->rt_rate = 108;
7582 ipw_rt->rt_rate = 0;
7586 /* antenna number */
7587 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7589 /* set the preamble flag if we have it */
7590 if ((antennaAndPhy & 64))
7591 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7593 /* Set the size of the skb to the size of the frame */
7594 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
7596 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7598 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7599 priv->ieee->stats.rx_errors++;
7600 else { /* ieee80211_rx succeeded, so it now owns the SKB */
7602 /* no LED during capture */
7607 static int is_network_packet(struct ipw_priv *priv,
7608 struct ieee80211_hdr_4addr *header)
7610 /* Filter incoming packets to determine if they are targetted toward
7611 * this network, discarding packets coming from ourselves */
7612 switch (priv->ieee->iw_mode) {
7613 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
7614 /* packets from our adapter are dropped (echo) */
7615 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7618 /* {broad,multi}cast packets to our BSSID go through */
7619 if (is_multicast_ether_addr(header->addr1))
7620 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
7622 /* packets to our adapter go through */
7623 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7626 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
7627 /* packets from our adapter are dropped (echo) */
7628 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7631 /* {broad,multi}cast packets to our BSS go through */
7632 if (is_multicast_ether_addr(header->addr1))
7633 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7635 /* packets to our adapter go through */
7636 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7643 #define IPW_PACKET_RETRY_TIME HZ
7645 static int is_duplicate_packet(struct ipw_priv *priv,
7646 struct ieee80211_hdr_4addr *header)
7648 u16 sc = le16_to_cpu(header->seq_ctl);
7649 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7650 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7651 u16 *last_seq, *last_frag;
7652 unsigned long *last_time;
7654 switch (priv->ieee->iw_mode) {
7657 struct list_head *p;
7658 struct ipw_ibss_seq *entry = NULL;
7659 u8 *mac = header->addr2;
7660 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
7662 __list_for_each(p, &priv->ibss_mac_hash[index]) {
7664 list_entry(p, struct ipw_ibss_seq, list);
7665 if (!memcmp(entry->mac, mac, ETH_ALEN))
7668 if (p == &priv->ibss_mac_hash[index]) {
7669 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
7672 ("Cannot malloc new mac entry\n");
7675 memcpy(entry->mac, mac, ETH_ALEN);
7676 entry->seq_num = seq;
7677 entry->frag_num = frag;
7678 entry->packet_time = jiffies;
7679 list_add(&entry->list,
7680 &priv->ibss_mac_hash[index]);
7683 last_seq = &entry->seq_num;
7684 last_frag = &entry->frag_num;
7685 last_time = &entry->packet_time;
7689 last_seq = &priv->last_seq_num;
7690 last_frag = &priv->last_frag_num;
7691 last_time = &priv->last_packet_time;
7696 if ((*last_seq == seq) &&
7697 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
7698 if (*last_frag == frag)
7700 if (*last_frag + 1 != frag)
7701 /* out-of-order fragment */
7707 *last_time = jiffies;
7711 /* Comment this line now since we observed the card receives
7712 * duplicate packets but the FCTL_RETRY bit is not set in the
7713 * IBSS mode with fragmentation enabled.
7714 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
7718 static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
7719 struct ipw_rx_mem_buffer *rxb,
7720 struct ieee80211_rx_stats *stats)
7722 struct sk_buff *skb = rxb->skb;
7723 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
7724 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
7725 (skb->data + IPW_RX_FRAME_SIZE);
7727 ieee80211_rx_mgt(priv->ieee, header, stats);
7729 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
7730 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7731 IEEE80211_STYPE_PROBE_RESP) ||
7732 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7733 IEEE80211_STYPE_BEACON))) {
7734 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
7735 ipw_add_station(priv, header->addr2);
7738 if (priv->config & CFG_NET_STATS) {
7739 IPW_DEBUG_HC("sending stat packet\n");
7741 /* Set the size of the skb to the size of the full
7742 * ipw header and 802.11 frame */
7743 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
7746 /* Advance past the ipw packet header to the 802.11 frame */
7747 skb_pull(skb, IPW_RX_FRAME_SIZE);
7749 /* Push the ieee80211_rx_stats before the 802.11 frame */
7750 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
7752 skb->dev = priv->ieee->dev;
7754 /* Point raw at the ieee80211_stats */
7755 skb->mac.raw = skb->data;
7757 skb->pkt_type = PACKET_OTHERHOST;
7758 skb->protocol = __constant_htons(ETH_P_80211_STATS);
7759 memset(skb->cb, 0, sizeof(rxb->skb->cb));
7766 * Main entry function for recieving a packet with 80211 headers. This
7767 * should be called when ever the FW has notified us that there is a new
7768 * skb in the recieve queue.
7770 static void ipw_rx(struct ipw_priv *priv)
7772 struct ipw_rx_mem_buffer *rxb;
7773 struct ipw_rx_packet *pkt;
7774 struct ieee80211_hdr_4addr *header;
7778 r = ipw_read32(priv, IPW_RX_READ_INDEX);
7779 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
7780 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
7783 rxb = priv->rxq->queue[i];
7784 if (unlikely(rxb == NULL)) {
7785 printk(KERN_CRIT "Queue not allocated!\n");
7788 priv->rxq->queue[i] = NULL;
7790 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
7792 PCI_DMA_FROMDEVICE);
7794 pkt = (struct ipw_rx_packet *)rxb->skb->data;
7795 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
7796 pkt->header.message_type,
7797 pkt->header.rx_seq_num, pkt->header.control_bits);
7799 switch (pkt->header.message_type) {
7800 case RX_FRAME_TYPE: /* 802.11 frame */ {
7801 struct ieee80211_rx_stats stats = {
7803 le16_to_cpu(pkt->u.frame.rssi_dbm) -
7806 le16_to_cpu(pkt->u.frame.rssi_dbm) -
7807 IPW_RSSI_TO_DBM + 0x100,
7809 le16_to_cpu(pkt->u.frame.noise),
7810 .rate = pkt->u.frame.rate,
7811 .mac_time = jiffies,
7813 pkt->u.frame.received_channel,
7816 control & (1 << 0)) ?
7817 IEEE80211_24GHZ_BAND :
7818 IEEE80211_52GHZ_BAND,
7819 .len = le16_to_cpu(pkt->u.frame.length),
7822 if (stats.rssi != 0)
7823 stats.mask |= IEEE80211_STATMASK_RSSI;
7824 if (stats.signal != 0)
7825 stats.mask |= IEEE80211_STATMASK_SIGNAL;
7826 if (stats.noise != 0)
7827 stats.mask |= IEEE80211_STATMASK_NOISE;
7828 if (stats.rate != 0)
7829 stats.mask |= IEEE80211_STATMASK_RATE;
7833 #ifdef CONFIG_IPW2200_MONITOR
7834 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7835 #ifdef CONFIG_IEEE80211_RADIOTAP
7836 ipw_handle_data_packet_monitor(priv,
7840 ipw_handle_data_packet(priv, rxb,
7848 (struct ieee80211_hdr_4addr *)(rxb->skb->
7851 /* TODO: Check Ad-Hoc dest/source and make sure
7852 * that we are actually parsing these packets
7853 * correctly -- we should probably use the
7854 * frame control of the packet and disregard
7855 * the current iw_mode */
7858 is_network_packet(priv, header);
7859 if (network_packet && priv->assoc_network) {
7860 priv->assoc_network->stats.rssi =
7862 priv->exp_avg_rssi =
7863 exponential_average(priv->exp_avg_rssi,
7864 stats.rssi, DEPTH_RSSI);
7867 IPW_DEBUG_RX("Frame: len=%u\n",
7868 le16_to_cpu(pkt->u.frame.length));
7870 if (le16_to_cpu(pkt->u.frame.length) <
7871 ieee80211_get_hdrlen(le16_to_cpu(
7872 header->frame_ctl))) {
7874 ("Received packet is too small. "
7876 priv->ieee->stats.rx_errors++;
7877 priv->wstats.discard.misc++;
7881 switch (WLAN_FC_GET_TYPE
7882 (le16_to_cpu(header->frame_ctl))) {
7884 case IEEE80211_FTYPE_MGMT:
7885 ipw_handle_mgmt_packet(priv, rxb,
7889 case IEEE80211_FTYPE_CTL:
7892 case IEEE80211_FTYPE_DATA:
7893 if (unlikely(!network_packet ||
7894 is_duplicate_packet(priv,
7897 IPW_DEBUG_DROP("Dropping: "
7910 ipw_handle_data_packet(priv, rxb,
7918 case RX_HOST_NOTIFICATION_TYPE:{
7920 ("Notification: subtype=%02X flags=%02X size=%d\n",
7921 pkt->u.notification.subtype,
7922 pkt->u.notification.flags,
7923 pkt->u.notification.size);
7924 ipw_rx_notification(priv, &pkt->u.notification);
7929 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
7930 pkt->header.message_type);
7934 /* For now we just don't re-use anything. We can tweak this
7935 * later to try and re-use notification packets and SKBs that
7936 * fail to Rx correctly */
7937 if (rxb->skb != NULL) {
7938 dev_kfree_skb_any(rxb->skb);
7942 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
7943 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
7944 list_add_tail(&rxb->list, &priv->rxq->rx_used);
7946 i = (i + 1) % RX_QUEUE_SIZE;
7949 /* Backtrack one entry */
7950 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
7952 ipw_rx_queue_restock(priv);
7955 #define DEFAULT_RTS_THRESHOLD 2304U
7956 #define MIN_RTS_THRESHOLD 1U
7957 #define MAX_RTS_THRESHOLD 2304U
7958 #define DEFAULT_BEACON_INTERVAL 100U
7959 #define DEFAULT_SHORT_RETRY_LIMIT 7U
7960 #define DEFAULT_LONG_RETRY_LIMIT 4U
7964 * @option: options to control different reset behaviour
7965 * 0 = reset everything except the 'disable' module_param
7966 * 1 = reset everything and print out driver info (for probe only)
7967 * 2 = reset everything
7969 static int ipw_sw_reset(struct ipw_priv *priv, int option)
7971 int band, modulation;
7972 int old_mode = priv->ieee->iw_mode;
7974 /* Initialize module parameter values here */
7977 /* We default to disabling the LED code as right now it causes
7978 * too many systems to lock up... */
7980 priv->config |= CFG_NO_LED;
7983 priv->config |= CFG_ASSOCIATE;
7985 IPW_DEBUG_INFO("Auto associate disabled.\n");
7988 priv->config |= CFG_ADHOC_CREATE;
7990 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
7992 priv->config &= ~CFG_STATIC_ESSID;
7993 priv->essid_len = 0;
7994 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
7996 if (disable && option) {
7997 priv->status |= STATUS_RF_KILL_SW;
7998 IPW_DEBUG_INFO("Radio disabled.\n");
8002 priv->config |= CFG_STATIC_CHANNEL;
8003 priv->channel = channel;
8004 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8005 /* TODO: Validate that provided channel is in range */
8007 #ifdef CONFIG_IPW_QOS
8008 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8009 burst_duration_CCK, burst_duration_OFDM);
8010 #endif /* CONFIG_IPW_QOS */
8014 priv->ieee->iw_mode = IW_MODE_ADHOC;
8015 priv->net_dev->type = ARPHRD_ETHER;
8018 #ifdef CONFIG_IPW2200_MONITOR
8020 priv->ieee->iw_mode = IW_MODE_MONITOR;
8021 #ifdef CONFIG_IEEE80211_RADIOTAP
8022 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8024 priv->net_dev->type = ARPHRD_IEEE80211;
8030 priv->net_dev->type = ARPHRD_ETHER;
8031 priv->ieee->iw_mode = IW_MODE_INFRA;
8036 priv->ieee->host_encrypt = 0;
8037 priv->ieee->host_encrypt_msdu = 0;
8038 priv->ieee->host_decrypt = 0;
8039 priv->ieee->host_mc_decrypt = 0;
8041 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
8043 /* IPW2200/2915 is abled to do hardware fragmentation. */
8044 priv->ieee->host_open_frag = 0;
8046 if ((priv->pci_dev->device == 0x4223) ||
8047 (priv->pci_dev->device == 0x4224)) {
8049 printk(KERN_INFO DRV_NAME
8050 ": Detected Intel PRO/Wireless 2915ABG Network "
8052 priv->ieee->abg_true = 1;
8053 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8054 modulation = IEEE80211_OFDM_MODULATION |
8055 IEEE80211_CCK_MODULATION;
8056 priv->adapter = IPW_2915ABG;
8057 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
8060 printk(KERN_INFO DRV_NAME
8061 ": Detected Intel PRO/Wireless 2200BG Network "
8064 priv->ieee->abg_true = 0;
8065 band = IEEE80211_24GHZ_BAND;
8066 modulation = IEEE80211_OFDM_MODULATION |
8067 IEEE80211_CCK_MODULATION;
8068 priv->adapter = IPW_2200BG;
8069 priv->ieee->mode = IEEE_G | IEEE_B;
8072 priv->ieee->freq_band = band;
8073 priv->ieee->modulation = modulation;
8075 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
8077 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8078 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8080 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8081 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8082 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
8084 /* If power management is turned on, default to AC mode */
8085 priv->power_mode = IPW_POWER_AC;
8086 priv->tx_power = IPW_TX_POWER_DEFAULT;
8088 return old_mode == priv->ieee->iw_mode;
8092 * This file defines the Wireless Extension handlers. It does not
8093 * define any methods of hardware manipulation and relies on the
8094 * functions defined in ipw_main to provide the HW interaction.
8096 * The exception to this is the use of the ipw_get_ordinal()
8097 * function used to poll the hardware vs. making unecessary calls.
8101 static int ipw_wx_get_name(struct net_device *dev,
8102 struct iw_request_info *info,
8103 union iwreq_data *wrqu, char *extra)
8105 struct ipw_priv *priv = ieee80211_priv(dev);
8106 mutex_lock(&priv->mutex);
8107 if (priv->status & STATUS_RF_KILL_MASK)
8108 strcpy(wrqu->name, "radio off");
8109 else if (!(priv->status & STATUS_ASSOCIATED))
8110 strcpy(wrqu->name, "unassociated");
8112 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8113 ipw_modes[priv->assoc_request.ieee_mode]);
8114 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
8115 mutex_unlock(&priv->mutex);
8119 static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8122 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8123 priv->config &= ~CFG_STATIC_CHANNEL;
8124 IPW_DEBUG_ASSOC("Attempting to associate with new "
8126 ipw_associate(priv);
8130 priv->config |= CFG_STATIC_CHANNEL;
8132 if (priv->channel == channel) {
8133 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8138 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8139 priv->channel = channel;
8141 #ifdef CONFIG_IPW2200_MONITOR
8142 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
8144 if (priv->status & STATUS_SCANNING) {
8145 IPW_DEBUG_SCAN("Scan abort triggered due to "
8146 "channel change.\n");
8147 ipw_abort_scan(priv);
8150 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8153 if (priv->status & STATUS_SCANNING)
8154 IPW_DEBUG_SCAN("Still scanning...\n");
8156 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8161 #endif /* CONFIG_IPW2200_MONITOR */
8163 /* Network configuration changed -- force [re]association */
8164 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8165 if (!ipw_disassociate(priv))
8166 ipw_associate(priv);
8171 static int ipw_wx_set_freq(struct net_device *dev,
8172 struct iw_request_info *info,
8173 union iwreq_data *wrqu, char *extra)
8175 struct ipw_priv *priv = ieee80211_priv(dev);
8176 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
8177 struct iw_freq *fwrq = &wrqu->freq;
8183 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
8184 mutex_lock(&priv->mutex);
8185 ret = ipw_set_channel(priv, 0);
8186 mutex_unlock(&priv->mutex);
8189 /* if setting by freq convert to channel */
8191 channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
8197 if (!(band = ieee80211_is_valid_channel(priv->ieee, channel)))
8200 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
8201 i = ieee80211_channel_to_index(priv->ieee, channel);
8205 flags = (band == IEEE80211_24GHZ_BAND) ?
8206 geo->bg[i].flags : geo->a[i].flags;
8207 if (flags & IEEE80211_CH_PASSIVE_ONLY) {
8208 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8213 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
8214 mutex_lock(&priv->mutex);
8215 ret = ipw_set_channel(priv, channel);
8216 mutex_unlock(&priv->mutex);
8220 static int ipw_wx_get_freq(struct net_device *dev,
8221 struct iw_request_info *info,
8222 union iwreq_data *wrqu, char *extra)
8224 struct ipw_priv *priv = ieee80211_priv(dev);
8228 /* If we are associated, trying to associate, or have a statically
8229 * configured CHANNEL then return that; otherwise return ANY */
8230 mutex_lock(&priv->mutex);
8231 if (priv->config & CFG_STATIC_CHANNEL ||
8232 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8233 wrqu->freq.m = priv->channel;
8237 mutex_unlock(&priv->mutex);
8238 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8242 static int ipw_wx_set_mode(struct net_device *dev,
8243 struct iw_request_info *info,
8244 union iwreq_data *wrqu, char *extra)
8246 struct ipw_priv *priv = ieee80211_priv(dev);
8249 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8251 switch (wrqu->mode) {
8252 #ifdef CONFIG_IPW2200_MONITOR
8253 case IW_MODE_MONITOR:
8259 wrqu->mode = IW_MODE_INFRA;
8264 if (wrqu->mode == priv->ieee->iw_mode)
8267 mutex_lock(&priv->mutex);
8269 ipw_sw_reset(priv, 0);
8271 #ifdef CONFIG_IPW2200_MONITOR
8272 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
8273 priv->net_dev->type = ARPHRD_ETHER;
8275 if (wrqu->mode == IW_MODE_MONITOR)
8276 #ifdef CONFIG_IEEE80211_RADIOTAP
8277 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8279 priv->net_dev->type = ARPHRD_IEEE80211;
8281 #endif /* CONFIG_IPW2200_MONITOR */
8283 /* Free the existing firmware and reset the fw_loaded
8284 * flag so ipw_load() will bring in the new firmawre */
8287 priv->ieee->iw_mode = wrqu->mode;
8289 queue_work(priv->workqueue, &priv->adapter_restart);
8290 mutex_unlock(&priv->mutex);
8294 static int ipw_wx_get_mode(struct net_device *dev,
8295 struct iw_request_info *info,
8296 union iwreq_data *wrqu, char *extra)
8298 struct ipw_priv *priv = ieee80211_priv(dev);
8299 mutex_lock(&priv->mutex);
8300 wrqu->mode = priv->ieee->iw_mode;
8301 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
8302 mutex_unlock(&priv->mutex);
8306 /* Values are in microsecond */
8307 static const s32 timeout_duration[] = {
8315 static const s32 period_duration[] = {
8323 static int ipw_wx_get_range(struct net_device *dev,
8324 struct iw_request_info *info,
8325 union iwreq_data *wrqu, char *extra)
8327 struct ipw_priv *priv = ieee80211_priv(dev);
8328 struct iw_range *range = (struct iw_range *)extra;
8329 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
8332 wrqu->data.length = sizeof(*range);
8333 memset(range, 0, sizeof(*range));
8335 /* 54Mbs == ~27 Mb/s real (802.11g) */
8336 range->throughput = 27 * 1000 * 1000;
8338 range->max_qual.qual = 100;
8339 /* TODO: Find real max RSSI and stick here */
8340 range->max_qual.level = 0;
8341 range->max_qual.noise = 0;
8342 range->max_qual.updated = 7; /* Updated all three */
8344 range->avg_qual.qual = 70;
8345 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
8346 range->avg_qual.level = 0; /* FIXME to real average level */
8347 range->avg_qual.noise = 0;
8348 range->avg_qual.updated = 7; /* Updated all three */
8349 mutex_lock(&priv->mutex);
8350 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
8352 for (i = 0; i < range->num_bitrates; i++)
8353 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
8356 range->max_rts = DEFAULT_RTS_THRESHOLD;
8357 range->min_frag = MIN_FRAG_THRESHOLD;
8358 range->max_frag = MAX_FRAG_THRESHOLD;
8360 range->encoding_size[0] = 5;
8361 range->encoding_size[1] = 13;
8362 range->num_encoding_sizes = 2;
8363 range->max_encoding_tokens = WEP_KEYS;
8365 /* Set the Wireless Extension versions */
8366 range->we_version_compiled = WIRELESS_EXT;
8367 range->we_version_source = 18;
8370 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
8371 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8372 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8373 (geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8376 range->freq[i].i = geo->bg[j].channel;
8377 range->freq[i].m = geo->bg[j].freq * 100000;
8378 range->freq[i].e = 1;
8383 if (priv->ieee->mode & IEEE_A) {
8384 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8385 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8386 (geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8389 range->freq[i].i = geo->a[j].channel;
8390 range->freq[i].m = geo->a[j].freq * 100000;
8391 range->freq[i].e = 1;
8396 range->num_channels = i;
8397 range->num_frequency = i;
8399 mutex_unlock(&priv->mutex);
8401 /* Event capability (kernel + driver) */
8402 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8403 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
8404 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
8405 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
8406 range->event_capa[1] = IW_EVENT_CAPA_K_1;
8408 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8409 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8411 IPW_DEBUG_WX("GET Range\n");
8415 static int ipw_wx_set_wap(struct net_device *dev,
8416 struct iw_request_info *info,
8417 union iwreq_data *wrqu, char *extra)
8419 struct ipw_priv *priv = ieee80211_priv(dev);
8421 static const unsigned char any[] = {
8422 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8424 static const unsigned char off[] = {
8425 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8428 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
8430 mutex_lock(&priv->mutex);
8431 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8432 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8433 /* we disable mandatory BSSID association */
8434 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8435 priv->config &= ~CFG_STATIC_BSSID;
8436 IPW_DEBUG_ASSOC("Attempting to associate with new "
8438 ipw_associate(priv);
8439 mutex_unlock(&priv->mutex);
8443 priv->config |= CFG_STATIC_BSSID;
8444 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8445 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
8446 mutex_unlock(&priv->mutex);
8450 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8451 MAC_ARG(wrqu->ap_addr.sa_data));
8453 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8455 /* Network configuration changed -- force [re]association */
8456 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8457 if (!ipw_disassociate(priv))
8458 ipw_associate(priv);
8460 mutex_unlock(&priv->mutex);
8464 static int ipw_wx_get_wap(struct net_device *dev,
8465 struct iw_request_info *info,
8466 union iwreq_data *wrqu, char *extra)
8468 struct ipw_priv *priv = ieee80211_priv(dev);
8469 /* If we are associated, trying to associate, or have a statically
8470 * configured BSSID then return that; otherwise return ANY */
8471 mutex_lock(&priv->mutex);
8472 if (priv->config & CFG_STATIC_BSSID ||
8473 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8474 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
8475 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
8477 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8479 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8480 MAC_ARG(wrqu->ap_addr.sa_data));
8481 mutex_unlock(&priv->mutex);
8485 static int ipw_wx_set_essid(struct net_device *dev,
8486 struct iw_request_info *info,
8487 union iwreq_data *wrqu, char *extra)
8489 struct ipw_priv *priv = ieee80211_priv(dev);
8490 char *essid = ""; /* ANY */
8492 mutex_lock(&priv->mutex);
8493 if (wrqu->essid.flags && wrqu->essid.length) {
8494 length = wrqu->essid.length - 1;
8498 IPW_DEBUG_WX("Setting ESSID to ANY\n");
8499 if ((priv->config & CFG_STATIC_ESSID) &&
8500 !(priv->status & (STATUS_ASSOCIATED |
8501 STATUS_ASSOCIATING))) {
8502 IPW_DEBUG_ASSOC("Attempting to associate with new "
8504 priv->config &= ~CFG_STATIC_ESSID;
8505 ipw_associate(priv);
8507 mutex_unlock(&priv->mutex);
8511 length = min(length, IW_ESSID_MAX_SIZE);
8513 priv->config |= CFG_STATIC_ESSID;
8515 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8516 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
8517 mutex_unlock(&priv->mutex);
8521 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8524 priv->essid_len = length;
8525 memcpy(priv->essid, essid, priv->essid_len);
8527 /* Network configuration changed -- force [re]association */
8528 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8529 if (!ipw_disassociate(priv))
8530 ipw_associate(priv);
8532 mutex_unlock(&priv->mutex);
8536 static int ipw_wx_get_essid(struct net_device *dev,
8537 struct iw_request_info *info,
8538 union iwreq_data *wrqu, char *extra)
8540 struct ipw_priv *priv = ieee80211_priv(dev);
8542 /* If we are associated, trying to associate, or have a statically
8543 * configured ESSID then return that; otherwise return ANY */
8544 mutex_lock(&priv->mutex);
8545 if (priv->config & CFG_STATIC_ESSID ||
8546 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8547 IPW_DEBUG_WX("Getting essid: '%s'\n",
8548 escape_essid(priv->essid, priv->essid_len));
8549 memcpy(extra, priv->essid, priv->essid_len);
8550 wrqu->essid.length = priv->essid_len;
8551 wrqu->essid.flags = 1; /* active */
8553 IPW_DEBUG_WX("Getting essid: ANY\n");
8554 wrqu->essid.length = 0;
8555 wrqu->essid.flags = 0; /* active */
8557 mutex_unlock(&priv->mutex);
8561 static int ipw_wx_set_nick(struct net_device *dev,
8562 struct iw_request_info *info,
8563 union iwreq_data *wrqu, char *extra)
8565 struct ipw_priv *priv = ieee80211_priv(dev);
8567 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8568 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8570 mutex_lock(&priv->mutex);
8571 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
8572 memset(priv->nick, 0, sizeof(priv->nick));
8573 memcpy(priv->nick, extra, wrqu->data.length);
8574 IPW_DEBUG_TRACE("<<\n");
8575 mutex_unlock(&priv->mutex);
8580 static int ipw_wx_get_nick(struct net_device *dev,
8581 struct iw_request_info *info,
8582 union iwreq_data *wrqu, char *extra)
8584 struct ipw_priv *priv = ieee80211_priv(dev);
8585 IPW_DEBUG_WX("Getting nick\n");
8586 mutex_lock(&priv->mutex);
8587 wrqu->data.length = strlen(priv->nick) + 1;
8588 memcpy(extra, priv->nick, wrqu->data.length);
8589 wrqu->data.flags = 1; /* active */
8590 mutex_unlock(&priv->mutex);
8594 static int ipw_wx_set_sens(struct net_device *dev,
8595 struct iw_request_info *info,
8596 union iwreq_data *wrqu, char *extra)
8598 struct ipw_priv *priv = ieee80211_priv(dev);
8601 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
8602 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
8603 mutex_lock(&priv->mutex);
8605 if (wrqu->sens.fixed == 0)
8607 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8608 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8611 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
8612 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
8617 priv->roaming_threshold = wrqu->sens.value;
8618 priv->disassociate_threshold = 3*wrqu->sens.value;
8620 mutex_unlock(&priv->mutex);
8624 static int ipw_wx_get_sens(struct net_device *dev,
8625 struct iw_request_info *info,
8626 union iwreq_data *wrqu, char *extra)
8628 struct ipw_priv *priv = ieee80211_priv(dev);
8629 mutex_lock(&priv->mutex);
8630 wrqu->sens.fixed = 1;
8631 wrqu->sens.value = priv->roaming_threshold;
8632 mutex_unlock(&priv->mutex);
8634 IPW_DEBUG_WX("GET roaming threshold -> %s %d \n",
8635 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
8640 static int ipw_wx_set_rate(struct net_device *dev,
8641 struct iw_request_info *info,
8642 union iwreq_data *wrqu, char *extra)
8644 /* TODO: We should use semaphores or locks for access to priv */
8645 struct ipw_priv *priv = ieee80211_priv(dev);
8646 u32 target_rate = wrqu->bitrate.value;
8649 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8650 /* value = X, fixed = 1 means only rate X */
8651 /* value = X, fixed = 0 means all rates lower equal X */
8653 if (target_rate == -1) {
8655 mask = IEEE80211_DEFAULT_RATES_MASK;
8656 /* Now we should reassociate */
8661 fixed = wrqu->bitrate.fixed;
8663 if (target_rate == 1000000 || !fixed)
8664 mask |= IEEE80211_CCK_RATE_1MB_MASK;
8665 if (target_rate == 1000000)
8668 if (target_rate == 2000000 || !fixed)
8669 mask |= IEEE80211_CCK_RATE_2MB_MASK;
8670 if (target_rate == 2000000)
8673 if (target_rate == 5500000 || !fixed)
8674 mask |= IEEE80211_CCK_RATE_5MB_MASK;
8675 if (target_rate == 5500000)
8678 if (target_rate == 6000000 || !fixed)
8679 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
8680 if (target_rate == 6000000)
8683 if (target_rate == 9000000 || !fixed)
8684 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
8685 if (target_rate == 9000000)
8688 if (target_rate == 11000000 || !fixed)
8689 mask |= IEEE80211_CCK_RATE_11MB_MASK;
8690 if (target_rate == 11000000)
8693 if (target_rate == 12000000 || !fixed)
8694 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
8695 if (target_rate == 12000000)
8698 if (target_rate == 18000000 || !fixed)
8699 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
8700 if (target_rate == 18000000)
8703 if (target_rate == 24000000 || !fixed)
8704 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
8705 if (target_rate == 24000000)
8708 if (target_rate == 36000000 || !fixed)
8709 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
8710 if (target_rate == 36000000)
8713 if (target_rate == 48000000 || !fixed)
8714 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
8715 if (target_rate == 48000000)
8718 if (target_rate == 54000000 || !fixed)
8719 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
8720 if (target_rate == 54000000)
8723 IPW_DEBUG_WX("invalid rate specified, returning error\n");
8727 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
8728 mask, fixed ? "fixed" : "sub-rates");
8729 mutex_lock(&priv->mutex);
8730 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
8731 priv->config &= ~CFG_FIXED_RATE;
8732 ipw_set_fixed_rate(priv, priv->ieee->mode);
8734 priv->config |= CFG_FIXED_RATE;
8736 if (priv->rates_mask == mask) {
8737 IPW_DEBUG_WX("Mask set to current mask.\n");
8738 mutex_unlock(&priv->mutex);
8742 priv->rates_mask = mask;
8744 /* Network configuration changed -- force [re]association */
8745 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
8746 if (!ipw_disassociate(priv))
8747 ipw_associate(priv);
8749 mutex_unlock(&priv->mutex);
8753 static int ipw_wx_get_rate(struct net_device *dev,
8754 struct iw_request_info *info,
8755 union iwreq_data *wrqu, char *extra)
8757 struct ipw_priv *priv = ieee80211_priv(dev);
8758 mutex_lock(&priv->mutex);
8759 wrqu->bitrate.value = priv->last_rate;
8760 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
8761 mutex_unlock(&priv->mutex);
8762 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
8766 static int ipw_wx_set_rts(struct net_device *dev,
8767 struct iw_request_info *info,
8768 union iwreq_data *wrqu, char *extra)
8770 struct ipw_priv *priv = ieee80211_priv(dev);
8771 mutex_lock(&priv->mutex);
8772 if (wrqu->rts.disabled)
8773 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8775 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
8776 wrqu->rts.value > MAX_RTS_THRESHOLD) {
8777 mutex_unlock(&priv->mutex);
8780 priv->rts_threshold = wrqu->rts.value;
8783 ipw_send_rts_threshold(priv, priv->rts_threshold);
8784 mutex_unlock(&priv->mutex);
8785 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
8789 static int ipw_wx_get_rts(struct net_device *dev,
8790 struct iw_request_info *info,
8791 union iwreq_data *wrqu, char *extra)
8793 struct ipw_priv *priv = ieee80211_priv(dev);
8794 mutex_lock(&priv->mutex);
8795 wrqu->rts.value = priv->rts_threshold;
8796 wrqu->rts.fixed = 0; /* no auto select */
8797 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
8798 mutex_unlock(&priv->mutex);
8799 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
8803 static int ipw_wx_set_txpow(struct net_device *dev,
8804 struct iw_request_info *info,
8805 union iwreq_data *wrqu, char *extra)
8807 struct ipw_priv *priv = ieee80211_priv(dev);
8810 mutex_lock(&priv->mutex);
8811 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
8816 if (!wrqu->power.fixed)
8817 wrqu->power.value = IPW_TX_POWER_DEFAULT;
8819 if (wrqu->power.flags != IW_TXPOW_DBM) {
8824 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
8825 (wrqu->power.value < IPW_TX_POWER_MIN)) {
8830 priv->tx_power = wrqu->power.value;
8831 err = ipw_set_tx_power(priv);
8833 mutex_unlock(&priv->mutex);
8837 static int ipw_wx_get_txpow(struct net_device *dev,
8838 struct iw_request_info *info,
8839 union iwreq_data *wrqu, char *extra)
8841 struct ipw_priv *priv = ieee80211_priv(dev);
8842 mutex_lock(&priv->mutex);
8843 wrqu->power.value = priv->tx_power;
8844 wrqu->power.fixed = 1;
8845 wrqu->power.flags = IW_TXPOW_DBM;
8846 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
8847 mutex_unlock(&priv->mutex);
8849 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
8850 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
8855 static int ipw_wx_set_frag(struct net_device *dev,
8856 struct iw_request_info *info,
8857 union iwreq_data *wrqu, char *extra)
8859 struct ipw_priv *priv = ieee80211_priv(dev);
8860 mutex_lock(&priv->mutex);
8861 if (wrqu->frag.disabled)
8862 priv->ieee->fts = DEFAULT_FTS;
8864 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
8865 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
8866 mutex_unlock(&priv->mutex);
8870 priv->ieee->fts = wrqu->frag.value & ~0x1;
8873 ipw_send_frag_threshold(priv, wrqu->frag.value);
8874 mutex_unlock(&priv->mutex);
8875 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
8879 static int ipw_wx_get_frag(struct net_device *dev,
8880 struct iw_request_info *info,
8881 union iwreq_data *wrqu, char *extra)
8883 struct ipw_priv *priv = ieee80211_priv(dev);
8884 mutex_lock(&priv->mutex);
8885 wrqu->frag.value = priv->ieee->fts;
8886 wrqu->frag.fixed = 0; /* no auto select */
8887 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
8888 mutex_unlock(&priv->mutex);
8889 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
8894 static int ipw_wx_set_retry(struct net_device *dev,
8895 struct iw_request_info *info,
8896 union iwreq_data *wrqu, char *extra)
8898 struct ipw_priv *priv = ieee80211_priv(dev);
8900 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
8903 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
8906 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
8909 mutex_lock(&priv->mutex);
8910 if (wrqu->retry.flags & IW_RETRY_MIN)
8911 priv->short_retry_limit = (u8) wrqu->retry.value;
8912 else if (wrqu->retry.flags & IW_RETRY_MAX)
8913 priv->long_retry_limit = (u8) wrqu->retry.value;
8915 priv->short_retry_limit = (u8) wrqu->retry.value;
8916 priv->long_retry_limit = (u8) wrqu->retry.value;
8919 ipw_send_retry_limit(priv, priv->short_retry_limit,
8920 priv->long_retry_limit);
8921 mutex_unlock(&priv->mutex);
8922 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
8923 priv->short_retry_limit, priv->long_retry_limit);
8927 static int ipw_wx_get_retry(struct net_device *dev,
8928 struct iw_request_info *info,
8929 union iwreq_data *wrqu, char *extra)
8931 struct ipw_priv *priv = ieee80211_priv(dev);
8933 mutex_lock(&priv->mutex);
8934 wrqu->retry.disabled = 0;
8936 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
8937 mutex_unlock(&priv->mutex);
8941 if (wrqu->retry.flags & IW_RETRY_MAX) {
8942 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
8943 wrqu->retry.value = priv->long_retry_limit;
8944 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
8945 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
8946 wrqu->retry.value = priv->short_retry_limit;
8948 wrqu->retry.flags = IW_RETRY_LIMIT;
8949 wrqu->retry.value = priv->short_retry_limit;
8951 mutex_unlock(&priv->mutex);
8953 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
8958 static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
8961 struct ipw_scan_request_ext scan;
8962 int err = 0, scan_type;
8964 if (!(priv->status & STATUS_INIT) ||
8965 (priv->status & STATUS_EXIT_PENDING))
8968 mutex_lock(&priv->mutex);
8970 if (priv->status & STATUS_RF_KILL_MASK) {
8971 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
8972 priv->status |= STATUS_SCAN_PENDING;
8976 IPW_DEBUG_HC("starting request direct scan!\n");
8978 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
8979 /* We should not sleep here; otherwise we will block most
8980 * of the system (for instance, we hold rtnl_lock when we
8986 memset(&scan, 0, sizeof(scan));
8988 if (priv->config & CFG_SPEED_SCAN)
8989 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
8992 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
8995 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
8997 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
8998 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
9000 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
9002 err = ipw_send_ssid(priv, essid, essid_len);
9004 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
9007 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
9009 ipw_add_scan_channels(priv, &scan, scan_type);
9011 err = ipw_send_scan_request_ext(priv, &scan);
9013 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
9017 priv->status |= STATUS_SCANNING;
9020 mutex_unlock(&priv->mutex);
9024 static int ipw_wx_set_scan(struct net_device *dev,
9025 struct iw_request_info *info,
9026 union iwreq_data *wrqu, char *extra)
9028 struct ipw_priv *priv = ieee80211_priv(dev);
9029 struct iw_scan_req *req = NULL;
9030 if (wrqu->data.length
9031 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9032 req = (struct iw_scan_req *)extra;
9033 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9034 ipw_request_direct_scan(priv, req->essid,
9040 IPW_DEBUG_WX("Start scan\n");
9042 queue_work(priv->workqueue, &priv->request_scan);
9047 static int ipw_wx_get_scan(struct net_device *dev,
9048 struct iw_request_info *info,
9049 union iwreq_data *wrqu, char *extra)
9051 struct ipw_priv *priv = ieee80211_priv(dev);
9052 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9055 static int ipw_wx_set_encode(struct net_device *dev,
9056 struct iw_request_info *info,
9057 union iwreq_data *wrqu, char *key)
9059 struct ipw_priv *priv = ieee80211_priv(dev);
9061 u32 cap = priv->capability;
9063 mutex_lock(&priv->mutex);
9064 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
9066 /* In IBSS mode, we need to notify the firmware to update
9067 * the beacon info after we changed the capability. */
9068 if (cap != priv->capability &&
9069 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9070 priv->status & STATUS_ASSOCIATED)
9071 ipw_disassociate(priv);
9073 mutex_unlock(&priv->mutex);
9077 static int ipw_wx_get_encode(struct net_device *dev,
9078 struct iw_request_info *info,
9079 union iwreq_data *wrqu, char *key)
9081 struct ipw_priv *priv = ieee80211_priv(dev);
9082 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9085 static int ipw_wx_set_power(struct net_device *dev,
9086 struct iw_request_info *info,
9087 union iwreq_data *wrqu, char *extra)
9089 struct ipw_priv *priv = ieee80211_priv(dev);
9091 mutex_lock(&priv->mutex);
9092 if (wrqu->power.disabled) {
9093 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9094 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9096 IPW_DEBUG_WX("failed setting power mode.\n");
9097 mutex_unlock(&priv->mutex);
9100 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
9101 mutex_unlock(&priv->mutex);
9105 switch (wrqu->power.flags & IW_POWER_MODE) {
9106 case IW_POWER_ON: /* If not specified */
9107 case IW_POWER_MODE: /* If set all mask */
9108 case IW_POWER_ALL_R: /* If explicitely state all */
9110 default: /* Otherwise we don't support it */
9111 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9113 mutex_unlock(&priv->mutex);
9117 /* If the user hasn't specified a power management mode yet, default
9119 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
9120 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
9122 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9123 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9125 IPW_DEBUG_WX("failed setting power mode.\n");
9126 mutex_unlock(&priv->mutex);
9130 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
9131 mutex_unlock(&priv->mutex);
9135 static int ipw_wx_get_power(struct net_device *dev,
9136 struct iw_request_info *info,
9137 union iwreq_data *wrqu, char *extra)
9139 struct ipw_priv *priv = ieee80211_priv(dev);
9140 mutex_lock(&priv->mutex);
9141 if (!(priv->power_mode & IPW_POWER_ENABLED))
9142 wrqu->power.disabled = 1;
9144 wrqu->power.disabled = 0;
9146 mutex_unlock(&priv->mutex);
9147 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
9152 static int ipw_wx_set_powermode(struct net_device *dev,
9153 struct iw_request_info *info,
9154 union iwreq_data *wrqu, char *extra)
9156 struct ipw_priv *priv = ieee80211_priv(dev);
9157 int mode = *(int *)extra;
9159 mutex_lock(&priv->mutex);
9160 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9161 mode = IPW_POWER_AC;
9162 priv->power_mode = mode;
9164 priv->power_mode = IPW_POWER_ENABLED | mode;
9167 if (priv->power_mode != mode) {
9168 err = ipw_send_power_mode(priv, mode);
9171 IPW_DEBUG_WX("failed setting power mode.\n");
9172 mutex_unlock(&priv->mutex);
9176 mutex_unlock(&priv->mutex);
9180 #define MAX_WX_STRING 80
9181 static int ipw_wx_get_powermode(struct net_device *dev,
9182 struct iw_request_info *info,
9183 union iwreq_data *wrqu, char *extra)
9185 struct ipw_priv *priv = ieee80211_priv(dev);
9186 int level = IPW_POWER_LEVEL(priv->power_mode);
9189 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9193 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9195 case IPW_POWER_BATTERY:
9196 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9199 p += snprintf(p, MAX_WX_STRING - (p - extra),
9200 "(Timeout %dms, Period %dms)",
9201 timeout_duration[level - 1] / 1000,
9202 period_duration[level - 1] / 1000);
9205 if (!(priv->power_mode & IPW_POWER_ENABLED))
9206 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
9208 wrqu->data.length = p - extra + 1;
9213 static int ipw_wx_set_wireless_mode(struct net_device *dev,
9214 struct iw_request_info *info,
9215 union iwreq_data *wrqu, char *extra)
9217 struct ipw_priv *priv = ieee80211_priv(dev);
9218 int mode = *(int *)extra;
9219 u8 band = 0, modulation = 0;
9221 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
9222 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
9225 mutex_lock(&priv->mutex);
9226 if (priv->adapter == IPW_2915ABG) {
9227 priv->ieee->abg_true = 1;
9228 if (mode & IEEE_A) {
9229 band |= IEEE80211_52GHZ_BAND;
9230 modulation |= IEEE80211_OFDM_MODULATION;
9232 priv->ieee->abg_true = 0;
9234 if (mode & IEEE_A) {
9235 IPW_WARNING("Attempt to set 2200BG into "
9237 mutex_unlock(&priv->mutex);
9241 priv->ieee->abg_true = 0;
9244 if (mode & IEEE_B) {
9245 band |= IEEE80211_24GHZ_BAND;
9246 modulation |= IEEE80211_CCK_MODULATION;
9248 priv->ieee->abg_true = 0;
9250 if (mode & IEEE_G) {
9251 band |= IEEE80211_24GHZ_BAND;
9252 modulation |= IEEE80211_OFDM_MODULATION;
9254 priv->ieee->abg_true = 0;
9256 priv->ieee->mode = mode;
9257 priv->ieee->freq_band = band;
9258 priv->ieee->modulation = modulation;
9259 init_supported_rates(priv, &priv->rates);
9261 /* Network configuration changed -- force [re]association */
9262 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9263 if (!ipw_disassociate(priv)) {
9264 ipw_send_supported_rates(priv, &priv->rates);
9265 ipw_associate(priv);
9268 /* Update the band LEDs */
9269 ipw_led_band_on(priv);
9271 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
9272 mode & IEEE_A ? 'a' : '.',
9273 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
9274 mutex_unlock(&priv->mutex);
9278 static int ipw_wx_get_wireless_mode(struct net_device *dev,
9279 struct iw_request_info *info,
9280 union iwreq_data *wrqu, char *extra)
9282 struct ipw_priv *priv = ieee80211_priv(dev);
9283 mutex_lock(&priv->mutex);
9284 switch (priv->ieee->mode) {
9286 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9289 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9291 case IEEE_A | IEEE_B:
9292 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9295 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9297 case IEEE_A | IEEE_G:
9298 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9300 case IEEE_B | IEEE_G:
9301 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9303 case IEEE_A | IEEE_B | IEEE_G:
9304 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9307 strncpy(extra, "unknown", MAX_WX_STRING);
9311 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9313 wrqu->data.length = strlen(extra) + 1;
9314 mutex_unlock(&priv->mutex);
9319 static int ipw_wx_set_preamble(struct net_device *dev,
9320 struct iw_request_info *info,
9321 union iwreq_data *wrqu, char *extra)
9323 struct ipw_priv *priv = ieee80211_priv(dev);
9324 int mode = *(int *)extra;
9325 mutex_lock(&priv->mutex);
9326 /* Switching from SHORT -> LONG requires a disassociation */
9328 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9329 priv->config |= CFG_PREAMBLE_LONG;
9331 /* Network configuration changed -- force [re]association */
9333 ("[re]association triggered due to preamble change.\n");
9334 if (!ipw_disassociate(priv))
9335 ipw_associate(priv);
9341 priv->config &= ~CFG_PREAMBLE_LONG;
9344 mutex_unlock(&priv->mutex);
9348 mutex_unlock(&priv->mutex);
9352 static int ipw_wx_get_preamble(struct net_device *dev,
9353 struct iw_request_info *info,
9354 union iwreq_data *wrqu, char *extra)
9356 struct ipw_priv *priv = ieee80211_priv(dev);
9357 mutex_lock(&priv->mutex);
9358 if (priv->config & CFG_PREAMBLE_LONG)
9359 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9361 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
9362 mutex_unlock(&priv->mutex);
9366 #ifdef CONFIG_IPW2200_MONITOR
9367 static int ipw_wx_set_monitor(struct net_device *dev,
9368 struct iw_request_info *info,
9369 union iwreq_data *wrqu, char *extra)
9371 struct ipw_priv *priv = ieee80211_priv(dev);
9372 int *parms = (int *)extra;
9373 int enable = (parms[0] > 0);
9374 mutex_lock(&priv->mutex);
9375 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
9377 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9378 #ifdef CONFIG_IEEE80211_RADIOTAP
9379 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9381 priv->net_dev->type = ARPHRD_IEEE80211;
9383 queue_work(priv->workqueue, &priv->adapter_restart);
9386 ipw_set_channel(priv, parms[1]);
9388 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9389 mutex_unlock(&priv->mutex);
9392 priv->net_dev->type = ARPHRD_ETHER;
9393 queue_work(priv->workqueue, &priv->adapter_restart);
9395 mutex_unlock(&priv->mutex);
9399 #endif // CONFIG_IPW2200_MONITOR
9401 static int ipw_wx_reset(struct net_device *dev,
9402 struct iw_request_info *info,
9403 union iwreq_data *wrqu, char *extra)
9405 struct ipw_priv *priv = ieee80211_priv(dev);
9406 IPW_DEBUG_WX("RESET\n");
9407 queue_work(priv->workqueue, &priv->adapter_restart);
9411 static int ipw_wx_sw_reset(struct net_device *dev,
9412 struct iw_request_info *info,
9413 union iwreq_data *wrqu, char *extra)
9415 struct ipw_priv *priv = ieee80211_priv(dev);
9416 union iwreq_data wrqu_sec = {
9418 .flags = IW_ENCODE_DISABLED,
9423 IPW_DEBUG_WX("SW_RESET\n");
9425 mutex_lock(&priv->mutex);
9427 ret = ipw_sw_reset(priv, 2);
9430 ipw_adapter_restart(priv);
9433 /* The SW reset bit might have been toggled on by the 'disable'
9434 * module parameter, so take appropriate action */
9435 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9437 mutex_unlock(&priv->mutex);
9438 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
9439 mutex_lock(&priv->mutex);
9441 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9442 /* Configuration likely changed -- force [re]association */
9443 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9445 if (!ipw_disassociate(priv))
9446 ipw_associate(priv);
9449 mutex_unlock(&priv->mutex);
9454 /* Rebase the WE IOCTLs to zero for the handler array */
9455 #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
9456 static iw_handler ipw_wx_handlers[] = {
9457 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9458 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9459 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9460 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9461 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
9462 IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens,
9463 IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens,
9464 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9465 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9466 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9467 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9468 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9469 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9470 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9471 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9472 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9473 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9474 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9475 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9476 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9477 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9478 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9479 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9480 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9481 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9482 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9483 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9484 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9485 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9486 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
9487 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9488 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9489 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9490 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
9491 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9492 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9493 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9494 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9495 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9496 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9497 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
9501 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9505 IPW_PRIV_SET_PREAMBLE,
9506 IPW_PRIV_GET_PREAMBLE,
9509 #ifdef CONFIG_IPW2200_MONITOR
9510 IPW_PRIV_SET_MONITOR,
9514 static struct iw_priv_args ipw_priv_args[] = {
9516 .cmd = IPW_PRIV_SET_POWER,
9517 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9518 .name = "set_power"},
9520 .cmd = IPW_PRIV_GET_POWER,
9521 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9522 .name = "get_power"},
9524 .cmd = IPW_PRIV_SET_MODE,
9525 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9526 .name = "set_mode"},
9528 .cmd = IPW_PRIV_GET_MODE,
9529 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9530 .name = "get_mode"},
9532 .cmd = IPW_PRIV_SET_PREAMBLE,
9533 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9534 .name = "set_preamble"},
9536 .cmd = IPW_PRIV_GET_PREAMBLE,
9537 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9538 .name = "get_preamble"},
9541 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
9544 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9545 #ifdef CONFIG_IPW2200_MONITOR
9547 IPW_PRIV_SET_MONITOR,
9548 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9549 #endif /* CONFIG_IPW2200_MONITOR */
9552 static iw_handler ipw_priv_handler[] = {
9553 ipw_wx_set_powermode,
9554 ipw_wx_get_powermode,
9555 ipw_wx_set_wireless_mode,
9556 ipw_wx_get_wireless_mode,
9557 ipw_wx_set_preamble,
9558 ipw_wx_get_preamble,
9561 #ifdef CONFIG_IPW2200_MONITOR
9566 static struct iw_handler_def ipw_wx_handler_def = {
9567 .standard = ipw_wx_handlers,
9568 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9569 .num_private = ARRAY_SIZE(ipw_priv_handler),
9570 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9571 .private = ipw_priv_handler,
9572 .private_args = ipw_priv_args,
9573 .get_wireless_stats = ipw_get_wireless_stats,
9577 * Get wireless statistics.
9578 * Called by /proc/net/wireless
9579 * Also called by SIOCGIWSTATS
9581 static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
9583 struct ipw_priv *priv = ieee80211_priv(dev);
9584 struct iw_statistics *wstats;
9586 wstats = &priv->wstats;
9588 /* if hw is disabled, then ipw_get_ordinal() can't be called.
9589 * netdev->get_wireless_stats seems to be called before fw is
9590 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9591 * and associated; if not associcated, the values are all meaningless
9592 * anyway, so set them all to NULL and INVALID */
9593 if (!(priv->status & STATUS_ASSOCIATED)) {
9594 wstats->miss.beacon = 0;
9595 wstats->discard.retries = 0;
9596 wstats->qual.qual = 0;
9597 wstats->qual.level = 0;
9598 wstats->qual.noise = 0;
9599 wstats->qual.updated = 7;
9600 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
9601 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
9605 wstats->qual.qual = priv->quality;
9606 wstats->qual.level = priv->exp_avg_rssi;
9607 wstats->qual.noise = priv->exp_avg_noise;
9608 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
9609 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
9611 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9612 wstats->discard.retries = priv->last_tx_failures;
9613 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
9615 /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9616 goto fail_get_ordinal;
9617 wstats->discard.retries += tx_retry; */
9622 /* net device stuff */
9624 static void init_sys_config(struct ipw_sys_config *sys_config)
9626 memset(sys_config, 0, sizeof(struct ipw_sys_config));
9627 sys_config->bt_coexistence = 0;
9628 sys_config->answer_broadcast_ssid_probe = 0;
9629 sys_config->accept_all_data_frames = 0;
9630 sys_config->accept_non_directed_frames = 1;
9631 sys_config->exclude_unicast_unencrypted = 0;
9632 sys_config->disable_unicast_decryption = 1;
9633 sys_config->exclude_multicast_unencrypted = 0;
9634 sys_config->disable_multicast_decryption = 1;
9635 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
9636 antenna = CFG_SYS_ANTENNA_BOTH;
9637 sys_config->antenna_diversity = antenna;
9638 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
9639 sys_config->dot11g_auto_detection = 0;
9640 sys_config->enable_cts_to_self = 0;
9641 sys_config->bt_coexist_collision_thr = 0;
9642 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
9643 sys_config->silence_threshold = 0x1e;
9646 static int ipw_net_open(struct net_device *dev)
9648 struct ipw_priv *priv = ieee80211_priv(dev);
9649 IPW_DEBUG_INFO("dev->open\n");
9650 /* we should be verifying the device is ready to be opened */
9651 mutex_lock(&priv->mutex);
9652 if (!(priv->status & STATUS_RF_KILL_MASK) &&
9653 (priv->status & STATUS_ASSOCIATED))
9654 netif_start_queue(dev);
9655 mutex_unlock(&priv->mutex);
9659 static int ipw_net_stop(struct net_device *dev)
9661 IPW_DEBUG_INFO("dev->close\n");
9662 netif_stop_queue(dev);
9669 modify to send one tfd per fragment instead of using chunking. otherwise
9670 we need to heavily modify the ieee80211_skb_to_txb.
9673 static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
9676 struct ieee80211_hdr_3addrqos *hdr = (struct ieee80211_hdr_3addrqos *)
9677 txb->fragments[0]->data;
9679 struct tfd_frame *tfd;
9680 #ifdef CONFIG_IPW_QOS
9681 int tx_id = ipw_get_tx_queue_number(priv, pri);
9682 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9684 struct clx2_tx_queue *txq = &priv->txq[0];
9686 struct clx2_queue *q = &txq->q;
9687 u8 id, hdr_len, unicast;
9688 u16 remaining_bytes;
9691 hdr_len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
9692 switch (priv->ieee->iw_mode) {
9694 unicast = !is_multicast_ether_addr(hdr->addr1);
9695 id = ipw_find_station(priv, hdr->addr1);
9696 if (id == IPW_INVALID_STATION) {
9697 id = ipw_add_station(priv, hdr->addr1);
9698 if (id == IPW_INVALID_STATION) {
9699 IPW_WARNING("Attempt to send data to "
9700 "invalid cell: " MAC_FMT "\n",
9701 MAC_ARG(hdr->addr1));
9709 unicast = !is_multicast_ether_addr(hdr->addr3);
9714 tfd = &txq->bd[q->first_empty];
9715 txq->txb[q->first_empty] = txb;
9716 memset(tfd, 0, sizeof(*tfd));
9717 tfd->u.data.station_number = id;
9719 tfd->control_flags.message_type = TX_FRAME_TYPE;
9720 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
9722 tfd->u.data.cmd_id = DINO_CMD_TX;
9723 tfd->u.data.len = cpu_to_le16(txb->payload_size);
9724 remaining_bytes = txb->payload_size;
9726 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
9727 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
9729 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
9731 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
9732 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
9734 fc = le16_to_cpu(hdr->frame_ctl);
9735 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
9737 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
9739 if (likely(unicast))
9740 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9742 if (txb->encrypted && !priv->ieee->host_encrypt) {
9743 switch (priv->ieee->sec.level) {
9745 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9746 IEEE80211_FCTL_PROTECTED;
9747 /* XXX: ACK flag must be set for CCMP even if it
9748 * is a multicast/broadcast packet, because CCMP
9749 * group communication encrypted by GTK is
9750 * actually done by the AP. */
9752 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9754 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9755 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
9756 tfd->u.data.key_index = 0;
9757 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
9760 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9761 IEEE80211_FCTL_PROTECTED;
9762 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9763 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
9764 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
9767 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9768 IEEE80211_FCTL_PROTECTED;
9769 tfd->u.data.key_index = priv->ieee->tx_keyidx;
9770 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
9772 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
9774 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
9779 printk(KERN_ERR "Unknow security level %d\n",
9780 priv->ieee->sec.level);
9784 /* No hardware encryption */
9785 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
9787 #ifdef CONFIG_IPW_QOS
9788 if (fc & IEEE80211_STYPE_QOS_DATA)
9789 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
9790 #endif /* CONFIG_IPW_QOS */
9793 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
9795 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
9796 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
9797 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
9798 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
9799 i, le32_to_cpu(tfd->u.data.num_chunks),
9800 txb->fragments[i]->len - hdr_len);
9801 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
9802 i, tfd->u.data.num_chunks,
9803 txb->fragments[i]->len - hdr_len);
9804 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
9805 txb->fragments[i]->len - hdr_len);
9807 tfd->u.data.chunk_ptr[i] =
9808 cpu_to_le32(pci_map_single
9810 txb->fragments[i]->data + hdr_len,
9811 txb->fragments[i]->len - hdr_len,
9813 tfd->u.data.chunk_len[i] =
9814 cpu_to_le16(txb->fragments[i]->len - hdr_len);
9817 if (i != txb->nr_frags) {
9818 struct sk_buff *skb;
9819 u16 remaining_bytes = 0;
9822 for (j = i; j < txb->nr_frags; j++)
9823 remaining_bytes += txb->fragments[j]->len - hdr_len;
9825 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
9827 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
9829 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
9830 for (j = i; j < txb->nr_frags; j++) {
9831 int size = txb->fragments[j]->len - hdr_len;
9833 printk(KERN_INFO "Adding frag %d %d...\n",
9835 memcpy(skb_put(skb, size),
9836 txb->fragments[j]->data + hdr_len, size);
9838 dev_kfree_skb_any(txb->fragments[i]);
9839 txb->fragments[i] = skb;
9840 tfd->u.data.chunk_ptr[i] =
9841 cpu_to_le32(pci_map_single
9842 (priv->pci_dev, skb->data,
9843 tfd->u.data.chunk_len[i],
9846 tfd->u.data.num_chunks =
9847 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
9853 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
9854 ipw_write32(priv, q->reg_w, q->first_empty);
9856 if (ipw_queue_space(q) < q->high_mark)
9857 netif_stop_queue(priv->net_dev);
9859 return NETDEV_TX_OK;
9862 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
9863 ieee80211_txb_free(txb);
9864 return NETDEV_TX_OK;
9867 static int ipw_net_is_queue_full(struct net_device *dev, int pri)
9869 struct ipw_priv *priv = ieee80211_priv(dev);
9870 #ifdef CONFIG_IPW_QOS
9871 int tx_id = ipw_get_tx_queue_number(priv, pri);
9872 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9874 struct clx2_tx_queue *txq = &priv->txq[0];
9875 #endif /* CONFIG_IPW_QOS */
9877 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
9883 static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
9884 struct net_device *dev, int pri)
9886 struct ipw_priv *priv = ieee80211_priv(dev);
9887 unsigned long flags;
9890 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
9891 spin_lock_irqsave(&priv->lock, flags);
9893 if (!(priv->status & STATUS_ASSOCIATED)) {
9894 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
9895 priv->ieee->stats.tx_carrier_errors++;
9896 netif_stop_queue(dev);
9900 ret = ipw_tx_skb(priv, txb, pri);
9901 if (ret == NETDEV_TX_OK)
9902 __ipw_led_activity_on(priv);
9903 spin_unlock_irqrestore(&priv->lock, flags);
9908 spin_unlock_irqrestore(&priv->lock, flags);
9912 static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
9914 struct ipw_priv *priv = ieee80211_priv(dev);
9916 priv->ieee->stats.tx_packets = priv->tx_packets;
9917 priv->ieee->stats.rx_packets = priv->rx_packets;
9918 return &priv->ieee->stats;
9921 static void ipw_net_set_multicast_list(struct net_device *dev)
9926 static int ipw_net_set_mac_address(struct net_device *dev, void *p)
9928 struct ipw_priv *priv = ieee80211_priv(dev);
9929 struct sockaddr *addr = p;
9930 if (!is_valid_ether_addr(addr->sa_data))
9931 return -EADDRNOTAVAIL;
9932 mutex_lock(&priv->mutex);
9933 priv->config |= CFG_CUSTOM_MAC;
9934 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
9935 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
9936 priv->net_dev->name, MAC_ARG(priv->mac_addr));
9937 queue_work(priv->workqueue, &priv->adapter_restart);
9938 mutex_unlock(&priv->mutex);
9942 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
9943 struct ethtool_drvinfo *info)
9945 struct ipw_priv *p = ieee80211_priv(dev);
9950 strcpy(info->driver, DRV_NAME);
9951 strcpy(info->version, DRV_VERSION);
9954 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
9956 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
9958 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
9960 strcpy(info->bus_info, pci_name(p->pci_dev));
9961 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
9964 static u32 ipw_ethtool_get_link(struct net_device *dev)
9966 struct ipw_priv *priv = ieee80211_priv(dev);
9967 return (priv->status & STATUS_ASSOCIATED) != 0;
9970 static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
9972 return IPW_EEPROM_IMAGE_SIZE;
9975 static int ipw_ethtool_get_eeprom(struct net_device *dev,
9976 struct ethtool_eeprom *eeprom, u8 * bytes)
9978 struct ipw_priv *p = ieee80211_priv(dev);
9980 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
9982 mutex_lock(&p->mutex);
9983 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
9984 mutex_unlock(&p->mutex);
9988 static int ipw_ethtool_set_eeprom(struct net_device *dev,
9989 struct ethtool_eeprom *eeprom, u8 * bytes)
9991 struct ipw_priv *p = ieee80211_priv(dev);
9994 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
9996 mutex_lock(&p->mutex);
9997 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
9998 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
9999 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
10000 mutex_unlock(&p->mutex);
10004 static struct ethtool_ops ipw_ethtool_ops = {
10005 .get_link = ipw_ethtool_get_link,
10006 .get_drvinfo = ipw_ethtool_get_drvinfo,
10007 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10008 .get_eeprom = ipw_ethtool_get_eeprom,
10009 .set_eeprom = ipw_ethtool_set_eeprom,
10012 static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
10014 struct ipw_priv *priv = data;
10015 u32 inta, inta_mask;
10020 spin_lock(&priv->lock);
10022 if (!(priv->status & STATUS_INT_ENABLED)) {
10027 inta = ipw_read32(priv, IPW_INTA_RW);
10028 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
10030 if (inta == 0xFFFFFFFF) {
10031 /* Hardware disappeared */
10032 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10036 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
10037 /* Shared interrupt */
10041 /* tell the device to stop sending interrupts */
10042 ipw_disable_interrupts(priv);
10044 /* ack current interrupts */
10045 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10046 ipw_write32(priv, IPW_INTA_RW, inta);
10048 /* Cache INTA value for our tasklet */
10049 priv->isr_inta = inta;
10051 tasklet_schedule(&priv->irq_tasklet);
10053 spin_unlock(&priv->lock);
10055 return IRQ_HANDLED;
10057 spin_unlock(&priv->lock);
10061 static void ipw_rf_kill(void *adapter)
10063 struct ipw_priv *priv = adapter;
10064 unsigned long flags;
10066 spin_lock_irqsave(&priv->lock, flags);
10068 if (rf_kill_active(priv)) {
10069 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10070 if (priv->workqueue)
10071 queue_delayed_work(priv->workqueue,
10072 &priv->rf_kill, 2 * HZ);
10076 /* RF Kill is now disabled, so bring the device back up */
10078 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10079 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10082 /* we can not do an adapter restart while inside an irq lock */
10083 queue_work(priv->workqueue, &priv->adapter_restart);
10085 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10089 spin_unlock_irqrestore(&priv->lock, flags);
10092 static void ipw_bg_rf_kill(void *data)
10094 struct ipw_priv *priv = data;
10095 mutex_lock(&priv->mutex);
10097 mutex_unlock(&priv->mutex);
10100 static void ipw_link_up(struct ipw_priv *priv)
10102 priv->last_seq_num = -1;
10103 priv->last_frag_num = -1;
10104 priv->last_packet_time = 0;
10106 netif_carrier_on(priv->net_dev);
10107 if (netif_queue_stopped(priv->net_dev)) {
10108 IPW_DEBUG_NOTIF("waking queue\n");
10109 netif_wake_queue(priv->net_dev);
10111 IPW_DEBUG_NOTIF("starting queue\n");
10112 netif_start_queue(priv->net_dev);
10115 cancel_delayed_work(&priv->request_scan);
10116 ipw_reset_stats(priv);
10117 /* Ensure the rate is updated immediately */
10118 priv->last_rate = ipw_get_current_rate(priv);
10119 ipw_gather_stats(priv);
10120 ipw_led_link_up(priv);
10121 notify_wx_assoc_event(priv);
10123 if (priv->config & CFG_BACKGROUND_SCAN)
10124 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10127 static void ipw_bg_link_up(void *data)
10129 struct ipw_priv *priv = data;
10130 mutex_lock(&priv->mutex);
10132 mutex_unlock(&priv->mutex);
10135 static void ipw_link_down(struct ipw_priv *priv)
10137 ipw_led_link_down(priv);
10138 netif_carrier_off(priv->net_dev);
10139 netif_stop_queue(priv->net_dev);
10140 notify_wx_assoc_event(priv);
10142 /* Cancel any queued work ... */
10143 cancel_delayed_work(&priv->request_scan);
10144 cancel_delayed_work(&priv->adhoc_check);
10145 cancel_delayed_work(&priv->gather_stats);
10147 ipw_reset_stats(priv);
10149 if (!(priv->status & STATUS_EXIT_PENDING)) {
10150 /* Queue up another scan... */
10151 queue_work(priv->workqueue, &priv->request_scan);
10155 static void ipw_bg_link_down(void *data)
10157 struct ipw_priv *priv = data;
10158 mutex_lock(&priv->mutex);
10159 ipw_link_down(data);
10160 mutex_unlock(&priv->mutex);
10163 static int ipw_setup_deferred_work(struct ipw_priv *priv)
10167 priv->workqueue = create_workqueue(DRV_NAME);
10168 init_waitqueue_head(&priv->wait_command_queue);
10169 init_waitqueue_head(&priv->wait_state);
10171 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10172 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10173 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
10174 INIT_WORK(&priv->system_config, ipw_system_config, priv);
10175 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10176 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10177 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10178 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10179 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
10180 INIT_WORK(&priv->request_scan,
10181 (void (*)(void *))ipw_request_scan, priv);
10182 INIT_WORK(&priv->gather_stats,
10183 (void (*)(void *))ipw_bg_gather_stats, priv);
10184 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10185 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10186 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10187 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10188 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10189 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
10191 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
10193 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10195 INIT_WORK(&priv->merge_networks,
10196 (void (*)(void *))ipw_merge_adhoc_network, priv);
10198 #ifdef CONFIG_IPW_QOS
10199 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10201 #endif /* CONFIG_IPW_QOS */
10203 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10204 ipw_irq_tasklet, (unsigned long)priv);
10209 static void shim__set_security(struct net_device *dev,
10210 struct ieee80211_security *sec)
10212 struct ipw_priv *priv = ieee80211_priv(dev);
10214 for (i = 0; i < 4; i++) {
10215 if (sec->flags & (1 << i)) {
10216 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
10217 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
10218 if (sec->key_sizes[i] == 0)
10219 priv->ieee->sec.flags &= ~(1 << i);
10221 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
10222 sec->key_sizes[i]);
10223 priv->ieee->sec.flags |= (1 << i);
10225 priv->status |= STATUS_SECURITY_UPDATED;
10226 } else if (sec->level != SEC_LEVEL_1)
10227 priv->ieee->sec.flags &= ~(1 << i);
10230 if (sec->flags & SEC_ACTIVE_KEY) {
10231 if (sec->active_key <= 3) {
10232 priv->ieee->sec.active_key = sec->active_key;
10233 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
10235 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
10236 priv->status |= STATUS_SECURITY_UPDATED;
10238 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
10240 if ((sec->flags & SEC_AUTH_MODE) &&
10241 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10242 priv->ieee->sec.auth_mode = sec->auth_mode;
10243 priv->ieee->sec.flags |= SEC_AUTH_MODE;
10244 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10245 priv->capability |= CAP_SHARED_KEY;
10247 priv->capability &= ~CAP_SHARED_KEY;
10248 priv->status |= STATUS_SECURITY_UPDATED;
10251 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10252 priv->ieee->sec.flags |= SEC_ENABLED;
10253 priv->ieee->sec.enabled = sec->enabled;
10254 priv->status |= STATUS_SECURITY_UPDATED;
10256 priv->capability |= CAP_PRIVACY_ON;
10258 priv->capability &= ~CAP_PRIVACY_ON;
10261 if (sec->flags & SEC_ENCRYPT)
10262 priv->ieee->sec.encrypt = sec->encrypt;
10264 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10265 priv->ieee->sec.level = sec->level;
10266 priv->ieee->sec.flags |= SEC_LEVEL;
10267 priv->status |= STATUS_SECURITY_UPDATED;
10270 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10271 ipw_set_hwcrypto_keys(priv);
10273 /* To match current functionality of ipw2100 (which works well w/
10274 * various supplicants, we don't force a disassociate if the
10275 * privacy capability changes ... */
10277 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
10278 (((priv->assoc_request.capability &
10279 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
10280 (!(priv->assoc_request.capability &
10281 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
10282 IPW_DEBUG_ASSOC("Disassociating due to capability "
10284 ipw_disassociate(priv);
10289 static int init_supported_rates(struct ipw_priv *priv,
10290 struct ipw_supported_rates *rates)
10292 /* TODO: Mask out rates based on priv->rates_mask */
10294 memset(rates, 0, sizeof(*rates));
10295 /* configure supported rates */
10296 switch (priv->ieee->freq_band) {
10297 case IEEE80211_52GHZ_BAND:
10298 rates->ieee_mode = IPW_A_MODE;
10299 rates->purpose = IPW_RATE_CAPABILITIES;
10300 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10301 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10304 default: /* Mixed or 2.4Ghz */
10305 rates->ieee_mode = IPW_G_MODE;
10306 rates->purpose = IPW_RATE_CAPABILITIES;
10307 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10308 IEEE80211_CCK_DEFAULT_RATES_MASK);
10309 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10310 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10311 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10319 static int ipw_config(struct ipw_priv *priv)
10321 /* This is only called from ipw_up, which resets/reloads the firmware
10322 so, we don't need to first disable the card before we configure
10324 if (ipw_set_tx_power(priv))
10327 /* initialize adapter address */
10328 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10331 /* set basic system config settings */
10332 init_sys_config(&priv->sys_config);
10334 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10335 * Does not support BT priority yet (don't abort or defer our Tx) */
10337 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
10339 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10340 priv->sys_config.bt_coexistence
10341 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
10342 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10343 priv->sys_config.bt_coexistence
10344 |= CFG_BT_COEXISTENCE_OOB;
10347 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10348 priv->sys_config.answer_broadcast_ssid_probe = 1;
10350 priv->sys_config.answer_broadcast_ssid_probe = 0;
10352 if (ipw_send_system_config(priv, &priv->sys_config))
10355 init_supported_rates(priv, &priv->rates);
10356 if (ipw_send_supported_rates(priv, &priv->rates))
10359 /* Set request-to-send threshold */
10360 if (priv->rts_threshold) {
10361 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10364 #ifdef CONFIG_IPW_QOS
10365 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10366 ipw_qos_activate(priv, NULL);
10367 #endif /* CONFIG_IPW_QOS */
10369 if (ipw_set_random_seed(priv))
10372 /* final state transition to the RUN state */
10373 if (ipw_send_host_complete(priv))
10376 priv->status |= STATUS_INIT;
10378 ipw_led_init(priv);
10379 ipw_led_radio_on(priv);
10380 priv->notif_missed_beacons = 0;
10382 /* Set hardware WEP key if it is configured. */
10383 if ((priv->capability & CAP_PRIVACY_ON) &&
10384 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10385 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10386 ipw_set_hwcrypto_keys(priv);
10397 * These tables have been tested in conjunction with the
10398 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10400 * Altering this values, using it on other hardware, or in geographies
10401 * not intended for resale of the above mentioned Intel adapters has
10404 * Remember to update the table in README.ipw2200 when changing this
10408 static const struct ieee80211_geo ipw_geos[] = {
10412 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10413 {2427, 4}, {2432, 5}, {2437, 6},
10414 {2442, 7}, {2447, 8}, {2452, 9},
10415 {2457, 10}, {2462, 11}},
10418 { /* Custom US/Canada */
10421 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10422 {2427, 4}, {2432, 5}, {2437, 6},
10423 {2442, 7}, {2447, 8}, {2452, 9},
10424 {2457, 10}, {2462, 11}},
10430 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10431 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10432 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10433 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10436 { /* Rest of World */
10439 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10440 {2427, 4}, {2432, 5}, {2437, 6},
10441 {2442, 7}, {2447, 8}, {2452, 9},
10442 {2457, 10}, {2462, 11}, {2467, 12},
10446 { /* Custom USA & Europe & High */
10449 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10450 {2427, 4}, {2432, 5}, {2437, 6},
10451 {2442, 7}, {2447, 8}, {2452, 9},
10452 {2457, 10}, {2462, 11}},
10458 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10459 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10460 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10461 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10469 { /* Custom NA & Europe */
10472 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10473 {2427, 4}, {2432, 5}, {2437, 6},
10474 {2442, 7}, {2447, 8}, {2452, 9},
10475 {2457, 10}, {2462, 11}},
10481 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10482 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10483 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10484 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10485 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10486 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10487 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10488 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10489 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10492 { /* Custom Japan */
10495 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10496 {2427, 4}, {2432, 5}, {2437, 6},
10497 {2442, 7}, {2447, 8}, {2452, 9},
10498 {2457, 10}, {2462, 11}},
10500 .a = {{5170, 34}, {5190, 38},
10501 {5210, 42}, {5230, 46}},
10507 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10508 {2427, 4}, {2432, 5}, {2437, 6},
10509 {2442, 7}, {2447, 8}, {2452, 9},
10510 {2457, 10}, {2462, 11}},
10516 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10517 {2427, 4}, {2432, 5}, {2437, 6},
10518 {2442, 7}, {2447, 8}, {2452, 9},
10519 {2457, 10}, {2462, 11}, {2467, 12},
10526 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10527 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10528 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10529 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10530 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10531 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10532 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10533 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10534 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10535 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10536 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10537 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10538 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10539 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10540 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10543 { /* Custom Japan */
10546 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10547 {2427, 4}, {2432, 5}, {2437, 6},
10548 {2442, 7}, {2447, 8}, {2452, 9},
10549 {2457, 10}, {2462, 11}, {2467, 12},
10550 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10552 .a = {{5170, 34}, {5190, 38},
10553 {5210, 42}, {5230, 46}},
10556 { /* Rest of World */
10559 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10560 {2427, 4}, {2432, 5}, {2437, 6},
10561 {2442, 7}, {2447, 8}, {2452, 9},
10562 {2457, 10}, {2462, 11}, {2467, 12},
10563 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
10564 IEEE80211_CH_PASSIVE_ONLY}},
10570 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10571 {2427, 4}, {2432, 5}, {2437, 6},
10572 {2442, 7}, {2447, 8}, {2452, 9},
10573 {2457, 10}, {2462, 11},
10574 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10575 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10577 .a = {{5745, 149}, {5765, 153},
10578 {5785, 157}, {5805, 161}},
10581 { /* Custom Europe */
10584 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10585 {2427, 4}, {2432, 5}, {2437, 6},
10586 {2442, 7}, {2447, 8}, {2452, 9},
10587 {2457, 10}, {2462, 11},
10588 {2467, 12}, {2472, 13}},
10590 .a = {{5180, 36}, {5200, 40},
10591 {5220, 44}, {5240, 48}},
10597 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10598 {2427, 4}, {2432, 5}, {2437, 6},
10599 {2442, 7}, {2447, 8}, {2452, 9},
10600 {2457, 10}, {2462, 11},
10601 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10602 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10604 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10605 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10606 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10607 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10608 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10609 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10610 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10611 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10612 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10613 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10614 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10615 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10616 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10617 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10618 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10619 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10620 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10621 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10622 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
10623 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10624 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10625 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10626 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10627 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10633 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10634 {2427, 4}, {2432, 5}, {2437, 6},
10635 {2442, 7}, {2447, 8}, {2452, 9},
10636 {2457, 10}, {2462, 11}},
10638 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10639 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10640 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10641 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10642 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10643 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10644 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10645 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10646 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10647 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10648 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10649 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10650 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10654 #define MAX_HW_RESTARTS 5
10655 static int ipw_up(struct ipw_priv *priv)
10659 if (priv->status & STATUS_EXIT_PENDING)
10662 if (cmdlog && !priv->cmdlog) {
10663 priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
10665 if (priv->cmdlog == NULL) {
10666 IPW_ERROR("Error allocating %d command log entries.\n",
10670 memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
10671 priv->cmdlog_len = cmdlog;
10675 for (i = 0; i < MAX_HW_RESTARTS; i++) {
10676 /* Load the microcode, firmware, and eeprom.
10677 * Also start the clocks. */
10678 rc = ipw_load(priv);
10680 IPW_ERROR("Unable to load firmware: %d\n", rc);
10684 ipw_init_ordinals(priv);
10685 if (!(priv->config & CFG_CUSTOM_MAC))
10686 eeprom_parse_mac(priv, priv->mac_addr);
10687 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
10689 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
10690 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
10691 ipw_geos[j].name, 3))
10694 if (j == ARRAY_SIZE(ipw_geos)) {
10695 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
10696 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
10697 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
10698 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
10701 if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
10702 IPW_WARNING("Could not set geography.");
10706 if (priv->status & STATUS_RF_KILL_SW) {
10707 IPW_WARNING("Radio disabled by module parameter.\n");
10709 } else if (rf_kill_active(priv)) {
10710 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
10711 "Kill switch must be turned off for "
10712 "wireless networking to work.\n");
10713 queue_delayed_work(priv->workqueue, &priv->rf_kill,
10718 rc = ipw_config(priv);
10720 IPW_DEBUG_INFO("Configured device on count %i\n", i);
10722 /* If configure to try and auto-associate, kick
10724 queue_work(priv->workqueue, &priv->request_scan);
10729 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
10730 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
10731 i, MAX_HW_RESTARTS);
10733 /* We had an error bringing up the hardware, so take it
10734 * all the way back down so we can try again */
10738 /* tried to restart and config the device for as long as our
10739 * patience could withstand */
10740 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
10745 static void ipw_bg_up(void *data)
10747 struct ipw_priv *priv = data;
10748 mutex_lock(&priv->mutex);
10750 mutex_unlock(&priv->mutex);
10753 static void ipw_deinit(struct ipw_priv *priv)
10757 if (priv->status & STATUS_SCANNING) {
10758 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
10759 ipw_abort_scan(priv);
10762 if (priv->status & STATUS_ASSOCIATED) {
10763 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
10764 ipw_disassociate(priv);
10767 ipw_led_shutdown(priv);
10769 /* Wait up to 1s for status to change to not scanning and not
10770 * associated (disassociation can take a while for a ful 802.11
10772 for (i = 1000; i && (priv->status &
10773 (STATUS_DISASSOCIATING |
10774 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
10777 if (priv->status & (STATUS_DISASSOCIATING |
10778 STATUS_ASSOCIATED | STATUS_SCANNING))
10779 IPW_DEBUG_INFO("Still associated or scanning...\n");
10781 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
10783 /* Attempt to disable the card */
10784 ipw_send_card_disable(priv, 0);
10786 priv->status &= ~STATUS_INIT;
10789 static void ipw_down(struct ipw_priv *priv)
10791 int exit_pending = priv->status & STATUS_EXIT_PENDING;
10793 priv->status |= STATUS_EXIT_PENDING;
10795 if (ipw_is_init(priv))
10798 /* Wipe out the EXIT_PENDING status bit if we are not actually
10799 * exiting the module */
10801 priv->status &= ~STATUS_EXIT_PENDING;
10803 /* tell the device to stop sending interrupts */
10804 ipw_disable_interrupts(priv);
10806 /* Clear all bits but the RF Kill */
10807 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
10808 netif_carrier_off(priv->net_dev);
10809 netif_stop_queue(priv->net_dev);
10811 ipw_stop_nic(priv);
10813 ipw_led_radio_off(priv);
10816 static void ipw_bg_down(void *data)
10818 struct ipw_priv *priv = data;
10819 mutex_lock(&priv->mutex);
10821 mutex_unlock(&priv->mutex);
10824 /* Called by register_netdev() */
10825 static int ipw_net_init(struct net_device *dev)
10827 struct ipw_priv *priv = ieee80211_priv(dev);
10828 mutex_lock(&priv->mutex);
10830 if (ipw_up(priv)) {
10831 mutex_unlock(&priv->mutex);
10835 mutex_unlock(&priv->mutex);
10839 /* PCI driver stuff */
10840 static struct pci_device_id card_ids[] = {
10841 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
10842 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
10843 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
10844 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
10845 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
10846 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
10847 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
10848 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
10849 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
10850 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
10851 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
10852 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
10853 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
10854 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
10855 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
10856 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
10857 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
10858 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
10859 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
10860 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
10861 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
10862 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
10864 /* required last entry */
10868 MODULE_DEVICE_TABLE(pci, card_ids);
10870 static struct attribute *ipw_sysfs_entries[] = {
10871 &dev_attr_rf_kill.attr,
10872 &dev_attr_direct_dword.attr,
10873 &dev_attr_indirect_byte.attr,
10874 &dev_attr_indirect_dword.attr,
10875 &dev_attr_mem_gpio_reg.attr,
10876 &dev_attr_command_event_reg.attr,
10877 &dev_attr_nic_type.attr,
10878 &dev_attr_status.attr,
10879 &dev_attr_cfg.attr,
10880 &dev_attr_error.attr,
10881 &dev_attr_event_log.attr,
10882 &dev_attr_cmd_log.attr,
10883 &dev_attr_eeprom_delay.attr,
10884 &dev_attr_ucode_version.attr,
10885 &dev_attr_rtc.attr,
10886 &dev_attr_scan_age.attr,
10887 &dev_attr_led.attr,
10888 &dev_attr_speed_scan.attr,
10889 &dev_attr_net_stats.attr,
10893 static struct attribute_group ipw_attribute_group = {
10894 .name = NULL, /* put in device directory */
10895 .attrs = ipw_sysfs_entries,
10898 static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
10901 struct net_device *net_dev;
10902 void __iomem *base;
10904 struct ipw_priv *priv;
10907 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
10908 if (net_dev == NULL) {
10913 priv = ieee80211_priv(net_dev);
10914 priv->ieee = netdev_priv(net_dev);
10916 priv->net_dev = net_dev;
10917 priv->pci_dev = pdev;
10918 #ifdef CONFIG_IPW2200_DEBUG
10919 ipw_debug_level = debug;
10921 spin_lock_init(&priv->lock);
10922 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
10923 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
10925 mutex_init(&priv->mutex);
10926 if (pci_enable_device(pdev)) {
10928 goto out_free_ieee80211;
10931 pci_set_master(pdev);
10933 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
10935 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
10937 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
10938 goto out_pci_disable_device;
10941 pci_set_drvdata(pdev, priv);
10943 err = pci_request_regions(pdev, DRV_NAME);
10945 goto out_pci_disable_device;
10947 /* We disable the RETRY_TIMEOUT register (0x41) to keep
10948 * PCI Tx retries from interfering with C3 CPU state */
10949 pci_read_config_dword(pdev, 0x40, &val);
10950 if ((val & 0x0000ff00) != 0)
10951 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
10953 length = pci_resource_len(pdev, 0);
10954 priv->hw_len = length;
10956 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
10959 goto out_pci_release_regions;
10962 priv->hw_base = base;
10963 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
10964 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
10966 err = ipw_setup_deferred_work(priv);
10968 IPW_ERROR("Unable to setup deferred work\n");
10972 ipw_sw_reset(priv, 1);
10974 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
10976 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
10977 goto out_destroy_workqueue;
10980 SET_MODULE_OWNER(net_dev);
10981 SET_NETDEV_DEV(net_dev, &pdev->dev);
10983 mutex_lock(&priv->mutex);
10985 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
10986 priv->ieee->set_security = shim__set_security;
10987 priv->ieee->is_queue_full = ipw_net_is_queue_full;
10989 #ifdef CONFIG_IPW_QOS
10990 priv->ieee->is_qos_active = ipw_is_qos_active;
10991 priv->ieee->handle_probe_response = ipw_handle_beacon;
10992 priv->ieee->handle_beacon = ipw_handle_probe_response;
10993 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
10994 #endif /* CONFIG_IPW_QOS */
10996 priv->ieee->perfect_rssi = -20;
10997 priv->ieee->worst_rssi = -85;
10999 net_dev->open = ipw_net_open;
11000 net_dev->stop = ipw_net_stop;
11001 net_dev->init = ipw_net_init;
11002 net_dev->get_stats = ipw_net_get_stats;
11003 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11004 net_dev->set_mac_address = ipw_net_set_mac_address;
11005 priv->wireless_data.spy_data = &priv->ieee->spy_data;
11006 net_dev->wireless_data = &priv->wireless_data;
11007 net_dev->wireless_handlers = &ipw_wx_handler_def;
11008 net_dev->ethtool_ops = &ipw_ethtool_ops;
11009 net_dev->irq = pdev->irq;
11010 net_dev->base_addr = (unsigned long)priv->hw_base;
11011 net_dev->mem_start = pci_resource_start(pdev, 0);
11012 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11014 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11016 IPW_ERROR("failed to create sysfs device attributes\n");
11017 mutex_unlock(&priv->mutex);
11018 goto out_release_irq;
11021 mutex_unlock(&priv->mutex);
11022 err = register_netdev(net_dev);
11024 IPW_ERROR("failed to register network device\n");
11025 goto out_remove_sysfs;
11028 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11029 "channels, %d 802.11a channels)\n",
11030 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11031 priv->ieee->geo.a_channels);
11036 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11038 free_irq(pdev->irq, priv);
11039 out_destroy_workqueue:
11040 destroy_workqueue(priv->workqueue);
11041 priv->workqueue = NULL;
11043 iounmap(priv->hw_base);
11044 out_pci_release_regions:
11045 pci_release_regions(pdev);
11046 out_pci_disable_device:
11047 pci_disable_device(pdev);
11048 pci_set_drvdata(pdev, NULL);
11049 out_free_ieee80211:
11050 free_ieee80211(priv->net_dev);
11055 static void ipw_pci_remove(struct pci_dev *pdev)
11057 struct ipw_priv *priv = pci_get_drvdata(pdev);
11058 struct list_head *p, *q;
11064 mutex_lock(&priv->mutex);
11066 priv->status |= STATUS_EXIT_PENDING;
11068 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11070 mutex_unlock(&priv->mutex);
11072 unregister_netdev(priv->net_dev);
11075 ipw_rx_queue_free(priv, priv->rxq);
11078 ipw_tx_queue_free(priv);
11080 if (priv->cmdlog) {
11081 kfree(priv->cmdlog);
11082 priv->cmdlog = NULL;
11084 /* ipw_down will ensure that there is no more pending work
11085 * in the workqueue's, so we can safely remove them now. */
11086 cancel_delayed_work(&priv->adhoc_check);
11087 cancel_delayed_work(&priv->gather_stats);
11088 cancel_delayed_work(&priv->request_scan);
11089 cancel_delayed_work(&priv->rf_kill);
11090 cancel_delayed_work(&priv->scan_check);
11091 destroy_workqueue(priv->workqueue);
11092 priv->workqueue = NULL;
11094 /* Free MAC hash list for ADHOC */
11095 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11096 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
11098 kfree(list_entry(p, struct ipw_ibss_seq, list));
11103 ipw_free_error_log(priv->error);
11104 priv->error = NULL;
11107 free_irq(pdev->irq, priv);
11108 iounmap(priv->hw_base);
11109 pci_release_regions(pdev);
11110 pci_disable_device(pdev);
11111 pci_set_drvdata(pdev, NULL);
11112 free_ieee80211(priv->net_dev);
11117 static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
11119 struct ipw_priv *priv = pci_get_drvdata(pdev);
11120 struct net_device *dev = priv->net_dev;
11122 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11124 /* Take down the device; powers it off, etc. */
11127 /* Remove the PRESENT state of the device */
11128 netif_device_detach(dev);
11130 pci_save_state(pdev);
11131 pci_disable_device(pdev);
11132 pci_set_power_state(pdev, pci_choose_state(pdev, state));
11137 static int ipw_pci_resume(struct pci_dev *pdev)
11139 struct ipw_priv *priv = pci_get_drvdata(pdev);
11140 struct net_device *dev = priv->net_dev;
11143 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11145 pci_set_power_state(pdev, PCI_D0);
11146 pci_enable_device(pdev);
11147 pci_restore_state(pdev);
11150 * Suspend/Resume resets the PCI configuration space, so we have to
11151 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11152 * from interfering with C3 CPU state. pci_restore_state won't help
11153 * here since it only restores the first 64 bytes pci config header.
11155 pci_read_config_dword(pdev, 0x40, &val);
11156 if ((val & 0x0000ff00) != 0)
11157 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11159 /* Set the device back into the PRESENT state; this will also wake
11160 * the queue of needed */
11161 netif_device_attach(dev);
11163 /* Bring the device back up */
11164 queue_work(priv->workqueue, &priv->up);
11170 /* driver initialization stuff */
11171 static struct pci_driver ipw_driver = {
11173 .id_table = card_ids,
11174 .probe = ipw_pci_probe,
11175 .remove = __devexit_p(ipw_pci_remove),
11177 .suspend = ipw_pci_suspend,
11178 .resume = ipw_pci_resume,
11182 static int __init ipw_init(void)
11186 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11187 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11189 ret = pci_module_init(&ipw_driver);
11191 IPW_ERROR("Unable to initialize PCI module\n");
11195 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
11197 IPW_ERROR("Unable to create driver sysfs file\n");
11198 pci_unregister_driver(&ipw_driver);
11205 static void __exit ipw_exit(void)
11207 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11208 pci_unregister_driver(&ipw_driver);
11211 module_param(disable, int, 0444);
11212 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11214 module_param(associate, int, 0444);
11215 MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11217 module_param(auto_create, int, 0444);
11218 MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11220 module_param(led, int, 0444);
11221 MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
11223 #ifdef CONFIG_IPW2200_DEBUG
11224 module_param(debug, int, 0444);
11225 MODULE_PARM_DESC(debug, "debug output mask");
11228 module_param(channel, int, 0444);
11229 MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
11231 #ifdef CONFIG_IPW_QOS
11232 module_param(qos_enable, int, 0444);
11233 MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
11235 module_param(qos_burst_enable, int, 0444);
11236 MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11238 module_param(qos_no_ack_mask, int, 0444);
11239 MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11241 module_param(burst_duration_CCK, int, 0444);
11242 MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11244 module_param(burst_duration_OFDM, int, 0444);
11245 MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11246 #endif /* CONFIG_IPW_QOS */
11248 #ifdef CONFIG_IPW2200_MONITOR
11249 module_param(mode, int, 0444);
11250 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11252 module_param(mode, int, 0444);
11253 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11256 module_param(bt_coexist, int, 0444);
11257 MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
11259 module_param(hwcrypto, int, 0444);
11260 MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
11262 module_param(cmdlog, int, 0444);
11263 MODULE_PARM_DESC(cmdlog,
11264 "allocate a ring buffer for logging firmware commands");
11266 module_param(roaming, int, 0444);
11267 MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
11269 module_param(antenna, int, 0444);
11270 MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
11272 module_exit(ipw_exit);
11273 module_init(ipw_init);