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.2"
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 MODULE_DESCRIPTION(DRV_DESCRIPTION);
41 MODULE_VERSION(DRV_VERSION);
42 MODULE_AUTHOR(DRV_COPYRIGHT);
43 MODULE_LICENSE("GPL");
46 static int channel = 0;
49 static u32 ipw_debug_level;
50 static int associate = 1;
51 static int auto_create = 1;
53 static int disable = 0;
54 static const char ipw_modes[] = {
58 static void ipw_rx(struct ipw_priv *priv);
59 static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
60 struct clx2_tx_queue *txq, int qindex);
61 static int ipw_queue_reset(struct ipw_priv *priv);
63 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
66 static void ipw_tx_queue_free(struct ipw_priv *);
68 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
69 static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
70 static void ipw_rx_queue_replenish(void *);
72 static int ipw_up(struct ipw_priv *);
73 static void ipw_down(struct ipw_priv *);
74 static int ipw_config(struct ipw_priv *);
75 static int init_supported_rates(struct ipw_priv *priv,
76 struct ipw_supported_rates *prates);
78 static u8 band_b_active_channel[MAX_B_CHANNELS] = {
79 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0
81 static u8 band_a_active_channel[MAX_A_CHANNELS] = {
82 36, 40, 44, 48, 149, 153, 157, 161, 165, 52, 56, 60, 64, 0
85 static int is_valid_channel(int mode_mask, int channel)
92 if (mode_mask & IEEE_A)
93 for (i = 0; i < MAX_A_CHANNELS; i++)
94 if (band_a_active_channel[i] == channel)
97 if (mode_mask & (IEEE_B | IEEE_G))
98 for (i = 0; i < MAX_B_CHANNELS; i++)
99 if (band_b_active_channel[i] == channel)
100 return mode_mask & (IEEE_B | IEEE_G);
105 static char *snprint_line(char *buf, size_t count,
106 const u8 * data, u32 len, u32 ofs)
111 out = snprintf(buf, count, "%08X", ofs);
113 for (l = 0, i = 0; i < 2; i++) {
114 out += snprintf(buf + out, count - out, " ");
115 for (j = 0; j < 8 && l < len; j++, l++)
116 out += snprintf(buf + out, count - out, "%02X ",
119 out += snprintf(buf + out, count - out, " ");
122 out += snprintf(buf + out, count - out, " ");
123 for (l = 0, i = 0; i < 2; i++) {
124 out += snprintf(buf + out, count - out, " ");
125 for (j = 0; j < 8 && l < len; j++, l++) {
126 c = data[(i * 8 + j)];
127 if (!isascii(c) || !isprint(c))
130 out += snprintf(buf + out, count - out, "%c", c);
134 out += snprintf(buf + out, count - out, " ");
140 static void printk_buf(int level, const u8 * data, u32 len)
144 if (!(ipw_debug_level & level))
148 printk(KERN_DEBUG "%s\n",
149 snprint_line(line, sizeof(line), &data[ofs],
150 min(len, 16U), ofs));
152 len -= min(len, 16U);
156 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
157 #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
159 static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
160 #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
162 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
163 static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
165 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
166 __LINE__, (u32) (b), (u32) (c));
167 _ipw_write_reg8(a, b, c);
170 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
171 static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
173 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
174 __LINE__, (u32) (b), (u32) (c));
175 _ipw_write_reg16(a, b, c);
178 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
179 static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
181 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
182 __LINE__, (u32) (b), (u32) (c));
183 _ipw_write_reg32(a, b, c);
186 #define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
187 #define ipw_write8(ipw, ofs, val) \
188 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
189 _ipw_write8(ipw, ofs, val)
191 #define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
192 #define ipw_write16(ipw, ofs, val) \
193 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
194 _ipw_write16(ipw, ofs, val)
196 #define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
197 #define ipw_write32(ipw, ofs, val) \
198 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
199 _ipw_write32(ipw, ofs, val)
201 #define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
202 static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
204 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
205 return _ipw_read8(ipw, ofs);
208 #define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
210 #define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
211 static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
213 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
214 return _ipw_read16(ipw, ofs);
217 #define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
219 #define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
220 static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
222 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
223 return _ipw_read32(ipw, ofs);
226 #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
228 static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
229 #define ipw_read_indirect(a, b, c, d) \
230 IPW_DEBUG_IO("%s %d: read_inddirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
231 _ipw_read_indirect(a, b, c, d)
233 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
235 #define ipw_write_indirect(a, b, c, d) \
236 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
237 _ipw_write_indirect(a, b, c, d)
239 /* indirect write s */
240 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
242 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
243 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg);
244 _ipw_write32(priv, CX2_INDIRECT_DATA, value);
247 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
249 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
250 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK);
251 _ipw_write8(priv, CX2_INDIRECT_DATA, value);
252 IPW_DEBUG_IO(" reg = 0x%8lX : value = 0x%8X\n",
253 (unsigned long)(priv->hw_base + CX2_INDIRECT_DATA), value);
256 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
258 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
259 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK);
260 _ipw_write16(priv, CX2_INDIRECT_DATA, value);
263 /* indirect read s */
265 static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
268 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK);
269 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
270 word = _ipw_read32(priv, CX2_INDIRECT_DATA);
271 return (word >> ((reg & 0x3) * 8)) & 0xff;
274 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
278 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
280 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg);
281 value = _ipw_read32(priv, CX2_INDIRECT_DATA);
282 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
286 /* iterative/auto-increment 32 bit reads and writes */
287 static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
290 u32 aligned_addr = addr & CX2_INDIRECT_ADDR_MASK;
291 u32 dif_len = addr - aligned_addr;
294 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
300 /* Read the first nibble byte by byte */
301 if (unlikely(dif_len)) {
302 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
303 /* Start reading at aligned_addr + dif_len */
304 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
305 *buf++ = _ipw_read8(priv, CX2_INDIRECT_DATA + i);
309 _ipw_write32(priv, CX2_AUTOINC_ADDR, aligned_addr);
310 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
311 *(u32 *) buf = _ipw_read32(priv, CX2_AUTOINC_DATA);
313 /* Copy the last nibble */
315 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
316 for (i = 0; num > 0; i++, num--)
317 *buf++ = ipw_read8(priv, CX2_INDIRECT_DATA + i);
321 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
324 u32 aligned_addr = addr & CX2_INDIRECT_ADDR_MASK;
325 u32 dif_len = addr - aligned_addr;
328 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
334 /* Write the first nibble byte by byte */
335 if (unlikely(dif_len)) {
336 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
337 /* Start reading at aligned_addr + dif_len */
338 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
339 _ipw_write8(priv, CX2_INDIRECT_DATA + i, *buf);
343 _ipw_write32(priv, CX2_AUTOINC_ADDR, aligned_addr);
344 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
345 _ipw_write32(priv, CX2_AUTOINC_DATA, *(u32 *) buf);
347 /* Copy the last nibble */
349 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
350 for (i = 0; num > 0; i++, num--, buf++)
351 _ipw_write8(priv, CX2_INDIRECT_DATA + i, *buf);
355 static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
358 memcpy_toio((priv->hw_base + addr), buf, num);
361 static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
363 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
366 static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
368 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
371 static inline void ipw_enable_interrupts(struct ipw_priv *priv)
373 if (priv->status & STATUS_INT_ENABLED)
375 priv->status |= STATUS_INT_ENABLED;
376 ipw_write32(priv, CX2_INTA_MASK_R, CX2_INTA_MASK_ALL);
379 static inline void ipw_disable_interrupts(struct ipw_priv *priv)
381 if (!(priv->status & STATUS_INT_ENABLED))
383 priv->status &= ~STATUS_INT_ENABLED;
384 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL);
387 static char *ipw_error_desc(u32 val)
390 case IPW_FW_ERROR_OK:
392 case IPW_FW_ERROR_FAIL:
394 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
395 return "MEMORY_UNDERFLOW";
396 case IPW_FW_ERROR_MEMORY_OVERFLOW:
397 return "MEMORY_OVERFLOW";
398 case IPW_FW_ERROR_BAD_PARAM:
399 return "ERROR_BAD_PARAM";
400 case IPW_FW_ERROR_BAD_CHECKSUM:
401 return "ERROR_BAD_CHECKSUM";
402 case IPW_FW_ERROR_NMI_INTERRUPT:
403 return "ERROR_NMI_INTERRUPT";
404 case IPW_FW_ERROR_BAD_DATABASE:
405 return "ERROR_BAD_DATABASE";
406 case IPW_FW_ERROR_ALLOC_FAIL:
407 return "ERROR_ALLOC_FAIL";
408 case IPW_FW_ERROR_DMA_UNDERRUN:
409 return "ERROR_DMA_UNDERRUN";
410 case IPW_FW_ERROR_DMA_STATUS:
411 return "ERROR_DMA_STATUS";
412 case IPW_FW_ERROR_DINOSTATUS_ERROR:
413 return "ERROR_DINOSTATUS_ERROR";
414 case IPW_FW_ERROR_EEPROMSTATUS_ERROR:
415 return "ERROR_EEPROMSTATUS_ERROR";
416 case IPW_FW_ERROR_SYSASSERT:
417 return "ERROR_SYSASSERT";
418 case IPW_FW_ERROR_FATAL_ERROR:
419 return "ERROR_FATALSTATUS_ERROR";
421 return "UNKNOWNSTATUS_ERROR";
425 static void ipw_dump_nic_error_log(struct ipw_priv *priv)
427 u32 desc, time, blink1, blink2, ilink1, ilink2, idata, i, count, base;
429 base = ipw_read32(priv, IPWSTATUS_ERROR_LOG);
430 count = ipw_read_reg32(priv, base);
432 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
433 IPW_ERROR("Start IPW Error Log Dump:\n");
434 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
435 priv->status, priv->config);
438 for (i = ERROR_START_OFFSET;
439 i <= count * ERROR_ELEM_SIZE; i += ERROR_ELEM_SIZE) {
440 desc = ipw_read_reg32(priv, base + i);
441 time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
442 blink1 = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
443 blink2 = ipw_read_reg32(priv, base + i + 3 * sizeof(u32));
444 ilink1 = ipw_read_reg32(priv, base + i + 4 * sizeof(u32));
445 ilink2 = ipw_read_reg32(priv, base + i + 5 * sizeof(u32));
446 idata = ipw_read_reg32(priv, base + i + 6 * sizeof(u32));
448 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
449 ipw_error_desc(desc), time, blink1, blink2,
450 ilink1, ilink2, idata);
454 static void ipw_dump_nic_event_log(struct ipw_priv *priv)
456 u32 ev, time, data, i, count, base;
458 base = ipw_read32(priv, IPW_EVENT_LOG);
459 count = ipw_read_reg32(priv, base);
461 if (EVENT_START_OFFSET <= count * EVENT_ELEM_SIZE)
462 IPW_ERROR("Start IPW Event Log Dump:\n");
464 for (i = EVENT_START_OFFSET;
465 i <= count * EVENT_ELEM_SIZE; i += EVENT_ELEM_SIZE) {
466 ev = ipw_read_reg32(priv, base + i);
467 time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
468 data = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
470 #ifdef CONFIG_IPW_DEBUG
471 IPW_ERROR("%i\t0x%08x\t%i\n", time, data, ev);
476 static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
478 u32 addr, field_info, field_len, field_count, total_len;
480 IPW_DEBUG_ORD("ordinal = %i\n", ord);
482 if (!priv || !val || !len) {
483 IPW_DEBUG_ORD("Invalid argument\n");
487 /* verify device ordinal tables have been initialized */
488 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
489 IPW_DEBUG_ORD("Access ordinals before initialization\n");
493 switch (IPW_ORD_TABLE_ID_MASK & ord) {
494 case IPW_ORD_TABLE_0_MASK:
496 * TABLE 0: Direct access to a table of 32 bit values
498 * This is a very simple table with the data directly
499 * read from the table
502 /* remove the table id from the ordinal */
503 ord &= IPW_ORD_TABLE_VALUE_MASK;
506 if (ord > priv->table0_len) {
507 IPW_DEBUG_ORD("ordinal value (%i) longer then "
508 "max (%i)\n", ord, priv->table0_len);
512 /* verify we have enough room to store the value */
513 if (*len < sizeof(u32)) {
514 IPW_DEBUG_ORD("ordinal buffer length too small, "
515 "need %zd\n", sizeof(u32));
519 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
520 ord, priv->table0_addr + (ord << 2));
524 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
527 case IPW_ORD_TABLE_1_MASK:
529 * TABLE 1: Indirect access to a table of 32 bit values
531 * This is a fairly large table of u32 values each
532 * representing starting addr for the data (which is
536 /* remove the table id from the ordinal */
537 ord &= IPW_ORD_TABLE_VALUE_MASK;
540 if (ord > priv->table1_len) {
541 IPW_DEBUG_ORD("ordinal value too long\n");
545 /* verify we have enough room to store the value */
546 if (*len < sizeof(u32)) {
547 IPW_DEBUG_ORD("ordinal buffer length too small, "
548 "need %zd\n", sizeof(u32));
553 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
557 case IPW_ORD_TABLE_2_MASK:
559 * TABLE 2: Indirect access to a table of variable sized values
561 * This table consist of six values, each containing
562 * - dword containing the starting offset of the data
563 * - dword containing the lengh in the first 16bits
564 * and the count in the second 16bits
567 /* remove the table id from the ordinal */
568 ord &= IPW_ORD_TABLE_VALUE_MASK;
571 if (ord > priv->table2_len) {
572 IPW_DEBUG_ORD("ordinal value too long\n");
576 /* get the address of statistic */
577 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
579 /* get the second DW of statistics ;
580 * two 16-bit words - first is length, second is count */
583 priv->table2_addr + (ord << 3) +
586 /* get each entry length */
587 field_len = *((u16 *) & field_info);
589 /* get number of entries */
590 field_count = *(((u16 *) & field_info) + 1);
592 /* abort if not enought memory */
593 total_len = field_len * field_count;
594 if (total_len > *len) {
603 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
604 "field_info = 0x%08x\n",
605 addr, total_len, field_info);
606 ipw_read_indirect(priv, addr, val, total_len);
610 IPW_DEBUG_ORD("Invalid ordinal!\n");
618 static void ipw_init_ordinals(struct ipw_priv *priv)
620 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
621 priv->table0_len = ipw_read32(priv, priv->table0_addr);
623 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
624 priv->table0_addr, priv->table0_len);
626 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
627 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
629 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
630 priv->table1_addr, priv->table1_len);
632 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
633 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
634 priv->table2_len &= 0x0000ffff; /* use first two bytes */
636 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
637 priv->table2_addr, priv->table2_len);
641 u32 ipw_register_toggle(u32 reg)
643 reg &= ~CX2_START_STANDBY;
644 if (reg & CX2_GATE_ODMA)
645 reg &= ~CX2_GATE_ODMA;
646 if (reg & CX2_GATE_IDMA)
647 reg &= ~CX2_GATE_IDMA;
648 if (reg & CX2_GATE_ADMA)
649 reg &= ~CX2_GATE_ADMA;
655 * - On radio ON, turn on any LEDs that require to be on during start
656 * - On initialization, start unassociated blink
657 * - On association, disable unassociated blink
658 * - On disassociation, start unassociated blink
659 * - On radio OFF, turn off any LEDs started during radio on
662 #define LD_TIME_LINK_ON 300
663 #define LD_TIME_LINK_OFF 2700
664 #define LD_TIME_ACT_ON 250
666 void ipw_led_link_on(struct ipw_priv *priv)
671 /* If configured to not use LEDs, or nic_type is 1,
672 * then we don't toggle a LINK led */
673 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
676 spin_lock_irqsave(&priv->lock, flags);
678 if (!(priv->status & STATUS_RF_KILL_MASK) &&
679 !(priv->status & STATUS_LED_LINK_ON)) {
680 IPW_DEBUG_LED("Link LED On\n");
681 led = ipw_read_reg32(priv, CX2_EVENT_REG);
682 led |= priv->led_association_on;
684 led = ipw_register_toggle(led);
686 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
687 ipw_write_reg32(priv, CX2_EVENT_REG, led);
689 priv->status |= STATUS_LED_LINK_ON;
691 /* If we aren't associated, schedule turning the LED off */
692 if (!(priv->status & STATUS_ASSOCIATED))
693 queue_delayed_work(priv->workqueue,
698 spin_unlock_irqrestore(&priv->lock, flags);
701 void ipw_led_link_off(struct ipw_priv *priv)
706 /* If configured not to use LEDs, or nic type is 1,
707 * then we don't goggle the LINK led. */
708 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
711 spin_lock_irqsave(&priv->lock, flags);
713 if (priv->status & STATUS_LED_LINK_ON) {
714 led = ipw_read_reg32(priv, CX2_EVENT_REG);
715 led &= priv->led_association_off;
716 led = ipw_register_toggle(led);
718 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
719 ipw_write_reg32(priv, CX2_EVENT_REG, led);
721 IPW_DEBUG_LED("Link LED Off\n");
723 priv->status &= ~STATUS_LED_LINK_ON;
725 /* If we aren't associated and the radio is on, schedule
726 * turning the LED on (blink while unassociated) */
727 if (!(priv->status & STATUS_RF_KILL_MASK) &&
728 !(priv->status & STATUS_ASSOCIATED))
729 queue_delayed_work(priv->workqueue, &priv->led_link_on,
734 spin_unlock_irqrestore(&priv->lock, flags);
737 void ipw_led_activity_on(struct ipw_priv *priv)
742 if (priv->config & CFG_NO_LED)
745 spin_lock_irqsave(&priv->lock, flags);
747 if (priv->status & STATUS_RF_KILL_MASK) {
748 spin_unlock_irqrestore(&priv->lock, flags);
752 if (!(priv->status & STATUS_LED_ACT_ON)) {
753 led = ipw_read_reg32(priv, CX2_EVENT_REG);
754 led |= priv->led_activity_on;
756 led = ipw_register_toggle(led);
758 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
759 ipw_write_reg32(priv, CX2_EVENT_REG, led);
761 IPW_DEBUG_LED("Activity LED On\n");
763 priv->status |= STATUS_LED_ACT_ON;
765 queue_delayed_work(priv->workqueue, &priv->led_act_off,
768 /* Reschedule LED off for full time period */
769 cancel_delayed_work(&priv->led_act_off);
770 queue_delayed_work(priv->workqueue, &priv->led_act_off,
774 spin_unlock_irqrestore(&priv->lock, flags);
777 void ipw_led_activity_off(struct ipw_priv *priv)
782 if (priv->config & CFG_NO_LED)
785 spin_lock_irqsave(&priv->lock, flags);
787 if (priv->status & STATUS_LED_ACT_ON) {
788 led = ipw_read_reg32(priv, CX2_EVENT_REG);
789 led &= priv->led_activity_off;
791 led = ipw_register_toggle(led);
793 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
794 ipw_write_reg32(priv, CX2_EVENT_REG, led);
796 IPW_DEBUG_LED("Activity LED Off\n");
798 priv->status &= ~STATUS_LED_ACT_ON;
801 spin_unlock_irqrestore(&priv->lock, flags);
804 void ipw_led_band_on(struct ipw_priv *priv)
809 /* Only nic type 1 supports mode LEDs */
810 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
813 spin_lock_irqsave(&priv->lock, flags);
815 led = ipw_read_reg32(priv, CX2_EVENT_REG);
816 if (priv->assoc_network->mode == IEEE_A) {
817 led |= priv->led_ofdm_on;
818 led &= priv->led_association_off;
819 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
820 } else if (priv->assoc_network->mode == IEEE_G) {
821 led |= priv->led_ofdm_on;
822 led |= priv->led_association_on;
823 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
825 led &= priv->led_ofdm_off;
826 led |= priv->led_association_on;
827 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
830 led = ipw_register_toggle(led);
832 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
833 ipw_write_reg32(priv, CX2_EVENT_REG, led);
835 spin_unlock_irqrestore(&priv->lock, flags);
838 void ipw_led_band_off(struct ipw_priv *priv)
843 /* Only nic type 1 supports mode LEDs */
844 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
847 spin_lock_irqsave(&priv->lock, flags);
849 led = ipw_read_reg32(priv, CX2_EVENT_REG);
850 led &= priv->led_ofdm_off;
851 led &= priv->led_association_off;
853 led = ipw_register_toggle(led);
855 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
856 ipw_write_reg32(priv, CX2_EVENT_REG, led);
858 spin_unlock_irqrestore(&priv->lock, flags);
861 void ipw_led_radio_on(struct ipw_priv *priv)
863 ipw_led_link_on(priv);
866 void ipw_led_radio_off(struct ipw_priv *priv)
868 ipw_led_activity_off(priv);
869 ipw_led_link_off(priv);
872 void ipw_led_link_up(struct ipw_priv *priv)
874 /* Set the Link Led on for all nic types */
875 ipw_led_link_on(priv);
878 void ipw_led_link_down(struct ipw_priv *priv)
880 ipw_led_activity_off(priv);
881 ipw_led_link_off(priv);
883 if (priv->status & STATUS_RF_KILL_MASK)
884 ipw_led_radio_off(priv);
887 void ipw_led_init(struct ipw_priv *priv)
889 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
891 /* Set the default PINs for the link and activity leds */
892 priv->led_activity_on = CX2_ACTIVITY_LED;
893 priv->led_activity_off = ~(CX2_ACTIVITY_LED);
895 priv->led_association_on = CX2_ASSOCIATED_LED;
896 priv->led_association_off = ~(CX2_ASSOCIATED_LED);
898 /* Set the default PINs for the OFDM leds */
899 priv->led_ofdm_on = CX2_OFDM_LED;
900 priv->led_ofdm_off = ~(CX2_OFDM_LED);
902 switch (priv->nic_type) {
903 case EEPROM_NIC_TYPE_1:
904 /* In this NIC type, the LEDs are reversed.... */
905 priv->led_activity_on = CX2_ASSOCIATED_LED;
906 priv->led_activity_off = ~(CX2_ASSOCIATED_LED);
907 priv->led_association_on = CX2_ACTIVITY_LED;
908 priv->led_association_off = ~(CX2_ACTIVITY_LED);
910 if (!(priv->config & CFG_NO_LED))
911 ipw_led_band_on(priv);
913 /* And we don't blink link LEDs for this nic, so
914 * just return here */
917 case EEPROM_NIC_TYPE_3:
918 case EEPROM_NIC_TYPE_2:
919 case EEPROM_NIC_TYPE_4:
920 case EEPROM_NIC_TYPE_0:
924 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
926 priv->nic_type = EEPROM_NIC_TYPE_0;
930 if (!(priv->config & CFG_NO_LED)) {
931 if (priv->status & STATUS_ASSOCIATED)
932 ipw_led_link_on(priv);
934 ipw_led_link_off(priv);
938 void ipw_led_shutdown(struct ipw_priv *priv)
940 cancel_delayed_work(&priv->led_link_on);
941 cancel_delayed_work(&priv->led_link_off);
942 cancel_delayed_work(&priv->led_act_off);
943 ipw_led_activity_off(priv);
944 ipw_led_link_off(priv);
945 ipw_led_band_off(priv);
949 * The following adds a new attribute to the sysfs representation
950 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
951 * used for controling the debug level.
953 * See the level definitions in ipw for details.
955 static ssize_t show_debug_level(struct device_driver *d, char *buf)
957 return sprintf(buf, "0x%08X\n", ipw_debug_level);
960 static ssize_t store_debug_level(struct device_driver *d, const char *buf,
963 char *p = (char *)buf;
966 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
968 if (p[0] == 'x' || p[0] == 'X')
970 val = simple_strtoul(p, &p, 16);
972 val = simple_strtoul(p, &p, 10);
974 printk(KERN_INFO DRV_NAME
975 ": %s is not in hex or decimal form.\n", buf);
977 ipw_debug_level = val;
979 return strnlen(buf, count);
982 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
983 show_debug_level, store_debug_level);
985 static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
988 struct ipw_priv *priv = dev_get_drvdata(d);
989 return sprintf(buf, "%d\n", priv->ieee->scan_age);
992 static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
993 const char *buf, size_t count)
995 struct ipw_priv *priv = dev_get_drvdata(d);
996 struct net_device *dev = priv->net_dev;
997 char buffer[] = "00000000";
999 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1003 IPW_DEBUG_INFO("enter\n");
1005 strncpy(buffer, buf, len);
1008 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1010 if (p[0] == 'x' || p[0] == 'X')
1012 val = simple_strtoul(p, &p, 16);
1014 val = simple_strtoul(p, &p, 10);
1016 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1018 priv->ieee->scan_age = val;
1019 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1022 IPW_DEBUG_INFO("exit\n");
1026 static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1028 static ssize_t show_led(struct device *d, struct device_attribute *attr,
1031 struct ipw_priv *priv = dev_get_drvdata(d);
1032 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1035 static ssize_t store_led(struct device *d, struct device_attribute *attr,
1036 const char *buf, size_t count)
1038 struct ipw_priv *priv = dev_get_drvdata(d);
1040 IPW_DEBUG_INFO("enter\n");
1046 IPW_DEBUG_LED("Disabling LED control.\n");
1047 priv->config |= CFG_NO_LED;
1048 ipw_led_shutdown(priv);
1050 IPW_DEBUG_LED("Enabling LED control.\n");
1051 priv->config &= ~CFG_NO_LED;
1055 IPW_DEBUG_INFO("exit\n");
1059 static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1061 static ssize_t show_status(struct device *d,
1062 struct device_attribute *attr, char *buf)
1064 struct ipw_priv *p = d->driver_data;
1065 return sprintf(buf, "0x%08x\n", (int)p->status);
1068 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1070 static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1073 struct ipw_priv *p = d->driver_data;
1074 return sprintf(buf, "0x%08x\n", (int)p->config);
1077 static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1079 static ssize_t show_nic_type(struct device *d,
1080 struct device_attribute *attr, char *buf)
1082 struct ipw_priv *priv = d->driver_data;
1083 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
1086 static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1088 static ssize_t dump_error_log(struct device *d,
1089 struct device_attribute *attr, const char *buf,
1092 char *p = (char *)buf;
1095 ipw_dump_nic_error_log((struct ipw_priv *)d->driver_data);
1097 return strnlen(buf, count);
1100 static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
1102 static ssize_t dump_event_log(struct device *d,
1103 struct device_attribute *attr, const char *buf,
1106 char *p = (char *)buf;
1109 ipw_dump_nic_event_log((struct ipw_priv *)d->driver_data);
1111 return strnlen(buf, count);
1114 static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
1116 static ssize_t show_ucode_version(struct device *d,
1117 struct device_attribute *attr, char *buf)
1119 u32 len = sizeof(u32), tmp = 0;
1120 struct ipw_priv *p = d->driver_data;
1122 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
1125 return sprintf(buf, "0x%08x\n", tmp);
1128 static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
1130 static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1133 u32 len = sizeof(u32), tmp = 0;
1134 struct ipw_priv *p = d->driver_data;
1136 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
1139 return sprintf(buf, "0x%08x\n", tmp);
1142 static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
1145 * Add a device attribute to view/control the delay between eeprom
1148 static ssize_t show_eeprom_delay(struct device *d,
1149 struct device_attribute *attr, char *buf)
1151 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
1152 return sprintf(buf, "%i\n", n);
1154 static ssize_t store_eeprom_delay(struct device *d,
1155 struct device_attribute *attr,
1156 const char *buf, size_t count)
1158 struct ipw_priv *p = d->driver_data;
1159 sscanf(buf, "%i", &p->eeprom_delay);
1160 return strnlen(buf, count);
1163 static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1164 show_eeprom_delay, store_eeprom_delay);
1166 static ssize_t show_command_event_reg(struct device *d,
1167 struct device_attribute *attr, char *buf)
1170 struct ipw_priv *p = d->driver_data;
1172 reg = ipw_read_reg32(p, CX2_INTERNAL_CMD_EVENT);
1173 return sprintf(buf, "0x%08x\n", reg);
1175 static ssize_t store_command_event_reg(struct device *d,
1176 struct device_attribute *attr,
1177 const char *buf, size_t count)
1180 struct ipw_priv *p = d->driver_data;
1182 sscanf(buf, "%x", ®);
1183 ipw_write_reg32(p, CX2_INTERNAL_CMD_EVENT, reg);
1184 return strnlen(buf, count);
1187 static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1188 show_command_event_reg, store_command_event_reg);
1190 static ssize_t show_mem_gpio_reg(struct device *d,
1191 struct device_attribute *attr, char *buf)
1194 struct ipw_priv *p = d->driver_data;
1196 reg = ipw_read_reg32(p, 0x301100);
1197 return sprintf(buf, "0x%08x\n", reg);
1199 static ssize_t store_mem_gpio_reg(struct device *d,
1200 struct device_attribute *attr,
1201 const char *buf, size_t count)
1204 struct ipw_priv *p = d->driver_data;
1206 sscanf(buf, "%x", ®);
1207 ipw_write_reg32(p, 0x301100, reg);
1208 return strnlen(buf, count);
1211 static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1212 show_mem_gpio_reg, store_mem_gpio_reg);
1214 static ssize_t show_indirect_dword(struct device *d,
1215 struct device_attribute *attr, char *buf)
1218 struct ipw_priv *priv = d->driver_data;
1219 if (priv->status & STATUS_INDIRECT_DWORD)
1220 reg = ipw_read_reg32(priv, priv->indirect_dword);
1224 return sprintf(buf, "0x%08x\n", reg);
1226 static ssize_t store_indirect_dword(struct device *d,
1227 struct device_attribute *attr,
1228 const char *buf, size_t count)
1230 struct ipw_priv *priv = d->driver_data;
1232 sscanf(buf, "%x", &priv->indirect_dword);
1233 priv->status |= STATUS_INDIRECT_DWORD;
1234 return strnlen(buf, count);
1237 static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1238 show_indirect_dword, store_indirect_dword);
1240 static ssize_t show_indirect_byte(struct device *d,
1241 struct device_attribute *attr, char *buf)
1244 struct ipw_priv *priv = d->driver_data;
1245 if (priv->status & STATUS_INDIRECT_BYTE)
1246 reg = ipw_read_reg8(priv, priv->indirect_byte);
1250 return sprintf(buf, "0x%02x\n", reg);
1252 static ssize_t store_indirect_byte(struct device *d,
1253 struct device_attribute *attr,
1254 const char *buf, size_t count)
1256 struct ipw_priv *priv = d->driver_data;
1258 sscanf(buf, "%x", &priv->indirect_byte);
1259 priv->status |= STATUS_INDIRECT_BYTE;
1260 return strnlen(buf, count);
1263 static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
1264 show_indirect_byte, store_indirect_byte);
1266 static ssize_t show_direct_dword(struct device *d,
1267 struct device_attribute *attr, char *buf)
1270 struct ipw_priv *priv = d->driver_data;
1272 if (priv->status & STATUS_DIRECT_DWORD)
1273 reg = ipw_read32(priv, priv->direct_dword);
1277 return sprintf(buf, "0x%08x\n", reg);
1279 static ssize_t store_direct_dword(struct device *d,
1280 struct device_attribute *attr,
1281 const char *buf, size_t count)
1283 struct ipw_priv *priv = d->driver_data;
1285 sscanf(buf, "%x", &priv->direct_dword);
1286 priv->status |= STATUS_DIRECT_DWORD;
1287 return strnlen(buf, count);
1290 static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1291 show_direct_dword, store_direct_dword);
1293 static inline int rf_kill_active(struct ipw_priv *priv)
1295 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1296 priv->status |= STATUS_RF_KILL_HW;
1298 priv->status &= ~STATUS_RF_KILL_HW;
1300 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1303 static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
1306 /* 0 - RF kill not enabled
1307 1 - SW based RF kill active (sysfs)
1308 2 - HW based RF kill active
1309 3 - Both HW and SW baed RF kill active */
1310 struct ipw_priv *priv = d->driver_data;
1311 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
1312 (rf_kill_active(priv) ? 0x2 : 0x0);
1313 return sprintf(buf, "%i\n", val);
1316 static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1318 if ((disable_radio ? 1 : 0) ==
1319 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
1322 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1323 disable_radio ? "OFF" : "ON");
1325 if (disable_radio) {
1326 priv->status |= STATUS_RF_KILL_SW;
1328 if (priv->workqueue)
1329 cancel_delayed_work(&priv->request_scan);
1330 wake_up_interruptible(&priv->wait_command_queue);
1331 queue_work(priv->workqueue, &priv->down);
1333 priv->status &= ~STATUS_RF_KILL_SW;
1334 if (rf_kill_active(priv)) {
1335 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1336 "disabled by HW switch\n");
1337 /* Make sure the RF_KILL check timer is running */
1338 cancel_delayed_work(&priv->rf_kill);
1339 queue_delayed_work(priv->workqueue, &priv->rf_kill,
1342 queue_work(priv->workqueue, &priv->up);
1348 static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1349 const char *buf, size_t count)
1351 struct ipw_priv *priv = d->driver_data;
1353 ipw_radio_kill_sw(priv, buf[0] == '1');
1358 static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
1360 static void notify_wx_assoc_event(struct ipw_priv *priv)
1362 union iwreq_data wrqu;
1363 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1364 if (priv->status & STATUS_ASSOCIATED)
1365 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1367 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1368 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1371 static void ipw_irq_tasklet(struct ipw_priv *priv)
1373 u32 inta, inta_mask, handled = 0;
1374 unsigned long flags;
1377 spin_lock_irqsave(&priv->lock, flags);
1379 inta = ipw_read32(priv, CX2_INTA_RW);
1380 inta_mask = ipw_read32(priv, CX2_INTA_MASK_R);
1381 inta &= (CX2_INTA_MASK_ALL & inta_mask);
1383 /* Add any cached INTA values that need to be handled */
1384 inta |= priv->isr_inta;
1386 /* handle all the justifications for the interrupt */
1387 if (inta & CX2_INTA_BIT_RX_TRANSFER) {
1389 handled |= CX2_INTA_BIT_RX_TRANSFER;
1392 if (inta & CX2_INTA_BIT_TX_CMD_QUEUE) {
1393 IPW_DEBUG_HC("Command completed.\n");
1394 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
1395 priv->status &= ~STATUS_HCMD_ACTIVE;
1396 wake_up_interruptible(&priv->wait_command_queue);
1397 handled |= CX2_INTA_BIT_TX_CMD_QUEUE;
1400 if (inta & CX2_INTA_BIT_TX_QUEUE_1) {
1401 IPW_DEBUG_TX("TX_QUEUE_1\n");
1402 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
1403 handled |= CX2_INTA_BIT_TX_QUEUE_1;
1406 if (inta & CX2_INTA_BIT_TX_QUEUE_2) {
1407 IPW_DEBUG_TX("TX_QUEUE_2\n");
1408 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
1409 handled |= CX2_INTA_BIT_TX_QUEUE_2;
1412 if (inta & CX2_INTA_BIT_TX_QUEUE_3) {
1413 IPW_DEBUG_TX("TX_QUEUE_3\n");
1414 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
1415 handled |= CX2_INTA_BIT_TX_QUEUE_3;
1418 if (inta & CX2_INTA_BIT_TX_QUEUE_4) {
1419 IPW_DEBUG_TX("TX_QUEUE_4\n");
1420 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
1421 handled |= CX2_INTA_BIT_TX_QUEUE_4;
1424 if (inta & CX2_INTA_BIT_STATUS_CHANGE) {
1425 IPW_WARNING("STATUS_CHANGE\n");
1426 handled |= CX2_INTA_BIT_STATUS_CHANGE;
1429 if (inta & CX2_INTA_BIT_BEACON_PERIOD_EXPIRED) {
1430 IPW_WARNING("TX_PERIOD_EXPIRED\n");
1431 handled |= CX2_INTA_BIT_BEACON_PERIOD_EXPIRED;
1434 if (inta & CX2_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
1435 IPW_WARNING("HOST_CMD_DONE\n");
1436 handled |= CX2_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
1439 if (inta & CX2_INTA_BIT_FW_INITIALIZATION_DONE) {
1440 IPW_WARNING("FW_INITIALIZATION_DONE\n");
1441 handled |= CX2_INTA_BIT_FW_INITIALIZATION_DONE;
1444 if (inta & CX2_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
1445 IPW_WARNING("PHY_OFF_DONE\n");
1446 handled |= CX2_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
1449 if (inta & CX2_INTA_BIT_RF_KILL_DONE) {
1450 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1451 priv->status |= STATUS_RF_KILL_HW;
1452 wake_up_interruptible(&priv->wait_command_queue);
1453 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1454 cancel_delayed_work(&priv->request_scan);
1455 schedule_work(&priv->link_down);
1456 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
1457 handled |= CX2_INTA_BIT_RF_KILL_DONE;
1460 if (inta & CX2_INTA_BIT_FATAL_ERROR) {
1461 IPW_ERROR("Firmware error detected. Restarting.\n");
1462 #ifdef CONFIG_IPW_DEBUG
1463 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1464 ipw_dump_nic_error_log(priv);
1465 ipw_dump_nic_event_log(priv);
1468 queue_work(priv->workqueue, &priv->adapter_restart);
1469 handled |= CX2_INTA_BIT_FATAL_ERROR;
1472 if (inta & CX2_INTA_BIT_PARITY_ERROR) {
1473 IPW_ERROR("Parity error\n");
1474 handled |= CX2_INTA_BIT_PARITY_ERROR;
1477 if (handled != inta) {
1478 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
1481 /* enable all interrupts */
1482 ipw_enable_interrupts(priv);
1484 spin_unlock_irqrestore(&priv->lock, flags);
1487 #ifdef CONFIG_IPW_DEBUG
1488 #define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1489 static char *get_cmd_string(u8 cmd)
1492 IPW_CMD(HOST_COMPLETE);
1493 IPW_CMD(POWER_DOWN);
1494 IPW_CMD(SYSTEM_CONFIG);
1495 IPW_CMD(MULTICAST_ADDRESS);
1497 IPW_CMD(ADAPTER_ADDRESS);
1499 IPW_CMD(RTS_THRESHOLD);
1500 IPW_CMD(FRAG_THRESHOLD);
1501 IPW_CMD(POWER_MODE);
1503 IPW_CMD(TGI_TX_KEY);
1504 IPW_CMD(SCAN_REQUEST);
1505 IPW_CMD(SCAN_REQUEST_EXT);
1507 IPW_CMD(SUPPORTED_RATES);
1508 IPW_CMD(SCAN_ABORT);
1510 IPW_CMD(QOS_PARAMETERS);
1511 IPW_CMD(DINO_CONFIG);
1512 IPW_CMD(RSN_CAPABILITIES);
1514 IPW_CMD(CARD_DISABLE);
1515 IPW_CMD(SEED_NUMBER);
1517 IPW_CMD(COUNTRY_INFO);
1518 IPW_CMD(AIRONET_INFO);
1519 IPW_CMD(AP_TX_POWER);
1521 IPW_CMD(CCX_VER_INFO);
1522 IPW_CMD(SET_CALIBRATION);
1523 IPW_CMD(SENSITIVITY_CALIB);
1524 IPW_CMD(RETRY_LIMIT);
1525 IPW_CMD(IPW_PRE_POWER_DOWN);
1526 IPW_CMD(VAP_BEACON_TEMPLATE);
1527 IPW_CMD(VAP_DTIM_PERIOD);
1528 IPW_CMD(EXT_SUPPORTED_RATES);
1529 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
1530 IPW_CMD(VAP_QUIET_INTERVALS);
1531 IPW_CMD(VAP_CHANNEL_SWITCH);
1532 IPW_CMD(VAP_MANDATORY_CHANNELS);
1533 IPW_CMD(VAP_CELL_PWR_LIMIT);
1534 IPW_CMD(VAP_CF_PARAM_SET);
1535 IPW_CMD(VAP_SET_BEACONING_STATE);
1536 IPW_CMD(MEASUREMENT);
1537 IPW_CMD(POWER_CAPABILITY);
1538 IPW_CMD(SUPPORTED_CHANNELS);
1539 IPW_CMD(TPC_REPORT);
1541 IPW_CMD(PRODUCTION_COMMAND);
1548 #define HOST_COMPLETE_TIMEOUT HZ
1549 static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
1552 unsigned long flags;
1554 spin_lock_irqsave(&priv->lock, flags);
1555 if (priv->status & STATUS_HCMD_ACTIVE) {
1556 IPW_ERROR("Already sending a command\n");
1557 spin_unlock_irqrestore(&priv->lock, flags);
1561 priv->status |= STATUS_HCMD_ACTIVE;
1563 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
1564 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len);
1565 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
1567 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0);
1569 priv->status &= ~STATUS_HCMD_ACTIVE;
1570 spin_unlock_irqrestore(&priv->lock, flags);
1573 spin_unlock_irqrestore(&priv->lock, flags);
1575 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1577 status & STATUS_HCMD_ACTIVE),
1578 HOST_COMPLETE_TIMEOUT);
1580 spin_lock_irqsave(&priv->lock, flags);
1581 if (priv->status & STATUS_HCMD_ACTIVE) {
1582 IPW_DEBUG_INFO("Command completion failed out after "
1584 1000 * (HOST_COMPLETE_TIMEOUT / HZ));
1585 priv->status &= ~STATUS_HCMD_ACTIVE;
1586 spin_unlock_irqrestore(&priv->lock, flags);
1589 spin_unlock_irqrestore(&priv->lock, flags);
1592 if (priv->status & STATUS_RF_KILL_MASK) {
1593 IPW_DEBUG_INFO("Command aborted due to RF Kill Switch\n");
1600 static int ipw_send_host_complete(struct ipw_priv *priv)
1602 struct host_cmd cmd = {
1603 .cmd = IPW_CMD_HOST_COMPLETE,
1608 IPW_ERROR("Invalid args\n");
1612 if (ipw_send_cmd(priv, &cmd)) {
1613 IPW_ERROR("failed to send HOST_COMPLETE command\n");
1620 static int ipw_send_system_config(struct ipw_priv *priv,
1621 struct ipw_sys_config *config)
1623 struct host_cmd cmd = {
1624 .cmd = IPW_CMD_SYSTEM_CONFIG,
1625 .len = sizeof(*config)
1628 if (!priv || !config) {
1629 IPW_ERROR("Invalid args\n");
1633 memcpy(&cmd.param, config, sizeof(*config));
1634 if (ipw_send_cmd(priv, &cmd)) {
1635 IPW_ERROR("failed to send SYSTEM_CONFIG command\n");
1642 static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
1644 struct host_cmd cmd = {
1645 .cmd = IPW_CMD_SSID,
1646 .len = min(len, IW_ESSID_MAX_SIZE)
1649 if (!priv || !ssid) {
1650 IPW_ERROR("Invalid args\n");
1654 memcpy(&cmd.param, ssid, cmd.len);
1655 if (ipw_send_cmd(priv, &cmd)) {
1656 IPW_ERROR("failed to send SSID command\n");
1663 static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
1665 struct host_cmd cmd = {
1666 .cmd = IPW_CMD_ADAPTER_ADDRESS,
1670 if (!priv || !mac) {
1671 IPW_ERROR("Invalid args\n");
1675 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
1676 priv->net_dev->name, MAC_ARG(mac));
1678 memcpy(&cmd.param, mac, ETH_ALEN);
1680 if (ipw_send_cmd(priv, &cmd)) {
1681 IPW_ERROR("failed to send ADAPTER_ADDRESS command\n");
1689 * NOTE: This must be executed from our workqueue as it results in udelay
1690 * being called which may corrupt the keyboard if executed on default
1693 static void ipw_adapter_restart(void *adapter)
1695 struct ipw_priv *priv = adapter;
1697 if (priv->status & STATUS_RF_KILL_MASK)
1702 IPW_ERROR("Failed to up device\n");
1707 #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
1709 static void ipw_scan_check(void *data)
1711 struct ipw_priv *priv = data;
1712 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
1713 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
1714 "adapter (%dms).\n",
1715 IPW_SCAN_CHECK_WATCHDOG / 100);
1716 queue_work(priv->workqueue, &priv->adapter_restart);
1720 static int ipw_send_scan_request_ext(struct ipw_priv *priv,
1721 struct ipw_scan_request_ext *request)
1723 struct host_cmd cmd = {
1724 .cmd = IPW_CMD_SCAN_REQUEST_EXT,
1725 .len = sizeof(*request)
1728 if (!priv || !request) {
1729 IPW_ERROR("Invalid args\n");
1733 memcpy(&cmd.param, request, sizeof(*request));
1734 if (ipw_send_cmd(priv, &cmd)) {
1735 IPW_ERROR("failed to send SCAN_REQUEST_EXT command\n");
1739 queue_delayed_work(priv->workqueue, &priv->scan_check,
1740 IPW_SCAN_CHECK_WATCHDOG);
1744 static int ipw_send_scan_abort(struct ipw_priv *priv)
1746 struct host_cmd cmd = {
1747 .cmd = IPW_CMD_SCAN_ABORT,
1752 IPW_ERROR("Invalid args\n");
1756 if (ipw_send_cmd(priv, &cmd)) {
1757 IPW_ERROR("failed to send SCAN_ABORT command\n");
1764 static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
1766 struct host_cmd cmd = {
1767 .cmd = IPW_CMD_SENSITIVITY_CALIB,
1768 .len = sizeof(struct ipw_sensitivity_calib)
1770 struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *)
1772 calib->beacon_rssi_raw = sens;
1773 if (ipw_send_cmd(priv, &cmd)) {
1774 IPW_ERROR("failed to send SENSITIVITY CALIB command\n");
1781 static int ipw_send_associate(struct ipw_priv *priv,
1782 struct ipw_associate *associate)
1784 struct host_cmd cmd = {
1785 .cmd = IPW_CMD_ASSOCIATE,
1786 .len = sizeof(*associate)
1789 struct ipw_associate tmp_associate;
1790 memcpy(&tmp_associate, associate, sizeof(*associate));
1791 tmp_associate.policy_support =
1792 cpu_to_le16(tmp_associate.policy_support);
1793 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
1794 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
1795 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
1796 tmp_associate.listen_interval =
1797 cpu_to_le16(tmp_associate.listen_interval);
1798 tmp_associate.beacon_interval =
1799 cpu_to_le16(tmp_associate.beacon_interval);
1800 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
1802 if (!priv || !associate) {
1803 IPW_ERROR("Invalid args\n");
1807 memcpy(&cmd.param, &tmp_associate, sizeof(*associate));
1808 if (ipw_send_cmd(priv, &cmd)) {
1809 IPW_ERROR("failed to send ASSOCIATE command\n");
1816 static int ipw_send_supported_rates(struct ipw_priv *priv,
1817 struct ipw_supported_rates *rates)
1819 struct host_cmd cmd = {
1820 .cmd = IPW_CMD_SUPPORTED_RATES,
1821 .len = sizeof(*rates)
1824 if (!priv || !rates) {
1825 IPW_ERROR("Invalid args\n");
1829 memcpy(&cmd.param, rates, sizeof(*rates));
1830 if (ipw_send_cmd(priv, &cmd)) {
1831 IPW_ERROR("failed to send SUPPORTED_RATES command\n");
1838 static int ipw_set_random_seed(struct ipw_priv *priv)
1840 struct host_cmd cmd = {
1841 .cmd = IPW_CMD_SEED_NUMBER,
1846 IPW_ERROR("Invalid args\n");
1850 get_random_bytes(&cmd.param, sizeof(u32));
1852 if (ipw_send_cmd(priv, &cmd)) {
1853 IPW_ERROR("failed to send SEED_NUMBER command\n");
1861 static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
1863 struct host_cmd cmd = {
1864 .cmd = IPW_CMD_CARD_DISABLE,
1869 IPW_ERROR("Invalid args\n");
1873 *((u32 *) & cmd.param) = phy_off;
1875 if (ipw_send_cmd(priv, &cmd)) {
1876 IPW_ERROR("failed to send CARD_DISABLE command\n");
1884 static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
1886 struct host_cmd cmd = {
1887 .cmd = IPW_CMD_TX_POWER,
1888 .len = sizeof(*power)
1891 if (!priv || !power) {
1892 IPW_ERROR("Invalid args\n");
1896 memcpy(&cmd.param, power, sizeof(*power));
1897 if (ipw_send_cmd(priv, &cmd)) {
1898 IPW_ERROR("failed to send TX_POWER command\n");
1905 static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
1907 struct ipw_rts_threshold rts_threshold = {
1908 .rts_threshold = rts,
1910 struct host_cmd cmd = {
1911 .cmd = IPW_CMD_RTS_THRESHOLD,
1912 .len = sizeof(rts_threshold)
1916 IPW_ERROR("Invalid args\n");
1920 memcpy(&cmd.param, &rts_threshold, sizeof(rts_threshold));
1921 if (ipw_send_cmd(priv, &cmd)) {
1922 IPW_ERROR("failed to send RTS_THRESHOLD command\n");
1929 static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
1931 struct ipw_frag_threshold frag_threshold = {
1932 .frag_threshold = frag,
1934 struct host_cmd cmd = {
1935 .cmd = IPW_CMD_FRAG_THRESHOLD,
1936 .len = sizeof(frag_threshold)
1940 IPW_ERROR("Invalid args\n");
1944 memcpy(&cmd.param, &frag_threshold, sizeof(frag_threshold));
1945 if (ipw_send_cmd(priv, &cmd)) {
1946 IPW_ERROR("failed to send FRAG_THRESHOLD command\n");
1953 static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
1955 struct host_cmd cmd = {
1956 .cmd = IPW_CMD_POWER_MODE,
1959 u32 *param = (u32 *) (&cmd.param);
1962 IPW_ERROR("Invalid args\n");
1966 /* If on battery, set to 3, if AC set to CAM, else user
1969 case IPW_POWER_BATTERY:
1970 *param = IPW_POWER_INDEX_3;
1973 *param = IPW_POWER_MODE_CAM;
1980 if (ipw_send_cmd(priv, &cmd)) {
1981 IPW_ERROR("failed to send POWER_MODE command\n");
1989 * The IPW device contains a Microwire compatible EEPROM that stores
1990 * various data like the MAC address. Usually the firmware has exclusive
1991 * access to the eeprom, but during device initialization (before the
1992 * device driver has sent the HostComplete command to the firmware) the
1993 * device driver has read access to the EEPROM by way of indirect addressing
1994 * through a couple of memory mapped registers.
1996 * The following is a simplified implementation for pulling data out of the
1997 * the eeprom, along with some helper functions to find information in
1998 * the per device private data's copy of the eeprom.
2000 * NOTE: To better understand how these functions work (i.e what is a chip
2001 * select and why do have to keep driving the eeprom clock?), read
2002 * just about any data sheet for a Microwire compatible EEPROM.
2005 /* write a 32 bit value into the indirect accessor register */
2006 static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2008 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
2010 /* the eeprom requires some time to complete the operation */
2011 udelay(p->eeprom_delay);
2016 /* perform a chip select operation */
2017 static inline void eeprom_cs(struct ipw_priv *priv)
2019 eeprom_write_reg(priv, 0);
2020 eeprom_write_reg(priv, EEPROM_BIT_CS);
2021 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2022 eeprom_write_reg(priv, EEPROM_BIT_CS);
2025 /* perform a chip select operation */
2026 static inline void eeprom_disable_cs(struct ipw_priv *priv)
2028 eeprom_write_reg(priv, EEPROM_BIT_CS);
2029 eeprom_write_reg(priv, 0);
2030 eeprom_write_reg(priv, EEPROM_BIT_SK);
2033 /* push a single bit down to the eeprom */
2034 static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
2036 int d = (bit ? EEPROM_BIT_DI : 0);
2037 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2038 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
2041 /* push an opcode followed by an address down to the eeprom */
2042 static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
2047 eeprom_write_bit(priv, 1);
2048 eeprom_write_bit(priv, op & 2);
2049 eeprom_write_bit(priv, op & 1);
2050 for (i = 7; i >= 0; i--) {
2051 eeprom_write_bit(priv, addr & (1 << i));
2055 /* pull 16 bits off the eeprom, one bit at a time */
2056 static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
2061 /* Send READ Opcode */
2062 eeprom_op(priv, EEPROM_CMD_READ, addr);
2064 /* Send dummy bit */
2065 eeprom_write_reg(priv, EEPROM_BIT_CS);
2067 /* Read the byte off the eeprom one bit at a time */
2068 for (i = 0; i < 16; i++) {
2070 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2071 eeprom_write_reg(priv, EEPROM_BIT_CS);
2072 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2073 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
2076 /* Send another dummy bit */
2077 eeprom_write_reg(priv, 0);
2078 eeprom_disable_cs(priv);
2083 /* helper function for pulling the mac address out of the private */
2084 /* data's copy of the eeprom data */
2085 static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
2087 u8 *ee = (u8 *) priv->eeprom;
2088 memcpy(mac, &ee[EEPROM_MAC_ADDRESS], 6);
2092 * Either the device driver (i.e. the host) or the firmware can
2093 * load eeprom data into the designated region in SRAM. If neither
2094 * happens then the FW will shutdown with a fatal error.
2096 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2097 * bit needs region of shared SRAM needs to be non-zero.
2099 static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2102 u16 *eeprom = (u16 *) priv->eeprom;
2104 IPW_DEBUG_TRACE(">>\n");
2106 /* read entire contents of eeprom into private buffer */
2107 for (i = 0; i < 128; i++)
2108 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
2111 If the data looks correct, then copy it to our private
2112 copy. Otherwise let the firmware know to perform the operation
2115 if ((priv->eeprom + EEPROM_VERSION) != 0) {
2116 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2118 /* write the eeprom data to sram */
2119 for (i = 0; i < CX2_EEPROM_IMAGE_SIZE; i++)
2120 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
2122 /* Do not load eeprom data on fatal error or suspend */
2123 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2125 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2127 /* Load eeprom data on fatal error or suspend */
2128 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2131 IPW_DEBUG_TRACE("<<\n");
2134 static inline void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
2139 _ipw_write32(priv, CX2_AUTOINC_ADDR, start);
2141 _ipw_write32(priv, CX2_AUTOINC_DATA, 0);
2144 static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2146 ipw_zero_memory(priv, CX2_SHARED_SRAM_DMA_CONTROL,
2147 CB_NUMBER_OF_ELEMENTS_SMALL *
2148 sizeof(struct command_block));
2151 static int ipw_fw_dma_enable(struct ipw_priv *priv)
2152 { /* start dma engine but no transfers yet */
2154 IPW_DEBUG_FW(">> : \n");
2157 ipw_fw_dma_reset_command_blocks(priv);
2159 /* Write CB base address */
2160 ipw_write_reg32(priv, CX2_DMA_I_CB_BASE, CX2_SHARED_SRAM_DMA_CONTROL);
2162 IPW_DEBUG_FW("<< : \n");
2166 static void ipw_fw_dma_abort(struct ipw_priv *priv)
2170 IPW_DEBUG_FW(">> :\n");
2172 //set the Stop and Abort bit
2173 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
2174 ipw_write_reg32(priv, CX2_DMA_I_DMA_CONTROL, control);
2175 priv->sram_desc.last_cb_index = 0;
2177 IPW_DEBUG_FW("<< \n");
2180 static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2181 struct command_block *cb)
2184 CX2_SHARED_SRAM_DMA_CONTROL +
2185 (sizeof(struct command_block) * index);
2186 IPW_DEBUG_FW(">> :\n");
2188 ipw_write_indirect(priv, address, (u8 *) cb,
2189 (int)sizeof(struct command_block));
2191 IPW_DEBUG_FW("<< :\n");
2196 static int ipw_fw_dma_kick(struct ipw_priv *priv)
2201 IPW_DEBUG_FW(">> :\n");
2203 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
2204 ipw_fw_dma_write_command_block(priv, index,
2205 &priv->sram_desc.cb_list[index]);
2207 /* Enable the DMA in the CSR register */
2208 ipw_clear_bit(priv, CX2_RESET_REG,
2209 CX2_RESET_REG_MASTER_DISABLED |
2210 CX2_RESET_REG_STOP_MASTER);
2212 /* Set the Start bit. */
2213 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
2214 ipw_write_reg32(priv, CX2_DMA_I_DMA_CONTROL, control);
2216 IPW_DEBUG_FW("<< :\n");
2220 static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2223 u32 register_value = 0;
2224 u32 cb_fields_address = 0;
2226 IPW_DEBUG_FW(">> :\n");
2227 address = ipw_read_reg32(priv, CX2_DMA_I_CURRENT_CB);
2228 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
2230 /* Read the DMA Controlor register */
2231 register_value = ipw_read_reg32(priv, CX2_DMA_I_DMA_CONTROL);
2232 IPW_DEBUG_FW_INFO("CX2_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
2234 /* Print the CB values */
2235 cb_fields_address = address;
2236 register_value = ipw_read_reg32(priv, cb_fields_address);
2237 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
2239 cb_fields_address += sizeof(u32);
2240 register_value = ipw_read_reg32(priv, cb_fields_address);
2241 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
2243 cb_fields_address += sizeof(u32);
2244 register_value = ipw_read_reg32(priv, cb_fields_address);
2245 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2248 cb_fields_address += sizeof(u32);
2249 register_value = ipw_read_reg32(priv, cb_fields_address);
2250 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
2252 IPW_DEBUG_FW(">> :\n");
2255 static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2257 u32 current_cb_address = 0;
2258 u32 current_cb_index = 0;
2260 IPW_DEBUG_FW("<< :\n");
2261 current_cb_address = ipw_read_reg32(priv, CX2_DMA_I_CURRENT_CB);
2263 current_cb_index = (current_cb_address - CX2_SHARED_SRAM_DMA_CONTROL) /
2264 sizeof(struct command_block);
2266 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
2267 current_cb_index, current_cb_address);
2269 IPW_DEBUG_FW(">> :\n");
2270 return current_cb_index;
2274 static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2278 int interrupt_enabled, int is_last)
2281 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
2282 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2284 struct command_block *cb;
2285 u32 last_cb_element = 0;
2287 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2288 src_address, dest_address, length);
2290 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2293 last_cb_element = priv->sram_desc.last_cb_index;
2294 cb = &priv->sram_desc.cb_list[last_cb_element];
2295 priv->sram_desc.last_cb_index++;
2297 /* Calculate the new CB control word */
2298 if (interrupt_enabled)
2299 control |= CB_INT_ENABLED;
2302 control |= CB_LAST_VALID;
2306 /* Calculate the CB Element's checksum value */
2307 cb->status = control ^ src_address ^ dest_address;
2309 /* Copy the Source and Destination addresses */
2310 cb->dest_addr = dest_address;
2311 cb->source_addr = src_address;
2313 /* Copy the Control Word last */
2314 cb->control = control;
2319 static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
2320 u32 src_phys, u32 dest_address, u32 length)
2322 u32 bytes_left = length;
2324 u32 dest_offset = 0;
2326 IPW_DEBUG_FW(">> \n");
2327 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2328 src_phys, dest_address, length);
2329 while (bytes_left > CB_MAX_LENGTH) {
2330 status = ipw_fw_dma_add_command_block(priv,
2331 src_phys + src_offset,
2334 CB_MAX_LENGTH, 0, 0);
2336 IPW_DEBUG_FW_INFO(": Failed\n");
2339 IPW_DEBUG_FW_INFO(": Added new cb\n");
2341 src_offset += CB_MAX_LENGTH;
2342 dest_offset += CB_MAX_LENGTH;
2343 bytes_left -= CB_MAX_LENGTH;
2346 /* add the buffer tail */
2347 if (bytes_left > 0) {
2349 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2350 dest_address + dest_offset,
2353 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2357 (": Adding new cb - the buffer tail\n");
2360 IPW_DEBUG_FW("<< \n");
2364 static int ipw_fw_dma_wait(struct ipw_priv *priv)
2366 u32 current_index = 0;
2369 IPW_DEBUG_FW(">> : \n");
2371 current_index = ipw_fw_dma_command_block_index(priv);
2372 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n",
2373 (int)priv->sram_desc.last_cb_index);
2375 while (current_index < priv->sram_desc.last_cb_index) {
2377 current_index = ipw_fw_dma_command_block_index(priv);
2381 if (watchdog > 400) {
2382 IPW_DEBUG_FW_INFO("Timeout\n");
2383 ipw_fw_dma_dump_command_block(priv);
2384 ipw_fw_dma_abort(priv);
2389 ipw_fw_dma_abort(priv);
2391 /*Disable the DMA in the CSR register */
2392 ipw_set_bit(priv, CX2_RESET_REG,
2393 CX2_RESET_REG_MASTER_DISABLED | CX2_RESET_REG_STOP_MASTER);
2395 IPW_DEBUG_FW("<< dmaWaitSync \n");
2399 static void ipw_remove_current_network(struct ipw_priv *priv)
2401 struct list_head *element, *safe;
2402 struct ieee80211_network *network = NULL;
2403 unsigned long flags;
2405 spin_lock_irqsave(&priv->ieee->lock, flags);
2406 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2407 network = list_entry(element, struct ieee80211_network, list);
2408 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2410 list_add_tail(&network->list,
2411 &priv->ieee->network_free_list);
2414 spin_unlock_irqrestore(&priv->ieee->lock, flags);
2418 * Check that card is still alive.
2419 * Reads debug register from domain0.
2420 * If card is present, pre-defined value should
2424 * @return 1 if card is present, 0 otherwise
2426 static inline int ipw_alive(struct ipw_priv *priv)
2428 return ipw_read32(priv, 0x90) == 0xd55555d5;
2431 static inline int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2437 if ((ipw_read32(priv, addr) & mask) == mask)
2441 } while (i < timeout);
2446 /* These functions load the firmware and micro code for the operation of
2447 * the ipw hardware. It assumes the buffer has all the bits for the
2448 * image and the caller is handling the memory allocation and clean up.
2451 static int ipw_stop_master(struct ipw_priv *priv)
2455 IPW_DEBUG_TRACE(">> \n");
2456 /* stop master. typical delay - 0 */
2457 ipw_set_bit(priv, CX2_RESET_REG, CX2_RESET_REG_STOP_MASTER);
2459 rc = ipw_poll_bit(priv, CX2_RESET_REG,
2460 CX2_RESET_REG_MASTER_DISABLED, 100);
2462 IPW_ERROR("stop master failed in 10ms\n");
2466 IPW_DEBUG_INFO("stop master %dms\n", rc);
2471 static void ipw_arc_release(struct ipw_priv *priv)
2473 IPW_DEBUG_TRACE(">> \n");
2476 ipw_clear_bit(priv, CX2_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
2478 /* no one knows timing, for safety add some delay */
2492 #define IPW_FW_MAJOR_VERSION 2
2493 #define IPW_FW_MINOR_VERSION 2
2495 #define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
2496 #define IPW_FW_MAJOR(x) (x & 0xff)
2498 #define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | \
2499 IPW_FW_MAJOR_VERSION)
2501 #define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
2502 "." __stringify(IPW_FW_MINOR_VERSION) "-"
2504 #if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
2505 #define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
2507 #define IPW_FW_NAME(x) "ipw2200_" x ".fw"
2510 static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
2512 int rc = 0, i, addr;
2516 image = (u16 *) data;
2518 IPW_DEBUG_TRACE(">> \n");
2520 rc = ipw_stop_master(priv);
2525 // spin_lock_irqsave(&priv->lock, flags);
2527 for (addr = CX2_SHARED_LOWER_BOUND;
2528 addr < CX2_REGISTER_DOMAIN1_END; addr += 4) {
2529 ipw_write32(priv, addr, 0);
2532 /* no ucode (yet) */
2533 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2534 /* destroy DMA queues */
2535 /* reset sequence */
2537 ipw_write_reg32(priv, CX2_MEM_HALT_AND_RESET, CX2_BIT_HALT_RESET_ON);
2538 ipw_arc_release(priv);
2539 ipw_write_reg32(priv, CX2_MEM_HALT_AND_RESET, CX2_BIT_HALT_RESET_OFF);
2543 ipw_write_reg32(priv, CX2_INTERNAL_CMD_EVENT, CX2_BASEBAND_POWER_DOWN);
2546 ipw_write_reg32(priv, CX2_INTERNAL_CMD_EVENT, 0);
2549 /* enable ucode store */
2550 ipw_write_reg8(priv, DINO_CONTROL_REG, 0x0);
2551 ipw_write_reg8(priv, DINO_CONTROL_REG, DINO_ENABLE_CS);
2557 * Do NOT set indirect address register once and then
2558 * store data to indirect data register in the loop.
2559 * It seems very reasonable, but in this case DINO do not
2560 * accept ucode. It is essential to set address each time.
2562 /* load new ipw uCode */
2563 for (i = 0; i < len / 2; i++)
2564 ipw_write_reg16(priv, CX2_BASEBAND_CONTROL_STORE,
2565 cpu_to_le16(image[i]));
2568 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 0);
2569 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
2571 /* this is where the igx / win driver deveates from the VAP driver. */
2573 /* wait for alive response */
2574 for (i = 0; i < 100; i++) {
2575 /* poll for incoming data */
2576 cr = ipw_read_reg8(priv, CX2_BASEBAND_CONTROL_STATUS);
2577 if (cr & DINO_RXFIFO_DATA)
2582 if (cr & DINO_RXFIFO_DATA) {
2583 /* alive_command_responce size is NOT multiple of 4 */
2584 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
2586 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
2587 response_buffer[i] =
2588 le32_to_cpu(ipw_read_reg32(priv,
2589 CX2_BASEBAND_RX_FIFO_READ));
2590 memcpy(&priv->dino_alive, response_buffer,
2591 sizeof(priv->dino_alive));
2592 if (priv->dino_alive.alive_command == 1
2593 && priv->dino_alive.ucode_valid == 1) {
2596 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2597 "of %02d/%02d/%02d %02d:%02d\n",
2598 priv->dino_alive.software_revision,
2599 priv->dino_alive.software_revision,
2600 priv->dino_alive.device_identifier,
2601 priv->dino_alive.device_identifier,
2602 priv->dino_alive.time_stamp[0],
2603 priv->dino_alive.time_stamp[1],
2604 priv->dino_alive.time_stamp[2],
2605 priv->dino_alive.time_stamp[3],
2606 priv->dino_alive.time_stamp[4]);
2608 IPW_DEBUG_INFO("Microcode is not alive\n");
2612 IPW_DEBUG_INFO("No alive response from DINO\n");
2616 /* disable DINO, otherwise for some reason
2617 firmware have problem getting alive resp. */
2618 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 0);
2620 // spin_unlock_irqrestore(&priv->lock, flags);
2625 static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
2629 struct fw_chunk *chunk;
2630 dma_addr_t shared_phys;
2633 IPW_DEBUG_TRACE("<< : \n");
2634 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
2639 memmove(shared_virt, data, len);
2642 rc = ipw_fw_dma_enable(priv);
2644 if (priv->sram_desc.last_cb_index > 0) {
2645 /* the DMA is already ready this would be a bug. */
2651 chunk = (struct fw_chunk *)(data + offset);
2652 offset += sizeof(struct fw_chunk);
2653 /* build DMA packet and queue up for sending */
2654 /* dma to chunk->address, the chunk->length bytes from data +
2657 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
2658 le32_to_cpu(chunk->address),
2659 le32_to_cpu(chunk->length));
2661 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
2665 offset += le32_to_cpu(chunk->length);
2666 } while (offset < len);
2668 /* Run the DMA and wait for the answer */
2669 rc = ipw_fw_dma_kick(priv);
2671 IPW_ERROR("dmaKick Failed\n");
2675 rc = ipw_fw_dma_wait(priv);
2677 IPW_ERROR("dmaWaitSync Failed\n");
2681 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
2686 static int ipw_stop_nic(struct ipw_priv *priv)
2691 ipw_write32(priv, CX2_RESET_REG, CX2_RESET_REG_STOP_MASTER);
2693 rc = ipw_poll_bit(priv, CX2_RESET_REG,
2694 CX2_RESET_REG_MASTER_DISABLED, 500);
2696 IPW_ERROR("wait for reg master disabled failed\n");
2700 ipw_set_bit(priv, CX2_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
2705 static void ipw_start_nic(struct ipw_priv *priv)
2707 IPW_DEBUG_TRACE(">>\n");
2709 /* prvHwStartNic release ARC */
2710 ipw_clear_bit(priv, CX2_RESET_REG,
2711 CX2_RESET_REG_MASTER_DISABLED |
2712 CX2_RESET_REG_STOP_MASTER |
2713 CBD_RESET_REG_PRINCETON_RESET);
2715 /* enable power management */
2716 ipw_set_bit(priv, CX2_GP_CNTRL_RW,
2717 CX2_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
2719 IPW_DEBUG_TRACE("<<\n");
2722 static int ipw_init_nic(struct ipw_priv *priv)
2726 IPW_DEBUG_TRACE(">>\n");
2729 /* set "initialization complete" bit to move adapter to D0 state */
2730 ipw_set_bit(priv, CX2_GP_CNTRL_RW, CX2_GP_CNTRL_BIT_INIT_DONE);
2732 /* low-level PLL activation */
2733 ipw_write32(priv, CX2_READ_INT_REGISTER,
2734 CX2_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
2736 /* wait for clock stabilization */
2737 rc = ipw_poll_bit(priv, CX2_GP_CNTRL_RW,
2738 CX2_GP_CNTRL_BIT_CLOCK_READY, 250);
2740 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
2742 /* assert SW reset */
2743 ipw_set_bit(priv, CX2_RESET_REG, CX2_RESET_REG_SW_RESET);
2747 /* set "initialization complete" bit to move adapter to D0 state */
2748 ipw_set_bit(priv, CX2_GP_CNTRL_RW, CX2_GP_CNTRL_BIT_INIT_DONE);
2750 IPW_DEBUG_TRACE(">>\n");
2754 /* Call this function from process context, it will sleep in request_firmware.
2755 * Probe is an ok place to call this from.
2757 static int ipw_reset_nic(struct ipw_priv *priv)
2760 unsigned long flags;
2762 IPW_DEBUG_TRACE(">>\n");
2764 rc = ipw_init_nic(priv);
2766 spin_lock_irqsave(&priv->lock, flags);
2767 /* Clear the 'host command active' bit... */
2768 priv->status &= ~STATUS_HCMD_ACTIVE;
2769 wake_up_interruptible(&priv->wait_command_queue);
2770 spin_unlock_irqrestore(&priv->lock, flags);
2772 IPW_DEBUG_TRACE("<<\n");
2776 static int ipw_get_fw(struct ipw_priv *priv,
2777 const struct firmware **fw, const char *name)
2779 struct fw_header *header;
2782 /* ask firmware_class module to get the boot firmware off disk */
2783 rc = request_firmware(fw, name, &priv->pci_dev->dev);
2785 IPW_ERROR("%s load failed: Reason %d\n", name, rc);
2789 header = (struct fw_header *)(*fw)->data;
2790 if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) {
2791 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
2793 IPW_FW_MAJOR(le32_to_cpu(header->version)),
2794 IPW_FW_MAJOR_VERSION);
2798 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
2800 IPW_FW_MAJOR(le32_to_cpu(header->version)),
2801 IPW_FW_MINOR(le32_to_cpu(header->version)),
2802 (*fw)->size - sizeof(struct fw_header));
2806 #define CX2_RX_BUF_SIZE (3000)
2808 static inline void ipw_rx_queue_reset(struct ipw_priv *priv,
2809 struct ipw_rx_queue *rxq)
2811 unsigned long flags;
2814 spin_lock_irqsave(&rxq->lock, flags);
2816 INIT_LIST_HEAD(&rxq->rx_free);
2817 INIT_LIST_HEAD(&rxq->rx_used);
2819 /* Fill the rx_used queue with _all_ of the Rx buffers */
2820 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
2821 /* In the reset function, these buffers may have been allocated
2822 * to an SKB, so we need to unmap and free potential storage */
2823 if (rxq->pool[i].skb != NULL) {
2824 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
2825 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
2826 dev_kfree_skb(rxq->pool[i].skb);
2827 rxq->pool[i].skb = NULL;
2829 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
2832 /* Set us so that we have processed and used all buffers, but have
2833 * not restocked the Rx queue with fresh buffers */
2834 rxq->read = rxq->write = 0;
2835 rxq->processed = RX_QUEUE_SIZE - 1;
2836 rxq->free_count = 0;
2837 spin_unlock_irqrestore(&rxq->lock, flags);
2841 static int fw_loaded = 0;
2842 static const struct firmware *bootfw = NULL;
2843 static const struct firmware *firmware = NULL;
2844 static const struct firmware *ucode = NULL;
2847 static int ipw_load(struct ipw_priv *priv)
2850 const struct firmware *bootfw = NULL;
2851 const struct firmware *firmware = NULL;
2852 const struct firmware *ucode = NULL;
2854 int rc = 0, retries = 3;
2859 rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot"));
2863 switch (priv->ieee->iw_mode) {
2865 rc = ipw_get_fw(priv, &ucode,
2866 IPW_FW_NAME("ibss_ucode"));
2870 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss"));
2873 #ifdef CONFIG_IPW_MONITOR
2874 case IW_MODE_MONITOR:
2875 rc = ipw_get_fw(priv, &ucode,
2876 IPW_FW_NAME("sniffer_ucode"));
2880 rc = ipw_get_fw(priv, &firmware,
2881 IPW_FW_NAME("sniffer"));
2885 rc = ipw_get_fw(priv, &ucode, IPW_FW_NAME("bss_ucode"));
2889 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("bss"));
2905 priv->rxq = ipw_rx_queue_alloc(priv);
2907 ipw_rx_queue_reset(priv, priv->rxq);
2909 IPW_ERROR("Unable to initialize Rx queue\n");
2914 /* Ensure interrupts are disabled */
2915 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL);
2916 priv->status &= ~STATUS_INT_ENABLED;
2918 /* ack pending interrupts */
2919 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_MASK_ALL);
2923 rc = ipw_reset_nic(priv);
2925 IPW_ERROR("Unable to reset NIC\n");
2929 ipw_zero_memory(priv, CX2_NIC_SRAM_LOWER_BOUND,
2930 CX2_NIC_SRAM_UPPER_BOUND - CX2_NIC_SRAM_LOWER_BOUND);
2932 /* DMA the initial boot firmware into the device */
2933 rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
2934 bootfw->size - sizeof(struct fw_header));
2936 IPW_ERROR("Unable to load boot firmware\n");
2940 /* kick start the device */
2941 ipw_start_nic(priv);
2943 /* wait for the device to finish it's initial startup sequence */
2944 rc = ipw_poll_bit(priv, CX2_INTA_RW,
2945 CX2_INTA_BIT_FW_INITIALIZATION_DONE, 500);
2947 IPW_ERROR("device failed to boot initial fw image\n");
2950 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
2952 /* ack fw init done interrupt */
2953 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_BIT_FW_INITIALIZATION_DONE);
2955 /* DMA the ucode into the device */
2956 rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
2957 ucode->size - sizeof(struct fw_header));
2959 IPW_ERROR("Unable to load ucode\n");
2966 /* DMA bss firmware into the device */
2967 rc = ipw_load_firmware(priv, firmware->data +
2968 sizeof(struct fw_header),
2969 firmware->size - sizeof(struct fw_header));
2971 IPW_ERROR("Unable to load firmware\n");
2975 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2977 rc = ipw_queue_reset(priv);
2979 IPW_ERROR("Unable to initialize queues\n");
2983 /* Ensure interrupts are disabled */
2984 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL);
2986 /* kick start the device */
2987 ipw_start_nic(priv);
2989 if (ipw_read32(priv, CX2_INTA_RW) & CX2_INTA_BIT_PARITY_ERROR) {
2991 IPW_WARNING("Parity error. Retrying init.\n");
2996 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3001 /* wait for the device */
3002 rc = ipw_poll_bit(priv, CX2_INTA_RW,
3003 CX2_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3005 IPW_ERROR("device failed to start after 500ms\n");
3008 IPW_DEBUG_INFO("device response after %dms\n", rc);
3010 /* ack fw init done interrupt */
3011 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_BIT_FW_INITIALIZATION_DONE);
3013 /* read eeprom data and initialize the eeprom region of sram */
3014 priv->eeprom_delay = 1;
3015 ipw_eeprom_init_sram(priv);
3017 /* enable interrupts */
3018 ipw_enable_interrupts(priv);
3020 /* Ensure our queue has valid packets */
3021 ipw_rx_queue_replenish(priv);
3023 ipw_write32(priv, CX2_RX_READ_INDEX, priv->rxq->read);
3025 /* ack pending interrupts */
3026 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_MASK_ALL);
3029 release_firmware(bootfw);
3030 release_firmware(ucode);
3031 release_firmware(firmware);
3037 ipw_rx_queue_free(priv, priv->rxq);
3040 ipw_tx_queue_free(priv);
3042 release_firmware(bootfw);
3044 release_firmware(ucode);
3046 release_firmware(firmware);
3049 bootfw = ucode = firmware = NULL;
3058 * Theory of operation
3060 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3061 * 2 empty entries always kept in the buffer to protect from overflow.
3063 * For Tx queue, there are low mark and high mark limits. If, after queuing
3064 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3065 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
3068 * The IPW operates with six queues, one receive queue in the device's
3069 * sram, one transmit queue for sending commands to the device firmware,
3070 * and four transmit queues for data.
3072 * The four transmit queues allow for performing quality of service (qos)
3073 * transmissions as per the 802.11 protocol. Currently Linux does not
3074 * provide a mechanism to the user for utilizing prioritized queues, so
3075 * we only utilize the first data transmit queue (queue1).
3079 * Driver allocates buffers of this size for Rx
3082 static inline int ipw_queue_space(const struct clx2_queue *q)
3084 int s = q->last_used - q->first_empty;
3087 s -= 2; /* keep some reserve to not confuse empty and full situations */
3093 static inline int ipw_queue_inc_wrap(int index, int n_bd)
3095 return (++index == n_bd) ? 0 : index;
3099 * Initialize common DMA queue structure
3101 * @param q queue to init
3102 * @param count Number of BD's to allocate. Should be power of 2
3103 * @param read_register Address for 'read' register
3104 * (not offset within BAR, full address)
3105 * @param write_register Address for 'write' register
3106 * (not offset within BAR, full address)
3107 * @param base_register Address for 'base' register
3108 * (not offset within BAR, full address)
3109 * @param size Address for 'size' register
3110 * (not offset within BAR, full address)
3112 static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
3113 int count, u32 read, u32 write, u32 base, u32 size)
3117 q->low_mark = q->n_bd / 4;
3118 if (q->low_mark < 4)
3121 q->high_mark = q->n_bd / 8;
3122 if (q->high_mark < 2)
3125 q->first_empty = q->last_used = 0;
3129 ipw_write32(priv, base, q->dma_addr);
3130 ipw_write32(priv, size, count);
3131 ipw_write32(priv, read, 0);
3132 ipw_write32(priv, write, 0);
3134 _ipw_read32(priv, 0x90);
3137 static int ipw_queue_tx_init(struct ipw_priv *priv,
3138 struct clx2_tx_queue *q,
3139 int count, u32 read, u32 write, u32 base, u32 size)
3141 struct pci_dev *dev = priv->pci_dev;
3143 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3145 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3150 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
3152 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
3153 sizeof(q->bd[0]) * count);
3159 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3164 * Free one TFD, those at index [txq->q.last_used].
3165 * Do NOT advance any indexes
3170 static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3171 struct clx2_tx_queue *txq)
3173 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3174 struct pci_dev *dev = priv->pci_dev;
3178 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3179 /* nothing to cleanup after for host commands */
3183 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3184 IPW_ERROR("Too many chunks: %i\n",
3185 le32_to_cpu(bd->u.data.num_chunks));
3186 /** @todo issue fatal error, it is quite serious situation */
3190 /* unmap chunks if any */
3191 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3192 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3193 le16_to_cpu(bd->u.data.chunk_len[i]),
3195 if (txq->txb[txq->q.last_used]) {
3196 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3197 txq->txb[txq->q.last_used] = NULL;
3203 * Deallocate DMA queue.
3205 * Empty queue by removing and destroying all BD's.
3211 static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
3213 struct clx2_queue *q = &txq->q;
3214 struct pci_dev *dev = priv->pci_dev;
3219 /* first, empty all BD's */
3220 for (; q->first_empty != q->last_used;
3221 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3222 ipw_queue_tx_free_tfd(priv, txq);
3225 /* free buffers belonging to queue itself */
3226 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
3230 /* 0 fill whole structure */
3231 memset(txq, 0, sizeof(*txq));
3235 * Destroy all DMA queues and structures
3239 static void ipw_tx_queue_free(struct ipw_priv *priv)
3242 ipw_queue_tx_free(priv, &priv->txq_cmd);
3245 ipw_queue_tx_free(priv, &priv->txq[0]);
3246 ipw_queue_tx_free(priv, &priv->txq[1]);
3247 ipw_queue_tx_free(priv, &priv->txq[2]);
3248 ipw_queue_tx_free(priv, &priv->txq[3]);
3251 static void inline __maybe_wake_tx(struct ipw_priv *priv)
3253 if (netif_running(priv->net_dev)) {
3254 switch (priv->port_type) {
3255 case DCR_TYPE_MU_BSS:
3256 case DCR_TYPE_MU_IBSS:
3257 if (!(priv->status & STATUS_ASSOCIATED))
3260 netif_wake_queue(priv->net_dev);
3265 static inline void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
3267 /* First 3 bytes are manufacturer */
3268 bssid[0] = priv->mac_addr[0];
3269 bssid[1] = priv->mac_addr[1];
3270 bssid[2] = priv->mac_addr[2];
3272 /* Last bytes are random */
3273 get_random_bytes(&bssid[3], ETH_ALEN - 3);
3275 bssid[0] &= 0xfe; /* clear multicast bit */
3276 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
3279 static inline u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
3281 struct ipw_station_entry entry;
3284 for (i = 0; i < priv->num_stations; i++) {
3285 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3286 /* Another node is active in network */
3287 priv->missed_adhoc_beacons = 0;
3288 if (!(priv->config & CFG_STATIC_CHANNEL))
3289 /* when other nodes drop out, we drop out */
3290 priv->config &= ~CFG_ADHOC_PERSIST;
3296 if (i == MAX_STATIONS)
3297 return IPW_INVALID_STATION;
3299 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3302 entry.support_mode = 0;
3303 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3304 memcpy(priv->stations[i], bssid, ETH_ALEN);
3305 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
3306 &entry, sizeof(entry));
3307 priv->num_stations++;
3312 static inline u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
3316 for (i = 0; i < priv->num_stations; i++)
3317 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
3320 return IPW_INVALID_STATION;
3323 static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3327 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))) {
3328 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3332 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3334 MAC_ARG(priv->assoc_request.bssid),
3335 priv->assoc_request.channel);
3337 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3338 priv->status |= STATUS_DISASSOCIATING;
3341 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3343 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
3344 err = ipw_send_associate(priv, &priv->assoc_request);
3346 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3353 static void ipw_disassociate(void *data)
3355 ipw_send_disassociate(data, 0);
3358 struct ipw_status_code {
3363 static const struct ipw_status_code ipw_status_codes[] = {
3364 {0x00, "Successful"},
3365 {0x01, "Unspecified failure"},
3366 {0x0A, "Cannot support all requested capabilities in the "
3367 "Capability information field"},
3368 {0x0B, "Reassociation denied due to inability to confirm that "
3369 "association exists"},
3370 {0x0C, "Association denied due to reason outside the scope of this "
3373 "Responding station does not support the specified authentication "
3376 "Received an Authentication frame with authentication sequence "
3377 "transaction sequence number out of expected sequence"},
3378 {0x0F, "Authentication rejected because of challenge failure"},
3379 {0x10, "Authentication rejected due to timeout waiting for next "
3380 "frame in sequence"},
3381 {0x11, "Association denied because AP is unable to handle additional "
3382 "associated stations"},
3384 "Association denied due to requesting station not supporting all "
3385 "of the datarates in the BSSBasicServiceSet Parameter"},
3387 "Association denied due to requesting station not supporting "
3388 "short preamble operation"},
3390 "Association denied due to requesting station not supporting "
3393 "Association denied due to requesting station not supporting "
3396 "Association denied due to requesting station not supporting "
3397 "short slot operation"},
3399 "Association denied due to requesting station not supporting "
3400 "DSSS-OFDM operation"},
3401 {0x28, "Invalid Information Element"},
3402 {0x29, "Group Cipher is not valid"},
3403 {0x2A, "Pairwise Cipher is not valid"},
3404 {0x2B, "AKMP is not valid"},
3405 {0x2C, "Unsupported RSN IE version"},
3406 {0x2D, "Invalid RSN IE Capabilities"},
3407 {0x2E, "Cipher suite is rejected per security policy"},
3410 #ifdef CONFIG_IPW_DEBUG
3411 static const char *ipw_get_status_code(u16 status)
3414 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
3415 if (ipw_status_codes[i].status == (status & 0xff))
3416 return ipw_status_codes[i].reason;
3417 return "Unknown status value.";
3421 static void inline average_init(struct average *avg)
3423 memset(avg, 0, sizeof(*avg));
3426 static void inline average_add(struct average *avg, s16 val)
3428 avg->sum -= avg->entries[avg->pos];
3430 avg->entries[avg->pos++] = val;
3431 if (unlikely(avg->pos == AVG_ENTRIES)) {
3437 static s16 inline average_value(struct average *avg)
3439 if (!unlikely(avg->init)) {
3441 return avg->sum / avg->pos;
3445 return avg->sum / AVG_ENTRIES;
3448 static void ipw_reset_stats(struct ipw_priv *priv)
3450 u32 len = sizeof(u32);
3454 average_init(&priv->average_missed_beacons);
3455 average_init(&priv->average_rssi);
3456 average_init(&priv->average_noise);
3458 priv->last_rate = 0;
3459 priv->last_missed_beacons = 0;
3460 priv->last_rx_packets = 0;
3461 priv->last_tx_packets = 0;
3462 priv->last_tx_failures = 0;
3464 /* Firmware managed, reset only when NIC is restarted, so we have to
3465 * normalize on the current value */
3466 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
3467 &priv->last_rx_err, &len);
3468 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
3469 &priv->last_tx_failures, &len);
3471 /* Driver managed, reset with each association */
3472 priv->missed_adhoc_beacons = 0;
3473 priv->missed_beacons = 0;
3474 priv->tx_packets = 0;
3475 priv->rx_packets = 0;
3479 static inline u32 ipw_get_max_rate(struct ipw_priv *priv)
3482 u32 mask = priv->rates_mask;
3483 /* If currently associated in B mode, restrict the maximum
3484 * rate match to B rates */
3485 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3486 mask &= IEEE80211_CCK_RATES_MASK;
3488 /* TODO: Verify that the rate is supported by the current rates
3491 while (i && !(mask & i))
3494 case IEEE80211_CCK_RATE_1MB_MASK:
3496 case IEEE80211_CCK_RATE_2MB_MASK:
3498 case IEEE80211_CCK_RATE_5MB_MASK:
3500 case IEEE80211_OFDM_RATE_6MB_MASK:
3502 case IEEE80211_OFDM_RATE_9MB_MASK:
3504 case IEEE80211_CCK_RATE_11MB_MASK:
3506 case IEEE80211_OFDM_RATE_12MB_MASK:
3508 case IEEE80211_OFDM_RATE_18MB_MASK:
3510 case IEEE80211_OFDM_RATE_24MB_MASK:
3512 case IEEE80211_OFDM_RATE_36MB_MASK:
3514 case IEEE80211_OFDM_RATE_48MB_MASK:
3516 case IEEE80211_OFDM_RATE_54MB_MASK:
3520 if (priv->ieee->mode == IEEE_B)
3526 static u32 ipw_get_current_rate(struct ipw_priv *priv)
3528 u32 rate, len = sizeof(rate);
3531 if (!(priv->status & STATUS_ASSOCIATED))
3534 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
3535 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
3538 IPW_DEBUG_INFO("failed querying ordinals.\n");
3542 return ipw_get_max_rate(priv);
3545 case IPW_TX_RATE_1MB:
3547 case IPW_TX_RATE_2MB:
3549 case IPW_TX_RATE_5MB:
3551 case IPW_TX_RATE_6MB:
3553 case IPW_TX_RATE_9MB:
3555 case IPW_TX_RATE_11MB:
3557 case IPW_TX_RATE_12MB:
3559 case IPW_TX_RATE_18MB:
3561 case IPW_TX_RATE_24MB:
3563 case IPW_TX_RATE_36MB:
3565 case IPW_TX_RATE_48MB:
3567 case IPW_TX_RATE_54MB:
3574 #define PERFECT_RSSI (-20)
3575 #define WORST_RSSI (-85)
3576 #define IPW_STATS_INTERVAL (2 * HZ)
3577 static void ipw_gather_stats(struct ipw_priv *priv)
3579 u32 rx_err, rx_err_delta, rx_packets_delta;
3580 u32 tx_failures, tx_failures_delta, tx_packets_delta;
3581 u32 missed_beacons_percent, missed_beacons_delta;
3583 u32 len = sizeof(u32);
3585 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
3589 if (!(priv->status & STATUS_ASSOCIATED)) {
3594 /* Update the statistics */
3595 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
3596 &priv->missed_beacons, &len);
3597 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
3598 priv->last_missed_beacons = priv->missed_beacons;
3599 if (priv->assoc_request.beacon_interval) {
3600 missed_beacons_percent = missed_beacons_delta *
3601 (HZ * priv->assoc_request.beacon_interval) /
3602 (IPW_STATS_INTERVAL * 10);
3604 missed_beacons_percent = 0;
3606 average_add(&priv->average_missed_beacons, missed_beacons_percent);
3608 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
3609 rx_err_delta = rx_err - priv->last_rx_err;
3610 priv->last_rx_err = rx_err;
3612 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
3613 tx_failures_delta = tx_failures - priv->last_tx_failures;
3614 priv->last_tx_failures = tx_failures;
3616 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
3617 priv->last_rx_packets = priv->rx_packets;
3619 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
3620 priv->last_tx_packets = priv->tx_packets;
3622 /* Calculate quality based on the following:
3624 * Missed beacon: 100% = 0, 0% = 70% missed
3625 * Rate: 60% = 1Mbs, 100% = Max
3626 * Rx and Tx errors represent a straight % of total Rx/Tx
3627 * RSSI: 100% = > -50, 0% = < -80
3628 * Rx errors: 100% = 0, 0% = 50% missed
3630 * The lowest computed quality is used.
3633 #define BEACON_THRESHOLD 5
3634 beacon_quality = 100 - missed_beacons_percent;
3635 if (beacon_quality < BEACON_THRESHOLD)
3638 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
3639 (100 - BEACON_THRESHOLD);
3640 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
3641 beacon_quality, missed_beacons_percent);
3643 priv->last_rate = ipw_get_current_rate(priv);
3644 max_rate = ipw_get_max_rate(priv);
3645 rate_quality = priv->last_rate * 40 / max_rate + 60;
3646 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
3647 rate_quality, priv->last_rate / 1000000);
3649 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
3650 rx_quality = 100 - (rx_err_delta * 100) /
3651 (rx_packets_delta + rx_err_delta);
3654 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
3655 rx_quality, rx_err_delta, rx_packets_delta);
3657 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
3658 tx_quality = 100 - (tx_failures_delta * 100) /
3659 (tx_packets_delta + tx_failures_delta);
3662 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
3663 tx_quality, tx_failures_delta, tx_packets_delta);
3665 rssi = average_value(&priv->average_rssi);
3666 if (rssi > PERFECT_RSSI)
3667 signal_quality = 100;
3668 else if (rssi < WORST_RSSI)
3670 else /* qual = 100a^2 - 15ab + 62b^2 / a^2 */
3673 (PERFECT_RSSI - WORST_RSSI) *
3674 (PERFECT_RSSI - WORST_RSSI) -
3675 (PERFECT_RSSI - rssi) *
3676 (15 * (PERFECT_RSSI - WORST_RSSI) +
3677 62 * (PERFECT_RSSI - rssi))) /
3678 ((PERFECT_RSSI - WORST_RSSI) * (PERFECT_RSSI - WORST_RSSI));
3680 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
3681 signal_quality, rssi);
3683 quality = min(beacon_quality,
3685 min(tx_quality, min(rx_quality, signal_quality))));
3686 if (quality == beacon_quality)
3687 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
3689 if (quality == rate_quality)
3690 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
3692 if (quality == tx_quality)
3693 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
3695 if (quality == rx_quality)
3696 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
3698 if (quality == signal_quality)
3699 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
3702 priv->quality = quality;
3704 queue_delayed_work(priv->workqueue, &priv->gather_stats,
3705 IPW_STATS_INTERVAL);
3708 static inline void ipw_handle_missed_beacon(struct ipw_priv *priv,
3711 priv->notif_missed_beacons = missed_count;
3713 if (missed_count > priv->missed_beacon_threshold &&
3714 priv->status & STATUS_ASSOCIATED) {
3715 /* If associated and we've hit the missed
3716 * beacon threshold, disassociate, turn
3717 * off roaming, and abort any active scans */
3718 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
3720 "Missed beacon: %d - disassociate\n", missed_count);
3721 priv->status &= ~STATUS_ROAMING;
3722 if (priv->status & STATUS_SCANNING) {
3723 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
3725 "Aborting scan with missed beacon.\n");
3726 queue_work(priv->workqueue, &priv->abort_scan);
3729 queue_work(priv->workqueue, &priv->disassociate);
3733 if (priv->status & STATUS_ROAMING) {
3734 /* If we are currently roaming, then just
3735 * print a debug statement... */
3736 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3737 "Missed beacon: %d - roam in progress\n",
3742 if (missed_count > priv->roaming_threshold) {
3743 /* If we are not already roaming, set the ROAM
3744 * bit in the status and kick off a scan */
3745 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3746 "Missed beacon: %d - initiate "
3747 "roaming\n", missed_count);
3748 if (!(priv->status & STATUS_ROAMING)) {
3749 priv->status |= STATUS_ROAMING;
3750 if (!(priv->status & STATUS_SCANNING))
3751 queue_work(priv->workqueue,
3752 &priv->request_scan);
3757 if (priv->status & STATUS_SCANNING) {
3758 /* Stop scan to keep fw from getting
3759 * stuck (only if we aren't roaming --
3760 * otherwise we'll never scan more than 2 or 3
3762 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
3763 IPW_DL_STATE, "Aborting scan with missed beacon.\n");
3764 queue_work(priv->workqueue, &priv->abort_scan);
3767 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
3772 * Handle host notification packet.
3773 * Called from interrupt routine
3775 static inline void ipw_rx_notification(struct ipw_priv *priv,
3776 struct ipw_rx_notification *notif)
3778 notif->size = le16_to_cpu(notif->size);
3780 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
3782 switch (notif->subtype) {
3783 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
3784 struct notif_association *assoc = ¬if->u.assoc;
3786 switch (assoc->state) {
3787 case CMAS_ASSOCIATED:{
3788 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3790 "associated: '%s' " MAC_FMT
3792 escape_essid(priv->essid,
3794 MAC_ARG(priv->bssid));
3796 switch (priv->ieee->iw_mode) {
3798 memcpy(priv->ieee->bssid,
3799 priv->bssid, ETH_ALEN);
3803 memcpy(priv->ieee->bssid,
3804 priv->bssid, ETH_ALEN);
3806 /* clear out the station table */
3807 priv->num_stations = 0;
3810 ("queueing adhoc check\n");
3811 queue_delayed_work(priv->
3821 priv->status &= ~STATUS_ASSOCIATING;
3822 priv->status |= STATUS_ASSOCIATED;
3824 schedule_work(&priv->link_up);
3829 case CMAS_AUTHENTICATED:{
3831 status & (STATUS_ASSOCIATED |
3833 #ifdef CONFIG_IPW_DEBUG
3834 struct notif_authenticate *auth
3836 IPW_DEBUG(IPW_DL_NOTIF |
3839 "deauthenticated: '%s' "
3841 ": (0x%04X) - %s \n",
3846 MAC_ARG(priv->bssid),
3847 ntohs(auth->status),
3854 ~(STATUS_ASSOCIATING |
3858 schedule_work(&priv->link_down);
3862 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3864 "authenticated: '%s' " MAC_FMT
3866 escape_essid(priv->essid,
3868 MAC_ARG(priv->bssid));
3873 if (priv->status & STATUS_AUTH) {
3875 ieee80211_assoc_response
3879 ieee80211_assoc_response
3881 IPW_DEBUG(IPW_DL_NOTIF |
3884 "association failed (0x%04X): %s\n",
3885 ntohs(resp->status),
3891 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3893 "disassociated: '%s' " MAC_FMT
3895 escape_essid(priv->essid,
3897 MAC_ARG(priv->bssid));
3900 ~(STATUS_DISASSOCIATING |
3901 STATUS_ASSOCIATING |
3902 STATUS_ASSOCIATED | STATUS_AUTH);
3904 schedule_work(&priv->link_down);
3910 IPW_ERROR("assoc: unknown (%d)\n",
3918 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
3919 struct notif_authenticate *auth = ¬if->u.auth;
3920 switch (auth->state) {
3921 case CMAS_AUTHENTICATED:
3922 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3923 "authenticated: '%s' " MAC_FMT " \n",
3924 escape_essid(priv->essid,
3926 MAC_ARG(priv->bssid));
3927 priv->status |= STATUS_AUTH;
3931 if (priv->status & STATUS_AUTH) {
3932 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3934 "authentication failed (0x%04X): %s\n",
3935 ntohs(auth->status),
3936 ipw_get_status_code(ntohs
3940 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3942 "deauthenticated: '%s' " MAC_FMT "\n",
3943 escape_essid(priv->essid,
3945 MAC_ARG(priv->bssid));
3947 priv->status &= ~(STATUS_ASSOCIATING |
3951 schedule_work(&priv->link_down);
3954 case CMAS_TX_AUTH_SEQ_1:
3955 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3956 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
3958 case CMAS_RX_AUTH_SEQ_2:
3959 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3960 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
3962 case CMAS_AUTH_SEQ_1_PASS:
3963 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3964 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
3966 case CMAS_AUTH_SEQ_1_FAIL:
3967 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3968 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
3970 case CMAS_TX_AUTH_SEQ_3:
3971 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3972 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
3974 case CMAS_RX_AUTH_SEQ_4:
3975 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3976 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
3978 case CMAS_AUTH_SEQ_2_PASS:
3979 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3980 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
3982 case CMAS_AUTH_SEQ_2_FAIL:
3983 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3984 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
3987 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3988 IPW_DL_ASSOC, "TX_ASSOC\n");
3990 case CMAS_RX_ASSOC_RESP:
3991 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3992 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
3994 case CMAS_ASSOCIATED:
3995 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3996 IPW_DL_ASSOC, "ASSOCIATED\n");
3999 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4006 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4007 struct notif_channel_result *x =
4008 ¬if->u.channel_result;
4010 if (notif->size == sizeof(*x)) {
4011 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4014 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4015 "(should be %zd)\n",
4016 notif->size, sizeof(*x));
4021 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4022 struct notif_scan_complete *x = ¬if->u.scan_complete;
4023 if (notif->size == sizeof(*x)) {
4025 ("Scan completed: type %d, %d channels, "
4026 "%d status\n", x->scan_type,
4027 x->num_channels, x->status);
4029 IPW_ERROR("Scan completed of wrong size %d "
4030 "(should be %zd)\n",
4031 notif->size, sizeof(*x));
4035 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4037 cancel_delayed_work(&priv->scan_check);
4039 if (!(priv->status & (STATUS_ASSOCIATED |
4040 STATUS_ASSOCIATING |
4042 STATUS_DISASSOCIATING)))
4043 queue_work(priv->workqueue, &priv->associate);
4044 else if (priv->status & STATUS_ROAMING) {
4045 /* If a scan completed and we are in roam mode, then
4046 * the scan that completed was the one requested as a
4047 * result of entering roam... so, schedule the
4049 queue_work(priv->workqueue, &priv->roam);
4050 } else if (priv->status & STATUS_SCAN_PENDING)
4051 queue_work(priv->workqueue,
4052 &priv->request_scan);
4053 else if (priv->config & CFG_BACKGROUND_SCAN
4054 && priv->status & STATUS_ASSOCIATED)
4055 queue_delayed_work(priv->workqueue,
4056 &priv->request_scan, HZ);
4058 priv->ieee->scans++;
4062 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4063 struct notif_frag_length *x = ¬if->u.frag_len;
4065 if (notif->size == sizeof(*x))
4066 IPW_ERROR("Frag length: %d\n",
4067 le16_to_cpu(x->frag_length));
4069 IPW_ERROR("Frag length of wrong size %d "
4070 "(should be %zd)\n",
4071 notif->size, sizeof(*x));
4075 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4076 struct notif_link_deterioration *x =
4077 ¬if->u.link_deterioration;
4078 if (notif->size == sizeof(*x)) {
4079 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4080 "link deterioration: '%s' " MAC_FMT
4081 " \n", escape_essid(priv->essid,
4083 MAC_ARG(priv->bssid));
4084 memcpy(&priv->last_link_deterioration, x,
4087 IPW_ERROR("Link Deterioration of wrong size %d "
4088 "(should be %zd)\n",
4089 notif->size, sizeof(*x));
4094 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4095 IPW_ERROR("Dino config\n");
4097 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
4098 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
4103 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4104 struct notif_beacon_state *x = ¬if->u.beacon_state;
4105 if (notif->size != sizeof(*x)) {
4107 ("Beacon state of wrong size %d (should "
4108 "be %zd)\n", notif->size, sizeof(*x));
4112 if (le32_to_cpu(x->state) ==
4113 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4114 ipw_handle_missed_beacon(priv,
4121 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4122 struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key;
4123 if (notif->size == sizeof(*x)) {
4124 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4125 "0x%02x station %d\n",
4126 x->key_state, x->security_type,
4132 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4133 notif->size, sizeof(*x));
4137 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4138 struct notif_calibration *x = ¬if->u.calibration;
4140 if (notif->size == sizeof(*x)) {
4141 memcpy(&priv->calib, x, sizeof(*x));
4142 IPW_DEBUG_INFO("TODO: Calibration\n");
4147 ("Calibration of wrong size %d (should be %zd)\n",
4148 notif->size, sizeof(*x));
4152 case HOST_NOTIFICATION_NOISE_STATS:{
4153 if (notif->size == sizeof(u32)) {
4155 (u8) (le32_to_cpu(notif->u.noise.value) &
4157 average_add(&priv->average_noise,
4163 ("Noise stat is wrong size %d (should be %zd)\n",
4164 notif->size, sizeof(u32));
4169 IPW_ERROR("Unknown notification: "
4170 "subtype=%d,flags=0x%2x,size=%d\n",
4171 notif->subtype, notif->flags, notif->size);
4176 * Destroys all DMA structures and initialise them again
4179 * @return error code
4181 static int ipw_queue_reset(struct ipw_priv *priv)
4184 /** @todo customize queue sizes */
4185 int nTx = 64, nTxCmd = 8;
4186 ipw_tx_queue_free(priv);
4188 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
4189 CX2_TX_CMD_QUEUE_READ_INDEX,
4190 CX2_TX_CMD_QUEUE_WRITE_INDEX,
4191 CX2_TX_CMD_QUEUE_BD_BASE,
4192 CX2_TX_CMD_QUEUE_BD_SIZE);
4194 IPW_ERROR("Tx Cmd queue init failed\n");
4198 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
4199 CX2_TX_QUEUE_0_READ_INDEX,
4200 CX2_TX_QUEUE_0_WRITE_INDEX,
4201 CX2_TX_QUEUE_0_BD_BASE, CX2_TX_QUEUE_0_BD_SIZE);
4203 IPW_ERROR("Tx 0 queue init failed\n");
4206 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
4207 CX2_TX_QUEUE_1_READ_INDEX,
4208 CX2_TX_QUEUE_1_WRITE_INDEX,
4209 CX2_TX_QUEUE_1_BD_BASE, CX2_TX_QUEUE_1_BD_SIZE);
4211 IPW_ERROR("Tx 1 queue init failed\n");
4214 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
4215 CX2_TX_QUEUE_2_READ_INDEX,
4216 CX2_TX_QUEUE_2_WRITE_INDEX,
4217 CX2_TX_QUEUE_2_BD_BASE, CX2_TX_QUEUE_2_BD_SIZE);
4219 IPW_ERROR("Tx 2 queue init failed\n");
4222 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
4223 CX2_TX_QUEUE_3_READ_INDEX,
4224 CX2_TX_QUEUE_3_WRITE_INDEX,
4225 CX2_TX_QUEUE_3_BD_BASE, CX2_TX_QUEUE_3_BD_SIZE);
4227 IPW_ERROR("Tx 3 queue init failed\n");
4231 priv->rx_bufs_min = 0;
4232 priv->rx_pend_max = 0;
4236 ipw_tx_queue_free(priv);
4241 * Reclaim Tx queue entries no more used by NIC.
4243 * When FW adwances 'R' index, all entries between old and
4244 * new 'R' index need to be reclaimed. As result, some free space
4245 * forms. If there is enough free space (> low mark), wake Tx queue.
4247 * @note Need to protect against garbage in 'R' index
4251 * @return Number of used entries remains in the queue
4253 static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
4254 struct clx2_tx_queue *txq, int qindex)
4258 struct clx2_queue *q = &txq->q;
4260 hw_tail = ipw_read32(priv, q->reg_r);
4261 if (hw_tail >= q->n_bd) {
4263 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4267 for (; q->last_used != hw_tail;
4268 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4269 ipw_queue_tx_free_tfd(priv, txq);
4273 if (ipw_queue_space(q) > q->low_mark && qindex >= 0)
4274 __maybe_wake_tx(priv);
4275 used = q->first_empty - q->last_used;
4282 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4285 struct clx2_tx_queue *txq = &priv->txq_cmd;
4286 struct clx2_queue *q = &txq->q;
4287 struct tfd_frame *tfd;
4289 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4290 IPW_ERROR("No space for Tx\n");
4294 tfd = &txq->bd[q->first_empty];
4295 txq->txb[q->first_empty] = NULL;
4297 memset(tfd, 0, sizeof(*tfd));
4298 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4299 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4301 tfd->u.cmd.index = hcmd;
4302 tfd->u.cmd.length = len;
4303 memcpy(tfd->u.cmd.payload, buf, len);
4304 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4305 ipw_write32(priv, q->reg_w, q->first_empty);
4306 _ipw_read32(priv, 0x90);
4312 * Rx theory of operation
4314 * The host allocates 32 DMA target addresses and passes the host address
4315 * to the firmware at register CX2_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
4319 * The host/firmware share two index registers for managing the Rx buffers.
4321 * The READ index maps to the first position that the firmware may be writing
4322 * to -- the driver can read up to (but not including) this position and get
4324 * The READ index is managed by the firmware once the card is enabled.
4326 * The WRITE index maps to the last position the driver has read from -- the
4327 * position preceding WRITE is the last slot the firmware can place a packet.
4329 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
4332 * During initialization the host sets up the READ queue position to the first
4333 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4335 * When the firmware places a packet in a buffer it will advance the READ index
4336 * and fire the RX interrupt. The driver can then query the READ index and
4337 * process as many packets as possible, moving the WRITE index forward as it
4338 * resets the Rx queue buffers with new memory.
4340 * The management in the driver is as follows:
4341 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
4342 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
4343 * to replensish the ipw->rxq->rx_free.
4344 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4345 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4346 * 'processed' and 'read' driver indexes as well)
4347 * + A received packet is processed and handed to the kernel network stack,
4348 * detached from the ipw->rxq. The driver 'processed' index is updated.
4349 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
4350 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4351 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
4352 * were enough free buffers and RX_STALLED is set it is cleared.
4357 * ipw_rx_queue_alloc() Allocates rx_free
4358 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4359 * ipw_rx_queue_restock
4360 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4361 * queue, updates firmware pointers, and updates
4362 * the WRITE index. If insufficient rx_free buffers
4363 * are available, schedules ipw_rx_queue_replenish
4365 * -- enable interrupts --
4366 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
4367 * READ INDEX, detaching the SKB from the pool.
4368 * Moves the packet buffer from queue to rx_used.
4369 * Calls ipw_rx_queue_restock to refill any empty
4376 * If there are slots in the RX queue that need to be restocked,
4377 * and we have free pre-allocated buffers, fill the ranks as much
4378 * as we can pulling from rx_free.
4380 * This moves the 'write' index forward to catch up with 'processed', and
4381 * also updates the memory address in the firmware to reference the new
4384 static void ipw_rx_queue_restock(struct ipw_priv *priv)
4386 struct ipw_rx_queue *rxq = priv->rxq;
4387 struct list_head *element;
4388 struct ipw_rx_mem_buffer *rxb;
4389 unsigned long flags;
4392 spin_lock_irqsave(&rxq->lock, flags);
4394 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4395 element = rxq->rx_free.next;
4396 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4399 ipw_write32(priv, CX2_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
4401 rxq->queue[rxq->write] = rxb;
4402 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4405 spin_unlock_irqrestore(&rxq->lock, flags);
4407 /* If the pre-allocated buffer pool is dropping low, schedule to
4409 if (rxq->free_count <= RX_LOW_WATERMARK)
4410 queue_work(priv->workqueue, &priv->rx_replenish);
4412 /* If we've added more space for the firmware to place data, tell it */
4413 if (write != rxq->write)
4414 ipw_write32(priv, CX2_RX_WRITE_INDEX, rxq->write);
4418 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
4419 * Also restock the Rx queue via ipw_rx_queue_restock.
4421 * This is called as a scheduled work item (except for during intialization)
4423 static void ipw_rx_queue_replenish(void *data)
4425 struct ipw_priv *priv = data;
4426 struct ipw_rx_queue *rxq = priv->rxq;
4427 struct list_head *element;
4428 struct ipw_rx_mem_buffer *rxb;
4429 unsigned long flags;
4431 spin_lock_irqsave(&rxq->lock, flags);
4432 while (!list_empty(&rxq->rx_used)) {
4433 element = rxq->rx_used.next;
4434 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4435 rxb->skb = alloc_skb(CX2_RX_BUF_SIZE, GFP_ATOMIC);
4437 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
4438 priv->net_dev->name);
4439 /* We don't reschedule replenish work here -- we will
4440 * call the restock method and if it still needs
4441 * more buffers it will schedule replenish */
4446 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
4448 pci_map_single(priv->pci_dev, rxb->skb->data,
4449 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4451 list_add_tail(&rxb->list, &rxq->rx_free);
4454 spin_unlock_irqrestore(&rxq->lock, flags);
4456 ipw_rx_queue_restock(priv);
4459 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4460 * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
4461 * This free routine walks the list of POOL entries and if SKB is set to
4462 * non NULL it is unmapped and freed
4464 static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
4471 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4472 if (rxq->pool[i].skb != NULL) {
4473 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
4474 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4475 dev_kfree_skb(rxq->pool[i].skb);
4482 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4484 struct ipw_rx_queue *rxq;
4487 rxq = (struct ipw_rx_queue *)kmalloc(sizeof(*rxq), GFP_KERNEL);
4488 if (unlikely(!rxq)) {
4489 IPW_ERROR("memory allocation failed\n");
4492 memset(rxq, 0, sizeof(*rxq));
4493 spin_lock_init(&rxq->lock);
4494 INIT_LIST_HEAD(&rxq->rx_free);
4495 INIT_LIST_HEAD(&rxq->rx_used);
4497 /* Fill the rx_used queue with _all_ of the Rx buffers */
4498 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
4499 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4501 /* Set us so that we have processed and used all buffers, but have
4502 * not restocked the Rx queue with fresh buffers */
4503 rxq->read = rxq->write = 0;
4504 rxq->processed = RX_QUEUE_SIZE - 1;
4505 rxq->free_count = 0;
4510 static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
4512 rate &= ~IEEE80211_BASIC_RATE_MASK;
4513 if (ieee_mode == IEEE_A) {
4515 case IEEE80211_OFDM_RATE_6MB:
4516 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
4518 case IEEE80211_OFDM_RATE_9MB:
4519 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
4521 case IEEE80211_OFDM_RATE_12MB:
4523 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
4524 case IEEE80211_OFDM_RATE_18MB:
4526 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
4527 case IEEE80211_OFDM_RATE_24MB:
4529 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
4530 case IEEE80211_OFDM_RATE_36MB:
4532 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
4533 case IEEE80211_OFDM_RATE_48MB:
4535 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
4536 case IEEE80211_OFDM_RATE_54MB:
4538 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
4546 case IEEE80211_CCK_RATE_1MB:
4547 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
4548 case IEEE80211_CCK_RATE_2MB:
4549 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
4550 case IEEE80211_CCK_RATE_5MB:
4551 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
4552 case IEEE80211_CCK_RATE_11MB:
4553 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
4556 /* If we are limited to B modulations, bail at this point */
4557 if (ieee_mode == IEEE_B)
4562 case IEEE80211_OFDM_RATE_6MB:
4563 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
4564 case IEEE80211_OFDM_RATE_9MB:
4565 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
4566 case IEEE80211_OFDM_RATE_12MB:
4567 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
4568 case IEEE80211_OFDM_RATE_18MB:
4569 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
4570 case IEEE80211_OFDM_RATE_24MB:
4571 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
4572 case IEEE80211_OFDM_RATE_36MB:
4573 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
4574 case IEEE80211_OFDM_RATE_48MB:
4575 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
4576 case IEEE80211_OFDM_RATE_54MB:
4577 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
4583 static int ipw_compatible_rates(struct ipw_priv *priv,
4584 const struct ieee80211_network *network,
4585 struct ipw_supported_rates *rates)
4589 memset(rates, 0, sizeof(*rates));
4590 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
4591 rates->num_rates = 0;
4592 for (i = 0; i < num_rates; i++) {
4593 if (!ipw_is_rate_in_mask(priv, network->mode,
4594 network->rates[i])) {
4596 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
4597 IPW_DEBUG_SCAN("Adding masked mandatory "
4600 rates->supported_rates[rates->num_rates++] =
4605 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4606 network->rates[i], priv->rates_mask);
4610 rates->supported_rates[rates->num_rates++] = network->rates[i];
4613 num_rates = min(network->rates_ex_len,
4614 (u8) (IPW_MAX_RATES - num_rates));
4615 for (i = 0; i < num_rates; i++) {
4616 if (!ipw_is_rate_in_mask(priv, network->mode,
4617 network->rates_ex[i])) {
4618 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
4619 IPW_DEBUG_SCAN("Adding masked mandatory "
4621 network->rates_ex[i]);
4622 rates->supported_rates[rates->num_rates++] =
4627 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4628 network->rates_ex[i], priv->rates_mask);
4632 rates->supported_rates[rates->num_rates++] =
4633 network->rates_ex[i];
4639 static inline void ipw_copy_rates(struct ipw_supported_rates *dest,
4640 const struct ipw_supported_rates *src)
4643 for (i = 0; i < src->num_rates; i++)
4644 dest->supported_rates[i] = src->supported_rates[i];
4645 dest->num_rates = src->num_rates;
4648 /* TODO: Look at sniffed packets in the air to determine if the basic rate
4649 * mask should ever be used -- right now all callers to add the scan rates are
4650 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
4651 static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
4652 u8 modulation, u32 rate_mask)
4654 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
4655 IEEE80211_BASIC_RATE_MASK : 0;
4657 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
4658 rates->supported_rates[rates->num_rates++] =
4659 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
4661 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
4662 rates->supported_rates[rates->num_rates++] =
4663 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
4665 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
4666 rates->supported_rates[rates->num_rates++] = basic_mask |
4667 IEEE80211_CCK_RATE_5MB;
4669 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
4670 rates->supported_rates[rates->num_rates++] = basic_mask |
4671 IEEE80211_CCK_RATE_11MB;
4674 static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
4675 u8 modulation, u32 rate_mask)
4677 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
4678 IEEE80211_BASIC_RATE_MASK : 0;
4680 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
4681 rates->supported_rates[rates->num_rates++] = basic_mask |
4682 IEEE80211_OFDM_RATE_6MB;
4684 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
4685 rates->supported_rates[rates->num_rates++] =
4686 IEEE80211_OFDM_RATE_9MB;
4688 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
4689 rates->supported_rates[rates->num_rates++] = basic_mask |
4690 IEEE80211_OFDM_RATE_12MB;
4692 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
4693 rates->supported_rates[rates->num_rates++] =
4694 IEEE80211_OFDM_RATE_18MB;
4696 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
4697 rates->supported_rates[rates->num_rates++] = basic_mask |
4698 IEEE80211_OFDM_RATE_24MB;
4700 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
4701 rates->supported_rates[rates->num_rates++] =
4702 IEEE80211_OFDM_RATE_36MB;
4704 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
4705 rates->supported_rates[rates->num_rates++] =
4706 IEEE80211_OFDM_RATE_48MB;
4708 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
4709 rates->supported_rates[rates->num_rates++] =
4710 IEEE80211_OFDM_RATE_54MB;
4713 struct ipw_network_match {
4714 struct ieee80211_network *network;
4715 struct ipw_supported_rates rates;
4718 static int ipw_best_network(struct ipw_priv *priv,
4719 struct ipw_network_match *match,
4720 struct ieee80211_network *network, int roaming)
4722 struct ipw_supported_rates rates;
4724 /* Verify that this network's capability is compatible with the
4725 * current mode (AdHoc or Infrastructure) */
4726 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
4727 !(network->capability & WLAN_CAPABILITY_ESS)) ||
4728 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
4729 !(network->capability & WLAN_CAPABILITY_IBSS))) {
4730 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
4731 "capability mismatch.\n",
4732 escape_essid(network->ssid, network->ssid_len),
4733 MAC_ARG(network->bssid));
4737 /* If we do not have an ESSID for this AP, we can not associate with
4739 if (network->flags & NETWORK_EMPTY_ESSID) {
4740 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4741 "because of hidden ESSID.\n",
4742 escape_essid(network->ssid, network->ssid_len),
4743 MAC_ARG(network->bssid));
4747 if (unlikely(roaming)) {
4748 /* If we are roaming, then ensure check if this is a valid
4749 * network to try and roam to */
4750 if ((network->ssid_len != match->network->ssid_len) ||
4751 memcmp(network->ssid, match->network->ssid,
4752 network->ssid_len)) {
4753 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
4754 "because of non-network ESSID.\n",
4755 escape_essid(network->ssid,
4757 MAC_ARG(network->bssid));
4761 /* If an ESSID has been configured then compare the broadcast
4763 if ((priv->config & CFG_STATIC_ESSID) &&
4764 ((network->ssid_len != priv->essid_len) ||
4765 memcmp(network->ssid, priv->essid,
4766 min(network->ssid_len, priv->essid_len)))) {
4767 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
4769 escape_essid(network->ssid, network->ssid_len),
4771 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4772 "because of ESSID mismatch: '%s'.\n",
4773 escaped, MAC_ARG(network->bssid),
4774 escape_essid(priv->essid,
4780 /* If the old network rate is better than this one, don't bother
4781 * testing everything else. */
4782 if (match->network && match->network->stats.rssi > network->stats.rssi) {
4783 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
4785 escape_essid(network->ssid, network->ssid_len),
4787 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
4788 "'%s (" MAC_FMT ")' has a stronger signal.\n",
4789 escaped, MAC_ARG(network->bssid),
4790 escape_essid(match->network->ssid,
4791 match->network->ssid_len),
4792 MAC_ARG(match->network->bssid));
4796 /* If this network has already had an association attempt within the
4797 * last 3 seconds, do not try and associate again... */
4798 if (network->last_associate &&
4799 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
4800 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4801 "because of storming (%lu since last "
4802 "assoc attempt).\n",
4803 escape_essid(network->ssid, network->ssid_len),
4804 MAC_ARG(network->bssid),
4805 (jiffies - network->last_associate) / HZ);
4809 /* Now go through and see if the requested network is valid... */
4810 if (priv->ieee->scan_age != 0 &&
4811 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
4812 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4813 "because of age: %lums.\n",
4814 escape_essid(network->ssid, network->ssid_len),
4815 MAC_ARG(network->bssid),
4816 (jiffies - network->last_scanned) / (HZ / 100));
4820 if ((priv->config & CFG_STATIC_CHANNEL) &&
4821 (network->channel != priv->channel)) {
4822 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4823 "because of channel mismatch: %d != %d.\n",
4824 escape_essid(network->ssid, network->ssid_len),
4825 MAC_ARG(network->bssid),
4826 network->channel, priv->channel);
4830 /* Verify privacy compatability */
4831 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
4832 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
4833 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4834 "because of privacy mismatch: %s != %s.\n",
4835 escape_essid(network->ssid, network->ssid_len),
4836 MAC_ARG(network->bssid),
4837 priv->capability & CAP_PRIVACY_ON ? "on" :
4839 network->capability &
4840 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
4844 if ((priv->config & CFG_STATIC_BSSID) &&
4845 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
4846 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4847 "because of BSSID mismatch: " MAC_FMT ".\n",
4848 escape_essid(network->ssid, network->ssid_len),
4849 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
4853 /* Filter out any incompatible freq / mode combinations */
4854 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
4855 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4856 "because of invalid frequency/mode "
4858 escape_essid(network->ssid, network->ssid_len),
4859 MAC_ARG(network->bssid));
4863 /* Ensure that the rates supported by the driver are compatible with
4864 * this AP, including verification of basic rates (mandatory) */
4865 if (!ipw_compatible_rates(priv, network, &rates)) {
4866 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4867 "because configured rate mask excludes "
4868 "AP mandatory rate.\n",
4869 escape_essid(network->ssid, network->ssid_len),
4870 MAC_ARG(network->bssid));
4874 if (rates.num_rates == 0) {
4875 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4876 "because of no compatible rates.\n",
4877 escape_essid(network->ssid, network->ssid_len),
4878 MAC_ARG(network->bssid));
4882 /* TODO: Perform any further minimal comparititive tests. We do not
4883 * want to put too much policy logic here; intelligent scan selection
4884 * should occur within a generic IEEE 802.11 user space tool. */
4886 /* Set up 'new' AP to this network */
4887 ipw_copy_rates(&match->rates, &rates);
4888 match->network = network;
4890 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
4891 escape_essid(network->ssid, network->ssid_len),
4892 MAC_ARG(network->bssid));
4897 static void ipw_adhoc_create(struct ipw_priv *priv,
4898 struct ieee80211_network *network)
4901 * For the purposes of scanning, we can set our wireless mode
4902 * to trigger scans across combinations of bands, but when it
4903 * comes to creating a new ad-hoc network, we have tell the FW
4904 * exactly which band to use.
4906 * We also have the possibility of an invalid channel for the
4907 * chossen band. Attempting to create a new ad-hoc network
4908 * with an invalid channel for wireless mode will trigger a
4911 network->mode = is_valid_channel(priv->ieee->mode, priv->channel);
4912 if (!network->mode) {
4913 IPW_WARNING("Overriding invalid channel\n");
4914 if (priv->ieee->mode & IEEE_A) {
4915 network->mode = IEEE_A;
4916 priv->channel = band_a_active_channel[0];
4917 } else if (priv->ieee->mode & IEEE_G) {
4918 network->mode = IEEE_G;
4919 priv->channel = band_b_active_channel[0];
4921 network->mode = IEEE_B;
4922 priv->channel = band_b_active_channel[0];
4926 network->channel = priv->channel;
4927 priv->config |= CFG_ADHOC_PERSIST;
4928 ipw_create_bssid(priv, network->bssid);
4929 network->ssid_len = priv->essid_len;
4930 memcpy(network->ssid, priv->essid, priv->essid_len);
4931 memset(&network->stats, 0, sizeof(network->stats));
4932 network->capability = WLAN_CAPABILITY_IBSS;
4933 if (!(priv->config & CFG_PREAMBLE_LONG))
4934 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
4935 if (priv->capability & CAP_PRIVACY_ON)
4936 network->capability |= WLAN_CAPABILITY_PRIVACY;
4937 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
4938 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
4939 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
4940 memcpy(network->rates_ex,
4941 &priv->rates.supported_rates[network->rates_len],
4942 network->rates_ex_len);
4943 network->last_scanned = 0;
4945 network->last_associate = 0;
4946 network->time_stamp[0] = 0;
4947 network->time_stamp[1] = 0;
4948 network->beacon_interval = 100; /* Default */
4949 network->listen_interval = 10; /* Default */
4950 network->atim_window = 0; /* Default */
4951 network->wpa_ie_len = 0;
4952 network->rsn_ie_len = 0;
4955 static void ipw_send_wep_keys(struct ipw_priv *priv)
4957 struct ipw_wep_key *key;
4959 struct host_cmd cmd = {
4960 .cmd = IPW_CMD_WEP_KEY,
4964 key = (struct ipw_wep_key *)&cmd.param;
4965 key->cmd_id = DINO_CMD_WEP_KEY;
4968 for (i = 0; i < 4; i++) {
4970 if (!(priv->sec.flags & (1 << i)))
4973 key->key_size = priv->sec.key_sizes[i];
4974 memcpy(key->key, priv->sec.keys[i], key->key_size);
4977 if (ipw_send_cmd(priv, &cmd)) {
4978 IPW_ERROR("failed to send WEP_KEY command\n");
4984 static void ipw_adhoc_check(void *data)
4986 struct ipw_priv *priv = data;
4988 if (priv->missed_adhoc_beacons++ > priv->missed_beacon_threshold &&
4989 !(priv->config & CFG_ADHOC_PERSIST)) {
4990 IPW_DEBUG_SCAN("Disassociating due to missed beacons\n");
4991 ipw_remove_current_network(priv);
4992 ipw_disassociate(priv);
4996 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
4997 priv->assoc_request.beacon_interval);
5000 #ifdef CONFIG_IPW_DEBUG
5001 static void ipw_debug_config(struct ipw_priv *priv)
5003 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5004 "[CFG 0x%08X]\n", priv->config);
5005 if (priv->config & CFG_STATIC_CHANNEL)
5006 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
5008 IPW_DEBUG_INFO("Channel unlocked.\n");
5009 if (priv->config & CFG_STATIC_ESSID)
5010 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
5011 escape_essid(priv->essid, priv->essid_len));
5013 IPW_DEBUG_INFO("ESSID unlocked.\n");
5014 if (priv->config & CFG_STATIC_BSSID)
5015 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5016 MAC_ARG(priv->bssid));
5018 IPW_DEBUG_INFO("BSSID unlocked.\n");
5019 if (priv->capability & CAP_PRIVACY_ON)
5020 IPW_DEBUG_INFO("PRIVACY on\n");
5022 IPW_DEBUG_INFO("PRIVACY off\n");
5023 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5026 #define ipw_debug_config(x) do {} while (0)
5029 static inline void ipw_set_fixed_rate(struct ipw_priv *priv,
5030 struct ieee80211_network *network)
5032 /* TODO: Verify that this works... */
5033 struct ipw_fixed_rate fr = {
5034 .tx_rates = priv->rates_mask
5039 /* Identify 'current FW band' and match it with the fixed
5042 switch (priv->ieee->freq_band) {
5043 case IEEE80211_52GHZ_BAND: /* A only */
5045 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5046 /* Invalid fixed rate mask */
5048 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5053 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5056 default: /* 2.4Ghz or Mixed */
5058 if (network->mode == IEEE_B) {
5059 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
5060 /* Invalid fixed rate mask */
5062 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5069 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5070 IEEE80211_OFDM_RATES_MASK)) {
5071 /* Invalid fixed rate mask */
5073 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5078 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
5079 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
5080 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
5083 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
5084 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
5085 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
5088 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
5089 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
5090 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
5093 fr.tx_rates |= mask;
5097 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
5098 ipw_write_reg32(priv, reg, *(u32 *) & fr);
5101 static void ipw_abort_scan(struct ipw_priv *priv)
5105 if (priv->status & STATUS_SCAN_ABORTING) {
5106 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5109 priv->status |= STATUS_SCAN_ABORTING;
5111 err = ipw_send_scan_abort(priv);
5113 IPW_DEBUG_HC("Request to abort scan failed.\n");
5116 static int ipw_request_scan(struct ipw_priv *priv)
5118 struct ipw_scan_request_ext scan;
5119 int channel_index = 0;
5120 int i, err, scan_type;
5122 if (priv->status & STATUS_EXIT_PENDING) {
5123 IPW_DEBUG_SCAN("Aborting scan due to device shutdown\n");
5124 priv->status |= STATUS_SCAN_PENDING;
5128 if (priv->status & STATUS_SCANNING) {
5129 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
5130 // IPW_DEBUG_HC("Concurrent scan requested. Aborting first.\n");
5131 priv->status |= STATUS_SCAN_PENDING;
5132 // ipw_abort_scan(priv);
5136 if (priv->status & STATUS_SCAN_ABORTING) {
5137 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
5138 priv->status |= STATUS_SCAN_PENDING;
5142 if (priv->status & STATUS_RF_KILL_MASK) {
5143 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
5144 priv->status |= STATUS_SCAN_PENDING;
5148 memset(&scan, 0, sizeof(scan));
5150 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = cpu_to_le16(20);
5151 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
5153 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20);
5155 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
5157 #ifdef CONFIG_IPW_MONITOR
5158 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5159 u8 band = 0, channel = priv->channel;
5161 if (is_valid_channel(IEEE_A, channel))
5162 band = (u8) (IPW_A_MODE << 6) | 1;
5164 if (is_valid_channel(IEEE_B | IEEE_G, channel))
5165 band = (u8) (IPW_B_MODE << 6) | 1;
5168 band = (u8) (IPW_B_MODE << 6) | 1;
5172 scan.channels_list[channel_index++] = band;
5173 scan.channels_list[channel_index] = channel;
5174 ipw_set_scan_type(&scan, channel_index,
5175 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
5177 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
5180 #endif /* CONFIG_IPW_MONITOR */
5181 /* If we are roaming, then make this a directed scan for the current
5182 * network. Otherwise, ensure that every other scan is a fast
5183 * channel hop scan */
5184 if ((priv->status & STATUS_ROAMING)
5185 || (!(priv->status & STATUS_ASSOCIATED)
5186 && (priv->config & CFG_STATIC_ESSID)
5187 && (le32_to_cpu(scan.full_scan_index) % 2))) {
5188 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
5191 ("Attempt to send SSID command failed.\n");
5195 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
5197 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
5200 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
5201 int start = channel_index;
5202 for (i = 0; i < MAX_A_CHANNELS; i++) {
5203 if (band_a_active_channel[i] == 0)
5205 if ((priv->status & STATUS_ASSOCIATED) &&
5206 band_a_active_channel[i] == priv->channel)
5209 scan.channels_list[channel_index] =
5210 band_a_active_channel[i];
5211 ipw_set_scan_type(&scan, channel_index,
5215 if (start != channel_index) {
5216 scan.channels_list[start] =
5217 (u8) (IPW_A_MODE << 6) | (channel_index -
5223 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
5224 int start = channel_index;
5225 for (i = 0; i < MAX_B_CHANNELS; i++) {
5226 if (band_b_active_channel[i] == 0)
5228 if ((priv->status & STATUS_ASSOCIATED) &&
5229 band_b_active_channel[i] == priv->channel)
5232 scan.channels_list[channel_index] =
5233 band_b_active_channel[i];
5234 ipw_set_scan_type(&scan, channel_index,
5238 if (start != channel_index) {
5239 scan.channels_list[start] =
5240 (u8) (IPW_B_MODE << 6) | (channel_index -
5244 #ifdef CONFIG_IPW_MONITOR
5248 err = ipw_send_scan_request_ext(priv, &scan);
5250 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
5254 priv->status |= STATUS_SCANNING;
5255 priv->status &= ~STATUS_SCAN_PENDING;
5260 /* Support for wpa_supplicant. Will be replaced with WEXT once
5261 * they get WPA support. */
5263 /* following definitions must match definitions in driver_ipw.c */
5265 #define IPW_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
5267 #define IPW_CMD_SET_WPA_PARAM 1
5268 #define IPW_CMD_SET_WPA_IE 2
5269 #define IPW_CMD_SET_ENCRYPTION 3
5270 #define IPW_CMD_MLME 4
5272 #define IPW_PARAM_WPA_ENABLED 1
5273 #define IPW_PARAM_TKIP_COUNTERMEASURES 2
5274 #define IPW_PARAM_DROP_UNENCRYPTED 3
5275 #define IPW_PARAM_PRIVACY_INVOKED 4
5276 #define IPW_PARAM_AUTH_ALGS 5
5277 #define IPW_PARAM_IEEE_802_1X 6
5279 #define IPW_MLME_STA_DEAUTH 1
5280 #define IPW_MLME_STA_DISASSOC 2
5282 #define IPW_CRYPT_ERR_UNKNOWN_ALG 2
5283 #define IPW_CRYPT_ERR_UNKNOWN_ADDR 3
5284 #define IPW_CRYPT_ERR_CRYPT_INIT_FAILED 4
5285 #define IPW_CRYPT_ERR_KEY_SET_FAILED 5
5286 #define IPW_CRYPT_ERR_TX_KEY_SET_FAILED 6
5287 #define IPW_CRYPT_ERR_CARD_CONF_FAILED 7
5289 #define IPW_CRYPT_ALG_NAME_LEN 16
5293 u8 sta_addr[ETH_ALEN];
5308 u8 alg[IPW_CRYPT_ALG_NAME_LEN];
5312 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
5320 /* end of driver_ipw.c code */
5322 static int ipw_wpa_enable(struct ipw_priv *priv, int value)
5324 struct ieee80211_device *ieee = priv->ieee;
5325 struct ieee80211_security sec = {
5326 .flags = SEC_LEVEL | SEC_ENABLED,
5330 ieee->wpa_enabled = value;
5333 sec.level = SEC_LEVEL_3;
5336 sec.level = SEC_LEVEL_0;
5338 ieee->wpa_ie_len = 0;
5341 if (ieee->set_security)
5342 ieee->set_security(ieee->dev, &sec);
5349 #define AUTH_ALG_OPEN_SYSTEM 0x1
5350 #define AUTH_ALG_SHARED_KEY 0x2
5352 static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
5354 struct ieee80211_device *ieee = priv->ieee;
5355 struct ieee80211_security sec = {
5356 .flags = SEC_AUTH_MODE,
5360 if (value & AUTH_ALG_SHARED_KEY) {
5361 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
5364 sec.auth_mode = WLAN_AUTH_OPEN;
5368 if (ieee->set_security)
5369 ieee->set_security(ieee->dev, &sec);
5376 static int ipw_wpa_set_param(struct net_device *dev, u8 name, u32 value)
5378 struct ipw_priv *priv = ieee80211_priv(dev);
5379 struct ieee80211_crypt_data *crypt;
5380 unsigned long flags;
5384 case IPW_PARAM_WPA_ENABLED:
5385 ret = ipw_wpa_enable(priv, value);
5388 case IPW_PARAM_TKIP_COUNTERMEASURES:
5389 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
5390 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) {
5391 IPW_WARNING("Can't set TKIP countermeasures: "
5392 "crypt not set!\n");
5396 flags = crypt->ops->get_flags(crypt->priv);
5399 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
5401 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
5403 crypt->ops->set_flags(flags, crypt->priv);
5407 case IPW_PARAM_DROP_UNENCRYPTED:
5408 priv->ieee->drop_unencrypted = value;
5411 case IPW_PARAM_PRIVACY_INVOKED:
5412 priv->ieee->privacy_invoked = value;
5415 case IPW_PARAM_AUTH_ALGS:
5416 ret = ipw_wpa_set_auth_algs(priv, value);
5419 case IPW_PARAM_IEEE_802_1X:
5420 priv->ieee->ieee802_1x = value;
5424 IPW_ERROR("%s: Unknown WPA param: %d\n", dev->name, name);
5431 static int ipw_wpa_mlme(struct net_device *dev, int command, int reason)
5433 struct ipw_priv *priv = ieee80211_priv(dev);
5437 case IPW_MLME_STA_DEAUTH:
5441 case IPW_MLME_STA_DISASSOC:
5442 ipw_disassociate(priv);
5446 IPW_ERROR("%s: Unknown MLME request: %d\n", dev->name, command);
5453 static int ipw_set_rsn_capa(struct ipw_priv *priv,
5454 char *capabilities, int length)
5456 struct host_cmd cmd = {
5457 .cmd = IPW_CMD_RSN_CAPABILITIES,
5461 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
5463 memcpy(&cmd.param, capabilities, length);
5464 if (ipw_send_cmd(priv, &cmd)) {
5465 IPW_ERROR("failed to send HOST_CMD_RSN_CAPABILITIES command\n");
5471 void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, int wpa_ie_len)
5473 /* make sure WPA is enabled */
5474 ipw_wpa_enable(priv, 1);
5476 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))
5477 ipw_disassociate(priv);
5480 static int ipw_wpa_set_wpa_ie(struct net_device *dev,
5481 struct ipw_param *param, int plen)
5483 struct ipw_priv *priv = ieee80211_priv(dev);
5484 struct ieee80211_device *ieee = priv->ieee;
5487 if (!ieee->wpa_enabled)
5490 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
5491 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
5494 if (param->u.wpa_ie.len) {
5495 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
5499 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
5500 kfree(ieee->wpa_ie);
5502 ieee->wpa_ie_len = param->u.wpa_ie.len;
5504 kfree(ieee->wpa_ie);
5505 ieee->wpa_ie = NULL;
5506 ieee->wpa_ie_len = 0;
5509 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
5513 /* implementation borrowed from hostap driver */
5515 static int ipw_wpa_set_encryption(struct net_device *dev,
5516 struct ipw_param *param, int param_len)
5519 struct ipw_priv *priv = ieee80211_priv(dev);
5520 struct ieee80211_device *ieee = priv->ieee;
5521 struct ieee80211_crypto_ops *ops;
5522 struct ieee80211_crypt_data **crypt;
5524 struct ieee80211_security sec = {
5528 param->u.crypt.err = 0;
5529 param->u.crypt.alg[IPW_CRYPT_ALG_NAME_LEN - 1] = '\0';
5532 (int)((char *)param->u.crypt.key - (char *)param) +
5533 param->u.crypt.key_len) {
5534 IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len,
5535 param->u.crypt.key_len);
5538 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
5539 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
5540 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
5541 if (param->u.crypt.idx >= WEP_KEYS)
5543 crypt = &ieee->crypt[param->u.crypt.idx];
5548 if (strcmp(param->u.crypt.alg, "none") == 0) {
5551 sec.level = SEC_LEVEL_0;
5552 sec.flags |= SEC_ENABLED | SEC_LEVEL;
5553 ieee80211_crypt_delayed_deinit(ieee, crypt);
5558 sec.flags |= SEC_ENABLED;
5560 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
5561 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
5562 request_module("ieee80211_crypt_wep");
5563 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
5564 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
5565 request_module("ieee80211_crypt_tkip");
5566 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
5567 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
5568 request_module("ieee80211_crypt_ccmp");
5569 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
5572 IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
5573 dev->name, param->u.crypt.alg);
5574 param->u.crypt.err = IPW_CRYPT_ERR_UNKNOWN_ALG;
5579 if (*crypt == NULL || (*crypt)->ops != ops) {
5580 struct ieee80211_crypt_data *new_crypt;
5582 ieee80211_crypt_delayed_deinit(ieee, crypt);
5584 new_crypt = (struct ieee80211_crypt_data *)
5585 kmalloc(sizeof(*new_crypt), GFP_KERNEL);
5586 if (new_crypt == NULL) {
5590 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
5591 new_crypt->ops = ops;
5592 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
5594 new_crypt->ops->init(param->u.crypt.idx);
5596 if (new_crypt->priv == NULL) {
5598 param->u.crypt.err = IPW_CRYPT_ERR_CRYPT_INIT_FAILED;
5606 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
5607 (*crypt)->ops->set_key(param->u.crypt.key,
5608 param->u.crypt.key_len, param->u.crypt.seq,
5609 (*crypt)->priv) < 0) {
5610 IPW_DEBUG_INFO("%s: key setting failed\n", dev->name);
5611 param->u.crypt.err = IPW_CRYPT_ERR_KEY_SET_FAILED;
5616 if (param->u.crypt.set_tx) {
5617 ieee->tx_keyidx = param->u.crypt.idx;
5618 sec.active_key = param->u.crypt.idx;
5619 sec.flags |= SEC_ACTIVE_KEY;
5622 if (ops->name != NULL) {
5623 if (strcmp(ops->name, "WEP") == 0) {
5624 memcpy(sec.keys[param->u.crypt.idx],
5625 param->u.crypt.key, param->u.crypt.key_len);
5626 sec.key_sizes[param->u.crypt.idx] =
5627 param->u.crypt.key_len;
5628 sec.flags |= (1 << param->u.crypt.idx);
5629 sec.flags |= SEC_LEVEL;
5630 sec.level = SEC_LEVEL_1;
5631 } else if (strcmp(ops->name, "TKIP") == 0) {
5632 sec.flags |= SEC_LEVEL;
5633 sec.level = SEC_LEVEL_2;
5634 } else if (strcmp(ops->name, "CCMP") == 0) {
5635 sec.flags |= SEC_LEVEL;
5636 sec.level = SEC_LEVEL_3;
5640 if (ieee->set_security)
5641 ieee->set_security(ieee->dev, &sec);
5643 /* Do not reset port if card is in Managed mode since resetting will
5644 * generate new IEEE 802.11 authentication which may end up in looping
5645 * with IEEE 802.1X. If your hardware requires a reset after WEP
5646 * configuration (for example... Prism2), implement the reset_port in
5647 * the callbacks structures used to initialize the 802.11 stack. */
5648 if (ieee->reset_on_keychange &&
5649 ieee->iw_mode != IW_MODE_INFRA &&
5650 ieee->reset_port && ieee->reset_port(dev)) {
5651 IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
5652 param->u.crypt.err = IPW_CRYPT_ERR_CARD_CONF_FAILED;
5659 static int ipw_wpa_supplicant(struct net_device *dev, struct iw_point *p)
5661 struct ipw_param *param;
5664 IPW_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
5666 if (p->length < sizeof(struct ipw_param) || !p->pointer)
5669 param = (struct ipw_param *)kmalloc(p->length, GFP_KERNEL);
5673 if (copy_from_user(param, p->pointer, p->length)) {
5678 switch (param->cmd) {
5680 case IPW_CMD_SET_WPA_PARAM:
5681 ret = ipw_wpa_set_param(dev, param->u.wpa_param.name,
5682 param->u.wpa_param.value);
5685 case IPW_CMD_SET_WPA_IE:
5686 ret = ipw_wpa_set_wpa_ie(dev, param, p->length);
5689 case IPW_CMD_SET_ENCRYPTION:
5690 ret = ipw_wpa_set_encryption(dev, param, p->length);
5694 ret = ipw_wpa_mlme(dev, param->u.mlme.command,
5695 param->u.mlme.reason_code);
5699 IPW_ERROR("%s: Unknown WPA supplicant request: %d\n",
5700 dev->name, param->cmd);
5704 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
5711 static int ipw_associate_network(struct ipw_priv *priv,
5712 struct ieee80211_network *network,
5713 struct ipw_supported_rates *rates, int roaming)
5717 if (priv->config & CFG_FIXED_RATE)
5718 ipw_set_fixed_rate(priv, network);
5720 if (!(priv->config & CFG_STATIC_ESSID)) {
5721 priv->essid_len = min(network->ssid_len,
5722 (u8) IW_ESSID_MAX_SIZE);
5723 memcpy(priv->essid, network->ssid, priv->essid_len);
5726 network->last_associate = jiffies;
5728 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
5729 priv->assoc_request.channel = network->channel;
5730 if ((priv->capability & CAP_PRIVACY_ON) &&
5731 (priv->capability & CAP_SHARED_KEY)) {
5732 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
5733 priv->assoc_request.auth_key = priv->sec.active_key;
5735 priv->assoc_request.auth_type = AUTH_OPEN;
5736 priv->assoc_request.auth_key = 0;
5739 if (priv->capability & CAP_PRIVACY_ON)
5740 ipw_send_wep_keys(priv);
5742 if (priv->ieee->wpa_ie_len) {
5743 priv->assoc_request.policy_support = 0x02; /* RSN active */
5744 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
5745 priv->ieee->wpa_ie_len);
5749 * It is valid for our ieee device to support multiple modes, but
5750 * when it comes to associating to a given network we have to choose
5753 if (network->mode & priv->ieee->mode & IEEE_A)
5754 priv->assoc_request.ieee_mode = IPW_A_MODE;
5755 else if (network->mode & priv->ieee->mode & IEEE_G)
5756 priv->assoc_request.ieee_mode = IPW_G_MODE;
5757 else if (network->mode & priv->ieee->mode & IEEE_B)
5758 priv->assoc_request.ieee_mode = IPW_B_MODE;
5760 priv->assoc_request.capability = network->capability;
5761 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
5762 && !(priv->config & CFG_PREAMBLE_LONG)) {
5763 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
5765 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
5767 /* Clear the short preamble if we won't be supporting it */
5768 priv->assoc_request.capability &=
5769 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
5772 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
5773 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
5774 roaming ? "Rea" : "A",
5775 escape_essid(priv->essid, priv->essid_len),
5777 ipw_modes[priv->assoc_request.ieee_mode],
5779 (priv->assoc_request.preamble_length ==
5780 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
5781 network->capability &
5782 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
5783 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
5784 priv->capability & CAP_PRIVACY_ON ?
5785 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
5787 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
5788 priv->capability & CAP_PRIVACY_ON ?
5789 '1' + priv->sec.active_key : '.',
5790 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
5792 priv->assoc_request.beacon_interval = network->beacon_interval;
5793 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
5794 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
5795 priv->assoc_request.assoc_type = HC_IBSS_START;
5796 priv->assoc_request.assoc_tsf_msw = 0;
5797 priv->assoc_request.assoc_tsf_lsw = 0;
5799 if (unlikely(roaming))
5800 priv->assoc_request.assoc_type = HC_REASSOCIATE;
5802 priv->assoc_request.assoc_type = HC_ASSOCIATE;
5803 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
5804 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
5807 memcpy(&priv->assoc_request.bssid, network->bssid, ETH_ALEN);
5809 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5810 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
5811 priv->assoc_request.atim_window = network->atim_window;
5813 memcpy(&priv->assoc_request.dest, network->bssid, ETH_ALEN);
5814 priv->assoc_request.atim_window = 0;
5817 priv->assoc_request.listen_interval = network->listen_interval;
5819 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
5821 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
5825 rates->ieee_mode = priv->assoc_request.ieee_mode;
5826 rates->purpose = IPW_RATE_CONNECT;
5827 ipw_send_supported_rates(priv, rates);
5829 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
5830 priv->sys_config.dot11g_auto_detection = 1;
5832 priv->sys_config.dot11g_auto_detection = 0;
5833 err = ipw_send_system_config(priv, &priv->sys_config);
5835 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
5839 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
5840 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
5842 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
5847 * If preemption is enabled, it is possible for the association
5848 * to complete before we return from ipw_send_associate. Therefore
5849 * we have to be sure and update our priviate data first.
5851 priv->channel = network->channel;
5852 memcpy(priv->bssid, network->bssid, ETH_ALEN);
5853 priv->status |= STATUS_ASSOCIATING;
5854 priv->status &= ~STATUS_SECURITY_UPDATED;
5856 priv->assoc_network = network;
5858 err = ipw_send_associate(priv, &priv->assoc_request);
5860 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
5864 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
5865 escape_essid(priv->essid, priv->essid_len),
5866 MAC_ARG(priv->bssid));
5871 static void ipw_roam(void *data)
5873 struct ipw_priv *priv = data;
5874 struct ieee80211_network *network = NULL;
5875 struct ipw_network_match match = {
5876 .network = priv->assoc_network
5879 /* The roaming process is as follows:
5881 * 1. Missed beacon threshold triggers the roaming process by
5882 * setting the status ROAM bit and requesting a scan.
5883 * 2. When the scan completes, it schedules the ROAM work
5884 * 3. The ROAM work looks at all of the known networks for one that
5885 * is a better network than the currently associated. If none
5886 * found, the ROAM process is over (ROAM bit cleared)
5887 * 4. If a better network is found, a disassociation request is
5889 * 5. When the disassociation completes, the roam work is again
5890 * scheduled. The second time through, the driver is no longer
5891 * associated, and the newly selected network is sent an
5892 * association request.
5893 * 6. At this point ,the roaming process is complete and the ROAM
5894 * status bit is cleared.
5897 /* If we are no longer associated, and the roaming bit is no longer
5898 * set, then we are not actively roaming, so just return */
5899 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
5902 if (priv->status & STATUS_ASSOCIATED) {
5903 /* First pass through ROAM process -- look for a better
5905 unsigned long flags;
5906 u8 rssi = priv->assoc_network->stats.rssi;
5907 priv->assoc_network->stats.rssi = -128;
5908 spin_lock_irqsave(&priv->ieee->lock, flags);
5909 list_for_each_entry(network, &priv->ieee->network_list, list) {
5910 if (network != priv->assoc_network)
5911 ipw_best_network(priv, &match, network, 1);
5913 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5914 priv->assoc_network->stats.rssi = rssi;
5916 if (match.network == priv->assoc_network) {
5917 IPW_DEBUG_ASSOC("No better APs in this network to "
5919 priv->status &= ~STATUS_ROAMING;
5920 ipw_debug_config(priv);
5924 ipw_send_disassociate(priv, 1);
5925 priv->assoc_network = match.network;
5930 /* Second pass through ROAM process -- request association */
5931 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
5932 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
5933 priv->status &= ~STATUS_ROAMING;
5936 static void ipw_associate(void *data)
5938 struct ipw_priv *priv = data;
5940 struct ieee80211_network *network = NULL;
5941 struct ipw_network_match match = {
5944 struct ipw_supported_rates *rates;
5945 struct list_head *element;
5946 unsigned long flags;
5948 if (!(priv->config & CFG_ASSOCIATE) &&
5949 !(priv->config & (CFG_STATIC_ESSID |
5950 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
5951 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
5955 /* Protect our use of the network_list */
5956 spin_lock_irqsave(&priv->ieee->lock, flags);
5957 list_for_each_entry(network, &priv->ieee->network_list, list)
5958 ipw_best_network(priv, &match, network, 0);
5960 network = match.network;
5961 rates = &match.rates;
5963 if (network == NULL &&
5964 priv->ieee->iw_mode == IW_MODE_ADHOC &&
5965 priv->config & CFG_ADHOC_CREATE &&
5966 priv->config & CFG_STATIC_ESSID &&
5967 priv->config & CFG_STATIC_CHANNEL &&
5968 !list_empty(&priv->ieee->network_free_list)) {
5969 element = priv->ieee->network_free_list.next;
5970 network = list_entry(element, struct ieee80211_network, list);
5971 ipw_adhoc_create(priv, network);
5972 rates = &priv->rates;
5974 list_add_tail(&network->list, &priv->ieee->network_list);
5976 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5978 /* If we reached the end of the list, then we don't have any valid
5981 ipw_debug_config(priv);
5983 if (!(priv->status & STATUS_SCANNING))
5984 queue_delayed_work(priv->workqueue, &priv->request_scan,
5990 ipw_associate_network(priv, network, rates, 0);
5993 static inline void ipw_handle_data_packet(struct ipw_priv *priv,
5994 struct ipw_rx_mem_buffer *rxb,
5995 struct ieee80211_rx_stats *stats)
5997 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
5999 /* We received data from the HW, so stop the watchdog */
6000 priv->net_dev->trans_start = jiffies;
6002 /* We only process data packets if the
6003 * interface is open */
6004 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
6005 skb_tailroom(rxb->skb))) {
6006 priv->ieee->stats.rx_errors++;
6007 priv->wstats.discard.misc++;
6008 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
6010 } else if (unlikely(!netif_running(priv->net_dev))) {
6011 priv->ieee->stats.rx_dropped++;
6012 priv->wstats.discard.misc++;
6013 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
6017 /* Advance skb->data to the start of the actual payload */
6018 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
6020 /* Set the size of the skb to the size of the frame */
6021 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
6023 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
6025 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
6026 priv->ieee->stats.rx_errors++;
6027 else { /* ieee80211_rx succeeded, so it now owns the SKB */
6029 ipw_led_activity_on(priv);
6033 static inline int is_network_packet(struct ipw_priv *priv,
6034 struct ieee80211_hdr_4addr *header)
6036 /* Filter incoming packets to determine if they are targetted toward
6037 * this network, discarding packets coming from ourselves */
6038 switch (priv->ieee->iw_mode) {
6039 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
6040 /* {broad,multi}cast packets to our IBSS go through */
6041 if (is_broadcast_ether_addr(header->addr1) ||
6042 is_multicast_ether_addr(header->addr1))
6043 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
6045 /* packets to our adapter go through */
6046 return !memcmp(header->addr1, priv->net_dev->dev_addr,
6050 case IW_MODE_INFRA: /* Header: Dest. | AP{BSSID} | Source */
6051 /* {broad,multi}cast packets to our IBSS go through */
6052 if (is_broadcast_ether_addr(header->addr1) ||
6053 is_multicast_ether_addr(header->addr1))
6054 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
6056 /* packets to our adapter go through */
6057 return !memcmp(header->addr1, priv->net_dev->dev_addr,
6066 * Main entry function for recieving a packet with 80211 headers. This
6067 * should be called when ever the FW has notified us that there is a new
6068 * skb in the recieve queue.
6070 static void ipw_rx(struct ipw_priv *priv)
6072 struct ipw_rx_mem_buffer *rxb;
6073 struct ipw_rx_packet *pkt;
6074 struct ieee80211_hdr_4addr *header;
6078 r = ipw_read32(priv, CX2_RX_READ_INDEX);
6079 w = ipw_read32(priv, CX2_RX_WRITE_INDEX);
6080 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
6083 rxb = priv->rxq->queue[i];
6084 #ifdef CONFIG_IPW_DEBUG
6085 if (unlikely(rxb == NULL)) {
6086 printk(KERN_CRIT "Queue not allocated!\n");
6090 priv->rxq->queue[i] = NULL;
6092 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
6094 PCI_DMA_FROMDEVICE);
6096 pkt = (struct ipw_rx_packet *)rxb->skb->data;
6097 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
6098 pkt->header.message_type,
6099 pkt->header.rx_seq_num, pkt->header.control_bits);
6101 switch (pkt->header.message_type) {
6102 case RX_FRAME_TYPE: /* 802.11 frame */ {
6103 struct ieee80211_rx_stats stats = {
6104 .rssi = pkt->u.frame.rssi_dbm -
6106 /* .signal = le16_to_cpu(pkt->u.frame.signal), */
6107 .rate = pkt->u.frame.rate,
6108 .mac_time = jiffies,
6110 pkt->u.frame.received_channel,
6113 control & (1 << 0)) ?
6114 IEEE80211_24GHZ_BAND :
6115 IEEE80211_52GHZ_BAND,
6116 .len = le16_to_cpu(pkt->u.frame.length),
6119 if (stats.rssi != 0)
6120 stats.mask |= IEEE80211_STATMASK_RSSI;
6121 if (stats.signal != 0)
6122 stats.mask |= IEEE80211_STATMASK_SIGNAL;
6123 if (stats.rate != 0)
6124 stats.mask |= IEEE80211_STATMASK_RATE;
6128 #ifdef CONFIG_IPW_MONITOR
6129 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
6130 ipw_handle_data_packet(priv, rxb,
6137 (struct ieee80211_hdr_4addr *)(rxb->skb->
6140 /* TODO: Check Ad-Hoc dest/source and make sure
6141 * that we are actually parsing these packets
6142 * correctly -- we should probably use the
6143 * frame control of the packet and disregard
6144 * the current iw_mode */
6147 is_network_packet(priv, header);
6148 if (network_packet && priv->assoc_network) {
6149 priv->assoc_network->stats.rssi =
6151 average_add(&priv->average_rssi,
6153 priv->last_rx_rssi = stats.rssi;
6156 IPW_DEBUG_RX("Frame: len=%u\n",
6157 le16_to_cpu(pkt->u.frame.length));
6159 if (le16_to_cpu(pkt->u.frame.length) <
6160 frame_hdr_len(header)) {
6162 ("Received packet is too small. "
6164 priv->ieee->stats.rx_errors++;
6165 priv->wstats.discard.misc++;
6169 switch (WLAN_FC_GET_TYPE
6170 (le16_to_cpu(header->frame_ctl))) {
6171 case IEEE80211_FTYPE_MGMT:
6172 ieee80211_rx_mgt(priv->ieee, header,
6174 if (priv->ieee->iw_mode == IW_MODE_ADHOC
6177 (le16_to_cpu(header->frame_ctl))
6178 == IEEE80211_STYPE_PROBE_RESP)
6181 (le16_to_cpu(header->frame_ctl))
6182 == IEEE80211_STYPE_BEACON))
6183 && !memcmp(header->addr3,
6184 priv->bssid, ETH_ALEN))
6185 ipw_add_station(priv,
6189 case IEEE80211_FTYPE_CTL:
6192 case IEEE80211_FTYPE_DATA:
6194 ipw_handle_data_packet(priv,
6198 IPW_DEBUG_DROP("Dropping: "
6213 case RX_HOST_NOTIFICATION_TYPE:{
6215 ("Notification: subtype=%02X flags=%02X size=%d\n",
6216 pkt->u.notification.subtype,
6217 pkt->u.notification.flags,
6218 pkt->u.notification.size);
6219 ipw_rx_notification(priv, &pkt->u.notification);
6224 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
6225 pkt->header.message_type);
6229 /* For now we just don't re-use anything. We can tweak this
6230 * later to try and re-use notification packets and SKBs that
6231 * fail to Rx correctly */
6232 if (rxb->skb != NULL) {
6233 dev_kfree_skb_any(rxb->skb);
6237 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
6238 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
6239 list_add_tail(&rxb->list, &priv->rxq->rx_used);
6241 i = (i + 1) % RX_QUEUE_SIZE;
6244 /* Backtrack one entry */
6245 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
6247 ipw_rx_queue_restock(priv);
6251 * This file defines the Wireless Extension handlers. It does not
6252 * define any methods of hardware manipulation and relies on the
6253 * functions defined in ipw_main to provide the HW interaction.
6255 * The exception to this is the use of the ipw_get_ordinal()
6256 * function used to poll the hardware vs. making unecessary calls.
6260 static int ipw_wx_get_name(struct net_device *dev,
6261 struct iw_request_info *info,
6262 union iwreq_data *wrqu, char *extra)
6264 struct ipw_priv *priv = ieee80211_priv(dev);
6265 if (priv->status & STATUS_RF_KILL_MASK) {
6266 strcpy(wrqu->name, "radio off");
6267 } else if (!(priv->status & STATUS_ASSOCIATED))
6268 strcpy(wrqu->name, "unassociated");
6270 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
6271 ipw_modes[priv->assoc_request.ieee_mode]);
6272 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
6276 static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
6279 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
6280 priv->config &= ~CFG_STATIC_CHANNEL;
6281 if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED |
6282 STATUS_ASSOCIATING))) {
6283 IPW_DEBUG_ASSOC("Attempting to associate with new "
6285 ipw_associate(priv);
6291 priv->config |= CFG_STATIC_CHANNEL;
6293 if (priv->channel == channel) {
6294 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
6299 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
6300 priv->channel = channel;
6302 /* If we are currently associated, or trying to associate
6303 * then see if this is a new channel (causing us to disassociate) */
6304 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
6305 IPW_DEBUG_ASSOC("Disassociating due to channel change.\n");
6306 ipw_disassociate(priv);
6307 } else if (!(priv->status & (STATUS_SCANNING)))
6308 ipw_associate(priv);
6313 static int ipw_wx_set_freq(struct net_device *dev,
6314 struct iw_request_info *info,
6315 union iwreq_data *wrqu, char *extra)
6317 struct ipw_priv *priv = ieee80211_priv(dev);
6318 struct iw_freq *fwrq = &wrqu->freq;
6320 /* if setting by freq convert to channel */
6322 if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) {
6323 int f = fwrq->m / 100000;
6326 while ((c < REG_MAX_CHANNEL) &&
6327 (f != ipw_frequencies[c]))
6330 /* hack to fall through */
6336 if (fwrq->e > 0 || fwrq->m > 1000)
6339 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
6340 return ipw_set_channel(priv, (u8) fwrq->m);
6343 static int ipw_wx_get_freq(struct net_device *dev,
6344 struct iw_request_info *info,
6345 union iwreq_data *wrqu, char *extra)
6347 struct ipw_priv *priv = ieee80211_priv(dev);
6351 /* If we are associated, trying to associate, or have a statically
6352 * configured CHANNEL then return that; otherwise return ANY */
6353 if (priv->config & CFG_STATIC_CHANNEL ||
6354 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
6355 wrqu->freq.m = priv->channel;
6359 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
6363 static int ipw_wx_set_mode(struct net_device *dev,
6364 struct iw_request_info *info,
6365 union iwreq_data *wrqu, char *extra)
6367 struct ipw_priv *priv = ieee80211_priv(dev);
6370 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
6372 if (wrqu->mode == priv->ieee->iw_mode)
6375 switch (wrqu->mode) {
6376 #ifdef CONFIG_IPW_MONITOR
6377 case IW_MODE_MONITOR:
6383 wrqu->mode = IW_MODE_INFRA;
6389 #ifdef CONFIG_IPW_MONITOR
6390 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
6391 priv->net_dev->type = ARPHRD_ETHER;
6393 if (wrqu->mode == IW_MODE_MONITOR)
6394 priv->net_dev->type = ARPHRD_IEEE80211;
6395 #endif /* CONFIG_IPW_MONITOR */
6398 /* Free the existing firmware and reset the fw_loaded
6399 * flag so ipw_load() will bring in the new firmawre */
6403 release_firmware(bootfw);
6404 release_firmware(ucode);
6405 release_firmware(firmware);
6406 bootfw = ucode = firmware = NULL;
6409 priv->ieee->iw_mode = wrqu->mode;
6410 queue_work(priv->workqueue, &priv->adapter_restart);
6415 static int ipw_wx_get_mode(struct net_device *dev,
6416 struct iw_request_info *info,
6417 union iwreq_data *wrqu, char *extra)
6419 struct ipw_priv *priv = ieee80211_priv(dev);
6421 wrqu->mode = priv->ieee->iw_mode;
6422 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
6427 #define DEFAULT_RTS_THRESHOLD 2304U
6428 #define MIN_RTS_THRESHOLD 1U
6429 #define MAX_RTS_THRESHOLD 2304U
6430 #define DEFAULT_BEACON_INTERVAL 100U
6431 #define DEFAULT_SHORT_RETRY_LIMIT 7U
6432 #define DEFAULT_LONG_RETRY_LIMIT 4U
6434 /* Values are in microsecond */
6435 static const s32 timeout_duration[] = {
6443 static const s32 period_duration[] = {
6451 static int ipw_wx_get_range(struct net_device *dev,
6452 struct iw_request_info *info,
6453 union iwreq_data *wrqu, char *extra)
6455 struct ipw_priv *priv = ieee80211_priv(dev);
6456 struct iw_range *range = (struct iw_range *)extra;
6460 wrqu->data.length = sizeof(*range);
6461 memset(range, 0, sizeof(*range));
6463 /* 54Mbs == ~27 Mb/s real (802.11g) */
6464 range->throughput = 27 * 1000 * 1000;
6466 range->max_qual.qual = 100;
6467 /* TODO: Find real max RSSI and stick here */
6468 range->max_qual.level = 0;
6469 range->max_qual.noise = 0;
6470 range->max_qual.updated = 7; /* Updated all three */
6472 range->avg_qual.qual = 70;
6473 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
6474 range->avg_qual.level = 0; /* FIXME to real average level */
6475 range->avg_qual.noise = 0;
6476 range->avg_qual.updated = 7; /* Updated all three */
6478 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
6480 for (i = 0; i < range->num_bitrates; i++)
6481 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
6484 range->max_rts = DEFAULT_RTS_THRESHOLD;
6485 range->min_frag = MIN_FRAG_THRESHOLD;
6486 range->max_frag = MAX_FRAG_THRESHOLD;
6488 range->encoding_size[0] = 5;
6489 range->encoding_size[1] = 13;
6490 range->num_encoding_sizes = 2;
6491 range->max_encoding_tokens = WEP_KEYS;
6493 /* Set the Wireless Extension versions */
6494 range->we_version_compiled = WIRELESS_EXT;
6495 range->we_version_source = 16;
6497 range->num_channels = FREQ_COUNT;
6500 for (i = 0; i < FREQ_COUNT; i++) {
6501 range->freq[val].i = i + 1;
6502 range->freq[val].m = ipw_frequencies[i] * 100000;
6503 range->freq[val].e = 1;
6506 if (val == IW_MAX_FREQUENCIES)
6509 range->num_frequency = val;
6511 IPW_DEBUG_WX("GET Range\n");
6515 static int ipw_wx_set_wap(struct net_device *dev,
6516 struct iw_request_info *info,
6517 union iwreq_data *wrqu, char *extra)
6519 struct ipw_priv *priv = ieee80211_priv(dev);
6521 static const unsigned char any[] = {
6522 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
6524 static const unsigned char off[] = {
6525 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
6528 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
6531 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
6532 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
6533 /* we disable mandatory BSSID association */
6534 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
6535 priv->config &= ~CFG_STATIC_BSSID;
6536 if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED |
6537 STATUS_ASSOCIATING))) {
6538 IPW_DEBUG_ASSOC("Attempting to associate with new "
6540 ipw_associate(priv);
6546 priv->config |= CFG_STATIC_BSSID;
6547 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
6548 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
6552 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
6553 MAC_ARG(wrqu->ap_addr.sa_data));
6555 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
6557 /* If we are currently associated, or trying to associate
6558 * then see if this is a new BSSID (causing us to disassociate) */
6559 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
6560 IPW_DEBUG_ASSOC("Disassociating due to BSSID change.\n");
6561 ipw_disassociate(priv);
6562 } else if (!(priv->status & (STATUS_SCANNING)))
6563 ipw_associate(priv);
6568 static int ipw_wx_get_wap(struct net_device *dev,
6569 struct iw_request_info *info,
6570 union iwreq_data *wrqu, char *extra)
6572 struct ipw_priv *priv = ieee80211_priv(dev);
6573 /* If we are associated, trying to associate, or have a statically
6574 * configured BSSID then return that; otherwise return ANY */
6575 if (priv->config & CFG_STATIC_BSSID ||
6576 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
6577 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
6578 memcpy(wrqu->ap_addr.sa_data, &priv->bssid, ETH_ALEN);
6580 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
6582 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
6583 MAC_ARG(wrqu->ap_addr.sa_data));
6587 static int ipw_wx_set_essid(struct net_device *dev,
6588 struct iw_request_info *info,
6589 union iwreq_data *wrqu, char *extra)
6591 struct ipw_priv *priv = ieee80211_priv(dev);
6592 char *essid = ""; /* ANY */
6595 if (wrqu->essid.flags && wrqu->essid.length) {
6596 length = wrqu->essid.length - 1;
6600 IPW_DEBUG_WX("Setting ESSID to ANY\n");
6601 priv->config &= ~CFG_STATIC_ESSID;
6602 if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED |
6603 STATUS_ASSOCIATING))) {
6604 IPW_DEBUG_ASSOC("Attempting to associate with new "
6606 ipw_associate(priv);
6612 length = min(length, IW_ESSID_MAX_SIZE);
6614 priv->config |= CFG_STATIC_ESSID;
6616 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
6617 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
6621 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
6624 priv->essid_len = length;
6625 memcpy(priv->essid, essid, priv->essid_len);
6627 /* If we are currently associated, or trying to associate
6628 * then see if this is a new ESSID (causing us to disassociate) */
6629 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
6630 IPW_DEBUG_ASSOC("Disassociating due to ESSID change.\n");
6631 ipw_disassociate(priv);
6632 } else if (!(priv->status & (STATUS_SCANNING)))
6633 ipw_associate(priv);
6638 static int ipw_wx_get_essid(struct net_device *dev,
6639 struct iw_request_info *info,
6640 union iwreq_data *wrqu, char *extra)
6642 struct ipw_priv *priv = ieee80211_priv(dev);
6644 /* If we are associated, trying to associate, or have a statically
6645 * configured ESSID then return that; otherwise return ANY */
6646 if (priv->config & CFG_STATIC_ESSID ||
6647 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
6648 IPW_DEBUG_WX("Getting essid: '%s'\n",
6649 escape_essid(priv->essid, priv->essid_len));
6650 memcpy(extra, priv->essid, priv->essid_len);
6651 wrqu->essid.length = priv->essid_len;
6652 wrqu->essid.flags = 1; /* active */
6654 IPW_DEBUG_WX("Getting essid: ANY\n");
6655 wrqu->essid.length = 0;
6656 wrqu->essid.flags = 0; /* active */
6662 static int ipw_wx_set_nick(struct net_device *dev,
6663 struct iw_request_info *info,
6664 union iwreq_data *wrqu, char *extra)
6666 struct ipw_priv *priv = ieee80211_priv(dev);
6668 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
6669 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
6672 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
6673 memset(priv->nick, 0, sizeof(priv->nick));
6674 memcpy(priv->nick, extra, wrqu->data.length);
6675 IPW_DEBUG_TRACE("<<\n");
6680 static int ipw_wx_get_nick(struct net_device *dev,
6681 struct iw_request_info *info,
6682 union iwreq_data *wrqu, char *extra)
6684 struct ipw_priv *priv = ieee80211_priv(dev);
6685 IPW_DEBUG_WX("Getting nick\n");
6686 wrqu->data.length = strlen(priv->nick) + 1;
6687 memcpy(extra, priv->nick, wrqu->data.length);
6688 wrqu->data.flags = 1; /* active */
6692 static int ipw_wx_set_rate(struct net_device *dev,
6693 struct iw_request_info *info,
6694 union iwreq_data *wrqu, char *extra)
6696 /* TODO: We should use semaphores or locks for access to priv */
6697 struct ipw_priv *priv = ieee80211_priv(dev);
6698 u32 target_rate = wrqu->bitrate.value;
6701 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
6702 /* value = X, fixed = 1 means only rate X */
6703 /* value = X, fixed = 0 means all rates lower equal X */
6705 if (target_rate == -1) {
6707 mask = IEEE80211_DEFAULT_RATES_MASK;
6708 /* Now we should reassociate */
6713 fixed = wrqu->bitrate.fixed;
6715 if (target_rate == 1000000 || !fixed)
6716 mask |= IEEE80211_CCK_RATE_1MB_MASK;
6717 if (target_rate == 1000000)
6720 if (target_rate == 2000000 || !fixed)
6721 mask |= IEEE80211_CCK_RATE_2MB_MASK;
6722 if (target_rate == 2000000)
6725 if (target_rate == 5500000 || !fixed)
6726 mask |= IEEE80211_CCK_RATE_5MB_MASK;
6727 if (target_rate == 5500000)
6730 if (target_rate == 6000000 || !fixed)
6731 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
6732 if (target_rate == 6000000)
6735 if (target_rate == 9000000 || !fixed)
6736 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
6737 if (target_rate == 9000000)
6740 if (target_rate == 11000000 || !fixed)
6741 mask |= IEEE80211_CCK_RATE_11MB_MASK;
6742 if (target_rate == 11000000)
6745 if (target_rate == 12000000 || !fixed)
6746 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
6747 if (target_rate == 12000000)
6750 if (target_rate == 18000000 || !fixed)
6751 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
6752 if (target_rate == 18000000)
6755 if (target_rate == 24000000 || !fixed)
6756 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
6757 if (target_rate == 24000000)
6760 if (target_rate == 36000000 || !fixed)
6761 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
6762 if (target_rate == 36000000)
6765 if (target_rate == 48000000 || !fixed)
6766 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
6767 if (target_rate == 48000000)
6770 if (target_rate == 54000000 || !fixed)
6771 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
6772 if (target_rate == 54000000)
6775 IPW_DEBUG_WX("invalid rate specified, returning error\n");
6779 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
6780 mask, fixed ? "fixed" : "sub-rates");
6782 if (mask == IEEE80211_DEFAULT_RATES_MASK)
6783 priv->config &= ~CFG_FIXED_RATE;
6785 priv->config |= CFG_FIXED_RATE;
6787 if (priv->rates_mask != mask) {
6788 priv->rates_mask = mask;
6789 /* If we are already associated or are currently trying to
6790 * associate, disassociate and try again */
6791 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
6792 IPW_DEBUG_ASSOC("Disassociating due to RATE change.\n");
6793 ipw_disassociate(priv);
6794 } else if (!(priv->status & (STATUS_SCANNING))) {
6795 /* We are not yet associated, so kick one off... */
6796 ipw_associate(priv);
6803 static int ipw_wx_get_rate(struct net_device *dev,
6804 struct iw_request_info *info,
6805 union iwreq_data *wrqu, char *extra)
6807 struct ipw_priv *priv = ieee80211_priv(dev);
6808 wrqu->bitrate.value = priv->last_rate;
6810 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
6814 static int ipw_wx_set_rts(struct net_device *dev,
6815 struct iw_request_info *info,
6816 union iwreq_data *wrqu, char *extra)
6818 struct ipw_priv *priv = ieee80211_priv(dev);
6820 if (wrqu->rts.disabled)
6821 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
6823 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
6824 wrqu->rts.value > MAX_RTS_THRESHOLD)
6827 priv->rts_threshold = wrqu->rts.value;
6830 ipw_send_rts_threshold(priv, priv->rts_threshold);
6831 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
6835 static int ipw_wx_get_rts(struct net_device *dev,
6836 struct iw_request_info *info,
6837 union iwreq_data *wrqu, char *extra)
6839 struct ipw_priv *priv = ieee80211_priv(dev);
6840 wrqu->rts.value = priv->rts_threshold;
6841 wrqu->rts.fixed = 0; /* no auto select */
6842 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
6844 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
6848 static int ipw_wx_set_txpow(struct net_device *dev,
6849 struct iw_request_info *info,
6850 union iwreq_data *wrqu, char *extra)
6852 struct ipw_priv *priv = ieee80211_priv(dev);
6853 struct ipw_tx_power tx_power;
6856 if (ipw_radio_kill_sw(priv, wrqu->power.disabled))
6857 return -EINPROGRESS;
6859 if (wrqu->power.flags != IW_TXPOW_DBM)
6862 if ((wrqu->power.value > 20) || (wrqu->power.value < -12))
6865 priv->tx_power = wrqu->power.value;
6867 memset(&tx_power, 0, sizeof(tx_power));
6869 /* configure device for 'G' band */
6870 tx_power.ieee_mode = IPW_G_MODE;
6871 tx_power.num_channels = 11;
6872 for (i = 0; i < 11; i++) {
6873 tx_power.channels_tx_power[i].channel_number = i + 1;
6874 tx_power.channels_tx_power[i].tx_power = priv->tx_power;
6876 if (ipw_send_tx_power(priv, &tx_power))
6879 /* configure device to also handle 'B' band */
6880 tx_power.ieee_mode = IPW_B_MODE;
6881 if (ipw_send_tx_power(priv, &tx_power))
6890 static int ipw_wx_get_txpow(struct net_device *dev,
6891 struct iw_request_info *info,
6892 union iwreq_data *wrqu, char *extra)
6894 struct ipw_priv *priv = ieee80211_priv(dev);
6896 wrqu->power.value = priv->tx_power;
6897 wrqu->power.fixed = 1;
6898 wrqu->power.flags = IW_TXPOW_DBM;
6899 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
6901 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
6902 wrqu->power.disabled ? "ON" : "OFF", wrqu->power.value);
6907 static int ipw_wx_set_frag(struct net_device *dev,
6908 struct iw_request_info *info,
6909 union iwreq_data *wrqu, char *extra)
6911 struct ipw_priv *priv = ieee80211_priv(dev);
6913 if (wrqu->frag.disabled)
6914 priv->ieee->fts = DEFAULT_FTS;
6916 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
6917 wrqu->frag.value > MAX_FRAG_THRESHOLD)
6920 priv->ieee->fts = wrqu->frag.value & ~0x1;
6923 ipw_send_frag_threshold(priv, wrqu->frag.value);
6924 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
6928 static int ipw_wx_get_frag(struct net_device *dev,
6929 struct iw_request_info *info,
6930 union iwreq_data *wrqu, char *extra)
6932 struct ipw_priv *priv = ieee80211_priv(dev);
6933 wrqu->frag.value = priv->ieee->fts;
6934 wrqu->frag.fixed = 0; /* no auto select */
6935 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
6937 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
6942 static int ipw_wx_set_retry(struct net_device *dev,
6943 struct iw_request_info *info,
6944 union iwreq_data *wrqu, char *extra)
6946 IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu);
6950 static int ipw_wx_get_retry(struct net_device *dev,
6951 struct iw_request_info *info,
6952 union iwreq_data *wrqu, char *extra)
6954 IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu);
6958 static int ipw_wx_set_scan(struct net_device *dev,
6959 struct iw_request_info *info,
6960 union iwreq_data *wrqu, char *extra)
6962 struct ipw_priv *priv = ieee80211_priv(dev);
6963 IPW_DEBUG_WX("Start scan\n");
6964 if (ipw_request_scan(priv))
6969 static int ipw_wx_get_scan(struct net_device *dev,
6970 struct iw_request_info *info,
6971 union iwreq_data *wrqu, char *extra)
6973 struct ipw_priv *priv = ieee80211_priv(dev);
6974 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
6977 static int ipw_wx_set_encode(struct net_device *dev,
6978 struct iw_request_info *info,
6979 union iwreq_data *wrqu, char *key)
6981 struct ipw_priv *priv = ieee80211_priv(dev);
6982 return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
6985 static int ipw_wx_get_encode(struct net_device *dev,
6986 struct iw_request_info *info,
6987 union iwreq_data *wrqu, char *key)
6989 struct ipw_priv *priv = ieee80211_priv(dev);
6990 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
6993 static int ipw_wx_set_power(struct net_device *dev,
6994 struct iw_request_info *info,
6995 union iwreq_data *wrqu, char *extra)
6997 struct ipw_priv *priv = ieee80211_priv(dev);
7000 if (wrqu->power.disabled) {
7001 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
7002 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
7004 IPW_DEBUG_WX("failed setting power mode.\n");
7007 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7012 switch (wrqu->power.flags & IW_POWER_MODE) {
7013 case IW_POWER_ON: /* If not specified */
7014 case IW_POWER_MODE: /* If set all mask */
7015 case IW_POWER_ALL_R: /* If explicitely state all */
7017 default: /* Otherwise we don't support it */
7018 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7023 /* If the user hasn't specified a power management mode yet, default
7025 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
7026 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
7028 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
7029 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
7031 IPW_DEBUG_WX("failed setting power mode.\n");
7035 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
7040 static int ipw_wx_get_power(struct net_device *dev,
7041 struct iw_request_info *info,
7042 union iwreq_data *wrqu, char *extra)
7044 struct ipw_priv *priv = ieee80211_priv(dev);
7046 if (!(priv->power_mode & IPW_POWER_ENABLED))
7047 wrqu->power.disabled = 1;
7049 wrqu->power.disabled = 0;
7051 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
7056 static int ipw_wx_set_powermode(struct net_device *dev,
7057 struct iw_request_info *info,
7058 union iwreq_data *wrqu, char *extra)
7060 struct ipw_priv *priv = ieee80211_priv(dev);
7061 int mode = *(int *)extra;
7064 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
7065 mode = IPW_POWER_AC;
7066 priv->power_mode = mode;
7068 priv->power_mode = IPW_POWER_ENABLED | mode;
7071 if (priv->power_mode != mode) {
7072 err = ipw_send_power_mode(priv, mode);
7075 IPW_DEBUG_WX("failed setting power mode.\n");
7083 #define MAX_WX_STRING 80
7084 static int ipw_wx_get_powermode(struct net_device *dev,
7085 struct iw_request_info *info,
7086 union iwreq_data *wrqu, char *extra)
7088 struct ipw_priv *priv = ieee80211_priv(dev);
7089 int level = IPW_POWER_LEVEL(priv->power_mode);
7092 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
7096 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
7098 case IPW_POWER_BATTERY:
7099 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
7102 p += snprintf(p, MAX_WX_STRING - (p - extra),
7103 "(Timeout %dms, Period %dms)",
7104 timeout_duration[level - 1] / 1000,
7105 period_duration[level - 1] / 1000);
7108 if (!(priv->power_mode & IPW_POWER_ENABLED))
7109 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
7111 wrqu->data.length = p - extra + 1;
7116 static int ipw_wx_set_wireless_mode(struct net_device *dev,
7117 struct iw_request_info *info,
7118 union iwreq_data *wrqu, char *extra)
7120 struct ipw_priv *priv = ieee80211_priv(dev);
7121 int mode = *(int *)extra;
7122 u8 band = 0, modulation = 0;
7124 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
7125 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
7129 if (priv->adapter == IPW_2915ABG) {
7130 priv->ieee->abg_true = 1;
7131 if (mode & IEEE_A) {
7132 band |= IEEE80211_52GHZ_BAND;
7133 modulation |= IEEE80211_OFDM_MODULATION;
7135 priv->ieee->abg_true = 0;
7137 if (mode & IEEE_A) {
7138 IPW_WARNING("Attempt to set 2200BG into "
7143 priv->ieee->abg_true = 0;
7146 if (mode & IEEE_B) {
7147 band |= IEEE80211_24GHZ_BAND;
7148 modulation |= IEEE80211_CCK_MODULATION;
7150 priv->ieee->abg_true = 0;
7152 if (mode & IEEE_G) {
7153 band |= IEEE80211_24GHZ_BAND;
7154 modulation |= IEEE80211_OFDM_MODULATION;
7156 priv->ieee->abg_true = 0;
7158 priv->ieee->mode = mode;
7159 priv->ieee->freq_band = band;
7160 priv->ieee->modulation = modulation;
7161 init_supported_rates(priv, &priv->rates);
7163 /* If we are currently associated, or trying to associate
7164 * then see if this is a new configuration (causing us to
7166 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
7167 /* The resulting association will trigger
7168 * the new rates to be sent to the device */
7169 IPW_DEBUG_ASSOC("Disassociating due to mode change.\n");
7170 ipw_disassociate(priv);
7172 ipw_send_supported_rates(priv, &priv->rates);
7174 /* Update the band LEDs */
7175 ipw_led_band_on(priv);
7177 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
7178 mode & IEEE_A ? 'a' : '.',
7179 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
7183 static int ipw_wx_get_wireless_mode(struct net_device *dev,
7184 struct iw_request_info *info,
7185 union iwreq_data *wrqu, char *extra)
7187 struct ipw_priv *priv = ieee80211_priv(dev);
7189 switch (priv->ieee->mode) {
7191 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
7194 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
7196 case IEEE_A | IEEE_B:
7197 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
7200 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
7202 case IEEE_A | IEEE_G:
7203 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
7205 case IEEE_B | IEEE_G:
7206 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
7208 case IEEE_A | IEEE_B | IEEE_G:
7209 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
7212 strncpy(extra, "unknown", MAX_WX_STRING);
7216 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
7218 wrqu->data.length = strlen(extra) + 1;
7223 static int ipw_wx_set_preamble(struct net_device *dev,
7224 struct iw_request_info *info,
7225 union iwreq_data *wrqu, char *extra)
7227 struct ipw_priv *priv = ieee80211_priv(dev);
7228 int mode = *(int *)extra;
7230 /* Switching from SHORT -> LONG requires a disassociation */
7232 if (!(priv->config & CFG_PREAMBLE_LONG)) {
7233 priv->config |= CFG_PREAMBLE_LONG;
7235 (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
7237 ("Disassociating due to preamble "
7239 ipw_disassociate(priv);
7246 priv->config &= ~CFG_PREAMBLE_LONG;
7256 static int ipw_wx_get_preamble(struct net_device *dev,
7257 struct iw_request_info *info,
7258 union iwreq_data *wrqu, char *extra)
7260 struct ipw_priv *priv = ieee80211_priv(dev);
7262 if (priv->config & CFG_PREAMBLE_LONG)
7263 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
7265 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
7270 #ifdef CONFIG_IPW_MONITOR
7271 static int ipw_wx_set_monitor(struct net_device *dev,
7272 struct iw_request_info *info,
7273 union iwreq_data *wrqu, char *extra)
7275 struct ipw_priv *priv = ieee80211_priv(dev);
7276 int *parms = (int *)extra;
7277 int enable = (parms[0] > 0);
7279 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
7281 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
7282 priv->net_dev->type = ARPHRD_IEEE80211;
7283 queue_work(priv->workqueue, &priv->adapter_restart);
7286 ipw_set_channel(priv, parms[1]);
7288 if (priv->ieee->iw_mode != IW_MODE_MONITOR)
7290 priv->net_dev->type = ARPHRD_ETHER;
7291 queue_work(priv->workqueue, &priv->adapter_restart);
7296 static int ipw_wx_reset(struct net_device *dev,
7297 struct iw_request_info *info,
7298 union iwreq_data *wrqu, char *extra)
7300 struct ipw_priv *priv = ieee80211_priv(dev);
7301 IPW_DEBUG_WX("RESET\n");
7302 queue_work(priv->workqueue, &priv->adapter_restart);
7305 #endif // CONFIG_IPW_MONITOR
7307 /* Rebase the WE IOCTLs to zero for the handler array */
7308 #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
7309 static iw_handler ipw_wx_handlers[] = {
7310 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
7311 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
7312 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
7313 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
7314 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
7315 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
7316 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
7317 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
7318 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
7319 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
7320 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
7321 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
7322 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
7323 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
7324 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
7325 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
7326 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
7327 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
7328 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
7329 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
7330 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
7331 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
7332 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
7333 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
7334 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
7335 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
7336 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
7337 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
7338 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
7339 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
7340 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
7341 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
7344 #define IPW_PRIV_SET_POWER SIOCIWFIRSTPRIV
7345 #define IPW_PRIV_GET_POWER SIOCIWFIRSTPRIV+1
7346 #define IPW_PRIV_SET_MODE SIOCIWFIRSTPRIV+2
7347 #define IPW_PRIV_GET_MODE SIOCIWFIRSTPRIV+3
7348 #define IPW_PRIV_SET_PREAMBLE SIOCIWFIRSTPRIV+4
7349 #define IPW_PRIV_GET_PREAMBLE SIOCIWFIRSTPRIV+5
7350 #define IPW_PRIV_SET_MONITOR SIOCIWFIRSTPRIV+6
7351 #define IPW_PRIV_RESET SIOCIWFIRSTPRIV+7
7353 static struct iw_priv_args ipw_priv_args[] = {
7355 .cmd = IPW_PRIV_SET_POWER,
7356 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
7357 .name = "set_power"},
7359 .cmd = IPW_PRIV_GET_POWER,
7360 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
7361 .name = "get_power"},
7363 .cmd = IPW_PRIV_SET_MODE,
7364 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
7365 .name = "set_mode"},
7367 .cmd = IPW_PRIV_GET_MODE,
7368 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
7369 .name = "get_mode"},
7371 .cmd = IPW_PRIV_SET_PREAMBLE,
7372 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
7373 .name = "set_preamble"},
7375 .cmd = IPW_PRIV_GET_PREAMBLE,
7376 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
7377 .name = "get_preamble"},
7378 #ifdef CONFIG_IPW_MONITOR
7380 IPW_PRIV_SET_MONITOR,
7381 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
7384 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
7385 #endif /* CONFIG_IPW_MONITOR */
7388 static iw_handler ipw_priv_handler[] = {
7389 ipw_wx_set_powermode,
7390 ipw_wx_get_powermode,
7391 ipw_wx_set_wireless_mode,
7392 ipw_wx_get_wireless_mode,
7393 ipw_wx_set_preamble,
7394 ipw_wx_get_preamble,
7395 #ifdef CONFIG_IPW_MONITOR
7401 static struct iw_handler_def ipw_wx_handler_def = {
7402 .standard = ipw_wx_handlers,
7403 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
7404 .num_private = ARRAY_SIZE(ipw_priv_handler),
7405 .num_private_args = ARRAY_SIZE(ipw_priv_args),
7406 .private = ipw_priv_handler,
7407 .private_args = ipw_priv_args,
7410 static struct iw_public_data ipw_wx_data;
7413 * Get wireless statistics.
7414 * Called by /proc/net/wireless
7415 * Also called by SIOCGIWSTATS
7417 static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
7419 struct ipw_priv *priv = ieee80211_priv(dev);
7420 struct iw_statistics *wstats;
7422 wstats = &priv->wstats;
7424 /* if hw is disabled, then ipw_get_ordinal() can't be called.
7425 * ipw2100_wx_wireless_stats seems to be called before fw is
7426 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
7427 * and associated; if not associcated, the values are all meaningless
7428 * anyway, so set them all to NULL and INVALID */
7429 if (!(priv->status & STATUS_ASSOCIATED)) {
7430 wstats->miss.beacon = 0;
7431 wstats->discard.retries = 0;
7432 wstats->qual.qual = 0;
7433 wstats->qual.level = 0;
7434 wstats->qual.noise = 0;
7435 wstats->qual.updated = 7;
7436 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
7437 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
7441 wstats->qual.qual = priv->quality;
7442 wstats->qual.level = average_value(&priv->average_rssi);
7443 wstats->qual.noise = average_value(&priv->average_noise);
7444 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
7445 IW_QUAL_NOISE_UPDATED;
7447 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
7448 wstats->discard.retries = priv->last_tx_failures;
7449 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
7451 /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
7452 goto fail_get_ordinal;
7453 wstats->discard.retries += tx_retry; */
7458 /* net device stuff */
7460 static inline void init_sys_config(struct ipw_sys_config *sys_config)
7462 memset(sys_config, 0, sizeof(struct ipw_sys_config));
7463 sys_config->bt_coexistence = 1; /* We may need to look into prvStaBtConfig */
7464 sys_config->answer_broadcast_ssid_probe = 0;
7465 sys_config->accept_all_data_frames = 0;
7466 sys_config->accept_non_directed_frames = 1;
7467 sys_config->exclude_unicast_unencrypted = 0;
7468 sys_config->disable_unicast_decryption = 1;
7469 sys_config->exclude_multicast_unencrypted = 0;
7470 sys_config->disable_multicast_decryption = 1;
7471 sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
7472 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
7473 sys_config->dot11g_auto_detection = 0;
7474 sys_config->enable_cts_to_self = 0;
7475 sys_config->bt_coexist_collision_thr = 0;
7476 sys_config->pass_noise_stats_to_host = 0; //1 -- fix for 256
7479 static int ipw_net_open(struct net_device *dev)
7481 struct ipw_priv *priv = ieee80211_priv(dev);
7482 IPW_DEBUG_INFO("dev->open\n");
7483 /* we should be verifying the device is ready to be opened */
7484 if (!(priv->status & STATUS_RF_KILL_MASK) &&
7485 (priv->status & STATUS_ASSOCIATED))
7486 netif_start_queue(dev);
7490 static int ipw_net_stop(struct net_device *dev)
7492 IPW_DEBUG_INFO("dev->close\n");
7493 netif_stop_queue(dev);
7500 modify to send one tfd per fragment instead of using chunking. otherwise
7501 we need to heavily modify the ieee80211_skb_to_txb.
7504 static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
7506 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
7507 txb->fragments[0]->data;
7509 struct tfd_frame *tfd;
7510 struct clx2_tx_queue *txq = &priv->txq[0];
7511 struct clx2_queue *q = &txq->q;
7512 u8 id, hdr_len, unicast;
7513 u16 remaining_bytes;
7515 switch (priv->ieee->iw_mode) {
7517 hdr_len = IEEE80211_3ADDR_LEN;
7518 unicast = !is_broadcast_ether_addr(hdr->addr1) &&
7519 !is_multicast_ether_addr(hdr->addr1);
7520 id = ipw_find_station(priv, hdr->addr1);
7521 if (id == IPW_INVALID_STATION) {
7522 id = ipw_add_station(priv, hdr->addr1);
7523 if (id == IPW_INVALID_STATION) {
7524 IPW_WARNING("Attempt to send data to "
7525 "invalid cell: " MAC_FMT "\n",
7526 MAC_ARG(hdr->addr1));
7534 unicast = !is_broadcast_ether_addr(hdr->addr3) &&
7535 !is_multicast_ether_addr(hdr->addr3);
7536 hdr_len = IEEE80211_3ADDR_LEN;
7541 tfd = &txq->bd[q->first_empty];
7542 txq->txb[q->first_empty] = txb;
7543 memset(tfd, 0, sizeof(*tfd));
7544 tfd->u.data.station_number = id;
7546 tfd->control_flags.message_type = TX_FRAME_TYPE;
7547 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
7549 tfd->u.data.cmd_id = DINO_CMD_TX;
7550 tfd->u.data.len = cpu_to_le16(txb->payload_size);
7551 remaining_bytes = txb->payload_size;
7552 if (unlikely(!unicast))
7553 tfd->u.data.tx_flags = DCT_FLAG_NO_WEP;
7555 tfd->u.data.tx_flags = DCT_FLAG_NO_WEP | DCT_FLAG_ACK_REQD;
7557 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
7558 tfd->u.data.tx_flags_ext = DCT_FLAG_EXT_MODE_CCK;
7560 tfd->u.data.tx_flags_ext = DCT_FLAG_EXT_MODE_OFDM;
7562 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
7563 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
7565 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
7568 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
7570 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
7571 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
7572 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
7573 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
7574 i, le32_to_cpu(tfd->u.data.num_chunks),
7575 txb->fragments[i]->len - hdr_len);
7576 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
7577 i, tfd->u.data.num_chunks,
7578 txb->fragments[i]->len - hdr_len);
7579 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
7580 txb->fragments[i]->len - hdr_len);
7582 tfd->u.data.chunk_ptr[i] =
7583 cpu_to_le32(pci_map_single
7585 txb->fragments[i]->data + hdr_len,
7586 txb->fragments[i]->len - hdr_len,
7588 tfd->u.data.chunk_len[i] =
7589 cpu_to_le16(txb->fragments[i]->len - hdr_len);
7592 if (i != txb->nr_frags) {
7593 struct sk_buff *skb;
7594 u16 remaining_bytes = 0;
7597 for (j = i; j < txb->nr_frags; j++)
7598 remaining_bytes += txb->fragments[j]->len - hdr_len;
7600 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
7602 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
7604 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
7605 for (j = i; j < txb->nr_frags; j++) {
7606 int size = txb->fragments[j]->len - hdr_len;
7607 printk(KERN_INFO "Adding frag %d %d...\n",
7609 memcpy(skb_put(skb, size),
7610 txb->fragments[j]->data + hdr_len, size);
7612 dev_kfree_skb_any(txb->fragments[i]);
7613 txb->fragments[i] = skb;
7614 tfd->u.data.chunk_ptr[i] =
7615 cpu_to_le32(pci_map_single
7616 (priv->pci_dev, skb->data,
7617 tfd->u.data.chunk_len[i],
7620 tfd->u.data.num_chunks =
7621 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
7627 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
7628 ipw_write32(priv, q->reg_w, q->first_empty);
7630 if (ipw_queue_space(q) < q->high_mark)
7631 netif_stop_queue(priv->net_dev);
7636 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
7637 ieee80211_txb_free(txb);
7640 static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
7641 struct net_device *dev, int pri)
7643 struct ipw_priv *priv = ieee80211_priv(dev);
7644 unsigned long flags;
7646 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
7648 spin_lock_irqsave(&priv->lock, flags);
7650 if (!(priv->status & STATUS_ASSOCIATED)) {
7651 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
7652 priv->ieee->stats.tx_carrier_errors++;
7653 netif_stop_queue(dev);
7657 ipw_tx_skb(priv, txb);
7658 ipw_led_activity_on(priv);
7660 spin_unlock_irqrestore(&priv->lock, flags);
7664 spin_unlock_irqrestore(&priv->lock, flags);
7668 static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
7670 struct ipw_priv *priv = ieee80211_priv(dev);
7672 priv->ieee->stats.tx_packets = priv->tx_packets;
7673 priv->ieee->stats.rx_packets = priv->rx_packets;
7674 return &priv->ieee->stats;
7677 static void ipw_net_set_multicast_list(struct net_device *dev)
7682 static int ipw_net_set_mac_address(struct net_device *dev, void *p)
7684 struct ipw_priv *priv = ieee80211_priv(dev);
7685 struct sockaddr *addr = p;
7686 if (!is_valid_ether_addr(addr->sa_data))
7687 return -EADDRNOTAVAIL;
7688 priv->config |= CFG_CUSTOM_MAC;
7689 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
7690 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
7691 priv->net_dev->name, MAC_ARG(priv->mac_addr));
7692 queue_work(priv->workqueue, &priv->adapter_restart);
7696 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
7697 struct ethtool_drvinfo *info)
7699 struct ipw_priv *p = ieee80211_priv(dev);
7704 strcpy(info->driver, DRV_NAME);
7705 strcpy(info->version, DRV_VERSION);
7708 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
7710 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
7712 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
7714 strcpy(info->bus_info, pci_name(p->pci_dev));
7715 info->eedump_len = CX2_EEPROM_IMAGE_SIZE;
7718 static u32 ipw_ethtool_get_link(struct net_device *dev)
7720 struct ipw_priv *priv = ieee80211_priv(dev);
7721 return (priv->status & STATUS_ASSOCIATED) != 0;
7724 static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
7726 return CX2_EEPROM_IMAGE_SIZE;
7729 static int ipw_ethtool_get_eeprom(struct net_device *dev,
7730 struct ethtool_eeprom *eeprom, u8 * bytes)
7732 struct ipw_priv *p = ieee80211_priv(dev);
7734 if (eeprom->offset + eeprom->len > CX2_EEPROM_IMAGE_SIZE)
7737 memcpy(bytes, &((u8 *) p->eeprom)[eeprom->offset], eeprom->len);
7741 static int ipw_ethtool_set_eeprom(struct net_device *dev,
7742 struct ethtool_eeprom *eeprom, u8 * bytes)
7744 struct ipw_priv *p = ieee80211_priv(dev);
7747 if (eeprom->offset + eeprom->len > CX2_EEPROM_IMAGE_SIZE)
7750 memcpy(&((u8 *) p->eeprom)[eeprom->offset], bytes, eeprom->len);
7751 for (i = IPW_EEPROM_DATA;
7752 i < IPW_EEPROM_DATA + CX2_EEPROM_IMAGE_SIZE; i++)
7753 ipw_write8(p, i, p->eeprom[i]);
7758 static struct ethtool_ops ipw_ethtool_ops = {
7759 .get_link = ipw_ethtool_get_link,
7760 .get_drvinfo = ipw_ethtool_get_drvinfo,
7761 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
7762 .get_eeprom = ipw_ethtool_get_eeprom,
7763 .set_eeprom = ipw_ethtool_set_eeprom,
7766 static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
7768 struct ipw_priv *priv = data;
7769 u32 inta, inta_mask;
7774 spin_lock(&priv->lock);
7776 if (!(priv->status & STATUS_INT_ENABLED)) {
7781 inta = ipw_read32(priv, CX2_INTA_RW);
7782 inta_mask = ipw_read32(priv, CX2_INTA_MASK_R);
7784 if (inta == 0xFFFFFFFF) {
7785 /* Hardware disappeared */
7786 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
7790 if (!(inta & (CX2_INTA_MASK_ALL & inta_mask))) {
7791 /* Shared interrupt */
7795 /* tell the device to stop sending interrupts */
7796 ipw_disable_interrupts(priv);
7798 /* ack current interrupts */
7799 inta &= (CX2_INTA_MASK_ALL & inta_mask);
7800 ipw_write32(priv, CX2_INTA_RW, inta);
7802 /* Cache INTA value for our tasklet */
7803 priv->isr_inta = inta;
7805 tasklet_schedule(&priv->irq_tasklet);
7807 spin_unlock(&priv->lock);
7811 spin_unlock(&priv->lock);
7815 static void ipw_rf_kill(void *adapter)
7817 struct ipw_priv *priv = adapter;
7818 unsigned long flags;
7820 spin_lock_irqsave(&priv->lock, flags);
7822 if (rf_kill_active(priv)) {
7823 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
7824 if (priv->workqueue)
7825 queue_delayed_work(priv->workqueue,
7826 &priv->rf_kill, 2 * HZ);
7830 /* RF Kill is now disabled, so bring the device back up */
7832 if (!(priv->status & STATUS_RF_KILL_MASK)) {
7833 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
7836 /* we can not do an adapter restart while inside an irq lock */
7837 queue_work(priv->workqueue, &priv->adapter_restart);
7839 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
7843 spin_unlock_irqrestore(&priv->lock, flags);
7846 void ipw_link_up(struct ipw_priv *priv)
7848 netif_carrier_on(priv->net_dev);
7849 if (netif_queue_stopped(priv->net_dev)) {
7850 IPW_DEBUG_NOTIF("waking queue\n");
7851 netif_wake_queue(priv->net_dev);
7853 IPW_DEBUG_NOTIF("starting queue\n");
7854 netif_start_queue(priv->net_dev);
7857 ipw_reset_stats(priv);
7858 /* Ensure the rate is updated immediately */
7859 priv->last_rate = ipw_get_current_rate(priv);
7860 ipw_gather_stats(priv);
7861 ipw_led_link_up(priv);
7862 notify_wx_assoc_event(priv);
7864 if (priv->config & CFG_BACKGROUND_SCAN)
7865 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
7868 void ipw_link_down(struct ipw_priv *priv)
7870 ipw_led_link_down(priv);
7871 netif_carrier_off(priv->net_dev);
7872 netif_stop_queue(priv->net_dev);
7873 notify_wx_assoc_event(priv);
7875 /* Cancel any queued work ... */
7876 cancel_delayed_work(&priv->request_scan);
7877 cancel_delayed_work(&priv->adhoc_check);
7878 cancel_delayed_work(&priv->gather_stats);
7880 ipw_reset_stats(priv);
7882 /* Queue up another scan... */
7883 queue_work(priv->workqueue, &priv->request_scan);
7886 static int ipw_setup_deferred_work(struct ipw_priv *priv)
7890 priv->workqueue = create_workqueue(DRV_NAME);
7891 init_waitqueue_head(&priv->wait_command_queue);
7893 INIT_WORK(&priv->adhoc_check, ipw_adhoc_check, priv);
7894 INIT_WORK(&priv->associate, ipw_associate, priv);
7895 INIT_WORK(&priv->disassociate, ipw_disassociate, priv);
7896 INIT_WORK(&priv->rx_replenish, ipw_rx_queue_replenish, priv);
7897 INIT_WORK(&priv->adapter_restart, ipw_adapter_restart, priv);
7898 INIT_WORK(&priv->rf_kill, ipw_rf_kill, priv);
7899 INIT_WORK(&priv->up, (void (*)(void *))ipw_up, priv);
7900 INIT_WORK(&priv->down, (void (*)(void *))ipw_down, priv);
7901 INIT_WORK(&priv->request_scan,
7902 (void (*)(void *))ipw_request_scan, priv);
7903 INIT_WORK(&priv->gather_stats,
7904 (void (*)(void *))ipw_gather_stats, priv);
7905 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_abort_scan, priv);
7906 INIT_WORK(&priv->roam, ipw_roam, priv);
7907 INIT_WORK(&priv->scan_check, ipw_scan_check, priv);
7908 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_link_up, priv);
7909 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_link_down, priv);
7910 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_led_link_on, priv);
7911 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_led_link_off,
7913 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_led_activity_off,
7916 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
7917 ipw_irq_tasklet, (unsigned long)priv);
7922 static void shim__set_security(struct net_device *dev,
7923 struct ieee80211_security *sec)
7925 struct ipw_priv *priv = ieee80211_priv(dev);
7928 for (i = 0; i < 4; i++) {
7929 if (sec->flags & (1 << i)) {
7930 priv->sec.key_sizes[i] = sec->key_sizes[i];
7931 if (sec->key_sizes[i] == 0)
7932 priv->sec.flags &= ~(1 << i);
7934 memcpy(priv->sec.keys[i], sec->keys[i],
7936 priv->sec.flags |= (1 << i);
7937 priv->status |= STATUS_SECURITY_UPDATED;
7941 if ((sec->flags & SEC_ACTIVE_KEY) &&
7942 priv->sec.active_key != sec->active_key) {
7943 if (sec->active_key <= 3) {
7944 priv->sec.active_key = sec->active_key;
7945 priv->sec.flags |= SEC_ACTIVE_KEY;
7947 priv->sec.flags &= ~SEC_ACTIVE_KEY;
7948 priv->status |= STATUS_SECURITY_UPDATED;
7951 if ((sec->flags & SEC_AUTH_MODE) &&
7952 (priv->sec.auth_mode != sec->auth_mode)) {
7953 priv->sec.auth_mode = sec->auth_mode;
7954 priv->sec.flags |= SEC_AUTH_MODE;
7955 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
7956 priv->capability |= CAP_SHARED_KEY;
7958 priv->capability &= ~CAP_SHARED_KEY;
7959 priv->status |= STATUS_SECURITY_UPDATED;
7962 if (sec->flags & SEC_ENABLED && priv->sec.enabled != sec->enabled) {
7963 priv->sec.flags |= SEC_ENABLED;
7964 priv->sec.enabled = sec->enabled;
7965 priv->status |= STATUS_SECURITY_UPDATED;
7967 priv->capability |= CAP_PRIVACY_ON;
7969 priv->capability &= ~CAP_PRIVACY_ON;
7972 if (sec->flags & SEC_LEVEL && priv->sec.level != sec->level) {
7973 priv->sec.level = sec->level;
7974 priv->sec.flags |= SEC_LEVEL;
7975 priv->status |= STATUS_SECURITY_UPDATED;
7978 /* To match current functionality of ipw2100 (which works well w/
7979 * various supplicants, we don't force a disassociate if the
7980 * privacy capability changes ... */
7982 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
7983 (((priv->assoc_request.capability &
7984 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
7985 (!(priv->assoc_request.capability &
7986 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
7987 IPW_DEBUG_ASSOC("Disassociating due to capability "
7989 ipw_disassociate(priv);
7994 static int init_supported_rates(struct ipw_priv *priv,
7995 struct ipw_supported_rates *rates)
7997 /* TODO: Mask out rates based on priv->rates_mask */
7999 memset(rates, 0, sizeof(*rates));
8000 /* configure supported rates */
8001 switch (priv->ieee->freq_band) {
8002 case IEEE80211_52GHZ_BAND:
8003 rates->ieee_mode = IPW_A_MODE;
8004 rates->purpose = IPW_RATE_CAPABILITIES;
8005 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
8006 IEEE80211_OFDM_DEFAULT_RATES_MASK);
8009 default: /* Mixed or 2.4Ghz */
8010 rates->ieee_mode = IPW_G_MODE;
8011 rates->purpose = IPW_RATE_CAPABILITIES;
8012 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
8013 IEEE80211_CCK_DEFAULT_RATES_MASK);
8014 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
8015 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
8016 IEEE80211_OFDM_DEFAULT_RATES_MASK);
8024 static int ipw_config(struct ipw_priv *priv)
8027 struct ipw_tx_power tx_power;
8029 memset(&priv->sys_config, 0, sizeof(priv->sys_config));
8030 memset(&tx_power, 0, sizeof(tx_power));
8032 /* This is only called from ipw_up, which resets/reloads the firmware
8033 so, we don't need to first disable the card before we configure
8036 /* configure device for 'G' band */
8037 tx_power.ieee_mode = IPW_G_MODE;
8038 tx_power.num_channels = 11;
8039 for (i = 0; i < 11; i++) {
8040 tx_power.channels_tx_power[i].channel_number = i + 1;
8041 tx_power.channels_tx_power[i].tx_power = priv->tx_power;
8043 if (ipw_send_tx_power(priv, &tx_power))
8046 /* configure device to also handle 'B' band */
8047 tx_power.ieee_mode = IPW_B_MODE;
8048 if (ipw_send_tx_power(priv, &tx_power))
8051 /* initialize adapter address */
8052 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
8055 /* set basic system config settings */
8056 init_sys_config(&priv->sys_config);
8057 if (ipw_send_system_config(priv, &priv->sys_config))
8060 init_supported_rates(priv, &priv->rates);
8061 if (ipw_send_supported_rates(priv, &priv->rates))
8064 /* Set request-to-send threshold */
8065 if (priv->rts_threshold) {
8066 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
8070 if (ipw_set_random_seed(priv))
8073 /* final state transition to the RUN state */
8074 if (ipw_send_host_complete(priv))
8077 /* If configured to try and auto-associate, kick off a scan */
8078 if ((priv->config & CFG_ASSOCIATE) && ipw_request_scan(priv))
8087 #define MAX_HW_RESTARTS 5
8088 static int ipw_up(struct ipw_priv *priv)
8092 if (priv->status & STATUS_EXIT_PENDING)
8095 for (i = 0; i < MAX_HW_RESTARTS; i++) {
8096 /* Load the microcode, firmware, and eeprom.
8097 * Also start the clocks. */
8098 rc = ipw_load(priv);
8100 IPW_ERROR("Unable to load firmware: 0x%08X\n", rc);
8104 ipw_init_ordinals(priv);
8105 if (!(priv->config & CFG_CUSTOM_MAC))
8106 eeprom_parse_mac(priv, priv->mac_addr);
8107 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
8109 if (priv->status & STATUS_RF_KILL_MASK)
8112 rc = ipw_config(priv);
8114 IPW_DEBUG_INFO("Configured device on count %i\n", i);
8116 ipw_led_radio_on(priv);
8117 priv->notif_missed_beacons = 0;
8120 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n",
8124 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
8125 i, MAX_HW_RESTARTS);
8127 /* We had an error bringing up the hardware, so take it
8128 * all the way back down so we can try again */
8132 /* tried to restart and config the device for as long as our
8133 * patience could withstand */
8134 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
8138 static void ipw_down(struct ipw_priv *priv)
8140 /* Attempt to disable the card */
8142 ipw_send_card_disable(priv, 0);
8145 /* tell the device to stop sending interrupts */
8146 ipw_disable_interrupts(priv);
8148 /* Clear all bits but the RF Kill */
8149 priv->status &= STATUS_RF_KILL_MASK;
8151 netif_carrier_off(priv->net_dev);
8152 netif_stop_queue(priv->net_dev);
8156 ipw_led_radio_off(priv);
8159 static int ipw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
8161 struct iwreq *wrq = (struct iwreq *)rq;
8164 case IPW_IOCTL_WPA_SUPPLICANT:
8165 ret = ipw_wpa_supplicant(dev, &wrq->u.data);
8175 /* Called by register_netdev() */
8176 static int ipw_net_init(struct net_device *dev)
8178 struct ipw_priv *priv = ieee80211_priv(dev);
8180 if (priv->status & STATUS_RF_KILL_SW) {
8181 IPW_WARNING("Radio disabled by module parameter.\n");
8183 } else if (rf_kill_active(priv)) {
8184 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
8185 "Kill switch must be turned off for "
8186 "wireless networking to work.\n");
8187 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
8197 /* PCI driver stuff */
8198 static struct pci_device_id card_ids[] = {
8199 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
8200 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
8201 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
8202 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
8203 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
8204 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
8205 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
8206 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
8207 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
8208 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
8209 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
8210 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
8211 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
8212 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
8213 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
8214 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
8215 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
8216 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
8217 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
8218 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
8219 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
8220 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
8222 /* required last entry */
8226 MODULE_DEVICE_TABLE(pci, card_ids);
8228 static struct attribute *ipw_sysfs_entries[] = {
8229 &dev_attr_rf_kill.attr,
8230 &dev_attr_direct_dword.attr,
8231 &dev_attr_indirect_byte.attr,
8232 &dev_attr_indirect_dword.attr,
8233 &dev_attr_mem_gpio_reg.attr,
8234 &dev_attr_command_event_reg.attr,
8235 &dev_attr_nic_type.attr,
8236 &dev_attr_status.attr,
8238 &dev_attr_dump_errors.attr,
8239 &dev_attr_dump_events.attr,
8240 &dev_attr_eeprom_delay.attr,
8241 &dev_attr_ucode_version.attr,
8243 &dev_attr_scan_age.attr,
8248 static struct attribute_group ipw_attribute_group = {
8249 .name = NULL, /* put in device directory */
8250 .attrs = ipw_sysfs_entries,
8253 static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
8256 struct net_device *net_dev;
8259 struct ipw_priv *priv;
8260 int band, modulation;
8262 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
8263 if (net_dev == NULL) {
8268 priv = ieee80211_priv(net_dev);
8269 priv->ieee = netdev_priv(net_dev);
8271 priv->net_dev = net_dev;
8272 priv->pci_dev = pdev;
8273 #ifdef CONFIG_IPW_DEBUG
8274 ipw_debug_level = debug;
8276 spin_lock_init(&priv->lock);
8278 if (pci_enable_device(pdev)) {
8280 goto out_free_ieee80211;
8283 pci_set_master(pdev);
8285 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
8287 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
8289 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
8290 goto out_pci_disable_device;
8293 pci_set_drvdata(pdev, priv);
8295 err = pci_request_regions(pdev, DRV_NAME);
8297 goto out_pci_disable_device;
8299 /* We disable the RETRY_TIMEOUT register (0x41) to keep
8300 * PCI Tx retries from interfering with C3 CPU state */
8301 pci_read_config_dword(pdev, 0x40, &val);
8302 if ((val & 0x0000ff00) != 0)
8303 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
8305 length = pci_resource_len(pdev, 0);
8306 priv->hw_len = length;
8308 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
8311 goto out_pci_release_regions;
8314 priv->hw_base = base;
8315 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
8316 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
8318 err = ipw_setup_deferred_work(priv);
8320 IPW_ERROR("Unable to setup deferred work\n");
8324 /* Initialize module parameter values here */
8326 /* We default to disabling the LED code as right now it causes
8327 * too many systems to lock up... */
8329 priv->config |= CFG_NO_LED;
8332 priv->config |= CFG_ASSOCIATE;
8334 IPW_DEBUG_INFO("Auto associate disabled.\n");
8337 priv->config |= CFG_ADHOC_CREATE;
8339 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8342 priv->status |= STATUS_RF_KILL_SW;
8343 IPW_DEBUG_INFO("Radio disabled.\n");
8347 priv->config |= CFG_STATIC_CHANNEL;
8348 priv->channel = channel;
8349 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8350 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8351 /* TODO: Validate that provided channel is in range */
8356 priv->ieee->iw_mode = IW_MODE_ADHOC;
8358 #ifdef CONFIG_IPW_MONITOR
8360 priv->ieee->iw_mode = IW_MODE_MONITOR;
8365 priv->ieee->iw_mode = IW_MODE_INFRA;
8369 if ((priv->pci_dev->device == 0x4223) ||
8370 (priv->pci_dev->device == 0x4224)) {
8371 printk(KERN_INFO DRV_NAME
8372 ": Detected Intel PRO/Wireless 2915ABG Network "
8374 priv->ieee->abg_true = 1;
8375 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8376 modulation = IEEE80211_OFDM_MODULATION |
8377 IEEE80211_CCK_MODULATION;
8378 priv->adapter = IPW_2915ABG;
8379 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
8381 printk(KERN_INFO DRV_NAME
8382 ": Detected Intel PRO/Wireless 2200BG Network "
8385 priv->ieee->abg_true = 0;
8386 band = IEEE80211_24GHZ_BAND;
8387 modulation = IEEE80211_OFDM_MODULATION |
8388 IEEE80211_CCK_MODULATION;
8389 priv->adapter = IPW_2200BG;
8390 priv->ieee->mode = IEEE_G | IEEE_B;
8393 priv->ieee->freq_band = band;
8394 priv->ieee->modulation = modulation;
8396 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
8398 priv->missed_beacon_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8399 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8401 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8403 /* If power management is turned on, default to AC mode */
8404 priv->power_mode = IPW_POWER_AC;
8405 priv->tx_power = IPW_DEFAULT_TX_POWER;
8407 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
8409 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
8410 goto out_destroy_workqueue;
8413 SET_MODULE_OWNER(net_dev);
8414 SET_NETDEV_DEV(net_dev, &pdev->dev);
8416 ipw_wx_data.spy_data = &priv->ieee->spy_data;
8417 ipw_wx_data.ieee80211 = priv->ieee;
8419 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
8420 priv->ieee->set_security = shim__set_security;
8422 net_dev->open = ipw_net_open;
8423 net_dev->stop = ipw_net_stop;
8424 net_dev->init = ipw_net_init;
8425 net_dev->do_ioctl = ipw_ioctl;
8426 net_dev->get_stats = ipw_net_get_stats;
8427 net_dev->set_multicast_list = ipw_net_set_multicast_list;
8428 net_dev->set_mac_address = ipw_net_set_mac_address;
8429 net_dev->get_wireless_stats = ipw_get_wireless_stats;
8430 net_dev->wireless_data = &ipw_wx_data;
8431 net_dev->wireless_handlers = &ipw_wx_handler_def;
8432 net_dev->ethtool_ops = &ipw_ethtool_ops;
8433 net_dev->irq = pdev->irq;
8434 net_dev->base_addr = (unsigned long)priv->hw_base;
8435 net_dev->mem_start = pci_resource_start(pdev, 0);
8436 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
8438 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
8440 IPW_ERROR("failed to create sysfs device attributes\n");
8441 goto out_release_irq;
8444 err = register_netdev(net_dev);
8446 IPW_ERROR("failed to register network device\n");
8447 goto out_remove_sysfs;
8453 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
8455 free_irq(pdev->irq, priv);
8456 out_destroy_workqueue:
8457 destroy_workqueue(priv->workqueue);
8458 priv->workqueue = NULL;
8460 iounmap(priv->hw_base);
8461 out_pci_release_regions:
8462 pci_release_regions(pdev);
8463 out_pci_disable_device:
8464 pci_disable_device(pdev);
8465 pci_set_drvdata(pdev, NULL);
8467 free_ieee80211(priv->net_dev);
8472 static void ipw_pci_remove(struct pci_dev *pdev)
8474 struct ipw_priv *priv = pci_get_drvdata(pdev);
8478 priv->status |= STATUS_EXIT_PENDING;
8480 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
8484 unregister_netdev(priv->net_dev);
8487 ipw_rx_queue_free(priv, priv->rxq);
8490 ipw_tx_queue_free(priv);
8492 ipw_led_shutdown(priv);
8494 /* ipw_down will ensure that there is no more pending work
8495 * in the workqueue's, so we can safely remove them now. */
8496 cancel_delayed_work(&priv->adhoc_check);
8497 cancel_delayed_work(&priv->gather_stats);
8498 cancel_delayed_work(&priv->request_scan);
8499 cancel_delayed_work(&priv->rf_kill);
8500 cancel_delayed_work(&priv->scan_check);
8501 destroy_workqueue(priv->workqueue);
8502 priv->workqueue = NULL;
8504 free_irq(pdev->irq, priv);
8505 iounmap(priv->hw_base);
8506 pci_release_regions(pdev);
8507 pci_disable_device(pdev);
8508 pci_set_drvdata(pdev, NULL);
8509 free_ieee80211(priv->net_dev);
8513 release_firmware(bootfw);
8514 release_firmware(ucode);
8515 release_firmware(firmware);
8522 static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
8524 struct ipw_priv *priv = pci_get_drvdata(pdev);
8525 struct net_device *dev = priv->net_dev;
8527 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
8529 /* Take down the device; powers it off, etc. */
8532 /* Remove the PRESENT state of the device */
8533 netif_device_detach(dev);
8535 pci_save_state(pdev);
8536 pci_disable_device(pdev);
8537 pci_set_power_state(pdev, pci_choose_state(pdev, state));
8542 static int ipw_pci_resume(struct pci_dev *pdev)
8544 struct ipw_priv *priv = pci_get_drvdata(pdev);
8545 struct net_device *dev = priv->net_dev;
8548 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
8550 pci_set_power_state(pdev, PCI_D0);
8551 pci_enable_device(pdev);
8552 pci_restore_state(pdev);
8555 * Suspend/Resume resets the PCI configuration space, so we have to
8556 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
8557 * from interfering with C3 CPU state. pci_restore_state won't help
8558 * here since it only restores the first 64 bytes pci config header.
8560 pci_read_config_dword(pdev, 0x40, &val);
8561 if ((val & 0x0000ff00) != 0)
8562 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
8564 /* Set the device back into the PRESENT state; this will also wake
8565 * the queue of needed */
8566 netif_device_attach(dev);
8568 /* Bring the device back up */
8569 queue_work(priv->workqueue, &priv->up);
8575 /* driver initialization stuff */
8576 static struct pci_driver ipw_driver = {
8578 .id_table = card_ids,
8579 .probe = ipw_pci_probe,
8580 .remove = __devexit_p(ipw_pci_remove),
8582 .suspend = ipw_pci_suspend,
8583 .resume = ipw_pci_resume,
8587 static int __init ipw_init(void)
8591 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
8592 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
8594 ret = pci_module_init(&ipw_driver);
8596 IPW_ERROR("Unable to initialize PCI module\n");
8600 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
8602 IPW_ERROR("Unable to create driver sysfs file\n");
8603 pci_unregister_driver(&ipw_driver);
8610 static void __exit ipw_exit(void)
8612 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
8613 pci_unregister_driver(&ipw_driver);
8616 module_param(disable, int, 0444);
8617 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
8619 module_param(associate, int, 0444);
8620 MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
8622 module_param(auto_create, int, 0444);
8623 MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
8625 module_param(led, int, 0444);
8626 MODULE_PARM_DESC(auto_create,
8627 "enable led control on some systems (default 0 off)\n");
8629 module_param(debug, int, 0444);
8630 MODULE_PARM_DESC(debug, "debug output mask");
8632 module_param(channel, int, 0444);
8633 MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
8635 #ifdef CONFIG_IPW_MONITOR
8636 module_param(mode, int, 0444);
8637 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
8639 module_param(mode, int, 0444);
8640 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
8643 module_exit(ipw_exit);
8644 module_init(ipw_init);