1 /******************************************************************************
3 Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved.
5 802.11 status code portion of this file from ethereal-0.10.6:
6 Copyright 2000, Axis Communications AB
7 Ethereal - Network traffic analyzer
8 By Gerald Combs <gerald@ethereal.com>
9 Copyright 1998 Gerald Combs
11 This program is free software; you can redistribute it and/or modify it
12 under the terms of version 2 of the GNU General Public License as
13 published by the Free Software Foundation.
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59
22 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 The full GNU General Public License is included in this distribution in the
28 James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 ******************************************************************************/
34 #include <linux/version.h>
43 #ifdef CONFIG_IPW2200_DEBUG
49 #ifdef CONFIG_IPW2200_MONITOR
55 #ifdef CONFIG_IPW2200_PROMISCUOUS
61 #ifdef CONFIG_IPW2200_RADIOTAP
67 #ifdef CONFIG_IPW2200_QOS
73 #define IPW2200_VERSION "1.1.2" VK VD VM VP VR VQ
74 #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
75 #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
76 #define DRV_VERSION IPW2200_VERSION
78 #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
80 MODULE_DESCRIPTION(DRV_DESCRIPTION);
81 MODULE_VERSION(DRV_VERSION);
82 MODULE_AUTHOR(DRV_COPYRIGHT);
83 MODULE_LICENSE("GPL");
85 static int cmdlog = 0;
86 #ifdef CONFIG_IPW2200_DEBUG
89 static int channel = 0;
92 static u32 ipw_debug_level;
93 static int associate = 1;
94 static int auto_create = 1;
96 static int disable = 0;
97 static int bt_coexist = 0;
98 static int hwcrypto = 0;
99 static int roaming = 1;
100 static const char ipw_modes[] = {
103 static int antenna = CFG_SYS_ANTENNA_BOTH;
105 #ifdef CONFIG_IPW2200_PROMISCUOUS
106 static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */
110 #ifdef CONFIG_IPW2200_QOS
111 static int qos_enable = 0;
112 static int qos_burst_enable = 0;
113 static int qos_no_ack_mask = 0;
114 static int burst_duration_CCK = 0;
115 static int burst_duration_OFDM = 0;
117 static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
118 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
119 QOS_TX3_CW_MIN_OFDM},
120 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
121 QOS_TX3_CW_MAX_OFDM},
122 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
123 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
124 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
125 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
128 static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
129 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
131 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
133 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
134 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
135 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
136 QOS_TX3_TXOP_LIMIT_CCK}
139 static struct ieee80211_qos_parameters def_parameters_OFDM = {
140 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
141 DEF_TX3_CW_MIN_OFDM},
142 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
143 DEF_TX3_CW_MAX_OFDM},
144 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
145 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
146 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
147 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
150 static struct ieee80211_qos_parameters def_parameters_CCK = {
151 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
153 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
155 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
156 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
157 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
158 DEF_TX3_TXOP_LIMIT_CCK}
161 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
163 static int from_priority_to_tx_queue[] = {
164 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
165 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
168 static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
170 static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
172 static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
174 #endif /* CONFIG_IPW2200_QOS */
176 static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
177 static void ipw_remove_current_network(struct ipw_priv *priv);
178 static void ipw_rx(struct ipw_priv *priv);
179 static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
180 struct clx2_tx_queue *txq, int qindex);
181 static int ipw_queue_reset(struct ipw_priv *priv);
183 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
186 static void ipw_tx_queue_free(struct ipw_priv *);
188 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
189 static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
190 static void ipw_rx_queue_replenish(void *);
191 static int ipw_up(struct ipw_priv *);
192 static void ipw_bg_up(void *);
193 static void ipw_down(struct ipw_priv *);
194 static void ipw_bg_down(void *);
195 static int ipw_config(struct ipw_priv *);
196 static int init_supported_rates(struct ipw_priv *priv,
197 struct ipw_supported_rates *prates);
198 static void ipw_set_hwcrypto_keys(struct ipw_priv *);
199 static void ipw_send_wep_keys(struct ipw_priv *, int);
201 static int snprint_line(char *buf, size_t count,
202 const u8 * data, u32 len, u32 ofs)
207 out = snprintf(buf, count, "%08X", ofs);
209 for (l = 0, i = 0; i < 2; i++) {
210 out += snprintf(buf + out, count - out, " ");
211 for (j = 0; j < 8 && l < len; j++, l++)
212 out += snprintf(buf + out, count - out, "%02X ",
215 out += snprintf(buf + out, count - out, " ");
218 out += snprintf(buf + out, count - out, " ");
219 for (l = 0, i = 0; i < 2; i++) {
220 out += snprintf(buf + out, count - out, " ");
221 for (j = 0; j < 8 && l < len; j++, l++) {
222 c = data[(i * 8 + j)];
223 if (!isascii(c) || !isprint(c))
226 out += snprintf(buf + out, count - out, "%c", c);
230 out += snprintf(buf + out, count - out, " ");
236 static void printk_buf(int level, const u8 * data, u32 len)
240 if (!(ipw_debug_level & level))
244 snprint_line(line, sizeof(line), &data[ofs],
246 printk(KERN_DEBUG "%s\n", line);
248 len -= min(len, 16U);
252 static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
258 while (size && len) {
259 out = snprint_line(output, size, &data[ofs],
260 min_t(size_t, len, 16U), ofs);
265 len -= min_t(size_t, len, 16U);
271 /* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
272 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
273 #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
275 /* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
276 static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
277 #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
279 /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
280 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
281 static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
283 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
284 __LINE__, (u32) (b), (u32) (c));
285 _ipw_write_reg8(a, b, c);
288 /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
289 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
290 static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
292 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
293 __LINE__, (u32) (b), (u32) (c));
294 _ipw_write_reg16(a, b, c);
297 /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
298 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
299 static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
301 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
302 __LINE__, (u32) (b), (u32) (c));
303 _ipw_write_reg32(a, b, c);
306 /* 8-bit direct write (low 4K) */
307 #define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
309 /* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
310 #define ipw_write8(ipw, ofs, val) \
311 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
312 _ipw_write8(ipw, ofs, val)
314 /* 16-bit direct write (low 4K) */
315 #define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
317 /* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
318 #define ipw_write16(ipw, ofs, val) \
319 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
320 _ipw_write16(ipw, ofs, val)
322 /* 32-bit direct write (low 4K) */
323 #define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
325 /* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
326 #define ipw_write32(ipw, ofs, val) \
327 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
328 _ipw_write32(ipw, ofs, val)
330 /* 8-bit direct read (low 4K) */
331 #define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
333 /* 8-bit direct read (low 4K), with debug wrapper */
334 static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
336 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
337 return _ipw_read8(ipw, ofs);
340 /* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
341 #define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
343 /* 16-bit direct read (low 4K) */
344 #define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
346 /* 16-bit direct read (low 4K), with debug wrapper */
347 static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
349 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
350 return _ipw_read16(ipw, ofs);
353 /* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
354 #define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
356 /* 32-bit direct read (low 4K) */
357 #define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
359 /* 32-bit direct read (low 4K), with debug wrapper */
360 static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
362 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
363 return _ipw_read32(ipw, ofs);
366 /* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
367 #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
369 /* multi-byte read (above 4K), with debug wrapper */
370 static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
371 static inline void __ipw_read_indirect(const char *f, int l,
372 struct ipw_priv *a, u32 b, u8 * c, int d)
374 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
376 _ipw_read_indirect(a, b, c, d);
379 /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
380 #define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
382 /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
383 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
385 #define ipw_write_indirect(a, b, c, d) \
386 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
387 _ipw_write_indirect(a, b, c, d)
389 /* 32-bit indirect write (above 4K) */
390 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
392 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
393 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
394 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
397 /* 8-bit indirect write (above 4K) */
398 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
400 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
401 u32 dif_len = reg - aligned_addr;
403 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
404 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
405 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
408 /* 16-bit indirect write (above 4K) */
409 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
411 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
412 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
414 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
415 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
416 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
419 /* 8-bit indirect read (above 4K) */
420 static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
423 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
424 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
425 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
426 return (word >> ((reg & 0x3) * 8)) & 0xff;
429 /* 32-bit indirect read (above 4K) */
430 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
434 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
436 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
437 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
438 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
442 /* General purpose, no alignment requirement, iterative (multi-byte) read, */
443 /* for area above 1st 4K of SRAM/reg space */
444 static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
447 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
448 u32 dif_len = addr - aligned_addr;
451 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
457 /* Read the first dword (or portion) byte by byte */
458 if (unlikely(dif_len)) {
459 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
460 /* Start reading at aligned_addr + dif_len */
461 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
462 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
466 /* Read all of the middle dwords as dwords, with auto-increment */
467 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
468 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
469 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
471 /* Read the last dword (or portion) byte by byte */
473 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
474 for (i = 0; num > 0; i++, num--)
475 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
479 /* General purpose, no alignment requirement, iterative (multi-byte) write, */
480 /* for area above 1st 4K of SRAM/reg space */
481 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
484 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
485 u32 dif_len = addr - aligned_addr;
488 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
494 /* Write the first dword (or portion) byte by byte */
495 if (unlikely(dif_len)) {
496 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
497 /* Start writing at aligned_addr + dif_len */
498 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
499 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
503 /* Write all of the middle dwords as dwords, with auto-increment */
504 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
505 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
506 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
508 /* Write the last dword (or portion) byte by byte */
510 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
511 for (i = 0; num > 0; i++, num--, buf++)
512 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
516 /* General purpose, no alignment requirement, iterative (multi-byte) write, */
517 /* for 1st 4K of SRAM/regs space */
518 static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
521 memcpy_toio((priv->hw_base + addr), buf, num);
524 /* Set bit(s) in low 4K of SRAM/regs */
525 static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
527 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
530 /* Clear bit(s) in low 4K of SRAM/regs */
531 static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
533 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
536 static inline void __ipw_enable_interrupts(struct ipw_priv *priv)
538 if (priv->status & STATUS_INT_ENABLED)
540 priv->status |= STATUS_INT_ENABLED;
541 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
544 static inline void __ipw_disable_interrupts(struct ipw_priv *priv)
546 if (!(priv->status & STATUS_INT_ENABLED))
548 priv->status &= ~STATUS_INT_ENABLED;
549 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
552 static inline void ipw_enable_interrupts(struct ipw_priv *priv)
556 spin_lock_irqsave(&priv->irq_lock, flags);
557 __ipw_enable_interrupts(priv);
558 spin_unlock_irqrestore(&priv->irq_lock, flags);
561 static inline void ipw_disable_interrupts(struct ipw_priv *priv)
565 spin_lock_irqsave(&priv->irq_lock, flags);
566 __ipw_disable_interrupts(priv);
567 spin_unlock_irqrestore(&priv->irq_lock, flags);
570 #ifdef CONFIG_IPW2200_DEBUG
571 static char *ipw_error_desc(u32 val)
574 case IPW_FW_ERROR_OK:
576 case IPW_FW_ERROR_FAIL:
578 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
579 return "MEMORY_UNDERFLOW";
580 case IPW_FW_ERROR_MEMORY_OVERFLOW:
581 return "MEMORY_OVERFLOW";
582 case IPW_FW_ERROR_BAD_PARAM:
584 case IPW_FW_ERROR_BAD_CHECKSUM:
585 return "BAD_CHECKSUM";
586 case IPW_FW_ERROR_NMI_INTERRUPT:
587 return "NMI_INTERRUPT";
588 case IPW_FW_ERROR_BAD_DATABASE:
589 return "BAD_DATABASE";
590 case IPW_FW_ERROR_ALLOC_FAIL:
592 case IPW_FW_ERROR_DMA_UNDERRUN:
593 return "DMA_UNDERRUN";
594 case IPW_FW_ERROR_DMA_STATUS:
596 case IPW_FW_ERROR_DINO_ERROR:
598 case IPW_FW_ERROR_EEPROM_ERROR:
599 return "EEPROM_ERROR";
600 case IPW_FW_ERROR_SYSASSERT:
602 case IPW_FW_ERROR_FATAL_ERROR:
603 return "FATAL_ERROR";
605 return "UNKNOWN_ERROR";
609 static void ipw_dump_error_log(struct ipw_priv *priv,
610 struct ipw_fw_error *error)
615 IPW_ERROR("Error allocating and capturing error log. "
616 "Nothing to dump.\n");
620 IPW_ERROR("Start IPW Error Log Dump:\n");
621 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
622 error->status, error->config);
624 for (i = 0; i < error->elem_len; i++)
625 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
626 ipw_error_desc(error->elem[i].desc),
628 error->elem[i].blink1,
629 error->elem[i].blink2,
630 error->elem[i].link1,
631 error->elem[i].link2, error->elem[i].data);
632 for (i = 0; i < error->log_len; i++)
633 IPW_ERROR("%i\t0x%08x\t%i\n",
635 error->log[i].data, error->log[i].event);
639 static inline int ipw_is_init(struct ipw_priv *priv)
641 return (priv->status & STATUS_INIT) ? 1 : 0;
644 static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
646 u32 addr, field_info, field_len, field_count, total_len;
648 IPW_DEBUG_ORD("ordinal = %i\n", ord);
650 if (!priv || !val || !len) {
651 IPW_DEBUG_ORD("Invalid argument\n");
655 /* verify device ordinal tables have been initialized */
656 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
657 IPW_DEBUG_ORD("Access ordinals before initialization\n");
661 switch (IPW_ORD_TABLE_ID_MASK & ord) {
662 case IPW_ORD_TABLE_0_MASK:
664 * TABLE 0: Direct access to a table of 32 bit values
666 * This is a very simple table with the data directly
667 * read from the table
670 /* remove the table id from the ordinal */
671 ord &= IPW_ORD_TABLE_VALUE_MASK;
674 if (ord > priv->table0_len) {
675 IPW_DEBUG_ORD("ordinal value (%i) longer then "
676 "max (%i)\n", ord, priv->table0_len);
680 /* verify we have enough room to store the value */
681 if (*len < sizeof(u32)) {
682 IPW_DEBUG_ORD("ordinal buffer length too small, "
683 "need %zd\n", sizeof(u32));
687 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
688 ord, priv->table0_addr + (ord << 2));
692 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
695 case IPW_ORD_TABLE_1_MASK:
697 * TABLE 1: Indirect access to a table of 32 bit values
699 * This is a fairly large table of u32 values each
700 * representing starting addr for the data (which is
704 /* remove the table id from the ordinal */
705 ord &= IPW_ORD_TABLE_VALUE_MASK;
708 if (ord > priv->table1_len) {
709 IPW_DEBUG_ORD("ordinal value too long\n");
713 /* verify we have enough room to store the value */
714 if (*len < sizeof(u32)) {
715 IPW_DEBUG_ORD("ordinal buffer length too small, "
716 "need %zd\n", sizeof(u32));
721 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
725 case IPW_ORD_TABLE_2_MASK:
727 * TABLE 2: Indirect access to a table of variable sized values
729 * This table consist of six values, each containing
730 * - dword containing the starting offset of the data
731 * - dword containing the lengh in the first 16bits
732 * and the count in the second 16bits
735 /* remove the table id from the ordinal */
736 ord &= IPW_ORD_TABLE_VALUE_MASK;
739 if (ord > priv->table2_len) {
740 IPW_DEBUG_ORD("ordinal value too long\n");
744 /* get the address of statistic */
745 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
747 /* get the second DW of statistics ;
748 * two 16-bit words - first is length, second is count */
751 priv->table2_addr + (ord << 3) +
754 /* get each entry length */
755 field_len = *((u16 *) & field_info);
757 /* get number of entries */
758 field_count = *(((u16 *) & field_info) + 1);
760 /* abort if not enought memory */
761 total_len = field_len * field_count;
762 if (total_len > *len) {
771 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
772 "field_info = 0x%08x\n",
773 addr, total_len, field_info);
774 ipw_read_indirect(priv, addr, val, total_len);
778 IPW_DEBUG_ORD("Invalid ordinal!\n");
786 static void ipw_init_ordinals(struct ipw_priv *priv)
788 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
789 priv->table0_len = ipw_read32(priv, priv->table0_addr);
791 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
792 priv->table0_addr, priv->table0_len);
794 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
795 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
797 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
798 priv->table1_addr, priv->table1_len);
800 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
801 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
802 priv->table2_len &= 0x0000ffff; /* use first two bytes */
804 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
805 priv->table2_addr, priv->table2_len);
809 static u32 ipw_register_toggle(u32 reg)
811 reg &= ~IPW_START_STANDBY;
812 if (reg & IPW_GATE_ODMA)
813 reg &= ~IPW_GATE_ODMA;
814 if (reg & IPW_GATE_IDMA)
815 reg &= ~IPW_GATE_IDMA;
816 if (reg & IPW_GATE_ADMA)
817 reg &= ~IPW_GATE_ADMA;
823 * - On radio ON, turn on any LEDs that require to be on during start
824 * - On initialization, start unassociated blink
825 * - On association, disable unassociated blink
826 * - On disassociation, start unassociated blink
827 * - On radio OFF, turn off any LEDs started during radio on
830 #define LD_TIME_LINK_ON msecs_to_jiffies(300)
831 #define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
832 #define LD_TIME_ACT_ON msecs_to_jiffies(250)
834 static void ipw_led_link_on(struct ipw_priv *priv)
839 /* If configured to not use LEDs, or nic_type is 1,
840 * then we don't toggle a LINK led */
841 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
844 spin_lock_irqsave(&priv->lock, flags);
846 if (!(priv->status & STATUS_RF_KILL_MASK) &&
847 !(priv->status & STATUS_LED_LINK_ON)) {
848 IPW_DEBUG_LED("Link LED On\n");
849 led = ipw_read_reg32(priv, IPW_EVENT_REG);
850 led |= priv->led_association_on;
852 led = ipw_register_toggle(led);
854 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
855 ipw_write_reg32(priv, IPW_EVENT_REG, led);
857 priv->status |= STATUS_LED_LINK_ON;
859 /* If we aren't associated, schedule turning the LED off */
860 if (!(priv->status & STATUS_ASSOCIATED))
861 queue_delayed_work(priv->workqueue,
866 spin_unlock_irqrestore(&priv->lock, flags);
869 static void ipw_bg_led_link_on(void *data)
871 struct ipw_priv *priv = data;
872 mutex_lock(&priv->mutex);
873 ipw_led_link_on(data);
874 mutex_unlock(&priv->mutex);
877 static void ipw_led_link_off(struct ipw_priv *priv)
882 /* If configured not to use LEDs, or nic type is 1,
883 * then we don't goggle the LINK led. */
884 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
887 spin_lock_irqsave(&priv->lock, flags);
889 if (priv->status & STATUS_LED_LINK_ON) {
890 led = ipw_read_reg32(priv, IPW_EVENT_REG);
891 led &= priv->led_association_off;
892 led = ipw_register_toggle(led);
894 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
895 ipw_write_reg32(priv, IPW_EVENT_REG, led);
897 IPW_DEBUG_LED("Link LED Off\n");
899 priv->status &= ~STATUS_LED_LINK_ON;
901 /* If we aren't associated and the radio is on, schedule
902 * turning the LED on (blink while unassociated) */
903 if (!(priv->status & STATUS_RF_KILL_MASK) &&
904 !(priv->status & STATUS_ASSOCIATED))
905 queue_delayed_work(priv->workqueue, &priv->led_link_on,
910 spin_unlock_irqrestore(&priv->lock, flags);
913 static void ipw_bg_led_link_off(void *data)
915 struct ipw_priv *priv = data;
916 mutex_lock(&priv->mutex);
917 ipw_led_link_off(data);
918 mutex_unlock(&priv->mutex);
921 static void __ipw_led_activity_on(struct ipw_priv *priv)
925 if (priv->config & CFG_NO_LED)
928 if (priv->status & STATUS_RF_KILL_MASK)
931 if (!(priv->status & STATUS_LED_ACT_ON)) {
932 led = ipw_read_reg32(priv, IPW_EVENT_REG);
933 led |= priv->led_activity_on;
935 led = ipw_register_toggle(led);
937 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
938 ipw_write_reg32(priv, IPW_EVENT_REG, led);
940 IPW_DEBUG_LED("Activity LED On\n");
942 priv->status |= STATUS_LED_ACT_ON;
944 cancel_delayed_work(&priv->led_act_off);
945 queue_delayed_work(priv->workqueue, &priv->led_act_off,
948 /* Reschedule LED off for full time period */
949 cancel_delayed_work(&priv->led_act_off);
950 queue_delayed_work(priv->workqueue, &priv->led_act_off,
956 void ipw_led_activity_on(struct ipw_priv *priv)
959 spin_lock_irqsave(&priv->lock, flags);
960 __ipw_led_activity_on(priv);
961 spin_unlock_irqrestore(&priv->lock, flags);
965 static void ipw_led_activity_off(struct ipw_priv *priv)
970 if (priv->config & CFG_NO_LED)
973 spin_lock_irqsave(&priv->lock, flags);
975 if (priv->status & STATUS_LED_ACT_ON) {
976 led = ipw_read_reg32(priv, IPW_EVENT_REG);
977 led &= priv->led_activity_off;
979 led = ipw_register_toggle(led);
981 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
982 ipw_write_reg32(priv, IPW_EVENT_REG, led);
984 IPW_DEBUG_LED("Activity LED Off\n");
986 priv->status &= ~STATUS_LED_ACT_ON;
989 spin_unlock_irqrestore(&priv->lock, flags);
992 static void ipw_bg_led_activity_off(void *data)
994 struct ipw_priv *priv = data;
995 mutex_lock(&priv->mutex);
996 ipw_led_activity_off(data);
997 mutex_unlock(&priv->mutex);
1000 static void ipw_led_band_on(struct ipw_priv *priv)
1002 unsigned long flags;
1005 /* Only nic type 1 supports mode LEDs */
1006 if (priv->config & CFG_NO_LED ||
1007 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
1010 spin_lock_irqsave(&priv->lock, flags);
1012 led = ipw_read_reg32(priv, IPW_EVENT_REG);
1013 if (priv->assoc_network->mode == IEEE_A) {
1014 led |= priv->led_ofdm_on;
1015 led &= priv->led_association_off;
1016 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
1017 } else if (priv->assoc_network->mode == IEEE_G) {
1018 led |= priv->led_ofdm_on;
1019 led |= priv->led_association_on;
1020 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
1022 led &= priv->led_ofdm_off;
1023 led |= priv->led_association_on;
1024 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
1027 led = ipw_register_toggle(led);
1029 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
1030 ipw_write_reg32(priv, IPW_EVENT_REG, led);
1032 spin_unlock_irqrestore(&priv->lock, flags);
1035 static void ipw_led_band_off(struct ipw_priv *priv)
1037 unsigned long flags;
1040 /* Only nic type 1 supports mode LEDs */
1041 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
1044 spin_lock_irqsave(&priv->lock, flags);
1046 led = ipw_read_reg32(priv, IPW_EVENT_REG);
1047 led &= priv->led_ofdm_off;
1048 led &= priv->led_association_off;
1050 led = ipw_register_toggle(led);
1052 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
1053 ipw_write_reg32(priv, IPW_EVENT_REG, led);
1055 spin_unlock_irqrestore(&priv->lock, flags);
1058 static void ipw_led_radio_on(struct ipw_priv *priv)
1060 ipw_led_link_on(priv);
1063 static void ipw_led_radio_off(struct ipw_priv *priv)
1065 ipw_led_activity_off(priv);
1066 ipw_led_link_off(priv);
1069 static void ipw_led_link_up(struct ipw_priv *priv)
1071 /* Set the Link Led on for all nic types */
1072 ipw_led_link_on(priv);
1075 static void ipw_led_link_down(struct ipw_priv *priv)
1077 ipw_led_activity_off(priv);
1078 ipw_led_link_off(priv);
1080 if (priv->status & STATUS_RF_KILL_MASK)
1081 ipw_led_radio_off(priv);
1084 static void ipw_led_init(struct ipw_priv *priv)
1086 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1088 /* Set the default PINs for the link and activity leds */
1089 priv->led_activity_on = IPW_ACTIVITY_LED;
1090 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
1092 priv->led_association_on = IPW_ASSOCIATED_LED;
1093 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
1095 /* Set the default PINs for the OFDM leds */
1096 priv->led_ofdm_on = IPW_OFDM_LED;
1097 priv->led_ofdm_off = ~(IPW_OFDM_LED);
1099 switch (priv->nic_type) {
1100 case EEPROM_NIC_TYPE_1:
1101 /* In this NIC type, the LEDs are reversed.... */
1102 priv->led_activity_on = IPW_ASSOCIATED_LED;
1103 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1104 priv->led_association_on = IPW_ACTIVITY_LED;
1105 priv->led_association_off = ~(IPW_ACTIVITY_LED);
1107 if (!(priv->config & CFG_NO_LED))
1108 ipw_led_band_on(priv);
1110 /* And we don't blink link LEDs for this nic, so
1111 * just return here */
1114 case EEPROM_NIC_TYPE_3:
1115 case EEPROM_NIC_TYPE_2:
1116 case EEPROM_NIC_TYPE_4:
1117 case EEPROM_NIC_TYPE_0:
1121 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1123 priv->nic_type = EEPROM_NIC_TYPE_0;
1127 if (!(priv->config & CFG_NO_LED)) {
1128 if (priv->status & STATUS_ASSOCIATED)
1129 ipw_led_link_on(priv);
1131 ipw_led_link_off(priv);
1135 static void ipw_led_shutdown(struct ipw_priv *priv)
1137 ipw_led_activity_off(priv);
1138 ipw_led_link_off(priv);
1139 ipw_led_band_off(priv);
1140 cancel_delayed_work(&priv->led_link_on);
1141 cancel_delayed_work(&priv->led_link_off);
1142 cancel_delayed_work(&priv->led_act_off);
1146 * The following adds a new attribute to the sysfs representation
1147 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1148 * used for controling the debug level.
1150 * See the level definitions in ipw for details.
1152 static ssize_t show_debug_level(struct device_driver *d, char *buf)
1154 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1157 static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1160 char *p = (char *)buf;
1163 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1165 if (p[0] == 'x' || p[0] == 'X')
1167 val = simple_strtoul(p, &p, 16);
1169 val = simple_strtoul(p, &p, 10);
1171 printk(KERN_INFO DRV_NAME
1172 ": %s is not in hex or decimal form.\n", buf);
1174 ipw_debug_level = val;
1176 return strnlen(buf, count);
1179 static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
1180 show_debug_level, store_debug_level);
1182 static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1184 /* length = 1st dword in log */
1185 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1188 static void ipw_capture_event_log(struct ipw_priv *priv,
1189 u32 log_len, struct ipw_event *log)
1194 base = ipw_read32(priv, IPW_EVENT_LOG);
1195 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1196 (u8 *) log, sizeof(*log) * log_len);
1200 static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1202 struct ipw_fw_error *error;
1203 u32 log_len = ipw_get_event_log_len(priv);
1204 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1205 u32 elem_len = ipw_read_reg32(priv, base);
1207 error = kmalloc(sizeof(*error) +
1208 sizeof(*error->elem) * elem_len +
1209 sizeof(*error->log) * log_len, GFP_ATOMIC);
1211 IPW_ERROR("Memory allocation for firmware error log "
1215 error->jiffies = jiffies;
1216 error->status = priv->status;
1217 error->config = priv->config;
1218 error->elem_len = elem_len;
1219 error->log_len = log_len;
1220 error->elem = (struct ipw_error_elem *)error->payload;
1221 error->log = (struct ipw_event *)(error->elem + elem_len);
1223 ipw_capture_event_log(priv, log_len, error->log);
1226 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1227 sizeof(*error->elem) * elem_len);
1232 static void ipw_free_error_log(struct ipw_fw_error *error)
1238 static ssize_t show_event_log(struct device *d,
1239 struct device_attribute *attr, char *buf)
1241 struct ipw_priv *priv = dev_get_drvdata(d);
1242 u32 log_len = ipw_get_event_log_len(priv);
1243 struct ipw_event log[log_len];
1246 ipw_capture_event_log(priv, log_len, log);
1248 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1249 for (i = 0; i < log_len; i++)
1250 len += snprintf(buf + len, PAGE_SIZE - len,
1252 log[i].time, log[i].event, log[i].data);
1253 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1257 static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1259 static ssize_t show_error(struct device *d,
1260 struct device_attribute *attr, char *buf)
1262 struct ipw_priv *priv = dev_get_drvdata(d);
1266 len += snprintf(buf + len, PAGE_SIZE - len,
1267 "%08lX%08X%08X%08X",
1268 priv->error->jiffies,
1269 priv->error->status,
1270 priv->error->config, priv->error->elem_len);
1271 for (i = 0; i < priv->error->elem_len; i++)
1272 len += snprintf(buf + len, PAGE_SIZE - len,
1273 "\n%08X%08X%08X%08X%08X%08X%08X",
1274 priv->error->elem[i].time,
1275 priv->error->elem[i].desc,
1276 priv->error->elem[i].blink1,
1277 priv->error->elem[i].blink2,
1278 priv->error->elem[i].link1,
1279 priv->error->elem[i].link2,
1280 priv->error->elem[i].data);
1282 len += snprintf(buf + len, PAGE_SIZE - len,
1283 "\n%08X", priv->error->log_len);
1284 for (i = 0; i < priv->error->log_len; i++)
1285 len += snprintf(buf + len, PAGE_SIZE - len,
1287 priv->error->log[i].time,
1288 priv->error->log[i].event,
1289 priv->error->log[i].data);
1290 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1294 static ssize_t clear_error(struct device *d,
1295 struct device_attribute *attr,
1296 const char *buf, size_t count)
1298 struct ipw_priv *priv = dev_get_drvdata(d);
1300 ipw_free_error_log(priv->error);
1306 static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1308 static ssize_t show_cmd_log(struct device *d,
1309 struct device_attribute *attr, char *buf)
1311 struct ipw_priv *priv = dev_get_drvdata(d);
1315 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1316 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1317 i = (i + 1) % priv->cmdlog_len) {
1319 snprintf(buf + len, PAGE_SIZE - len,
1320 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1321 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1322 priv->cmdlog[i].cmd.len);
1324 snprintk_buf(buf + len, PAGE_SIZE - len,
1325 (u8 *) priv->cmdlog[i].cmd.param,
1326 priv->cmdlog[i].cmd.len);
1327 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1329 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1333 static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1335 #ifdef CONFIG_IPW2200_PROMISCUOUS
1336 static void ipw_prom_free(struct ipw_priv *priv);
1337 static int ipw_prom_alloc(struct ipw_priv *priv);
1338 static ssize_t store_rtap_iface(struct device *d,
1339 struct device_attribute *attr,
1340 const char *buf, size_t count)
1342 struct ipw_priv *priv = dev_get_drvdata(d);
1353 if (netif_running(priv->prom_net_dev)) {
1354 IPW_WARNING("Interface is up. Cannot unregister.\n");
1358 ipw_prom_free(priv);
1366 rc = ipw_prom_alloc(priv);
1376 IPW_ERROR("Failed to register promiscuous network "
1377 "device (error %d).\n", rc);
1383 static ssize_t show_rtap_iface(struct device *d,
1384 struct device_attribute *attr,
1387 struct ipw_priv *priv = dev_get_drvdata(d);
1389 return sprintf(buf, "%s", priv->prom_net_dev->name);
1398 static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1401 static ssize_t store_rtap_filter(struct device *d,
1402 struct device_attribute *attr,
1403 const char *buf, size_t count)
1405 struct ipw_priv *priv = dev_get_drvdata(d);
1407 if (!priv->prom_priv) {
1408 IPW_ERROR("Attempting to set filter without "
1409 "rtap_iface enabled.\n");
1413 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1415 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1416 BIT_ARG16(priv->prom_priv->filter));
1421 static ssize_t show_rtap_filter(struct device *d,
1422 struct device_attribute *attr,
1425 struct ipw_priv *priv = dev_get_drvdata(d);
1426 return sprintf(buf, "0x%04X",
1427 priv->prom_priv ? priv->prom_priv->filter : 0);
1430 static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1434 static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1437 struct ipw_priv *priv = dev_get_drvdata(d);
1438 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1441 static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1442 const char *buf, size_t count)
1444 struct ipw_priv *priv = dev_get_drvdata(d);
1445 #ifdef CONFIG_IPW2200_DEBUG
1446 struct net_device *dev = priv->net_dev;
1448 char buffer[] = "00000000";
1450 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1454 IPW_DEBUG_INFO("enter\n");
1456 strncpy(buffer, buf, len);
1459 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1461 if (p[0] == 'x' || p[0] == 'X')
1463 val = simple_strtoul(p, &p, 16);
1465 val = simple_strtoul(p, &p, 10);
1467 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1469 priv->ieee->scan_age = val;
1470 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1473 IPW_DEBUG_INFO("exit\n");
1477 static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1479 static ssize_t show_led(struct device *d, struct device_attribute *attr,
1482 struct ipw_priv *priv = dev_get_drvdata(d);
1483 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1486 static ssize_t store_led(struct device *d, struct device_attribute *attr,
1487 const char *buf, size_t count)
1489 struct ipw_priv *priv = dev_get_drvdata(d);
1491 IPW_DEBUG_INFO("enter\n");
1497 IPW_DEBUG_LED("Disabling LED control.\n");
1498 priv->config |= CFG_NO_LED;
1499 ipw_led_shutdown(priv);
1501 IPW_DEBUG_LED("Enabling LED control.\n");
1502 priv->config &= ~CFG_NO_LED;
1506 IPW_DEBUG_INFO("exit\n");
1510 static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1512 static ssize_t show_status(struct device *d,
1513 struct device_attribute *attr, char *buf)
1515 struct ipw_priv *p = d->driver_data;
1516 return sprintf(buf, "0x%08x\n", (int)p->status);
1519 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1521 static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1524 struct ipw_priv *p = d->driver_data;
1525 return sprintf(buf, "0x%08x\n", (int)p->config);
1528 static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1530 static ssize_t show_nic_type(struct device *d,
1531 struct device_attribute *attr, char *buf)
1533 struct ipw_priv *priv = d->driver_data;
1534 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
1537 static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1539 static ssize_t show_ucode_version(struct device *d,
1540 struct device_attribute *attr, char *buf)
1542 u32 len = sizeof(u32), tmp = 0;
1543 struct ipw_priv *p = d->driver_data;
1545 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
1548 return sprintf(buf, "0x%08x\n", tmp);
1551 static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
1553 static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1556 u32 len = sizeof(u32), tmp = 0;
1557 struct ipw_priv *p = d->driver_data;
1559 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
1562 return sprintf(buf, "0x%08x\n", tmp);
1565 static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
1568 * Add a device attribute to view/control the delay between eeprom
1571 static ssize_t show_eeprom_delay(struct device *d,
1572 struct device_attribute *attr, char *buf)
1574 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
1575 return sprintf(buf, "%i\n", n);
1577 static ssize_t store_eeprom_delay(struct device *d,
1578 struct device_attribute *attr,
1579 const char *buf, size_t count)
1581 struct ipw_priv *p = d->driver_data;
1582 sscanf(buf, "%i", &p->eeprom_delay);
1583 return strnlen(buf, count);
1586 static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1587 show_eeprom_delay, store_eeprom_delay);
1589 static ssize_t show_command_event_reg(struct device *d,
1590 struct device_attribute *attr, char *buf)
1593 struct ipw_priv *p = d->driver_data;
1595 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
1596 return sprintf(buf, "0x%08x\n", reg);
1598 static ssize_t store_command_event_reg(struct device *d,
1599 struct device_attribute *attr,
1600 const char *buf, size_t count)
1603 struct ipw_priv *p = d->driver_data;
1605 sscanf(buf, "%x", ®);
1606 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
1607 return strnlen(buf, count);
1610 static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1611 show_command_event_reg, store_command_event_reg);
1613 static ssize_t show_mem_gpio_reg(struct device *d,
1614 struct device_attribute *attr, char *buf)
1617 struct ipw_priv *p = d->driver_data;
1619 reg = ipw_read_reg32(p, 0x301100);
1620 return sprintf(buf, "0x%08x\n", reg);
1622 static ssize_t store_mem_gpio_reg(struct device *d,
1623 struct device_attribute *attr,
1624 const char *buf, size_t count)
1627 struct ipw_priv *p = d->driver_data;
1629 sscanf(buf, "%x", ®);
1630 ipw_write_reg32(p, 0x301100, reg);
1631 return strnlen(buf, count);
1634 static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1635 show_mem_gpio_reg, store_mem_gpio_reg);
1637 static ssize_t show_indirect_dword(struct device *d,
1638 struct device_attribute *attr, char *buf)
1641 struct ipw_priv *priv = d->driver_data;
1643 if (priv->status & STATUS_INDIRECT_DWORD)
1644 reg = ipw_read_reg32(priv, priv->indirect_dword);
1648 return sprintf(buf, "0x%08x\n", reg);
1650 static ssize_t store_indirect_dword(struct device *d,
1651 struct device_attribute *attr,
1652 const char *buf, size_t count)
1654 struct ipw_priv *priv = d->driver_data;
1656 sscanf(buf, "%x", &priv->indirect_dword);
1657 priv->status |= STATUS_INDIRECT_DWORD;
1658 return strnlen(buf, count);
1661 static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1662 show_indirect_dword, store_indirect_dword);
1664 static ssize_t show_indirect_byte(struct device *d,
1665 struct device_attribute *attr, char *buf)
1668 struct ipw_priv *priv = d->driver_data;
1670 if (priv->status & STATUS_INDIRECT_BYTE)
1671 reg = ipw_read_reg8(priv, priv->indirect_byte);
1675 return sprintf(buf, "0x%02x\n", reg);
1677 static ssize_t store_indirect_byte(struct device *d,
1678 struct device_attribute *attr,
1679 const char *buf, size_t count)
1681 struct ipw_priv *priv = d->driver_data;
1683 sscanf(buf, "%x", &priv->indirect_byte);
1684 priv->status |= STATUS_INDIRECT_BYTE;
1685 return strnlen(buf, count);
1688 static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
1689 show_indirect_byte, store_indirect_byte);
1691 static ssize_t show_direct_dword(struct device *d,
1692 struct device_attribute *attr, char *buf)
1695 struct ipw_priv *priv = d->driver_data;
1697 if (priv->status & STATUS_DIRECT_DWORD)
1698 reg = ipw_read32(priv, priv->direct_dword);
1702 return sprintf(buf, "0x%08x\n", reg);
1704 static ssize_t store_direct_dword(struct device *d,
1705 struct device_attribute *attr,
1706 const char *buf, size_t count)
1708 struct ipw_priv *priv = d->driver_data;
1710 sscanf(buf, "%x", &priv->direct_dword);
1711 priv->status |= STATUS_DIRECT_DWORD;
1712 return strnlen(buf, count);
1715 static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1716 show_direct_dword, store_direct_dword);
1718 static int rf_kill_active(struct ipw_priv *priv)
1720 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1721 priv->status |= STATUS_RF_KILL_HW;
1723 priv->status &= ~STATUS_RF_KILL_HW;
1725 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1728 static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
1731 /* 0 - RF kill not enabled
1732 1 - SW based RF kill active (sysfs)
1733 2 - HW based RF kill active
1734 3 - Both HW and SW baed RF kill active */
1735 struct ipw_priv *priv = d->driver_data;
1736 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
1737 (rf_kill_active(priv) ? 0x2 : 0x0);
1738 return sprintf(buf, "%i\n", val);
1741 static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1743 if ((disable_radio ? 1 : 0) ==
1744 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
1747 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1748 disable_radio ? "OFF" : "ON");
1750 if (disable_radio) {
1751 priv->status |= STATUS_RF_KILL_SW;
1753 if (priv->workqueue)
1754 cancel_delayed_work(&priv->request_scan);
1755 queue_work(priv->workqueue, &priv->down);
1757 priv->status &= ~STATUS_RF_KILL_SW;
1758 if (rf_kill_active(priv)) {
1759 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1760 "disabled by HW switch\n");
1761 /* Make sure the RF_KILL check timer is running */
1762 cancel_delayed_work(&priv->rf_kill);
1763 queue_delayed_work(priv->workqueue, &priv->rf_kill,
1766 queue_work(priv->workqueue, &priv->up);
1772 static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1773 const char *buf, size_t count)
1775 struct ipw_priv *priv = d->driver_data;
1777 ipw_radio_kill_sw(priv, buf[0] == '1');
1782 static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
1784 static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1787 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1788 int pos = 0, len = 0;
1789 if (priv->config & CFG_SPEED_SCAN) {
1790 while (priv->speed_scan[pos] != 0)
1791 len += sprintf(&buf[len], "%d ",
1792 priv->speed_scan[pos++]);
1793 return len + sprintf(&buf[len], "\n");
1796 return sprintf(buf, "0\n");
1799 static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1800 const char *buf, size_t count)
1802 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1803 int channel, pos = 0;
1804 const char *p = buf;
1806 /* list of space separated channels to scan, optionally ending with 0 */
1807 while ((channel = simple_strtol(p, NULL, 0))) {
1808 if (pos == MAX_SPEED_SCAN - 1) {
1809 priv->speed_scan[pos] = 0;
1813 if (ieee80211_is_valid_channel(priv->ieee, channel))
1814 priv->speed_scan[pos++] = channel;
1816 IPW_WARNING("Skipping invalid channel request: %d\n",
1821 while (*p == ' ' || *p == '\t')
1826 priv->config &= ~CFG_SPEED_SCAN;
1828 priv->speed_scan_pos = 0;
1829 priv->config |= CFG_SPEED_SCAN;
1835 static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1838 static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1841 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1842 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1845 static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1846 const char *buf, size_t count)
1848 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1850 priv->config |= CFG_NET_STATS;
1852 priv->config &= ~CFG_NET_STATS;
1857 static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1858 show_net_stats, store_net_stats);
1860 static void notify_wx_assoc_event(struct ipw_priv *priv)
1862 union iwreq_data wrqu;
1863 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1864 if (priv->status & STATUS_ASSOCIATED)
1865 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1867 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1868 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1871 static void ipw_irq_tasklet(struct ipw_priv *priv)
1873 u32 inta, inta_mask, handled = 0;
1874 unsigned long flags;
1877 spin_lock_irqsave(&priv->irq_lock, flags);
1879 inta = ipw_read32(priv, IPW_INTA_RW);
1880 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1881 inta &= (IPW_INTA_MASK_ALL & inta_mask);
1883 /* Add any cached INTA values that need to be handled */
1884 inta |= priv->isr_inta;
1886 spin_unlock_irqrestore(&priv->irq_lock, flags);
1888 spin_lock_irqsave(&priv->lock, flags);
1890 /* handle all the justifications for the interrupt */
1891 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
1893 handled |= IPW_INTA_BIT_RX_TRANSFER;
1896 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
1897 IPW_DEBUG_HC("Command completed.\n");
1898 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
1899 priv->status &= ~STATUS_HCMD_ACTIVE;
1900 wake_up_interruptible(&priv->wait_command_queue);
1901 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
1904 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
1905 IPW_DEBUG_TX("TX_QUEUE_1\n");
1906 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
1907 handled |= IPW_INTA_BIT_TX_QUEUE_1;
1910 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
1911 IPW_DEBUG_TX("TX_QUEUE_2\n");
1912 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
1913 handled |= IPW_INTA_BIT_TX_QUEUE_2;
1916 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
1917 IPW_DEBUG_TX("TX_QUEUE_3\n");
1918 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
1919 handled |= IPW_INTA_BIT_TX_QUEUE_3;
1922 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
1923 IPW_DEBUG_TX("TX_QUEUE_4\n");
1924 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
1925 handled |= IPW_INTA_BIT_TX_QUEUE_4;
1928 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
1929 IPW_WARNING("STATUS_CHANGE\n");
1930 handled |= IPW_INTA_BIT_STATUS_CHANGE;
1933 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
1934 IPW_WARNING("TX_PERIOD_EXPIRED\n");
1935 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
1938 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
1939 IPW_WARNING("HOST_CMD_DONE\n");
1940 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
1943 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
1944 IPW_WARNING("FW_INITIALIZATION_DONE\n");
1945 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
1948 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
1949 IPW_WARNING("PHY_OFF_DONE\n");
1950 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
1953 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
1954 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1955 priv->status |= STATUS_RF_KILL_HW;
1956 wake_up_interruptible(&priv->wait_command_queue);
1957 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1958 cancel_delayed_work(&priv->request_scan);
1959 schedule_work(&priv->link_down);
1960 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
1961 handled |= IPW_INTA_BIT_RF_KILL_DONE;
1964 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
1965 IPW_WARNING("Firmware error detected. Restarting.\n");
1967 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
1968 #ifdef CONFIG_IPW2200_DEBUG
1969 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1970 struct ipw_fw_error *error =
1971 ipw_alloc_error_log(priv);
1972 ipw_dump_error_log(priv, error);
1974 ipw_free_error_log(error);
1978 priv->error = ipw_alloc_error_log(priv);
1980 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
1982 IPW_DEBUG_FW("Error allocating sysfs 'error' "
1984 #ifdef CONFIG_IPW2200_DEBUG
1985 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1986 ipw_dump_error_log(priv, priv->error);
1990 /* XXX: If hardware encryption is for WPA/WPA2,
1991 * we have to notify the supplicant. */
1992 if (priv->ieee->sec.encrypt) {
1993 priv->status &= ~STATUS_ASSOCIATED;
1994 notify_wx_assoc_event(priv);
1997 /* Keep the restart process from trying to send host
1998 * commands by clearing the INIT status bit */
1999 priv->status &= ~STATUS_INIT;
2001 /* Cancel currently queued command. */
2002 priv->status &= ~STATUS_HCMD_ACTIVE;
2003 wake_up_interruptible(&priv->wait_command_queue);
2005 queue_work(priv->workqueue, &priv->adapter_restart);
2006 handled |= IPW_INTA_BIT_FATAL_ERROR;
2009 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
2010 IPW_ERROR("Parity error\n");
2011 handled |= IPW_INTA_BIT_PARITY_ERROR;
2014 if (handled != inta) {
2015 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
2018 spin_unlock_irqrestore(&priv->lock, flags);
2020 /* enable all interrupts */
2021 ipw_enable_interrupts(priv);
2024 #define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2025 static char *get_cmd_string(u8 cmd)
2028 IPW_CMD(HOST_COMPLETE);
2029 IPW_CMD(POWER_DOWN);
2030 IPW_CMD(SYSTEM_CONFIG);
2031 IPW_CMD(MULTICAST_ADDRESS);
2033 IPW_CMD(ADAPTER_ADDRESS);
2035 IPW_CMD(RTS_THRESHOLD);
2036 IPW_CMD(FRAG_THRESHOLD);
2037 IPW_CMD(POWER_MODE);
2039 IPW_CMD(TGI_TX_KEY);
2040 IPW_CMD(SCAN_REQUEST);
2041 IPW_CMD(SCAN_REQUEST_EXT);
2043 IPW_CMD(SUPPORTED_RATES);
2044 IPW_CMD(SCAN_ABORT);
2046 IPW_CMD(QOS_PARAMETERS);
2047 IPW_CMD(DINO_CONFIG);
2048 IPW_CMD(RSN_CAPABILITIES);
2050 IPW_CMD(CARD_DISABLE);
2051 IPW_CMD(SEED_NUMBER);
2053 IPW_CMD(COUNTRY_INFO);
2054 IPW_CMD(AIRONET_INFO);
2055 IPW_CMD(AP_TX_POWER);
2057 IPW_CMD(CCX_VER_INFO);
2058 IPW_CMD(SET_CALIBRATION);
2059 IPW_CMD(SENSITIVITY_CALIB);
2060 IPW_CMD(RETRY_LIMIT);
2061 IPW_CMD(IPW_PRE_POWER_DOWN);
2062 IPW_CMD(VAP_BEACON_TEMPLATE);
2063 IPW_CMD(VAP_DTIM_PERIOD);
2064 IPW_CMD(EXT_SUPPORTED_RATES);
2065 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2066 IPW_CMD(VAP_QUIET_INTERVALS);
2067 IPW_CMD(VAP_CHANNEL_SWITCH);
2068 IPW_CMD(VAP_MANDATORY_CHANNELS);
2069 IPW_CMD(VAP_CELL_PWR_LIMIT);
2070 IPW_CMD(VAP_CF_PARAM_SET);
2071 IPW_CMD(VAP_SET_BEACONING_STATE);
2072 IPW_CMD(MEASUREMENT);
2073 IPW_CMD(POWER_CAPABILITY);
2074 IPW_CMD(SUPPORTED_CHANNELS);
2075 IPW_CMD(TPC_REPORT);
2077 IPW_CMD(PRODUCTION_COMMAND);
2083 #define HOST_COMPLETE_TIMEOUT HZ
2085 static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
2088 unsigned long flags;
2090 spin_lock_irqsave(&priv->lock, flags);
2091 if (priv->status & STATUS_HCMD_ACTIVE) {
2092 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2093 get_cmd_string(cmd->cmd));
2094 spin_unlock_irqrestore(&priv->lock, flags);
2098 priv->status |= STATUS_HCMD_ACTIVE;
2101 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2102 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2103 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2104 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2106 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2109 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2110 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2113 #ifndef DEBUG_CMD_WEP_KEY
2114 if (cmd->cmd == IPW_CMD_WEP_KEY)
2115 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2118 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2120 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
2122 priv->status &= ~STATUS_HCMD_ACTIVE;
2123 IPW_ERROR("Failed to send %s: Reason %d\n",
2124 get_cmd_string(cmd->cmd), rc);
2125 spin_unlock_irqrestore(&priv->lock, flags);
2128 spin_unlock_irqrestore(&priv->lock, flags);
2130 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2132 status & STATUS_HCMD_ACTIVE),
2133 HOST_COMPLETE_TIMEOUT);
2135 spin_lock_irqsave(&priv->lock, flags);
2136 if (priv->status & STATUS_HCMD_ACTIVE) {
2137 IPW_ERROR("Failed to send %s: Command timed out.\n",
2138 get_cmd_string(cmd->cmd));
2139 priv->status &= ~STATUS_HCMD_ACTIVE;
2140 spin_unlock_irqrestore(&priv->lock, flags);
2144 spin_unlock_irqrestore(&priv->lock, flags);
2148 if (priv->status & STATUS_RF_KILL_HW) {
2149 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2150 get_cmd_string(cmd->cmd));
2157 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2158 priv->cmdlog_pos %= priv->cmdlog_len;
2163 static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
2165 struct host_cmd cmd = {
2169 return __ipw_send_cmd(priv, &cmd);
2172 static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2175 struct host_cmd cmd = {
2181 return __ipw_send_cmd(priv, &cmd);
2184 static int ipw_send_host_complete(struct ipw_priv *priv)
2187 IPW_ERROR("Invalid args\n");
2191 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
2194 static int ipw_send_system_config(struct ipw_priv *priv)
2196 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2197 sizeof(priv->sys_config),
2201 static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
2203 if (!priv || !ssid) {
2204 IPW_ERROR("Invalid args\n");
2208 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
2212 static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
2214 if (!priv || !mac) {
2215 IPW_ERROR("Invalid args\n");
2219 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2220 priv->net_dev->name, MAC_ARG(mac));
2222 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
2226 * NOTE: This must be executed from our workqueue as it results in udelay
2227 * being called which may corrupt the keyboard if executed on default
2230 static void ipw_adapter_restart(void *adapter)
2232 struct ipw_priv *priv = adapter;
2234 if (priv->status & STATUS_RF_KILL_MASK)
2239 if (priv->assoc_network &&
2240 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2241 ipw_remove_current_network(priv);
2244 IPW_ERROR("Failed to up device\n");
2249 static void ipw_bg_adapter_restart(void *data)
2251 struct ipw_priv *priv = data;
2252 mutex_lock(&priv->mutex);
2253 ipw_adapter_restart(data);
2254 mutex_unlock(&priv->mutex);
2257 #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2259 static void ipw_scan_check(void *data)
2261 struct ipw_priv *priv = data;
2262 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2263 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
2264 "adapter after (%dms).\n",
2265 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
2266 queue_work(priv->workqueue, &priv->adapter_restart);
2270 static void ipw_bg_scan_check(void *data)
2272 struct ipw_priv *priv = data;
2273 mutex_lock(&priv->mutex);
2274 ipw_scan_check(data);
2275 mutex_unlock(&priv->mutex);
2278 static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2279 struct ipw_scan_request_ext *request)
2281 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
2282 sizeof(*request), request);
2285 static int ipw_send_scan_abort(struct ipw_priv *priv)
2288 IPW_ERROR("Invalid args\n");
2292 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
2295 static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2297 struct ipw_sensitivity_calib calib = {
2298 .beacon_rssi_raw = sens,
2301 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
2305 static int ipw_send_associate(struct ipw_priv *priv,
2306 struct ipw_associate *associate)
2308 struct ipw_associate tmp_associate;
2310 if (!priv || !associate) {
2311 IPW_ERROR("Invalid args\n");
2315 memcpy(&tmp_associate, associate, sizeof(*associate));
2316 tmp_associate.policy_support =
2317 cpu_to_le16(tmp_associate.policy_support);
2318 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2319 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2320 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2321 tmp_associate.listen_interval =
2322 cpu_to_le16(tmp_associate.listen_interval);
2323 tmp_associate.beacon_interval =
2324 cpu_to_le16(tmp_associate.beacon_interval);
2325 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2327 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
2331 static int ipw_send_supported_rates(struct ipw_priv *priv,
2332 struct ipw_supported_rates *rates)
2334 if (!priv || !rates) {
2335 IPW_ERROR("Invalid args\n");
2339 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
2343 static int ipw_set_random_seed(struct ipw_priv *priv)
2348 IPW_ERROR("Invalid args\n");
2352 get_random_bytes(&val, sizeof(val));
2354 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
2357 static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2360 IPW_ERROR("Invalid args\n");
2364 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off),
2368 static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
2370 if (!priv || !power) {
2371 IPW_ERROR("Invalid args\n");
2375 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
2378 static int ipw_set_tx_power(struct ipw_priv *priv)
2380 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
2381 struct ipw_tx_power tx_power;
2385 memset(&tx_power, 0, sizeof(tx_power));
2387 /* configure device for 'G' band */
2388 tx_power.ieee_mode = IPW_G_MODE;
2389 tx_power.num_channels = geo->bg_channels;
2390 for (i = 0; i < geo->bg_channels; i++) {
2391 max_power = geo->bg[i].max_power;
2392 tx_power.channels_tx_power[i].channel_number =
2394 tx_power.channels_tx_power[i].tx_power = max_power ?
2395 min(max_power, priv->tx_power) : priv->tx_power;
2397 if (ipw_send_tx_power(priv, &tx_power))
2400 /* configure device to also handle 'B' band */
2401 tx_power.ieee_mode = IPW_B_MODE;
2402 if (ipw_send_tx_power(priv, &tx_power))
2405 /* configure device to also handle 'A' band */
2406 if (priv->ieee->abg_true) {
2407 tx_power.ieee_mode = IPW_A_MODE;
2408 tx_power.num_channels = geo->a_channels;
2409 for (i = 0; i < tx_power.num_channels; i++) {
2410 max_power = geo->a[i].max_power;
2411 tx_power.channels_tx_power[i].channel_number =
2413 tx_power.channels_tx_power[i].tx_power = max_power ?
2414 min(max_power, priv->tx_power) : priv->tx_power;
2416 if (ipw_send_tx_power(priv, &tx_power))
2422 static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2424 struct ipw_rts_threshold rts_threshold = {
2425 .rts_threshold = rts,
2429 IPW_ERROR("Invalid args\n");
2433 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2434 sizeof(rts_threshold), &rts_threshold);
2437 static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2439 struct ipw_frag_threshold frag_threshold = {
2440 .frag_threshold = frag,
2444 IPW_ERROR("Invalid args\n");
2448 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2449 sizeof(frag_threshold), &frag_threshold);
2452 static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2457 IPW_ERROR("Invalid args\n");
2461 /* If on battery, set to 3, if AC set to CAM, else user
2464 case IPW_POWER_BATTERY:
2465 param = IPW_POWER_INDEX_3;
2468 param = IPW_POWER_MODE_CAM;
2475 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
2479 static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2481 struct ipw_retry_limit retry_limit = {
2482 .short_retry_limit = slimit,
2483 .long_retry_limit = llimit
2487 IPW_ERROR("Invalid args\n");
2491 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
2496 * The IPW device contains a Microwire compatible EEPROM that stores
2497 * various data like the MAC address. Usually the firmware has exclusive
2498 * access to the eeprom, but during device initialization (before the
2499 * device driver has sent the HostComplete command to the firmware) the
2500 * device driver has read access to the EEPROM by way of indirect addressing
2501 * through a couple of memory mapped registers.
2503 * The following is a simplified implementation for pulling data out of the
2504 * the eeprom, along with some helper functions to find information in
2505 * the per device private data's copy of the eeprom.
2507 * NOTE: To better understand how these functions work (i.e what is a chip
2508 * select and why do have to keep driving the eeprom clock?), read
2509 * just about any data sheet for a Microwire compatible EEPROM.
2512 /* write a 32 bit value into the indirect accessor register */
2513 static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2515 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
2517 /* the eeprom requires some time to complete the operation */
2518 udelay(p->eeprom_delay);
2523 /* perform a chip select operation */
2524 static void eeprom_cs(struct ipw_priv *priv)
2526 eeprom_write_reg(priv, 0);
2527 eeprom_write_reg(priv, EEPROM_BIT_CS);
2528 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2529 eeprom_write_reg(priv, EEPROM_BIT_CS);
2532 /* perform a chip select operation */
2533 static void eeprom_disable_cs(struct ipw_priv *priv)
2535 eeprom_write_reg(priv, EEPROM_BIT_CS);
2536 eeprom_write_reg(priv, 0);
2537 eeprom_write_reg(priv, EEPROM_BIT_SK);
2540 /* push a single bit down to the eeprom */
2541 static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
2543 int d = (bit ? EEPROM_BIT_DI : 0);
2544 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2545 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
2548 /* push an opcode followed by an address down to the eeprom */
2549 static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
2554 eeprom_write_bit(priv, 1);
2555 eeprom_write_bit(priv, op & 2);
2556 eeprom_write_bit(priv, op & 1);
2557 for (i = 7; i >= 0; i--) {
2558 eeprom_write_bit(priv, addr & (1 << i));
2562 /* pull 16 bits off the eeprom, one bit at a time */
2563 static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
2568 /* Send READ Opcode */
2569 eeprom_op(priv, EEPROM_CMD_READ, addr);
2571 /* Send dummy bit */
2572 eeprom_write_reg(priv, EEPROM_BIT_CS);
2574 /* Read the byte off the eeprom one bit at a time */
2575 for (i = 0; i < 16; i++) {
2577 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2578 eeprom_write_reg(priv, EEPROM_BIT_CS);
2579 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2580 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
2583 /* Send another dummy bit */
2584 eeprom_write_reg(priv, 0);
2585 eeprom_disable_cs(priv);
2590 /* helper function for pulling the mac address out of the private */
2591 /* data's copy of the eeprom data */
2592 static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
2594 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
2598 * Either the device driver (i.e. the host) or the firmware can
2599 * load eeprom data into the designated region in SRAM. If neither
2600 * happens then the FW will shutdown with a fatal error.
2602 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2603 * bit needs region of shared SRAM needs to be non-zero.
2605 static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2608 u16 *eeprom = (u16 *) priv->eeprom;
2610 IPW_DEBUG_TRACE(">>\n");
2612 /* read entire contents of eeprom into private buffer */
2613 for (i = 0; i < 128; i++)
2614 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
2617 If the data looks correct, then copy it to our private
2618 copy. Otherwise let the firmware know to perform the operation
2621 if (priv->eeprom[EEPROM_VERSION] != 0) {
2622 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2624 /* write the eeprom data to sram */
2625 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
2626 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
2628 /* Do not load eeprom data on fatal error or suspend */
2629 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2631 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2633 /* Load eeprom data on fatal error or suspend */
2634 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2637 IPW_DEBUG_TRACE("<<\n");
2640 static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
2645 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
2647 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
2650 static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2652 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
2653 CB_NUMBER_OF_ELEMENTS_SMALL *
2654 sizeof(struct command_block));
2657 static int ipw_fw_dma_enable(struct ipw_priv *priv)
2658 { /* start dma engine but no transfers yet */
2660 IPW_DEBUG_FW(">> : \n");
2663 ipw_fw_dma_reset_command_blocks(priv);
2665 /* Write CB base address */
2666 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
2668 IPW_DEBUG_FW("<< : \n");
2672 static void ipw_fw_dma_abort(struct ipw_priv *priv)
2676 IPW_DEBUG_FW(">> :\n");
2678 //set the Stop and Abort bit
2679 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
2680 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2681 priv->sram_desc.last_cb_index = 0;
2683 IPW_DEBUG_FW("<< \n");
2686 static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2687 struct command_block *cb)
2690 IPW_SHARED_SRAM_DMA_CONTROL +
2691 (sizeof(struct command_block) * index);
2692 IPW_DEBUG_FW(">> :\n");
2694 ipw_write_indirect(priv, address, (u8 *) cb,
2695 (int)sizeof(struct command_block));
2697 IPW_DEBUG_FW("<< :\n");
2702 static int ipw_fw_dma_kick(struct ipw_priv *priv)
2707 IPW_DEBUG_FW(">> :\n");
2709 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
2710 ipw_fw_dma_write_command_block(priv, index,
2711 &priv->sram_desc.cb_list[index]);
2713 /* Enable the DMA in the CSR register */
2714 ipw_clear_bit(priv, IPW_RESET_REG,
2715 IPW_RESET_REG_MASTER_DISABLED |
2716 IPW_RESET_REG_STOP_MASTER);
2718 /* Set the Start bit. */
2719 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
2720 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2722 IPW_DEBUG_FW("<< :\n");
2726 static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2729 u32 register_value = 0;
2730 u32 cb_fields_address = 0;
2732 IPW_DEBUG_FW(">> :\n");
2733 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2734 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
2736 /* Read the DMA Controlor register */
2737 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2738 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
2740 /* Print the CB values */
2741 cb_fields_address = address;
2742 register_value = ipw_read_reg32(priv, cb_fields_address);
2743 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
2745 cb_fields_address += sizeof(u32);
2746 register_value = ipw_read_reg32(priv, cb_fields_address);
2747 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
2749 cb_fields_address += sizeof(u32);
2750 register_value = ipw_read_reg32(priv, cb_fields_address);
2751 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2754 cb_fields_address += sizeof(u32);
2755 register_value = ipw_read_reg32(priv, cb_fields_address);
2756 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
2758 IPW_DEBUG_FW(">> :\n");
2761 static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2763 u32 current_cb_address = 0;
2764 u32 current_cb_index = 0;
2766 IPW_DEBUG_FW("<< :\n");
2767 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2769 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
2770 sizeof(struct command_block);
2772 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
2773 current_cb_index, current_cb_address);
2775 IPW_DEBUG_FW(">> :\n");
2776 return current_cb_index;
2780 static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2784 int interrupt_enabled, int is_last)
2787 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
2788 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2790 struct command_block *cb;
2791 u32 last_cb_element = 0;
2793 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2794 src_address, dest_address, length);
2796 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2799 last_cb_element = priv->sram_desc.last_cb_index;
2800 cb = &priv->sram_desc.cb_list[last_cb_element];
2801 priv->sram_desc.last_cb_index++;
2803 /* Calculate the new CB control word */
2804 if (interrupt_enabled)
2805 control |= CB_INT_ENABLED;
2808 control |= CB_LAST_VALID;
2812 /* Calculate the CB Element's checksum value */
2813 cb->status = control ^ src_address ^ dest_address;
2815 /* Copy the Source and Destination addresses */
2816 cb->dest_addr = dest_address;
2817 cb->source_addr = src_address;
2819 /* Copy the Control Word last */
2820 cb->control = control;
2825 static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
2826 u32 src_phys, u32 dest_address, u32 length)
2828 u32 bytes_left = length;
2830 u32 dest_offset = 0;
2832 IPW_DEBUG_FW(">> \n");
2833 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2834 src_phys, dest_address, length);
2835 while (bytes_left > CB_MAX_LENGTH) {
2836 status = ipw_fw_dma_add_command_block(priv,
2837 src_phys + src_offset,
2840 CB_MAX_LENGTH, 0, 0);
2842 IPW_DEBUG_FW_INFO(": Failed\n");
2845 IPW_DEBUG_FW_INFO(": Added new cb\n");
2847 src_offset += CB_MAX_LENGTH;
2848 dest_offset += CB_MAX_LENGTH;
2849 bytes_left -= CB_MAX_LENGTH;
2852 /* add the buffer tail */
2853 if (bytes_left > 0) {
2855 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2856 dest_address + dest_offset,
2859 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2863 (": Adding new cb - the buffer tail\n");
2866 IPW_DEBUG_FW("<< \n");
2870 static int ipw_fw_dma_wait(struct ipw_priv *priv)
2872 u32 current_index = 0, previous_index;
2875 IPW_DEBUG_FW(">> : \n");
2877 current_index = ipw_fw_dma_command_block_index(priv);
2878 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
2879 (int)priv->sram_desc.last_cb_index);
2881 while (current_index < priv->sram_desc.last_cb_index) {
2883 previous_index = current_index;
2884 current_index = ipw_fw_dma_command_block_index(priv);
2886 if (previous_index < current_index) {
2890 if (++watchdog > 400) {
2891 IPW_DEBUG_FW_INFO("Timeout\n");
2892 ipw_fw_dma_dump_command_block(priv);
2893 ipw_fw_dma_abort(priv);
2898 ipw_fw_dma_abort(priv);
2900 /*Disable the DMA in the CSR register */
2901 ipw_set_bit(priv, IPW_RESET_REG,
2902 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
2904 IPW_DEBUG_FW("<< dmaWaitSync \n");
2908 static void ipw_remove_current_network(struct ipw_priv *priv)
2910 struct list_head *element, *safe;
2911 struct ieee80211_network *network = NULL;
2912 unsigned long flags;
2914 spin_lock_irqsave(&priv->ieee->lock, flags);
2915 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2916 network = list_entry(element, struct ieee80211_network, list);
2917 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2919 list_add_tail(&network->list,
2920 &priv->ieee->network_free_list);
2923 spin_unlock_irqrestore(&priv->ieee->lock, flags);
2927 * Check that card is still alive.
2928 * Reads debug register from domain0.
2929 * If card is present, pre-defined value should
2933 * @return 1 if card is present, 0 otherwise
2935 static inline int ipw_alive(struct ipw_priv *priv)
2937 return ipw_read32(priv, 0x90) == 0xd55555d5;
2940 /* timeout in msec, attempted in 10-msec quanta */
2941 static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2947 if ((ipw_read32(priv, addr) & mask) == mask)
2951 } while (i < timeout);
2956 /* These functions load the firmware and micro code for the operation of
2957 * the ipw hardware. It assumes the buffer has all the bits for the
2958 * image and the caller is handling the memory allocation and clean up.
2961 static int ipw_stop_master(struct ipw_priv *priv)
2965 IPW_DEBUG_TRACE(">> \n");
2966 /* stop master. typical delay - 0 */
2967 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
2969 /* timeout is in msec, polled in 10-msec quanta */
2970 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2971 IPW_RESET_REG_MASTER_DISABLED, 100);
2973 IPW_ERROR("wait for stop master failed after 100ms\n");
2977 IPW_DEBUG_INFO("stop master %dms\n", rc);
2982 static void ipw_arc_release(struct ipw_priv *priv)
2984 IPW_DEBUG_TRACE(">> \n");
2987 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
2989 /* no one knows timing, for safety add some delay */
2998 static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
3000 int rc = 0, i, addr;
3004 image = (u16 *) data;
3006 IPW_DEBUG_TRACE(">> \n");
3008 rc = ipw_stop_master(priv);
3013 // spin_lock_irqsave(&priv->lock, flags);
3015 for (addr = IPW_SHARED_LOWER_BOUND;
3016 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
3017 ipw_write32(priv, addr, 0);
3020 /* no ucode (yet) */
3021 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3022 /* destroy DMA queues */
3023 /* reset sequence */
3025 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
3026 ipw_arc_release(priv);
3027 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
3031 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
3034 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
3037 /* enable ucode store */
3038 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3039 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
3045 * Do NOT set indirect address register once and then
3046 * store data to indirect data register in the loop.
3047 * It seems very reasonable, but in this case DINO do not
3048 * accept ucode. It is essential to set address each time.
3050 /* load new ipw uCode */
3051 for (i = 0; i < len / 2; i++)
3052 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
3053 cpu_to_le16(image[i]));
3056 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3057 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
3059 /* this is where the igx / win driver deveates from the VAP driver. */
3061 /* wait for alive response */
3062 for (i = 0; i < 100; i++) {
3063 /* poll for incoming data */
3064 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
3065 if (cr & DINO_RXFIFO_DATA)
3070 if (cr & DINO_RXFIFO_DATA) {
3071 /* alive_command_responce size is NOT multiple of 4 */
3072 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
3074 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
3075 response_buffer[i] =
3076 le32_to_cpu(ipw_read_reg32(priv,
3077 IPW_BASEBAND_RX_FIFO_READ));
3078 memcpy(&priv->dino_alive, response_buffer,
3079 sizeof(priv->dino_alive));
3080 if (priv->dino_alive.alive_command == 1
3081 && priv->dino_alive.ucode_valid == 1) {
3084 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3085 "of %02d/%02d/%02d %02d:%02d\n",
3086 priv->dino_alive.software_revision,
3087 priv->dino_alive.software_revision,
3088 priv->dino_alive.device_identifier,
3089 priv->dino_alive.device_identifier,
3090 priv->dino_alive.time_stamp[0],
3091 priv->dino_alive.time_stamp[1],
3092 priv->dino_alive.time_stamp[2],
3093 priv->dino_alive.time_stamp[3],
3094 priv->dino_alive.time_stamp[4]);
3096 IPW_DEBUG_INFO("Microcode is not alive\n");
3100 IPW_DEBUG_INFO("No alive response from DINO\n");
3104 /* disable DINO, otherwise for some reason
3105 firmware have problem getting alive resp. */
3106 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3108 // spin_unlock_irqrestore(&priv->lock, flags);
3113 static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
3117 struct fw_chunk *chunk;
3118 dma_addr_t shared_phys;
3121 IPW_DEBUG_TRACE("<< : \n");
3122 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
3127 memmove(shared_virt, data, len);
3130 rc = ipw_fw_dma_enable(priv);
3132 if (priv->sram_desc.last_cb_index > 0) {
3133 /* the DMA is already ready this would be a bug. */
3139 chunk = (struct fw_chunk *)(data + offset);
3140 offset += sizeof(struct fw_chunk);
3141 /* build DMA packet and queue up for sending */
3142 /* dma to chunk->address, the chunk->length bytes from data +
3145 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
3146 le32_to_cpu(chunk->address),
3147 le32_to_cpu(chunk->length));
3149 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3153 offset += le32_to_cpu(chunk->length);
3154 } while (offset < len);
3156 /* Run the DMA and wait for the answer */
3157 rc = ipw_fw_dma_kick(priv);
3159 IPW_ERROR("dmaKick Failed\n");
3163 rc = ipw_fw_dma_wait(priv);
3165 IPW_ERROR("dmaWaitSync Failed\n");
3169 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
3174 static int ipw_stop_nic(struct ipw_priv *priv)
3179 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
3181 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3182 IPW_RESET_REG_MASTER_DISABLED, 500);
3184 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
3188 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
3193 static void ipw_start_nic(struct ipw_priv *priv)
3195 IPW_DEBUG_TRACE(">>\n");
3197 /* prvHwStartNic release ARC */
3198 ipw_clear_bit(priv, IPW_RESET_REG,
3199 IPW_RESET_REG_MASTER_DISABLED |
3200 IPW_RESET_REG_STOP_MASTER |
3201 CBD_RESET_REG_PRINCETON_RESET);
3203 /* enable power management */
3204 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3205 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
3207 IPW_DEBUG_TRACE("<<\n");
3210 static int ipw_init_nic(struct ipw_priv *priv)
3214 IPW_DEBUG_TRACE(">>\n");
3217 /* set "initialization complete" bit to move adapter to D0 state */
3218 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3220 /* low-level PLL activation */
3221 ipw_write32(priv, IPW_READ_INT_REGISTER,
3222 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
3224 /* wait for clock stabilization */
3225 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3226 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
3228 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3230 /* assert SW reset */
3231 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
3235 /* set "initialization complete" bit to move adapter to D0 state */
3236 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3238 IPW_DEBUG_TRACE(">>\n");
3242 /* Call this function from process context, it will sleep in request_firmware.
3243 * Probe is an ok place to call this from.
3245 static int ipw_reset_nic(struct ipw_priv *priv)
3248 unsigned long flags;
3250 IPW_DEBUG_TRACE(">>\n");
3252 rc = ipw_init_nic(priv);
3254 spin_lock_irqsave(&priv->lock, flags);
3255 /* Clear the 'host command active' bit... */
3256 priv->status &= ~STATUS_HCMD_ACTIVE;
3257 wake_up_interruptible(&priv->wait_command_queue);
3258 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3259 wake_up_interruptible(&priv->wait_state);
3260 spin_unlock_irqrestore(&priv->lock, flags);
3262 IPW_DEBUG_TRACE("<<\n");
3275 static int ipw_get_fw(struct ipw_priv *priv,
3276 const struct firmware **raw, const char *name)
3281 /* ask firmware_class module to get the boot firmware off disk */
3282 rc = request_firmware(raw, name, &priv->pci_dev->dev);
3284 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
3288 if ((*raw)->size < sizeof(*fw)) {
3289 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
3293 fw = (void *)(*raw)->data;
3295 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3296 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
3297 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3298 name, (*raw)->size);
3302 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
3304 le32_to_cpu(fw->ver) >> 16,
3305 le32_to_cpu(fw->ver) & 0xff,
3306 (*raw)->size - sizeof(*fw));
3310 #define IPW_RX_BUF_SIZE (3000)
3312 static void ipw_rx_queue_reset(struct ipw_priv *priv,
3313 struct ipw_rx_queue *rxq)
3315 unsigned long flags;
3318 spin_lock_irqsave(&rxq->lock, flags);