1 /******************************************************************************
3 Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
5 802.11 status code portion of this file from ethereal-0.10.6:
6 Copyright 2000, Axis Communications AB
7 Ethereal - Network traffic analyzer
8 By Gerald Combs <gerald@ethereal.com>
9 Copyright 1998 Gerald Combs
11 This program is free software; you can redistribute it and/or modify it
12 under the terms of version 2 of the GNU General Public License as
13 published by the Free Software Foundation.
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59
22 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 The full GNU General Public License is included in this distribution in the
28 James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 ******************************************************************************/
35 #define IPW2200_VERSION "1.0.5"
36 #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
37 #define DRV_COPYRIGHT "Copyright(c) 2003-2004 Intel Corporation"
38 #define DRV_VERSION IPW2200_VERSION
40 #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
42 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
43 MODULE_VERSION(DRV_VERSION
);
44 MODULE_AUTHOR(DRV_COPYRIGHT
);
45 MODULE_LICENSE("GPL");
48 static int channel
= 0;
51 static u32 ipw_debug_level
;
52 static int associate
= 1;
53 static int auto_create
= 1;
55 static int disable
= 0;
56 static int hwcrypto
= 1;
57 static const char ipw_modes
[] = {
62 static int qos_enable
= 0;
63 static int qos_burst_enable
= 0;
64 static int qos_no_ack_mask
= 0;
65 static int burst_duration_CCK
= 0;
66 static int burst_duration_OFDM
= 0;
68 static struct ieee80211_qos_parameters def_qos_parameters_OFDM
= {
69 {QOS_TX0_CW_MIN_OFDM
, QOS_TX1_CW_MIN_OFDM
, QOS_TX2_CW_MIN_OFDM
,
71 {QOS_TX0_CW_MAX_OFDM
, QOS_TX1_CW_MAX_OFDM
, QOS_TX2_CW_MAX_OFDM
,
73 {QOS_TX0_AIFS
, QOS_TX1_AIFS
, QOS_TX2_AIFS
, QOS_TX3_AIFS
},
74 {QOS_TX0_ACM
, QOS_TX1_ACM
, QOS_TX2_ACM
, QOS_TX3_ACM
},
75 {QOS_TX0_TXOP_LIMIT_OFDM
, QOS_TX1_TXOP_LIMIT_OFDM
,
76 QOS_TX2_TXOP_LIMIT_OFDM
, QOS_TX3_TXOP_LIMIT_OFDM
}
79 static struct ieee80211_qos_parameters def_qos_parameters_CCK
= {
80 {QOS_TX0_CW_MIN_CCK
, QOS_TX1_CW_MIN_CCK
, QOS_TX2_CW_MIN_CCK
,
82 {QOS_TX0_CW_MAX_CCK
, QOS_TX1_CW_MAX_CCK
, QOS_TX2_CW_MAX_CCK
,
84 {QOS_TX0_AIFS
, QOS_TX1_AIFS
, QOS_TX2_AIFS
, QOS_TX3_AIFS
},
85 {QOS_TX0_ACM
, QOS_TX1_ACM
, QOS_TX2_ACM
, QOS_TX3_ACM
},
86 {QOS_TX0_TXOP_LIMIT_CCK
, QOS_TX1_TXOP_LIMIT_CCK
, QOS_TX2_TXOP_LIMIT_CCK
,
87 QOS_TX3_TXOP_LIMIT_CCK
}
90 static struct ieee80211_qos_parameters def_parameters_OFDM
= {
91 {DEF_TX0_CW_MIN_OFDM
, DEF_TX1_CW_MIN_OFDM
, DEF_TX2_CW_MIN_OFDM
,
93 {DEF_TX0_CW_MAX_OFDM
, DEF_TX1_CW_MAX_OFDM
, DEF_TX2_CW_MAX_OFDM
,
95 {DEF_TX0_AIFS
, DEF_TX1_AIFS
, DEF_TX2_AIFS
, DEF_TX3_AIFS
},
96 {DEF_TX0_ACM
, DEF_TX1_ACM
, DEF_TX2_ACM
, DEF_TX3_ACM
},
97 {DEF_TX0_TXOP_LIMIT_OFDM
, DEF_TX1_TXOP_LIMIT_OFDM
,
98 DEF_TX2_TXOP_LIMIT_OFDM
, DEF_TX3_TXOP_LIMIT_OFDM
}
101 static struct ieee80211_qos_parameters def_parameters_CCK
= {
102 {DEF_TX0_CW_MIN_CCK
, DEF_TX1_CW_MIN_CCK
, DEF_TX2_CW_MIN_CCK
,
104 {DEF_TX0_CW_MAX_CCK
, DEF_TX1_CW_MAX_CCK
, DEF_TX2_CW_MAX_CCK
,
106 {DEF_TX0_AIFS
, DEF_TX1_AIFS
, DEF_TX2_AIFS
, DEF_TX3_AIFS
},
107 {DEF_TX0_ACM
, DEF_TX1_ACM
, DEF_TX2_ACM
, DEF_TX3_ACM
},
108 {DEF_TX0_TXOP_LIMIT_CCK
, DEF_TX1_TXOP_LIMIT_CCK
, DEF_TX2_TXOP_LIMIT_CCK
,
109 DEF_TX3_TXOP_LIMIT_CCK
}
112 static u8 qos_oui
[QOS_OUI_LEN
] = { 0x00, 0x50, 0xF2 };
114 static int from_priority_to_tx_queue
[] = {
115 IPW_TX_QUEUE_1
, IPW_TX_QUEUE_2
, IPW_TX_QUEUE_2
, IPW_TX_QUEUE_1
,
116 IPW_TX_QUEUE_3
, IPW_TX_QUEUE_3
, IPW_TX_QUEUE_4
, IPW_TX_QUEUE_4
119 static u32
ipw_qos_get_burst_duration(struct ipw_priv
*priv
);
121 static int ipw_send_qos_params_command(struct ipw_priv
*priv
, struct ieee80211_qos_parameters
123 static int ipw_send_qos_info_command(struct ipw_priv
*priv
, struct ieee80211_qos_information_element
125 #endif /* CONFIG_IPW_QOS */
127 static void ipw_remove_current_network(struct ipw_priv
*priv
);
128 static void ipw_rx(struct ipw_priv
*priv
);
129 static int ipw_queue_tx_reclaim(struct ipw_priv
*priv
,
130 struct clx2_tx_queue
*txq
, int qindex
);
131 static int ipw_queue_reset(struct ipw_priv
*priv
);
133 static int ipw_queue_tx_hcmd(struct ipw_priv
*priv
, int hcmd
, void *buf
,
136 static void ipw_tx_queue_free(struct ipw_priv
*);
138 static struct ipw_rx_queue
*ipw_rx_queue_alloc(struct ipw_priv
*);
139 static void ipw_rx_queue_free(struct ipw_priv
*, struct ipw_rx_queue
*);
140 static void ipw_rx_queue_replenish(void *);
141 static int ipw_up(struct ipw_priv
*);
142 static void ipw_bg_up(void *);
143 static void ipw_down(struct ipw_priv
*);
144 static void ipw_bg_down(void *);
145 static int ipw_config(struct ipw_priv
*);
146 static int init_supported_rates(struct ipw_priv
*priv
,
147 struct ipw_supported_rates
*prates
);
148 static void ipw_set_hwcrypto_keys(struct ipw_priv
*);
149 static void ipw_send_wep_keys(struct ipw_priv
*, int);
151 static char *snprint_line(char *buf
, size_t count
,
152 const u8
* data
, u32 len
, u32 ofs
)
157 out
= snprintf(buf
, count
, "%08X", ofs
);
159 for (l
= 0, i
= 0; i
< 2; i
++) {
160 out
+= snprintf(buf
+ out
, count
- out
, " ");
161 for (j
= 0; j
< 8 && l
< len
; j
++, l
++)
162 out
+= snprintf(buf
+ out
, count
- out
, "%02X ",
165 out
+= snprintf(buf
+ out
, count
- out
, " ");
168 out
+= snprintf(buf
+ out
, count
- out
, " ");
169 for (l
= 0, i
= 0; i
< 2; i
++) {
170 out
+= snprintf(buf
+ out
, count
- out
, " ");
171 for (j
= 0; j
< 8 && l
< len
; j
++, l
++) {
172 c
= data
[(i
* 8 + j
)];
173 if (!isascii(c
) || !isprint(c
))
176 out
+= snprintf(buf
+ out
, count
- out
, "%c", c
);
180 out
+= snprintf(buf
+ out
, count
- out
, " ");
186 static void printk_buf(int level
, const u8
* data
, u32 len
)
190 if (!(ipw_debug_level
& level
))
194 printk(KERN_DEBUG
"%s\n",
195 snprint_line(line
, sizeof(line
), &data
[ofs
],
196 min(len
, 16U), ofs
));
198 len
-= min(len
, 16U);
202 static u32
_ipw_read_reg32(struct ipw_priv
*priv
, u32 reg
);
203 #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
205 static u8
_ipw_read_reg8(struct ipw_priv
*ipw
, u32 reg
);
206 #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
208 static void _ipw_write_reg8(struct ipw_priv
*priv
, u32 reg
, u8 value
);
209 static inline void ipw_write_reg8(struct ipw_priv
*a
, u32 b
, u8 c
)
211 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__
,
212 __LINE__
, (u32
) (b
), (u32
) (c
));
213 _ipw_write_reg8(a
, b
, c
);
216 static void _ipw_write_reg16(struct ipw_priv
*priv
, u32 reg
, u16 value
);
217 static inline void ipw_write_reg16(struct ipw_priv
*a
, u32 b
, u16 c
)
219 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__
,
220 __LINE__
, (u32
) (b
), (u32
) (c
));
221 _ipw_write_reg16(a
, b
, c
);
224 static void _ipw_write_reg32(struct ipw_priv
*priv
, u32 reg
, u32 value
);
225 static inline void ipw_write_reg32(struct ipw_priv
*a
, u32 b
, u32 c
)
227 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__
,
228 __LINE__
, (u32
) (b
), (u32
) (c
));
229 _ipw_write_reg32(a
, b
, c
);
232 #define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
233 #define ipw_write8(ipw, ofs, val) \
234 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
235 _ipw_write8(ipw, ofs, val)
237 #define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
238 #define ipw_write16(ipw, ofs, val) \
239 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
240 _ipw_write16(ipw, ofs, val)
242 #define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
243 #define ipw_write32(ipw, ofs, val) \
244 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
245 _ipw_write32(ipw, ofs, val)
247 #define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
248 static inline u8
__ipw_read8(char *f
, u32 l
, struct ipw_priv
*ipw
, u32 ofs
)
250 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f
, l
, (u32
) (ofs
));
251 return _ipw_read8(ipw
, ofs
);
254 #define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
256 #define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
257 static inline u16
__ipw_read16(char *f
, u32 l
, struct ipw_priv
*ipw
, u32 ofs
)
259 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f
, l
, (u32
) (ofs
));
260 return _ipw_read16(ipw
, ofs
);
263 #define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
265 #define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
266 static inline u32
__ipw_read32(char *f
, u32 l
, struct ipw_priv
*ipw
, u32 ofs
)
268 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f
, l
, (u32
) (ofs
));
269 return _ipw_read32(ipw
, ofs
);
272 #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
274 static void _ipw_read_indirect(struct ipw_priv
*, u32
, u8
*, int);
275 #define ipw_read_indirect(a, b, c, d) \
276 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
277 _ipw_read_indirect(a, b, c, d)
279 static void _ipw_write_indirect(struct ipw_priv
*priv
, u32 addr
, u8
* data
,
281 #define ipw_write_indirect(a, b, c, d) \
282 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
283 _ipw_write_indirect(a, b, c, d)
285 /* indirect write s */
286 static void _ipw_write_reg32(struct ipw_priv
*priv
, u32 reg
, u32 value
)
288 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv
, reg
, value
);
289 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, reg
);
290 _ipw_write32(priv
, IPW_INDIRECT_DATA
, value
);
293 static void _ipw_write_reg8(struct ipw_priv
*priv
, u32 reg
, u8 value
)
295 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg
, value
);
296 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, reg
& IPW_INDIRECT_ADDR_MASK
);
297 _ipw_write8(priv
, IPW_INDIRECT_DATA
, value
);
300 static void _ipw_write_reg16(struct ipw_priv
*priv
, u32 reg
, u16 value
)
302 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg
, value
);
303 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, reg
& IPW_INDIRECT_ADDR_MASK
);
304 _ipw_write16(priv
, IPW_INDIRECT_DATA
, value
);
307 /* indirect read s */
309 static u8
_ipw_read_reg8(struct ipw_priv
*priv
, u32 reg
)
312 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, reg
& IPW_INDIRECT_ADDR_MASK
);
313 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg
);
314 word
= _ipw_read32(priv
, IPW_INDIRECT_DATA
);
315 return (word
>> ((reg
& 0x3) * 8)) & 0xff;
318 static u32
_ipw_read_reg32(struct ipw_priv
*priv
, u32 reg
)
322 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv
, reg
);
324 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, reg
);
325 value
= _ipw_read32(priv
, IPW_INDIRECT_DATA
);
326 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg
, value
);
330 /* iterative/auto-increment 32 bit reads and writes */
331 static void _ipw_read_indirect(struct ipw_priv
*priv
, u32 addr
, u8
* buf
,
334 u32 aligned_addr
= addr
& IPW_INDIRECT_ADDR_MASK
;
335 u32 dif_len
= addr
- aligned_addr
;
338 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr
, buf
, num
);
344 /* Read the first nibble byte by byte */
345 if (unlikely(dif_len
)) {
346 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, aligned_addr
);
347 /* Start reading at aligned_addr + dif_len */
348 for (i
= dif_len
; ((i
< 4) && (num
> 0)); i
++, num
--)
349 *buf
++ = _ipw_read8(priv
, IPW_INDIRECT_DATA
+ i
);
353 _ipw_write32(priv
, IPW_AUTOINC_ADDR
, aligned_addr
);
354 for (; num
>= 4; buf
+= 4, aligned_addr
+= 4, num
-= 4)
355 *(u32
*) buf
= _ipw_read32(priv
, IPW_AUTOINC_DATA
);
357 /* Copy the last nibble */
359 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, aligned_addr
);
360 for (i
= 0; num
> 0; i
++, num
--)
361 *buf
++ = ipw_read8(priv
, IPW_INDIRECT_DATA
+ i
);
365 static void _ipw_write_indirect(struct ipw_priv
*priv
, u32 addr
, u8
* buf
,
368 u32 aligned_addr
= addr
& IPW_INDIRECT_ADDR_MASK
;
369 u32 dif_len
= addr
- aligned_addr
;
372 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr
, buf
, num
);
378 /* Write the first nibble byte by byte */
379 if (unlikely(dif_len
)) {
380 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, aligned_addr
);
381 /* Start reading at aligned_addr + dif_len */
382 for (i
= dif_len
; ((i
< 4) && (num
> 0)); i
++, num
--, buf
++)
383 _ipw_write8(priv
, IPW_INDIRECT_DATA
+ i
, *buf
);
387 _ipw_write32(priv
, IPW_AUTOINC_ADDR
, aligned_addr
);
388 for (; num
>= 4; buf
+= 4, aligned_addr
+= 4, num
-= 4)
389 _ipw_write32(priv
, IPW_AUTOINC_DATA
, *(u32
*) buf
);
391 /* Copy the last nibble */
393 _ipw_write32(priv
, IPW_INDIRECT_ADDR
, aligned_addr
);
394 for (i
= 0; num
> 0; i
++, num
--, buf
++)
395 _ipw_write8(priv
, IPW_INDIRECT_DATA
+ i
, *buf
);
399 static void ipw_write_direct(struct ipw_priv
*priv
, u32 addr
, void *buf
,
402 memcpy_toio((priv
->hw_base
+ addr
), buf
, num
);
405 static inline void ipw_set_bit(struct ipw_priv
*priv
, u32 reg
, u32 mask
)
407 ipw_write32(priv
, reg
, ipw_read32(priv
, reg
) | mask
);
410 static inline void ipw_clear_bit(struct ipw_priv
*priv
, u32 reg
, u32 mask
)
412 ipw_write32(priv
, reg
, ipw_read32(priv
, reg
) & ~mask
);
415 static inline void ipw_enable_interrupts(struct ipw_priv
*priv
)
417 if (priv
->status
& STATUS_INT_ENABLED
)
419 priv
->status
|= STATUS_INT_ENABLED
;
420 ipw_write32(priv
, IPW_INTA_MASK_R
, IPW_INTA_MASK_ALL
);
423 static inline void ipw_disable_interrupts(struct ipw_priv
*priv
)
425 if (!(priv
->status
& STATUS_INT_ENABLED
))
427 priv
->status
&= ~STATUS_INT_ENABLED
;
428 ipw_write32(priv
, IPW_INTA_MASK_R
, ~IPW_INTA_MASK_ALL
);
431 static char *ipw_error_desc(u32 val
)
434 case IPW_FW_ERROR_OK
:
436 case IPW_FW_ERROR_FAIL
:
438 case IPW_FW_ERROR_MEMORY_UNDERFLOW
:
439 return "MEMORY_UNDERFLOW";
440 case IPW_FW_ERROR_MEMORY_OVERFLOW
:
441 return "MEMORY_OVERFLOW";
442 case IPW_FW_ERROR_BAD_PARAM
:
444 case IPW_FW_ERROR_BAD_CHECKSUM
:
445 return "BAD_CHECKSUM";
446 case IPW_FW_ERROR_NMI_INTERRUPT
:
447 return "NMI_INTERRUPT";
448 case IPW_FW_ERROR_BAD_DATABASE
:
449 return "BAD_DATABASE";
450 case IPW_FW_ERROR_ALLOC_FAIL
:
452 case IPW_FW_ERROR_DMA_UNDERRUN
:
453 return "DMA_UNDERRUN";
454 case IPW_FW_ERROR_DMA_STATUS
:
456 case IPW_FW_ERROR_DINO_ERROR
:
458 case IPW_FW_ERROR_EEPROM_ERROR
:
459 return "EEPROM_ERROR";
460 case IPW_FW_ERROR_SYSASSERT
:
462 case IPW_FW_ERROR_FATAL_ERROR
:
463 return "FATAL_ERROR";
465 return "UNKNOWN_ERROR";
469 static void ipw_dump_nic_error_log(struct ipw_priv
*priv
)
471 u32 desc
, time
, blink1
, blink2
, ilink1
, ilink2
, idata
, i
, count
, base
;
473 base
= ipw_read32(priv
, IPWSTATUS_ERROR_LOG
);
474 count
= ipw_read_reg32(priv
, base
);
476 if (ERROR_START_OFFSET
<= count
* ERROR_ELEM_SIZE
) {
477 IPW_ERROR("Start IPW Error Log Dump:\n");
478 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
479 priv
->status
, priv
->config
);
482 for (i
= ERROR_START_OFFSET
;
483 i
<= count
* ERROR_ELEM_SIZE
; i
+= ERROR_ELEM_SIZE
) {
484 desc
= ipw_read_reg32(priv
, base
+ i
);
485 time
= ipw_read_reg32(priv
, base
+ i
+ 1 * sizeof(u32
));
486 blink1
= ipw_read_reg32(priv
, base
+ i
+ 2 * sizeof(u32
));
487 blink2
= ipw_read_reg32(priv
, base
+ i
+ 3 * sizeof(u32
));
488 ilink1
= ipw_read_reg32(priv
, base
+ i
+ 4 * sizeof(u32
));
489 ilink2
= ipw_read_reg32(priv
, base
+ i
+ 5 * sizeof(u32
));
490 idata
= ipw_read_reg32(priv
, base
+ i
+ 6 * sizeof(u32
));
492 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
493 ipw_error_desc(desc
), time
, blink1
, blink2
,
494 ilink1
, ilink2
, idata
);
498 static void ipw_dump_nic_event_log(struct ipw_priv
*priv
)
500 u32 ev
, time
, data
, i
, count
, base
;
502 base
= ipw_read32(priv
, IPW_EVENT_LOG
);
503 count
= ipw_read_reg32(priv
, base
);
505 if (EVENT_START_OFFSET
<= count
* EVENT_ELEM_SIZE
)
506 IPW_ERROR("Start IPW Event Log Dump:\n");
508 for (i
= EVENT_START_OFFSET
;
509 i
<= count
* EVENT_ELEM_SIZE
; i
+= EVENT_ELEM_SIZE
) {
510 ev
= ipw_read_reg32(priv
, base
+ i
);
511 time
= ipw_read_reg32(priv
, base
+ i
+ 1 * sizeof(u32
));
512 data
= ipw_read_reg32(priv
, base
+ i
+ 2 * sizeof(u32
));
514 #ifdef CONFIG_IPW_DEBUG
515 IPW_ERROR("%i\t0x%08x\t%i\n", time
, data
, ev
);
520 static inline int ipw_is_init(struct ipw_priv
*priv
)
522 return (priv
->status
& STATUS_INIT
) ? 1 : 0;
525 static int ipw_get_ordinal(struct ipw_priv
*priv
, u32 ord
, void *val
, u32
* len
)
527 u32 addr
, field_info
, field_len
, field_count
, total_len
;
529 IPW_DEBUG_ORD("ordinal = %i\n", ord
);
531 if (!priv
|| !val
|| !len
) {
532 IPW_DEBUG_ORD("Invalid argument\n");
536 /* verify device ordinal tables have been initialized */
537 if (!priv
->table0_addr
|| !priv
->table1_addr
|| !priv
->table2_addr
) {
538 IPW_DEBUG_ORD("Access ordinals before initialization\n");
542 switch (IPW_ORD_TABLE_ID_MASK
& ord
) {
543 case IPW_ORD_TABLE_0_MASK
:
545 * TABLE 0: Direct access to a table of 32 bit values
547 * This is a very simple table with the data directly
548 * read from the table
551 /* remove the table id from the ordinal */
552 ord
&= IPW_ORD_TABLE_VALUE_MASK
;
555 if (ord
> priv
->table0_len
) {
556 IPW_DEBUG_ORD("ordinal value (%i) longer then "
557 "max (%i)\n", ord
, priv
->table0_len
);
561 /* verify we have enough room to store the value */
562 if (*len
< sizeof(u32
)) {
563 IPW_DEBUG_ORD("ordinal buffer length too small, "
564 "need %zd\n", sizeof(u32
));
568 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
569 ord
, priv
->table0_addr
+ (ord
<< 2));
573 *((u32
*) val
) = ipw_read32(priv
, priv
->table0_addr
+ ord
);
576 case IPW_ORD_TABLE_1_MASK
:
578 * TABLE 1: Indirect access to a table of 32 bit values
580 * This is a fairly large table of u32 values each
581 * representing starting addr for the data (which is
585 /* remove the table id from the ordinal */
586 ord
&= IPW_ORD_TABLE_VALUE_MASK
;
589 if (ord
> priv
->table1_len
) {
590 IPW_DEBUG_ORD("ordinal value too long\n");
594 /* verify we have enough room to store the value */
595 if (*len
< sizeof(u32
)) {
596 IPW_DEBUG_ORD("ordinal buffer length too small, "
597 "need %zd\n", sizeof(u32
));
602 ipw_read_reg32(priv
, (priv
->table1_addr
+ (ord
<< 2)));
606 case IPW_ORD_TABLE_2_MASK
:
608 * TABLE 2: Indirect access to a table of variable sized values
610 * This table consist of six values, each containing
611 * - dword containing the starting offset of the data
612 * - dword containing the lengh in the first 16bits
613 * and the count in the second 16bits
616 /* remove the table id from the ordinal */
617 ord
&= IPW_ORD_TABLE_VALUE_MASK
;
620 if (ord
> priv
->table2_len
) {
621 IPW_DEBUG_ORD("ordinal value too long\n");
625 /* get the address of statistic */
626 addr
= ipw_read_reg32(priv
, priv
->table2_addr
+ (ord
<< 3));
628 /* get the second DW of statistics ;
629 * two 16-bit words - first is length, second is count */
632 priv
->table2_addr
+ (ord
<< 3) +
635 /* get each entry length */
636 field_len
= *((u16
*) & field_info
);
638 /* get number of entries */
639 field_count
= *(((u16
*) & field_info
) + 1);
641 /* abort if not enought memory */
642 total_len
= field_len
* field_count
;
643 if (total_len
> *len
) {
652 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
653 "field_info = 0x%08x\n",
654 addr
, total_len
, field_info
);
655 ipw_read_indirect(priv
, addr
, val
, total_len
);
659 IPW_DEBUG_ORD("Invalid ordinal!\n");
667 static void ipw_init_ordinals(struct ipw_priv
*priv
)
669 priv
->table0_addr
= IPW_ORDINALS_TABLE_LOWER
;
670 priv
->table0_len
= ipw_read32(priv
, priv
->table0_addr
);
672 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
673 priv
->table0_addr
, priv
->table0_len
);
675 priv
->table1_addr
= ipw_read32(priv
, IPW_ORDINALS_TABLE_1
);
676 priv
->table1_len
= ipw_read_reg32(priv
, priv
->table1_addr
);
678 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
679 priv
->table1_addr
, priv
->table1_len
);
681 priv
->table2_addr
= ipw_read32(priv
, IPW_ORDINALS_TABLE_2
);
682 priv
->table2_len
= ipw_read_reg32(priv
, priv
->table2_addr
);
683 priv
->table2_len
&= 0x0000ffff; /* use first two bytes */
685 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
686 priv
->table2_addr
, priv
->table2_len
);
690 u32
ipw_register_toggle(u32 reg
)
692 reg
&= ~IPW_START_STANDBY
;
693 if (reg
& IPW_GATE_ODMA
)
694 reg
&= ~IPW_GATE_ODMA
;
695 if (reg
& IPW_GATE_IDMA
)
696 reg
&= ~IPW_GATE_IDMA
;
697 if (reg
& IPW_GATE_ADMA
)
698 reg
&= ~IPW_GATE_ADMA
;
704 * - On radio ON, turn on any LEDs that require to be on during start
705 * - On initialization, start unassociated blink
706 * - On association, disable unassociated blink
707 * - On disassociation, start unassociated blink
708 * - On radio OFF, turn off any LEDs started during radio on
711 #define LD_TIME_LINK_ON 300
712 #define LD_TIME_LINK_OFF 2700
713 #define LD_TIME_ACT_ON 250
715 void ipw_led_link_on(struct ipw_priv
*priv
)
720 /* If configured to not use LEDs, or nic_type is 1,
721 * then we don't toggle a LINK led */
722 if (priv
->config
& CFG_NO_LED
|| priv
->nic_type
== EEPROM_NIC_TYPE_1
)
725 spin_lock_irqsave(&priv
->lock
, flags
);
727 if (!(priv
->status
& STATUS_RF_KILL_MASK
) &&
728 !(priv
->status
& STATUS_LED_LINK_ON
)) {
729 IPW_DEBUG_LED("Link LED On\n");
730 led
= ipw_read_reg32(priv
, IPW_EVENT_REG
);
731 led
|= priv
->led_association_on
;
733 led
= ipw_register_toggle(led
);
735 IPW_DEBUG_LED("Reg: 0x%08X\n", led
);
736 ipw_write_reg32(priv
, IPW_EVENT_REG
, led
);
738 priv
->status
|= STATUS_LED_LINK_ON
;
740 /* If we aren't associated, schedule turning the LED off */
741 if (!(priv
->status
& STATUS_ASSOCIATED
))
742 queue_delayed_work(priv
->workqueue
,
747 spin_unlock_irqrestore(&priv
->lock
, flags
);
750 static void ipw_bg_led_link_on(void *data
)
752 struct ipw_priv
*priv
= data
;
754 ipw_led_link_on(data
);
758 void ipw_led_link_off(struct ipw_priv
*priv
)
763 /* If configured not to use LEDs, or nic type is 1,
764 * then we don't goggle the LINK led. */
765 if (priv
->config
& CFG_NO_LED
|| priv
->nic_type
== EEPROM_NIC_TYPE_1
)
768 spin_lock_irqsave(&priv
->lock
, flags
);
770 if (priv
->status
& STATUS_LED_LINK_ON
) {
771 led
= ipw_read_reg32(priv
, IPW_EVENT_REG
);
772 led
&= priv
->led_association_off
;
773 led
= ipw_register_toggle(led
);
775 IPW_DEBUG_LED("Reg: 0x%08X\n", led
);
776 ipw_write_reg32(priv
, IPW_EVENT_REG
, led
);
778 IPW_DEBUG_LED("Link LED Off\n");
780 priv
->status
&= ~STATUS_LED_LINK_ON
;
782 /* If we aren't associated and the radio is on, schedule
783 * turning the LED on (blink while unassociated) */
784 if (!(priv
->status
& STATUS_RF_KILL_MASK
) &&
785 !(priv
->status
& STATUS_ASSOCIATED
))
786 queue_delayed_work(priv
->workqueue
, &priv
->led_link_on
,
791 spin_unlock_irqrestore(&priv
->lock
, flags
);
794 static void ipw_bg_led_link_off(void *data
)
796 struct ipw_priv
*priv
= data
;
798 ipw_led_link_off(data
);
802 static inline void __ipw_led_activity_on(struct ipw_priv
*priv
)
806 if (priv
->config
& CFG_NO_LED
)
809 if (priv
->status
& STATUS_RF_KILL_MASK
)
812 if (!(priv
->status
& STATUS_LED_ACT_ON
)) {
813 led
= ipw_read_reg32(priv
, IPW_EVENT_REG
);
814 led
|= priv
->led_activity_on
;
816 led
= ipw_register_toggle(led
);
818 IPW_DEBUG_LED("Reg: 0x%08X\n", led
);
819 ipw_write_reg32(priv
, IPW_EVENT_REG
, led
);
821 IPW_DEBUG_LED("Activity LED On\n");
823 priv
->status
|= STATUS_LED_ACT_ON
;
825 cancel_delayed_work(&priv
->led_act_off
);
826 queue_delayed_work(priv
->workqueue
, &priv
->led_act_off
,
829 /* Reschedule LED off for full time period */
830 cancel_delayed_work(&priv
->led_act_off
);
831 queue_delayed_work(priv
->workqueue
, &priv
->led_act_off
,
836 void ipw_led_activity_on(struct ipw_priv
*priv
)
839 spin_lock_irqsave(&priv
->lock
, flags
);
840 __ipw_led_activity_on(priv
);
841 spin_unlock_irqrestore(&priv
->lock
, flags
);
844 void ipw_led_activity_off(struct ipw_priv
*priv
)
849 if (priv
->config
& CFG_NO_LED
)
852 spin_lock_irqsave(&priv
->lock
, flags
);
854 if (priv
->status
& STATUS_LED_ACT_ON
) {
855 led
= ipw_read_reg32(priv
, IPW_EVENT_REG
);
856 led
&= priv
->led_activity_off
;
858 led
= ipw_register_toggle(led
);
860 IPW_DEBUG_LED("Reg: 0x%08X\n", led
);
861 ipw_write_reg32(priv
, IPW_EVENT_REG
, led
);
863 IPW_DEBUG_LED("Activity LED Off\n");
865 priv
->status
&= ~STATUS_LED_ACT_ON
;
868 spin_unlock_irqrestore(&priv
->lock
, flags
);
871 static void ipw_bg_led_activity_off(void *data
)
873 struct ipw_priv
*priv
= data
;
875 ipw_led_activity_off(data
);
879 void ipw_led_band_on(struct ipw_priv
*priv
)
884 /* Only nic type 1 supports mode LEDs */
885 if (priv
->config
& CFG_NO_LED
||
886 priv
->nic_type
!= EEPROM_NIC_TYPE_1
|| !priv
->assoc_network
)
889 spin_lock_irqsave(&priv
->lock
, flags
);
891 led
= ipw_read_reg32(priv
, IPW_EVENT_REG
);
892 if (priv
->assoc_network
->mode
== IEEE_A
) {
893 led
|= priv
->led_ofdm_on
;
894 led
&= priv
->led_association_off
;
895 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
896 } else if (priv
->assoc_network
->mode
== IEEE_G
) {
897 led
|= priv
->led_ofdm_on
;
898 led
|= priv
->led_association_on
;
899 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
901 led
&= priv
->led_ofdm_off
;
902 led
|= priv
->led_association_on
;
903 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
906 led
= ipw_register_toggle(led
);
908 IPW_DEBUG_LED("Reg: 0x%08X\n", led
);
909 ipw_write_reg32(priv
, IPW_EVENT_REG
, led
);
911 spin_unlock_irqrestore(&priv
->lock
, flags
);
914 void ipw_led_band_off(struct ipw_priv
*priv
)
919 /* Only nic type 1 supports mode LEDs */
920 if (priv
->config
& CFG_NO_LED
|| priv
->nic_type
!= EEPROM_NIC_TYPE_1
)
923 spin_lock_irqsave(&priv
->lock
, flags
);
925 led
= ipw_read_reg32(priv
, IPW_EVENT_REG
);
926 led
&= priv
->led_ofdm_off
;
927 led
&= priv
->led_association_off
;
929 led
= ipw_register_toggle(led
);
931 IPW_DEBUG_LED("Reg: 0x%08X\n", led
);
932 ipw_write_reg32(priv
, IPW_EVENT_REG
, led
);
934 spin_unlock_irqrestore(&priv
->lock
, flags
);
937 void ipw_led_radio_on(struct ipw_priv
*priv
)
939 ipw_led_link_on(priv
);
942 void ipw_led_radio_off(struct ipw_priv
*priv
)
944 ipw_led_activity_off(priv
);
945 ipw_led_link_off(priv
);
948 void ipw_led_link_up(struct ipw_priv
*priv
)
950 /* Set the Link Led on for all nic types */
951 ipw_led_link_on(priv
);
954 void ipw_led_link_down(struct ipw_priv
*priv
)
956 ipw_led_activity_off(priv
);
957 ipw_led_link_off(priv
);
959 if (priv
->status
& STATUS_RF_KILL_MASK
)
960 ipw_led_radio_off(priv
);
963 void ipw_led_init(struct ipw_priv
*priv
)
965 priv
->nic_type
= priv
->eeprom
[EEPROM_NIC_TYPE
];
967 /* Set the default PINs for the link and activity leds */
968 priv
->led_activity_on
= IPW_ACTIVITY_LED
;
969 priv
->led_activity_off
= ~(IPW_ACTIVITY_LED
);
971 priv
->led_association_on
= IPW_ASSOCIATED_LED
;
972 priv
->led_association_off
= ~(IPW_ASSOCIATED_LED
);
974 /* Set the default PINs for the OFDM leds */
975 priv
->led_ofdm_on
= IPW_OFDM_LED
;
976 priv
->led_ofdm_off
= ~(IPW_OFDM_LED
);
978 switch (priv
->nic_type
) {
979 case EEPROM_NIC_TYPE_1
:
980 /* In this NIC type, the LEDs are reversed.... */
981 priv
->led_activity_on
= IPW_ASSOCIATED_LED
;
982 priv
->led_activity_off
= ~(IPW_ASSOCIATED_LED
);
983 priv
->led_association_on
= IPW_ACTIVITY_LED
;
984 priv
->led_association_off
= ~(IPW_ACTIVITY_LED
);
986 if (!(priv
->config
& CFG_NO_LED
))
987 ipw_led_band_on(priv
);
989 /* And we don't blink link LEDs for this nic, so
990 * just return here */
993 case EEPROM_NIC_TYPE_3
:
994 case EEPROM_NIC_TYPE_2
:
995 case EEPROM_NIC_TYPE_4
:
996 case EEPROM_NIC_TYPE_0
:
1000 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1002 priv
->nic_type
= EEPROM_NIC_TYPE_0
;
1006 if (!(priv
->config
& CFG_NO_LED
)) {
1007 if (priv
->status
& STATUS_ASSOCIATED
)
1008 ipw_led_link_on(priv
);
1010 ipw_led_link_off(priv
);
1014 void ipw_led_shutdown(struct ipw_priv
*priv
)
1016 ipw_led_activity_off(priv
);
1017 ipw_led_link_off(priv
);
1018 ipw_led_band_off(priv
);
1019 cancel_delayed_work(&priv
->led_link_on
);
1020 cancel_delayed_work(&priv
->led_link_off
);
1021 cancel_delayed_work(&priv
->led_act_off
);
1025 * The following adds a new attribute to the sysfs representation
1026 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1027 * used for controling the debug level.
1029 * See the level definitions in ipw for details.
1031 static ssize_t
show_debug_level(struct device_driver
*d
, char *buf
)
1033 return sprintf(buf
, "0x%08X\n", ipw_debug_level
);
1036 static ssize_t
store_debug_level(struct device_driver
*d
, const char *buf
,
1039 char *p
= (char *)buf
;
1042 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
1044 if (p
[0] == 'x' || p
[0] == 'X')
1046 val
= simple_strtoul(p
, &p
, 16);
1048 val
= simple_strtoul(p
, &p
, 10);
1050 printk(KERN_INFO DRV_NAME
1051 ": %s is not in hex or decimal form.\n", buf
);
1053 ipw_debug_level
= val
;
1055 return strnlen(buf
, count
);
1058 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
1059 show_debug_level
, store_debug_level
);
1061 static ssize_t
show_scan_age(struct device
*d
, struct device_attribute
*attr
,
1064 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1065 return sprintf(buf
, "%d\n", priv
->ieee
->scan_age
);
1068 static ssize_t
store_scan_age(struct device
*d
, struct device_attribute
*attr
,
1069 const char *buf
, size_t count
)
1071 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1072 #ifdef CONFIG_IPW_DEBUG
1073 struct net_device
*dev
= priv
->net_dev
;
1075 char buffer
[] = "00000000";
1077 (sizeof(buffer
) - 1) > count
? count
: sizeof(buffer
) - 1;
1081 IPW_DEBUG_INFO("enter\n");
1083 strncpy(buffer
, buf
, len
);
1086 if (p
[1] == 'x' || p
[1] == 'X' || p
[0] == 'x' || p
[0] == 'X') {
1088 if (p
[0] == 'x' || p
[0] == 'X')
1090 val
= simple_strtoul(p
, &p
, 16);
1092 val
= simple_strtoul(p
, &p
, 10);
1094 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev
->name
);
1096 priv
->ieee
->scan_age
= val
;
1097 IPW_DEBUG_INFO("set scan_age = %u\n", priv
->ieee
->scan_age
);
1100 IPW_DEBUG_INFO("exit\n");
1104 static DEVICE_ATTR(scan_age
, S_IWUSR
| S_IRUGO
, show_scan_age
, store_scan_age
);
1106 static ssize_t
show_led(struct device
*d
, struct device_attribute
*attr
,
1109 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1110 return sprintf(buf
, "%d\n", (priv
->config
& CFG_NO_LED
) ? 0 : 1);
1113 static ssize_t
store_led(struct device
*d
, struct device_attribute
*attr
,
1114 const char *buf
, size_t count
)
1116 struct ipw_priv
*priv
= dev_get_drvdata(d
);
1118 IPW_DEBUG_INFO("enter\n");
1124 IPW_DEBUG_LED("Disabling LED control.\n");
1125 priv
->config
|= CFG_NO_LED
;
1126 ipw_led_shutdown(priv
);
1128 IPW_DEBUG_LED("Enabling LED control.\n");
1129 priv
->config
&= ~CFG_NO_LED
;
1133 IPW_DEBUG_INFO("exit\n");
1137 static DEVICE_ATTR(led
, S_IWUSR
| S_IRUGO
, show_led
, store_led
);
1139 static ssize_t
show_status(struct device
*d
,
1140 struct device_attribute
*attr
, char *buf
)
1142 struct ipw_priv
*p
= d
->driver_data
;
1143 return sprintf(buf
, "0x%08x\n", (int)p
->status
);
1146 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
1148 static ssize_t
show_cfg(struct device
*d
, struct device_attribute
*attr
,
1151 struct ipw_priv
*p
= d
->driver_data
;
1152 return sprintf(buf
, "0x%08x\n", (int)p
->config
);
1155 static DEVICE_ATTR(cfg
, S_IRUGO
, show_cfg
, NULL
);
1157 static ssize_t
show_nic_type(struct device
*d
,
1158 struct device_attribute
*attr
, char *buf
)
1160 struct ipw_priv
*priv
= d
->driver_data
;
1161 return sprintf(buf
, "TYPE: %d\n", priv
->nic_type
);
1164 static DEVICE_ATTR(nic_type
, S_IRUGO
, show_nic_type
, NULL
);
1166 static ssize_t
dump_error_log(struct device
*d
,
1167 struct device_attribute
*attr
, const char *buf
,
1170 char *p
= (char *)buf
;
1173 ipw_dump_nic_error_log((struct ipw_priv
*)d
->driver_data
);
1175 return strnlen(buf
, count
);
1178 static DEVICE_ATTR(dump_errors
, S_IWUSR
, NULL
, dump_error_log
);
1180 static ssize_t
dump_event_log(struct device
*d
,
1181 struct device_attribute
*attr
, const char *buf
,
1184 char *p
= (char *)buf
;
1187 ipw_dump_nic_event_log((struct ipw_priv
*)d
->driver_data
);
1189 return strnlen(buf
, count
);
1192 static DEVICE_ATTR(dump_events
, S_IWUSR
, NULL
, dump_event_log
);
1194 static ssize_t
show_ucode_version(struct device
*d
,
1195 struct device_attribute
*attr
, char *buf
)
1197 u32 len
= sizeof(u32
), tmp
= 0;
1198 struct ipw_priv
*p
= d
->driver_data
;
1200 if (ipw_get_ordinal(p
, IPW_ORD_STAT_UCODE_VERSION
, &tmp
, &len
))
1203 return sprintf(buf
, "0x%08x\n", tmp
);
1206 static DEVICE_ATTR(ucode_version
, S_IWUSR
| S_IRUGO
, show_ucode_version
, NULL
);
1208 static ssize_t
show_rtc(struct device
*d
, struct device_attribute
*attr
,
1211 u32 len
= sizeof(u32
), tmp
= 0;
1212 struct ipw_priv
*p
= d
->driver_data
;
1214 if (ipw_get_ordinal(p
, IPW_ORD_STAT_RTC
, &tmp
, &len
))
1217 return sprintf(buf
, "0x%08x\n", tmp
);
1220 static DEVICE_ATTR(rtc
, S_IWUSR
| S_IRUGO
, show_rtc
, NULL
);
1223 * Add a device attribute to view/control the delay between eeprom
1226 static ssize_t
show_eeprom_delay(struct device
*d
,
1227 struct device_attribute
*attr
, char *buf
)
1229 int n
= ((struct ipw_priv
*)d
->driver_data
)->eeprom_delay
;
1230 return sprintf(buf
, "%i\n", n
);
1232 static ssize_t
store_eeprom_delay(struct device
*d
,
1233 struct device_attribute
*attr
,
1234 const char *buf
, size_t count
)
1236 struct ipw_priv
*p
= d
->driver_data
;
1237 sscanf(buf
, "%i", &p
->eeprom_delay
);
1238 return strnlen(buf
, count
);
1241 static DEVICE_ATTR(eeprom_delay
, S_IWUSR
| S_IRUGO
,
1242 show_eeprom_delay
, store_eeprom_delay
);
1244 static ssize_t
show_command_event_reg(struct device
*d
,
1245 struct device_attribute
*attr
, char *buf
)
1248 struct ipw_priv
*p
= d
->driver_data
;
1250 reg
= ipw_read_reg32(p
, IPW_INTERNAL_CMD_EVENT
);
1251 return sprintf(buf
, "0x%08x\n", reg
);
1253 static ssize_t
store_command_event_reg(struct device
*d
,
1254 struct device_attribute
*attr
,
1255 const char *buf
, size_t count
)
1258 struct ipw_priv
*p
= d
->driver_data
;
1260 sscanf(buf
, "%x", ®
);
1261 ipw_write_reg32(p
, IPW_INTERNAL_CMD_EVENT
, reg
);
1262 return strnlen(buf
, count
);
1265 static DEVICE_ATTR(command_event_reg
, S_IWUSR
| S_IRUGO
,
1266 show_command_event_reg
, store_command_event_reg
);
1268 static ssize_t
show_mem_gpio_reg(struct device
*d
,
1269 struct device_attribute
*attr
, char *buf
)
1272 struct ipw_priv
*p
= d
->driver_data
;
1274 reg
= ipw_read_reg32(p
, 0x301100);
1275 return sprintf(buf
, "0x%08x\n", reg
);
1277 static ssize_t
store_mem_gpio_reg(struct device
*d
,
1278 struct device_attribute
*attr
,
1279 const char *buf
, size_t count
)
1282 struct ipw_priv
*p
= d
->driver_data
;
1284 sscanf(buf
, "%x", ®
);
1285 ipw_write_reg32(p
, 0x301100, reg
);
1286 return strnlen(buf
, count
);
1289 static DEVICE_ATTR(mem_gpio_reg
, S_IWUSR
| S_IRUGO
,
1290 show_mem_gpio_reg
, store_mem_gpio_reg
);
1292 static ssize_t
show_indirect_dword(struct device
*d
,
1293 struct device_attribute
*attr
, char *buf
)
1296 struct ipw_priv
*priv
= d
->driver_data
;
1298 if (priv
->status
& STATUS_INDIRECT_DWORD
)
1299 reg
= ipw_read_reg32(priv
, priv
->indirect_dword
);
1303 return sprintf(buf
, "0x%08x\n", reg
);
1305 static ssize_t
store_indirect_dword(struct device
*d
,
1306 struct device_attribute
*attr
,
1307 const char *buf
, size_t count
)
1309 struct ipw_priv
*priv
= d
->driver_data
;
1311 sscanf(buf
, "%x", &priv
->indirect_dword
);
1312 priv
->status
|= STATUS_INDIRECT_DWORD
;
1313 return strnlen(buf
, count
);
1316 static DEVICE_ATTR(indirect_dword
, S_IWUSR
| S_IRUGO
,
1317 show_indirect_dword
, store_indirect_dword
);
1319 static ssize_t
show_indirect_byte(struct device
*d
,
1320 struct device_attribute
*attr
, char *buf
)
1323 struct ipw_priv
*priv
= d
->driver_data
;
1325 if (priv
->status
& STATUS_INDIRECT_BYTE
)
1326 reg
= ipw_read_reg8(priv
, priv
->indirect_byte
);
1330 return sprintf(buf
, "0x%02x\n", reg
);
1332 static ssize_t
store_indirect_byte(struct device
*d
,
1333 struct device_attribute
*attr
,
1334 const char *buf
, size_t count
)
1336 struct ipw_priv
*priv
= d
->driver_data
;
1338 sscanf(buf
, "%x", &priv
->indirect_byte
);
1339 priv
->status
|= STATUS_INDIRECT_BYTE
;
1340 return strnlen(buf
, count
);
1343 static DEVICE_ATTR(indirect_byte
, S_IWUSR
| S_IRUGO
,
1344 show_indirect_byte
, store_indirect_byte
);
1346 static ssize_t
show_direct_dword(struct device
*d
,
1347 struct device_attribute
*attr
, char *buf
)
1350 struct ipw_priv
*priv
= d
->driver_data
;
1352 if (priv
->status
& STATUS_DIRECT_DWORD
)
1353 reg
= ipw_read32(priv
, priv
->direct_dword
);
1357 return sprintf(buf
, "0x%08x\n", reg
);
1359 static ssize_t
store_direct_dword(struct device
*d
,
1360 struct device_attribute
*attr
,
1361 const char *buf
, size_t count
)
1363 struct ipw_priv
*priv
= d
->driver_data
;
1365 sscanf(buf
, "%x", &priv
->direct_dword
);
1366 priv
->status
|= STATUS_DIRECT_DWORD
;
1367 return strnlen(buf
, count
);
1370 static DEVICE_ATTR(direct_dword
, S_IWUSR
| S_IRUGO
,
1371 show_direct_dword
, store_direct_dword
);
1373 static inline int rf_kill_active(struct ipw_priv
*priv
)
1375 if (0 == (ipw_read32(priv
, 0x30) & 0x10000))
1376 priv
->status
|= STATUS_RF_KILL_HW
;
1378 priv
->status
&= ~STATUS_RF_KILL_HW
;
1380 return (priv
->status
& STATUS_RF_KILL_HW
) ? 1 : 0;
1383 static ssize_t
show_rf_kill(struct device
*d
, struct device_attribute
*attr
,
1386 /* 0 - RF kill not enabled
1387 1 - SW based RF kill active (sysfs)
1388 2 - HW based RF kill active
1389 3 - Both HW and SW baed RF kill active */
1390 struct ipw_priv
*priv
= d
->driver_data
;
1391 int val
= ((priv
->status
& STATUS_RF_KILL_SW
) ? 0x1 : 0x0) |
1392 (rf_kill_active(priv
) ? 0x2 : 0x0);
1393 return sprintf(buf
, "%i\n", val
);
1396 static int ipw_radio_kill_sw(struct ipw_priv
*priv
, int disable_radio
)
1398 if ((disable_radio
? 1 : 0) ==
1399 ((priv
->status
& STATUS_RF_KILL_SW
) ? 1 : 0))
1402 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1403 disable_radio
? "OFF" : "ON");
1405 if (disable_radio
) {
1406 priv
->status
|= STATUS_RF_KILL_SW
;
1408 if (priv
->workqueue
)
1409 cancel_delayed_work(&priv
->request_scan
);
1410 queue_work(priv
->workqueue
, &priv
->down
);
1412 priv
->status
&= ~STATUS_RF_KILL_SW
;
1413 if (rf_kill_active(priv
)) {
1414 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1415 "disabled by HW switch\n");
1416 /* Make sure the RF_KILL check timer is running */
1417 cancel_delayed_work(&priv
->rf_kill
);
1418 queue_delayed_work(priv
->workqueue
, &priv
->rf_kill
,
1421 queue_work(priv
->workqueue
, &priv
->up
);
1427 static ssize_t
store_rf_kill(struct device
*d
, struct device_attribute
*attr
,
1428 const char *buf
, size_t count
)
1430 struct ipw_priv
*priv
= d
->driver_data
;
1432 ipw_radio_kill_sw(priv
, buf
[0] == '1');
1437 static DEVICE_ATTR(rf_kill
, S_IWUSR
| S_IRUGO
, show_rf_kill
, store_rf_kill
);
1439 static ssize_t
show_speed_scan(struct device
*d
, struct device_attribute
*attr
,
1442 struct ipw_priv
*priv
= (struct ipw_priv
*)d
->driver_data
;
1443 int pos
= 0, len
= 0;
1444 if (priv
->config
& CFG_SPEED_SCAN
) {
1445 while (priv
->speed_scan
[pos
] != 0)
1446 len
+= sprintf(&buf
[len
], "%d ",
1447 priv
->speed_scan
[pos
++]);
1448 return len
+ sprintf(&buf
[len
], "\n");
1451 return sprintf(buf
, "0\n");
1454 static ssize_t
store_speed_scan(struct device
*d
, struct device_attribute
*attr
,
1455 const char *buf
, size_t count
)
1457 struct ipw_priv
*priv
= (struct ipw_priv
*)d
->driver_data
;
1458 int channel
, pos
= 0;
1459 const char *p
= buf
;
1461 /* list of space separated channels to scan, optionally ending with 0 */
1462 while ((channel
= simple_strtol(p
, NULL
, 0))) {
1463 if (pos
== MAX_SPEED_SCAN
- 1) {
1464 priv
->speed_scan
[pos
] = 0;
1468 if (ieee80211_is_valid_channel(priv
->ieee
, channel
))
1469 priv
->speed_scan
[pos
++] = channel
;
1471 IPW_WARNING("Skipping invalid channel request: %d\n",
1476 while (*p
== ' ' || *p
== '\t')
1481 priv
->config
&= ~CFG_SPEED_SCAN
;
1483 priv
->speed_scan_pos
= 0;
1484 priv
->config
|= CFG_SPEED_SCAN
;
1490 static DEVICE_ATTR(speed_scan
, S_IWUSR
| S_IRUGO
, show_speed_scan
,
1493 static ssize_t
show_net_stats(struct device
*d
, struct device_attribute
*attr
,
1496 struct ipw_priv
*priv
= (struct ipw_priv
*)d
->driver_data
;
1497 return sprintf(buf
, "%c\n", (priv
->config
& CFG_NET_STATS
) ? '1' : '0');
1500 static ssize_t
store_net_stats(struct device
*d
, struct device_attribute
*attr
,
1501 const char *buf
, size_t count
)
1503 struct ipw_priv
*priv
= (struct ipw_priv
*)d
->driver_data
;
1505 priv
->config
|= CFG_NET_STATS
;
1507 priv
->config
&= ~CFG_NET_STATS
;
1512 static DEVICE_ATTR(net_stats
, S_IWUSR
| S_IRUGO
,
1513 show_net_stats
, store_net_stats
);
1515 static void notify_wx_assoc_event(struct ipw_priv
*priv
)
1517 union iwreq_data wrqu
;
1518 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1519 if (priv
->status
& STATUS_ASSOCIATED
)
1520 memcpy(wrqu
.ap_addr
.sa_data
, priv
->bssid
, ETH_ALEN
);
1522 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
1523 wireless_send_event(priv
->net_dev
, SIOCGIWAP
, &wrqu
, NULL
);
1526 static void ipw_irq_tasklet(struct ipw_priv
*priv
)
1528 u32 inta
, inta_mask
, handled
= 0;
1529 unsigned long flags
;
1532 spin_lock_irqsave(&priv
->lock
, flags
);
1534 inta
= ipw_read32(priv
, IPW_INTA_RW
);
1535 inta_mask
= ipw_read32(priv
, IPW_INTA_MASK_R
);
1536 inta
&= (IPW_INTA_MASK_ALL
& inta_mask
);
1538 /* Add any cached INTA values that need to be handled */
1539 inta
|= priv
->isr_inta
;
1541 /* handle all the justifications for the interrupt */
1542 if (inta
& IPW_INTA_BIT_RX_TRANSFER
) {
1544 handled
|= IPW_INTA_BIT_RX_TRANSFER
;
1547 if (inta
& IPW_INTA_BIT_TX_CMD_QUEUE
) {
1548 IPW_DEBUG_HC("Command completed.\n");
1549 rc
= ipw_queue_tx_reclaim(priv
, &priv
->txq_cmd
, -1);
1550 priv
->status
&= ~STATUS_HCMD_ACTIVE
;
1551 wake_up_interruptible(&priv
->wait_command_queue
);
1552 handled
|= IPW_INTA_BIT_TX_CMD_QUEUE
;
1555 if (inta
& IPW_INTA_BIT_TX_QUEUE_1
) {
1556 IPW_DEBUG_TX("TX_QUEUE_1\n");
1557 rc
= ipw_queue_tx_reclaim(priv
, &priv
->txq
[0], 0);
1558 handled
|= IPW_INTA_BIT_TX_QUEUE_1
;
1561 if (inta
& IPW_INTA_BIT_TX_QUEUE_2
) {
1562 IPW_DEBUG_TX("TX_QUEUE_2\n");
1563 rc
= ipw_queue_tx_reclaim(priv
, &priv
->txq
[1], 1);
1564 handled
|= IPW_INTA_BIT_TX_QUEUE_2
;
1567 if (inta
& IPW_INTA_BIT_TX_QUEUE_3
) {
1568 IPW_DEBUG_TX("TX_QUEUE_3\n");
1569 rc
= ipw_queue_tx_reclaim(priv
, &priv
->txq
[2], 2);
1570 handled
|= IPW_INTA_BIT_TX_QUEUE_3
;
1573 if (inta
& IPW_INTA_BIT_TX_QUEUE_4
) {
1574 IPW_DEBUG_TX("TX_QUEUE_4\n");
1575 rc
= ipw_queue_tx_reclaim(priv
, &priv
->txq
[3], 3);
1576 handled
|= IPW_INTA_BIT_TX_QUEUE_4
;
1579 if (inta
& IPW_INTA_BIT_STATUS_CHANGE
) {
1580 IPW_WARNING("STATUS_CHANGE\n");
1581 handled
|= IPW_INTA_BIT_STATUS_CHANGE
;
1584 if (inta
& IPW_INTA_BIT_BEACON_PERIOD_EXPIRED
) {
1585 IPW_WARNING("TX_PERIOD_EXPIRED\n");
1586 handled
|= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED
;
1589 if (inta
& IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE
) {
1590 IPW_WARNING("HOST_CMD_DONE\n");
1591 handled
|= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE
;
1594 if (inta
& IPW_INTA_BIT_FW_INITIALIZATION_DONE
) {
1595 IPW_WARNING("FW_INITIALIZATION_DONE\n");
1596 handled
|= IPW_INTA_BIT_FW_INITIALIZATION_DONE
;
1599 if (inta
& IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE
) {
1600 IPW_WARNING("PHY_OFF_DONE\n");
1601 handled
|= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE
;
1604 if (inta
& IPW_INTA_BIT_RF_KILL_DONE
) {
1605 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1606 priv
->status
|= STATUS_RF_KILL_HW
;
1607 wake_up_interruptible(&priv
->wait_command_queue
);
1608 priv
->status
&= ~(STATUS_ASSOCIATED
| STATUS_ASSOCIATING
);
1609 cancel_delayed_work(&priv
->request_scan
);
1610 schedule_work(&priv
->link_down
);
1611 queue_delayed_work(priv
->workqueue
, &priv
->rf_kill
, 2 * HZ
);
1612 handled
|= IPW_INTA_BIT_RF_KILL_DONE
;
1615 if (inta
& IPW_INTA_BIT_FATAL_ERROR
) {
1616 IPW_ERROR("Firmware error detected. Restarting.\n");
1617 #ifdef CONFIG_IPW_DEBUG
1618 if (ipw_debug_level
& IPW_DL_FW_ERRORS
) {
1619 ipw_dump_nic_error_log(priv
);
1620 ipw_dump_nic_event_log(priv
);
1623 /* XXX: If hardware encryption is for WPA/WPA2,
1624 * we have to notify the supplicant. */
1625 if (priv
->ieee
->sec
.encrypt
) {
1626 priv
->status
&= ~STATUS_ASSOCIATED
;
1627 notify_wx_assoc_event(priv
);
1630 /* Keep the restart process from trying to send host
1631 * commands by clearing the INIT status bit */
1632 priv
->status
&= ~STATUS_INIT
;
1634 /* Cancel currently queued command. */
1635 priv
->status
&= ~STATUS_HCMD_ACTIVE
;
1636 wake_up_interruptible(&priv
->wait_command_queue
);
1638 queue_work(priv
->workqueue
, &priv
->adapter_restart
);
1639 handled
|= IPW_INTA_BIT_FATAL_ERROR
;
1642 if (inta
& IPW_INTA_BIT_PARITY_ERROR
) {
1643 IPW_ERROR("Parity error\n");
1644 handled
|= IPW_INTA_BIT_PARITY_ERROR
;
1647 if (handled
!= inta
) {
1648 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
1651 /* enable all interrupts */
1652 ipw_enable_interrupts(priv
);
1654 spin_unlock_irqrestore(&priv
->lock
, flags
);
1657 #ifdef CONFIG_IPW_DEBUG
1658 #define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1659 static char *get_cmd_string(u8 cmd
)
1662 IPW_CMD(HOST_COMPLETE
);
1663 IPW_CMD(POWER_DOWN
);
1664 IPW_CMD(SYSTEM_CONFIG
);
1665 IPW_CMD(MULTICAST_ADDRESS
);
1667 IPW_CMD(ADAPTER_ADDRESS
);
1669 IPW_CMD(RTS_THRESHOLD
);
1670 IPW_CMD(FRAG_THRESHOLD
);
1671 IPW_CMD(POWER_MODE
);
1673 IPW_CMD(TGI_TX_KEY
);
1674 IPW_CMD(SCAN_REQUEST
);
1675 IPW_CMD(SCAN_REQUEST_EXT
);
1677 IPW_CMD(SUPPORTED_RATES
);
1678 IPW_CMD(SCAN_ABORT
);
1680 IPW_CMD(QOS_PARAMETERS
);
1681 IPW_CMD(DINO_CONFIG
);
1682 IPW_CMD(RSN_CAPABILITIES
);
1684 IPW_CMD(CARD_DISABLE
);
1685 IPW_CMD(SEED_NUMBER
);
1687 IPW_CMD(COUNTRY_INFO
);
1688 IPW_CMD(AIRONET_INFO
);
1689 IPW_CMD(AP_TX_POWER
);
1691 IPW_CMD(CCX_VER_INFO
);
1692 IPW_CMD(SET_CALIBRATION
);
1693 IPW_CMD(SENSITIVITY_CALIB
);
1694 IPW_CMD(RETRY_LIMIT
);
1695 IPW_CMD(IPW_PRE_POWER_DOWN
);
1696 IPW_CMD(VAP_BEACON_TEMPLATE
);
1697 IPW_CMD(VAP_DTIM_PERIOD
);
1698 IPW_CMD(EXT_SUPPORTED_RATES
);
1699 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT
);
1700 IPW_CMD(VAP_QUIET_INTERVALS
);
1701 IPW_CMD(VAP_CHANNEL_SWITCH
);
1702 IPW_CMD(VAP_MANDATORY_CHANNELS
);
1703 IPW_CMD(VAP_CELL_PWR_LIMIT
);
1704 IPW_CMD(VAP_CF_PARAM_SET
);
1705 IPW_CMD(VAP_SET_BEACONING_STATE
);
1706 IPW_CMD(MEASUREMENT
);
1707 IPW_CMD(POWER_CAPABILITY
);
1708 IPW_CMD(SUPPORTED_CHANNELS
);
1709 IPW_CMD(TPC_REPORT
);
1711 IPW_CMD(PRODUCTION_COMMAND
);
1718 #define HOST_COMPLETE_TIMEOUT HZ
1719 static int ipw_send_cmd(struct ipw_priv
*priv
, struct host_cmd
*cmd
)
1722 unsigned long flags
;
1724 spin_lock_irqsave(&priv
->lock
, flags
);
1725 if (priv
->status
& STATUS_HCMD_ACTIVE
) {
1726 IPW_ERROR("Already sending a command\n");
1727 spin_unlock_irqrestore(&priv
->lock
, flags
);
1731 priv
->status
|= STATUS_HCMD_ACTIVE
;
1733 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
1734 get_cmd_string(cmd
->cmd
), cmd
->cmd
, cmd
->len
,
1736 printk_buf(IPW_DL_HOST_COMMAND
, (u8
*) cmd
->param
, cmd
->len
);
1738 rc
= ipw_queue_tx_hcmd(priv
, cmd
->cmd
, &cmd
->param
, cmd
->len
, 0);
1740 priv
->status
&= ~STATUS_HCMD_ACTIVE
;
1741 spin_unlock_irqrestore(&priv
->lock
, flags
);
1744 spin_unlock_irqrestore(&priv
->lock
, flags
);
1746 rc
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
1748 status
& STATUS_HCMD_ACTIVE
),
1749 HOST_COMPLETE_TIMEOUT
);
1751 spin_lock_irqsave(&priv
->lock
, flags
);
1752 if (priv
->status
& STATUS_HCMD_ACTIVE
) {
1753 IPW_DEBUG_INFO("Command completion failed out after "
1755 1000 * (HOST_COMPLETE_TIMEOUT
/ HZ
));
1756 priv
->status
&= ~STATUS_HCMD_ACTIVE
;
1757 spin_unlock_irqrestore(&priv
->lock
, flags
);
1760 spin_unlock_irqrestore(&priv
->lock
, flags
);
1763 if (priv
->status
& STATUS_RF_KILL_HW
) {
1764 IPW_DEBUG_INFO("Command aborted due to RF Kill Switch\n");
1771 static int ipw_send_host_complete(struct ipw_priv
*priv
)
1773 struct host_cmd cmd
= {
1774 .cmd
= IPW_CMD_HOST_COMPLETE
,
1779 IPW_ERROR("Invalid args\n");
1783 if (ipw_send_cmd(priv
, &cmd
)) {
1784 IPW_ERROR("failed to send HOST_COMPLETE command\n");
1791 static int ipw_send_system_config(struct ipw_priv
*priv
,
1792 struct ipw_sys_config
*config
)
1794 struct host_cmd cmd
= {
1795 .cmd
= IPW_CMD_SYSTEM_CONFIG
,
1796 .len
= sizeof(*config
)
1799 if (!priv
|| !config
) {
1800 IPW_ERROR("Invalid args\n");
1804 memcpy(cmd
.param
, config
, sizeof(*config
));
1805 if (ipw_send_cmd(priv
, &cmd
)) {
1806 IPW_ERROR("failed to send SYSTEM_CONFIG command\n");
1813 static int ipw_send_ssid(struct ipw_priv
*priv
, u8
* ssid
, int len
)
1815 struct host_cmd cmd
= {
1816 .cmd
= IPW_CMD_SSID
,
1817 .len
= min(len
, IW_ESSID_MAX_SIZE
)
1820 if (!priv
|| !ssid
) {
1821 IPW_ERROR("Invalid args\n");
1825 memcpy(cmd
.param
, ssid
, cmd
.len
);
1826 if (ipw_send_cmd(priv
, &cmd
)) {
1827 IPW_ERROR("failed to send SSID command\n");
1834 static int ipw_send_adapter_address(struct ipw_priv
*priv
, u8
* mac
)
1836 struct host_cmd cmd
= {
1837 .cmd
= IPW_CMD_ADAPTER_ADDRESS
,
1841 if (!priv
|| !mac
) {
1842 IPW_ERROR("Invalid args\n");
1846 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT
"\n",
1847 priv
->net_dev
->name
, MAC_ARG(mac
));
1849 memcpy(cmd
.param
, mac
, ETH_ALEN
);
1850 if (ipw_send_cmd(priv
, &cmd
)) {
1851 IPW_ERROR("failed to send ADAPTER_ADDRESS command\n");
1859 * NOTE: This must be executed from our workqueue as it results in udelay
1860 * being called which may corrupt the keyboard if executed on default
1863 static void ipw_adapter_restart(void *adapter
)
1865 struct ipw_priv
*priv
= adapter
;
1867 if (priv
->status
& STATUS_RF_KILL_MASK
)
1872 if (priv
->assoc_network
&&
1873 (priv
->assoc_network
->capability
& WLAN_CAPABILITY_IBSS
))
1874 ipw_remove_current_network(priv
);
1877 IPW_ERROR("Failed to up device\n");
1882 static void ipw_bg_adapter_restart(void *data
)
1884 struct ipw_priv
*priv
= data
;
1886 ipw_adapter_restart(data
);
1890 #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
1892 static void ipw_scan_check(void *data
)
1894 struct ipw_priv
*priv
= data
;
1895 if (priv
->status
& (STATUS_SCANNING
| STATUS_SCAN_ABORTING
)) {
1896 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
1897 "adapter (%dms).\n",
1898 IPW_SCAN_CHECK_WATCHDOG
/ 100);
1899 queue_work(priv
->workqueue
, &priv
->adapter_restart
);
1903 static void ipw_bg_scan_check(void *data
)
1905 struct ipw_priv
*priv
= data
;
1907 ipw_scan_check(data
);
1911 static int ipw_send_scan_request_ext(struct ipw_priv
*priv
,
1912 struct ipw_scan_request_ext
*request
)
1914 struct host_cmd cmd
= {
1915 .cmd
= IPW_CMD_SCAN_REQUEST_EXT
,
1916 .len
= sizeof(*request
)
1919 memcpy(cmd
.param
, request
, sizeof(*request
));
1920 if (ipw_send_cmd(priv
, &cmd
)) {
1921 IPW_ERROR("failed to send SCAN_REQUEST_EXT command\n");
1928 static int ipw_send_scan_abort(struct ipw_priv
*priv
)
1930 struct host_cmd cmd
= {
1931 .cmd
= IPW_CMD_SCAN_ABORT
,
1936 IPW_ERROR("Invalid args\n");
1940 if (ipw_send_cmd(priv
, &cmd
)) {
1941 IPW_ERROR("failed to send SCAN_ABORT command\n");
1948 static int ipw_set_sensitivity(struct ipw_priv
*priv
, u16 sens
)
1950 struct host_cmd cmd
= {
1951 .cmd
= IPW_CMD_SENSITIVITY_CALIB
,
1952 .len
= sizeof(struct ipw_sensitivity_calib
)
1954 struct ipw_sensitivity_calib
*calib
= (struct ipw_sensitivity_calib
*)
1956 calib
->beacon_rssi_raw
= sens
;
1957 if (ipw_send_cmd(priv
, &cmd
)) {
1958 IPW_ERROR("failed to send SENSITIVITY CALIB command\n");
1965 static int ipw_send_associate(struct ipw_priv
*priv
,
1966 struct ipw_associate
*associate
)
1968 struct host_cmd cmd
= {
1969 .cmd
= IPW_CMD_ASSOCIATE
,
1970 .len
= sizeof(*associate
)
1973 struct ipw_associate tmp_associate
;
1974 memcpy(&tmp_associate
, associate
, sizeof(*associate
));
1975 tmp_associate
.policy_support
=
1976 cpu_to_le16(tmp_associate
.policy_support
);
1977 tmp_associate
.assoc_tsf_msw
= cpu_to_le32(tmp_associate
.assoc_tsf_msw
);
1978 tmp_associate
.assoc_tsf_lsw
= cpu_to_le32(tmp_associate
.assoc_tsf_lsw
);
1979 tmp_associate
.capability
= cpu_to_le16(tmp_associate
.capability
);
1980 tmp_associate
.listen_interval
=
1981 cpu_to_le16(tmp_associate
.listen_interval
);
1982 tmp_associate
.beacon_interval
=
1983 cpu_to_le16(tmp_associate
.beacon_interval
);
1984 tmp_associate
.atim_window
= cpu_to_le16(tmp_associate
.atim_window
);
1986 if (!priv
|| !associate
) {
1987 IPW_ERROR("Invalid args\n");
1991 memcpy(cmd
.param
, &tmp_associate
, sizeof(*associate
));
1992 if (ipw_send_cmd(priv
, &cmd
)) {
1993 IPW_ERROR("failed to send ASSOCIATE command\n");
2000 static int ipw_send_supported_rates(struct ipw_priv
*priv
,
2001 struct ipw_supported_rates
*rates
)
2003 struct host_cmd cmd
= {
2004 .cmd
= IPW_CMD_SUPPORTED_RATES
,
2005 .len
= sizeof(*rates
)
2008 if (!priv
|| !rates
) {
2009 IPW_ERROR("Invalid args\n");
2013 memcpy(cmd
.param
, rates
, sizeof(*rates
));
2014 if (ipw_send_cmd(priv
, &cmd
)) {
2015 IPW_ERROR("failed to send SUPPORTED_RATES command\n");
2022 static int ipw_set_random_seed(struct ipw_priv
*priv
)
2024 struct host_cmd cmd
= {
2025 .cmd
= IPW_CMD_SEED_NUMBER
,
2030 IPW_ERROR("Invalid args\n");
2034 get_random_bytes(&cmd
.param
, sizeof(u32
));
2036 if (ipw_send_cmd(priv
, &cmd
)) {
2037 IPW_ERROR("failed to send SEED_NUMBER command\n");
2044 static int ipw_send_card_disable(struct ipw_priv
*priv
, u32 phy_off
)
2046 struct host_cmd cmd
= {
2047 .cmd
= IPW_CMD_CARD_DISABLE
,
2052 IPW_ERROR("Invalid args\n");
2056 *((u32
*) & cmd
.param
) = phy_off
;
2058 if (ipw_send_cmd(priv
, &cmd
)) {
2059 IPW_ERROR("failed to send CARD_DISABLE command\n");
2066 static int ipw_send_tx_power(struct ipw_priv
*priv
, struct ipw_tx_power
*power
)
2068 struct host_cmd cmd
= {
2069 .cmd
= IPW_CMD_TX_POWER
,
2070 .len
= sizeof(*power
)
2073 if (!priv
|| !power
) {
2074 IPW_ERROR("Invalid args\n");
2078 memcpy(cmd
.param
, power
, sizeof(*power
));
2079 if (ipw_send_cmd(priv
, &cmd
)) {
2080 IPW_ERROR("failed to send TX_POWER command\n");
2087 static int ipw_send_rts_threshold(struct ipw_priv
*priv
, u16 rts
)
2089 struct ipw_rts_threshold rts_threshold
= {
2090 .rts_threshold
= rts
,
2092 struct host_cmd cmd
= {
2093 .cmd
= IPW_CMD_RTS_THRESHOLD
,
2094 .len
= sizeof(rts_threshold
)
2098 IPW_ERROR("Invalid args\n");
2102 memcpy(cmd
.param
, &rts_threshold
, sizeof(rts_threshold
));
2103 if (ipw_send_cmd(priv
, &cmd
)) {
2104 IPW_ERROR("failed to send RTS_THRESHOLD command\n");
2111 static int ipw_send_frag_threshold(struct ipw_priv
*priv
, u16 frag
)
2113 struct ipw_frag_threshold frag_threshold
= {
2114 .frag_threshold
= frag
,
2116 struct host_cmd cmd
= {
2117 .cmd
= IPW_CMD_FRAG_THRESHOLD
,
2118 .len
= sizeof(frag_threshold
)
2122 IPW_ERROR("Invalid args\n");
2126 memcpy(cmd
.param
, &frag_threshold
, sizeof(frag_threshold
));
2127 if (ipw_send_cmd(priv
, &cmd
)) {
2128 IPW_ERROR("failed to send FRAG_THRESHOLD command\n");
2135 static int ipw_send_power_mode(struct ipw_priv
*priv
, u32 mode
)
2137 struct host_cmd cmd
= {
2138 .cmd
= IPW_CMD_POWER_MODE
,
2141 u32
*param
= (u32
*) (&cmd
.param
);
2144 IPW_ERROR("Invalid args\n");
2148 /* If on battery, set to 3, if AC set to CAM, else user
2151 case IPW_POWER_BATTERY
:
2152 *param
= IPW_POWER_INDEX_3
;
2155 *param
= IPW_POWER_MODE_CAM
;
2162 if (ipw_send_cmd(priv
, &cmd
)) {
2163 IPW_ERROR("failed to send POWER_MODE command\n");
2170 static int ipw_send_retry_limit(struct ipw_priv
*priv
, u8 slimit
, u8 llimit
)
2172 struct ipw_retry_limit retry_limit
= {
2173 .short_retry_limit
= slimit
,
2174 .long_retry_limit
= llimit
2176 struct host_cmd cmd
= {
2177 .cmd
= IPW_CMD_RETRY_LIMIT
,
2178 .len
= sizeof(retry_limit
)
2182 IPW_ERROR("Invalid args\n");
2186 memcpy(cmd
.param
, &retry_limit
, sizeof(retry_limit
));
2187 if (ipw_send_cmd(priv
, &cmd
)) {
2188 IPW_ERROR("failed to send RETRY_LIMIT command\n");
2196 * The IPW device contains a Microwire compatible EEPROM that stores
2197 * various data like the MAC address. Usually the firmware has exclusive
2198 * access to the eeprom, but during device initialization (before the
2199 * device driver has sent the HostComplete command to the firmware) the
2200 * device driver has read access to the EEPROM by way of indirect addressing
2201 * through a couple of memory mapped registers.
2203 * The following is a simplified implementation for pulling data out of the
2204 * the eeprom, along with some helper functions to find information in
2205 * the per device private data's copy of the eeprom.
2207 * NOTE: To better understand how these functions work (i.e what is a chip
2208 * select and why do have to keep driving the eeprom clock?), read
2209 * just about any data sheet for a Microwire compatible EEPROM.
2212 /* write a 32 bit value into the indirect accessor register */
2213 static inline void eeprom_write_reg(struct ipw_priv
*p
, u32 data
)
2215 ipw_write_reg32(p
, FW_MEM_REG_EEPROM_ACCESS
, data
);
2217 /* the eeprom requires some time to complete the operation */
2218 udelay(p
->eeprom_delay
);
2223 /* perform a chip select operation */
2224 static inline void eeprom_cs(struct ipw_priv
*priv
)
2226 eeprom_write_reg(priv
, 0);
2227 eeprom_write_reg(priv
, EEPROM_BIT_CS
);
2228 eeprom_write_reg(priv
, EEPROM_BIT_CS
| EEPROM_BIT_SK
);
2229 eeprom_write_reg(priv
, EEPROM_BIT_CS
);
2232 /* perform a chip select operation */
2233 static inline void eeprom_disable_cs(struct ipw_priv
*priv
)
2235 eeprom_write_reg(priv
, EEPROM_BIT_CS
);
2236 eeprom_write_reg(priv
, 0);
2237 eeprom_write_reg(priv
, EEPROM_BIT_SK
);
2240 /* push a single bit down to the eeprom */
2241 static inline void eeprom_write_bit(struct ipw_priv
*p
, u8 bit
)
2243 int d
= (bit
? EEPROM_BIT_DI
: 0);
2244 eeprom_write_reg(p
, EEPROM_BIT_CS
| d
);
2245 eeprom_write_reg(p
, EEPROM_BIT_CS
| d
| EEPROM_BIT_SK
);
2248 /* push an opcode followed by an address down to the eeprom */
2249 static void eeprom_op(struct ipw_priv
*priv
, u8 op
, u8 addr
)
2254 eeprom_write_bit(priv
, 1);
2255 eeprom_write_bit(priv
, op
& 2);
2256 eeprom_write_bit(priv
, op
& 1);
2257 for (i
= 7; i
>= 0; i
--) {
2258 eeprom_write_bit(priv
, addr
& (1 << i
));
2262 /* pull 16 bits off the eeprom, one bit at a time */
2263 static u16
eeprom_read_u16(struct ipw_priv
*priv
, u8 addr
)
2268 /* Send READ Opcode */
2269 eeprom_op(priv
, EEPROM_CMD_READ
, addr
);
2271 /* Send dummy bit */
2272 eeprom_write_reg(priv
, EEPROM_BIT_CS
);
2274 /* Read the byte off the eeprom one bit at a time */
2275 for (i
= 0; i
< 16; i
++) {
2277 eeprom_write_reg(priv
, EEPROM_BIT_CS
| EEPROM_BIT_SK
);
2278 eeprom_write_reg(priv
, EEPROM_BIT_CS
);
2279 data
= ipw_read_reg32(priv
, FW_MEM_REG_EEPROM_ACCESS
);
2280 r
= (r
<< 1) | ((data
& EEPROM_BIT_DO
) ? 1 : 0);
2283 /* Send another dummy bit */
2284 eeprom_write_reg(priv
, 0);
2285 eeprom_disable_cs(priv
);
2290 /* helper function for pulling the mac address out of the private */
2291 /* data's copy of the eeprom data */
2292 static void eeprom_parse_mac(struct ipw_priv
*priv
, u8
* mac
)
2294 memcpy(mac
, &priv
->eeprom
[EEPROM_MAC_ADDRESS
], 6);
2298 * Either the device driver (i.e. the host) or the firmware can
2299 * load eeprom data into the designated region in SRAM. If neither
2300 * happens then the FW will shutdown with a fatal error.
2302 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2303 * bit needs region of shared SRAM needs to be non-zero.
2305 static void ipw_eeprom_init_sram(struct ipw_priv
*priv
)
2308 u16
*eeprom
= (u16
*) priv
->eeprom
;
2310 IPW_DEBUG_TRACE(">>\n");
2312 /* read entire contents of eeprom into private buffer */
2313 for (i
= 0; i
< 128; i
++)
2314 eeprom
[i
] = le16_to_cpu(eeprom_read_u16(priv
, (u8
) i
));
2317 If the data looks correct, then copy it to our private
2318 copy. Otherwise let the firmware know to perform the operation
2321 if ((priv
->eeprom
+ EEPROM_VERSION
) != 0) {
2322 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2324 /* write the eeprom data to sram */
2325 for (i
= 0; i
< IPW_EEPROM_IMAGE_SIZE
; i
++)
2326 ipw_write8(priv
, IPW_EEPROM_DATA
+ i
, priv
->eeprom
[i
]);
2328 /* Do not load eeprom data on fatal error or suspend */
2329 ipw_write32(priv
, IPW_EEPROM_LOAD_DISABLE
, 0);
2331 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2333 /* Load eeprom data on fatal error or suspend */
2334 ipw_write32(priv
, IPW_EEPROM_LOAD_DISABLE
, 1);
2337 IPW_DEBUG_TRACE("<<\n");
2340 static inline void ipw_zero_memory(struct ipw_priv
*priv
, u32 start
, u32 count
)
2345 _ipw_write32(priv
, IPW_AUTOINC_ADDR
, start
);
2347 _ipw_write32(priv
, IPW_AUTOINC_DATA
, 0);
2350 static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv
*priv
)
2352 ipw_zero_memory(priv
, IPW_SHARED_SRAM_DMA_CONTROL
,
2353 CB_NUMBER_OF_ELEMENTS_SMALL
*
2354 sizeof(struct command_block
));
2357 static int ipw_fw_dma_enable(struct ipw_priv
*priv
)
2358 { /* start dma engine but no transfers yet */
2360 IPW_DEBUG_FW(">> : \n");
2363 ipw_fw_dma_reset_command_blocks(priv
);
2365 /* Write CB base address */
2366 ipw_write_reg32(priv
, IPW_DMA_I_CB_BASE
, IPW_SHARED_SRAM_DMA_CONTROL
);
2368 IPW_DEBUG_FW("<< : \n");
2372 static void ipw_fw_dma_abort(struct ipw_priv
*priv
)
2376 IPW_DEBUG_FW(">> :\n");
2378 //set the Stop and Abort bit
2379 control
= DMA_CONTROL_SMALL_CB_CONST_VALUE
| DMA_CB_STOP_AND_ABORT
;
2380 ipw_write_reg32(priv
, IPW_DMA_I_DMA_CONTROL
, control
);
2381 priv
->sram_desc
.last_cb_index
= 0;
2383 IPW_DEBUG_FW("<< \n");
2386 static int ipw_fw_dma_write_command_block(struct ipw_priv
*priv
, int index
,
2387 struct command_block
*cb
)
2390 IPW_SHARED_SRAM_DMA_CONTROL
+
2391 (sizeof(struct command_block
) * index
);
2392 IPW_DEBUG_FW(">> :\n");
2394 ipw_write_indirect(priv
, address
, (u8
*) cb
,
2395 (int)sizeof(struct command_block
));
2397 IPW_DEBUG_FW("<< :\n");
2402 static int ipw_fw_dma_kick(struct ipw_priv
*priv
)
2407 IPW_DEBUG_FW(">> :\n");
2409 for (index
= 0; index
< priv
->sram_desc
.last_cb_index
; index
++)
2410 ipw_fw_dma_write_command_block(priv
, index
,
2411 &priv
->sram_desc
.cb_list
[index
]);
2413 /* Enable the DMA in the CSR register */
2414 ipw_clear_bit(priv
, IPW_RESET_REG
,
2415 IPW_RESET_REG_MASTER_DISABLED
|
2416 IPW_RESET_REG_STOP_MASTER
);
2418 /* Set the Start bit. */
2419 control
= DMA_CONTROL_SMALL_CB_CONST_VALUE
| DMA_CB_START
;
2420 ipw_write_reg32(priv
, IPW_DMA_I_DMA_CONTROL
, control
);
2422 IPW_DEBUG_FW("<< :\n");
2426 static void ipw_fw_dma_dump_command_block(struct ipw_priv
*priv
)
2429 u32 register_value
= 0;
2430 u32 cb_fields_address
= 0;
2432 IPW_DEBUG_FW(">> :\n");
2433 address
= ipw_read_reg32(priv
, IPW_DMA_I_CURRENT_CB
);
2434 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address
);
2436 /* Read the DMA Controlor register */
2437 register_value
= ipw_read_reg32(priv
, IPW_DMA_I_DMA_CONTROL
);
2438 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value
);
2440 /* Print the CB values */
2441 cb_fields_address
= address
;
2442 register_value
= ipw_read_reg32(priv
, cb_fields_address
);
2443 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value
);
2445 cb_fields_address
+= sizeof(u32
);
2446 register_value
= ipw_read_reg32(priv
, cb_fields_address
);
2447 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value
);
2449 cb_fields_address
+= sizeof(u32
);
2450 register_value
= ipw_read_reg32(priv
, cb_fields_address
);
2451 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2454 cb_fields_address
+= sizeof(u32
);
2455 register_value
= ipw_read_reg32(priv
, cb_fields_address
);
2456 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value
);
2458 IPW_DEBUG_FW(">> :\n");
2461 static int ipw_fw_dma_command_block_index(struct ipw_priv
*priv
)
2463 u32 current_cb_address
= 0;
2464 u32 current_cb_index
= 0;
2466 IPW_DEBUG_FW("<< :\n");
2467 current_cb_address
= ipw_read_reg32(priv
, IPW_DMA_I_CURRENT_CB
);
2469 current_cb_index
= (current_cb_address
- IPW_SHARED_SRAM_DMA_CONTROL
) /
2470 sizeof(struct command_block
);
2472 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
2473 current_cb_index
, current_cb_address
);
2475 IPW_DEBUG_FW(">> :\n");
2476 return current_cb_index
;
2480 static int ipw_fw_dma_add_command_block(struct ipw_priv
*priv
,
2484 int interrupt_enabled
, int is_last
)
2487 u32 control
= CB_VALID
| CB_SRC_LE
| CB_DEST_LE
| CB_SRC_AUTOINC
|
2488 CB_SRC_IO_GATED
| CB_DEST_AUTOINC
| CB_SRC_SIZE_LONG
|
2490 struct command_block
*cb
;
2491 u32 last_cb_element
= 0;
2493 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2494 src_address
, dest_address
, length
);
2496 if (priv
->sram_desc
.last_cb_index
>= CB_NUMBER_OF_ELEMENTS_SMALL
)
2499 last_cb_element
= priv
->sram_desc
.last_cb_index
;
2500 cb
= &priv
->sram_desc
.cb_list
[last_cb_element
];
2501 priv
->sram_desc
.last_cb_index
++;
2503 /* Calculate the new CB control word */
2504 if (interrupt_enabled
)
2505 control
|= CB_INT_ENABLED
;
2508 control
|= CB_LAST_VALID
;
2512 /* Calculate the CB Element's checksum value */
2513 cb
->status
= control
^ src_address
^ dest_address
;
2515 /* Copy the Source and Destination addresses */
2516 cb
->dest_addr
= dest_address
;
2517 cb
->source_addr
= src_address
;
2519 /* Copy the Control Word last */
2520 cb
->control
= control
;
2525 static int ipw_fw_dma_add_buffer(struct ipw_priv
*priv
,
2526 u32 src_phys
, u32 dest_address
, u32 length
)
2528 u32 bytes_left
= length
;
2530 u32 dest_offset
= 0;
2532 IPW_DEBUG_FW(">> \n");
2533 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2534 src_phys
, dest_address
, length
);
2535 while (bytes_left
> CB_MAX_LENGTH
) {
2536 status
= ipw_fw_dma_add_command_block(priv
,
2537 src_phys
+ src_offset
,
2540 CB_MAX_LENGTH
, 0, 0);
2542 IPW_DEBUG_FW_INFO(": Failed\n");
2545 IPW_DEBUG_FW_INFO(": Added new cb\n");
2547 src_offset
+= CB_MAX_LENGTH
;
2548 dest_offset
+= CB_MAX_LENGTH
;
2549 bytes_left
-= CB_MAX_LENGTH
;
2552 /* add the buffer tail */
2553 if (bytes_left
> 0) {
2555 ipw_fw_dma_add_command_block(priv
, src_phys
+ src_offset
,
2556 dest_address
+ dest_offset
,
2559 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2563 (": Adding new cb - the buffer tail\n");
2566 IPW_DEBUG_FW("<< \n");
2570 static int ipw_fw_dma_wait(struct ipw_priv
*priv
)
2572 u32 current_index
= 0;
2575 IPW_DEBUG_FW(">> : \n");
2577 current_index
= ipw_fw_dma_command_block_index(priv
);
2578 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n",
2579 (int)priv
->sram_desc
.last_cb_index
);
2581 while (current_index
< priv
->sram_desc
.last_cb_index
) {
2583 current_index
= ipw_fw_dma_command_block_index(priv
);
2587 if (watchdog
> 400) {
2588 IPW_DEBUG_FW_INFO("Timeout\n");
2589 ipw_fw_dma_dump_command_block(priv
);
2590 ipw_fw_dma_abort(priv
);
2595 ipw_fw_dma_abort(priv
);
2597 /*Disable the DMA in the CSR register */
2598 ipw_set_bit(priv
, IPW_RESET_REG
,
2599 IPW_RESET_REG_MASTER_DISABLED
| IPW_RESET_REG_STOP_MASTER
);
2601 IPW_DEBUG_FW("<< dmaWaitSync \n");
2605 static void ipw_remove_current_network(struct ipw_priv
*priv
)
2607 struct list_head
*element
, *safe
;
2608 struct ieee80211_network
*network
= NULL
;
2609 unsigned long flags
;
2611 spin_lock_irqsave(&priv
->ieee
->lock
, flags
);
2612 list_for_each_safe(element
, safe
, &priv
->ieee
->network_list
) {
2613 network
= list_entry(element
, struct ieee80211_network
, list
);
2614 if (!memcmp(network
->bssid
, priv
->bssid
, ETH_ALEN
)) {
2616 list_add_tail(&network
->list
,
2617 &priv
->ieee
->network_free_list
);
2620 spin_unlock_irqrestore(&priv
->ieee
->lock
, flags
);
2624 * Check that card is still alive.
2625 * Reads debug register from domain0.
2626 * If card is present, pre-defined value should
2630 * @return 1 if card is present, 0 otherwise
2632 static inline int ipw_alive(struct ipw_priv
*priv
)
2634 return ipw_read32(priv
, 0x90) == 0xd55555d5;
2637 static inline int ipw_poll_bit(struct ipw_priv
*priv
, u32 addr
, u32 mask
,
2643 if ((ipw_read32(priv
, addr
) & mask
) == mask
)
2647 } while (i
< timeout
);
2652 /* These functions load the firmware and micro code for the operation of
2653 * the ipw hardware. It assumes the buffer has all the bits for the
2654 * image and the caller is handling the memory allocation and clean up.
2657 static int ipw_stop_master(struct ipw_priv
*priv
)
2661 IPW_DEBUG_TRACE(">> \n");
2662 /* stop master. typical delay - 0 */
2663 ipw_set_bit(priv
, IPW_RESET_REG
, IPW_RESET_REG_STOP_MASTER
);
2665 rc
= ipw_poll_bit(priv
, IPW_RESET_REG
,
2666 IPW_RESET_REG_MASTER_DISABLED
, 100);
2668 IPW_ERROR("stop master failed in 10ms\n");
2672 IPW_DEBUG_INFO("stop master %dms\n", rc
);
2677 static void ipw_arc_release(struct ipw_priv
*priv
)
2679 IPW_DEBUG_TRACE(">> \n");
2682 ipw_clear_bit(priv
, IPW_RESET_REG
, CBD_RESET_REG_PRINCETON_RESET
);
2684 /* no one knows timing, for safety add some delay */
2698 #define IPW_FW_MAJOR_VERSION 2
2699 #define IPW_FW_MINOR_VERSION 3
2701 #define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
2702 #define IPW_FW_MAJOR(x) (x & 0xff)
2704 #define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | IPW_FW_MAJOR_VERSION)
2706 #define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
2707 "." __stringify(IPW_FW_MINOR_VERSION) "-"
2709 #if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
2710 #define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
2712 #define IPW_FW_NAME(x) "ipw2200_" x ".fw"
2715 static int ipw_load_ucode(struct ipw_priv
*priv
, u8
* data
, size_t len
)
2717 int rc
= 0, i
, addr
;
2721 image
= (u16
*) data
;
2723 IPW_DEBUG_TRACE(">> \n");
2725 rc
= ipw_stop_master(priv
);
2730 // spin_lock_irqsave(&priv->lock, flags);
2732 for (addr
= IPW_SHARED_LOWER_BOUND
;
2733 addr
< IPW_REGISTER_DOMAIN1_END
; addr
+= 4) {
2734 ipw_write32(priv
, addr
, 0);
2737 /* no ucode (yet) */
2738 memset(&priv
->dino_alive
, 0, sizeof(priv
->dino_alive
));
2739 /* destroy DMA queues */
2740 /* reset sequence */
2742 ipw_write_reg32(priv
, IPW_MEM_HALT_AND_RESET
, IPW_BIT_HALT_RESET_ON
);
2743 ipw_arc_release(priv
);
2744 ipw_write_reg32(priv
, IPW_MEM_HALT_AND_RESET
, IPW_BIT_HALT_RESET_OFF
);
2748 ipw_write_reg32(priv
, IPW_INTERNAL_CMD_EVENT
, IPW_BASEBAND_POWER_DOWN
);
2751 ipw_write_reg32(priv
, IPW_INTERNAL_CMD_EVENT
, 0);
2754 /* enable ucode store */
2755 ipw_write_reg8(priv
, DINO_CONTROL_REG
, 0x0);
2756 ipw_write_reg8(priv
, DINO_CONTROL_REG
, DINO_ENABLE_CS
);
2762 * Do NOT set indirect address register once and then
2763 * store data to indirect data register in the loop.
2764 * It seems very reasonable, but in this case DINO do not
2765 * accept ucode. It is essential to set address each time.
2767 /* load new ipw uCode */
2768 for (i
= 0; i
< len
/ 2; i
++)
2769 ipw_write_reg16(priv
, IPW_BASEBAND_CONTROL_STORE
,
2770 cpu_to_le16(image
[i
]));
2773 ipw_write_reg8(priv
, IPW_BASEBAND_CONTROL_STATUS
, 0);
2774 ipw_write_reg8(priv
, IPW_BASEBAND_CONTROL_STATUS
, DINO_ENABLE_SYSTEM
);
2776 /* this is where the igx / win driver deveates from the VAP driver. */
2778 /* wait for alive response */
2779 for (i
= 0; i
< 100; i
++) {
2780 /* poll for incoming data */
2781 cr
= ipw_read_reg8(priv
, IPW_BASEBAND_CONTROL_STATUS
);
2782 if (cr
& DINO_RXFIFO_DATA
)
2787 if (cr
& DINO_RXFIFO_DATA
) {
2788 /* alive_command_responce size is NOT multiple of 4 */
2789 u32 response_buffer
[(sizeof(priv
->dino_alive
) + 3) / 4];
2791 for (i
= 0; i
< ARRAY_SIZE(response_buffer
); i
++)
2792 response_buffer
[i
] =
2793 le32_to_cpu(ipw_read_reg32(priv
,
2794 IPW_BASEBAND_RX_FIFO_READ
));
2795 memcpy(&priv
->dino_alive
, response_buffer
,
2796 sizeof(priv
->dino_alive
));
2797 if (priv
->dino_alive
.alive_command
== 1
2798 && priv
->dino_alive
.ucode_valid
== 1) {
2801 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2802 "of %02d/%02d/%02d %02d:%02d\n",
2803 priv
->dino_alive
.software_revision
,
2804 priv
->dino_alive
.software_revision
,
2805 priv
->dino_alive
.device_identifier
,
2806 priv
->dino_alive
.device_identifier
,
2807 priv
->dino_alive
.time_stamp
[0],
2808 priv
->dino_alive
.time_stamp
[1],
2809 priv
->dino_alive
.time_stamp
[2],
2810 priv
->dino_alive
.time_stamp
[3],
2811 priv
->dino_alive
.time_stamp
[4]);
2813 IPW_DEBUG_INFO("Microcode is not alive\n");
2817 IPW_DEBUG_INFO("No alive response from DINO\n");
2821 /* disable DINO, otherwise for some reason
2822 firmware have problem getting alive resp. */
2823 ipw_write_reg8(priv
, IPW_BASEBAND_CONTROL_STATUS
, 0);
2825 // spin_unlock_irqrestore(&priv->lock, flags);
2830 static int ipw_load_firmware(struct ipw_priv
*priv
, u8
* data
, size_t len
)
2834 struct fw_chunk
*chunk
;
2835 dma_addr_t shared_phys
;
2838 IPW_DEBUG_TRACE("<< : \n");
2839 shared_virt
= pci_alloc_consistent(priv
->pci_dev
, len
, &shared_phys
);
2844 memmove(shared_virt
, data
, len
);
2847 rc
= ipw_fw_dma_enable(priv
);
2849 if (priv
->sram_desc
.last_cb_index
> 0) {
2850 /* the DMA is already ready this would be a bug. */
2856 chunk
= (struct fw_chunk
*)(data
+ offset
);
2857 offset
+= sizeof(struct fw_chunk
);
2858 /* build DMA packet and queue up for sending */
2859 /* dma to chunk->address, the chunk->length bytes from data +
2862 rc
= ipw_fw_dma_add_buffer(priv
, shared_phys
+ offset
,
2863 le32_to_cpu(chunk
->address
),
2864 le32_to_cpu(chunk
->length
));
2866 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
2870 offset
+= le32_to_cpu(chunk
->length
);
2871 } while (offset
< len
);
2873 /* Run the DMA and wait for the answer */
2874 rc
= ipw_fw_dma_kick(priv
);
2876 IPW_ERROR("dmaKick Failed\n");
2880 rc
= ipw_fw_dma_wait(priv
);
2882 IPW_ERROR("dmaWaitSync Failed\n");
2886 pci_free_consistent(priv
->pci_dev
, len
, shared_virt
, shared_phys
);
2891 static int ipw_stop_nic(struct ipw_priv
*priv
)
2896 ipw_write32(priv
, IPW_RESET_REG
, IPW_RESET_REG_STOP_MASTER
);
2898 rc
= ipw_poll_bit(priv
, IPW_RESET_REG
,
2899 IPW_RESET_REG_MASTER_DISABLED
, 500);
2901 IPW_ERROR("wait for reg master disabled failed\n");
2905 ipw_set_bit(priv
, IPW_RESET_REG
, CBD_RESET_REG_PRINCETON_RESET
);
2910 static void ipw_start_nic(struct ipw_priv
*priv
)
2912 IPW_DEBUG_TRACE(">>\n");
2914 /* prvHwStartNic release ARC */
2915 ipw_clear_bit(priv
, IPW_RESET_REG
,
2916 IPW_RESET_REG_MASTER_DISABLED
|
2917 IPW_RESET_REG_STOP_MASTER
|
2918 CBD_RESET_REG_PRINCETON_RESET
);
2920 /* enable power management */
2921 ipw_set_bit(priv
, IPW_GP_CNTRL_RW
,
2922 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY
);
2924 IPW_DEBUG_TRACE("<<\n");
2927 static int ipw_init_nic(struct ipw_priv
*priv
)
2931 IPW_DEBUG_TRACE(">>\n");
2934 /* set "initialization complete" bit to move adapter to D0 state */
2935 ipw_set_bit(priv
, IPW_GP_CNTRL_RW
, IPW_GP_CNTRL_BIT_INIT_DONE
);
2937 /* low-level PLL activation */
2938 ipw_write32(priv
, IPW_READ_INT_REGISTER
,
2939 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER
);
2941 /* wait for clock stabilization */
2942 rc
= ipw_poll_bit(priv
, IPW_GP_CNTRL_RW
,
2943 IPW_GP_CNTRL_BIT_CLOCK_READY
, 250);
2945 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
2947 /* assert SW reset */
2948 ipw_set_bit(priv
, IPW_RESET_REG
, IPW_RESET_REG_SW_RESET
);
2952 /* set "initialization complete" bit to move adapter to D0 state */
2953 ipw_set_bit(priv
, IPW_GP_CNTRL_RW
, IPW_GP_CNTRL_BIT_INIT_DONE
);
2955 IPW_DEBUG_TRACE(">>\n");
2959 /* Call this function from process context, it will sleep in request_firmware.
2960 * Probe is an ok place to call this from.
2962 static int ipw_reset_nic(struct ipw_priv
*priv
)
2965 unsigned long flags
;
2967 IPW_DEBUG_TRACE(">>\n");
2969 rc
= ipw_init_nic(priv
);
2971 spin_lock_irqsave(&priv
->lock
, flags
);
2972 /* Clear the 'host command active' bit... */
2973 priv
->status
&= ~STATUS_HCMD_ACTIVE
;
2974 wake_up_interruptible(&priv
->wait_command_queue
);
2975 priv
->status
&= ~(STATUS_SCANNING
| STATUS_SCAN_ABORTING
);
2976 wake_up_interruptible(&priv
->wait_state
);
2977 spin_unlock_irqrestore(&priv
->lock
, flags
);
2979 IPW_DEBUG_TRACE("<<\n");
2983 static int ipw_get_fw(struct ipw_priv
*priv
,
2984 const struct firmware
**fw
, const char *name
)
2986 struct fw_header
*header
;
2989 /* ask firmware_class module to get the boot firmware off disk */
2990 rc
= request_firmware(fw
, name
, &priv
->pci_dev
->dev
);
2992 IPW_ERROR("%s load failed: Reason %d\n", name
, rc
);
2996 header
= (struct fw_header
*)(*fw
)->data
;
2997 if (IPW_FW_MAJOR(le32_to_cpu(header
->version
)) != IPW_FW_MAJOR_VERSION
) {
2998 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
3000 IPW_FW_MAJOR(le32_to_cpu(header
->version
)),
3001 IPW_FW_MAJOR_VERSION
);
3005 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
3007 IPW_FW_MAJOR(le32_to_cpu(header
->version
)),
3008 IPW_FW_MINOR(le32_to_cpu(header
->version
)),
3009 (*fw
)->size
- sizeof(struct fw_header
));
3013 #define IPW_RX_BUF_SIZE (3000)
3015 static inline void ipw_rx_queue_reset(struct ipw_priv
*priv
,
3016 struct ipw_rx_queue
*rxq
)
3018 unsigned long flags
;
3021 spin_lock_irqsave(&rxq
->lock
, flags
);
3023 INIT_LIST_HEAD(&rxq
->rx_free
);
3024 INIT_LIST_HEAD(&rxq
->rx_used
);
3026 /* Fill the rx_used queue with _all_ of the Rx buffers */
3027 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++) {
3028 /* In the reset function, these buffers may have been allocated
3029 * to an SKB, so we need to unmap and free potential storage */
3030 if (rxq
->pool
[i
].skb
!= NULL
) {
3031 pci_unmap_single(priv
->pci_dev
, rxq
->pool
[i
].dma_addr
,
3032 IPW_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
3033 dev_kfree_skb(rxq
->pool
[i
].skb
);
3034 rxq
->pool
[i
].skb
= NULL
;
3036 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
3039 /* Set us so that we have processed and used all buffers, but have
3040 * not restocked the Rx queue with fresh buffers */
3041 rxq
->read
= rxq
->write
= 0;
3042 rxq
->processed
= RX_QUEUE_SIZE
- 1;
3043 rxq
->free_count
= 0;
3044 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3048 static int fw_loaded
= 0;
3049 static const struct firmware
*bootfw
= NULL
;
3050 static const struct firmware
*firmware
= NULL
;
3051 static const struct firmware
*ucode
= NULL
;
3053 static void free_firmware(void)
3056 release_firmware(bootfw
);
3057 release_firmware(ucode
);
3058 release_firmware(firmware
);
3059 bootfw
= ucode
= firmware
= NULL
;
3064 #define free_firmware() do {} while (0)
3067 static int ipw_load(struct ipw_priv
*priv
)
3070 const struct firmware
*bootfw
= NULL
;
3071 const struct firmware
*firmware
= NULL
;
3072 const struct firmware
*ucode
= NULL
;
3074 int rc
= 0, retries
= 3;
3079 rc
= ipw_get_fw(priv
, &bootfw
, IPW_FW_NAME("boot"));
3083 switch (priv
->ieee
->iw_mode
) {
3085 rc
= ipw_get_fw(priv
, &ucode
,
3086 IPW_FW_NAME("ibss_ucode"));
3090 rc
= ipw_get_fw(priv
, &firmware
, IPW_FW_NAME("ibss"));
3093 #ifdef CONFIG_IPW2200_MONITOR
3094 case IW_MODE_MONITOR
:
3095 rc
= ipw_get_fw(priv
, &ucode
,
3096 IPW_FW_NAME("sniffer_ucode"));
3100 rc
= ipw_get_fw(priv
, &firmware
,
3101 IPW_FW_NAME("sniffer"));
3105 rc
= ipw_get_fw(priv
, &ucode
, IPW_FW_NAME("bss_ucode"));
3109 rc
= ipw_get_fw(priv
, &firmware
, IPW_FW_NAME("bss"));
3125 priv
->rxq
= ipw_rx_queue_alloc(priv
);
3127 ipw_rx_queue_reset(priv
, priv
->rxq
);
3129 IPW_ERROR("Unable to initialize Rx queue\n");
3134 /* Ensure interrupts are disabled */
3135 ipw_write32(priv
, IPW_INTA_MASK_R
, ~IPW_INTA_MASK_ALL
);
3136 priv
->status
&= ~STATUS_INT_ENABLED
;
3138 /* ack pending interrupts */
3139 ipw_write32(priv
, IPW_INTA_RW
, IPW_INTA_MASK_ALL
);
3143 rc
= ipw_reset_nic(priv
);
3145 IPW_ERROR("Unable to reset NIC\n");
3149 ipw_zero_memory(priv
, IPW_NIC_SRAM_LOWER_BOUND
,
3150 IPW_NIC_SRAM_UPPER_BOUND
- IPW_NIC_SRAM_LOWER_BOUND
);
3152 /* DMA the initial boot firmware into the device */
3153 rc
= ipw_load_firmware(priv
, bootfw
->data
+ sizeof(struct fw_header
),
3154 bootfw
->size
- sizeof(struct fw_header
));
3156 IPW_ERROR("Unable to load boot firmware\n");
3160 /* kick start the device */
3161 ipw_start_nic(priv
);
3163 /* wait for the device to finish it's initial startup sequence */
3164 rc
= ipw_poll_bit(priv
, IPW_INTA_RW
,
3165 IPW_INTA_BIT_FW_INITIALIZATION_DONE
, 500);
3167 IPW_ERROR("device failed to boot initial fw image\n");
3170 IPW_DEBUG_INFO("initial device response after %dms\n", rc
);
3172 /* ack fw init done interrupt */
3173 ipw_write32(priv
, IPW_INTA_RW
, IPW_INTA_BIT_FW_INITIALIZATION_DONE
);
3175 /* DMA the ucode into the device */
3176 rc
= ipw_load_ucode(priv
, ucode
->data
+ sizeof(struct fw_header
),
3177 ucode
->size
- sizeof(struct fw_header
));
3179 IPW_ERROR("Unable to load ucode\n");
3186 /* DMA bss firmware into the device */
3187 rc
= ipw_load_firmware(priv
, firmware
->data
+
3188 sizeof(struct fw_header
),
3189 firmware
->size
- sizeof(struct fw_header
));
3191 IPW_ERROR("Unable to load firmware\n");
3195 ipw_write32(priv
, IPW_EEPROM_LOAD_DISABLE
, 0);
3197 rc
= ipw_queue_reset(priv
);
3199 IPW_ERROR("Unable to initialize queues\n");
3203 /* Ensure interrupts are disabled */
3204 ipw_write32(priv
, IPW_INTA_MASK_R
, ~IPW_INTA_MASK_ALL
);
3205 /* ack pending interrupts */
3206 ipw_write32(priv
, IPW_INTA_RW
, IPW_INTA_MASK_ALL
);
3208 /* kick start the device */
3209 ipw_start_nic(priv
);
3211 if (ipw_read32(priv
, IPW_INTA_RW
) & IPW_INTA_BIT_PARITY_ERROR
) {
3213 IPW_WARNING("Parity error. Retrying init.\n");
3218 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3223 /* wait for the device */
3224 rc
= ipw_poll_bit(priv
, IPW_INTA_RW
,
3225 IPW_INTA_BIT_FW_INITIALIZATION_DONE
, 500);
3227 IPW_ERROR("device failed to start after 500ms\n");
3230 IPW_DEBUG_INFO("device response after %dms\n", rc
);
3232 /* ack fw init done interrupt */
3233 ipw_write32(priv
, IPW_INTA_RW
, IPW_INTA_BIT_FW_INITIALIZATION_DONE
);
3235 /* read eeprom data and initialize the eeprom region of sram */
3236 priv
->eeprom_delay
= 1;
3237 ipw_eeprom_init_sram(priv
);
3239 /* enable interrupts */
3240 ipw_enable_interrupts(priv
);
3242 /* Ensure our queue has valid packets */
3243 ipw_rx_queue_replenish(priv
);
3245 ipw_write32(priv
, IPW_RX_READ_INDEX
, priv
->rxq
->read
);
3247 /* ack pending interrupts */
3248 ipw_write32(priv
, IPW_INTA_RW
, IPW_INTA_MASK_ALL
);
3251 release_firmware(bootfw
);
3252 release_firmware(ucode
);
3253 release_firmware(firmware
);
3259 ipw_rx_queue_free(priv
, priv
->rxq
);
3262 ipw_tx_queue_free(priv
);
3264 release_firmware(bootfw
);
3266 release_firmware(ucode
);
3268 release_firmware(firmware
);
3271 bootfw
= ucode
= firmware
= NULL
;
3280 * Theory of operation
3282 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3283 * 2 empty entries always kept in the buffer to protect from overflow.
3285 * For Tx queue, there are low mark and high mark limits. If, after queuing
3286 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3287 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
3290 * The IPW operates with six queues, one receive queue in the device's
3291 * sram, one transmit queue for sending commands to the device firmware,
3292 * and four transmit queues for data.
3294 * The four transmit queues allow for performing quality of service (qos)
3295 * transmissions as per the 802.11 protocol. Currently Linux does not
3296 * provide a mechanism to the user for utilizing prioritized queues, so
3297 * we only utilize the first data transmit queue (queue1).
3301 * Driver allocates buffers of this size for Rx
3304 static inline int ipw_queue_space(const struct clx2_queue
*q
)
3306 int s
= q
->last_used
- q
->first_empty
;
3309 s
-= 2; /* keep some reserve to not confuse empty and full situations */
3315 static inline int ipw_queue_inc_wrap(int index
, int n_bd
)
3317 return (++index
== n_bd
) ? 0 : index
;
3321 * Initialize common DMA queue structure
3323 * @param q queue to init
3324 * @param count Number of BD's to allocate. Should be power of 2
3325 * @param read_register Address for 'read' register
3326 * (not offset within BAR, full address)
3327 * @param write_register Address for 'write' register
3328 * (not offset within BAR, full address)
3329 * @param base_register Address for 'base' register
3330 * (not offset within BAR, full address)
3331 * @param size Address for 'size' register
3332 * (not offset within BAR, full address)
3334 static void ipw_queue_init(struct ipw_priv
*priv
, struct clx2_queue
*q
,
3335 int count
, u32 read
, u32 write
, u32 base
, u32 size
)
3339 q
->low_mark
= q
->n_bd
/ 4;
3340 if (q
->low_mark
< 4)
3343 q
->high_mark
= q
->n_bd
/ 8;
3344 if (q
->high_mark
< 2)
3347 q
->first_empty
= q
->last_used
= 0;
3351 ipw_write32(priv
, base
, q
->dma_addr
);
3352 ipw_write32(priv
, size
, count
);
3353 ipw_write32(priv
, read
, 0);
3354 ipw_write32(priv
, write
, 0);
3356 _ipw_read32(priv
, 0x90);
3359 static int ipw_queue_tx_init(struct ipw_priv
*priv
,
3360 struct clx2_tx_queue
*q
,
3361 int count
, u32 read
, u32 write
, u32 base
, u32 size
)
3363 struct pci_dev
*dev
= priv
->pci_dev
;
3365 q
->txb
= kmalloc(sizeof(q
->txb
[0]) * count
, GFP_KERNEL
);
3367 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3372 pci_alloc_consistent(dev
, sizeof(q
->bd
[0]) * count
, &q
->q
.dma_addr
);
3374 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
3375 sizeof(q
->bd
[0]) * count
);
3381 ipw_queue_init(priv
, &q
->q
, count
, read
, write
, base
, size
);
3386 * Free one TFD, those at index [txq->q.last_used].
3387 * Do NOT advance any indexes
3392 static void ipw_queue_tx_free_tfd(struct ipw_priv
*priv
,
3393 struct clx2_tx_queue
*txq
)
3395 struct tfd_frame
*bd
= &txq
->bd
[txq
->q
.last_used
];
3396 struct pci_dev
*dev
= priv
->pci_dev
;
3400 if (bd
->control_flags
.message_type
== TX_HOST_COMMAND_TYPE
)
3401 /* nothing to cleanup after for host commands */
3405 if (le32_to_cpu(bd
->u
.data
.num_chunks
) > NUM_TFD_CHUNKS
) {
3406 IPW_ERROR("Too many chunks: %i\n",
3407 le32_to_cpu(bd
->u
.data
.num_chunks
));
3408 /** @todo issue fatal error, it is quite serious situation */
3412 /* unmap chunks if any */
3413 for (i
= 0; i
< le32_to_cpu(bd
->u
.data
.num_chunks
); i
++) {
3414 pci_unmap_single(dev
, le32_to_cpu(bd
->u
.data
.chunk_ptr
[i
]),
3415 le16_to_cpu(bd
->u
.data
.chunk_len
[i
]),
3417 if (txq
->txb
[txq
->q
.last_used
]) {
3418 ieee80211_txb_free(txq
->txb
[txq
->q
.last_used
]);
3419 txq
->txb
[txq
->q
.last_used
] = NULL
;
3425 * Deallocate DMA queue.
3427 * Empty queue by removing and destroying all BD's.
3433 static void ipw_queue_tx_free(struct ipw_priv
*priv
, struct clx2_tx_queue
*txq
)
3435 struct clx2_queue
*q
= &txq
->q
;
3436 struct pci_dev
*dev
= priv
->pci_dev
;
3441 /* first, empty all BD's */
3442 for (; q
->first_empty
!= q
->last_used
;
3443 q
->last_used
= ipw_queue_inc_wrap(q
->last_used
, q
->n_bd
)) {
3444 ipw_queue_tx_free_tfd(priv
, txq
);
3447 /* free buffers belonging to queue itself */
3448 pci_free_consistent(dev
, sizeof(txq
->bd
[0]) * q
->n_bd
, txq
->bd
,
3452 /* 0 fill whole structure */
3453 memset(txq
, 0, sizeof(*txq
));
3457 * Destroy all DMA queues and structures
3461 static void ipw_tx_queue_free(struct ipw_priv
*priv
)
3464 ipw_queue_tx_free(priv
, &priv
->txq_cmd
);
3467 ipw_queue_tx_free(priv
, &priv
->txq
[0]);
3468 ipw_queue_tx_free(priv
, &priv
->txq
[1]);
3469 ipw_queue_tx_free(priv
, &priv
->txq
[2]);
3470 ipw_queue_tx_free(priv
, &priv
->txq
[3]);
3473 static void inline __maybe_wake_tx(struct ipw_priv
*priv
)
3475 if (netif_running(priv
->net_dev
)) {
3476 switch (priv
->port_type
) {
3477 case DCR_TYPE_MU_BSS
:
3478 case DCR_TYPE_MU_IBSS
:
3479 if (!(priv
->status
& STATUS_ASSOCIATED
))
3482 netif_wake_queue(priv
->net_dev
);
3487 static inline void ipw_create_bssid(struct ipw_priv
*priv
, u8
* bssid
)
3489 /* First 3 bytes are manufacturer */
3490 bssid
[0] = priv
->mac_addr
[0];
3491 bssid
[1] = priv
->mac_addr
[1];
3492 bssid
[2] = priv
->mac_addr
[2];
3494 /* Last bytes are random */
3495 get_random_bytes(&bssid
[3], ETH_ALEN
- 3);
3497 bssid
[0] &= 0xfe; /* clear multicast bit */
3498 bssid
[0] |= 0x02; /* set local assignment bit (IEEE802) */
3501 static inline u8
ipw_add_station(struct ipw_priv
*priv
, u8
* bssid
)
3503 struct ipw_station_entry entry
;
3506 for (i
= 0; i
< priv
->num_stations
; i
++) {
3507 if (!memcmp(priv
->stations
[i
], bssid
, ETH_ALEN
)) {
3508 /* Another node is active in network */
3509 priv
->missed_adhoc_beacons
= 0;
3510 if (!(priv
->config
& CFG_STATIC_CHANNEL
))
3511 /* when other nodes drop out, we drop out */
3512 priv
->config
&= ~CFG_ADHOC_PERSIST
;
3518 if (i
== MAX_STATIONS
)
3519 return IPW_INVALID_STATION
;
3521 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT
"\n", MAC_ARG(bssid
));
3524 entry
.support_mode
= 0;
3525 memcpy(entry
.mac_addr
, bssid
, ETH_ALEN
);
3526 memcpy(priv
->stations
[i
], bssid
, ETH_ALEN
);
3527 ipw_write_direct(priv
, IPW_STATION_TABLE_LOWER
+ i
* sizeof(entry
),
3528 &entry
, sizeof(entry
));
3529 priv
->num_stations
++;
3534 static inline u8
ipw_find_station(struct ipw_priv
*priv
, u8
* bssid
)
3538 for (i
= 0; i
< priv
->num_stations
; i
++)
3539 if (!memcmp(priv
->stations
[i
], bssid
, ETH_ALEN
))
3542 return IPW_INVALID_STATION
;
3545 static void ipw_send_disassociate(struct ipw_priv
*priv
, int quiet
)
3549 if (!(priv
->status
& (STATUS_ASSOCIATING
| STATUS_ASSOCIATED
))) {
3550 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3554 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT
" "
3556 MAC_ARG(priv
->assoc_request
.bssid
),
3557 priv
->assoc_request
.channel
);
3559 priv
->status
&= ~(STATUS_ASSOCIATING
| STATUS_ASSOCIATED
);
3560 priv
->status
|= STATUS_DISASSOCIATING
;
3563 priv
->assoc_request
.assoc_type
= HC_DISASSOC_QUIET
;
3565 priv
->assoc_request
.assoc_type
= HC_DISASSOCIATE
;
3566 err
= ipw_send_associate(priv
, &priv
->assoc_request
);
3568 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3575 static int ipw_disassociate(void *data
)
3577 struct ipw_priv
*priv
= data
;
3578 if (!(priv
->status
& (STATUS_ASSOCIATED
| STATUS_ASSOCIATING
)))
3580 ipw_send_disassociate(data
, 0);
3584 static void ipw_bg_disassociate(void *data
)
3586 struct ipw_priv
*priv
= data
;
3588 ipw_disassociate(data
);
3592 struct ipw_status_code
{
3597 static const struct ipw_status_code ipw_status_codes
[] = {
3598 {0x00, "Successful"},
3599 {0x01, "Unspecified failure"},
3600 {0x0A, "Cannot support all requested capabilities in the "
3601 "Capability information field"},
3602 {0x0B, "Reassociation denied due to inability to confirm that "
3603 "association exists"},
3604 {0x0C, "Association denied due to reason outside the scope of this "
3607 "Responding station does not support the specified authentication "
3610 "Received an Authentication frame with authentication sequence "
3611 "transaction sequence number out of expected sequence"},
3612 {0x0F, "Authentication rejected because of challenge failure"},
3613 {0x10, "Authentication rejected due to timeout waiting for next "
3614 "frame in sequence"},
3615 {0x11, "Association denied because AP is unable to handle additional "
3616 "associated stations"},
3618 "Association denied due to requesting station not supporting all "
3619 "of the datarates in the BSSBasicServiceSet Parameter"},
3621 "Association denied due to requesting station not supporting "
3622 "short preamble operation"},
3624 "Association denied due to requesting station not supporting "
3627 "Association denied due to requesting station not supporting "
3630 "Association denied due to requesting station not supporting "
3631 "short slot operation"},
3633 "Association denied due to requesting station not supporting "
3634 "DSSS-OFDM operation"},
3635 {0x28, "Invalid Information Element"},
3636 {0x29, "Group Cipher is not valid"},
3637 {0x2A, "Pairwise Cipher is not valid"},
3638 {0x2B, "AKMP is not valid"},
3639 {0x2C, "Unsupported RSN IE version"},
3640 {0x2D, "Invalid RSN IE Capabilities"},
3641 {0x2E, "Cipher suite is rejected per security policy"},
3644 #ifdef CONFIG_IPW_DEBUG
3645 static const char *ipw_get_status_code(u16 status
)
3648 for (i
= 0; i
< ARRAY_SIZE(ipw_status_codes
); i
++)
3649 if (ipw_status_codes
[i
].status
== (status
& 0xff))
3650 return ipw_status_codes
[i
].reason
;
3651 return "Unknown status value.";
3655 static void inline average_init(struct average
*avg
)
3657 memset(avg
, 0, sizeof(*avg
));
3660 static void inline average_add(struct average
*avg
, s16 val
)
3662 avg
->sum
-= avg
->entries
[avg
->pos
];
3664 avg
->entries
[avg
->pos
++] = val
;
3665 if (unlikely(avg
->pos
== AVG_ENTRIES
)) {
3671 static s16
inline average_value(struct average
*avg
)
3673 if (!unlikely(avg
->init
)) {
3675 return avg
->sum
/ avg
->pos
;
3679 return avg
->sum
/ AVG_ENTRIES
;
3682 static void ipw_reset_stats(struct ipw_priv
*priv
)
3684 u32 len
= sizeof(u32
);
3688 average_init(&priv
->average_missed_beacons
);
3689 average_init(&priv
->average_rssi
);
3690 average_init(&priv
->average_noise
);
3692 priv
->last_rate
= 0;
3693 priv
->last_missed_beacons
= 0;
3694 priv
->last_rx_packets
= 0;
3695 priv
->last_tx_packets
= 0;
3696 priv
->last_tx_failures
= 0;
3698 /* Firmware managed, reset only when NIC is restarted, so we have to
3699 * normalize on the current value */
3700 ipw_get_ordinal(priv
, IPW_ORD_STAT_RX_ERR_CRC
,
3701 &priv
->last_rx_err
, &len
);
3702 ipw_get_ordinal(priv
, IPW_ORD_STAT_TX_FAILURE
,
3703 &priv
->last_tx_failures
, &len
);
3705 /* Driver managed, reset with each association */
3706 priv
->missed_adhoc_beacons
= 0;
3707 priv
->missed_beacons
= 0;
3708 priv
->tx_packets
= 0;
3709 priv
->rx_packets
= 0;
3713 static inline u32
ipw_get_max_rate(struct ipw_priv
*priv
)
3716 u32 mask
= priv
->rates_mask
;
3717 /* If currently associated in B mode, restrict the maximum
3718 * rate match to B rates */
3719 if (priv
->assoc_request
.ieee_mode
== IPW_B_MODE
)
3720 mask
&= IEEE80211_CCK_RATES_MASK
;
3722 /* TODO: Verify that the rate is supported by the current rates
3725 while (i
&& !(mask
& i
))
3728 case IEEE80211_CCK_RATE_1MB_MASK
:
3730 case IEEE80211_CCK_RATE_2MB_MASK
:
3732 case IEEE80211_CCK_RATE_5MB_MASK
:
3734 case IEEE80211_OFDM_RATE_6MB_MASK
:
3736 case IEEE80211_OFDM_RATE_9MB_MASK
:
3738 case IEEE80211_CCK_RATE_11MB_MASK
:
3740 case IEEE80211_OFDM_RATE_12MB_MASK
:
3742 case IEEE80211_OFDM_RATE_18MB_MASK
:
3744 case IEEE80211_OFDM_RATE_24MB_MASK
:
3746 case IEEE80211_OFDM_RATE_36MB_MASK
:
3748 case IEEE80211_OFDM_RATE_48MB_MASK
:
3750 case IEEE80211_OFDM_RATE_54MB_MASK
:
3754 if (priv
->ieee
->mode
== IEEE_B
)
3760 static u32
ipw_get_current_rate(struct ipw_priv
*priv
)
3762 u32 rate
, len
= sizeof(rate
);
3765 if (!(priv
->status
& STATUS_ASSOCIATED
))
3768 if (priv
->tx_packets
> IPW_REAL_RATE_RX_PACKET_THRESHOLD
) {
3769 err
= ipw_get_ordinal(priv
, IPW_ORD_STAT_TX_CURR_RATE
, &rate
,
3772 IPW_DEBUG_INFO("failed querying ordinals.\n");
3776 return ipw_get_max_rate(priv
);
3779 case IPW_TX_RATE_1MB
:
3781 case IPW_TX_RATE_2MB
:
3783 case IPW_TX_RATE_5MB
:
3785 case IPW_TX_RATE_6MB
:
3787 case IPW_TX_RATE_9MB
:
3789 case IPW_TX_RATE_11MB
:
3791 case IPW_TX_RATE_12MB
:
3793 case IPW_TX_RATE_18MB
:
3795 case IPW_TX_RATE_24MB
:
3797 case IPW_TX_RATE_36MB
:
3799 case IPW_TX_RATE_48MB
:
3801 case IPW_TX_RATE_54MB
:
3808 #define IPW_STATS_INTERVAL (2 * HZ)
3809 static void ipw_gather_stats(struct ipw_priv
*priv
)
3811 u32 rx_err
, rx_err_delta
, rx_packets_delta
;
3812 u32 tx_failures
, tx_failures_delta
, tx_packets_delta
;
3813 u32 missed_beacons_percent
, missed_beacons_delta
;
3815 u32 len
= sizeof(u32
);
3817 u32 beacon_quality
, signal_quality
, tx_quality
, rx_quality
,
3821 if (!(priv
->status
& STATUS_ASSOCIATED
)) {
3826 /* Update the statistics */
3827 ipw_get_ordinal(priv
, IPW_ORD_STAT_MISSED_BEACONS
,
3828 &priv
->missed_beacons
, &len
);
3829 missed_beacons_delta
= priv
->missed_beacons
- priv
->last_missed_beacons
;
3830 priv
->last_missed_beacons
= priv
->missed_beacons
;
3831 if (priv
->assoc_request
.beacon_interval
) {
3832 missed_beacons_percent
= missed_beacons_delta
*
3833 (HZ
* priv
->assoc_request
.beacon_interval
) /
3834 (IPW_STATS_INTERVAL
* 10);
3836 missed_beacons_percent
= 0;
3838 average_add(&priv
->average_missed_beacons
, missed_beacons_percent
);
3840 ipw_get_ordinal(priv
, IPW_ORD_STAT_RX_ERR_CRC
, &rx_err
, &len
);
3841 rx_err_delta
= rx_err
- priv
->last_rx_err
;
3842 priv
->last_rx_err
= rx_err
;
3844 ipw_get_ordinal(priv
, IPW_ORD_STAT_TX_FAILURE
, &tx_failures
, &len
);
3845 tx_failures_delta
= tx_failures
- priv
->last_tx_failures
;
3846 priv
->last_tx_failures
= tx_failures
;
3848 rx_packets_delta
= priv
->rx_packets
- priv
->last_rx_packets
;
3849 priv
->last_rx_packets
= priv
->rx_packets
;
3851 tx_packets_delta
= priv
->tx_packets
- priv
->last_tx_packets
;
3852 priv
->last_tx_packets
= priv
->tx_packets
;
3854 /* Calculate quality based on the following:
3856 * Missed beacon: 100% = 0, 0% = 70% missed
3857 * Rate: 60% = 1Mbs, 100% = Max
3858 * Rx and Tx errors represent a straight % of total Rx/Tx
3859 * RSSI: 100% = > -50, 0% = < -80
3860 * Rx errors: 100% = 0, 0% = 50% missed
3862 * The lowest computed quality is used.
3865 #define BEACON_THRESHOLD 5
3866 beacon_quality
= 100 - missed_beacons_percent
;
3867 if (beacon_quality
< BEACON_THRESHOLD
)
3870 beacon_quality
= (beacon_quality
- BEACON_THRESHOLD
) * 100 /
3871 (100 - BEACON_THRESHOLD
);
3872 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
3873 beacon_quality
, missed_beacons_percent
);
3875 priv
->last_rate
= ipw_get_current_rate(priv
);
3876 max_rate
= ipw_get_max_rate(priv
);
3877 rate_quality
= priv
->last_rate
* 40 / max_rate
+ 60;
3878 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
3879 rate_quality
, priv
->last_rate
/ 1000000);
3881 if (rx_packets_delta
> 100 && rx_packets_delta
+ rx_err_delta
)
3882 rx_quality
= 100 - (rx_err_delta
* 100) /
3883 (rx_packets_delta
+ rx_err_delta
);
3886 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
3887 rx_quality
, rx_err_delta
, rx_packets_delta
);
3889 if (tx_packets_delta
> 100 && tx_packets_delta
+ tx_failures_delta
)
3890 tx_quality
= 100 - (tx_failures_delta
* 100) /
3891 (tx_packets_delta
+ tx_failures_delta
);
3894 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
3895 tx_quality
, tx_failures_delta
, tx_packets_delta
);
3897 rssi
= average_value(&priv
->average_rssi
);
3900 (priv
->ieee
->perfect_rssi
- priv
->ieee
->worst_rssi
) *
3901 (priv
->ieee
->perfect_rssi
- priv
->ieee
->worst_rssi
) -
3902 (priv
->ieee
->perfect_rssi
- rssi
) *
3903 (15 * (priv
->ieee
->perfect_rssi
- priv
->ieee
->worst_rssi
) +
3904 62 * (priv
->ieee
->perfect_rssi
- rssi
))) /
3905 ((priv
->ieee
->perfect_rssi
- priv
->ieee
->worst_rssi
) *
3906 (priv
->ieee
->perfect_rssi
- priv
->ieee
->worst_rssi
));
3907 if (signal_quality
> 100)
3908 signal_quality
= 100;
3909 else if (signal_quality
< 1)
3912 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
3913 signal_quality
, rssi
);
3915 quality
= min(beacon_quality
,
3917 min(tx_quality
, min(rx_quality
, signal_quality
))));
3918 if (quality
== beacon_quality
)
3919 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
3921 if (quality
== rate_quality
)
3922 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
3924 if (quality
== tx_quality
)
3925 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
3927 if (quality
== rx_quality
)
3928 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
3930 if (quality
== signal_quality
)
3931 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
3934 priv
->quality
= quality
;
3936 queue_delayed_work(priv
->workqueue
, &priv
->gather_stats
,
3937 IPW_STATS_INTERVAL
);
3940 static void ipw_bg_gather_stats(void *data
)
3942 struct ipw_priv
*priv
= data
;
3944 ipw_gather_stats(data
);
3948 static inline void ipw_handle_missed_beacon(struct ipw_priv
*priv
,
3951 priv
->notif_missed_beacons
= missed_count
;
3953 if (missed_count
> priv
->disassociate_threshold
&&
3954 priv
->status
& STATUS_ASSOCIATED
) {
3955 /* If associated and we've hit the missed
3956 * beacon threshold, disassociate, turn
3957 * off roaming, and abort any active scans */
3958 IPW_DEBUG(IPW_DL_INFO
| IPW_DL_NOTIF
|
3959 IPW_DL_STATE
| IPW_DL_ASSOC
,
3960 "Missed beacon: %d - disassociate\n", missed_count
);
3961 priv
->status
&= ~STATUS_ROAMING
;
3962 if (priv
->status
& STATUS_SCANNING
) {
3963 IPW_DEBUG(IPW_DL_INFO
| IPW_DL_NOTIF
|
3965 "Aborting scan with missed beacon.\n");
3966 queue_work(priv
->workqueue
, &priv
->abort_scan
);
3969 queue_work(priv
->workqueue
, &priv
->disassociate
);
3973 if (priv
->status
& STATUS_ROAMING
) {
3974 /* If we are currently roaming, then just
3975 * print a debug statement... */
3976 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
,
3977 "Missed beacon: %d - roam in progress\n",
3982 if (missed_count
> priv
->roaming_threshold
) {
3983 /* If we are not already roaming, set the ROAM
3984 * bit in the status and kick off a scan */
3985 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
,
3986 "Missed beacon: %d - initiate "
3987 "roaming\n", missed_count
);
3988 if (!(priv
->status
& STATUS_ROAMING
)) {
3989 priv
->status
|= STATUS_ROAMING
;
3990 if (!(priv
->status
& STATUS_SCANNING
))
3991 queue_work(priv
->workqueue
,
3992 &priv
->request_scan
);
3997 if (priv
->status
& STATUS_SCANNING
) {
3998 /* Stop scan to keep fw from getting
3999 * stuck (only if we aren't roaming --
4000 * otherwise we'll never scan more than 2 or 3
4002 IPW_DEBUG(IPW_DL_INFO
| IPW_DL_NOTIF
| IPW_DL_STATE
,
4003 "Aborting scan with missed beacon.\n");
4004 queue_work(priv
->workqueue
, &priv
->abort_scan
);
4007 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count
);
4012 * Handle host notification packet.
4013 * Called from interrupt routine
4015 static inline void ipw_rx_notification(struct ipw_priv
*priv
,
4016 struct ipw_rx_notification
*notif
)
4018 notif
->size
= le16_to_cpu(notif
->size
);
4020 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif
->subtype
, notif
->size
);
4022 switch (notif
->subtype
) {
4023 case HOST_NOTIFICATION_STATUS_ASSOCIATED
:{
4024 struct notif_association
*assoc
= ¬if
->u
.assoc
;
4026 switch (assoc
->state
) {
4027 case CMAS_ASSOCIATED
:{
4028 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4030 "associated: '%s' " MAC_FMT
4032 escape_essid(priv
->essid
,
4034 MAC_ARG(priv
->bssid
));
4036 switch (priv
->ieee
->iw_mode
) {
4038 memcpy(priv
->ieee
->bssid
,
4039 priv
->bssid
, ETH_ALEN
);
4043 memcpy(priv
->ieee
->bssid
,
4044 priv
->bssid
, ETH_ALEN
);
4046 /* clear out the station table */
4047 priv
->num_stations
= 0;
4050 ("queueing adhoc check\n");
4051 queue_delayed_work(priv
->
4061 priv
->status
&= ~STATUS_ASSOCIATING
;
4062 priv
->status
|= STATUS_ASSOCIATED
;
4064 #ifdef CONFIG_IPW_QOS
4065 #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4066 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4067 if ((priv
->status
& STATUS_AUTH
) &&
4068 (IPW_GET_PACKET_STYPE(¬if
->u
.raw
)
4069 == IEEE80211_STYPE_ASSOC_RESP
)) {
4072 ieee80211_assoc_response_frame
)
4074 && (notif
->size
<= 2314)) {
4087 ieee80211_rx_mgt(priv
->
4092 ¬if
->u
.raw
, &stats
);
4097 schedule_work(&priv
->link_up
);
4102 case CMAS_AUTHENTICATED
:{
4104 status
& (STATUS_ASSOCIATED
|
4106 #ifdef CONFIG_IPW_DEBUG
4107 struct notif_authenticate
*auth
4109 IPW_DEBUG(IPW_DL_NOTIF
|
4112 "deauthenticated: '%s' "
4114 ": (0x%04X) - %s \n",
4119 MAC_ARG(priv
->bssid
),
4120 ntohs(auth
->status
),
4127 ~(STATUS_ASSOCIATING
|
4131 schedule_work(&priv
->link_down
);
4135 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4137 "authenticated: '%s' " MAC_FMT
4139 escape_essid(priv
->essid
,
4141 MAC_ARG(priv
->bssid
));
4146 if (priv
->status
& STATUS_AUTH
) {
4148 ieee80211_assoc_response
4152 ieee80211_assoc_response
4154 IPW_DEBUG(IPW_DL_NOTIF
|
4157 "association failed (0x%04X): %s\n",
4158 ntohs(resp
->status
),
4164 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4166 "disassociated: '%s' " MAC_FMT
4168 escape_essid(priv
->essid
,
4170 MAC_ARG(priv
->bssid
));
4173 ~(STATUS_DISASSOCIATING
|
4174 STATUS_ASSOCIATING
|
4175 STATUS_ASSOCIATED
| STATUS_AUTH
);
4176 if (priv
->assoc_network
4177 && (priv
->assoc_network
->
4179 WLAN_CAPABILITY_IBSS
))
4180 ipw_remove_current_network
4183 schedule_work(&priv
->link_down
);
4188 case CMAS_RX_ASSOC_RESP
:
4192 IPW_ERROR("assoc: unknown (%d)\n",
4200 case HOST_NOTIFICATION_STATUS_AUTHENTICATE
:{
4201 struct notif_authenticate
*auth
= ¬if
->u
.auth
;
4202 switch (auth
->state
) {
4203 case CMAS_AUTHENTICATED
:
4204 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
,
4205 "authenticated: '%s' " MAC_FMT
" \n",
4206 escape_essid(priv
->essid
,
4208 MAC_ARG(priv
->bssid
));
4209 priv
->status
|= STATUS_AUTH
;
4213 if (priv
->status
& STATUS_AUTH
) {
4214 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4216 "authentication failed (0x%04X): %s\n",
4217 ntohs(auth
->status
),
4218 ipw_get_status_code(ntohs
4222 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4224 "deauthenticated: '%s' " MAC_FMT
"\n",
4225 escape_essid(priv
->essid
,
4227 MAC_ARG(priv
->bssid
));
4229 priv
->status
&= ~(STATUS_ASSOCIATING
|
4233 schedule_work(&priv
->link_down
);
4236 case CMAS_TX_AUTH_SEQ_1
:
4237 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4238 IPW_DL_ASSOC
, "AUTH_SEQ_1\n");
4240 case CMAS_RX_AUTH_SEQ_2
:
4241 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4242 IPW_DL_ASSOC
, "AUTH_SEQ_2\n");
4244 case CMAS_AUTH_SEQ_1_PASS
:
4245 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4246 IPW_DL_ASSOC
, "AUTH_SEQ_1_PASS\n");
4248 case CMAS_AUTH_SEQ_1_FAIL
:
4249 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4250 IPW_DL_ASSOC
, "AUTH_SEQ_1_FAIL\n");
4252 case CMAS_TX_AUTH_SEQ_3
:
4253 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4254 IPW_DL_ASSOC
, "AUTH_SEQ_3\n");
4256 case CMAS_RX_AUTH_SEQ_4
:
4257 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4258 IPW_DL_ASSOC
, "RX_AUTH_SEQ_4\n");
4260 case CMAS_AUTH_SEQ_2_PASS
:
4261 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4262 IPW_DL_ASSOC
, "AUTH_SEQ_2_PASS\n");
4264 case CMAS_AUTH_SEQ_2_FAIL
:
4265 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4266 IPW_DL_ASSOC
, "AUT_SEQ_2_FAIL\n");
4269 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4270 IPW_DL_ASSOC
, "TX_ASSOC\n");
4272 case CMAS_RX_ASSOC_RESP
:
4273 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4274 IPW_DL_ASSOC
, "RX_ASSOC_RESP\n");
4277 case CMAS_ASSOCIATED
:
4278 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
|
4279 IPW_DL_ASSOC
, "ASSOCIATED\n");
4282 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4289 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT
:{
4290 struct notif_channel_result
*x
=
4291 ¬if
->u
.channel_result
;
4293 if (notif
->size
== sizeof(*x
)) {
4294 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4297 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4298 "(should be %zd)\n",
4299 notif
->size
, sizeof(*x
));
4304 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED
:{
4305 struct notif_scan_complete
*x
= ¬if
->u
.scan_complete
;
4306 if (notif
->size
== sizeof(*x
)) {
4308 ("Scan completed: type %d, %d channels, "
4309 "%d status\n", x
->scan_type
,
4310 x
->num_channels
, x
->status
);
4312 IPW_ERROR("Scan completed of wrong size %d "
4313 "(should be %zd)\n",
4314 notif
->size
, sizeof(*x
));
4318 ~(STATUS_SCANNING
| STATUS_SCAN_ABORTING
);
4320 cancel_delayed_work(&priv
->scan_check
);
4322 if (priv
->status
& STATUS_EXIT_PENDING
)
4325 priv
->ieee
->scans
++;
4327 #ifdef CONFIG_IPW2200_MONITOR
4328 if (priv
->ieee
->iw_mode
== IW_MODE_MONITOR
) {
4329 priv
->status
|= STATUS_SCAN_FORCED
;
4330 queue_work(priv
->workqueue
,
4331 &priv
->request_scan
);
4334 priv
->status
&= ~STATUS_SCAN_FORCED
;
4335 #endif /* CONFIG_IPW2200_MONITOR */
4337 if (!(priv
->status
& (STATUS_ASSOCIATED
|
4338 STATUS_ASSOCIATING
|
4340 STATUS_DISASSOCIATING
)))
4341 queue_work(priv
->workqueue
, &priv
->associate
);
4342 else if (priv
->status
& STATUS_ROAMING
) {
4343 /* If a scan completed and we are in roam mode, then
4344 * the scan that completed was the one requested as a
4345 * result of entering roam... so, schedule the
4347 queue_work(priv
->workqueue
, &priv
->roam
);
4348 } else if (priv
->status
& STATUS_SCAN_PENDING
)
4349 queue_work(priv
->workqueue
,
4350 &priv
->request_scan
);
4351 else if (priv
->config
& CFG_BACKGROUND_SCAN
4352 && priv
->status
& STATUS_ASSOCIATED
)
4353 queue_delayed_work(priv
->workqueue
,
4354 &priv
->request_scan
, HZ
);
4358 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH
:{
4359 struct notif_frag_length
*x
= ¬if
->u
.frag_len
;
4361 if (notif
->size
== sizeof(*x
))
4362 IPW_ERROR("Frag length: %d\n",
4363 le16_to_cpu(x
->frag_length
));
4365 IPW_ERROR("Frag length of wrong size %d "
4366 "(should be %zd)\n",
4367 notif
->size
, sizeof(*x
));
4371 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION
:{
4372 struct notif_link_deterioration
*x
=
4373 ¬if
->u
.link_deterioration
;
4375 if (notif
->size
== sizeof(*x
)) {
4376 IPW_DEBUG(IPW_DL_NOTIF
| IPW_DL_STATE
,
4377 "link deterioration: '%s' " MAC_FMT
4378 " \n", escape_essid(priv
->essid
,
4380 MAC_ARG(priv
->bssid
));
4381 memcpy(&priv
->last_link_deterioration
, x
,
4384 IPW_ERROR("Link Deterioration of wrong size %d "
4385 "(should be %zd)\n",
4386 notif
->size
, sizeof(*x
));
4391 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE
:{
4392 IPW_ERROR("Dino config\n");
4394 && priv
->hcmd
->cmd
!= HOST_CMD_DINO_CONFIG
)
4395 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
4400 case HOST_NOTIFICATION_STATUS_BEACON_STATE
:{
4401 struct notif_beacon_state
*x
= ¬if
->u
.beacon_state
;
4402 if (notif
->size
!= sizeof(*x
)) {
4404 ("Beacon state of wrong size %d (should "
4405 "be %zd)\n", notif
->size
, sizeof(*x
));
4409 if (le32_to_cpu(x
->state
) ==
4410 HOST_NOTIFICATION_STATUS_BEACON_MISSING
)
4411 ipw_handle_missed_beacon(priv
,
4418 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY
:{
4419 struct notif_tgi_tx_key
*x
= ¬if
->u
.tgi_tx_key
;
4420 if (notif
->size
== sizeof(*x
)) {
4421 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4422 "0x%02x station %d\n",
4423 x
->key_state
, x
->security_type
,
4429 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4430 notif
->size
, sizeof(*x
));
4434 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS
:{
4435 struct notif_calibration
*x
= ¬if
->u
.calibration
;
4437 if (notif
->size
== sizeof(*x
)) {
4438 memcpy(&priv
->calib
, x
, sizeof(*x
));
4439 IPW_DEBUG_INFO("TODO: Calibration\n");
4444 ("Calibration of wrong size %d (should be %zd)\n",
4445 notif
->size
, sizeof(*x
));
4449 case HOST_NOTIFICATION_NOISE_STATS
:{
4450 if (notif
->size
== sizeof(u32
)) {
4452 (u8
) (le32_to_cpu(notif
->u
.noise
.value
) &
4454 average_add(&priv
->average_noise
,
4460 ("Noise stat is wrong size %d (should be %zd)\n",
4461 notif
->size
, sizeof(u32
));
4466 IPW_ERROR("Unknown notification: "
4467 "subtype=%d,flags=0x%2x,size=%d\n",
4468 notif
->subtype
, notif
->flags
, notif
->size
);
4473 * Destroys all DMA structures and initialise them again
4476 * @return error code
4478 static int ipw_queue_reset(struct ipw_priv
*priv
)
4481 /** @todo customize queue sizes */
4482 int nTx
= 64, nTxCmd
= 8;
4483 ipw_tx_queue_free(priv
);
4485 rc
= ipw_queue_tx_init(priv
, &priv
->txq_cmd
, nTxCmd
,
4486 IPW_TX_CMD_QUEUE_READ_INDEX
,
4487 IPW_TX_CMD_QUEUE_WRITE_INDEX
,
4488 IPW_TX_CMD_QUEUE_BD_BASE
,
4489 IPW_TX_CMD_QUEUE_BD_SIZE
);
4491 IPW_ERROR("Tx Cmd queue init failed\n");
4495 rc
= ipw_queue_tx_init(priv
, &priv
->txq
[0], nTx
,
4496 IPW_TX_QUEUE_0_READ_INDEX
,
4497 IPW_TX_QUEUE_0_WRITE_INDEX
,
4498 IPW_TX_QUEUE_0_BD_BASE
, IPW_TX_QUEUE_0_BD_SIZE
);
4500 IPW_ERROR("Tx 0 queue init failed\n");
4503 rc
= ipw_queue_tx_init(priv
, &priv
->txq
[1], nTx
,
4504 IPW_TX_QUEUE_1_READ_INDEX
,
4505 IPW_TX_QUEUE_1_WRITE_INDEX
,
4506 IPW_TX_QUEUE_1_BD_BASE
, IPW_TX_QUEUE_1_BD_SIZE
);
4508 IPW_ERROR("Tx 1 queue init failed\n");
4511 rc
= ipw_queue_tx_init(priv
, &priv
->txq
[2], nTx
,
4512 IPW_TX_QUEUE_2_READ_INDEX
,
4513 IPW_TX_QUEUE_2_WRITE_INDEX
,
4514 IPW_TX_QUEUE_2_BD_BASE
, IPW_TX_QUEUE_2_BD_SIZE
);
4516 IPW_ERROR("Tx 2 queue init failed\n");
4519 rc
= ipw_queue_tx_init(priv
, &priv
->txq
[3], nTx
,
4520 IPW_TX_QUEUE_3_READ_INDEX
,
4521 IPW_TX_QUEUE_3_WRITE_INDEX
,
4522 IPW_TX_QUEUE_3_BD_BASE
, IPW_TX_QUEUE_3_BD_SIZE
);
4524 IPW_ERROR("Tx 3 queue init failed\n");
4528 priv
->rx_bufs_min
= 0;
4529 priv
->rx_pend_max
= 0;
4533 ipw_tx_queue_free(priv
);
4538 * Reclaim Tx queue entries no more used by NIC.
4540 * When FW adwances 'R' index, all entries between old and
4541 * new 'R' index need to be reclaimed. As result, some free space
4542 * forms. If there is enough free space (> low mark), wake Tx queue.
4544 * @note Need to protect against garbage in 'R' index
4548 * @return Number of used entries remains in the queue
4550 static int ipw_queue_tx_reclaim(struct ipw_priv
*priv
,
4551 struct clx2_tx_queue
*txq
, int qindex
)
4555 struct clx2_queue
*q
= &txq
->q
;
4557 hw_tail
= ipw_read32(priv
, q
->reg_r
);
4558 if (hw_tail
>= q
->n_bd
) {
4560 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4564 for (; q
->last_used
!= hw_tail
;
4565 q
->last_used
= ipw_queue_inc_wrap(q
->last_used
, q
->n_bd
)) {
4566 ipw_queue_tx_free_tfd(priv
, txq
);
4570 if (ipw_queue_space(q
) > q
->low_mark
&& qindex
>= 0)
4571 __maybe_wake_tx(priv
);
4572 used
= q
->first_empty
- q
->last_used
;
4579 static int ipw_queue_tx_hcmd(struct ipw_priv
*priv
, int hcmd
, void *buf
,
4582 struct clx2_tx_queue
*txq
= &priv
->txq_cmd
;
4583 struct clx2_queue
*q
= &txq
->q
;
4584 struct tfd_frame
*tfd
;
4586 if (ipw_queue_space(q
) < (sync
? 1 : 2)) {
4587 IPW_ERROR("No space for Tx\n");
4591 tfd
= &txq
->bd
[q
->first_empty
];
4592 txq
->txb
[q
->first_empty
] = NULL
;
4594 memset(tfd
, 0, sizeof(*tfd
));
4595 tfd
->control_flags
.message_type
= TX_HOST_COMMAND_TYPE
;
4596 tfd
->control_flags
.control_bits
= TFD_NEED_IRQ_MASK
;
4598 tfd
->u
.cmd
.index
= hcmd
;
4599 tfd
->u
.cmd
.length
= len
;
4600 memcpy(tfd
->u
.cmd
.payload
, buf
, len
);
4601 q
->first_empty
= ipw_queue_inc_wrap(q
->first_empty
, q
->n_bd
);
4602 ipw_write32(priv
, q
->reg_w
, q
->first_empty
);
4603 _ipw_read32(priv
, 0x90);
4609 * Rx theory of operation
4611 * The host allocates 32 DMA target addresses and passes the host address
4612 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
4616 * The host/firmware share two index registers for managing the Rx buffers.
4618 * The READ index maps to the first position that the firmware may be writing
4619 * to -- the driver can read up to (but not including) this position and get
4621 * The READ index is managed by the firmware once the card is enabled.
4623 * The WRITE index maps to the last position the driver has read from -- the
4624 * position preceding WRITE is the last slot the firmware can place a packet.
4626 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
4629 * During initialization the host sets up the READ queue position to the first
4630 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4632 * When the firmware places a packet in a buffer it will advance the READ index
4633 * and fire the RX interrupt. The driver can then query the READ index and
4634 * process as many packets as possible, moving the WRITE index forward as it
4635 * resets the Rx queue buffers with new memory.
4637 * The management in the driver is as follows:
4638 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
4639 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
4640 * to replensish the ipw->rxq->rx_free.
4641 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4642 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4643 * 'processed' and 'read' driver indexes as well)
4644 * + A received packet is processed and handed to the kernel network stack,
4645 * detached from the ipw->rxq. The driver 'processed' index is updated.
4646 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
4647 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4648 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
4649 * were enough free buffers and RX_STALLED is set it is cleared.
4654 * ipw_rx_queue_alloc() Allocates rx_free
4655 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4656 * ipw_rx_queue_restock
4657 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4658 * queue, updates firmware pointers, and updates
4659 * the WRITE index. If insufficient rx_free buffers
4660 * are available, schedules ipw_rx_queue_replenish
4662 * -- enable interrupts --
4663 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
4664 * READ INDEX, detaching the SKB from the pool.
4665 * Moves the packet buffer from queue to rx_used.
4666 * Calls ipw_rx_queue_restock to refill any empty
4673 * If there are slots in the RX queue that need to be restocked,
4674 * and we have free pre-allocated buffers, fill the ranks as much
4675 * as we can pulling from rx_free.
4677 * This moves the 'write' index forward to catch up with 'processed', and
4678 * also updates the memory address in the firmware to reference the new
4681 static void ipw_rx_queue_restock(struct ipw_priv
*priv
)
4683 struct ipw_rx_queue
*rxq
= priv
->rxq
;
4684 struct list_head
*element
;
4685 struct ipw_rx_mem_buffer
*rxb
;
4686 unsigned long flags
;
4689 spin_lock_irqsave(&rxq
->lock
, flags
);
4691 while ((rxq
->write
!= rxq
->processed
) && (rxq
->free_count
)) {
4692 element
= rxq
->rx_free
.next
;
4693 rxb
= list_entry(element
, struct ipw_rx_mem_buffer
, list
);
4696 ipw_write32(priv
, IPW_RFDS_TABLE_LOWER
+ rxq
->write
* RFD_SIZE
,
4698 rxq
->queue
[rxq
->write
] = rxb
;
4699 rxq
->write
= (rxq
->write
+ 1) % RX_QUEUE_SIZE
;
4702 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4704 /* If the pre-allocated buffer pool is dropping low, schedule to
4706 if (rxq
->free_count
<= RX_LOW_WATERMARK
)
4707 queue_work(priv
->workqueue
, &priv
->rx_replenish
);
4709 /* If we've added more space for the firmware to place data, tell it */
4710 if (write
!= rxq
->write
)
4711 ipw_write32(priv
, IPW_RX_WRITE_INDEX
, rxq
->write
);
4715 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
4716 * Also restock the Rx queue via ipw_rx_queue_restock.
4718 * This is called as a scheduled work item (except for during intialization)
4720 static void ipw_rx_queue_replenish(void *data
)
4722 struct ipw_priv
*priv
= data
;
4723 struct ipw_rx_queue
*rxq
= priv
->rxq
;
4724 struct list_head
*element
;
4725 struct ipw_rx_mem_buffer
*rxb
;
4726 unsigned long flags
;
4728 spin_lock_irqsave(&rxq
->lock
, flags
);
4729 while (!list_empty(&rxq
->rx_used
)) {
4730 element
= rxq
->rx_used
.next
;
4731 rxb
= list_entry(element
, struct ipw_rx_mem_buffer
, list
);
4732 rxb
->skb
= alloc_skb(IPW_RX_BUF_SIZE
, GFP_ATOMIC
);
4734 printk(KERN_CRIT
"%s: Can not allocate SKB buffers.\n",
4735 priv
->net_dev
->name
);
4736 /* We don't reschedule replenish work here -- we will
4737 * call the restock method and if it still needs
4738 * more buffers it will schedule replenish */
4743 rxb
->rxb
= (struct ipw_rx_buffer
*)rxb
->skb
->data
;
4745 pci_map_single(priv
->pci_dev
, rxb
->skb
->data
,
4746 IPW_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
4748 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
4751 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4753 ipw_rx_queue_restock(priv
);
4756 static void ipw_bg_rx_queue_replenish(void *data
)
4758 struct ipw_priv
*priv
= data
;
4760 ipw_rx_queue_replenish(data
);
4764 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4765 * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
4766 * This free routine walks the list of POOL entries and if SKB is set to
4767 * non NULL it is unmapped and freed
4769 static void ipw_rx_queue_free(struct ipw_priv
*priv
, struct ipw_rx_queue
*rxq
)
4776 for (i
= 0; i
< RX_QUEUE_SIZE
+ RX_FREE_BUFFERS
; i
++) {
4777 if (rxq
->pool
[i
].skb
!= NULL
) {
4778 pci_unmap_single(priv
->pci_dev
, rxq
->pool
[i
].dma_addr
,
4779 IPW_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
4780 dev_kfree_skb(rxq
->pool
[i
].skb
);
4787 static struct ipw_rx_queue
*ipw_rx_queue_alloc(struct ipw_priv
*priv
)
4789 struct ipw_rx_queue
*rxq
;
4792 rxq
= (struct ipw_rx_queue
*)kmalloc(sizeof(*rxq
), GFP_KERNEL
);
4793 if (unlikely(!rxq
)) {
4794 IPW_ERROR("memory allocation failed\n");
4797 memset(rxq
, 0, sizeof(*rxq
));
4798 spin_lock_init(&rxq
->lock
);
4799 INIT_LIST_HEAD(&rxq
->rx_free
);
4800 INIT_LIST_HEAD(&rxq
->rx_used
);
4802 /* Fill the rx_used queue with _all_ of the Rx buffers */
4803 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++)
4804 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
4806 /* Set us so that we have processed and used all buffers, but have
4807 * not restocked the Rx queue with fresh buffers */
4808 rxq
->read
= rxq
->write
= 0;
4809 rxq
->processed
= RX_QUEUE_SIZE
- 1;
4810 rxq
->free_count
= 0;
4815 static int ipw_is_rate_in_mask(struct ipw_priv
*priv
, int ieee_mode
, u8 rate
)
4817 rate
&= ~IEEE80211_BASIC_RATE_MASK
;
4818 if (ieee_mode
== IEEE_A
) {
4820 case IEEE80211_OFDM_RATE_6MB
:
4821 return priv
->rates_mask
& IEEE80211_OFDM_RATE_6MB_MASK
?
4823 case IEEE80211_OFDM_RATE_9MB
:
4824 return priv
->rates_mask
& IEEE80211_OFDM_RATE_9MB_MASK
?
4826 case IEEE80211_OFDM_RATE_12MB
:
4828 rates_mask
& IEEE80211_OFDM_RATE_12MB_MASK
? 1 : 0;
4829 case IEEE80211_OFDM_RATE_18MB
:
4831 rates_mask
& IEEE80211_OFDM_RATE_18MB_MASK
? 1 : 0;
4832 case IEEE80211_OFDM_RATE_24MB
:
4834 rates_mask
& IEEE80211_OFDM_RATE_24MB_MASK
? 1 : 0;
4835 case IEEE80211_OFDM_RATE_36MB
:
4837 rates_mask
& IEEE80211_OFDM_RATE_36MB_MASK
? 1 : 0;
4838 case IEEE80211_OFDM_RATE_48MB
:
4840 rates_mask
& IEEE80211_OFDM_RATE_48MB_MASK
? 1 : 0;
4841 case IEEE80211_OFDM_RATE_54MB
:
4843 rates_mask
& IEEE80211_OFDM_RATE_54MB_MASK
? 1 : 0;
4851 case IEEE80211_CCK_RATE_1MB
:
4852 return priv
->rates_mask
& IEEE80211_CCK_RATE_1MB_MASK
? 1 : 0;
4853 case IEEE80211_CCK_RATE_2MB
:
4854 return priv
->rates_mask
& IEEE80211_CCK_RATE_2MB_MASK
? 1 : 0;
4855 case IEEE80211_CCK_RATE_5MB
:
4856 return priv
->rates_mask
& IEEE80211_CCK_RATE_5MB_MASK
? 1 : 0;
4857 case IEEE80211_CCK_RATE_11MB
:
4858 return priv
->rates_mask
& IEEE80211_CCK_RATE_11MB_MASK
? 1 : 0;
4861 /* If we are limited to B modulations, bail at this point */
4862 if (ieee_mode
== IEEE_B
)
4867 case IEEE80211_OFDM_RATE_6MB
:
4868 return priv
->rates_mask
& IEEE80211_OFDM_RATE_6MB_MASK
? 1 : 0;
4869 case IEEE80211_OFDM_RATE_9MB
:
4870 return priv
->rates_mask
& IEEE80211_OFDM_RATE_9MB_MASK
? 1 : 0;
4871 case IEEE80211_OFDM_RATE_12MB
:
4872 return priv
->rates_mask
& IEEE80211_OFDM_RATE_12MB_MASK
? 1 : 0;
4873 case IEEE80211_OFDM_RATE_18MB
:
4874 return priv
->rates_mask
& IEEE80211_OFDM_RATE_18MB_MASK
? 1 : 0;
4875 case IEEE80211_OFDM_RATE_24MB
:
4876 return priv
->rates_mask
& IEEE80211_OFDM_RATE_24MB_MASK
? 1 : 0;
4877 case IEEE80211_OFDM_RATE_36MB
:
4878 return priv
->rates_mask
& IEEE80211_OFDM_RATE_36MB_MASK
? 1 : 0;
4879 case IEEE80211_OFDM_RATE_48MB
:
4880 return priv
->rates_mask
& IEEE80211_OFDM_RATE_48MB_MASK
? 1 : 0;
4881 case IEEE80211_OFDM_RATE_54MB
:
4882 return priv
->rates_mask
& IEEE80211_OFDM_RATE_54MB_MASK
? 1 : 0;
4888 static int ipw_compatible_rates(struct ipw_priv
*priv
,
4889 const struct ieee80211_network
*network
,
4890 struct ipw_supported_rates
*rates
)
4894 memset(rates
, 0, sizeof(*rates
));
4895 num_rates
= min(network
->rates_len
, (u8
) IPW_MAX_RATES
);
4896 rates
->num_rates
= 0;
4897 for (i
= 0; i
< num_rates
; i
++) {
4898 if (!ipw_is_rate_in_mask(priv
, network
->mode
,
4899 network
->rates
[i
])) {
4901 if (network
->rates
[i
] & IEEE80211_BASIC_RATE_MASK
) {
4902 IPW_DEBUG_SCAN("Adding masked mandatory "
4905 rates
->supported_rates
[rates
->num_rates
++] =
4910 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4911 network
->rates
[i
], priv
->rates_mask
);
4915 rates
->supported_rates
[rates
->num_rates
++] = network
->rates
[i
];
4918 num_rates
= min(network
->rates_ex_len
,
4919 (u8
) (IPW_MAX_RATES
- num_rates
));
4920 for (i
= 0; i
< num_rates
; i
++) {
4921 if (!ipw_is_rate_in_mask(priv
, network
->mode
,
4922 network
->rates_ex
[i
])) {
4923 if (network
->rates_ex
[i
] & IEEE80211_BASIC_RATE_MASK
) {
4924 IPW_DEBUG_SCAN("Adding masked mandatory "
4926 network
->rates_ex
[i
]);
4927 rates
->supported_rates
[rates
->num_rates
++] =
4932 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4933 network
->rates_ex
[i
], priv
->rates_mask
);
4937 rates
->supported_rates
[rates
->num_rates
++] =
4938 network
->rates_ex
[i
];
4944 static inline void ipw_copy_rates(struct ipw_supported_rates
*dest
,
4945 const struct ipw_supported_rates
*src
)
4948 for (i
= 0; i
< src
->num_rates
; i
++)
4949 dest
->supported_rates
[i
] = src
->supported_rates
[i
];
4950 dest
->num_rates
= src
->num_rates
;
4953 /* TODO: Look at sniffed packets in the air to determine if the basic rate
4954 * mask should ever be used -- right now all callers to add the scan rates are
4955 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
4956 static void ipw_add_cck_scan_rates(struct ipw_supported_rates
*rates
,
4957 u8 modulation
, u32 rate_mask
)
4959 u8 basic_mask
= (IEEE80211_OFDM_MODULATION
== modulation
) ?
4960 IEEE80211_BASIC_RATE_MASK
: 0;
4962 if (rate_mask
& IEEE80211_CCK_RATE_1MB_MASK
)
4963 rates
->supported_rates
[rates
->num_rates
++] =
4964 IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_1MB
;
4966 if (rate_mask
& IEEE80211_CCK_RATE_2MB_MASK
)
4967 rates
->supported_rates
[rates
->num_rates
++] =
4968 IEEE80211_BASIC_RATE_MASK
| IEEE80211_CCK_RATE_2MB
;
4970 if (rate_mask
& IEEE80211_CCK_RATE_5MB_MASK
)
4971 rates
->supported_rates
[rates
->num_rates
++] = basic_mask
|
4972 IEEE80211_CCK_RATE_5MB
;
4974 if (rate_mask
& IEEE80211_CCK_RATE_11MB_MASK
)
4975 rates
->supported_rates
[rates
->num_rates
++] = basic_mask
|
4976 IEEE80211_CCK_RATE_11MB
;
4979 static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates
*rates
,
4980 u8 modulation
, u32 rate_mask
)
4982 u8 basic_mask
= (IEEE80211_OFDM_MODULATION
== modulation
) ?
4983 IEEE80211_BASIC_RATE_MASK
: 0;
4985 if (rate_mask
& IEEE80211_OFDM_RATE_6MB_MASK
)
4986 rates
->supported_rates
[rates
->num_rates
++] = basic_mask
|
4987 IEEE80211_OFDM_RATE_6MB
;
4989 if (rate_mask
& IEEE80211_OFDM_RATE_9MB_MASK
)
4990 rates
->supported_rates
[rates
->num_rates
++] =
4991 IEEE80211_OFDM_RATE_9MB
;
4993 if (rate_mask
& IEEE80211_OFDM_RATE_12MB_MASK
)
4994 rates
->supported_rates
[rates
->num_rates
++] = basic_mask
|
4995 IEEE80211_OFDM_RATE_12MB
;
4997 if (rate_mask
& IEEE80211_OFDM_RATE_18MB_MASK
)
4998 rates
->supported_rates
[rates
->num_rates
++] =
4999 IEEE80211_OFDM_RATE_18MB
;
5001 if (rate_mask
& IEEE80211_OFDM_RATE_24MB_MASK
)
5002 rates
->supported_rates
[rates
->num_rates
++] = basic_mask
|
5003 IEEE80211_OFDM_RATE_24MB
;
5005 if (rate_mask
& IEEE80211_OFDM_RATE_36MB_MASK
)
5006 rates
->supported_rates
[rates
->num_rates
++] =
5007 IEEE80211_OFDM_RATE_36MB
;
5009 if (rate_mask
& IEEE80211_OFDM_RATE_48MB_MASK
)
5010 rates
->supported_rates
[rates
->num_rates
++] =
5011 IEEE80211_OFDM_RATE_48MB
;
5013 if (rate_mask
& IEEE80211_OFDM_RATE_54MB_MASK
)
5014 rates
->supported_rates
[rates
->num_rates
++] =
5015 IEEE80211_OFDM_RATE_54MB
;
5018 struct ipw_network_match
{
5019 struct ieee80211_network
*network
;
5020 struct ipw_supported_rates rates
;
5023 static int ipw_find_adhoc_network(struct ipw_priv
*priv
,
5024 struct ipw_network_match
*match
,
5025 struct ieee80211_network
*network
,
5028 struct ipw_supported_rates rates
;
5030 /* Verify that this network's capability is compatible with the
5031 * current mode (AdHoc or Infrastructure) */
5032 if ((priv
->ieee
->iw_mode
== IW_MODE_ADHOC
&&
5033 !(network
->capability
& WLAN_CAPABILITY_IBSS
))) {
5034 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT
")' excluded due to "
5035 "capability mismatch.\n",
5036 escape_essid(network
->ssid
, network
->ssid_len
),
5037 MAC_ARG(network
->bssid
));
5041 /* If we do not have an ESSID for this AP, we can not associate with
5043 if (network
->flags
& NETWORK_EMPTY_ESSID
) {
5044 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT
")' excluded "
5045 "because of hidden ESSID.\n",
5046 escape_essid(network
->ssid
, network
->ssid_len
),
5047 MAC_ARG(network
->bssid
));
5051 if (unlikely(roaming
)) {
5052 /* If we are roaming, then ensure check if this is a valid
5053 * network to try and roam to */
5054 if ((network
->ssid_len
!= match
->network
->ssid_len
) ||
5055 memcmp(network
->ssid
, match
->network
->ssid
,
5056 network
->ssid_len
)) {
5057 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT
")' excluded "
5058 "because of non-network ESSID.\n",
5059 escape_essid(network
->ssid
,
5061 MAC_ARG(network
->bssid
));
5065 /* If an ESSID has been configured then compare the broadcast
5067 if ((priv
->config
& CFG_STATIC_ESSID
) &&
5068 ((network
->ssid_len
!= priv
->essid_len
) ||
5069 memcmp(network
->ssid
, priv
->essid
,
5070 min(network
->ssid_len
, priv
->essid_len
)))) {
5071 char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
5074 escape_essid(network
->ssid
, network
->ssid_len
),
5076 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT
")' excluded "
5077 "because of ESSID mismatch: '%s'.\n",
5078 escaped
, MAC_ARG(network
->bssid
),
5079 escape_essid(priv
->essid
,
5085 /* If the old network rate is better than this one, don't bother
5086 * testing everything else. */
5088 if (network
->time_stamp
[0] < match
->network
->time_stamp
[0]) {
5089 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5090 "current network.\n",
5091 escape_essid(match
->network
->ssid
,
5092 match
->network
->ssid_len
));
5094 } else if (network
->time_stamp
[1] < match
->network
->time_stamp
[1]) {
5095 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5096 "current network.\n",
5097 escape_essid(match
->network
->ssid
,
5098 match
->network
->ssid_len
));
5102 /* Now go through and see if the requested network is valid... */
5103 if (priv
->ieee
->scan_age
!= 0 &&
5104 time_after(jiffies
, network
->last_scanned
+ priv
->ieee
->scan_age
)) {
5105 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT
")' excluded "
5106 "because of age: %lums.\n",
5107 escape_essid(network
->ssid
, network
->ssid_len
),
5108 MAC_ARG(network
->bssid
),
5109 1000 * (jiffies
- network
->last_scanned
) / HZ
);
5113 if ((priv
->config
& CFG_STATIC_CHANNEL
) &&
5114 (network
->channel
!= priv
->channel
)) {
5115 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT
")' excluded "
5116 "because of channel mismatch: %d != %d.\n",
5117 escape_essid(network
->ssid
, network
->ssid_len
),
5118 MAC_ARG(network
->bssid
),
5119 network
->channel
, priv
->channel
);
5123 /* Verify privacy compatability */
5124 if (((priv
->capability
& CAP_PRIVACY_ON
) ? 1 : 0) !=
5125 ((network
->capability
& WLAN_CAPABILITY_PRIVACY
) ? 1 : 0)) {
5126 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT
")' excluded "
5127 "because of privacy mismatch: %s != %s.\n",
5128 escape_essid(network
->ssid
, network
->ssid_len
),
5129 MAC_ARG(network
->bssid
),
5131 capability
& CAP_PRIVACY_ON
? "on" : "off",
5133 capability
& WLAN_CAPABILITY_PRIVACY
? "on" :
5138 if (!memcmp(network
->bssid
, priv
->bssid
, ETH_ALEN
)) {
5139 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT
")' excluded "
5140 "because of the same BSSID match: " MAC_FMT
5141 ".\n", escape_essid(network
->ssid
,
5143 MAC_ARG(network
->bssid
), MAC_ARG(priv
->bssid
));
5147 /* Filter out any incompatible freq / mode combinations */
5148 if (!ieee80211_is_valid_mode(priv
->ieee
, network
->mode
)) {
5149 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT
")' excluded "
5150 "because of invalid frequency/mode "
5152 escape_essid(network
->ssid
, network
->ssid_len
),
5153 MAC_ARG(network
->bssid
));
5157 /* Ensure that the rates supported by the driver are compatible with
5158 * this AP, including verification of basic rates (mandatory) */
5159 if (!ipw_compatible_rates(priv
, network
, &rates
)) {
5160 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT
")' excluded "
5161 "because configured rate mask excludes "
5162 "AP mandatory rate.\n",
5163 escape_essid(network
->ssid
, network
->ssid_len
),
5164 MAC_ARG(network
->bssid
));
5168 if (rates
.num_rates
== 0) {
5169 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT
")' excluded "
5170 "because of no compatible rates.\n",
5171 escape_essid(network
->ssid
, network
->ssid_len
),
5172 MAC_ARG(network
->bssid
));
5176 /* TODO: Perform any further minimal comparititive tests. We do not
5177 * want to put too much policy logic here; intelligent scan selection
5178 * should occur within a generic IEEE 802.11 user space tool. */
5180 /* Set up 'new' AP to this network */
5181 ipw_copy_rates(&match
->rates
, &rates
);
5182 match
->network
= network
;
5183 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT
")' is a viable match.\n",
5184 escape_essid(network
->ssid
, network
->ssid_len
),
5185 MAC_ARG(network
->bssid
));
5190 static void ipw_merge_adhoc_network(void *data
)
5192 struct ipw_priv
*priv
= data
;
5193 struct ieee80211_network
*network
= NULL
;
5194 struct ipw_network_match match
= {
5195 .network
= priv
->assoc_network
5198 if ((priv
->status
& STATUS_ASSOCIATED
) &&
5199 (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
)) {
5200 /* First pass through ROAM process -- look for a better
5202 unsigned long flags
;
5204 spin_lock_irqsave(&priv
->ieee
->lock
, flags
);
5205 list_for_each_entry(network
, &priv
->ieee
->network_list
, list
) {
5206 if (network
!= priv
->assoc_network
)
5207 ipw_find_adhoc_network(priv
, &match
, network
,
5210 spin_unlock_irqrestore(&priv
->ieee
->lock
, flags
);
5212 if (match
.network
== priv
->assoc_network
) {
5213 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5219 if ((priv
->ieee
->iw_mode
== IW_MODE_ADHOC
)) {
5220 IPW_DEBUG_MERGE("remove network %s\n",
5221 escape_essid(priv
->essid
,
5223 ipw_remove_current_network(priv
);
5226 ipw_disassociate(priv
);
5227 priv
->assoc_network
= match
.network
;
5233 static int ipw_best_network(struct ipw_priv
*priv
,
5234 struct ipw_network_match
*match
,
5235 struct ieee80211_network
*network
, int roaming
)
5237 struct ipw_supported_rates rates
;
5239 /* Verify that this network's capability is compatible with the
5240 * current mode (AdHoc or Infrastructure) */
5241 if ((priv
->ieee
->iw_mode
== IW_MODE_INFRA
&&
5242 !(network
->capability
& WLAN_CAPABILITY_ESS
)) ||
5243 (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
&&
5244 !(network
->capability
& WLAN_CAPABILITY_IBSS
))) {
5245 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT
")' excluded due to "
5246 "capability mismatch.\n",
5247 escape_essid(network
->ssid
, network
->ssid_len
),
5248 MAC_ARG(network
->bssid
));
5252 /* If we do not have an ESSID for this AP, we can not associate with
5254 if (network
->flags
& NETWORK_EMPTY_ESSID
) {
5255 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT
")' excluded "
5256 "because of hidden ESSID.\n",
5257 escape_essid(network
->ssid
, network
->ssid_len
),
5258 MAC_ARG(network
->bssid
));
5262 if (unlikely(roaming
)) {
5263 /* If we are roaming, then ensure check if this is a valid
5264 * network to try and roam to */
5265 if ((network
->ssid_len
!= match
->network
->ssid_len
) ||
5266 memcmp(network
->ssid
, match
->network
->ssid
,
5267 network
->ssid_len
)) {
5268 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT
")' excluded "
5269 "because of non-network ESSID.\n",
5270 escape_essid(network
->ssid
,
5272 MAC_ARG(network
->bssid
));
5276 /* If an ESSID has been configured then compare the broadcast
5278 if ((priv
->config
& CFG_STATIC_ESSID
) &&
5279 ((network
->ssid_len
!= priv
->essid_len
) ||
5280 memcmp(network
->ssid
, priv
->essid
,
5281 min(network
->ssid_len
, priv
->essid_len
)))) {
5282 char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
5284 escape_essid(network
->ssid
, network
->ssid_len
),
5286 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT
")' excluded "
5287 "because of ESSID mismatch: '%s'.\n",
5288 escaped
, MAC_ARG(network
->bssid
),
5289 escape_essid(priv
->essid
,
5295 /* If the old network rate is better than this one, don't bother
5296 * testing everything else. */
5297 if (match
->network
&& match
->network
->stats
.rssi
> network
->stats
.rssi
) {
5298 char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
5300 escape_essid(network
->ssid
, network
->ssid_len
),
5302 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT
")' excluded because "
5303 "'%s (" MAC_FMT
")' has a stronger signal.\n",
5304 escaped
, MAC_ARG(network
->bssid
),
5305 escape_essid(match
->network
->ssid
,
5306 match
->network
->ssid_len
),
5307 MAC_ARG(match
->network
->bssid
));
5311 /* If this network has already had an association attempt within the
5312 * last 3 seconds, do not try and associate again... */
5313 if (network
->last_associate
&&
5314 time_after(network
->last_associate
+ (HZ
* 3UL), jiffies
)) {
5315 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT
")' excluded "
5316 "because of storming (%lus since last "
5317 "assoc attempt).\n",
5318 escape_essid(network
->ssid
, network
->ssid_len
),
5319 MAC_ARG(network
->bssid
),
5320 (jiffies
- network
->last_associate
) / HZ
);
5324 /* Now go through and see if the requested network is valid... */
5325 if (priv
->ieee
->scan_age
!= 0 &&
5326 time_after(jiffies
, network
->last_scanned
+ priv
->ieee
->scan_age
)) {
5327 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT
")' excluded "
5328 "because of age: %lums.\n",
5329 escape_essid(network
->ssid
, network
->ssid_len
),
5330 MAC_ARG(network
->bssid
),
5331 1000 * (jiffies
- network
->last_scanned
) / HZ
);
5335 if ((priv
->config
& CFG_STATIC_CHANNEL
) &&
5336 (network
->channel
!= priv
->channel
)) {
5337 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT
")' excluded "
5338 "because of channel mismatch: %d != %d.\n",
5339 escape_essid(network
->ssid
, network
->ssid_len
),
5340 MAC_ARG(network
->bssid
),
5341 network
->channel
, priv
->channel
);
5345 /* Verify privacy compatability */
5346 if (((priv
->capability
& CAP_PRIVACY_ON
) ? 1 : 0) !=
5347 ((network
->capability
& WLAN_CAPABILITY_PRIVACY
) ? 1 : 0)) {
5348 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT
")' excluded "
5349 "because of privacy mismatch: %s != %s.\n",
5350 escape_essid(network
->ssid
, network
->ssid_len
),
5351 MAC_ARG(network
->bssid
),
5352 priv
->capability
& CAP_PRIVACY_ON
? "on" :
5354 network
->capability
&
5355 WLAN_CAPABILITY_PRIVACY
? "on" : "off");
5359 if ((priv
->config
& CFG_STATIC_BSSID
) &&
5360 memcmp(network
->bssid
, priv
->bssid
, ETH_ALEN
)) {
5361 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT
")' excluded "
5362 "because of BSSID mismatch: " MAC_FMT
".\n",
5363 escape_essid(network
->ssid
, network
->ssid_len
),
5364 MAC_ARG(network
->bssid
), MAC_ARG(priv
->bssid
));
5368 /* Filter out any incompatible freq / mode combinations */
5369 if (!ieee80211_is_valid_mode(priv
->ieee
, network
->mode
)) {
5370 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT
")' excluded "
5371 "because of invalid frequency/mode "
5373 escape_essid(network
->ssid
, network
->ssid_len
),
5374 MAC_ARG(network
->bssid
));
5378 /* Ensure that the rates supported by the driver are compatible with
5379 * this AP, including verification of basic rates (mandatory) */
5380 if (!ipw_compatible_rates(priv
, network
, &rates
)) {
5381 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT
")' excluded "
5382 "because configured rate mask excludes "
5383 "AP mandatory rate.\n",
5384 escape_essid(network
->ssid
, network
->ssid_len
),
5385 MAC_ARG(network
->bssid
));
5389 if (rates
.num_rates
== 0) {
5390 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT
")' excluded "
5391 "because of no compatible rates.\n",
5392 escape_essid(network
->ssid
, network
->ssid_len
),
5393 MAC_ARG(network
->bssid
));
5397 /* TODO: Perform any further minimal comparititive tests. We do not
5398 * want to put too much policy logic here; intelligent scan selection
5399 * should occur within a generic IEEE 802.11 user space tool. */
5401 /* Set up 'new' AP to this network */
5402 ipw_copy_rates(&match
->rates
, &rates
);
5403 match
->network
= network
;
5405 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT
")' is a viable match.\n",
5406 escape_essid(network
->ssid
, network
->ssid_len
),
5407 MAC_ARG(network
->bssid
));
5412 static void ipw_adhoc_create(struct ipw_priv
*priv
,
5413 struct ieee80211_network
*network
)
5415 const struct ieee80211_geo
*geo
= ieee80211_get_geo(priv
->ieee
);
5419 * For the purposes of scanning, we can set our wireless mode
5420 * to trigger scans across combinations of bands, but when it
5421 * comes to creating a new ad-hoc network, we have tell the FW
5422 * exactly which band to use.
5424 * We also have the possibility of an invalid channel for the
5425 * chossen band. Attempting to create a new ad-hoc network
5426 * with an invalid channel for wireless mode will trigger a
5430 switch (ieee80211_is_valid_channel(priv
->ieee
, priv
->channel
)) {
5431 case IEEE80211_52GHZ_BAND
:
5432 network
->mode
= IEEE_A
;
5433 i
= ieee80211_channel_to_index(priv
->ieee
, priv
->channel
);
5436 if (geo
->a
[i
].flags
& IEEE80211_CH_PASSIVE_ONLY
) {
5437 IPW_WARNING("Overriding invalid channel\n");
5438 priv
->channel
= geo
->a
[0].channel
;
5442 case IEEE80211_24GHZ_BAND
:
5443 if (priv
->ieee
->mode
& IEEE_G
)
5444 network
->mode
= IEEE_G
;
5446 network
->mode
= IEEE_B
;
5450 IPW_WARNING("Overriding invalid channel\n");
5451 if (priv
->ieee
->mode
& IEEE_A
) {
5452 network
->mode
= IEEE_A
;
5453 priv
->channel
= geo
->a
[0].channel
;
5454 } else if (priv
->ieee
->mode
& IEEE_G
) {
5455 network
->mode
= IEEE_G
;
5456 priv
->channel
= geo
->bg
[0].channel
;
5458 network
->mode
= IEEE_B
;
5459 priv
->channel
= geo
->bg
[0].channel
;
5464 network
->channel
= priv
->channel
;
5465 priv
->config
|= CFG_ADHOC_PERSIST
;
5466 ipw_create_bssid(priv
, network
->bssid
);
5467 network
->ssid_len
= priv
->essid_len
;
5468 memcpy(network
->ssid
, priv
->essid
, priv
->essid_len
);
5469 memset(&network
->stats
, 0, sizeof(network
->stats
));
5470 network
->capability
= WLAN_CAPABILITY_IBSS
;
5471 if (!(priv
->config
& CFG_PREAMBLE_LONG
))
5472 network
->capability
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
5473 if (priv
->capability
& CAP_PRIVACY_ON
)
5474 network
->capability
|= WLAN_CAPABILITY_PRIVACY
;
5475 network
->rates_len
= min(priv
->rates
.num_rates
, MAX_RATES_LENGTH
);
5476 memcpy(network
->rates
, priv
->rates
.supported_rates
, network
->rates_len
);
5477 network
->rates_ex_len
= priv
->rates
.num_rates
- network
->rates_len
;
5478 memcpy(network
->rates_ex
,
5479 &priv
->rates
.supported_rates
[network
->rates_len
],
5480 network
->rates_ex_len
);
5481 network
->last_scanned
= 0;
5483 network
->last_associate
= 0;
5484 network
->time_stamp
[0] = 0;
5485 network
->time_stamp
[1] = 0;
5486 network
->beacon_interval
= 100; /* Default */
5487 network
->listen_interval
= 10; /* Default */
5488 network
->atim_window
= 0; /* Default */
5489 network
->wpa_ie_len
= 0;
5490 network
->rsn_ie_len
= 0;
5493 static void ipw_send_tgi_tx_key(struct ipw_priv
*priv
, int type
, int index
)
5495 struct ipw_tgi_tx_key
*key
;
5496 struct host_cmd cmd
= {
5497 .cmd
= IPW_CMD_TGI_TX_KEY
,
5501 if (!(priv
->ieee
->sec
.flags
& (1 << index
)))
5504 key
= (struct ipw_tgi_tx_key
*)&cmd
.param
;
5505 key
->key_id
= index
;
5506 memcpy(key
->key
, priv
->ieee
->sec
.keys
[index
], SCM_TEMPORAL_KEY_LENGTH
);
5507 key
->security_type
= type
;
5508 key
->station_index
= 0; /* always 0 for BSS */
5510 /* 0 for new key; previous value of counter (after fatal error) */
5511 key
->tx_counter
[0] = 0;
5512 key
->tx_counter
[1] = 0;
5514 if (ipw_send_cmd(priv
, &cmd
)) {
5515 IPW_ERROR("failed to send TGI_TX_KEY command\n");
5520 static void ipw_send_wep_keys(struct ipw_priv
*priv
, int type
)
5522 struct ipw_wep_key
*key
;
5524 struct host_cmd cmd
= {
5525 .cmd
= IPW_CMD_WEP_KEY
,
5529 key
= (struct ipw_wep_key
*)&cmd
.param
;
5530 key
->cmd_id
= DINO_CMD_WEP_KEY
;
5533 /* Note: AES keys cannot be set for multiple times.
5534 * Only set it at the first time. */
5535 for (i
= 0; i
< 4; i
++) {
5536 key
->key_index
= i
| type
;
5537 if (!(priv
->ieee
->sec
.flags
& (1 << i
))) {
5542 key
->key_size
= priv
->ieee
->sec
.key_sizes
[i
];
5543 memcpy(key
->key
, priv
->ieee
->sec
.keys
[i
], key
->key_size
);
5545 if (ipw_send_cmd(priv
, &cmd
)) {
5546 IPW_ERROR("failed to send WEP_KEY command\n");
5552 static void ipw_set_hwcrypto_keys(struct ipw_priv
*priv
)
5554 switch (priv
->ieee
->sec
.level
) {
5556 if (!(priv
->ieee
->sec
.flags
& SEC_ACTIVE_KEY
))
5559 ipw_send_tgi_tx_key(priv
, DCT_FLAG_EXT_SECURITY_CCM
,
5560 priv
->ieee
->sec
.active_key
);
5561 ipw_send_wep_keys(priv
, DCW_WEP_KEY_SEC_TYPE_CCM
);
5563 priv
->sys_config
.disable_unicast_decryption
= 0;
5564 priv
->sys_config
.disable_multicast_decryption
= 0;
5565 priv
->ieee
->host_decrypt
= 0;
5566 if (ipw_send_system_config(priv
, &priv
->sys_config
))
5567 IPW_ERROR("ipw_send_system_config failed\n");
5571 if (!(priv
->ieee
->sec
.flags
& SEC_ACTIVE_KEY
))
5574 ipw_send_tgi_tx_key(priv
, DCT_FLAG_EXT_SECURITY_TKIP
,
5575 priv
->ieee
->sec
.active_key
);
5577 priv
->sys_config
.disable_unicast_decryption
= 1;
5578 priv
->sys_config
.disable_multicast_decryption
= 1;
5579 priv
->ieee
->host_decrypt
= 1;
5580 if (ipw_send_system_config(priv
, &priv
->sys_config
))
5581 IPW_ERROR("ipw_send_system_config failed\n");
5585 ipw_send_wep_keys(priv
, DCW_WEP_KEY_SEC_TYPE_WEP
);
5587 priv
->sys_config
.disable_unicast_decryption
= 0;
5588 priv
->sys_config
.disable_multicast_decryption
= 0;
5589 priv
->ieee
->host_decrypt
= 0;
5590 if (ipw_send_system_config(priv
, &priv
->sys_config
))
5591 IPW_ERROR("ipw_send_system_config failed\n");
5600 static void ipw_adhoc_check(void *data
)
5602 struct ipw_priv
*priv
= data
;
5604 if (priv
->missed_adhoc_beacons
++ > priv
->disassociate_threshold
&&
5605 !(priv
->config
& CFG_ADHOC_PERSIST
)) {
5606 IPW_DEBUG(IPW_DL_INFO
| IPW_DL_NOTIF
|
5607 IPW_DL_STATE
| IPW_DL_ASSOC
,
5608 "Missed beacon: %d - disassociate\n",
5609 priv
->missed_adhoc_beacons
);
5610 ipw_remove_current_network(priv
);
5611 ipw_disassociate(priv
);
5615 queue_delayed_work(priv
->workqueue
, &priv
->adhoc_check
,
5616 priv
->assoc_request
.beacon_interval
);
5619 static void ipw_bg_adhoc_check(void *data
)
5621 struct ipw_priv
*priv
= data
;
5623 ipw_adhoc_check(data
);
5627 #ifdef CONFIG_IPW_DEBUG
5628 static void ipw_debug_config(struct ipw_priv
*priv
)
5630 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5631 "[CFG 0x%08X]\n", priv
->config
);
5632 if (priv
->config
& CFG_STATIC_CHANNEL
)
5633 IPW_DEBUG_INFO("Channel locked to %d\n", priv
->channel
);
5635 IPW_DEBUG_INFO("Channel unlocked.\n");
5636 if (priv
->config
& CFG_STATIC_ESSID
)
5637 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
5638 escape_essid(priv
->essid
, priv
->essid_len
));
5640 IPW_DEBUG_INFO("ESSID unlocked.\n");
5641 if (priv
->config
& CFG_STATIC_BSSID
)
5642 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT
"\n",
5643 MAC_ARG(priv
->bssid
));
5645 IPW_DEBUG_INFO("BSSID unlocked.\n");
5646 if (priv
->capability
& CAP_PRIVACY_ON
)
5647 IPW_DEBUG_INFO("PRIVACY on\n");
5649 IPW_DEBUG_INFO("PRIVACY off\n");
5650 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv
->rates_mask
);
5653 #define ipw_debug_config(x) do {} while (0)
5656 static inline void ipw_set_fixed_rate(struct ipw_priv
*priv
, int mode
)
5658 /* TODO: Verify that this works... */
5659 struct ipw_fixed_rate fr
= {
5660 .tx_rates
= priv
->rates_mask
5665 /* Identify 'current FW band' and match it with the fixed
5668 switch (priv
->ieee
->freq_band
) {
5669 case IEEE80211_52GHZ_BAND
: /* A only */
5671 if (priv
->rates_mask
& ~IEEE80211_OFDM_RATES_MASK
) {
5672 /* Invalid fixed rate mask */
5674 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5679 fr
.tx_rates
>>= IEEE80211_OFDM_SHIFT_MASK_A
;
5682 default: /* 2.4Ghz or Mixed */
5684 if (mode
== IEEE_B
) {
5685 if (fr
.tx_rates
& ~IEEE80211_CCK_RATES_MASK
) {
5686 /* Invalid fixed rate mask */
5688 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5695 if (fr
.tx_rates
& ~(IEEE80211_CCK_RATES_MASK
|
5696 IEEE80211_OFDM_RATES_MASK
)) {
5697 /* Invalid fixed rate mask */
5699 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
5704 if (IEEE80211_OFDM_RATE_6MB_MASK
& fr
.tx_rates
) {
5705 mask
|= (IEEE80211_OFDM_RATE_6MB_MASK
>> 1);
5706 fr
.tx_rates
&= ~IEEE80211_OFDM_RATE_6MB_MASK
;
5709 if (IEEE80211_OFDM_RATE_9MB_MASK
& fr
.tx_rates
) {
5710 mask
|= (IEEE80211_OFDM_RATE_9MB_MASK
>> 1);
5711 fr
.tx_rates
&= ~IEEE80211_OFDM_RATE_9MB_MASK
;
5714 if (IEEE80211_OFDM_RATE_12MB_MASK
& fr
.tx_rates
) {
5715 mask
|= (IEEE80211_OFDM_RATE_12MB_MASK
>> 1);
5716 fr
.tx_rates
&= ~IEEE80211_OFDM_RATE_12MB_MASK
;
5719 fr
.tx_rates
|= mask
;
5723 reg
= ipw_read32(priv
, IPW_MEM_FIXED_OVERRIDE
);
5724 ipw_write_reg32(priv
, reg
, *(u32
*) & fr
);
5727 static void ipw_abort_scan(struct ipw_priv
*priv
)
5731 if (priv
->status
& STATUS_SCAN_ABORTING
) {
5732 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5735 priv
->status
|= STATUS_SCAN_ABORTING
;
5737 err
= ipw_send_scan_abort(priv
);
5739 IPW_DEBUG_HC("Request to abort scan failed.\n");
5742 static void ipw_add_scan_channels(struct ipw_priv
*priv
,
5743 struct ipw_scan_request_ext
*scan
,
5746 int channel_index
= 0;
5747 const struct ieee80211_geo
*geo
;
5750 geo
= ieee80211_get_geo(priv
->ieee
);
5752 if (priv
->ieee
->freq_band
& IEEE80211_52GHZ_BAND
) {
5753 int start
= channel_index
;
5754 for (i
= 0; i
< geo
->a_channels
; i
++) {
5755 if ((priv
->status
& STATUS_ASSOCIATED
) &&
5756 geo
->a
[i
].channel
== priv
->channel
)
5759 scan
->channels_list
[channel_index
] = geo
->a
[i
].channel
;
5760 ipw_set_scan_type(scan
, channel_index
, scan_type
);
5763 if (start
!= channel_index
) {
5764 scan
->channels_list
[start
] = (u8
) (IPW_A_MODE
<< 6) |
5765 (channel_index
- start
);
5770 if (priv
->ieee
->freq_band
& IEEE80211_24GHZ_BAND
) {
5771 int start
= channel_index
;
5772 if (priv
->config
& CFG_SPEED_SCAN
) {
5773 u8 channels
[IEEE80211_24GHZ_CHANNELS
] = {
5774 /* nop out the list */
5779 while (channel_index
< IPW_SCAN_CHANNELS
) {
5781 priv
->speed_scan
[priv
->speed_scan_pos
];
5783 priv
->speed_scan_pos
= 0;
5784 channel
= priv
->speed_scan
[0];
5786 if ((priv
->status
& STATUS_ASSOCIATED
) &&
5787 channel
== priv
->channel
) {
5788 priv
->speed_scan_pos
++;
5792 /* If this channel has already been
5793 * added in scan, break from loop
5794 * and this will be the first channel
5797 if (channels
[channel
- 1] != 0)
5800 channels
[channel
- 1] = 1;
5801 priv
->speed_scan_pos
++;
5803 scan
->channels_list
[channel_index
] = channel
;
5804 ipw_set_scan_type(scan
, channel_index
,
5808 for (i
= 0; i
< geo
->bg_channels
; i
++) {
5809 if ((priv
->status
& STATUS_ASSOCIATED
) &&
5810 geo
->bg
[i
].channel
== priv
->channel
)
5813 scan
->channels_list
[channel_index
] =
5815 ipw_set_scan_type(scan
, channel_index
,
5820 if (start
!= channel_index
) {
5821 scan
->channels_list
[start
] = (u8
) (IPW_B_MODE
<< 6) |
5822 (channel_index
- start
);
5827 static int ipw_request_scan(struct ipw_priv
*priv
)
5829 struct ipw_scan_request_ext scan
;
5830 int err
= 0, scan_type
;
5832 if (!(priv
->status
& STATUS_INIT
) ||
5833 (priv
->status
& STATUS_EXIT_PENDING
))
5838 if (priv
->status
& STATUS_SCANNING
) {
5839 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
5840 priv
->status
|= STATUS_SCAN_PENDING
;
5844 if (!(priv
->status
& STATUS_SCAN_FORCED
) &&
5845 priv
->status
& STATUS_SCAN_ABORTING
) {
5846 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
5847 priv
->status
|= STATUS_SCAN_PENDING
;
5851 if (priv
->status
& STATUS_RF_KILL_MASK
) {
5852 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
5853 priv
->status
|= STATUS_SCAN_PENDING
;
5857 memset(&scan
, 0, sizeof(scan
));
5859 if (priv
->config
& CFG_SPEED_SCAN
)
5860 scan
.dwell_time
[IPW_SCAN_ACTIVE_BROADCAST_SCAN
] =
5863 scan
.dwell_time
[IPW_SCAN_ACTIVE_BROADCAST_SCAN
] =
5866 scan
.dwell_time
[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN
] =
5868 scan
.dwell_time
[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
] = cpu_to_le16(20);
5870 scan
.full_scan_index
= cpu_to_le32(ieee80211_get_scans(priv
->ieee
));
5872 #ifdef CONFIG_IPW2200_MONITOR
5873 if (priv
->ieee
->iw_mode
== IW_MODE_MONITOR
) {
5877 switch (ieee80211_is_valid_channel(priv
->ieee
, priv
->channel
)) {
5878 case IEEE80211_52GHZ_BAND
:
5879 band
= (u8
) (IPW_A_MODE
<< 6) | 1;
5880 channel
= priv
->channel
;
5883 case IEEE80211_24GHZ_BAND
:
5884 band
= (u8
) (IPW_B_MODE
<< 6) | 1;
5885 channel
= priv
->channel
;
5889 band
= (u8
) (IPW_B_MODE
<< 6) | 1;
5894 scan
.channels_list
[0] = band
;
5895 scan
.channels_list
[1] = channel
;
5896 ipw_set_scan_type(&scan
, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
);
5898 /* NOTE: The card will sit on this channel for this time
5899 * period. Scan aborts are timing sensitive and frequently
5900 * result in firmware restarts. As such, it is best to
5901 * set a small dwell_time here and just keep re-issuing
5902 * scans. Otherwise fast channel hopping will not actually
5905 * TODO: Move SPEED SCAN support to all modes and bands */
5906 scan
.dwell_time
[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
] =
5909 #endif /* CONFIG_IPW2200_MONITOR */
5910 /* If we are roaming, then make this a directed scan for the
5911 * current network. Otherwise, ensure that every other scan
5912 * is a fast channel hop scan */
5913 if ((priv
->status
& STATUS_ROAMING
)
5914 || (!(priv
->status
& STATUS_ASSOCIATED
)
5915 && (priv
->config
& CFG_STATIC_ESSID
)
5916 && (le32_to_cpu(scan
.full_scan_index
) % 2))) {
5917 err
= ipw_send_ssid(priv
, priv
->essid
, priv
->essid_len
);
5919 IPW_DEBUG_HC("Attempt to send SSID command "
5924 scan_type
= IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN
;
5926 scan_type
= IPW_SCAN_ACTIVE_BROADCAST_SCAN
;
5928 ipw_add_scan_channels(priv
, &scan
, scan_type
);
5929 #ifdef CONFIG_IPW2200_MONITOR
5933 err
= ipw_send_scan_request_ext(priv
, &scan
);
5935 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err
);
5939 priv
->status
|= STATUS_SCANNING
;
5940 priv
->status
&= ~STATUS_SCAN_PENDING
;
5941 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
5942 IPW_SCAN_CHECK_WATCHDOG
);
5948 static void ipw_bg_abort_scan(void *data
)
5950 struct ipw_priv
*priv
= data
;
5952 ipw_abort_scan(data
);
5956 #if WIRELESS_EXT < 18
5957 /* Support for wpa_supplicant before WE-18, deprecated. */
5959 /* following definitions must match definitions in driver_ipw.c */
5961 #define IPW_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
5963 #define IPW_CMD_SET_WPA_PARAM 1
5964 #define IPW_CMD_SET_WPA_IE 2
5965 #define IPW_CMD_SET_ENCRYPTION 3
5966 #define IPW_CMD_MLME 4
5968 #define IPW_PARAM_WPA_ENABLED 1
5969 #define IPW_PARAM_TKIP_COUNTERMEASURES 2
5970 #define IPW_PARAM_DROP_UNENCRYPTED 3
5971 #define IPW_PARAM_PRIVACY_INVOKED 4
5972 #define IPW_PARAM_AUTH_ALGS 5
5973 #define IPW_PARAM_IEEE_802_1X 6
5975 #define IPW_MLME_STA_DEAUTH 1
5976 #define IPW_MLME_STA_DISASSOC 2
5978 #define IPW_CRYPT_ERR_UNKNOWN_ALG 2
5979 #define IPW_CRYPT_ERR_UNKNOWN_ADDR 3
5980 #define IPW_CRYPT_ERR_CRYPT_INIT_FAILED 4
5981 #define IPW_CRYPT_ERR_KEY_SET_FAILED 5
5982 #define IPW_CRYPT_ERR_TX_KEY_SET_FAILED 6
5983 #define IPW_CRYPT_ERR_CARD_CONF_FAILED 7
5985 #define IPW_CRYPT_ALG_NAME_LEN 16
5989 u8 sta_addr
[ETH_ALEN
];
6005 u8 alg
[IPW_CRYPT_ALG_NAME_LEN
];
6009 u8 seq
[8]; /* sequence counter (set: RX, get: TX) */
6017 /* end of driver_ipw.c code */
6020 static int ipw_wpa_enable(struct ipw_priv
*priv
, int value
)
6022 /* This is called when wpa_supplicant loads and closes the driver
6027 #if WIRELESS_EXT < 18
6028 #define IW_AUTH_ALG_OPEN_SYSTEM 0x1
6029 #define IW_AUTH_ALG_SHARED_KEY 0x2
6032 static int ipw_wpa_set_auth_algs(struct ipw_priv
*priv
, int value
)
6034 struct ieee80211_device
*ieee
= priv
->ieee
;
6035 struct ieee80211_security sec
= {
6036 .flags
= SEC_AUTH_MODE
,
6040 if (value
& IW_AUTH_ALG_SHARED_KEY
) {
6041 sec
.auth_mode
= WLAN_AUTH_SHARED_KEY
;
6043 } else if (value
& IW_AUTH_ALG_OPEN_SYSTEM
) {
6044 sec
.auth_mode
= WLAN_AUTH_OPEN
;
6049 if (ieee
->set_security
)
6050 ieee
->set_security(ieee
->dev
, &sec
);
6057 void ipw_wpa_assoc_frame(struct ipw_priv
*priv
, char *wpa_ie
, int wpa_ie_len
)
6059 /* make sure WPA is enabled */
6060 ipw_wpa_enable(priv
, 1);
6062 ipw_disassociate(priv
);
6065 static int ipw_set_rsn_capa(struct ipw_priv
*priv
,
6066 char *capabilities
, int length
)
6068 struct host_cmd cmd
= {
6069 .cmd
= IPW_CMD_RSN_CAPABILITIES
,
6073 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6075 memcpy(cmd
.param
, capabilities
, length
);
6076 if (ipw_send_cmd(priv
, &cmd
)) {
6077 IPW_ERROR("failed to send HOST_CMD_RSN_CAPABILITIES command\n");
6083 #if WIRELESS_EXT < 18
6084 static int ipw_wpa_set_param(struct net_device
*dev
, u8 name
, u32 value
)
6086 struct ipw_priv
*priv
= ieee80211_priv(dev
);
6087 struct ieee80211_crypt_data
*crypt
;
6088 unsigned long flags
;
6092 case IPW_PARAM_WPA_ENABLED
:
6093 ret
= ipw_wpa_enable(priv
, value
);
6096 case IPW_PARAM_TKIP_COUNTERMEASURES
:
6097 crypt
= priv
->ieee
->crypt
[priv
->ieee
->tx_keyidx
];
6098 if (!crypt
|| !crypt
->ops
->set_flags
|| !crypt
->ops
->get_flags
) {
6099 IPW_WARNING("Can't set TKIP countermeasures: "
6100 "crypt not set!\n");
6104 flags
= crypt
->ops
->get_flags(crypt
->priv
);
6107 flags
|= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES
;
6109 flags
&= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES
;
6111 crypt
->ops
->set_flags(flags
, crypt
->priv
);
6115 case IPW_PARAM_DROP_UNENCRYPTED
:{
6118 * wpa_supplicant calls set_wpa_enabled when the driver
6119 * is loaded and unloaded, regardless of if WPA is being
6120 * used. No other calls are made which can be used to
6121 * determine if encryption will be used or not prior to
6122 * association being expected. If encryption is not being
6123 * used, drop_unencrypted is set to false, else true -- we
6124 * can use this to determine if the CAP_PRIVACY_ON bit should
6127 struct ieee80211_security sec
= {
6128 .flags
= SEC_ENABLED
,
6131 priv
->ieee
->drop_unencrypted
= value
;
6132 /* We only change SEC_LEVEL for open mode. Others
6133 * are set by ipw_wpa_set_encryption.
6136 sec
.flags
|= SEC_LEVEL
;
6137 sec
.level
= SEC_LEVEL_0
;
6139 sec
.flags
|= SEC_LEVEL
;
6140 sec
.level
= SEC_LEVEL_1
;
6142 if (priv
->ieee
->set_security
)
6143 priv
->ieee
->set_security(priv
->ieee
->dev
, &sec
);
6147 case IPW_PARAM_PRIVACY_INVOKED
:
6148 priv
->ieee
->privacy_invoked
= value
;
6151 case IPW_PARAM_AUTH_ALGS
:
6152 ret
= ipw_wpa_set_auth_algs(priv
, value
);
6155 case IPW_PARAM_IEEE_802_1X
:
6156 priv
->ieee
->ieee802_1x
= value
;
6160 IPW_ERROR("%s: Unknown WPA param: %d\n", dev
->name
, name
);
6167 static int ipw_wpa_mlme(struct net_device
*dev
, int command
, int reason
)
6169 struct ipw_priv
*priv
= ieee80211_priv(dev
);
6173 case IPW_MLME_STA_DEAUTH
:
6177 case IPW_MLME_STA_DISASSOC
:
6178 ipw_disassociate(priv
);
6182 IPW_ERROR("%s: Unknown MLME request: %d\n", dev
->name
, command
);
6189 static int ipw_wpa_set_wpa_ie(struct net_device
*dev
,
6190 struct ipw_param
*param
, int plen
)
6192 struct ipw_priv
*priv
= ieee80211_priv(dev
);
6193 struct ieee80211_device
*ieee
= priv
->ieee
;
6196 if (param
->u
.wpa_ie
.len
> MAX_WPA_IE_LEN
||
6197 (param
->u
.wpa_ie
.len
&& param
->u
.wpa_ie
.data
== NULL
))
6200 if (param
->u
.wpa_ie
.len
) {
6201 buf
= kmalloc(param
->u
.wpa_ie
.len
, GFP_KERNEL
);
6205 memcpy(buf
, param
->u
.wpa_ie
.data
, param
->u
.wpa_ie
.len
);
6206 kfree(ieee
->wpa_ie
);
6208 ieee
->wpa_ie_len
= param
->u
.wpa_ie
.len
;
6210 kfree(ieee
->wpa_ie
);
6211 ieee
->wpa_ie
= NULL
;
6212 ieee
->wpa_ie_len
= 0;
6215 ipw_wpa_assoc_frame(priv
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
6219 /* implementation borrowed from hostap driver */
6221 static int ipw_wpa_set_encryption(struct net_device
*dev
,
6222 struct ipw_param
*param
, int param_len
)
6225 struct ipw_priv
*priv
= ieee80211_priv(dev
);
6226 struct ieee80211_device
*ieee
= priv
->ieee
;
6227 struct ieee80211_crypto_ops
*ops
;
6228 struct ieee80211_crypt_data
**crypt
;
6230 struct ieee80211_security sec
= {
6234 param
->u
.crypt
.err
= 0;
6235 param
->u
.crypt
.alg
[IPW_CRYPT_ALG_NAME_LEN
- 1] = '\0';
6238 (int)((char *)param
->u
.crypt
.key
- (char *)param
) +
6239 param
->u
.crypt
.key_len
) {
6240 IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len
,
6241 param
->u
.crypt
.key_len
);
6244 if (param
->sta_addr
[0] == 0xff && param
->sta_addr
[1] == 0xff &&
6245 param
->sta_addr
[2] == 0xff && param
->sta_addr
[3] == 0xff &&
6246 param
->sta_addr
[4] == 0xff && param
->sta_addr
[5] == 0xff) {
6247 if (param
->u
.crypt
.idx
>= WEP_KEYS
)
6249 crypt
= &ieee
->crypt
[param
->u
.crypt
.idx
];
6254 sec
.flags
|= SEC_ENABLED
| SEC_ENCRYPT
;
6255 if (strcmp(param
->u
.crypt
.alg
, "none") == 0) {
6259 sec
.level
= SEC_LEVEL_0
;
6260 sec
.flags
|= SEC_LEVEL
;
6261 ieee80211_crypt_delayed_deinit(ieee
, crypt
);
6268 /* IPW HW cannot build TKIP MIC, host decryption still needed. */
6269 if (strcmp(param
->u
.crypt
.alg
, "TKIP") == 0)
6270 ieee
->host_encrypt_msdu
= 1;
6272 if (!(ieee
->host_encrypt
|| ieee
->host_encrypt_msdu
||
6273 ieee
->host_decrypt
))
6274 goto skip_host_crypt
;
6276 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
6277 if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "WEP") == 0) {
6278 request_module("ieee80211_crypt_wep");
6279 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
6280 } else if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "TKIP") == 0) {
6281 request_module("ieee80211_crypt_tkip");
6282 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
6283 } else if (ops
== NULL
&& strcmp(param
->u
.crypt
.alg
, "CCMP") == 0) {
6284 request_module("ieee80211_crypt_ccmp");
6285 ops
= ieee80211_get_crypto_ops(param
->u
.crypt
.alg
);
6288 IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
6289 dev
->name
, param
->u
.crypt
.alg
);
6290 param
->u
.crypt
.err
= IPW_CRYPT_ERR_UNKNOWN_ALG
;
6295 if (*crypt
== NULL
|| (*crypt
)->ops
!= ops
) {
6296 struct ieee80211_crypt_data
*new_crypt
;
6298 ieee80211_crypt_delayed_deinit(ieee
, crypt
);
6300 new_crypt
= (struct ieee80211_crypt_data
*)
6301 kmalloc(sizeof(*new_crypt
), GFP_KERNEL
);
6302 if (new_crypt
== NULL
) {
6306 memset(new_crypt
, 0, sizeof(struct ieee80211_crypt_data
));
6307 new_crypt
->ops
= ops
;
6308 if (new_crypt
->ops
&& try_module_get(new_crypt
->ops
->owner
))
6310 new_crypt
->ops
->init(param
->u
.crypt
.idx
);
6312 if (new_crypt
->priv
== NULL
) {
6314 param
->u
.crypt
.err
= IPW_CRYPT_ERR_CRYPT_INIT_FAILED
;
6322 if (param
->u
.crypt
.key_len
> 0 && (*crypt
)->ops
->set_key
&&
6323 (*crypt
)->ops
->set_key(param
->u
.crypt
.key
,
6324 param
->u
.crypt
.key_len
, param
->u
.crypt
.seq
,
6325 (*crypt
)->priv
) < 0) {
6326 IPW_DEBUG_INFO("%s: key setting failed\n", dev
->name
);
6327 param
->u
.crypt
.err
= IPW_CRYPT_ERR_KEY_SET_FAILED
;
6333 if (param
->u
.crypt
.set_tx
) {
6334 ieee
->tx_keyidx
= param
->u
.crypt
.idx
;
6335 sec
.active_key
= param
->u
.crypt
.idx
;
6336 sec
.flags
|= SEC_ACTIVE_KEY
;
6338 sec
.flags
&= ~SEC_ACTIVE_KEY
;
6340 if (param
->u
.crypt
.alg
!= NULL
) {
6341 memcpy(sec
.keys
[param
->u
.crypt
.idx
],
6342 param
->u
.crypt
.key
, param
->u
.crypt
.key_len
);
6343 sec
.key_sizes
[param
->u
.crypt
.idx
] = param
->u
.crypt
.key_len
;
6344 sec
.flags
|= (1 << param
->u
.crypt
.idx
);
6346 if (strcmp(param
->u
.crypt
.alg
, "WEP") == 0) {
6347 sec
.flags
|= SEC_LEVEL
;
6348 sec
.level
= SEC_LEVEL_1
;
6349 } else if (strcmp(param
->u
.crypt
.alg
, "TKIP") == 0) {
6350 sec
.flags
|= SEC_LEVEL
;
6351 sec
.level
= SEC_LEVEL_2
;
6352 } else if (strcmp(param
->u
.crypt
.alg
, "CCMP") == 0) {
6353 sec
.flags
|= SEC_LEVEL
;
6354 sec
.level
= SEC_LEVEL_3
;
6358 if (ieee
->set_security
)
6359 ieee
->set_security(ieee
->dev
, &sec
);
6361 /* Do not reset port if card is in Managed mode since resetting will
6362 * generate new IEEE 802.11 authentication which may end up in looping
6363 * with IEEE 802.1X. If your hardware requires a reset after WEP
6364 * configuration (for example... Prism2), implement the reset_port in
6365 * the callbacks structures used to initialize the 802.11 stack. */
6366 if (ieee
->reset_on_keychange
&&
6367 ieee
->iw_mode
!= IW_MODE_INFRA
&&
6368 ieee
->reset_port
&& ieee
->reset_port(dev
)) {
6369 IPW_DEBUG_INFO("%s: reset_port failed\n", dev
->name
);
6370 param
->u
.crypt
.err
= IPW_CRYPT_ERR_CARD_CONF_FAILED
;
6377 static int ipw_wpa_supplicant(struct net_device
*dev
, struct iw_point
*p
)
6379 struct ipw_param
*param
;
6380 struct ipw_priv
*priv
= ieee80211_priv(dev
);
6383 IPW_DEBUG_INFO("wpa_supplicant: len=%d\n", p
->length
);
6385 if (p
->length
< sizeof(struct ipw_param
) || !p
->pointer
)
6388 param
= (struct ipw_param
*)kmalloc(p
->length
, GFP_KERNEL
);
6392 if (copy_from_user(param
, p
->pointer
, p
->length
)) {
6398 switch (param
->cmd
) {
6400 case IPW_CMD_SET_WPA_PARAM
:
6401 ret
= ipw_wpa_set_param(dev
, param
->u
.wpa_param
.name
,
6402 param
->u
.wpa_param
.value
);
6405 case IPW_CMD_SET_WPA_IE
:
6406 ret
= ipw_wpa_set_wpa_ie(dev
, param
, p
->length
);
6409 case IPW_CMD_SET_ENCRYPTION
:
6410 ret
= ipw_wpa_set_encryption(dev
, param
, p
->length
);
6414 ret
= ipw_wpa_mlme(dev
, param
->u
.mlme
.command
,
6415 param
->u
.mlme
.reason_code
);
6419 IPW_ERROR("%s: Unknown WPA supplicant request: %d\n",
6420 dev
->name
, param
->cmd
);
6425 if (ret
== 0 && copy_to_user(p
->pointer
, param
, p
->length
))
6437 static int ipw_wx_set_genie(struct net_device
*dev
,
6438 struct iw_request_info
*info
,
6439 union iwreq_data
*wrqu
, char *extra
)
6441 struct ipw_priv
*priv
= ieee80211_priv(dev
);
6442 struct ieee80211_device
*ieee
= priv
->ieee
;
6446 if (wrqu
->data
.length
> MAX_WPA_IE_LEN
||
6447 (wrqu
->data
.length
&& extra
== NULL
))
6452 //if (!ieee->wpa_enabled) {
6453 // err = -EOPNOTSUPP;
6457 if (wrqu
->data
.length
) {
6458 buf
= kmalloc(wrqu
->data
.length
, GFP_KERNEL
);
6464 memcpy(buf
, extra
, wrqu
->data
.length
);
6465 kfree(ieee
->wpa_ie
);
6467 ieee
->wpa_ie_len
= wrqu
->data
.length
;
6469 kfree(ieee
->wpa_ie
);
6470 ieee
->wpa_ie
= NULL
;
6471 ieee
->wpa_ie_len
= 0;
6474 ipw_wpa_assoc_frame(priv
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
6481 static int ipw_wx_get_genie(struct net_device
*dev
,
6482 struct iw_request_info
*info
,
6483 union iwreq_data
*wrqu
, char *extra
)
6485 struct ipw_priv
*priv
= ieee80211_priv(dev
);
6486 struct ieee80211_device
*ieee
= priv
->ieee
;
6491 //if (!ieee->wpa_enabled) {
6492 // err = -EOPNOTSUPP;
6496 if (ieee
->wpa_ie_len
== 0 || ieee
->wpa_ie
== NULL
) {
6497 wrqu
->data
.length
= 0;
6501 if (wrqu
->data
.length
< ieee
->wpa_ie_len
) {
6506 wrqu
->data
.length
= ieee
->wpa_ie_len
;
6507 memcpy(extra
, ieee
->wpa_ie
, ieee
->wpa_ie_len
);
6515 static int ipw_wx_set_auth(struct net_device
*dev
,
6516 struct iw_request_info
*info
,
6517 union iwreq_data
*wrqu
, char *extra
)
6519 struct ipw_priv
*priv
= ieee80211_priv(dev
);
6520 struct ieee80211_device
*ieee
= priv
->ieee
;
6521 struct iw_param
*param
= &wrqu
->param
;
6522 struct ieee80211_crypt_data
*crypt
;
6523 unsigned long flags
;
6526 switch (param
->flags
& IW_AUTH_INDEX
) {
6527 case IW_AUTH_WPA_VERSION
:
6528 case IW_AUTH_CIPHER_PAIRWISE
:
6529 case IW_AUTH_CIPHER_GROUP
:
6530 case IW_AUTH_KEY_MGMT
:
6532 * ipw2200 does not use these parameters
6536 case IW_AUTH_TKIP_COUNTERMEASURES
:
6537 crypt
= priv
->ieee
->crypt
[priv
->ieee
->tx_keyidx
];
6538 if (!crypt
|| !crypt
->ops
->set_flags
|| !crypt
->ops
->get_flags
) {
6539 IPW_WARNING("Can't set TKIP countermeasures: "
6540 "crypt not set!\n");
6544 flags
= crypt
->ops
->get_flags(crypt
->priv
);
6547 flags
|= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES
;
6549 flags
&= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES
;
6551 crypt
->ops
->set_flags(flags
, crypt
->priv
);
6555 case IW_AUTH_DROP_UNENCRYPTED
:{
6558 * wpa_supplicant calls set_wpa_enabled when the driver
6559 * is loaded and unloaded, regardless of if WPA is being
6560 * used. No other calls are made which can be used to
6561 * determine if encryption will be used or not prior to
6562 * association being expected. If encryption is not being
6563 * used, drop_unencrypted is set to false, else true -- we
6564 * can use this to determine if the CAP_PRIVACY_ON bit should
6567 struct ieee80211_security sec
= {
6568 .flags
= SEC_ENABLED
,
6569 .enabled
= param
->value
,
6571 priv
->ieee
->drop_unencrypted
= param
->value
;
6572 /* We only change SEC_LEVEL for open mode. Others
6573 * are set by ipw_wpa_set_encryption.
6575 if (!param
->value
) {
6576 sec
.flags
|= SEC_LEVEL
;
6577 sec
.level
= SEC_LEVEL_0
;
6579 sec
.flags
|= SEC_LEVEL
;
6580 sec
.level
= SEC_LEVEL_1
;
6582 if (priv
->ieee
->set_security
)
6583 priv
->ieee
->set_security(priv
->ieee
->dev
, &sec
);
6587 case IW_AUTH_80211_AUTH_ALG
:
6588 ret
= ipw_wpa_set_auth_algs(priv
, param
->value
);
6591 case IW_AUTH_WPA_ENABLED
:
6592 ret
= ipw_wpa_enable(priv
, param
->value
);
6595 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
6596 ieee
->ieee802_1x
= param
->value
;
6599 //case IW_AUTH_ROAMING_CONTROL:
6600 case IW_AUTH_PRIVACY_INVOKED
:
6601 ieee
->privacy_invoked
= param
->value
;
6611 static int ipw_wx_get_auth(struct net_device
*dev
,
6612 struct iw_request_info
*info
,
6613 union iwreq_data
*wrqu
, char *extra
)
6615 struct ipw_priv
*priv
= ieee80211_priv(dev
);
6616 struct ieee80211_device
*ieee
= priv
->ieee
;
6617 struct ieee80211_crypt_data
*crypt
;
6618 struct iw_param
*param
= &wrqu
->param
;
6621 switch (param
->flags
& IW_AUTH_INDEX
) {
6622 case IW_AUTH_WPA_VERSION
:
6623 case IW_AUTH_CIPHER_PAIRWISE
:
6624 case IW_AUTH_CIPHER_GROUP
:
6625 case IW_AUTH_KEY_MGMT
:
6627 * wpa_supplicant will control these internally
6632 case IW_AUTH_TKIP_COUNTERMEASURES
:
6633 crypt
= priv
->ieee
->crypt
[priv
->ieee
->tx_keyidx
];
6634 if (!crypt
|| !crypt
->ops
->get_flags
) {
6635 IPW_WARNING("Can't get TKIP countermeasures: "
6636 "crypt not set!\n");
6640 param
->value
= (crypt
->ops
->get_flags(crypt
->priv
) &
6641 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES
) ? 1 : 0;
6645 case IW_AUTH_DROP_UNENCRYPTED
:
6646 param
->value
= ieee
->drop_unencrypted
;
6649 case IW_AUTH_80211_AUTH_ALG
:
6650 param
->value
= ieee
->sec
.auth_mode
;
6653 case IW_AUTH_WPA_ENABLED
:
6654 param
->value
= ieee
->wpa_enabled
;
6657 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
6658 param
->value
= ieee
->ieee802_1x
;
6661 case IW_AUTH_ROAMING_CONTROL
:
6662 case IW_AUTH_PRIVACY_INVOKED
:
6663 param
->value
= ieee
->privacy_invoked
;
6672 /* SIOCSIWENCODEEXT */
6673 static int ipw_wx_set_encodeext(struct net_device
*dev
,
6674 struct iw_request_info
*info
,
6675 union iwreq_data
*wrqu
, char *extra
)
6677 struct ipw_priv
*priv
= ieee80211_priv(dev
);
6678 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
6681 /* IPW HW can't build TKIP MIC, host decryption still needed */
6682 if (ext
->alg
== IW_ENCODE_ALG_TKIP
) {
6683 priv
->ieee
->host_encrypt
= 0;
6684 priv
->ieee
->host_encrypt_msdu
= 1;
6685 priv
->ieee
->host_decrypt
= 1;
6687 priv
->ieee
->host_encrypt
= 0;
6688 priv
->ieee
->host_encrypt_msdu
= 0;
6689 priv
->ieee
->host_decrypt
= 0;
6693 return ieee80211_wx_set_encodeext(priv
->ieee
, info
, wrqu
, extra
);
6696 /* SIOCGIWENCODEEXT */
6697 static int ipw_wx_get_encodeext(struct net_device
*dev
,
6698 struct iw_request_info
*info
,
6699 union iwreq_data
*wrqu
, char *extra
)
6701 struct ipw_priv
*priv
= ieee80211_priv(dev
);
6702 return ieee80211_wx_get_encodeext(priv
->ieee
, info
, wrqu
, extra
);
6706 static int ipw_wx_set_mlme(struct net_device
*dev
,
6707 struct iw_request_info
*info
,
6708 union iwreq_data
*wrqu
, char *extra
)
6710 struct ipw_priv
*priv
= ieee80211_priv(dev
);
6711 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
6714 reason
= cpu_to_le16(mlme
->reason_code
);
6716 switch (mlme
->cmd
) {
6717 case IW_MLME_DEAUTH
:
6721 case IW_MLME_DISASSOC
:
6722 ipw_disassociate(priv
);
6732 #ifdef CONFIG_IPW_QOS
6736 * get the modulation type of the current network or
6737 * the card current mode
6739 u8
ipw_qos_current_mode(struct ipw_priv
* priv
)
6743 if (priv
->status
& STATUS_ASSOCIATED
) {
6744 unsigned long flags
;
6746 spin_lock_irqsave(&priv
->ieee
->lock
, flags
);
6747 mode
= priv
->assoc_network
->mode
;
6748 spin_unlock_irqrestore(&priv
->ieee
->lock
, flags
);
6750 mode
= priv
->ieee
->mode
;
6752 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode
);
6757 * Handle management frame beacon and probe response
6759 static int ipw_qos_handle_probe_reponse(struct ipw_priv
*priv
,
6761 struct ieee80211_network
*network
)
6763 u32 size
= sizeof(struct ieee80211_qos_parameters
);
6765 if (network
->capability
& WLAN_CAPABILITY_IBSS
)
6766 network
->qos_data
.active
= network
->qos_data
.supported
;
6768 if (network
->flags
& NETWORK_HAS_QOS_MASK
) {
6769 if (active_network
&&
6770 (network
->flags
& NETWORK_HAS_QOS_PARAMETERS
))
6771 network
->qos_data
.active
= network
->qos_data
.supported
;
6773 if ((network
->qos_data
.active
== 1) && (active_network
== 1) &&
6774 (network
->flags
& NETWORK_HAS_QOS_PARAMETERS
) &&
6775 (network
->qos_data
.old_param_count
!=
6776 network
->qos_data
.param_count
)) {
6777 network
->qos_data
.old_param_count
=
6778 network
->qos_data
.param_count
;
6779 schedule_work(&priv
->qos_activate
);
6780 IPW_DEBUG_QOS("QoS parameters change call "
6784 if ((priv
->ieee
->mode
== IEEE_B
) || (network
->mode
== IEEE_B
))
6785 memcpy(&network
->qos_data
.parameters
,
6786 &def_parameters_CCK
, size
);
6788 memcpy(&network
->qos_data
.parameters
,
6789 &def_parameters_OFDM
, size
);
6791 if ((network
->qos_data
.active
== 1) && (active_network
== 1)) {
6792 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6793 schedule_work(&priv
->qos_activate
);
6796 network
->qos_data
.active
= 0;
6797 network
->qos_data
.supported
= 0;
6799 if ((priv
->status
& STATUS_ASSOCIATED
) &&
6800 (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
) && (active_network
== 0)) {
6801 if (memcmp(network
->bssid
, priv
->bssid
, ETH_ALEN
))
6802 if ((network
->capability
& WLAN_CAPABILITY_IBSS
) &&
6803 !(network
->flags
& NETWORK_EMPTY_ESSID
))
6804 if ((network
->ssid_len
==
6805 priv
->assoc_network
->ssid_len
) &&
6806 !memcmp(network
->ssid
,
6807 priv
->assoc_network
->ssid
,
6808 network
->ssid_len
)) {
6809 queue_work(priv
->workqueue
,
6810 &priv
->merge_networks
);
6818 * This function set up the firmware to support QoS. It sends
6819 * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6821 static int ipw_qos_activate(struct ipw_priv
*priv
,
6822 struct ieee80211_qos_data
*qos_network_data
)
6825 struct ieee80211_qos_parameters qos_parameters
[QOS_QOS_SETS
];
6826 struct ieee80211_qos_parameters
*active_one
= NULL
;
6827 u32 size
= sizeof(struct ieee80211_qos_parameters
);
6832 type
= ipw_qos_current_mode(priv
);
6834 active_one
= &(qos_parameters
[QOS_PARAM_SET_DEF_CCK
]);
6835 memcpy(active_one
, priv
->qos_data
.def_qos_parm_CCK
, size
);
6836 active_one
= &(qos_parameters
[QOS_PARAM_SET_DEF_OFDM
]);
6837 memcpy(active_one
, priv
->qos_data
.def_qos_parm_OFDM
, size
);
6839 if (qos_network_data
== NULL
) {
6840 if (type
== IEEE_B
) {
6841 IPW_DEBUG_QOS("QoS activate network mode %d\n", type
);
6842 active_one
= &def_parameters_CCK
;
6844 active_one
= &def_parameters_OFDM
;
6846 memcpy(&qos_parameters
[QOS_PARAM_SET_ACTIVE
], active_one
, size
);
6847 burst_duration
= ipw_qos_get_burst_duration(priv
);
6848 for (i
= 0; i
< QOS_QUEUE_NUM
; i
++)
6849 qos_parameters
[QOS_PARAM_SET_ACTIVE
].tx_op_limit
[i
] =
6850 (u16
) burst_duration
;
6851 } else if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
) {
6852 if (type
== IEEE_B
) {
6853 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6855 if (priv
->qos_data
.qos_enable
== 0)
6856 active_one
= &def_parameters_CCK
;
6858 active_one
= priv
->qos_data
.def_qos_parm_CCK
;
6860 if (priv
->qos_data
.qos_enable
== 0)
6861 active_one
= &def_parameters_OFDM
;
6863 active_one
= priv
->qos_data
.def_qos_parm_OFDM
;
6865 memcpy(&qos_parameters
[QOS_PARAM_SET_ACTIVE
], active_one
, size
);
6867 unsigned long flags
;
6870 spin_lock_irqsave(&priv
->ieee
->lock
, flags
);
6871 active_one
= &(qos_network_data
->parameters
);
6872 qos_network_data
->old_param_count
=
6873 qos_network_data
->param_count
;
6874 memcpy(&qos_parameters
[QOS_PARAM_SET_ACTIVE
], active_one
, size
);
6875 active
= qos_network_data
->supported
;
6876 spin_unlock_irqrestore(&priv
->ieee
->lock
, flags
);
6879 burst_duration
= ipw_qos_get_burst_duration(priv
);
6880 for (i
= 0; i
< QOS_QUEUE_NUM
; i
++)
6881 qos_parameters
[QOS_PARAM_SET_ACTIVE
].
6882 tx_op_limit
[i
] = (u16
) burst_duration
;
6886 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
6887 err
= ipw_send_qos_params_command(priv
,
6888 (struct ieee80211_qos_parameters
*)
6889 &(qos_parameters
[0]));
6891 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6897 * send IPW_CMD_WME_INFO to the firmware
6899 static int ipw_qos_set_info_element(struct ipw_priv
*priv
)
6902 struct ieee80211_qos_information_element qos_info
;
6907 qos_info
.elementID
= QOS_ELEMENT_ID
;
6908 qos_info
.length
= sizeof(struct ieee80211_qos_information_element
) - 2;
6910 qos_info
.version
= QOS_VERSION_1
;
6911 qos_info
.ac_info
= 0;
6913 memcpy(qos_info
.qui
, qos_oui
, QOS_OUI_LEN
);
6914 qos_info
.qui_type
= QOS_OUI_TYPE
;
6915 qos_info
.qui_subtype
= QOS_OUI_INFO_SUB_TYPE
;
6917 ret
= ipw_send_qos_info_command(priv
, &qos_info
);
6919 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6925 * Set the QoS parameter with the association request structure
6927 static int ipw_qos_association(struct ipw_priv
*priv
,
6928 struct ieee80211_network
*network
)
6931 struct ieee80211_qos_data
*qos_data
= NULL
;
6932 struct ieee80211_qos_data ibss_data
= {
6937 switch (priv
->ieee
->iw_mode
) {
6939 if (!(network
->capability
& WLAN_CAPABILITY_IBSS
))
6942 qos_data
= &ibss_data
;
6946 qos_data
= &network
->qos_data
;
6954 err
= ipw_qos_activate(priv
, qos_data
);
6956 priv
->assoc_request
.policy_support
&= ~HC_QOS_SUPPORT_ASSOC
;
6960 if (priv
->qos_data
.qos_enable
&& qos_data
->supported
) {
6961 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6962 priv
->assoc_request
.policy_support
|= HC_QOS_SUPPORT_ASSOC
;
6963 return ipw_qos_set_info_element(priv
);
6970 * handling the beaconing responces. if we get different QoS setting
6971 * of the network from the the associated setting adjust the QoS
6974 static int ipw_qos_association_resp(struct ipw_priv
*priv
,
6975 struct ieee80211_network
*network
)
6978 unsigned long flags
;
6979 u32 size
= sizeof(struct ieee80211_qos_parameters
);
6980 int set_qos_param
= 0;
6982 if ((priv
== NULL
) || (network
== NULL
) ||
6983 (priv
->assoc_network
== NULL
))
6986 if (!(priv
->status
& STATUS_ASSOCIATED
))
6989 if ((priv
->ieee
->iw_mode
!= IW_MODE_INFRA
))
6992 spin_lock_irqsave(&priv
->ieee
->lock
, flags
);
6993 if (network
->flags
& NETWORK_HAS_QOS_PARAMETERS
) {
6994 memcpy(&priv
->assoc_network
->qos_data
, &network
->qos_data
,
6995 sizeof(struct ieee80211_qos_data
));
6996 priv
->assoc_network
->qos_data
.active
= 1;
6997 if ((network
->qos_data
.old_param_count
!=
6998 network
->qos_data
.param_count
)) {
7000 network
->qos_data
.old_param_count
=
7001 network
->qos_data
.param_count
;
7005 if ((network
->mode
== IEEE_B
) || (priv
->ieee
->mode
== IEEE_B
))
7006 memcpy(&priv
->assoc_network
->qos_data
.parameters
,
7007 &def_parameters_CCK
, size
);
7009 memcpy(&priv
->assoc_network
->qos_data
.parameters
,
7010 &def_parameters_OFDM
, size
);
7011 priv
->assoc_network
->qos_data
.active
= 0;
7012 priv
->assoc_network
->qos_data
.supported
= 0;
7016 spin_unlock_irqrestore(&priv
->ieee
->lock
, flags
);
7018 if (set_qos_param
== 1)
7019 schedule_work(&priv
->qos_activate
);
7024 static u32
ipw_qos_get_burst_duration(struct ipw_priv
*priv
)
7031 if (!(priv
->ieee
->modulation
& IEEE80211_OFDM_MODULATION
))
7032 ret
= priv
->qos_data
.burst_duration_CCK
;
7034 ret
= priv
->qos_data
.burst_duration_OFDM
;
7040 * Initialize the setting of QoS global
7042 static void ipw_qos_init(struct ipw_priv
*priv
, int enable
,
7043 int burst_enable
, u32 burst_duration_CCK
,
7044 u32 burst_duration_OFDM
)
7046 priv
->qos_data
.qos_enable
= enable
;
7048 if (priv
->qos_data
.qos_enable
) {
7049 priv
->qos_data
.def_qos_parm_CCK
= &def_qos_parameters_CCK
;
7050 priv
->qos_data
.def_qos_parm_OFDM
= &def_qos_parameters_OFDM
;
7051 IPW_DEBUG_QOS("QoS is enabled\n");
7053 priv
->qos_data
.def_qos_parm_CCK
= &def_parameters_CCK
;
7054 priv
->qos_data
.def_qos_parm_OFDM
= &def_parameters_OFDM
;
7055 IPW_DEBUG_QOS("QoS is not enabled\n");
7058 priv
->qos_data
.burst_enable
= burst_enable
;
7061 priv
->qos_data
.burst_duration_CCK
= burst_duration_CCK
;
7062 priv
->qos_data
.burst_duration_OFDM
= burst_duration_OFDM
;
7064 priv
->qos_data
.burst_duration_CCK
= 0;
7065 priv
->qos_data
.burst_duration_OFDM
= 0;
7070 * map the packet priority to the right TX Queue
7072 static int ipw_get_tx_queue_number(struct ipw_priv
*priv
, u16 priority
)
7074 if (priority
> 7 || !priv
->qos_data
.qos_enable
)
7077 return from_priority_to_tx_queue
[priority
] - 1;
7081 * add QoS parameter to the TX command
7083 static int ipw_qos_set_tx_queue_command(struct ipw_priv
*priv
,
7085 struct tfd_data
*tfd
, u8 unicast
)
7088 int tx_queue_id
= 0;
7089 struct ieee80211_qos_data
*qos_data
= NULL
;
7090 int active
, supported
;
7091 unsigned long flags
;
7093 if (!(priv
->status
& STATUS_ASSOCIATED
))
7096 qos_data
= &priv
->assoc_network
->qos_data
;
7098 spin_lock_irqsave(&priv
->ieee
->lock
, flags
);
7100 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
) {
7102 qos_data
->active
= 0;
7104 qos_data
->active
= qos_data
->supported
;
7107 active
= qos_data
->active
;
7108 supported
= qos_data
->supported
;
7110 spin_unlock_irqrestore(&priv
->ieee
->lock
, flags
);
7112 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7114 priv
->qos_data
.qos_enable
, active
, supported
, unicast
);
7115 if (active
&& priv
->qos_data
.qos_enable
) {
7116 ret
= from_priority_to_tx_queue
[priority
];
7117 tx_queue_id
= ret
- 1;
7118 IPW_DEBUG_QOS("QoS packet priority is %d \n", priority
);
7119 if (priority
<= 7) {
7120 tfd
->tx_flags_ext
|= DCT_FLAG_EXT_QOS_ENABLED
;
7121 tfd
->tfd
.tfd_26
.mchdr
.qos_ctrl
= priority
;
7122 tfd
->tfd
.tfd_26
.mchdr
.frame_ctl
|=
7123 IEEE80211_STYPE_QOS_DATA
;
7125 if (priv
->qos_data
.qos_no_ack_mask
&
7126 (1UL << tx_queue_id
)) {
7127 tfd
->tx_flags
&= ~DCT_FLAG_ACK_REQD
;
7128 tfd
->tfd
.tfd_26
.mchdr
.qos_ctrl
|=
7138 * background support to run QoS activate functionality
7140 static void ipw_bg_qos_activate(void *data
)
7142 struct ipw_priv
*priv
= data
;
7149 if (priv
->status
& STATUS_ASSOCIATED
)
7150 ipw_qos_activate(priv
, &(priv
->assoc_network
->qos_data
));
7156 * Handler for probe responce and beacon frame
7158 static int ipw_handle_management_frame(struct net_device
*dev
,
7159 struct ieee80211_network
*network
,
7162 struct ipw_priv
*priv
= ieee80211_priv(dev
);
7165 if (priv
->status
& STATUS_ASSOCIATED
&& network
== priv
->assoc_network
)
7171 case IEEE80211_STYPE_PROBE_RESP
:
7172 case IEEE80211_STYPE_BEACON
:
7173 ipw_qos_handle_probe_reponse(priv
, active_network
, network
);
7175 case IEEE80211_STYPE_ASSOC_RESP
:
7176 ipw_qos_association_resp(priv
, network
);
7185 static int ipw_send_qos_params_command(struct ipw_priv
*priv
, struct ieee80211_qos_parameters
7188 struct host_cmd cmd
= {
7189 .cmd
= IPW_CMD_QOS_PARAMETERS
,
7190 .len
= (sizeof(struct ieee80211_qos_parameters
) * 3)
7193 if (!priv
|| !qos_param
) {
7194 IPW_ERROR("Invalid args\n");
7198 memcpy(cmd
.param
, qos_param
, sizeof(*qos_param
) * 3);
7199 if (ipw_send_cmd(priv
, &cmd
)) {
7200 IPW_ERROR("failed to send IPW_CMD_QOS_PARAMETERS command\n");
7207 static int ipw_send_qos_info_command(struct ipw_priv
*priv
, struct ieee80211_qos_information_element
7210 struct host_cmd cmd
= {
7211 .cmd
= IPW_CMD_WME_INFO
,
7212 .len
= sizeof(*qos_param
)
7215 if (!priv
|| !qos_param
) {
7216 IPW_ERROR("Invalid args\n");
7220 memcpy(cmd
.param
, qos_param
, sizeof(*qos_param
));
7221 if (ipw_send_cmd(priv
, &cmd
)) {
7222 IPW_ERROR("failed to send CMD_QOS_INFO command\n");
7229 #endif /* CONFIG_IPW_QOS */
7231 static int ipw_associate_network(struct ipw_priv
*priv
,
7232 struct ieee80211_network
*network
,
7233 struct ipw_supported_rates
*rates
, int roaming
)
7237 if (priv
->config
& CFG_FIXED_RATE
)
7238 ipw_set_fixed_rate(priv
, network
->mode
);
7240 if (!(priv
->config
& CFG_STATIC_ESSID
)) {
7241 priv
->essid_len
= min(network
->ssid_len
,
7242 (u8
) IW_ESSID_MAX_SIZE
);
7243 memcpy(priv
->essid
, network
->ssid
, priv
->essid_len
);
7246 network
->last_associate
= jiffies
;
7248 memset(&priv
->assoc_request
, 0, sizeof(priv
->assoc_request
));
7249 priv
->assoc_request
.channel
= network
->channel
;
7250 if ((priv
->capability
& CAP_PRIVACY_ON
) &&
7251 (priv
->capability
& CAP_SHARED_KEY
)) {
7252 priv
->assoc_request
.auth_type
= AUTH_SHARED_KEY
;
7253 priv
->assoc_request
.auth_key
= priv
->ieee
->sec
.active_key
;
7255 if ((priv
->capability
& CAP_PRIVACY_ON
) &&
7256 (priv
->ieee
->sec
.level
== SEC_LEVEL_1
) &&
7257 !(priv
->ieee
->host_encrypt
|| priv
->ieee
->host_decrypt
))
7258 ipw_send_wep_keys(priv
, DCW_WEP_KEY_SEC_TYPE_WEP
);
7260 priv
->assoc_request
.auth_type
= AUTH_OPEN
;
7261 priv
->assoc_request
.auth_key
= 0;
7264 if (priv
->ieee
->wpa_ie_len
) {
7265 priv
->assoc_request
.policy_support
= 0x02; /* RSN active */
7266 ipw_set_rsn_capa(priv
, priv
->ieee
->wpa_ie
,
7267 priv
->ieee
->wpa_ie_len
);
7271 * It is valid for our ieee device to support multiple modes, but
7272 * when it comes to associating to a given network we have to choose
7275 if (network
->mode
& priv
->ieee
->mode
& IEEE_A
)
7276 priv
->assoc_request
.ieee_mode
= IPW_A_MODE
;
7277 else if (network
->mode
& priv
->ieee
->mode
& IEEE_G
)
7278 priv
->assoc_request
.ieee_mode
= IPW_G_MODE
;
7279 else if (network
->mode
& priv
->ieee
->mode
& IEEE_B
)
7280 priv
->assoc_request
.ieee_mode
= IPW_B_MODE
;
7282 priv
->assoc_request
.capability
= network
->capability
;
7283 if ((network
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
7284 && !(priv
->config
& CFG_PREAMBLE_LONG
)) {
7285 priv
->assoc_request
.preamble_length
= DCT_FLAG_SHORT_PREAMBLE
;
7287 priv
->assoc_request
.preamble_length
= DCT_FLAG_LONG_PREAMBLE
;
7289 /* Clear the short preamble if we won't be supporting it */
7290 priv
->assoc_request
.capability
&=
7291 ~WLAN_CAPABILITY_SHORT_PREAMBLE
;
7294 /* Clear capability bits that aren't used in Ad Hoc */
7295 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
)
7296 priv
->assoc_request
.capability
&=
7297 ~WLAN_CAPABILITY_SHORT_SLOT_TIME
;
7299 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
7300 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
7301 roaming
? "Rea" : "A",
7302 escape_essid(priv
->essid
, priv
->essid_len
),
7304 ipw_modes
[priv
->assoc_request
.ieee_mode
],
7306 (priv
->assoc_request
.preamble_length
==
7307 DCT_FLAG_LONG_PREAMBLE
) ? "long" : "short",
7308 network
->capability
&
7309 WLAN_CAPABILITY_SHORT_PREAMBLE
? "short" : "long",
7310 priv
->capability
& CAP_PRIVACY_ON
? "on " : "off",
7311 priv
->capability
& CAP_PRIVACY_ON
?
7312 (priv
->capability
& CAP_SHARED_KEY
? "(shared)" :
7314 priv
->capability
& CAP_PRIVACY_ON
? " key=" : "",
7315 priv
->capability
& CAP_PRIVACY_ON
?
7316 '1' + priv
->ieee
->sec
.active_key
: '.',
7317 priv
->capability
& CAP_PRIVACY_ON
? '.' : ' ');
7319 priv
->assoc_request
.beacon_interval
= network
->beacon_interval
;
7320 if ((priv
->ieee
->iw_mode
== IW_MODE_ADHOC
) &&
7321 (network
->time_stamp
[0] == 0) && (network
->time_stamp
[1] == 0)) {
7322 priv
->assoc_request
.assoc_type
= HC_IBSS_START
;
7323 priv
->assoc_request
.assoc_tsf_msw
= 0;
7324 priv
->assoc_request
.assoc_tsf_lsw
= 0;
7326 if (unlikely(roaming
))
7327 priv
->assoc_request
.assoc_type
= HC_REASSOCIATE
;
7329 priv
->assoc_request
.assoc_type
= HC_ASSOCIATE
;
7330 priv
->assoc_request
.assoc_tsf_msw
= network
->time_stamp
[1];
7331 priv
->assoc_request
.assoc_tsf_lsw
= network
->time_stamp
[0];
7334 memcpy(priv
->assoc_request
.bssid
, network
->bssid
, ETH_ALEN
);
7336 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
) {
7337 memset(&priv
->assoc_request
.dest
, 0xFF, ETH_ALEN
);
7338 priv
->assoc_request
.atim_window
= network
->atim_window
;
7340 memcpy(priv
->assoc_request
.dest
, network
->bssid
, ETH_ALEN
);
7341 priv
->assoc_request
.atim_window
= 0;
7344 priv
->assoc_request
.listen_interval
= network
->listen_interval
;
7346 err
= ipw_send_ssid(priv
, priv
->essid
, priv
->essid_len
);
7348 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7352 rates
->ieee_mode
= priv
->assoc_request
.ieee_mode
;
7353 rates
->purpose
= IPW_RATE_CONNECT
;
7354 ipw_send_supported_rates(priv
, rates
);
7356 if (priv
->assoc_request
.ieee_mode
== IPW_G_MODE
)
7357 priv
->sys_config
.dot11g_auto_detection
= 1;
7359 priv
->sys_config
.dot11g_auto_detection
= 0;
7361 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
)
7362 priv
->sys_config
.answer_broadcast_ssid_probe
= 1;
7364 priv
->sys_config
.answer_broadcast_ssid_probe
= 0;
7366 err
= ipw_send_system_config(priv
, &priv
->sys_config
);
7368 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7372 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network
->stats
.rssi
);
7373 err
= ipw_set_sensitivity(priv
, network
->stats
.rssi
+ IPW_RSSI_TO_DBM
);
7375 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7380 * If preemption is enabled, it is possible for the association
7381 * to complete before we return from ipw_send_associate. Therefore
7382 * we have to be sure and update our priviate data first.
7384 priv
->channel
= network
->channel
;
7385 memcpy(priv
->bssid
, network
->bssid
, ETH_ALEN
);
7386 priv
->status
|= STATUS_ASSOCIATING
;
7387 priv
->status
&= ~STATUS_SECURITY_UPDATED
;
7389 priv
->assoc_network
= network
;
7391 #ifdef CONFIG_IPW_QOS
7392 ipw_qos_association(priv
, network
);
7395 err
= ipw_send_associate(priv
, &priv
->assoc_request
);
7397 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7401 IPW_DEBUG(IPW_DL_STATE
, "associating: '%s' " MAC_FMT
" \n",
7402 escape_essid(priv
->essid
, priv
->essid_len
),
7403 MAC_ARG(priv
->bssid
));
7408 static void ipw_roam(void *data
)
7410 struct ipw_priv
*priv
= data
;
7411 struct ieee80211_network
*network
= NULL
;
7412 struct ipw_network_match match
= {
7413 .network
= priv
->assoc_network
7416 /* The roaming process is as follows:
7418 * 1. Missed beacon threshold triggers the roaming process by
7419 * setting the status ROAM bit and requesting a scan.
7420 * 2. When the scan completes, it schedules the ROAM work
7421 * 3. The ROAM work looks at all of the known networks for one that
7422 * is a better network than the currently associated. If none
7423 * found, the ROAM process is over (ROAM bit cleared)
7424 * 4. If a better network is found, a disassociation request is
7426 * 5. When the disassociation completes, the roam work is again
7427 * scheduled. The second time through, the driver is no longer
7428 * associated, and the newly selected network is sent an
7429 * association request.
7430 * 6. At this point ,the roaming process is complete and the ROAM
7431 * status bit is cleared.
7434 /* If we are no longer associated, and the roaming bit is no longer
7435 * set, then we are not actively roaming, so just return */
7436 if (!(priv
->status
& (STATUS_ASSOCIATED
| STATUS_ROAMING
)))
7439 if (priv
->status
& STATUS_ASSOCIATED
) {
7440 /* First pass through ROAM process -- look for a better
7442 unsigned long flags
;
7443 u8 rssi
= priv
->assoc_network
->stats
.rssi
;
7444 priv
->assoc_network
->stats
.rssi
= -128;
7445 spin_lock_irqsave(&priv
->ieee
->lock
, flags
);
7446 list_for_each_entry(network
, &priv
->ieee
->network_list
, list
) {
7447 if (network
!= priv
->assoc_network
)
7448 ipw_best_network(priv
, &match
, network
, 1);
7450 spin_unlock_irqrestore(&priv
->ieee
->lock
, flags
);
7451 priv
->assoc_network
->stats
.rssi
= rssi
;
7453 if (match
.network
== priv
->assoc_network
) {
7454 IPW_DEBUG_ASSOC("No better APs in this network to "
7456 priv
->status
&= ~STATUS_ROAMING
;
7457 ipw_debug_config(priv
);
7461 ipw_send_disassociate(priv
, 1);
7462 priv
->assoc_network
= match
.network
;
7467 /* Second pass through ROAM process -- request association */
7468 ipw_compatible_rates(priv
, priv
->assoc_network
, &match
.rates
);
7469 ipw_associate_network(priv
, priv
->assoc_network
, &match
.rates
, 1);
7470 priv
->status
&= ~STATUS_ROAMING
;
7473 static void ipw_bg_roam(void *data
)
7475 struct ipw_priv
*priv
= data
;
7481 static int ipw_associate(void *data
)
7483 struct ipw_priv
*priv
= data
;
7485 struct ieee80211_network
*network
= NULL
;
7486 struct ipw_network_match match
= {
7489 struct ipw_supported_rates
*rates
;
7490 struct list_head
*element
;
7491 unsigned long flags
;
7493 if (priv
->ieee
->iw_mode
== IW_MODE_MONITOR
) {
7494 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7498 if (priv
->status
& (STATUS_ASSOCIATED
| STATUS_ASSOCIATING
)) {
7499 IPW_DEBUG_ASSOC("Not attempting association (already in "
7504 if (!ipw_is_init(priv
) || (priv
->status
& STATUS_SCANNING
)) {
7505 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7510 if (!(priv
->config
& CFG_ASSOCIATE
) &&
7511 !(priv
->config
& (CFG_STATIC_ESSID
|
7512 CFG_STATIC_CHANNEL
| CFG_STATIC_BSSID
))) {
7513 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
7517 /* Protect our use of the network_list */
7518 spin_lock_irqsave(&priv
->ieee
->lock
, flags
);
7519 list_for_each_entry(network
, &priv
->ieee
->network_list
, list
)
7520 ipw_best_network(priv
, &match
, network
, 0);
7522 network
= match
.network
;
7523 rates
= &match
.rates
;
7525 if (network
== NULL
&&
7526 priv
->ieee
->iw_mode
== IW_MODE_ADHOC
&&
7527 priv
->config
& CFG_ADHOC_CREATE
&&
7528 priv
->config
& CFG_STATIC_ESSID
&&
7529 priv
->config
& CFG_STATIC_CHANNEL
&&
7530 !list_empty(&priv
->ieee
->network_free_list
)) {
7531 element
= priv
->ieee
->network_free_list
.next
;
7532 network
= list_entry(element
, struct ieee80211_network
, list
);
7533 ipw_adhoc_create(priv
, network
);
7534 rates
= &priv
->rates
;
7536 list_add_tail(&network
->list
, &priv
->ieee
->network_list
);
7538 spin_unlock_irqrestore(&priv
->ieee
->lock
, flags
);
7540 /* If we reached the end of the list, then we don't have any valid
7543 ipw_debug_config(priv
);
7545 if (!(priv
->status
& STATUS_SCANNING
)) {
7546 if (!(priv
->config
& CFG_SPEED_SCAN
))
7547 queue_delayed_work(priv
->workqueue
,
7548 &priv
->request_scan
,
7551 queue_work(priv
->workqueue
,
7552 &priv
->request_scan
);
7558 ipw_associate_network(priv
, network
, rates
, 0);
7563 static void ipw_bg_associate(void *data
)
7565 struct ipw_priv
*priv
= data
;
7567 ipw_associate(data
);
7571 static void ipw_rebuild_decrypted_skb(struct ipw_priv
*priv
,
7572 struct sk_buff
*skb
)
7574 struct ieee80211_hdr
*hdr
;
7577 hdr
= (struct ieee80211_hdr
*)skb
->data
;
7578 fc
= le16_to_cpu(hdr
->frame_ctl
);
7579 if (!(fc
& IEEE80211_FCTL_PROTECTED
))
7582 fc
&= ~IEEE80211_FCTL_PROTECTED
;
7583 hdr
->frame_ctl
= cpu_to_le16(fc
);
7584 switch (priv
->ieee
->sec
.level
) {
7586 /* Remove CCMP HDR */
7587 memmove(skb
->data
+ IEEE80211_3ADDR_LEN
,
7588 skb
->data
+ IEEE80211_3ADDR_LEN
+ 8,
7589 skb
->len
- IEEE80211_3ADDR_LEN
- 8);
7590 if (fc
& IEEE80211_FCTL_MOREFRAGS
)
7591 skb_trim(skb
, skb
->len
- 16); /* 2*MIC */
7593 skb_trim(skb
, skb
->len
- 8); /* MIC */
7599 memmove(skb
->data
+ IEEE80211_3ADDR_LEN
,
7600 skb
->data
+ IEEE80211_3ADDR_LEN
+ 4,
7601 skb
->len
- IEEE80211_3ADDR_LEN
- 4);
7602 if (fc
& IEEE80211_FCTL_MOREFRAGS
)
7603 skb_trim(skb
, skb
->len
- 8); /* 2*ICV */
7605 skb_trim(skb
, skb
->len
- 4); /* ICV */
7610 printk(KERN_ERR
"Unknow security level %d\n",
7611 priv
->ieee
->sec
.level
);
7616 static void ipw_handle_data_packet(struct ipw_priv
*priv
,
7617 struct ipw_rx_mem_buffer
*rxb
,
7618 struct ieee80211_rx_stats
*stats
)
7620 struct ipw_rx_packet
*pkt
= (struct ipw_rx_packet
*)rxb
->skb
->data
;
7622 /* We received data from the HW, so stop the watchdog */
7623 priv
->net_dev
->trans_start
= jiffies
;
7625 /* We only process data packets if the
7626 * interface is open */
7627 if (unlikely((le16_to_cpu(pkt
->u
.frame
.length
) + IPW_RX_FRAME_SIZE
) >
7628 skb_tailroom(rxb
->skb
))) {
7629 priv
->ieee
->stats
.rx_errors
++;
7630 priv
->wstats
.discard
.misc
++;
7631 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7633 } else if (unlikely(!netif_running(priv
->net_dev
))) {
7634 priv
->ieee
->stats
.rx_dropped
++;
7635 priv
->wstats
.discard
.misc
++;
7636 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7640 /* Advance skb->data to the start of the actual payload */
7641 skb_reserve(rxb
->skb
, offsetof(struct ipw_rx_packet
, u
.frame
.data
));
7643 /* Set the size of the skb to the size of the frame */
7644 skb_put(rxb
->skb
, le16_to_cpu(pkt
->u
.frame
.length
));
7646 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb
->skb
->len
);
7648 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
7649 if (!priv
->ieee
->host_decrypt
)
7650 ipw_rebuild_decrypted_skb(priv
, rxb
->skb
);
7652 if (!ieee80211_rx(priv
->ieee
, rxb
->skb
, stats
))
7653 priv
->ieee
->stats
.rx_errors
++;
7654 else { /* ieee80211_rx succeeded, so it now owns the SKB */
7656 __ipw_led_activity_on(priv
);
7660 static inline int is_network_packet(struct ipw_priv
*priv
,
7661 struct ieee80211_hdr_4addr
*header
)
7663 /* Filter incoming packets to determine if they are targetted toward
7664 * this network, discarding packets coming from ourselves */
7665 switch (priv
->ieee
->iw_mode
) {
7666 case IW_MODE_ADHOC
: /* Header: Dest. | Source | BSSID */
7667 /* packets from our adapter are dropped (echo) */
7668 if (!memcmp(header
->addr2
, priv
->net_dev
->dev_addr
, ETH_ALEN
))
7671 /* multicast packets to our IBSS go through */
7672 if (is_multicast_ether_addr(header
->addr1
))
7673 return !memcmp(header
->addr3
, priv
->bssid
, ETH_ALEN
);
7675 /* packets to our adapter go through */
7676 return !memcmp(header
->addr1
, priv
->net_dev
->dev_addr
,
7679 case IW_MODE_INFRA
: /* Header: Dest. | AP{BSSID} | Source */
7680 /* packets from our adapter are dropped (echo) */
7681 if (!memcmp(header
->addr3
, priv
->net_dev
->dev_addr
, ETH_ALEN
))
7684 /* {broad,multi}cast packets to our IBSS go through */
7685 if (is_multicast_ether_addr(header
->addr1
))
7686 return !memcmp(header
->addr2
, priv
->bssid
, ETH_ALEN
);
7688 /* packets to our adapter go through */
7689 return !memcmp(header
->addr1
, priv
->net_dev
->dev_addr
,
7696 #define IPW_PACKET_RETRY_TIME HZ
7698 static inline int is_duplicate_packet(struct ipw_priv
*priv
,
7699 struct ieee80211_hdr_4addr
*header
)
7701 u16 fc
= le16_to_cpu(header
->frame_ctl
);
7702 u16 sc
= le16_to_cpu(header
->seq_ctl
);
7703 u16 seq
= WLAN_GET_SEQ_SEQ(sc
);
7704 u16 frag
= WLAN_GET_SEQ_FRAG(sc
);
7705 u16
*last_seq
, *last_frag
;
7706 unsigned long *last_time
;
7708 switch (priv
->ieee
->iw_mode
) {
7711 struct list_head
*p
;
7712 struct ipw_ibss_seq
*entry
= NULL
;
7713 u8
*mac
= header
->addr2
;
7714 int index
= mac
[5] % IPW_IBSS_MAC_HASH_SIZE
;
7716 __list_for_each(p
, &priv
->ibss_mac_hash
[index
]) {
7718 list_entry(p
, struct ipw_ibss_seq
, list
);
7719 if (!memcmp(entry
->mac
, mac
, ETH_ALEN
))
7722 if (p
== &priv
->ibss_mac_hash
[index
]) {
7723 entry
= kmalloc(sizeof(*entry
), GFP_ATOMIC
);
7726 ("Cannot malloc new mac entry\n");
7729 memcpy(entry
->mac
, mac
, ETH_ALEN
);
7730 entry
->seq_num
= seq
;
7731 entry
->frag_num
= frag
;
7732 entry
->packet_time
= jiffies
;
7733 list_add(&entry
->list
,
7734 &priv
->ibss_mac_hash
[index
]);
7737 last_seq
= &entry
->seq_num
;
7738 last_frag
= &entry
->frag_num
;
7739 last_time
= &entry
->packet_time
;
7743 last_seq
= &priv
->last_seq_num
;
7744 last_frag
= &priv
->last_frag_num
;
7745 last_time
= &priv
->last_packet_time
;
7750 if ((*last_seq
== seq
) &&
7751 time_after(*last_time
+ IPW_PACKET_RETRY_TIME
, jiffies
)) {
7752 if (*last_frag
== frag
)
7754 if (*last_frag
+ 1 != frag
)
7755 /* out-of-order fragment */
7761 *last_time
= jiffies
;
7765 BUG_ON(!(fc
& IEEE80211_FCTL_RETRY
));
7769 static void ipw_handle_mgmt_packet(struct ipw_priv
*priv
,
7770 struct ipw_rx_mem_buffer
*rxb
,
7771 struct ieee80211_rx_stats
*stats
)
7773 struct sk_buff
*skb
= rxb
->skb
;
7774 struct ipw_rx_packet
*pkt
= (struct ipw_rx_packet
*)skb
->data
;
7775 struct ieee80211_hdr_4addr
*header
= (struct ieee80211_hdr_4addr
*)
7776 (skb
->data
+ IPW_RX_FRAME_SIZE
);
7778 ieee80211_rx_mgt(priv
->ieee
, header
, stats
);
7780 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
&&
7781 ((WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
)) ==
7782 IEEE80211_STYPE_PROBE_RESP
) ||
7783 (WLAN_FC_GET_STYPE(le16_to_cpu(header
->frame_ctl
)) ==
7784 IEEE80211_STYPE_BEACON
))) {
7785 if (!memcmp(header
->addr3
, priv
->bssid
, ETH_ALEN
))
7786 ipw_add_station(priv
, header
->addr2
);
7789 if (priv
->config
& CFG_NET_STATS
) {
7790 IPW_DEBUG_HC("sending stat packet\n");
7792 /* Set the size of the skb to the size of the full
7793 * ipw header and 802.11 frame */
7794 skb_put(skb
, le16_to_cpu(pkt
->u
.frame
.length
) +
7797 /* Advance past the ipw packet header to the 802.11 frame */
7798 skb_pull(skb
, IPW_RX_FRAME_SIZE
);
7800 /* Push the ieee80211_rx_stats before the 802.11 frame */
7801 memcpy(skb_push(skb
, sizeof(*stats
)), stats
, sizeof(*stats
));
7803 skb
->dev
= priv
->ieee
->dev
;
7805 /* Point raw at the ieee80211_stats */
7806 skb
->mac
.raw
= skb
->data
;
7808 skb
->pkt_type
= PACKET_OTHERHOST
;
7809 skb
->protocol
= __constant_htons(ETH_P_80211_STATS
);
7810 memset(skb
->cb
, 0, sizeof(rxb
->skb
->cb
));
7817 * Main entry function for recieving a packet with 80211 headers. This
7818 * should be called when ever the FW has notified us that there is a new
7819 * skb in the recieve queue.
7821 static void ipw_rx(struct ipw_priv
*priv
)
7823 struct ipw_rx_mem_buffer
*rxb
;
7824 struct ipw_rx_packet
*pkt
;
7825 struct ieee80211_hdr_4addr
*header
;
7829 r
= ipw_read32(priv
, IPW_RX_READ_INDEX
);
7830 w
= ipw_read32(priv
, IPW_RX_WRITE_INDEX
);
7831 i
= (priv
->rxq
->processed
+ 1) % RX_QUEUE_SIZE
;
7834 rxb
= priv
->rxq
->queue
[i
];
7835 #ifdef CONFIG_IPW_DEBUG
7836 if (unlikely(rxb
== NULL
)) {
7837 printk(KERN_CRIT
"Queue not allocated!\n");
7841 priv
->rxq
->queue
[i
] = NULL
;
7843 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->dma_addr
,
7845 PCI_DMA_FROMDEVICE
);
7847 pkt
= (struct ipw_rx_packet
*)rxb
->skb
->data
;
7848 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
7849 pkt
->header
.message_type
,
7850 pkt
->header
.rx_seq_num
, pkt
->header
.control_bits
);
7852 switch (pkt
->header
.message_type
) {
7853 case RX_FRAME_TYPE
: /* 802.11 frame */ {
7854 struct ieee80211_rx_stats stats
= {
7856 le16_to_cpu(pkt
->u
.frame
.rssi_dbm
) -
7859 le16_to_cpu(pkt
->u
.frame
.signal
),
7861 le16_to_cpu(pkt
->u
.frame
.noise
),
7862 .rate
= pkt
->u
.frame
.rate
,
7863 .mac_time
= jiffies
,
7865 pkt
->u
.frame
.received_channel
,
7868 control
& (1 << 0)) ?
7869 IEEE80211_24GHZ_BAND
:
7870 IEEE80211_52GHZ_BAND
,
7871 .len
= le16_to_cpu(pkt
->u
.frame
.length
),
7874 if (stats
.rssi
!= 0)
7875 stats
.mask
|= IEEE80211_STATMASK_RSSI
;
7876 if (stats
.signal
!= 0)
7877 stats
.mask
|= IEEE80211_STATMASK_SIGNAL
;
7878 if (stats
.noise
!= 0)
7879 stats
.mask
|= IEEE80211_STATMASK_NOISE
;
7880 if (stats
.rate
!= 0)
7881 stats
.mask
|= IEEE80211_STATMASK_RATE
;
7885 #ifdef CONFIG_IPW2200_MONITOR
7886 if (priv
->ieee
->iw_mode
== IW_MODE_MONITOR
) {
7887 ipw_handle_data_packet(priv
, rxb
,
7894 (struct ieee80211_hdr_4addr
*)(rxb
->skb
->
7897 /* TODO: Check Ad-Hoc dest/source and make sure
7898 * that we are actually parsing these packets
7899 * correctly -- we should probably use the
7900 * frame control of the packet and disregard
7901 * the current iw_mode */
7904 is_network_packet(priv
, header
);
7905 if (network_packet
&& priv
->assoc_network
) {
7906 priv
->assoc_network
->stats
.rssi
=
7908 average_add(&priv
->average_rssi
,
7910 priv
->last_rx_rssi
= stats
.rssi
;
7913 IPW_DEBUG_RX("Frame: len=%u\n",
7914 le16_to_cpu(pkt
->u
.frame
.length
));
7916 if (le16_to_cpu(pkt
->u
.frame
.length
) <
7917 frame_hdr_len(header
)) {
7919 ("Received packet is too small. "
7921 priv
->ieee
->stats
.rx_errors
++;
7922 priv
->wstats
.discard
.misc
++;
7926 switch (WLAN_FC_GET_TYPE
7927 (le16_to_cpu(header
->frame_ctl
))) {
7929 case IEEE80211_FTYPE_MGMT
:
7930 ipw_handle_mgmt_packet(priv
, rxb
,
7934 case IEEE80211_FTYPE_CTL
:
7937 case IEEE80211_FTYPE_DATA
:
7938 if (unlikely(!network_packet
||
7939 is_duplicate_packet(priv
,
7942 IPW_DEBUG_DROP("Dropping: "
7955 ipw_handle_data_packet(priv
, rxb
,
7963 case RX_HOST_NOTIFICATION_TYPE
:{
7965 ("Notification: subtype=%02X flags=%02X size=%d\n",
7966 pkt
->u
.notification
.subtype
,
7967 pkt
->u
.notification
.flags
,
7968 pkt
->u
.notification
.size
);
7969 ipw_rx_notification(priv
, &pkt
->u
.notification
);
7974 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
7975 pkt
->header
.message_type
);
7979 /* For now we just don't re-use anything. We can tweak this
7980 * later to try and re-use notification packets and SKBs that
7981 * fail to Rx correctly */
7982 if (rxb
->skb
!= NULL
) {
7983 dev_kfree_skb_any(rxb
->skb
);
7987 pci_unmap_single(priv
->pci_dev
, rxb
->dma_addr
,
7988 IPW_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
7989 list_add_tail(&rxb
->list
, &priv
->rxq
->rx_used
);
7991 i
= (i
+ 1) % RX_QUEUE_SIZE
;
7994 /* Backtrack one entry */
7995 priv
->rxq
->processed
= (i
? i
: RX_QUEUE_SIZE
) - 1;
7997 ipw_rx_queue_restock(priv
);
8000 #define DEFAULT_RTS_THRESHOLD 2304U
8001 #define MIN_RTS_THRESHOLD 1U
8002 #define MAX_RTS_THRESHOLD 2304U
8003 #define DEFAULT_BEACON_INTERVAL 100U
8004 #define DEFAULT_SHORT_RETRY_LIMIT 7U
8005 #define DEFAULT_LONG_RETRY_LIMIT 4U
8007 static int ipw_sw_reset(struct ipw_priv
*priv
, int init
)
8009 int band
, modulation
;
8010 int old_mode
= priv
->ieee
->iw_mode
;
8012 /* Initialize module parameter values here */
8015 /* We default to disabling the LED code as right now it causes
8016 * too many systems to lock up... */
8018 priv
->config
|= CFG_NO_LED
;
8021 priv
->config
|= CFG_ASSOCIATE
;
8023 IPW_DEBUG_INFO("Auto associate disabled.\n");
8026 priv
->config
|= CFG_ADHOC_CREATE
;
8028 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8031 priv
->status
|= STATUS_RF_KILL_SW
;
8032 IPW_DEBUG_INFO("Radio disabled.\n");
8036 priv
->config
|= CFG_STATIC_CHANNEL
;
8037 priv
->channel
= channel
;
8038 IPW_DEBUG_INFO("Bind to static channel %d\n", channel
);
8039 /* TODO: Validate that provided channel is in range */
8041 #ifdef CONFIG_IPW_QOS
8042 ipw_qos_init(priv
, qos_enable
, qos_burst_enable
,
8043 burst_duration_CCK
, burst_duration_OFDM
);
8044 #endif /* CONFIG_IPW_QOS */
8048 priv
->ieee
->iw_mode
= IW_MODE_ADHOC
;
8049 priv
->net_dev
->type
= ARPHRD_ETHER
;
8052 #ifdef CONFIG_IPW2200_MONITOR
8054 priv
->ieee
->iw_mode
= IW_MODE_MONITOR
;
8055 priv
->net_dev
->type
= ARPHRD_IEEE80211
;
8060 priv
->net_dev
->type
= ARPHRD_ETHER
;
8061 priv
->ieee
->iw_mode
= IW_MODE_INFRA
;
8066 priv
->ieee
->host_encrypt
= 0;
8067 priv
->ieee
->host_encrypt_msdu
= 0;
8068 priv
->ieee
->host_decrypt
= 0;
8070 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto
? "on" : "off");
8072 if ((priv
->pci_dev
->device
== 0x4223) ||
8073 (priv
->pci_dev
->device
== 0x4224)) {
8075 printk(KERN_INFO DRV_NAME
8076 ": Detected Intel PRO/Wireless 2915ABG Network "
8078 priv
->ieee
->abg_true
= 1;
8079 band
= IEEE80211_52GHZ_BAND
| IEEE80211_24GHZ_BAND
;
8080 modulation
= IEEE80211_OFDM_MODULATION
|
8081 IEEE80211_CCK_MODULATION
;
8082 priv
->adapter
= IPW_2915ABG
;
8083 priv
->ieee
->mode
= IEEE_A
| IEEE_G
| IEEE_B
;
8086 printk(KERN_INFO DRV_NAME
8087 ": Detected Intel PRO/Wireless 2200BG Network "
8090 priv
->ieee
->abg_true
= 0;
8091 band
= IEEE80211_24GHZ_BAND
;
8092 modulation
= IEEE80211_OFDM_MODULATION
|
8093 IEEE80211_CCK_MODULATION
;
8094 priv
->adapter
= IPW_2200BG
;
8095 priv
->ieee
->mode
= IEEE_G
| IEEE_B
;
8098 priv
->ieee
->freq_band
= band
;
8099 priv
->ieee
->modulation
= modulation
;
8101 priv
->rates_mask
= IEEE80211_DEFAULT_RATES_MASK
;
8103 priv
->disassociate_threshold
= IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT
;
8104 priv
->roaming_threshold
= IPW_MB_ROAMING_THRESHOLD_DEFAULT
;
8106 priv
->rts_threshold
= DEFAULT_RTS_THRESHOLD
;
8107 priv
->short_retry_limit
= DEFAULT_SHORT_RETRY_LIMIT
;
8108 priv
->long_retry_limit
= DEFAULT_LONG_RETRY_LIMIT
;
8110 /* If power management is turned on, default to AC mode */
8111 priv
->power_mode
= IPW_POWER_AC
;
8112 priv
->tx_power
= IPW_TX_POWER_DEFAULT
;
8114 return old_mode
== priv
->ieee
->mode
;
8118 * This file defines the Wireless Extension handlers. It does not
8119 * define any methods of hardware manipulation and relies on the
8120 * functions defined in ipw_main to provide the HW interaction.
8122 * The exception to this is the use of the ipw_get_ordinal()
8123 * function used to poll the hardware vs. making unecessary calls.
8127 static int ipw_wx_get_name(struct net_device
*dev
,
8128 struct iw_request_info
*info
,
8129 union iwreq_data
*wrqu
, char *extra
)
8131 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8133 if (priv
->status
& STATUS_RF_KILL_MASK
)
8134 strcpy(wrqu
->name
, "radio off");
8135 else if (!(priv
->status
& STATUS_ASSOCIATED
))
8136 strcpy(wrqu
->name
, "unassociated");
8138 snprintf(wrqu
->name
, IFNAMSIZ
, "IEEE 802.11%c",
8139 ipw_modes
[priv
->assoc_request
.ieee_mode
]);
8140 IPW_DEBUG_WX("Name: %s\n", wrqu
->name
);
8145 static int ipw_set_channel(struct ipw_priv
*priv
, u8 channel
)
8148 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8149 priv
->config
&= ~CFG_STATIC_CHANNEL
;
8150 IPW_DEBUG_ASSOC("Attempting to associate with new "
8152 ipw_associate(priv
);
8156 priv
->config
|= CFG_STATIC_CHANNEL
;
8158 if (priv
->channel
== channel
) {
8159 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8164 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel
);
8165 priv
->channel
= channel
;
8167 #ifdef CONFIG_IPW2200_MONITOR
8168 if (priv
->ieee
->iw_mode
== IW_MODE_MONITOR
) {
8170 if (priv
->status
& STATUS_SCANNING
) {
8171 IPW_DEBUG_SCAN("Scan abort triggered due to "
8172 "channel change.\n");
8173 ipw_abort_scan(priv
);
8176 for (i
= 1000; i
&& (priv
->status
& STATUS_SCANNING
); i
--)
8179 if (priv
->status
& STATUS_SCANNING
)
8180 IPW_DEBUG_SCAN("Still scanning...\n");
8182 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8187 #endif /* CONFIG_IPW2200_MONITOR */
8189 /* Network configuration changed -- force [re]association */
8190 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8191 if (!ipw_disassociate(priv
))
8192 ipw_associate(priv
);
8197 static int ipw_wx_set_freq(struct net_device
*dev
,
8198 struct iw_request_info
*info
,
8199 union iwreq_data
*wrqu
, char *extra
)
8201 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8202 const struct ieee80211_geo
*geo
= ieee80211_get_geo(priv
->ieee
);
8203 struct iw_freq
*fwrq
= &wrqu
->freq
;
8208 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
8210 ret
= ipw_set_channel(priv
, 0);
8214 /* if setting by freq convert to channel */
8216 channel
= ieee80211_freq_to_channel(priv
->ieee
, fwrq
->m
);
8222 if (!ieee80211_is_valid_channel(priv
->ieee
, channel
))
8225 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
&& priv
->ieee
->mode
& IEEE_A
) {
8226 i
= ieee80211_channel_to_index(priv
->ieee
, channel
);
8229 if (geo
->a
[i
].flags
& IEEE80211_CH_PASSIVE_ONLY
) {
8230 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8235 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq
->m
);
8237 ret
= ipw_set_channel(priv
, channel
);
8242 static int ipw_wx_get_freq(struct net_device
*dev
,
8243 struct iw_request_info
*info
,
8244 union iwreq_data
*wrqu
, char *extra
)
8246 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8250 /* If we are associated, trying to associate, or have a statically
8251 * configured CHANNEL then return that; otherwise return ANY */
8253 if (priv
->config
& CFG_STATIC_CHANNEL
||
8254 priv
->status
& (STATUS_ASSOCIATING
| STATUS_ASSOCIATED
))
8255 wrqu
->freq
.m
= priv
->channel
;
8260 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv
->channel
);
8264 static int ipw_wx_set_mode(struct net_device
*dev
,
8265 struct iw_request_info
*info
,
8266 union iwreq_data
*wrqu
, char *extra
)
8268 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8271 IPW_DEBUG_WX("Set MODE: %d\n", wrqu
->mode
);
8273 switch (wrqu
->mode
) {
8274 #ifdef CONFIG_IPW2200_MONITOR
8275 case IW_MODE_MONITOR
:
8281 wrqu
->mode
= IW_MODE_INFRA
;
8286 if (wrqu
->mode
== priv
->ieee
->iw_mode
)
8291 ipw_sw_reset(priv
, 0);
8293 #ifdef CONFIG_IPW2200_MONITOR
8294 if (priv
->ieee
->iw_mode
== IW_MODE_MONITOR
)
8295 priv
->net_dev
->type
= ARPHRD_ETHER
;
8297 if (wrqu
->mode
== IW_MODE_MONITOR
)
8298 priv
->net_dev
->type
= ARPHRD_IEEE80211
;
8299 #endif /* CONFIG_IPW2200_MONITOR */
8301 /* Free the existing firmware and reset the fw_loaded
8302 * flag so ipw_load() will bring in the new firmawre */
8305 priv
->ieee
->iw_mode
= wrqu
->mode
;
8307 queue_work(priv
->workqueue
, &priv
->adapter_restart
);
8312 static int ipw_wx_get_mode(struct net_device
*dev
,
8313 struct iw_request_info
*info
,
8314 union iwreq_data
*wrqu
, char *extra
)
8316 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8318 wrqu
->mode
= priv
->ieee
->iw_mode
;
8319 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu
->mode
);
8324 /* Values are in microsecond */
8325 static const s32 timeout_duration
[] = {
8333 static const s32 period_duration
[] = {
8341 static int ipw_wx_get_range(struct net_device
*dev
,
8342 struct iw_request_info
*info
,
8343 union iwreq_data
*wrqu
, char *extra
)
8345 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8346 struct iw_range
*range
= (struct iw_range
*)extra
;
8347 const struct ieee80211_geo
*geo
= ieee80211_get_geo(priv
->ieee
);
8350 wrqu
->data
.length
= sizeof(*range
);
8351 memset(range
, 0, sizeof(*range
));
8353 /* 54Mbs == ~27 Mb/s real (802.11g) */
8354 range
->throughput
= 27 * 1000 * 1000;
8356 range
->max_qual
.qual
= 100;
8357 /* TODO: Find real max RSSI and stick here */
8358 range
->max_qual
.level
= 0;
8359 range
->max_qual
.noise
= priv
->ieee
->worst_rssi
+ 0x100;
8360 range
->max_qual
.updated
= 7; /* Updated all three */
8362 range
->avg_qual
.qual
= 70;
8363 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
8364 range
->avg_qual
.level
= 0; /* FIXME to real average level */
8365 range
->avg_qual
.noise
= 0;
8366 range
->avg_qual
.updated
= 7; /* Updated all three */
8368 range
->num_bitrates
= min(priv
->rates
.num_rates
, (u8
) IW_MAX_BITRATES
);
8370 for (i
= 0; i
< range
->num_bitrates
; i
++)
8371 range
->bitrate
[i
] = (priv
->rates
.supported_rates
[i
] & 0x7F) *
8374 range
->max_rts
= DEFAULT_RTS_THRESHOLD
;
8375 range
->min_frag
= MIN_FRAG_THRESHOLD
;
8376 range
->max_frag
= MAX_FRAG_THRESHOLD
;
8378 range
->encoding_size
[0] = 5;
8379 range
->encoding_size
[1] = 13;
8380 range
->num_encoding_sizes
= 2;
8381 range
->max_encoding_tokens
= WEP_KEYS
;
8383 /* Set the Wireless Extension versions */
8384 range
->we_version_compiled
= WIRELESS_EXT
;
8385 range
->we_version_source
= 16;
8388 if (priv
->ieee
->mode
& (IEEE_B
| IEEE_G
)) {
8389 for (j
= 0; j
< geo
->bg_channels
&& i
< IW_MAX_FREQUENCIES
;
8391 range
->freq
[i
].i
= geo
->bg
[j
].channel
;
8392 range
->freq
[i
].m
= geo
->bg
[j
].freq
* 100000;
8393 range
->freq
[i
].e
= 1;
8397 if (priv
->ieee
->mode
& IEEE_A
) {
8398 for (j
= 0; j
< geo
->a_channels
&& i
< IW_MAX_FREQUENCIES
;
8400 range
->freq
[i
].i
= geo
->a
[j
].channel
;
8401 range
->freq
[i
].m
= geo
->a
[j
].freq
* 100000;
8402 range
->freq
[i
].e
= 1;
8406 range
->num_channels
= i
;
8407 range
->num_frequency
= i
;
8410 IPW_DEBUG_WX("GET Range\n");
8414 static int ipw_wx_set_wap(struct net_device
*dev
,
8415 struct iw_request_info
*info
,
8416 union iwreq_data
*wrqu
, char *extra
)
8418 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8420 static const unsigned char any
[] = {
8421 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8423 static const unsigned char off
[] = {
8424 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8427 if (wrqu
->ap_addr
.sa_family
!= ARPHRD_ETHER
)
8430 if (!memcmp(any
, wrqu
->ap_addr
.sa_data
, ETH_ALEN
) ||
8431 !memcmp(off
, wrqu
->ap_addr
.sa_data
, ETH_ALEN
)) {
8432 /* we disable mandatory BSSID association */
8433 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8434 priv
->config
&= ~CFG_STATIC_BSSID
;
8435 IPW_DEBUG_ASSOC("Attempting to associate with new "
8437 ipw_associate(priv
);
8442 priv
->config
|= CFG_STATIC_BSSID
;
8443 if (!memcmp(priv
->bssid
, wrqu
->ap_addr
.sa_data
, ETH_ALEN
)) {
8444 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
8449 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT
"\n",
8450 MAC_ARG(wrqu
->ap_addr
.sa_data
));
8452 memcpy(priv
->bssid
, wrqu
->ap_addr
.sa_data
, ETH_ALEN
);
8454 /* Network configuration changed -- force [re]association */
8455 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8456 if (!ipw_disassociate(priv
))
8457 ipw_associate(priv
);
8463 static int ipw_wx_get_wap(struct net_device
*dev
,
8464 struct iw_request_info
*info
,
8465 union iwreq_data
*wrqu
, char *extra
)
8467 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8468 /* If we are associated, trying to associate, or have a statically
8469 * configured BSSID then return that; otherwise return ANY */
8471 if (priv
->config
& CFG_STATIC_BSSID
||
8472 priv
->status
& (STATUS_ASSOCIATED
| STATUS_ASSOCIATING
)) {
8473 wrqu
->ap_addr
.sa_family
= ARPHRD_ETHER
;
8474 memcpy(wrqu
->ap_addr
.sa_data
, priv
->bssid
, ETH_ALEN
);
8476 memset(wrqu
->ap_addr
.sa_data
, 0, ETH_ALEN
);
8478 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT
"\n",
8479 MAC_ARG(wrqu
->ap_addr
.sa_data
));
8484 static int ipw_wx_set_essid(struct net_device
*dev
,
8485 struct iw_request_info
*info
,
8486 union iwreq_data
*wrqu
, char *extra
)
8488 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8489 char *essid
= ""; /* ANY */
8492 if (wrqu
->essid
.flags
&& wrqu
->essid
.length
) {
8493 length
= wrqu
->essid
.length
- 1;
8497 IPW_DEBUG_WX("Setting ESSID to ANY\n");
8498 if ((priv
->config
& CFG_STATIC_ESSID
) &&
8499 !(priv
->status
& (STATUS_ASSOCIATED
|
8500 STATUS_ASSOCIATING
))) {
8501 IPW_DEBUG_ASSOC("Attempting to associate with new "
8503 priv
->config
&= ~CFG_STATIC_ESSID
;
8504 ipw_associate(priv
);
8510 length
= min(length
, IW_ESSID_MAX_SIZE
);
8512 priv
->config
|= CFG_STATIC_ESSID
;
8514 if (priv
->essid_len
== length
&& !memcmp(priv
->essid
, extra
, length
)) {
8515 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
8520 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid
, length
),
8523 priv
->essid_len
= length
;
8524 memcpy(priv
->essid
, essid
, priv
->essid_len
);
8526 /* Network configuration changed -- force [re]association */
8527 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8528 if (!ipw_disassociate(priv
))
8529 ipw_associate(priv
);
8535 static int ipw_wx_get_essid(struct net_device
*dev
,
8536 struct iw_request_info
*info
,
8537 union iwreq_data
*wrqu
, char *extra
)
8539 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8541 /* If we are associated, trying to associate, or have a statically
8542 * configured ESSID then return that; otherwise return ANY */
8544 if (priv
->config
& CFG_STATIC_ESSID
||
8545 priv
->status
& (STATUS_ASSOCIATED
| STATUS_ASSOCIATING
)) {
8546 IPW_DEBUG_WX("Getting essid: '%s'\n",
8547 escape_essid(priv
->essid
, priv
->essid_len
));
8548 memcpy(extra
, priv
->essid
, priv
->essid_len
);
8549 wrqu
->essid
.length
= priv
->essid_len
;
8550 wrqu
->essid
.flags
= 1; /* active */
8552 IPW_DEBUG_WX("Getting essid: ANY\n");
8553 wrqu
->essid
.length
= 0;
8554 wrqu
->essid
.flags
= 0; /* active */
8560 static int ipw_wx_set_nick(struct net_device
*dev
,
8561 struct iw_request_info
*info
,
8562 union iwreq_data
*wrqu
, char *extra
)
8564 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8566 IPW_DEBUG_WX("Setting nick to '%s'\n", extra
);
8567 if (wrqu
->data
.length
> IW_ESSID_MAX_SIZE
)
8570 wrqu
->data
.length
= min((size_t) wrqu
->data
.length
, sizeof(priv
->nick
));
8571 memset(priv
->nick
, 0, sizeof(priv
->nick
));
8572 memcpy(priv
->nick
, extra
, wrqu
->data
.length
);
8573 IPW_DEBUG_TRACE("<<\n");
8579 static int ipw_wx_get_nick(struct net_device
*dev
,
8580 struct iw_request_info
*info
,
8581 union iwreq_data
*wrqu
, char *extra
)
8583 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8584 IPW_DEBUG_WX("Getting nick\n");
8586 wrqu
->data
.length
= strlen(priv
->nick
) + 1;
8587 memcpy(extra
, priv
->nick
, wrqu
->data
.length
);
8588 wrqu
->data
.flags
= 1; /* active */
8593 static int ipw_wx_set_rate(struct net_device
*dev
,
8594 struct iw_request_info
*info
,
8595 union iwreq_data
*wrqu
, char *extra
)
8597 /* TODO: We should use semaphores or locks for access to priv */
8598 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8599 u32 target_rate
= wrqu
->bitrate
.value
;
8602 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8603 /* value = X, fixed = 1 means only rate X */
8604 /* value = X, fixed = 0 means all rates lower equal X */
8606 if (target_rate
== -1) {
8608 mask
= IEEE80211_DEFAULT_RATES_MASK
;
8609 /* Now we should reassociate */
8614 fixed
= wrqu
->bitrate
.fixed
;
8616 if (target_rate
== 1000000 || !fixed
)
8617 mask
|= IEEE80211_CCK_RATE_1MB_MASK
;
8618 if (target_rate
== 1000000)
8621 if (target_rate
== 2000000 || !fixed
)
8622 mask
|= IEEE80211_CCK_RATE_2MB_MASK
;
8623 if (target_rate
== 2000000)
8626 if (target_rate
== 5500000 || !fixed
)
8627 mask
|= IEEE80211_CCK_RATE_5MB_MASK
;
8628 if (target_rate
== 5500000)
8631 if (target_rate
== 6000000 || !fixed
)
8632 mask
|= IEEE80211_OFDM_RATE_6MB_MASK
;
8633 if (target_rate
== 6000000)
8636 if (target_rate
== 9000000 || !fixed
)
8637 mask
|= IEEE80211_OFDM_RATE_9MB_MASK
;
8638 if (target_rate
== 9000000)
8641 if (target_rate
== 11000000 || !fixed
)
8642 mask
|= IEEE80211_CCK_RATE_11MB_MASK
;
8643 if (target_rate
== 11000000)
8646 if (target_rate
== 12000000 || !fixed
)
8647 mask
|= IEEE80211_OFDM_RATE_12MB_MASK
;
8648 if (target_rate
== 12000000)
8651 if (target_rate
== 18000000 || !fixed
)
8652 mask
|= IEEE80211_OFDM_RATE_18MB_MASK
;
8653 if (target_rate
== 18000000)
8656 if (target_rate
== 24000000 || !fixed
)
8657 mask
|= IEEE80211_OFDM_RATE_24MB_MASK
;
8658 if (target_rate
== 24000000)
8661 if (target_rate
== 36000000 || !fixed
)
8662 mask
|= IEEE80211_OFDM_RATE_36MB_MASK
;
8663 if (target_rate
== 36000000)
8666 if (target_rate
== 48000000 || !fixed
)
8667 mask
|= IEEE80211_OFDM_RATE_48MB_MASK
;
8668 if (target_rate
== 48000000)
8671 if (target_rate
== 54000000 || !fixed
)
8672 mask
|= IEEE80211_OFDM_RATE_54MB_MASK
;
8673 if (target_rate
== 54000000)
8676 IPW_DEBUG_WX("invalid rate specified, returning error\n");
8680 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
8681 mask
, fixed
? "fixed" : "sub-rates");
8683 if (mask
== IEEE80211_DEFAULT_RATES_MASK
) {
8684 priv
->config
&= ~CFG_FIXED_RATE
;
8685 ipw_set_fixed_rate(priv
, priv
->ieee
->mode
);
8687 priv
->config
|= CFG_FIXED_RATE
;
8689 if (priv
->rates_mask
== mask
) {
8690 IPW_DEBUG_WX("Mask set to current mask.\n");
8695 priv
->rates_mask
= mask
;
8697 /* Network configuration changed -- force [re]association */
8698 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
8699 if (!ipw_disassociate(priv
))
8700 ipw_associate(priv
);
8706 static int ipw_wx_get_rate(struct net_device
*dev
,
8707 struct iw_request_info
*info
,
8708 union iwreq_data
*wrqu
, char *extra
)
8710 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8712 wrqu
->bitrate
.value
= priv
->last_rate
;
8714 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu
->bitrate
.value
);
8718 static int ipw_wx_set_rts(struct net_device
*dev
,
8719 struct iw_request_info
*info
,
8720 union iwreq_data
*wrqu
, char *extra
)
8722 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8724 if (wrqu
->rts
.disabled
)
8725 priv
->rts_threshold
= DEFAULT_RTS_THRESHOLD
;
8727 if (wrqu
->rts
.value
< MIN_RTS_THRESHOLD
||
8728 wrqu
->rts
.value
> MAX_RTS_THRESHOLD
) {
8732 priv
->rts_threshold
= wrqu
->rts
.value
;
8735 ipw_send_rts_threshold(priv
, priv
->rts_threshold
);
8737 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv
->rts_threshold
);
8741 static int ipw_wx_get_rts(struct net_device
*dev
,
8742 struct iw_request_info
*info
,
8743 union iwreq_data
*wrqu
, char *extra
)
8745 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8747 wrqu
->rts
.value
= priv
->rts_threshold
;
8748 wrqu
->rts
.fixed
= 0; /* no auto select */
8749 wrqu
->rts
.disabled
= (wrqu
->rts
.value
== DEFAULT_RTS_THRESHOLD
);
8751 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu
->rts
.value
);
8755 static int ipw_wx_set_txpow(struct net_device
*dev
,
8756 struct iw_request_info
*info
,
8757 union iwreq_data
*wrqu
, char *extra
)
8759 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8760 struct ipw_tx_power tx_power
;
8764 if (ipw_radio_kill_sw(priv
, wrqu
->power
.disabled
)) {
8766 return -EINPROGRESS
;
8769 if (!wrqu
->power
.fixed
)
8770 wrqu
->power
.value
= IPW_TX_POWER_DEFAULT
;
8772 if (wrqu
->power
.flags
!= IW_TXPOW_DBM
) {
8777 if ((wrqu
->power
.value
> IPW_TX_POWER_MAX
) ||
8778 (wrqu
->power
.value
< IPW_TX_POWER_MIN
)) {
8783 priv
->tx_power
= wrqu
->power
.value
;
8785 memset(&tx_power
, 0, sizeof(tx_power
));
8787 /* configure device for 'G' band */
8788 tx_power
.ieee_mode
= IPW_G_MODE
;
8789 tx_power
.num_channels
= 11;
8790 for (i
= 0; i
< 11; i
++) {
8791 tx_power
.channels_tx_power
[i
].channel_number
= i
+ 1;
8792 tx_power
.channels_tx_power
[i
].tx_power
= priv
->tx_power
;
8794 if (ipw_send_tx_power(priv
, &tx_power
))
8797 /* configure device to also handle 'B' band */
8798 tx_power
.ieee_mode
= IPW_B_MODE
;
8799 if (ipw_send_tx_power(priv
, &tx_power
))
8810 static int ipw_wx_get_txpow(struct net_device
*dev
,
8811 struct iw_request_info
*info
,
8812 union iwreq_data
*wrqu
, char *extra
)
8814 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8816 wrqu
->power
.value
= priv
->tx_power
;
8817 wrqu
->power
.fixed
= 1;
8818 wrqu
->power
.flags
= IW_TXPOW_DBM
;
8819 wrqu
->power
.disabled
= (priv
->status
& STATUS_RF_KILL_MASK
) ? 1 : 0;
8822 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
8823 wrqu
->power
.disabled
? "ON" : "OFF", wrqu
->power
.value
);
8828 static int ipw_wx_set_frag(struct net_device
*dev
,
8829 struct iw_request_info
*info
,
8830 union iwreq_data
*wrqu
, char *extra
)
8832 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8834 if (wrqu
->frag
.disabled
)
8835 priv
->ieee
->fts
= DEFAULT_FTS
;
8837 if (wrqu
->frag
.value
< MIN_FRAG_THRESHOLD
||
8838 wrqu
->frag
.value
> MAX_FRAG_THRESHOLD
) {
8843 priv
->ieee
->fts
= wrqu
->frag
.value
& ~0x1;
8846 ipw_send_frag_threshold(priv
, wrqu
->frag
.value
);
8848 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu
->frag
.value
);
8852 static int ipw_wx_get_frag(struct net_device
*dev
,
8853 struct iw_request_info
*info
,
8854 union iwreq_data
*wrqu
, char *extra
)
8856 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8858 wrqu
->frag
.value
= priv
->ieee
->fts
;
8859 wrqu
->frag
.fixed
= 0; /* no auto select */
8860 wrqu
->frag
.disabled
= (wrqu
->frag
.value
== DEFAULT_FTS
);
8862 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu
->frag
.value
);
8867 static int ipw_wx_set_retry(struct net_device
*dev
,
8868 struct iw_request_info
*info
,
8869 union iwreq_data
*wrqu
, char *extra
)
8871 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8873 if (wrqu
->retry
.flags
& IW_RETRY_LIFETIME
|| wrqu
->retry
.disabled
)
8876 if (!(wrqu
->retry
.flags
& IW_RETRY_LIMIT
))
8879 if (wrqu
->retry
.value
< 0 || wrqu
->retry
.value
> 255)
8883 if (wrqu
->retry
.flags
& IW_RETRY_MIN
)
8884 priv
->short_retry_limit
= (u8
) wrqu
->retry
.value
;
8885 else if (wrqu
->retry
.flags
& IW_RETRY_MAX
)
8886 priv
->long_retry_limit
= (u8
) wrqu
->retry
.value
;
8888 priv
->short_retry_limit
= (u8
) wrqu
->retry
.value
;
8889 priv
->long_retry_limit
= (u8
) wrqu
->retry
.value
;
8892 ipw_send_retry_limit(priv
, priv
->short_retry_limit
,
8893 priv
->long_retry_limit
);
8895 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
8896 priv
->short_retry_limit
, priv
->long_retry_limit
);
8900 static int ipw_wx_get_retry(struct net_device
*dev
,
8901 struct iw_request_info
*info
,
8902 union iwreq_data
*wrqu
, char *extra
)
8904 struct ipw_priv
*priv
= ieee80211_priv(dev
);
8907 wrqu
->retry
.disabled
= 0;
8909 if ((wrqu
->retry
.flags
& IW_RETRY_TYPE
) == IW_RETRY_LIFETIME
) {
8914 if (wrqu
->retry
.flags
& IW_RETRY_MAX
) {
8915 wrqu
->retry
.flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
8916 wrqu
->retry
.value
= priv
->long_retry_limit
;
8917 } else if (wrqu
->retry
.flags
& IW_RETRY_MIN
) {
8918 wrqu
->retry
.flags
= IW_RETRY_LIMIT
| IW_RETRY_MIN
;
8919 wrqu
->retry
.value
= priv
->short_retry_limit
;
8921 wrqu
->retry
.flags
= IW_RETRY_LIMIT
;
8922 wrqu
->retry
.value
= priv
->short_retry_limit
;
8926 IPW_DEBUG_WX("GET retry -> %d \n", wrqu
->retry
.value
);
8931 #if WIRELESS_EXT > 17
8932 static int ipw_request_direct_scan(struct ipw_priv
*priv
, char *essid
,
8935 struct ipw_scan_request_ext scan
;
8936 int err
= 0, scan_type
;
8940 if (priv
->status
& STATUS_RF_KILL_MASK
) {
8941 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
8942 priv
->status
|= STATUS_SCAN_PENDING
;
8946 IPW_DEBUG_HC("starting request direct scan!\n");
8948 if (priv
->status
& (STATUS_SCANNING
| STATUS_SCAN_ABORTING
)) {
8949 err
= wait_event_interruptible(priv
->wait_state
,
8951 status
& (STATUS_SCANNING
|
8952 STATUS_SCAN_ABORTING
)));
8954 IPW_DEBUG_HC("aborting direct scan");
8958 memset(&scan
, 0, sizeof(scan
));
8960 if (priv
->config
& CFG_SPEED_SCAN
)
8961 scan
.dwell_time
[IPW_SCAN_ACTIVE_BROADCAST_SCAN
] =
8964 scan
.dwell_time
[IPW_SCAN_ACTIVE_BROADCAST_SCAN
] =
8967 scan
.dwell_time
[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN
] =
8969 scan
.dwell_time
[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
] = cpu_to_le16(20);
8970 scan
.dwell_time
[IPW_SCAN_ACTIVE_DIRECT_SCAN
] = cpu_to_le16(20);
8972 scan
.full_scan_index
= cpu_to_le32(ieee80211_get_scans(priv
->ieee
));
8974 err
= ipw_send_ssid(priv
, essid
, essid_len
);
8976 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
8979 scan_type
= IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN
;
8981 ipw_add_scan_channels(priv
, &scan
, scan_type
);
8983 err
= ipw_send_scan_request_ext(priv
, &scan
);
8985 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err
);
8989 priv
->status
|= STATUS_SCANNING
;
8995 #endif /* WIRELESS_EXT > 17 */
8997 static int ipw_wx_set_scan(struct net_device
*dev
,
8998 struct iw_request_info
*info
,
8999 union iwreq_data
*wrqu
, char *extra
)
9001 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9002 #if WIRELESS_EXT > 17
9003 struct iw_scan_req
*req
= NULL
;
9004 if (wrqu
->data
.length
9005 && wrqu
->data
.length
== sizeof(struct iw_scan_req
)) {
9006 req
= (struct iw_scan_req
*)extra
;
9007 if (wrqu
->data
.flags
& IW_SCAN_THIS_ESSID
) {
9008 ipw_request_direct_scan(priv
, req
->essid
,
9014 IPW_DEBUG_WX("Start scan\n");
9016 queue_work(priv
->workqueue
, &priv
->request_scan
);
9021 static int ipw_wx_get_scan(struct net_device
*dev
,
9022 struct iw_request_info
*info
,
9023 union iwreq_data
*wrqu
, char *extra
)
9025 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9026 return ieee80211_wx_get_scan(priv
->ieee
, info
, wrqu
, extra
);
9029 static int ipw_wx_set_encode(struct net_device
*dev
,
9030 struct iw_request_info
*info
,
9031 union iwreq_data
*wrqu
, char *key
)
9033 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9037 ret
= ieee80211_wx_set_encode(priv
->ieee
, info
, wrqu
, key
);
9043 static int ipw_wx_get_encode(struct net_device
*dev
,
9044 struct iw_request_info
*info
,
9045 union iwreq_data
*wrqu
, char *key
)
9047 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9048 return ieee80211_wx_get_encode(priv
->ieee
, info
, wrqu
, key
);
9051 static int ipw_wx_set_power(struct net_device
*dev
,
9052 struct iw_request_info
*info
,
9053 union iwreq_data
*wrqu
, char *extra
)
9055 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9058 if (wrqu
->power
.disabled
) {
9059 priv
->power_mode
= IPW_POWER_LEVEL(priv
->power_mode
);
9060 err
= ipw_send_power_mode(priv
, IPW_POWER_MODE_CAM
);
9062 IPW_DEBUG_WX("failed setting power mode.\n");
9066 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
9071 switch (wrqu
->power
.flags
& IW_POWER_MODE
) {
9072 case IW_POWER_ON
: /* If not specified */
9073 case IW_POWER_MODE
: /* If set all mask */
9074 case IW_POWER_ALL_R
: /* If explicitely state all */
9076 default: /* Otherwise we don't support it */
9077 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9083 /* If the user hasn't specified a power management mode yet, default
9085 if (IPW_POWER_LEVEL(priv
->power_mode
) == IPW_POWER_AC
)
9086 priv
->power_mode
= IPW_POWER_ENABLED
| IPW_POWER_BATTERY
;
9088 priv
->power_mode
= IPW_POWER_ENABLED
| priv
->power_mode
;
9089 err
= ipw_send_power_mode(priv
, IPW_POWER_LEVEL(priv
->power_mode
));
9091 IPW_DEBUG_WX("failed setting power mode.\n");
9096 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv
->power_mode
);
9101 static int ipw_wx_get_power(struct net_device
*dev
,
9102 struct iw_request_info
*info
,
9103 union iwreq_data
*wrqu
, char *extra
)
9105 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9107 if (!(priv
->power_mode
& IPW_POWER_ENABLED
))
9108 wrqu
->power
.disabled
= 1;
9110 wrqu
->power
.disabled
= 0;
9113 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv
->power_mode
);
9118 static int ipw_wx_set_powermode(struct net_device
*dev
,
9119 struct iw_request_info
*info
,
9120 union iwreq_data
*wrqu
, char *extra
)
9122 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9123 int mode
= *(int *)extra
;
9126 if ((mode
< 1) || (mode
> IPW_POWER_LIMIT
)) {
9127 mode
= IPW_POWER_AC
;
9128 priv
->power_mode
= mode
;
9130 priv
->power_mode
= IPW_POWER_ENABLED
| mode
;
9133 if (priv
->power_mode
!= mode
) {
9134 err
= ipw_send_power_mode(priv
, mode
);
9137 IPW_DEBUG_WX("failed setting power mode.\n");
9146 #define MAX_WX_STRING 80
9147 static int ipw_wx_get_powermode(struct net_device
*dev
,
9148 struct iw_request_info
*info
,
9149 union iwreq_data
*wrqu
, char *extra
)
9151 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9152 int level
= IPW_POWER_LEVEL(priv
->power_mode
);
9155 p
+= snprintf(p
, MAX_WX_STRING
, "Power save level: %d ", level
);
9159 p
+= snprintf(p
, MAX_WX_STRING
- (p
- extra
), "(AC)");
9161 case IPW_POWER_BATTERY
:
9162 p
+= snprintf(p
, MAX_WX_STRING
- (p
- extra
), "(BATTERY)");
9165 p
+= snprintf(p
, MAX_WX_STRING
- (p
- extra
),
9166 "(Timeout %dms, Period %dms)",
9167 timeout_duration
[level
- 1] / 1000,
9168 period_duration
[level
- 1] / 1000);
9171 if (!(priv
->power_mode
& IPW_POWER_ENABLED
))
9172 p
+= snprintf(p
, MAX_WX_STRING
- (p
- extra
), " OFF");
9174 wrqu
->data
.length
= p
- extra
+ 1;
9179 static int ipw_wx_set_wireless_mode(struct net_device
*dev
,
9180 struct iw_request_info
*info
,
9181 union iwreq_data
*wrqu
, char *extra
)
9183 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9184 int mode
= *(int *)extra
;
9185 u8 band
= 0, modulation
= 0;
9187 if (mode
== 0 || mode
& ~IEEE_MODE_MASK
) {
9188 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode
);
9192 if (priv
->adapter
== IPW_2915ABG
) {
9193 priv
->ieee
->abg_true
= 1;
9194 if (mode
& IEEE_A
) {
9195 band
|= IEEE80211_52GHZ_BAND
;
9196 modulation
|= IEEE80211_OFDM_MODULATION
;
9198 priv
->ieee
->abg_true
= 0;
9200 if (mode
& IEEE_A
) {
9201 IPW_WARNING("Attempt to set 2200BG into "
9207 priv
->ieee
->abg_true
= 0;
9210 if (mode
& IEEE_B
) {
9211 band
|= IEEE80211_24GHZ_BAND
;
9212 modulation
|= IEEE80211_CCK_MODULATION
;
9214 priv
->ieee
->abg_true
= 0;
9216 if (mode
& IEEE_G
) {
9217 band
|= IEEE80211_24GHZ_BAND
;
9218 modulation
|= IEEE80211_OFDM_MODULATION
;
9220 priv
->ieee
->abg_true
= 0;
9222 priv
->ieee
->mode
= mode
;
9223 priv
->ieee
->freq_band
= band
;
9224 priv
->ieee
->modulation
= modulation
;
9225 init_supported_rates(priv
, &priv
->rates
);
9227 /* Network configuration changed -- force [re]association */
9228 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9229 if (!ipw_disassociate(priv
)) {
9230 ipw_send_supported_rates(priv
, &priv
->rates
);
9231 ipw_associate(priv
);
9234 /* Update the band LEDs */
9235 ipw_led_band_on(priv
);
9237 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
9238 mode
& IEEE_A
? 'a' : '.',
9239 mode
& IEEE_B
? 'b' : '.', mode
& IEEE_G
? 'g' : '.');
9244 static int ipw_wx_get_wireless_mode(struct net_device
*dev
,
9245 struct iw_request_info
*info
,
9246 union iwreq_data
*wrqu
, char *extra
)
9248 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9250 switch (priv
->ieee
->mode
) {
9252 strncpy(extra
, "802.11a (1)", MAX_WX_STRING
);
9255 strncpy(extra
, "802.11b (2)", MAX_WX_STRING
);
9257 case IEEE_A
| IEEE_B
:
9258 strncpy(extra
, "802.11ab (3)", MAX_WX_STRING
);
9261 strncpy(extra
, "802.11g (4)", MAX_WX_STRING
);
9263 case IEEE_A
| IEEE_G
:
9264 strncpy(extra
, "802.11ag (5)", MAX_WX_STRING
);
9266 case IEEE_B
| IEEE_G
:
9267 strncpy(extra
, "802.11bg (6)", MAX_WX_STRING
);
9269 case IEEE_A
| IEEE_B
| IEEE_G
:
9270 strncpy(extra
, "802.11abg (7)", MAX_WX_STRING
);
9273 strncpy(extra
, "unknown", MAX_WX_STRING
);
9277 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra
);
9279 wrqu
->data
.length
= strlen(extra
) + 1;
9285 static int ipw_wx_set_preamble(struct net_device
*dev
,
9286 struct iw_request_info
*info
,
9287 union iwreq_data
*wrqu
, char *extra
)
9289 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9290 int mode
= *(int *)extra
;
9292 /* Switching from SHORT -> LONG requires a disassociation */
9294 if (!(priv
->config
& CFG_PREAMBLE_LONG
)) {
9295 priv
->config
|= CFG_PREAMBLE_LONG
;
9297 /* Network configuration changed -- force [re]association */
9299 ("[re]association triggered due to preamble change.\n");
9300 if (!ipw_disassociate(priv
))
9301 ipw_associate(priv
);
9307 priv
->config
&= ~CFG_PREAMBLE_LONG
;
9318 static int ipw_wx_get_preamble(struct net_device
*dev
,
9319 struct iw_request_info
*info
,
9320 union iwreq_data
*wrqu
, char *extra
)
9322 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9324 if (priv
->config
& CFG_PREAMBLE_LONG
)
9325 snprintf(wrqu
->name
, IFNAMSIZ
, "long (1)");
9327 snprintf(wrqu
->name
, IFNAMSIZ
, "auto (0)");
9332 #ifdef CONFIG_IPW2200_MONITOR
9333 static int ipw_wx_set_monitor(struct net_device
*dev
,
9334 struct iw_request_info
*info
,
9335 union iwreq_data
*wrqu
, char *extra
)
9337 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9338 int *parms
= (int *)extra
;
9339 int enable
= (parms
[0] > 0);
9341 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable
, parms
[1]);
9343 if (priv
->ieee
->iw_mode
!= IW_MODE_MONITOR
) {
9344 priv
->net_dev
->type
= ARPHRD_IEEE80211
;
9345 queue_work(priv
->workqueue
, &priv
->adapter_restart
);
9348 ipw_set_channel(priv
, parms
[1]);
9350 if (priv
->ieee
->iw_mode
!= IW_MODE_MONITOR
) {
9354 priv
->net_dev
->type
= ARPHRD_ETHER
;
9355 queue_work(priv
->workqueue
, &priv
->adapter_restart
);
9361 #endif // CONFIG_IPW2200_MONITOR
9363 static int ipw_wx_reset(struct net_device
*dev
,
9364 struct iw_request_info
*info
,
9365 union iwreq_data
*wrqu
, char *extra
)
9367 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9368 IPW_DEBUG_WX("RESET\n");
9369 queue_work(priv
->workqueue
, &priv
->adapter_restart
);
9373 static int ipw_wx_sw_reset(struct net_device
*dev
,
9374 struct iw_request_info
*info
,
9375 union iwreq_data
*wrqu
, char *extra
)
9377 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9378 union iwreq_data wrqu_sec
= {
9380 .flags
= IW_ENCODE_DISABLED
,
9385 IPW_DEBUG_WX("SW_RESET\n");
9389 ret
= ipw_sw_reset(priv
, 0);
9392 ipw_adapter_restart(priv
);
9395 /* The SW reset bit might have been toggled on by the 'disable'
9396 * module parameter, so take appropriate action */
9397 ipw_radio_kill_sw(priv
, priv
->status
& STATUS_RF_KILL_SW
);
9400 ieee80211_wx_set_encode(priv
->ieee
, info
, &wrqu_sec
, NULL
);
9403 if (!(priv
->status
& STATUS_RF_KILL_MASK
)) {
9404 /* Configuration likely changed -- force [re]association */
9405 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9407 if (!ipw_disassociate(priv
))
9408 ipw_associate(priv
);
9416 /* Rebase the WE IOCTLs to zero for the handler array */
9417 #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
9418 static iw_handler ipw_wx_handlers
[] = {
9419 IW_IOCTL(SIOCGIWNAME
) = ipw_wx_get_name
,
9420 IW_IOCTL(SIOCSIWFREQ
) = ipw_wx_set_freq
,
9421 IW_IOCTL(SIOCGIWFREQ
) = ipw_wx_get_freq
,
9422 IW_IOCTL(SIOCSIWMODE
) = ipw_wx_set_mode
,
9423 IW_IOCTL(SIOCGIWMODE
) = ipw_wx_get_mode
,
9424 IW_IOCTL(SIOCGIWRANGE
) = ipw_wx_get_range
,
9425 IW_IOCTL(SIOCSIWAP
) = ipw_wx_set_wap
,
9426 IW_IOCTL(SIOCGIWAP
) = ipw_wx_get_wap
,
9427 IW_IOCTL(SIOCSIWSCAN
) = ipw_wx_set_scan
,
9428 IW_IOCTL(SIOCGIWSCAN
) = ipw_wx_get_scan
,
9429 IW_IOCTL(SIOCSIWESSID
) = ipw_wx_set_essid
,
9430 IW_IOCTL(SIOCGIWESSID
) = ipw_wx_get_essid
,
9431 IW_IOCTL(SIOCSIWNICKN
) = ipw_wx_set_nick
,
9432 IW_IOCTL(SIOCGIWNICKN
) = ipw_wx_get_nick
,
9433 IW_IOCTL(SIOCSIWRATE
) = ipw_wx_set_rate
,
9434 IW_IOCTL(SIOCGIWRATE
) = ipw_wx_get_rate
,
9435 IW_IOCTL(SIOCSIWRTS
) = ipw_wx_set_rts
,
9436 IW_IOCTL(SIOCGIWRTS
) = ipw_wx_get_rts
,
9437 IW_IOCTL(SIOCSIWFRAG
) = ipw_wx_set_frag
,
9438 IW_IOCTL(SIOCGIWFRAG
) = ipw_wx_get_frag
,
9439 IW_IOCTL(SIOCSIWTXPOW
) = ipw_wx_set_txpow
,
9440 IW_IOCTL(SIOCGIWTXPOW
) = ipw_wx_get_txpow
,
9441 IW_IOCTL(SIOCSIWRETRY
) = ipw_wx_set_retry
,
9442 IW_IOCTL(SIOCGIWRETRY
) = ipw_wx_get_retry
,
9443 IW_IOCTL(SIOCSIWENCODE
) = ipw_wx_set_encode
,
9444 IW_IOCTL(SIOCGIWENCODE
) = ipw_wx_get_encode
,
9445 IW_IOCTL(SIOCSIWPOWER
) = ipw_wx_set_power
,
9446 IW_IOCTL(SIOCGIWPOWER
) = ipw_wx_get_power
,
9447 IW_IOCTL(SIOCSIWSPY
) = iw_handler_set_spy
,
9448 IW_IOCTL(SIOCGIWSPY
) = iw_handler_get_spy
,
9449 IW_IOCTL(SIOCSIWTHRSPY
) = iw_handler_set_thrspy
,
9450 IW_IOCTL(SIOCGIWTHRSPY
) = iw_handler_get_thrspy
,
9451 #if WIRELESS_EXT > 17
9452 IW_IOCTL(SIOCSIWGENIE
) = ipw_wx_set_genie
,
9453 IW_IOCTL(SIOCGIWGENIE
) = ipw_wx_get_genie
,
9454 IW_IOCTL(SIOCSIWMLME
) = ipw_wx_set_mlme
,
9455 IW_IOCTL(SIOCSIWAUTH
) = ipw_wx_set_auth
,
9456 IW_IOCTL(SIOCGIWAUTH
) = ipw_wx_get_auth
,
9457 IW_IOCTL(SIOCSIWENCODEEXT
) = ipw_wx_set_encodeext
,
9458 IW_IOCTL(SIOCGIWENCODEEXT
) = ipw_wx_get_encodeext
,
9463 IPW_PRIV_SET_POWER
= SIOCIWFIRSTPRIV
,
9467 IPW_PRIV_SET_PREAMBLE
,
9468 IPW_PRIV_GET_PREAMBLE
,
9471 #ifdef CONFIG_IPW2200_MONITOR
9472 IPW_PRIV_SET_MONITOR
,
9476 static struct iw_priv_args ipw_priv_args
[] = {
9478 .cmd
= IPW_PRIV_SET_POWER
,
9479 .set_args
= IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
9480 .name
= "set_power"},
9482 .cmd
= IPW_PRIV_GET_POWER
,
9483 .get_args
= IW_PRIV_TYPE_CHAR
| IW_PRIV_SIZE_FIXED
| MAX_WX_STRING
,
9484 .name
= "get_power"},
9486 .cmd
= IPW_PRIV_SET_MODE
,
9487 .set_args
= IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
9488 .name
= "set_mode"},
9490 .cmd
= IPW_PRIV_GET_MODE
,
9491 .get_args
= IW_PRIV_TYPE_CHAR
| IW_PRIV_SIZE_FIXED
| MAX_WX_STRING
,
9492 .name
= "get_mode"},
9494 .cmd
= IPW_PRIV_SET_PREAMBLE
,
9495 .set_args
= IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
9496 .name
= "set_preamble"},
9498 .cmd
= IPW_PRIV_GET_PREAMBLE
,
9499 .get_args
= IW_PRIV_TYPE_CHAR
| IW_PRIV_SIZE_FIXED
| IFNAMSIZ
,
9500 .name
= "get_preamble"},
9503 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 0, 0, "reset"},
9506 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 0, 0, "sw_reset"},
9507 #ifdef CONFIG_IPW2200_MONITOR
9509 IPW_PRIV_SET_MONITOR
,
9510 IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 2, 0, "monitor"},
9511 #endif /* CONFIG_IPW2200_MONITOR */
9514 static iw_handler ipw_priv_handler
[] = {
9515 ipw_wx_set_powermode
,
9516 ipw_wx_get_powermode
,
9517 ipw_wx_set_wireless_mode
,
9518 ipw_wx_get_wireless_mode
,
9519 ipw_wx_set_preamble
,
9520 ipw_wx_get_preamble
,
9523 #ifdef CONFIG_IPW2200_MONITOR
9528 static struct iw_handler_def ipw_wx_handler_def
= {
9529 .standard
= ipw_wx_handlers
,
9530 .num_standard
= ARRAY_SIZE(ipw_wx_handlers
),
9531 .num_private
= ARRAY_SIZE(ipw_priv_handler
),
9532 .num_private_args
= ARRAY_SIZE(ipw_priv_args
),
9533 .private = ipw_priv_handler
,
9534 .private_args
= ipw_priv_args
,
9537 static struct iw_public_data ipw_wx_data
;
9540 * Get wireless statistics.
9541 * Called by /proc/net/wireless
9542 * Also called by SIOCGIWSTATS
9544 static struct iw_statistics
*ipw_get_wireless_stats(struct net_device
*dev
)
9546 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9547 struct iw_statistics
*wstats
;
9549 wstats
= &priv
->wstats
;
9551 /* if hw is disabled, then ipw_get_ordinal() can't be called.
9552 * netdev->get_wireless_stats seems to be called before fw is
9553 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9554 * and associated; if not associcated, the values are all meaningless
9555 * anyway, so set them all to NULL and INVALID */
9556 if (!(priv
->status
& STATUS_ASSOCIATED
)) {
9557 wstats
->miss
.beacon
= 0;
9558 wstats
->discard
.retries
= 0;
9559 wstats
->qual
.qual
= 0;
9560 wstats
->qual
.level
= 0;
9561 wstats
->qual
.noise
= 0;
9562 wstats
->qual
.updated
= 7;
9563 wstats
->qual
.updated
|= IW_QUAL_NOISE_INVALID
|
9564 IW_QUAL_QUAL_INVALID
| IW_QUAL_LEVEL_INVALID
;
9568 wstats
->qual
.qual
= priv
->quality
;
9569 wstats
->qual
.level
= average_value(&priv
->average_rssi
);
9570 wstats
->qual
.noise
= average_value(&priv
->average_noise
);
9571 wstats
->qual
.updated
= IW_QUAL_QUAL_UPDATED
| IW_QUAL_LEVEL_UPDATED
|
9572 IW_QUAL_NOISE_UPDATED
;
9574 wstats
->miss
.beacon
= average_value(&priv
->average_missed_beacons
);
9575 wstats
->discard
.retries
= priv
->last_tx_failures
;
9576 wstats
->discard
.code
= priv
->ieee
->ieee_stats
.rx_discards_undecryptable
;
9578 /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9579 goto fail_get_ordinal;
9580 wstats->discard.retries += tx_retry; */
9585 /* net device stuff */
9587 static inline void init_sys_config(struct ipw_sys_config
*sys_config
)
9589 memset(sys_config
, 0, sizeof(struct ipw_sys_config
));
9590 sys_config
->bt_coexistence
= 1; /* We may need to look into prvStaBtConfig */
9591 sys_config
->answer_broadcast_ssid_probe
= 0;
9592 sys_config
->accept_all_data_frames
= 0;
9593 sys_config
->accept_non_directed_frames
= 1;
9594 sys_config
->exclude_unicast_unencrypted
= 0;
9595 sys_config
->disable_unicast_decryption
= 1;
9596 sys_config
->exclude_multicast_unencrypted
= 0;
9597 sys_config
->disable_multicast_decryption
= 1;
9598 sys_config
->antenna_diversity
= CFG_SYS_ANTENNA_BOTH
;
9599 sys_config
->pass_crc_to_host
= 0; /* TODO: See if 1 gives us FCS */
9600 sys_config
->dot11g_auto_detection
= 0;
9601 sys_config
->enable_cts_to_self
= 0;
9602 sys_config
->bt_coexist_collision_thr
= 0;
9603 sys_config
->pass_noise_stats_to_host
= 1; //1 -- fix for 256
9606 static int ipw_net_open(struct net_device
*dev
)
9608 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9609 IPW_DEBUG_INFO("dev->open\n");
9610 /* we should be verifying the device is ready to be opened */
9612 if (!(priv
->status
& STATUS_RF_KILL_MASK
) &&
9613 (priv
->status
& STATUS_ASSOCIATED
))
9614 netif_start_queue(dev
);
9619 static int ipw_net_stop(struct net_device
*dev
)
9621 IPW_DEBUG_INFO("dev->close\n");
9622 netif_stop_queue(dev
);
9629 modify to send one tfd per fragment instead of using chunking. otherwise
9630 we need to heavily modify the ieee80211_skb_to_txb.
9633 static inline void ipw_tx_skb(struct ipw_priv
*priv
, struct ieee80211_txb
*txb
,
9636 struct ieee80211_hdr_3addr
*hdr
= (struct ieee80211_hdr_3addr
*)
9637 txb
->fragments
[0]->data
;
9639 struct tfd_frame
*tfd
;
9640 #ifdef CONFIG_IPW_QOS
9641 int tx_id
= ipw_get_tx_queue_number(priv
, pri
);
9642 struct clx2_tx_queue
*txq
= &priv
->txq
[tx_id
];
9644 struct clx2_tx_queue
*txq
= &priv
->txq
[0];
9646 struct clx2_queue
*q
= &txq
->q
;
9647 u8 id
, hdr_len
, unicast
;
9648 u16 remaining_bytes
;
9651 switch (priv
->ieee
->iw_mode
) {
9653 hdr_len
= IEEE80211_3ADDR_LEN
;
9654 unicast
= !is_multicast_ether_addr(hdr
->addr1
);
9655 id
= ipw_find_station(priv
, hdr
->addr1
);
9656 if (id
== IPW_INVALID_STATION
) {
9657 id
= ipw_add_station(priv
, hdr
->addr1
);
9658 if (id
== IPW_INVALID_STATION
) {
9659 IPW_WARNING("Attempt to send data to "
9660 "invalid cell: " MAC_FMT
"\n",
9661 MAC_ARG(hdr
->addr1
));
9669 unicast
= !is_multicast_ether_addr(hdr
->addr3
);
9670 hdr_len
= IEEE80211_3ADDR_LEN
;
9675 tfd
= &txq
->bd
[q
->first_empty
];
9676 txq
->txb
[q
->first_empty
] = txb
;
9677 memset(tfd
, 0, sizeof(*tfd
));
9678 tfd
->u
.data
.station_number
= id
;
9680 tfd
->control_flags
.message_type
= TX_FRAME_TYPE
;
9681 tfd
->control_flags
.control_bits
= TFD_NEED_IRQ_MASK
;
9683 tfd
->u
.data
.cmd_id
= DINO_CMD_TX
;
9684 tfd
->u
.data
.len
= cpu_to_le16(txb
->payload_size
);
9685 remaining_bytes
= txb
->payload_size
;
9687 if (priv
->assoc_request
.ieee_mode
== IPW_B_MODE
)
9688 tfd
->u
.data
.tx_flags_ext
|= DCT_FLAG_EXT_MODE_CCK
;
9690 tfd
->u
.data
.tx_flags_ext
|= DCT_FLAG_EXT_MODE_OFDM
;
9692 if (priv
->assoc_request
.preamble_length
== DCT_FLAG_SHORT_PREAMBLE
)
9693 tfd
->u
.data
.tx_flags
|= DCT_FLAG_SHORT_PREAMBLE
;
9695 fc
= le16_to_cpu(hdr
->frame_ctl
);
9696 hdr
->frame_ctl
= cpu_to_le16(fc
& ~IEEE80211_FCTL_MOREFRAGS
);
9698 memcpy(&tfd
->u
.data
.tfd
.tfd_24
.mchdr
, hdr
, hdr_len
);
9700 if (likely(unicast
))
9701 tfd
->u
.data
.tx_flags
|= DCT_FLAG_ACK_REQD
;
9703 if (txb
->encrypted
&& !priv
->ieee
->host_encrypt
) {
9704 switch (priv
->ieee
->sec
.level
) {
9706 tfd
->u
.data
.tfd
.tfd_24
.mchdr
.frame_ctl
|=
9707 IEEE80211_FCTL_PROTECTED
;
9708 /* XXX: ACK flag must be set for CCMP even if it
9709 * is a multicast/broadcast packet, because CCMP
9710 * group communication encrypted by GTK is
9711 * actually done by the AP. */
9713 tfd
->u
.data
.tx_flags
|= DCT_FLAG_ACK_REQD
;
9715 tfd
->u
.data
.tx_flags
&= ~DCT_FLAG_NO_WEP
;
9716 tfd
->u
.data
.tx_flags_ext
|= DCT_FLAG_EXT_SECURITY_CCM
;
9717 tfd
->u
.data
.key_index
= 0;
9718 tfd
->u
.data
.key_index
|= DCT_WEP_INDEX_USE_IMMEDIATE
;
9721 tfd
->u
.data
.tfd
.tfd_24
.mchdr
.frame_ctl
|=
9722 IEEE80211_FCTL_PROTECTED
;
9723 tfd
->u
.data
.tx_flags
&= ~DCT_FLAG_NO_WEP
;
9724 tfd
->u
.data
.tx_flags_ext
|= DCT_FLAG_EXT_SECURITY_TKIP
;
9725 tfd
->u
.data
.key_index
= DCT_WEP_INDEX_USE_IMMEDIATE
;
9728 tfd
->u
.data
.tfd
.tfd_24
.mchdr
.frame_ctl
|=
9729 IEEE80211_FCTL_PROTECTED
;
9730 tfd
->u
.data
.key_index
= priv
->ieee
->tx_keyidx
;
9731 if (priv
->ieee
->sec
.key_sizes
[priv
->ieee
->tx_keyidx
] <=
9733 tfd
->u
.data
.key_index
|= DCT_WEP_KEY_64Bit
;
9735 tfd
->u
.data
.key_index
|= DCT_WEP_KEY_128Bit
;
9740 printk(KERN_ERR
"Unknow security level %d\n",
9741 priv
->ieee
->sec
.level
);
9745 /* No hardware encryption */
9746 tfd
->u
.data
.tx_flags
|= DCT_FLAG_NO_WEP
;
9748 #ifdef CONFIG_IPW_QOS
9749 ipw_qos_set_tx_queue_command(priv
, pri
, &(tfd
->u
.data
), unicast
);
9750 #endif /* CONFIG_IPW_QOS */
9753 tfd
->u
.data
.num_chunks
= cpu_to_le32(min((u8
) (NUM_TFD_CHUNKS
- 2),
9755 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
9756 txb
->nr_frags
, le32_to_cpu(tfd
->u
.data
.num_chunks
));
9757 for (i
= 0; i
< le32_to_cpu(tfd
->u
.data
.num_chunks
); i
++) {
9758 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
9759 i
, le32_to_cpu(tfd
->u
.data
.num_chunks
),
9760 txb
->fragments
[i
]->len
- hdr_len
);
9761 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
9762 i
, tfd
->u
.data
.num_chunks
,
9763 txb
->fragments
[i
]->len
- hdr_len
);
9764 printk_buf(IPW_DL_TX
, txb
->fragments
[i
]->data
+ hdr_len
,
9765 txb
->fragments
[i
]->len
- hdr_len
);
9767 tfd
->u
.data
.chunk_ptr
[i
] =
9768 cpu_to_le32(pci_map_single
9770 txb
->fragments
[i
]->data
+ hdr_len
,
9771 txb
->fragments
[i
]->len
- hdr_len
,
9773 tfd
->u
.data
.chunk_len
[i
] =
9774 cpu_to_le16(txb
->fragments
[i
]->len
- hdr_len
);
9777 if (i
!= txb
->nr_frags
) {
9778 struct sk_buff
*skb
;
9779 u16 remaining_bytes
= 0;
9782 for (j
= i
; j
< txb
->nr_frags
; j
++)
9783 remaining_bytes
+= txb
->fragments
[j
]->len
- hdr_len
;
9785 printk(KERN_INFO
"Trying to reallocate for %d bytes\n",
9787 skb
= alloc_skb(remaining_bytes
, GFP_ATOMIC
);
9789 tfd
->u
.data
.chunk_len
[i
] = cpu_to_le16(remaining_bytes
);
9790 for (j
= i
; j
< txb
->nr_frags
; j
++) {
9791 int size
= txb
->fragments
[j
]->len
- hdr_len
;
9793 printk(KERN_INFO
"Adding frag %d %d...\n",
9795 memcpy(skb_put(skb
, size
),
9796 txb
->fragments
[j
]->data
+ hdr_len
, size
);
9798 dev_kfree_skb_any(txb
->fragments
[i
]);
9799 txb
->fragments
[i
] = skb
;
9800 tfd
->u
.data
.chunk_ptr
[i
] =
9801 cpu_to_le32(pci_map_single
9802 (priv
->pci_dev
, skb
->data
,
9803 tfd
->u
.data
.chunk_len
[i
],
9806 tfd
->u
.data
.num_chunks
=
9807 cpu_to_le32(le32_to_cpu(tfd
->u
.data
.num_chunks
) +
9813 q
->first_empty
= ipw_queue_inc_wrap(q
->first_empty
, q
->n_bd
);
9814 ipw_write32(priv
, q
->reg_w
, q
->first_empty
);
9816 if (ipw_queue_space(q
) < q
->high_mark
)
9817 netif_stop_queue(priv
->net_dev
);
9822 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
9823 ieee80211_txb_free(txb
);
9826 static int ipw_net_hard_start_xmit(struct ieee80211_txb
*txb
,
9827 struct net_device
*dev
, int pri
)
9829 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9830 unsigned long flags
;
9832 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb
->payload_size
);
9833 spin_lock_irqsave(&priv
->lock
, flags
);
9835 if (!(priv
->status
& STATUS_ASSOCIATED
)) {
9836 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
9837 priv
->ieee
->stats
.tx_carrier_errors
++;
9838 netif_stop_queue(dev
);
9842 ipw_tx_skb(priv
, txb
, pri
);
9843 __ipw_led_activity_on(priv
);
9844 spin_unlock_irqrestore(&priv
->lock
, flags
);
9849 spin_unlock_irqrestore(&priv
->lock
, flags
);
9853 static struct net_device_stats
*ipw_net_get_stats(struct net_device
*dev
)
9855 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9857 priv
->ieee
->stats
.tx_packets
= priv
->tx_packets
;
9858 priv
->ieee
->stats
.rx_packets
= priv
->rx_packets
;
9859 return &priv
->ieee
->stats
;
9862 static void ipw_net_set_multicast_list(struct net_device
*dev
)
9867 static int ipw_net_set_mac_address(struct net_device
*dev
, void *p
)
9869 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9870 struct sockaddr
*addr
= p
;
9871 if (!is_valid_ether_addr(addr
->sa_data
))
9872 return -EADDRNOTAVAIL
;
9874 priv
->config
|= CFG_CUSTOM_MAC
;
9875 memcpy(priv
->mac_addr
, addr
->sa_data
, ETH_ALEN
);
9876 printk(KERN_INFO
"%s: Setting MAC to " MAC_FMT
"\n",
9877 priv
->net_dev
->name
, MAC_ARG(priv
->mac_addr
));
9878 queue_work(priv
->workqueue
, &priv
->adapter_restart
);
9883 static void ipw_ethtool_get_drvinfo(struct net_device
*dev
,
9884 struct ethtool_drvinfo
*info
)
9886 struct ipw_priv
*p
= ieee80211_priv(dev
);
9891 strcpy(info
->driver
, DRV_NAME
);
9892 strcpy(info
->version
, DRV_VERSION
);
9895 ipw_get_ordinal(p
, IPW_ORD_STAT_FW_VERSION
, vers
, &len
);
9897 ipw_get_ordinal(p
, IPW_ORD_STAT_FW_DATE
, date
, &len
);
9899 snprintf(info
->fw_version
, sizeof(info
->fw_version
), "%s (%s)",
9901 strcpy(info
->bus_info
, pci_name(p
->pci_dev
));
9902 info
->eedump_len
= IPW_EEPROM_IMAGE_SIZE
;
9905 static u32
ipw_ethtool_get_link(struct net_device
*dev
)
9907 struct ipw_priv
*priv
= ieee80211_priv(dev
);
9908 return (priv
->status
& STATUS_ASSOCIATED
) != 0;
9911 static int ipw_ethtool_get_eeprom_len(struct net_device
*dev
)
9913 return IPW_EEPROM_IMAGE_SIZE
;
9916 static int ipw_ethtool_get_eeprom(struct net_device
*dev
,
9917 struct ethtool_eeprom
*eeprom
, u8
* bytes
)
9919 struct ipw_priv
*p
= ieee80211_priv(dev
);
9921 if (eeprom
->offset
+ eeprom
->len
> IPW_EEPROM_IMAGE_SIZE
)
9924 memcpy(bytes
, &p
->eeprom
[eeprom
->offset
], eeprom
->len
);
9929 static int ipw_ethtool_set_eeprom(struct net_device
*dev
,
9930 struct ethtool_eeprom
*eeprom
, u8
* bytes
)
9932 struct ipw_priv
*p
= ieee80211_priv(dev
);
9935 if (eeprom
->offset
+ eeprom
->len
> IPW_EEPROM_IMAGE_SIZE
)
9938 memcpy(&p
->eeprom
[eeprom
->offset
], bytes
, eeprom
->len
);
9939 for (i
= IPW_EEPROM_DATA
;
9940 i
< IPW_EEPROM_DATA
+ IPW_EEPROM_IMAGE_SIZE
; i
++)
9941 ipw_write8(p
, i
, p
->eeprom
[i
]);
9946 static struct ethtool_ops ipw_ethtool_ops
= {
9947 .get_link
= ipw_ethtool_get_link
,
9948 .get_drvinfo
= ipw_ethtool_get_drvinfo
,
9949 .get_eeprom_len
= ipw_ethtool_get_eeprom_len
,
9950 .get_eeprom
= ipw_ethtool_get_eeprom
,
9951 .set_eeprom
= ipw_ethtool_set_eeprom
,
9954 static irqreturn_t
ipw_isr(int irq
, void *data
, struct pt_regs
*regs
)
9956 struct ipw_priv
*priv
= data
;
9957 u32 inta
, inta_mask
;
9962 spin_lock(&priv
->lock
);
9964 if (!(priv
->status
& STATUS_INT_ENABLED
)) {
9969 inta
= ipw_read32(priv
, IPW_INTA_RW
);
9970 inta_mask
= ipw_read32(priv
, IPW_INTA_MASK_R
);
9972 if (inta
== 0xFFFFFFFF) {
9973 /* Hardware disappeared */
9974 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
9978 if (!(inta
& (IPW_INTA_MASK_ALL
& inta_mask
))) {
9979 /* Shared interrupt */
9983 /* tell the device to stop sending interrupts */
9984 ipw_disable_interrupts(priv
);
9986 /* ack current interrupts */
9987 inta
&= (IPW_INTA_MASK_ALL
& inta_mask
);
9988 ipw_write32(priv
, IPW_INTA_RW
, inta
);
9990 /* Cache INTA value for our tasklet */
9991 priv
->isr_inta
= inta
;
9993 tasklet_schedule(&priv
->irq_tasklet
);
9995 spin_unlock(&priv
->lock
);
9999 spin_unlock(&priv
->lock
);
10003 static void ipw_rf_kill(void *adapter
)
10005 struct ipw_priv
*priv
= adapter
;
10006 unsigned long flags
;
10008 spin_lock_irqsave(&priv
->lock
, flags
);
10010 if (rf_kill_active(priv
)) {
10011 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10012 if (priv
->workqueue
)
10013 queue_delayed_work(priv
->workqueue
,
10014 &priv
->rf_kill
, 2 * HZ
);
10018 /* RF Kill is now disabled, so bring the device back up */
10020 if (!(priv
->status
& STATUS_RF_KILL_MASK
)) {
10021 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10024 /* we can not do an adapter restart while inside an irq lock */
10025 queue_work(priv
->workqueue
, &priv
->adapter_restart
);
10027 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10031 spin_unlock_irqrestore(&priv
->lock
, flags
);
10034 static void ipw_bg_rf_kill(void *data
)
10036 struct ipw_priv
*priv
= data
;
10042 void ipw_link_up(struct ipw_priv
*priv
)
10044 priv
->last_seq_num
= -1;
10045 priv
->last_frag_num
= -1;
10046 priv
->last_packet_time
= 0;
10048 netif_carrier_on(priv
->net_dev
);
10049 if (netif_queue_stopped(priv
->net_dev
)) {
10050 IPW_DEBUG_NOTIF("waking queue\n");
10051 netif_wake_queue(priv
->net_dev
);
10053 IPW_DEBUG_NOTIF("starting queue\n");
10054 netif_start_queue(priv
->net_dev
);
10057 cancel_delayed_work(&priv
->request_scan
);
10058 ipw_reset_stats(priv
);
10059 /* Ensure the rate is updated immediately */
10060 priv
->last_rate
= ipw_get_current_rate(priv
);
10061 ipw_gather_stats(priv
);
10062 ipw_led_link_up(priv
);
10063 notify_wx_assoc_event(priv
);
10065 if (priv
->config
& CFG_BACKGROUND_SCAN
)
10066 queue_delayed_work(priv
->workqueue
, &priv
->request_scan
, HZ
);
10069 static void ipw_bg_link_up(void *data
)
10071 struct ipw_priv
*priv
= data
;
10077 void ipw_link_down(struct ipw_priv
*priv
)
10079 ipw_led_link_down(priv
);
10080 netif_carrier_off(priv
->net_dev
);
10081 netif_stop_queue(priv
->net_dev
);
10082 notify_wx_assoc_event(priv
);
10084 /* Cancel any queued work ... */
10085 cancel_delayed_work(&priv
->request_scan
);
10086 cancel_delayed_work(&priv
->adhoc_check
);
10087 cancel_delayed_work(&priv
->gather_stats
);
10089 ipw_reset_stats(priv
);
10091 if (!(priv
->status
& STATUS_EXIT_PENDING
)) {
10092 /* Queue up another scan... */
10093 queue_work(priv
->workqueue
, &priv
->request_scan
);
10097 static void ipw_bg_link_down(void *data
)
10099 struct ipw_priv
*priv
= data
;
10101 ipw_link_down(data
);
10105 static int ipw_setup_deferred_work(struct ipw_priv
*priv
)
10109 priv
->workqueue
= create_workqueue(DRV_NAME
);
10110 init_waitqueue_head(&priv
->wait_command_queue
);
10111 init_waitqueue_head(&priv
->wait_state
);
10113 INIT_WORK(&priv
->adhoc_check
, ipw_bg_adhoc_check
, priv
);
10114 INIT_WORK(&priv
->associate
, ipw_bg_associate
, priv
);
10115 INIT_WORK(&priv
->disassociate
, ipw_bg_disassociate
, priv
);
10116 INIT_WORK(&priv
->rx_replenish
, ipw_bg_rx_queue_replenish
, priv
);
10117 INIT_WORK(&priv
->adapter_restart
, ipw_bg_adapter_restart
, priv
);
10118 INIT_WORK(&priv
->rf_kill
, ipw_bg_rf_kill
, priv
);
10119 INIT_WORK(&priv
->up
, (void (*)(void *))ipw_bg_up
, priv
);
10120 INIT_WORK(&priv
->down
, (void (*)(void *))ipw_bg_down
, priv
);
10121 INIT_WORK(&priv
->request_scan
,
10122 (void (*)(void *))ipw_request_scan
, priv
);
10123 INIT_WORK(&priv
->gather_stats
,
10124 (void (*)(void *))ipw_bg_gather_stats
, priv
);
10125 INIT_WORK(&priv
->abort_scan
, (void (*)(void *))ipw_bg_abort_scan
, priv
);
10126 INIT_WORK(&priv
->roam
, ipw_bg_roam
, priv
);
10127 INIT_WORK(&priv
->scan_check
, ipw_bg_scan_check
, priv
);
10128 INIT_WORK(&priv
->link_up
, (void (*)(void *))ipw_bg_link_up
, priv
);
10129 INIT_WORK(&priv
->link_down
, (void (*)(void *))ipw_bg_link_down
, priv
);
10130 INIT_WORK(&priv
->led_link_on
, (void (*)(void *))ipw_bg_led_link_on
,
10132 INIT_WORK(&priv
->led_link_off
, (void (*)(void *))ipw_bg_led_link_off
,
10134 INIT_WORK(&priv
->led_act_off
, (void (*)(void *))ipw_bg_led_activity_off
,
10136 INIT_WORK(&priv
->merge_networks
,
10137 (void (*)(void *))ipw_merge_adhoc_network
, priv
);
10139 #ifdef CONFIG_IPW_QOS
10140 INIT_WORK(&priv
->qos_activate
, (void (*)(void *))ipw_bg_qos_activate
,
10142 #endif /* CONFIG_IPW_QOS */
10144 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
10145 ipw_irq_tasklet
, (unsigned long)priv
);
10150 static void shim__set_security(struct net_device
*dev
,
10151 struct ieee80211_security
*sec
)
10153 struct ipw_priv
*priv
= ieee80211_priv(dev
);
10155 for (i
= 0; i
< 4; i
++) {
10156 if (sec
->flags
& (1 << i
)) {
10157 priv
->ieee
->sec
.encode_alg
[i
] = sec
->encode_alg
[i
];
10158 priv
->ieee
->sec
.key_sizes
[i
] = sec
->key_sizes
[i
];
10159 if (sec
->key_sizes
[i
] == 0)
10160 priv
->ieee
->sec
.flags
&= ~(1 << i
);
10162 memcpy(priv
->ieee
->sec
.keys
[i
], sec
->keys
[i
],
10163 sec
->key_sizes
[i
]);
10164 priv
->ieee
->sec
.flags
|= (1 << i
);
10166 priv
->status
|= STATUS_SECURITY_UPDATED
;
10167 } else if (sec
->level
!= SEC_LEVEL_1
)
10168 priv
->ieee
->sec
.flags
&= ~(1 << i
);
10171 if (sec
->flags
& SEC_ACTIVE_KEY
) {
10172 if (sec
->active_key
<= 3) {
10173 priv
->ieee
->sec
.active_key
= sec
->active_key
;
10174 priv
->ieee
->sec
.flags
|= SEC_ACTIVE_KEY
;
10176 priv
->ieee
->sec
.flags
&= ~SEC_ACTIVE_KEY
;
10177 priv
->status
|= STATUS_SECURITY_UPDATED
;
10179 priv
->ieee
->sec
.flags
&= ~SEC_ACTIVE_KEY
;
10181 if ((sec
->flags
& SEC_AUTH_MODE
) &&
10182 (priv
->ieee
->sec
.auth_mode
!= sec
->auth_mode
)) {
10183 priv
->ieee
->sec
.auth_mode
= sec
->auth_mode
;
10184 priv
->ieee
->sec
.flags
|= SEC_AUTH_MODE
;
10185 if (sec
->auth_mode
== WLAN_AUTH_SHARED_KEY
)
10186 priv
->capability
|= CAP_SHARED_KEY
;
10188 priv
->capability
&= ~CAP_SHARED_KEY
;
10189 priv
->status
|= STATUS_SECURITY_UPDATED
;
10192 if (sec
->flags
& SEC_ENABLED
&& priv
->ieee
->sec
.enabled
!= sec
->enabled
) {
10193 priv
->ieee
->sec
.flags
|= SEC_ENABLED
;
10194 priv
->ieee
->sec
.enabled
= sec
->enabled
;
10195 priv
->status
|= STATUS_SECURITY_UPDATED
;
10197 priv
->capability
|= CAP_PRIVACY_ON
;
10199 priv
->capability
&= ~CAP_PRIVACY_ON
;
10202 if (sec
->flags
& SEC_ENCRYPT
)
10203 priv
->ieee
->sec
.encrypt
= sec
->encrypt
;
10205 if (sec
->flags
& SEC_LEVEL
&& priv
->ieee
->sec
.level
!= sec
->level
) {
10206 priv
->ieee
->sec
.level
= sec
->level
;
10207 priv
->ieee
->sec
.flags
|= SEC_LEVEL
;
10208 priv
->status
|= STATUS_SECURITY_UPDATED
;
10211 if (!priv
->ieee
->host_encrypt
)
10212 ipw_set_hwcrypto_keys(priv
);
10214 /* To match current functionality of ipw2100 (which works well w/
10215 * various supplicants, we don't force a disassociate if the
10216 * privacy capability changes ... */
10218 if ((priv
->status
& (STATUS_ASSOCIATED
| STATUS_ASSOCIATING
)) &&
10219 (((priv
->assoc_request
.capability
&
10220 WLAN_CAPABILITY_PRIVACY
) && !sec
->enabled
) ||
10221 (!(priv
->assoc_request
.capability
&
10222 WLAN_CAPABILITY_PRIVACY
) && sec
->enabled
))) {
10223 IPW_DEBUG_ASSOC("Disassociating due to capability "
10225 ipw_disassociate(priv
);
10230 static int init_supported_rates(struct ipw_priv
*priv
,
10231 struct ipw_supported_rates
*rates
)
10233 /* TODO: Mask out rates based on priv->rates_mask */
10235 memset(rates
, 0, sizeof(*rates
));
10236 /* configure supported rates */
10237 switch (priv
->ieee
->freq_band
) {
10238 case IEEE80211_52GHZ_BAND
:
10239 rates
->ieee_mode
= IPW_A_MODE
;
10240 rates
->purpose
= IPW_RATE_CAPABILITIES
;
10241 ipw_add_ofdm_scan_rates(rates
, IEEE80211_CCK_MODULATION
,
10242 IEEE80211_OFDM_DEFAULT_RATES_MASK
);
10245 default: /* Mixed or 2.4Ghz */
10246 rates
->ieee_mode
= IPW_G_MODE
;
10247 rates
->purpose
= IPW_RATE_CAPABILITIES
;
10248 ipw_add_cck_scan_rates(rates
, IEEE80211_CCK_MODULATION
,
10249 IEEE80211_CCK_DEFAULT_RATES_MASK
);
10250 if (priv
->ieee
->modulation
& IEEE80211_OFDM_MODULATION
) {
10251 ipw_add_ofdm_scan_rates(rates
, IEEE80211_CCK_MODULATION
,
10252 IEEE80211_OFDM_DEFAULT_RATES_MASK
);
10260 static int ipw_config(struct ipw_priv
*priv
)
10263 struct ipw_tx_power tx_power
;
10265 memset(&priv
->sys_config
, 0, sizeof(priv
->sys_config
));
10266 memset(&tx_power
, 0, sizeof(tx_power
));
10268 /* This is only called from ipw_up, which resets/reloads the firmware
10269 so, we don't need to first disable the card before we configure
10272 /* configure device for 'G' band */
10273 tx_power
.ieee_mode
= IPW_G_MODE
;
10274 tx_power
.num_channels
= 11;
10275 for (i
= 0; i
< 11; i
++) {
10276 tx_power
.channels_tx_power
[i
].channel_number
= i
+ 1;
10277 tx_power
.channels_tx_power
[i
].tx_power
= priv
->tx_power
;
10279 if (ipw_send_tx_power(priv
, &tx_power
))
10282 /* configure device to also handle 'B' band */
10283 tx_power
.ieee_mode
= IPW_B_MODE
;
10284 if (ipw_send_tx_power(priv
, &tx_power
))
10287 /* initialize adapter address */
10288 if (ipw_send_adapter_address(priv
, priv
->net_dev
->dev_addr
))
10291 /* set basic system config settings */
10292 init_sys_config(&priv
->sys_config
);
10293 if (priv
->ieee
->iw_mode
== IW_MODE_ADHOC
)
10294 priv
->sys_config
.answer_broadcast_ssid_probe
= 1;
10296 priv
->sys_config
.answer_broadcast_ssid_probe
= 0;
10298 if (ipw_send_system_config(priv
, &priv
->sys_config
))
10301 init_supported_rates(priv
, &priv
->rates
);
10302 if (ipw_send_supported_rates(priv
, &priv
->rates
))
10305 /* Set request-to-send threshold */
10306 if (priv
->rts_threshold
) {
10307 if (ipw_send_rts_threshold(priv
, priv
->rts_threshold
))
10310 #ifdef CONFIG_IPW_QOS
10311 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10312 ipw_qos_activate(priv
, NULL
);
10313 #endif /* CONFIG_IPW_QOS */
10315 if (ipw_set_random_seed(priv
))
10318 /* final state transition to the RUN state */
10319 if (ipw_send_host_complete(priv
))
10322 /* If configured to try and auto-associate, kick off a scan */
10323 if (priv
->config
& CFG_ASSOCIATE
)
10324 queue_work(priv
->workqueue
, &priv
->request_scan
);
10332 static const struct ieee80211_geo ipw_geo
= {
10335 .bg
= {{2412, 1}, {2417, 2}, {2422, 3},
10336 {2427, 4}, {2432, 5}, {2437, 6},
10337 {2442, 7}, {2447, 8}, {2452, 9},
10338 {2457, 10}, {2462, 11}},
10344 {5260, 52, IEEE80211_CH_PASSIVE_ONLY
},
10345 {5280, 56, IEEE80211_CH_PASSIVE_ONLY
},
10346 {5300, 60, IEEE80211_CH_PASSIVE_ONLY
},
10347 {5320, 64, IEEE80211_CH_PASSIVE_ONLY
}},
10350 #define MAX_HW_RESTARTS 5
10351 static int ipw_up(struct ipw_priv
*priv
)
10355 if (priv
->status
& STATUS_EXIT_PENDING
)
10358 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
10359 /* Load the microcode, firmware, and eeprom.
10360 * Also start the clocks. */
10361 rc
= ipw_load(priv
);
10363 IPW_ERROR("Unable to load firmware: 0x%08X\n", rc
);
10367 ipw_init_ordinals(priv
);
10368 if (!(priv
->config
& CFG_CUSTOM_MAC
))
10369 eeprom_parse_mac(priv
, priv
->mac_addr
);
10370 memcpy(priv
->net_dev
->dev_addr
, priv
->mac_addr
, ETH_ALEN
);
10372 memcpy(priv
->country
, &priv
->eeprom
[EEPROM_COUNTRY_CODE
], 3);
10373 priv
->country
[3] = '\0';
10374 ieee80211_set_geo(priv
->ieee
, &ipw_geo
);
10376 if (priv
->status
& STATUS_RF_KILL_SW
) {
10377 IPW_WARNING("Radio disabled by module parameter.\n");
10379 } else if (rf_kill_active(priv
)) {
10380 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
10381 "Kill switch must be turned off for "
10382 "wireless networking to work.\n");
10383 queue_delayed_work(priv
->workqueue
, &priv
->rf_kill
,
10388 rc
= ipw_config(priv
);
10390 IPW_DEBUG_INFO("Configured device on count %i\n", i
);
10391 ipw_led_init(priv
);
10392 ipw_led_radio_on(priv
);
10393 priv
->notif_missed_beacons
= 0;
10394 priv
->status
|= STATUS_INIT
;
10396 /* Set hardware WEP key if it is configured. */
10397 if ((priv
->capability
& CAP_PRIVACY_ON
) &&
10398 (priv
->ieee
->sec
.level
== SEC_LEVEL_1
) &&
10399 !(priv
->ieee
->host_encrypt
||
10400 priv
->ieee
->host_decrypt
))
10401 ipw_set_hwcrypto_keys(priv
);
10406 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc
);
10407 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
10408 i
, MAX_HW_RESTARTS
);
10410 /* We had an error bringing up the hardware, so take it
10411 * all the way back down so we can try again */
10415 /* tried to restart and config the device for as long as our
10416 * patience could withstand */
10417 IPW_ERROR("Unable to initialize device after %d attempts.\n", i
);
10422 static void ipw_bg_up(void *data
)
10424 struct ipw_priv
*priv
= data
;
10430 static void ipw_deinit(struct ipw_priv
*priv
)
10434 if (priv
->status
& STATUS_SCANNING
) {
10435 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
10436 ipw_abort_scan(priv
);
10439 if (priv
->status
& STATUS_ASSOCIATED
) {
10440 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
10441 ipw_disassociate(priv
);
10444 ipw_led_shutdown(priv
);
10446 /* Wait up to 1s for status to change to not scanning and not
10447 * associated (disassociation can take a while for a ful 802.11
10449 for (i
= 1000; i
&& (priv
->status
&
10450 (STATUS_DISASSOCIATING
|
10451 STATUS_ASSOCIATED
| STATUS_SCANNING
)); i
--)
10454 if (priv
->status
& (STATUS_DISASSOCIATING
|
10455 STATUS_ASSOCIATED
| STATUS_SCANNING
))
10456 IPW_DEBUG_INFO("Still associated or scanning...\n");
10458 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i
);
10460 /* Attempt to disable the card */
10461 ipw_send_card_disable(priv
, 0);
10463 priv
->status
&= ~STATUS_INIT
;
10466 static void ipw_down(struct ipw_priv
*priv
)
10468 int exit_pending
= priv
->status
& STATUS_EXIT_PENDING
;
10470 priv
->status
|= STATUS_EXIT_PENDING
;
10472 if (ipw_is_init(priv
))
10475 /* Wipe out the EXIT_PENDING status bit if we are not actually
10476 * exiting the module */
10478 priv
->status
&= ~STATUS_EXIT_PENDING
;
10480 /* tell the device to stop sending interrupts */
10481 ipw_disable_interrupts(priv
);
10483 /* Clear all bits but the RF Kill */
10484 priv
->status
&= STATUS_RF_KILL_MASK
| STATUS_EXIT_PENDING
;
10485 netif_carrier_off(priv
->net_dev
);
10486 netif_stop_queue(priv
->net_dev
);
10488 ipw_stop_nic(priv
);
10490 ipw_led_radio_off(priv
);
10493 static void ipw_bg_down(void *data
)
10495 struct ipw_priv
*priv
= data
;
10501 #if WIRELESS_EXT < 18
10502 static int ipw_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
10504 struct iwreq
*wrq
= (struct iwreq
*)rq
;
10507 case IPW_IOCTL_WPA_SUPPLICANT
:
10508 ret
= ipw_wpa_supplicant(dev
, &wrq
->u
.data
);
10512 return -EOPNOTSUPP
;
10515 return -EOPNOTSUPP
;
10519 /* Called by register_netdev() */
10520 static int ipw_net_init(struct net_device
*dev
)
10522 struct ipw_priv
*priv
= ieee80211_priv(dev
);
10525 if (ipw_up(priv
)) {
10534 /* PCI driver stuff */
10535 static struct pci_device_id card_ids
[] = {
10536 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2701, 0, 0, 0},
10537 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2702, 0, 0, 0},
10538 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2711, 0, 0, 0},
10539 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2712, 0, 0, 0},
10540 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2721, 0, 0, 0},
10541 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2722, 0, 0, 0},
10542 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2731, 0, 0, 0},
10543 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2732, 0, 0, 0},
10544 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2741, 0, 0, 0},
10545 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x103c, 0x2741, 0, 0, 0},
10546 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2742, 0, 0, 0},
10547 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2751, 0, 0, 0},
10548 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2752, 0, 0, 0},
10549 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2753, 0, 0, 0},
10550 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2754, 0, 0, 0},
10551 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2761, 0, 0, 0},
10552 {PCI_VENDOR_ID_INTEL
, 0x1043, 0x8086, 0x2762, 0, 0, 0},
10553 {PCI_VENDOR_ID_INTEL
, 0x104f, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0},
10554 {PCI_VENDOR_ID_INTEL
, 0x4220, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0}, /* BG */
10555 {PCI_VENDOR_ID_INTEL
, 0x4221, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0}, /* BG */
10556 {PCI_VENDOR_ID_INTEL
, 0x4223, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0}, /* ABG */
10557 {PCI_VENDOR_ID_INTEL
, 0x4224, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0}, /* ABG */
10559 /* required last entry */
10563 MODULE_DEVICE_TABLE(pci
, card_ids
);
10565 static struct attribute
*ipw_sysfs_entries
[] = {
10566 &dev_attr_rf_kill
.attr
,
10567 &dev_attr_direct_dword
.attr
,
10568 &dev_attr_indirect_byte
.attr
,
10569 &dev_attr_indirect_dword
.attr
,
10570 &dev_attr_mem_gpio_reg
.attr
,
10571 &dev_attr_command_event_reg
.attr
,
10572 &dev_attr_nic_type
.attr
,
10573 &dev_attr_status
.attr
,
10574 &dev_attr_cfg
.attr
,
10575 &dev_attr_dump_errors
.attr
,
10576 &dev_attr_dump_events
.attr
,
10577 &dev_attr_eeprom_delay
.attr
,
10578 &dev_attr_ucode_version
.attr
,
10579 &dev_attr_rtc
.attr
,
10580 &dev_attr_scan_age
.attr
,
10581 &dev_attr_led
.attr
,
10582 &dev_attr_speed_scan
.attr
,
10583 &dev_attr_net_stats
.attr
,
10587 static struct attribute_group ipw_attribute_group
= {
10588 .name
= NULL
, /* put in device directory */
10589 .attrs
= ipw_sysfs_entries
,
10592 static int ipw_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
10595 struct net_device
*net_dev
;
10596 void __iomem
*base
;
10598 struct ipw_priv
*priv
;
10601 net_dev
= alloc_ieee80211(sizeof(struct ipw_priv
));
10602 if (net_dev
== NULL
) {
10607 priv
= ieee80211_priv(net_dev
);
10608 priv
->ieee
= netdev_priv(net_dev
);
10610 priv
->net_dev
= net_dev
;
10611 priv
->pci_dev
= pdev
;
10612 #ifdef CONFIG_IPW_DEBUG
10613 ipw_debug_level
= debug
;
10615 spin_lock_init(&priv
->lock
);
10616 for (i
= 0; i
< IPW_IBSS_MAC_HASH_SIZE
; i
++)
10617 INIT_LIST_HEAD(&priv
->ibss_mac_hash
[i
]);
10619 init_MUTEX(&priv
->sem
);
10620 if (pci_enable_device(pdev
)) {
10622 goto out_free_ieee80211
;
10625 pci_set_master(pdev
);
10627 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
10629 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
10631 printk(KERN_WARNING DRV_NAME
": No suitable DMA available.\n");
10632 goto out_pci_disable_device
;
10635 pci_set_drvdata(pdev
, priv
);
10637 err
= pci_request_regions(pdev
, DRV_NAME
);
10639 goto out_pci_disable_device
;
10641 /* We disable the RETRY_TIMEOUT register (0x41) to keep
10642 * PCI Tx retries from interfering with C3 CPU state */
10643 pci_read_config_dword(pdev
, 0x40, &val
);
10644 if ((val
& 0x0000ff00) != 0)
10645 pci_write_config_dword(pdev
, 0x40, val
& 0xffff00ff);
10647 length
= pci_resource_len(pdev
, 0);
10648 priv
->hw_len
= length
;
10650 base
= ioremap_nocache(pci_resource_start(pdev
, 0), length
);
10653 goto out_pci_release_regions
;
10656 priv
->hw_base
= base
;
10657 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length
);
10658 IPW_DEBUG_INFO("pci_resource_base = %p\n", base
);
10660 err
= ipw_setup_deferred_work(priv
);
10662 IPW_ERROR("Unable to setup deferred work\n");
10666 ipw_sw_reset(priv
, 1);
10668 err
= request_irq(pdev
->irq
, ipw_isr
, SA_SHIRQ
, DRV_NAME
, priv
);
10670 IPW_ERROR("Error allocating IRQ %d\n", pdev
->irq
);
10671 goto out_destroy_workqueue
;
10674 SET_MODULE_OWNER(net_dev
);
10675 SET_NETDEV_DEV(net_dev
, &pdev
->dev
);
10677 ipw_wx_data
.spy_data
= &priv
->ieee
->spy_data
;
10678 ipw_wx_data
.ieee80211
= priv
->ieee
;
10682 priv
->ieee
->hard_start_xmit
= ipw_net_hard_start_xmit
;
10683 priv
->ieee
->set_security
= shim__set_security
;
10685 #ifdef CONFIG_IPW_QOS
10686 priv
->ieee
->handle_management_frame
= ipw_handle_management_frame
;
10687 #endif /* CONFIG_IPW_QOS */
10689 priv
->ieee
->perfect_rssi
= -20;
10690 priv
->ieee
->worst_rssi
= -85;
10692 net_dev
->open
= ipw_net_open
;
10693 net_dev
->stop
= ipw_net_stop
;
10694 net_dev
->init
= ipw_net_init
;
10695 #if WIRELESS_EXT < 18
10696 net_dev
->do_ioctl
= ipw_ioctl
;
10698 net_dev
->get_stats
= ipw_net_get_stats
;
10699 net_dev
->set_multicast_list
= ipw_net_set_multicast_list
;
10700 net_dev
->set_mac_address
= ipw_net_set_mac_address
;
10701 net_dev
->get_wireless_stats
= ipw_get_wireless_stats
;
10702 net_dev
->wireless_data
= &ipw_wx_data
;
10703 net_dev
->wireless_handlers
= &ipw_wx_handler_def
;
10704 net_dev
->ethtool_ops
= &ipw_ethtool_ops
;
10705 net_dev
->irq
= pdev
->irq
;
10706 net_dev
->base_addr
= (unsigned long)priv
->hw_base
;
10707 net_dev
->mem_start
= pci_resource_start(pdev
, 0);
10708 net_dev
->mem_end
= net_dev
->mem_start
+ pci_resource_len(pdev
, 0) - 1;
10710 err
= sysfs_create_group(&pdev
->dev
.kobj
, &ipw_attribute_group
);
10712 IPW_ERROR("failed to create sysfs device attributes\n");
10714 goto out_release_irq
;
10718 err
= register_netdev(net_dev
);
10720 IPW_ERROR("failed to register network device\n");
10721 goto out_remove_sysfs
;
10726 sysfs_remove_group(&pdev
->dev
.kobj
, &ipw_attribute_group
);
10728 free_irq(pdev
->irq
, priv
);
10729 out_destroy_workqueue
:
10730 destroy_workqueue(priv
->workqueue
);
10731 priv
->workqueue
= NULL
;
10733 iounmap(priv
->hw_base
);
10734 out_pci_release_regions
:
10735 pci_release_regions(pdev
);
10736 out_pci_disable_device
:
10737 pci_disable_device(pdev
);
10738 pci_set_drvdata(pdev
, NULL
);
10739 out_free_ieee80211
:
10740 free_ieee80211(priv
->net_dev
);
10745 static void ipw_pci_remove(struct pci_dev
*pdev
)
10747 struct ipw_priv
*priv
= pci_get_drvdata(pdev
);
10748 struct list_head
*p
, *q
;
10756 priv
->status
|= STATUS_EXIT_PENDING
;
10758 sysfs_remove_group(&pdev
->dev
.kobj
, &ipw_attribute_group
);
10762 unregister_netdev(priv
->net_dev
);
10765 ipw_rx_queue_free(priv
, priv
->rxq
);
10768 ipw_tx_queue_free(priv
);
10770 /* ipw_down will ensure that there is no more pending work
10771 * in the workqueue's, so we can safely remove them now. */
10772 cancel_delayed_work(&priv
->adhoc_check
);
10773 cancel_delayed_work(&priv
->gather_stats
);
10774 cancel_delayed_work(&priv
->request_scan
);
10775 cancel_delayed_work(&priv
->rf_kill
);
10776 cancel_delayed_work(&priv
->scan_check
);
10777 destroy_workqueue(priv
->workqueue
);
10778 priv
->workqueue
= NULL
;
10780 /* Free MAC hash list for ADHOC */
10781 for (i
= 0; i
< IPW_IBSS_MAC_HASH_SIZE
; i
++) {
10782 list_for_each_safe(p
, q
, &priv
->ibss_mac_hash
[i
]) {
10783 kfree(list_entry(p
, struct ipw_ibss_seq
, list
));
10788 free_irq(pdev
->irq
, priv
);
10789 iounmap(priv
->hw_base
);
10790 pci_release_regions(pdev
);
10791 pci_disable_device(pdev
);
10792 pci_set_drvdata(pdev
, NULL
);
10793 free_ieee80211(priv
->net_dev
);
10798 static int ipw_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
10800 struct ipw_priv
*priv
= pci_get_drvdata(pdev
);
10801 struct net_device
*dev
= priv
->net_dev
;
10803 printk(KERN_INFO
"%s: Going into suspend...\n", dev
->name
);
10805 /* Take down the device; powers it off, etc. */
10808 /* Remove the PRESENT state of the device */
10809 netif_device_detach(dev
);
10811 pci_save_state(pdev
);
10812 pci_disable_device(pdev
);
10813 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
10818 static int ipw_pci_resume(struct pci_dev
*pdev
)
10820 struct ipw_priv
*priv
= pci_get_drvdata(pdev
);
10821 struct net_device
*dev
= priv
->net_dev
;
10824 printk(KERN_INFO
"%s: Coming out of suspend...\n", dev
->name
);
10826 pci_set_power_state(pdev
, PCI_D0
);
10827 pci_enable_device(pdev
);
10828 pci_restore_state(pdev
);
10831 * Suspend/Resume resets the PCI configuration space, so we have to
10832 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
10833 * from interfering with C3 CPU state. pci_restore_state won't help
10834 * here since it only restores the first 64 bytes pci config header.
10836 pci_read_config_dword(pdev
, 0x40, &val
);
10837 if ((val
& 0x0000ff00) != 0)
10838 pci_write_config_dword(pdev
, 0x40, val
& 0xffff00ff);
10840 /* Set the device back into the PRESENT state; this will also wake
10841 * the queue of needed */
10842 netif_device_attach(dev
);
10844 /* Bring the device back up */
10845 queue_work(priv
->workqueue
, &priv
->up
);
10851 /* driver initialization stuff */
10852 static struct pci_driver ipw_driver
= {
10854 .id_table
= card_ids
,
10855 .probe
= ipw_pci_probe
,
10856 .remove
= __devexit_p(ipw_pci_remove
),
10858 .suspend
= ipw_pci_suspend
,
10859 .resume
= ipw_pci_resume
,
10863 static int __init
ipw_init(void)
10867 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
10868 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
10870 ret
= pci_module_init(&ipw_driver
);
10872 IPW_ERROR("Unable to initialize PCI module\n");
10876 ret
= driver_create_file(&ipw_driver
.driver
, &driver_attr_debug_level
);
10878 IPW_ERROR("Unable to create driver sysfs file\n");
10879 pci_unregister_driver(&ipw_driver
);
10886 static void __exit
ipw_exit(void)
10888 driver_remove_file(&ipw_driver
.driver
, &driver_attr_debug_level
);
10889 pci_unregister_driver(&ipw_driver
);
10892 module_param(disable
, int, 0444);
10893 MODULE_PARM_DESC(disable
, "manually disable the radio (default 0 [radio on])");
10895 module_param(associate
, int, 0444);
10896 MODULE_PARM_DESC(associate
, "auto associate when scanning (default on)");
10898 module_param(auto_create
, int, 0444);
10899 MODULE_PARM_DESC(auto_create
, "auto create adhoc network (default on)");
10901 module_param(led
, int, 0444);
10902 MODULE_PARM_DESC(led
, "enable led control on some systems (default 0 off)\n");
10904 module_param(debug
, int, 0444);
10905 MODULE_PARM_DESC(debug
, "debug output mask");
10907 module_param(channel
, int, 0444);
10908 MODULE_PARM_DESC(channel
, "channel to limit associate to (default 0 [ANY])");
10910 #ifdef CONFIG_IPW_QOS
10911 module_param(qos_enable
, int, 0444);
10912 MODULE_PARM_DESC(qos_enable
, "enable all QoS functionalitis");
10914 module_param(qos_burst_enable
, int, 0444);
10915 MODULE_PARM_DESC(qos_burst_enable
, "enable QoS burst mode");
10917 module_param(qos_no_ack_mask
, int, 0444);
10918 MODULE_PARM_DESC(qos_no_ack_mask
, "mask Tx_Queue to no ack");
10920 module_param(burst_duration_CCK
, int, 0444);
10921 MODULE_PARM_DESC(burst_duration_CCK
, "set CCK burst value");
10923 module_param(burst_duration_OFDM
, int, 0444);
10924 MODULE_PARM_DESC(burst_duration_OFDM
, "set OFDM burst value");
10925 #endif /* CONFIG_IPW_QOS */
10927 #ifdef CONFIG_IPW2200_MONITOR
10928 module_param(mode
, int, 0444);
10929 MODULE_PARM_DESC(mode
, "network mode (0=BSS,1=IBSS,2=Monitor)");
10931 module_param(mode
, int, 0444);
10932 MODULE_PARM_DESC(mode
, "network mode (0=BSS,1=IBSS)");
10935 module_param(hwcrypto
, int, 0444);
10936 MODULE_PARM_DESC(hwcrypto
, "enable hardware crypto (default on)");
10938 module_exit(ipw_exit
);
10939 module_init(ipw_init
);