1 /******************************************************************************
3 Copyright(c) 2003 - 2004 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 ******************************************************************************/
35 #define IPW2200_VERSION "1.0.4"
36 #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
37 #define DRV_COPYRIGHT "Copyright(c) 2003-2004 Intel Corporation"
38 #define DRV_VERSION IPW2200_VERSION
40 #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
42 MODULE_DESCRIPTION(DRV_DESCRIPTION);
43 MODULE_VERSION(DRV_VERSION);
44 MODULE_AUTHOR(DRV_COPYRIGHT);
45 MODULE_LICENSE("GPL");
48 static int channel = 0;
51 static u32 ipw_debug_level;
52 static int associate = 1;
53 static int auto_create = 1;
55 static int disable = 0;
56 static int hwcrypto = 1;
57 static const char ipw_modes[] = {
62 static int qos_enable = 0;
63 static int qos_burst_enable = 0;
64 static int qos_no_ack_mask = 0;
65 static int burst_duration_CCK = 0;
66 static int burst_duration_OFDM = 0;
68 static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
69 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
71 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
73 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
74 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
75 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
76 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
79 static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
80 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
82 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
84 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
85 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
86 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
87 QOS_TX3_TXOP_LIMIT_CCK}
90 static struct ieee80211_qos_parameters def_parameters_OFDM = {
91 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
93 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
95 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
96 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
97 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
98 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
101 static struct ieee80211_qos_parameters def_parameters_CCK = {
102 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
104 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
106 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
107 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
108 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
109 DEF_TX3_TXOP_LIMIT_CCK}
112 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
114 static int from_priority_to_tx_queue[] = {
115 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
116 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
119 static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
121 static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
123 static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
125 #endif /* CONFIG_IPW_QOS */
127 static void ipw_remove_current_network(struct ipw_priv *priv);
128 static void ipw_rx(struct ipw_priv *priv);
129 static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
130 struct clx2_tx_queue *txq, int qindex);
131 static int ipw_queue_reset(struct ipw_priv *priv);
133 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
136 static void ipw_tx_queue_free(struct ipw_priv *);
138 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
139 static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
140 static void ipw_rx_queue_replenish(void *);
141 static int ipw_up(struct ipw_priv *);
142 static void ipw_bg_up(void *);
143 static void ipw_down(struct ipw_priv *);
144 static void ipw_bg_down(void *);
145 static int ipw_config(struct ipw_priv *);
146 static int init_supported_rates(struct ipw_priv *priv,
147 struct ipw_supported_rates *prates);
148 static void ipw_set_hwcrypto_keys(struct ipw_priv *);
149 static void ipw_send_wep_keys(struct ipw_priv *, int);
151 static char *snprint_line(char *buf, size_t count,
152 const u8 * data, u32 len, u32 ofs)
157 out = snprintf(buf, count, "%08X", ofs);
159 for (l = 0, i = 0; i < 2; i++) {
160 out += snprintf(buf + out, count - out, " ");
161 for (j = 0; j < 8 && l < len; j++, l++)
162 out += snprintf(buf + out, count - out, "%02X ",
165 out += snprintf(buf + out, count - out, " ");
168 out += snprintf(buf + out, count - out, " ");
169 for (l = 0, i = 0; i < 2; i++) {
170 out += snprintf(buf + out, count - out, " ");
171 for (j = 0; j < 8 && l < len; j++, l++) {
172 c = data[(i * 8 + j)];
173 if (!isascii(c) || !isprint(c))
176 out += snprintf(buf + out, count - out, "%c", c);
180 out += snprintf(buf + out, count - out, " ");
186 static void printk_buf(int level, const u8 * data, u32 len)
190 if (!(ipw_debug_level & level))
194 printk(KERN_DEBUG "%s\n",
195 snprint_line(line, sizeof(line), &data[ofs],
196 min(len, 16U), ofs));
198 len -= min(len, 16U);
202 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
203 #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
205 static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
206 #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
208 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
209 static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
211 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
212 __LINE__, (u32) (b), (u32) (c));
213 _ipw_write_reg8(a, b, c);
216 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
217 static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
219 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
220 __LINE__, (u32) (b), (u32) (c));
221 _ipw_write_reg16(a, b, c);
224 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
225 static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
227 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
228 __LINE__, (u32) (b), (u32) (c));
229 _ipw_write_reg32(a, b, c);
232 #define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
233 #define ipw_write8(ipw, ofs, val) \
234 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
235 _ipw_write8(ipw, ofs, val)
237 #define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
238 #define ipw_write16(ipw, ofs, val) \
239 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
240 _ipw_write16(ipw, ofs, val)
242 #define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
243 #define ipw_write32(ipw, ofs, val) \
244 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
245 _ipw_write32(ipw, ofs, val)
247 #define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
248 static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
250 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
251 return _ipw_read8(ipw, ofs);
254 #define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
256 #define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
257 static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
259 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
260 return _ipw_read16(ipw, ofs);
263 #define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
265 #define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
266 static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
268 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
269 return _ipw_read32(ipw, ofs);
272 #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
274 static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
275 #define ipw_read_indirect(a, b, c, d) \
276 IPW_DEBUG_IO("%s %d: read_inddirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
277 _ipw_read_indirect(a, b, c, d)
279 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
281 #define ipw_write_indirect(a, b, c, d) \
282 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
283 _ipw_write_indirect(a, b, c, d)
285 /* indirect write s */
286 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
288 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
289 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
290 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
293 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
295 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
296 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
297 _ipw_write8(priv, IPW_INDIRECT_DATA, value);
298 IPW_DEBUG_IO(" reg = 0x%8lX : value = 0x%8X\n",
299 (unsigned long)(priv->hw_base + IPW_INDIRECT_DATA), value);
302 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
304 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
305 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
306 _ipw_write16(priv, IPW_INDIRECT_DATA, value);
309 /* indirect read s */
311 static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
314 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
315 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
316 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
317 return (word >> ((reg & 0x3) * 8)) & 0xff;
320 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
324 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
326 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
327 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
328 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
332 /* iterative/auto-increment 32 bit reads and writes */
333 static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
336 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK;
337 u32 dif_len = addr - aligned_addr;
340 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
346 /* Read the first nibble byte by byte */
347 if (unlikely(dif_len)) {
348 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
349 /* Start reading at aligned_addr + dif_len */
350 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
351 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
355 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
356 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
357 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
359 /* Copy the last nibble */
361 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
362 for (i = 0; num > 0; i++, num--)
363 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
367 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
370 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK;
371 u32 dif_len = addr - aligned_addr;
374 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
380 /* Write the first nibble byte by byte */
381 if (unlikely(dif_len)) {
382 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
383 /* Start reading at aligned_addr + dif_len */
384 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
385 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
389 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
390 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
391 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
393 /* Copy the last nibble */
395 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
396 for (i = 0; num > 0; i++, num--, buf++)
397 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
401 static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
404 memcpy_toio((priv->hw_base + addr), buf, num);
407 static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
409 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
412 static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
414 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
417 static inline void ipw_enable_interrupts(struct ipw_priv *priv)
419 if (priv->status & STATUS_INT_ENABLED)
421 priv->status |= STATUS_INT_ENABLED;
422 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
425 static inline void ipw_disable_interrupts(struct ipw_priv *priv)
427 if (!(priv->status & STATUS_INT_ENABLED))
429 priv->status &= ~STATUS_INT_ENABLED;
430 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
433 static char *ipw_error_desc(u32 val)
436 case IPW_FW_ERROR_OK:
438 case IPW_FW_ERROR_FAIL:
440 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
441 return "MEMORY_UNDERFLOW";
442 case IPW_FW_ERROR_MEMORY_OVERFLOW:
443 return "MEMORY_OVERFLOW";
444 case IPW_FW_ERROR_BAD_PARAM:
446 case IPW_FW_ERROR_BAD_CHECKSUM:
447 return "BAD_CHECKSUM";
448 case IPW_FW_ERROR_NMI_INTERRUPT:
449 return "NMI_INTERRUPT";
450 case IPW_FW_ERROR_BAD_DATABASE:
451 return "BAD_DATABASE";
452 case IPW_FW_ERROR_ALLOC_FAIL:
454 case IPW_FW_ERROR_DMA_UNDERRUN:
455 return "DMA_UNDERRUN";
456 case IPW_FW_ERROR_DMA_STATUS:
458 case IPW_FW_ERROR_DINO_ERROR:
460 case IPW_FW_ERROR_EEPROM_ERROR:
461 return "EEPROM_ERROR";
462 case IPW_FW_ERROR_SYSASSERT:
464 case IPW_FW_ERROR_FATAL_ERROR:
465 return "FATAL_ERROR";
467 return "UNKNOWN_ERROR";
471 static void ipw_dump_nic_error_log(struct ipw_priv *priv)
473 u32 desc, time, blink1, blink2, ilink1, ilink2, idata, i, count, base;
475 base = ipw_read32(priv, IPWSTATUS_ERROR_LOG);
476 count = ipw_read_reg32(priv, base);
478 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
479 IPW_ERROR("Start IPW Error Log Dump:\n");
480 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
481 priv->status, priv->config);
484 for (i = ERROR_START_OFFSET;
485 i <= count * ERROR_ELEM_SIZE; i += ERROR_ELEM_SIZE) {
486 desc = ipw_read_reg32(priv, base + i);
487 time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
488 blink1 = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
489 blink2 = ipw_read_reg32(priv, base + i + 3 * sizeof(u32));
490 ilink1 = ipw_read_reg32(priv, base + i + 4 * sizeof(u32));
491 ilink2 = ipw_read_reg32(priv, base + i + 5 * sizeof(u32));
492 idata = ipw_read_reg32(priv, base + i + 6 * sizeof(u32));
494 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
495 ipw_error_desc(desc), time, blink1, blink2,
496 ilink1, ilink2, idata);
500 static void ipw_dump_nic_event_log(struct ipw_priv *priv)
502 u32 ev, time, data, i, count, base;
504 base = ipw_read32(priv, IPW_EVENT_LOG);
505 count = ipw_read_reg32(priv, base);
507 if (EVENT_START_OFFSET <= count * EVENT_ELEM_SIZE)
508 IPW_ERROR("Start IPW Event Log Dump:\n");
510 for (i = EVENT_START_OFFSET;
511 i <= count * EVENT_ELEM_SIZE; i += EVENT_ELEM_SIZE) {
512 ev = ipw_read_reg32(priv, base + i);
513 time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
514 data = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
516 #ifdef CONFIG_IPW_DEBUG
517 IPW_ERROR("%i\t0x%08x\t%i\n", time, data, ev);
522 static inline int ipw_is_init(struct ipw_priv *priv)
524 return (priv->status & STATUS_INIT) ? 1 : 0;
527 static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
529 u32 addr, field_info, field_len, field_count, total_len;
531 IPW_DEBUG_ORD("ordinal = %i\n", ord);
533 if (!priv || !val || !len) {
534 IPW_DEBUG_ORD("Invalid argument\n");
538 /* verify device ordinal tables have been initialized */
539 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
540 IPW_DEBUG_ORD("Access ordinals before initialization\n");
544 switch (IPW_ORD_TABLE_ID_MASK & ord) {
545 case IPW_ORD_TABLE_0_MASK:
547 * TABLE 0: Direct access to a table of 32 bit values
549 * This is a very simple table with the data directly
550 * read from the table
553 /* remove the table id from the ordinal */
554 ord &= IPW_ORD_TABLE_VALUE_MASK;
557 if (ord > priv->table0_len) {
558 IPW_DEBUG_ORD("ordinal value (%i) longer then "
559 "max (%i)\n", ord, priv->table0_len);
563 /* verify we have enough room to store the value */
564 if (*len < sizeof(u32)) {
565 IPW_DEBUG_ORD("ordinal buffer length too small, "
566 "need %zd\n", sizeof(u32));
570 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
571 ord, priv->table0_addr + (ord << 2));
575 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
578 case IPW_ORD_TABLE_1_MASK:
580 * TABLE 1: Indirect access to a table of 32 bit values
582 * This is a fairly large table of u32 values each
583 * representing starting addr for the data (which is
587 /* remove the table id from the ordinal */
588 ord &= IPW_ORD_TABLE_VALUE_MASK;
591 if (ord > priv->table1_len) {
592 IPW_DEBUG_ORD("ordinal value too long\n");
596 /* verify we have enough room to store the value */
597 if (*len < sizeof(u32)) {
598 IPW_DEBUG_ORD("ordinal buffer length too small, "
599 "need %zd\n", sizeof(u32));
604 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
608 case IPW_ORD_TABLE_2_MASK:
610 * TABLE 2: Indirect access to a table of variable sized values
612 * This table consist of six values, each containing
613 * - dword containing the starting offset of the data
614 * - dword containing the lengh in the first 16bits
615 * and the count in the second 16bits
618 /* remove the table id from the ordinal */
619 ord &= IPW_ORD_TABLE_VALUE_MASK;
622 if (ord > priv->table2_len) {
623 IPW_DEBUG_ORD("ordinal value too long\n");
627 /* get the address of statistic */
628 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
630 /* get the second DW of statistics ;
631 * two 16-bit words - first is length, second is count */
634 priv->table2_addr + (ord << 3) +
637 /* get each entry length */
638 field_len = *((u16 *) & field_info);
640 /* get number of entries */
641 field_count = *(((u16 *) & field_info) + 1);
643 /* abort if not enought memory */
644 total_len = field_len * field_count;
645 if (total_len > *len) {
654 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
655 "field_info = 0x%08x\n",
656 addr, total_len, field_info);
657 ipw_read_indirect(priv, addr, val, total_len);
661 IPW_DEBUG_ORD("Invalid ordinal!\n");
669 static void ipw_init_ordinals(struct ipw_priv *priv)
671 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
672 priv->table0_len = ipw_read32(priv, priv->table0_addr);
674 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
675 priv->table0_addr, priv->table0_len);
677 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
678 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
680 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
681 priv->table1_addr, priv->table1_len);
683 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
684 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
685 priv->table2_len &= 0x0000ffff; /* use first two bytes */
687 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
688 priv->table2_addr, priv->table2_len);
692 u32 ipw_register_toggle(u32 reg)
694 reg &= ~IPW_START_STANDBY;
695 if (reg & IPW_GATE_ODMA)
696 reg &= ~IPW_GATE_ODMA;
697 if (reg & IPW_GATE_IDMA)
698 reg &= ~IPW_GATE_IDMA;
699 if (reg & IPW_GATE_ADMA)
700 reg &= ~IPW_GATE_ADMA;
706 * - On radio ON, turn on any LEDs that require to be on during start
707 * - On initialization, start unassociated blink
708 * - On association, disable unassociated blink
709 * - On disassociation, start unassociated blink
710 * - On radio OFF, turn off any LEDs started during radio on
713 #define LD_TIME_LINK_ON 300
714 #define LD_TIME_LINK_OFF 2700
715 #define LD_TIME_ACT_ON 250
717 void ipw_led_link_on(struct ipw_priv *priv)
722 /* If configured to not use LEDs, or nic_type is 1,
723 * then we don't toggle a LINK led */
724 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
727 spin_lock_irqsave(&priv->lock, flags);
729 if (!(priv->status & STATUS_RF_KILL_MASK) &&
730 !(priv->status & STATUS_LED_LINK_ON)) {
731 IPW_DEBUG_LED("Link LED On\n");
732 led = ipw_read_reg32(priv, IPW_EVENT_REG);
733 led |= priv->led_association_on;
735 led = ipw_register_toggle(led);
737 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
738 ipw_write_reg32(priv, IPW_EVENT_REG, led);
740 priv->status |= STATUS_LED_LINK_ON;
742 /* If we aren't associated, schedule turning the LED off */
743 if (!(priv->status & STATUS_ASSOCIATED))
744 queue_delayed_work(priv->workqueue,
749 spin_unlock_irqrestore(&priv->lock, flags);
752 static void ipw_bg_led_link_on(void *data)
754 struct ipw_priv *priv = data;
756 ipw_led_link_on(data);
760 void ipw_led_link_off(struct ipw_priv *priv)
765 /* If configured not to use LEDs, or nic type is 1,
766 * then we don't goggle the LINK led. */
767 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
770 spin_lock_irqsave(&priv->lock, flags);
772 if (priv->status & STATUS_LED_LINK_ON) {
773 led = ipw_read_reg32(priv, IPW_EVENT_REG);
774 led &= priv->led_association_off;
775 led = ipw_register_toggle(led);
777 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
778 ipw_write_reg32(priv, IPW_EVENT_REG, led);
780 IPW_DEBUG_LED("Link LED Off\n");
782 priv->status &= ~STATUS_LED_LINK_ON;
784 /* If we aren't associated and the radio is on, schedule
785 * turning the LED on (blink while unassociated) */
786 if (!(priv->status & STATUS_RF_KILL_MASK) &&
787 !(priv->status & STATUS_ASSOCIATED))
788 queue_delayed_work(priv->workqueue, &priv->led_link_on,
793 spin_unlock_irqrestore(&priv->lock, flags);
796 static void ipw_bg_led_link_off(void *data)
798 struct ipw_priv *priv = data;
800 ipw_led_link_off(data);
804 static inline void __ipw_led_activity_on(struct ipw_priv *priv)
808 if (priv->config & CFG_NO_LED)
811 if (priv->status & STATUS_RF_KILL_MASK)
814 if (!(priv->status & STATUS_LED_ACT_ON)) {
815 led = ipw_read_reg32(priv, IPW_EVENT_REG);
816 led |= priv->led_activity_on;
818 led = ipw_register_toggle(led);
820 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
821 ipw_write_reg32(priv, IPW_EVENT_REG, led);
823 IPW_DEBUG_LED("Activity LED On\n");
825 priv->status |= STATUS_LED_ACT_ON;
827 cancel_delayed_work(&priv->led_act_off);
828 queue_delayed_work(priv->workqueue, &priv->led_act_off,
831 /* Reschedule LED off for full time period */
832 cancel_delayed_work(&priv->led_act_off);
833 queue_delayed_work(priv->workqueue, &priv->led_act_off,
838 void ipw_led_activity_on(struct ipw_priv *priv)
841 spin_lock_irqsave(&priv->lock, flags);
842 __ipw_led_activity_on(priv);
843 spin_unlock_irqrestore(&priv->lock, flags);
846 void ipw_led_activity_off(struct ipw_priv *priv)
851 if (priv->config & CFG_NO_LED)
854 spin_lock_irqsave(&priv->lock, flags);
856 if (priv->status & STATUS_LED_ACT_ON) {
857 led = ipw_read_reg32(priv, IPW_EVENT_REG);
858 led &= priv->led_activity_off;
860 led = ipw_register_toggle(led);
862 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
863 ipw_write_reg32(priv, IPW_EVENT_REG, led);
865 IPW_DEBUG_LED("Activity LED Off\n");
867 priv->status &= ~STATUS_LED_ACT_ON;
870 spin_unlock_irqrestore(&priv->lock, flags);
873 static void ipw_bg_led_activity_off(void *data)
875 struct ipw_priv *priv = data;
877 ipw_led_activity_off(data);
881 void ipw_led_band_on(struct ipw_priv *priv)
886 /* Only nic type 1 supports mode LEDs */
887 if (priv->config & CFG_NO_LED ||
888 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
891 spin_lock_irqsave(&priv->lock, flags);
893 led = ipw_read_reg32(priv, IPW_EVENT_REG);
894 if (priv->assoc_network->mode == IEEE_A) {
895 led |= priv->led_ofdm_on;
896 led &= priv->led_association_off;
897 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
898 } else if (priv->assoc_network->mode == IEEE_G) {
899 led |= priv->led_ofdm_on;
900 led |= priv->led_association_on;
901 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
903 led &= priv->led_ofdm_off;
904 led |= priv->led_association_on;
905 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
908 led = ipw_register_toggle(led);
910 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
911 ipw_write_reg32(priv, IPW_EVENT_REG, led);
913 spin_unlock_irqrestore(&priv->lock, flags);
916 void ipw_led_band_off(struct ipw_priv *priv)
921 /* Only nic type 1 supports mode LEDs */
922 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
925 spin_lock_irqsave(&priv->lock, flags);
927 led = ipw_read_reg32(priv, IPW_EVENT_REG);
928 led &= priv->led_ofdm_off;
929 led &= priv->led_association_off;
931 led = ipw_register_toggle(led);
933 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
934 ipw_write_reg32(priv, IPW_EVENT_REG, led);
936 spin_unlock_irqrestore(&priv->lock, flags);
939 void ipw_led_radio_on(struct ipw_priv *priv)
941 ipw_led_link_on(priv);
944 void ipw_led_radio_off(struct ipw_priv *priv)
946 ipw_led_activity_off(priv);
947 ipw_led_link_off(priv);
950 void ipw_led_link_up(struct ipw_priv *priv)
952 /* Set the Link Led on for all nic types */
953 ipw_led_link_on(priv);
956 void ipw_led_link_down(struct ipw_priv *priv)
958 ipw_led_activity_off(priv);
959 ipw_led_link_off(priv);
961 if (priv->status & STATUS_RF_KILL_MASK)
962 ipw_led_radio_off(priv);
965 void ipw_led_init(struct ipw_priv *priv)
967 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
969 /* Set the default PINs for the link and activity leds */
970 priv->led_activity_on = IPW_ACTIVITY_LED;
971 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
973 priv->led_association_on = IPW_ASSOCIATED_LED;
974 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
976 /* Set the default PINs for the OFDM leds */
977 priv->led_ofdm_on = IPW_OFDM_LED;
978 priv->led_ofdm_off = ~(IPW_OFDM_LED);
980 switch (priv->nic_type) {
981 case EEPROM_NIC_TYPE_1:
982 /* In this NIC type, the LEDs are reversed.... */
983 priv->led_activity_on = IPW_ASSOCIATED_LED;
984 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
985 priv->led_association_on = IPW_ACTIVITY_LED;
986 priv->led_association_off = ~(IPW_ACTIVITY_LED);
988 if (!(priv->config & CFG_NO_LED))
989 ipw_led_band_on(priv);
991 /* And we don't blink link LEDs for this nic, so
992 * just return here */
995 case EEPROM_NIC_TYPE_3:
996 case EEPROM_NIC_TYPE_2:
997 case EEPROM_NIC_TYPE_4:
998 case EEPROM_NIC_TYPE_0:
1002 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1004 priv->nic_type = EEPROM_NIC_TYPE_0;
1008 if (!(priv->config & CFG_NO_LED)) {
1009 if (priv->status & STATUS_ASSOCIATED)
1010 ipw_led_link_on(priv);
1012 ipw_led_link_off(priv);
1016 void ipw_led_shutdown(struct ipw_priv *priv)
1018 cancel_delayed_work(&priv->led_link_on);
1019 cancel_delayed_work(&priv->led_link_off);
1020 cancel_delayed_work(&priv->led_act_off);
1021 ipw_led_activity_off(priv);
1022 ipw_led_link_off(priv);
1023 ipw_led_band_off(priv);
1027 * The following adds a new attribute to the sysfs representation
1028 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1029 * used for controling the debug level.
1031 * See the level definitions in ipw for details.
1033 static ssize_t show_debug_level(struct device_driver *d, char *buf)
1035 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1038 static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1041 char *p = (char *)buf;
1044 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1046 if (p[0] == 'x' || p[0] == 'X')
1048 val = simple_strtoul(p, &p, 16);
1050 val = simple_strtoul(p, &p, 10);
1052 printk(KERN_INFO DRV_NAME
1053 ": %s is not in hex or decimal form.\n", buf);
1055 ipw_debug_level = val;
1057 return strnlen(buf, count);
1060 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
1061 show_debug_level, store_debug_level);
1063 static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1066 struct ipw_priv *priv = dev_get_drvdata(d);
1067 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1070 static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1071 const char *buf, size_t count)
1073 struct ipw_priv *priv = dev_get_drvdata(d);
1074 #ifdef CONFIG_IPW_DEBUG
1075 struct net_device *dev = priv->net_dev;
1077 char buffer[] = "00000000";
1079 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1083 IPW_DEBUG_INFO("enter\n");
1085 strncpy(buffer, buf, len);
1088 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1090 if (p[0] == 'x' || p[0] == 'X')
1092 val = simple_strtoul(p, &p, 16);
1094 val = simple_strtoul(p, &p, 10);
1096 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1098 priv->ieee->scan_age = val;
1099 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1102 IPW_DEBUG_INFO("exit\n");
1106 static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1108 static ssize_t show_led(struct device *d, struct device_attribute *attr,
1111 struct ipw_priv *priv = dev_get_drvdata(d);
1112 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1115 static ssize_t store_led(struct device *d, struct device_attribute *attr,
1116 const char *buf, size_t count)
1118 struct ipw_priv *priv = dev_get_drvdata(d);
1120 IPW_DEBUG_INFO("enter\n");
1126 IPW_DEBUG_LED("Disabling LED control.\n");
1127 priv->config |= CFG_NO_LED;
1128 ipw_led_shutdown(priv);
1130 IPW_DEBUG_LED("Enabling LED control.\n");
1131 priv->config &= ~CFG_NO_LED;
1135 IPW_DEBUG_INFO("exit\n");
1139 static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1141 static ssize_t show_status(struct device *d,
1142 struct device_attribute *attr, char *buf)
1144 struct ipw_priv *p = d->driver_data;
1145 return sprintf(buf, "0x%08x\n", (int)p->status);
1148 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1150 static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1153 struct ipw_priv *p = d->driver_data;
1154 return sprintf(buf, "0x%08x\n", (int)p->config);
1157 static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1159 static ssize_t show_nic_type(struct device *d,
1160 struct device_attribute *attr, char *buf)
1162 struct ipw_priv *priv = d->driver_data;
1163 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
1166 static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1168 static ssize_t dump_error_log(struct device *d,
1169 struct device_attribute *attr, const char *buf,
1172 char *p = (char *)buf;
1175 ipw_dump_nic_error_log((struct ipw_priv *)d->driver_data);
1177 return strnlen(buf, count);
1180 static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
1182 static ssize_t dump_event_log(struct device *d,
1183 struct device_attribute *attr, const char *buf,
1186 char *p = (char *)buf;
1189 ipw_dump_nic_event_log((struct ipw_priv *)d->driver_data);
1191 return strnlen(buf, count);
1194 static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
1196 static ssize_t show_ucode_version(struct device *d,
1197 struct device_attribute *attr, char *buf)
1199 u32 len = sizeof(u32), tmp = 0;
1200 struct ipw_priv *p = d->driver_data;
1202 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
1205 return sprintf(buf, "0x%08x\n", tmp);
1208 static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
1210 static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1213 u32 len = sizeof(u32), tmp = 0;
1214 struct ipw_priv *p = d->driver_data;
1216 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
1219 return sprintf(buf, "0x%08x\n", tmp);
1222 static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
1225 * Add a device attribute to view/control the delay between eeprom
1228 static ssize_t show_eeprom_delay(struct device *d,
1229 struct device_attribute *attr, char *buf)
1231 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
1232 return sprintf(buf, "%i\n", n);
1234 static ssize_t store_eeprom_delay(struct device *d,
1235 struct device_attribute *attr,
1236 const char *buf, size_t count)
1238 struct ipw_priv *p = d->driver_data;
1239 sscanf(buf, "%i", &p->eeprom_delay);
1240 return strnlen(buf, count);
1243 static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1244 show_eeprom_delay, store_eeprom_delay);
1246 static ssize_t show_command_event_reg(struct device *d,
1247 struct device_attribute *attr, char *buf)
1250 struct ipw_priv *p = d->driver_data;
1252 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
1253 return sprintf(buf, "0x%08x\n", reg);
1255 static ssize_t store_command_event_reg(struct device *d,
1256 struct device_attribute *attr,
1257 const char *buf, size_t count)
1260 struct ipw_priv *p = d->driver_data;
1262 sscanf(buf, "%x", ®);
1263 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
1264 return strnlen(buf, count);
1267 static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1268 show_command_event_reg, store_command_event_reg);
1270 static ssize_t show_mem_gpio_reg(struct device *d,
1271 struct device_attribute *attr, char *buf)
1274 struct ipw_priv *p = d->driver_data;
1276 reg = ipw_read_reg32(p, 0x301100);
1277 return sprintf(buf, "0x%08x\n", reg);
1279 static ssize_t store_mem_gpio_reg(struct device *d,
1280 struct device_attribute *attr,
1281 const char *buf, size_t count)
1284 struct ipw_priv *p = d->driver_data;
1286 sscanf(buf, "%x", ®);
1287 ipw_write_reg32(p, 0x301100, reg);
1288 return strnlen(buf, count);
1291 static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1292 show_mem_gpio_reg, store_mem_gpio_reg);
1294 static ssize_t show_indirect_dword(struct device *d,
1295 struct device_attribute *attr, char *buf)
1298 struct ipw_priv *priv = d->driver_data;
1299 if (priv->status & STATUS_INDIRECT_DWORD)
1300 reg = ipw_read_reg32(priv, priv->indirect_dword);
1304 return sprintf(buf, "0x%08x\n", reg);
1306 static ssize_t store_indirect_dword(struct device *d,
1307 struct device_attribute *attr,
1308 const char *buf, size_t count)
1310 struct ipw_priv *priv = d->driver_data;
1312 sscanf(buf, "%x", &priv->indirect_dword);
1313 priv->status |= STATUS_INDIRECT_DWORD;
1314 return strnlen(buf, count);
1317 static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1318 show_indirect_dword, store_indirect_dword);
1320 static ssize_t show_indirect_byte(struct device *d,
1321 struct device_attribute *attr, char *buf)
1324 struct ipw_priv *priv = d->driver_data;
1325 if (priv->status & STATUS_INDIRECT_BYTE)
1326 reg = ipw_read_reg8(priv, priv->indirect_byte);
1330 return sprintf(buf, "0x%02x\n", reg);
1332 static ssize_t store_indirect_byte(struct device *d,
1333 struct device_attribute *attr,
1334 const char *buf, size_t count)
1336 struct ipw_priv *priv = d->driver_data;
1338 sscanf(buf, "%x", &priv->indirect_byte);
1339 priv->status |= STATUS_INDIRECT_BYTE;
1340 return strnlen(buf, count);
1343 static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
1344 show_indirect_byte, store_indirect_byte);
1346 static ssize_t show_direct_dword(struct device *d,
1347 struct device_attribute *attr, char *buf)
1350 struct ipw_priv *priv = d->driver_data;
1352 if (priv->status & STATUS_DIRECT_DWORD)
1353 reg = ipw_read32(priv, priv->direct_dword);
1357 return sprintf(buf, "0x%08x\n", reg);
1359 static ssize_t store_direct_dword(struct device *d,
1360 struct device_attribute *attr,
1361 const char *buf, size_t count)
1363 struct ipw_priv *priv = d->driver_data;
1365 sscanf(buf, "%x", &priv->direct_dword);
1366 priv->status |= STATUS_DIRECT_DWORD;
1367 return strnlen(buf, count);
1370 static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1371 show_direct_dword, store_direct_dword);
1373 static inline int rf_kill_active(struct ipw_priv *priv)
1375 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1376 priv->status |= STATUS_RF_KILL_HW;
1378 priv->status &= ~STATUS_RF_KILL_HW;
1380 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1383 static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
1386 /* 0 - RF kill not enabled
1387 1 - SW based RF kill active (sysfs)
1388 2 - HW based RF kill active
1389 3 - Both HW and SW baed RF kill active */
1390 struct ipw_priv *priv = d->driver_data;
1391 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
1392 (rf_kill_active(priv) ? 0x2 : 0x0);
1393 return sprintf(buf, "%i\n", val);
1396 static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1398 if ((disable_radio ? 1 : 0) ==
1399 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
1402 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1403 disable_radio ? "OFF" : "ON");
1405 if (disable_radio) {
1406 priv->status |= STATUS_RF_KILL_SW;
1408 if (priv->workqueue)
1409 cancel_delayed_work(&priv->request_scan);
1410 queue_work(priv->workqueue, &priv->down);
1412 priv->status &= ~STATUS_RF_KILL_SW;
1413 if (rf_kill_active(priv)) {
1414 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1415 "disabled by HW switch\n");
1416 /* Make sure the RF_KILL check timer is running */
1417 cancel_delayed_work(&priv->rf_kill);
1418 queue_delayed_work(priv->workqueue, &priv->rf_kill,
1421 queue_work(priv->workqueue, &priv->up);
1427 static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1428 const char *buf, size_t count)
1430 struct ipw_priv *priv = d->driver_data;
1432 ipw_radio_kill_sw(priv, buf[0] == '1');
1437 static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
1439 static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1442 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1443 int pos = 0, len = 0;
1444 if (priv->config & CFG_SPEED_SCAN) {
1445 while (priv->speed_scan[pos] != 0)
1446 len += sprintf(&buf[len], "%d ",
1447 priv->speed_scan[pos++]);
1448 return len + sprintf(&buf[len], "\n");
1451 return sprintf(buf, "0\n");
1454 static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1455 const char *buf, size_t count)
1457 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1458 int channel, pos = 0;
1459 const char *p = buf;
1461 /* list of space separated channels to scan, optionally ending with 0 */
1462 while ((channel = simple_strtol(p, NULL, 0))) {
1463 if (pos == MAX_SPEED_SCAN - 1) {
1464 priv->speed_scan[pos] = 0;
1468 if (ieee80211_is_valid_channel(priv->ieee, channel))
1469 priv->speed_scan[pos++] = channel;
1471 IPW_WARNING("Skipping invalid channel request: %d\n",
1476 while (*p == ' ' || *p == '\t')
1481 priv->config &= ~CFG_SPEED_SCAN;
1483 priv->speed_scan_pos = 0;
1484 priv->config |= CFG_SPEED_SCAN;
1490 static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1493 static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1496 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1497 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1500 static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1501 const char *buf, size_t count)
1503 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1505 priv->config |= CFG_NET_STATS;
1507 priv->config &= ~CFG_NET_STATS;
1512 static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO, show_net_stats,
1515 static void notify_wx_assoc_event(struct ipw_priv *priv)
1517 union iwreq_data wrqu;
1518 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1519 if (priv->status & STATUS_ASSOCIATED)
1520 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1522 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1523 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1526 static void ipw_irq_tasklet(struct ipw_priv *priv)
1528 u32 inta, inta_mask, handled = 0;
1529 unsigned long flags;
1532 spin_lock_irqsave(&priv->lock, flags);
1534 inta = ipw_read32(priv, IPW_INTA_RW);
1535 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1536 inta &= (IPW_INTA_MASK_ALL & inta_mask);
1538 /* Add any cached INTA values that need to be handled */
1539 inta |= priv->isr_inta;
1541 /* handle all the justifications for the interrupt */
1542 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
1544 handled |= IPW_INTA_BIT_RX_TRANSFER;
1547 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
1548 IPW_DEBUG_HC("Command completed.\n");
1549 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
1550 priv->status &= ~STATUS_HCMD_ACTIVE;
1551 wake_up_interruptible(&priv->wait_command_queue);
1552 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
1555 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
1556 IPW_DEBUG_TX("TX_QUEUE_1\n");
1557 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
1558 handled |= IPW_INTA_BIT_TX_QUEUE_1;
1561 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
1562 IPW_DEBUG_TX("TX_QUEUE_2\n");
1563 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
1564 handled |= IPW_INTA_BIT_TX_QUEUE_2;
1567 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
1568 IPW_DEBUG_TX("TX_QUEUE_3\n");
1569 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
1570 handled |= IPW_INTA_BIT_TX_QUEUE_3;
1573 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
1574 IPW_DEBUG_TX("TX_QUEUE_4\n");
1575 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
1576 handled |= IPW_INTA_BIT_TX_QUEUE_4;
1579 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
1580 IPW_WARNING("STATUS_CHANGE\n");
1581 handled |= IPW_INTA_BIT_STATUS_CHANGE;
1584 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
1585 IPW_WARNING("TX_PERIOD_EXPIRED\n");
1586 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
1589 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
1590 IPW_WARNING("HOST_CMD_DONE\n");
1591 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
1594 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
1595 IPW_WARNING("FW_INITIALIZATION_DONE\n");
1596 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
1599 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
1600 IPW_WARNING("PHY_OFF_DONE\n");
1601 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
1604 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
1605 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1606 priv->status |= STATUS_RF_KILL_HW;
1607 wake_up_interruptible(&priv->wait_command_queue);
1608 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1609 cancel_delayed_work(&priv->request_scan);
1610 schedule_work(&priv->link_down);
1611 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
1612 handled |= IPW_INTA_BIT_RF_KILL_DONE;
1615 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
1616 IPW_ERROR("Firmware error detected. Restarting.\n");
1617 #ifdef CONFIG_IPW_DEBUG
1618 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1619 ipw_dump_nic_error_log(priv);
1620 ipw_dump_nic_event_log(priv);
1623 /* XXX: If hardware encryption is for WPA/WPA2,
1624 * we have to notify the supplicant. */
1625 if (priv->ieee->sec.encrypt) {
1626 priv->status &= ~STATUS_ASSOCIATED;
1627 notify_wx_assoc_event(priv);
1630 /* Keep the restart process from trying to send host
1631 * commands by clearing the INIT status bit */
1632 priv->status &= ~STATUS_INIT;
1633 queue_work(priv->workqueue, &priv->adapter_restart);
1634 handled |= IPW_INTA_BIT_FATAL_ERROR;
1637 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
1638 IPW_ERROR("Parity error\n");
1639 handled |= IPW_INTA_BIT_PARITY_ERROR;
1642 if (handled != inta) {
1643 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
1646 /* enable all interrupts */
1647 ipw_enable_interrupts(priv);
1649 spin_unlock_irqrestore(&priv->lock, flags);
1652 #ifdef CONFIG_IPW_DEBUG
1653 #define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1654 static char *get_cmd_string(u8 cmd)
1657 IPW_CMD(HOST_COMPLETE);
1658 IPW_CMD(POWER_DOWN);
1659 IPW_CMD(SYSTEM_CONFIG);
1660 IPW_CMD(MULTICAST_ADDRESS);
1662 IPW_CMD(ADAPTER_ADDRESS);
1664 IPW_CMD(RTS_THRESHOLD);
1665 IPW_CMD(FRAG_THRESHOLD);
1666 IPW_CMD(POWER_MODE);
1668 IPW_CMD(TGI_TX_KEY);
1669 IPW_CMD(SCAN_REQUEST);
1670 IPW_CMD(SCAN_REQUEST_EXT);
1672 IPW_CMD(SUPPORTED_RATES);
1673 IPW_CMD(SCAN_ABORT);
1675 IPW_CMD(QOS_PARAMETERS);
1676 IPW_CMD(DINO_CONFIG);
1677 IPW_CMD(RSN_CAPABILITIES);
1679 IPW_CMD(CARD_DISABLE);
1680 IPW_CMD(SEED_NUMBER);
1682 IPW_CMD(COUNTRY_INFO);
1683 IPW_CMD(AIRONET_INFO);
1684 IPW_CMD(AP_TX_POWER);
1686 IPW_CMD(CCX_VER_INFO);
1687 IPW_CMD(SET_CALIBRATION);
1688 IPW_CMD(SENSITIVITY_CALIB);
1689 IPW_CMD(RETRY_LIMIT);
1690 IPW_CMD(IPW_PRE_POWER_DOWN);
1691 IPW_CMD(VAP_BEACON_TEMPLATE);
1692 IPW_CMD(VAP_DTIM_PERIOD);
1693 IPW_CMD(EXT_SUPPORTED_RATES);
1694 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
1695 IPW_CMD(VAP_QUIET_INTERVALS);
1696 IPW_CMD(VAP_CHANNEL_SWITCH);
1697 IPW_CMD(VAP_MANDATORY_CHANNELS);
1698 IPW_CMD(VAP_CELL_PWR_LIMIT);
1699 IPW_CMD(VAP_CF_PARAM_SET);
1700 IPW_CMD(VAP_SET_BEACONING_STATE);
1701 IPW_CMD(MEASUREMENT);
1702 IPW_CMD(POWER_CAPABILITY);
1703 IPW_CMD(SUPPORTED_CHANNELS);
1704 IPW_CMD(TPC_REPORT);
1706 IPW_CMD(PRODUCTION_COMMAND);
1713 #define HOST_COMPLETE_TIMEOUT HZ
1714 static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
1717 unsigned long flags;
1719 spin_lock_irqsave(&priv->lock, flags);
1720 if (priv->status & STATUS_HCMD_ACTIVE) {
1721 IPW_ERROR("Already sending a command\n");
1722 spin_unlock_irqrestore(&priv->lock, flags);
1726 priv->status |= STATUS_HCMD_ACTIVE;
1728 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
1729 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
1731 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
1733 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0);
1735 priv->status &= ~STATUS_HCMD_ACTIVE;
1736 spin_unlock_irqrestore(&priv->lock, flags);
1739 spin_unlock_irqrestore(&priv->lock, flags);
1741 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1743 status & STATUS_HCMD_ACTIVE),
1744 HOST_COMPLETE_TIMEOUT);
1746 spin_lock_irqsave(&priv->lock, flags);
1747 if (priv->status & STATUS_HCMD_ACTIVE) {
1748 IPW_DEBUG_INFO("Command completion failed out after "
1750 1000 * (HOST_COMPLETE_TIMEOUT / HZ));
1751 priv->status &= ~STATUS_HCMD_ACTIVE;
1752 spin_unlock_irqrestore(&priv->lock, flags);
1755 spin_unlock_irqrestore(&priv->lock, flags);
1758 if (priv->status & STATUS_RF_KILL_HW) {
1759 IPW_DEBUG_INFO("Command aborted due to RF Kill Switch\n");
1766 static int ipw_send_host_complete(struct ipw_priv *priv)
1768 struct host_cmd cmd = {
1769 .cmd = IPW_CMD_HOST_COMPLETE,
1774 IPW_ERROR("Invalid args\n");
1778 if (ipw_send_cmd(priv, &cmd)) {
1779 IPW_ERROR("failed to send HOST_COMPLETE command\n");
1786 static int ipw_send_system_config(struct ipw_priv *priv,
1787 struct ipw_sys_config *config)
1789 struct host_cmd cmd = {
1790 .cmd = IPW_CMD_SYSTEM_CONFIG,
1791 .len = sizeof(*config)
1794 if (!priv || !config) {
1795 IPW_ERROR("Invalid args\n");
1799 memcpy(&cmd.param, config, sizeof(*config));
1800 if (ipw_send_cmd(priv, &cmd)) {
1801 IPW_ERROR("failed to send SYSTEM_CONFIG command\n");
1808 static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
1810 struct host_cmd cmd = {
1811 .cmd = IPW_CMD_SSID,
1812 .len = min(len, IW_ESSID_MAX_SIZE)
1815 if (!priv || !ssid) {
1816 IPW_ERROR("Invalid args\n");
1820 memcpy(&cmd.param, ssid, cmd.len);
1821 if (ipw_send_cmd(priv, &cmd)) {
1822 IPW_ERROR("failed to send SSID command\n");
1829 static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
1831 struct host_cmd cmd = {
1832 .cmd = IPW_CMD_ADAPTER_ADDRESS,
1836 if (!priv || !mac) {
1837 IPW_ERROR("Invalid args\n");
1841 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
1842 priv->net_dev->name, MAC_ARG(mac));
1844 memcpy(&cmd.param, mac, ETH_ALEN);
1846 if (ipw_send_cmd(priv, &cmd)) {
1847 IPW_ERROR("failed to send ADAPTER_ADDRESS command\n");
1855 * NOTE: This must be executed from our workqueue as it results in udelay
1856 * being called which may corrupt the keyboard if executed on default
1859 static void ipw_adapter_restart(void *adapter)
1861 struct ipw_priv *priv = adapter;
1863 if (priv->status & STATUS_RF_KILL_MASK)
1868 if (priv->assoc_network &&
1869 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
1870 ipw_remove_current_network(priv);
1873 IPW_ERROR("Failed to up device\n");
1877 if ((priv->capability & CAP_PRIVACY_ON) &&
1878 (priv->ieee->sec.level == SEC_LEVEL_1) &&
1879 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
1880 ipw_set_hwcrypto_keys(priv);
1883 static void ipw_bg_adapter_restart(void *data)
1885 struct ipw_priv *priv = data;
1887 ipw_adapter_restart(data);
1891 #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
1893 static void ipw_scan_check(void *data)
1895 struct ipw_priv *priv = data;
1896 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
1897 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
1898 "adapter (%dms).\n",
1899 IPW_SCAN_CHECK_WATCHDOG / 100);
1900 queue_work(priv->workqueue, &priv->adapter_restart);
1904 static void ipw_bg_scan_check(void *data)
1906 struct ipw_priv *priv = data;
1908 ipw_scan_check(data);
1912 static int ipw_send_scan_request_ext(struct ipw_priv *priv,
1913 struct ipw_scan_request_ext *request)
1915 struct host_cmd cmd = {
1916 .cmd = IPW_CMD_SCAN_REQUEST_EXT,
1917 .len = sizeof(*request)
1920 memcpy(&cmd.param, request, sizeof(*request));
1921 if (ipw_send_cmd(priv, &cmd)) {
1922 IPW_ERROR("failed to send SCAN_REQUEST_EXT command\n");
1926 queue_delayed_work(priv->workqueue, &priv->scan_check,
1927 IPW_SCAN_CHECK_WATCHDOG);
1931 static int ipw_send_scan_abort(struct ipw_priv *priv)
1933 struct host_cmd cmd = {
1934 .cmd = IPW_CMD_SCAN_ABORT,
1939 IPW_ERROR("Invalid args\n");
1943 if (ipw_send_cmd(priv, &cmd)) {
1944 IPW_ERROR("failed to send SCAN_ABORT command\n");
1951 static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
1953 struct host_cmd cmd = {
1954 .cmd = IPW_CMD_SENSITIVITY_CALIB,
1955 .len = sizeof(struct ipw_sensitivity_calib)
1957 struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *)
1959 calib->beacon_rssi_raw = sens;
1960 if (ipw_send_cmd(priv, &cmd)) {
1961 IPW_ERROR("failed to send SENSITIVITY CALIB command\n");
1968 static int ipw_send_associate(struct ipw_priv *priv,
1969 struct ipw_associate *associate)
1971 struct host_cmd cmd = {
1972 .cmd = IPW_CMD_ASSOCIATE,
1973 .len = sizeof(*associate)
1976 struct ipw_associate tmp_associate;
1977 memcpy(&tmp_associate, associate, sizeof(*associate));
1978 tmp_associate.policy_support =
1979 cpu_to_le16(tmp_associate.policy_support);
1980 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
1981 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
1982 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
1983 tmp_associate.listen_interval =
1984 cpu_to_le16(tmp_associate.listen_interval);
1985 tmp_associate.beacon_interval =
1986 cpu_to_le16(tmp_associate.beacon_interval);
1987 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
1989 if (!priv || !associate) {
1990 IPW_ERROR("Invalid args\n");
1994 memcpy(&cmd.param, &tmp_associate, sizeof(*associate));
1995 if (ipw_send_cmd(priv, &cmd)) {
1996 IPW_ERROR("failed to send ASSOCIATE command\n");
2003 static int ipw_send_supported_rates(struct ipw_priv *priv,
2004 struct ipw_supported_rates *rates)
2006 struct host_cmd cmd = {
2007 .cmd = IPW_CMD_SUPPORTED_RATES,
2008 .len = sizeof(*rates)
2011 if (!priv || !rates) {
2012 IPW_ERROR("Invalid args\n");
2016 memcpy(&cmd.param, rates, sizeof(*rates));
2017 if (ipw_send_cmd(priv, &cmd)) {
2018 IPW_ERROR("failed to send SUPPORTED_RATES command\n");
2025 static int ipw_set_random_seed(struct ipw_priv *priv)
2027 struct host_cmd cmd = {
2028 .cmd = IPW_CMD_SEED_NUMBER,
2033 IPW_ERROR("Invalid args\n");
2037 get_random_bytes(&cmd.param, sizeof(u32));
2039 if (ipw_send_cmd(priv, &cmd)) {
2040 IPW_ERROR("failed to send SEED_NUMBER command\n");
2047 static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2049 struct host_cmd cmd = {
2050 .cmd = IPW_CMD_CARD_DISABLE,
2055 IPW_ERROR("Invalid args\n");
2059 *((u32 *) & cmd.param) = phy_off;
2061 if (ipw_send_cmd(priv, &cmd)) {
2062 IPW_ERROR("failed to send CARD_DISABLE command\n");
2069 static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
2071 struct host_cmd cmd = {
2072 .cmd = IPW_CMD_TX_POWER,
2073 .len = sizeof(*power)
2076 if (!priv || !power) {
2077 IPW_ERROR("Invalid args\n");
2081 memcpy(&cmd.param, power, sizeof(*power));
2082 if (ipw_send_cmd(priv, &cmd)) {
2083 IPW_ERROR("failed to send TX_POWER command\n");
2090 static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2092 struct ipw_rts_threshold rts_threshold = {
2093 .rts_threshold = rts,
2095 struct host_cmd cmd = {
2096 .cmd = IPW_CMD_RTS_THRESHOLD,
2097 .len = sizeof(rts_threshold)
2101 IPW_ERROR("Invalid args\n");
2105 memcpy(&cmd.param, &rts_threshold, sizeof(rts_threshold));
2106 if (ipw_send_cmd(priv, &cmd)) {
2107 IPW_ERROR("failed to send RTS_THRESHOLD command\n");
2114 static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2116 struct ipw_frag_threshold frag_threshold = {
2117 .frag_threshold = frag,
2119 struct host_cmd cmd = {
2120 .cmd = IPW_CMD_FRAG_THRESHOLD,
2121 .len = sizeof(frag_threshold)
2125 IPW_ERROR("Invalid args\n");
2129 memcpy(&cmd.param, &frag_threshold, sizeof(frag_threshold));
2130 if (ipw_send_cmd(priv, &cmd)) {
2131 IPW_ERROR("failed to send FRAG_THRESHOLD command\n");
2138 static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2140 struct host_cmd cmd = {
2141 .cmd = IPW_CMD_POWER_MODE,
2144 u32 *param = (u32 *) (&cmd.param);
2147 IPW_ERROR("Invalid args\n");
2151 /* If on battery, set to 3, if AC set to CAM, else user
2154 case IPW_POWER_BATTERY:
2155 *param = IPW_POWER_INDEX_3;
2158 *param = IPW_POWER_MODE_CAM;
2165 if (ipw_send_cmd(priv, &cmd)) {
2166 IPW_ERROR("failed to send POWER_MODE command\n");
2174 * The IPW device contains a Microwire compatible EEPROM that stores
2175 * various data like the MAC address. Usually the firmware has exclusive
2176 * access to the eeprom, but during device initialization (before the
2177 * device driver has sent the HostComplete command to the firmware) the
2178 * device driver has read access to the EEPROM by way of indirect addressing
2179 * through a couple of memory mapped registers.
2181 * The following is a simplified implementation for pulling data out of the
2182 * the eeprom, along with some helper functions to find information in
2183 * the per device private data's copy of the eeprom.
2185 * NOTE: To better understand how these functions work (i.e what is a chip
2186 * select and why do have to keep driving the eeprom clock?), read
2187 * just about any data sheet for a Microwire compatible EEPROM.
2190 /* write a 32 bit value into the indirect accessor register */
2191 static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2193 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
2195 /* the eeprom requires some time to complete the operation */
2196 udelay(p->eeprom_delay);
2201 /* perform a chip select operation */
2202 static inline void eeprom_cs(struct ipw_priv *priv)
2204 eeprom_write_reg(priv, 0);
2205 eeprom_write_reg(priv, EEPROM_BIT_CS);
2206 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2207 eeprom_write_reg(priv, EEPROM_BIT_CS);
2210 /* perform a chip select operation */
2211 static inline void eeprom_disable_cs(struct ipw_priv *priv)
2213 eeprom_write_reg(priv, EEPROM_BIT_CS);
2214 eeprom_write_reg(priv, 0);
2215 eeprom_write_reg(priv, EEPROM_BIT_SK);
2218 /* push a single bit down to the eeprom */
2219 static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
2221 int d = (bit ? EEPROM_BIT_DI : 0);
2222 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2223 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
2226 /* push an opcode followed by an address down to the eeprom */
2227 static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
2232 eeprom_write_bit(priv, 1);
2233 eeprom_write_bit(priv, op & 2);
2234 eeprom_write_bit(priv, op & 1);
2235 for (i = 7; i >= 0; i--) {
2236 eeprom_write_bit(priv, addr & (1 << i));
2240 /* pull 16 bits off the eeprom, one bit at a time */
2241 static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
2246 /* Send READ Opcode */
2247 eeprom_op(priv, EEPROM_CMD_READ, addr);
2249 /* Send dummy bit */
2250 eeprom_write_reg(priv, EEPROM_BIT_CS);
2252 /* Read the byte off the eeprom one bit at a time */
2253 for (i = 0; i < 16; i++) {
2255 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2256 eeprom_write_reg(priv, EEPROM_BIT_CS);
2257 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2258 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
2261 /* Send another dummy bit */
2262 eeprom_write_reg(priv, 0);
2263 eeprom_disable_cs(priv);
2268 /* helper function for pulling the mac address out of the private */
2269 /* data's copy of the eeprom data */
2270 static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
2272 u8 *ee = (u8 *) priv->eeprom;
2273 memcpy(mac, &ee[EEPROM_MAC_ADDRESS], 6);
2277 * Either the device driver (i.e. the host) or the firmware can
2278 * load eeprom data into the designated region in SRAM. If neither
2279 * happens then the FW will shutdown with a fatal error.
2281 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2282 * bit needs region of shared SRAM needs to be non-zero.
2284 static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2287 u16 *eeprom = (u16 *) priv->eeprom;
2289 IPW_DEBUG_TRACE(">>\n");
2291 /* read entire contents of eeprom into private buffer */
2292 for (i = 0; i < 128; i++)
2293 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
2296 If the data looks correct, then copy it to our private
2297 copy. Otherwise let the firmware know to perform the operation
2300 if ((priv->eeprom + EEPROM_VERSION) != 0) {
2301 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2303 /* write the eeprom data to sram */
2304 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
2305 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
2307 /* Do not load eeprom data on fatal error or suspend */
2308 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2310 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2312 /* Load eeprom data on fatal error or suspend */
2313 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2316 IPW_DEBUG_TRACE("<<\n");
2319 static inline void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
2324 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
2326 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
2329 static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2331 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
2332 CB_NUMBER_OF_ELEMENTS_SMALL *
2333 sizeof(struct command_block));
2336 static int ipw_fw_dma_enable(struct ipw_priv *priv)
2337 { /* start dma engine but no transfers yet */
2339 IPW_DEBUG_FW(">> : \n");
2342 ipw_fw_dma_reset_command_blocks(priv);
2344 /* Write CB base address */
2345 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
2347 IPW_DEBUG_FW("<< : \n");
2351 static void ipw_fw_dma_abort(struct ipw_priv *priv)
2355 IPW_DEBUG_FW(">> :\n");
2357 //set the Stop and Abort bit
2358 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
2359 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2360 priv->sram_desc.last_cb_index = 0;
2362 IPW_DEBUG_FW("<< \n");
2365 static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2366 struct command_block *cb)
2369 IPW_SHARED_SRAM_DMA_CONTROL +
2370 (sizeof(struct command_block) * index);
2371 IPW_DEBUG_FW(">> :\n");
2373 ipw_write_indirect(priv, address, (u8 *) cb,
2374 (int)sizeof(struct command_block));
2376 IPW_DEBUG_FW("<< :\n");
2381 static int ipw_fw_dma_kick(struct ipw_priv *priv)
2386 IPW_DEBUG_FW(">> :\n");
2388 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
2389 ipw_fw_dma_write_command_block(priv, index,
2390 &priv->sram_desc.cb_list[index]);
2392 /* Enable the DMA in the CSR register */
2393 ipw_clear_bit(priv, IPW_RESET_REG,
2394 IPW_RESET_REG_MASTER_DISABLED |
2395 IPW_RESET_REG_STOP_MASTER);
2397 /* Set the Start bit. */
2398 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
2399 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2401 IPW_DEBUG_FW("<< :\n");
2405 static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2408 u32 register_value = 0;
2409 u32 cb_fields_address = 0;
2411 IPW_DEBUG_FW(">> :\n");
2412 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2413 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
2415 /* Read the DMA Controlor register */
2416 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2417 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
2419 /* Print the CB values */
2420 cb_fields_address = address;
2421 register_value = ipw_read_reg32(priv, cb_fields_address);
2422 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
2424 cb_fields_address += sizeof(u32);
2425 register_value = ipw_read_reg32(priv, cb_fields_address);
2426 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
2428 cb_fields_address += sizeof(u32);
2429 register_value = ipw_read_reg32(priv, cb_fields_address);
2430 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2433 cb_fields_address += sizeof(u32);
2434 register_value = ipw_read_reg32(priv, cb_fields_address);
2435 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
2437 IPW_DEBUG_FW(">> :\n");
2440 static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2442 u32 current_cb_address = 0;
2443 u32 current_cb_index = 0;
2445 IPW_DEBUG_FW("<< :\n");
2446 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2448 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
2449 sizeof(struct command_block);
2451 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
2452 current_cb_index, current_cb_address);
2454 IPW_DEBUG_FW(">> :\n");
2455 return current_cb_index;
2459 static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2463 int interrupt_enabled, int is_last)
2466 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
2467 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2469 struct command_block *cb;
2470 u32 last_cb_element = 0;
2472 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2473 src_address, dest_address, length);
2475 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2478 last_cb_element = priv->sram_desc.last_cb_index;
2479 cb = &priv->sram_desc.cb_list[last_cb_element];
2480 priv->sram_desc.last_cb_index++;
2482 /* Calculate the new CB control word */
2483 if (interrupt_enabled)
2484 control |= CB_INT_ENABLED;
2487 control |= CB_LAST_VALID;
2491 /* Calculate the CB Element's checksum value */
2492 cb->status = control ^ src_address ^ dest_address;
2494 /* Copy the Source and Destination addresses */
2495 cb->dest_addr = dest_address;
2496 cb->source_addr = src_address;
2498 /* Copy the Control Word last */
2499 cb->control = control;
2504 static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
2505 u32 src_phys, u32 dest_address, u32 length)
2507 u32 bytes_left = length;
2509 u32 dest_offset = 0;
2511 IPW_DEBUG_FW(">> \n");
2512 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2513 src_phys, dest_address, length);
2514 while (bytes_left > CB_MAX_LENGTH) {
2515 status = ipw_fw_dma_add_command_block(priv,
2516 src_phys + src_offset,
2519 CB_MAX_LENGTH, 0, 0);
2521 IPW_DEBUG_FW_INFO(": Failed\n");
2524 IPW_DEBUG_FW_INFO(": Added new cb\n");
2526 src_offset += CB_MAX_LENGTH;
2527 dest_offset += CB_MAX_LENGTH;
2528 bytes_left -= CB_MAX_LENGTH;
2531 /* add the buffer tail */
2532 if (bytes_left > 0) {
2534 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2535 dest_address + dest_offset,
2538 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2542 (": Adding new cb - the buffer tail\n");
2545 IPW_DEBUG_FW("<< \n");
2549 static int ipw_fw_dma_wait(struct ipw_priv *priv)
2551 u32 current_index = 0;
2554 IPW_DEBUG_FW(">> : \n");
2556 current_index = ipw_fw_dma_command_block_index(priv);
2557 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n",
2558 (int)priv->sram_desc.last_cb_index);
2560 while (current_index < priv->sram_desc.last_cb_index) {
2562 current_index = ipw_fw_dma_command_block_index(priv);
2566 if (watchdog > 400) {
2567 IPW_DEBUG_FW_INFO("Timeout\n");
2568 ipw_fw_dma_dump_command_block(priv);
2569 ipw_fw_dma_abort(priv);
2574 ipw_fw_dma_abort(priv);
2576 /*Disable the DMA in the CSR register */
2577 ipw_set_bit(priv, IPW_RESET_REG,
2578 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
2580 IPW_DEBUG_FW("<< dmaWaitSync \n");
2584 static void ipw_remove_current_network(struct ipw_priv *priv)
2586 struct list_head *element, *safe;
2587 struct ieee80211_network *network = NULL;
2588 unsigned long flags;
2590 spin_lock_irqsave(&priv->ieee->lock, flags);
2591 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2592 network = list_entry(element, struct ieee80211_network, list);
2593 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2595 list_add_tail(&network->list,
2596 &priv->ieee->network_free_list);
2599 spin_unlock_irqrestore(&priv->ieee->lock, flags);
2603 * Check that card is still alive.
2604 * Reads debug register from domain0.
2605 * If card is present, pre-defined value should
2609 * @return 1 if card is present, 0 otherwise
2611 static inline int ipw_alive(struct ipw_priv *priv)
2613 return ipw_read32(priv, 0x90) == 0xd55555d5;
2616 static inline int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2622 if ((ipw_read32(priv, addr) & mask) == mask)
2626 } while (i < timeout);
2631 /* These functions load the firmware and micro code for the operation of
2632 * the ipw hardware. It assumes the buffer has all the bits for the
2633 * image and the caller is handling the memory allocation and clean up.
2636 static int ipw_stop_master(struct ipw_priv *priv)
2640 IPW_DEBUG_TRACE(">> \n");
2641 /* stop master. typical delay - 0 */
2642 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
2644 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2645 IPW_RESET_REG_MASTER_DISABLED, 100);
2647 IPW_ERROR("stop master failed in 10ms\n");
2651 IPW_DEBUG_INFO("stop master %dms\n", rc);
2656 static void ipw_arc_release(struct ipw_priv *priv)
2658 IPW_DEBUG_TRACE(">> \n");
2661 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
2663 /* no one knows timing, for safety add some delay */
2677 #define IPW_FW_MAJOR_VERSION 2
2678 #define IPW_FW_MINOR_VERSION 3
2680 #define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
2681 #define IPW_FW_MAJOR(x) (x & 0xff)
2683 #define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | \
2684 IPW_FW_MAJOR_VERSION)
2686 #define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
2687 "." __stringify(IPW_FW_MINOR_VERSION) "-"
2689 #if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
2690 #define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
2692 #define IPW_FW_NAME(x) "ipw2200_" x ".fw"
2695 static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
2697 int rc = 0, i, addr;
2701 image = (u16 *) data;
2703 IPW_DEBUG_TRACE(">> \n");
2705 rc = ipw_stop_master(priv);
2710 // spin_lock_irqsave(&priv->lock, flags);
2712 for (addr = IPW_SHARED_LOWER_BOUND;
2713 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
2714 ipw_write32(priv, addr, 0);
2717 /* no ucode (yet) */
2718 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2719 /* destroy DMA queues */
2720 /* reset sequence */
2722 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
2723 ipw_arc_release(priv);
2724 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
2728 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
2731 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
2734 /* enable ucode store */
2735 ipw_write_reg8(priv, DINO_CONTROL_REG, 0x0);
2736 ipw_write_reg8(priv, DINO_CONTROL_REG, DINO_ENABLE_CS);
2742 * Do NOT set indirect address register once and then
2743 * store data to indirect data register in the loop.
2744 * It seems very reasonable, but in this case DINO do not
2745 * accept ucode. It is essential to set address each time.
2747 /* load new ipw uCode */
2748 for (i = 0; i < len / 2; i++)
2749 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
2750 cpu_to_le16(image[i]));
2753 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2754 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
2756 /* this is where the igx / win driver deveates from the VAP driver. */
2758 /* wait for alive response */
2759 for (i = 0; i < 100; i++) {
2760 /* poll for incoming data */
2761 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
2762 if (cr & DINO_RXFIFO_DATA)
2767 if (cr & DINO_RXFIFO_DATA) {
2768 /* alive_command_responce size is NOT multiple of 4 */
2769 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
2771 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
2772 response_buffer[i] =
2773 le32_to_cpu(ipw_read_reg32(priv,
2774 IPW_BASEBAND_RX_FIFO_READ));
2775 memcpy(&priv->dino_alive, response_buffer,
2776 sizeof(priv->dino_alive));
2777 if (priv->dino_alive.alive_command == 1
2778 && priv->dino_alive.ucode_valid == 1) {
2781 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2782 "of %02d/%02d/%02d %02d:%02d\n",
2783 priv->dino_alive.software_revision,
2784 priv->dino_alive.software_revision,
2785 priv->dino_alive.device_identifier,
2786 priv->dino_alive.device_identifier,
2787 priv->dino_alive.time_stamp[0],
2788 priv->dino_alive.time_stamp[1],
2789 priv->dino_alive.time_stamp[2],
2790 priv->dino_alive.time_stamp[3],
2791 priv->dino_alive.time_stamp[4]);
2793 IPW_DEBUG_INFO("Microcode is not alive\n");
2797 IPW_DEBUG_INFO("No alive response from DINO\n");
2801 /* disable DINO, otherwise for some reason
2802 firmware have problem getting alive resp. */
2803 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2805 // spin_unlock_irqrestore(&priv->lock, flags);
2810 static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
2814 struct fw_chunk *chunk;
2815 dma_addr_t shared_phys;
2818 IPW_DEBUG_TRACE("<< : \n");
2819 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
2824 memmove(shared_virt, data, len);
2827 rc = ipw_fw_dma_enable(priv);
2829 if (priv->sram_desc.last_cb_index > 0) {
2830 /* the DMA is already ready this would be a bug. */
2836 chunk = (struct fw_chunk *)(data + offset);
2837 offset += sizeof(struct fw_chunk);
2838 /* build DMA packet and queue up for sending */
2839 /* dma to chunk->address, the chunk->length bytes from data +
2842 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
2843 le32_to_cpu(chunk->address),
2844 le32_to_cpu(chunk->length));
2846 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
2850 offset += le32_to_cpu(chunk->length);
2851 } while (offset < len);
2853 /* Run the DMA and wait for the answer */
2854 rc = ipw_fw_dma_kick(priv);
2856 IPW_ERROR("dmaKick Failed\n");
2860 rc = ipw_fw_dma_wait(priv);
2862 IPW_ERROR("dmaWaitSync Failed\n");
2866 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
2871 static int ipw_stop_nic(struct ipw_priv *priv)
2876 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
2878 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2879 IPW_RESET_REG_MASTER_DISABLED, 500);
2881 IPW_ERROR("wait for reg master disabled failed\n");
2885 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
2890 static void ipw_start_nic(struct ipw_priv *priv)
2892 IPW_DEBUG_TRACE(">>\n");
2894 /* prvHwStartNic release ARC */
2895 ipw_clear_bit(priv, IPW_RESET_REG,
2896 IPW_RESET_REG_MASTER_DISABLED |
2897 IPW_RESET_REG_STOP_MASTER |
2898 CBD_RESET_REG_PRINCETON_RESET);
2900 /* enable power management */
2901 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
2902 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
2904 IPW_DEBUG_TRACE("<<\n");
2907 static int ipw_init_nic(struct ipw_priv *priv)
2911 IPW_DEBUG_TRACE(">>\n");
2914 /* set "initialization complete" bit to move adapter to D0 state */
2915 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
2917 /* low-level PLL activation */
2918 ipw_write32(priv, IPW_READ_INT_REGISTER,
2919 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
2921 /* wait for clock stabilization */
2922 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
2923 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
2925 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
2927 /* assert SW reset */
2928 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
2932 /* set "initialization complete" bit to move adapter to D0 state */
2933 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
2935 IPW_DEBUG_TRACE(">>\n");
2939 /* Call this function from process context, it will sleep in request_firmware.
2940 * Probe is an ok place to call this from.
2942 static int ipw_reset_nic(struct ipw_priv *priv)
2945 unsigned long flags;
2947 IPW_DEBUG_TRACE(">>\n");
2949 rc = ipw_init_nic(priv);
2951 spin_lock_irqsave(&priv->lock, flags);
2952 /* Clear the 'host command active' bit... */
2953 priv->status &= ~STATUS_HCMD_ACTIVE;
2954 wake_up_interruptible(&priv->wait_command_queue);
2955 spin_unlock_irqrestore(&priv->lock, flags);
2957 IPW_DEBUG_TRACE("<<\n");
2961 static int ipw_get_fw(struct ipw_priv *priv,
2962 const struct firmware **fw, const char *name)
2964 struct fw_header *header;
2967 /* ask firmware_class module to get the boot firmware off disk */
2968 rc = request_firmware(fw, name, &priv->pci_dev->dev);
2970 IPW_ERROR("%s load failed: Reason %d\n", name, rc);
2974 header = (struct fw_header *)(*fw)->data;
2975 if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) {
2976 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
2978 IPW_FW_MAJOR(le32_to_cpu(header->version)),
2979 IPW_FW_MAJOR_VERSION);
2983 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
2985 IPW_FW_MAJOR(le32_to_cpu(header->version)),
2986 IPW_FW_MINOR(le32_to_cpu(header->version)),
2987 (*fw)->size - sizeof(struct fw_header));
2991 #define IPW_RX_BUF_SIZE (3000)
2993 static inline void ipw_rx_queue_reset(struct ipw_priv *priv,
2994 struct ipw_rx_queue *rxq)
2996 unsigned long flags;
2999 spin_lock_irqsave(&rxq->lock, flags);
3001 INIT_LIST_HEAD(&rxq->rx_free);
3002 INIT_LIST_HEAD(&rxq->rx_used);
3004 /* Fill the rx_used queue with _all_ of the Rx buffers */
3005 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3006 /* In the reset function, these buffers may have been allocated
3007 * to an SKB, so we need to unmap and free potential storage */
3008 if (rxq->pool[i].skb != NULL) {
3009 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
3010 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
3011 dev_kfree_skb(rxq->pool[i].skb);
3012 rxq->pool[i].skb = NULL;
3014 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3017 /* Set us so that we have processed and used all buffers, but have
3018 * not restocked the Rx queue with fresh buffers */
3019 rxq->read = rxq->write = 0;
3020 rxq->processed = RX_QUEUE_SIZE - 1;
3021 rxq->free_count = 0;
3022 spin_unlock_irqrestore(&rxq->lock, flags);
3026 static int fw_loaded = 0;
3027 static const struct firmware *bootfw = NULL;
3028 static const struct firmware *firmware = NULL;
3029 static const struct firmware *ucode = NULL;
3032 static int ipw_load(struct ipw_priv *priv)
3035 const struct firmware *bootfw = NULL;
3036 const struct firmware *firmware = NULL;
3037 const struct firmware *ucode = NULL;
3039 int rc = 0, retries = 3;
3044 rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot"));
3048 switch (priv->ieee->iw_mode) {
3050 rc = ipw_get_fw(priv, &ucode,
3051 IPW_FW_NAME("ibss_ucode"));
3055 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss"));
3058 #ifdef CONFIG_IPW2200_MONITOR
3059 case IW_MODE_MONITOR:
3060 rc = ipw_get_fw(priv, &ucode,
3061 IPW_FW_NAME("sniffer_ucode"));
3065 rc = ipw_get_fw(priv, &firmware,
3066 IPW_FW_NAME("sniffer"));
3070 rc = ipw_get_fw(priv, &ucode, IPW_FW_NAME("bss_ucode"));
3074 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("bss"));
3090 priv->rxq = ipw_rx_queue_alloc(priv);
3092 ipw_rx_queue_reset(priv, priv->rxq);
3094 IPW_ERROR("Unable to initialize Rx queue\n");
3099 /* Ensure interrupts are disabled */
3100 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3101 priv->status &= ~STATUS_INT_ENABLED;
3103 /* ack pending interrupts */
3104 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3108 rc = ipw_reset_nic(priv);
3110 IPW_ERROR("Unable to reset NIC\n");
3114 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3115 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
3117 /* DMA the initial boot firmware into the device */
3118 rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
3119 bootfw->size - sizeof(struct fw_header));
3121 IPW_ERROR("Unable to load boot firmware\n");
3125 /* kick start the device */
3126 ipw_start_nic(priv);
3128 /* wait for the device to finish it's initial startup sequence */
3129 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3130 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3132 IPW_ERROR("device failed to boot initial fw image\n");
3135 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3137 /* ack fw init done interrupt */
3138 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3140 /* DMA the ucode into the device */
3141 rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
3142 ucode->size - sizeof(struct fw_header));
3144 IPW_ERROR("Unable to load ucode\n");
3151 /* DMA bss firmware into the device */
3152 rc = ipw_load_firmware(priv, firmware->data +
3153 sizeof(struct fw_header),
3154 firmware->size - sizeof(struct fw_header));
3156 IPW_ERROR("Unable to load firmware\n");
3160 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3162 rc = ipw_queue_reset(priv);
3164 IPW_ERROR("Unable to initialize queues\n");
3168 /* Ensure interrupts are disabled */
3169 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3170 /* ack pending interrupts */
3171 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3173 /* kick start the device */
3174 ipw_start_nic(priv);
3176 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
3178 IPW_WARNING("Parity error. Retrying init.\n");
3183 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3188 /* wait for the device */
3189 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3190 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3192 IPW_ERROR("device failed to start after 500ms\n");
3195 IPW_DEBUG_INFO("device response after %dms\n", rc);
3197 /* ack fw init done interrupt */
3198 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3200 /* read eeprom data and initialize the eeprom region of sram */
3201 priv->eeprom_delay = 1;
3202 ipw_eeprom_init_sram(priv);
3204 /* enable interrupts */
3205 ipw_enable_interrupts(priv);
3207 /* Ensure our queue has valid packets */
3208 ipw_rx_queue_replenish(priv);
3210 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
3212 /* ack pending interrupts */
3213 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3216 release_firmware(bootfw);
3217 release_firmware(ucode);
3218 release_firmware(firmware);
3224 ipw_rx_queue_free(priv, priv->rxq);
3227 ipw_tx_queue_free(priv);
3229 release_firmware(bootfw);
3231 release_firmware(ucode);
3233 release_firmware(firmware);
3236 bootfw = ucode = firmware = NULL;
3245 * Theory of operation
3247 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3248 * 2 empty entries always kept in the buffer to protect from overflow.
3250 * For Tx queue, there are low mark and high mark limits. If, after queuing
3251 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3252 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
3255 * The IPW operates with six queues, one receive queue in the device's
3256 * sram, one transmit queue for sending commands to the device firmware,
3257 * and four transmit queues for data.
3259 * The four transmit queues allow for performing quality of service (qos)
3260 * transmissions as per the 802.11 protocol. Currently Linux does not
3261 * provide a mechanism to the user for utilizing prioritized queues, so
3262 * we only utilize the first data transmit queue (queue1).
3266 * Driver allocates buffers of this size for Rx
3269 static inline int ipw_queue_space(const struct clx2_queue *q)
3271 int s = q->last_used - q->first_empty;
3274 s -= 2; /* keep some reserve to not confuse empty and full situations */
3280 static inline int ipw_queue_inc_wrap(int index, int n_bd)
3282 return (++index == n_bd) ? 0 : index;
3286 * Initialize common DMA queue structure
3288 * @param q queue to init
3289 * @param count Number of BD's to allocate. Should be power of 2
3290 * @param read_register Address for 'read' register
3291 * (not offset within BAR, full address)
3292 * @param write_register Address for 'write' register
3293 * (not offset within BAR, full address)
3294 * @param base_register Address for 'base' register
3295 * (not offset within BAR, full address)
3296 * @param size Address for 'size' register
3297 * (not offset within BAR, full address)
3299 static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
3300 int count, u32 read, u32 write, u32 base, u32 size)
3304 q->low_mark = q->n_bd / 4;
3305 if (q->low_mark < 4)
3308 q->high_mark = q->n_bd / 8;
3309 if (q->high_mark < 2)
3312 q->first_empty = q->last_used = 0;
3316 ipw_write32(priv, base, q->dma_addr);
3317 ipw_write32(priv, size, count);
3318 ipw_write32(priv, read, 0);
3319 ipw_write32(priv, write, 0);
3321 _ipw_read32(priv, 0x90);
3324 static int ipw_queue_tx_init(struct ipw_priv *priv,
3325 struct clx2_tx_queue *q,
3326 int count, u32 read, u32 write, u32 base, u32 size)
3328 struct pci_dev *dev = priv->pci_dev;
3330 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3332 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3337 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
3339 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
3340 sizeof(q->bd[0]) * count);
3346 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3351 * Free one TFD, those at index [txq->q.last_used].
3352 * Do NOT advance any indexes
3357 static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3358 struct clx2_tx_queue *txq)
3360 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3361 struct pci_dev *dev = priv->pci_dev;
3365 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3366 /* nothing to cleanup after for host commands */
3370 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3371 IPW_ERROR("Too many chunks: %i\n",
3372 le32_to_cpu(bd->u.data.num_chunks));
3373 /** @todo issue fatal error, it is quite serious situation */
3377 /* unmap chunks if any */
3378 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3379 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3380 le16_to_cpu(bd->u.data.chunk_len[i]),
3382 if (txq->txb[txq->q.last_used]) {
3383 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3384 txq->txb[txq->q.last_used] = NULL;
3390 * Deallocate DMA queue.
3392 * Empty queue by removing and destroying all BD's.
3398 static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
3400 struct clx2_queue *q = &txq->q;
3401 struct pci_dev *dev = priv->pci_dev;
3406 /* first, empty all BD's */
3407 for (; q->first_empty != q->last_used;
3408 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3409 ipw_queue_tx_free_tfd(priv, txq);
3412 /* free buffers belonging to queue itself */
3413 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
3417 /* 0 fill whole structure */
3418 memset(txq, 0, sizeof(*txq));
3422 * Destroy all DMA queues and structures
3426 static void ipw_tx_queue_free(struct ipw_priv *priv)
3429 ipw_queue_tx_free(priv, &priv->txq_cmd);
3432 ipw_queue_tx_free(priv, &priv->txq[0]);
3433 ipw_queue_tx_free(priv, &priv->txq[1]);
3434 ipw_queue_tx_free(priv, &priv->txq[2]);
3435 ipw_queue_tx_free(priv, &priv->txq[3]);
3438 static void inline __maybe_wake_tx(struct ipw_priv *priv)
3440 if (netif_running(priv->net_dev)) {
3441 switch (priv->port_type) {
3442 case DCR_TYPE_MU_BSS:
3443 case DCR_TYPE_MU_IBSS:
3444 if (!(priv->status & STATUS_ASSOCIATED))
3447 netif_wake_queue(priv->net_dev);
3452 static inline void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
3454 /* First 3 bytes are manufacturer */
3455 bssid[0] = priv->mac_addr[0];
3456 bssid[1] = priv->mac_addr[1];
3457 bssid[2] = priv->mac_addr[2];
3459 /* Last bytes are random */
3460 get_random_bytes(&bssid[3], ETH_ALEN - 3);
3462 bssid[0] &= 0xfe; /* clear multicast bit */
3463 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
3466 static inline u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
3468 struct ipw_station_entry entry;
3471 for (i = 0; i < priv->num_stations; i++) {
3472 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3473 /* Another node is active in network */
3474 priv->missed_adhoc_beacons = 0;
3475 if (!(priv->config & CFG_STATIC_CHANNEL))
3476 /* when other nodes drop out, we drop out */
3477 priv->config &= ~CFG_ADHOC_PERSIST;
3483 if (i == MAX_STATIONS)
3484 return IPW_INVALID_STATION;
3486 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3489 entry.support_mode = 0;
3490 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3491 memcpy(priv->stations[i], bssid, ETH_ALEN);
3492 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
3493 &entry, sizeof(entry));
3494 priv->num_stations++;
3499 static inline u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
3503 for (i = 0; i < priv->num_stations; i++)
3504 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
3507 return IPW_INVALID_STATION;
3510 static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3514 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))) {
3515 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3519 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3521 MAC_ARG(priv->assoc_request.bssid),
3522 priv->assoc_request.channel);
3524 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3525 priv->status |= STATUS_DISASSOCIATING;
3528 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3530 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
3531 err = ipw_send_associate(priv, &priv->assoc_request);
3533 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3540 static int ipw_disassociate(void *data)
3542 struct ipw_priv *priv = data;
3543 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3545 ipw_send_disassociate(data, 0);
3549 static void ipw_bg_disassociate(void *data)
3551 struct ipw_priv *priv = data;
3553 ipw_disassociate(data);
3557 struct ipw_status_code {
3562 static const struct ipw_status_code ipw_status_codes[] = {
3563 {0x00, "Successful"},
3564 {0x01, "Unspecified failure"},
3565 {0x0A, "Cannot support all requested capabilities in the "
3566 "Capability information field"},
3567 {0x0B, "Reassociation denied due to inability to confirm that "
3568 "association exists"},
3569 {0x0C, "Association denied due to reason outside the scope of this "
3572 "Responding station does not support the specified authentication "
3575 "Received an Authentication frame with authentication sequence "
3576 "transaction sequence number out of expected sequence"},
3577 {0x0F, "Authentication rejected because of challenge failure"},
3578 {0x10, "Authentication rejected due to timeout waiting for next "
3579 "frame in sequence"},
3580 {0x11, "Association denied because AP is unable to handle additional "
3581 "associated stations"},
3583 "Association denied due to requesting station not supporting all "
3584 "of the datarates in the BSSBasicServiceSet Parameter"},
3586 "Association denied due to requesting station not supporting "
3587 "short preamble operation"},
3589 "Association denied due to requesting station not supporting "
3592 "Association denied due to requesting station not supporting "
3595 "Association denied due to requesting station not supporting "
3596 "short slot operation"},
3598 "Association denied due to requesting station not supporting "
3599 "DSSS-OFDM operation"},
3600 {0x28, "Invalid Information Element"},
3601 {0x29, "Group Cipher is not valid"},
3602 {0x2A, "Pairwise Cipher is not valid"},
3603 {0x2B, "AKMP is not valid"},
3604 {0x2C, "Unsupported RSN IE version"},
3605 {0x2D, "Invalid RSN IE Capabilities"},
3606 {0x2E, "Cipher suite is rejected per security policy"},
3609 #ifdef CONFIG_IPW_DEBUG
3610 static const char *ipw_get_status_code(u16 status)
3613 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
3614 if (ipw_status_codes[i].status == (status & 0xff))
3615 return ipw_status_codes[i].reason;
3616 return "Unknown status value.";
3620 static void inline average_init(struct average *avg)
3622 memset(avg, 0, sizeof(*avg));
3625 static void inline average_add(struct average *avg, s16 val)
3627 avg->sum -= avg->entries[avg->pos];
3629 avg->entries[avg->pos++] = val;
3630 if (unlikely(avg->pos == AVG_ENTRIES)) {
3636 static s16 inline average_value(struct average *avg)
3638 if (!unlikely(avg->init)) {
3640 return avg->sum / avg->pos;
3644 return avg->sum / AVG_ENTRIES;
3647 static void ipw_reset_stats(struct ipw_priv *priv)
3649 u32 len = sizeof(u32);
3653 average_init(&priv->average_missed_beacons);
3654 average_init(&priv->average_rssi);
3655 average_init(&priv->average_noise);
3657 priv->last_rate = 0;
3658 priv->last_missed_beacons = 0;
3659 priv->last_rx_packets = 0;
3660 priv->last_tx_packets = 0;
3661 priv->last_tx_failures = 0;
3663 /* Firmware managed, reset only when NIC is restarted, so we have to
3664 * normalize on the current value */
3665 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
3666 &priv->last_rx_err, &len);
3667 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
3668 &priv->last_tx_failures, &len);
3670 /* Driver managed, reset with each association */
3671 priv->missed_adhoc_beacons = 0;
3672 priv->missed_beacons = 0;
3673 priv->tx_packets = 0;
3674 priv->rx_packets = 0;
3678 static inline u32 ipw_get_max_rate(struct ipw_priv *priv)
3681 u32 mask = priv->rates_mask;
3682 /* If currently associated in B mode, restrict the maximum
3683 * rate match to B rates */
3684 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3685 mask &= IEEE80211_CCK_RATES_MASK;
3687 /* TODO: Verify that the rate is supported by the current rates
3690 while (i && !(mask & i))
3693 case IEEE80211_CCK_RATE_1MB_MASK:
3695 case IEEE80211_CCK_RATE_2MB_MASK:
3697 case IEEE80211_CCK_RATE_5MB_MASK:
3699 case IEEE80211_OFDM_RATE_6MB_MASK:
3701 case IEEE80211_OFDM_RATE_9MB_MASK:
3703 case IEEE80211_CCK_RATE_11MB_MASK:
3705 case IEEE80211_OFDM_RATE_12MB_MASK:
3707 case IEEE80211_OFDM_RATE_18MB_MASK:
3709 case IEEE80211_OFDM_RATE_24MB_MASK:
3711 case IEEE80211_OFDM_RATE_36MB_MASK:
3713 case IEEE80211_OFDM_RATE_48MB_MASK:
3715 case IEEE80211_OFDM_RATE_54MB_MASK:
3719 if (priv->ieee->mode == IEEE_B)
3725 static u32 ipw_get_current_rate(struct ipw_priv *priv)
3727 u32 rate, len = sizeof(rate);
3730 if (!(priv->status & STATUS_ASSOCIATED))
3733 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
3734 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
3737 IPW_DEBUG_INFO("failed querying ordinals.\n");
3741 return ipw_get_max_rate(priv);
3744 case IPW_TX_RATE_1MB:
3746 case IPW_TX_RATE_2MB:
3748 case IPW_TX_RATE_5MB:
3750 case IPW_TX_RATE_6MB:
3752 case IPW_TX_RATE_9MB:
3754 case IPW_TX_RATE_11MB:
3756 case IPW_TX_RATE_12MB:
3758 case IPW_TX_RATE_18MB:
3760 case IPW_TX_RATE_24MB:
3762 case IPW_TX_RATE_36MB:
3764 case IPW_TX_RATE_48MB:
3766 case IPW_TX_RATE_54MB:
3773 #define IPW_STATS_INTERVAL (2 * HZ)
3774 static void ipw_gather_stats(struct ipw_priv *priv)
3776 u32 rx_err, rx_err_delta, rx_packets_delta;
3777 u32 tx_failures, tx_failures_delta, tx_packets_delta;
3778 u32 missed_beacons_percent, missed_beacons_delta;
3780 u32 len = sizeof(u32);
3782 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
3786 if (!(priv->status & STATUS_ASSOCIATED)) {
3791 /* Update the statistics */
3792 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
3793 &priv->missed_beacons, &len);
3794 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
3795 priv->last_missed_beacons = priv->missed_beacons;
3796 if (priv->assoc_request.beacon_interval) {
3797 missed_beacons_percent = missed_beacons_delta *
3798 (HZ * priv->assoc_request.beacon_interval) /
3799 (IPW_STATS_INTERVAL * 10);
3801 missed_beacons_percent = 0;
3803 average_add(&priv->average_missed_beacons, missed_beacons_percent);
3805 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
3806 rx_err_delta = rx_err - priv->last_rx_err;
3807 priv->last_rx_err = rx_err;
3809 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
3810 tx_failures_delta = tx_failures - priv->last_tx_failures;
3811 priv->last_tx_failures = tx_failures;
3813 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
3814 priv->last_rx_packets = priv->rx_packets;
3816 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
3817 priv->last_tx_packets = priv->tx_packets;
3819 /* Calculate quality based on the following:
3821 * Missed beacon: 100% = 0, 0% = 70% missed
3822 * Rate: 60% = 1Mbs, 100% = Max
3823 * Rx and Tx errors represent a straight % of total Rx/Tx
3824 * RSSI: 100% = > -50, 0% = < -80
3825 * Rx errors: 100% = 0, 0% = 50% missed
3827 * The lowest computed quality is used.
3830 #define BEACON_THRESHOLD 5
3831 beacon_quality = 100 - missed_beacons_percent;
3832 if (beacon_quality < BEACON_THRESHOLD)
3835 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
3836 (100 - BEACON_THRESHOLD);
3837 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
3838 beacon_quality, missed_beacons_percent);
3840 priv->last_rate = ipw_get_current_rate(priv);
3841 max_rate = ipw_get_max_rate(priv);
3842 rate_quality = priv->last_rate * 40 / max_rate + 60;
3843 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
3844 rate_quality, priv->last_rate / 1000000);
3846 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
3847 rx_quality = 100 - (rx_err_delta * 100) /
3848 (rx_packets_delta + rx_err_delta);
3851 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
3852 rx_quality, rx_err_delta, rx_packets_delta);
3854 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
3855 tx_quality = 100 - (tx_failures_delta * 100) /
3856 (tx_packets_delta + tx_failures_delta);
3859 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
3860 tx_quality, tx_failures_delta, tx_packets_delta);
3862 rssi = average_value(&priv->average_rssi);
3865 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
3866 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
3867 (priv->ieee->perfect_rssi - rssi) *
3868 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
3869 62 * (priv->ieee->perfect_rssi - rssi))) /
3870 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
3871 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
3872 if (signal_quality > 100)
3873 signal_quality = 100;
3874 else if (signal_quality < 1)
3877 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
3878 signal_quality, rssi);
3880 quality = min(beacon_quality,
3882 min(tx_quality, min(rx_quality, signal_quality))));
3883 if (quality == beacon_quality)
3884 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
3886 if (quality == rate_quality)
3887 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
3889 if (quality == tx_quality)
3890 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
3892 if (quality == rx_quality)
3893 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
3895 if (quality == signal_quality)
3896 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
3899 priv->quality = quality;
3901 queue_delayed_work(priv->workqueue, &priv->gather_stats,
3902 IPW_STATS_INTERVAL);
3905 static void ipw_bg_gather_stats(void *data)
3907 struct ipw_priv *priv = data;
3909 ipw_gather_stats(data);
3913 static inline void ipw_handle_missed_beacon(struct ipw_priv *priv,
3916 priv->notif_missed_beacons = missed_count;
3918 if (missed_count > priv->missed_beacon_threshold &&
3919 priv->status & STATUS_ASSOCIATED) {
3920 /* If associated and we've hit the missed
3921 * beacon threshold, disassociate, turn
3922 * off roaming, and abort any active scans */
3923 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
3925 "Missed beacon: %d - disassociate\n", missed_count);
3926 priv->status &= ~STATUS_ROAMING;
3927 if (priv->status & STATUS_SCANNING) {
3928 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
3930 "Aborting scan with missed beacon.\n");
3931 queue_work(priv->workqueue, &priv->abort_scan);
3934 queue_work(priv->workqueue, &priv->disassociate);
3938 if (priv->status & STATUS_ROAMING) {
3939 /* If we are currently roaming, then just
3940 * print a debug statement... */
3941 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3942 "Missed beacon: %d - roam in progress\n",
3947 if (missed_count > priv->roaming_threshold) {
3948 /* If we are not already roaming, set the ROAM
3949 * bit in the status and kick off a scan */
3950 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3951 "Missed beacon: %d - initiate "
3952 "roaming\n", missed_count);
3953 if (!(priv->status & STATUS_ROAMING)) {
3954 priv->status |= STATUS_ROAMING;
3955 if (!(priv->status & STATUS_SCANNING))
3956 queue_work(priv->workqueue,
3957 &priv->request_scan);
3962 if (priv->status & STATUS_SCANNING) {
3963 /* Stop scan to keep fw from getting
3964 * stuck (only if we aren't roaming --
3965 * otherwise we'll never scan more than 2 or 3
3967 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
3968 "Aborting scan with missed beacon.\n");
3969 queue_work(priv->workqueue, &priv->abort_scan);
3972 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
3977 * Handle host notification packet.
3978 * Called from interrupt routine
3980 static inline void ipw_rx_notification(struct ipw_priv *priv,
3981 struct ipw_rx_notification *notif)
3983 notif->size = le16_to_cpu(notif->size);
3985 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
3987 switch (notif->subtype) {
3988 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
3989 struct notif_association *assoc = ¬if->u.assoc;
3991 switch (assoc->state) {
3992 case CMAS_ASSOCIATED:{
3993 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3995 "associated: '%s' " MAC_FMT
3997 escape_essid(priv->essid,
3999 MAC_ARG(priv->bssid));
4001 switch (priv->ieee->iw_mode) {
4003 memcpy(priv->ieee->bssid,
4004 priv->bssid, ETH_ALEN);
4008 memcpy(priv->ieee->bssid,
4009 priv->bssid, ETH_ALEN);
4011 /* clear out the station table */
4012 priv->num_stations = 0;
4015 ("queueing adhoc check\n");
4016 queue_delayed_work(priv->
4026 priv->status &= ~STATUS_ASSOCIATING;
4027 priv->status |= STATUS_ASSOCIATED;
4029 #ifdef CONFIG_IPW_QOS
4030 if (priv->status & STATUS_AUTH) {
4033 ieee80211_assoc_response_frame)
4035 && (notif->size <= 2314)) {
4048 ieee80211_rx_mgt(priv->
4053 ¬if->u.raw, &stats);
4058 schedule_work(&priv->link_up);
4063 case CMAS_AUTHENTICATED:{
4065 status & (STATUS_ASSOCIATED |
4067 #ifdef CONFIG_IPW_DEBUG
4068 struct notif_authenticate *auth
4070 IPW_DEBUG(IPW_DL_NOTIF |
4073 "deauthenticated: '%s' "
4075 ": (0x%04X) - %s \n",
4080 MAC_ARG(priv->bssid),
4081 ntohs(auth->status),
4088 ~(STATUS_ASSOCIATING |
4092 schedule_work(&priv->link_down);
4096 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4098 "authenticated: '%s' " MAC_FMT
4100 escape_essid(priv->essid,
4102 MAC_ARG(priv->bssid));
4107 if (priv->status & STATUS_AUTH) {
4109 ieee80211_assoc_response
4113 ieee80211_assoc_response
4115 IPW_DEBUG(IPW_DL_NOTIF |
4118 "association failed (0x%04X): %s\n",
4119 ntohs(resp->status),
4125 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4127 "disassociated: '%s' " MAC_FMT
4129 escape_essid(priv->essid,
4131 MAC_ARG(priv->bssid));
4134 ~(STATUS_DISASSOCIATING |
4135 STATUS_ASSOCIATING |
4136 STATUS_ASSOCIATED | STATUS_AUTH);
4137 if (priv->assoc_network
4138 && (priv->assoc_network->
4140 WLAN_CAPABILITY_IBSS))
4141 ipw_remove_current_network
4144 schedule_work(&priv->link_down);
4149 case CMAS_RX_ASSOC_RESP:
4153 IPW_ERROR("assoc: unknown (%d)\n",
4161 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4162 struct notif_authenticate *auth = ¬if->u.auth;
4163 switch (auth->state) {
4164 case CMAS_AUTHENTICATED:
4165 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4166 "authenticated: '%s' " MAC_FMT " \n",
4167 escape_essid(priv->essid,
4169 MAC_ARG(priv->bssid));
4170 priv->status |= STATUS_AUTH;
4174 if (priv->status & STATUS_AUTH) {
4175 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4177 "authentication failed (0x%04X): %s\n",
4178 ntohs(auth->status),
4179 ipw_get_status_code(ntohs
4183 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4185 "deauthenticated: '%s' " MAC_FMT "\n",
4186 escape_essid(priv->essid,
4188 MAC_ARG(priv->bssid));
4190 priv->status &= ~(STATUS_ASSOCIATING |
4194 schedule_work(&priv->link_down);
4197 case CMAS_TX_AUTH_SEQ_1:
4198 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4199 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4201 case CMAS_RX_AUTH_SEQ_2:
4202 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4203 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4205 case CMAS_AUTH_SEQ_1_PASS:
4206 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4207 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4209 case CMAS_AUTH_SEQ_1_FAIL:
4210 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4211 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4213 case CMAS_TX_AUTH_SEQ_3:
4214 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4215 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4217 case CMAS_RX_AUTH_SEQ_4:
4218 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4219 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4221 case CMAS_AUTH_SEQ_2_PASS:
4222 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4223 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4225 case CMAS_AUTH_SEQ_2_FAIL:
4226 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4227 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4230 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4231 IPW_DL_ASSOC, "TX_ASSOC\n");
4233 case CMAS_RX_ASSOC_RESP:
4234 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4235 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
4238 case CMAS_ASSOCIATED:
4239 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4240 IPW_DL_ASSOC, "ASSOCIATED\n");
4243 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4250 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4251 struct notif_channel_result *x =
4252 ¬if->u.channel_result;
4254 if (notif->size == sizeof(*x)) {
4255 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4258 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4259 "(should be %zd)\n",
4260 notif->size, sizeof(*x));
4265 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4266 struct notif_scan_complete *x = ¬if->u.scan_complete;
4267 if (notif->size == sizeof(*x)) {
4269 ("Scan completed: type %d, %d channels, "
4270 "%d status\n", x->scan_type,
4271 x->num_channels, x->status);
4273 IPW_ERROR("Scan completed of wrong size %d "
4274 "(should be %zd)\n",
4275 notif->size, sizeof(*x));
4279 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4281 cancel_delayed_work(&priv->scan_check);
4283 if (priv->status & STATUS_EXIT_PENDING)
4286 priv->ieee->scans++;
4288 #ifdef CONFIG_IPW2200_MONITOR
4289 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
4290 queue_work(priv->workqueue,
4291 &priv->request_scan);
4294 #endif /* CONFIG_IPW2200_MONITOR */
4296 if (!(priv->status & (STATUS_ASSOCIATED |
4297 STATUS_ASSOCIATING |
4299 STATUS_DISASSOCIATING)))
4300 queue_work(priv->workqueue, &priv->associate);
4301 else if (priv->status & STATUS_ROAMING) {
4302 /* If a scan completed and we are in roam mode, then
4303 * the scan that completed was the one requested as a
4304 * result of entering roam... so, schedule the
4306 queue_work(priv->workqueue, &priv->roam);
4307 } else if (priv->status & STATUS_SCAN_PENDING)
4308 queue_work(priv->workqueue,
4309 &priv->request_scan);
4310 else if (priv->config & CFG_BACKGROUND_SCAN
4311 && priv->status & STATUS_ASSOCIATED)
4312 queue_delayed_work(priv->workqueue,
4313 &priv->request_scan, HZ);
4317 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4318 struct notif_frag_length *x = ¬if->u.frag_len;
4320 if (notif->size == sizeof(*x))
4321 IPW_ERROR("Frag length: %d\n",
4322 le16_to_cpu(x->frag_length));
4324 IPW_ERROR("Frag length of wrong size %d "
4325 "(should be %zd)\n",
4326 notif->size, sizeof(*x));
4330 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4331 struct notif_link_deterioration *x =
4332 ¬if->u.link_deterioration;
4333 if (notif->size == sizeof(*x)) {
4334 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4335 "link deterioration: '%s' " MAC_FMT
4336 " \n", escape_essid(priv->essid,
4338 MAC_ARG(priv->bssid));
4339 memcpy(&priv->last_link_deterioration, x,
4342 IPW_ERROR("Link Deterioration of wrong size %d "
4343 "(should be %zd)\n",
4344 notif->size, sizeof(*x));
4349 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4350 IPW_ERROR("Dino config\n");
4352 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
4353 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
4358 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4359 struct notif_beacon_state *x = ¬if->u.beacon_state;
4360 if (notif->size != sizeof(*x)) {
4362 ("Beacon state of wrong size %d (should "
4363 "be %zd)\n", notif->size, sizeof(*x));
4367 if (le32_to_cpu(x->state) ==
4368 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4369 ipw_handle_missed_beacon(priv,
4376 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4377 struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key;
4378 if (notif->size == sizeof(*x)) {
4379 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4380 "0x%02x station %d\n",
4381 x->key_state, x->security_type,
4387 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4388 notif->size, sizeof(*x));
4392 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4393 struct notif_calibration *x = ¬if->u.calibration;
4395 if (notif->size == sizeof(*x)) {
4396 memcpy(&priv->calib, x, sizeof(*x));
4397 IPW_DEBUG_INFO("TODO: Calibration\n");
4402 ("Calibration of wrong size %d (should be %zd)\n",
4403 notif->size, sizeof(*x));
4407 case HOST_NOTIFICATION_NOISE_STATS:{
4408 if (notif->size == sizeof(u32)) {
4410 (u8) (le32_to_cpu(notif->u.noise.value) &
4412 average_add(&priv->average_noise,
4418 ("Noise stat is wrong size %d (should be %zd)\n",
4419 notif->size, sizeof(u32));
4424 IPW_ERROR("Unknown notification: "
4425 "subtype=%d,flags=0x%2x,size=%d\n",
4426 notif->subtype, notif->flags, notif->size);
4431 * Destroys all DMA structures and initialise them again
4434 * @return error code
4436 static int ipw_queue_reset(struct ipw_priv *priv)
4439 /** @todo customize queue sizes */
4440 int nTx = 64, nTxCmd = 8;
4441 ipw_tx_queue_free(priv);
4443 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
4444 IPW_TX_CMD_QUEUE_READ_INDEX,
4445 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4446 IPW_TX_CMD_QUEUE_BD_BASE,
4447 IPW_TX_CMD_QUEUE_BD_SIZE);
4449 IPW_ERROR("Tx Cmd queue init failed\n");
4453 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
4454 IPW_TX_QUEUE_0_READ_INDEX,
4455 IPW_TX_QUEUE_0_WRITE_INDEX,
4456 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
4458 IPW_ERROR("Tx 0 queue init failed\n");
4461 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
4462 IPW_TX_QUEUE_1_READ_INDEX,
4463 IPW_TX_QUEUE_1_WRITE_INDEX,
4464 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
4466 IPW_ERROR("Tx 1 queue init failed\n");
4469 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
4470 IPW_TX_QUEUE_2_READ_INDEX,
4471 IPW_TX_QUEUE_2_WRITE_INDEX,
4472 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
4474 IPW_ERROR("Tx 2 queue init failed\n");
4477 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
4478 IPW_TX_QUEUE_3_READ_INDEX,
4479 IPW_TX_QUEUE_3_WRITE_INDEX,
4480 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
4482 IPW_ERROR("Tx 3 queue init failed\n");
4486 priv->rx_bufs_min = 0;
4487 priv->rx_pend_max = 0;
4491 ipw_tx_queue_free(priv);
4496 * Reclaim Tx queue entries no more used by NIC.
4498 * When FW adwances 'R' index, all entries between old and
4499 * new 'R' index need to be reclaimed. As result, some free space
4500 * forms. If there is enough free space (> low mark), wake Tx queue.
4502 * @note Need to protect against garbage in 'R' index
4506 * @return Number of used entries remains in the queue
4508 static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
4509 struct clx2_tx_queue *txq, int qindex)
4513 struct clx2_queue *q = &txq->q;
4515 hw_tail = ipw_read32(priv, q->reg_r);
4516 if (hw_tail >= q->n_bd) {
4518 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4522 for (; q->last_used != hw_tail;
4523 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4524 ipw_queue_tx_free_tfd(priv, txq);
4528 if (ipw_queue_space(q) > q->low_mark && qindex >= 0)
4529 __maybe_wake_tx(priv);
4530 used = q->first_empty - q->last_used;
4537 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4540 struct clx2_tx_queue *txq = &priv->txq_cmd;
4541 struct clx2_queue *q = &txq->q;
4542 struct tfd_frame *tfd;
4544 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4545 IPW_ERROR("No space for Tx\n");
4549 tfd = &txq->bd[q->first_empty];
4550 txq->txb[q->first_empty] = NULL;
4552 memset(tfd, 0, sizeof(*tfd));
4553 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4554 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4556 tfd->u.cmd.index = hcmd;
4557 tfd->u.cmd.length = len;
4558 memcpy(tfd->u.cmd.payload, buf, len);
4559 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4560 ipw_write32(priv, q->reg_w, q->first_empty);
4561 _ipw_read32(priv, 0x90);
4567 * Rx theory of operation
4569 * The host allocates 32 DMA target addresses and passes the host address
4570 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
4574 * The host/firmware share two index registers for managing the Rx buffers.
4576 * The READ index maps to the first position that the firmware may be writing
4577 * to -- the driver can read up to (but not including) this position and get
4579 * The READ index is managed by the firmware once the card is enabled.
4581 * The WRITE index maps to the last position the driver has read from -- the
4582 * position preceding WRITE is the last slot the firmware can place a packet.
4584 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
4587 * During initialization the host sets up the READ queue position to the first
4588 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4590 * When the firmware places a packet in a buffer it will advance the READ index
4591 * and fire the RX interrupt. The driver can then query the READ index and
4592 * process as many packets as possible, moving the WRITE index forward as it
4593 * resets the Rx queue buffers with new memory.
4595 * The management in the driver is as follows:
4596 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
4597 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
4598 * to replensish the ipw->rxq->rx_free.
4599 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4600 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4601 * 'processed' and 'read' driver indexes as well)
4602 * + A received packet is processed and handed to the kernel network stack,
4603 * detached from the ipw->rxq. The driver 'processed' index is updated.
4604 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
4605 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4606 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
4607 * were enough free buffers and RX_STALLED is set it is cleared.
4612 * ipw_rx_queue_alloc() Allocates rx_free
4613 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4614 * ipw_rx_queue_restock
4615 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4616 * queue, updates firmware pointers, and updates
4617 * the WRITE index. If insufficient rx_free buffers
4618 * are available, schedules ipw_rx_queue_replenish
4620 * -- enable interrupts --
4621 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
4622 * READ INDEX, detaching the SKB from the pool.
4623 * Moves the packet buffer from queue to rx_used.
4624 * Calls ipw_rx_queue_restock to refill any empty
4631 * If there are slots in the RX queue that need to be restocked,
4632 * and we have free pre-allocated buffers, fill the ranks as much
4633 * as we can pulling from rx_free.
4635 * This moves the 'write' index forward to catch up with 'processed', and
4636 * also updates the memory address in the firmware to reference the new
4639 static void ipw_rx_queue_restock(struct ipw_priv *priv)
4641 struct ipw_rx_queue *rxq = priv->rxq;
4642 struct list_head *element;
4643 struct ipw_rx_mem_buffer *rxb;
4644 unsigned long flags;
4647 spin_lock_irqsave(&rxq->lock, flags);
4649 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4650 element = rxq->rx_free.next;
4651 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4654 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
4656 rxq->queue[rxq->write] = rxb;
4657 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4660 spin_unlock_irqrestore(&rxq->lock, flags);
4662 /* If the pre-allocated buffer pool is dropping low, schedule to
4664 if (rxq->free_count <= RX_LOW_WATERMARK)
4665 queue_work(priv->workqueue, &priv->rx_replenish);
4667 /* If we've added more space for the firmware to place data, tell it */
4668 if (write != rxq->write)
4669 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
4673 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
4674 * Also restock the Rx queue via ipw_rx_queue_restock.
4676 * This is called as a scheduled work item (except for during intialization)
4678 static void ipw_rx_queue_replenish(void *data)
4680 struct ipw_priv *priv = data;
4681 struct ipw_rx_queue *rxq = priv->rxq;
4682 struct list_head *element;
4683 struct ipw_rx_mem_buffer *rxb;
4684 unsigned long flags;
4686 spin_lock_irqsave(&rxq->lock, flags);
4687 while (!list_empty(&rxq->rx_used)) {
4688 element = rxq->rx_used.next;
4689 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4690 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
4692 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
4693 priv->net_dev->name);
4694 /* We don't reschedule replenish work here -- we will
4695 * call the restock method and if it still needs
4696 * more buffers it will schedule replenish */
4701 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
4703 pci_map_single(priv->pci_dev, rxb->skb->data,
4704 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4706 list_add_tail(&rxb->list, &rxq->rx_free);
4709 spin_unlock_irqrestore(&rxq->lock, flags);
4711 ipw_rx_queue_restock(priv);
4714 static void ipw_bg_rx_queue_replenish(void *data)
4716 struct ipw_priv *priv = data;
4718 ipw_rx_queue_replenish(data);
4722 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4723 * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
4724 * This free routine walks the list of POOL entries and if SKB is set to
4725 * non NULL it is unmapped and freed
4727 static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
4734 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4735 if (rxq->pool[i].skb != NULL) {
4736 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
4737 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4738 dev_kfree_skb(rxq->pool[i].skb);
4745 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4747 struct ipw_rx_queue *rxq;
4750 rxq = (struct ipw_rx_queue *)kmalloc(sizeof(*rxq), GFP_KERNEL);
4751 if (unlikely(!rxq)) {
4752 IPW_ERROR("memory allocation failed\n");
4755 memset(rxq, 0, sizeof(*rxq));
4756 spin_lock_init(&rxq->lock);
4757 INIT_LIST_HEAD(&rxq->rx_free);
4758 INIT_LIST_HEAD(&rxq->rx_used);
4760 /* Fill the rx_used queue with _all_ of the Rx buffers */
4761 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
4762 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4764 /* Set us so that we have processed and used all buffers, but have
4765 * not restocked the Rx queue with fresh buffers */
4766 rxq->read = rxq->write = 0;
4767 rxq->processed = RX_QUEUE_SIZE - 1;
4768 rxq->free_count = 0;
4773 static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
4775 rate &= ~IEEE80211_BASIC_RATE_MASK;
4776 if (ieee_mode == IEEE_A) {
4778 case IEEE80211_OFDM_RATE_6MB:
4779 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
4781 case IEEE80211_OFDM_RATE_9MB:
4782 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
4784 case IEEE80211_OFDM_RATE_12MB:
4786 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
4787 case IEEE80211_OFDM_RATE_18MB:
4789 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
4790 case IEEE80211_OFDM_RATE_24MB:
4792 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
4793 case IEEE80211_OFDM_RATE_36MB:
4795 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
4796 case IEEE80211_OFDM_RATE_48MB:
4798 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
4799 case IEEE80211_OFDM_RATE_54MB:
4801 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
4809 case IEEE80211_CCK_RATE_1MB:
4810 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
4811 case IEEE80211_CCK_RATE_2MB:
4812 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
4813 case IEEE80211_CCK_RATE_5MB:
4814 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
4815 case IEEE80211_CCK_RATE_11MB:
4816 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
4819 /* If we are limited to B modulations, bail at this point */
4820 if (ieee_mode == IEEE_B)
4825 case IEEE80211_OFDM_RATE_6MB:
4826 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
4827 case IEEE80211_OFDM_RATE_9MB:
4828 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
4829 case IEEE80211_OFDM_RATE_12MB:
4830 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
4831 case IEEE80211_OFDM_RATE_18MB:
4832 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
4833 case IEEE80211_OFDM_RATE_24MB:
4834 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
4835 case IEEE80211_OFDM_RATE_36MB:
4836 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
4837 case IEEE80211_OFDM_RATE_48MB:
4838 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
4839 case IEEE80211_OFDM_RATE_54MB:
4840 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
4846 static int ipw_compatible_rates(struct ipw_priv *priv,
4847 const struct ieee80211_network *network,
4848 struct ipw_supported_rates *rates)
4852 memset(rates, 0, sizeof(*rates));
4853 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
4854 rates->num_rates = 0;
4855 for (i = 0; i < num_rates; i++) {
4856 if (!ipw_is_rate_in_mask(priv, network->mode,
4857 network->rates[i])) {
4859 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
4860 IPW_DEBUG_SCAN("Adding masked mandatory "
4863 rates->supported_rates[rates->num_rates++] =
4868 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4869 network->rates[i], priv->rates_mask);
4873 rates->supported_rates[rates->num_rates++] = network->rates[i];
4876 num_rates = min(network->rates_ex_len,
4877 (u8) (IPW_MAX_RATES - num_rates));
4878 for (i = 0; i < num_rates; i++) {
4879 if (!ipw_is_rate_in_mask(priv, network->mode,
4880 network->rates_ex[i])) {
4881 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
4882 IPW_DEBUG_SCAN("Adding masked mandatory "
4884 network->rates_ex[i]);
4885 rates->supported_rates[rates->num_rates++] =
4890 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4891 network->rates_ex[i], priv->rates_mask);
4895 rates->supported_rates[rates->num_rates++] =
4896 network->rates_ex[i];
4902 static inline void ipw_copy_rates(struct ipw_supported_rates *dest,
4903 const struct ipw_supported_rates *src)
4906 for (i = 0; i < src->num_rates; i++)
4907 dest->supported_rates[i] = src->supported_rates[i];
4908 dest->num_rates = src->num_rates;
4911 /* TODO: Look at sniffed packets in the air to determine if the basic rate
4912 * mask should ever be used -- right now all callers to add the scan rates are
4913 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
4914 static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
4915 u8 modulation, u32 rate_mask)
4917 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
4918 IEEE80211_BASIC_RATE_MASK : 0;
4920 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
4921 rates->supported_rates[rates->num_rates++] =
4922 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
4924 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
4925 rates->supported_rates[rates->num_rates++] =
4926 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
4928 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
4929 rates->supported_rates[rates->num_rates++] = basic_mask |
4930 IEEE80211_CCK_RATE_5MB;
4932 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
4933 rates->supported_rates[rates->num_rates++] = basic_mask |
4934 IEEE80211_CCK_RATE_11MB;
4937 static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
4938 u8 modulation, u32 rate_mask)
4940 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
4941 IEEE80211_BASIC_RATE_MASK : 0;
4943 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
4944 rates->supported_rates[rates->num_rates++] = basic_mask |
4945 IEEE80211_OFDM_RATE_6MB;
4947 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
4948 rates->supported_rates[rates->num_rates++] =
4949 IEEE80211_OFDM_RATE_9MB;
4951 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
4952 rates->supported_rates[rates->num_rates++] = basic_mask |
4953 IEEE80211_OFDM_RATE_12MB;
4955 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
4956 rates->supported_rates[rates->num_rates++] =
4957 IEEE80211_OFDM_RATE_18MB;
4959 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
4960 rates->supported_rates[rates->num_rates++] = basic_mask |
4961 IEEE80211_OFDM_RATE_24MB;
4963 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
4964 rates->supported_rates[rates->num_rates++] =
4965 IEEE80211_OFDM_RATE_36MB;
4967 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
4968 rates->supported_rates[rates->num_rates++] =
4969 IEEE80211_OFDM_RATE_48MB;
4971 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
4972 rates->supported_rates[rates->num_rates++] =
4973 IEEE80211_OFDM_RATE_54MB;
4976 struct ipw_network_match {
4977 struct ieee80211_network *network;
4978 struct ipw_supported_rates rates;
4981 static int ipw_find_adhoc_network(struct ipw_priv *priv,
4982 struct ipw_network_match *match,
4983 struct ieee80211_network *network,
4986 struct ipw_supported_rates rates;
4988 /* Verify that this network's capability is compatible with the
4989 * current mode (AdHoc or Infrastructure) */
4990 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
4991 !(network->capability & WLAN_CAPABILITY_IBSS))) {
4992 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
4993 "capability mismatch.\n",
4994 escape_essid(network->ssid, network->ssid_len),
4995 MAC_ARG(network->bssid));
4999 /* If we do not have an ESSID for this AP, we can not associate with
5001 if (network->flags & NETWORK_EMPTY_ESSID) {
5002 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5003 "because of hidden ESSID.\n",
5004 escape_essid(network->ssid, network->ssid_len),
5005 MAC_ARG(network->bssid));
5009 if (unlikely(roaming)) {
5010 /* If we are roaming, then ensure check if this is a valid
5011 * network to try and roam to */
5012 if ((network->ssid_len != match->network->ssid_len) ||
5013 memcmp(network->ssid, match->network->ssid,
5014 network->ssid_len)) {
5015 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5016 "because of non-network ESSID.\n",
5017 escape_essid(network->ssid,
5019 MAC_ARG(network->bssid));
5023 /* If an ESSID has been configured then compare the broadcast
5025 if ((priv->config & CFG_STATIC_ESSID) &&
5026 ((network->ssid_len != priv->essid_len) ||
5027 memcmp(network->ssid, priv->essid,
5028 min(network->ssid_len, priv->essid_len)))) {
5029 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5031 escape_essid(network->ssid, network->ssid_len),
5033 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5034 "because of ESSID mismatch: '%s'.\n",
5035 escaped, MAC_ARG(network->bssid),
5036 escape_essid(priv->essid,
5042 /* If the old network rate is better than this one, don't bother
5043 * testing everything else. */
5045 if (network->time_stamp[0] < match->network->time_stamp[0]) {
5047 ("Network '%s excluded because newer than current network.\n",
5048 escape_essid(match->network->ssid,
5049 match->network->ssid_len));
5051 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
5053 ("Network '%s excluded because newer than current network.\n",
5054 escape_essid(match->network->ssid,
5055 match->network->ssid_len));
5059 /* Now go through and see if the requested network is valid... */
5060 if (priv->ieee->scan_age != 0 &&
5061 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5062 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5063 "because of age: %lums.\n",
5064 escape_essid(network->ssid, network->ssid_len),
5065 MAC_ARG(network->bssid),
5066 (jiffies - network->last_scanned) / (HZ / 100));
5070 if ((priv->config & CFG_STATIC_CHANNEL) &&
5071 (network->channel != priv->channel)) {
5072 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5073 "because of channel mismatch: %d != %d.\n",
5074 escape_essid(network->ssid, network->ssid_len),
5075 MAC_ARG(network->bssid),
5076 network->channel, priv->channel);
5080 /* Verify privacy compatability */
5081 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5082 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5083 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5084 "because of privacy mismatch: %s != %s.\n",
5085 escape_essid(network->ssid, network->ssid_len),
5086 MAC_ARG(network->bssid),
5087 priv->capability & CAP_PRIVACY_ON ? "on" :
5089 network->capability &
5090 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
5094 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5095 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5096 "because of the same BSSID match: " MAC_FMT
5097 ".\n", escape_essid(network->ssid,
5099 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5103 /* Filter out any incompatible freq / mode combinations */
5104 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5105 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5106 "because of invalid frequency/mode "
5108 escape_essid(network->ssid, network->ssid_len),
5109 MAC_ARG(network->bssid));
5113 /* Ensure that the rates supported by the driver are compatible with
5114 * this AP, including verification of basic rates (mandatory) */
5115 if (!ipw_compatible_rates(priv, network, &rates)) {
5116 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5117 "because configured rate mask excludes "
5118 "AP mandatory rate.\n",
5119 escape_essid(network->ssid, network->ssid_len),
5120 MAC_ARG(network->bssid));
5124 if (rates.num_rates == 0) {
5125 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5126 "because of no compatible rates.\n",
5127 escape_essid(network->ssid, network->ssid_len),
5128 MAC_ARG(network->bssid));
5132 /* TODO: Perform any further minimal comparititive tests. We do not
5133 * want to put too much policy logic here; intelligent scan selection
5134 * should occur within a generic IEEE 802.11 user space tool. */
5136 /* Set up 'new' AP to this network */
5137 ipw_copy_rates(&match->rates, &rates);
5138 match->network = network;
5139 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5140 escape_essid(network->ssid, network->ssid_len),
5141 MAC_ARG(network->bssid));
5146 static void ipw_merge_adhoc_network(void *data)
5148 struct ipw_priv *priv = data;
5149 struct ieee80211_network *network = NULL;
5150 struct ipw_network_match match = {
5151 .network = priv->assoc_network
5154 if ((priv->status & STATUS_ASSOCIATED)
5155 && (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5156 /* First pass through ROAM process -- look for a better
5158 unsigned long flags;
5160 spin_lock_irqsave(&priv->ieee->lock, flags);
5161 list_for_each_entry(network, &priv->ieee->network_list, list) {
5162 if (network != priv->assoc_network)
5163 ipw_find_adhoc_network(priv, &match, network,
5166 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5168 if (match.network == priv->assoc_network) {
5169 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5175 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5176 IPW_DEBUG_MERGE("remove network %s\n",
5177 escape_essid(priv->essid,
5179 ipw_remove_current_network(priv);
5182 ipw_disassociate(priv);
5183 priv->assoc_network = match.network;
5190 static int ipw_best_network(struct ipw_priv *priv,
5191 struct ipw_network_match *match,
5192 struct ieee80211_network *network, int roaming)
5194 struct ipw_supported_rates rates;
5196 /* Verify that this network's capability is compatible with the
5197 * current mode (AdHoc or Infrastructure) */
5198 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
5199 !(network->capability & WLAN_CAPABILITY_ESS)) ||
5200 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5201 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5202 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
5203 "capability mismatch.\n",
5204 escape_essid(network->ssid, network->ssid_len),
5205 MAC_ARG(network->bssid));
5209 /* If we do not have an ESSID for this AP, we can not associate with
5211 if (network->flags & NETWORK_EMPTY_ESSID) {
5212 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5213 "because of hidden ESSID.\n",
5214 escape_essid(network->ssid, network->ssid_len),
5215 MAC_ARG(network->bssid));
5219 if (unlikely(roaming)) {
5220 /* If we are roaming, then ensure check if this is a valid
5221 * network to try and roam to */
5222 if ((network->ssid_len != match->network->ssid_len) ||
5223 memcmp(network->ssid, match->network->ssid,
5224 network->ssid_len)) {
5225 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5226 "because of non-network ESSID.\n",
5227 escape_essid(network->ssid,
5229 MAC_ARG(network->bssid));
5233 /* If an ESSID has been configured then compare the broadcast
5235 if ((priv->config & CFG_STATIC_ESSID) &&
5236 ((network->ssid_len != priv->essid_len) ||
5237 memcmp(network->ssid, priv->essid,
5238 min(network->ssid_len, priv->essid_len)))) {
5239 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5241 escape_essid(network->ssid, network->ssid_len),
5243 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5244 "because of ESSID mismatch: '%s'.\n",
5245 escaped, MAC_ARG(network->bssid),
5246 escape_essid(priv->essid,
5252 /* If the old network rate is better than this one, don't bother
5253 * testing everything else. */
5254 if (match->network && match->network->stats.rssi > network->stats.rssi) {
5255 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5257 escape_essid(network->ssid, network->ssid_len),
5259 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5260 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5261 escaped, MAC_ARG(network->bssid),
5262 escape_essid(match->network->ssid,
5263 match->network->ssid_len),
5264 MAC_ARG(match->network->bssid));
5268 /* If this network has already had an association attempt within the
5269 * last 3 seconds, do not try and associate again... */
5270 if (network->last_associate &&
5271 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
5272 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5273 "because of storming (%lu since last "
5274 "assoc attempt).\n",
5275 escape_essid(network->ssid, network->ssid_len),
5276 MAC_ARG(network->bssid),
5277 (jiffies - network->last_associate) / HZ);
5281 /* Now go through and see if the requested network is valid... */
5282 if (priv->ieee->scan_age != 0 &&
5283 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5284 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5285 "because of age: %lums.\n",
5286 escape_essid(network->ssid, network->ssid_len),
5287 MAC_ARG(network->bssid),
5288 (jiffies - network->last_scanned) / (HZ / 100));
5292 if ((priv->config & CFG_STATIC_CHANNEL) &&
5293 (network->channel != priv->channel)) {
5294 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5295 "because of channel mismatch: %d != %d.\n",
5296 escape_essid(network->ssid, network->ssid_len),
5297 MAC_ARG(network->bssid),
5298 network->channel, priv->channel);
5302 /* Verify privacy compatability */
5303 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5304 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5305 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5306 "because of privacy mismatch: %s != %s.\n",
5307 escape_essid(network->ssid, network->ssid_len),
5308 MAC_ARG(network->bssid),
5309 priv->capability & CAP_PRIVACY_ON ? "on" :
5311 network->capability &
5312 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
5316 if ((priv->config & CFG_STATIC_BSSID) &&
5317 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5318 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5319 "because of BSSID mismatch: " MAC_FMT ".\n",
5320 escape_essid(network->ssid, network->ssid_len),
5321 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5325 /* Filter out any incompatible freq / mode combinations */
5326 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5327 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5328 "because of invalid frequency/mode "
5330 escape_essid(network->ssid, network->ssid_len),
5331 MAC_ARG(network->bssid));
5335 /* Ensure that the rates supported by the driver are compatible with
5336 * this AP, including verification of basic rates (mandatory) */
5337 if (!ipw_compatible_rates(priv, network, &rates)) {
5338 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5339 "because configured rate mask excludes "
5340 "AP mandatory rate.\n",
5341 escape_essid(network->ssid, network->ssid_len),
5342 MAC_ARG(network->bssid));
5346 if (rates.num_rates == 0) {
5347 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5348 "because of no compatible rates.\n",
5349 escape_essid(network->ssid, network->ssid_len),
5350 MAC_ARG(network->bssid));
5354 /* TODO: Perform any further minimal comparititive tests. We do not
5355 * want to put too much policy logic here; intelligent scan selection
5356 * should occur within a generic IEEE 802.11 user space tool. */
5358 /* Set up 'new' AP to this network */
5359 ipw_copy_rates(&match->rates, &rates);
5360 match->network = network;
5362 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5363 escape_essid(network->ssid, network->ssid_len),
5364 MAC_ARG(network->bssid));
5369 static void ipw_adhoc_create(struct ipw_priv *priv,
5370 struct ieee80211_network *network)
5373 * For the purposes of scanning, we can set our wireless mode
5374 * to trigger scans across combinations of bands, but when it
5375 * comes to creating a new ad-hoc network, we have tell the FW
5376 * exactly which band to use.
5378 * We also have the possibility of an invalid channel for the
5379 * chossen band. Attempting to create a new ad-hoc network
5380 * with an invalid channel for wireless mode will trigger a
5383 if (!ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
5384 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
5385 IPW_WARNING("Overriding invalid channel\n");
5386 if (priv->ieee->mode & IEEE_A) {
5387 network->mode = IEEE_A;
5388 priv->channel = geo->a[0].channel;
5389 } else if (priv->ieee->mode & IEEE_G) {
5390 network->mode = IEEE_G;
5391 priv->channel = geo->bg[0].channel;
5393 network->mode = IEEE_B;
5394 priv->channel = geo->bg[0].channel;
5397 network->mode = priv->ieee->mode;
5399 network->channel = priv->channel;
5400 priv->config |= CFG_ADHOC_PERSIST;
5401 ipw_create_bssid(priv, network->bssid);
5402 network->ssid_len = priv->essid_len;
5403 memcpy(network->ssid, priv->essid, priv->essid_len);
5404 memset(&network->stats, 0, sizeof(network->stats));
5405 network->capability = WLAN_CAPABILITY_IBSS;
5406 if (!(priv->config & CFG_PREAMBLE_LONG))
5407 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
5408 if (priv->capability & CAP_PRIVACY_ON)
5409 network->capability |= WLAN_CAPABILITY_PRIVACY;
5410 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
5411 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
5412 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
5413 memcpy(network->rates_ex,
5414 &priv->rates.supported_rates[network->rates_len],
5415 network->rates_ex_len);
5416 network->last_scanned = 0;
5418 network->last_associate = 0;
5419 network->time_stamp[0] = 0;
5420 network->time_stamp[1] = 0;
5421 network->beacon_interval = 100; /* Default */
5422 network->listen_interval = 10; /* Default */
5423 network->atim_window = 0; /* Default */
5424 network->wpa_ie_len = 0;
5425 network->rsn_ie_len = 0;
5428 static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5430 struct ipw_tgi_tx_key *key;
5431 struct host_cmd cmd = {
5432 .cmd = IPW_CMD_TGI_TX_KEY,
5436 if (!(priv->ieee->sec.flags & (1 << index)))
5439 key = (struct ipw_tgi_tx_key *)&cmd.param;
5440 key->key_id = index;
5441 memcpy(key->key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5442 key->security_type = type;
5443 key->station_index = 0; /* always 0 for BSS */
5445 /* 0 for new key; previous value of counter (after fatal error) */
5446 key->tx_counter[0] = 0;
5447 key->tx_counter[1] = 0;
5449 if (ipw_send_cmd(priv, &cmd)) {
5450 IPW_ERROR("failed to send TGI_TX_KEY command\n");
5455 static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
5457 struct ipw_wep_key *key;
5459 struct host_cmd cmd = {
5460 .cmd = IPW_CMD_WEP_KEY,
5464 key = (struct ipw_wep_key *)&cmd.param;
5465 key->cmd_id = DINO_CMD_WEP_KEY;
5468 /* Note: AES keys cannot be set for multiple times.
5469 * Only set it at the first time. */
5470 for (i = 0; i < 4; i++) {
5471 key->key_index = i | type;
5472 if (!(priv->ieee->sec.flags & (1 << i))) {
5477 key->key_size = priv->ieee->sec.key_sizes[i];
5478 memcpy(key->key, priv->ieee->sec.keys[i], key->key_size);
5480 if (ipw_send_cmd(priv, &cmd)) {
5481 IPW_ERROR("failed to send WEP_KEY command\n");
5487 static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5489 switch (priv->ieee->sec.level) {
5491 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5492 ipw_send_tgi_tx_key(priv,
5493 DCT_FLAG_EXT_SECURITY_CCM,
5494 priv->ieee->sec.active_key);
5495 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
5497 priv->sys_config.disable_unicast_decryption = 0;
5498 priv->sys_config.disable_multicast_decryption = 0;
5499 priv->ieee->host_decrypt = 0;
5500 if (ipw_send_system_config(priv, &priv->sys_config))
5501 IPW_ERROR("ipw_send_system_config failed\n");
5505 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5506 ipw_send_tgi_tx_key(priv,
5507 DCT_FLAG_EXT_SECURITY_TKIP,
5508 priv->ieee->sec.active_key);
5510 priv->sys_config.disable_unicast_decryption = 1;
5511 priv->sys_config.disable_multicast_decryption = 1;
5512 priv->ieee->host_decrypt = 1;
5513 if (ipw_send_system_config(priv, &priv->sys_config))
5514 IPW_ERROR("ipw_send_system_config failed\n");
5518 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
5520 priv->sys_config.disable_unicast_decryption = 0;
5521 priv->sys_config.disable_multicast_decryption = 0;
5522 priv->ieee->host_decrypt = 0;
5523 if (ipw_send_system_config(priv, &priv->sys_config))
5524 IPW_ERROR("ipw_send_system_config failed\n");
5533 static void ipw_adhoc_check(void *data)
5535 struct ipw_priv *priv = data;
5537 if (priv->missed_adhoc_beacons++ > priv->missed_beacon_threshold &&
5538 !(priv->config & CFG_ADHOC_PERSIST)) {
5539 IPW_DEBUG_SCAN("Disassociating due to missed beacons\n");
5540 ipw_remove_current_network(priv);
5541 ipw_disassociate(priv);
5545 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
5546 priv->assoc_request.beacon_interval);
5549 static void ipw_bg_adhoc_check(void *data)
5551 struct ipw_priv *priv = data;
5553 ipw_adhoc_check(data);
5557 #ifdef CONFIG_IPW_DEBUG
5558 static void ipw_debug_config(struct ipw_priv *priv)
5560 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5561 "[CFG 0x%08X]\n", priv->config);
5562 if (priv->config & CFG_STATIC_CHANNEL)
5563 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
5565 IPW_DEBUG_INFO("Channel unlocked.\n");
5566 if (priv->config & CFG_STATIC_ESSID)
5567 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
5568 escape_essid(priv->essid, priv->essid_len));
5570 IPW_DEBUG_INFO("ESSID unlocked.\n");
5571 if (priv->config & CFG_STATIC_BSSID)
5572 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5573 MAC_ARG(priv->bssid));
5575 IPW_DEBUG_INFO("BSSID unlocked.\n");
5576 if (priv->capability & CAP_PRIVACY_ON)
5577 IPW_DEBUG_INFO("PRIVACY on\n");
5579 IPW_DEBUG_INFO("PRIVACY off\n");
5580 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5583 #define ipw_debug_config(x) do {} while (0)
5586 static inline void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
5588 /* TODO: Verify that this works... */
5589 struct ipw_fixed_rate fr = {
5590 .tx_rates = priv->rates_mask
5595 /* Identify 'current FW band' and match it with the fixed
5598 switch (priv->ieee->freq_band) {
5599 case IEEE80211_52GHZ_BAND: /* A only */
5601 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5602 /* Invalid fixed rate mask */
5604 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5609 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5612 default: /* 2.4Ghz or Mixed */
5614 if (mode == IEEE_B) {
5615 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
5616 /* Invalid fixed rate mask */
5618 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5625 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5626 IEEE80211_OFDM_RATES_MASK)) {
5627 /* Invalid fixed rate mask */
5629 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5634 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
5635 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
5636 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
5639 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
5640 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
5641 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
5644 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
5645 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
5646 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
5649 fr.tx_rates |= mask;
5653 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
5654 ipw_write_reg32(priv, reg, *(u32 *) & fr);
5657 static void ipw_abort_scan(struct ipw_priv *priv)
5661 if (priv->status & STATUS_SCAN_ABORTING) {
5662 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5665 priv->status |= STATUS_SCAN_ABORTING;
5667 err = ipw_send_scan_abort(priv);
5669 IPW_DEBUG_HC("Request to abort scan failed.\n");
5672 static int ipw_request_scan(struct ipw_priv *priv)
5674 struct ipw_scan_request_ext scan;
5675 int channel_index = 0;
5676 int i, err = 0, scan_type;
5677 const struct ieee80211_geo *geo;
5678 #ifdef CONFIG_IPW2200_MONITOR
5684 geo = ieee80211_get_geo(priv->ieee);
5686 if (priv->status & STATUS_SCANNING) {
5687 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
5688 priv->status |= STATUS_SCAN_PENDING;
5692 if (priv->status & STATUS_SCAN_ABORTING) {
5693 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
5694 priv->status |= STATUS_SCAN_PENDING;
5698 if (priv->status & STATUS_RF_KILL_MASK) {
5699 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
5700 priv->status |= STATUS_SCAN_PENDING;
5704 memset(&scan, 0, sizeof(scan));
5706 if (priv->config & CFG_SPEED_SCAN)
5707 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
5710 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
5713 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
5715 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20);
5717 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
5719 #ifdef CONFIG_IPW2200_MONITOR
5720 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5723 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
5724 case IEEE80211_52GHZ_BAND:
5725 band = (u8) (IPW_A_MODE << 6) | 1;
5726 channel = priv->channel;
5729 case IEEE80211_24GHZ_BAND:
5730 band = (u8) (IPW_B_MODE << 6) | 1;
5731 channel = priv->channel;
5735 band = (u8) (IPW_B_MODE << 6) | 1;
5740 scan.channels_list[0] = band;
5741 scan.channels_list[1] = channel;
5742 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
5744 /* NOTE: The card will sit on this channel for this time
5745 * period. Scan aborts are timing sensitive and frequently
5746 * result in firmware restarts. As such, it is best to
5747 * set a small dwell_time here and just keep re-issuing
5748 * scans. Otherwise fast channel hopping will not actually
5751 * TODO: Move SPEED SCAN support to all modes and bands */
5752 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
5755 #endif /* CONFIG_IPW2200_MONITOR */
5756 /* If we are roaming, then make this a directed scan for the
5757 * current network. Otherwise, ensure that every other scan
5758 * is a fast channel hop scan */
5759 if ((priv->status & STATUS_ROAMING)
5760 || (!(priv->status & STATUS_ASSOCIATED)
5761 && (priv->config & CFG_STATIC_ESSID)
5762 && (le32_to_cpu(scan.full_scan_index) % 2))) {
5763 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
5765 IPW_DEBUG_HC("Attempt to send SSID command "
5770 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
5772 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
5775 /* Add channels to the scan list */
5776 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
5777 int start = channel_index;
5778 for (i = 0; i < geo->a_channels; i++) {
5779 if ((priv->status & STATUS_ASSOCIATED) &&
5780 geo->a[i].channel == priv->channel)
5783 scan.channels_list[channel_index] =
5785 ipw_set_scan_type(&scan, channel_index,
5789 if (start != channel_index) {
5790 scan.channels_list[start] =
5791 (u8) (IPW_A_MODE << 6) | (channel_index -
5797 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
5798 int start = channel_index;
5799 if (priv->config & CFG_SPEED_SCAN) {
5800 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
5801 /* nop out the list */
5806 while (channel_index < IPW_SCAN_CHANNELS) {
5808 priv->speed_scan[priv->
5811 priv->speed_scan_pos = 0;
5812 channel = priv->speed_scan[0];
5814 if ((priv->status & STATUS_ASSOCIATED)
5815 && channel == priv->channel) {
5816 priv->speed_scan_pos++;
5820 /* If this channel has already been
5821 * added in scan, break from loop
5822 * and this will be the first channel
5825 if (channels[channel - 1] != 0)
5828 channels[channel - 1] = 1;
5829 priv->speed_scan_pos++;
5831 scan.channels_list[channel_index] =
5833 ipw_set_scan_type(&scan, channel_index,
5837 for (i = 0; i < geo->bg_channels; i++) {
5838 if ((priv->status & STATUS_ASSOCIATED)
5839 && geo->bg[i].channel ==
5843 scan.channels_list[channel_index] =
5845 ipw_set_scan_type(&scan, channel_index,
5850 if (start != channel_index) {
5851 scan.channels_list[start] =
5852 (u8) (IPW_B_MODE << 6) | (channel_index -
5856 #ifdef CONFIG_IPW2200_MONITOR
5860 err = ipw_send_scan_request_ext(priv, &scan);
5862 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
5866 priv->status |= STATUS_SCANNING;
5867 priv->status &= ~STATUS_SCAN_PENDING;
5874 static void ipw_bg_abort_scan(void *data)
5876 struct ipw_priv *priv = data;
5878 ipw_abort_scan(data);
5882 /* Support for wpa_supplicant. Will be replaced with WEXT once
5883 * they get WPA support. */
5885 /* following definitions must match definitions in driver_ipw.c */
5887 #define IPW_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
5889 #define IPW_CMD_SET_WPA_PARAM 1
5890 #define IPW_CMD_SET_WPA_IE 2
5891 #define IPW_CMD_SET_ENCRYPTION 3
5892 #define IPW_CMD_MLME 4
5894 #define IPW_PARAM_WPA_ENABLED 1
5895 #define IPW_PARAM_TKIP_COUNTERMEASURES 2
5896 #define IPW_PARAM_DROP_UNENCRYPTED 3
5897 #define IPW_PARAM_PRIVACY_INVOKED 4
5898 #define IPW_PARAM_AUTH_ALGS 5
5899 #define IPW_PARAM_IEEE_802_1X 6
5901 #define IPW_MLME_STA_DEAUTH 1
5902 #define IPW_MLME_STA_DISASSOC 2
5904 #define IPW_CRYPT_ERR_UNKNOWN_ALG 2
5905 #define IPW_CRYPT_ERR_UNKNOWN_ADDR 3
5906 #define IPW_CRYPT_ERR_CRYPT_INIT_FAILED 4
5907 #define IPW_CRYPT_ERR_KEY_SET_FAILED 5
5908 #define IPW_CRYPT_ERR_TX_KEY_SET_FAILED 6
5909 #define IPW_CRYPT_ERR_CARD_CONF_FAILED 7
5911 #define IPW_CRYPT_ALG_NAME_LEN 16
5915 u8 sta_addr[ETH_ALEN];
5931 u8 alg[IPW_CRYPT_ALG_NAME_LEN];
5935 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
5943 /* end of driver_ipw.c code */
5945 static int ipw_wpa_enable(struct ipw_priv *priv, int value)
5947 /* This is called when wpa_supplicant loads and closes the driver
5952 #define AUTH_ALG_OPEN_SYSTEM 0x1
5953 #define AUTH_ALG_SHARED_KEY 0x2
5955 static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
5957 struct ieee80211_device *ieee = priv->ieee;
5958 struct ieee80211_security sec = {
5959 .flags = SEC_AUTH_MODE,
5963 if (value & AUTH_ALG_SHARED_KEY) {
5964 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
5967 sec.auth_mode = WLAN_AUTH_OPEN;
5971 if (ieee->set_security)
5972 ieee->set_security(ieee->dev, &sec);
5979 static int ipw_wpa_set_param(struct net_device *dev, u8 name, u32 value)
5981 struct ipw_priv *priv = ieee80211_priv(dev);
5982 struct ieee80211_crypt_data *crypt;
5983 unsigned long flags;
5987 case IPW_PARAM_WPA_ENABLED:
5988 ret = ipw_wpa_enable(priv, value);
5991 case IPW_PARAM_TKIP_COUNTERMEASURES:
5992 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
5993 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) {
5994 IPW_WARNING("Can't set TKIP countermeasures: "
5995 "crypt not set!\n");
5999 flags = crypt->ops->get_flags(crypt->priv);
6002 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6004 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6006 crypt->ops->set_flags(flags, crypt->priv);
6010 case IPW_PARAM_DROP_UNENCRYPTED:{
6013 * wpa_supplicant calls set_wpa_enabled when the driver
6014 * is loaded and unloaded, regardless of if WPA is being
6015 * used. No other calls are made which can be used to
6016 * determine if encryption will be used or not prior to
6017 * association being expected. If encryption is not being
6018 * used, drop_unencrypted is set to false, else true -- we
6019 * can use this to determine if the CAP_PRIVACY_ON bit should
6022 struct ieee80211_security sec = {
6023 .flags = SEC_ENABLED,
6026 priv->ieee->drop_unencrypted = value;
6027 /* We only change SEC_LEVEL for open mode. Others
6028 * are set by ipw_wpa_set_encryption.
6031 sec.flags |= SEC_LEVEL;
6032 sec.level = SEC_LEVEL_0;
6034 sec.flags |= SEC_LEVEL;
6035 sec.level = SEC_LEVEL_1;
6037 if (priv->ieee->set_security)
6038 priv->ieee->set_security(priv->ieee->dev, &sec);
6042 case IPW_PARAM_PRIVACY_INVOKED:
6043 priv->ieee->privacy_invoked = value;
6046 case IPW_PARAM_AUTH_ALGS:
6047 ret = ipw_wpa_set_auth_algs(priv, value);
6050 case IPW_PARAM_IEEE_802_1X:
6051 priv->ieee->ieee802_1x = value;
6055 IPW_ERROR("%s: Unknown WPA param: %d\n", dev->name, name);
6062 static int ipw_wpa_mlme(struct net_device *dev, int command, int reason)
6064 struct ipw_priv *priv = ieee80211_priv(dev);
6068 case IPW_MLME_STA_DEAUTH:
6072 case IPW_MLME_STA_DISASSOC:
6073 ipw_disassociate(priv);
6077 IPW_ERROR("%s: Unknown MLME request: %d\n", dev->name, command);
6084 static int ipw_set_rsn_capa(struct ipw_priv *priv,
6085 char *capabilities, int length)
6087 struct host_cmd cmd = {
6088 .cmd = IPW_CMD_RSN_CAPABILITIES,
6092 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6094 memcpy(&cmd.param, capabilities, length);
6095 if (ipw_send_cmd(priv, &cmd)) {
6096 IPW_ERROR("failed to send HOST_CMD_RSN_CAPABILITIES command\n");
6102 void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, int wpa_ie_len)
6104 /* make sure WPA is enabled */
6105 ipw_wpa_enable(priv, 1);
6107 ipw_disassociate(priv);
6110 static int ipw_wpa_set_wpa_ie(struct net_device *dev,
6111 struct ipw_param *param, int plen)
6113 struct ipw_priv *priv = ieee80211_priv(dev);
6114 struct ieee80211_device *ieee = priv->ieee;
6117 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
6118 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
6121 if (param->u.wpa_ie.len) {
6122 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
6126 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
6127 kfree(ieee->wpa_ie);
6129 ieee->wpa_ie_len = param->u.wpa_ie.len;
6131 kfree(ieee->wpa_ie);
6132 ieee->wpa_ie = NULL;
6133 ieee->wpa_ie_len = 0;
6136 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6140 /* implementation borrowed from hostap driver */
6142 static int ipw_wpa_set_encryption(struct net_device *dev,
6143 struct ipw_param *param, int param_len)
6146 struct ipw_priv *priv = ieee80211_priv(dev);
6147 struct ieee80211_device *ieee = priv->ieee;
6148 struct ieee80211_crypto_ops *ops;
6149 struct ieee80211_crypt_data **crypt;
6151 struct ieee80211_security sec = {
6155 param->u.crypt.err = 0;
6156 param->u.crypt.alg[IPW_CRYPT_ALG_NAME_LEN - 1] = '\0';
6159 (int)((char *)param->u.crypt.key - (char *)param) +
6160 param->u.crypt.key_len) {
6161 IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len,
6162 param->u.crypt.key_len);
6165 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
6166 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
6167 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
6168 if (param->u.crypt.idx >= WEP_KEYS)
6170 crypt = &ieee->crypt[param->u.crypt.idx];
6175 if (strcmp(param->u.crypt.alg, "none") == 0) {
6179 sec.level = SEC_LEVEL_0;
6180 sec.flags |= SEC_ENABLED | SEC_LEVEL;
6181 ieee80211_crypt_delayed_deinit(ieee, crypt);
6187 sec.flags |= SEC_ENABLED;
6189 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
6190 if (!(ieee->host_encrypt || ieee->host_decrypt) &&
6191 strcmp(param->u.crypt.alg, "TKIP"))
6192 goto skip_host_crypt;
6194 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6195 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
6196 request_module("ieee80211_crypt_wep");
6197 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6198 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
6199 request_module("ieee80211_crypt_tkip");
6200 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6201 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
6202 request_module("ieee80211_crypt_ccmp");
6203 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
6206 IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
6207 dev->name, param->u.crypt.alg);
6208 param->u.crypt.err = IPW_CRYPT_ERR_UNKNOWN_ALG;
6213 if (*crypt == NULL || (*crypt)->ops != ops) {
6214 struct ieee80211_crypt_data *new_crypt;
6216 ieee80211_crypt_delayed_deinit(ieee, crypt);
6218 new_crypt = (struct ieee80211_crypt_data *)
6219 kmalloc(sizeof(*new_crypt), GFP_KERNEL);
6220 if (new_crypt == NULL) {
6224 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
6225 new_crypt->ops = ops;
6226 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
6228 new_crypt->ops->init(param->u.crypt.idx);
6230 if (new_crypt->priv == NULL) {
6232 param->u.crypt.err = IPW_CRYPT_ERR_CRYPT_INIT_FAILED;
6240 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
6241 (*crypt)->ops->set_key(param->u.crypt.key,
6242 param->u.crypt.key_len, param->u.crypt.seq,
6243 (*crypt)->priv) < 0) {
6244 IPW_DEBUG_INFO("%s: key setting failed\n", dev->name);
6245 param->u.crypt.err = IPW_CRYPT_ERR_KEY_SET_FAILED;
6251 if (param->u.crypt.set_tx) {
6252 ieee->tx_keyidx = param->u.crypt.idx;
6253 sec.active_key = param->u.crypt.idx;
6254 sec.flags |= SEC_ACTIVE_KEY;
6256 sec.flags &= ~SEC_ACTIVE_KEY;
6258 if (param->u.crypt.alg != NULL) {
6259 memcpy(sec.keys[param->u.crypt.idx],
6260 param->u.crypt.key, param->u.crypt.key_len);
6261 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
6262 sec.flags |= (1 << param->u.crypt.idx);
6264 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
6265 sec.flags |= SEC_LEVEL;
6266 sec.level = SEC_LEVEL_1;
6267 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
6268 sec.flags |= SEC_LEVEL;
6269 sec.level = SEC_LEVEL_2;
6270 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
6271 sec.flags |= SEC_LEVEL;
6272 sec.level = SEC_LEVEL_3;
6276 if (ieee->set_security)
6277 ieee->set_security(ieee->dev, &sec);
6279 /* Do not reset port if card is in Managed mode since resetting will
6280 * generate new IEEE 802.11 authentication which may end up in looping
6281 * with IEEE 802.1X. If your hardware requires a reset after WEP
6282 * configuration (for example... Prism2), implement the reset_port in
6283 * the callbacks structures used to initialize the 802.11 stack. */
6284 if (ieee->reset_on_keychange &&
6285 ieee->iw_mode != IW_MODE_INFRA &&
6286 ieee->reset_port && ieee->reset_port(dev)) {
6287 IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
6288 param->u.crypt.err = IPW_CRYPT_ERR_CARD_CONF_FAILED;
6295 static int ipw_wpa_supplicant(struct net_device *dev, struct iw_point *p)
6297 struct ipw_param *param;
6300 IPW_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
6302 if (p->length < sizeof(struct ipw_param) || !p->pointer)
6305 param = (struct ipw_param *)kmalloc(p->length, GFP_KERNEL);
6309 if (copy_from_user(param, p->pointer, p->length)) {
6314 switch (param->cmd) {
6316 case IPW_CMD_SET_WPA_PARAM:
6317 ret = ipw_wpa_set_param(dev, param->u.wpa_param.name,
6318 param->u.wpa_param.value);
6321 case IPW_CMD_SET_WPA_IE:
6322 ret = ipw_wpa_set_wpa_ie(dev, param, p->length);
6325 case IPW_CMD_SET_ENCRYPTION:
6326 ret = ipw_wpa_set_encryption(dev, param, p->length);
6330 ret = ipw_wpa_mlme(dev, param->u.mlme.command,
6331 param->u.mlme.reason_code);
6335 IPW_ERROR("%s: Unknown WPA supplicant request: %d\n",
6336 dev->name, param->cmd);
6340 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
6347 #ifdef CONFIG_IPW_QOS
6351 * get the modulation type of the current network or
6352 * the card current mode
6354 u8 ipw_qos_current_mode(struct ipw_priv * priv)
6358 if (priv->status & STATUS_ASSOCIATED) {
6359 unsigned long flags;
6361 spin_lock_irqsave(&priv->ieee->lock, flags);
6362 mode = priv->assoc_network->mode;
6363 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6365 mode = priv->ieee->mode;
6367 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6372 * Handle management frame beacon and probe response
6374 static int ipw_qos_handle_probe_reponse(struct ipw_priv *priv,
6376 struct ieee80211_network *network)
6378 u32 size = sizeof(struct ieee80211_qos_parameters);
6380 if ((network->capability & WLAN_CAPABILITY_IBSS))
6381 network->qos_data.active = network->qos_data.supported;
6383 if (network->flags & NETWORK_HAS_QOS_MASK) {
6385 && (network->flags & NETWORK_HAS_QOS_PARAMETERS))
6386 network->qos_data.active = network->qos_data.supported;
6388 if ((network->qos_data.active == 1) && (active_network == 1) &&
6389 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6390 (network->qos_data.old_param_count !=
6391 network->qos_data.param_count)) {
6392 network->qos_data.old_param_count =
6393 network->qos_data.param_count;
6394 schedule_work(&priv->qos_activate);
6396 ("QoS parameters change call qos_activate\n");
6399 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B)) {
6400 memcpy(&(network->qos_data.parameters),
6401 &def_parameters_CCK, size);
6403 memcpy(&(network->qos_data.parameters),
6404 &def_parameters_OFDM, size);
6406 if ((network->qos_data.active == 1) && (active_network == 1)) {
6407 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6408 schedule_work(&priv->qos_activate);
6411 network->qos_data.active = 0;
6412 network->qos_data.supported = 0;
6414 if ((priv->status & STATUS_ASSOCIATED)
6415 && (priv->ieee->iw_mode == IW_MODE_ADHOC)
6416 && (active_network == 0)) {
6418 if (memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
6419 if ((network->capability & WLAN_CAPABILITY_IBSS)
6420 && !(network->flags & NETWORK_EMPTY_ESSID)) {
6421 if ((network->ssid_len ==
6422 priv->assoc_network->ssid_len)
6423 && !memcmp(network->ssid,
6424 priv->assoc_network->ssid,
6425 network->ssid_len)) {
6426 queue_work(priv->workqueue,
6427 &priv->merge_networks);
6438 * This function set up the firmware to support QoS. It sends
6439 * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6441 static int ipw_qos_activate(struct ipw_priv *priv,
6442 struct ieee80211_qos_data *qos_network_data)
6445 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6446 struct ieee80211_qos_parameters *active_one = NULL;
6447 u32 size = sizeof(struct ieee80211_qos_parameters);
6452 type = ipw_qos_current_mode(priv);
6454 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6455 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6456 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6457 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6459 if (qos_network_data == NULL) {
6460 if (type == IEEE_B) {
6461 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6462 active_one = &def_parameters_CCK;
6464 active_one = &def_parameters_OFDM;
6466 memcpy(&(qos_parameters[QOS_PARAM_SET_ACTIVE]), active_one,
6468 burst_duration = ipw_qos_get_burst_duration(priv);
6469 for (i = 0; i < QOS_QUEUE_NUM; i++)
6470 qos_parameters[QOS_PARAM_SET_ACTIVE].
6471 tx_op_limit[i] = (u16) burst_duration;
6472 } else if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
6473 if (type == IEEE_B) {
6474 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6476 if (priv->qos_data.qos_enable == 0)
6477 active_one = &def_parameters_CCK;
6479 active_one = priv->qos_data.def_qos_parm_CCK;
6481 if (priv->qos_data.qos_enable == 0)
6482 active_one = &def_parameters_OFDM;
6484 active_one = priv->qos_data.def_qos_parm_OFDM;
6486 memcpy(&(qos_parameters[QOS_PARAM_SET_ACTIVE]), active_one,
6489 unsigned long flags;
6492 spin_lock_irqsave(&priv->ieee->lock, flags);
6493 active_one = &(qos_network_data->parameters);
6494 qos_network_data->old_param_count =
6495 qos_network_data->param_count;
6496 memcpy(&(qos_parameters[QOS_PARAM_SET_ACTIVE]), active_one,
6498 active = qos_network_data->supported;
6499 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6502 burst_duration = ipw_qos_get_burst_duration(priv);
6503 for (i = 0; i < QOS_QUEUE_NUM; i++)
6504 qos_parameters[QOS_PARAM_SET_ACTIVE].
6505 tx_op_limit[i] = (u16) burst_duration;
6509 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
6511 ipw_send_qos_params_command(priv,
6512 (struct ieee80211_qos_parameters *)
6513 &(qos_parameters[0]));
6515 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6521 * send IPW_CMD_WME_INFO to the firmware
6523 static int ipw_qos_set_info_element(struct ipw_priv *priv)
6526 struct ieee80211_qos_information_element qos_info;
6531 qos_info.elementID = QOS_ELEMENT_ID;
6532 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6534 qos_info.version = QOS_VERSION_1;
6535 qos_info.ac_info = 0;
6537 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6538 qos_info.qui_type = QOS_OUI_TYPE;
6539 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6541 ret = ipw_send_qos_info_command(priv, &qos_info);
6543 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6549 * Set the QoS parameter with the association request structure
6551 static int ipw_qos_association(struct ipw_priv *priv,
6552 struct ieee80211_network *network)
6555 struct ieee80211_qos_data *qos_data = NULL;
6556 struct ieee80211_qos_data ibss_data = {
6561 switch (priv->ieee->iw_mode) {
6563 if (!(network->capability & WLAN_CAPABILITY_IBSS))
6566 qos_data = &ibss_data;
6570 qos_data = &network->qos_data;
6578 err = ipw_qos_activate(priv, qos_data);
6580 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6584 if (priv->qos_data.qos_enable && qos_data->supported) {
6585 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6586 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6587 return ipw_qos_set_info_element(priv);
6594 * handling the beaconing responces. if we get different QoS setting
6595 * of the network from the the associated setting adjust the QoS
6598 static int ipw_qos_association_resp(struct ipw_priv *priv,
6599 struct ieee80211_network *network)
6602 unsigned long flags;
6603 u32 size = sizeof(struct ieee80211_qos_parameters);
6604 int set_qos_param = 0;
6606 if ((priv == NULL) || (network == NULL)
6607 || (priv->assoc_network == NULL))
6611 if (!(priv->status & STATUS_ASSOCIATED))
6614 if ((priv->ieee->iw_mode != IW_MODE_INFRA)) {
6618 spin_lock_irqsave(&priv->ieee->lock, flags);
6619 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
6620 memcpy(&(priv->assoc_network->qos_data), &(network->qos_data),
6621 sizeof(struct ieee80211_qos_data));
6622 priv->assoc_network->qos_data.active = 1;
6623 if ((network->qos_data.old_param_count !=
6624 network->qos_data.param_count)) {
6626 network->qos_data.old_param_count =
6627 network->qos_data.param_count;
6631 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B)) {
6632 memcpy(&(priv->assoc_network->qos_data.parameters),
6633 &def_parameters_CCK, size);
6635 memcpy(&(priv->assoc_network->qos_data.parameters),
6636 &def_parameters_OFDM, size);
6638 priv->assoc_network->qos_data.active = 0;
6639 priv->assoc_network->qos_data.supported = 0;
6643 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6645 if (set_qos_param == 1)
6646 schedule_work(&priv->qos_activate);
6651 static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
6658 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION)) {
6659 ret = priv->qos_data.burst_duration_CCK;
6661 ret = priv->qos_data.burst_duration_OFDM;
6667 * Initialize the setting of QoS global
6669 static void ipw_qos_init(struct ipw_priv *priv, int enable,
6670 int burst_enable, u32 burst_duration_CCK,
6671 u32 burst_duration_OFDM)
6673 priv->qos_data.qos_enable = enable;
6675 if (priv->qos_data.qos_enable) {
6676 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
6677 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
6678 IPW_DEBUG_QOS("QoS is enabled\n");
6680 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
6681 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
6682 IPW_DEBUG_QOS("QoS is not enabled\n");
6685 priv->qos_data.burst_enable = burst_enable;
6688 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
6689 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
6691 priv->qos_data.burst_duration_CCK = 0;
6692 priv->qos_data.burst_duration_OFDM = 0;
6697 * map the packet priority to the right TX Queue
6699 static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
6701 if (priority > 7 || !priv->qos_data.qos_enable)
6704 return from_priority_to_tx_queue[priority] - 1;
6708 * add QoS parameter to the TX command
6710 static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
6712 struct tfd_data *tfd, u8 unicast)
6715 int tx_queue_id = 0;
6716 struct ieee80211_qos_data *qos_data = NULL;
6717 int active, supported;
6718 unsigned long flags;
6720 if (!(priv->status & STATUS_ASSOCIATED))
6723 qos_data = &priv->assoc_network->qos_data;
6725 spin_lock_irqsave(&priv->ieee->lock, flags);
6727 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6729 qos_data->active = 0;
6731 qos_data->active = qos_data->supported;
6734 active = qos_data->active;
6735 supported = qos_data->supported;
6737 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6740 ("QoS %d network is QoS active %d supported %d unicast %d\n",
6741 priv->qos_data.qos_enable, active, supported, unicast);
6742 if (active && priv->qos_data.qos_enable) {
6743 ret = from_priority_to_tx_queue[priority];
6744 tx_queue_id = ret - 1;
6745 IPW_DEBUG_QOS("QoS packet priority is %d \n", priority);
6746 if (priority <= 7) {
6747 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
6748 tfd->tfd.tfd_26.mchdr.qos_ctrl = priority;
6749 tfd->tfd.tfd_26.mchdr.frame_ctl |=
6750 IEEE80211_STYPE_QOS_DATA;
6752 if (priv->qos_data.qos_no_ack_mask &
6753 (1UL << tx_queue_id)) {
6754 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
6755 tfd->tfd.tfd_26.mchdr.qos_ctrl |=
6765 * background support to run QoS activate functionality
6767 static void ipw_bg_qos_activate(void *data)
6769 struct ipw_priv *priv = data;
6776 if (priv->status & STATUS_ASSOCIATED)
6777 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
6783 * Handler for probe responce and beacon frame
6785 static int ipw_handle_management_frame(struct net_device *dev,
6786 struct ieee80211_network *network,
6789 struct ipw_priv *priv = ieee80211_priv(dev);
6792 if (priv->status & STATUS_ASSOCIATED && network == priv->assoc_network)
6798 case IEEE80211_STYPE_PROBE_RESP:
6799 case IEEE80211_STYPE_BEACON:
6800 ipw_qos_handle_probe_reponse(priv, active_network, network);
6802 case IEEE80211_STYPE_ASSOC_RESP:
6803 ipw_qos_association_resp(priv, network);
6812 static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
6815 struct host_cmd cmd = {
6816 .cmd = IPW_CMD_QOS_PARAMETERS,
6817 .len = (sizeof(struct ieee80211_qos_parameters) * 3)
6820 if (!priv || !qos_param) {
6821 IPW_ERROR("Invalid args\n");
6825 memcpy(&cmd.param, qos_param,
6826 (sizeof(struct ieee80211_qos_parameters) * 3));
6827 if (ipw_send_cmd(priv, &cmd)) {
6828 IPW_ERROR("failed to send IPW_CMD_QOS_PARAMETERS command\n");
6835 static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
6838 struct host_cmd cmd = {
6839 .cmd = IPW_CMD_WME_INFO,
6840 .len = sizeof(*qos_param)
6843 if (!priv || !qos_param) {
6844 IPW_ERROR("Invalid args\n");
6848 memcpy(&cmd.param, qos_param, sizeof(*qos_param));
6849 if (ipw_send_cmd(priv, &cmd)) {
6850 IPW_ERROR("failed to send CMD_QOS_INFO command\n");
6857 #endif /* CONFIG_IPW_QOS */
6859 static int ipw_associate_network(struct ipw_priv *priv,
6860 struct ieee80211_network *network,
6861 struct ipw_supported_rates *rates, int roaming)
6865 if (priv->config & CFG_FIXED_RATE)
6866 ipw_set_fixed_rate(priv, network->mode);
6868 if (!(priv->config & CFG_STATIC_ESSID)) {
6869 priv->essid_len = min(network->ssid_len,
6870 (u8) IW_ESSID_MAX_SIZE);
6871 memcpy(priv->essid, network->ssid, priv->essid_len);
6874 network->last_associate = jiffies;
6876 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
6877 priv->assoc_request.channel = network->channel;
6878 if ((priv->capability & CAP_PRIVACY_ON) &&
6879 (priv->capability & CAP_SHARED_KEY)) {
6880 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
6881 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
6883 if ((priv->capability & CAP_PRIVACY_ON) &&
6884 (priv->ieee->sec.level == SEC_LEVEL_1) &&
6885 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
6886 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
6888 priv->assoc_request.auth_type = AUTH_OPEN;
6889 priv->assoc_request.auth_key = 0;
6892 if (priv->ieee->wpa_ie_len) {
6893 priv->assoc_request.policy_support = 0x02; /* RSN active */
6894 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
6895 priv->ieee->wpa_ie_len);
6899 * It is valid for our ieee device to support multiple modes, but
6900 * when it comes to associating to a given network we have to choose
6903 if (network->mode & priv->ieee->mode & IEEE_A)
6904 priv->assoc_request.ieee_mode = IPW_A_MODE;
6905 else if (network->mode & priv->ieee->mode & IEEE_G)
6906 priv->assoc_request.ieee_mode = IPW_G_MODE;
6907 else if (network->mode & priv->ieee->mode & IEEE_B)
6908 priv->assoc_request.ieee_mode = IPW_B_MODE;
6910 priv->assoc_request.capability = network->capability;
6911 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
6912 && !(priv->config & CFG_PREAMBLE_LONG)) {
6913 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
6915 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
6917 /* Clear the short preamble if we won't be supporting it */
6918 priv->assoc_request.capability &=
6919 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
6922 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
6923 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
6924 roaming ? "Rea" : "A",
6925 escape_essid(priv->essid, priv->essid_len),
6927 ipw_modes[priv->assoc_request.ieee_mode],
6929 (priv->assoc_request.preamble_length ==
6930 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
6931 network->capability &
6932 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
6933 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
6934 priv->capability & CAP_PRIVACY_ON ?
6935 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
6937 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
6938 priv->capability & CAP_PRIVACY_ON ?
6939 '1' + priv->ieee->sec.active_key : '.',
6940 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
6942 priv->assoc_request.beacon_interval = network->beacon_interval;
6943 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
6944 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
6945 priv->assoc_request.assoc_type = HC_IBSS_START;
6946 priv->assoc_request.assoc_tsf_msw = 0;
6947 priv->assoc_request.assoc_tsf_lsw = 0;
6949 if (unlikely(roaming))
6950 priv->assoc_request.assoc_type = HC_REASSOCIATE;
6952 priv->assoc_request.assoc_type = HC_ASSOCIATE;
6953 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
6954 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
6957 memcpy(&priv->assoc_request.bssid, network->bssid, ETH_ALEN);
6959 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6960 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
6961 priv->assoc_request.atim_window = network->atim_window;
6963 memcpy(&priv->assoc_request.dest, network->bssid, ETH_ALEN);
6964 priv->assoc_request.atim_window = 0;
6967 priv->assoc_request.listen_interval = network->listen_interval;
6969 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6971 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
6975 rates->ieee_mode = priv->assoc_request.ieee_mode;
6976 rates->purpose = IPW_RATE_CONNECT;
6977 ipw_send_supported_rates(priv, rates);
6979 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
6980 priv->sys_config.dot11g_auto_detection = 1;
6982 priv->sys_config.dot11g_auto_detection = 0;
6984 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
6985 priv->sys_config.answer_broadcast_ssid_probe = 1;
6987 priv->sys_config.answer_broadcast_ssid_probe = 0;
6989 err = ipw_send_system_config(priv, &priv->sys_config);
6991 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
6995 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
6996 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
6998 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7003 * If preemption is enabled, it is possible for the association
7004 * to complete before we return from ipw_send_associate. Therefore
7005 * we have to be sure and update our priviate data first.
7007 priv->channel = network->channel;
7008 memcpy(priv->bssid, network->bssid, ETH_ALEN);
7009 priv->status |= STATUS_ASSOCIATING;
7010 priv->status &= ~STATUS_SECURITY_UPDATED;
7012 priv->assoc_network = network;
7014 #ifdef CONFIG_IPW_QOS
7015 ipw_qos_association(priv, network);
7018 err = ipw_send_associate(priv, &priv->assoc_request);
7020 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7024 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
7025 escape_essid(priv->essid, priv->essid_len),
7026 MAC_ARG(priv->bssid));
7031 static void ipw_roam(void *data)
7033 struct ipw_priv *priv = data;
7034 struct ieee80211_network *network = NULL;
7035 struct ipw_network_match match = {
7036 .network = priv->assoc_network
7039 /* The roaming process is as follows:
7041 * 1. Missed beacon threshold triggers the roaming process by
7042 * setting the status ROAM bit and requesting a scan.
7043 * 2. When the scan completes, it schedules the ROAM work
7044 * 3. The ROAM work looks at all of the known networks for one that
7045 * is a better network than the currently associated. If none
7046 * found, the ROAM process is over (ROAM bit cleared)
7047 * 4. If a better network is found, a disassociation request is
7049 * 5. When the disassociation completes, the roam work is again
7050 * scheduled. The second time through, the driver is no longer
7051 * associated, and the newly selected network is sent an
7052 * association request.
7053 * 6. At this point ,the roaming process is complete and the ROAM
7054 * status bit is cleared.
7057 /* If we are no longer associated, and the roaming bit is no longer
7058 * set, then we are not actively roaming, so just return */
7059 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7062 if (priv->status & STATUS_ASSOCIATED) {
7063 /* First pass through ROAM process -- look for a better
7065 unsigned long flags;
7066 u8 rssi = priv->assoc_network->stats.rssi;
7067 priv->assoc_network->stats.rssi = -128;
7068 spin_lock_irqsave(&priv->ieee->lock, flags);
7069 list_for_each_entry(network, &priv->ieee->network_list, list) {
7070 if (network != priv->assoc_network)
7071 ipw_best_network(priv, &match, network, 1);
7073 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7074 priv->assoc_network->stats.rssi = rssi;
7076 if (match.network == priv->assoc_network) {
7077 IPW_DEBUG_ASSOC("No better APs in this network to "
7079 priv->status &= ~STATUS_ROAMING;
7080 ipw_debug_config(priv);
7084 ipw_send_disassociate(priv, 1);
7085 priv->assoc_network = match.network;
7090 /* Second pass through ROAM process -- request association */
7091 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7092 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7093 priv->status &= ~STATUS_ROAMING;
7096 static void ipw_bg_roam(void *data)
7098 struct ipw_priv *priv = data;
7104 static int ipw_associate(void *data)
7106 struct ipw_priv *priv = data;
7108 struct ieee80211_network *network = NULL;
7109 struct ipw_network_match match = {
7112 struct ipw_supported_rates *rates;
7113 struct list_head *element;
7114 unsigned long flags;
7116 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7117 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7121 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
7123 ("Not attempting association (already in progress)\n");
7127 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
7129 ("Not attempting association (scanning or not initialized)\n");
7133 if (!(priv->config & CFG_ASSOCIATE) &&
7134 !(priv->config & (CFG_STATIC_ESSID |
7135 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
7136 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
7140 /* Protect our use of the network_list */
7141 spin_lock_irqsave(&priv->ieee->lock, flags);
7142 list_for_each_entry(network, &priv->ieee->network_list, list)
7143 ipw_best_network(priv, &match, network, 0);
7145 network = match.network;
7146 rates = &match.rates;
7148 if (network == NULL &&
7149 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7150 priv->config & CFG_ADHOC_CREATE &&
7151 priv->config & CFG_STATIC_ESSID &&
7152 priv->config & CFG_STATIC_CHANNEL &&
7153 !list_empty(&priv->ieee->network_free_list)) {
7154 element = priv->ieee->network_free_list.next;
7155 network = list_entry(element, struct ieee80211_network, list);
7156 ipw_adhoc_create(priv, network);
7157 rates = &priv->rates;
7159 list_add_tail(&network->list, &priv->ieee->network_list);
7161 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7163 /* If we reached the end of the list, then we don't have any valid
7166 ipw_debug_config(priv);
7168 if (!(priv->status & STATUS_SCANNING)) {
7169 if (!(priv->config & CFG_SPEED_SCAN))
7170 queue_delayed_work(priv->workqueue,
7171 &priv->request_scan,
7174 queue_work(priv->workqueue,
7175 &priv->request_scan);
7181 ipw_associate_network(priv, network, rates, 0);
7186 static void ipw_bg_associate(void *data)
7188 struct ipw_priv *priv = data;
7190 ipw_associate(data);
7194 static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7195 struct sk_buff *skb)
7197 struct ieee80211_hdr *hdr;
7200 hdr = (struct ieee80211_hdr *)skb->data;
7201 fc = le16_to_cpu(hdr->frame_ctl);
7202 if (!(fc & IEEE80211_FCTL_PROTECTED))
7205 fc &= ~IEEE80211_FCTL_PROTECTED;
7206 hdr->frame_ctl = cpu_to_le16(fc);
7207 switch (priv->ieee->sec.level) {
7209 /* Remove CCMP HDR */
7210 memmove(skb->data + IEEE80211_3ADDR_LEN,
7211 skb->data + IEEE80211_3ADDR_LEN + 8,
7212 skb->len - IEEE80211_3ADDR_LEN - 8);
7213 skb_trim(skb, skb->len - 8); /* MIC */
7219 memmove(skb->data + IEEE80211_3ADDR_LEN,
7220 skb->data + IEEE80211_3ADDR_LEN + 4,
7221 skb->len - IEEE80211_3ADDR_LEN - 4);
7222 skb_trim(skb, skb->len - 4); /* ICV */
7227 printk(KERN_ERR "Unknow security level %d\n",
7228 priv->ieee->sec.level);
7233 static void ipw_handle_data_packet(struct ipw_priv *priv,
7234 struct ipw_rx_mem_buffer *rxb,
7235 struct ieee80211_rx_stats *stats)
7237 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7239 /* We received data from the HW, so stop the watchdog */
7240 priv->net_dev->trans_start = jiffies;
7242 /* We only process data packets if the
7243 * interface is open */
7244 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7245 skb_tailroom(rxb->skb))) {
7246 priv->ieee->stats.rx_errors++;
7247 priv->wstats.discard.misc++;
7248 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7250 } else if (unlikely(!netif_running(priv->net_dev))) {
7251 priv->ieee->stats.rx_dropped++;
7252 priv->wstats.discard.misc++;
7253 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7257 /* Advance skb->data to the start of the actual payload */
7258 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
7260 /* Set the size of the skb to the size of the frame */
7261 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
7263 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7265 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
7266 if (!priv->ieee->host_decrypt)
7267 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7269 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7270 priv->ieee->stats.rx_errors++;
7271 else { /* ieee80211_rx succeeded, so it now owns the SKB */
7273 __ipw_led_activity_on(priv);
7277 static inline int is_network_packet(struct ipw_priv *priv,
7278 struct ieee80211_hdr_4addr *header)
7280 /* Filter incoming packets to determine if they are targetted toward
7281 * this network, discarding packets coming from ourselves */
7282 switch (priv->ieee->iw_mode) {
7283 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
7284 /* packets from our adapter are dropped (echo) */
7285 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7288 /* {broad,multi}cast packets to our IBSS go through */
7289 if (is_broadcast_ether_addr(header->addr1) ||
7290 is_multicast_ether_addr(header->addr1))
7291 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
7293 /* packets to our adapter go through */
7294 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7297 case IW_MODE_INFRA: /* Header: Dest. | AP{BSSID} | Source */
7298 /* packets from our adapter are dropped (echo) */
7299 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7302 /* {broad,multi}cast packets to our IBSS go through */
7303 if (is_broadcast_ether_addr(header->addr1) ||
7304 is_multicast_ether_addr(header->addr1))
7305 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7307 /* packets to our adapter go through */
7308 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7315 static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
7316 struct ipw_rx_mem_buffer *rxb,
7317 struct ieee80211_rx_stats *stats)
7319 struct sk_buff *skb = rxb->skb;
7320 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
7321 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
7322 (skb->data + IPW_RX_FRAME_SIZE);
7324 ieee80211_rx_mgt(priv->ieee, header, stats);
7326 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
7327 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7328 IEEE80211_STYPE_PROBE_RESP) ||
7329 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7330 IEEE80211_STYPE_BEACON))) {
7331 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
7332 ipw_add_station(priv, header->addr2);
7335 if (priv->config & CFG_NET_STATS) {
7336 IPW_DEBUG_HC("sending stat packet\n");
7338 /* Set the size of the skb to the size of the full
7339 * ipw header and 802.11 frame */
7340 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
7343 /* Advance past the ipw packet header to the 802.11 frame */
7344 skb_pull(skb, IPW_RX_FRAME_SIZE);
7346 /* Push the ieee80211_rx_stats before the 802.11 frame */
7347 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
7349 skb->dev = priv->ieee->dev;
7351 /* Point raw at the ieee80211_stats */
7352 skb->mac.raw = skb->data;
7354 skb->pkt_type = PACKET_OTHERHOST;
7355 skb->protocol = __constant_htons(ETH_P_80211_STATS);
7356 memset(skb->cb, 0, sizeof(rxb->skb->cb));
7363 * Main entry function for recieving a packet with 80211 headers. This
7364 * should be called when ever the FW has notified us that there is a new
7365 * skb in the recieve queue.
7367 static void ipw_rx(struct ipw_priv *priv)
7369 struct ipw_rx_mem_buffer *rxb;
7370 struct ipw_rx_packet *pkt;
7371 struct ieee80211_hdr_4addr *header;
7375 r = ipw_read32(priv, IPW_RX_READ_INDEX);
7376 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
7377 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
7380 rxb = priv->rxq->queue[i];
7381 #ifdef CONFIG_IPW_DEBUG
7382 if (unlikely(rxb == NULL)) {
7383 printk(KERN_CRIT "Queue not allocated!\n");
7387 priv->rxq->queue[i] = NULL;
7389 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
7391 PCI_DMA_FROMDEVICE);
7393 pkt = (struct ipw_rx_packet *)rxb->skb->data;
7394 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
7395 pkt->header.message_type,
7396 pkt->header.rx_seq_num, pkt->header.control_bits);
7398 switch (pkt->header.message_type) {
7399 case RX_FRAME_TYPE: /* 802.11 frame */ {
7400 struct ieee80211_rx_stats stats = {
7402 le16_to_cpu(pkt->u.frame.rssi_dbm) -
7405 le16_to_cpu(pkt->u.frame.signal),
7407 le16_to_cpu(pkt->u.frame.noise),
7408 .rate = pkt->u.frame.rate,
7409 .mac_time = jiffies,
7411 pkt->u.frame.received_channel,
7414 control & (1 << 0)) ?
7415 IEEE80211_24GHZ_BAND :
7416 IEEE80211_52GHZ_BAND,
7417 .len = le16_to_cpu(pkt->u.frame.length),
7420 if (stats.rssi != 0)
7421 stats.mask |= IEEE80211_STATMASK_RSSI;
7422 if (stats.signal != 0)
7423 stats.mask |= IEEE80211_STATMASK_SIGNAL;
7424 if (stats.noise != 0)
7425 stats.mask |= IEEE80211_STATMASK_NOISE;
7426 if (stats.rate != 0)
7427 stats.mask |= IEEE80211_STATMASK_RATE;
7431 #ifdef CONFIG_IPW2200_MONITOR
7432 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7433 ipw_handle_data_packet(priv, rxb,
7440 (struct ieee80211_hdr_4addr *)(rxb->skb->
7443 /* TODO: Check Ad-Hoc dest/source and make sure
7444 * that we are actually parsing these packets
7445 * correctly -- we should probably use the
7446 * frame control of the packet and disregard
7447 * the current iw_mode */
7450 is_network_packet(priv, header);
7451 if (network_packet && priv->assoc_network) {
7452 priv->assoc_network->stats.rssi =
7454 average_add(&priv->average_rssi,
7456 priv->last_rx_rssi = stats.rssi;
7459 IPW_DEBUG_RX("Frame: len=%u\n",
7460 le16_to_cpu(pkt->u.frame.length));
7462 if (le16_to_cpu(pkt->u.frame.length) <
7463 frame_hdr_len(header)) {
7465 ("Received packet is too small. "
7467 priv->ieee->stats.rx_errors++;
7468 priv->wstats.discard.misc++;
7472 switch (WLAN_FC_GET_TYPE
7473 (le16_to_cpu(header->frame_ctl))) {
7475 case IEEE80211_FTYPE_MGMT:
7476 ipw_handle_mgmt_packet(priv, rxb,
7480 case IEEE80211_FTYPE_CTL:
7483 case IEEE80211_FTYPE_DATA:
7484 if (unlikely(!network_packet)) {
7485 IPW_DEBUG_DROP("Dropping: "
7498 ipw_handle_data_packet(priv, rxb,
7506 case RX_HOST_NOTIFICATION_TYPE:{
7508 ("Notification: subtype=%02X flags=%02X size=%d\n",
7509 pkt->u.notification.subtype,
7510 pkt->u.notification.flags,
7511 pkt->u.notification.size);
7512 ipw_rx_notification(priv, &pkt->u.notification);
7517 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
7518 pkt->header.message_type);
7522 /* For now we just don't re-use anything. We can tweak this
7523 * later to try and re-use notification packets and SKBs that
7524 * fail to Rx correctly */
7525 if (rxb->skb != NULL) {
7526 dev_kfree_skb_any(rxb->skb);
7530 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
7531 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
7532 list_add_tail(&rxb->list, &priv->rxq->rx_used);
7534 i = (i + 1) % RX_QUEUE_SIZE;
7537 /* Backtrack one entry */
7538 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
7540 ipw_rx_queue_restock(priv);
7544 * This file defines the Wireless Extension handlers. It does not
7545 * define any methods of hardware manipulation and relies on the
7546 * functions defined in ipw_main to provide the HW interaction.
7548 * The exception to this is the use of the ipw_get_ordinal()
7549 * function used to poll the hardware vs. making unecessary calls.
7553 static int ipw_wx_get_name(struct net_device *dev,
7554 struct iw_request_info *info,
7555 union iwreq_data *wrqu, char *extra)
7557 struct ipw_priv *priv = ieee80211_priv(dev);
7559 if (priv->status & STATUS_RF_KILL_MASK)
7560 strcpy(wrqu->name, "radio off");
7561 else if (!(priv->status & STATUS_ASSOCIATED))
7562 strcpy(wrqu->name, "unassociated");
7564 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
7565 ipw_modes[priv->assoc_request.ieee_mode]);
7566 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
7571 static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
7576 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
7577 priv->config &= ~CFG_STATIC_CHANNEL;
7578 IPW_DEBUG_ASSOC("Attempting to associate with new "
7580 ipw_associate(priv);
7584 priv->config |= CFG_STATIC_CHANNEL;
7586 if (priv->channel == channel) {
7587 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
7592 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
7593 priv->channel = channel;
7595 #ifdef CONFIG_IPW2200_MONITOR
7596 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7597 if (priv->status & STATUS_SCANNING) {
7598 IPW_DEBUG_SCAN("scan abort triggered due to "
7599 "channel change.\n");
7600 queue_work(priv->workqueue, &priv->abort_scan);
7603 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
7606 if (priv->status & STATUS_SCANNING)
7607 IPW_DEBUG_SCAN("Still scanning...\n");
7609 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
7614 #endif /* CONFIG_IPW2200_MONITOR */
7616 /* Network configuration changed -- force [re]association */
7617 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
7618 if (!ipw_disassociate(priv))
7619 ipw_associate(priv);
7624 static int ipw_wx_set_freq(struct net_device *dev,
7625 struct iw_request_info *info,
7626 union iwreq_data *wrqu, char *extra)
7628 struct ipw_priv *priv = ieee80211_priv(dev);
7629 struct iw_freq *fwrq = &wrqu->freq;
7634 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
7636 ret = ipw_set_channel(priv, 0);
7641 /* if setting by freq convert to channel */
7643 channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
7649 if (!ieee80211_is_valid_channel(priv->ieee, channel))
7652 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
7654 ret = ipw_set_channel(priv, channel);
7659 static int ipw_wx_get_freq(struct net_device *dev,
7660 struct iw_request_info *info,
7661 union iwreq_data *wrqu, char *extra)
7663 struct ipw_priv *priv = ieee80211_priv(dev);
7667 /* If we are associated, trying to associate, or have a statically
7668 * configured CHANNEL then return that; otherwise return ANY */
7670 if (priv->config & CFG_STATIC_CHANNEL ||
7671 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
7672 wrqu->freq.m = priv->channel;
7677 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
7681 static int ipw_wx_set_mode(struct net_device *dev,
7682 struct iw_request_info *info,
7683 union iwreq_data *wrqu, char *extra)
7685 struct ipw_priv *priv = ieee80211_priv(dev);
7688 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
7690 switch (wrqu->mode) {
7691 #ifdef CONFIG_IPW2200_MONITOR
7692 case IW_MODE_MONITOR:
7698 wrqu->mode = IW_MODE_INFRA;
7703 if (wrqu->mode == priv->ieee->iw_mode)
7707 #ifdef CONFIG_IPW2200_MONITOR
7708 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
7709 priv->net_dev->type = ARPHRD_ETHER;
7711 if (wrqu->mode == IW_MODE_MONITOR)
7712 priv->net_dev->type = ARPHRD_IEEE80211;
7713 #endif /* CONFIG_IPW2200_MONITOR */
7716 /* Free the existing firmware and reset the fw_loaded
7717 * flag so ipw_load() will bring in the new firmawre */
7721 release_firmware(bootfw);
7722 release_firmware(ucode);
7723 release_firmware(firmware);
7724 bootfw = ucode = firmware = NULL;
7727 priv->ieee->iw_mode = wrqu->mode;
7729 queue_work(priv->workqueue, &priv->adapter_restart);
7734 static int ipw_wx_get_mode(struct net_device *dev,
7735 struct iw_request_info *info,
7736 union iwreq_data *wrqu, char *extra)
7738 struct ipw_priv *priv = ieee80211_priv(dev);
7740 wrqu->mode = priv->ieee->iw_mode;
7741 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
7746 #define DEFAULT_RTS_THRESHOLD 2304U
7747 #define MIN_RTS_THRESHOLD 1U
7748 #define MAX_RTS_THRESHOLD 2304U
7749 #define DEFAULT_BEACON_INTERVAL 100U
7750 #define DEFAULT_SHORT_RETRY_LIMIT 7U
7751 #define DEFAULT_LONG_RETRY_LIMIT 4U
7753 /* Values are in microsecond */
7754 static const s32 timeout_duration[] = {
7762 static const s32 period_duration[] = {
7770 static int ipw_wx_get_range(struct net_device *dev,
7771 struct iw_request_info *info,
7772 union iwreq_data *wrqu, char *extra)
7774 struct ipw_priv *priv = ieee80211_priv(dev);
7775 struct iw_range *range = (struct iw_range *)extra;
7776 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
7779 wrqu->data.length = sizeof(*range);
7780 memset(range, 0, sizeof(*range));
7782 /* 54Mbs == ~27 Mb/s real (802.11g) */
7783 range->throughput = 27 * 1000 * 1000;
7785 range->max_qual.qual = 100;
7786 /* TODO: Find real max RSSI and stick here */
7787 range->max_qual.level = 0;
7788 range->max_qual.noise = priv->ieee->worst_rssi + 0x100;
7789 range->max_qual.updated = 7; /* Updated all three */
7791 range->avg_qual.qual = 70;
7792 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
7793 range->avg_qual.level = 0; /* FIXME to real average level */
7794 range->avg_qual.noise = 0;
7795 range->avg_qual.updated = 7; /* Updated all three */
7797 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
7799 for (i = 0; i < range->num_bitrates; i++)
7800 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
7803 range->max_rts = DEFAULT_RTS_THRESHOLD;
7804 range->min_frag = MIN_FRAG_THRESHOLD;
7805 range->max_frag = MAX_FRAG_THRESHOLD;
7807 range->encoding_size[0] = 5;
7808 range->encoding_size[1] = 13;
7809 range->num_encoding_sizes = 2;
7810 range->max_encoding_tokens = WEP_KEYS;
7812 /* Set the Wireless Extension versions */
7813 range->we_version_compiled = WIRELESS_EXT;
7814 range->we_version_source = 16;
7817 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
7818 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES;
7820 range->freq[i].i = geo->bg[j].channel;
7821 range->freq[i].m = geo->bg[j].freq * 100000;
7822 range->freq[i].e = 1;
7826 if (priv->ieee->mode & IEEE_A) {
7827 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES;
7829 range->freq[i].i = geo->a[j].channel;
7830 range->freq[i].m = geo->a[j].freq * 100000;
7831 range->freq[i].e = 1;
7835 range->num_channels = i;
7836 range->num_frequency = i;
7839 IPW_DEBUG_WX("GET Range\n");
7843 static int ipw_wx_set_wap(struct net_device *dev,
7844 struct iw_request_info *info,
7845 union iwreq_data *wrqu, char *extra)
7847 struct ipw_priv *priv = ieee80211_priv(dev);
7849 static const unsigned char any[] = {
7850 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
7852 static const unsigned char off[] = {
7853 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
7856 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
7859 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
7860 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
7861 /* we disable mandatory BSSID association */
7862 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
7863 priv->config &= ~CFG_STATIC_BSSID;
7864 IPW_DEBUG_ASSOC("Attempting to associate with new "
7866 ipw_associate(priv);
7871 priv->config |= CFG_STATIC_BSSID;
7872 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
7873 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
7878 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
7879 MAC_ARG(wrqu->ap_addr.sa_data));
7881 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
7883 /* Network configuration changed -- force [re]association */
7884 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
7885 if (!ipw_disassociate(priv))
7886 ipw_associate(priv);
7892 static int ipw_wx_get_wap(struct net_device *dev,
7893 struct iw_request_info *info,
7894 union iwreq_data *wrqu, char *extra)
7896 struct ipw_priv *priv = ieee80211_priv(dev);
7897 /* If we are associated, trying to associate, or have a statically
7898 * configured BSSID then return that; otherwise return ANY */
7900 if (priv->config & CFG_STATIC_BSSID ||
7901 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
7902 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
7903 memcpy(wrqu->ap_addr.sa_data, &priv->bssid, ETH_ALEN);
7905 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
7907 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
7908 MAC_ARG(wrqu->ap_addr.sa_data));
7913 static int ipw_wx_set_essid(struct net_device *dev,
7914 struct iw_request_info *info,
7915 union iwreq_data *wrqu, char *extra)
7917 struct ipw_priv *priv = ieee80211_priv(dev);
7918 char *essid = ""; /* ANY */
7921 if (wrqu->essid.flags && wrqu->essid.length) {
7922 length = wrqu->essid.length - 1;
7926 IPW_DEBUG_WX("Setting ESSID to ANY\n");
7927 priv->config &= ~CFG_STATIC_ESSID;
7928 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
7929 IPW_DEBUG_ASSOC("Attempting to associate with new "
7931 ipw_associate(priv);
7937 length = min(length, IW_ESSID_MAX_SIZE);
7939 priv->config |= CFG_STATIC_ESSID;
7941 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
7942 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
7947 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
7950 priv->essid_len = length;
7951 memcpy(priv->essid, essid, priv->essid_len);
7953 /* Network configuration changed -- force [re]association */
7954 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
7955 if (!ipw_disassociate(priv))
7956 ipw_associate(priv);
7962 static int ipw_wx_get_essid(struct net_device *dev,
7963 struct iw_request_info *info,
7964 union iwreq_data *wrqu, char *extra)
7966 struct ipw_priv *priv = ieee80211_priv(dev);
7968 /* If we are associated, trying to associate, or have a statically
7969 * configured ESSID then return that; otherwise return ANY */
7971 if (priv->config & CFG_STATIC_ESSID ||
7972 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
7973 IPW_DEBUG_WX("Getting essid: '%s'\n",
7974 escape_essid(priv->essid, priv->essid_len));
7975 memcpy(extra, priv->essid, priv->essid_len);
7976 wrqu->essid.length = priv->essid_len;
7977 wrqu->essid.flags = 1; /* active */
7979 IPW_DEBUG_WX("Getting essid: ANY\n");
7980 wrqu->essid.length = 0;
7981 wrqu->essid.flags = 0; /* active */
7987 static int ipw_wx_set_nick(struct net_device *dev,
7988 struct iw_request_info *info,
7989 union iwreq_data *wrqu, char *extra)
7991 struct ipw_priv *priv = ieee80211_priv(dev);
7993 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
7994 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
7997 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
7998 memset(priv->nick, 0, sizeof(priv->nick));
7999 memcpy(priv->nick, extra, wrqu->data.length);
8000 IPW_DEBUG_TRACE("<<\n");
8006 static int ipw_wx_get_nick(struct net_device *dev,
8007 struct iw_request_info *info,
8008 union iwreq_data *wrqu, char *extra)
8010 struct ipw_priv *priv = ieee80211_priv(dev);
8011 IPW_DEBUG_WX("Getting nick\n");
8013 wrqu->data.length = strlen(priv->nick) + 1;
8014 memcpy(extra, priv->nick, wrqu->data.length);
8015 wrqu->data.flags = 1; /* active */
8020 static int ipw_wx_set_rate(struct net_device *dev,
8021 struct iw_request_info *info,
8022 union iwreq_data *wrqu, char *extra)
8024 /* TODO: We should use semaphores or locks for access to priv */
8025 struct ipw_priv *priv = ieee80211_priv(dev);
8026 u32 target_rate = wrqu->bitrate.value;
8029 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8030 /* value = X, fixed = 1 means only rate X */
8031 /* value = X, fixed = 0 means all rates lower equal X */
8033 if (target_rate == -1) {
8035 mask = IEEE80211_DEFAULT_RATES_MASK;
8036 /* Now we should reassociate */
8041 fixed = wrqu->bitrate.fixed;
8043 if (target_rate == 1000000 || !fixed)
8044 mask |= IEEE80211_CCK_RATE_1MB_MASK;
8045 if (target_rate == 1000000)
8048 if (target_rate == 2000000 || !fixed)
8049 mask |= IEEE80211_CCK_RATE_2MB_MASK;
8050 if (target_rate == 2000000)
8053 if (target_rate == 5500000 || !fixed)
8054 mask |= IEEE80211_CCK_RATE_5MB_MASK;
8055 if (target_rate == 5500000)
8058 if (target_rate == 6000000 || !fixed)
8059 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
8060 if (target_rate == 6000000)
8063 if (target_rate == 9000000 || !fixed)
8064 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
8065 if (target_rate == 9000000)
8068 if (target_rate == 11000000 || !fixed)
8069 mask |= IEEE80211_CCK_RATE_11MB_MASK;
8070 if (target_rate == 11000000)
8073 if (target_rate == 12000000 || !fixed)
8074 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
8075 if (target_rate == 12000000)
8078 if (target_rate == 18000000 || !fixed)
8079 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
8080 if (target_rate == 18000000)
8083 if (target_rate == 24000000 || !fixed)
8084 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
8085 if (target_rate == 24000000)
8088 if (target_rate == 36000000 || !fixed)
8089 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
8090 if (target_rate == 36000000)
8093 if (target_rate == 48000000 || !fixed)
8094 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
8095 if (target_rate == 48000000)
8098 if (target_rate == 54000000 || !fixed)
8099 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
8100 if (target_rate == 54000000)
8103 IPW_DEBUG_WX("invalid rate specified, returning error\n");
8107 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
8108 mask, fixed ? "fixed" : "sub-rates");
8110 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
8111 priv->config &= ~CFG_FIXED_RATE;
8112 ipw_set_fixed_rate(priv, priv->ieee->mode);
8114 priv->config |= CFG_FIXED_RATE;
8116 if (priv->rates_mask == mask) {
8117 IPW_DEBUG_WX("Mask set to current mask.\n");
8122 priv->rates_mask = mask;
8124 /* Network configuration changed -- force [re]association */
8125 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
8126 if (!ipw_disassociate(priv))
8127 ipw_associate(priv);
8133 static int ipw_wx_get_rate(struct net_device *dev,
8134 struct iw_request_info *info,
8135 union iwreq_data *wrqu, char *extra)
8137 struct ipw_priv *priv = ieee80211_priv(dev);
8139 wrqu->bitrate.value = priv->last_rate;
8141 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
8145 static int ipw_wx_set_rts(struct net_device *dev,
8146 struct iw_request_info *info,
8147 union iwreq_data *wrqu, char *extra)
8149 struct ipw_priv *priv = ieee80211_priv(dev);
8151 if (wrqu->rts.disabled)
8152 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8154 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
8155 wrqu->rts.value > MAX_RTS_THRESHOLD) {
8159 priv->rts_threshold = wrqu->rts.value;
8162 ipw_send_rts_threshold(priv, priv->rts_threshold);
8164 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
8168 static int ipw_wx_get_rts(struct net_device *dev,
8169 struct iw_request_info *info,
8170 union iwreq_data *wrqu, char *extra)
8172 struct ipw_priv *priv = ieee80211_priv(dev);
8174 wrqu->rts.value = priv->rts_threshold;
8175 wrqu->rts.fixed = 0; /* no auto select */
8176 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
8178 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
8182 static int ipw_wx_set_txpow(struct net_device *dev,
8183 struct iw_request_info *info,
8184 union iwreq_data *wrqu, char *extra)
8186 struct ipw_priv *priv = ieee80211_priv(dev);
8187 struct ipw_tx_power tx_power;
8191 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
8193 return -EINPROGRESS;
8196 if (!wrqu->power.fixed)
8197 wrqu->power.value = IPW_TX_POWER_DEFAULT;
8199 if (wrqu->power.flags != IW_TXPOW_DBM) {
8204 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
8205 (wrqu->power.value < -IPW_TX_POWER_MAX) || !wrqu->power.fixed) {
8210 priv->tx_power = wrqu->power.value;
8212 memset(&tx_power, 0, sizeof(tx_power));
8214 /* configure device for 'G' band */
8215 tx_power.ieee_mode = IPW_G_MODE;
8216 tx_power.num_channels = 11;
8217 for (i = 0; i < 11; i++) {
8218 tx_power.channels_tx_power[i].channel_number = i + 1;
8219 tx_power.channels_tx_power[i].tx_power = priv->tx_power;
8221 if (ipw_send_tx_power(priv, &tx_power))
8224 /* configure device to also handle 'B' band */
8225 tx_power.ieee_mode = IPW_B_MODE;
8226 if (ipw_send_tx_power(priv, &tx_power))
8237 static int ipw_wx_get_txpow(struct net_device *dev,
8238 struct iw_request_info *info,
8239 union iwreq_data *wrqu, char *extra)
8241 struct ipw_priv *priv = ieee80211_priv(dev);
8243 wrqu->power.value = priv->tx_power;
8244 wrqu->power.fixed = 1;
8245 wrqu->power.flags = IW_TXPOW_DBM;
8246 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
8249 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
8250 wrqu->power.disabled ? "ON" : "OFF", wrqu->power.value);
8255 static int ipw_wx_set_frag(struct net_device *dev,
8256 struct iw_request_info *info,
8257 union iwreq_data *wrqu, char *extra)
8259 struct ipw_priv *priv = ieee80211_priv(dev);
8261 if (wrqu->frag.disabled)
8262 priv->ieee->fts = DEFAULT_FTS;
8264 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
8265 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
8270 priv->ieee->fts = wrqu->frag.value & ~0x1;
8273 ipw_send_frag_threshold(priv, wrqu->frag.value);
8275 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
8279 static int ipw_wx_get_frag(struct net_device *dev,
8280 struct iw_request_info *info,
8281 union iwreq_data *wrqu, char *extra)
8283 struct ipw_priv *priv = ieee80211_priv(dev);
8285 wrqu->frag.value = priv->ieee->fts;
8286 wrqu->frag.fixed = 0; /* no auto select */
8287 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
8289 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
8294 static int ipw_wx_set_retry(struct net_device *dev,
8295 struct iw_request_info *info,
8296 union iwreq_data *wrqu, char *extra)
8298 IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu);
8302 static int ipw_wx_get_retry(struct net_device *dev,
8303 struct iw_request_info *info,
8304 union iwreq_data *wrqu, char *extra)
8306 IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu);
8310 static int ipw_wx_set_scan(struct net_device *dev,
8311 struct iw_request_info *info,
8312 union iwreq_data *wrqu, char *extra)
8314 struct ipw_priv *priv = ieee80211_priv(dev);
8315 IPW_DEBUG_WX("Start scan\n");
8317 queue_work(priv->workqueue, &priv->request_scan);
8322 static int ipw_wx_get_scan(struct net_device *dev,
8323 struct iw_request_info *info,
8324 union iwreq_data *wrqu, char *extra)
8326 struct ipw_priv *priv = ieee80211_priv(dev);
8327 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
8330 static int ipw_wx_set_encode(struct net_device *dev,
8331 struct iw_request_info *info,
8332 union iwreq_data *wrqu, char *key)
8334 struct ipw_priv *priv = ieee80211_priv(dev);
8335 return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
8338 static int ipw_wx_get_encode(struct net_device *dev,
8339 struct iw_request_info *info,
8340 union iwreq_data *wrqu, char *key)
8342 struct ipw_priv *priv = ieee80211_priv(dev);
8343 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
8346 static int ipw_wx_set_power(struct net_device *dev,
8347 struct iw_request_info *info,
8348 union iwreq_data *wrqu, char *extra)
8350 struct ipw_priv *priv = ieee80211_priv(dev);
8353 if (wrqu->power.disabled) {
8354 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
8355 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
8357 IPW_DEBUG_WX("failed setting power mode.\n");
8361 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
8366 switch (wrqu->power.flags & IW_POWER_MODE) {
8367 case IW_POWER_ON: /* If not specified */
8368 case IW_POWER_MODE: /* If set all mask */
8369 case IW_POWER_ALL_R: /* If explicitely state all */
8371 default: /* Otherwise we don't support it */
8372 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
8378 /* If the user hasn't specified a power management mode yet, default
8380 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
8381 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
8383 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
8384 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
8386 IPW_DEBUG_WX("failed setting power mode.\n");
8391 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
8396 static int ipw_wx_get_power(struct net_device *dev,
8397 struct iw_request_info *info,
8398 union iwreq_data *wrqu, char *extra)
8400 struct ipw_priv *priv = ieee80211_priv(dev);
8402 if (!(priv->power_mode & IPW_POWER_ENABLED))
8403 wrqu->power.disabled = 1;
8405 wrqu->power.disabled = 0;
8408 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
8413 static int ipw_wx_set_powermode(struct net_device *dev,
8414 struct iw_request_info *info,
8415 union iwreq_data *wrqu, char *extra)
8417 struct ipw_priv *priv = ieee80211_priv(dev);
8418 int mode = *(int *)extra;
8421 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
8422 mode = IPW_POWER_AC;
8423 priv->power_mode = mode;
8425 priv->power_mode = IPW_POWER_ENABLED | mode;
8428 if (priv->power_mode != mode) {
8429 err = ipw_send_power_mode(priv, mode);
8432 IPW_DEBUG_WX("failed setting power mode.\n");
8441 #define MAX_WX_STRING 80
8442 static int ipw_wx_get_powermode(struct net_device *dev,
8443 struct iw_request_info *info,
8444 union iwreq_data *wrqu, char *extra)
8446 struct ipw_priv *priv = ieee80211_priv(dev);
8447 int level = IPW_POWER_LEVEL(priv->power_mode);
8450 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
8454 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
8456 case IPW_POWER_BATTERY:
8457 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
8460 p += snprintf(p, MAX_WX_STRING - (p - extra),
8461 "(Timeout %dms, Period %dms)",
8462 timeout_duration[level - 1] / 1000,
8463 period_duration[level - 1] / 1000);
8466 if (!(priv->power_mode & IPW_POWER_ENABLED))
8467 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
8469 wrqu->data.length = p - extra + 1;
8474 static int ipw_wx_set_wireless_mode(struct net_device *dev,
8475 struct iw_request_info *info,
8476 union iwreq_data *wrqu, char *extra)
8478 struct ipw_priv *priv = ieee80211_priv(dev);
8479 int mode = *(int *)extra;
8480 u8 band = 0, modulation = 0;
8482 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
8483 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
8487 if (priv->adapter == IPW_2915ABG) {
8488 priv->ieee->abg_true = 1;
8489 if (mode & IEEE_A) {
8490 band |= IEEE80211_52GHZ_BAND;
8491 modulation |= IEEE80211_OFDM_MODULATION;
8493 priv->ieee->abg_true = 0;
8495 if (mode & IEEE_A) {
8496 IPW_WARNING("Attempt to set 2200BG into "
8502 priv->ieee->abg_true = 0;
8505 if (mode & IEEE_B) {
8506 band |= IEEE80211_24GHZ_BAND;
8507 modulation |= IEEE80211_CCK_MODULATION;
8509 priv->ieee->abg_true = 0;
8511 if (mode & IEEE_G) {
8512 band |= IEEE80211_24GHZ_BAND;
8513 modulation |= IEEE80211_OFDM_MODULATION;
8515 priv->ieee->abg_true = 0;
8517 priv->ieee->mode = mode;
8518 priv->ieee->freq_band = band;
8519 priv->ieee->modulation = modulation;
8520 init_supported_rates(priv, &priv->rates);
8522 /* Network configuration changed -- force [re]association */
8523 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
8524 if (!ipw_disassociate(priv)) {
8525 ipw_send_supported_rates(priv, &priv->rates);
8526 ipw_associate(priv);
8529 /* Update the band LEDs */
8530 ipw_led_band_on(priv);
8532 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
8533 mode & IEEE_A ? 'a' : '.',
8534 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
8539 static int ipw_wx_get_wireless_mode(struct net_device *dev,
8540 struct iw_request_info *info,
8541 union iwreq_data *wrqu, char *extra)
8543 struct ipw_priv *priv = ieee80211_priv(dev);
8545 switch (priv->ieee->mode) {
8547 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
8550 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
8552 case IEEE_A | IEEE_B:
8553 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
8556 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
8558 case IEEE_A | IEEE_G:
8559 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
8561 case IEEE_B | IEEE_G:
8562 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
8564 case IEEE_A | IEEE_B | IEEE_G:
8565 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
8568 strncpy(extra, "unknown", MAX_WX_STRING);
8572 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
8574 wrqu->data.length = strlen(extra) + 1;
8580 static int ipw_wx_set_preamble(struct net_device *dev,
8581 struct iw_request_info *info,
8582 union iwreq_data *wrqu, char *extra)
8584 struct ipw_priv *priv = ieee80211_priv(dev);
8585 int mode = *(int *)extra;
8587 /* Switching from SHORT -> LONG requires a disassociation */
8589 if (!(priv->config & CFG_PREAMBLE_LONG)) {
8590 priv->config |= CFG_PREAMBLE_LONG;
8592 /* Network configuration changed -- force [re]association */
8594 ("[re]association triggered due to preamble change.\n");
8595 if (!ipw_disassociate(priv))
8596 ipw_associate(priv);
8602 priv->config &= ~CFG_PREAMBLE_LONG;
8613 static int ipw_wx_get_preamble(struct net_device *dev,
8614 struct iw_request_info *info,
8615 union iwreq_data *wrqu, char *extra)
8617 struct ipw_priv *priv = ieee80211_priv(dev);
8619 if (priv->config & CFG_PREAMBLE_LONG)
8620 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
8622 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
8627 #ifdef CONFIG_IPW2200_MONITOR
8628 static int ipw_wx_set_monitor(struct net_device *dev,
8629 struct iw_request_info *info,
8630 union iwreq_data *wrqu, char *extra)
8632 struct ipw_priv *priv = ieee80211_priv(dev);
8633 int *parms = (int *)extra;
8634 int enable = (parms[0] > 0);
8636 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
8638 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
8639 priv->net_dev->type = ARPHRD_IEEE80211;
8640 queue_work(priv->workqueue, &priv->adapter_restart);
8643 ipw_set_channel(priv, parms[1]);
8645 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
8649 priv->net_dev->type = ARPHRD_ETHER;
8650 queue_work(priv->workqueue, &priv->adapter_restart);
8656 #endif // CONFIG_IPW2200_MONITOR
8658 static int ipw_wx_reset(struct net_device *dev,
8659 struct iw_request_info *info,
8660 union iwreq_data *wrqu, char *extra)
8662 struct ipw_priv *priv = ieee80211_priv(dev);
8663 IPW_DEBUG_WX("RESET\n");
8664 queue_work(priv->workqueue, &priv->adapter_restart);
8668 static void ipw_sw_reset(struct ipw_priv *priv, int init)
8670 int band, modulation;
8672 /* Initialize module parameter values here */
8675 /* We default to disabling the LED code as right now it causes
8676 * too many systems to lock up... */
8678 priv->config |= CFG_NO_LED;
8681 priv->config |= CFG_ASSOCIATE;
8683 IPW_DEBUG_INFO("Auto associate disabled.\n");
8686 priv->config |= CFG_ADHOC_CREATE;
8688 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8691 priv->status |= STATUS_RF_KILL_SW;
8692 IPW_DEBUG_INFO("Radio disabled.\n");
8696 priv->config |= CFG_STATIC_CHANNEL;
8697 priv->channel = channel;
8698 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8699 /* TODO: Validate that provided channel is in range */
8701 #ifdef CONFIG_IPW_QOS
8702 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8703 burst_duration_CCK, burst_duration_OFDM);
8704 #endif /* CONFIG_IPW_QOS */
8708 priv->ieee->iw_mode = IW_MODE_ADHOC;
8709 priv->net_dev->type = ARPHRD_ETHER;
8712 #ifdef CONFIG_IPW2200_MONITOR
8714 priv->ieee->iw_mode = IW_MODE_MONITOR;
8715 priv->net_dev->type = ARPHRD_IEEE80211;
8720 priv->net_dev->type = ARPHRD_ETHER;
8721 priv->ieee->iw_mode = IW_MODE_INFRA;
8726 priv->ieee->host_encrypt = 0;
8727 priv->ieee->host_decrypt = 0;
8729 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
8731 if ((priv->pci_dev->device == 0x4223) ||
8732 (priv->pci_dev->device == 0x4224)) {
8734 printk(KERN_INFO DRV_NAME
8735 ": Detected Intel PRO/Wireless 2915ABG Network "
8737 priv->ieee->abg_true = 1;
8738 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8739 modulation = IEEE80211_OFDM_MODULATION |
8740 IEEE80211_CCK_MODULATION;
8741 priv->adapter = IPW_2915ABG;
8742 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
8745 printk(KERN_INFO DRV_NAME
8746 ": Detected Intel PRO/Wireless 2200BG Network "
8749 priv->ieee->abg_true = 0;
8750 band = IEEE80211_24GHZ_BAND;
8751 modulation = IEEE80211_OFDM_MODULATION |
8752 IEEE80211_CCK_MODULATION;
8753 priv->adapter = IPW_2200BG;
8754 priv->ieee->mode = IEEE_G | IEEE_B;
8757 priv->ieee->freq_band = band;
8758 priv->ieee->modulation = modulation;
8760 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
8762 priv->missed_beacon_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8763 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8765 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8767 /* If power management is turned on, default to AC mode */
8768 priv->power_mode = IPW_POWER_AC;
8769 priv->tx_power = IPW_TX_POWER_DEFAULT;
8772 static int ipw_wx_sw_reset(struct net_device *dev,
8773 struct iw_request_info *info,
8774 union iwreq_data *wrqu, char *extra)
8776 struct ipw_priv *priv = ieee80211_priv(dev);
8777 union iwreq_data wrqu_sec = {
8779 .flags = IW_ENCODE_DISABLED,
8783 IPW_DEBUG_WX("SW_RESET\n");
8787 ipw_sw_reset(priv, 0);
8789 /* The SW reset bit might have been toggled on by the 'disable'
8790 * module parameter, so take appropriate action */
8791 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
8794 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
8797 if (!(priv->status & STATUS_RF_KILL_MASK)) {
8798 /* Configuration likely changed -- force [re]association */
8799 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
8801 if (!ipw_disassociate(priv))
8802 ipw_associate(priv);
8810 /* Rebase the WE IOCTLs to zero for the handler array */
8811 #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
8812 static iw_handler ipw_wx_handlers[] = {
8813 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
8814 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
8815 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
8816 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
8817 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
8818 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
8819 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
8820 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
8821 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
8822 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
8823 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
8824 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
8825 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
8826 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
8827 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
8828 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
8829 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
8830 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
8831 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
8832 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
8833 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
8834 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
8835 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
8836 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
8837 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
8838 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
8839 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
8840 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
8841 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
8842 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
8843 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
8844 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
8848 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
8852 IPW_PRIV_SET_PREAMBLE,
8853 IPW_PRIV_GET_PREAMBLE,
8856 #ifdef CONFIG_IPW2200_MONITOR
8857 IPW_PRIV_SET_MONITOR,
8861 static struct iw_priv_args ipw_priv_args[] = {
8863 .cmd = IPW_PRIV_SET_POWER,
8864 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
8865 .name = "set_power"},
8867 .cmd = IPW_PRIV_GET_POWER,
8868 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
8869 .name = "get_power"},
8871 .cmd = IPW_PRIV_SET_MODE,
8872 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
8873 .name = "set_mode"},
8875 .cmd = IPW_PRIV_GET_MODE,
8876 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
8877 .name = "get_mode"},
8879 .cmd = IPW_PRIV_SET_PREAMBLE,
8880 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
8881 .name = "set_preamble"},
8883 .cmd = IPW_PRIV_GET_PREAMBLE,
8884 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
8885 .name = "get_preamble"},
8888 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
8891 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
8892 #ifdef CONFIG_IPW2200_MONITOR
8894 IPW_PRIV_SET_MONITOR,
8895 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
8896 #endif /* CONFIG_IPW2200_MONITOR */
8899 static iw_handler ipw_priv_handler[] = {
8900 ipw_wx_set_powermode,
8901 ipw_wx_get_powermode,
8902 ipw_wx_set_wireless_mode,
8903 ipw_wx_get_wireless_mode,
8904 ipw_wx_set_preamble,
8905 ipw_wx_get_preamble,
8908 #ifdef CONFIG_IPW2200_MONITOR
8913 static struct iw_handler_def ipw_wx_handler_def = {
8914 .standard = ipw_wx_handlers,
8915 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
8916 .num_private = ARRAY_SIZE(ipw_priv_handler),
8917 .num_private_args = ARRAY_SIZE(ipw_priv_args),
8918 .private = ipw_priv_handler,
8919 .private_args = ipw_priv_args,
8922 static struct iw_public_data ipw_wx_data;
8925 * Get wireless statistics.
8926 * Called by /proc/net/wireless
8927 * Also called by SIOCGIWSTATS
8929 static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
8931 struct ipw_priv *priv = ieee80211_priv(dev);
8932 struct iw_statistics *wstats;
8934 wstats = &priv->wstats;
8936 /* if hw is disabled, then ipw_get_ordinal() can't be called.
8937 * ipw2100_wx_wireless_stats seems to be called before fw is
8938 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
8939 * and associated; if not associcated, the values are all meaningless
8940 * anyway, so set them all to NULL and INVALID */
8941 if (!(priv->status & STATUS_ASSOCIATED)) {
8942 wstats->miss.beacon = 0;
8943 wstats->discard.retries = 0;
8944 wstats->qual.qual = 0;
8945 wstats->qual.level = 0;
8946 wstats->qual.noise = 0;
8947 wstats->qual.updated = 7;
8948 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
8949 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
8953 wstats->qual.qual = priv->quality;
8954 wstats->qual.level = average_value(&priv->average_rssi);
8955 wstats->qual.noise = average_value(&priv->average_noise);
8956 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
8957 IW_QUAL_NOISE_UPDATED;
8959 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
8960 wstats->discard.retries = priv->last_tx_failures;
8961 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
8963 /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
8964 goto fail_get_ordinal;
8965 wstats->discard.retries += tx_retry; */
8970 /* net device stuff */
8972 static inline void init_sys_config(struct ipw_sys_config *sys_config)
8974 memset(sys_config, 0, sizeof(struct ipw_sys_config));
8975 sys_config->bt_coexistence = 1; /* We may need to look into prvStaBtConfig */
8976 sys_config->answer_broadcast_ssid_probe = 0;
8977 sys_config->accept_all_data_frames = 0;
8978 sys_config->accept_non_directed_frames = 1;
8979 sys_config->exclude_unicast_unencrypted = 0;
8980 sys_config->disable_unicast_decryption = 1;
8981 sys_config->exclude_multicast_unencrypted = 0;
8982 sys_config->disable_multicast_decryption = 1;
8983 sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
8984 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
8985 sys_config->dot11g_auto_detection = 0;
8986 sys_config->enable_cts_to_self = 0;
8987 sys_config->bt_coexist_collision_thr = 0;
8988 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
8991 static int ipw_net_open(struct net_device *dev)
8993 struct ipw_priv *priv = ieee80211_priv(dev);
8994 IPW_DEBUG_INFO("dev->open\n");
8995 /* we should be verifying the device is ready to be opened */
8997 if (!(priv->status & STATUS_RF_KILL_MASK) &&
8998 (priv->status & STATUS_ASSOCIATED))
8999 netif_start_queue(dev);
9004 static int ipw_net_stop(struct net_device *dev)
9006 IPW_DEBUG_INFO("dev->close\n");
9007 netif_stop_queue(dev);
9014 modify to send one tfd per fragment instead of using chunking. otherwise
9015 we need to heavily modify the ieee80211_skb_to_txb.
9018 static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
9021 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
9022 txb->fragments[0]->data;
9024 struct tfd_frame *tfd;
9025 #ifdef CONFIG_IPW_QOS
9026 int tx_id = ipw_get_tx_queue_number(priv, pri);
9027 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9029 struct clx2_tx_queue *txq = &priv->txq[0];
9031 struct clx2_queue *q = &txq->q;
9032 u8 id, hdr_len, unicast;
9033 u16 remaining_bytes;
9036 switch (priv->ieee->iw_mode) {
9038 hdr_len = IEEE80211_3ADDR_LEN;
9039 unicast = !is_broadcast_ether_addr(hdr->addr1) &&
9040 !is_multicast_ether_addr(hdr->addr1);
9041 id = ipw_find_station(priv, hdr->addr1);
9042 if (id == IPW_INVALID_STATION) {
9043 id = ipw_add_station(priv, hdr->addr1);
9044 if (id == IPW_INVALID_STATION) {
9045 IPW_WARNING("Attempt to send data to "
9046 "invalid cell: " MAC_FMT "\n",
9047 MAC_ARG(hdr->addr1));
9055 unicast = !is_broadcast_ether_addr(hdr->addr3) &&
9056 !is_multicast_ether_addr(hdr->addr3);
9057 hdr_len = IEEE80211_3ADDR_LEN;
9062 tfd = &txq->bd[q->first_empty];
9063 txq->txb[q->first_empty] = txb;
9064 memset(tfd, 0, sizeof(*tfd));
9065 tfd->u.data.station_number = id;
9067 tfd->control_flags.message_type = TX_FRAME_TYPE;
9068 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
9070 tfd->u.data.cmd_id = DINO_CMD_TX;
9071 tfd->u.data.len = cpu_to_le16(txb->payload_size);
9072 remaining_bytes = txb->payload_size;
9074 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
9075 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
9077 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
9079 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
9080 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
9082 fc = le16_to_cpu(hdr->frame_ctl);
9083 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
9085 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
9087 if (likely(unicast))
9088 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9090 if (txb->encrypted && !priv->ieee->host_encrypt) {
9091 switch (priv->ieee->sec.level) {
9093 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9094 IEEE80211_FCTL_PROTECTED;
9095 /* XXX: ACK flag must be set for CCMP even if it
9096 * is a multicast/broadcast packet, because CCMP
9097 * group communication encrypted by GTK is
9098 * actually done by the AP. */
9100 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9102 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9103 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
9104 tfd->u.data.key_index = 0;
9105 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
9108 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9109 IEEE80211_FCTL_PROTECTED;
9110 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9111 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
9112 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
9115 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9116 IEEE80211_FCTL_PROTECTED;
9117 tfd->u.data.key_index = priv->ieee->tx_keyidx;
9118 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
9120 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
9122 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
9127 printk(KERN_ERR "Unknow security level %d\n",
9128 priv->ieee->sec.level);
9132 /* No hardware encryption */
9133 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
9135 #ifdef CONFIG_IPW_QOS
9136 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast);
9137 #endif /* CONFIG_IPW_QOS */
9140 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
9142 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
9143 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
9144 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
9145 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
9146 i, le32_to_cpu(tfd->u.data.num_chunks),
9147 txb->fragments[i]->len - hdr_len);
9148 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
9149 i, tfd->u.data.num_chunks,
9150 txb->fragments[i]->len - hdr_len);
9151 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
9152 txb->fragments[i]->len - hdr_len);
9154 tfd->u.data.chunk_ptr[i] =
9155 cpu_to_le32(pci_map_single
9157 txb->fragments[i]->data + hdr_len,
9158 txb->fragments[i]->len - hdr_len,
9160 tfd->u.data.chunk_len[i] =
9161 cpu_to_le16(txb->fragments[i]->len - hdr_len);
9164 if (i != txb->nr_frags) {
9165 struct sk_buff *skb;
9166 u16 remaining_bytes = 0;
9169 for (j = i; j < txb->nr_frags; j++)
9170 remaining_bytes += txb->fragments[j]->len - hdr_len;
9172 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
9174 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
9176 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
9177 for (j = i; j < txb->nr_frags; j++) {
9178 int size = txb->fragments[j]->len - hdr_len;
9179 printk(KERN_INFO "Adding frag %d %d...\n",
9181 memcpy(skb_put(skb, size),
9182 txb->fragments[j]->data + hdr_len, size);
9184 dev_kfree_skb_any(txb->fragments[i]);
9185 txb->fragments[i] = skb;
9186 tfd->u.data.chunk_ptr[i] =
9187 cpu_to_le32(pci_map_single
9188 (priv->pci_dev, skb->data,
9189 tfd->u.data.chunk_len[i],
9192 tfd->u.data.num_chunks =
9193 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
9199 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
9200 ipw_write32(priv, q->reg_w, q->first_empty);
9202 if (ipw_queue_space(q) < q->high_mark)
9203 netif_stop_queue(priv->net_dev);
9208 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
9209 ieee80211_txb_free(txb);
9212 static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
9213 struct net_device *dev, int pri)
9215 struct ipw_priv *priv = ieee80211_priv(dev);
9216 unsigned long flags;
9218 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
9219 spin_lock_irqsave(&priv->lock, flags);
9221 if (!(priv->status & STATUS_ASSOCIATED)) {
9222 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
9223 priv->ieee->stats.tx_carrier_errors++;
9224 netif_stop_queue(dev);
9228 ipw_tx_skb(priv, txb, pri);
9229 __ipw_led_activity_on(priv);
9230 spin_unlock_irqrestore(&priv->lock, flags);
9235 spin_unlock_irqrestore(&priv->lock, flags);
9239 static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
9241 struct ipw_priv *priv = ieee80211_priv(dev);
9243 priv->ieee->stats.tx_packets = priv->tx_packets;
9244 priv->ieee->stats.rx_packets = priv->rx_packets;
9245 return &priv->ieee->stats;
9248 static void ipw_net_set_multicast_list(struct net_device *dev)
9253 static int ipw_net_set_mac_address(struct net_device *dev, void *p)
9255 struct ipw_priv *priv = ieee80211_priv(dev);
9256 struct sockaddr *addr = p;
9257 if (!is_valid_ether_addr(addr->sa_data))
9258 return -EADDRNOTAVAIL;
9260 priv->config |= CFG_CUSTOM_MAC;
9261 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
9262 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
9263 priv->net_dev->name, MAC_ARG(priv->mac_addr));
9264 queue_work(priv->workqueue, &priv->adapter_restart);
9269 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
9270 struct ethtool_drvinfo *info)
9272 struct ipw_priv *p = ieee80211_priv(dev);
9277 strcpy(info->driver, DRV_NAME);
9278 strcpy(info->version, DRV_VERSION);
9281 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
9283 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
9285 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
9287 strcpy(info->bus_info, pci_name(p->pci_dev));
9288 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
9291 static u32 ipw_ethtool_get_link(struct net_device *dev)
9293 struct ipw_priv *priv = ieee80211_priv(dev);
9294 return (priv->status & STATUS_ASSOCIATED) != 0;
9297 static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
9299 return IPW_EEPROM_IMAGE_SIZE;
9302 static int ipw_ethtool_get_eeprom(struct net_device *dev,
9303 struct ethtool_eeprom *eeprom, u8 * bytes)
9305 struct ipw_priv *p = ieee80211_priv(dev);
9307 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
9310 memcpy(bytes, &((u8 *) p->eeprom)[eeprom->offset], eeprom->len);
9315 static int ipw_ethtool_set_eeprom(struct net_device *dev,
9316 struct ethtool_eeprom *eeprom, u8 * bytes)
9318 struct ipw_priv *p = ieee80211_priv(dev);
9321 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
9324 memcpy(&((u8 *) p->eeprom)[eeprom->offset], bytes, eeprom->len);
9325 for (i = IPW_EEPROM_DATA;
9326 i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++)
9327 ipw_write8(p, i, p->eeprom[i]);
9332 static struct ethtool_ops ipw_ethtool_ops = {
9333 .get_link = ipw_ethtool_get_link,
9334 .get_drvinfo = ipw_ethtool_get_drvinfo,
9335 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
9336 .get_eeprom = ipw_ethtool_get_eeprom,
9337 .set_eeprom = ipw_ethtool_set_eeprom,
9340 static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
9342 struct ipw_priv *priv = data;
9343 u32 inta, inta_mask;
9348 spin_lock(&priv->lock);
9350 if (!(priv->status & STATUS_INT_ENABLED)) {
9355 inta = ipw_read32(priv, IPW_INTA_RW);
9356 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
9358 if (inta == 0xFFFFFFFF) {
9359 /* Hardware disappeared */
9360 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
9364 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
9365 /* Shared interrupt */
9369 /* tell the device to stop sending interrupts */
9370 ipw_disable_interrupts(priv);
9372 /* ack current interrupts */
9373 inta &= (IPW_INTA_MASK_ALL & inta_mask);
9374 ipw_write32(priv, IPW_INTA_RW, inta);
9376 /* Cache INTA value for our tasklet */
9377 priv->isr_inta = inta;
9379 tasklet_schedule(&priv->irq_tasklet);
9381 spin_unlock(&priv->lock);
9385 spin_unlock(&priv->lock);
9389 static void ipw_rf_kill(void *adapter)
9391 struct ipw_priv *priv = adapter;
9392 unsigned long flags;
9394 spin_lock_irqsave(&priv->lock, flags);
9396 if (rf_kill_active(priv)) {
9397 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
9398 if (priv->workqueue)
9399 queue_delayed_work(priv->workqueue,
9400 &priv->rf_kill, 2 * HZ);
9404 /* RF Kill is now disabled, so bring the device back up */
9406 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9407 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
9410 /* we can not do an adapter restart while inside an irq lock */
9411 queue_work(priv->workqueue, &priv->adapter_restart);
9413 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
9417 spin_unlock_irqrestore(&priv->lock, flags);
9420 static void ipw_bg_rf_kill(void *data)
9422 struct ipw_priv *priv = data;
9428 void ipw_link_up(struct ipw_priv *priv)
9430 netif_carrier_on(priv->net_dev);
9431 if (netif_queue_stopped(priv->net_dev)) {
9432 IPW_DEBUG_NOTIF("waking queue\n");
9433 netif_wake_queue(priv->net_dev);
9435 IPW_DEBUG_NOTIF("starting queue\n");
9436 netif_start_queue(priv->net_dev);
9439 cancel_delayed_work(&priv->request_scan);
9440 ipw_reset_stats(priv);
9441 /* Ensure the rate is updated immediately */
9442 priv->last_rate = ipw_get_current_rate(priv);
9443 ipw_gather_stats(priv);
9444 ipw_led_link_up(priv);
9445 notify_wx_assoc_event(priv);
9447 if (priv->config & CFG_BACKGROUND_SCAN)
9448 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
9451 static void ipw_bg_link_up(void *data)
9453 struct ipw_priv *priv = data;
9459 void ipw_link_down(struct ipw_priv *priv)
9461 ipw_led_link_down(priv);
9462 netif_carrier_off(priv->net_dev);
9463 netif_stop_queue(priv->net_dev);
9464 notify_wx_assoc_event(priv);
9466 /* Cancel any queued work ... */
9467 cancel_delayed_work(&priv->request_scan);
9468 cancel_delayed_work(&priv->adhoc_check);
9469 cancel_delayed_work(&priv->gather_stats);
9471 ipw_reset_stats(priv);
9473 /* Queue up another scan... */
9474 queue_work(priv->workqueue, &priv->request_scan);
9477 static void ipw_bg_link_down(void *data)
9479 struct ipw_priv *priv = data;
9481 ipw_link_down(data);
9485 static int ipw_setup_deferred_work(struct ipw_priv *priv)
9489 priv->workqueue = create_workqueue(DRV_NAME);
9490 init_waitqueue_head(&priv->wait_command_queue);
9492 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
9493 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
9494 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
9495 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
9496 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
9497 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
9498 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
9499 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
9500 INIT_WORK(&priv->request_scan,
9501 (void (*)(void *))ipw_request_scan, priv);
9502 INIT_WORK(&priv->gather_stats,
9503 (void (*)(void *))ipw_bg_gather_stats, priv);
9504 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
9505 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
9506 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
9507 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
9508 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
9509 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
9511 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
9513 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
9515 INIT_WORK(&priv->merge_networks,
9516 (void (*)(void *))ipw_merge_adhoc_network, priv);
9518 #ifdef CONFIG_IPW_QOS
9519 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
9521 #endif /* CONFIG_IPW_QOS */
9523 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
9524 ipw_irq_tasklet, (unsigned long)priv);
9529 static void shim__set_security(struct net_device *dev,
9530 struct ieee80211_security *sec)
9532 struct ipw_priv *priv = ieee80211_priv(dev);
9535 for (i = 0; i < 4; i++) {
9536 if (sec->flags & (1 << i)) {
9537 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
9538 if (sec->key_sizes[i] == 0)
9539 priv->ieee->sec.flags &= ~(1 << i);
9541 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
9543 priv->ieee->sec.flags |= (1 << i);
9545 priv->status |= STATUS_SECURITY_UPDATED;
9546 } else if (sec->level != SEC_LEVEL_1)
9547 priv->ieee->sec.flags &= ~(1 << i);
9550 if (sec->flags & SEC_ACTIVE_KEY) {
9551 if (sec->active_key <= 3) {
9552 priv->ieee->sec.active_key = sec->active_key;
9553 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
9555 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
9556 priv->status |= STATUS_SECURITY_UPDATED;
9558 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
9560 if ((sec->flags & SEC_AUTH_MODE) &&
9561 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
9562 priv->ieee->sec.auth_mode = sec->auth_mode;
9563 priv->ieee->sec.flags |= SEC_AUTH_MODE;
9564 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
9565 priv->capability |= CAP_SHARED_KEY;
9567 priv->capability &= ~CAP_SHARED_KEY;
9568 priv->status |= STATUS_SECURITY_UPDATED;
9571 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
9572 priv->ieee->sec.flags |= SEC_ENABLED;
9573 priv->ieee->sec.enabled = sec->enabled;
9574 priv->status |= STATUS_SECURITY_UPDATED;
9576 priv->capability |= CAP_PRIVACY_ON;
9578 priv->capability &= ~CAP_PRIVACY_ON;
9580 priv->ieee->sec.encrypt = sec->encrypt;
9582 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
9583 priv->ieee->sec.level = sec->level;
9584 priv->ieee->sec.flags |= SEC_LEVEL;
9585 priv->status |= STATUS_SECURITY_UPDATED;
9588 if (!priv->ieee->host_encrypt)
9589 ipw_set_hwcrypto_keys(priv);
9591 /* To match current functionality of ipw2100 (which works well w/
9592 * various supplicants, we don't force a disassociate if the
9593 * privacy capability changes ... */
9595 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
9596 (((priv->assoc_request.capability &
9597 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
9598 (!(priv->assoc_request.capability &
9599 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
9600 IPW_DEBUG_ASSOC("Disassociating due to capability "
9602 ipw_disassociate(priv);
9608 static int init_supported_rates(struct ipw_priv *priv,
9609 struct ipw_supported_rates *rates)
9611 /* TODO: Mask out rates based on priv->rates_mask */
9613 memset(rates, 0, sizeof(*rates));
9614 /* configure supported rates */
9615 switch (priv->ieee->freq_band) {
9616 case IEEE80211_52GHZ_BAND:
9617 rates->ieee_mode = IPW_A_MODE;
9618 rates->purpose = IPW_RATE_CAPABILITIES;
9619 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
9620 IEEE80211_OFDM_DEFAULT_RATES_MASK);
9623 default: /* Mixed or 2.4Ghz */
9624 rates->ieee_mode = IPW_G_MODE;
9625 rates->purpose = IPW_RATE_CAPABILITIES;
9626 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
9627 IEEE80211_CCK_DEFAULT_RATES_MASK);
9628 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
9629 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
9630 IEEE80211_OFDM_DEFAULT_RATES_MASK);
9638 static int ipw_config(struct ipw_priv *priv)
9641 struct ipw_tx_power tx_power;
9643 memset(&priv->sys_config, 0, sizeof(priv->sys_config));
9644 memset(&tx_power, 0, sizeof(tx_power));
9646 /* This is only called from ipw_up, which resets/reloads the firmware
9647 so, we don't need to first disable the card before we configure
9650 /* configure device for 'G' band */
9651 tx_power.ieee_mode = IPW_G_MODE;
9652 tx_power.num_channels = 11;
9653 for (i = 0; i < 11; i++) {
9654 tx_power.channels_tx_power[i].channel_number = i + 1;
9655 tx_power.channels_tx_power[i].tx_power = priv->tx_power;
9657 if (ipw_send_tx_power(priv, &tx_power))
9660 /* configure device to also handle 'B' band */
9661 tx_power.ieee_mode = IPW_B_MODE;
9662 if (ipw_send_tx_power(priv, &tx_power))
9665 /* initialize adapter address */
9666 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
9669 /* set basic system config settings */
9670 init_sys_config(&priv->sys_config);
9671 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
9672 priv->sys_config.answer_broadcast_ssid_probe = 1;
9674 priv->sys_config.answer_broadcast_ssid_probe = 0;
9676 if (ipw_send_system_config(priv, &priv->sys_config))
9679 init_supported_rates(priv, &priv->rates);
9680 if (ipw_send_supported_rates(priv, &priv->rates))
9683 /* Set request-to-send threshold */
9684 if (priv->rts_threshold) {
9685 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
9688 #ifdef CONFIG_IPW_QOS
9689 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
9690 ipw_qos_activate(priv, NULL);
9691 #endif /* CONFIG_IPW_QOS */
9693 if (ipw_set_random_seed(priv))
9696 /* final state transition to the RUN state */
9697 if (ipw_send_host_complete(priv))
9700 /* If configured to try and auto-associate, kick off a scan */
9701 if (priv->config & CFG_ASSOCIATE)
9702 queue_work(priv->workqueue, &priv->request_scan);
9710 #define MAX_HW_RESTARTS 5
9711 static int ipw_up(struct ipw_priv *priv)
9715 if (priv->status & STATUS_EXIT_PENDING)
9718 for (i = 0; i < MAX_HW_RESTARTS; i++) {
9719 /* Load the microcode, firmware, and eeprom.
9720 * Also start the clocks. */
9721 rc = ipw_load(priv);
9723 IPW_ERROR("Unable to load firmware: 0x%08X\n", rc);
9727 ipw_init_ordinals(priv);
9728 if (!(priv->config & CFG_CUSTOM_MAC))
9729 eeprom_parse_mac(priv, priv->mac_addr);
9730 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
9732 if (priv->status & STATUS_RF_KILL_SW) {
9733 IPW_WARNING("Radio disabled by module parameter.\n");
9735 } else if (rf_kill_active(priv)) {
9736 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
9737 "Kill switch must be turned off for "
9738 "wireless networking to work.\n");
9739 queue_delayed_work(priv->workqueue, &priv->rf_kill,
9744 rc = ipw_config(priv);
9746 IPW_DEBUG_INFO("Configured device on count %i\n", i);
9748 ipw_led_radio_on(priv);
9749 priv->notif_missed_beacons = 0;
9750 priv->status |= STATUS_INIT;
9754 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
9755 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
9756 i, MAX_HW_RESTARTS);
9758 /* We had an error bringing up the hardware, so take it
9759 * all the way back down so we can try again */
9763 /* tried to restart and config the device for as long as our
9764 * patience could withstand */
9765 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
9770 static void ipw_bg_up(void *data)
9772 struct ipw_priv *priv = data;
9778 static void ipw_deinit(struct ipw_priv *priv)
9782 if (priv->status & STATUS_SCANNING) {
9783 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
9784 ipw_abort_scan(priv);
9787 if (priv->status & STATUS_ASSOCIATED) {
9788 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
9789 ipw_disassociate(priv);
9792 ipw_led_shutdown(priv);
9794 /* Wait up to 1s for status to change to not scanning and not
9795 * associated (disassociation can take a while for a ful 802.11
9797 for (i = 1000; i && (priv->status &
9798 (STATUS_DISASSOCIATING |
9799 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
9802 if (priv->status & (STATUS_DISASSOCIATING |
9803 STATUS_ASSOCIATED | STATUS_SCANNING))
9804 IPW_DEBUG_INFO("Still associated or scanning...\n");
9806 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
9808 /* Attempt to disable the card */
9809 ipw_send_card_disable(priv, 0);
9811 priv->status &= ~STATUS_INIT;
9814 static void ipw_down(struct ipw_priv *priv)
9816 int exit_pending = priv->status & STATUS_EXIT_PENDING;
9818 priv->status |= STATUS_EXIT_PENDING;
9820 if (ipw_is_init(priv))
9823 /* Wipe out the EXIT_PENDING status bit if we are not actually
9824 * exiting the module */
9826 priv->status &= ~STATUS_EXIT_PENDING;
9828 /* tell the device to stop sending interrupts */
9829 ipw_disable_interrupts(priv);
9831 /* Clear all bits but the RF Kill */
9832 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
9833 netif_carrier_off(priv->net_dev);
9834 netif_stop_queue(priv->net_dev);
9838 ipw_led_radio_off(priv);
9841 static void ipw_bg_down(void *data)
9843 struct ipw_priv *priv = data;
9849 static int ipw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
9851 struct iwreq *wrq = (struct iwreq *)rq;
9854 case IPW_IOCTL_WPA_SUPPLICANT:
9855 ret = ipw_wpa_supplicant(dev, &wrq->u.data);
9865 /* Called by register_netdev() */
9866 static int ipw_net_init(struct net_device *dev)
9868 struct ipw_priv *priv = ieee80211_priv(dev);
9880 /* PCI driver stuff */
9881 static struct pci_device_id card_ids[] = {
9882 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
9883 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
9884 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
9885 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
9886 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
9887 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
9888 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
9889 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
9890 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
9891 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
9892 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
9893 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
9894 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
9895 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
9896 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
9897 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
9898 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
9899 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
9900 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
9901 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
9902 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
9903 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
9905 /* required last entry */
9909 MODULE_DEVICE_TABLE(pci, card_ids);
9911 static struct attribute *ipw_sysfs_entries[] = {
9912 &dev_attr_rf_kill.attr,
9913 &dev_attr_direct_dword.attr,
9914 &dev_attr_indirect_byte.attr,
9915 &dev_attr_indirect_dword.attr,
9916 &dev_attr_mem_gpio_reg.attr,
9917 &dev_attr_command_event_reg.attr,
9918 &dev_attr_nic_type.attr,
9919 &dev_attr_status.attr,
9921 &dev_attr_dump_errors.attr,
9922 &dev_attr_dump_events.attr,
9923 &dev_attr_eeprom_delay.attr,
9924 &dev_attr_ucode_version.attr,
9926 &dev_attr_scan_age.attr,
9928 &dev_attr_speed_scan.attr,
9929 &dev_attr_net_stats.attr,
9933 static struct attribute_group ipw_attribute_group = {
9934 .name = NULL, /* put in device directory */
9935 .attrs = ipw_sysfs_entries,
9938 static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
9941 struct net_device *net_dev;
9944 struct ipw_priv *priv;
9946 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
9947 if (net_dev == NULL) {
9952 priv = ieee80211_priv(net_dev);
9953 priv->ieee = netdev_priv(net_dev);
9955 priv->net_dev = net_dev;
9956 priv->pci_dev = pdev;
9957 #ifdef CONFIG_IPW_DEBUG
9958 ipw_debug_level = debug;
9960 spin_lock_init(&priv->lock);
9962 init_MUTEX(&priv->sem);
9963 if (pci_enable_device(pdev)) {
9965 goto out_free_ieee80211;
9968 pci_set_master(pdev);
9970 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
9972 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
9974 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
9975 goto out_pci_disable_device;
9978 pci_set_drvdata(pdev, priv);
9980 err = pci_request_regions(pdev, DRV_NAME);
9982 goto out_pci_disable_device;
9984 /* We disable the RETRY_TIMEOUT register (0x41) to keep
9985 * PCI Tx retries from interfering with C3 CPU state */
9986 pci_read_config_dword(pdev, 0x40, &val);
9987 if ((val & 0x0000ff00) != 0)
9988 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
9990 length = pci_resource_len(pdev, 0);
9991 priv->hw_len = length;
9993 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
9996 goto out_pci_release_regions;
9999 priv->hw_base = base;
10000 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
10001 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
10003 err = ipw_setup_deferred_work(priv);
10005 IPW_ERROR("Unable to setup deferred work\n");
10009 ipw_sw_reset(priv, 1);
10011 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
10013 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
10014 goto out_destroy_workqueue;
10017 SET_MODULE_OWNER(net_dev);
10018 SET_NETDEV_DEV(net_dev, &pdev->dev);
10020 ipw_wx_data.spy_data = &priv->ieee->spy_data;
10021 ipw_wx_data.ieee80211 = priv->ieee;
10025 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
10026 priv->ieee->set_security = shim__set_security;
10028 #ifdef CONFIG_IPW_QOS
10029 priv->ieee->handle_management_frame = ipw_handle_management_frame;
10030 #endif /* CONFIG_IPW_QOS */
10032 priv->ieee->perfect_rssi = -20;
10033 priv->ieee->worst_rssi = -85;
10035 net_dev->open = ipw_net_open;
10036 net_dev->stop = ipw_net_stop;
10037 net_dev->init = ipw_net_init;
10038 net_dev->do_ioctl = ipw_ioctl;
10039 net_dev->get_stats = ipw_net_get_stats;
10040 net_dev->set_multicast_list = ipw_net_set_multicast_list;
10041 net_dev->set_mac_address = ipw_net_set_mac_address;
10042 net_dev->get_wireless_stats = ipw_get_wireless_stats;
10043 net_dev->wireless_data = &ipw_wx_data;
10044 net_dev->wireless_handlers = &ipw_wx_handler_def;
10045 net_dev->ethtool_ops = &ipw_ethtool_ops;
10046 net_dev->irq = pdev->irq;
10047 net_dev->base_addr = (unsigned long)priv->hw_base;
10048 net_dev->mem_start = pci_resource_start(pdev, 0);
10049 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
10051 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
10053 IPW_ERROR("failed to create sysfs device attributes\n");
10055 goto out_release_irq;
10059 err = register_netdev(net_dev);
10061 IPW_ERROR("failed to register network device\n");
10062 goto out_remove_sysfs;
10067 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
10069 free_irq(pdev->irq, priv);
10070 out_destroy_workqueue:
10071 destroy_workqueue(priv->workqueue);
10072 priv->workqueue = NULL;
10074 iounmap(priv->hw_base);
10075 out_pci_release_regions:
10076 pci_release_regions(pdev);
10077 out_pci_disable_device:
10078 pci_disable_device(pdev);
10079 pci_set_drvdata(pdev, NULL);
10080 out_free_ieee80211:
10081 free_ieee80211(priv->net_dev);
10086 static void ipw_pci_remove(struct pci_dev *pdev)
10088 struct ipw_priv *priv = pci_get_drvdata(pdev);
10095 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
10098 unregister_netdev(priv->net_dev);
10101 ipw_rx_queue_free(priv, priv->rxq);
10104 ipw_tx_queue_free(priv);
10106 /* ipw_down will ensure that there is no more pending work
10107 * in the workqueue's, so we can safely remove them now. */
10108 cancel_delayed_work(&priv->adhoc_check);
10109 cancel_delayed_work(&priv->gather_stats);
10110 cancel_delayed_work(&priv->request_scan);
10111 cancel_delayed_work(&priv->rf_kill);
10112 cancel_delayed_work(&priv->scan_check);
10113 destroy_workqueue(priv->workqueue);
10114 priv->workqueue = NULL;
10116 free_irq(pdev->irq, priv);
10117 iounmap(priv->hw_base);
10118 pci_release_regions(pdev);
10119 pci_disable_device(pdev);
10120 pci_set_drvdata(pdev, NULL);
10121 free_ieee80211(priv->net_dev);
10125 release_firmware(bootfw);
10126 release_firmware(ucode);
10127 release_firmware(firmware);
10134 static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
10136 struct ipw_priv *priv = pci_get_drvdata(pdev);
10137 struct net_device *dev = priv->net_dev;
10139 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
10141 /* Take down the device; powers it off, etc. */
10144 /* Remove the PRESENT state of the device */
10145 netif_device_detach(dev);
10147 pci_save_state(pdev);
10148 pci_disable_device(pdev);
10149 pci_set_power_state(pdev, pci_choose_state(pdev, state));
10154 static int ipw_pci_resume(struct pci_dev *pdev)
10156 struct ipw_priv *priv = pci_get_drvdata(pdev);
10157 struct net_device *dev = priv->net_dev;
10160 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
10162 pci_set_power_state(pdev, PCI_D0);
10163 pci_enable_device(pdev);
10164 pci_restore_state(pdev);
10167 * Suspend/Resume resets the PCI configuration space, so we have to
10168 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
10169 * from interfering with C3 CPU state. pci_restore_state won't help
10170 * here since it only restores the first 64 bytes pci config header.
10172 pci_read_config_dword(pdev, 0x40, &val);
10173 if ((val & 0x0000ff00) != 0)
10174 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
10176 /* Set the device back into the PRESENT state; this will also wake
10177 * the queue of needed */
10178 netif_device_attach(dev);
10180 /* Bring the device back up */
10181 queue_work(priv->workqueue, &priv->up);
10187 /* driver initialization stuff */
10188 static struct pci_driver ipw_driver = {
10190 .id_table = card_ids,
10191 .probe = ipw_pci_probe,
10192 .remove = __devexit_p(ipw_pci_remove),
10194 .suspend = ipw_pci_suspend,
10195 .resume = ipw_pci_resume,
10199 static int __init ipw_init(void)
10203 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
10204 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
10206 ret = pci_module_init(&ipw_driver);
10208 IPW_ERROR("Unable to initialize PCI module\n");
10212 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
10214 IPW_ERROR("Unable to create driver sysfs file\n");
10215 pci_unregister_driver(&ipw_driver);
10222 static void __exit ipw_exit(void)
10224 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
10225 pci_unregister_driver(&ipw_driver);
10228 module_param(disable, int, 0444);
10229 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
10231 module_param(associate, int, 0444);
10232 MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
10234 module_param(auto_create, int, 0444);
10235 MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
10237 module_param(led, int, 0444);
10238 MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
10240 module_param(debug, int, 0444);
10241 MODULE_PARM_DESC(debug, "debug output mask");
10243 module_param(channel, int, 0444);
10244 MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
10246 #ifdef CONFIG_IPW_QOS
10247 module_param(qos_enable, int, 0444);
10248 MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
10250 module_param(qos_burst_enable, int, 0444);
10251 MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
10253 module_param(qos_no_ack_mask, int, 0444);
10254 MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
10256 module_param(burst_duration_CCK, int, 0444);
10257 MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
10259 module_param(burst_duration_OFDM, int, 0444);
10260 MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
10261 #endif /* CONFIG_IPW_QOS */
10263 #ifdef CONFIG_IPW2200_MONITOR
10264 module_param(mode, int, 0444);
10265 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
10267 module_param(mode, int, 0444);
10268 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
10271 module_param(hwcrypto, int, 0444);
10272 MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default on)");
10274 module_exit(ipw_exit);
10275 module_init(ipw_init);