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 ssize_t show_event_log(struct device *d,
1233 struct device_attribute *attr, char *buf)
1235 struct ipw_priv *priv = dev_get_drvdata(d);
1236 u32 log_len = ipw_get_event_log_len(priv);
1237 struct ipw_event log[log_len];
1240 ipw_capture_event_log(priv, log_len, log);
1242 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1243 for (i = 0; i < log_len; i++)
1244 len += snprintf(buf + len, PAGE_SIZE - len,
1246 log[i].time, log[i].event, log[i].data);
1247 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1251 static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1253 static ssize_t show_error(struct device *d,
1254 struct device_attribute *attr, char *buf)
1256 struct ipw_priv *priv = dev_get_drvdata(d);
1260 len += snprintf(buf + len, PAGE_SIZE - len,
1261 "%08lX%08X%08X%08X",
1262 priv->error->jiffies,
1263 priv->error->status,
1264 priv->error->config, priv->error->elem_len);
1265 for (i = 0; i < priv->error->elem_len; i++)
1266 len += snprintf(buf + len, PAGE_SIZE - len,
1267 "\n%08X%08X%08X%08X%08X%08X%08X",
1268 priv->error->elem[i].time,
1269 priv->error->elem[i].desc,
1270 priv->error->elem[i].blink1,
1271 priv->error->elem[i].blink2,
1272 priv->error->elem[i].link1,
1273 priv->error->elem[i].link2,
1274 priv->error->elem[i].data);
1276 len += snprintf(buf + len, PAGE_SIZE - len,
1277 "\n%08X", priv->error->log_len);
1278 for (i = 0; i < priv->error->log_len; i++)
1279 len += snprintf(buf + len, PAGE_SIZE - len,
1281 priv->error->log[i].time,
1282 priv->error->log[i].event,
1283 priv->error->log[i].data);
1284 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1288 static ssize_t clear_error(struct device *d,
1289 struct device_attribute *attr,
1290 const char *buf, size_t count)
1292 struct ipw_priv *priv = dev_get_drvdata(d);
1299 static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1301 static ssize_t show_cmd_log(struct device *d,
1302 struct device_attribute *attr, char *buf)
1304 struct ipw_priv *priv = dev_get_drvdata(d);
1308 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1309 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1310 i = (i + 1) % priv->cmdlog_len) {
1312 snprintf(buf + len, PAGE_SIZE - len,
1313 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1314 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1315 priv->cmdlog[i].cmd.len);
1317 snprintk_buf(buf + len, PAGE_SIZE - len,
1318 (u8 *) priv->cmdlog[i].cmd.param,
1319 priv->cmdlog[i].cmd.len);
1320 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1322 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1326 static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1328 #ifdef CONFIG_IPW2200_PROMISCUOUS
1329 static void ipw_prom_free(struct ipw_priv *priv);
1330 static int ipw_prom_alloc(struct ipw_priv *priv);
1331 static ssize_t store_rtap_iface(struct device *d,
1332 struct device_attribute *attr,
1333 const char *buf, size_t count)
1335 struct ipw_priv *priv = dev_get_drvdata(d);
1346 if (netif_running(priv->prom_net_dev)) {
1347 IPW_WARNING("Interface is up. Cannot unregister.\n");
1351 ipw_prom_free(priv);
1359 rc = ipw_prom_alloc(priv);
1369 IPW_ERROR("Failed to register promiscuous network "
1370 "device (error %d).\n", rc);
1376 static ssize_t show_rtap_iface(struct device *d,
1377 struct device_attribute *attr,
1380 struct ipw_priv *priv = dev_get_drvdata(d);
1382 return sprintf(buf, "%s", priv->prom_net_dev->name);
1391 static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1394 static ssize_t store_rtap_filter(struct device *d,
1395 struct device_attribute *attr,
1396 const char *buf, size_t count)
1398 struct ipw_priv *priv = dev_get_drvdata(d);
1400 if (!priv->prom_priv) {
1401 IPW_ERROR("Attempting to set filter without "
1402 "rtap_iface enabled.\n");
1406 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1408 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1409 BIT_ARG16(priv->prom_priv->filter));
1414 static ssize_t show_rtap_filter(struct device *d,
1415 struct device_attribute *attr,
1418 struct ipw_priv *priv = dev_get_drvdata(d);
1419 return sprintf(buf, "0x%04X",
1420 priv->prom_priv ? priv->prom_priv->filter : 0);
1423 static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1427 static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1430 struct ipw_priv *priv = dev_get_drvdata(d);
1431 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1434 static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1435 const char *buf, size_t count)
1437 struct ipw_priv *priv = dev_get_drvdata(d);
1438 #ifdef CONFIG_IPW2200_DEBUG
1439 struct net_device *dev = priv->net_dev;
1441 char buffer[] = "00000000";
1443 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1447 IPW_DEBUG_INFO("enter\n");
1449 strncpy(buffer, buf, len);
1452 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1454 if (p[0] == 'x' || p[0] == 'X')
1456 val = simple_strtoul(p, &p, 16);
1458 val = simple_strtoul(p, &p, 10);
1460 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1462 priv->ieee->scan_age = val;
1463 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1466 IPW_DEBUG_INFO("exit\n");
1470 static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1472 static ssize_t show_led(struct device *d, struct device_attribute *attr,
1475 struct ipw_priv *priv = dev_get_drvdata(d);
1476 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1479 static ssize_t store_led(struct device *d, struct device_attribute *attr,
1480 const char *buf, size_t count)
1482 struct ipw_priv *priv = dev_get_drvdata(d);
1484 IPW_DEBUG_INFO("enter\n");
1490 IPW_DEBUG_LED("Disabling LED control.\n");
1491 priv->config |= CFG_NO_LED;
1492 ipw_led_shutdown(priv);
1494 IPW_DEBUG_LED("Enabling LED control.\n");
1495 priv->config &= ~CFG_NO_LED;
1499 IPW_DEBUG_INFO("exit\n");
1503 static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1505 static ssize_t show_status(struct device *d,
1506 struct device_attribute *attr, char *buf)
1508 struct ipw_priv *p = d->driver_data;
1509 return sprintf(buf, "0x%08x\n", (int)p->status);
1512 static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1514 static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1517 struct ipw_priv *p = d->driver_data;
1518 return sprintf(buf, "0x%08x\n", (int)p->config);
1521 static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1523 static ssize_t show_nic_type(struct device *d,
1524 struct device_attribute *attr, char *buf)
1526 struct ipw_priv *priv = d->driver_data;
1527 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
1530 static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1532 static ssize_t show_ucode_version(struct device *d,
1533 struct device_attribute *attr, char *buf)
1535 u32 len = sizeof(u32), tmp = 0;
1536 struct ipw_priv *p = d->driver_data;
1538 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
1541 return sprintf(buf, "0x%08x\n", tmp);
1544 static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
1546 static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1549 u32 len = sizeof(u32), tmp = 0;
1550 struct ipw_priv *p = d->driver_data;
1552 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
1555 return sprintf(buf, "0x%08x\n", tmp);
1558 static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
1561 * Add a device attribute to view/control the delay between eeprom
1564 static ssize_t show_eeprom_delay(struct device *d,
1565 struct device_attribute *attr, char *buf)
1567 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
1568 return sprintf(buf, "%i\n", n);
1570 static ssize_t store_eeprom_delay(struct device *d,
1571 struct device_attribute *attr,
1572 const char *buf, size_t count)
1574 struct ipw_priv *p = d->driver_data;
1575 sscanf(buf, "%i", &p->eeprom_delay);
1576 return strnlen(buf, count);
1579 static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1580 show_eeprom_delay, store_eeprom_delay);
1582 static ssize_t show_command_event_reg(struct device *d,
1583 struct device_attribute *attr, char *buf)
1586 struct ipw_priv *p = d->driver_data;
1588 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
1589 return sprintf(buf, "0x%08x\n", reg);
1591 static ssize_t store_command_event_reg(struct device *d,
1592 struct device_attribute *attr,
1593 const char *buf, size_t count)
1596 struct ipw_priv *p = d->driver_data;
1598 sscanf(buf, "%x", ®);
1599 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
1600 return strnlen(buf, count);
1603 static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1604 show_command_event_reg, store_command_event_reg);
1606 static ssize_t show_mem_gpio_reg(struct device *d,
1607 struct device_attribute *attr, char *buf)
1610 struct ipw_priv *p = d->driver_data;
1612 reg = ipw_read_reg32(p, 0x301100);
1613 return sprintf(buf, "0x%08x\n", reg);
1615 static ssize_t store_mem_gpio_reg(struct device *d,
1616 struct device_attribute *attr,
1617 const char *buf, size_t count)
1620 struct ipw_priv *p = d->driver_data;
1622 sscanf(buf, "%x", ®);
1623 ipw_write_reg32(p, 0x301100, reg);
1624 return strnlen(buf, count);
1627 static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1628 show_mem_gpio_reg, store_mem_gpio_reg);
1630 static ssize_t show_indirect_dword(struct device *d,
1631 struct device_attribute *attr, char *buf)
1634 struct ipw_priv *priv = d->driver_data;
1636 if (priv->status & STATUS_INDIRECT_DWORD)
1637 reg = ipw_read_reg32(priv, priv->indirect_dword);
1641 return sprintf(buf, "0x%08x\n", reg);
1643 static ssize_t store_indirect_dword(struct device *d,
1644 struct device_attribute *attr,
1645 const char *buf, size_t count)
1647 struct ipw_priv *priv = d->driver_data;
1649 sscanf(buf, "%x", &priv->indirect_dword);
1650 priv->status |= STATUS_INDIRECT_DWORD;
1651 return strnlen(buf, count);
1654 static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1655 show_indirect_dword, store_indirect_dword);
1657 static ssize_t show_indirect_byte(struct device *d,
1658 struct device_attribute *attr, char *buf)
1661 struct ipw_priv *priv = d->driver_data;
1663 if (priv->status & STATUS_INDIRECT_BYTE)
1664 reg = ipw_read_reg8(priv, priv->indirect_byte);
1668 return sprintf(buf, "0x%02x\n", reg);
1670 static ssize_t store_indirect_byte(struct device *d,
1671 struct device_attribute *attr,
1672 const char *buf, size_t count)
1674 struct ipw_priv *priv = d->driver_data;
1676 sscanf(buf, "%x", &priv->indirect_byte);
1677 priv->status |= STATUS_INDIRECT_BYTE;
1678 return strnlen(buf, count);
1681 static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
1682 show_indirect_byte, store_indirect_byte);
1684 static ssize_t show_direct_dword(struct device *d,
1685 struct device_attribute *attr, char *buf)
1688 struct ipw_priv *priv = d->driver_data;
1690 if (priv->status & STATUS_DIRECT_DWORD)
1691 reg = ipw_read32(priv, priv->direct_dword);
1695 return sprintf(buf, "0x%08x\n", reg);
1697 static ssize_t store_direct_dword(struct device *d,
1698 struct device_attribute *attr,
1699 const char *buf, size_t count)
1701 struct ipw_priv *priv = d->driver_data;
1703 sscanf(buf, "%x", &priv->direct_dword);
1704 priv->status |= STATUS_DIRECT_DWORD;
1705 return strnlen(buf, count);
1708 static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1709 show_direct_dword, store_direct_dword);
1711 static int rf_kill_active(struct ipw_priv *priv)
1713 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1714 priv->status |= STATUS_RF_KILL_HW;
1716 priv->status &= ~STATUS_RF_KILL_HW;
1718 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1721 static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
1724 /* 0 - RF kill not enabled
1725 1 - SW based RF kill active (sysfs)
1726 2 - HW based RF kill active
1727 3 - Both HW and SW baed RF kill active */
1728 struct ipw_priv *priv = d->driver_data;
1729 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
1730 (rf_kill_active(priv) ? 0x2 : 0x0);
1731 return sprintf(buf, "%i\n", val);
1734 static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1736 if ((disable_radio ? 1 : 0) ==
1737 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
1740 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1741 disable_radio ? "OFF" : "ON");
1743 if (disable_radio) {
1744 priv->status |= STATUS_RF_KILL_SW;
1746 if (priv->workqueue)
1747 cancel_delayed_work(&priv->request_scan);
1748 queue_work(priv->workqueue, &priv->down);
1750 priv->status &= ~STATUS_RF_KILL_SW;
1751 if (rf_kill_active(priv)) {
1752 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1753 "disabled by HW switch\n");
1754 /* Make sure the RF_KILL check timer is running */
1755 cancel_delayed_work(&priv->rf_kill);
1756 queue_delayed_work(priv->workqueue, &priv->rf_kill,
1759 queue_work(priv->workqueue, &priv->up);
1765 static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1766 const char *buf, size_t count)
1768 struct ipw_priv *priv = d->driver_data;
1770 ipw_radio_kill_sw(priv, buf[0] == '1');
1775 static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
1777 static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1780 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1781 int pos = 0, len = 0;
1782 if (priv->config & CFG_SPEED_SCAN) {
1783 while (priv->speed_scan[pos] != 0)
1784 len += sprintf(&buf[len], "%d ",
1785 priv->speed_scan[pos++]);
1786 return len + sprintf(&buf[len], "\n");
1789 return sprintf(buf, "0\n");
1792 static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1793 const char *buf, size_t count)
1795 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1796 int channel, pos = 0;
1797 const char *p = buf;
1799 /* list of space separated channels to scan, optionally ending with 0 */
1800 while ((channel = simple_strtol(p, NULL, 0))) {
1801 if (pos == MAX_SPEED_SCAN - 1) {
1802 priv->speed_scan[pos] = 0;
1806 if (ieee80211_is_valid_channel(priv->ieee, channel))
1807 priv->speed_scan[pos++] = channel;
1809 IPW_WARNING("Skipping invalid channel request: %d\n",
1814 while (*p == ' ' || *p == '\t')
1819 priv->config &= ~CFG_SPEED_SCAN;
1821 priv->speed_scan_pos = 0;
1822 priv->config |= CFG_SPEED_SCAN;
1828 static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1831 static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1834 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1835 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1838 static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1839 const char *buf, size_t count)
1841 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1843 priv->config |= CFG_NET_STATS;
1845 priv->config &= ~CFG_NET_STATS;
1850 static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1851 show_net_stats, store_net_stats);
1853 static void notify_wx_assoc_event(struct ipw_priv *priv)
1855 union iwreq_data wrqu;
1856 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1857 if (priv->status & STATUS_ASSOCIATED)
1858 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1860 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1861 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1864 static void ipw_irq_tasklet(struct ipw_priv *priv)
1866 u32 inta, inta_mask, handled = 0;
1867 unsigned long flags;
1870 spin_lock_irqsave(&priv->irq_lock, flags);
1872 inta = ipw_read32(priv, IPW_INTA_RW);
1873 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1874 inta &= (IPW_INTA_MASK_ALL & inta_mask);
1876 /* Add any cached INTA values that need to be handled */
1877 inta |= priv->isr_inta;
1879 spin_unlock_irqrestore(&priv->irq_lock, flags);
1881 spin_lock_irqsave(&priv->lock, flags);
1883 /* handle all the justifications for the interrupt */
1884 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
1886 handled |= IPW_INTA_BIT_RX_TRANSFER;
1889 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
1890 IPW_DEBUG_HC("Command completed.\n");
1891 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
1892 priv->status &= ~STATUS_HCMD_ACTIVE;
1893 wake_up_interruptible(&priv->wait_command_queue);
1894 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
1897 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
1898 IPW_DEBUG_TX("TX_QUEUE_1\n");
1899 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
1900 handled |= IPW_INTA_BIT_TX_QUEUE_1;
1903 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
1904 IPW_DEBUG_TX("TX_QUEUE_2\n");
1905 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
1906 handled |= IPW_INTA_BIT_TX_QUEUE_2;
1909 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
1910 IPW_DEBUG_TX("TX_QUEUE_3\n");
1911 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
1912 handled |= IPW_INTA_BIT_TX_QUEUE_3;
1915 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
1916 IPW_DEBUG_TX("TX_QUEUE_4\n");
1917 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
1918 handled |= IPW_INTA_BIT_TX_QUEUE_4;
1921 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
1922 IPW_WARNING("STATUS_CHANGE\n");
1923 handled |= IPW_INTA_BIT_STATUS_CHANGE;
1926 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
1927 IPW_WARNING("TX_PERIOD_EXPIRED\n");
1928 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
1931 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
1932 IPW_WARNING("HOST_CMD_DONE\n");
1933 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
1936 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
1937 IPW_WARNING("FW_INITIALIZATION_DONE\n");
1938 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
1941 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
1942 IPW_WARNING("PHY_OFF_DONE\n");
1943 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
1946 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
1947 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1948 priv->status |= STATUS_RF_KILL_HW;
1949 wake_up_interruptible(&priv->wait_command_queue);
1950 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1951 cancel_delayed_work(&priv->request_scan);
1952 schedule_work(&priv->link_down);
1953 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
1954 handled |= IPW_INTA_BIT_RF_KILL_DONE;
1957 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
1958 IPW_WARNING("Firmware error detected. Restarting.\n");
1960 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
1961 #ifdef CONFIG_IPW2200_DEBUG
1962 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1963 struct ipw_fw_error *error =
1964 ipw_alloc_error_log(priv);
1965 ipw_dump_error_log(priv, error);
1970 priv->error = ipw_alloc_error_log(priv);
1972 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
1974 IPW_DEBUG_FW("Error allocating sysfs 'error' "
1976 #ifdef CONFIG_IPW2200_DEBUG
1977 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1978 ipw_dump_error_log(priv, priv->error);
1982 /* XXX: If hardware encryption is for WPA/WPA2,
1983 * we have to notify the supplicant. */
1984 if (priv->ieee->sec.encrypt) {
1985 priv->status &= ~STATUS_ASSOCIATED;
1986 notify_wx_assoc_event(priv);
1989 /* Keep the restart process from trying to send host
1990 * commands by clearing the INIT status bit */
1991 priv->status &= ~STATUS_INIT;
1993 /* Cancel currently queued command. */
1994 priv->status &= ~STATUS_HCMD_ACTIVE;
1995 wake_up_interruptible(&priv->wait_command_queue);
1997 queue_work(priv->workqueue, &priv->adapter_restart);
1998 handled |= IPW_INTA_BIT_FATAL_ERROR;
2001 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
2002 IPW_ERROR("Parity error\n");
2003 handled |= IPW_INTA_BIT_PARITY_ERROR;
2006 if (handled != inta) {
2007 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
2010 spin_unlock_irqrestore(&priv->lock, flags);
2012 /* enable all interrupts */
2013 ipw_enable_interrupts(priv);
2016 #define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2017 static char *get_cmd_string(u8 cmd)
2020 IPW_CMD(HOST_COMPLETE);
2021 IPW_CMD(POWER_DOWN);
2022 IPW_CMD(SYSTEM_CONFIG);
2023 IPW_CMD(MULTICAST_ADDRESS);
2025 IPW_CMD(ADAPTER_ADDRESS);
2027 IPW_CMD(RTS_THRESHOLD);
2028 IPW_CMD(FRAG_THRESHOLD);
2029 IPW_CMD(POWER_MODE);
2031 IPW_CMD(TGI_TX_KEY);
2032 IPW_CMD(SCAN_REQUEST);
2033 IPW_CMD(SCAN_REQUEST_EXT);
2035 IPW_CMD(SUPPORTED_RATES);
2036 IPW_CMD(SCAN_ABORT);
2038 IPW_CMD(QOS_PARAMETERS);
2039 IPW_CMD(DINO_CONFIG);
2040 IPW_CMD(RSN_CAPABILITIES);
2042 IPW_CMD(CARD_DISABLE);
2043 IPW_CMD(SEED_NUMBER);
2045 IPW_CMD(COUNTRY_INFO);
2046 IPW_CMD(AIRONET_INFO);
2047 IPW_CMD(AP_TX_POWER);
2049 IPW_CMD(CCX_VER_INFO);
2050 IPW_CMD(SET_CALIBRATION);
2051 IPW_CMD(SENSITIVITY_CALIB);
2052 IPW_CMD(RETRY_LIMIT);
2053 IPW_CMD(IPW_PRE_POWER_DOWN);
2054 IPW_CMD(VAP_BEACON_TEMPLATE);
2055 IPW_CMD(VAP_DTIM_PERIOD);
2056 IPW_CMD(EXT_SUPPORTED_RATES);
2057 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2058 IPW_CMD(VAP_QUIET_INTERVALS);
2059 IPW_CMD(VAP_CHANNEL_SWITCH);
2060 IPW_CMD(VAP_MANDATORY_CHANNELS);
2061 IPW_CMD(VAP_CELL_PWR_LIMIT);
2062 IPW_CMD(VAP_CF_PARAM_SET);
2063 IPW_CMD(VAP_SET_BEACONING_STATE);
2064 IPW_CMD(MEASUREMENT);
2065 IPW_CMD(POWER_CAPABILITY);
2066 IPW_CMD(SUPPORTED_CHANNELS);
2067 IPW_CMD(TPC_REPORT);
2069 IPW_CMD(PRODUCTION_COMMAND);
2075 #define HOST_COMPLETE_TIMEOUT HZ
2077 static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
2080 unsigned long flags;
2082 spin_lock_irqsave(&priv->lock, flags);
2083 if (priv->status & STATUS_HCMD_ACTIVE) {
2084 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2085 get_cmd_string(cmd->cmd));
2086 spin_unlock_irqrestore(&priv->lock, flags);
2090 priv->status |= STATUS_HCMD_ACTIVE;
2093 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2094 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2095 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2096 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2098 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2101 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2102 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2105 #ifndef DEBUG_CMD_WEP_KEY
2106 if (cmd->cmd == IPW_CMD_WEP_KEY)
2107 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2110 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2112 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
2114 priv->status &= ~STATUS_HCMD_ACTIVE;
2115 IPW_ERROR("Failed to send %s: Reason %d\n",
2116 get_cmd_string(cmd->cmd), rc);
2117 spin_unlock_irqrestore(&priv->lock, flags);
2120 spin_unlock_irqrestore(&priv->lock, flags);
2122 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2124 status & STATUS_HCMD_ACTIVE),
2125 HOST_COMPLETE_TIMEOUT);
2127 spin_lock_irqsave(&priv->lock, flags);
2128 if (priv->status & STATUS_HCMD_ACTIVE) {
2129 IPW_ERROR("Failed to send %s: Command timed out.\n",
2130 get_cmd_string(cmd->cmd));
2131 priv->status &= ~STATUS_HCMD_ACTIVE;
2132 spin_unlock_irqrestore(&priv->lock, flags);
2136 spin_unlock_irqrestore(&priv->lock, flags);
2140 if (priv->status & STATUS_RF_KILL_HW) {
2141 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2142 get_cmd_string(cmd->cmd));
2149 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2150 priv->cmdlog_pos %= priv->cmdlog_len;
2155 static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
2157 struct host_cmd cmd = {
2161 return __ipw_send_cmd(priv, &cmd);
2164 static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2167 struct host_cmd cmd = {
2173 return __ipw_send_cmd(priv, &cmd);
2176 static int ipw_send_host_complete(struct ipw_priv *priv)
2179 IPW_ERROR("Invalid args\n");
2183 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
2186 static int ipw_send_system_config(struct ipw_priv *priv)
2188 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2189 sizeof(priv->sys_config),
2193 static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
2195 if (!priv || !ssid) {
2196 IPW_ERROR("Invalid args\n");
2200 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
2204 static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
2206 if (!priv || !mac) {
2207 IPW_ERROR("Invalid args\n");
2211 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2212 priv->net_dev->name, MAC_ARG(mac));
2214 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
2218 * NOTE: This must be executed from our workqueue as it results in udelay
2219 * being called which may corrupt the keyboard if executed on default
2222 static void ipw_adapter_restart(void *adapter)
2224 struct ipw_priv *priv = adapter;
2226 if (priv->status & STATUS_RF_KILL_MASK)
2231 if (priv->assoc_network &&
2232 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2233 ipw_remove_current_network(priv);
2236 IPW_ERROR("Failed to up device\n");
2241 static void ipw_bg_adapter_restart(void *data)
2243 struct ipw_priv *priv = data;
2244 mutex_lock(&priv->mutex);
2245 ipw_adapter_restart(data);
2246 mutex_unlock(&priv->mutex);
2249 #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2251 static void ipw_scan_check(void *data)
2253 struct ipw_priv *priv = data;
2254 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2255 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
2256 "adapter after (%dms).\n",
2257 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
2258 queue_work(priv->workqueue, &priv->adapter_restart);
2262 static void ipw_bg_scan_check(void *data)
2264 struct ipw_priv *priv = data;
2265 mutex_lock(&priv->mutex);
2266 ipw_scan_check(data);
2267 mutex_unlock(&priv->mutex);
2270 static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2271 struct ipw_scan_request_ext *request)
2273 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
2274 sizeof(*request), request);
2277 static int ipw_send_scan_abort(struct ipw_priv *priv)
2280 IPW_ERROR("Invalid args\n");
2284 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
2287 static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2289 struct ipw_sensitivity_calib calib = {
2290 .beacon_rssi_raw = sens,
2293 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
2297 static int ipw_send_associate(struct ipw_priv *priv,
2298 struct ipw_associate *associate)
2300 struct ipw_associate tmp_associate;
2302 if (!priv || !associate) {
2303 IPW_ERROR("Invalid args\n");
2307 memcpy(&tmp_associate, associate, sizeof(*associate));
2308 tmp_associate.policy_support =
2309 cpu_to_le16(tmp_associate.policy_support);
2310 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2311 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2312 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2313 tmp_associate.listen_interval =
2314 cpu_to_le16(tmp_associate.listen_interval);
2315 tmp_associate.beacon_interval =
2316 cpu_to_le16(tmp_associate.beacon_interval);
2317 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2319 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
2323 static int ipw_send_supported_rates(struct ipw_priv *priv,
2324 struct ipw_supported_rates *rates)
2326 if (!priv || !rates) {
2327 IPW_ERROR("Invalid args\n");
2331 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
2335 static int ipw_set_random_seed(struct ipw_priv *priv)
2340 IPW_ERROR("Invalid args\n");
2344 get_random_bytes(&val, sizeof(val));
2346 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
2349 static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2352 IPW_ERROR("Invalid args\n");
2356 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off),
2360 static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
2362 if (!priv || !power) {
2363 IPW_ERROR("Invalid args\n");
2367 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
2370 static int ipw_set_tx_power(struct ipw_priv *priv)
2372 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
2373 struct ipw_tx_power tx_power;
2377 memset(&tx_power, 0, sizeof(tx_power));
2379 /* configure device for 'G' band */
2380 tx_power.ieee_mode = IPW_G_MODE;
2381 tx_power.num_channels = geo->bg_channels;
2382 for (i = 0; i < geo->bg_channels; i++) {
2383 max_power = geo->bg[i].max_power;
2384 tx_power.channels_tx_power[i].channel_number =
2386 tx_power.channels_tx_power[i].tx_power = max_power ?
2387 min(max_power, priv->tx_power) : priv->tx_power;
2389 if (ipw_send_tx_power(priv, &tx_power))
2392 /* configure device to also handle 'B' band */
2393 tx_power.ieee_mode = IPW_B_MODE;
2394 if (ipw_send_tx_power(priv, &tx_power))
2397 /* configure device to also handle 'A' band */
2398 if (priv->ieee->abg_true) {
2399 tx_power.ieee_mode = IPW_A_MODE;
2400 tx_power.num_channels = geo->a_channels;
2401 for (i = 0; i < tx_power.num_channels; i++) {
2402 max_power = geo->a[i].max_power;
2403 tx_power.channels_tx_power[i].channel_number =
2405 tx_power.channels_tx_power[i].tx_power = max_power ?
2406 min(max_power, priv->tx_power) : priv->tx_power;
2408 if (ipw_send_tx_power(priv, &tx_power))
2414 static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2416 struct ipw_rts_threshold rts_threshold = {
2417 .rts_threshold = rts,
2421 IPW_ERROR("Invalid args\n");
2425 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2426 sizeof(rts_threshold), &rts_threshold);
2429 static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2431 struct ipw_frag_threshold frag_threshold = {
2432 .frag_threshold = frag,
2436 IPW_ERROR("Invalid args\n");
2440 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2441 sizeof(frag_threshold), &frag_threshold);
2444 static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2449 IPW_ERROR("Invalid args\n");
2453 /* If on battery, set to 3, if AC set to CAM, else user
2456 case IPW_POWER_BATTERY:
2457 param = IPW_POWER_INDEX_3;
2460 param = IPW_POWER_MODE_CAM;
2467 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
2471 static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2473 struct ipw_retry_limit retry_limit = {
2474 .short_retry_limit = slimit,
2475 .long_retry_limit = llimit
2479 IPW_ERROR("Invalid args\n");
2483 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
2488 * The IPW device contains a Microwire compatible EEPROM that stores
2489 * various data like the MAC address. Usually the firmware has exclusive
2490 * access to the eeprom, but during device initialization (before the
2491 * device driver has sent the HostComplete command to the firmware) the
2492 * device driver has read access to the EEPROM by way of indirect addressing
2493 * through a couple of memory mapped registers.
2495 * The following is a simplified implementation for pulling data out of the
2496 * the eeprom, along with some helper functions to find information in
2497 * the per device private data's copy of the eeprom.
2499 * NOTE: To better understand how these functions work (i.e what is a chip
2500 * select and why do have to keep driving the eeprom clock?), read
2501 * just about any data sheet for a Microwire compatible EEPROM.
2504 /* write a 32 bit value into the indirect accessor register */
2505 static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2507 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
2509 /* the eeprom requires some time to complete the operation */
2510 udelay(p->eeprom_delay);
2515 /* perform a chip select operation */
2516 static void eeprom_cs(struct ipw_priv *priv)
2518 eeprom_write_reg(priv, 0);
2519 eeprom_write_reg(priv, EEPROM_BIT_CS);
2520 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2521 eeprom_write_reg(priv, EEPROM_BIT_CS);
2524 /* perform a chip select operation */
2525 static void eeprom_disable_cs(struct ipw_priv *priv)
2527 eeprom_write_reg(priv, EEPROM_BIT_CS);
2528 eeprom_write_reg(priv, 0);
2529 eeprom_write_reg(priv, EEPROM_BIT_SK);
2532 /* push a single bit down to the eeprom */
2533 static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
2535 int d = (bit ? EEPROM_BIT_DI : 0);
2536 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2537 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
2540 /* push an opcode followed by an address down to the eeprom */
2541 static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
2546 eeprom_write_bit(priv, 1);
2547 eeprom_write_bit(priv, op & 2);
2548 eeprom_write_bit(priv, op & 1);
2549 for (i = 7; i >= 0; i--) {
2550 eeprom_write_bit(priv, addr & (1 << i));
2554 /* pull 16 bits off the eeprom, one bit at a time */
2555 static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
2560 /* Send READ Opcode */
2561 eeprom_op(priv, EEPROM_CMD_READ, addr);
2563 /* Send dummy bit */
2564 eeprom_write_reg(priv, EEPROM_BIT_CS);
2566 /* Read the byte off the eeprom one bit at a time */
2567 for (i = 0; i < 16; i++) {
2569 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2570 eeprom_write_reg(priv, EEPROM_BIT_CS);
2571 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2572 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
2575 /* Send another dummy bit */
2576 eeprom_write_reg(priv, 0);
2577 eeprom_disable_cs(priv);
2582 /* helper function for pulling the mac address out of the private */
2583 /* data's copy of the eeprom data */
2584 static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
2586 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
2590 * Either the device driver (i.e. the host) or the firmware can
2591 * load eeprom data into the designated region in SRAM. If neither
2592 * happens then the FW will shutdown with a fatal error.
2594 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2595 * bit needs region of shared SRAM needs to be non-zero.
2597 static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2600 u16 *eeprom = (u16 *) priv->eeprom;
2602 IPW_DEBUG_TRACE(">>\n");
2604 /* read entire contents of eeprom into private buffer */
2605 for (i = 0; i < 128; i++)
2606 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
2609 If the data looks correct, then copy it to our private
2610 copy. Otherwise let the firmware know to perform the operation
2613 if (priv->eeprom[EEPROM_VERSION] != 0) {
2614 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2616 /* write the eeprom data to sram */
2617 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
2618 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
2620 /* Do not load eeprom data on fatal error or suspend */
2621 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2623 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2625 /* Load eeprom data on fatal error or suspend */
2626 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2629 IPW_DEBUG_TRACE("<<\n");
2632 static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
2637 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
2639 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
2642 static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2644 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
2645 CB_NUMBER_OF_ELEMENTS_SMALL *
2646 sizeof(struct command_block));
2649 static int ipw_fw_dma_enable(struct ipw_priv *priv)
2650 { /* start dma engine but no transfers yet */
2652 IPW_DEBUG_FW(">> : \n");
2655 ipw_fw_dma_reset_command_blocks(priv);
2657 /* Write CB base address */
2658 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
2660 IPW_DEBUG_FW("<< : \n");
2664 static void ipw_fw_dma_abort(struct ipw_priv *priv)
2668 IPW_DEBUG_FW(">> :\n");
2670 //set the Stop and Abort bit
2671 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
2672 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2673 priv->sram_desc.last_cb_index = 0;
2675 IPW_DEBUG_FW("<< \n");
2678 static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2679 struct command_block *cb)
2682 IPW_SHARED_SRAM_DMA_CONTROL +
2683 (sizeof(struct command_block) * index);
2684 IPW_DEBUG_FW(">> :\n");
2686 ipw_write_indirect(priv, address, (u8 *) cb,
2687 (int)sizeof(struct command_block));
2689 IPW_DEBUG_FW("<< :\n");
2694 static int ipw_fw_dma_kick(struct ipw_priv *priv)
2699 IPW_DEBUG_FW(">> :\n");
2701 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
2702 ipw_fw_dma_write_command_block(priv, index,
2703 &priv->sram_desc.cb_list[index]);
2705 /* Enable the DMA in the CSR register */
2706 ipw_clear_bit(priv, IPW_RESET_REG,
2707 IPW_RESET_REG_MASTER_DISABLED |
2708 IPW_RESET_REG_STOP_MASTER);
2710 /* Set the Start bit. */
2711 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
2712 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2714 IPW_DEBUG_FW("<< :\n");
2718 static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2721 u32 register_value = 0;
2722 u32 cb_fields_address = 0;
2724 IPW_DEBUG_FW(">> :\n");
2725 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2726 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
2728 /* Read the DMA Controlor register */
2729 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2730 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
2732 /* Print the CB values */
2733 cb_fields_address = address;
2734 register_value = ipw_read_reg32(priv, cb_fields_address);
2735 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
2737 cb_fields_address += sizeof(u32);
2738 register_value = ipw_read_reg32(priv, cb_fields_address);
2739 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
2741 cb_fields_address += sizeof(u32);
2742 register_value = ipw_read_reg32(priv, cb_fields_address);
2743 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2746 cb_fields_address += sizeof(u32);
2747 register_value = ipw_read_reg32(priv, cb_fields_address);
2748 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
2750 IPW_DEBUG_FW(">> :\n");
2753 static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2755 u32 current_cb_address = 0;
2756 u32 current_cb_index = 0;
2758 IPW_DEBUG_FW("<< :\n");
2759 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2761 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
2762 sizeof(struct command_block);
2764 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
2765 current_cb_index, current_cb_address);
2767 IPW_DEBUG_FW(">> :\n");
2768 return current_cb_index;
2772 static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2776 int interrupt_enabled, int is_last)
2779 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
2780 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2782 struct command_block *cb;
2783 u32 last_cb_element = 0;
2785 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2786 src_address, dest_address, length);
2788 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2791 last_cb_element = priv->sram_desc.last_cb_index;
2792 cb = &priv->sram_desc.cb_list[last_cb_element];
2793 priv->sram_desc.last_cb_index++;
2795 /* Calculate the new CB control word */
2796 if (interrupt_enabled)
2797 control |= CB_INT_ENABLED;
2800 control |= CB_LAST_VALID;
2804 /* Calculate the CB Element's checksum value */
2805 cb->status = control ^ src_address ^ dest_address;
2807 /* Copy the Source and Destination addresses */
2808 cb->dest_addr = dest_address;
2809 cb->source_addr = src_address;
2811 /* Copy the Control Word last */
2812 cb->control = control;
2817 static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
2818 u32 src_phys, u32 dest_address, u32 length)
2820 u32 bytes_left = length;
2822 u32 dest_offset = 0;
2824 IPW_DEBUG_FW(">> \n");
2825 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2826 src_phys, dest_address, length);
2827 while (bytes_left > CB_MAX_LENGTH) {
2828 status = ipw_fw_dma_add_command_block(priv,
2829 src_phys + src_offset,
2832 CB_MAX_LENGTH, 0, 0);
2834 IPW_DEBUG_FW_INFO(": Failed\n");
2837 IPW_DEBUG_FW_INFO(": Added new cb\n");
2839 src_offset += CB_MAX_LENGTH;
2840 dest_offset += CB_MAX_LENGTH;
2841 bytes_left -= CB_MAX_LENGTH;
2844 /* add the buffer tail */
2845 if (bytes_left > 0) {
2847 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2848 dest_address + dest_offset,
2851 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2855 (": Adding new cb - the buffer tail\n");
2858 IPW_DEBUG_FW("<< \n");
2862 static int ipw_fw_dma_wait(struct ipw_priv *priv)
2864 u32 current_index = 0, previous_index;
2867 IPW_DEBUG_FW(">> : \n");
2869 current_index = ipw_fw_dma_command_block_index(priv);
2870 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
2871 (int)priv->sram_desc.last_cb_index);
2873 while (current_index < priv->sram_desc.last_cb_index) {
2875 previous_index = current_index;
2876 current_index = ipw_fw_dma_command_block_index(priv);
2878 if (previous_index < current_index) {
2882 if (++watchdog > 400) {
2883 IPW_DEBUG_FW_INFO("Timeout\n");
2884 ipw_fw_dma_dump_command_block(priv);
2885 ipw_fw_dma_abort(priv);
2890 ipw_fw_dma_abort(priv);
2892 /*Disable the DMA in the CSR register */
2893 ipw_set_bit(priv, IPW_RESET_REG,
2894 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
2896 IPW_DEBUG_FW("<< dmaWaitSync \n");
2900 static void ipw_remove_current_network(struct ipw_priv *priv)
2902 struct list_head *element, *safe;
2903 struct ieee80211_network *network = NULL;
2904 unsigned long flags;
2906 spin_lock_irqsave(&priv->ieee->lock, flags);
2907 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2908 network = list_entry(element, struct ieee80211_network, list);
2909 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2911 list_add_tail(&network->list,
2912 &priv->ieee->network_free_list);
2915 spin_unlock_irqrestore(&priv->ieee->lock, flags);
2919 * Check that card is still alive.
2920 * Reads debug register from domain0.
2921 * If card is present, pre-defined value should
2925 * @return 1 if card is present, 0 otherwise
2927 static inline int ipw_alive(struct ipw_priv *priv)
2929 return ipw_read32(priv, 0x90) == 0xd55555d5;
2932 /* timeout in msec, attempted in 10-msec quanta */
2933 static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2939 if ((ipw_read32(priv, addr) & mask) == mask)
2943 } while (i < timeout);
2948 /* These functions load the firmware and micro code for the operation of
2949 * the ipw hardware. It assumes the buffer has all the bits for the
2950 * image and the caller is handling the memory allocation and clean up.
2953 static int ipw_stop_master(struct ipw_priv *priv)
2957 IPW_DEBUG_TRACE(">> \n");
2958 /* stop master. typical delay - 0 */
2959 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
2961 /* timeout is in msec, polled in 10-msec quanta */
2962 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2963 IPW_RESET_REG_MASTER_DISABLED, 100);
2965 IPW_ERROR("wait for stop master failed after 100ms\n");
2969 IPW_DEBUG_INFO("stop master %dms\n", rc);
2974 static void ipw_arc_release(struct ipw_priv *priv)
2976 IPW_DEBUG_TRACE(">> \n");
2979 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
2981 /* no one knows timing, for safety add some delay */
2990 static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
2992 int rc = 0, i, addr;
2996 image = (u16 *) data;
2998 IPW_DEBUG_TRACE(">> \n");
3000 rc = ipw_stop_master(priv);
3005 // spin_lock_irqsave(&priv->lock, flags);
3007 for (addr = IPW_SHARED_LOWER_BOUND;
3008 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
3009 ipw_write32(priv, addr, 0);
3012 /* no ucode (yet) */
3013 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3014 /* destroy DMA queues */
3015 /* reset sequence */
3017 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
3018 ipw_arc_release(priv);
3019 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
3023 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
3026 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
3029 /* enable ucode store */
3030 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3031 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
3037 * Do NOT set indirect address register once and then
3038 * store data to indirect data register in the loop.
3039 * It seems very reasonable, but in this case DINO do not
3040 * accept ucode. It is essential to set address each time.
3042 /* load new ipw uCode */
3043 for (i = 0; i < len / 2; i++)
3044 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
3045 cpu_to_le16(image[i]));
3048 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3049 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
3051 /* this is where the igx / win driver deveates from the VAP driver. */
3053 /* wait for alive response */
3054 for (i = 0; i < 100; i++) {
3055 /* poll for incoming data */
3056 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
3057 if (cr & DINO_RXFIFO_DATA)
3062 if (cr & DINO_RXFIFO_DATA) {
3063 /* alive_command_responce size is NOT multiple of 4 */
3064 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
3066 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
3067 response_buffer[i] =
3068 le32_to_cpu(ipw_read_reg32(priv,
3069 IPW_BASEBAND_RX_FIFO_READ));
3070 memcpy(&priv->dino_alive, response_buffer,
3071 sizeof(priv->dino_alive));
3072 if (priv->dino_alive.alive_command == 1
3073 && priv->dino_alive.ucode_valid == 1) {
3076 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3077 "of %02d/%02d/%02d %02d:%02d\n",
3078 priv->dino_alive.software_revision,
3079 priv->dino_alive.software_revision,
3080 priv->dino_alive.device_identifier,
3081 priv->dino_alive.device_identifier,
3082 priv->dino_alive.time_stamp[0],
3083 priv->dino_alive.time_stamp[1],
3084 priv->dino_alive.time_stamp[2],
3085 priv->dino_alive.time_stamp[3],
3086 priv->dino_alive.time_stamp[4]);
3088 IPW_DEBUG_INFO("Microcode is not alive\n");
3092 IPW_DEBUG_INFO("No alive response from DINO\n");
3096 /* disable DINO, otherwise for some reason
3097 firmware have problem getting alive resp. */
3098 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3100 // spin_unlock_irqrestore(&priv->lock, flags);
3105 static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
3109 struct fw_chunk *chunk;
3110 dma_addr_t shared_phys;
3113 IPW_DEBUG_TRACE("<< : \n");
3114 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
3119 memmove(shared_virt, data, len);
3122 rc = ipw_fw_dma_enable(priv);
3124 if (priv->sram_desc.last_cb_index > 0) {
3125 /* the DMA is already ready this would be a bug. */
3131 chunk = (struct fw_chunk *)(data + offset);
3132 offset += sizeof(struct fw_chunk);
3133 /* build DMA packet and queue up for sending */
3134 /* dma to chunk->address, the chunk->length bytes from data +
3137 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
3138 le32_to_cpu(chunk->address),
3139 le32_to_cpu(chunk->length));
3141 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3145 offset += le32_to_cpu(chunk->length);
3146 } while (offset < len);
3148 /* Run the DMA and wait for the answer */
3149 rc = ipw_fw_dma_kick(priv);
3151 IPW_ERROR("dmaKick Failed\n");
3155 rc = ipw_fw_dma_wait(priv);
3157 IPW_ERROR("dmaWaitSync Failed\n");
3161 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
3166 static int ipw_stop_nic(struct ipw_priv *priv)
3171 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
3173 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3174 IPW_RESET_REG_MASTER_DISABLED, 500);
3176 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
3180 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
3185 static void ipw_start_nic(struct ipw_priv *priv)
3187 IPW_DEBUG_TRACE(">>\n");
3189 /* prvHwStartNic release ARC */
3190 ipw_clear_bit(priv, IPW_RESET_REG,
3191 IPW_RESET_REG_MASTER_DISABLED |
3192 IPW_RESET_REG_STOP_MASTER |
3193 CBD_RESET_REG_PRINCETON_RESET);
3195 /* enable power management */
3196 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3197 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
3199 IPW_DEBUG_TRACE("<<\n");
3202 static int ipw_init_nic(struct ipw_priv *priv)
3206 IPW_DEBUG_TRACE(">>\n");
3209 /* set "initialization complete" bit to move adapter to D0 state */
3210 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3212 /* low-level PLL activation */
3213 ipw_write32(priv, IPW_READ_INT_REGISTER,
3214 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
3216 /* wait for clock stabilization */
3217 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3218 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
3220 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3222 /* assert SW reset */
3223 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
3227 /* set "initialization complete" bit to move adapter to D0 state */
3228 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3230 IPW_DEBUG_TRACE(">>\n");
3234 /* Call this function from process context, it will sleep in request_firmware.
3235 * Probe is an ok place to call this from.
3237 static int ipw_reset_nic(struct ipw_priv *priv)
3240 unsigned long flags;
3242 IPW_DEBUG_TRACE(">>\n");
3244 rc = ipw_init_nic(priv);
3246 spin_lock_irqsave(&priv->lock, flags);
3247 /* Clear the 'host command active' bit... */
3248 priv->status &= ~STATUS_HCMD_ACTIVE;
3249 wake_up_interruptible(&priv->wait_command_queue);
3250 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3251 wake_up_interruptible(&priv->wait_state);
3252 spin_unlock_irqrestore(&priv->lock, flags);
3254 IPW_DEBUG_TRACE("<<\n");
3267 static int ipw_get_fw(struct ipw_priv *priv,
3268 const struct firmware **raw, const char *name)
3273 /* ask firmware_class module to get the boot firmware off disk */
3274 rc = request_firmware(raw, name, &priv->pci_dev->dev);
3276 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
3280 if ((*raw)->size < sizeof(*fw)) {
3281 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
3285 fw = (void *)(*raw)->data;
3287 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3288 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
3289 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3290 name, (*raw)->size);
3294 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
3296 le32_to_cpu(fw->ver) >> 16,
3297 le32_to_cpu(fw->ver) & 0xff,
3298 (*raw)->size - sizeof(*fw));
3302 #define IPW_RX_BUF_SIZE (3000)
3304 static void ipw_rx_queue_reset(struct ipw_priv *priv,
3305 struct ipw_rx_queue *rxq)
3307 unsigned long flags;
3310 spin_lock_irqsave(&rxq->lock, flags);
3312 INIT_LIST_HEAD(&rxq->rx_free);
3313 INIT_LIST_HEAD(&rxq->rx_used);
3315 /* Fill the rx_used queue with _all_ of the Rx buffers */
3316 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3317 /* In the reset function, these buffers may have been allocated
3318 * to an SKB, so we need to unmap and free potential storage */
3319 if (rxq->pool[i].skb !=