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;
50 static int channel = 0;
53 static u32 ipw_debug_level;
54 static int associate = 1;
55 static int auto_create = 1;
57 static int disable = 0;
58 static int bt_coexist = 0;
59 static int hwcrypto = 0;
60 static int roaming = 1;
61 static const char ipw_modes[] = {
66 static int qos_enable = 0;
67 static int qos_burst_enable = 0;
68 static int qos_no_ack_mask = 0;
69 static int burst_duration_CCK = 0;
70 static int burst_duration_OFDM = 0;
72 static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
73 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
75 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
77 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
78 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
79 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
80 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
83 static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
84 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
86 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
88 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
89 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
90 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
91 QOS_TX3_TXOP_LIMIT_CCK}
94 static struct ieee80211_qos_parameters def_parameters_OFDM = {
95 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
97 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
99 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
100 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
101 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
102 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
105 static struct ieee80211_qos_parameters def_parameters_CCK = {
106 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
108 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
110 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
111 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
112 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
113 DEF_TX3_TXOP_LIMIT_CCK}
116 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
118 static int from_priority_to_tx_queue[] = {
119 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
120 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
123 static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
125 static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
127 static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
129 #endif /* CONFIG_IPW_QOS */
131 static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
132 static void ipw_remove_current_network(struct ipw_priv *priv);
133 static void ipw_rx(struct ipw_priv *priv);
134 static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
135 struct clx2_tx_queue *txq, int qindex);
136 static int ipw_queue_reset(struct ipw_priv *priv);
138 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
141 static void ipw_tx_queue_free(struct ipw_priv *);
143 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
144 static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
145 static void ipw_rx_queue_replenish(void *);
146 static int ipw_up(struct ipw_priv *);
147 static void ipw_bg_up(void *);
148 static void ipw_down(struct ipw_priv *);
149 static void ipw_bg_down(void *);
150 static int ipw_config(struct ipw_priv *);
151 static int init_supported_rates(struct ipw_priv *priv,
152 struct ipw_supported_rates *prates);
153 static void ipw_set_hwcrypto_keys(struct ipw_priv *);
154 static void ipw_send_wep_keys(struct ipw_priv *, int);
156 static int snprint_line(char *buf, size_t count,
157 const u8 * data, u32 len, u32 ofs)
162 out = snprintf(buf, count, "%08X", ofs);
164 for (l = 0, i = 0; i < 2; i++) {
165 out += snprintf(buf + out, count - out, " ");
166 for (j = 0; j < 8 && l < len; j++, l++)
167 out += snprintf(buf + out, count - out, "%02X ",
170 out += snprintf(buf + out, count - out, " ");
173 out += snprintf(buf + out, count - out, " ");
174 for (l = 0, i = 0; i < 2; i++) {
175 out += snprintf(buf + out, count - out, " ");
176 for (j = 0; j < 8 && l < len; j++, l++) {
177 c = data[(i * 8 + j)];
178 if (!isascii(c) || !isprint(c))
181 out += snprintf(buf + out, count - out, "%c", c);
185 out += snprintf(buf + out, count - out, " ");
191 static void printk_buf(int level, const u8 * data, u32 len)
195 if (!(ipw_debug_level & level))
199 snprint_line(line, sizeof(line), &data[ofs],
201 printk(KERN_DEBUG "%s\n", line);
203 len -= min(len, 16U);
207 static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
213 while (size && len) {
214 out = snprint_line(output, size, &data[ofs],
215 min_t(size_t, len, 16U), ofs);
220 len -= min_t(size_t, len, 16U);
226 /* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
227 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
228 #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
230 /* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
231 static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
232 #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
234 /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
235 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
236 static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
238 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
239 __LINE__, (u32) (b), (u32) (c));
240 _ipw_write_reg8(a, b, c);
243 /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
244 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
245 static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
247 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
248 __LINE__, (u32) (b), (u32) (c));
249 _ipw_write_reg16(a, b, c);
252 /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
253 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
254 static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
256 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
257 __LINE__, (u32) (b), (u32) (c));
258 _ipw_write_reg32(a, b, c);
261 /* 8-bit direct write (low 4K) */
262 #define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
264 /* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
265 #define ipw_write8(ipw, ofs, val) \
266 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
267 _ipw_write8(ipw, ofs, val)
269 /* 16-bit direct write (low 4K) */
270 #define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
272 /* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
273 #define ipw_write16(ipw, ofs, val) \
274 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
275 _ipw_write16(ipw, ofs, val)
277 /* 32-bit direct write (low 4K) */
278 #define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
280 /* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
281 #define ipw_write32(ipw, ofs, val) \
282 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
283 _ipw_write32(ipw, ofs, val)
285 /* 8-bit direct read (low 4K) */
286 #define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
288 /* 8-bit direct read (low 4K), with debug wrapper */
289 static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
291 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
292 return _ipw_read8(ipw, ofs);
295 /* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
296 #define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
298 /* 16-bit direct read (low 4K) */
299 #define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
301 /* 16-bit direct read (low 4K), with debug wrapper */
302 static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
304 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
305 return _ipw_read16(ipw, ofs);
308 /* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
309 #define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
311 /* 32-bit direct read (low 4K) */
312 #define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
314 /* 32-bit direct read (low 4K), with debug wrapper */
315 static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
317 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
318 return _ipw_read32(ipw, ofs);
321 /* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
322 #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
324 /* multi-byte read (above 4K), with debug wrapper */
325 static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
326 static inline void __ipw_read_indirect(const char *f, int l,
327 struct ipw_priv *a, u32 b, u8 * c, int d)
329 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
331 _ipw_read_indirect(a, b, c, d);
334 /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
335 #define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
337 /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
338 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
340 #define ipw_write_indirect(a, b, c, d) \
341 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
342 _ipw_write_indirect(a, b, c, d)
344 /* 32-bit indirect write (above 4K) */
345 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
347 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
348 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
349 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
352 /* 8-bit indirect write (above 4K) */
353 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
355 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
356 u32 dif_len = reg - aligned_addr;
358 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
359 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
360 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
363 /* 16-bit indirect write (above 4K) */
364 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
366 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
367 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
369 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
370 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
371 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
374 /* 8-bit indirect read (above 4K) */
375 static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
378 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
379 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
380 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
381 return (word >> ((reg & 0x3) * 8)) & 0xff;
384 /* 32-bit indirect read (above 4K) */
385 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
389 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
391 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
392 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
393 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
397 /* General purpose, no alignment requirement, iterative (multi-byte) read, */
398 /* for area above 1st 4K of SRAM/reg space */
399 static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
402 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
403 u32 dif_len = addr - aligned_addr;
406 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
412 /* Read the first dword (or portion) byte by byte */
413 if (unlikely(dif_len)) {
414 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
415 /* Start reading at aligned_addr + dif_len */
416 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
417 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
421 /* Read all of the middle dwords as dwords, with auto-increment */
422 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
423 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
424 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
426 /* Read the last dword (or portion) byte by byte */
428 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
429 for (i = 0; num > 0; i++, num--)
430 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
434 /* General purpose, no alignment requirement, iterative (multi-byte) write, */
435 /* for area above 1st 4K of SRAM/reg space */
436 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
439 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
440 u32 dif_len = addr - aligned_addr;
443 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
449 /* Write the first dword (or portion) byte by byte */
450 if (unlikely(dif_len)) {
451 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
452 /* Start writing at aligned_addr + dif_len */
453 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
454 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
458 /* Write all of the middle dwords as dwords, with auto-increment */
459 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
460 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
461 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
463 /* Write the last dword (or portion) byte by byte */
465 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
466 for (i = 0; num > 0; i++, num--, buf++)
467 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
471 /* General purpose, no alignment requirement, iterative (multi-byte) write, */
472 /* for 1st 4K of SRAM/regs space */
473 static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
476 memcpy_toio((priv->hw_base + addr), buf, num);
479 /* Set bit(s) in low 4K of SRAM/regs */
480 static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
482 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
485 /* Clear bit(s) in low 4K of SRAM/regs */
486 static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
488 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
491 static inline void ipw_enable_interrupts(struct ipw_priv *priv)
493 if (priv->status & STATUS_INT_ENABLED)
495 priv->status |= STATUS_INT_ENABLED;
496 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
499 static inline void ipw_disable_interrupts(struct ipw_priv *priv)
501 if (!(priv->status & STATUS_INT_ENABLED))
503 priv->status &= ~STATUS_INT_ENABLED;
504 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
507 #ifdef CONFIG_IPW2200_DEBUG
508 static char *ipw_error_desc(u32 val)
511 case IPW_FW_ERROR_OK:
513 case IPW_FW_ERROR_FAIL:
515 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
516 return "MEMORY_UNDERFLOW";
517 case IPW_FW_ERROR_MEMORY_OVERFLOW:
518 return "MEMORY_OVERFLOW";
519 case IPW_FW_ERROR_BAD_PARAM:
521 case IPW_FW_ERROR_BAD_CHECKSUM:
522 return "BAD_CHECKSUM";
523 case IPW_FW_ERROR_NMI_INTERRUPT:
524 return "NMI_INTERRUPT";
525 case IPW_FW_ERROR_BAD_DATABASE:
526 return "BAD_DATABASE";
527 case IPW_FW_ERROR_ALLOC_FAIL:
529 case IPW_FW_ERROR_DMA_UNDERRUN:
530 return "DMA_UNDERRUN";
531 case IPW_FW_ERROR_DMA_STATUS:
533 case IPW_FW_ERROR_DINO_ERROR:
535 case IPW_FW_ERROR_EEPROM_ERROR:
536 return "EEPROM_ERROR";
537 case IPW_FW_ERROR_SYSASSERT:
539 case IPW_FW_ERROR_FATAL_ERROR:
540 return "FATAL_ERROR";
542 return "UNKNOWN_ERROR";
546 static void ipw_dump_error_log(struct ipw_priv *priv,
547 struct ipw_fw_error *error)
552 IPW_ERROR("Error allocating and capturing error log. "
553 "Nothing to dump.\n");
557 IPW_ERROR("Start IPW Error Log Dump:\n");
558 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
559 error->status, error->config);
561 for (i = 0; i < error->elem_len; i++)
562 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
563 ipw_error_desc(error->elem[i].desc),
565 error->elem[i].blink1,
566 error->elem[i].blink2,
567 error->elem[i].link1,
568 error->elem[i].link2, error->elem[i].data);
569 for (i = 0; i < error->log_len; i++)
570 IPW_ERROR("%i\t0x%08x\t%i\n",
572 error->log[i].data, error->log[i].event);
576 static inline int ipw_is_init(struct ipw_priv *priv)
578 return (priv->status & STATUS_INIT) ? 1 : 0;
581 static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
583 u32 addr, field_info, field_len, field_count, total_len;
585 IPW_DEBUG_ORD("ordinal = %i\n", ord);
587 if (!priv || !val || !len) {
588 IPW_DEBUG_ORD("Invalid argument\n");
592 /* verify device ordinal tables have been initialized */
593 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
594 IPW_DEBUG_ORD("Access ordinals before initialization\n");
598 switch (IPW_ORD_TABLE_ID_MASK & ord) {
599 case IPW_ORD_TABLE_0_MASK:
601 * TABLE 0: Direct access to a table of 32 bit values
603 * This is a very simple table with the data directly
604 * read from the table
607 /* remove the table id from the ordinal */
608 ord &= IPW_ORD_TABLE_VALUE_MASK;
611 if (ord > priv->table0_len) {
612 IPW_DEBUG_ORD("ordinal value (%i) longer then "
613 "max (%i)\n", ord, priv->table0_len);
617 /* verify we have enough room to store the value */
618 if (*len < sizeof(u32)) {
619 IPW_DEBUG_ORD("ordinal buffer length too small, "
620 "need %zd\n", sizeof(u32));
624 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
625 ord, priv->table0_addr + (ord << 2));
629 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
632 case IPW_ORD_TABLE_1_MASK:
634 * TABLE 1: Indirect access to a table of 32 bit values
636 * This is a fairly large table of u32 values each
637 * representing starting addr for the data (which is
641 /* remove the table id from the ordinal */
642 ord &= IPW_ORD_TABLE_VALUE_MASK;
645 if (ord > priv->table1_len) {
646 IPW_DEBUG_ORD("ordinal value too long\n");
650 /* verify we have enough room to store the value */
651 if (*len < sizeof(u32)) {
652 IPW_DEBUG_ORD("ordinal buffer length too small, "
653 "need %zd\n", sizeof(u32));
658 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
662 case IPW_ORD_TABLE_2_MASK:
664 * TABLE 2: Indirect access to a table of variable sized values
666 * This table consist of six values, each containing
667 * - dword containing the starting offset of the data
668 * - dword containing the lengh in the first 16bits
669 * and the count in the second 16bits
672 /* remove the table id from the ordinal */
673 ord &= IPW_ORD_TABLE_VALUE_MASK;
676 if (ord > priv->table2_len) {
677 IPW_DEBUG_ORD("ordinal value too long\n");
681 /* get the address of statistic */
682 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
684 /* get the second DW of statistics ;
685 * two 16-bit words - first is length, second is count */
688 priv->table2_addr + (ord << 3) +
691 /* get each entry length */
692 field_len = *((u16 *) & field_info);
694 /* get number of entries */
695 field_count = *(((u16 *) & field_info) + 1);
697 /* abort if not enought memory */
698 total_len = field_len * field_count;
699 if (total_len > *len) {
708 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
709 "field_info = 0x%08x\n",
710 addr, total_len, field_info);
711 ipw_read_indirect(priv, addr, val, total_len);
715 IPW_DEBUG_ORD("Invalid ordinal!\n");
723 static void ipw_init_ordinals(struct ipw_priv *priv)
725 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
726 priv->table0_len = ipw_read32(priv, priv->table0_addr);
728 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
729 priv->table0_addr, priv->table0_len);
731 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
732 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
734 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
735 priv->table1_addr, priv->table1_len);
737 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
738 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
739 priv->table2_len &= 0x0000ffff; /* use first two bytes */
741 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
742 priv->table2_addr, priv->table2_len);
746 static u32 ipw_register_toggle(u32 reg)
748 reg &= ~IPW_START_STANDBY;
749 if (reg & IPW_GATE_ODMA)
750 reg &= ~IPW_GATE_ODMA;
751 if (reg & IPW_GATE_IDMA)
752 reg &= ~IPW_GATE_IDMA;
753 if (reg & IPW_GATE_ADMA)
754 reg &= ~IPW_GATE_ADMA;
760 * - On radio ON, turn on any LEDs that require to be on during start
761 * - On initialization, start unassociated blink
762 * - On association, disable unassociated blink
763 * - On disassociation, start unassociated blink
764 * - On radio OFF, turn off any LEDs started during radio on
767 #define LD_TIME_LINK_ON msecs_to_jiffies(300)
768 #define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
769 #define LD_TIME_ACT_ON msecs_to_jiffies(250)
771 static void ipw_led_link_on(struct ipw_priv *priv)
776 /* If configured to not use LEDs, or nic_type is 1,
777 * then we don't toggle a LINK led */
778 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
781 spin_lock_irqsave(&priv->lock, flags);
783 if (!(priv->status & STATUS_RF_KILL_MASK) &&
784 !(priv->status & STATUS_LED_LINK_ON)) {
785 IPW_DEBUG_LED("Link LED On\n");
786 led = ipw_read_reg32(priv, IPW_EVENT_REG);
787 led |= priv->led_association_on;
789 led = ipw_register_toggle(led);
791 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
792 ipw_write_reg32(priv, IPW_EVENT_REG, led);
794 priv->status |= STATUS_LED_LINK_ON;
796 /* If we aren't associated, schedule turning the LED off */
797 if (!(priv->status & STATUS_ASSOCIATED))
798 queue_delayed_work(priv->workqueue,
803 spin_unlock_irqrestore(&priv->lock, flags);
806 static void ipw_bg_led_link_on(void *data)
808 struct ipw_priv *priv = data;
809 mutex_lock(&priv->mutex);
810 ipw_led_link_on(data);
811 mutex_unlock(&priv->mutex);
814 static void ipw_led_link_off(struct ipw_priv *priv)
819 /* If configured not to use LEDs, or nic type is 1,
820 * then we don't goggle the LINK led. */
821 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
824 spin_lock_irqsave(&priv->lock, flags);
826 if (priv->status & STATUS_LED_LINK_ON) {
827 led = ipw_read_reg32(priv, IPW_EVENT_REG);
828 led &= priv->led_association_off;
829 led = ipw_register_toggle(led);
831 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
832 ipw_write_reg32(priv, IPW_EVENT_REG, led);
834 IPW_DEBUG_LED("Link LED Off\n");
836 priv->status &= ~STATUS_LED_LINK_ON;
838 /* If we aren't associated and the radio is on, schedule
839 * turning the LED on (blink while unassociated) */
840 if (!(priv->status & STATUS_RF_KILL_MASK) &&
841 !(priv->status & STATUS_ASSOCIATED))
842 queue_delayed_work(priv->workqueue, &priv->led_link_on,
847 spin_unlock_irqrestore(&priv->lock, flags);
850 static void ipw_bg_led_link_off(void *data)
852 struct ipw_priv *priv = data;
853 mutex_lock(&priv->mutex);
854 ipw_led_link_off(data);
855 mutex_unlock(&priv->mutex);
858 static void __ipw_led_activity_on(struct ipw_priv *priv)
862 if (priv->config & CFG_NO_LED)
865 if (priv->status & STATUS_RF_KILL_MASK)
868 if (!(priv->status & STATUS_LED_ACT_ON)) {
869 led = ipw_read_reg32(priv, IPW_EVENT_REG);
870 led |= priv->led_activity_on;
872 led = ipw_register_toggle(led);
874 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
875 ipw_write_reg32(priv, IPW_EVENT_REG, led);
877 IPW_DEBUG_LED("Activity LED On\n");
879 priv->status |= STATUS_LED_ACT_ON;
881 cancel_delayed_work(&priv->led_act_off);
882 queue_delayed_work(priv->workqueue, &priv->led_act_off,
885 /* Reschedule LED off for full time period */
886 cancel_delayed_work(&priv->led_act_off);
887 queue_delayed_work(priv->workqueue, &priv->led_act_off,
893 void ipw_led_activity_on(struct ipw_priv *priv)
896 spin_lock_irqsave(&priv->lock, flags);
897 __ipw_led_activity_on(priv);
898 spin_unlock_irqrestore(&priv->lock, flags);
902 static void ipw_led_activity_off(struct ipw_priv *priv)
907 if (priv->config & CFG_NO_LED)
910 spin_lock_irqsave(&priv->lock, flags);
912 if (priv->status & STATUS_LED_ACT_ON) {
913 led = ipw_read_reg32(priv, IPW_EVENT_REG);
914 led &= priv->led_activity_off;
916 led = ipw_register_toggle(led);
918 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
919 ipw_write_reg32(priv, IPW_EVENT_REG, led);
921 IPW_DEBUG_LED("Activity LED Off\n");
923 priv->status &= ~STATUS_LED_ACT_ON;
926 spin_unlock_irqrestore(&priv->lock, flags);
929 static void ipw_bg_led_activity_off(void *data)
931 struct ipw_priv *priv = data;
932 mutex_lock(&priv->mutex);
933 ipw_led_activity_off(data);
934 mutex_unlock(&priv->mutex);
937 static void ipw_led_band_on(struct ipw_priv *priv)
942 /* Only nic type 1 supports mode LEDs */
943 if (priv->config & CFG_NO_LED ||
944 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
947 spin_lock_irqsave(&priv->lock, flags);
949 led = ipw_read_reg32(priv, IPW_EVENT_REG);
950 if (priv->assoc_network->mode == IEEE_A) {
951 led |= priv->led_ofdm_on;
952 led &= priv->led_association_off;
953 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
954 } else if (priv->assoc_network->mode == IEEE_G) {
955 led |= priv->led_ofdm_on;
956 led |= priv->led_association_on;
957 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
959 led &= priv->led_ofdm_off;
960 led |= priv->led_association_on;
961 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
964 led = ipw_register_toggle(led);
966 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
967 ipw_write_reg32(priv, IPW_EVENT_REG, led);
969 spin_unlock_irqrestore(&priv->lock, flags);
972 static void ipw_led_band_off(struct ipw_priv *priv)
977 /* Only nic type 1 supports mode LEDs */
978 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
981 spin_lock_irqsave(&priv->lock, flags);
983 led = ipw_read_reg32(priv, IPW_EVENT_REG);
984 led &= priv->led_ofdm_off;
985 led &= priv->led_association_off;
987 led = ipw_register_toggle(led);
989 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
990 ipw_write_reg32(priv, IPW_EVENT_REG, led);
992 spin_unlock_irqrestore(&priv->lock, flags);
995 static void ipw_led_radio_on(struct ipw_priv *priv)
997 ipw_led_link_on(priv);
1000 static void ipw_led_radio_off(struct ipw_priv *priv)
1002 ipw_led_activity_off(priv);
1003 ipw_led_link_off(priv);
1006 static void ipw_led_link_up(struct ipw_priv *priv)
1008 /* Set the Link Led on for all nic types */
1009 ipw_led_link_on(priv);
1012 static void ipw_led_link_down(struct ipw_priv *priv)
1014 ipw_led_activity_off(priv);
1015 ipw_led_link_off(priv);
1017 if (priv->status & STATUS_RF_KILL_MASK)
1018 ipw_led_radio_off(priv);
1021 static void ipw_led_init(struct ipw_priv *priv)
1023 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1025 /* Set the default PINs for the link and activity leds */
1026 priv->led_activity_on = IPW_ACTIVITY_LED;
1027 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
1029 priv->led_association_on = IPW_ASSOCIATED_LED;
1030 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
1032 /* Set the default PINs for the OFDM leds */
1033 priv->led_ofdm_on = IPW_OFDM_LED;
1034 priv->led_ofdm_off = ~(IPW_OFDM_LED);
1036 switch (priv->nic_type) {
1037 case EEPROM_NIC_TYPE_1:
1038 /* In this NIC type, the LEDs are reversed.... */
1039 priv->led_activity_on = IPW_ASSOCIATED_LED;
1040 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1041 priv->led_association_on = IPW_ACTIVITY_LED;
1042 priv->led_association_off = ~(IPW_ACTIVITY_LED);
1044 if (!(priv->config & CFG_NO_LED))
1045 ipw_led_band_on(priv);
1047 /* And we don't blink link LEDs for this nic, so
1048 * just return here */
1051 case EEPROM_NIC_TYPE_3:
1052 case EEPROM_NIC_TYPE_2:
1053 case EEPROM_NIC_TYPE_4:
1054 case EEPROM_NIC_TYPE_0:
1058 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1060 priv->nic_type = EEPROM_NIC_TYPE_0;
1064 if (!(priv->config & CFG_NO_LED)) {
1065 if (priv->status & STATUS_ASSOCIATED)
1066 ipw_led_link_on(priv);
1068 ipw_led_link_off(priv);
1072 static void ipw_led_shutdown(struct ipw_priv *priv)
1074 ipw_led_activity_off(priv);
1075 ipw_led_link_off(priv);
1076 ipw_led_band_off(priv);
1077 cancel_delayed_work(&priv->led_link_on);
1078 cancel_delayed_work(&priv->led_link_off);
1079 cancel_delayed_work(&priv->led_act_off);
1083 * The following adds a new attribute to the sysfs representation
1084 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1085 * used for controling the debug level.
1087 * See the level definitions in ipw for details.
1089 static ssize_t show_debug_level(struct device_driver *d, char *buf)
1091 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1094 static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1097 char *p = (char *)buf;
1100 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1102 if (p[0] == 'x' || p[0] == 'X')
1104 val = simple_strtoul(p, &p, 16);
1106 val = simple_strtoul(p, &p, 10);
1108 printk(KERN_INFO DRV_NAME
1109 ": %s is not in hex or decimal form.\n", buf);
1111 ipw_debug_level = val;
1113 return strnlen(buf, count);
1116 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
1117 show_debug_level, store_debug_level);
1119 static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1121 /* length = 1st dword in log */
1122 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1125 static void ipw_capture_event_log(struct ipw_priv *priv,
1126 u32 log_len, struct ipw_event *log)
1131 base = ipw_read32(priv, IPW_EVENT_LOG);
1132 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1133 (u8 *) log, sizeof(*log) * log_len);
1137 static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1139 struct ipw_fw_error *error;
1140 u32 log_len = ipw_get_event_log_len(priv);
1141 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1142 u32 elem_len = ipw_read_reg32(priv, base);
1144 error = kmalloc(sizeof(*error) +
1145 sizeof(*error->elem) * elem_len +
1146 sizeof(*error->log) * log_len, GFP_ATOMIC);
1148 IPW_ERROR("Memory allocation for firmware error log "
1152 error->jiffies = jiffies;
1153 error->status = priv->status;
1154 error->config = priv->config;
1155 error->elem_len = elem_len;
1156 error->log_len = log_len;
1157 error->elem = (struct ipw_error_elem *)error->payload;
1158 error->log = (struct ipw_event *)(error->elem + elem_len);
1160 ipw_capture_event_log(priv, log_len, error->log);
1163 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1164 sizeof(*error->elem) * elem_len);
1169 static void ipw_free_error_log(struct ipw_fw_error *error)
1175 static ssize_t show_event_log(struct device *d,
1176 struct device_attribute *attr, char *buf)
1178 struct ipw_priv *priv = dev_get_drvdata(d);
1179 u32 log_len = ipw_get_event_log_len(priv);
1180 struct ipw_event log[log_len];
1183 ipw_capture_event_log(priv, log_len, log);
1185 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1186 for (i = 0; i < log_len; i++)
1187 len += snprintf(buf + len, PAGE_SIZE - len,
1189 log[i].time, log[i].event, log[i].data);
1190 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1194 static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1196 static ssize_t show_error(struct device *d,
1197 struct device_attribute *attr, char *buf)
1199 struct ipw_priv *priv = dev_get_drvdata(d);
1203 len += snprintf(buf + len, PAGE_SIZE - len,
1204 "%08lX%08X%08X%08X",
1205 priv->error->jiffies,
1206 priv->error->status,
1207 priv->error->config, priv->error->elem_len);
1208 for (i = 0; i < priv->error->elem_len; i++)
1209 len += snprintf(buf + len, PAGE_SIZE - len,
1210 "\n%08X%08X%08X%08X%08X%08X%08X",
1211 priv->error->elem[i].time,
1212 priv->error->elem[i].desc,
1213 priv->error->elem[i].blink1,
1214 priv->error->elem[i].blink2,
1215 priv->error->elem[i].link1,
1216 priv->error->elem[i].link2,
1217 priv->error->elem[i].data);
1219 len += snprintf(buf + len, PAGE_SIZE - len,
1220 "\n%08X", priv->error->log_len);
1221 for (i = 0; i < priv->error->log_len; i++)
1222 len += snprintf(buf + len, PAGE_SIZE - len,
1224 priv->error->log[i].time,
1225 priv->error->log[i].event,
1226 priv->error->log[i].data);
1227 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1231 static ssize_t clear_error(struct device *d,
1232 struct device_attribute *attr,
1233 const char *buf, size_t count)
1235 struct ipw_priv *priv = dev_get_drvdata(d);
1237 ipw_free_error_log(priv->error);
1243 static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1245 static ssize_t show_cmd_log(struct device *d,
1246 struct device_attribute *attr, char *buf)
1248 struct ipw_priv *priv = dev_get_drvdata(d);
1252 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1253 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1254 i = (i + 1) % priv->cmdlog_len) {
1256 snprintf(buf + len, PAGE_SIZE - len,
1257 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1258 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1259 priv->cmdlog[i].cmd.len);
1261 snprintk_buf(buf + len, PAGE_SIZE - len,
1262 (u8 *) priv->cmdlog[i].cmd.param,
1263 priv->cmdlog[i].cmd.len);
1264 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1266 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1270 static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1272 static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1275 struct ipw_priv *priv = dev_get_drvdata(d);
1276 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1279 static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1280 const char *buf, size_t count)
1282 struct ipw_priv *priv = dev_get_drvdata(d);
1283 #ifdef CONFIG_IPW2200_DEBUG
1284 struct net_device *dev = priv->net_dev;
1286 char buffer[] = "00000000";
1288 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1292 IPW_DEBUG_INFO("enter\n");
1294 strncpy(buffer, buf, len);
1297 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1299 if (p[0] == 'x' || p[0] == 'X')
1301 val = simple_strtoul(p, &p, 16);
1303 val = simple_strtoul(p, &p, 10);
1305 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1307 priv->ieee->scan_age = val;
1308 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1311 IPW_DEBUG_INFO("exit\n");
1315 static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1317 static ssize_t show_led(struct device *d, struct device_attribute *attr,
1320 struct ipw_priv *priv = dev_get_drvdata(d);
1321 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1324 static ssize_t store_led(struct device *d, struct device_attribute *attr,
1325 const char *buf, size_t count)
1327 struct ipw_priv *priv = dev_get_drvdata(d);
1329 IPW_DEBUG_INFO("enter\n");
1335 IPW_DEBUG_LED("Disabling LED control.\n");
1336 priv->config |= CFG_NO_LED;
1337 ipw_led_shutdown(priv);
1339 IPW_DEBUG_LED("Enabling LED control.\n");
1340 priv->config &= ~CFG_NO_LED;
1344 IPW_DEBUG_INFO("exit\n");
1348 static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1350 static ssize_t show_status(struct device *d,
1351 struct device_attribute *attr, char *buf)
1353 struct ipw_priv *p = d->driver_data;
1354 return sprintf(buf, "0x%08x\n", (int)p->status);
1357 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1359 static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1362 struct ipw_priv *p = d->driver_data;
1363 return sprintf(buf, "0x%08x\n", (int)p->config);
1366 static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1368 static ssize_t show_nic_type(struct device *d,
1369 struct device_attribute *attr, char *buf)
1371 struct ipw_priv *priv = d->driver_data;
1372 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
1375 static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1377 static ssize_t show_ucode_version(struct device *d,
1378 struct device_attribute *attr, char *buf)
1380 u32 len = sizeof(u32), tmp = 0;
1381 struct ipw_priv *p = d->driver_data;
1383 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
1386 return sprintf(buf, "0x%08x\n", tmp);
1389 static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
1391 static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1394 u32 len = sizeof(u32), tmp = 0;
1395 struct ipw_priv *p = d->driver_data;
1397 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
1400 return sprintf(buf, "0x%08x\n", tmp);
1403 static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
1406 * Add a device attribute to view/control the delay between eeprom
1409 static ssize_t show_eeprom_delay(struct device *d,
1410 struct device_attribute *attr, char *buf)
1412 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
1413 return sprintf(buf, "%i\n", n);
1415 static ssize_t store_eeprom_delay(struct device *d,
1416 struct device_attribute *attr,
1417 const char *buf, size_t count)
1419 struct ipw_priv *p = d->driver_data;
1420 sscanf(buf, "%i", &p->eeprom_delay);
1421 return strnlen(buf, count);
1424 static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1425 show_eeprom_delay, store_eeprom_delay);
1427 static ssize_t show_command_event_reg(struct device *d,
1428 struct device_attribute *attr, char *buf)
1431 struct ipw_priv *p = d->driver_data;
1433 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
1434 return sprintf(buf, "0x%08x\n", reg);
1436 static ssize_t store_command_event_reg(struct device *d,
1437 struct device_attribute *attr,
1438 const char *buf, size_t count)
1441 struct ipw_priv *p = d->driver_data;
1443 sscanf(buf, "%x", ®);
1444 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
1445 return strnlen(buf, count);
1448 static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1449 show_command_event_reg, store_command_event_reg);
1451 static ssize_t show_mem_gpio_reg(struct device *d,
1452 struct device_attribute *attr, char *buf)
1455 struct ipw_priv *p = d->driver_data;
1457 reg = ipw_read_reg32(p, 0x301100);
1458 return sprintf(buf, "0x%08x\n", reg);
1460 static ssize_t store_mem_gpio_reg(struct device *d,
1461 struct device_attribute *attr,
1462 const char *buf, size_t count)
1465 struct ipw_priv *p = d->driver_data;
1467 sscanf(buf, "%x", ®);
1468 ipw_write_reg32(p, 0x301100, reg);
1469 return strnlen(buf, count);
1472 static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1473 show_mem_gpio_reg, store_mem_gpio_reg);
1475 static ssize_t show_indirect_dword(struct device *d,
1476 struct device_attribute *attr, char *buf)
1479 struct ipw_priv *priv = d->driver_data;
1481 if (priv->status & STATUS_INDIRECT_DWORD)
1482 reg = ipw_read_reg32(priv, priv->indirect_dword);
1486 return sprintf(buf, "0x%08x\n", reg);
1488 static ssize_t store_indirect_dword(struct device *d,
1489 struct device_attribute *attr,
1490 const char *buf, size_t count)
1492 struct ipw_priv *priv = d->driver_data;
1494 sscanf(buf, "%x", &priv->indirect_dword);
1495 priv->status |= STATUS_INDIRECT_DWORD;
1496 return strnlen(buf, count);
1499 static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1500 show_indirect_dword, store_indirect_dword);
1502 static ssize_t show_indirect_byte(struct device *d,
1503 struct device_attribute *attr, char *buf)
1506 struct ipw_priv *priv = d->driver_data;
1508 if (priv->status & STATUS_INDIRECT_BYTE)
1509 reg = ipw_read_reg8(priv, priv->indirect_byte);
1513 return sprintf(buf, "0x%02x\n", reg);
1515 static ssize_t store_indirect_byte(struct device *d,
1516 struct device_attribute *attr,
1517 const char *buf, size_t count)
1519 struct ipw_priv *priv = d->driver_data;
1521 sscanf(buf, "%x", &priv->indirect_byte);
1522 priv->status |= STATUS_INDIRECT_BYTE;
1523 return strnlen(buf, count);
1526 static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
1527 show_indirect_byte, store_indirect_byte);
1529 static ssize_t show_direct_dword(struct device *d,
1530 struct device_attribute *attr, char *buf)
1533 struct ipw_priv *priv = d->driver_data;
1535 if (priv->status & STATUS_DIRECT_DWORD)
1536 reg = ipw_read32(priv, priv->direct_dword);
1540 return sprintf(buf, "0x%08x\n", reg);
1542 static ssize_t store_direct_dword(struct device *d,
1543 struct device_attribute *attr,
1544 const char *buf, size_t count)
1546 struct ipw_priv *priv = d->driver_data;
1548 sscanf(buf, "%x", &priv->direct_dword);
1549 priv->status |= STATUS_DIRECT_DWORD;
1550 return strnlen(buf, count);
1553 static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1554 show_direct_dword, store_direct_dword);
1556 static int rf_kill_active(struct ipw_priv *priv)
1558 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1559 priv->status |= STATUS_RF_KILL_HW;
1561 priv->status &= ~STATUS_RF_KILL_HW;
1563 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1566 static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
1569 /* 0 - RF kill not enabled
1570 1 - SW based RF kill active (sysfs)
1571 2 - HW based RF kill active
1572 3 - Both HW and SW baed RF kill active */
1573 struct ipw_priv *priv = d->driver_data;
1574 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
1575 (rf_kill_active(priv) ? 0x2 : 0x0);
1576 return sprintf(buf, "%i\n", val);
1579 static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1581 if ((disable_radio ? 1 : 0) ==
1582 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
1585 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1586 disable_radio ? "OFF" : "ON");
1588 if (disable_radio) {
1589 priv->status |= STATUS_RF_KILL_SW;
1591 if (priv->workqueue)
1592 cancel_delayed_work(&priv->request_scan);
1593 queue_work(priv->workqueue, &priv->down);
1595 priv->status &= ~STATUS_RF_KILL_SW;
1596 if (rf_kill_active(priv)) {
1597 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1598 "disabled by HW switch\n");
1599 /* Make sure the RF_KILL check timer is running */
1600 cancel_delayed_work(&priv->rf_kill);
1601 queue_delayed_work(priv->workqueue, &priv->rf_kill,
1604 queue_work(priv->workqueue, &priv->up);
1610 static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1611 const char *buf, size_t count)
1613 struct ipw_priv *priv = d->driver_data;
1615 ipw_radio_kill_sw(priv, buf[0] == '1');
1620 static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
1622 static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1625 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1626 int pos = 0, len = 0;
1627 if (priv->config & CFG_SPEED_SCAN) {
1628 while (priv->speed_scan[pos] != 0)
1629 len += sprintf(&buf[len], "%d ",
1630 priv->speed_scan[pos++]);
1631 return len + sprintf(&buf[len], "\n");
1634 return sprintf(buf, "0\n");
1637 static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1638 const char *buf, size_t count)
1640 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1641 int channel, pos = 0;
1642 const char *p = buf;
1644 /* list of space separated channels to scan, optionally ending with 0 */
1645 while ((channel = simple_strtol(p, NULL, 0))) {
1646 if (pos == MAX_SPEED_SCAN - 1) {
1647 priv->speed_scan[pos] = 0;
1651 if (ieee80211_is_valid_channel(priv->ieee, channel))
1652 priv->speed_scan[pos++] = channel;
1654 IPW_WARNING("Skipping invalid channel request: %d\n",
1659 while (*p == ' ' || *p == '\t')
1664 priv->config &= ~CFG_SPEED_SCAN;
1666 priv->speed_scan_pos = 0;
1667 priv->config |= CFG_SPEED_SCAN;
1673 static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1676 static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1679 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1680 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1683 static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1684 const char *buf, size_t count)
1686 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1688 priv->config |= CFG_NET_STATS;
1690 priv->config &= ~CFG_NET_STATS;
1695 static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1696 show_net_stats, store_net_stats);
1698 static void notify_wx_assoc_event(struct ipw_priv *priv)
1700 union iwreq_data wrqu;
1701 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1702 if (priv->status & STATUS_ASSOCIATED)
1703 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1705 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1706 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1709 static void ipw_irq_tasklet(struct ipw_priv *priv)
1711 u32 inta, inta_mask, handled = 0;
1712 unsigned long flags;
1715 spin_lock_irqsave(&priv->lock, flags);
1717 inta = ipw_read32(priv, IPW_INTA_RW);
1718 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1719 inta &= (IPW_INTA_MASK_ALL & inta_mask);
1721 /* Add any cached INTA values that need to be handled */
1722 inta |= priv->isr_inta;
1724 /* handle all the justifications for the interrupt */
1725 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
1727 handled |= IPW_INTA_BIT_RX_TRANSFER;
1730 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
1731 IPW_DEBUG_HC("Command completed.\n");
1732 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
1733 priv->status &= ~STATUS_HCMD_ACTIVE;
1734 wake_up_interruptible(&priv->wait_command_queue);
1735 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
1738 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
1739 IPW_DEBUG_TX("TX_QUEUE_1\n");
1740 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
1741 handled |= IPW_INTA_BIT_TX_QUEUE_1;
1744 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
1745 IPW_DEBUG_TX("TX_QUEUE_2\n");
1746 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
1747 handled |= IPW_INTA_BIT_TX_QUEUE_2;
1750 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
1751 IPW_DEBUG_TX("TX_QUEUE_3\n");
1752 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
1753 handled |= IPW_INTA_BIT_TX_QUEUE_3;
1756 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
1757 IPW_DEBUG_TX("TX_QUEUE_4\n");
1758 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
1759 handled |= IPW_INTA_BIT_TX_QUEUE_4;
1762 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
1763 IPW_WARNING("STATUS_CHANGE\n");
1764 handled |= IPW_INTA_BIT_STATUS_CHANGE;
1767 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
1768 IPW_WARNING("TX_PERIOD_EXPIRED\n");
1769 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
1772 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
1773 IPW_WARNING("HOST_CMD_DONE\n");
1774 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
1777 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
1778 IPW_WARNING("FW_INITIALIZATION_DONE\n");
1779 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
1782 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
1783 IPW_WARNING("PHY_OFF_DONE\n");
1784 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
1787 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
1788 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1789 priv->status |= STATUS_RF_KILL_HW;
1790 wake_up_interruptible(&priv->wait_command_queue);
1791 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1792 cancel_delayed_work(&priv->request_scan);
1793 schedule_work(&priv->link_down);
1794 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
1795 handled |= IPW_INTA_BIT_RF_KILL_DONE;
1798 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
1799 IPW_WARNING("Firmware error detected. Restarting.\n");
1801 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
1802 #ifdef CONFIG_IPW2200_DEBUG
1803 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1804 struct ipw_fw_error *error =
1805 ipw_alloc_error_log(priv);
1806 ipw_dump_error_log(priv, error);
1808 ipw_free_error_log(error);
1812 priv->error = ipw_alloc_error_log(priv);
1814 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
1816 IPW_DEBUG_FW("Error allocating sysfs 'error' "
1818 #ifdef CONFIG_IPW2200_DEBUG
1819 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1820 ipw_dump_error_log(priv, priv->error);
1824 /* XXX: If hardware encryption is for WPA/WPA2,
1825 * we have to notify the supplicant. */
1826 if (priv->ieee->sec.encrypt) {
1827 priv->status &= ~STATUS_ASSOCIATED;
1828 notify_wx_assoc_event(priv);
1831 /* Keep the restart process from trying to send host
1832 * commands by clearing the INIT status bit */
1833 priv->status &= ~STATUS_INIT;
1835 /* Cancel currently queued command. */
1836 priv->status &= ~STATUS_HCMD_ACTIVE;
1837 wake_up_interruptible(&priv->wait_command_queue);
1839 queue_work(priv->workqueue, &priv->adapter_restart);
1840 handled |= IPW_INTA_BIT_FATAL_ERROR;
1843 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
1844 IPW_ERROR("Parity error\n");
1845 handled |= IPW_INTA_BIT_PARITY_ERROR;
1848 if (handled != inta) {
1849 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
1852 /* enable all interrupts */
1853 ipw_enable_interrupts(priv);
1855 spin_unlock_irqrestore(&priv->lock, flags);
1858 #define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1859 static char *get_cmd_string(u8 cmd)
1862 IPW_CMD(HOST_COMPLETE);
1863 IPW_CMD(POWER_DOWN);
1864 IPW_CMD(SYSTEM_CONFIG);
1865 IPW_CMD(MULTICAST_ADDRESS);
1867 IPW_CMD(ADAPTER_ADDRESS);
1869 IPW_CMD(RTS_THRESHOLD);
1870 IPW_CMD(FRAG_THRESHOLD);
1871 IPW_CMD(POWER_MODE);
1873 IPW_CMD(TGI_TX_KEY);
1874 IPW_CMD(SCAN_REQUEST);
1875 IPW_CMD(SCAN_REQUEST_EXT);
1877 IPW_CMD(SUPPORTED_RATES);
1878 IPW_CMD(SCAN_ABORT);
1880 IPW_CMD(QOS_PARAMETERS);
1881 IPW_CMD(DINO_CONFIG);
1882 IPW_CMD(RSN_CAPABILITIES);
1884 IPW_CMD(CARD_DISABLE);
1885 IPW_CMD(SEED_NUMBER);
1887 IPW_CMD(COUNTRY_INFO);
1888 IPW_CMD(AIRONET_INFO);
1889 IPW_CMD(AP_TX_POWER);
1891 IPW_CMD(CCX_VER_INFO);
1892 IPW_CMD(SET_CALIBRATION);
1893 IPW_CMD(SENSITIVITY_CALIB);
1894 IPW_CMD(RETRY_LIMIT);
1895 IPW_CMD(IPW_PRE_POWER_DOWN);
1896 IPW_CMD(VAP_BEACON_TEMPLATE);
1897 IPW_CMD(VAP_DTIM_PERIOD);
1898 IPW_CMD(EXT_SUPPORTED_RATES);
1899 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
1900 IPW_CMD(VAP_QUIET_INTERVALS);
1901 IPW_CMD(VAP_CHANNEL_SWITCH);
1902 IPW_CMD(VAP_MANDATORY_CHANNELS);
1903 IPW_CMD(VAP_CELL_PWR_LIMIT);
1904 IPW_CMD(VAP_CF_PARAM_SET);
1905 IPW_CMD(VAP_SET_BEACONING_STATE);
1906 IPW_CMD(MEASUREMENT);
1907 IPW_CMD(POWER_CAPABILITY);
1908 IPW_CMD(SUPPORTED_CHANNELS);
1909 IPW_CMD(TPC_REPORT);
1911 IPW_CMD(PRODUCTION_COMMAND);
1917 #define HOST_COMPLETE_TIMEOUT HZ
1919 static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
1922 unsigned long flags;
1924 spin_lock_irqsave(&priv->lock, flags);
1925 if (priv->status & STATUS_HCMD_ACTIVE) {
1926 IPW_ERROR("Failed to send %s: Already sending a command.\n",
1927 get_cmd_string(cmd->cmd));
1928 spin_unlock_irqrestore(&priv->lock, flags);
1932 priv->status |= STATUS_HCMD_ACTIVE;
1935 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
1936 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
1937 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
1938 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
1940 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
1943 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
1944 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
1947 #ifndef DEBUG_CMD_WEP_KEY
1948 if (cmd->cmd == IPW_CMD_WEP_KEY)
1949 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
1952 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
1954 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
1956 priv->status &= ~STATUS_HCMD_ACTIVE;
1957 IPW_ERROR("Failed to send %s: Reason %d\n",
1958 get_cmd_string(cmd->cmd), rc);
1959 spin_unlock_irqrestore(&priv->lock, flags);
1962 spin_unlock_irqrestore(&priv->lock, flags);
1964 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1966 status & STATUS_HCMD_ACTIVE),
1967 HOST_COMPLETE_TIMEOUT);
1969 spin_lock_irqsave(&priv->lock, flags);
1970 if (priv->status & STATUS_HCMD_ACTIVE) {
1971 IPW_ERROR("Failed to send %s: Command timed out.\n",
1972 get_cmd_string(cmd->cmd));
1973 priv->status &= ~STATUS_HCMD_ACTIVE;
1974 spin_unlock_irqrestore(&priv->lock, flags);
1978 spin_unlock_irqrestore(&priv->lock, flags);
1982 if (priv->status & STATUS_RF_KILL_HW) {
1983 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
1984 get_cmd_string(cmd->cmd));
1991 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
1992 priv->cmdlog_pos %= priv->cmdlog_len;
1997 static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
1999 struct host_cmd cmd = {
2003 return __ipw_send_cmd(priv, &cmd);
2006 static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2009 struct host_cmd cmd = {
2015 return __ipw_send_cmd(priv, &cmd);
2018 static int ipw_send_host_complete(struct ipw_priv *priv)
2021 IPW_ERROR("Invalid args\n");
2025 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
2028 static int ipw_send_system_config(struct ipw_priv *priv,
2029 struct ipw_sys_config *config)
2031 if (!priv || !config) {
2032 IPW_ERROR("Invalid args\n");
2036 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, sizeof(*config),
2040 static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
2042 if (!priv || !ssid) {
2043 IPW_ERROR("Invalid args\n");
2047 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
2051 static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
2053 if (!priv || !mac) {
2054 IPW_ERROR("Invalid args\n");
2058 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2059 priv->net_dev->name, MAC_ARG(mac));
2061 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
2065 * NOTE: This must be executed from our workqueue as it results in udelay
2066 * being called which may corrupt the keyboard if executed on default
2069 static void ipw_adapter_restart(void *adapter)
2071 struct ipw_priv *priv = adapter;
2073 if (priv->status & STATUS_RF_KILL_MASK)
2078 if (priv->assoc_network &&
2079 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2080 ipw_remove_current_network(priv);
2083 IPW_ERROR("Failed to up device\n");
2088 static void ipw_bg_adapter_restart(void *data)
2090 struct ipw_priv *priv = data;
2091 mutex_lock(&priv->mutex);
2092 ipw_adapter_restart(data);
2093 mutex_unlock(&priv->mutex);
2096 #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2098 static void ipw_scan_check(void *data)
2100 struct ipw_priv *priv = data;
2101 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2102 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
2103 "adapter after (%dms).\n",
2104 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
2105 queue_work(priv->workqueue, &priv->adapter_restart);
2109 static void ipw_bg_scan_check(void *data)
2111 struct ipw_priv *priv = data;
2112 mutex_lock(&priv->mutex);
2113 ipw_scan_check(data);
2114 mutex_unlock(&priv->mutex);
2117 static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2118 struct ipw_scan_request_ext *request)
2120 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
2121 sizeof(*request), request);
2124 static int ipw_send_scan_abort(struct ipw_priv *priv)
2127 IPW_ERROR("Invalid args\n");
2131 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
2134 static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2136 struct ipw_sensitivity_calib calib = {
2137 .beacon_rssi_raw = sens,
2140 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
2144 static int ipw_send_associate(struct ipw_priv *priv,
2145 struct ipw_associate *associate)
2147 struct ipw_associate tmp_associate;
2149 if (!priv || !associate) {
2150 IPW_ERROR("Invalid args\n");
2154 memcpy(&tmp_associate, associate, sizeof(*associate));
2155 tmp_associate.policy_support =
2156 cpu_to_le16(tmp_associate.policy_support);
2157 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2158 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2159 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2160 tmp_associate.listen_interval =
2161 cpu_to_le16(tmp_associate.listen_interval);
2162 tmp_associate.beacon_interval =
2163 cpu_to_le16(tmp_associate.beacon_interval);
2164 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2166 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
2170 static int ipw_send_supported_rates(struct ipw_priv *priv,
2171 struct ipw_supported_rates *rates)
2173 if (!priv || !rates) {
2174 IPW_ERROR("Invalid args\n");
2178 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
2182 static int ipw_set_random_seed(struct ipw_priv *priv)
2187 IPW_ERROR("Invalid args\n");
2191 get_random_bytes(&val, sizeof(val));
2193 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
2196 static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2199 IPW_ERROR("Invalid args\n");
2203 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off),
2207 static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
2209 if (!priv || !power) {
2210 IPW_ERROR("Invalid args\n");
2214 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
2217 static int ipw_set_tx_power(struct ipw_priv *priv)
2219 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
2220 struct ipw_tx_power tx_power;
2224 memset(&tx_power, 0, sizeof(tx_power));
2226 /* configure device for 'G' band */
2227 tx_power.ieee_mode = IPW_G_MODE;
2228 tx_power.num_channels = geo->bg_channels;
2229 for (i = 0; i < geo->bg_channels; i++) {
2230 max_power = geo->bg[i].max_power;
2231 tx_power.channels_tx_power[i].channel_number =
2233 tx_power.channels_tx_power[i].tx_power = max_power ?
2234 min(max_power, priv->tx_power) : priv->tx_power;
2236 if (ipw_send_tx_power(priv, &tx_power))
2239 /* configure device to also handle 'B' band */
2240 tx_power.ieee_mode = IPW_B_MODE;
2241 if (ipw_send_tx_power(priv, &tx_power))
2244 /* configure device to also handle 'A' band */
2245 if (priv->ieee->abg_true) {
2246 tx_power.ieee_mode = IPW_A_MODE;
2247 tx_power.num_channels = geo->a_channels;
2248 for (i = 0; i < tx_power.num_channels; i++) {
2249 max_power = geo->a[i].max_power;
2250 tx_power.channels_tx_power[i].channel_number =
2252 tx_power.channels_tx_power[i].tx_power = max_power ?
2253 min(max_power, priv->tx_power) : priv->tx_power;
2255 if (ipw_send_tx_power(priv, &tx_power))
2261 static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2263 struct ipw_rts_threshold rts_threshold = {
2264 .rts_threshold = rts,
2268 IPW_ERROR("Invalid args\n");
2272 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2273 sizeof(rts_threshold), &rts_threshold);
2276 static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2278 struct ipw_frag_threshold frag_threshold = {
2279 .frag_threshold = frag,
2283 IPW_ERROR("Invalid args\n");
2287 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2288 sizeof(frag_threshold), &frag_threshold);
2291 static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2296 IPW_ERROR("Invalid args\n");
2300 /* If on battery, set to 3, if AC set to CAM, else user
2303 case IPW_POWER_BATTERY:
2304 param = IPW_POWER_INDEX_3;
2307 param = IPW_POWER_MODE_CAM;
2314 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
2318 static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2320 struct ipw_retry_limit retry_limit = {
2321 .short_retry_limit = slimit,
2322 .long_retry_limit = llimit
2326 IPW_ERROR("Invalid args\n");
2330 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
2335 * The IPW device contains a Microwire compatible EEPROM that stores
2336 * various data like the MAC address. Usually the firmware has exclusive
2337 * access to the eeprom, but during device initialization (before the
2338 * device driver has sent the HostComplete command to the firmware) the
2339 * device driver has read access to the EEPROM by way of indirect addressing
2340 * through a couple of memory mapped registers.
2342 * The following is a simplified implementation for pulling data out of the
2343 * the eeprom, along with some helper functions to find information in
2344 * the per device private data's copy of the eeprom.
2346 * NOTE: To better understand how these functions work (i.e what is a chip
2347 * select and why do have to keep driving the eeprom clock?), read
2348 * just about any data sheet for a Microwire compatible EEPROM.
2351 /* write a 32 bit value into the indirect accessor register */
2352 static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2354 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
2356 /* the eeprom requires some time to complete the operation */
2357 udelay(p->eeprom_delay);
2362 /* perform a chip select operation */
2363 static void eeprom_cs(struct ipw_priv *priv)
2365 eeprom_write_reg(priv, 0);
2366 eeprom_write_reg(priv, EEPROM_BIT_CS);
2367 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2368 eeprom_write_reg(priv, EEPROM_BIT_CS);
2371 /* perform a chip select operation */
2372 static void eeprom_disable_cs(struct ipw_priv *priv)
2374 eeprom_write_reg(priv, EEPROM_BIT_CS);
2375 eeprom_write_reg(priv, 0);
2376 eeprom_write_reg(priv, EEPROM_BIT_SK);
2379 /* push a single bit down to the eeprom */
2380 static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
2382 int d = (bit ? EEPROM_BIT_DI : 0);
2383 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2384 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
2387 /* push an opcode followed by an address down to the eeprom */
2388 static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
2393 eeprom_write_bit(priv, 1);
2394 eeprom_write_bit(priv, op & 2);
2395 eeprom_write_bit(priv, op & 1);
2396 for (i = 7; i >= 0; i--) {
2397 eeprom_write_bit(priv, addr & (1 << i));
2401 /* pull 16 bits off the eeprom, one bit at a time */
2402 static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
2407 /* Send READ Opcode */
2408 eeprom_op(priv, EEPROM_CMD_READ, addr);
2410 /* Send dummy bit */
2411 eeprom_write_reg(priv, EEPROM_BIT_CS);
2413 /* Read the byte off the eeprom one bit at a time */
2414 for (i = 0; i < 16; i++) {
2416 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2417 eeprom_write_reg(priv, EEPROM_BIT_CS);
2418 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2419 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
2422 /* Send another dummy bit */
2423 eeprom_write_reg(priv, 0);
2424 eeprom_disable_cs(priv);
2429 /* helper function for pulling the mac address out of the private */
2430 /* data's copy of the eeprom data */
2431 static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
2433 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
2437 * Either the device driver (i.e. the host) or the firmware can
2438 * load eeprom data into the designated region in SRAM. If neither
2439 * happens then the FW will shutdown with a fatal error.
2441 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2442 * bit needs region of shared SRAM needs to be non-zero.
2444 static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2447 u16 *eeprom = (u16 *) priv->eeprom;
2449 IPW_DEBUG_TRACE(">>\n");
2451 /* read entire contents of eeprom into private buffer */
2452 for (i = 0; i < 128; i++)
2453 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
2456 If the data looks correct, then copy it to our private
2457 copy. Otherwise let the firmware know to perform the operation
2460 if (priv->eeprom[EEPROM_VERSION] != 0) {
2461 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2463 /* write the eeprom data to sram */
2464 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
2465 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
2467 /* Do not load eeprom data on fatal error or suspend */
2468 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2470 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2472 /* Load eeprom data on fatal error or suspend */
2473 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2476 IPW_DEBUG_TRACE("<<\n");
2479 static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
2484 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
2486 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
2489 static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2491 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
2492 CB_NUMBER_OF_ELEMENTS_SMALL *
2493 sizeof(struct command_block));
2496 static int ipw_fw_dma_enable(struct ipw_priv *priv)
2497 { /* start dma engine but no transfers yet */
2499 IPW_DEBUG_FW(">> : \n");
2502 ipw_fw_dma_reset_command_blocks(priv);
2504 /* Write CB base address */
2505 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
2507 IPW_DEBUG_FW("<< : \n");
2511 static void ipw_fw_dma_abort(struct ipw_priv *priv)
2515 IPW_DEBUG_FW(">> :\n");
2517 //set the Stop and Abort bit
2518 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
2519 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2520 priv->sram_desc.last_cb_index = 0;
2522 IPW_DEBUG_FW("<< \n");
2525 static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2526 struct command_block *cb)
2529 IPW_SHARED_SRAM_DMA_CONTROL +
2530 (sizeof(struct command_block) * index);
2531 IPW_DEBUG_FW(">> :\n");
2533 ipw_write_indirect(priv, address, (u8 *) cb,
2534 (int)sizeof(struct command_block));
2536 IPW_DEBUG_FW("<< :\n");
2541 static int ipw_fw_dma_kick(struct ipw_priv *priv)
2546 IPW_DEBUG_FW(">> :\n");
2548 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
2549 ipw_fw_dma_write_command_block(priv, index,
2550 &priv->sram_desc.cb_list[index]);
2552 /* Enable the DMA in the CSR register */
2553 ipw_clear_bit(priv, IPW_RESET_REG,
2554 IPW_RESET_REG_MASTER_DISABLED |
2555 IPW_RESET_REG_STOP_MASTER);
2557 /* Set the Start bit. */
2558 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
2559 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2561 IPW_DEBUG_FW("<< :\n");
2565 static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2568 u32 register_value = 0;
2569 u32 cb_fields_address = 0;
2571 IPW_DEBUG_FW(">> :\n");
2572 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2573 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
2575 /* Read the DMA Controlor register */
2576 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2577 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
2579 /* Print the CB values */
2580 cb_fields_address = address;
2581 register_value = ipw_read_reg32(priv, cb_fields_address);
2582 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
2584 cb_fields_address += sizeof(u32);
2585 register_value = ipw_read_reg32(priv, cb_fields_address);
2586 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
2588 cb_fields_address += sizeof(u32);
2589 register_value = ipw_read_reg32(priv, cb_fields_address);
2590 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2593 cb_fields_address += sizeof(u32);
2594 register_value = ipw_read_reg32(priv, cb_fields_address);
2595 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
2597 IPW_DEBUG_FW(">> :\n");
2600 static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2602 u32 current_cb_address = 0;
2603 u32 current_cb_index = 0;
2605 IPW_DEBUG_FW("<< :\n");
2606 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2608 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
2609 sizeof(struct command_block);
2611 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
2612 current_cb_index, current_cb_address);
2614 IPW_DEBUG_FW(">> :\n");
2615 return current_cb_index;
2619 static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2623 int interrupt_enabled, int is_last)
2626 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
2627 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2629 struct command_block *cb;
2630 u32 last_cb_element = 0;
2632 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2633 src_address, dest_address, length);
2635 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2638 last_cb_element = priv->sram_desc.last_cb_index;
2639 cb = &priv->sram_desc.cb_list[last_cb_element];
2640 priv->sram_desc.last_cb_index++;
2642 /* Calculate the new CB control word */
2643 if (interrupt_enabled)
2644 control |= CB_INT_ENABLED;
2647 control |= CB_LAST_VALID;
2651 /* Calculate the CB Element's checksum value */
2652 cb->status = control ^ src_address ^ dest_address;
2654 /* Copy the Source and Destination addresses */
2655 cb->dest_addr = dest_address;
2656 cb->source_addr = src_address;
2658 /* Copy the Control Word last */
2659 cb->control = control;
2664 static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
2665 u32 src_phys, u32 dest_address, u32 length)
2667 u32 bytes_left = length;
2669 u32 dest_offset = 0;
2671 IPW_DEBUG_FW(">> \n");
2672 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2673 src_phys, dest_address, length);
2674 while (bytes_left > CB_MAX_LENGTH) {
2675 status = ipw_fw_dma_add_command_block(priv,
2676 src_phys + src_offset,
2679 CB_MAX_LENGTH, 0, 0);
2681 IPW_DEBUG_FW_INFO(": Failed\n");
2684 IPW_DEBUG_FW_INFO(": Added new cb\n");
2686 src_offset += CB_MAX_LENGTH;
2687 dest_offset += CB_MAX_LENGTH;
2688 bytes_left -= CB_MAX_LENGTH;
2691 /* add the buffer tail */
2692 if (bytes_left > 0) {
2694 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2695 dest_address + dest_offset,
2698 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2702 (": Adding new cb - the buffer tail\n");
2705 IPW_DEBUG_FW("<< \n");
2709 static int ipw_fw_dma_wait(struct ipw_priv *priv)
2711 u32 current_index = 0, previous_index;
2714 IPW_DEBUG_FW(">> : \n");
2716 current_index = ipw_fw_dma_command_block_index(priv);
2717 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
2718 (int)priv->sram_desc.last_cb_index);
2720 while (current_index < priv->sram_desc.last_cb_index) {
2722 previous_index = current_index;
2723 current_index = ipw_fw_dma_command_block_index(priv);
2725 if (previous_index < current_index) {
2729 if (++watchdog > 400) {
2730 IPW_DEBUG_FW_INFO("Timeout\n");
2731 ipw_fw_dma_dump_command_block(priv);
2732 ipw_fw_dma_abort(priv);
2737 ipw_fw_dma_abort(priv);
2739 /*Disable the DMA in the CSR register */
2740 ipw_set_bit(priv, IPW_RESET_REG,
2741 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
2743 IPW_DEBUG_FW("<< dmaWaitSync \n");
2747 static void ipw_remove_current_network(struct ipw_priv *priv)
2749 struct list_head *element, *safe;
2750 struct ieee80211_network *network = NULL;
2751 unsigned long flags;
2753 spin_lock_irqsave(&priv->ieee->lock, flags);
2754 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2755 network = list_entry(element, struct ieee80211_network, list);
2756 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2758 list_add_tail(&network->list,
2759 &priv->ieee->network_free_list);
2762 spin_unlock_irqrestore(&priv->ieee->lock, flags);
2766 * Check that card is still alive.
2767 * Reads debug register from domain0.
2768 * If card is present, pre-defined value should
2772 * @return 1 if card is present, 0 otherwise
2774 static inline int ipw_alive(struct ipw_priv *priv)
2776 return ipw_read32(priv, 0x90) == 0xd55555d5;
2779 /* timeout in msec, attempted in 10-msec quanta */
2780 static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2786 if ((ipw_read32(priv, addr) & mask) == mask)
2790 } while (i < timeout);
2795 /* These functions load the firmware and micro code for the operation of
2796 * the ipw hardware. It assumes the buffer has all the bits for the
2797 * image and the caller is handling the memory allocation and clean up.
2800 static int ipw_stop_master(struct ipw_priv *priv)
2804 IPW_DEBUG_TRACE(">> \n");
2805 /* stop master. typical delay - 0 */
2806 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
2808 /* timeout is in msec, polled in 10-msec quanta */
2809 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2810 IPW_RESET_REG_MASTER_DISABLED, 100);
2812 IPW_ERROR("wait for stop master failed after 100ms\n");
2816 IPW_DEBUG_INFO("stop master %dms\n", rc);
2821 static void ipw_arc_release(struct ipw_priv *priv)
2823 IPW_DEBUG_TRACE(">> \n");
2826 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
2828 /* no one knows timing, for safety add some delay */
2837 static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
2839 int rc = 0, i, addr;
2843 image = (u16 *) data;
2845 IPW_DEBUG_TRACE(">> \n");
2847 rc = ipw_stop_master(priv);
2852 // spin_lock_irqsave(&priv->lock, flags);
2854 for (addr = IPW_SHARED_LOWER_BOUND;
2855 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
2856 ipw_write32(priv, addr, 0);
2859 /* no ucode (yet) */
2860 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2861 /* destroy DMA queues */
2862 /* reset sequence */
2864 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
2865 ipw_arc_release(priv);
2866 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
2870 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
2873 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
2876 /* enable ucode store */
2877 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
2878 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
2884 * Do NOT set indirect address register once and then
2885 * store data to indirect data register in the loop.
2886 * It seems very reasonable, but in this case DINO do not
2887 * accept ucode. It is essential to set address each time.
2889 /* load new ipw uCode */
2890 for (i = 0; i < len / 2; i++)
2891 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
2892 cpu_to_le16(image[i]));
2895 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2896 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
2898 /* this is where the igx / win driver deveates from the VAP driver. */
2900 /* wait for alive response */
2901 for (i = 0; i < 100; i++) {
2902 /* poll for incoming data */
2903 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
2904 if (cr & DINO_RXFIFO_DATA)
2909 if (cr & DINO_RXFIFO_DATA) {
2910 /* alive_command_responce size is NOT multiple of 4 */
2911 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
2913 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
2914 response_buffer[i] =
2915 le32_to_cpu(ipw_read_reg32(priv,
2916 IPW_BASEBAND_RX_FIFO_READ));
2917 memcpy(&priv->dino_alive, response_buffer,
2918 sizeof(priv->dino_alive));
2919 if (priv->dino_alive.alive_command == 1
2920 && priv->dino_alive.ucode_valid == 1) {
2923 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2924 "of %02d/%02d/%02d %02d:%02d\n",
2925 priv->dino_alive.software_revision,
2926 priv->dino_alive.software_revision,
2927 priv->dino_alive.device_identifier,
2928 priv->dino_alive.device_identifier,
2929 priv->dino_alive.time_stamp[0],
2930 priv->dino_alive.time_stamp[1],
2931 priv->dino_alive.time_stamp[2],
2932 priv->dino_alive.time_stamp[3],
2933 priv->dino_alive.time_stamp[4]);
2935 IPW_DEBUG_INFO("Microcode is not alive\n");
2939 IPW_DEBUG_INFO("No alive response from DINO\n");
2943 /* disable DINO, otherwise for some reason
2944 firmware have problem getting alive resp. */
2945 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2947 // spin_unlock_irqrestore(&priv->lock, flags);
2952 static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
2956 struct fw_chunk *chunk;
2957 dma_addr_t shared_phys;
2960 IPW_DEBUG_TRACE("<< : \n");
2961 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
2966 memmove(shared_virt, data, len);
2969 rc = ipw_fw_dma_enable(priv);
2971 if (priv->sram_desc.last_cb_index > 0) {
2972 /* the DMA is already ready this would be a bug. */
2978 chunk = (struct fw_chunk *)(data + offset);
2979 offset += sizeof(struct fw_chunk);
2980 /* build DMA packet and queue up for sending */
2981 /* dma to chunk->address, the chunk->length bytes from data +
2984 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
2985 le32_to_cpu(chunk->address),
2986 le32_to_cpu(chunk->length));
2988 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
2992 offset += le32_to_cpu(chunk->length);
2993 } while (offset < len);
2995 /* Run the DMA and wait for the answer */
2996 rc = ipw_fw_dma_kick(priv);
2998 IPW_ERROR("dmaKick Failed\n");
3002 rc = ipw_fw_dma_wait(priv);
3004 IPW_ERROR("dmaWaitSync Failed\n");
3008 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
3013 static int ipw_stop_nic(struct ipw_priv *priv)
3018 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
3020 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3021 IPW_RESET_REG_MASTER_DISABLED, 500);
3023 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
3027 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
3032 static void ipw_start_nic(struct ipw_priv *priv)
3034 IPW_DEBUG_TRACE(">>\n");
3036 /* prvHwStartNic release ARC */
3037 ipw_clear_bit(priv, IPW_RESET_REG,
3038 IPW_RESET_REG_MASTER_DISABLED |
3039 IPW_RESET_REG_STOP_MASTER |
3040 CBD_RESET_REG_PRINCETON_RESET);
3042 /* enable power management */
3043 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3044 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
3046 IPW_DEBUG_TRACE("<<\n");
3049 static int ipw_init_nic(struct ipw_priv *priv)
3053 IPW_DEBUG_TRACE(">>\n");
3056 /* set "initialization complete" bit to move adapter to D0 state */
3057 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3059 /* low-level PLL activation */
3060 ipw_write32(priv, IPW_READ_INT_REGISTER,
3061 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
3063 /* wait for clock stabilization */
3064 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3065 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
3067 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3069 /* assert SW reset */
3070 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
3074 /* set "initialization complete" bit to move adapter to D0 state */
3075 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3077 IPW_DEBUG_TRACE(">>\n");
3081 /* Call this function from process context, it will sleep in request_firmware.
3082 * Probe is an ok place to call this from.
3084 static int ipw_reset_nic(struct ipw_priv *priv)
3087 unsigned long flags;
3089 IPW_DEBUG_TRACE(">>\n");
3091 rc = ipw_init_nic(priv);
3093 spin_lock_irqsave(&priv->lock, flags);
3094 /* Clear the 'host command active' bit... */
3095 priv->status &= ~STATUS_HCMD_ACTIVE;
3096 wake_up_interruptible(&priv->wait_command_queue);
3097 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3098 wake_up_interruptible(&priv->wait_state);
3099 spin_unlock_irqrestore(&priv->lock, flags);
3101 IPW_DEBUG_TRACE("<<\n");
3114 static int ipw_get_fw(struct ipw_priv *priv,
3115 const struct firmware **raw, const char *name)
3120 /* ask firmware_class module to get the boot firmware off disk */
3121 rc = request_firmware(raw, name, &priv->pci_dev->dev);
3123 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
3127 if ((*raw)->size < sizeof(*fw)) {
3128 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
3132 fw = (void *)(*raw)->data;
3134 if ((*raw)->size < sizeof(*fw) +
3135 fw->boot_size + fw->ucode_size + fw->fw_size) {
3136 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3137 name, (*raw)->size);
3141 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
3143 le32_to_cpu(fw->ver) >> 16,
3144 le32_to_cpu(fw->ver) & 0xff,
3145 (*raw)->size - sizeof(*fw));
3149 #define IPW_RX_BUF_SIZE (3000)
3151 static void ipw_rx_queue_reset(struct ipw_priv *priv,
3152 struct ipw_rx_queue *rxq)
3154 unsigned long flags;
3157 spin_lock_irqsave(&rxq->lock, flags);
3159 INIT_LIST_HEAD(&rxq->rx_free);
3160 INIT_LIST_HEAD(&rxq->rx_used);
3162 /* Fill the rx_used queue with _all_ of the Rx buffers */
3163 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3164 /* In the reset function, these buffers may have been allocated
3165 * to an SKB, so we need to unmap and free potential storage */
3166 if (rxq->pool[i].skb != NULL) {
3167 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
3168 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
3169 dev_kfree_skb(rxq->pool[i].skb);
3170 rxq->pool[i].skb = NULL;
3172 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3175 /* Set us so that we have processed and used all buffers, but have
3176 * not restocked the Rx queue with fresh buffers */
3177 rxq->read = rxq->write = 0;
3178 rxq->processed = RX_QUEUE_SIZE - 1;
3179 rxq->free_count = 0;
3180 spin_unlock_irqrestore(&rxq->lock, flags);
3184 static int fw_loaded = 0;
3185 static const struct firmware *raw = NULL;
3187 static void free_firmware(void)
3190 release_firmware(raw);
3196 #define free_firmware() do {} while (0)
3199 static int ipw_load(struct ipw_priv *priv)
3202 const struct firmware *raw = NULL;
3205 u8 *boot_img, *ucode_img, *fw_img;
3207 int rc = 0, retries = 3;
3209 switch (priv->ieee->iw_mode) {
3211 name = "ipw2200-ibss.fw";
3213 #ifdef CONFIG_IPW2200_MONITOR
3214 case IW_MODE_MONITOR:
3215 name = "ipw2200-sniffer.fw";
3219 name = "ipw2200-bss.fw";
3231 rc = ipw_get_fw(priv, &raw, name);
3238 fw = (void *)raw->data;
3239 boot_img = &fw->data[0];
3240 ucode_img = &fw->data[fw->boot_size];
3241 fw_img = &fw->data[fw->boot_size + fw->ucode_size];
3247 priv->rxq = ipw_rx_queue_alloc(priv);
3249 ipw_rx_queue_reset(priv, priv->rxq);
3251 IPW_ERROR("Unable to initialize Rx queue\n");
3256 /* Ensure interrupts are disabled */
3257 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3258 priv->status &= ~STATUS_INT_ENABLED;
3260 /* ack pending interrupts */
3261 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3265 rc = ipw_reset_nic(priv);
3267 IPW_ERROR("Unable to reset NIC\n");
3271 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3272 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
3274 /* DMA the initial boot firmware into the device */
3275 rc = ipw_load_firmware(priv, boot_img, fw->boot_size);
3277 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
3281 /* kick start the device */
3282 ipw_start_nic(priv);
3284 /* wait for the device to finish its initial startup sequence */
3285 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3286 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3288 IPW_ERROR("device failed to boot initial fw image\n");
3291 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3293 /* ack fw init done interrupt */
3294 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3296 /* DMA the ucode into the device */
3297 rc = ipw_load_ucode(priv, ucode_img, fw->ucode_size);
3299 IPW_ERROR("Unable to load ucode: %d\n", rc);
3306 /* DMA bss firmware into the device */
3307 rc = ipw_load_firmware(priv, fw_img, fw->fw_size);
3309 IPW_ERROR("Unable to load firmware: %d\n", rc);
3316 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3318 rc = ipw_queue_reset(priv);
3320 IPW_ERROR("Unable to initialize queues\n");
3324 /* Ensure interrupts are disabled */
3325 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3326 /* ack pending interrupts */
3327 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3329 /* kick start the device */
3330 ipw_start_nic(priv);
3332 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
3334 IPW_WARNING("Parity error. Retrying init.\n");
3339 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3344 /* wait for the device */
3345 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3346 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3348 IPW_ERROR("device failed to start within 500ms\n");
3351 IPW_DEBUG_INFO("device response after %dms\n", rc);
3353 /* ack fw init done interrupt */
3354 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3356 /* read eeprom data and initialize the eeprom region of sram */
3357 priv->eeprom_delay = 1;
3358 ipw_eeprom_init_sram(priv);
3360 /* enable interrupts */
3361 ipw_enable_interrupts(priv);
3363 /* Ensure our queue has valid packets */
3364 ipw_rx_queue_replenish(priv);
3366 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
3368 /* ack pending interrupts */
3369 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3372 release_firmware(raw);
3378 ipw_rx_queue_free(priv, priv->rxq);
3381 ipw_tx_queue_free(priv);
3383 release_firmware(raw);
3395 * Theory of operation
3397 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3398 * 2 empty entries always kept in the buffer to protect from overflow.
3400 * For Tx queue, there are low mark and high mark limits. If, after queuing
3401 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3402 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
3405 * The IPW operates with six queues, one receive queue in the device's
3406 * sram, one transmit queue for sending commands to the device firmware,
3407 * and four transmit queues for data.
3409 * The four transmit queues allow for performing quality of service (qos)
3410 * transmissions as per the 802.11 protocol. Currently Linux does not
3411 * provide a mechanism to the user for utilizing prioritized queues, so
3412 * we only utilize the first data transmit queue (queue1).
3416 * Driver allocates buffers of this size for Rx
3419 static inline int ipw_queue_space(const struct clx2_queue *q)
3421 int s = q->last_used - q->first_empty;
3424 s -= 2; /* keep some reserve to not confuse empty and full situations */
3430 static inline int ipw_queue_inc_wrap(int index, int n_bd)
3432 return (++index == n_bd) ? 0 : index;
3436 * Initialize common DMA queue structure
3438 * @param q queue to init
3439 * @param count Number of BD's to allocate. Should be power of 2
3440 * @param read_register Address for 'read' register
3441 * (not offset within BAR, full address)
3442 * @param write_register Address for 'write' register
3443 * (not offset within BAR, full address)
3444 * @param base_register Address for 'base' register
3445 * (not offset within BAR, full address)
3446 * @param size Address for 'size' register
3447 * (not offset within BAR, full address)
3449 static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
3450 int count, u32 read, u32 write, u32 base, u32 size)
3454 q->low_mark = q->n_bd / 4;
3455 if (q->low_mark < 4)
3458 q->high_mark = q->n_bd / 8;
3459 if (q->high_mark < 2)
3462 q->first_empty = q->last_used = 0;
3466 ipw_write32(priv, base, q->dma_addr);
3467 ipw_write32(priv, size, count);
3468 ipw_write32(priv, read, 0);
3469 ipw_write32(priv, write, 0);
3471 _ipw_read32(priv, 0x90);
3474 static int ipw_queue_tx_init(struct ipw_priv *priv,
3475 struct clx2_tx_queue *q,
3476 int count, u32 read, u32 write, u32 base, u32 size)
3478 struct pci_dev *dev = priv->pci_dev;
3480 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3482 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3487 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
3489 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
3490 sizeof(q->bd[0]) * count);
3496 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3501 * Free one TFD, those at index [txq->q.last_used].
3502 * Do NOT advance any indexes
3507 static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3508 struct clx2_tx_queue *txq)
3510 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3511 struct pci_dev *dev = priv->pci_dev;
3515 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3516 /* nothing to cleanup after for host commands */
3520 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3521 IPW_ERROR("Too many chunks: %i\n",
3522 le32_to_cpu(bd->u.data.num_chunks));
3523 /** @todo issue fatal error, it is quite serious situation */
3527 /* unmap chunks if any */
3528 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3529 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3530 le16_to_cpu(bd->u.data.chunk_len[i]),
3532 if (txq->txb[txq->q.last_used]) {
3533 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3534 txq->txb[txq->q.last_used] = NULL;
3540 * Deallocate DMA queue.
3542 * Empty queue by removing and destroying all BD's.
3548 static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
3550 struct clx2_queue *q = &txq->q;
3551 struct pci_dev *dev = priv->pci_dev;
3556 /* first, empty all BD's */
3557 for (; q->first_empty != q->last_used;
3558 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3559 ipw_queue_tx_free_tfd(priv, txq);
3562 /* free buffers belonging to queue itself */
3563 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
3567 /* 0 fill whole structure */
3568 memset(txq, 0, sizeof(*txq));
3572 * Destroy all DMA queues and structures
3576 static void ipw_tx_queue_free(struct ipw_priv *priv)
3579 ipw_queue_tx_free(priv, &priv->txq_cmd);
3582 ipw_queue_tx_free(priv, &priv->txq[0]);
3583 ipw_queue_tx_free(priv, &priv->txq[1]);
3584 ipw_queue_tx_free(priv, &priv->txq[2]);
3585 ipw_queue_tx_free(priv, &priv->txq[3]);
3588 static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
3590 /* First 3 bytes are manufacturer */
3591 bssid[0] = priv->mac_addr[0];
3592 bssid[1] = priv->mac_addr[1];
3593 bssid[2] = priv->mac_addr[2];
3595 /* Last bytes are random */
3596 get_random_bytes(&bssid[3], ETH_ALEN - 3);
3598 bssid[0] &= 0xfe; /* clear multicast bit */
3599 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
3602 static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
3604 struct ipw_station_entry entry;
3607 for (i = 0; i < priv->num_stations; i++) {
3608 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3609 /* Another node is active in network */
3610 priv->missed_adhoc_beacons = 0;
3611 if (!(priv->config & CFG_STATIC_CHANNEL))
3612 /* when other nodes drop out, we drop out */
3613 priv->config &= ~CFG_ADHOC_PERSIST;
3619 if (i == MAX_STATIONS)
3620 return IPW_INVALID_STATION;
3622 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3625 entry.support_mode = 0;
3626 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3627 memcpy(priv->stations[i], bssid, ETH_ALEN);
3628 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
3629 &entry, sizeof(entry));
3630 priv->num_stations++;
3635 static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
3639 for (i = 0; i < priv->num_stations; i++)
3640 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
3643 return IPW_INVALID_STATION;
3646 static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3650 if (priv->status & STATUS_ASSOCIATING) {
3651 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3652 queue_work(priv->workqueue, &priv->disassociate);
3656 if (!(priv->status & STATUS_ASSOCIATED)) {
3657 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3661 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3663 MAC_ARG(priv->assoc_request.bssid),
3664 priv->assoc_request.channel);
3666 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3667 priv->status |= STATUS_DISASSOCIATING;
3670 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3672 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
3674 err = ipw_send_associate(priv, &priv->assoc_request);
3676 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3683 static int ipw_disassociate(void *data)
3685 struct ipw_priv *priv = data;
3686 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3688 ipw_send_disassociate(data, 0);
3692 static void ipw_bg_disassociate(void *data)
3694 struct ipw_priv *priv = data;
3695 mutex_lock(&priv->mutex);
3696 ipw_disassociate(data);
3697 mutex_unlock(&priv->mutex);
3700 static void ipw_system_config(void *data)
3702 struct ipw_priv *priv = data;
3703 ipw_send_system_config(priv, &priv->sys_config);
3706 struct ipw_status_code {
3711 static const struct ipw_status_code ipw_status_codes[] = {
3712 {0x00, "Successful"},
3713 {0x01, "Unspecified failure"},
3714 {0x0A, "Cannot support all requested capabilities in the "
3715 "Capability information field"},
3716 {0x0B, "Reassociation denied due to inability to confirm that "
3717 "association exists"},
3718 {0x0C, "Association denied due to reason outside the scope of this "
3721 "Responding station does not support the specified authentication "
3724 "Received an Authentication frame with authentication sequence "
3725 "transaction sequence number out of expected sequence"},
3726 {0x0F, "Authentication rejected because of challenge failure"},
3727 {0x10, "Authentication rejected due to timeout waiting for next "
3728 "frame in sequence"},
3729 {0x11, "Association denied because AP is unable to handle additional "
3730 "associated stations"},
3732 "Association denied due to requesting station not supporting all "
3733 "of the datarates in the BSSBasicServiceSet Parameter"},
3735 "Association denied due to requesting station not supporting "
3736 "short preamble operation"},
3738 "Association denied due to requesting station not supporting "
3741 "Association denied due to requesting station not supporting "
3744 "Association denied due to requesting station not supporting "
3745 "short slot operation"},
3747 "Association denied due to requesting station not supporting "
3748 "DSSS-OFDM operation"},
3749 {0x28, "Invalid Information Element"},
3750 {0x29, "Group Cipher is not valid"},
3751 {0x2A, "Pairwise Cipher is not valid"},
3752 {0x2B, "AKMP is not valid"},
3753 {0x2C, "Unsupported RSN IE version"},
3754 {0x2D, "Invalid RSN IE Capabilities"},
3755 {0x2E, "Cipher suite is rejected per security policy"},
3758 #ifdef CONFIG_IPW2200_DEBUG
3759 static const char *ipw_get_status_code(u16 status)
3762 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
3763 if (ipw_status_codes[i].status == (status & 0xff))
3764 return ipw_status_codes[i].reason;
3765 return "Unknown status value.";
3769 static void inline average_init(struct average *avg)
3771 memset(avg, 0, sizeof(*avg));
3774 static void average_add(struct average *avg, s16 val)
3776 avg->sum -= avg->entries[avg->pos];
3778 avg->entries[avg->pos++] = val;
3779 if (unlikely(avg->pos == AVG_ENTRIES)) {
3785 static s16 average_value(struct average *avg)
3787 if (!unlikely(avg->init)) {
3789 return avg->sum / avg->pos;
3793 return avg->sum / AVG_ENTRIES;
3796 static void ipw_reset_stats(struct ipw_priv *priv)
3798 u32 len = sizeof(u32);
3802 average_init(&priv->average_missed_beacons);
3803 average_init(&priv->average_rssi);
3804 average_init(&priv->average_noise);
3806 priv->last_rate = 0;
3807 priv->last_missed_beacons = 0;
3808 priv->last_rx_packets = 0;
3809 priv->last_tx_packets = 0;
3810 priv->last_tx_failures = 0;
3812 /* Firmware managed, reset only when NIC is restarted, so we have to
3813 * normalize on the current value */
3814 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
3815 &priv->last_rx_err, &len);
3816 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
3817 &priv->last_tx_failures, &len);
3819 /* Driver managed, reset with each association */
3820 priv->missed_adhoc_beacons = 0;
3821 priv->missed_beacons = 0;
3822 priv->tx_packets = 0;
3823 priv->rx_packets = 0;
3827 static u32 ipw_get_max_rate(struct ipw_priv *priv)
3830 u32 mask = priv->rates_mask;
3831 /* If currently associated in B mode, restrict the maximum
3832 * rate match to B rates */
3833 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3834 mask &= IEEE80211_CCK_RATES_MASK;
3836 /* TODO: Verify that the rate is supported by the current rates
3839 while (i && !(mask & i))
3842 case IEEE80211_CCK_RATE_1MB_MASK:
3844 case IEEE80211_CCK_RATE_2MB_MASK:
3846 case IEEE80211_CCK_RATE_5MB_MASK:
3848 case IEEE80211_OFDM_RATE_6MB_MASK:
3850 case IEEE80211_OFDM_RATE_9MB_MASK:
3852 case IEEE80211_CCK_RATE_11MB_MASK:
3854 case IEEE80211_OFDM_RATE_12MB_MASK:
3856 case IEEE80211_OFDM_RATE_18MB_MASK:
3858 case IEEE80211_OFDM_RATE_24MB_MASK:
3860 case IEEE80211_OFDM_RATE_36MB_MASK:
3862 case IEEE80211_OFDM_RATE_48MB_MASK:
3864 case IEEE80211_OFDM_RATE_54MB_MASK:
3868 if (priv->ieee->mode == IEEE_B)
3874 static u32 ipw_get_current_rate(struct ipw_priv *priv)
3876 u32 rate, len = sizeof(rate);
3879 if (!(priv->status & STATUS_ASSOCIATED))
3882 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
3883 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
3886 IPW_DEBUG_INFO("failed querying ordinals.\n");
3890 return ipw_get_max_rate(priv);
3893 case IPW_TX_RATE_1MB:
3895 case IPW_TX_RATE_2MB:
3897 case IPW_TX_RATE_5MB:
3899 case IPW_TX_RATE_6MB:
3901 case IPW_TX_RATE_9MB:
3903 case IPW_TX_RATE_11MB:
3905 case IPW_TX_RATE_12MB:
3907 case IPW_TX_RATE_18MB:
3909 case IPW_TX_RATE_24MB:
3911 case IPW_TX_RATE_36MB:
3913 case IPW_TX_RATE_48MB:
3915 case IPW_TX_RATE_54MB:
3922 #define IPW_STATS_INTERVAL (2 * HZ)
3923 static void ipw_gather_stats(struct ipw_priv *priv)
3925 u32 rx_err, rx_err_delta, rx_packets_delta;
3926 u32 tx_failures, tx_failures_delta, tx_packets_delta;
3927 u32 missed_beacons_percent, missed_beacons_delta;
3929 u32 len = sizeof(u32);
3931 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
3935 if (!(priv->status & STATUS_ASSOCIATED)) {
3940 /* Update the statistics */
3941 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
3942 &priv->missed_beacons, &len);
3943 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
3944 priv->last_missed_beacons = priv->missed_beacons;
3945 if (priv->assoc_request.beacon_interval) {
3946 missed_beacons_percent = missed_beacons_delta *
3947 (HZ * priv->assoc_request.beacon_interval) /
3948 (IPW_STATS_INTERVAL * 10);
3950 missed_beacons_percent = 0;
3952 average_add(&priv->average_missed_beacons, missed_beacons_percent);
3954 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
3955 rx_err_delta = rx_err - priv->last_rx_err;
3956 priv->last_rx_err = rx_err;
3958 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
3959 tx_failures_delta = tx_failures - priv->last_tx_failures;
3960 priv->last_tx_failures = tx_failures;
3962 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
3963 priv->last_rx_packets = priv->rx_packets;
3965 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
3966 priv->last_tx_packets = priv->tx_packets;
3968 /* Calculate quality based on the following:
3970 * Missed beacon: 100% = 0, 0% = 70% missed
3971 * Rate: 60% = 1Mbs, 100% = Max
3972 * Rx and Tx errors represent a straight % of total Rx/Tx
3973 * RSSI: 100% = > -50, 0% = < -80
3974 * Rx errors: 100% = 0, 0% = 50% missed
3976 * The lowest computed quality is used.
3979 #define BEACON_THRESHOLD 5
3980 beacon_quality = 100 - missed_beacons_percent;
3981 if (beacon_quality < BEACON_THRESHOLD)
3984 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
3985 (100 - BEACON_THRESHOLD);
3986 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
3987 beacon_quality, missed_beacons_percent);
3989 priv->last_rate = ipw_get_current_rate(priv);
3990 max_rate = ipw_get_max_rate(priv);
3991 rate_quality = priv->last_rate * 40 / max_rate + 60;
3992 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
3993 rate_quality, priv->last_rate / 1000000);
3995 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
3996 rx_quality = 100 - (rx_err_delta * 100) /
3997 (rx_packets_delta + rx_err_delta);
4000 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4001 rx_quality, rx_err_delta, rx_packets_delta);
4003 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
4004 tx_quality = 100 - (tx_failures_delta * 100) /
4005 (tx_packets_delta + tx_failures_delta);
4008 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4009 tx_quality, tx_failures_delta, tx_packets_delta);
4011 rssi = average_value(&priv->average_rssi);
4014 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4015 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4016 (priv->ieee->perfect_rssi - rssi) *
4017 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4018 62 * (priv->ieee->perfect_rssi - rssi))) /
4019 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4020 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4021 if (signal_quality > 100)
4022 signal_quality = 100;
4023 else if (signal_quality < 1)
4026 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
4027 signal_quality, rssi);
4029 quality = min(beacon_quality,
4031 min(tx_quality, min(rx_quality, signal_quality))));
4032 if (quality == beacon_quality)
4033 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4035 if (quality == rate_quality)
4036 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4038 if (quality == tx_quality)
4039 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4041 if (quality == rx_quality)
4042 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4044 if (quality == signal_quality)
4045 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4048 priv->quality = quality;
4050 queue_delayed_work(priv->workqueue, &priv->gather_stats,
4051 IPW_STATS_INTERVAL);
4054 static void ipw_bg_gather_stats(void *data)
4056 struct ipw_priv *priv = data;
4057 mutex_lock(&priv->mutex);
4058 ipw_gather_stats(data);
4059 mutex_unlock(&priv->mutex);
4062 /* Missed beacon behavior:
4063 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4064 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4065 * Above disassociate threshold, give up and stop scanning.
4066 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
4067 static void ipw_handle_missed_beacon(struct ipw_priv *priv,
4070 priv->notif_missed_beacons = missed_count;
4072 if (missed_count > priv->disassociate_threshold &&
4073 priv->status & STATUS_ASSOCIATED) {
4074 /* If associated and we've hit the missed
4075 * beacon threshold, disassociate, turn
4076 * off roaming, and abort any active scans */
4077 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4078 IPW_DL_STATE | IPW_DL_ASSOC,
4079 "Missed beacon: %d - disassociate\n", missed_count);
4080 priv->status &= ~STATUS_ROAMING;
4081 if (priv->status & STATUS_SCANNING) {
4082 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4084 "Aborting scan with missed beacon.\n");
4085 queue_work(priv->workqueue, &priv->abort_scan);
4088 queue_work(priv->workqueue, &priv->disassociate);
4092 if (priv->status & STATUS_ROAMING) {
4093 /* If we are currently roaming, then just
4094 * print a debug statement... */
4095 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4096 "Missed beacon: %d - roam in progress\n",
4102 (missed_count > priv->roaming_threshold &&
4103 missed_count <= priv->disassociate_threshold)) {
4104 /* If we are not already roaming, set the ROAM
4105 * bit in the status and kick off a scan.
4106 * This can happen several times before we reach
4107 * disassociate_threshold. */
4108 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4109 "Missed beacon: %d - initiate "
4110 "roaming\n", missed_count);
4111 if (!(priv->status & STATUS_ROAMING)) {
4112 priv->status |= STATUS_ROAMING;
4113 if (!(priv->status & STATUS_SCANNING))
4114 queue_work(priv->workqueue,
4115 &priv->request_scan);
4120 if (priv->status & STATUS_SCANNING) {
4121 /* Stop scan to keep fw from getting
4122 * stuck (only if we aren't roaming --
4123 * otherwise we'll never scan more than 2 or 3
4125 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4126 "Aborting scan with missed beacon.\n");
4127 queue_work(priv->workqueue, &priv->abort_scan);
4130 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
4134 * Handle host notification packet.
4135 * Called from interrupt routine
4137 static void ipw_rx_notification(struct ipw_priv *priv,
4138 struct ipw_rx_notification *notif)
4140 notif->size = le16_to_cpu(notif->size);
4142 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
4144 switch (notif->subtype) {
4145 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4146 struct notif_association *assoc = ¬if->u.assoc;
4148 switch (assoc->state) {
4149 case CMAS_ASSOCIATED:{
4150 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4152 "associated: '%s' " MAC_FMT
4154 escape_essid(priv->essid,
4156 MAC_ARG(priv->bssid));
4158 switch (priv->ieee->iw_mode) {
4160 memcpy(priv->ieee->bssid,
4161 priv->bssid, ETH_ALEN);
4165 memcpy(priv->ieee->bssid,
4166 priv->bssid, ETH_ALEN);
4168 /* clear out the station table */
4169 priv->num_stations = 0;
4172 ("queueing adhoc check\n");
4173 queue_delayed_work(priv->
4183 priv->status &= ~STATUS_ASSOCIATING;
4184 priv->status |= STATUS_ASSOCIATED;
4185 queue_work(priv->workqueue,
4186 &priv->system_config);
4188 #ifdef CONFIG_IPW_QOS
4189 #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4190 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4191 if ((priv->status & STATUS_AUTH) &&
4192 (IPW_GET_PACKET_STYPE(¬if->u.raw)
4193 == IEEE80211_STYPE_ASSOC_RESP)) {
4196 ieee80211_assoc_response)
4198 && (notif->size <= 2314)) {
4211 ieee80211_rx_mgt(priv->
4216 ¬if->u.raw, &stats);
4221 schedule_work(&priv->link_up);
4226 case CMAS_AUTHENTICATED:{
4228 status & (STATUS_ASSOCIATED |
4230 #ifdef CONFIG_IPW2200_DEBUG
4231 struct notif_authenticate *auth
4233 IPW_DEBUG(IPW_DL_NOTIF |
4236 "deauthenticated: '%s' "
4238 ": (0x%04X) - %s \n",
4243 MAC_ARG(priv->bssid),
4244 ntohs(auth->status),
4251 ~(STATUS_ASSOCIATING |
4255 schedule_work(&priv->link_down);
4259 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4261 "authenticated: '%s' " MAC_FMT
4263 escape_essid(priv->essid,
4265 MAC_ARG(priv->bssid));
4270 if (priv->status & STATUS_AUTH) {
4272 ieee80211_assoc_response
4276 ieee80211_assoc_response
4278 IPW_DEBUG(IPW_DL_NOTIF |
4281 "association failed (0x%04X): %s\n",
4282 ntohs(resp->status),
4288 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4290 "disassociated: '%s' " MAC_FMT
4292 escape_essid(priv->essid,
4294 MAC_ARG(priv->bssid));
4297 ~(STATUS_DISASSOCIATING |
4298 STATUS_ASSOCIATING |
4299 STATUS_ASSOCIATED | STATUS_AUTH);
4300 if (priv->assoc_network
4301 && (priv->assoc_network->
4303 WLAN_CAPABILITY_IBSS))
4304 ipw_remove_current_network
4307 schedule_work(&priv->link_down);
4312 case CMAS_RX_ASSOC_RESP:
4316 IPW_ERROR("assoc: unknown (%d)\n",
4324 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4325 struct notif_authenticate *auth = ¬if->u.auth;
4326 switch (auth->state) {
4327 case CMAS_AUTHENTICATED:
4328 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4329 "authenticated: '%s' " MAC_FMT " \n",
4330 escape_essid(priv->essid,
4332 MAC_ARG(priv->bssid));
4333 priv->status |= STATUS_AUTH;
4337 if (priv->status & STATUS_AUTH) {
4338 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4340 "authentication failed (0x%04X): %s\n",
4341 ntohs(auth->status),
4342 ipw_get_status_code(ntohs
4346 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4348 "deauthenticated: '%s' " MAC_FMT "\n",
4349 escape_essid(priv->essid,
4351 MAC_ARG(priv->bssid));
4353 priv->status &= ~(STATUS_ASSOCIATING |
4357 schedule_work(&priv->link_down);
4360 case CMAS_TX_AUTH_SEQ_1:
4361 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4362 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4364 case CMAS_RX_AUTH_SEQ_2:
4365 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4366 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4368 case CMAS_AUTH_SEQ_1_PASS:
4369 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4370 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4372 case CMAS_AUTH_SEQ_1_FAIL:
4373 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4374 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4376 case CMAS_TX_AUTH_SEQ_3:
4377 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4378 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4380 case CMAS_RX_AUTH_SEQ_4:
4381 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4382 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4384 case CMAS_AUTH_SEQ_2_PASS:
4385 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4386 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4388 case CMAS_AUTH_SEQ_2_FAIL:
4389 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4390 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4393 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4394 IPW_DL_ASSOC, "TX_ASSOC\n");
4396 case CMAS_RX_ASSOC_RESP:
4397 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4398 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
4401 case CMAS_ASSOCIATED:
4402 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4403 IPW_DL_ASSOC, "ASSOCIATED\n");
4406 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4413 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4414 struct notif_channel_result *x =
4415 ¬if->u.channel_result;
4417 if (notif->size == sizeof(*x)) {
4418 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4421 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4422 "(should be %zd)\n",
4423 notif->size, sizeof(*x));
4428 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4429 struct notif_scan_complete *x = ¬if->u.scan_complete;
4430 if (notif->size == sizeof(*x)) {
4432 ("Scan completed: type %d, %d channels, "
4433 "%d status\n", x->scan_type,
4434 x->num_channels, x->status);
4436 IPW_ERROR("Scan completed of wrong size %d "
4437 "(should be %zd)\n",
4438 notif->size, sizeof(*x));
4442 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4444 wake_up_interruptible(&priv->wait_state);
4445 cancel_delayed_work(&priv->scan_check);
4447 if (priv->status & STATUS_EXIT_PENDING)
4450 priv->ieee->scans++;
4452 #ifdef CONFIG_IPW2200_MONITOR
4453 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
4454 priv->status |= STATUS_SCAN_FORCED;
4455 queue_work(priv->workqueue,
4456 &priv->request_scan);
4459 priv->status &= ~STATUS_SCAN_FORCED;
4460 #endif /* CONFIG_IPW2200_MONITOR */
4462 if (!(priv->status & (STATUS_ASSOCIATED |
4463 STATUS_ASSOCIATING |
4465 STATUS_DISASSOCIATING)))
4466 queue_work(priv->workqueue, &priv->associate);
4467 else if (priv->status & STATUS_ROAMING) {
4468 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4469 /* If a scan completed and we are in roam mode, then
4470 * the scan that completed was the one requested as a
4471 * result of entering roam... so, schedule the
4473 queue_work(priv->workqueue,
4476 /* Don't schedule if we aborted the scan */
4477 priv->status &= ~STATUS_ROAMING;
4478 } else if (priv->status & STATUS_SCAN_PENDING)
4479 queue_work(priv->workqueue,
4480 &priv->request_scan);
4481 else if (priv->config & CFG_BACKGROUND_SCAN
4482 && priv->status & STATUS_ASSOCIATED)
4483 queue_delayed_work(priv->workqueue,
4484 &priv->request_scan, HZ);
4488 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4489 struct notif_frag_length *x = ¬if->u.frag_len;
4491 if (notif->size == sizeof(*x))
4492 IPW_ERROR("Frag length: %d\n",
4493 le16_to_cpu(x->frag_length));
4495 IPW_ERROR("Frag length of wrong size %d "
4496 "(should be %zd)\n",
4497 notif->size, sizeof(*x));
4501 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4502 struct notif_link_deterioration *x =
4503 ¬if->u.link_deterioration;
4505 if (notif->size == sizeof(*x)) {
4506 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4507 "link deterioration: type %d, cnt %d\n",
4508 x->silence_notification_type,
4510 memcpy(&priv->last_link_deterioration, x,
4513 IPW_ERROR("Link Deterioration of wrong size %d "
4514 "(should be %zd)\n",
4515 notif->size, sizeof(*x));
4520 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4521 IPW_ERROR("Dino config\n");
4523 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
4524 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
4529 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4530 struct notif_beacon_state *x = ¬if->u.beacon_state;
4531 if (notif->size != sizeof(*x)) {
4533 ("Beacon state of wrong size %d (should "
4534 "be %zd)\n", notif->size, sizeof(*x));
4538 if (le32_to_cpu(x->state) ==
4539 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4540 ipw_handle_missed_beacon(priv,
4547 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4548 struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key;
4549 if (notif->size == sizeof(*x)) {
4550 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4551 "0x%02x station %d\n",
4552 x->key_state, x->security_type,
4558 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4559 notif->size, sizeof(*x));
4563 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4564 struct notif_calibration *x = ¬if->u.calibration;
4566 if (notif->size == sizeof(*x)) {
4567 memcpy(&priv->calib, x, sizeof(*x));
4568 IPW_DEBUG_INFO("TODO: Calibration\n");
4573 ("Calibration of wrong size %d (should be %zd)\n",
4574 notif->size, sizeof(*x));
4578 case HOST_NOTIFICATION_NOISE_STATS:{
4579 if (notif->size == sizeof(u32)) {
4581 (u8) (le32_to_cpu(notif->u.noise.value) &
4583 average_add(&priv->average_noise,
4589 ("Noise stat is wrong size %d (should be %zd)\n",
4590 notif->size, sizeof(u32));
4595 IPW_DEBUG_NOTIF("Unknown notification: "
4596 "subtype=%d,flags=0x%2x,size=%d\n",
4597 notif->subtype, notif->flags, notif->size);
4602 * Destroys all DMA structures and initialise them again
4605 * @return error code
4607 static int ipw_queue_reset(struct ipw_priv *priv)
4610 /** @todo customize queue sizes */
4611 int nTx = 64, nTxCmd = 8;
4612 ipw_tx_queue_free(priv);
4614 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
4615 IPW_TX_CMD_QUEUE_READ_INDEX,
4616 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4617 IPW_TX_CMD_QUEUE_BD_BASE,
4618 IPW_TX_CMD_QUEUE_BD_SIZE);
4620 IPW_ERROR("Tx Cmd queue init failed\n");
4624 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
4625 IPW_TX_QUEUE_0_READ_INDEX,
4626 IPW_TX_QUEUE_0_WRITE_INDEX,
4627 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
4629 IPW_ERROR("Tx 0 queue init failed\n");
4632 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
4633 IPW_TX_QUEUE_1_READ_INDEX,
4634 IPW_TX_QUEUE_1_WRITE_INDEX,
4635 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
4637 IPW_ERROR("Tx 1 queue init failed\n");
4640 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
4641 IPW_TX_QUEUE_2_READ_INDEX,
4642 IPW_TX_QUEUE_2_WRITE_INDEX,
4643 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
4645 IPW_ERROR("Tx 2 queue init failed\n");
4648 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
4649 IPW_TX_QUEUE_3_READ_INDEX,
4650 IPW_TX_QUEUE_3_WRITE_INDEX,
4651 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
4653 IPW_ERROR("Tx 3 queue init failed\n");
4657 priv->rx_bufs_min = 0;
4658 priv->rx_pend_max = 0;
4662 ipw_tx_queue_free(priv);
4667 * Reclaim Tx queue entries no more used by NIC.
4669 * When FW adwances 'R' index, all entries between old and
4670 * new 'R' index need to be reclaimed. As result, some free space
4671 * forms. If there is enough free space (> low mark), wake Tx queue.
4673 * @note Need to protect against garbage in 'R' index
4677 * @return Number of used entries remains in the queue
4679 static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
4680 struct clx2_tx_queue *txq, int qindex)
4684 struct clx2_queue *q = &txq->q;
4686 hw_tail = ipw_read32(priv, q->reg_r);
4687 if (hw_tail >= q->n_bd) {
4689 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4693 for (; q->last_used != hw_tail;
4694 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4695 ipw_queue_tx_free_tfd(priv, txq);
4699 if ((ipw_queue_space(q) > q->low_mark) &&
4701 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4702 netif_wake_queue(priv->net_dev);
4703 used = q->first_empty - q->last_used;
4710 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4713 struct clx2_tx_queue *txq = &priv->txq_cmd;
4714 struct clx2_queue *q = &txq->q;
4715 struct tfd_frame *tfd;
4717 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4718 IPW_ERROR("No space for Tx\n");
4722 tfd = &txq->bd[q->first_empty];
4723 txq->txb[q->first_empty] = NULL;
4725 memset(tfd, 0, sizeof(*tfd));
4726 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4727 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4729 tfd->u.cmd.index = hcmd;
4730 tfd->u.cmd.length = len;
4731 memcpy(tfd->u.cmd.payload, buf, len);
4732 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4733 ipw_write32(priv, q->reg_w, q->first_empty);
4734 _ipw_read32(priv, 0x90);
4740 * Rx theory of operation
4742 * The host allocates 32 DMA target addresses and passes the host address
4743 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
4747 * The host/firmware share two index registers for managing the Rx buffers.
4749 * The READ index maps to the first position that the firmware may be writing
4750 * to -- the driver can read up to (but not including) this position and get
4752 * The READ index is managed by the firmware once the card is enabled.
4754 * The WRITE index maps to the last position the driver has read from -- the
4755 * position preceding WRITE is the last slot the firmware can place a packet.
4757 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
4760 * During initialization the host sets up the READ queue position to the first
4761 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4763 * When the firmware places a packet in a buffer it will advance the READ index
4764 * and fire the RX interrupt. The driver can then query the READ index and
4765 * process as many packets as possible, moving the WRITE index forward as it
4766 * resets the Rx queue buffers with new memory.
4768 * The management in the driver is as follows:
4769 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
4770 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
4771 * to replensish the ipw->rxq->rx_free.
4772 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4773 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4774 * 'processed' and 'read' driver indexes as well)
4775 * + A received packet is processed and handed to the kernel network stack,
4776 * detached from the ipw->rxq. The driver 'processed' index is updated.
4777 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
4778 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4779 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
4780 * were enough free buffers and RX_STALLED is set it is cleared.
4785 * ipw_rx_queue_alloc() Allocates rx_free
4786 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4787 * ipw_rx_queue_restock
4788 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4789 * queue, updates firmware pointers, and updates
4790 * the WRITE index. If insufficient rx_free buffers
4791 * are available, schedules ipw_rx_queue_replenish
4793 * -- enable interrupts --
4794 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
4795 * READ INDEX, detaching the SKB from the pool.
4796 * Moves the packet buffer from queue to rx_used.
4797 * Calls ipw_rx_queue_restock to refill any empty
4804 * If there are slots in the RX queue that need to be restocked,
4805 * and we have free pre-allocated buffers, fill the ranks as much
4806 * as we can pulling from rx_free.
4808 * This moves the 'write' index forward to catch up with 'processed', and
4809 * also updates the memory address in the firmware to reference the new
4812 static void ipw_rx_queue_restock(struct ipw_priv *priv)
4814 struct ipw_rx_queue *rxq = priv->rxq;
4815 struct list_head *element;
4816 struct ipw_rx_mem_buffer *rxb;
4817 unsigned long flags;
4820 spin_lock_irqsave(&rxq->lock, flags);
4822 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4823 element = rxq->rx_free.next;
4824 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4827 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
4829 rxq->queue[rxq->write] = rxb;
4830 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4833 spin_unlock_irqrestore(&rxq->lock, flags);
4835 /* If the pre-allocated buffer pool is dropping low, schedule to
4837 if (rxq->free_count <= RX_LOW_WATERMARK)
4838 queue_work(priv->workqueue, &priv->rx_replenish);
4840 /* If we've added more space for the firmware to place data, tell it */
4841 if (write != rxq->write)
4842 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
4846 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
4847 * Also restock the Rx queue via ipw_rx_queue_restock.
4849 * This is called as a scheduled work item (except for during intialization)
4851 static void ipw_rx_queue_replenish(void *data)
4853 struct ipw_priv *priv = data;
4854 struct ipw_rx_queue *rxq = priv->rxq;
4855 struct list_head *element;
4856 struct ipw_rx_mem_buffer *rxb;
4857 unsigned long flags;
4859 spin_lock_irqsave(&rxq->lock, flags);
4860 while (!list_empty(&rxq->rx_used)) {
4861 element = rxq->rx_used.next;
4862 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4863 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
4865 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
4866 priv->net_dev->name);
4867 /* We don't reschedule replenish work here -- we will
4868 * call the restock method and if it still needs
4869 * more buffers it will schedule replenish */
4874 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
4876 pci_map_single(priv->pci_dev, rxb->skb->data,
4877 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4879 list_add_tail(&rxb->list, &rxq->rx_free);
4882 spin_unlock_irqrestore(&rxq->lock, flags);
4884 ipw_rx_queue_restock(priv);
4887 static void ipw_bg_rx_queue_replenish(void *data)
4889 struct ipw_priv *priv = data;
4890 mutex_lock(&priv->mutex);
4891 ipw_rx_queue_replenish(data);
4892 mutex_unlock(&priv->mutex);
4895 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4896 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
4897 * This free routine walks the list of POOL entries and if SKB is set to
4898 * non NULL it is unmapped and freed
4900 static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
4907 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4908 if (rxq->pool[i].skb != NULL) {
4909 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
4910 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4911 dev_kfree_skb(rxq->pool[i].skb);
4918 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4920 struct ipw_rx_queue *rxq;
4923 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
4924 if (unlikely(!rxq)) {
4925 IPW_ERROR("memory allocation failed\n");
4928 spin_lock_init(&rxq->lock);
4929 INIT_LIST_HEAD(&rxq->rx_free);
4930 INIT_LIST_HEAD(&rxq->rx_used);
4932 /* Fill the rx_used queue with _all_ of the Rx buffers */
4933 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
4934 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4936 /* Set us so that we have processed and used all buffers, but have
4937 * not restocked the Rx queue with fresh buffers */
4938 rxq->read = rxq->write = 0;
4939 rxq->processed = RX_QUEUE_SIZE - 1;
4940 rxq->free_count = 0;
4945 static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
4947 rate &= ~IEEE80211_BASIC_RATE_MASK;
4948 if (ieee_mode == IEEE_A) {
4950 case IEEE80211_OFDM_RATE_6MB:
4951 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
4953 case IEEE80211_OFDM_RATE_9MB:
4954 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
4956 case IEEE80211_OFDM_RATE_12MB:
4958 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
4959 case IEEE80211_OFDM_RATE_18MB:
4961 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
4962 case IEEE80211_OFDM_RATE_24MB:
4964 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
4965 case IEEE80211_OFDM_RATE_36MB:
4967 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
4968 case IEEE80211_OFDM_RATE_48MB:
4970 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
4971 case IEEE80211_OFDM_RATE_54MB:
4973 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
4981 case IEEE80211_CCK_RATE_1MB:
4982 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
4983 case IEEE80211_CCK_RATE_2MB:
4984 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
4985 case IEEE80211_CCK_RATE_5MB:
4986 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
4987 case IEEE80211_CCK_RATE_11MB:
4988 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
4991 /* If we are limited to B modulations, bail at this point */
4992 if (ieee_mode == IEEE_B)
4997 case IEEE80211_OFDM_RATE_6MB:
4998 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
4999 case IEEE80211_OFDM_RATE_9MB:
5000 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
5001 case IEEE80211_OFDM_RATE_12MB:
5002 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
5003 case IEEE80211_OFDM_RATE_18MB:
5004 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
5005 case IEEE80211_OFDM_RATE_24MB:
5006 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
5007 case IEEE80211_OFDM_RATE_36MB:
5008 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
5009 case IEEE80211_OFDM_RATE_48MB:
5010 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
5011 case IEEE80211_OFDM_RATE_54MB:
5012 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5018 static int ipw_compatible_rates(struct ipw_priv *priv,
5019 const struct ieee80211_network *network,
5020 struct ipw_supported_rates *rates)
5024 memset(rates, 0, sizeof(*rates));
5025 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
5026 rates->num_rates = 0;
5027 for (i = 0; i < num_rates; i++) {
5028 if (!ipw_is_rate_in_mask(priv, network->mode,
5029 network->rates[i])) {
5031 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
5032 IPW_DEBUG_SCAN("Adding masked mandatory "
5035 rates->supported_rates[rates->num_rates++] =
5040 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5041 network->rates[i], priv->rates_mask);
5045 rates->supported_rates[rates->num_rates++] = network->rates[i];
5048 num_rates = min(network->rates_ex_len,
5049 (u8) (IPW_MAX_RATES - num_rates));
5050 for (i = 0; i < num_rates; i++) {
5051 if (!ipw_is_rate_in_mask(priv, network->mode,
5052 network->rates_ex[i])) {
5053 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
5054 IPW_DEBUG_SCAN("Adding masked mandatory "
5056 network->rates_ex[i]);
5057 rates->supported_rates[rates->num_rates++] =
5062 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5063 network->rates_ex[i], priv->rates_mask);
5067 rates->supported_rates[rates->num_rates++] =
5068 network->rates_ex[i];
5074 static void ipw_copy_rates(struct ipw_supported_rates *dest,
5075 const struct ipw_supported_rates *src)
5078 for (i = 0; i < src->num_rates; i++)
5079 dest->supported_rates[i] = src->supported_rates[i];
5080 dest->num_rates = src->num_rates;
5083 /* TODO: Look at sniffed packets in the air to determine if the basic rate
5084 * mask should ever be used -- right now all callers to add the scan rates are
5085 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5086 static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
5087 u8 modulation, u32 rate_mask)
5089 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
5090 IEEE80211_BASIC_RATE_MASK : 0;
5092 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
5093 rates->supported_rates[rates->num_rates++] =
5094 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
5096 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
5097 rates->supported_rates[rates->num_rates++] =
5098 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
5100 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
5101 rates->supported_rates[rates->num_rates++] = basic_mask |
5102 IEEE80211_CCK_RATE_5MB;
5104 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
5105 rates->supported_rates[rates->num_rates++] = basic_mask |
5106 IEEE80211_CCK_RATE_11MB;
5109 static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
5110 u8 modulation, u32 rate_mask)
5112 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
5113 IEEE80211_BASIC_RATE_MASK : 0;
5115 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
5116 rates->supported_rates[rates->num_rates++] = basic_mask |
5117 IEEE80211_OFDM_RATE_6MB;
5119 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
5120 rates->supported_rates[rates->num_rates++] =
5121 IEEE80211_OFDM_RATE_9MB;
5123 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
5124 rates->supported_rates[rates->num_rates++] = basic_mask |
5125 IEEE80211_OFDM_RATE_12MB;
5127 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
5128 rates->supported_rates[rates->num_rates++] =
5129 IEEE80211_OFDM_RATE_18MB;
5131 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
5132 rates->supported_rates[rates->num_rates++] = basic_mask |
5133 IEEE80211_OFDM_RATE_24MB;
5135 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
5136 rates->supported_rates[rates->num_rates++] =
5137 IEEE80211_OFDM_RATE_36MB;
5139 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
5140 rates->supported_rates[rates->num_rates++] =
5141 IEEE80211_OFDM_RATE_48MB;
5143 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
5144 rates->supported_rates[rates->num_rates++] =
5145 IEEE80211_OFDM_RATE_54MB;
5148 struct ipw_network_match {
5149 struct ieee80211_network *network;
5150 struct ipw_supported_rates rates;
5153 static int ipw_find_adhoc_network(struct ipw_priv *priv,
5154 struct ipw_network_match *match,
5155 struct ieee80211_network *network,
5158 struct ipw_supported_rates rates;
5160 /* Verify that this network's capability is compatible with the
5161 * current mode (AdHoc or Infrastructure) */
5162 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5163 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5164 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5165 "capability mismatch.\n",
5166 escape_essid(network->ssid, network->ssid_len),
5167 MAC_ARG(network->bssid));
5171 /* If we do not have an ESSID for this AP, we can not associate with
5173 if (network->flags & NETWORK_EMPTY_ESSID) {
5174 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5175 "because of hidden ESSID.\n",
5176 escape_essid(network->ssid, network->ssid_len),
5177 MAC_ARG(network->bssid));
5181 if (unlikely(roaming)) {
5182 /* If we are roaming, then ensure check if this is a valid
5183 * network to try and roam to */
5184 if ((network->ssid_len != match->network->ssid_len) ||
5185 memcmp(network->ssid, match->network->ssid,
5186 network->ssid_len)) {
5187 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5188 "because of non-network ESSID.\n",
5189 escape_essid(network->ssid,
5191 MAC_ARG(network->bssid));
5195 /* If an ESSID has been configured then compare the broadcast
5197 if ((priv->config & CFG_STATIC_ESSID) &&
5198 ((network->ssid_len != priv->essid_len) ||
5199 memcmp(network->ssid, priv->essid,
5200 min(network->ssid_len, priv->essid_len)))) {
5201 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5204 escape_essid(network->ssid, network->ssid_len),
5206 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5207 "because of ESSID mismatch: '%s'.\n",
5208 escaped, MAC_ARG(network->bssid),
5209 escape_essid(priv->essid,
5215 /* If the old network rate is better than this one, don't bother
5216 * testing everything else. */
5218 if (network->time_stamp[0] < match->network->time_stamp[0]) {
5219 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5220 "current network.\n",
5221 escape_essid(match->network->ssid,
5222 match->network->ssid_len));
5224 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
5225 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5226 "current network.\n",
5227 escape_essid(match->network->ssid,
5228 match->network->ssid_len));
5232 /* Now go through and see if the requested network is valid... */
5233 if (priv->ieee->scan_age != 0 &&
5234 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5235 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5236 "because of age: %ums.\n",
5237 escape_essid(network->ssid, network->ssid_len),
5238 MAC_ARG(network->bssid),
5239 jiffies_to_msecs(jiffies -
5240 network->last_scanned));
5244 if ((priv->config & CFG_STATIC_CHANNEL) &&
5245 (network->channel != priv->channel)) {
5246 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5247 "because of channel mismatch: %d != %d.\n",
5248 escape_essid(network->ssid, network->ssid_len),
5249 MAC_ARG(network->bssid),
5250 network->channel, priv->channel);
5254 /* Verify privacy compatability */
5255 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5256 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5257 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5258 "because of privacy mismatch: %s != %s.\n",
5259 escape_essid(network->ssid, network->ssid_len),
5260 MAC_ARG(network->bssid),
5262 capability & CAP_PRIVACY_ON ? "on" : "off",
5264 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5269 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5270 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5271 "because of the same BSSID match: " MAC_FMT
5272 ".\n", escape_essid(network->ssid,
5274 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5278 /* Filter out any incompatible freq / mode combinations */
5279 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5280 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5281 "because of invalid frequency/mode "
5283 escape_essid(network->ssid, network->ssid_len),
5284 MAC_ARG(network->bssid));
5288 /* Ensure that the rates supported by the driver are compatible with
5289 * this AP, including verification of basic rates (mandatory) */
5290 if (!ipw_compatible_rates(priv, network, &rates)) {
5291 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5292 "because configured rate mask excludes "
5293 "AP mandatory rate.\n",
5294 escape_essid(network->ssid, network->ssid_len),
5295 MAC_ARG(network->bssid));
5299 if (rates.num_rates == 0) {
5300 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5301 "because of no compatible rates.\n",
5302 escape_essid(network->ssid, network->ssid_len),
5303 MAC_ARG(network->bssid));
5307 /* TODO: Perform any further minimal comparititive tests. We do not
5308 * want to put too much policy logic here; intelligent scan selection
5309 * should occur within a generic IEEE 802.11 user space tool. */
5311 /* Set up 'new' AP to this network */
5312 ipw_copy_rates(&match->rates, &rates);
5313 match->network = network;
5314 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5315 escape_essid(network->ssid, network->ssid_len),
5316 MAC_ARG(network->bssid));
5321 static void ipw_merge_adhoc_network(void *data)
5323 struct ipw_priv *priv = data;
5324 struct ieee80211_network *network = NULL;
5325 struct ipw_network_match match = {
5326 .network = priv->assoc_network
5329 if ((priv->status & STATUS_ASSOCIATED) &&
5330 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5331 /* First pass through ROAM process -- look for a better
5333 unsigned long flags;
5335 spin_lock_irqsave(&priv->ieee->lock, flags);
5336 list_for_each_entry(network, &priv->ieee->network_list, list) {
5337 if (network != priv->assoc_network)
5338 ipw_find_adhoc_network(priv, &match, network,
5341 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5343 if (match.network == priv->assoc_network) {
5344 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5349 mutex_lock(&priv->mutex);
5350 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5351 IPW_DEBUG_MERGE("remove network %s\n",
5352 escape_essid(priv->essid,
5354 ipw_remove_current_network(priv);
5357 ipw_disassociate(priv);
5358 priv->assoc_network = match.network;
5359 mutex_unlock(&priv->mutex);
5364 static int ipw_best_network(struct ipw_priv *priv,
5365 struct ipw_network_match *match,
5366 struct ieee80211_network *network, int roaming)
5368 struct ipw_supported_rates rates;
5370 /* Verify that this network's capability is compatible with the
5371 * current mode (AdHoc or Infrastructure) */
5372 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
5373 !(network->capability & WLAN_CAPABILITY_ESS)) ||
5374 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5375 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5376 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
5377 "capability mismatch.\n",
5378 escape_essid(network->ssid, network->ssid_len),
5379 MAC_ARG(network->bssid));
5383 /* If we do not have an ESSID for this AP, we can not associate with
5385 if (network->flags & NETWORK_EMPTY_ESSID) {
5386 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5387 "because of hidden ESSID.\n",
5388 escape_essid(network->ssid, network->ssid_len),
5389 MAC_ARG(network->bssid));
5393 if (unlikely(roaming)) {
5394 /* If we are roaming, then ensure check if this is a valid
5395 * network to try and roam to */
5396 if ((network->ssid_len != match->network->ssid_len) ||
5397 memcmp(network->ssid, match->network->ssid,
5398 network->ssid_len)) {
5399 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5400 "because of non-network ESSID.\n",
5401 escape_essid(network->ssid,
5403 MAC_ARG(network->bssid));
5407 /* If an ESSID has been configured then compare the broadcast
5409 if ((priv->config & CFG_STATIC_ESSID) &&
5410 ((network->ssid_len != priv->essid_len) ||
5411 memcmp(network->ssid, priv->essid,
5412 min(network->ssid_len, priv->essid_len)))) {
5413 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5415 escape_essid(network->ssid, network->ssid_len),
5417 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5418 "because of ESSID mismatch: '%s'.\n",
5419 escaped, MAC_ARG(network->bssid),
5420 escape_essid(priv->essid,
5426 /* If the old network rate is better than this one, don't bother
5427 * testing everything else. */
5428 if (match->network && match->network->stats.rssi > network->stats.rssi) {
5429 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5431 escape_essid(network->ssid, network->ssid_len),
5433 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5434 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5435 escaped, MAC_ARG(network->bssid),
5436 escape_essid(match->network->ssid,
5437 match->network->ssid_len),
5438 MAC_ARG(match->network->bssid));
5442 /* If this network has already had an association attempt within the
5443 * last 3 seconds, do not try and associate again... */
5444 if (network->last_associate &&
5445 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
5446 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5447 "because of storming (%ums since last "
5448 "assoc attempt).\n",
5449 escape_essid(network->ssid, network->ssid_len),
5450 MAC_ARG(network->bssid),
5451 jiffies_to_msecs(jiffies -
5452 network->last_associate));
5456 /* Now go through and see if the requested network is valid... */
5457 if (priv->ieee->scan_age != 0 &&
5458 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5459 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5460 "because of age: %ums.\n",
5461 escape_essid(network->ssid, network->ssid_len),
5462 MAC_ARG(network->bssid),
5463 jiffies_to_msecs(jiffies -
5464 network->last_scanned));
5468 if ((priv->config & CFG_STATIC_CHANNEL) &&
5469 (network->channel != priv->channel)) {
5470 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5471 "because of channel mismatch: %d != %d.\n",
5472 escape_essid(network->ssid, network->ssid_len),
5473 MAC_ARG(network->bssid),
5474 network->channel, priv->channel);
5478 /* Verify privacy compatability */
5479 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5480 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5481 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5482 "because of privacy mismatch: %s != %s.\n",
5483 escape_essid(network->ssid, network->ssid_len),
5484 MAC_ARG(network->bssid),
5485 priv->capability & CAP_PRIVACY_ON ? "on" :
5487 network->capability &
5488 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
5492 if ((priv->config & CFG_STATIC_BSSID) &&
5493 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5494 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5495 "because of BSSID mismatch: " MAC_FMT ".\n",
5496 escape_essid(network->ssid, network->ssid_len),
5497 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5501 /* Filter out any incompatible freq / mode combinations */
5502 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5503 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5504 "because of invalid frequency/mode "
5506 escape_essid(network->ssid, network->ssid_len),
5507 MAC_ARG(network->bssid));
5511 /* Filter out invalid channel in current GEO */
5512 if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) {
5513 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5514 "because of invalid channel in current GEO\n",
5515 escape_essid(network->ssid, network->ssid_len),
5516 MAC_ARG(network->bssid));
5520 /* Ensure that the rates supported by the driver are compatible with
5521 * this AP, including verification of basic rates (mandatory) */
5522 if (!ipw_compatible_rates(priv, network, &rates)) {
5523 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5524 "because configured rate mask excludes "
5525 "AP mandatory rate.\n",
5526 escape_essid(network->ssid, network->ssid_len),
5527 MAC_ARG(network->bssid));
5531 if (rates.num_rates == 0) {
5532 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5533 "because of no compatible rates.\n",
5534 escape_essid(network->ssid, network->ssid_len),
5535 MAC_ARG(network->bssid));
5539 /* TODO: Perform any further minimal comparititive tests. We do not
5540 * want to put too much policy logic here; intelligent scan selection
5541 * should occur within a generic IEEE 802.11 user space tool. */
5543 /* Set up 'new' AP to this network */
5544 ipw_copy_rates(&match->rates, &rates);
5545 match->network = network;
5547 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5548 escape_essid(network->ssid, network->ssid_len),
5549 MAC_ARG(network->bssid));
5554 static void ipw_adhoc_create(struct ipw_priv *priv,
5555 struct ieee80211_network *network)
5557 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
5561 * For the purposes of scanning, we can set our wireless mode
5562 * to trigger scans across combinations of bands, but when it
5563 * comes to creating a new ad-hoc network, we have tell the FW
5564 * exactly which band to use.
5566 * We also have the possibility of an invalid channel for the
5567 * chossen band. Attempting to create a new ad-hoc network
5568 * with an invalid channel for wireless mode will trigger a
5572 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
5573 case IEEE80211_52GHZ_BAND:
5574 network->mode = IEEE_A;
5575 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
5577 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5578 IPW_WARNING("Overriding invalid channel\n");
5579 priv->channel = geo->a[0].channel;
5583 case IEEE80211_24GHZ_BAND:
5584 if (priv->ieee->mode & IEEE_G)
5585 network->mode = IEEE_G;
5587 network->mode = IEEE_B;
5588 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
5590 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5591 IPW_WARNING("Overriding invalid channel\n");
5592 priv->channel = geo->bg[0].channel;
5597 IPW_WARNING("Overriding invalid channel\n");
5598 if (priv->ieee->mode & IEEE_A) {
5599 network->mode = IEEE_A;
5600 priv->channel = geo->a[0].channel;
5601 } else if (priv->ieee->mode & IEEE_G) {
5602 network->mode = IEEE_G;
5603 priv->channel = geo->bg[0].channel;
5605 network->mode = IEEE_B;
5606 priv->channel = geo->bg[0].channel;
5611 network->channel = priv->channel;
5612 priv->config |= CFG_ADHOC_PERSIST;
5613 ipw_create_bssid(priv, network->bssid);
5614 network->ssid_len = priv->essid_len;
5615 memcpy(network->ssid, priv->essid, priv->essid_len);
5616 memset(&network->stats, 0, sizeof(network->stats));
5617 network->capability = WLAN_CAPABILITY_IBSS;
5618 if (!(priv->config & CFG_PREAMBLE_LONG))
5619 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
5620 if (priv->capability & CAP_PRIVACY_ON)
5621 network->capability |= WLAN_CAPABILITY_PRIVACY;
5622 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
5623 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
5624 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
5625 memcpy(network->rates_ex,
5626 &priv->rates.supported_rates[network->rates_len],
5627 network->rates_ex_len);
5628 network->last_scanned = 0;
5630 network->last_associate = 0;
5631 network->time_stamp[0] = 0;
5632 network->time_stamp[1] = 0;
5633 network->beacon_interval = 100; /* Default */
5634 network->listen_interval = 10; /* Default */
5635 network->atim_window = 0; /* Default */
5636 network->wpa_ie_len = 0;
5637 network->rsn_ie_len = 0;
5640 static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5642 struct ipw_tgi_tx_key key;
5644 if (!(priv->ieee->sec.flags & (1 << index)))
5648 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5649 key.security_type = type;
5650 key.station_index = 0; /* always 0 for BSS */
5652 /* 0 for new key; previous value of counter (after fatal error) */
5653 key.tx_counter[0] = 0;
5654 key.tx_counter[1] = 0;
5656 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
5659 static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
5661 struct ipw_wep_key key;
5664 key.cmd_id = DINO_CMD_WEP_KEY;
5667 /* Note: AES keys cannot be set for multiple times.
5668 * Only set it at the first time. */
5669 for (i = 0; i < 4; i++) {
5670 key.key_index = i | type;
5671 if (!(priv->ieee->sec.flags & (1 << i))) {
5676 key.key_size = priv->ieee->sec.key_sizes[i];
5677 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
5679 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
5683 static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5685 if (priv->ieee->host_encrypt)
5690 priv->sys_config.disable_unicast_decryption = 0;
5691 priv->ieee->host_decrypt = 0;
5694 priv->sys_config.disable_unicast_decryption = 1;
5695 priv->ieee->host_decrypt = 1;
5698 priv->sys_config.disable_unicast_decryption = 0;
5699 priv->ieee->host_decrypt = 0;
5702 priv->sys_config.disable_unicast_decryption = 1;
5709 static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5711 if (priv->ieee->host_encrypt)
5716 priv->sys_config.disable_multicast_decryption = 0;
5719 priv->sys_config.disable_multicast_decryption = 1;
5722 priv->sys_config.disable_multicast_decryption = 0;
5725 priv->sys_config.disable_multicast_decryption = 1;
5732 static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5734 switch (priv->ieee->sec.level) {
5736 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5737 ipw_send_tgi_tx_key(priv,
5738 DCT_FLAG_EXT_SECURITY_CCM,
5739 priv->ieee->sec.active_key);
5741 if (!priv->ieee->host_mc_decrypt)
5742 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
5745 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5746 ipw_send_tgi_tx_key(priv,
5747 DCT_FLAG_EXT_SECURITY_TKIP,
5748 priv->ieee->sec.active_key);
5751 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
5752 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5753 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
5761 static void ipw_adhoc_check(void *data)
5763 struct ipw_priv *priv = data;
5765 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
5766 !(priv->config & CFG_ADHOC_PERSIST)) {
5767 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5768 IPW_DL_STATE | IPW_DL_ASSOC,
5769 "Missed beacon: %d - disassociate\n",
5770 priv->missed_adhoc_beacons);
5771 ipw_remove_current_network(priv);
5772 ipw_disassociate(priv);
5776 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
5777 priv->assoc_request.beacon_interval);
5780 static void ipw_bg_adhoc_check(void *data)
5782 struct ipw_priv *priv = data;
5783 mutex_lock(&priv->mutex);
5784 ipw_adhoc_check(data);
5785 mutex_unlock(&priv->mutex);
5788 #ifdef CONFIG_IPW2200_DEBUG
5789 static void ipw_debug_config(struct ipw_priv *priv)
5791 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5792 "[CFG 0x%08X]\n", priv->config);
5793 if (priv->config & CFG_STATIC_CHANNEL)
5794 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
5796 IPW_DEBUG_INFO("Channel unlocked.\n");
5797 if (priv->config & CFG_STATIC_ESSID)
5798 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
5799 escape_essid(priv->essid, priv->essid_len));
5801 IPW_DEBUG_INFO("ESSID unlocked.\n");
5802 if (priv->config & CFG_STATIC_BSSID)
5803 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5804 MAC_ARG(priv->bssid));
5806 IPW_DEBUG_INFO("BSSID unlocked.\n");
5807 if (priv->capability & CAP_PRIVACY_ON)
5808 IPW_DEBUG_INFO("PRIVACY on\n");
5810 IPW_DEBUG_INFO("PRIVACY off\n");
5811 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5814 #define ipw_debug_config(x) do {} while (0)
5817 static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
5819 /* TODO: Verify that this works... */
5820 struct ipw_fixed_rate fr = {
5821 .tx_rates = priv->rates_mask
5826 /* Identify 'current FW band' and match it with the fixed
5829 switch (priv->ieee->freq_band) {
5830 case IEEE80211_52GHZ_BAND: /* A only */
5832 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5833 /* Invalid fixed rate mask */
5835 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5840 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5843 default: /* 2.4Ghz or Mixed */
5845 if (mode == IEEE_B) {
5846 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
5847 /* Invalid fixed rate mask */
5849 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5856 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5857 IEEE80211_OFDM_RATES_MASK)) {
5858 /* Invalid fixed rate mask */
5860 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5865 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
5866 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
5867 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
5870 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
5871 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
5872 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
5875 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
5876 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
5877 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
5880 fr.tx_rates |= mask;
5884 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
5885 ipw_write_reg32(priv, reg, *(u32 *) & fr);
5888 static void ipw_abort_scan(struct ipw_priv *priv)
5892 if (priv->status & STATUS_SCAN_ABORTING) {
5893 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5896 priv->status |= STATUS_SCAN_ABORTING;
5898 err = ipw_send_scan_abort(priv);
5900 IPW_DEBUG_HC("Request to abort scan failed.\n");
5903 static void ipw_add_scan_channels(struct ipw_priv *priv,
5904 struct ipw_scan_request_ext *scan,
5907 int channel_index = 0;
5908 const struct ieee80211_geo *geo;
5911 geo = ieee80211_get_geo(priv->ieee);
5913 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
5914 int start = channel_index;
5915 for (i = 0; i < geo->a_channels; i++) {
5916 if ((priv->status & STATUS_ASSOCIATED) &&
5917 geo->a[i].channel == priv->channel)
5920 scan->channels_list[channel_index] = geo->a[i].channel;
5921 ipw_set_scan_type(scan, channel_index,
5923 flags & IEEE80211_CH_PASSIVE_ONLY ?
5924 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
5928 if (start != channel_index) {
5929 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
5930 (channel_index - start);
5935 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
5936 int start = channel_index;
5937 if (priv->config & CFG_SPEED_SCAN) {
5939 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
5940 /* nop out the list */
5945 while (channel_index < IPW_SCAN_CHANNELS) {
5947 priv->speed_scan[priv->speed_scan_pos];
5949 priv->speed_scan_pos = 0;
5950 channel = priv->speed_scan[0];
5952 if ((priv->status & STATUS_ASSOCIATED) &&
5953 channel == priv->channel) {
5954 priv->speed_scan_pos++;
5958 /* If this channel has already been
5959 * added in scan, break from loop
5960 * and this will be the first channel
5963 if (channels[channel - 1] != 0)
5966 channels[channel - 1] = 1;
5967 priv->speed_scan_pos++;
5969 scan->channels_list[channel_index] = channel;
5971 ieee80211_channel_to_index(priv->ieee, channel);
5972 ipw_set_scan_type(scan, channel_index,
5975 IEEE80211_CH_PASSIVE_ONLY ?
5976 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
5980 for (i = 0; i < geo->bg_channels; i++) {
5981 if ((priv->status & STATUS_ASSOCIATED) &&
5982 geo->bg[i].channel == priv->channel)
5985 scan->channels_list[channel_index] =
5987 ipw_set_scan_type(scan, channel_index,
5990 IEEE80211_CH_PASSIVE_ONLY ?
5991 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
5996 if (start != channel_index) {
5997 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
5998 (channel_index - start);
6003 static int ipw_request_scan(struct ipw_priv *priv)
6005 struct ipw_scan_request_ext scan;
6006 int err = 0, scan_type;
6008 if (!(priv->status & STATUS_INIT) ||
6009 (priv->status & STATUS_EXIT_PENDING))
6012 mutex_lock(&priv->mutex);
6014 if (priv->status & STATUS_SCANNING) {
6015 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
6016 priv->status |= STATUS_SCAN_PENDING;
6020 if (!(priv->status & STATUS_SCAN_FORCED) &&
6021 priv->status & STATUS_SCAN_ABORTING) {
6022 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6023 priv->status |= STATUS_SCAN_PENDING;
6027 if (priv->status & STATUS_RF_KILL_MASK) {
6028 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6029 priv->status |= STATUS_SCAN_PENDING;
6033 memset(&scan, 0, sizeof(scan));
6035 if (priv->config & CFG_SPEED_SCAN)
6036 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6039 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6042 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6044 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
6046 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
6048 #ifdef CONFIG_IPW2200_MONITOR
6049 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
6053 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
6054 case IEEE80211_52GHZ_BAND:
6055 band = (u8) (IPW_A_MODE << 6) | 1;
6056 channel = priv->channel;
6059 case IEEE80211_24GHZ_BAND:
6060 band = (u8) (IPW_B_MODE << 6) | 1;
6061 channel = priv->channel;
6065 band = (u8) (IPW_B_MODE << 6) | 1;
6070 scan.channels_list[0] = band;
6071 scan.channels_list[1] = channel;
6072 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
6074 /* NOTE: The card will sit on this channel for this time
6075 * period. Scan aborts are timing sensitive and frequently
6076 * result in firmware restarts. As such, it is best to
6077 * set a small dwell_time here and just keep re-issuing
6078 * scans. Otherwise fast channel hopping will not actually
6081 * TODO: Move SPEED SCAN support to all modes and bands */
6082 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6085 #endif /* CONFIG_IPW2200_MONITOR */
6086 /* If we are roaming, then make this a directed scan for the
6087 * current network. Otherwise, ensure that every other scan
6088 * is a fast channel hop scan */
6089 if ((priv->status & STATUS_ROAMING)
6090 || (!(priv->status & STATUS_ASSOCIATED)
6091 && (priv->config & CFG_STATIC_ESSID)
6092 && (le32_to_cpu(scan.full_scan_index) % 2))) {
6093 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6095 IPW_DEBUG_HC("Attempt to send SSID command "
6100 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6102 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
6104 ipw_add_scan_channels(priv, &scan, scan_type);
6105 #ifdef CONFIG_IPW2200_MONITOR
6109 err = ipw_send_scan_request_ext(priv, &scan);
6111 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
6115 priv->status |= STATUS_SCANNING;
6116 priv->status &= ~STATUS_SCAN_PENDING;
6117 queue_delayed_work(priv->workqueue, &priv->scan_check,
6118 IPW_SCAN_CHECK_WATCHDOG);
6120 mutex_unlock(&priv->mutex);
6124 static void ipw_bg_abort_scan(void *data)
6126 struct ipw_priv *priv = data;
6127 mutex_lock(&priv->mutex);
6128 ipw_abort_scan(data);
6129 mutex_unlock(&priv->mutex);
6132 static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6134 /* This is called when wpa_supplicant loads and closes the driver
6136 priv->ieee->wpa_enabled = value;
6140 static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6142 struct ieee80211_device *ieee = priv->ieee;
6143 struct ieee80211_security sec = {
6144 .flags = SEC_AUTH_MODE,
6148 if (value & IW_AUTH_ALG_SHARED_KEY) {
6149 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6151 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
6152 sec.auth_mode = WLAN_AUTH_OPEN;
6154 } else if (value & IW_AUTH_ALG_LEAP) {
6155 sec.auth_mode = WLAN_AUTH_LEAP;
6160 if (ieee->set_security)
6161 ieee->set_security(ieee->dev, &sec);
6168 static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6171 /* make sure WPA is enabled */
6172 ipw_wpa_enable(priv, 1);
6174 ipw_disassociate(priv);
6177 static int ipw_set_rsn_capa(struct ipw_priv *priv,
6178 char *capabilities, int length)
6180 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6182 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
6191 static int ipw_wx_set_genie(struct net_device *dev,
6192 struct iw_request_info *info,
6193 union iwreq_data *wrqu, char *extra)
6195 struct ipw_priv *priv = ieee80211_priv(dev);
6196 struct ieee80211_device *ieee = priv->ieee;
6200 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6201 (wrqu->data.length && extra == NULL))
6204 //mutex_lock(&priv->mutex);
6206 //if (!ieee->wpa_enabled) {
6207 // err = -EOPNOTSUPP;
6211 if (wrqu->data.length) {
6212 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6218 memcpy(buf, extra, wrqu->data.length);
6219 kfree(ieee->wpa_ie);
6221 ieee->wpa_ie_len = wrqu->data.length;
6223 kfree(ieee->wpa_ie);
6224 ieee->wpa_ie = NULL;
6225 ieee->wpa_ie_len = 0;
6228 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6230 //mutex_unlock(&priv->mutex);
6235 static int ipw_wx_get_genie(struct net_device *dev,
6236 struct iw_request_info *info,
6237 union iwreq_data *wrqu, char *extra)
6239 struct ipw_priv *priv = ieee80211_priv(dev);
6240 struct ieee80211_device *ieee = priv->ieee;
6243 //mutex_lock(&priv->mutex);
6245 //if (!ieee->wpa_enabled) {
6246 // err = -EOPNOTSUPP;
6250 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6251 wrqu->data.length = 0;
6255 if (wrqu->data.length < ieee->wpa_ie_len) {
6260 wrqu->data.length = ieee->wpa_ie_len;
6261 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6264 //mutex_unlock(&priv->mutex);
6268 static int wext_cipher2level(int cipher)
6271 case IW_AUTH_CIPHER_NONE:
6273 case IW_AUTH_CIPHER_WEP40:
6274 case IW_AUTH_CIPHER_WEP104:
6276 case IW_AUTH_CIPHER_TKIP:
6278 case IW_AUTH_CIPHER_CCMP:
6286 static int ipw_wx_set_auth(struct net_device *dev,
6287 struct iw_request_info *info,
6288 union iwreq_data *wrqu, char *extra)
6290 struct ipw_priv *priv = ieee80211_priv(dev);
6291 struct ieee80211_device *ieee = priv->ieee;
6292 struct iw_param *param = &wrqu->param;
6293 struct ieee80211_crypt_data *crypt;
6294 unsigned long flags;
6297 switch (param->flags & IW_AUTH_INDEX) {
6298 case IW_AUTH_WPA_VERSION:
6300 case IW_AUTH_CIPHER_PAIRWISE:
6301 ipw_set_hw_decrypt_unicast(priv,
6302 wext_cipher2level(param->value));
6304 case IW_AUTH_CIPHER_GROUP:
6305 ipw_set_hw_decrypt_multicast(priv,
6306 wext_cipher2level(param->value));
6308 case IW_AUTH_KEY_MGMT:
6310 * ipw2200 does not use these parameters
6314 case IW_AUTH_TKIP_COUNTERMEASURES:
6315 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6316 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
6319 flags = crypt->ops->get_flags(crypt->priv);
6322 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6324 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6326 crypt->ops->set_flags(flags, crypt->priv);
6330 case IW_AUTH_DROP_UNENCRYPTED:{
6333 * wpa_supplicant calls set_wpa_enabled when the driver
6334 * is loaded and unloaded, regardless of if WPA is being
6335 * used. No other calls are made which can be used to
6336 * determine if encryption will be used or not prior to
6337 * association being expected. If encryption is not being
6338 * used, drop_unencrypted is set to false, else true -- we
6339 * can use this to determine if the CAP_PRIVACY_ON bit should
6342 struct ieee80211_security sec = {
6343 .flags = SEC_ENABLED,
6344 .enabled = param->value,
6346 priv->ieee->drop_unencrypted = param->value;
6347 /* We only change SEC_LEVEL for open mode. Others
6348 * are set by ipw_wpa_set_encryption.
6350 if (!param->value) {
6351 sec.flags |= SEC_LEVEL;
6352 sec.level = SEC_LEVEL_0;
6354 sec.flags |= SEC_LEVEL;
6355 sec.level = SEC_LEVEL_1;
6357 if (priv->ieee->set_security)
6358 priv->ieee->set_security(priv->ieee->dev, &sec);
6362 case IW_AUTH_80211_AUTH_ALG:
6363 ret = ipw_wpa_set_auth_algs(priv, param->value);
6366 case IW_AUTH_WPA_ENABLED:
6367 ret = ipw_wpa_enable(priv, param->value);
6370 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6371 ieee->ieee802_1x = param->value;
6374 //case IW_AUTH_ROAMING_CONTROL:
6375 case IW_AUTH_PRIVACY_INVOKED:
6376 ieee->privacy_invoked = param->value;
6386 static int ipw_wx_get_auth(struct net_device *dev,
6387 struct iw_request_info *info,
6388 union iwreq_data *wrqu, char *extra)
6390 struct ipw_priv *priv = ieee80211_priv(dev);
6391 struct ieee80211_device *ieee = priv->ieee;
6392 struct ieee80211_crypt_data *crypt;
6393 struct iw_param *param = &wrqu->param;
6396 switch (param->flags & IW_AUTH_INDEX) {
6397 case IW_AUTH_WPA_VERSION:
6398 case IW_AUTH_CIPHER_PAIRWISE:
6399 case IW_AUTH_CIPHER_GROUP:
6400 case IW_AUTH_KEY_MGMT:
6402 * wpa_supplicant will control these internally
6407 case IW_AUTH_TKIP_COUNTERMEASURES:
6408 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6409 if (!crypt || !crypt->ops->get_flags)
6412 param->value = (crypt->ops->get_flags(crypt->priv) &
6413 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6417 case IW_AUTH_DROP_UNENCRYPTED:
6418 param->value = ieee->drop_unencrypted;
6421 case IW_AUTH_80211_AUTH_ALG:
6422 param->value = ieee->sec.auth_mode;
6425 case IW_AUTH_WPA_ENABLED:
6426 param->value = ieee->wpa_enabled;
6429 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6430 param->value = ieee->ieee802_1x;
6433 case IW_AUTH_ROAMING_CONTROL:
6434 case IW_AUTH_PRIVACY_INVOKED:
6435 param->value = ieee->privacy_invoked;
6444 /* SIOCSIWENCODEEXT */
6445 static int ipw_wx_set_encodeext(struct net_device *dev,
6446 struct iw_request_info *info,
6447 union iwreq_data *wrqu, char *extra)
6449 struct ipw_priv *priv = ieee80211_priv(dev);
6450 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6453 if (ext->alg == IW_ENCODE_ALG_TKIP) {
6454 /* IPW HW can't build TKIP MIC,
6455 host decryption still needed */
6456 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6457 priv->ieee->host_mc_decrypt = 1;
6459 priv->ieee->host_encrypt = 0;
6460 priv->ieee->host_encrypt_msdu = 1;
6461 priv->ieee->host_decrypt = 1;
6464 priv->ieee->host_encrypt = 0;
6465 priv->ieee->host_encrypt_msdu = 0;
6466 priv->ieee->host_decrypt = 0;
6467 priv->ieee->host_mc_decrypt = 0;
6471 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6474 /* SIOCGIWENCODEEXT */
6475 static int ipw_wx_get_encodeext(struct net_device *dev,
6476 struct iw_request_info *info,
6477 union iwreq_data *wrqu, char *extra)
6479 struct ipw_priv *priv = ieee80211_priv(dev);
6480 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6484 static int ipw_wx_set_mlme(struct net_device *dev,
6485 struct iw_request_info *info,
6486 union iwreq_data *wrqu, char *extra)
6488 struct ipw_priv *priv = ieee80211_priv(dev);
6489 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6492 reason = cpu_to_le16(mlme->reason_code);
6494 switch (mlme->cmd) {
6495 case IW_MLME_DEAUTH:
6499 case IW_MLME_DISASSOC:
6500 ipw_disassociate(priv);
6509 #ifdef CONFIG_IPW_QOS
6513 * get the modulation type of the current network or
6514 * the card current mode
6516 static u8 ipw_qos_current_mode(struct ipw_priv * priv)
6520 if (priv->status & STATUS_ASSOCIATED) {
6521 unsigned long flags;
6523 spin_lock_irqsave(&priv->ieee->lock, flags);
6524 mode = priv->assoc_network->mode;
6525 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6527 mode = priv->ieee->mode;
6529 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6534 * Handle management frame beacon and probe response
6536 static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6538 struct ieee80211_network *network)
6540 u32 size = sizeof(struct ieee80211_qos_parameters);
6542 if (network->capability & WLAN_CAPABILITY_IBSS)
6543 network->qos_data.active = network->qos_data.supported;
6545 if (network->flags & NETWORK_HAS_QOS_MASK) {
6546 if (active_network &&
6547 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
6548 network->qos_data.active = network->qos_data.supported;
6550 if ((network->qos_data.active == 1) && (active_network == 1) &&
6551 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6552 (network->qos_data.old_param_count !=
6553 network->qos_data.param_count)) {
6554 network->qos_data.old_param_count =
6555 network->qos_data.param_count;
6556 schedule_work(&priv->qos_activate);
6557 IPW_DEBUG_QOS("QoS parameters change call "
6561 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6562 memcpy(&network->qos_data.parameters,
6563 &def_parameters_CCK, size);
6565 memcpy(&network->qos_data.parameters,
6566 &def_parameters_OFDM, size);
6568 if ((network->qos_data.active == 1) && (active_network == 1)) {
6569 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6570 schedule_work(&priv->qos_activate);
6573 network->qos_data.active = 0;
6574 network->qos_data.supported = 0;
6576 if ((priv->status & STATUS_ASSOCIATED) &&
6577 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6578 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6579 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6580 !(network->flags & NETWORK_EMPTY_ESSID))
6581 if ((network->ssid_len ==
6582 priv->assoc_network->ssid_len) &&
6583 !memcmp(network->ssid,
6584 priv->assoc_network->ssid,
6585 network->ssid_len)) {
6586 queue_work(priv->workqueue,
6587 &priv->merge_networks);
6595 * This function set up the firmware to support QoS. It sends
6596 * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6598 static int ipw_qos_activate(struct ipw_priv *priv,
6599 struct ieee80211_qos_data *qos_network_data)
6602 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6603 struct ieee80211_qos_parameters *active_one = NULL;
6604 u32 size = sizeof(struct ieee80211_qos_parameters);
6609 type = ipw_qos_current_mode(priv);
6611 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6612 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6613 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6614 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6616 if (qos_network_data == NULL) {
6617 if (type == IEEE_B) {
6618 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6619 active_one = &def_parameters_CCK;
6621 active_one = &def_parameters_OFDM;
6623 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6624 burst_duration = ipw_qos_get_burst_duration(priv);
6625 for (i = 0; i < QOS_QUEUE_NUM; i++)
6626 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6627 (u16) burst_duration;
6628 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6629 if (type == IEEE_B) {
6630 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6632 if (priv->qos_data.qos_enable == 0)
6633 active_one = &def_parameters_CCK;
6635 active_one = priv->qos_data.def_qos_parm_CCK;
6637 if (priv->qos_data.qos_enable == 0)
6638 active_one = &def_parameters_OFDM;
6640 active_one = priv->qos_data.def_qos_parm_OFDM;
6642 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6644 unsigned long flags;
6647 spin_lock_irqsave(&priv->ieee->lock, flags);
6648 active_one = &(qos_network_data->parameters);
6649 qos_network_data->old_param_count =
6650 qos_network_data->param_count;
6651 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6652 active = qos_network_data->supported;
6653 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6656 burst_duration = ipw_qos_get_burst_duration(priv);
6657 for (i = 0; i < QOS_QUEUE_NUM; i++)
6658 qos_parameters[QOS_PARAM_SET_ACTIVE].
6659 tx_op_limit[i] = (u16) burst_duration;
6663 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
6664 err = ipw_send_qos_params_command(priv,
6665 (struct ieee80211_qos_parameters *)
6666 &(qos_parameters[0]));
6668 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6674 * send IPW_CMD_WME_INFO to the firmware
6676 static int ipw_qos_set_info_element(struct ipw_priv *priv)
6679 struct ieee80211_qos_information_element qos_info;
6684 qos_info.elementID = QOS_ELEMENT_ID;
6685 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6687 qos_info.version = QOS_VERSION_1;
6688 qos_info.ac_info = 0;
6690 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6691 qos_info.qui_type = QOS_OUI_TYPE;
6692 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6694 ret = ipw_send_qos_info_command(priv, &qos_info);
6696 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6702 * Set the QoS parameter with the association request structure
6704 static int ipw_qos_association(struct ipw_priv *priv,
6705 struct ieee80211_network *network)
6708 struct ieee80211_qos_data *qos_data = NULL;
6709 struct ieee80211_qos_data ibss_data = {
6714 switch (priv->ieee->iw_mode) {
6716 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
6718 qos_data = &ibss_data;
6722 qos_data = &network->qos_data;
6730 err = ipw_qos_activate(priv, qos_data);
6732 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6736 if (priv->qos_data.qos_enable && qos_data->supported) {
6737 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6738 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6739 return ipw_qos_set_info_element(priv);
6746 * handling the beaconing responces. if we get different QoS setting
6747 * of the network from the the associated setting adjust the QoS
6750 static int ipw_qos_association_resp(struct ipw_priv *priv,
6751 struct ieee80211_network *network)
6754 unsigned long flags;
6755 u32 size = sizeof(struct ieee80211_qos_parameters);
6756 int set_qos_param = 0;
6758 if ((priv == NULL) || (network == NULL) ||
6759 (priv->assoc_network == NULL))
6762 if (!(priv->status & STATUS_ASSOCIATED))
6765 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
6768 spin_lock_irqsave(&priv->ieee->lock, flags);
6769 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
6770 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
6771 sizeof(struct ieee80211_qos_data));
6772 priv->assoc_network->qos_data.active = 1;
6773 if ((network->qos_data.old_param_count !=
6774 network->qos_data.param_count)) {
6776 network->qos_data.old_param_count =
6777 network->qos_data.param_count;
6781 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
6782 memcpy(&priv->assoc_network->qos_data.parameters,
6783 &def_parameters_CCK, size);
6785 memcpy(&priv->assoc_network->qos_data.parameters,
6786 &def_parameters_OFDM, size);
6787 priv->assoc_network->qos_data.active = 0;
6788 priv->assoc_network->qos_data.supported = 0;
6792 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6794 if (set_qos_param == 1)
6795 schedule_work(&priv->qos_activate);
6800 static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
6807 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
6808 ret = priv->qos_data.burst_duration_CCK;
6810 ret = priv->qos_data.burst_duration_OFDM;
6816 * Initialize the setting of QoS global
6818 static void ipw_qos_init(struct ipw_priv *priv, int enable,
6819 int burst_enable, u32 burst_duration_CCK,
6820 u32 burst_duration_OFDM)
6822 priv->qos_data.qos_enable = enable;
6824 if (priv->qos_data.qos_enable) {
6825 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
6826 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
6827 IPW_DEBUG_QOS("QoS is enabled\n");
6829 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
6830 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
6831 IPW_DEBUG_QOS("QoS is not enabled\n");
6834 priv->qos_data.burst_enable = burst_enable;
6837 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
6838 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
6840 priv->qos_data.burst_duration_CCK = 0;
6841 priv->qos_data.burst_duration_OFDM = 0;
6846 * map the packet priority to the right TX Queue
6848 static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
6850 if (priority > 7 || !priv->qos_data.qos_enable)
6853 return from_priority_to_tx_queue[priority] - 1;
6857 * add QoS parameter to the TX command
6859 static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
6861 struct tfd_data *tfd, u8 unicast)
6864 int tx_queue_id = 0;
6865 struct ieee80211_qos_data *qos_data = NULL;
6866 int active, supported;
6867 unsigned long flags;
6869 if (!(priv->status & STATUS_ASSOCIATED))
6872 qos_data = &priv->assoc_network->qos_data;
6874 spin_lock_irqsave(&priv->ieee->lock, flags);
6876 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6878 qos_data->active = 0;
6880 qos_data->active = qos_data->supported;
6883 active = qos_data->active;
6884 supported = qos_data->supported;
6886 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6888 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
6890 priv->qos_data.qos_enable, active, supported, unicast);
6891 if (active && priv->qos_data.qos_enable) {
6892 ret = from_priority_to_tx_queue[priority];
6893 tx_queue_id = ret - 1;
6894 IPW_DEBUG_QOS("QoS packet priority is %d \n", priority);
6895 if (priority <= 7) {
6896 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
6897 tfd->tfd.tfd_26.mchdr.qos_ctrl = priority;
6898 tfd->tfd.tfd_26.mchdr.frame_ctl |=
6899 IEEE80211_STYPE_QOS_DATA;
6901 if (priv->qos_data.qos_no_ack_mask &
6902 (1UL << tx_queue_id)) {
6903 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
6904 tfd->tfd.tfd_26.mchdr.qos_ctrl |=
6914 * background support to run QoS activate functionality
6916 static void ipw_bg_qos_activate(void *data)
6918 struct ipw_priv *priv = data;
6923 mutex_lock(&priv->mutex);
6925 if (priv->status & STATUS_ASSOCIATED)
6926 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
6928 mutex_unlock(&priv->mutex);
6931 static int ipw_handle_probe_response(struct net_device *dev,
6932 struct ieee80211_probe_response *resp,
6933 struct ieee80211_network *network)
6935 struct ipw_priv *priv = ieee80211_priv(dev);
6936 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
6937 (network == priv->assoc_network));
6939 ipw_qos_handle_probe_response(priv, active_network, network);
6944 static int ipw_handle_beacon(struct net_device *dev,
6945 struct ieee80211_beacon *resp,
6946 struct ieee80211_network *network)
6948 struct ipw_priv *priv = ieee80211_priv(dev);
6949 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
6950 (network == priv->assoc_network));
6952 ipw_qos_handle_probe_response(priv, active_network, network);
6957 static int ipw_handle_assoc_response(struct net_device *dev,
6958 struct ieee80211_assoc_response *resp,
6959 struct ieee80211_network *network)
6961 struct ipw_priv *priv = ieee80211_priv(dev);
6962 ipw_qos_association_resp(priv, network);
6966 static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
6969 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
6970 sizeof(*qos_param) * 3, qos_param);
6973 static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
6976 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
6980 #endif /* CONFIG_IPW_QOS */
6982 static int ipw_associate_network(struct ipw_priv *priv,
6983 struct ieee80211_network *network,
6984 struct ipw_supported_rates *rates, int roaming)
6988 if (priv->config & CFG_FIXED_RATE)
6989 ipw_set_fixed_rate(priv, network->mode);
6991 if (!(priv->config & CFG_STATIC_ESSID)) {
6992 priv->essid_len = min(network->ssid_len,
6993 (u8) IW_ESSID_MAX_SIZE);
6994 memcpy(priv->essid, network->ssid, priv->essid_len);
6997 network->last_associate = jiffies;
6999 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7000 priv->assoc_request.channel = network->channel;
7001 priv->assoc_request.auth_key = 0;
7003 if ((priv->capability & CAP_PRIVACY_ON) &&
7004 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
7005 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
7006 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7008 if (priv->ieee->sec.level == SEC_LEVEL_1)
7009 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
7011 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7012 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7013 priv->assoc_request.auth_type = AUTH_LEAP;
7015 priv->assoc_request.auth_type = AUTH_OPEN;
7017 if (priv->ieee->wpa_ie_len) {
7018 priv->assoc_request.policy_support = 0x02; /* RSN active */
7019 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7020 priv->ieee->wpa_ie_len);
7024 * It is valid for our ieee device to support multiple modes, but
7025 * when it comes to associating to a given network we have to choose
7028 if (network->mode & priv->ieee->mode & IEEE_A)
7029 priv->assoc_request.ieee_mode = IPW_A_MODE;
7030 else if (network->mode & priv->ieee->mode & IEEE_G)
7031 priv->assoc_request.ieee_mode = IPW_G_MODE;
7032 else if (network->mode & priv->ieee->mode & IEEE_B)
7033 priv->assoc_request.ieee_mode = IPW_B_MODE;
7035 priv->assoc_request.capability = network->capability;
7036 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7037 && !(priv->config & CFG_PREAMBLE_LONG)) {
7038 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7040 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7042 /* Clear the short preamble if we won't be supporting it */
7043 priv->assoc_request.capability &=
7044 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7047 /* Clear capability bits that aren't used in Ad Hoc */
7048 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7049 priv->assoc_request.capability &=
7050 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7052 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
7053 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
7054 roaming ? "Rea" : "A",
7055 escape_essid(priv->essid, priv->essid_len),
7057 ipw_modes[priv->assoc_request.ieee_mode],
7059 (priv->assoc_request.preamble_length ==
7060 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7061 network->capability &
7062 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
7063 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
7064 priv->capability & CAP_PRIVACY_ON ?
7065 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
7067 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
7068 priv->capability & CAP_PRIVACY_ON ?
7069 '1' + priv->ieee->sec.active_key : '.',
7070 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
7072 priv->assoc_request.beacon_interval = network->beacon_interval;
7073 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
7074 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
7075 priv->assoc_request.assoc_type = HC_IBSS_START;
7076 priv->assoc_request.assoc_tsf_msw = 0;
7077 priv->assoc_request.assoc_tsf_lsw = 0;
7079 if (unlikely(roaming))
7080 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7082 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7083 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7084 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7087 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
7089 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7090 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7091 priv->assoc_request.atim_window = network->atim_window;
7093 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
7094 priv->assoc_request.atim_window = 0;
7097 priv->assoc_request.listen_interval = network->listen_interval;
7099 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7101 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7105 rates->ieee_mode = priv->assoc_request.ieee_mode;
7106 rates->purpose = IPW_RATE_CONNECT;
7107 ipw_send_supported_rates(priv, rates);
7109 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7110 priv->sys_config.dot11g_auto_detection = 1;
7112 priv->sys_config.dot11g_auto_detection = 0;
7114 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7115 priv->sys_config.answer_broadcast_ssid_probe = 1;
7117 priv->sys_config.answer_broadcast_ssid_probe = 0;
7119 err = ipw_send_system_config(priv, &priv->sys_config);
7121 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7125 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
7126 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
7128 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7133 * If preemption is enabled, it is possible for the association
7134 * to complete before we return from ipw_send_associate. Therefore
7135 * we have to be sure and update our priviate data first.
7137 priv->channel = network->channel;
7138 memcpy(priv->bssid, network->bssid, ETH_ALEN);
7139 priv->status |= STATUS_ASSOCIATING;
7140 priv->status &= ~STATUS_SECURITY_UPDATED;
7142 priv->assoc_network = network;
7144 #ifdef CONFIG_IPW_QOS
7145 ipw_qos_association(priv, network);
7148 err = ipw_send_associate(priv, &priv->assoc_request);
7150 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7154 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
7155 escape_essid(priv->essid, priv->essid_len),
7156 MAC_ARG(priv->bssid));
7161 static void ipw_roam(void *data)
7163 struct ipw_priv *priv = data;
7164 struct ieee80211_network *network = NULL;
7165 struct ipw_network_match match = {
7166 .network = priv->assoc_network
7169 /* The roaming process is as follows:
7171 * 1. Missed beacon threshold triggers the roaming process by
7172 * setting the status ROAM bit and requesting a scan.
7173 * 2. When the scan completes, it schedules the ROAM work
7174 * 3. The ROAM work looks at all of the known networks for one that
7175 * is a better network than the currently associated. If none
7176 * found, the ROAM process is over (ROAM bit cleared)
7177 * 4. If a better network is found, a disassociation request is
7179 * 5. When the disassociation completes, the roam work is again
7180 * scheduled. The second time through, the driver is no longer
7181 * associated, and the newly selected network is sent an
7182 * association request.
7183 * 6. At this point ,the roaming process is complete and the ROAM
7184 * status bit is cleared.
7187 /* If we are no longer associated, and the roaming bit is no longer
7188 * set, then we are not actively roaming, so just return */
7189 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7192 if (priv->status & STATUS_ASSOCIATED) {
7193 /* First pass through ROAM process -- look for a better
7195 unsigned long flags;
7196 u8 rssi = priv->assoc_network->stats.rssi;
7197 priv->assoc_network->stats.rssi = -128;
7198 spin_lock_irqsave(&priv->ieee->lock, flags);
7199 list_for_each_entry(network, &priv->ieee->network_list, list) {
7200 if (network != priv->assoc_network)
7201 ipw_best_network(priv, &match, network, 1);
7203 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7204 priv->assoc_network->stats.rssi = rssi;
7206 if (match.network == priv->assoc_network) {
7207 IPW_DEBUG_ASSOC("No better APs in this network to "
7209 priv->status &= ~STATUS_ROAMING;
7210 ipw_debug_config(priv);
7214 ipw_send_disassociate(priv, 1);
7215 priv->assoc_network = match.network;
7220 /* Second pass through ROAM process -- request association */
7221 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7222 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7223 priv->status &= ~STATUS_ROAMING;
7226 static void ipw_bg_roam(void *data)
7228 struct ipw_priv *priv = data;
7229 mutex_lock(&priv->mutex);
7231 mutex_unlock(&priv->mutex);
7234 static int ipw_associate(void *data)
7236 struct ipw_priv *priv = data;
7238 struct ieee80211_network *network = NULL;
7239 struct ipw_network_match match = {
7242 struct ipw_supported_rates *rates;
7243 struct list_head *element;
7244 unsigned long flags;
7246 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7247 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7251 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
7252 IPW_DEBUG_ASSOC("Not attempting association (already in "
7257 if (priv->status & STATUS_DISASSOCIATING) {
7258 IPW_DEBUG_ASSOC("Not attempting association (in "
7259 "disassociating)\n ");
7260 queue_work(priv->workqueue, &priv->associate);
7264 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
7265 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7270 if (!(priv->config & CFG_ASSOCIATE) &&
7271 !(priv->config & (CFG_STATIC_ESSID |
7272 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
7273 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
7277 /* Protect our use of the network_list */
7278 spin_lock_irqsave(&priv->ieee->lock, flags);
7279 list_for_each_entry(network, &priv->ieee->network_list, list)
7280 ipw_best_network(priv, &match, network, 0);
7282 network = match.network;
7283 rates = &match.rates;
7285 if (network == NULL &&
7286 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7287 priv->config & CFG_ADHOC_CREATE &&
7288 priv->config & CFG_STATIC_ESSID &&
7289 priv->config & CFG_STATIC_CHANNEL &&
7290 !list_empty(&priv->ieee->network_free_list)) {
7291 element = priv->ieee->network_free_list.next;
7292 network = list_entry(element, struct ieee80211_network, list);
7293 ipw_adhoc_create(priv, network);
7294 rates = &priv->rates;
7296 list_add_tail(&network->list, &priv->ieee->network_list);
7298 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7300 /* If we reached the end of the list, then we don't have any valid
7303 ipw_debug_config(priv);
7305 if (!(priv->status & STATUS_SCANNING)) {
7306 if (!(priv->config & CFG_SPEED_SCAN))
7307 queue_delayed_work(priv->workqueue,
7308 &priv->request_scan,
7311 queue_work(priv->workqueue,
7312 &priv->request_scan);
7318 ipw_associate_network(priv, network, rates, 0);
7323 static void ipw_bg_associate(void *data)
7325 struct ipw_priv *priv = data;
7326 mutex_lock(&priv->mutex);
7327 ipw_associate(data);
7328 mutex_unlock(&priv->mutex);
7331 static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7332 struct sk_buff *skb)
7334 struct ieee80211_hdr *hdr;
7337 hdr = (struct ieee80211_hdr *)skb->data;
7338 fc = le16_to_cpu(hdr->frame_ctl);
7339 if (!(fc & IEEE80211_FCTL_PROTECTED))
7342 fc &= ~IEEE80211_FCTL_PROTECTED;
7343 hdr->frame_ctl = cpu_to_le16(fc);
7344 switch (priv->ieee->sec.level) {
7346 /* Remove CCMP HDR */
7347 memmove(skb->data + IEEE80211_3ADDR_LEN,
7348 skb->data + IEEE80211_3ADDR_LEN + 8,
7349 skb->len - IEEE80211_3ADDR_LEN - 8);
7350 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
7356 memmove(skb->data + IEEE80211_3ADDR_LEN,
7357 skb->data + IEEE80211_3ADDR_LEN + 4,
7358 skb->len - IEEE80211_3ADDR_LEN - 4);
7359 skb_trim(skb, skb->len - 8); /* IV + ICV */
7364 printk(KERN_ERR "Unknow security level %d\n",
7365 priv->ieee->sec.level);
7370 static void ipw_handle_data_packet(struct ipw_priv *priv,
7371 struct ipw_rx_mem_buffer *rxb,
7372 struct ieee80211_rx_stats *stats)
7374 struct ieee80211_hdr_4addr *hdr;
7375 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7377 /* We received data from the HW, so stop the watchdog */
7378 priv->net_dev->trans_start = jiffies;
7380 /* We only process data packets if the
7381 * interface is open */
7382 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7383 skb_tailroom(rxb->skb))) {
7384 priv->ieee->stats.rx_errors++;
7385 priv->wstats.discard.misc++;
7386 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7388 } else if (unlikely(!netif_running(priv->net_dev))) {
7389 priv->ieee->stats.rx_dropped++;
7390 priv->wstats.discard.misc++;
7391 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7395 /* Advance skb->data to the start of the actual payload */
7396 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
7398 /* Set the size of the skb to the size of the frame */
7399 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
7401 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7403 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
7404 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7405 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
7406 (is_multicast_ether_addr(hdr->addr1) ?
7407 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
7408 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7410 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7411 priv->ieee->stats.rx_errors++;
7412 else { /* ieee80211_rx succeeded, so it now owns the SKB */
7414 __ipw_led_activity_on(priv);
7418 #ifdef CONFIG_IEEE80211_RADIOTAP
7419 static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7420 struct ipw_rx_mem_buffer *rxb,
7421 struct ieee80211_rx_stats *stats)
7423 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7424 struct ipw_rx_frame *frame = &pkt->u.frame;
7426 /* initial pull of some data */
7427 u16 received_channel = frame->received_channel;
7428 u8 antennaAndPhy = frame->antennaAndPhy;
7429 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7430 u16 pktrate = frame->rate;
7432 /* Magic struct that slots into the radiotap header -- no reason
7433 * to build this manually element by element, we can write it much
7434 * more efficiently than we can parse it. ORDER MATTERS HERE */
7436 struct ieee80211_radiotap_header rt_hdr;
7437 u8 rt_flags; /* radiotap packet flags */
7438 u8 rt_rate; /* rate in 500kb/s */
7439 u16 rt_channel; /* channel in mhz */
7440 u16 rt_chbitmask; /* channel bitfield */
7441 s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
7442 u8 rt_antenna; /* antenna number */
7445 short len = le16_to_cpu(pkt->u.frame.length);
7447 /* We received data from the HW, so stop the watchdog */
7448 priv->net_dev->trans_start = jiffies;
7450 /* We only process data packets if the
7451 * interface is open */
7452 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7453 skb_tailroom(rxb->skb))) {
7454 priv->ieee->stats.rx_errors++;
7455 priv->wstats.discard.misc++;
7456 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7458 } else if (unlikely(!netif_running(priv->net_dev))) {
7459 priv->ieee->stats.rx_dropped++;
7460 priv->wstats.discard.misc++;
7461 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7465 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7467 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7468 /* FIXME: Should alloc bigger skb instead */
7469 priv->ieee->stats.rx_dropped++;
7470 priv->wstats.discard.misc++;
7471 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7475 /* copy the frame itself */
7476 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7477 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7479 /* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7480 * part of our real header, saves a little time.
7482 * No longer necessary since we fill in all our data. Purge before merging
7484 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7485 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7488 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7490 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7491 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7492 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7494 /* Big bitfield of all the fields we provide in radiotap */
7495 ipw_rt->rt_hdr.it_present =
7496 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7497 (1 << IEEE80211_RADIOTAP_RATE) |
7498 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7499 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7500 (1 << IEEE80211_RADIOTAP_ANTENNA));
7502 /* Zero the flags, we'll add to them as we go */
7503 ipw_rt->rt_flags = 0;
7505 /* Convert signal to DBM */
7506 ipw_rt->rt_dbmsignal = antsignal;
7508 /* Convert the channel data and set the flags */
7509 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7510 if (received_channel > 14) { /* 802.11a */
7511 ipw_rt->rt_chbitmask =
7512 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7513 } else if (antennaAndPhy & 32) { /* 802.11b */
7514 ipw_rt->rt_chbitmask =
7515 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7516 } else { /* 802.11g */
7517 ipw_rt->rt_chbitmask =
7518 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7521 /* set the rate in multiples of 500k/s */
7523 case IPW_TX_RATE_1MB:
7524 ipw_rt->rt_rate = 2;
7526 case IPW_TX_RATE_2MB:
7527 ipw_rt->rt_rate = 4;
7529 case IPW_TX_RATE_5MB:
7530 ipw_rt->rt_rate = 10;
7532 case IPW_TX_RATE_6MB:
7533 ipw_rt->rt_rate = 12;
7535 case IPW_TX_RATE_9MB:
7536 ipw_rt->rt_rate = 18;
7538 case IPW_TX_RATE_11MB:
7539 ipw_rt->rt_rate = 22;
7541 case IPW_TX_RATE_12MB:
7542 ipw_rt->rt_rate = 24;
7544 case IPW_TX_RATE_18MB:
7545 ipw_rt->rt_rate = 36;
7547 case IPW_TX_RATE_24MB:
7548 ipw_rt->rt_rate = 48;
7550 case IPW_TX_RATE_36MB:
7551 ipw_rt->rt_rate = 72;
7553 case IPW_TX_RATE_48MB:
7554 ipw_rt->rt_rate = 96;
7556 case IPW_TX_RATE_54MB:
7557 ipw_rt->rt_rate = 108;
7560 ipw_rt->rt_rate = 0;
7564 /* antenna number */
7565 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7567 /* set the preamble flag if we have it */
7568 if ((antennaAndPhy & 64))
7569 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7571 /* Set the size of the skb to the size of the frame */
7572 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
7574 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7576 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7577 priv->ieee->stats.rx_errors++;
7578 else { /* ieee80211_rx succeeded, so it now owns the SKB */
7580 /* no LED during capture */
7585 static int is_network_packet(struct ipw_priv *priv,
7586 struct ieee80211_hdr_4addr *header)
7588 /* Filter incoming packets to determine if they are targetted toward
7589 * this network, discarding packets coming from ourselves */
7590 switch (priv->ieee->iw_mode) {
7591 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
7592 /* packets from our adapter are dropped (echo) */
7593 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7596 /* {broad,multi}cast packets to our BSSID go through */
7597 if (is_multicast_ether_addr(header->addr1))
7598 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
7600 /* packets to our adapter go through */
7601 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7604 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
7605 /* packets from our adapter are dropped (echo) */
7606 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7609 /* {broad,multi}cast packets to our BSS go through */
7610 if (is_multicast_ether_addr(header->addr1))
7611 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7613 /* packets to our adapter go through */
7614 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7621 #define IPW_PACKET_RETRY_TIME HZ
7623 static int is_duplicate_packet(struct ipw_priv *priv,
7624 struct ieee80211_hdr_4addr *header)
7626 u16 sc = le16_to_cpu(header->seq_ctl);
7627 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7628 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7629 u16 *last_seq, *last_frag;
7630 unsigned long *last_time;
7632 switch (priv->ieee->iw_mode) {
7635 struct list_head *p;
7636 struct ipw_ibss_seq *entry = NULL;
7637 u8 *mac = header->addr2;
7638 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
7640 __list_for_each(p, &priv->ibss_mac_hash[index]) {
7642 list_entry(p, struct ipw_ibss_seq, list);
7643 if (!memcmp(entry->mac, mac, ETH_ALEN))
7646 if (p == &priv->ibss_mac_hash[index]) {
7647 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
7650 ("Cannot malloc new mac entry\n");
7653 memcpy(entry->mac, mac, ETH_ALEN);
7654 entry->seq_num = seq;
7655 entry->frag_num = frag;
7656 entry->packet_time = jiffies;
7657 list_add(&entry->list,
7658 &priv->ibss_mac_hash[index]);
7661 last_seq = &entry->seq_num;
7662 last_frag = &entry->frag_num;
7663 last_time = &entry->packet_time;
7667 last_seq = &priv->last_seq_num;
7668 last_frag = &priv->last_frag_num;
7669 last_time = &priv->last_packet_time;
7674 if ((*last_seq == seq) &&
7675 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
7676 if (*last_frag == frag)
7678 if (*last_frag + 1 != frag)
7679 /* out-of-order fragment */
7685 *last_time = jiffies;
7689 /* Comment this line now since we observed the card receives
7690 * duplicate packets but the FCTL_RETRY bit is not set in the
7691 * IBSS mode with fragmentation enabled.
7692 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
7696 static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
7697 struct ipw_rx_mem_buffer *rxb,
7698 struct ieee80211_rx_stats *stats)
7700 struct sk_buff *skb = rxb->skb;
7701 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
7702 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
7703 (skb->data + IPW_RX_FRAME_SIZE);
7705 ieee80211_rx_mgt(priv->ieee, header, stats);
7707 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
7708 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7709 IEEE80211_STYPE_PROBE_RESP) ||
7710 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7711 IEEE80211_STYPE_BEACON))) {
7712 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
7713 ipw_add_station(priv, header->addr2);
7716 if (priv->config & CFG_NET_STATS) {
7717 IPW_DEBUG_HC("sending stat packet\n");
7719 /* Set the size of the skb to the size of the full
7720 * ipw header and 802.11 frame */
7721 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
7724 /* Advance past the ipw packet header to the 802.11 frame */
7725 skb_pull(skb, IPW_RX_FRAME_SIZE);
7727 /* Push the ieee80211_rx_stats before the 802.11 frame */
7728 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
7730 skb->dev = priv->ieee->dev;
7732 /* Point raw at the ieee80211_stats */
7733 skb->mac.raw = skb->data;
7735 skb->pkt_type = PACKET_OTHERHOST;
7736 skb->protocol = __constant_htons(ETH_P_80211_STATS);
7737 memset(skb->cb, 0, sizeof(rxb->skb->cb));
7744 * Main entry function for recieving a packet with 80211 headers. This
7745 * should be called when ever the FW has notified us that there is a new
7746 * skb in the recieve queue.
7748 static void ipw_rx(struct ipw_priv *priv)
7750 struct ipw_rx_mem_buffer *rxb;
7751 struct ipw_rx_packet *pkt;
7752 struct ieee80211_hdr_4addr *header;
7756 r = ipw_read32(priv, IPW_RX_READ_INDEX);
7757 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
7758 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
7761 rxb = priv->rxq->queue[i];
7762 if (unlikely(rxb == NULL)) {
7763 printk(KERN_CRIT "Queue not allocated!\n");
7766 priv->rxq->queue[i] = NULL;
7768 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
7770 PCI_DMA_FROMDEVICE);
7772 pkt = (struct ipw_rx_packet *)rxb->skb->data;
7773 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
7774 pkt->header.message_type,
7775 pkt->header.rx_seq_num, pkt->header.control_bits);
7777 switch (pkt->header.message_type) {
7778 case RX_FRAME_TYPE: /* 802.11 frame */ {
7779 struct ieee80211_rx_stats stats = {
7781 le16_to_cpu(pkt->u.frame.rssi_dbm) -
7784 le16_to_cpu(pkt->u.frame.rssi_dbm) -
7785 IPW_RSSI_TO_DBM + 0x100,
7787 le16_to_cpu(pkt->u.frame.noise),
7788 .rate = pkt->u.frame.rate,
7789 .mac_time = jiffies,
7791 pkt->u.frame.received_channel,
7794 control & (1 << 0)) ?
7795 IEEE80211_24GHZ_BAND :
7796 IEEE80211_52GHZ_BAND,
7797 .len = le16_to_cpu(pkt->u.frame.length),
7800 if (stats.rssi != 0)
7801 stats.mask |= IEEE80211_STATMASK_RSSI;
7802 if (stats.signal != 0)
7803 stats.mask |= IEEE80211_STATMASK_SIGNAL;
7804 if (stats.noise != 0)
7805 stats.mask |= IEEE80211_STATMASK_NOISE;
7806 if (stats.rate != 0)
7807 stats.mask |= IEEE80211_STATMASK_RATE;
7811 #ifdef CONFIG_IPW2200_MONITOR
7812 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7813 #ifdef CONFIG_IEEE80211_RADIOTAP
7814 ipw_handle_data_packet_monitor(priv,
7818 ipw_handle_data_packet(priv, rxb,
7826 (struct ieee80211_hdr_4addr *)(rxb->skb->
7829 /* TODO: Check Ad-Hoc dest/source and make sure
7830 * that we are actually parsing these packets
7831 * correctly -- we should probably use the
7832 * frame control of the packet and disregard
7833 * the current iw_mode */
7836 is_network_packet(priv, header);
7837 if (network_packet && priv->assoc_network) {
7838 priv->assoc_network->stats.rssi =
7840 average_add(&priv->average_rssi,
7842 priv->last_rx_rssi = stats.rssi;
7845 IPW_DEBUG_RX("Frame: len=%u\n",
7846 le16_to_cpu(pkt->u.frame.length));
7848 if (le16_to_cpu(pkt->u.frame.length) <
7849 ieee80211_get_hdrlen(le16_to_cpu(
7850 header->frame_ctl))) {
7852 ("Received packet is too small. "
7854 priv->ieee->stats.rx_errors++;
7855 priv->wstats.discard.misc++;
7859 switch (WLAN_FC_GET_TYPE
7860 (le16_to_cpu(header->frame_ctl))) {
7862 case IEEE80211_FTYPE_MGMT:
7863 ipw_handle_mgmt_packet(priv, rxb,
7867 case IEEE80211_FTYPE_CTL:
7870 case IEEE80211_FTYPE_DATA:
7871 if (unlikely(!network_packet ||
7872 is_duplicate_packet(priv,
7875 IPW_DEBUG_DROP("Dropping: "
7888 ipw_handle_data_packet(priv, rxb,
7896 case RX_HOST_NOTIFICATION_TYPE:{
7898 ("Notification: subtype=%02X flags=%02X size=%d\n",
7899 pkt->u.notification.subtype,
7900 pkt->u.notification.flags,
7901 pkt->u.notification.size);
7902 ipw_rx_notification(priv, &pkt->u.notification);
7907 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
7908 pkt->header.message_type);
7912 /* For now we just don't re-use anything. We can tweak this
7913 * later to try and re-use notification packets and SKBs that
7914 * fail to Rx correctly */
7915 if (rxb->skb != NULL) {
7916 dev_kfree_skb_any(rxb->skb);
7920 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
7921 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
7922 list_add_tail(&rxb->list, &priv->rxq->rx_used);
7924 i = (i + 1) % RX_QUEUE_SIZE;
7927 /* Backtrack one entry */
7928 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
7930 ipw_rx_queue_restock(priv);
7933 #define DEFAULT_RTS_THRESHOLD 2304U
7934 #define MIN_RTS_THRESHOLD 1U
7935 #define MAX_RTS_THRESHOLD 2304U
7936 #define DEFAULT_BEACON_INTERVAL 100U
7937 #define DEFAULT_SHORT_RETRY_LIMIT 7U
7938 #define DEFAULT_LONG_RETRY_LIMIT 4U
7942 * @option: options to control different reset behaviour
7943 * 0 = reset everything except the 'disable' module_param
7944 * 1 = reset everything and print out driver info (for probe only)
7945 * 2 = reset everything
7947 static int ipw_sw_reset(struct ipw_priv *priv, int option)
7949 int band, modulation;
7950 int old_mode = priv->ieee->iw_mode;
7952 /* Initialize module parameter values here */
7955 /* We default to disabling the LED code as right now it causes
7956 * too many systems to lock up... */
7958 priv->config |= CFG_NO_LED;
7961 priv->config |= CFG_ASSOCIATE;
7963 IPW_DEBUG_INFO("Auto associate disabled.\n");
7966 priv->config |= CFG_ADHOC_CREATE;
7968 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
7970 priv->config &= ~CFG_STATIC_ESSID;
7971 priv->essid_len = 0;
7972 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
7974 if (disable && option) {
7975 priv->status |= STATUS_RF_KILL_SW;
7976 IPW_DEBUG_INFO("Radio disabled.\n");
7980 priv->config |= CFG_STATIC_CHANNEL;
7981 priv->channel = channel;
7982 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
7983 /* TODO: Validate that provided channel is in range */
7985 #ifdef CONFIG_IPW_QOS
7986 ipw_qos_init(priv, qos_enable, qos_burst_enable,
7987 burst_duration_CCK, burst_duration_OFDM);
7988 #endif /* CONFIG_IPW_QOS */
7992 priv->ieee->iw_mode = IW_MODE_ADHOC;
7993 priv->net_dev->type = ARPHRD_ETHER;
7996 #ifdef CONFIG_IPW2200_MONITOR
7998 priv->ieee->iw_mode = IW_MODE_MONITOR;
7999 #ifdef CONFIG_IEEE80211_RADIOTAP
8000 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8002 priv->net_dev->type = ARPHRD_IEEE80211;
8008 priv->net_dev->type = ARPHRD_ETHER;
8009 priv->ieee->iw_mode = IW_MODE_INFRA;
8014 priv->ieee->host_encrypt = 0;
8015 priv->ieee->host_encrypt_msdu = 0;
8016 priv->ieee->host_decrypt = 0;
8017 priv->ieee->host_mc_decrypt = 0;
8019 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
8021 /* IPW2200/2915 is abled to do hardware fragmentation. */
8022 priv->ieee->host_open_frag = 0;
8024 if ((priv->pci_dev->device == 0x4223) ||
8025 (priv->pci_dev->device == 0x4224)) {
8027 printk(KERN_INFO DRV_NAME
8028 ": Detected Intel PRO/Wireless 2915ABG Network "
8030 priv->ieee->abg_true = 1;
8031 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8032 modulation = IEEE80211_OFDM_MODULATION |
8033 IEEE80211_CCK_MODULATION;
8034 priv->adapter = IPW_2915ABG;
8035 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
8038 printk(KERN_INFO DRV_NAME
8039 ": Detected Intel PRO/Wireless 2200BG Network "
8042 priv->ieee->abg_true = 0;
8043 band = IEEE80211_24GHZ_BAND;
8044 modulation = IEEE80211_OFDM_MODULATION |
8045 IEEE80211_CCK_MODULATION;
8046 priv->adapter = IPW_2200BG;
8047 priv->ieee->mode = IEEE_G | IEEE_B;
8050 priv->ieee->freq_band = band;
8051 priv->ieee->modulation = modulation;
8053 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
8055 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8056 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8058 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8059 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8060 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
8062 /* If power management is turned on, default to AC mode */
8063 priv->power_mode = IPW_POWER_AC;
8064 priv->tx_power = IPW_TX_POWER_DEFAULT;
8066 return old_mode == priv->ieee->iw_mode;
8070 * This file defines the Wireless Extension handlers. It does not
8071 * define any methods of hardware manipulation and relies on the
8072 * functions defined in ipw_main to provide the HW interaction.
8074 * The exception to this is the use of the ipw_get_ordinal()
8075 * function used to poll the hardware vs. making unecessary calls.
8079 static int ipw_wx_get_name(struct net_device *dev,
8080 struct iw_request_info *info,
8081 union iwreq_data *wrqu, char *extra)
8083 struct ipw_priv *priv = ieee80211_priv(dev);
8084 mutex_lock(&priv->mutex);
8085 if (priv->status & STATUS_RF_KILL_MASK)
8086 strcpy(wrqu->name, "radio off");
8087 else if (!(priv->status & STATUS_ASSOCIATED))
8088 strcpy(wrqu->name, "unassociated");
8090 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8091 ipw_modes[priv->assoc_request.ieee_mode]);
8092 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
8093 mutex_unlock(&priv->mutex);
8097 static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8100 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8101 priv->config &= ~CFG_STATIC_CHANNEL;
8102 IPW_DEBUG_ASSOC("Attempting to associate with new "
8104 ipw_associate(priv);
8108 priv->config |= CFG_STATIC_CHANNEL;
8110 if (priv->channel == channel) {
8111 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8116 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8117 priv->channel = channel;
8119 #ifdef CONFIG_IPW2200_MONITOR
8120 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
8122 if (priv->status & STATUS_SCANNING) {
8123 IPW_DEBUG_SCAN("Scan abort triggered due to "
8124 "channel change.\n");
8125 ipw_abort_scan(priv);
8128 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8131 if (priv->status & STATUS_SCANNING)
8132 IPW_DEBUG_SCAN("Still scanning...\n");
8134 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8139 #endif /* CONFIG_IPW2200_MONITOR */
8141 /* Network configuration changed -- force [re]association */
8142 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8143 if (!ipw_disassociate(priv))
8144 ipw_associate(priv);
8149 static int ipw_wx_set_freq(struct net_device *dev,
8150 struct iw_request_info *info,
8151 union iwreq_data *wrqu, char *extra)
8153 struct ipw_priv *priv = ieee80211_priv(dev);
8154 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
8155 struct iw_freq *fwrq = &wrqu->freq;
8161 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
8162 mutex_lock(&priv->mutex);
8163 ret = ipw_set_channel(priv, 0);
8164 mutex_unlock(&priv->mutex);
8167 /* if setting by freq convert to channel */
8169 channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
8175 if (!(band = ieee80211_is_valid_channel(priv->ieee, channel)))
8178 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
8179 i = ieee80211_channel_to_index(priv->ieee, channel);
8183 flags = (band == IEEE80211_24GHZ_BAND) ?
8184 geo->bg[i].flags : geo->a[i].flags;
8185 if (flags & IEEE80211_CH_PASSIVE_ONLY) {
8186 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8191 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
8192 mutex_lock(&priv->mutex);
8193 ret = ipw_set_channel(priv, channel);
8194 mutex_unlock(&priv->mutex);
8198 static int ipw_wx_get_freq(struct net_device *dev,
8199 struct iw_request_info *info,
8200 union iwreq_data *wrqu, char *extra)
8202 struct ipw_priv *priv = ieee80211_priv(dev);
8206 /* If we are associated, trying to associate, or have a statically
8207 * configured CHANNEL then return that; otherwise return ANY */
8208 mutex_lock(&priv->mutex);
8209 if (priv->config & CFG_STATIC_CHANNEL ||
8210 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8211 wrqu->freq.m = priv->channel;
8215 mutex_unlock(&priv->mutex);
8216 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8220 static int ipw_wx_set_mode(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);
8227 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8229 switch (wrqu->mode) {
8230 #ifdef CONFIG_IPW2200_MONITOR
8231 case IW_MODE_MONITOR:
8237 wrqu->mode = IW_MODE_INFRA;
8242 if (wrqu->mode == priv->ieee->iw_mode)
8245 mutex_lock(&priv->mutex);
8247 ipw_sw_reset(priv, 0);
8249 #ifdef CONFIG_IPW2200_MONITOR
8250 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
8251 priv->net_dev->type = ARPHRD_ETHER;
8253 if (wrqu->mode == IW_MODE_MONITOR)
8254 #ifdef CONFIG_IEEE80211_RADIOTAP
8255 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8257 priv->net_dev->type = ARPHRD_IEEE80211;
8259 #endif /* CONFIG_IPW2200_MONITOR */
8261 /* Free the existing firmware and reset the fw_loaded
8262 * flag so ipw_load() will bring in the new firmawre */
8265 priv->ieee->iw_mode = wrqu->mode;
8267 queue_work(priv->workqueue, &priv->adapter_restart);
8268 mutex_unlock(&priv->mutex);
8272 static int ipw_wx_get_mode(struct net_device *dev,
8273 struct iw_request_info *info,
8274 union iwreq_data *wrqu, char *extra)
8276 struct ipw_priv *priv = ieee80211_priv(dev);
8277 mutex_lock(&priv->mutex);
8278 wrqu->mode = priv->ieee->iw_mode;
8279 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
8280 mutex_unlock(&priv->mutex);
8284 /* Values are in microsecond */
8285 static const s32 timeout_duration[] = {
8293 static const s32 period_duration[] = {
8301 static int ipw_wx_get_range(struct net_device *dev,
8302 struct iw_request_info *info,
8303 union iwreq_data *wrqu, char *extra)
8305 struct ipw_priv *priv = ieee80211_priv(dev);
8306 struct iw_range *range = (struct iw_range *)extra;
8307 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
8310 wrqu->data.length = sizeof(*range);
8311 memset(range, 0, sizeof(*range));
8313 /* 54Mbs == ~27 Mb/s real (802.11g) */
8314 range->throughput = 27 * 1000 * 1000;
8316 range->max_qual.qual = 100;
8317 /* TODO: Find real max RSSI and stick here */
8318 range->max_qual.level = 0;
8319 range->max_qual.noise = 0;
8320 range->max_qual.updated = 7; /* Updated all three */
8322 range->avg_qual.qual = 70;
8323 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
8324 range->avg_qual.level = 0; /* FIXME to real average level */
8325 range->avg_qual.noise = 0;
8326 range->avg_qual.updated = 7; /* Updated all three */
8327 mutex_lock(&priv->mutex);
8328 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
8330 for (i = 0; i < range->num_bitrates; i++)
8331 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
8334 range->max_rts = DEFAULT_RTS_THRESHOLD;
8335 range->min_frag = MIN_FRAG_THRESHOLD;
8336 range->max_frag = MAX_FRAG_THRESHOLD;
8338 range->encoding_size[0] = 5;
8339 range->encoding_size[1] = 13;
8340 range->num_encoding_sizes = 2;
8341 range->max_encoding_tokens = WEP_KEYS;
8343 /* Set the Wireless Extension versions */
8344 range->we_version_compiled = WIRELESS_EXT;
8345 range->we_version_source = 18;
8348 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
8349 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8350 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8351 (geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8354 range->freq[i].i = geo->bg[j].channel;
8355 range->freq[i].m = geo->bg[j].freq * 100000;
8356 range->freq[i].e = 1;
8361 if (priv->ieee->mode & IEEE_A) {
8362 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8363 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8364 (geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8367 range->freq[i].i = geo->a[j].channel;
8368 range->freq[i].m = geo->a[j].freq * 100000;
8369 range->freq[i].e = 1;
8374 range->num_channels = i;
8375 range->num_frequency = i;
8377 mutex_unlock(&priv->mutex);
8379 /* Event capability (kernel + driver) */
8380 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8381 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
8382 IW_EVENT_CAPA_MASK(SIOCGIWAP));
8383 range->event_capa[1] = IW_EVENT_CAPA_K_1;
8385 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8386 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8388 IPW_DEBUG_WX("GET Range\n");
8392 static int ipw_wx_set_wap(struct net_device *dev,
8393 struct iw_request_info *info,
8394 union iwreq_data *wrqu, char *extra)
8396 struct ipw_priv *priv = ieee80211_priv(dev);
8398 static const unsigned char any[] = {
8399 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8401 static const unsigned char off[] = {
8402 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8405 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
8407 mutex_lock(&priv->mutex);
8408 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8409 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8410 /* we disable mandatory BSSID association */
8411 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8412 priv->config &= ~CFG_STATIC_BSSID;
8413 IPW_DEBUG_ASSOC("Attempting to associate with new "
8415 ipw_associate(priv);
8416 mutex_unlock(&priv->mutex);
8420 priv->config |= CFG_STATIC_BSSID;
8421 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8422 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
8423 mutex_unlock(&priv->mutex);
8427 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8428 MAC_ARG(wrqu->ap_addr.sa_data));
8430 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8432 /* Network configuration changed -- force [re]association */
8433 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8434 if (!ipw_disassociate(priv))
8435 ipw_associate(priv);
8437 mutex_unlock(&priv->mutex);
8441 static int ipw_wx_get_wap(struct net_device *dev,
8442 struct iw_request_info *info,
8443 union iwreq_data *wrqu, char *extra)
8445 struct ipw_priv *priv = ieee80211_priv(dev);
8446 /* If we are associated, trying to associate, or have a statically
8447 * configured BSSID then return that; otherwise return ANY */
8448 mutex_lock(&priv->mutex);
8449 if (priv->config & CFG_STATIC_BSSID ||
8450 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8451 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
8452 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
8454 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8456 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8457 MAC_ARG(wrqu->ap_addr.sa_data));
8458 mutex_unlock(&priv->mutex);
8462 static int ipw_wx_set_essid(struct net_device *dev,
8463 struct iw_request_info *info,
8464 union iwreq_data *wrqu, char *extra)
8466 struct ipw_priv *priv = ieee80211_priv(dev);
8467 char *essid = ""; /* ANY */
8469 mutex_lock(&priv->mutex);
8470 if (wrqu->essid.flags && wrqu->essid.length) {
8471 length = wrqu->essid.length - 1;
8475 IPW_DEBUG_WX("Setting ESSID to ANY\n");
8476 if ((priv->config & CFG_STATIC_ESSID) &&
8477 !(priv->status & (STATUS_ASSOCIATED |
8478 STATUS_ASSOCIATING))) {
8479 IPW_DEBUG_ASSOC("Attempting to associate with new "
8481 priv->config &= ~CFG_STATIC_ESSID;
8482 ipw_associate(priv);
8484 mutex_unlock(&priv->mutex);
8488 length = min(length, IW_ESSID_MAX_SIZE);
8490 priv->config |= CFG_STATIC_ESSID;
8492 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8493 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
8494 mutex_unlock(&priv->mutex);
8498 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8501 priv->essid_len = length;
8502 memcpy(priv->essid, essid, priv->essid_len);
8504 /* Network configuration changed -- force [re]association */
8505 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8506 if (!ipw_disassociate(priv))
8507 ipw_associate(priv);
8509 mutex_unlock(&priv->mutex);
8513 static int ipw_wx_get_essid(struct net_device *dev,
8514 struct iw_request_info *info,
8515 union iwreq_data *wrqu, char *extra)
8517 struct ipw_priv *priv = ieee80211_priv(dev);
8519 /* If we are associated, trying to associate, or have a statically
8520 * configured ESSID then return that; otherwise return ANY */
8521 mutex_lock(&priv->mutex);
8522 if (priv->config & CFG_STATIC_ESSID ||
8523 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8524 IPW_DEBUG_WX("Getting essid: '%s'\n",
8525 escape_essid(priv->essid, priv->essid_len));
8526 memcpy(extra, priv->essid, priv->essid_len);
8527 wrqu->essid.length = priv->essid_len;
8528 wrqu->essid.flags = 1; /* active */
8530 IPW_DEBUG_WX("Getting essid: ANY\n");
8531 wrqu->essid.length = 0;
8532 wrqu->essid.flags = 0; /* active */
8534 mutex_unlock(&priv->mutex);
8538 static int ipw_wx_set_nick(struct net_device *dev,
8539 struct iw_request_info *info,
8540 union iwreq_data *wrqu, char *extra)
8542 struct ipw_priv *priv = ieee80211_priv(dev);
8544 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8545 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8547 mutex_lock(&priv->mutex);
8548 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
8549 memset(priv->nick, 0, sizeof(priv->nick));
8550 memcpy(priv->nick, extra, wrqu->data.length);
8551 IPW_DEBUG_TRACE("<<\n");
8552 mutex_unlock(&priv->mutex);
8557 static int ipw_wx_get_nick(struct net_device *dev,
8558 struct iw_request_info *info,
8559 union iwreq_data *wrqu, char *extra)
8561 struct ipw_priv *priv = ieee80211_priv(dev);
8562 IPW_DEBUG_WX("Getting nick\n");
8563 mutex_lock(&priv->mutex);
8564 wrqu->data.length = strlen(priv->nick) + 1;
8565 memcpy(extra, priv->nick, wrqu->data.length);
8566 wrqu->data.flags = 1; /* active */
8567 mutex_unlock(&priv->mutex);
8571 static int ipw_wx_set_sens(struct net_device *dev,
8572 struct iw_request_info *info,
8573 union iwreq_data *wrqu, char *extra)
8575 struct ipw_priv *priv = ieee80211_priv(dev);
8578 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
8579 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
8580 mutex_lock(&priv->mutex);
8582 if (wrqu->sens.fixed == 0)
8584 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8585 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8588 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
8589 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
8594 priv->roaming_threshold = wrqu->sens.value;
8595 priv->disassociate_threshold = 3*wrqu->sens.value;
8597 mutex_unlock(&priv->mutex);
8601 static int ipw_wx_get_sens(struct net_device *dev,
8602 struct iw_request_info *info,
8603 union iwreq_data *wrqu, char *extra)
8605 struct ipw_priv *priv = ieee80211_priv(dev);
8606 mutex_lock(&priv->mutex);
8607 wrqu->sens.fixed = 1;
8608 wrqu->sens.value = priv->roaming_threshold;
8609 mutex_unlock(&priv->mutex);
8611 IPW_DEBUG_WX("GET roaming threshold -> %s %d \n",
8612 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
8617 static int ipw_wx_set_rate(struct net_device *dev,
8618 struct iw_request_info *info,
8619 union iwreq_data *wrqu, char *extra)
8621 /* TODO: We should use semaphores or locks for access to priv */
8622 struct ipw_priv *priv = ieee80211_priv(dev);
8623 u32 target_rate = wrqu->bitrate.value;
8626 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8627 /* value = X, fixed = 1 means only rate X */
8628 /* value = X, fixed = 0 means all rates lower equal X */
8630 if (target_rate == -1) {
8632 mask = IEEE80211_DEFAULT_RATES_MASK;
8633 /* Now we should reassociate */
8638 fixed = wrqu->bitrate.fixed;
8640 if (target_rate == 1000000 || !fixed)
8641 mask |= IEEE80211_CCK_RATE_1MB_MASK;
8642 if (target_rate == 1000000)
8645 if (target_rate == 2000000 || !fixed)
8646 mask |= IEEE80211_CCK_RATE_2MB_MASK;
8647 if (target_rate == 2000000)
8650 if (target_rate == 5500000 || !fixed)
8651 mask |= IEEE80211_CCK_RATE_5MB_MASK;
8652 if (target_rate == 5500000)
8655 if (target_rate == 6000000 || !fixed)
8656 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
8657 if (target_rate == 6000000)
8660 if (target_rate == 9000000 || !fixed)
8661 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
8662 if (target_rate == 9000000)
8665 if (target_rate == 11000000 || !fixed)
8666 mask |= IEEE80211_CCK_RATE_11MB_MASK;
8667 if (target_rate == 11000000)
8670 if (target_rate == 12000000 || !fixed)
8671 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
8672 if (target_rate == 12000000)
8675 if (target_rate == 18000000 || !fixed)
8676 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
8677 if (target_rate == 18000000)
8680 if (target_rate == 24000000 || !fixed)
8681 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
8682 if (target_rate == 24000000)
8685 if (target_rate == 36000000 || !fixed)
8686 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
8687 if (target_rate == 36000000)
8690 if (target_rate == 48000000 || !fixed)
8691 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
8692 if (target_rate == 48000000)
8695 if (target_rate == 54000000 || !fixed)
8696 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
8697 if (target_rate == 54000000)
8700 IPW_DEBUG_WX("invalid rate specified, returning error\n");
8704 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
8705 mask, fixed ? "fixed" : "sub-rates");
8706 mutex_lock(&priv->mutex);
8707 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
8708 priv->config &= ~CFG_FIXED_RATE;
8709 ipw_set_fixed_rate(priv, priv->ieee->mode);
8711 priv->config |= CFG_FIXED_RATE;
8713 if (priv->rates_mask == mask) {
8714 IPW_DEBUG_WX("Mask set to current mask.\n");
8715 mutex_unlock(&priv->mutex);
8719 priv->rates_mask = mask;
8721 /* Network configuration changed -- force [re]association */
8722 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
8723 if (!ipw_disassociate(priv))
8724 ipw_associate(priv);
8726 mutex_unlock(&priv->mutex);
8730 static int ipw_wx_get_rate(struct net_device *dev,
8731 struct iw_request_info *info,
8732 union iwreq_data *wrqu, char *extra)
8734 struct ipw_priv *priv = ieee80211_priv(dev);
8735 mutex_lock(&priv->mutex);
8736 wrqu->bitrate.value = priv->last_rate;
8737 mutex_unlock(&priv->mutex);
8738 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
8742 static int ipw_wx_set_rts(struct net_device *dev,
8743 struct iw_request_info *info,
8744 union iwreq_data *wrqu, char *extra)
8746 struct ipw_priv *priv = ieee80211_priv(dev);
8747 mutex_lock(&priv->mutex);
8748 if (wrqu->rts.disabled)
8749 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8751 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
8752 wrqu->rts.value > MAX_RTS_THRESHOLD) {
8753 mutex_unlock(&priv->mutex);
8756 priv->rts_threshold = wrqu->rts.value;
8759 ipw_send_rts_threshold(priv, priv->rts_threshold);
8760 mutex_unlock(&priv->mutex);
8761 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
8765 static int ipw_wx_get_rts(struct net_device *dev,
8766 struct iw_request_info *info,
8767 union iwreq_data *wrqu, char *extra)
8769 struct ipw_priv *priv = ieee80211_priv(dev);
8770 mutex_lock(&priv->mutex);
8771 wrqu->rts.value = priv->rts_threshold;
8772 wrqu->rts.fixed = 0; /* no auto select */
8773 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
8774 mutex_unlock(&priv->mutex);
8775 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
8779 static int ipw_wx_set_txpow(struct net_device *dev,
8780 struct iw_request_info *info,
8781 union iwreq_data *wrqu, char *extra)
8783 struct ipw_priv *priv = ieee80211_priv(dev);
8786 mutex_lock(&priv->mutex);
8787 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
8792 if (!wrqu->power.fixed)
8793 wrqu->power.value = IPW_TX_POWER_DEFAULT;
8795 if (wrqu->power.flags != IW_TXPOW_DBM) {
8800 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
8801 (wrqu->power.value < IPW_TX_POWER_MIN)) {
8806 priv->tx_power = wrqu->power.value;
8807 err = ipw_set_tx_power(priv);
8809 mutex_unlock(&priv->mutex);
8813 static int ipw_wx_get_txpow(struct net_device *dev,
8814 struct iw_request_info *info,
8815 union iwreq_data *wrqu, char *extra)
8817 struct ipw_priv *priv = ieee80211_priv(dev);
8818 mutex_lock(&priv->mutex);
8819 wrqu->power.value = priv->tx_power;
8820 wrqu->power.fixed = 1;
8821 wrqu->power.flags = IW_TXPOW_DBM;
8822 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
8823 mutex_unlock(&priv->mutex);
8825 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
8826 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
8831 static int ipw_wx_set_frag(struct net_device *dev,
8832 struct iw_request_info *info,
8833 union iwreq_data *wrqu, char *extra)
8835 struct ipw_priv *priv = ieee80211_priv(dev);
8836 mutex_lock(&priv->mutex);
8837 if (wrqu->frag.disabled)
8838 priv->ieee->fts = DEFAULT_FTS;
8840 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
8841 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
8842 mutex_unlock(&priv->mutex);
8846 priv->ieee->fts = wrqu->frag.value & ~0x1;
8849 ipw_send_frag_threshold(priv, wrqu->frag.value);
8850 mutex_unlock(&priv->mutex);
8851 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
8855 static int ipw_wx_get_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 wrqu->frag.value = priv->ieee->fts;
8862 wrqu->frag.fixed = 0; /* no auto select */
8863 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
8864 mutex_unlock(&priv->mutex);
8865 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
8870 static int ipw_wx_set_retry(struct net_device *dev,
8871 struct iw_request_info *info,
8872 union iwreq_data *wrqu, char *extra)
8874 struct ipw_priv *priv = ieee80211_priv(dev);
8876 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
8879 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
8882 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
8885 mutex_lock(&priv->mutex);
8886 if (wrqu->retry.flags & IW_RETRY_MIN)
8887 priv->short_retry_limit = (u8) wrqu->retry.value;
8888 else if (wrqu->retry.flags & IW_RETRY_MAX)
8889 priv->long_retry_limit = (u8) wrqu->retry.value;
8891 priv->short_retry_limit = (u8) wrqu->retry.value;
8892 priv->long_retry_limit = (u8) wrqu->retry.value;
8895 ipw_send_retry_limit(priv, priv->short_retry_limit,
8896 priv->long_retry_limit);
8897 mutex_unlock(&priv->mutex);
8898 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
8899 priv->short_retry_limit, priv->long_retry_limit);
8903 static int ipw_wx_get_retry(struct net_device *dev,
8904 struct iw_request_info *info,
8905 union iwreq_data *wrqu, char *extra)
8907 struct ipw_priv *priv = ieee80211_priv(dev);
8909 mutex_lock(&priv->mutex);
8910 wrqu->retry.disabled = 0;
8912 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
8913 mutex_unlock(&priv->mutex);
8917 if (wrqu->retry.flags & IW_RETRY_MAX) {
8918 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
8919 wrqu->retry.value = priv->long_retry_limit;
8920 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
8921 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
8922 wrqu->retry.value = priv->short_retry_limit;
8924 wrqu->retry.flags = IW_RETRY_LIMIT;
8925 wrqu->retry.value = priv->short_retry_limit;
8927 mutex_unlock(&priv->mutex);
8929 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
8934 static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
8937 struct ipw_scan_request_ext scan;
8938 int err = 0, scan_type;
8940 if (!(priv->status & STATUS_INIT) ||
8941 (priv->status & STATUS_EXIT_PENDING))
8944 mutex_lock(&priv->mutex);
8946 if (priv->status & STATUS_RF_KILL_MASK) {
8947 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
8948 priv->status |= STATUS_SCAN_PENDING;
8952 IPW_DEBUG_HC("starting request direct scan!\n");
8954 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
8955 /* We should not sleep here; otherwise we will block most
8956 * of the system (for instance, we hold rtnl_lock when we
8962 memset(&scan, 0, sizeof(scan));
8964 if (priv->config & CFG_SPEED_SCAN)
8965 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
8968 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
8971 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
8973 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
8974 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
8976 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
8978 err = ipw_send_ssid(priv, essid, essid_len);
8980 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
8983 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
8985 ipw_add_scan_channels(priv, &scan, scan_type);
8987 err = ipw_send_scan_request_ext(priv, &scan);
8989 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
8993 priv->status |= STATUS_SCANNING;
8996 mutex_unlock(&priv->mutex);
9000 static int ipw_wx_set_scan(struct net_device *dev,
9001 struct iw_request_info *info,
9002 union iwreq_data *wrqu, char *extra)
9004 struct ipw_priv *priv = ieee80211_priv(dev);
9005 struct iw_scan_req *req = NULL;
9006 if (wrqu->data.length
9007 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9008 req = (struct iw_scan_req *)extra;
9009 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9010 ipw_request_direct_scan(priv, req->essid,
9016 IPW_DEBUG_WX("Start scan\n");
9018 queue_work(priv->workqueue, &priv->request_scan);
9023 static int ipw_wx_get_scan(struct net_device *dev,
9024 struct iw_request_info *info,
9025 union iwreq_data *wrqu, char *extra)
9027 struct ipw_priv *priv = ieee80211_priv(dev);
9028 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9031 static int ipw_wx_set_encode(struct net_device *dev,
9032 struct iw_request_info *info,
9033 union iwreq_data *wrqu, char *key)
9035 struct ipw_priv *priv = ieee80211_priv(dev);
9037 u32 cap = priv->capability;
9039 mutex_lock(&priv->mutex);
9040 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
9042 /* In IBSS mode, we need to notify the firmware to update
9043 * the beacon info after we changed the capability. */
9044 if (cap != priv->capability &&
9045 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9046 priv->status & STATUS_ASSOCIATED)
9047 ipw_disassociate(priv);
9049 mutex_unlock(&priv->mutex);
9053 static int ipw_wx_get_encode(struct net_device *dev,
9054 struct iw_request_info *info,
9055 union iwreq_data *wrqu, char *key)
9057 struct ipw_priv *priv = ieee80211_priv(dev);
9058 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9061 static int ipw_wx_set_power(struct net_device *dev,
9062 struct iw_request_info *info,
9063 union iwreq_data *wrqu, char *extra)
9065 struct ipw_priv *priv = ieee80211_priv(dev);
9067 mutex_lock(&priv->mutex);
9068 if (wrqu->power.disabled) {
9069 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9070 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9072 IPW_DEBUG_WX("failed setting power mode.\n");
9073 mutex_unlock(&priv->mutex);
9076 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
9077 mutex_unlock(&priv->mutex);
9081 switch (wrqu->power.flags & IW_POWER_MODE) {
9082 case IW_POWER_ON: /* If not specified */
9083 case IW_POWER_MODE: /* If set all mask */
9084 case IW_POWER_ALL_R: /* If explicitely state all */
9086 default: /* Otherwise we don't support it */
9087 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9089 mutex_unlock(&priv->mutex);
9093 /* If the user hasn't specified a power management mode yet, default
9095 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
9096 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
9098 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9099 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9101 IPW_DEBUG_WX("failed setting power mode.\n");
9102 mutex_unlock(&priv->mutex);
9106 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
9107 mutex_unlock(&priv->mutex);
9111 static int ipw_wx_get_power(struct net_device *dev,
9112 struct iw_request_info *info,
9113 union iwreq_data *wrqu, char *extra)
9115 struct ipw_priv *priv = ieee80211_priv(dev);
9116 mutex_lock(&priv->mutex);
9117 if (!(priv->power_mode & IPW_POWER_ENABLED))
9118 wrqu->power.disabled = 1;
9120 wrqu->power.disabled = 0;
9122 mutex_unlock(&priv->mutex);
9123 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
9128 static int ipw_wx_set_powermode(struct net_device *dev,
9129 struct iw_request_info *info,
9130 union iwreq_data *wrqu, char *extra)
9132 struct ipw_priv *priv = ieee80211_priv(dev);
9133 int mode = *(int *)extra;
9135 mutex_lock(&priv->mutex);
9136 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9137 mode = IPW_POWER_AC;
9138 priv->power_mode = mode;
9140 priv->power_mode = IPW_POWER_ENABLED | mode;
9143 if (priv->power_mode != mode) {
9144 err = ipw_send_power_mode(priv, mode);
9147 IPW_DEBUG_WX("failed setting power mode.\n");
9148 mutex_unlock(&priv->mutex);
9152 mutex_unlock(&priv->mutex);
9156 #define MAX_WX_STRING 80
9157 static int ipw_wx_get_powermode(struct net_device *dev,
9158 struct iw_request_info *info,
9159 union iwreq_data *wrqu, char *extra)
9161 struct ipw_priv *priv = ieee80211_priv(dev);
9162 int level = IPW_POWER_LEVEL(priv->power_mode);
9165 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9169 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9171 case IPW_POWER_BATTERY:
9172 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9175 p += snprintf(p, MAX_WX_STRING - (p - extra),
9176 "(Timeout %dms, Period %dms)",
9177 timeout_duration[level - 1] / 1000,
9178 period_duration[level - 1] / 1000);
9181 if (!(priv->power_mode & IPW_POWER_ENABLED))
9182 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
9184 wrqu->data.length = p - extra + 1;
9189 static int ipw_wx_set_wireless_mode(struct net_device *dev,
9190 struct iw_request_info *info,
9191 union iwreq_data *wrqu, char *extra)
9193 struct ipw_priv *priv = ieee80211_priv(dev);
9194 int mode = *(int *)extra;
9195 u8 band = 0, modulation = 0;
9197 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
9198 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
9201 mutex_lock(&priv->mutex);
9202 if (priv->adapter == IPW_2915ABG) {
9203 priv->ieee->abg_true = 1;
9204 if (mode & IEEE_A) {
9205 band |= IEEE80211_52GHZ_BAND;
9206 modulation |= IEEE80211_OFDM_MODULATION;
9208 priv->ieee->abg_true = 0;
9210 if (mode & IEEE_A) {
9211 IPW_WARNING("Attempt to set 2200BG into "
9213 mutex_unlock(&priv->mutex);
9217 priv->ieee->abg_true = 0;
9220 if (mode & IEEE_B) {
9221 band |= IEEE80211_24GHZ_BAND;
9222 modulation |= IEEE80211_CCK_MODULATION;
9224 priv->ieee->abg_true = 0;
9226 if (mode & IEEE_G) {
9227 band |= IEEE80211_24GHZ_BAND;
9228 modulation |= IEEE80211_OFDM_MODULATION;
9230 priv->ieee->abg_true = 0;
9232 priv->ieee->mode = mode;
9233 priv->ieee->freq_band = band;
9234 priv->ieee->modulation = modulation;
9235 init_supported_rates(priv, &priv->rates);
9237 /* Network configuration changed -- force [re]association */
9238 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9239 if (!ipw_disassociate(priv)) {
9240 ipw_send_supported_rates(priv, &priv->rates);
9241 ipw_associate(priv);
9244 /* Update the band LEDs */
9245 ipw_led_band_on(priv);
9247 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
9248 mode & IEEE_A ? 'a' : '.',
9249 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
9250 mutex_unlock(&priv->mutex);
9254 static int ipw_wx_get_wireless_mode(struct net_device *dev,
9255 struct iw_request_info *info,
9256 union iwreq_data *wrqu, char *extra)
9258 struct ipw_priv *priv = ieee80211_priv(dev);
9259 mutex_lock(&priv->mutex);
9260 switch (priv->ieee->mode) {
9262 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9265 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9267 case IEEE_A | IEEE_B:
9268 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9271 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9273 case IEEE_A | IEEE_G:
9274 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9276 case IEEE_B | IEEE_G:
9277 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9279 case IEEE_A | IEEE_B | IEEE_G:
9280 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9283 strncpy(extra, "unknown", MAX_WX_STRING);
9287 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9289 wrqu->data.length = strlen(extra) + 1;
9290 mutex_unlock(&priv->mutex);
9295 static int ipw_wx_set_preamble(struct net_device *dev,
9296 struct iw_request_info *info,
9297 union iwreq_data *wrqu, char *extra)
9299 struct ipw_priv *priv = ieee80211_priv(dev);
9300 int mode = *(int *)extra;
9301 mutex_lock(&priv->mutex);
9302 /* Switching from SHORT -> LONG requires a disassociation */
9304 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9305 priv->config |= CFG_PREAMBLE_LONG;
9307 /* Network configuration changed -- force [re]association */
9309 ("[re]association triggered due to preamble change.\n");
9310 if (!ipw_disassociate(priv))
9311 ipw_associate(priv);
9317 priv->config &= ~CFG_PREAMBLE_LONG;
9320 mutex_unlock(&priv->mutex);
9324 mutex_unlock(&priv->mutex);
9328 static int ipw_wx_get_preamble(struct net_device *dev,
9329 struct iw_request_info *info,
9330 union iwreq_data *wrqu, char *extra)
9332 struct ipw_priv *priv = ieee80211_priv(dev);
9333 mutex_lock(&priv->mutex);
9334 if (priv->config & CFG_PREAMBLE_LONG)
9335 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9337 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
9338 mutex_unlock(&priv->mutex);
9342 #ifdef CONFIG_IPW2200_MONITOR
9343 static int ipw_wx_set_monitor(struct net_device *dev,
9344 struct iw_request_info *info,
9345 union iwreq_data *wrqu, char *extra)
9347 struct ipw_priv *priv = ieee80211_priv(dev);
9348 int *parms = (int *)extra;
9349 int enable = (parms[0] > 0);
9350 mutex_lock(&priv->mutex);
9351 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
9353 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9354 #ifdef CONFIG_IEEE80211_RADIOTAP
9355 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9357 priv->net_dev->type = ARPHRD_IEEE80211;
9359 queue_work(priv->workqueue, &priv->adapter_restart);
9362 ipw_set_channel(priv, parms[1]);
9364 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9365 mutex_unlock(&priv->mutex);
9368 priv->net_dev->type = ARPHRD_ETHER;
9369 queue_work(priv->workqueue, &priv->adapter_restart);
9371 mutex_unlock(&priv->mutex);
9375 #endif // CONFIG_IPW2200_MONITOR
9377 static int ipw_wx_reset(struct net_device *dev,
9378 struct iw_request_info *info,
9379 union iwreq_data *wrqu, char *extra)
9381 struct ipw_priv *priv = ieee80211_priv(dev);
9382 IPW_DEBUG_WX("RESET\n");
9383 queue_work(priv->workqueue, &priv->adapter_restart);
9387 static int ipw_wx_sw_reset(struct net_device *dev,
9388 struct iw_request_info *info,
9389 union iwreq_data *wrqu, char *extra)
9391 struct ipw_priv *priv = ieee80211_priv(dev);
9392 union iwreq_data wrqu_sec = {
9394 .flags = IW_ENCODE_DISABLED,
9399 IPW_DEBUG_WX("SW_RESET\n");
9401 mutex_lock(&priv->mutex);
9403 ret = ipw_sw_reset(priv, 2);
9406 ipw_adapter_restart(priv);
9409 /* The SW reset bit might have been toggled on by the 'disable'
9410 * module parameter, so take appropriate action */
9411 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9413 mutex_unlock(&priv->mutex);
9414 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
9415 mutex_lock(&priv->mutex);
9417 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9418 /* Configuration likely changed -- force [re]association */
9419 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9421 if (!ipw_disassociate(priv))
9422 ipw_associate(priv);
9425 mutex_unlock(&priv->mutex);
9430 /* Rebase the WE IOCTLs to zero for the handler array */
9431 #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
9432 static iw_handler ipw_wx_handlers[] = {
9433 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9434 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9435 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9436 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9437 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
9438 IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens,
9439 IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens,
9440 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9441 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9442 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9443 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9444 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9445 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9446 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9447 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9448 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9449 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9450 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9451 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9452 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9453 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9454 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9455 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9456 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9457 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9458 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9459 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9460 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9461 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9462 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
9463 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9464 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9465 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9466 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
9467 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9468 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9469 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9470 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9471 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9472 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9473 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
9477 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9481 IPW_PRIV_SET_PREAMBLE,
9482 IPW_PRIV_GET_PREAMBLE,
9485 #ifdef CONFIG_IPW2200_MONITOR
9486 IPW_PRIV_SET_MONITOR,
9490 static struct iw_priv_args ipw_priv_args[] = {
9492 .cmd = IPW_PRIV_SET_POWER,
9493 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9494 .name = "set_power"},
9496 .cmd = IPW_PRIV_GET_POWER,
9497 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9498 .name = "get_power"},
9500 .cmd = IPW_PRIV_SET_MODE,
9501 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9502 .name = "set_mode"},
9504 .cmd = IPW_PRIV_GET_MODE,
9505 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9506 .name = "get_mode"},
9508 .cmd = IPW_PRIV_SET_PREAMBLE,
9509 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9510 .name = "set_preamble"},
9512 .cmd = IPW_PRIV_GET_PREAMBLE,
9513 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9514 .name = "get_preamble"},
9517 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
9520 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9521 #ifdef CONFIG_IPW2200_MONITOR
9523 IPW_PRIV_SET_MONITOR,
9524 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9525 #endif /* CONFIG_IPW2200_MONITOR */
9528 static iw_handler ipw_priv_handler[] = {
9529 ipw_wx_set_powermode,
9530 ipw_wx_get_powermode,
9531 ipw_wx_set_wireless_mode,
9532 ipw_wx_get_wireless_mode,
9533 ipw_wx_set_preamble,
9534 ipw_wx_get_preamble,
9537 #ifdef CONFIG_IPW2200_MONITOR
9542 static struct iw_handler_def ipw_wx_handler_def = {
9543 .standard = ipw_wx_handlers,
9544 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9545 .num_private = ARRAY_SIZE(ipw_priv_handler),
9546 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9547 .private = ipw_priv_handler,
9548 .private_args = ipw_priv_args,
9549 .get_wireless_stats = ipw_get_wireless_stats,
9553 * Get wireless statistics.
9554 * Called by /proc/net/wireless
9555 * Also called by SIOCGIWSTATS
9557 static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
9559 struct ipw_priv *priv = ieee80211_priv(dev);
9560 struct iw_statistics *wstats;
9562 wstats = &priv->wstats;
9564 /* if hw is disabled, then ipw_get_ordinal() can't be called.
9565 * netdev->get_wireless_stats seems to be called before fw is
9566 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9567 * and associated; if not associcated, the values are all meaningless
9568 * anyway, so set them all to NULL and INVALID */
9569 if (!(priv->status & STATUS_ASSOCIATED)) {
9570 wstats->miss.beacon = 0;
9571 wstats->discard.retries = 0;
9572 wstats->qual.qual = 0;
9573 wstats->qual.level = 0;
9574 wstats->qual.noise = 0;
9575 wstats->qual.updated = 7;
9576 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
9577 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
9581 wstats->qual.qual = priv->quality;
9582 wstats->qual.level = average_value(&priv->average_rssi);
9583 wstats->qual.noise = average_value(&priv->average_noise);
9584 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
9585 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
9587 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9588 wstats->discard.retries = priv->last_tx_failures;
9589 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
9591 /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9592 goto fail_get_ordinal;
9593 wstats->discard.retries += tx_retry; */
9598 /* net device stuff */
9600 static void init_sys_config(struct ipw_sys_config *sys_config)
9602 memset(sys_config, 0, sizeof(struct ipw_sys_config));
9603 sys_config->bt_coexistence = 0;
9604 sys_config->answer_broadcast_ssid_probe = 0;
9605 sys_config->accept_all_data_frames = 0;
9606 sys_config->accept_non_directed_frames = 1;
9607 sys_config->exclude_unicast_unencrypted = 0;
9608 sys_config->disable_unicast_decryption = 1;
9609 sys_config->exclude_multicast_unencrypted = 0;
9610 sys_config->disable_multicast_decryption = 1;
9611 sys_config->antenna_diversity = CFG_SYS_ANTENNA_SLOW_DIV;
9612 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
9613 sys_config->dot11g_auto_detection = 0;
9614 sys_config->enable_cts_to_self = 0;
9615 sys_config->bt_coexist_collision_thr = 0;
9616 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
9617 sys_config->silence_threshold = 0x1e;
9620 static int ipw_net_open(struct net_device *dev)
9622 struct ipw_priv *priv = ieee80211_priv(dev);
9623 IPW_DEBUG_INFO("dev->open\n");
9624 /* we should be verifying the device is ready to be opened */
9625 mutex_lock(&priv->mutex);
9626 if (!(priv->status & STATUS_RF_KILL_MASK) &&
9627 (priv->status & STATUS_ASSOCIATED))
9628 netif_start_queue(dev);
9629 mutex_unlock(&priv->mutex);
9633 static int ipw_net_stop(struct net_device *dev)
9635 IPW_DEBUG_INFO("dev->close\n");
9636 netif_stop_queue(dev);
9643 modify to send one tfd per fragment instead of using chunking. otherwise
9644 we need to heavily modify the ieee80211_skb_to_txb.
9647 static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
9650 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
9651 txb->fragments[0]->data;
9653 struct tfd_frame *tfd;
9654 #ifdef CONFIG_IPW_QOS
9655 int tx_id = ipw_get_tx_queue_number(priv, pri);
9656 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9658 struct clx2_tx_queue *txq = &priv->txq[0];
9660 struct clx2_queue *q = &txq->q;
9661 u8 id, hdr_len, unicast;
9662 u16 remaining_bytes;
9665 switch (priv->ieee->iw_mode) {
9667 hdr_len = IEEE80211_3ADDR_LEN;
9668 unicast = !is_multicast_ether_addr(hdr->addr1);
9669 id = ipw_find_station(priv, hdr->addr1);
9670 if (id == IPW_INVALID_STATION) {
9671 id = ipw_add_station(priv, hdr->addr1);
9672 if (id == IPW_INVALID_STATION) {
9673 IPW_WARNING("Attempt to send data to "
9674 "invalid cell: " MAC_FMT "\n",
9675 MAC_ARG(hdr->addr1));
9683 unicast = !is_multicast_ether_addr(hdr->addr3);
9684 hdr_len = IEEE80211_3ADDR_LEN;
9689 tfd = &txq->bd[q->first_empty];
9690 txq->txb[q->first_empty] = txb;
9691 memset(tfd, 0, sizeof(*tfd));
9692 tfd->u.data.station_number = id;
9694 tfd->control_flags.message_type = TX_FRAME_TYPE;
9695 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
9697 tfd->u.data.cmd_id = DINO_CMD_TX;
9698 tfd->u.data.len = cpu_to_le16(txb->payload_size);
9699 remaining_bytes = txb->payload_size;
9701 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
9702 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
9704 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
9706 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
9707 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
9709 fc = le16_to_cpu(hdr->frame_ctl);
9710 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
9712 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
9714 if (likely(unicast))
9715 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9717 if (txb->encrypted && !priv->ieee->host_encrypt) {
9718 switch (priv->ieee->sec.level) {
9720 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9721 IEEE80211_FCTL_PROTECTED;
9722 /* XXX: ACK flag must be set for CCMP even if it
9723 * is a multicast/broadcast packet, because CCMP
9724 * group communication encrypted by GTK is
9725 * actually done by the AP. */
9727 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9729 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9730 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
9731 tfd->u.data.key_index = 0;
9732 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
9735 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9736 IEEE80211_FCTL_PROTECTED;
9737 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9738 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
9739 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
9742 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9743 IEEE80211_FCTL_PROTECTED;
9744 tfd->u.data.key_index = priv->ieee->tx_keyidx;
9745 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
9747 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
9749 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
9754 printk(KERN_ERR "Unknow security level %d\n",
9755 priv->ieee->sec.level);
9759 /* No hardware encryption */
9760 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
9762 #ifdef CONFIG_IPW_QOS
9763 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast);
9764 #endif /* CONFIG_IPW_QOS */
9767 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
9769 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
9770 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
9771 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
9772 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
9773 i, le32_to_cpu(tfd->u.data.num_chunks),
9774 txb->fragments[i]->len - hdr_len);
9775 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
9776 i, tfd->u.data.num_chunks,
9777 txb->fragments[i]->len - hdr_len);
9778 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
9779 txb->fragments[i]->len - hdr_len);
9781 tfd->u.data.chunk_ptr[i] =
9782 cpu_to_le32(pci_map_single
9784 txb->fragments[i]->data + hdr_len,
9785 txb->fragments[i]->len - hdr_len,
9787 tfd->u.data.chunk_len[i] =
9788 cpu_to_le16(txb->fragments[i]->len - hdr_len);
9791 if (i != txb->nr_frags) {
9792 struct sk_buff *skb;
9793 u16 remaining_bytes = 0;
9796 for (j = i; j < txb->nr_frags; j++)
9797 remaining_bytes += txb->fragments[j]->len - hdr_len;
9799 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
9801 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
9803 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
9804 for (j = i; j < txb->nr_frags; j++) {
9805 int size = txb->fragments[j]->len - hdr_len;
9807 printk(KERN_INFO "Adding frag %d %d...\n",
9809 memcpy(skb_put(skb, size),
9810 txb->fragments[j]->data + hdr_len, size);
9812 dev_kfree_skb_any(txb->fragments[i]);
9813 txb->fragments[i] = skb;
9814 tfd->u.data.chunk_ptr[i] =
9815 cpu_to_le32(pci_map_single
9816 (priv->pci_dev, skb->data,
9817 tfd->u.data.chunk_len[i],
9820 tfd->u.data.num_chunks =
9821 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
9827 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
9828 ipw_write32(priv, q->reg_w, q->first_empty);
9830 if (ipw_queue_space(q) < q->high_mark)
9831 netif_stop_queue(priv->net_dev);
9833 return NETDEV_TX_OK;
9836 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
9837 ieee80211_txb_free(txb);
9838 return NETDEV_TX_OK;
9841 static int ipw_net_is_queue_full(struct net_device *dev, int pri)
9843 struct ipw_priv *priv = ieee80211_priv(dev);
9844 #ifdef CONFIG_IPW_QOS
9845 int tx_id = ipw_get_tx_queue_number(priv, pri);
9846 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9848 struct clx2_tx_queue *txq = &priv->txq[0];
9849 #endif /* CONFIG_IPW_QOS */
9851 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
9857 static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
9858 struct net_device *dev, int pri)
9860 struct ipw_priv *priv = ieee80211_priv(dev);
9861 unsigned long flags;
9864 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
9865 spin_lock_irqsave(&priv->lock, flags);
9867 if (!(priv->status & STATUS_ASSOCIATED)) {
9868 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
9869 priv->ieee->stats.tx_carrier_errors++;
9870 netif_stop_queue(dev);
9874 ret = ipw_tx_skb(priv, txb, pri);
9875 if (ret == NETDEV_TX_OK)
9876 __ipw_led_activity_on(priv);
9877 spin_unlock_irqrestore(&priv->lock, flags);
9882 spin_unlock_irqrestore(&priv->lock, flags);
9886 static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
9888 struct ipw_priv *priv = ieee80211_priv(dev);
9890 priv->ieee->stats.tx_packets = priv->tx_packets;
9891 priv->ieee->stats.rx_packets = priv->rx_packets;
9892 return &priv->ieee->stats;
9895 static void ipw_net_set_multicast_list(struct net_device *dev)
9900 static int ipw_net_set_mac_address(struct net_device *dev, void *p)
9902 struct ipw_priv *priv = ieee80211_priv(dev);
9903 struct sockaddr *addr = p;
9904 if (!is_valid_ether_addr(addr->sa_data))
9905 return -EADDRNOTAVAIL;
9906 mutex_lock(&priv->mutex);
9907 priv->config |= CFG_CUSTOM_MAC;
9908 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
9909 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
9910 priv->net_dev->name, MAC_ARG(priv->mac_addr));
9911 queue_work(priv->workqueue, &priv->adapter_restart);
9912 mutex_unlock(&priv->mutex);
9916 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
9917 struct ethtool_drvinfo *info)
9919 struct ipw_priv *p = ieee80211_priv(dev);
9924 strcpy(info->driver, DRV_NAME);
9925 strcpy(info->version, DRV_VERSION);
9928 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
9930 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
9932 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
9934 strcpy(info->bus_info, pci_name(p->pci_dev));
9935 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
9938 static u32 ipw_ethtool_get_link(struct net_device *dev)
9940 struct ipw_priv *priv = ieee80211_priv(dev);
9941 return (priv->status & STATUS_ASSOCIATED) != 0;
9944 static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
9946 return IPW_EEPROM_IMAGE_SIZE;
9949 static int ipw_ethtool_get_eeprom(struct net_device *dev,
9950 struct ethtool_eeprom *eeprom, u8 * bytes)
9952 struct ipw_priv *p = ieee80211_priv(dev);
9954 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
9956 mutex_lock(&p->mutex);
9957 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
9958 mutex_unlock(&p->mutex);
9962 static int ipw_ethtool_set_eeprom(struct net_device *dev,
9963 struct ethtool_eeprom *eeprom, u8 * bytes)
9965 struct ipw_priv *p = ieee80211_priv(dev);
9968 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
9970 mutex_lock(&p->mutex);
9971 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
9972 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
9973 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
9974 mutex_unlock(&p->mutex);
9978 static struct ethtool_ops ipw_ethtool_ops = {
9979 .get_link = ipw_ethtool_get_link,
9980 .get_drvinfo = ipw_ethtool_get_drvinfo,
9981 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
9982 .get_eeprom = ipw_ethtool_get_eeprom,
9983 .set_eeprom = ipw_ethtool_set_eeprom,
9986 static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
9988 struct ipw_priv *priv = data;
9989 u32 inta, inta_mask;
9994 spin_lock(&priv->lock);
9996 if (!(priv->status & STATUS_INT_ENABLED)) {
10001 inta = ipw_read32(priv, IPW_INTA_RW);
10002 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
10004 if (inta == 0xFFFFFFFF) {
10005 /* Hardware disappeared */
10006 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10010 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
10011 /* Shared interrupt */
10015 /* tell the device to stop sending interrupts */
10016 ipw_disable_interrupts(priv);
10018 /* ack current interrupts */
10019 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10020 ipw_write32(priv, IPW_INTA_RW, inta);
10022 /* Cache INTA value for our tasklet */
10023 priv->isr_inta = inta;
10025 tasklet_schedule(&priv->irq_tasklet);
10027 spin_unlock(&priv->lock);
10029 return IRQ_HANDLED;
10031 spin_unlock(&priv->lock);
10035 static void ipw_rf_kill(void *adapter)
10037 struct ipw_priv *priv = adapter;
10038 unsigned long flags;
10040 spin_lock_irqsave(&priv->lock, flags);
10042 if (rf_kill_active(priv)) {
10043 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10044 if (priv->workqueue)
10045 queue_delayed_work(priv->workqueue,
10046 &priv->rf_kill, 2 * HZ);
10050 /* RF Kill is now disabled, so bring the device back up */
10052 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10053 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10056 /* we can not do an adapter restart while inside an irq lock */
10057 queue_work(priv->workqueue, &priv->adapter_restart);
10059 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10063 spin_unlock_irqrestore(&priv->lock, flags);
10066 static void ipw_bg_rf_kill(void *data)
10068 struct ipw_priv *priv = data;
10069 mutex_lock(&priv->mutex);
10071 mutex_unlock(&priv->mutex);
10074 static void ipw_link_up(struct ipw_priv *priv)
10076 priv->last_seq_num = -1;
10077 priv->last_frag_num = -1;
10078 priv->last_packet_time = 0;
10080 netif_carrier_on(priv->net_dev);
10081 if (netif_queue_stopped(priv->net_dev)) {
10082 IPW_DEBUG_NOTIF("waking queue\n");
10083 netif_wake_queue(priv->net_dev);
10085 IPW_DEBUG_NOTIF("starting queue\n");
10086 netif_start_queue(priv->net_dev);
10089 cancel_delayed_work(&priv->request_scan);
10090 ipw_reset_stats(priv);
10091 /* Ensure the rate is updated immediately */
10092 priv->last_rate = ipw_get_current_rate(priv);
10093 ipw_gather_stats(priv);
10094 ipw_led_link_up(priv);
10095 notify_wx_assoc_event(priv);
10097 if (priv->config & CFG_BACKGROUND_SCAN)
10098 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10101 static void ipw_bg_link_up(void *data)
10103 struct ipw_priv *priv = data;
10104 mutex_lock(&priv->mutex);
10106 mutex_unlock(&priv->mutex);
10109 static void ipw_link_down(struct ipw_priv *priv)
10111 ipw_led_link_down(priv);
10112 netif_carrier_off(priv->net_dev);
10113 netif_stop_queue(priv->net_dev);
10114 notify_wx_assoc_event(priv);
10116 /* Cancel any queued work ... */
10117 cancel_delayed_work(&priv->request_scan);
10118 cancel_delayed_work(&priv->adhoc_check);
10119 cancel_delayed_work(&priv->gather_stats);
10121 ipw_reset_stats(priv);
10123 if (!(priv->status & STATUS_EXIT_PENDING)) {
10124 /* Queue up another scan... */
10125 queue_work(priv->workqueue, &priv->request_scan);
10129 static void ipw_bg_link_down(void *data)
10131 struct ipw_priv *priv = data;
10132 mutex_lock(&priv->mutex);
10133 ipw_link_down(data);
10134 mutex_unlock(&priv->mutex);
10137 static int ipw_setup_deferred_work(struct ipw_priv *priv)
10141 priv->workqueue = create_workqueue(DRV_NAME);
10142 init_waitqueue_head(&priv->wait_command_queue);
10143 init_waitqueue_head(&priv->wait_state);
10145 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10146 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10147 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
10148 INIT_WORK(&priv->system_config, ipw_system_config, priv);
10149 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10150 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10151 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10152 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10153 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
10154 INIT_WORK(&priv->request_scan,
10155 (void (*)(void *))ipw_request_scan, priv);
10156 INIT_WORK(&priv->gather_stats,
10157 (void (*)(void *))ipw_bg_gather_stats, priv);
10158 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10159 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10160 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10161 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10162 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10163 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
10165 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
10167 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10169 INIT_WORK(&priv->merge_networks,
10170 (void (*)(void *))ipw_merge_adhoc_network, priv);
10172 #ifdef CONFIG_IPW_QOS
10173 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10175 #endif /* CONFIG_IPW_QOS */
10177 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10178 ipw_irq_tasklet, (unsigned long)priv);
10183 static void shim__set_security(struct net_device *dev,
10184 struct ieee80211_security *sec)
10186 struct ipw_priv *priv = ieee80211_priv(dev);
10188 for (i = 0; i < 4; i++) {
10189 if (sec->flags & (1 << i)) {
10190 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
10191 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
10192 if (sec->key_sizes[i] == 0)
10193 priv->ieee->sec.flags &= ~(1 << i);
10195 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
10196 sec->key_sizes[i]);
10197 priv->ieee->sec.flags |= (1 << i);
10199 priv->status |= STATUS_SECURITY_UPDATED;
10200 } else if (sec->level != SEC_LEVEL_1)
10201 priv->ieee->sec.flags &= ~(1 << i);
10204 if (sec->flags & SEC_ACTIVE_KEY) {
10205 if (sec->active_key <= 3) {
10206 priv->ieee->sec.active_key = sec->active_key;
10207 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
10209 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
10210 priv->status |= STATUS_SECURITY_UPDATED;
10212 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
10214 if ((sec->flags & SEC_AUTH_MODE) &&
10215 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10216 priv->ieee->sec.auth_mode = sec->auth_mode;
10217 priv->ieee->sec.flags |= SEC_AUTH_MODE;
10218 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10219 priv->capability |= CAP_SHARED_KEY;
10221 priv->capability &= ~CAP_SHARED_KEY;
10222 priv->status |= STATUS_SECURITY_UPDATED;
10225 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10226 priv->ieee->sec.flags |= SEC_ENABLED;
10227 priv->ieee->sec.enabled = sec->enabled;
10228 priv->status |= STATUS_SECURITY_UPDATED;
10230 priv->capability |= CAP_PRIVACY_ON;
10232 priv->capability &= ~CAP_PRIVACY_ON;
10235 if (sec->flags & SEC_ENCRYPT)
10236 priv->ieee->sec.encrypt = sec->encrypt;
10238 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10239 priv->ieee->sec.level = sec->level;
10240 priv->ieee->sec.flags |= SEC_LEVEL;
10241 priv->status |= STATUS_SECURITY_UPDATED;
10244 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10245 ipw_set_hwcrypto_keys(priv);
10247 /* To match current functionality of ipw2100 (which works well w/
10248 * various supplicants, we don't force a disassociate if the
10249 * privacy capability changes ... */
10251 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
10252 (((priv->assoc_request.capability &
10253 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
10254 (!(priv->assoc_request.capability &
10255 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
10256 IPW_DEBUG_ASSOC("Disassociating due to capability "
10258 ipw_disassociate(priv);
10263 static int init_supported_rates(struct ipw_priv *priv,
10264 struct ipw_supported_rates *rates)
10266 /* TODO: Mask out rates based on priv->rates_mask */
10268 memset(rates, 0, sizeof(*rates));
10269 /* configure supported rates */
10270 switch (priv->ieee->freq_band) {
10271 case IEEE80211_52GHZ_BAND:
10272 rates->ieee_mode = IPW_A_MODE;
10273 rates->purpose = IPW_RATE_CAPABILITIES;
10274 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10275 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10278 default: /* Mixed or 2.4Ghz */
10279 rates->ieee_mode = IPW_G_MODE;
10280 rates->purpose = IPW_RATE_CAPABILITIES;
10281 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10282 IEEE80211_CCK_DEFAULT_RATES_MASK);
10283 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10284 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10285 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10293 static int ipw_config(struct ipw_priv *priv)
10295 /* This is only called from ipw_up, which resets/reloads the firmware
10296 so, we don't need to first disable the card before we configure
10298 if (ipw_set_tx_power(priv))
10301 /* initialize adapter address */
10302 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10305 /* set basic system config settings */
10306 init_sys_config(&priv->sys_config);
10308 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10309 * Does not support BT priority yet (don't abort or defer our Tx) */
10311 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
10313 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10314 priv->sys_config.bt_coexistence
10315 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
10316 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10317 priv->sys_config.bt_coexistence
10318 |= CFG_BT_COEXISTENCE_OOB;
10321 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10322 priv->sys_config.answer_broadcast_ssid_probe = 1;
10324 priv->sys_config.answer_broadcast_ssid_probe = 0;
10326 if (ipw_send_system_config(priv, &priv->sys_config))
10329 init_supported_rates(priv, &priv->rates);
10330 if (ipw_send_supported_rates(priv, &priv->rates))
10333 /* Set request-to-send threshold */
10334 if (priv->rts_threshold) {
10335 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10338 #ifdef CONFIG_IPW_QOS
10339 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10340 ipw_qos_activate(priv, NULL);
10341 #endif /* CONFIG_IPW_QOS */
10343 if (ipw_set_random_seed(priv))
10346 /* final state transition to the RUN state */
10347 if (ipw_send_host_complete(priv))
10350 priv->status |= STATUS_INIT;
10352 ipw_led_init(priv);
10353 ipw_led_radio_on(priv);
10354 priv->notif_missed_beacons = 0;
10356 /* Set hardware WEP key if it is configured. */
10357 if ((priv->capability & CAP_PRIVACY_ON) &&
10358 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10359 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10360 ipw_set_hwcrypto_keys(priv);
10371 * These tables have been tested in conjunction with the
10372 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10374 * Altering this values, using it on other hardware, or in geographies
10375 * not intended for resale of the above mentioned Intel adapters has
10378 * Remember to update the table in README.ipw2200 when changing this
10382 static const struct ieee80211_geo ipw_geos[] = {
10386 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10387 {2427, 4}, {2432, 5}, {2437, 6},
10388 {2442, 7}, {2447, 8}, {2452, 9},
10389 {2457, 10}, {2462, 11}},
10392 { /* Custom US/Canada */
10395 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10396 {2427, 4}, {2432, 5}, {2437, 6},
10397 {2442, 7}, {2447, 8}, {2452, 9},
10398 {2457, 10}, {2462, 11}},
10404 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10405 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10406 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10407 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10410 { /* Rest of World */
10413 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10414 {2427, 4}, {2432, 5}, {2437, 6},
10415 {2442, 7}, {2447, 8}, {2452, 9},
10416 {2457, 10}, {2462, 11}, {2467, 12},
10420 { /* Custom USA & Europe & High */
10423 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10424 {2427, 4}, {2432, 5}, {2437, 6},
10425 {2442, 7}, {2447, 8}, {2452, 9},
10426 {2457, 10}, {2462, 11}},
10432 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10433 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10434 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10435 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10443 { /* Custom NA & Europe */
10446 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10447 {2427, 4}, {2432, 5}, {2437, 6},
10448 {2442, 7}, {2447, 8}, {2452, 9},
10449 {2457, 10}, {2462, 11}},
10455 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10456 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10457 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10458 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10459 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10460 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10461 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10462 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10463 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10466 { /* Custom Japan */
10469 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10470 {2427, 4}, {2432, 5}, {2437, 6},
10471 {2442, 7}, {2447, 8}, {2452, 9},
10472 {2457, 10}, {2462, 11}},
10474 .a = {{5170, 34}, {5190, 38},
10475 {5210, 42}, {5230, 46}},
10481 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10482 {2427, 4}, {2432, 5}, {2437, 6},
10483 {2442, 7}, {2447, 8}, {2452, 9},
10484 {2457, 10}, {2462, 11}},
10490 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10491 {2427, 4}, {2432, 5}, {2437, 6},
10492 {2442, 7}, {2447, 8}, {2452, 9},
10493 {2457, 10}, {2462, 11}, {2467, 12},
10500 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10501 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10502 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10503 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10504 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10505 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10506 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10507 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10508 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10509 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10510 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10511 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10512 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10513 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10514 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10517 { /* Custom Japan */
10520 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10521 {2427, 4}, {2432, 5}, {2437, 6},
10522 {2442, 7}, {2447, 8}, {2452, 9},
10523 {2457, 10}, {2462, 11}, {2467, 12},
10524 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10526 .a = {{5170, 34}, {5190, 38},
10527 {5210, 42}, {5230, 46}},
10530 { /* Rest of World */
10533 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10534 {2427, 4}, {2432, 5}, {2437, 6},
10535 {2442, 7}, {2447, 8}, {2452, 9},
10536 {2457, 10}, {2462, 11}, {2467, 12},
10537 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
10538 IEEE80211_CH_PASSIVE_ONLY}},
10544 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10545 {2427, 4}, {2432, 5}, {2437, 6},
10546 {2442, 7}, {2447, 8}, {2452, 9},
10547 {2457, 10}, {2462, 11},
10548 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10549 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10551 .a = {{5745, 149}, {5765, 153},
10552 {5785, 157}, {5805, 161}},
10555 { /* Custom Europe */
10558 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10559 {2427, 4}, {2432, 5}, {2437, 6},
10560 {2442, 7}, {2447, 8}, {2452, 9},
10561 {2457, 10}, {2462, 11},
10562 {2467, 12}, {2472, 13}},
10564 .a = {{5180, 36}, {5200, 40},
10565 {5220, 44}, {5240, 48}},
10571 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10572 {2427, 4}, {2432, 5}, {2437, 6},
10573 {2442, 7}, {2447, 8}, {2452, 9},
10574 {2457, 10}, {2462, 11},
10575 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10576 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10578 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10579 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10580 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10581 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10582 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10583 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10584 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10585 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10586 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10587 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10588 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10589 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10590 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10591 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10592 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10593 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10594 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10595 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10596 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
10597 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10598 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10599 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10600 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10601 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10607 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10608 {2427, 4}, {2432, 5}, {2437, 6},
10609 {2442, 7}, {2447, 8}, {2452, 9},
10610 {2457, 10}, {2462, 11}},
10612 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10613 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10614 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10615 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10616 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10617 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10618 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10619 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10620 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10621 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10622 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10623 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10624 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10628 #define MAX_HW_RESTARTS 5
10629 static int ipw_up(struct ipw_priv *priv)
10633 if (priv->status & STATUS_EXIT_PENDING)
10636 if (cmdlog && !priv->cmdlog) {
10637 priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
10639 if (priv->cmdlog == NULL) {
10640 IPW_ERROR("Error allocating %d command log entries.\n",
10643 memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
10644 priv->cmdlog_len = cmdlog;
10648 for (i = 0; i < MAX_HW_RESTARTS; i++) {
10649 /* Load the microcode, firmware, and eeprom.
10650 * Also start the clocks. */
10651 rc = ipw_load(priv);
10653 IPW_ERROR("Unable to load firmware: %d\n", rc);
10657 ipw_init_ordinals(priv);
10658 if (!(priv->config & CFG_CUSTOM_MAC))
10659 eeprom_parse_mac(priv, priv->mac_addr);
10660 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
10662 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
10663 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
10664 ipw_geos[j].name, 3))
10667 if (j == ARRAY_SIZE(ipw_geos)) {
10668 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
10669 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
10670 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
10671 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
10674 if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
10675 IPW_WARNING("Could not set geography.");
10679 if (priv->status & STATUS_RF_KILL_SW) {
10680 IPW_WARNING("Radio disabled by module parameter.\n");
10682 } else if (rf_kill_active(priv)) {
10683 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
10684 "Kill switch must be turned off for "
10685 "wireless networking to work.\n");
10686 queue_delayed_work(priv->workqueue, &priv->rf_kill,
10691 rc = ipw_config(priv);
10693 IPW_DEBUG_INFO("Configured device on count %i\n", i);
10695 /* If configure to try and auto-associate, kick
10697 queue_work(priv->workqueue, &priv->request_scan);
10702 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
10703 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
10704 i, MAX_HW_RESTARTS);
10706 /* We had an error bringing up the hardware, so take it
10707 * all the way back down so we can try again */
10711 /* tried to restart and config the device for as long as our
10712 * patience could withstand */
10713 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
10718 static void ipw_bg_up(void *data)
10720 struct ipw_priv *priv = data;
10721 mutex_lock(&priv->mutex);
10723 mutex_unlock(&priv->mutex);
10726 static void ipw_deinit(struct ipw_priv *priv)
10730 if (priv->status & STATUS_SCANNING) {
10731 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
10732 ipw_abort_scan(priv);
10735 if (priv->status & STATUS_ASSOCIATED) {
10736 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
10737 ipw_disassociate(priv);
10740 ipw_led_shutdown(priv);
10742 /* Wait up to 1s for status to change to not scanning and not
10743 * associated (disassociation can take a while for a ful 802.11
10745 for (i = 1000; i && (priv->status &
10746 (STATUS_DISASSOCIATING |
10747 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
10750 if (priv->status & (STATUS_DISASSOCIATING |
10751 STATUS_ASSOCIATED | STATUS_SCANNING))
10752 IPW_DEBUG_INFO("Still associated or scanning...\n");
10754 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
10756 /* Attempt to disable the card */
10757 ipw_send_card_disable(priv, 0);
10759 priv->status &= ~STATUS_INIT;
10762 static void ipw_down(struct ipw_priv *priv)
10764 int exit_pending = priv->status & STATUS_EXIT_PENDING;
10766 priv->status |= STATUS_EXIT_PENDING;
10768 if (ipw_is_init(priv))
10771 /* Wipe out the EXIT_PENDING status bit if we are not actually
10772 * exiting the module */
10774 priv->status &= ~STATUS_EXIT_PENDING;
10776 /* tell the device to stop sending interrupts */
10777 ipw_disable_interrupts(priv);
10779 /* Clear all bits but the RF Kill */
10780 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
10781 netif_carrier_off(priv->net_dev);
10782 netif_stop_queue(priv->net_dev);
10784 ipw_stop_nic(priv);
10786 ipw_led_radio_off(priv);
10789 static void ipw_bg_down(void *data)
10791 struct ipw_priv *priv = data;
10792 mutex_lock(&priv->mutex);
10794 mutex_unlock(&priv->mutex);
10797 /* Called by register_netdev() */
10798 static int ipw_net_init(struct net_device *dev)
10800 struct ipw_priv *priv = ieee80211_priv(dev);
10801 mutex_lock(&priv->mutex);
10803 if (ipw_up(priv)) {
10804 mutex_unlock(&priv->mutex);
10808 mutex_unlock(&priv->mutex);
10812 /* PCI driver stuff */
10813 static struct pci_device_id card_ids[] = {
10814 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
10815 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
10816 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
10817 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
10818 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
10819 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
10820 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
10821 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
10822 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
10823 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
10824 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
10825 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
10826 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
10827 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
10828 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
10829 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
10830 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
10831 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
10832 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
10833 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
10834 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
10835 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
10837 /* required last entry */
10841 MODULE_DEVICE_TABLE(pci, card_ids);
10843 static struct attribute *ipw_sysfs_entries[] = {
10844 &dev_attr_rf_kill.attr,
10845 &dev_attr_direct_dword.attr,
10846 &dev_attr_indirect_byte.attr,
10847 &dev_attr_indirect_dword.attr,
10848 &dev_attr_mem_gpio_reg.attr,
10849 &dev_attr_command_event_reg.attr,
10850 &dev_attr_nic_type.attr,
10851 &dev_attr_status.attr,
10852 &dev_attr_cfg.attr,
10853 &dev_attr_error.attr,
10854 &dev_attr_event_log.attr,
10855 &dev_attr_cmd_log.attr,
10856 &dev_attr_eeprom_delay.attr,
10857 &dev_attr_ucode_version.attr,
10858 &dev_attr_rtc.attr,
10859 &dev_attr_scan_age.attr,
10860 &dev_attr_led.attr,
10861 &dev_attr_speed_scan.attr,
10862 &dev_attr_net_stats.attr,
10866 static struct attribute_group ipw_attribute_group = {
10867 .name = NULL, /* put in device directory */
10868 .attrs = ipw_sysfs_entries,
10871 static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
10874 struct net_device *net_dev;
10875 void __iomem *base;
10877 struct ipw_priv *priv;
10880 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
10881 if (net_dev == NULL) {
10886 priv = ieee80211_priv(net_dev);
10887 priv->ieee = netdev_priv(net_dev);
10889 priv->net_dev = net_dev;
10890 priv->pci_dev = pdev;
10891 #ifdef CONFIG_IPW2200_DEBUG
10892 ipw_debug_level = debug;
10894 spin_lock_init(&priv->lock);
10895 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
10896 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
10898 mutex_init(&priv->mutex);
10899 if (pci_enable_device(pdev)) {
10901 goto out_free_ieee80211;
10904 pci_set_master(pdev);
10906 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
10908 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
10910 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
10911 goto out_pci_disable_device;
10914 pci_set_drvdata(pdev, priv);
10916 err = pci_request_regions(pdev, DRV_NAME);
10918 goto out_pci_disable_device;
10920 /* We disable the RETRY_TIMEOUT register (0x41) to keep
10921 * PCI Tx retries from interfering with C3 CPU state */
10922 pci_read_config_dword(pdev, 0x40, &val);
10923 if ((val & 0x0000ff00) != 0)
10924 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
10926 length = pci_resource_len(pdev, 0);
10927 priv->hw_len = length;
10929 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
10932 goto out_pci_release_regions;
10935 priv->hw_base = base;
10936 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
10937 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
10939 err = ipw_setup_deferred_work(priv);
10941 IPW_ERROR("Unable to setup deferred work\n");
10945 ipw_sw_reset(priv, 1);
10947 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
10949 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
10950 goto out_destroy_workqueue;
10953 SET_MODULE_OWNER(net_dev);
10954 SET_NETDEV_DEV(net_dev, &pdev->dev);
10956 mutex_lock(&priv->mutex);
10958 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
10959 priv->ieee->set_security = shim__set_security;
10960 priv->ieee->is_queue_full = ipw_net_is_queue_full;
10962 #ifdef CONFIG_IPW_QOS
10963 priv->ieee->handle_probe_response = ipw_handle_beacon;
10964 priv->ieee->handle_beacon = ipw_handle_probe_response;
10965 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
10966 #endif /* CONFIG_IPW_QOS */
10968 priv->ieee->perfect_rssi = -20;
10969 priv->ieee->worst_rssi = -85;
10971 net_dev->open = ipw_net_open;
10972 net_dev->stop = ipw_net_stop;
10973 net_dev->init = ipw_net_init;
10974 net_dev->get_stats = ipw_net_get_stats;
10975 net_dev->set_multicast_list = ipw_net_set_multicast_list;
10976 net_dev->set_mac_address = ipw_net_set_mac_address;
10977 priv->wireless_data.spy_data = &priv->ieee->spy_data;
10978 net_dev->wireless_data = &priv->wireless_data;
10979 net_dev->wireless_handlers = &ipw_wx_handler_def;
10980 net_dev->ethtool_ops = &ipw_ethtool_ops;
10981 net_dev->irq = pdev->irq;
10982 net_dev->base_addr = (unsigned long)priv->hw_base;
10983 net_dev->mem_start = pci_resource_start(pdev, 0);
10984 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
10986 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
10988 IPW_ERROR("failed to create sysfs device attributes\n");
10989 mutex_unlock(&priv->mutex);
10990 goto out_release_irq;
10993 mutex_unlock(&priv->mutex);
10994 err = register_netdev(net_dev);
10996 IPW_ERROR("failed to register network device\n");
10997 goto out_remove_sysfs;
11000 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11001 "channels, %d 802.11a channels)\n",
11002 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11003 priv->ieee->geo.a_channels);
11008 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11010 free_irq(pdev->irq, priv);
11011 out_destroy_workqueue:
11012 destroy_workqueue(priv->workqueue);
11013 priv->workqueue = NULL;
11015 iounmap(priv->hw_base);
11016 out_pci_release_regions:
11017 pci_release_regions(pdev);
11018 out_pci_disable_device:
11019 pci_disable_device(pdev);
11020 pci_set_drvdata(pdev, NULL);
11021 out_free_ieee80211:
11022 free_ieee80211(priv->net_dev);
11027 static void ipw_pci_remove(struct pci_dev *pdev)
11029 struct ipw_priv *priv = pci_get_drvdata(pdev);
11030 struct list_head *p, *q;
11036 mutex_lock(&priv->mutex);
11038 priv->status |= STATUS_EXIT_PENDING;
11040 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11042 mutex_unlock(&priv->mutex);
11044 unregister_netdev(priv->net_dev);
11047 ipw_rx_queue_free(priv, priv->rxq);
11050 ipw_tx_queue_free(priv);
11052 if (priv->cmdlog) {
11053 kfree(priv->cmdlog);
11054 priv->cmdlog = NULL;
11056 /* ipw_down will ensure that there is no more pending work
11057 * in the workqueue's, so we can safely remove them now. */
11058 cancel_delayed_work(&priv->adhoc_check);
11059 cancel_delayed_work(&priv->gather_stats);
11060 cancel_delayed_work(&priv->request_scan);
11061 cancel_delayed_work(&priv->rf_kill);
11062 cancel_delayed_work(&priv->scan_check);
11063 destroy_workqueue(priv->workqueue);
11064 priv->workqueue = NULL;
11066 /* Free MAC hash list for ADHOC */
11067 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11068 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
11070 kfree(list_entry(p, struct ipw_ibss_seq, list));
11075 ipw_free_error_log(priv->error);
11076 priv->error = NULL;
11079 free_irq(pdev->irq, priv);
11080 iounmap(priv->hw_base);
11081 pci_release_regions(pdev);
11082 pci_disable_device(pdev);
11083 pci_set_drvdata(pdev, NULL);
11084 free_ieee80211(priv->net_dev);
11089 static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
11091 struct ipw_priv *priv = pci_get_drvdata(pdev);
11092 struct net_device *dev = priv->net_dev;
11094 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11096 /* Take down the device; powers it off, etc. */
11099 /* Remove the PRESENT state of the device */
11100 netif_device_detach(dev);
11102 pci_save_state(pdev);
11103 pci_disable_device(pdev);
11104 pci_set_power_state(pdev, pci_choose_state(pdev, state));
11109 static int ipw_pci_resume(struct pci_dev *pdev)
11111 struct ipw_priv *priv = pci_get_drvdata(pdev);
11112 struct net_device *dev = priv->net_dev;
11115 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11117 pci_set_power_state(pdev, PCI_D0);
11118 pci_enable_device(pdev);
11119 pci_restore_state(pdev);
11122 * Suspend/Resume resets the PCI configuration space, so we have to
11123 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11124 * from interfering with C3 CPU state. pci_restore_state won't help
11125 * here since it only restores the first 64 bytes pci config header.
11127 pci_read_config_dword(pdev, 0x40, &val);
11128 if ((val & 0x0000ff00) != 0)
11129 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11131 /* Set the device back into the PRESENT state; this will also wake
11132 * the queue of needed */
11133 netif_device_attach(dev);
11135 /* Bring the device back up */
11136 queue_work(priv->workqueue, &priv->up);
11142 /* driver initialization stuff */
11143 static struct pci_driver ipw_driver = {
11145 .id_table = card_ids,
11146 .probe = ipw_pci_probe,
11147 .remove = __devexit_p(ipw_pci_remove),
11149 .suspend = ipw_pci_suspend,
11150 .resume = ipw_pci_resume,
11154 static int __init ipw_init(void)
11158 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11159 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11161 ret = pci_module_init(&ipw_driver);
11163 IPW_ERROR("Unable to initialize PCI module\n");
11167 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
11169 IPW_ERROR("Unable to create driver sysfs file\n");
11170 pci_unregister_driver(&ipw_driver);
11177 static void __exit ipw_exit(void)
11179 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11180 pci_unregister_driver(&ipw_driver);
11183 module_param(disable, int, 0444);
11184 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11186 module_param(associate, int, 0444);
11187 MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11189 module_param(auto_create, int, 0444);
11190 MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11192 module_param(led, int, 0444);
11193 MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
11195 #ifdef CONFIG_IPW2200_DEBUG
11196 module_param(debug, int, 0444);
11197 MODULE_PARM_DESC(debug, "debug output mask");
11200 module_param(channel, int, 0444);
11201 MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
11203 #ifdef CONFIG_IPW_QOS
11204 module_param(qos_enable, int, 0444);
11205 MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
11207 module_param(qos_burst_enable, int, 0444);
11208 MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11210 module_param(qos_no_ack_mask, int, 0444);
11211 MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11213 module_param(burst_duration_CCK, int, 0444);
11214 MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11216 module_param(burst_duration_OFDM, int, 0444);
11217 MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11218 #endif /* CONFIG_IPW_QOS */
11220 #ifdef CONFIG_IPW2200_MONITOR
11221 module_param(mode, int, 0444);
11222 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11224 module_param(mode, int, 0444);
11225 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11228 module_param(bt_coexist, int, 0444);
11229 MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
11231 module_param(hwcrypto, int, 0444);
11232 MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
11234 module_param(cmdlog, int, 0444);
11235 MODULE_PARM_DESC(cmdlog,
11236 "allocate a ring buffer for logging firmware commands");
11238 module_param(roaming, int, 0444);
11239 MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
11241 module_exit(ipw_exit);
11242 module_init(ipw_init);