1 // SPDX-License-Identifier: GPL-2.0-only
2 /******************************************************************************
3
4 Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved.
5
6 802.11 status code portion of this file from ethereal-0.10.6:
7 Copyright 2000, Axis Communications AB
8 Ethereal - Network traffic analyzer
9 By Gerald Combs <gerald@ethereal.com>
10 Copyright 1998 Gerald Combs
11
12
13 Contact Information:
14 Intel Linux Wireless <ilw@linux.intel.com>
15 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
16
17 ******************************************************************************/
18
19 #include <linux/sched.h>
20 #include <linux/slab.h>
21 #include <net/cfg80211-wext.h>
22 #include "ipw2200.h"
23 #include "ipw.h"
24
25
26 #ifndef KBUILD_EXTMOD
27 #define VK "k"
28 #else
29 #define VK
30 #endif
31
32 #ifdef CONFIG_IPW2200_DEBUG
33 #define VD "d"
34 #else
35 #define VD
36 #endif
37
38 #ifdef CONFIG_IPW2200_MONITOR
39 #define VM "m"
40 #else
41 #define VM
42 #endif
43
44 #ifdef CONFIG_IPW2200_PROMISCUOUS
45 #define VP "p"
46 #else
47 #define VP
48 #endif
49
50 #ifdef CONFIG_IPW2200_RADIOTAP
51 #define VR "r"
52 #else
53 #define VR
54 #endif
55
56 #ifdef CONFIG_IPW2200_QOS
57 #define VQ "q"
58 #else
59 #define VQ
60 #endif
61
62 #define IPW2200_VERSION "1.2.2" VK VD VM VP VR VQ
63 #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
64 #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
65 #define DRV_VERSION IPW2200_VERSION
66
67 #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
68
69 MODULE_DESCRIPTION(DRV_DESCRIPTION);
70 MODULE_VERSION(DRV_VERSION);
71 MODULE_AUTHOR(DRV_COPYRIGHT);
72 MODULE_LICENSE("GPL");
73 MODULE_FIRMWARE("ipw2200-ibss.fw");
74 #ifdef CONFIG_IPW2200_MONITOR
75 MODULE_FIRMWARE("ipw2200-sniffer.fw");
76 #endif
77 MODULE_FIRMWARE("ipw2200-bss.fw");
78
79 static int cmdlog = 0;
80 static int debug = 0;
81 static int default_channel = 0;
82 static int network_mode = 0;
83
84 static u32 ipw_debug_level;
85 static int associate;
86 static int auto_create = 1;
87 static int led_support = 1;
88 static int disable = 0;
89 static int bt_coexist = 0;
90 static int hwcrypto = 0;
91 static int roaming = 1;
92 static const char ipw_modes[] = {
93 'a', 'b', 'g', '?'
94 };
95 static int antenna = CFG_SYS_ANTENNA_BOTH;
96
97 #ifdef CONFIG_IPW2200_PROMISCUOUS
98 static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */
99 #endif
100
101 static struct ieee80211_rate ipw2200_rates[] = {
102 { .bitrate = 10 },
103 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
104 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
105 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
106 { .bitrate = 60 },
107 { .bitrate = 90 },
108 { .bitrate = 120 },
109 { .bitrate = 180 },
110 { .bitrate = 240 },
111 { .bitrate = 360 },
112 { .bitrate = 480 },
113 { .bitrate = 540 }
114 };
115
116 #define ipw2200_a_rates (ipw2200_rates + 4)
117 #define ipw2200_num_a_rates 8
118 #define ipw2200_bg_rates (ipw2200_rates + 0)
119 #define ipw2200_num_bg_rates 12
120
121 /* Ugly macro to convert literal channel numbers into their mhz equivalents
122 * There are certianly some conditions that will break this (like feeding it '30')
123 * but they shouldn't arise since nothing talks on channel 30. */
124 #define ieee80211chan2mhz(x) \
125 (((x) <= 14) ? \
126 (((x) == 14) ? 2484 : ((x) * 5) + 2407) : \
127 ((x) + 1000) * 5)
128
129 #ifdef CONFIG_IPW2200_QOS
130 static int qos_enable = 0;
131 static int qos_burst_enable = 0;
132 static int qos_no_ack_mask = 0;
133 static int burst_duration_CCK = 0;
134 static int burst_duration_OFDM = 0;
135
136 static struct libipw_qos_parameters def_qos_parameters_OFDM = {
137 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
138 QOS_TX3_CW_MIN_OFDM},
139 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
140 QOS_TX3_CW_MAX_OFDM},
141 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
142 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
143 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
144 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
145 };
146
147 static struct libipw_qos_parameters def_qos_parameters_CCK = {
148 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
149 QOS_TX3_CW_MIN_CCK},
150 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
151 QOS_TX3_CW_MAX_CCK},
152 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
153 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
154 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
155 QOS_TX3_TXOP_LIMIT_CCK}
156 };
157
158 static struct libipw_qos_parameters def_parameters_OFDM = {
159 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
160 DEF_TX3_CW_MIN_OFDM},
161 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
162 DEF_TX3_CW_MAX_OFDM},
163 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
164 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
165 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
166 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
167 };
168
169 static struct libipw_qos_parameters def_parameters_CCK = {
170 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
171 DEF_TX3_CW_MIN_CCK},
172 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
173 DEF_TX3_CW_MAX_CCK},
174 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
175 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
176 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
177 DEF_TX3_TXOP_LIMIT_CCK}
178 };
179
180 static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
181
182 static int from_priority_to_tx_queue[] = {
183 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
184 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
185 };
186
187 static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
188
189 static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
190 *qos_param);
191 static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
192 *qos_param);
193 #endif /* CONFIG_IPW2200_QOS */
194
195 static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
196 static void ipw_remove_current_network(struct ipw_priv *priv);
197 static void ipw_rx(struct ipw_priv *priv);
198 static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
199 struct clx2_tx_queue *txq, int qindex);
200 static int ipw_queue_reset(struct ipw_priv *priv);
201
202 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, const void *buf,
203 int len, int sync);
204
205 static void ipw_tx_queue_free(struct ipw_priv *);
206
207 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
208 static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
209 static void ipw_rx_queue_replenish(void *);
210 static int ipw_up(struct ipw_priv *);
211 static void ipw_bg_up(struct work_struct *work);
212 static void ipw_down(struct ipw_priv *);
213 static void ipw_bg_down(struct work_struct *work);
214 static int ipw_config(struct ipw_priv *);
215 static int init_supported_rates(struct ipw_priv *priv,
216 struct ipw_supported_rates *prates);
217 static void ipw_set_hwcrypto_keys(struct ipw_priv *);
218 static void ipw_send_wep_keys(struct ipw_priv *, int);
219
snprint_line(char * buf,size_t count,const u8 * data,u32 len,u32 ofs)220 static int snprint_line(char *buf, size_t count,
221 const u8 * data, u32 len, u32 ofs)
222 {
223 int out, i, j, l;
224 char c;
225
226 out = scnprintf(buf, count, "%08X", ofs);
227
228 for (l = 0, i = 0; i < 2; i++) {
229 out += scnprintf(buf + out, count - out, " ");
230 for (j = 0; j < 8 && l < len; j++, l++)
231 out += scnprintf(buf + out, count - out, "%02X ",
232 data[(i * 8 + j)]);
233 for (; j < 8; j++)
234 out += scnprintf(buf + out, count - out, " ");
235 }
236
237 out += scnprintf(buf + out, count - out, " ");
238 for (l = 0, i = 0; i < 2; i++) {
239 out += scnprintf(buf + out, count - out, " ");
240 for (j = 0; j < 8 && l < len; j++, l++) {
241 c = data[(i * 8 + j)];
242 if (!isascii(c) || !isprint(c))
243 c = '.';
244
245 out += scnprintf(buf + out, count - out, "%c", c);
246 }
247
248 for (; j < 8; j++)
249 out += scnprintf(buf + out, count - out, " ");
250 }
251
252 return out;
253 }
254
printk_buf(int level,const u8 * data,u32 len)255 static void printk_buf(int level, const u8 * data, u32 len)
256 {
257 char line[81];
258 u32 ofs = 0;
259 if (!(ipw_debug_level & level))
260 return;
261
262 while (len) {
263 snprint_line(line, sizeof(line), &data[ofs],
264 min(len, 16U), ofs);
265 printk(KERN_DEBUG "%s\n", line);
266 ofs += 16;
267 len -= min(len, 16U);
268 }
269 }
270
snprintk_buf(u8 * output,size_t size,const u8 * data,size_t len)271 static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
272 {
273 size_t out = size;
274 u32 ofs = 0;
275 int total = 0;
276
277 while (size && len) {
278 out = snprint_line(output, size, &data[ofs],
279 min_t(size_t, len, 16U), ofs);
280
281 ofs += 16;
282 output += out;
283 size -= out;
284 len -= min_t(size_t, len, 16U);
285 total += out;
286 }
287 return total;
288 }
289
290 /* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
291 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
292 #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
293
294 /* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
295 static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
296 #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
297
298 /* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
299 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
ipw_write_reg8(struct ipw_priv * a,u32 b,u8 c)300 static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
301 {
302 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
303 __LINE__, (u32) (b), (u32) (c));
304 _ipw_write_reg8(a, b, c);
305 }
306
307 /* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
308 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
ipw_write_reg16(struct ipw_priv * a,u32 b,u16 c)309 static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
310 {
311 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
312 __LINE__, (u32) (b), (u32) (c));
313 _ipw_write_reg16(a, b, c);
314 }
315
316 /* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
317 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
ipw_write_reg32(struct ipw_priv * a,u32 b,u32 c)318 static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
319 {
320 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
321 __LINE__, (u32) (b), (u32) (c));
322 _ipw_write_reg32(a, b, c);
323 }
324
325 /* 8-bit direct write (low 4K) */
_ipw_write8(struct ipw_priv * ipw,unsigned long ofs,u8 val)326 static inline void _ipw_write8(struct ipw_priv *ipw, unsigned long ofs,
327 u8 val)
328 {
329 writeb(val, ipw->hw_base + ofs);
330 }
331
332 /* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
333 #define ipw_write8(ipw, ofs, val) do { \
334 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, \
335 __LINE__, (u32)(ofs), (u32)(val)); \
336 _ipw_write8(ipw, ofs, val); \
337 } while (0)
338
339 /* 16-bit direct write (low 4K) */
_ipw_write16(struct ipw_priv * ipw,unsigned long ofs,u16 val)340 static inline void _ipw_write16(struct ipw_priv *ipw, unsigned long ofs,
341 u16 val)
342 {
343 writew(val, ipw->hw_base + ofs);
344 }
345
346 /* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
347 #define ipw_write16(ipw, ofs, val) do { \
348 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, \
349 __LINE__, (u32)(ofs), (u32)(val)); \
350 _ipw_write16(ipw, ofs, val); \
351 } while (0)
352
353 /* 32-bit direct write (low 4K) */
_ipw_write32(struct ipw_priv * ipw,unsigned long ofs,u32 val)354 static inline void _ipw_write32(struct ipw_priv *ipw, unsigned long ofs,
355 u32 val)
356 {
357 writel(val, ipw->hw_base + ofs);
358 }
359
360 /* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
361 #define ipw_write32(ipw, ofs, val) do { \
362 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, \
363 __LINE__, (u32)(ofs), (u32)(val)); \
364 _ipw_write32(ipw, ofs, val); \
365 } while (0)
366
367 /* 8-bit direct read (low 4K) */
_ipw_read8(struct ipw_priv * ipw,unsigned long ofs)368 static inline u8 _ipw_read8(struct ipw_priv *ipw, unsigned long ofs)
369 {
370 return readb(ipw->hw_base + ofs);
371 }
372
373 /* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
374 #define ipw_read8(ipw, ofs) ({ \
375 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", __FILE__, __LINE__, \
376 (u32)(ofs)); \
377 _ipw_read8(ipw, ofs); \
378 })
379
380 /* 32-bit direct read (low 4K) */
_ipw_read32(struct ipw_priv * ipw,unsigned long ofs)381 static inline u32 _ipw_read32(struct ipw_priv *ipw, unsigned long ofs)
382 {
383 return readl(ipw->hw_base + ofs);
384 }
385
386 /* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
387 #define ipw_read32(ipw, ofs) ({ \
388 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", __FILE__, __LINE__, \
389 (u32)(ofs)); \
390 _ipw_read32(ipw, ofs); \
391 })
392
393 static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
394 /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
395 #define ipw_read_indirect(a, b, c, d) ({ \
396 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %u bytes\n", __FILE__, \
397 __LINE__, (u32)(b), (u32)(d)); \
398 _ipw_read_indirect(a, b, c, d); \
399 })
400
401 /* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
402 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
403 int num);
404 #define ipw_write_indirect(a, b, c, d) do { \
405 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %u bytes\n", __FILE__, \
406 __LINE__, (u32)(b), (u32)(d)); \
407 _ipw_write_indirect(a, b, c, d); \
408 } while (0)
409
410 /* 32-bit indirect write (above 4K) */
_ipw_write_reg32(struct ipw_priv * priv,u32 reg,u32 value)411 static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
412 {
413 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
414 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
415 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
416 }
417
418 /* 8-bit indirect write (above 4K) */
_ipw_write_reg8(struct ipw_priv * priv,u32 reg,u8 value)419 static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
420 {
421 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
422 u32 dif_len = reg - aligned_addr;
423
424 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
425 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
426 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
427 }
428
429 /* 16-bit indirect write (above 4K) */
_ipw_write_reg16(struct ipw_priv * priv,u32 reg,u16 value)430 static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
431 {
432 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
433 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
434
435 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
436 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
437 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
438 }
439
440 /* 8-bit indirect read (above 4K) */
_ipw_read_reg8(struct ipw_priv * priv,u32 reg)441 static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
442 {
443 u32 word;
444 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
445 IPW_DEBUG_IO(" reg = 0x%8X :\n", reg);
446 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
447 return (word >> ((reg & 0x3) * 8)) & 0xff;
448 }
449
450 /* 32-bit indirect read (above 4K) */
_ipw_read_reg32(struct ipw_priv * priv,u32 reg)451 static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
452 {
453 u32 value;
454
455 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
456
457 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
458 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
459 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x\n", reg, value);
460 return value;
461 }
462
463 /* General purpose, no alignment requirement, iterative (multi-byte) read, */
464 /* for area above 1st 4K of SRAM/reg space */
_ipw_read_indirect(struct ipw_priv * priv,u32 addr,u8 * buf,int num)465 static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
466 int num)
467 {
468 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
469 u32 dif_len = addr - aligned_addr;
470 u32 i;
471
472 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
473
474 if (num <= 0) {
475 return;
476 }
477
478 /* Read the first dword (or portion) byte by byte */
479 if (unlikely(dif_len)) {
480 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
481 /* Start reading at aligned_addr + dif_len */
482 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
483 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
484 aligned_addr += 4;
485 }
486
487 /* Read all of the middle dwords as dwords, with auto-increment */
488 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
489 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
490 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
491
492 /* Read the last dword (or portion) byte by byte */
493 if (unlikely(num)) {
494 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
495 for (i = 0; num > 0; i++, num--)
496 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
497 }
498 }
499
500 /* General purpose, no alignment requirement, iterative (multi-byte) write, */
501 /* for area above 1st 4K of SRAM/reg space */
_ipw_write_indirect(struct ipw_priv * priv,u32 addr,u8 * buf,int num)502 static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
503 int num)
504 {
505 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
506 u32 dif_len = addr - aligned_addr;
507 u32 i;
508
509 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
510
511 if (num <= 0) {
512 return;
513 }
514
515 /* Write the first dword (or portion) byte by byte */
516 if (unlikely(dif_len)) {
517 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
518 /* Start writing at aligned_addr + dif_len */
519 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
520 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
521 aligned_addr += 4;
522 }
523
524 /* Write all of the middle dwords as dwords, with auto-increment */
525 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
526 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
527 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
528
529 /* Write the last dword (or portion) byte by byte */
530 if (unlikely(num)) {
531 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
532 for (i = 0; num > 0; i++, num--, buf++)
533 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
534 }
535 }
536
537 /* General purpose, no alignment requirement, iterative (multi-byte) write, */
538 /* for 1st 4K of SRAM/regs space */
ipw_write_direct(struct ipw_priv * priv,u32 addr,void * buf,int num)539 static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
540 int num)
541 {
542 memcpy_toio((priv->hw_base + addr), buf, num);
543 }
544
545 /* Set bit(s) in low 4K of SRAM/regs */
ipw_set_bit(struct ipw_priv * priv,u32 reg,u32 mask)546 static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
547 {
548 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
549 }
550
551 /* Clear bit(s) in low 4K of SRAM/regs */
ipw_clear_bit(struct ipw_priv * priv,u32 reg,u32 mask)552 static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
553 {
554 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
555 }
556
__ipw_enable_interrupts(struct ipw_priv * priv)557 static inline void __ipw_enable_interrupts(struct ipw_priv *priv)
558 {
559 if (priv->status & STATUS_INT_ENABLED)
560 return;
561 priv->status |= STATUS_INT_ENABLED;
562 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
563 }
564
__ipw_disable_interrupts(struct ipw_priv * priv)565 static inline void __ipw_disable_interrupts(struct ipw_priv *priv)
566 {
567 if (!(priv->status & STATUS_INT_ENABLED))
568 return;
569 priv->status &= ~STATUS_INT_ENABLED;
570 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
571 }
572
ipw_enable_interrupts(struct ipw_priv * priv)573 static inline void ipw_enable_interrupts(struct ipw_priv *priv)
574 {
575 unsigned long flags;
576
577 spin_lock_irqsave(&priv->irq_lock, flags);
578 __ipw_enable_interrupts(priv);
579 spin_unlock_irqrestore(&priv->irq_lock, flags);
580 }
581
ipw_disable_interrupts(struct ipw_priv * priv)582 static inline void ipw_disable_interrupts(struct ipw_priv *priv)
583 {
584 unsigned long flags;
585
586 spin_lock_irqsave(&priv->irq_lock, flags);
587 __ipw_disable_interrupts(priv);
588 spin_unlock_irqrestore(&priv->irq_lock, flags);
589 }
590
ipw_error_desc(u32 val)591 static char *ipw_error_desc(u32 val)
592 {
593 switch (val) {
594 case IPW_FW_ERROR_OK:
595 return "ERROR_OK";
596 case IPW_FW_ERROR_FAIL:
597 return "ERROR_FAIL";
598 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
599 return "MEMORY_UNDERFLOW";
600 case IPW_FW_ERROR_MEMORY_OVERFLOW:
601 return "MEMORY_OVERFLOW";
602 case IPW_FW_ERROR_BAD_PARAM:
603 return "BAD_PARAM";
604 case IPW_FW_ERROR_BAD_CHECKSUM:
605 return "BAD_CHECKSUM";
606 case IPW_FW_ERROR_NMI_INTERRUPT:
607 return "NMI_INTERRUPT";
608 case IPW_FW_ERROR_BAD_DATABASE:
609 return "BAD_DATABASE";
610 case IPW_FW_ERROR_ALLOC_FAIL:
611 return "ALLOC_FAIL";
612 case IPW_FW_ERROR_DMA_UNDERRUN:
613 return "DMA_UNDERRUN";
614 case IPW_FW_ERROR_DMA_STATUS:
615 return "DMA_STATUS";
616 case IPW_FW_ERROR_DINO_ERROR:
617 return "DINO_ERROR";
618 case IPW_FW_ERROR_EEPROM_ERROR:
619 return "EEPROM_ERROR";
620 case IPW_FW_ERROR_SYSASSERT:
621 return "SYSASSERT";
622 case IPW_FW_ERROR_FATAL_ERROR:
623 return "FATAL_ERROR";
624 default:
625 return "UNKNOWN_ERROR";
626 }
627 }
628
ipw_dump_error_log(struct ipw_priv * priv,struct ipw_fw_error * error)629 static void ipw_dump_error_log(struct ipw_priv *priv,
630 struct ipw_fw_error *error)
631 {
632 u32 i;
633
634 if (!error) {
635 IPW_ERROR("Error allocating and capturing error log. "
636 "Nothing to dump.\n");
637 return;
638 }
639
640 IPW_ERROR("Start IPW Error Log Dump:\n");
641 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
642 error->status, error->config);
643
644 for (i = 0; i < error->elem_len; i++)
645 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
646 ipw_error_desc(error->elem[i].desc),
647 error->elem[i].time,
648 error->elem[i].blink1,
649 error->elem[i].blink2,
650 error->elem[i].link1,
651 error->elem[i].link2, error->elem[i].data);
652 for (i = 0; i < error->log_len; i++)
653 IPW_ERROR("%i\t0x%08x\t%i\n",
654 error->log[i].time,
655 error->log[i].data, error->log[i].event);
656 }
657
ipw_is_init(struct ipw_priv * priv)658 static inline int ipw_is_init(struct ipw_priv *priv)
659 {
660 return (priv->status & STATUS_INIT) ? 1 : 0;
661 }
662
ipw_get_ordinal(struct ipw_priv * priv,u32 ord,void * val,u32 * len)663 static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
664 {
665 u32 addr, field_info, field_len, field_count, total_len;
666
667 IPW_DEBUG_ORD("ordinal = %i\n", ord);
668
669 if (!priv || !val || !len) {
670 IPW_DEBUG_ORD("Invalid argument\n");
671 return -EINVAL;
672 }
673
674 /* verify device ordinal tables have been initialized */
675 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
676 IPW_DEBUG_ORD("Access ordinals before initialization\n");
677 return -EINVAL;
678 }
679
680 switch (IPW_ORD_TABLE_ID_MASK & ord) {
681 case IPW_ORD_TABLE_0_MASK:
682 /*
683 * TABLE 0: Direct access to a table of 32 bit values
684 *
685 * This is a very simple table with the data directly
686 * read from the table
687 */
688
689 /* remove the table id from the ordinal */
690 ord &= IPW_ORD_TABLE_VALUE_MASK;
691
692 /* boundary check */
693 if (ord > priv->table0_len) {
694 IPW_DEBUG_ORD("ordinal value (%i) longer then "
695 "max (%i)\n", ord, priv->table0_len);
696 return -EINVAL;
697 }
698
699 /* verify we have enough room to store the value */
700 if (*len < sizeof(u32)) {
701 IPW_DEBUG_ORD("ordinal buffer length too small, "
702 "need %zd\n", sizeof(u32));
703 return -EINVAL;
704 }
705
706 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
707 ord, priv->table0_addr + (ord << 2));
708
709 *len = sizeof(u32);
710 ord <<= 2;
711 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
712 break;
713
714 case IPW_ORD_TABLE_1_MASK:
715 /*
716 * TABLE 1: Indirect access to a table of 32 bit values
717 *
718 * This is a fairly large table of u32 values each
719 * representing starting addr for the data (which is
720 * also a u32)
721 */
722
723 /* remove the table id from the ordinal */
724 ord &= IPW_ORD_TABLE_VALUE_MASK;
725
726 /* boundary check */
727 if (ord > priv->table1_len) {
728 IPW_DEBUG_ORD("ordinal value too long\n");
729 return -EINVAL;
730 }
731
732 /* verify we have enough room to store the value */
733 if (*len < sizeof(u32)) {
734 IPW_DEBUG_ORD("ordinal buffer length too small, "
735 "need %zd\n", sizeof(u32));
736 return -EINVAL;
737 }
738
739 *((u32 *) val) =
740 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
741 *len = sizeof(u32);
742 break;
743
744 case IPW_ORD_TABLE_2_MASK:
745 /*
746 * TABLE 2: Indirect access to a table of variable sized values
747 *
748 * This table consist of six values, each containing
749 * - dword containing the starting offset of the data
750 * - dword containing the lengh in the first 16bits
751 * and the count in the second 16bits
752 */
753
754 /* remove the table id from the ordinal */
755 ord &= IPW_ORD_TABLE_VALUE_MASK;
756
757 /* boundary check */
758 if (ord > priv->table2_len) {
759 IPW_DEBUG_ORD("ordinal value too long\n");
760 return -EINVAL;
761 }
762
763 /* get the address of statistic */
764 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
765
766 /* get the second DW of statistics ;
767 * two 16-bit words - first is length, second is count */
768 field_info =
769 ipw_read_reg32(priv,
770 priv->table2_addr + (ord << 3) +
771 sizeof(u32));
772
773 /* get each entry length */
774 field_len = *((u16 *) & field_info);
775
776 /* get number of entries */
777 field_count = *(((u16 *) & field_info) + 1);
778
779 /* abort if not enough memory */
780 total_len = field_len * field_count;
781 if (total_len > *len) {
782 *len = total_len;
783 return -EINVAL;
784 }
785
786 *len = total_len;
787 if (!total_len)
788 return 0;
789
790 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
791 "field_info = 0x%08x\n",
792 addr, total_len, field_info);
793 ipw_read_indirect(priv, addr, val, total_len);
794 break;
795
796 default:
797 IPW_DEBUG_ORD("Invalid ordinal!\n");
798 return -EINVAL;
799
800 }
801
802 return 0;
803 }
804
ipw_init_ordinals(struct ipw_priv * priv)805 static void ipw_init_ordinals(struct ipw_priv *priv)
806 {
807 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
808 priv->table0_len = ipw_read32(priv, priv->table0_addr);
809
810 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
811 priv->table0_addr, priv->table0_len);
812
813 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
814 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
815
816 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
817 priv->table1_addr, priv->table1_len);
818
819 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
820 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
821 priv->table2_len &= 0x0000ffff; /* use first two bytes */
822
823 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
824 priv->table2_addr, priv->table2_len);
825
826 }
827
ipw_register_toggle(u32 reg)828 static u32 ipw_register_toggle(u32 reg)
829 {
830 reg &= ~IPW_START_STANDBY;
831 if (reg & IPW_GATE_ODMA)
832 reg &= ~IPW_GATE_ODMA;
833 if (reg & IPW_GATE_IDMA)
834 reg &= ~IPW_GATE_IDMA;
835 if (reg & IPW_GATE_ADMA)
836 reg &= ~IPW_GATE_ADMA;
837 return reg;
838 }
839
840 /*
841 * LED behavior:
842 * - On radio ON, turn on any LEDs that require to be on during start
843 * - On initialization, start unassociated blink
844 * - On association, disable unassociated blink
845 * - On disassociation, start unassociated blink
846 * - On radio OFF, turn off any LEDs started during radio on
847 *
848 */
849 #define LD_TIME_LINK_ON msecs_to_jiffies(300)
850 #define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
851 #define LD_TIME_ACT_ON msecs_to_jiffies(250)
852
ipw_led_link_on(struct ipw_priv * priv)853 static void ipw_led_link_on(struct ipw_priv *priv)
854 {
855 unsigned long flags;
856 u32 led;
857
858 /* If configured to not use LEDs, or nic_type is 1,
859 * then we don't toggle a LINK led */
860 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
861 return;
862
863 spin_lock_irqsave(&priv->lock, flags);
864
865 if (!(priv->status & STATUS_RF_KILL_MASK) &&
866 !(priv->status & STATUS_LED_LINK_ON)) {
867 IPW_DEBUG_LED("Link LED On\n");
868 led = ipw_read_reg32(priv, IPW_EVENT_REG);
869 led |= priv->led_association_on;
870
871 led = ipw_register_toggle(led);
872
873 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
874 ipw_write_reg32(priv, IPW_EVENT_REG, led);
875
876 priv->status |= STATUS_LED_LINK_ON;
877
878 /* If we aren't associated, schedule turning the LED off */
879 if (!(priv->status & STATUS_ASSOCIATED))
880 schedule_delayed_work(&priv->led_link_off,
881 LD_TIME_LINK_ON);
882 }
883
884 spin_unlock_irqrestore(&priv->lock, flags);
885 }
886
ipw_bg_led_link_on(struct work_struct * work)887 static void ipw_bg_led_link_on(struct work_struct *work)
888 {
889 struct ipw_priv *priv =
890 container_of(work, struct ipw_priv, led_link_on.work);
891 mutex_lock(&priv->mutex);
892 ipw_led_link_on(priv);
893 mutex_unlock(&priv->mutex);
894 }
895
ipw_led_link_off(struct ipw_priv * priv)896 static void ipw_led_link_off(struct ipw_priv *priv)
897 {
898 unsigned long flags;
899 u32 led;
900
901 /* If configured not to use LEDs, or nic type is 1,
902 * then we don't goggle the LINK led. */
903 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
904 return;
905
906 spin_lock_irqsave(&priv->lock, flags);
907
908 if (priv->status & STATUS_LED_LINK_ON) {
909 led = ipw_read_reg32(priv, IPW_EVENT_REG);
910 led &= priv->led_association_off;
911 led = ipw_register_toggle(led);
912
913 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
914 ipw_write_reg32(priv, IPW_EVENT_REG, led);
915
916 IPW_DEBUG_LED("Link LED Off\n");
917
918 priv->status &= ~STATUS_LED_LINK_ON;
919
920 /* If we aren't associated and the radio is on, schedule
921 * turning the LED on (blink while unassociated) */
922 if (!(priv->status & STATUS_RF_KILL_MASK) &&
923 !(priv->status & STATUS_ASSOCIATED))
924 schedule_delayed_work(&priv->led_link_on,
925 LD_TIME_LINK_OFF);
926
927 }
928
929 spin_unlock_irqrestore(&priv->lock, flags);
930 }
931
ipw_bg_led_link_off(struct work_struct * work)932 static void ipw_bg_led_link_off(struct work_struct *work)
933 {
934 struct ipw_priv *priv =
935 container_of(work, struct ipw_priv, led_link_off.work);
936 mutex_lock(&priv->mutex);
937 ipw_led_link_off(priv);
938 mutex_unlock(&priv->mutex);
939 }
940
__ipw_led_activity_on(struct ipw_priv * priv)941 static void __ipw_led_activity_on(struct ipw_priv *priv)
942 {
943 u32 led;
944
945 if (priv->config & CFG_NO_LED)
946 return;
947
948 if (priv->status & STATUS_RF_KILL_MASK)
949 return;
950
951 if (!(priv->status & STATUS_LED_ACT_ON)) {
952 led = ipw_read_reg32(priv, IPW_EVENT_REG);
953 led |= priv->led_activity_on;
954
955 led = ipw_register_toggle(led);
956
957 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
958 ipw_write_reg32(priv, IPW_EVENT_REG, led);
959
960 IPW_DEBUG_LED("Activity LED On\n");
961
962 priv->status |= STATUS_LED_ACT_ON;
963
964 cancel_delayed_work(&priv->led_act_off);
965 schedule_delayed_work(&priv->led_act_off, LD_TIME_ACT_ON);
966 } else {
967 /* Reschedule LED off for full time period */
968 cancel_delayed_work(&priv->led_act_off);
969 schedule_delayed_work(&priv->led_act_off, LD_TIME_ACT_ON);
970 }
971 }
972
973 #if 0
974 void ipw_led_activity_on(struct ipw_priv *priv)
975 {
976 unsigned long flags;
977 spin_lock_irqsave(&priv->lock, flags);
978 __ipw_led_activity_on(priv);
979 spin_unlock_irqrestore(&priv->lock, flags);
980 }
981 #endif /* 0 */
982
ipw_led_activity_off(struct ipw_priv * priv)983 static void ipw_led_activity_off(struct ipw_priv *priv)
984 {
985 unsigned long flags;
986 u32 led;
987
988 if (priv->config & CFG_NO_LED)
989 return;
990
991 spin_lock_irqsave(&priv->lock, flags);
992
993 if (priv->status & STATUS_LED_ACT_ON) {
994 led = ipw_read_reg32(priv, IPW_EVENT_REG);
995 led &= priv->led_activity_off;
996
997 led = ipw_register_toggle(led);
998
999 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
1000 ipw_write_reg32(priv, IPW_EVENT_REG, led);
1001
1002 IPW_DEBUG_LED("Activity LED Off\n");
1003
1004 priv->status &= ~STATUS_LED_ACT_ON;
1005 }
1006
1007 spin_unlock_irqrestore(&priv->lock, flags);
1008 }
1009
ipw_bg_led_activity_off(struct work_struct * work)1010 static void ipw_bg_led_activity_off(struct work_struct *work)
1011 {
1012 struct ipw_priv *priv =
1013 container_of(work, struct ipw_priv, led_act_off.work);
1014 mutex_lock(&priv->mutex);
1015 ipw_led_activity_off(priv);
1016 mutex_unlock(&priv->mutex);
1017 }
1018
ipw_led_band_on(struct ipw_priv * priv)1019 static void ipw_led_band_on(struct ipw_priv *priv)
1020 {
1021 unsigned long flags;
1022 u32 led;
1023
1024 /* Only nic type 1 supports mode LEDs */
1025 if (priv->config & CFG_NO_LED ||
1026 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
1027 return;
1028
1029 spin_lock_irqsave(&priv->lock, flags);
1030
1031 led = ipw_read_reg32(priv, IPW_EVENT_REG);
1032 if (priv->assoc_network->mode == IEEE_A) {
1033 led |= priv->led_ofdm_on;
1034 led &= priv->led_association_off;
1035 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
1036 } else if (priv->assoc_network->mode == IEEE_G) {
1037 led |= priv->led_ofdm_on;
1038 led |= priv->led_association_on;
1039 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
1040 } else {
1041 led &= priv->led_ofdm_off;
1042 led |= priv->led_association_on;
1043 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
1044 }
1045
1046 led = ipw_register_toggle(led);
1047
1048 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
1049 ipw_write_reg32(priv, IPW_EVENT_REG, led);
1050
1051 spin_unlock_irqrestore(&priv->lock, flags);
1052 }
1053
ipw_led_band_off(struct ipw_priv * priv)1054 static void ipw_led_band_off(struct ipw_priv *priv)
1055 {
1056 unsigned long flags;
1057 u32 led;
1058
1059 /* Only nic type 1 supports mode LEDs */
1060 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
1061 return;
1062
1063 spin_lock_irqsave(&priv->lock, flags);
1064
1065 led = ipw_read_reg32(priv, IPW_EVENT_REG);
1066 led &= priv->led_ofdm_off;
1067 led &= priv->led_association_off;
1068
1069 led = ipw_register_toggle(led);
1070
1071 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
1072 ipw_write_reg32(priv, IPW_EVENT_REG, led);
1073
1074 spin_unlock_irqrestore(&priv->lock, flags);
1075 }
1076
ipw_led_radio_on(struct ipw_priv * priv)1077 static void ipw_led_radio_on(struct ipw_priv *priv)
1078 {
1079 ipw_led_link_on(priv);
1080 }
1081
ipw_led_radio_off(struct ipw_priv * priv)1082 static void ipw_led_radio_off(struct ipw_priv *priv)
1083 {
1084 ipw_led_activity_off(priv);
1085 ipw_led_link_off(priv);
1086 }
1087
ipw_led_link_up(struct ipw_priv * priv)1088 static void ipw_led_link_up(struct ipw_priv *priv)
1089 {
1090 /* Set the Link Led on for all nic types */
1091 ipw_led_link_on(priv);
1092 }
1093
ipw_led_link_down(struct ipw_priv * priv)1094 static void ipw_led_link_down(struct ipw_priv *priv)
1095 {
1096 ipw_led_activity_off(priv);
1097 ipw_led_link_off(priv);
1098
1099 if (priv->status & STATUS_RF_KILL_MASK)
1100 ipw_led_radio_off(priv);
1101 }
1102
ipw_led_init(struct ipw_priv * priv)1103 static void ipw_led_init(struct ipw_priv *priv)
1104 {
1105 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1106
1107 /* Set the default PINs for the link and activity leds */
1108 priv->led_activity_on = IPW_ACTIVITY_LED;
1109 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
1110
1111 priv->led_association_on = IPW_ASSOCIATED_LED;
1112 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
1113
1114 /* Set the default PINs for the OFDM leds */
1115 priv->led_ofdm_on = IPW_OFDM_LED;
1116 priv->led_ofdm_off = ~(IPW_OFDM_LED);
1117
1118 switch (priv->nic_type) {
1119 case EEPROM_NIC_TYPE_1:
1120 /* In this NIC type, the LEDs are reversed.... */
1121 priv->led_activity_on = IPW_ASSOCIATED_LED;
1122 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1123 priv->led_association_on = IPW_ACTIVITY_LED;
1124 priv->led_association_off = ~(IPW_ACTIVITY_LED);
1125
1126 if (!(priv->config & CFG_NO_LED))
1127 ipw_led_band_on(priv);
1128
1129 /* And we don't blink link LEDs for this nic, so
1130 * just return here */
1131 return;
1132
1133 case EEPROM_NIC_TYPE_3:
1134 case EEPROM_NIC_TYPE_2:
1135 case EEPROM_NIC_TYPE_4:
1136 case EEPROM_NIC_TYPE_0:
1137 break;
1138
1139 default:
1140 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1141 priv->nic_type);
1142 priv->nic_type = EEPROM_NIC_TYPE_0;
1143 break;
1144 }
1145
1146 if (!(priv->config & CFG_NO_LED)) {
1147 if (priv->status & STATUS_ASSOCIATED)
1148 ipw_led_link_on(priv);
1149 else
1150 ipw_led_link_off(priv);
1151 }
1152 }
1153
ipw_led_shutdown(struct ipw_priv * priv)1154 static void ipw_led_shutdown(struct ipw_priv *priv)
1155 {
1156 ipw_led_activity_off(priv);
1157 ipw_led_link_off(priv);
1158 ipw_led_band_off(priv);
1159 cancel_delayed_work(&priv->led_link_on);
1160 cancel_delayed_work(&priv->led_link_off);
1161 cancel_delayed_work(&priv->led_act_off);
1162 }
1163
1164 /*
1165 * The following adds a new attribute to the sysfs representation
1166 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1167 * used for controlling the debug level.
1168 *
1169 * See the level definitions in ipw for details.
1170 */
debug_level_show(struct device_driver * d,char * buf)1171 static ssize_t debug_level_show(struct device_driver *d, char *buf)
1172 {
1173 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1174 }
1175
debug_level_store(struct device_driver * d,const char * buf,size_t count)1176 static ssize_t debug_level_store(struct device_driver *d, const char *buf,
1177 size_t count)
1178 {
1179 unsigned long val;
1180
1181 int result = kstrtoul(buf, 0, &val);
1182
1183 if (result == -EINVAL)
1184 printk(KERN_INFO DRV_NAME
1185 ": %s is not in hex or decimal form.\n", buf);
1186 else if (result == -ERANGE)
1187 printk(KERN_INFO DRV_NAME
1188 ": %s has overflowed.\n", buf);
1189 else
1190 ipw_debug_level = val;
1191
1192 return count;
1193 }
1194 static DRIVER_ATTR_RW(debug_level);
1195
ipw_get_event_log_len(struct ipw_priv * priv)1196 static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1197 {
1198 /* length = 1st dword in log */
1199 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1200 }
1201
ipw_capture_event_log(struct ipw_priv * priv,u32 log_len,struct ipw_event * log)1202 static void ipw_capture_event_log(struct ipw_priv *priv,
1203 u32 log_len, struct ipw_event *log)
1204 {
1205 u32 base;
1206
1207 if (log_len) {
1208 base = ipw_read32(priv, IPW_EVENT_LOG);
1209 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1210 (u8 *) log, sizeof(*log) * log_len);
1211 }
1212 }
1213
ipw_alloc_error_log(struct ipw_priv * priv)1214 static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1215 {
1216 struct ipw_fw_error *error;
1217 u32 log_len = ipw_get_event_log_len(priv);
1218 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1219 u32 elem_len = ipw_read_reg32(priv, base);
1220
1221 error = kmalloc(size_add(struct_size(error, elem, elem_len),
1222 array_size(sizeof(*error->log), log_len)),
1223 GFP_ATOMIC);
1224 if (!error) {
1225 IPW_ERROR("Memory allocation for firmware error log "
1226 "failed.\n");
1227 return NULL;
1228 }
1229 error->jiffies = jiffies;
1230 error->status = priv->status;
1231 error->config = priv->config;
1232 error->elem_len = elem_len;
1233 error->log_len = log_len;
1234 error->log = (struct ipw_event *)(error->elem + elem_len);
1235
1236 ipw_capture_event_log(priv, log_len, error->log);
1237
1238 if (elem_len)
1239 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1240 sizeof(*error->elem) * elem_len);
1241
1242 return error;
1243 }
1244
event_log_show(struct device * d,struct device_attribute * attr,char * buf)1245 static ssize_t event_log_show(struct device *d,
1246 struct device_attribute *attr, char *buf)
1247 {
1248 struct ipw_priv *priv = dev_get_drvdata(d);
1249 u32 log_len = ipw_get_event_log_len(priv);
1250 u32 log_size;
1251 struct ipw_event *log;
1252 u32 len = 0, i;
1253
1254 /* not using min() because of its strict type checking */
1255 log_size = PAGE_SIZE / sizeof(*log) > log_len ?
1256 sizeof(*log) * log_len : PAGE_SIZE;
1257 log = kzalloc(log_size, GFP_KERNEL);
1258 if (!log) {
1259 IPW_ERROR("Unable to allocate memory for log\n");
1260 return 0;
1261 }
1262 log_len = log_size / sizeof(*log);
1263 ipw_capture_event_log(priv, log_len, log);
1264
1265 len += scnprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1266 for (i = 0; i < log_len; i++)
1267 len += scnprintf(buf + len, PAGE_SIZE - len,
1268 "\n%08X%08X%08X",
1269 log[i].time, log[i].event, log[i].data);
1270 len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
1271 kfree(log);
1272 return len;
1273 }
1274
1275 static DEVICE_ATTR_RO(event_log);
1276
error_show(struct device * d,struct device_attribute * attr,char * buf)1277 static ssize_t error_show(struct device *d,
1278 struct device_attribute *attr, char *buf)
1279 {
1280 struct ipw_priv *priv = dev_get_drvdata(d);
1281 u32 len = 0, i;
1282 if (!priv->error)
1283 return 0;
1284 len += scnprintf(buf + len, PAGE_SIZE - len,
1285 "%08lX%08X%08X%08X",
1286 priv->error->jiffies,
1287 priv->error->status,
1288 priv->error->config, priv->error->elem_len);
1289 for (i = 0; i < priv->error->elem_len; i++)
1290 len += scnprintf(buf + len, PAGE_SIZE - len,
1291 "\n%08X%08X%08X%08X%08X%08X%08X",
1292 priv->error->elem[i].time,
1293 priv->error->elem[i].desc,
1294 priv->error->elem[i].blink1,
1295 priv->error->elem[i].blink2,
1296 priv->error->elem[i].link1,
1297 priv->error->elem[i].link2,
1298 priv->error->elem[i].data);
1299
1300 len += scnprintf(buf + len, PAGE_SIZE - len,
1301 "\n%08X", priv->error->log_len);
1302 for (i = 0; i < priv->error->log_len; i++)
1303 len += scnprintf(buf + len, PAGE_SIZE - len,
1304 "\n%08X%08X%08X",
1305 priv->error->log[i].time,
1306 priv->error->log[i].event,
1307 priv->error->log[i].data);
1308 len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
1309 return len;
1310 }
1311
error_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)1312 static ssize_t error_store(struct device *d,
1313 struct device_attribute *attr,
1314 const char *buf, size_t count)
1315 {
1316 struct ipw_priv *priv = dev_get_drvdata(d);
1317
1318 kfree(priv->error);
1319 priv->error = NULL;
1320 return count;
1321 }
1322
1323 static DEVICE_ATTR_RW(error);
1324
cmd_log_show(struct device * d,struct device_attribute * attr,char * buf)1325 static ssize_t cmd_log_show(struct device *d,
1326 struct device_attribute *attr, char *buf)
1327 {
1328 struct ipw_priv *priv = dev_get_drvdata(d);
1329 u32 len = 0, i;
1330 if (!priv->cmdlog)
1331 return 0;
1332 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1333 (i != priv->cmdlog_pos) && (len < PAGE_SIZE);
1334 i = (i + 1) % priv->cmdlog_len) {
1335 len +=
1336 scnprintf(buf + len, PAGE_SIZE - len,
1337 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1338 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1339 priv->cmdlog[i].cmd.len);
1340 len +=
1341 snprintk_buf(buf + len, PAGE_SIZE - len,
1342 (u8 *) priv->cmdlog[i].cmd.param,
1343 priv->cmdlog[i].cmd.len);
1344 len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
1345 }
1346 len += scnprintf(buf + len, PAGE_SIZE - len, "\n");
1347 return len;
1348 }
1349
1350 static DEVICE_ATTR_RO(cmd_log);
1351
1352 #ifdef CONFIG_IPW2200_PROMISCUOUS
1353 static void ipw_prom_free(struct ipw_priv *priv);
1354 static int ipw_prom_alloc(struct ipw_priv *priv);
rtap_iface_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)1355 static ssize_t rtap_iface_store(struct device *d,
1356 struct device_attribute *attr,
1357 const char *buf, size_t count)
1358 {
1359 struct ipw_priv *priv = dev_get_drvdata(d);
1360 int rc = 0;
1361
1362 if (count < 1)
1363 return -EINVAL;
1364
1365 switch (buf[0]) {
1366 case '0':
1367 if (!rtap_iface)
1368 return count;
1369
1370 if (netif_running(priv->prom_net_dev)) {
1371 IPW_WARNING("Interface is up. Cannot unregister.\n");
1372 return count;
1373 }
1374
1375 ipw_prom_free(priv);
1376 rtap_iface = 0;
1377 break;
1378
1379 case '1':
1380 if (rtap_iface)
1381 return count;
1382
1383 rc = ipw_prom_alloc(priv);
1384 if (!rc)
1385 rtap_iface = 1;
1386 break;
1387
1388 default:
1389 return -EINVAL;
1390 }
1391
1392 if (rc) {
1393 IPW_ERROR("Failed to register promiscuous network "
1394 "device (error %d).\n", rc);
1395 }
1396
1397 return count;
1398 }
1399
rtap_iface_show(struct device * d,struct device_attribute * attr,char * buf)1400 static ssize_t rtap_iface_show(struct device *d,
1401 struct device_attribute *attr,
1402 char *buf)
1403 {
1404 struct ipw_priv *priv = dev_get_drvdata(d);
1405 if (rtap_iface)
1406 return sprintf(buf, "%s", priv->prom_net_dev->name);
1407 else {
1408 buf[0] = '-';
1409 buf[1] = '1';
1410 buf[2] = '\0';
1411 return 3;
1412 }
1413 }
1414
1415 static DEVICE_ATTR_ADMIN_RW(rtap_iface);
1416
rtap_filter_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)1417 static ssize_t rtap_filter_store(struct device *d,
1418 struct device_attribute *attr,
1419 const char *buf, size_t count)
1420 {
1421 struct ipw_priv *priv = dev_get_drvdata(d);
1422
1423 if (!priv->prom_priv) {
1424 IPW_ERROR("Attempting to set filter without "
1425 "rtap_iface enabled.\n");
1426 return -EPERM;
1427 }
1428
1429 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1430
1431 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1432 BIT_ARG16(priv->prom_priv->filter));
1433
1434 return count;
1435 }
1436
rtap_filter_show(struct device * d,struct device_attribute * attr,char * buf)1437 static ssize_t rtap_filter_show(struct device *d,
1438 struct device_attribute *attr,
1439 char *buf)
1440 {
1441 struct ipw_priv *priv = dev_get_drvdata(d);
1442 return sprintf(buf, "0x%04X",
1443 priv->prom_priv ? priv->prom_priv->filter : 0);
1444 }
1445
1446 static DEVICE_ATTR_ADMIN_RW(rtap_filter);
1447 #endif
1448
scan_age_show(struct device * d,struct device_attribute * attr,char * buf)1449 static ssize_t scan_age_show(struct device *d, struct device_attribute *attr,
1450 char *buf)
1451 {
1452 struct ipw_priv *priv = dev_get_drvdata(d);
1453 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1454 }
1455
scan_age_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)1456 static ssize_t scan_age_store(struct device *d, struct device_attribute *attr,
1457 const char *buf, size_t count)
1458 {
1459 struct ipw_priv *priv = dev_get_drvdata(d);
1460 struct net_device *dev = priv->net_dev;
1461
1462 IPW_DEBUG_INFO("enter\n");
1463
1464 unsigned long val;
1465 int result = kstrtoul(buf, 0, &val);
1466
1467 if (result == -EINVAL || result == -ERANGE) {
1468 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1469 } else {
1470 priv->ieee->scan_age = val;
1471 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1472 }
1473
1474 IPW_DEBUG_INFO("exit\n");
1475 return count;
1476 }
1477
1478 static DEVICE_ATTR_RW(scan_age);
1479
led_show(struct device * d,struct device_attribute * attr,char * buf)1480 static ssize_t led_show(struct device *d, struct device_attribute *attr,
1481 char *buf)
1482 {
1483 struct ipw_priv *priv = dev_get_drvdata(d);
1484 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1485 }
1486
led_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)1487 static ssize_t led_store(struct device *d, struct device_attribute *attr,
1488 const char *buf, size_t count)
1489 {
1490 struct ipw_priv *priv = dev_get_drvdata(d);
1491
1492 IPW_DEBUG_INFO("enter\n");
1493
1494 if (count == 0)
1495 return 0;
1496
1497 if (*buf == 0) {
1498 IPW_DEBUG_LED("Disabling LED control.\n");
1499 priv->config |= CFG_NO_LED;
1500 ipw_led_shutdown(priv);
1501 } else {
1502 IPW_DEBUG_LED("Enabling LED control.\n");
1503 priv->config &= ~CFG_NO_LED;
1504 ipw_led_init(priv);
1505 }
1506
1507 IPW_DEBUG_INFO("exit\n");
1508 return count;
1509 }
1510
1511 static DEVICE_ATTR_RW(led);
1512
status_show(struct device * d,struct device_attribute * attr,char * buf)1513 static ssize_t status_show(struct device *d,
1514 struct device_attribute *attr, char *buf)
1515 {
1516 struct ipw_priv *p = dev_get_drvdata(d);
1517 return sprintf(buf, "0x%08x\n", (int)p->status);
1518 }
1519
1520 static DEVICE_ATTR_RO(status);
1521
cfg_show(struct device * d,struct device_attribute * attr,char * buf)1522 static ssize_t cfg_show(struct device *d, struct device_attribute *attr,
1523 char *buf)
1524 {
1525 struct ipw_priv *p = dev_get_drvdata(d);
1526 return sprintf(buf, "0x%08x\n", (int)p->config);
1527 }
1528
1529 static DEVICE_ATTR_RO(cfg);
1530
nic_type_show(struct device * d,struct device_attribute * attr,char * buf)1531 static ssize_t nic_type_show(struct device *d,
1532 struct device_attribute *attr, char *buf)
1533 {
1534 struct ipw_priv *priv = dev_get_drvdata(d);
1535 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
1536 }
1537
1538 static DEVICE_ATTR_RO(nic_type);
1539
ucode_version_show(struct device * d,struct device_attribute * attr,char * buf)1540 static ssize_t ucode_version_show(struct device *d,
1541 struct device_attribute *attr, char *buf)
1542 {
1543 u32 len = sizeof(u32), tmp = 0;
1544 struct ipw_priv *p = dev_get_drvdata(d);
1545
1546 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
1547 return 0;
1548
1549 return sprintf(buf, "0x%08x\n", tmp);
1550 }
1551
1552 static DEVICE_ATTR_RO(ucode_version);
1553
rtc_show(struct device * d,struct device_attribute * attr,char * buf)1554 static ssize_t rtc_show(struct device *d, struct device_attribute *attr,
1555 char *buf)
1556 {
1557 u32 len = sizeof(u32), tmp = 0;
1558 struct ipw_priv *p = dev_get_drvdata(d);
1559
1560 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
1561 return 0;
1562
1563 return sprintf(buf, "0x%08x\n", tmp);
1564 }
1565
1566 static DEVICE_ATTR_RO(rtc);
1567
1568 /*
1569 * Add a device attribute to view/control the delay between eeprom
1570 * operations.
1571 */
eeprom_delay_show(struct device * d,struct device_attribute * attr,char * buf)1572 static ssize_t eeprom_delay_show(struct device *d,
1573 struct device_attribute *attr, char *buf)
1574 {
1575 struct ipw_priv *p = dev_get_drvdata(d);
1576 int n = p->eeprom_delay;
1577 return sprintf(buf, "%i\n", n);
1578 }
eeprom_delay_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)1579 static ssize_t eeprom_delay_store(struct device *d,
1580 struct device_attribute *attr,
1581 const char *buf, size_t count)
1582 {
1583 struct ipw_priv *p = dev_get_drvdata(d);
1584 sscanf(buf, "%i", &p->eeprom_delay);
1585 return strnlen(buf, count);
1586 }
1587
1588 static DEVICE_ATTR_RW(eeprom_delay);
1589
command_event_reg_show(struct device * d,struct device_attribute * attr,char * buf)1590 static ssize_t command_event_reg_show(struct device *d,
1591 struct device_attribute *attr, char *buf)
1592 {
1593 u32 reg = 0;
1594 struct ipw_priv *p = dev_get_drvdata(d);
1595
1596 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
1597 return sprintf(buf, "0x%08x\n", reg);
1598 }
command_event_reg_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)1599 static ssize_t command_event_reg_store(struct device *d,
1600 struct device_attribute *attr,
1601 const char *buf, size_t count)
1602 {
1603 u32 reg;
1604 struct ipw_priv *p = dev_get_drvdata(d);
1605
1606 sscanf(buf, "%x", ®);
1607 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
1608 return strnlen(buf, count);
1609 }
1610
1611 static DEVICE_ATTR_RW(command_event_reg);
1612
mem_gpio_reg_show(struct device * d,struct device_attribute * attr,char * buf)1613 static ssize_t mem_gpio_reg_show(struct device *d,
1614 struct device_attribute *attr, char *buf)
1615 {
1616 u32 reg = 0;
1617 struct ipw_priv *p = dev_get_drvdata(d);
1618
1619 reg = ipw_read_reg32(p, 0x301100);
1620 return sprintf(buf, "0x%08x\n", reg);
1621 }
mem_gpio_reg_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)1622 static ssize_t mem_gpio_reg_store(struct device *d,
1623 struct device_attribute *attr,
1624 const char *buf, size_t count)
1625 {
1626 u32 reg;
1627 struct ipw_priv *p = dev_get_drvdata(d);
1628
1629 sscanf(buf, "%x", ®);
1630 ipw_write_reg32(p, 0x301100, reg);
1631 return strnlen(buf, count);
1632 }
1633
1634 static DEVICE_ATTR_RW(mem_gpio_reg);
1635
indirect_dword_show(struct device * d,struct device_attribute * attr,char * buf)1636 static ssize_t indirect_dword_show(struct device *d,
1637 struct device_attribute *attr, char *buf)
1638 {
1639 u32 reg = 0;
1640 struct ipw_priv *priv = dev_get_drvdata(d);
1641
1642 if (priv->status & STATUS_INDIRECT_DWORD)
1643 reg = ipw_read_reg32(priv, priv->indirect_dword);
1644 else
1645 reg = 0;
1646
1647 return sprintf(buf, "0x%08x\n", reg);
1648 }
indirect_dword_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)1649 static ssize_t indirect_dword_store(struct device *d,
1650 struct device_attribute *attr,
1651 const char *buf, size_t count)
1652 {
1653 struct ipw_priv *priv = dev_get_drvdata(d);
1654
1655 sscanf(buf, "%x", &priv->indirect_dword);
1656 priv->status |= STATUS_INDIRECT_DWORD;
1657 return strnlen(buf, count);
1658 }
1659
1660 static DEVICE_ATTR_RW(indirect_dword);
1661
indirect_byte_show(struct device * d,struct device_attribute * attr,char * buf)1662 static ssize_t indirect_byte_show(struct device *d,
1663 struct device_attribute *attr, char *buf)
1664 {
1665 u8 reg = 0;
1666 struct ipw_priv *priv = dev_get_drvdata(d);
1667
1668 if (priv->status & STATUS_INDIRECT_BYTE)
1669 reg = ipw_read_reg8(priv, priv->indirect_byte);
1670 else
1671 reg = 0;
1672
1673 return sprintf(buf, "0x%02x\n", reg);
1674 }
indirect_byte_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)1675 static ssize_t indirect_byte_store(struct device *d,
1676 struct device_attribute *attr,
1677 const char *buf, size_t count)
1678 {
1679 struct ipw_priv *priv = dev_get_drvdata(d);
1680
1681 sscanf(buf, "%x", &priv->indirect_byte);
1682 priv->status |= STATUS_INDIRECT_BYTE;
1683 return strnlen(buf, count);
1684 }
1685
1686 static DEVICE_ATTR_RW(indirect_byte);
1687
direct_dword_show(struct device * d,struct device_attribute * attr,char * buf)1688 static ssize_t direct_dword_show(struct device *d,
1689 struct device_attribute *attr, char *buf)
1690 {
1691 u32 reg = 0;
1692 struct ipw_priv *priv = dev_get_drvdata(d);
1693
1694 if (priv->status & STATUS_DIRECT_DWORD)
1695 reg = ipw_read32(priv, priv->direct_dword);
1696 else
1697 reg = 0;
1698
1699 return sprintf(buf, "0x%08x\n", reg);
1700 }
direct_dword_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)1701 static ssize_t direct_dword_store(struct device *d,
1702 struct device_attribute *attr,
1703 const char *buf, size_t count)
1704 {
1705 struct ipw_priv *priv = dev_get_drvdata(d);
1706
1707 sscanf(buf, "%x", &priv->direct_dword);
1708 priv->status |= STATUS_DIRECT_DWORD;
1709 return strnlen(buf, count);
1710 }
1711
1712 static DEVICE_ATTR_RW(direct_dword);
1713
rf_kill_active(struct ipw_priv * priv)1714 static int rf_kill_active(struct ipw_priv *priv)
1715 {
1716 if (0 == (ipw_read32(priv, 0x30) & 0x10000)) {
1717 priv->status |= STATUS_RF_KILL_HW;
1718 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
1719 } else {
1720 priv->status &= ~STATUS_RF_KILL_HW;
1721 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
1722 }
1723
1724 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1725 }
1726
rf_kill_show(struct device * d,struct device_attribute * attr,char * buf)1727 static ssize_t rf_kill_show(struct device *d, struct device_attribute *attr,
1728 char *buf)
1729 {
1730 /* 0 - RF kill not enabled
1731 1 - SW based RF kill active (sysfs)
1732 2 - HW based RF kill active
1733 3 - Both HW and SW baed RF kill active */
1734 struct ipw_priv *priv = dev_get_drvdata(d);
1735 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
1736 (rf_kill_active(priv) ? 0x2 : 0x0);
1737 return sprintf(buf, "%i\n", val);
1738 }
1739
ipw_radio_kill_sw(struct ipw_priv * priv,int disable_radio)1740 static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1741 {
1742 if ((disable_radio ? 1 : 0) ==
1743 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
1744 return 0;
1745
1746 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1747 disable_radio ? "OFF" : "ON");
1748
1749 if (disable_radio) {
1750 priv->status |= STATUS_RF_KILL_SW;
1751
1752 cancel_delayed_work(&priv->request_scan);
1753 cancel_delayed_work(&priv->request_direct_scan);
1754 cancel_delayed_work(&priv->request_passive_scan);
1755 cancel_delayed_work(&priv->scan_event);
1756 schedule_work(&priv->down);
1757 } else {
1758 priv->status &= ~STATUS_RF_KILL_SW;
1759 if (rf_kill_active(priv)) {
1760 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1761 "disabled by HW switch\n");
1762 /* Make sure the RF_KILL check timer is running */
1763 cancel_delayed_work(&priv->rf_kill);
1764 schedule_delayed_work(&priv->rf_kill,
1765 round_jiffies_relative(2 * HZ));
1766 } else
1767 schedule_work(&priv->up);
1768 }
1769
1770 return 1;
1771 }
1772
rf_kill_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)1773 static ssize_t rf_kill_store(struct device *d, struct device_attribute *attr,
1774 const char *buf, size_t count)
1775 {
1776 struct ipw_priv *priv = dev_get_drvdata(d);
1777
1778 ipw_radio_kill_sw(priv, buf[0] == '1');
1779
1780 return count;
1781 }
1782
1783 static DEVICE_ATTR_RW(rf_kill);
1784
speed_scan_show(struct device * d,struct device_attribute * attr,char * buf)1785 static ssize_t speed_scan_show(struct device *d, struct device_attribute *attr,
1786 char *buf)
1787 {
1788 struct ipw_priv *priv = dev_get_drvdata(d);
1789 int pos = 0, len = 0;
1790 if (priv->config & CFG_SPEED_SCAN) {
1791 while (priv->speed_scan[pos] != 0)
1792 len += sprintf(&buf[len], "%d ",
1793 priv->speed_scan[pos++]);
1794 return len + sprintf(&buf[len], "\n");
1795 }
1796
1797 return sprintf(buf, "0\n");
1798 }
1799
speed_scan_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)1800 static ssize_t speed_scan_store(struct device *d, struct device_attribute *attr,
1801 const char *buf, size_t count)
1802 {
1803 struct ipw_priv *priv = dev_get_drvdata(d);
1804 int channel, pos = 0;
1805 const char *p = buf;
1806
1807 /* list of space separated channels to scan, optionally ending with 0 */
1808 while ((channel = simple_strtol(p, NULL, 0))) {
1809 if (pos == MAX_SPEED_SCAN - 1) {
1810 priv->speed_scan[pos] = 0;
1811 break;
1812 }
1813
1814 if (libipw_is_valid_channel(priv->ieee, channel))
1815 priv->speed_scan[pos++] = channel;
1816 else
1817 IPW_WARNING("Skipping invalid channel request: %d\n",
1818 channel);
1819 p = strchr(p, ' ');
1820 if (!p)
1821 break;
1822 while (*p == ' ' || *p == '\t')
1823 p++;
1824 }
1825
1826 if (pos == 0)
1827 priv->config &= ~CFG_SPEED_SCAN;
1828 else {
1829 priv->speed_scan_pos = 0;
1830 priv->config |= CFG_SPEED_SCAN;
1831 }
1832
1833 return count;
1834 }
1835
1836 static DEVICE_ATTR_RW(speed_scan);
1837
net_stats_show(struct device * d,struct device_attribute * attr,char * buf)1838 static ssize_t net_stats_show(struct device *d, struct device_attribute *attr,
1839 char *buf)
1840 {
1841 struct ipw_priv *priv = dev_get_drvdata(d);
1842 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1843 }
1844
net_stats_store(struct device * d,struct device_attribute * attr,const char * buf,size_t count)1845 static ssize_t net_stats_store(struct device *d, struct device_attribute *attr,
1846 const char *buf, size_t count)
1847 {
1848 struct ipw_priv *priv = dev_get_drvdata(d);
1849 if (buf[0] == '1')
1850 priv->config |= CFG_NET_STATS;
1851 else
1852 priv->config &= ~CFG_NET_STATS;
1853
1854 return count;
1855 }
1856
1857 static DEVICE_ATTR_RW(net_stats);
1858
channels_show(struct device * d,struct device_attribute * attr,char * buf)1859 static ssize_t channels_show(struct device *d,
1860 struct device_attribute *attr,
1861 char *buf)
1862 {
1863 struct ipw_priv *priv = dev_get_drvdata(d);
1864 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
1865 int len = 0, i;
1866
1867 len = sprintf(&buf[len],
1868 "Displaying %d channels in 2.4Ghz band "
1869 "(802.11bg):\n", geo->bg_channels);
1870
1871 for (i = 0; i < geo->bg_channels; i++) {
1872 len += sprintf(&buf[len], "%d: BSS%s%s, %s, Band %s.\n",
1873 geo->bg[i].channel,
1874 geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT ?
1875 " (radar spectrum)" : "",
1876 ((geo->bg[i].flags & LIBIPW_CH_NO_IBSS) ||
1877 (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT))
1878 ? "" : ", IBSS",
1879 geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
1880 "passive only" : "active/passive",
1881 geo->bg[i].flags & LIBIPW_CH_B_ONLY ?
1882 "B" : "B/G");
1883 }
1884
1885 len += sprintf(&buf[len],
1886 "Displaying %d channels in 5.2Ghz band "
1887 "(802.11a):\n", geo->a_channels);
1888 for (i = 0; i < geo->a_channels; i++) {
1889 len += sprintf(&buf[len], "%d: BSS%s%s, %s.\n",
1890 geo->a[i].channel,
1891 geo->a[i].flags & LIBIPW_CH_RADAR_DETECT ?
1892 " (radar spectrum)" : "",
1893 ((geo->a[i].flags & LIBIPW_CH_NO_IBSS) ||
1894 (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT))
1895 ? "" : ", IBSS",
1896 geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY ?
1897 "passive only" : "active/passive");
1898 }
1899
1900 return len;
1901 }
1902
1903 static DEVICE_ATTR_ADMIN_RO(channels);
1904
notify_wx_assoc_event(struct ipw_priv * priv)1905 static void notify_wx_assoc_event(struct ipw_priv *priv)
1906 {
1907 union iwreq_data wrqu;
1908 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1909 if (priv->status & STATUS_ASSOCIATED)
1910 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1911 else
1912 eth_zero_addr(wrqu.ap_addr.sa_data);
1913 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1914 }
1915
ipw_irq_tasklet(struct tasklet_struct * t)1916 static void ipw_irq_tasklet(struct tasklet_struct *t)
1917 {
1918 struct ipw_priv *priv = from_tasklet(priv, t, irq_tasklet);
1919 u32 inta, inta_mask, handled = 0;
1920 unsigned long flags;
1921
1922 spin_lock_irqsave(&priv->irq_lock, flags);
1923
1924 inta = ipw_read32(priv, IPW_INTA_RW);
1925 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1926
1927 if (inta == 0xFFFFFFFF) {
1928 /* Hardware disappeared */
1929 IPW_WARNING("TASKLET INTA == 0xFFFFFFFF\n");
1930 /* Only handle the cached INTA values */
1931 inta = 0;
1932 }
1933 inta &= (IPW_INTA_MASK_ALL & inta_mask);
1934
1935 /* Add any cached INTA values that need to be handled */
1936 inta |= priv->isr_inta;
1937
1938 spin_unlock_irqrestore(&priv->irq_lock, flags);
1939
1940 spin_lock_irqsave(&priv->lock, flags);
1941
1942 /* handle all the justifications for the interrupt */
1943 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
1944 ipw_rx(priv);
1945 handled |= IPW_INTA_BIT_RX_TRANSFER;
1946 }
1947
1948 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
1949 IPW_DEBUG_HC("Command completed.\n");
1950 ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
1951 priv->status &= ~STATUS_HCMD_ACTIVE;
1952 wake_up_interruptible(&priv->wait_command_queue);
1953 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
1954 }
1955
1956 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
1957 IPW_DEBUG_TX("TX_QUEUE_1\n");
1958 ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
1959 handled |= IPW_INTA_BIT_TX_QUEUE_1;
1960 }
1961
1962 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
1963 IPW_DEBUG_TX("TX_QUEUE_2\n");
1964 ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
1965 handled |= IPW_INTA_BIT_TX_QUEUE_2;
1966 }
1967
1968 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
1969 IPW_DEBUG_TX("TX_QUEUE_3\n");
1970 ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
1971 handled |= IPW_INTA_BIT_TX_QUEUE_3;
1972 }
1973
1974 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
1975 IPW_DEBUG_TX("TX_QUEUE_4\n");
1976 ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
1977 handled |= IPW_INTA_BIT_TX_QUEUE_4;
1978 }
1979
1980 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
1981 IPW_WARNING("STATUS_CHANGE\n");
1982 handled |= IPW_INTA_BIT_STATUS_CHANGE;
1983 }
1984
1985 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
1986 IPW_WARNING("TX_PERIOD_EXPIRED\n");
1987 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
1988 }
1989
1990 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
1991 IPW_WARNING("HOST_CMD_DONE\n");
1992 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
1993 }
1994
1995 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
1996 IPW_WARNING("FW_INITIALIZATION_DONE\n");
1997 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
1998 }
1999
2000 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
2001 IPW_WARNING("PHY_OFF_DONE\n");
2002 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
2003 }
2004
2005 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
2006 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
2007 priv->status |= STATUS_RF_KILL_HW;
2008 wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
2009 wake_up_interruptible(&priv->wait_command_queue);
2010 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
2011 cancel_delayed_work(&priv->request_scan);
2012 cancel_delayed_work(&priv->request_direct_scan);
2013 cancel_delayed_work(&priv->request_passive_scan);
2014 cancel_delayed_work(&priv->scan_event);
2015 schedule_work(&priv->link_down);
2016 schedule_delayed_work(&priv->rf_kill, 2 * HZ);
2017 handled |= IPW_INTA_BIT_RF_KILL_DONE;
2018 }
2019
2020 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
2021 IPW_WARNING("Firmware error detected. Restarting.\n");
2022 if (priv->error) {
2023 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
2024 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
2025 struct ipw_fw_error *error =
2026 ipw_alloc_error_log(priv);
2027 ipw_dump_error_log(priv, error);
2028 kfree(error);
2029 }
2030 } else {
2031 priv->error = ipw_alloc_error_log(priv);
2032 if (priv->error)
2033 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
2034 else
2035 IPW_DEBUG_FW("Error allocating sysfs 'error' "
2036 "log.\n");
2037 if (ipw_debug_level & IPW_DL_FW_ERRORS)
2038 ipw_dump_error_log(priv, priv->error);
2039 }
2040
2041 /* XXX: If hardware encryption is for WPA/WPA2,
2042 * we have to notify the supplicant. */
2043 if (priv->ieee->sec.encrypt) {
2044 priv->status &= ~STATUS_ASSOCIATED;
2045 notify_wx_assoc_event(priv);
2046 }
2047
2048 /* Keep the restart process from trying to send host
2049 * commands by clearing the INIT status bit */
2050 priv->status &= ~STATUS_INIT;
2051
2052 /* Cancel currently queued command. */
2053 priv->status &= ~STATUS_HCMD_ACTIVE;
2054 wake_up_interruptible(&priv->wait_command_queue);
2055
2056 schedule_work(&priv->adapter_restart);
2057 handled |= IPW_INTA_BIT_FATAL_ERROR;
2058 }
2059
2060 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
2061 IPW_ERROR("Parity error\n");
2062 handled |= IPW_INTA_BIT_PARITY_ERROR;
2063 }
2064
2065 if (handled != inta) {
2066 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
2067 }
2068
2069 spin_unlock_irqrestore(&priv->lock, flags);
2070
2071 /* enable all interrupts */
2072 ipw_enable_interrupts(priv);
2073 }
2074
2075 #define IPW_CMD(x) case IPW_CMD_ ## x : return #x
get_cmd_string(u8 cmd)2076 static char *get_cmd_string(u8 cmd)
2077 {
2078 switch (cmd) {
2079 IPW_CMD(HOST_COMPLETE);
2080 IPW_CMD(POWER_DOWN);
2081 IPW_CMD(SYSTEM_CONFIG);
2082 IPW_CMD(MULTICAST_ADDRESS);
2083 IPW_CMD(SSID);
2084 IPW_CMD(ADAPTER_ADDRESS);
2085 IPW_CMD(PORT_TYPE);
2086 IPW_CMD(RTS_THRESHOLD);
2087 IPW_CMD(FRAG_THRESHOLD);
2088 IPW_CMD(POWER_MODE);
2089 IPW_CMD(WEP_KEY);
2090 IPW_CMD(TGI_TX_KEY);
2091 IPW_CMD(SCAN_REQUEST);
2092 IPW_CMD(SCAN_REQUEST_EXT);
2093 IPW_CMD(ASSOCIATE);
2094 IPW_CMD(SUPPORTED_RATES);
2095 IPW_CMD(SCAN_ABORT);
2096 IPW_CMD(TX_FLUSH);
2097 IPW_CMD(QOS_PARAMETERS);
2098 IPW_CMD(DINO_CONFIG);
2099 IPW_CMD(RSN_CAPABILITIES);
2100 IPW_CMD(RX_KEY);
2101 IPW_CMD(CARD_DISABLE);
2102 IPW_CMD(SEED_NUMBER);
2103 IPW_CMD(TX_POWER);
2104 IPW_CMD(COUNTRY_INFO);
2105 IPW_CMD(AIRONET_INFO);
2106 IPW_CMD(AP_TX_POWER);
2107 IPW_CMD(CCKM_INFO);
2108 IPW_CMD(CCX_VER_INFO);
2109 IPW_CMD(SET_CALIBRATION);
2110 IPW_CMD(SENSITIVITY_CALIB);
2111 IPW_CMD(RETRY_LIMIT);
2112 IPW_CMD(IPW_PRE_POWER_DOWN);
2113 IPW_CMD(VAP_BEACON_TEMPLATE);
2114 IPW_CMD(VAP_DTIM_PERIOD);
2115 IPW_CMD(EXT_SUPPORTED_RATES);
2116 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2117 IPW_CMD(VAP_QUIET_INTERVALS);
2118 IPW_CMD(VAP_CHANNEL_SWITCH);
2119 IPW_CMD(VAP_MANDATORY_CHANNELS);
2120 IPW_CMD(VAP_CELL_PWR_LIMIT);
2121 IPW_CMD(VAP_CF_PARAM_SET);
2122 IPW_CMD(VAP_SET_BEACONING_STATE);
2123 IPW_CMD(MEASUREMENT);
2124 IPW_CMD(POWER_CAPABILITY);
2125 IPW_CMD(SUPPORTED_CHANNELS);
2126 IPW_CMD(TPC_REPORT);
2127 IPW_CMD(WME_INFO);
2128 IPW_CMD(PRODUCTION_COMMAND);
2129 default:
2130 return "UNKNOWN";
2131 }
2132 }
2133
2134 #define HOST_COMPLETE_TIMEOUT HZ
2135
__ipw_send_cmd(struct ipw_priv * priv,struct host_cmd * cmd)2136 static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
2137 {
2138 int rc = 0;
2139 unsigned long flags;
2140 unsigned long now, end;
2141
2142 spin_lock_irqsave(&priv->lock, flags);
2143 if (priv->status & STATUS_HCMD_ACTIVE) {
2144 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2145 get_cmd_string(cmd->cmd));
2146 spin_unlock_irqrestore(&priv->lock, flags);
2147 return -EAGAIN;
2148 }
2149
2150 priv->status |= STATUS_HCMD_ACTIVE;
2151
2152 if (priv->cmdlog) {
2153 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2154 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2155 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2156 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2157 cmd->len);
2158 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2159 }
2160
2161 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2162 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2163 priv->status);
2164
2165 #ifndef DEBUG_CMD_WEP_KEY
2166 if (cmd->cmd == IPW_CMD_WEP_KEY)
2167 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2168 else
2169 #endif
2170 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2171
2172 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
2173 if (rc) {
2174 priv->status &= ~STATUS_HCMD_ACTIVE;
2175 IPW_ERROR("Failed to send %s: Reason %d\n",
2176 get_cmd_string(cmd->cmd), rc);
2177 spin_unlock_irqrestore(&priv->lock, flags);
2178 goto exit;
2179 }
2180 spin_unlock_irqrestore(&priv->lock, flags);
2181
2182 now = jiffies;
2183 end = now + HOST_COMPLETE_TIMEOUT;
2184 again:
2185 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2186 !(priv->
2187 status & STATUS_HCMD_ACTIVE),
2188 end - now);
2189 if (rc < 0) {
2190 now = jiffies;
2191 if (time_before(now, end))
2192 goto again;
2193 rc = 0;
2194 }
2195
2196 if (rc == 0) {
2197 spin_lock_irqsave(&priv->lock, flags);
2198 if (priv->status & STATUS_HCMD_ACTIVE) {
2199 IPW_ERROR("Failed to send %s: Command timed out.\n",
2200 get_cmd_string(cmd->cmd));
2201 priv->status &= ~STATUS_HCMD_ACTIVE;
2202 spin_unlock_irqrestore(&priv->lock, flags);
2203 rc = -EIO;
2204 goto exit;
2205 }
2206 spin_unlock_irqrestore(&priv->lock, flags);
2207 } else
2208 rc = 0;
2209
2210 if (priv->status & STATUS_RF_KILL_HW) {
2211 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2212 get_cmd_string(cmd->cmd));
2213 rc = -EIO;
2214 goto exit;
2215 }
2216
2217 exit:
2218 if (priv->cmdlog) {
2219 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2220 priv->cmdlog_pos %= priv->cmdlog_len;
2221 }
2222 return rc;
2223 }
2224
ipw_send_cmd_simple(struct ipw_priv * priv,u8 command)2225 static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
2226 {
2227 struct host_cmd cmd = {
2228 .cmd = command,
2229 };
2230
2231 return __ipw_send_cmd(priv, &cmd);
2232 }
2233
ipw_send_cmd_pdu(struct ipw_priv * priv,u8 command,u8 len,const void * data)2234 static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2235 const void *data)
2236 {
2237 struct host_cmd cmd = {
2238 .cmd = command,
2239 .len = len,
2240 .param = data,
2241 };
2242
2243 return __ipw_send_cmd(priv, &cmd);
2244 }
2245
ipw_send_host_complete(struct ipw_priv * priv)2246 static int ipw_send_host_complete(struct ipw_priv *priv)
2247 {
2248 if (!priv) {
2249 IPW_ERROR("Invalid args\n");
2250 return -1;
2251 }
2252
2253 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
2254 }
2255
ipw_send_system_config(struct ipw_priv * priv)2256 static int ipw_send_system_config(struct ipw_priv *priv)
2257 {
2258 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2259 sizeof(priv->sys_config),
2260 &priv->sys_config);
2261 }
2262
ipw_send_ssid(struct ipw_priv * priv,u8 * ssid,int len)2263 static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
2264 {
2265 if (!priv || !ssid) {
2266 IPW_ERROR("Invalid args\n");
2267 return -1;
2268 }
2269
2270 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
2271 ssid);
2272 }
2273
ipw_send_adapter_address(struct ipw_priv * priv,const u8 * mac)2274 static int ipw_send_adapter_address(struct ipw_priv *priv, const u8 * mac)
2275 {
2276 if (!priv || !mac) {
2277 IPW_ERROR("Invalid args\n");
2278 return -1;
2279 }
2280
2281 IPW_DEBUG_INFO("%s: Setting MAC to %pM\n",
2282 priv->net_dev->name, mac);
2283
2284 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
2285 }
2286
ipw_adapter_restart(void * adapter)2287 static void ipw_adapter_restart(void *adapter)
2288 {
2289 struct ipw_priv *priv = adapter;
2290
2291 if (priv->status & STATUS_RF_KILL_MASK)
2292 return;
2293
2294 ipw_down(priv);
2295
2296 if (priv->assoc_network &&
2297 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2298 ipw_remove_current_network(priv);
2299
2300 if (ipw_up(priv)) {
2301 IPW_ERROR("Failed to up device\n");
2302 return;
2303 }
2304 }
2305
ipw_bg_adapter_restart(struct work_struct * work)2306 static void ipw_bg_adapter_restart(struct work_struct *work)
2307 {
2308 struct ipw_priv *priv =
2309 container_of(work, struct ipw_priv, adapter_restart);
2310 mutex_lock(&priv->mutex);
2311 ipw_adapter_restart(priv);
2312 mutex_unlock(&priv->mutex);
2313 }
2314
2315 static void ipw_abort_scan(struct ipw_priv *priv);
2316
2317 #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2318
ipw_scan_check(void * data)2319 static void ipw_scan_check(void *data)
2320 {
2321 struct ipw_priv *priv = data;
2322
2323 if (priv->status & STATUS_SCAN_ABORTING) {
2324 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
2325 "adapter after (%dms).\n",
2326 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
2327 schedule_work(&priv->adapter_restart);
2328 } else if (priv->status & STATUS_SCANNING) {
2329 IPW_DEBUG_SCAN("Scan completion watchdog aborting scan "
2330 "after (%dms).\n",
2331 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
2332 ipw_abort_scan(priv);
2333 schedule_delayed_work(&priv->scan_check, HZ);
2334 }
2335 }
2336
ipw_bg_scan_check(struct work_struct * work)2337 static void ipw_bg_scan_check(struct work_struct *work)
2338 {
2339 struct ipw_priv *priv =
2340 container_of(work, struct ipw_priv, scan_check.work);
2341 mutex_lock(&priv->mutex);
2342 ipw_scan_check(priv);
2343 mutex_unlock(&priv->mutex);
2344 }
2345
ipw_send_scan_request_ext(struct ipw_priv * priv,struct ipw_scan_request_ext * request)2346 static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2347 struct ipw_scan_request_ext *request)
2348 {
2349 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
2350 sizeof(*request), request);
2351 }
2352
ipw_send_scan_abort(struct ipw_priv * priv)2353 static int ipw_send_scan_abort(struct ipw_priv *priv)
2354 {
2355 if (!priv) {
2356 IPW_ERROR("Invalid args\n");
2357 return -1;
2358 }
2359
2360 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
2361 }
2362
ipw_set_sensitivity(struct ipw_priv * priv,u16 sens)2363 static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2364 {
2365 struct ipw_sensitivity_calib calib = {
2366 .beacon_rssi_raw = cpu_to_le16(sens),
2367 };
2368
2369 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
2370 &calib);
2371 }
2372
ipw_send_associate(struct ipw_priv * priv,struct ipw_associate * associate)2373 static int ipw_send_associate(struct ipw_priv *priv,
2374 struct ipw_associate *associate)
2375 {
2376 if (!priv || !associate) {
2377 IPW_ERROR("Invalid args\n");
2378 return -1;
2379 }
2380
2381 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(*associate),
2382 associate);
2383 }
2384
ipw_send_supported_rates(struct ipw_priv * priv,struct ipw_supported_rates * rates)2385 static int ipw_send_supported_rates(struct ipw_priv *priv,
2386 struct ipw_supported_rates *rates)
2387 {
2388 if (!priv || !rates) {
2389 IPW_ERROR("Invalid args\n");
2390 return -1;
2391 }
2392
2393 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
2394 rates);
2395 }
2396
ipw_set_random_seed(struct ipw_priv * priv)2397 static int ipw_set_random_seed(struct ipw_priv *priv)
2398 {
2399 u32 val;
2400
2401 if (!priv) {
2402 IPW_ERROR("Invalid args\n");
2403 return -1;
2404 }
2405
2406 get_random_bytes(&val, sizeof(val));
2407
2408 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
2409 }
2410
ipw_send_card_disable(struct ipw_priv * priv,u32 phy_off)2411 static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2412 {
2413 __le32 v = cpu_to_le32(phy_off);
2414 if (!priv) {
2415 IPW_ERROR("Invalid args\n");
2416 return -1;
2417 }
2418
2419 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(v), &v);
2420 }
2421
ipw_send_tx_power(struct ipw_priv * priv,struct ipw_tx_power * power)2422 static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
2423 {
2424 if (!priv || !power) {
2425 IPW_ERROR("Invalid args\n");
2426 return -1;
2427 }
2428
2429 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
2430 }
2431
ipw_set_tx_power(struct ipw_priv * priv)2432 static int ipw_set_tx_power(struct ipw_priv *priv)
2433 {
2434 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
2435 struct ipw_tx_power tx_power;
2436 s8 max_power;
2437 int i;
2438
2439 memset(&tx_power, 0, sizeof(tx_power));
2440
2441 /* configure device for 'G' band */
2442 tx_power.ieee_mode = IPW_G_MODE;
2443 tx_power.num_channels = geo->bg_channels;
2444 for (i = 0; i < geo->bg_channels; i++) {
2445 max_power = geo->bg[i].max_power;
2446 tx_power.channels_tx_power[i].channel_number =
2447 geo->bg[i].channel;
2448 tx_power.channels_tx_power[i].tx_power = max_power ?
2449 min(max_power, priv->tx_power) : priv->tx_power;
2450 }
2451 if (ipw_send_tx_power(priv, &tx_power))
2452 return -EIO;
2453
2454 /* configure device to also handle 'B' band */
2455 tx_power.ieee_mode = IPW_B_MODE;
2456 if (ipw_send_tx_power(priv, &tx_power))
2457 return -EIO;
2458
2459 /* configure device to also handle 'A' band */
2460 if (priv->ieee->abg_true) {
2461 tx_power.ieee_mode = IPW_A_MODE;
2462 tx_power.num_channels = geo->a_channels;
2463 for (i = 0; i < tx_power.num_channels; i++) {
2464 max_power = geo->a[i].max_power;
2465 tx_power.channels_tx_power[i].channel_number =
2466 geo->a[i].channel;
2467 tx_power.channels_tx_power[i].tx_power = max_power ?
2468 min(max_power, priv->tx_power) : priv->tx_power;
2469 }
2470 if (ipw_send_tx_power(priv, &tx_power))
2471 return -EIO;
2472 }
2473 return 0;
2474 }
2475
ipw_send_rts_threshold(struct ipw_priv * priv,u16 rts)2476 static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2477 {
2478 struct ipw_rts_threshold rts_threshold = {
2479 .rts_threshold = cpu_to_le16(rts),
2480 };
2481
2482 if (!priv) {
2483 IPW_ERROR("Invalid args\n");
2484 return -1;
2485 }
2486
2487 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2488 sizeof(rts_threshold), &rts_threshold);
2489 }
2490
ipw_send_frag_threshold(struct ipw_priv * priv,u16 frag)2491 static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2492 {
2493 struct ipw_frag_threshold frag_threshold = {
2494 .frag_threshold = cpu_to_le16(frag),
2495 };
2496
2497 if (!priv) {
2498 IPW_ERROR("Invalid args\n");
2499 return -1;
2500 }
2501
2502 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2503 sizeof(frag_threshold), &frag_threshold);
2504 }
2505
ipw_send_power_mode(struct ipw_priv * priv,u32 mode)2506 static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2507 {
2508 __le32 param;
2509
2510 if (!priv) {
2511 IPW_ERROR("Invalid args\n");
2512 return -1;
2513 }
2514
2515 /* If on battery, set to 3, if AC set to CAM, else user
2516 * level */
2517 switch (mode) {
2518 case IPW_POWER_BATTERY:
2519 param = cpu_to_le32(IPW_POWER_INDEX_3);
2520 break;
2521 case IPW_POWER_AC:
2522 param = cpu_to_le32(IPW_POWER_MODE_CAM);
2523 break;
2524 default:
2525 param = cpu_to_le32(mode);
2526 break;
2527 }
2528
2529 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
2530 ¶m);
2531 }
2532
ipw_send_retry_limit(struct ipw_priv * priv,u8 slimit,u8 llimit)2533 static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2534 {
2535 struct ipw_retry_limit retry_limit = {
2536 .short_retry_limit = slimit,
2537 .long_retry_limit = llimit
2538 };
2539
2540 if (!priv) {
2541 IPW_ERROR("Invalid args\n");
2542 return -1;
2543 }
2544
2545 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
2546 &retry_limit);
2547 }
2548
2549 /*
2550 * The IPW device contains a Microwire compatible EEPROM that stores
2551 * various data like the MAC address. Usually the firmware has exclusive
2552 * access to the eeprom, but during device initialization (before the
2553 * device driver has sent the HostComplete command to the firmware) the
2554 * device driver has read access to the EEPROM by way of indirect addressing
2555 * through a couple of memory mapped registers.
2556 *
2557 * The following is a simplified implementation for pulling data out of the
2558 * eeprom, along with some helper functions to find information in
2559 * the per device private data's copy of the eeprom.
2560 *
2561 * NOTE: To better understand how these functions work (i.e what is a chip
2562 * select and why do have to keep driving the eeprom clock?), read
2563 * just about any data sheet for a Microwire compatible EEPROM.
2564 */
2565
2566 /* write a 32 bit value into the indirect accessor register */
eeprom_write_reg(struct ipw_priv * p,u32 data)2567 static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2568 {
2569 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
2570
2571 /* the eeprom requires some time to complete the operation */
2572 udelay(p->eeprom_delay);
2573 }
2574
2575 /* perform a chip select operation */
eeprom_cs(struct ipw_priv * priv)2576 static void eeprom_cs(struct ipw_priv *priv)
2577 {
2578 eeprom_write_reg(priv, 0);
2579 eeprom_write_reg(priv, EEPROM_BIT_CS);
2580 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2581 eeprom_write_reg(priv, EEPROM_BIT_CS);
2582 }
2583
2584 /* perform a chip select operation */
eeprom_disable_cs(struct ipw_priv * priv)2585 static void eeprom_disable_cs(struct ipw_priv *priv)
2586 {
2587 eeprom_write_reg(priv, EEPROM_BIT_CS);
2588 eeprom_write_reg(priv, 0);
2589 eeprom_write_reg(priv, EEPROM_BIT_SK);
2590 }
2591
2592 /* push a single bit down to the eeprom */
eeprom_write_bit(struct ipw_priv * p,u8 bit)2593 static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
2594 {
2595 int d = (bit ? EEPROM_BIT_DI : 0);
2596 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2597 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
2598 }
2599
2600 /* push an opcode followed by an address down to the eeprom */
eeprom_op(struct ipw_priv * priv,u8 op,u8 addr)2601 static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
2602 {
2603 int i;
2604
2605 eeprom_cs(priv);
2606 eeprom_write_bit(priv, 1);
2607 eeprom_write_bit(priv, op & 2);
2608 eeprom_write_bit(priv, op & 1);
2609 for (i = 7; i >= 0; i--) {
2610 eeprom_write_bit(priv, addr & (1 << i));
2611 }
2612 }
2613
2614 /* pull 16 bits off the eeprom, one bit at a time */
eeprom_read_u16(struct ipw_priv * priv,u8 addr)2615 static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
2616 {
2617 int i;
2618 u16 r = 0;
2619
2620 /* Send READ Opcode */
2621 eeprom_op(priv, EEPROM_CMD_READ, addr);
2622
2623 /* Send dummy bit */
2624 eeprom_write_reg(priv, EEPROM_BIT_CS);
2625
2626 /* Read the byte off the eeprom one bit at a time */
2627 for (i = 0; i < 16; i++) {
2628 u32 data = 0;
2629 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2630 eeprom_write_reg(priv, EEPROM_BIT_CS);
2631 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2632 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
2633 }
2634
2635 /* Send another dummy bit */
2636 eeprom_write_reg(priv, 0);
2637 eeprom_disable_cs(priv);
2638
2639 return r;
2640 }
2641
2642 /* helper function for pulling the mac address out of the private */
2643 /* data's copy of the eeprom data */
eeprom_parse_mac(struct ipw_priv * priv,u8 * mac)2644 static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
2645 {
2646 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], ETH_ALEN);
2647 }
2648
ipw_read_eeprom(struct ipw_priv * priv)2649 static void ipw_read_eeprom(struct ipw_priv *priv)
2650 {
2651 int i;
2652 __le16 *eeprom = (__le16 *) priv->eeprom;
2653
2654 IPW_DEBUG_TRACE(">>\n");
2655
2656 /* read entire contents of eeprom into private buffer */
2657 for (i = 0; i < 128; i++)
2658 eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i));
2659
2660 IPW_DEBUG_TRACE("<<\n");
2661 }
2662
2663 /*
2664 * Either the device driver (i.e. the host) or the firmware can
2665 * load eeprom data into the designated region in SRAM. If neither
2666 * happens then the FW will shutdown with a fatal error.
2667 *
2668 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2669 * bit needs region of shared SRAM needs to be non-zero.
2670 */
ipw_eeprom_init_sram(struct ipw_priv * priv)2671 static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2672 {
2673 int i;
2674
2675 IPW_DEBUG_TRACE(">>\n");
2676
2677 /*
2678 If the data looks correct, then copy it to our private
2679 copy. Otherwise let the firmware know to perform the operation
2680 on its own.
2681 */
2682 if (priv->eeprom[EEPROM_VERSION] != 0) {
2683 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2684
2685 /* write the eeprom data to sram */
2686 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
2687 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
2688
2689 /* Do not load eeprom data on fatal error or suspend */
2690 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2691 } else {
2692 IPW_DEBUG_INFO("Enabling FW initialization of SRAM\n");
2693
2694 /* Load eeprom data on fatal error or suspend */
2695 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2696 }
2697
2698 IPW_DEBUG_TRACE("<<\n");
2699 }
2700
ipw_zero_memory(struct ipw_priv * priv,u32 start,u32 count)2701 static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
2702 {
2703 count >>= 2;
2704 if (!count)
2705 return;
2706 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
2707 while (count--)
2708 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
2709 }
2710
ipw_fw_dma_reset_command_blocks(struct ipw_priv * priv)2711 static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2712 {
2713 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
2714 CB_NUMBER_OF_ELEMENTS_SMALL *
2715 sizeof(struct command_block));
2716 }
2717
ipw_fw_dma_enable(struct ipw_priv * priv)2718 static int ipw_fw_dma_enable(struct ipw_priv *priv)
2719 { /* start dma engine but no transfers yet */
2720
2721 IPW_DEBUG_FW(">> :\n");
2722
2723 /* Start the dma */
2724 ipw_fw_dma_reset_command_blocks(priv);
2725
2726 /* Write CB base address */
2727 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
2728
2729 IPW_DEBUG_FW("<< :\n");
2730 return 0;
2731 }
2732
ipw_fw_dma_abort(struct ipw_priv * priv)2733 static void ipw_fw_dma_abort(struct ipw_priv *priv)
2734 {
2735 u32 control = 0;
2736
2737 IPW_DEBUG_FW(">> :\n");
2738
2739 /* set the Stop and Abort bit */
2740 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
2741 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2742 priv->sram_desc.last_cb_index = 0;
2743
2744 IPW_DEBUG_FW("<<\n");
2745 }
2746
ipw_fw_dma_write_command_block(struct ipw_priv * priv,int index,struct command_block * cb)2747 static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2748 struct command_block *cb)
2749 {
2750 u32 address =
2751 IPW_SHARED_SRAM_DMA_CONTROL +
2752 (sizeof(struct command_block) * index);
2753 IPW_DEBUG_FW(">> :\n");
2754
2755 ipw_write_indirect(priv, address, (u8 *) cb,
2756 (int)sizeof(struct command_block));
2757
2758 IPW_DEBUG_FW("<< :\n");
2759 return 0;
2760
2761 }
2762
ipw_fw_dma_kick(struct ipw_priv * priv)2763 static int ipw_fw_dma_kick(struct ipw_priv *priv)
2764 {
2765 u32 control = 0;
2766 u32 index = 0;
2767
2768 IPW_DEBUG_FW(">> :\n");
2769
2770 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
2771 ipw_fw_dma_write_command_block(priv, index,
2772 &priv->sram_desc.cb_list[index]);
2773
2774 /* Enable the DMA in the CSR register */
2775 ipw_clear_bit(priv, IPW_RESET_REG,
2776 IPW_RESET_REG_MASTER_DISABLED |
2777 IPW_RESET_REG_STOP_MASTER);
2778
2779 /* Set the Start bit. */
2780 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
2781 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
2782
2783 IPW_DEBUG_FW("<< :\n");
2784 return 0;
2785 }
2786
ipw_fw_dma_dump_command_block(struct ipw_priv * priv)2787 static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2788 {
2789 u32 address;
2790 u32 register_value = 0;
2791 u32 cb_fields_address = 0;
2792
2793 IPW_DEBUG_FW(">> :\n");
2794 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2795 IPW_DEBUG_FW_INFO("Current CB is 0x%x\n", address);
2796
2797 /* Read the DMA Controlor register */
2798 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2799 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x\n", register_value);
2800
2801 /* Print the CB values */
2802 cb_fields_address = address;
2803 register_value = ipw_read_reg32(priv, cb_fields_address);
2804 IPW_DEBUG_FW_INFO("Current CB Control Field is 0x%x\n", register_value);
2805
2806 cb_fields_address += sizeof(u32);
2807 register_value = ipw_read_reg32(priv, cb_fields_address);
2808 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x\n", register_value);
2809
2810 cb_fields_address += sizeof(u32);
2811 register_value = ipw_read_reg32(priv, cb_fields_address);
2812 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x\n",
2813 register_value);
2814
2815 cb_fields_address += sizeof(u32);
2816 register_value = ipw_read_reg32(priv, cb_fields_address);
2817 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x\n", register_value);
2818
2819 IPW_DEBUG_FW(">> :\n");
2820 }
2821
ipw_fw_dma_command_block_index(struct ipw_priv * priv)2822 static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2823 {
2824 u32 current_cb_address = 0;
2825 u32 current_cb_index = 0;
2826
2827 IPW_DEBUG_FW("<< :\n");
2828 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
2829
2830 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
2831 sizeof(struct command_block);
2832
2833 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X\n",
2834 current_cb_index, current_cb_address);
2835
2836 IPW_DEBUG_FW(">> :\n");
2837 return current_cb_index;
2838
2839 }
2840
ipw_fw_dma_add_command_block(struct ipw_priv * priv,u32 src_address,u32 dest_address,u32 length,int interrupt_enabled,int is_last)2841 static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2842 u32 src_address,
2843 u32 dest_address,
2844 u32 length,
2845 int interrupt_enabled, int is_last)
2846 {
2847
2848 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
2849 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2850 CB_DEST_SIZE_LONG;
2851 struct command_block *cb;
2852 u32 last_cb_element = 0;
2853
2854 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2855 src_address, dest_address, length);
2856
2857 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2858 return -1;
2859
2860 last_cb_element = priv->sram_desc.last_cb_index;
2861 cb = &priv->sram_desc.cb_list[last_cb_element];
2862 priv->sram_desc.last_cb_index++;
2863
2864 /* Calculate the new CB control word */
2865 if (interrupt_enabled)
2866 control |= CB_INT_ENABLED;
2867
2868 if (is_last)
2869 control |= CB_LAST_VALID;
2870
2871 control |= length;
2872
2873 /* Calculate the CB Element's checksum value */
2874 cb->status = control ^ src_address ^ dest_address;
2875
2876 /* Copy the Source and Destination addresses */
2877 cb->dest_addr = dest_address;
2878 cb->source_addr = src_address;
2879
2880 /* Copy the Control Word last */
2881 cb->control = control;
2882
2883 return 0;
2884 }
2885
ipw_fw_dma_add_buffer(struct ipw_priv * priv,dma_addr_t * src_address,int nr,u32 dest_address,u32 len)2886 static int ipw_fw_dma_add_buffer(struct ipw_priv *priv, dma_addr_t *src_address,
2887 int nr, u32 dest_address, u32 len)
2888 {
2889 int ret, i;
2890 u32 size;
2891
2892 IPW_DEBUG_FW(">>\n");
2893 IPW_DEBUG_FW_INFO("nr=%d dest_address=0x%x len=0x%x\n",
2894 nr, dest_address, len);
2895
2896 for (i = 0; i < nr; i++) {
2897 size = min_t(u32, len - i * CB_MAX_LENGTH, CB_MAX_LENGTH);
2898 ret = ipw_fw_dma_add_command_block(priv, src_address[i],
2899 dest_address +
2900 i * CB_MAX_LENGTH, size,
2901 0, 0);
2902 if (ret) {
2903 IPW_DEBUG_FW_INFO(": Failed\n");
2904 return -1;
2905 } else
2906 IPW_DEBUG_FW_INFO(": Added new cb\n");
2907 }
2908
2909 IPW_DEBUG_FW("<<\n");
2910 return 0;
2911 }
2912
ipw_fw_dma_wait(struct ipw_priv * priv)2913 static int ipw_fw_dma_wait(struct ipw_priv *priv)
2914 {
2915 u32 current_index = 0, previous_index;
2916 u32 watchdog = 0;
2917
2918 IPW_DEBUG_FW(">> :\n");
2919
2920 current_index = ipw_fw_dma_command_block_index(priv);
2921 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
2922 (int)priv->sram_desc.last_cb_index);
2923
2924 while (current_index < priv->sram_desc.last_cb_index) {
2925 udelay(50);
2926 previous_index = current_index;
2927 current_index = ipw_fw_dma_command_block_index(priv);
2928
2929 if (previous_index < current_index) {
2930 watchdog = 0;
2931 continue;
2932 }
2933 if (++watchdog > 400) {
2934 IPW_DEBUG_FW_INFO("Timeout\n");
2935 ipw_fw_dma_dump_command_block(priv);
2936 ipw_fw_dma_abort(priv);
2937 return -1;
2938 }
2939 }
2940
2941 ipw_fw_dma_abort(priv);
2942
2943 /*Disable the DMA in the CSR register */
2944 ipw_set_bit(priv, IPW_RESET_REG,
2945 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
2946
2947 IPW_DEBUG_FW("<< dmaWaitSync\n");
2948 return 0;
2949 }
2950
ipw_remove_current_network(struct ipw_priv * priv)2951 static void ipw_remove_current_network(struct ipw_priv *priv)
2952 {
2953 struct list_head *element, *safe;
2954 struct libipw_network *network = NULL;
2955 unsigned long flags;
2956
2957 spin_lock_irqsave(&priv->ieee->lock, flags);
2958 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2959 network = list_entry(element, struct libipw_network, list);
2960 if (ether_addr_equal(network->bssid, priv->bssid)) {
2961 list_del(element);
2962 list_add_tail(&network->list,
2963 &priv->ieee->network_free_list);
2964 }
2965 }
2966 spin_unlock_irqrestore(&priv->ieee->lock, flags);
2967 }
2968
2969 /* timeout in msec, attempted in 10-msec quanta */
ipw_poll_bit(struct ipw_priv * priv,u32 addr,u32 mask,int timeout)2970 static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2971 int timeout)
2972 {
2973 int i = 0;
2974
2975 do {
2976 if ((ipw_read32(priv, addr) & mask) == mask)
2977 return i;
2978 mdelay(10);
2979 i += 10;
2980 } while (i < timeout);
2981
2982 return -ETIME;
2983 }
2984
2985 /* These functions load the firmware and micro code for the operation of
2986 * the ipw hardware. It assumes the buffer has all the bits for the
2987 * image and the caller is handling the memory allocation and clean up.
2988 */
2989
ipw_stop_master(struct ipw_priv * priv)2990 static int ipw_stop_master(struct ipw_priv *priv)
2991 {
2992 int rc;
2993
2994 IPW_DEBUG_TRACE(">>\n");
2995 /* stop master. typical delay - 0 */
2996 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
2997
2998 /* timeout is in msec, polled in 10-msec quanta */
2999 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3000 IPW_RESET_REG_MASTER_DISABLED, 100);
3001 if (rc < 0) {
3002 IPW_ERROR("wait for stop master failed after 100ms\n");
3003 return -1;
3004 }
3005
3006 IPW_DEBUG_INFO("stop master %dms\n", rc);
3007
3008 return rc;
3009 }
3010
ipw_arc_release(struct ipw_priv * priv)3011 static void ipw_arc_release(struct ipw_priv *priv)
3012 {
3013 IPW_DEBUG_TRACE(">>\n");
3014 mdelay(5);
3015
3016 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
3017
3018 /* no one knows timing, for safety add some delay */
3019 mdelay(5);
3020 }
3021
3022 struct fw_chunk {
3023 __le32 address;
3024 __le32 length;
3025 };
3026
ipw_load_ucode(struct ipw_priv * priv,u8 * data,size_t len)3027 static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
3028 {
3029 int rc = 0, i, addr;
3030 u8 cr = 0;
3031 __le16 *image;
3032
3033 image = (__le16 *) data;
3034
3035 IPW_DEBUG_TRACE(">>\n");
3036
3037 rc = ipw_stop_master(priv);
3038
3039 if (rc < 0)
3040 return rc;
3041
3042 for (addr = IPW_SHARED_LOWER_BOUND;
3043 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
3044 ipw_write32(priv, addr, 0);
3045 }
3046
3047 /* no ucode (yet) */
3048 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3049 /* destroy DMA queues */
3050 /* reset sequence */
3051
3052 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
3053 ipw_arc_release(priv);
3054 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
3055 mdelay(1);
3056
3057 /* reset PHY */
3058 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
3059 mdelay(1);
3060
3061 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
3062 mdelay(1);
3063
3064 /* enable ucode store */
3065 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3066 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
3067 mdelay(1);
3068
3069 /* write ucode */
3070 /*
3071 * @bug
3072 * Do NOT set indirect address register once and then
3073 * store data to indirect data register in the loop.
3074 * It seems very reasonable, but in this case DINO do not
3075 * accept ucode. It is essential to set address each time.
3076 */
3077 /* load new ipw uCode */
3078 for (i = 0; i < len / 2; i++)
3079 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
3080 le16_to_cpu(image[i]));
3081
3082 /* enable DINO */
3083 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3084 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
3085
3086 /* this is where the igx / win driver deveates from the VAP driver. */
3087
3088 /* wait for alive response */
3089 for (i = 0; i < 100; i++) {
3090 /* poll for incoming data */
3091 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
3092 if (cr & DINO_RXFIFO_DATA)
3093 break;
3094 mdelay(1);
3095 }
3096
3097 if (cr & DINO_RXFIFO_DATA) {
3098 /* alive_command_responce size is NOT multiple of 4 */
3099 __le32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
3100
3101 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
3102 response_buffer[i] =
3103 cpu_to_le32(ipw_read_reg32(priv,
3104 IPW_BASEBAND_RX_FIFO_READ));
3105 memcpy(&priv->dino_alive, response_buffer,
3106 sizeof(priv->dino_alive));
3107 if (priv->dino_alive.alive_command == 1
3108 && priv->dino_alive.ucode_valid == 1) {
3109 rc = 0;
3110 IPW_DEBUG_INFO
3111 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3112 "of %02d/%02d/%02d %02d:%02d\n",
3113 priv->dino_alive.software_revision,
3114 priv->dino_alive.software_revision,
3115 priv->dino_alive.device_identifier,
3116 priv->dino_alive.device_identifier,
3117 priv->dino_alive.time_stamp[0],
3118 priv->dino_alive.time_stamp[1],
3119 priv->dino_alive.time_stamp[2],
3120 priv->dino_alive.time_stamp[3],
3121 priv->dino_alive.time_stamp[4]);
3122 } else {
3123 IPW_DEBUG_INFO("Microcode is not alive\n");
3124 rc = -EINVAL;
3125 }
3126 } else {
3127 IPW_DEBUG_INFO("No alive response from DINO\n");
3128 rc = -ETIME;
3129 }
3130
3131 /* disable DINO, otherwise for some reason
3132 firmware have problem getting alive resp. */
3133 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3134
3135 return rc;
3136 }
3137
ipw_load_firmware(struct ipw_priv * priv,u8 * data,size_t len)3138 static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
3139 {
3140 int ret = -1;
3141 int offset = 0;
3142 struct fw_chunk *chunk;
3143 int total_nr = 0;
3144 int i;
3145 struct dma_pool *pool;
3146 void **virts;
3147 dma_addr_t *phys;
3148
3149 IPW_DEBUG_TRACE("<< :\n");
3150
3151 virts = kmalloc_array(CB_NUMBER_OF_ELEMENTS_SMALL, sizeof(void *),
3152 GFP_KERNEL);
3153 if (!virts)
3154 return -ENOMEM;
3155
3156 phys = kmalloc_objs(dma_addr_t, CB_NUMBER_OF_ELEMENTS_SMALL);
3157 if (!phys) {
3158 kfree(virts);
3159 return -ENOMEM;
3160 }
3161 pool = dma_pool_create("ipw2200", &priv->pci_dev->dev, CB_MAX_LENGTH, 0,
3162 0);
3163 if (!pool) {
3164 IPW_ERROR("dma_pool_create failed\n");
3165 kfree(phys);
3166 kfree(virts);
3167 return -ENOMEM;
3168 }
3169
3170 /* Start the Dma */
3171 ret = ipw_fw_dma_enable(priv);
3172
3173 /* the DMA is already ready this would be a bug. */
3174 BUG_ON(priv->sram_desc.last_cb_index > 0);
3175
3176 do {
3177 u32 chunk_len;
3178 u8 *start;
3179 int size;
3180 int nr = 0;
3181
3182 chunk = (struct fw_chunk *)(data + offset);
3183 offset += sizeof(struct fw_chunk);
3184 chunk_len = le32_to_cpu(chunk->length);
3185 start = data + offset;
3186
3187 nr = (chunk_len + CB_MAX_LENGTH - 1) / CB_MAX_LENGTH;
3188 for (i = 0; i < nr; i++) {
3189 virts[total_nr] = dma_pool_alloc(pool, GFP_KERNEL,
3190 &phys[total_nr]);
3191 if (!virts[total_nr]) {
3192 ret = -ENOMEM;
3193 goto out;
3194 }
3195 size = min_t(u32, chunk_len - i * CB_MAX_LENGTH,
3196 CB_MAX_LENGTH);
3197 memcpy(virts[total_nr], start, size);
3198 start += size;
3199 total_nr++;
3200 /* We don't support fw chunk larger than 64*8K */
3201 BUG_ON(total_nr > CB_NUMBER_OF_ELEMENTS_SMALL);
3202 }
3203
3204 /* build DMA packet and queue up for sending */
3205 /* dma to chunk->address, the chunk->length bytes from data +
3206 * offeset*/
3207 /* Dma loading */
3208 ret = ipw_fw_dma_add_buffer(priv, &phys[total_nr - nr],
3209 nr, le32_to_cpu(chunk->address),
3210 chunk_len);
3211 if (ret) {
3212 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3213 goto out;
3214 }
3215
3216 offset += chunk_len;
3217 } while (offset < len);
3218
3219 /* Run the DMA and wait for the answer */
3220 ret = ipw_fw_dma_kick(priv);
3221 if (ret) {
3222 IPW_ERROR("dmaKick Failed\n");
3223 goto out;
3224 }
3225
3226 ret = ipw_fw_dma_wait(priv);
3227 if (ret) {
3228 IPW_ERROR("dmaWaitSync Failed\n");
3229 goto out;
3230 }
3231 out:
3232 for (i = 0; i < total_nr; i++)
3233 dma_pool_free(pool, virts[i], phys[i]);
3234
3235 dma_pool_destroy(pool);
3236 kfree(phys);
3237 kfree(virts);
3238
3239 return ret;
3240 }
3241
3242 /* stop nic */
ipw_stop_nic(struct ipw_priv * priv)3243 static int ipw_stop_nic(struct ipw_priv *priv)
3244 {
3245 int rc = 0;
3246
3247 /* stop */
3248 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
3249
3250 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3251 IPW_RESET_REG_MASTER_DISABLED, 500);
3252 if (rc < 0) {
3253 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
3254 return rc;
3255 }
3256
3257 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
3258
3259 return rc;
3260 }
3261
ipw_start_nic(struct ipw_priv * priv)3262 static void ipw_start_nic(struct ipw_priv *priv)
3263 {
3264 IPW_DEBUG_TRACE(">>\n");
3265
3266 /* prvHwStartNic release ARC */
3267 ipw_clear_bit(priv, IPW_RESET_REG,
3268 IPW_RESET_REG_MASTER_DISABLED |
3269 IPW_RESET_REG_STOP_MASTER |
3270 CBD_RESET_REG_PRINCETON_RESET);
3271
3272 /* enable power management */
3273 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3274 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
3275
3276 IPW_DEBUG_TRACE("<<\n");
3277 }
3278
ipw_init_nic(struct ipw_priv * priv)3279 static int ipw_init_nic(struct ipw_priv *priv)
3280 {
3281 int rc;
3282
3283 IPW_DEBUG_TRACE(">>\n");
3284 /* reset */
3285 /*prvHwInitNic */
3286 /* set "initialization complete" bit to move adapter to D0 state */
3287 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3288
3289 /* low-level PLL activation */
3290 ipw_write32(priv, IPW_READ_INT_REGISTER,
3291 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
3292
3293 /* wait for clock stabilization */
3294 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3295 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
3296 if (rc < 0)
3297 IPW_DEBUG_INFO("FAILED wait for clock stabilization\n");
3298
3299 /* assert SW reset */
3300 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
3301
3302 udelay(10);
3303
3304 /* set "initialization complete" bit to move adapter to D0 state */
3305 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
3306
3307 IPW_DEBUG_TRACE(">>\n");
3308 return 0;
3309 }
3310
3311 /* Call this function from process context, it will sleep in request_firmware.
3312 * Probe is an ok place to call this from.
3313 */
ipw_reset_nic(struct ipw_priv * priv)3314 static int ipw_reset_nic(struct ipw_priv *priv)
3315 {
3316 int rc = 0;
3317 unsigned long flags;
3318
3319 IPW_DEBUG_TRACE(">>\n");
3320
3321 rc = ipw_init_nic(priv);
3322
3323 spin_lock_irqsave(&priv->lock, flags);
3324 /* Clear the 'host command active' bit... */
3325 priv->status &= ~STATUS_HCMD_ACTIVE;
3326 wake_up_interruptible(&priv->wait_command_queue);
3327 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3328 wake_up_interruptible(&priv->wait_state);
3329 spin_unlock_irqrestore(&priv->lock, flags);
3330
3331 IPW_DEBUG_TRACE("<<\n");
3332 return rc;
3333 }
3334
3335
3336 struct ipw_fw {
3337 __le32 ver;
3338 __le32 boot_size;
3339 __le32 ucode_size;
3340 __le32 fw_size;
3341 u8 data[];
3342 };
3343
ipw_get_fw(struct ipw_priv * priv,const struct firmware ** raw,const char * name)3344 static int ipw_get_fw(struct ipw_priv *priv,
3345 const struct firmware **raw, const char *name)
3346 {
3347 struct ipw_fw *fw;
3348 int rc;
3349
3350 /* ask firmware_class module to get the boot firmware off disk */
3351 rc = request_firmware(raw, name, &priv->pci_dev->dev);
3352 if (rc < 0) {
3353 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
3354 return rc;
3355 }
3356
3357 if ((*raw)->size < sizeof(*fw)) {
3358 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
3359 return -EINVAL;
3360 }
3361
3362 fw = (void *)(*raw)->data;
3363
3364 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3365 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
3366 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3367 name, (*raw)->size);
3368 return -EINVAL;
3369 }
3370
3371 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
3372 name,
3373 le32_to_cpu(fw->ver) >> 16,
3374 le32_to_cpu(fw->ver) & 0xff,
3375 (*raw)->size - sizeof(*fw));
3376 return 0;
3377 }
3378
3379 #define IPW_RX_BUF_SIZE (3000)
3380
ipw_rx_queue_reset(struct ipw_priv * priv,struct ipw_rx_queue * rxq)3381 static void ipw_rx_queue_reset(struct ipw_priv *priv,
3382 struct ipw_rx_queue *rxq)
3383 {
3384 unsigned long flags;
3385 int i;
3386
3387 spin_lock_irqsave(&rxq->lock, flags);
3388
3389 INIT_LIST_HEAD(&rxq->rx_free);
3390 INIT_LIST_HEAD(&rxq->rx_used);
3391
3392 /* Fill the rx_used queue with _all_ of the Rx buffers */
3393 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3394 /* In the reset function, these buffers may have been allocated
3395 * to an SKB, so we need to unmap and free potential storage */
3396 if (rxq->pool[i].skb != NULL) {
3397 dma_unmap_single(&priv->pci_dev->dev,
3398 rxq->pool[i].dma_addr,
3399 IPW_RX_BUF_SIZE, DMA_FROM_DEVICE);
3400 dev_kfree_skb_irq(rxq->pool[i].skb);
3401 rxq->pool[i].skb = NULL;
3402 }
3403 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3404 }
3405
3406 /* Set us so that we have processed and used all buffers, but have
3407 * not restocked the Rx queue with fresh buffers */
3408 rxq->read = rxq->write = 0;
3409 rxq->free_count = 0;
3410 spin_unlock_irqrestore(&rxq->lock, flags);
3411 }
3412
3413 #ifdef CONFIG_PM
3414 static int fw_loaded = 0;
3415 static const struct firmware *raw = NULL;
3416
free_firmware(void)3417 static void free_firmware(void)
3418 {
3419 if (fw_loaded) {
3420 release_firmware(raw);
3421 raw = NULL;
3422 fw_loaded = 0;
3423 }
3424 }
3425 #else
3426 #define free_firmware() do {} while (0)
3427 #endif
3428
ipw_load(struct ipw_priv * priv)3429 static int ipw_load(struct ipw_priv *priv)
3430 {
3431 #ifndef CONFIG_PM
3432 const struct firmware *raw = NULL;
3433 #endif
3434 struct ipw_fw *fw;
3435 u8 *boot_img, *ucode_img, *fw_img;
3436 u8 *name = NULL;
3437 int rc = 0, retries = 3;
3438
3439 switch (priv->ieee->iw_mode) {
3440 case IW_MODE_ADHOC:
3441 name = "ipw2200-ibss.fw";
3442 break;
3443 #ifdef CONFIG_IPW2200_MONITOR
3444 case IW_MODE_MONITOR:
3445 name = "ipw2200-sniffer.fw";
3446 break;
3447 #endif
3448 case IW_MODE_INFRA:
3449 name = "ipw2200-bss.fw";
3450 break;
3451 }
3452
3453 if (!name) {
3454 rc = -EINVAL;
3455 goto error;
3456 }
3457
3458 #ifdef CONFIG_PM
3459 if (!fw_loaded) {
3460 #endif
3461 rc = ipw_get_fw(priv, &raw, name);
3462 if (rc < 0)
3463 goto error;
3464 #ifdef CONFIG_PM
3465 }
3466 #endif
3467
3468 fw = (void *)raw->data;
3469 boot_img = &fw->data[0];
3470 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3471 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3472 le32_to_cpu(fw->ucode_size)];
3473
3474 if (!priv->rxq)
3475 priv->rxq = ipw_rx_queue_alloc(priv);
3476 else
3477 ipw_rx_queue_reset(priv, priv->rxq);
3478 if (!priv->rxq) {
3479 IPW_ERROR("Unable to initialize Rx queue\n");
3480 rc = -ENOMEM;
3481 goto error;
3482 }
3483
3484 retry:
3485 /* Ensure interrupts are disabled */
3486 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3487 priv->status &= ~STATUS_INT_ENABLED;
3488
3489 /* ack pending interrupts */
3490 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3491
3492 ipw_stop_nic(priv);
3493
3494 rc = ipw_reset_nic(priv);
3495 if (rc < 0) {
3496 IPW_ERROR("Unable to reset NIC\n");
3497 goto error;
3498 }
3499
3500 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3501 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
3502
3503 /* DMA the initial boot firmware into the device */
3504 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
3505 if (rc < 0) {
3506 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
3507 goto error;
3508 }
3509
3510 /* kick start the device */
3511 ipw_start_nic(priv);
3512
3513 /* wait for the device to finish its initial startup sequence */
3514 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3515 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3516 if (rc < 0) {
3517 IPW_ERROR("device failed to boot initial fw image\n");
3518 goto error;
3519 }
3520 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3521
3522 /* ack fw init done interrupt */
3523 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3524
3525 /* DMA the ucode into the device */
3526 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
3527 if (rc < 0) {
3528 IPW_ERROR("Unable to load ucode: %d\n", rc);
3529 goto error;
3530 }
3531
3532 /* stop nic */
3533 ipw_stop_nic(priv);
3534
3535 /* DMA bss firmware into the device */
3536 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
3537 if (rc < 0) {
3538 IPW_ERROR("Unable to load firmware: %d\n", rc);
3539 goto error;
3540 }
3541 #ifdef CONFIG_PM
3542 fw_loaded = 1;
3543 #endif
3544
3545 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3546
3547 rc = ipw_queue_reset(priv);
3548 if (rc < 0) {
3549 IPW_ERROR("Unable to initialize queues\n");
3550 goto error;
3551 }
3552
3553 /* Ensure interrupts are disabled */
3554 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3555 /* ack pending interrupts */
3556 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3557
3558 /* kick start the device */
3559 ipw_start_nic(priv);
3560
3561 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
3562 if (retries > 0) {
3563 IPW_WARNING("Parity error. Retrying init.\n");
3564 retries--;
3565 goto retry;
3566 }
3567
3568 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3569 rc = -EIO;
3570 goto error;
3571 }
3572
3573 /* wait for the device */
3574 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3575 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
3576 if (rc < 0) {
3577 IPW_ERROR("device failed to start within 500ms\n");
3578 goto error;
3579 }
3580 IPW_DEBUG_INFO("device response after %dms\n", rc);
3581
3582 /* ack fw init done interrupt */
3583 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3584
3585 /* read eeprom data */
3586 priv->eeprom_delay = 1;
3587 ipw_read_eeprom(priv);
3588 /* initialize the eeprom region of sram */
3589 ipw_eeprom_init_sram(priv);
3590
3591 /* enable interrupts */
3592 ipw_enable_interrupts(priv);
3593
3594 /* Ensure our queue has valid packets */
3595 ipw_rx_queue_replenish(priv);
3596
3597 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
3598
3599 /* ack pending interrupts */
3600 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
3601
3602 #ifndef CONFIG_PM
3603 release_firmware(raw);
3604 #endif
3605 return 0;
3606
3607 error:
3608 if (priv->rxq) {
3609 ipw_rx_queue_free(priv, priv->rxq);
3610 priv->rxq = NULL;
3611 }
3612 ipw_tx_queue_free(priv);
3613 release_firmware(raw);
3614 #ifdef CONFIG_PM
3615 fw_loaded = 0;
3616 raw = NULL;
3617 #endif
3618
3619 return rc;
3620 }
3621
3622 /*
3623 * DMA services
3624 *
3625 * Theory of operation
3626 *
3627 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3628 * 2 empty entries always kept in the buffer to protect from overflow.
3629 *
3630 * For Tx queue, there are low mark and high mark limits. If, after queuing
3631 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3632 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
3633 * Tx queue resumed.
3634 *
3635 * The IPW operates with six queues, one receive queue in the device's
3636 * sram, one transmit queue for sending commands to the device firmware,
3637 * and four transmit queues for data.
3638 *
3639 * The four transmit queues allow for performing quality of service (qos)
3640 * transmissions as per the 802.11 protocol. Currently Linux does not
3641 * provide a mechanism to the user for utilizing prioritized queues, so
3642 * we only utilize the first data transmit queue (queue1).
3643 */
3644
3645 /*
3646 * Driver allocates buffers of this size for Rx
3647 */
3648
3649 /*
3650 * ipw_rx_queue_space - Return number of free slots available in queue.
3651 */
ipw_rx_queue_space(const struct ipw_rx_queue * q)3652 static int ipw_rx_queue_space(const struct ipw_rx_queue *q)
3653 {
3654 int s = q->read - q->write;
3655 if (s <= 0)
3656 s += RX_QUEUE_SIZE;
3657 /* keep some buffer to not confuse full and empty queue */
3658 s -= 2;
3659 if (s < 0)
3660 s = 0;
3661 return s;
3662 }
3663
ipw_tx_queue_space(const struct clx2_queue * q)3664 static inline int ipw_tx_queue_space(const struct clx2_queue *q)
3665 {
3666 int s = q->last_used - q->first_empty;
3667 if (s <= 0)
3668 s += q->n_bd;
3669 s -= 2; /* keep some reserve to not confuse empty and full situations */
3670 if (s < 0)
3671 s = 0;
3672 return s;
3673 }
3674
ipw_queue_inc_wrap(int index,int n_bd)3675 static inline int ipw_queue_inc_wrap(int index, int n_bd)
3676 {
3677 return (++index == n_bd) ? 0 : index;
3678 }
3679
3680 /*
3681 * Initialize common DMA queue structure
3682 *
3683 * @param q queue to init
3684 * @param count Number of BD's to allocate. Should be power of 2
3685 * @param read_register Address for 'read' register
3686 * (not offset within BAR, full address)
3687 * @param write_register Address for 'write' register
3688 * (not offset within BAR, full address)
3689 * @param base_register Address for 'base' register
3690 * (not offset within BAR, full address)
3691 * @param size Address for 'size' register
3692 * (not offset within BAR, full address)
3693 */
ipw_queue_init(struct ipw_priv * priv,struct clx2_queue * q,int count,u32 read,u32 write,u32 base,u32 size)3694 static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
3695 int count, u32 read, u32 write, u32 base, u32 size)
3696 {
3697 q->n_bd = count;
3698
3699 q->low_mark = q->n_bd / 4;
3700 if (q->low_mark < 4)
3701 q->low_mark = 4;
3702
3703 q->high_mark = q->n_bd / 8;
3704 if (q->high_mark < 2)
3705 q->high_mark = 2;
3706
3707 q->first_empty = q->last_used = 0;
3708 q->reg_r = read;
3709 q->reg_w = write;
3710
3711 ipw_write32(priv, base, q->dma_addr);
3712 ipw_write32(priv, size, count);
3713 ipw_write32(priv, read, 0);
3714 ipw_write32(priv, write, 0);
3715
3716 _ipw_read32(priv, 0x90);
3717 }
3718
ipw_queue_tx_init(struct ipw_priv * priv,struct clx2_tx_queue * q,int count,u32 read,u32 write,u32 base,u32 size)3719 static int ipw_queue_tx_init(struct ipw_priv *priv,
3720 struct clx2_tx_queue *q,
3721 int count, u32 read, u32 write, u32 base, u32 size)
3722 {
3723 struct pci_dev *dev = priv->pci_dev;
3724
3725 q->txb = kmalloc_objs(q->txb[0], count);
3726 if (!q->txb)
3727 return -ENOMEM;
3728
3729 q->bd =
3730 dma_alloc_coherent(&dev->dev, sizeof(q->bd[0]) * count,
3731 &q->q.dma_addr, GFP_KERNEL);
3732 if (!q->bd) {
3733 IPW_ERROR("dma_alloc_coherent(%zd) failed\n",
3734 sizeof(q->bd[0]) * count);
3735 kfree(q->txb);
3736 q->txb = NULL;
3737 return -ENOMEM;
3738 }
3739
3740 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3741 return 0;
3742 }
3743
3744 /*
3745 * Free one TFD, those at index [txq->q.last_used].
3746 * Do NOT advance any indexes
3747 *
3748 * @param dev
3749 * @param txq
3750 */
ipw_queue_tx_free_tfd(struct ipw_priv * priv,struct clx2_tx_queue * txq)3751 static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3752 struct clx2_tx_queue *txq)
3753 {
3754 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3755 struct pci_dev *dev = priv->pci_dev;
3756 int i;
3757
3758 /* classify bd */
3759 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3760 /* nothing to cleanup after for host commands */
3761 return;
3762
3763 /* sanity check */
3764 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3765 IPW_ERROR("Too many chunks: %i\n",
3766 le32_to_cpu(bd->u.data.num_chunks));
3767 /* @todo issue fatal error, it is quite serious situation */
3768 return;
3769 }
3770
3771 /* unmap chunks if any */
3772 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3773 dma_unmap_single(&dev->dev,
3774 le32_to_cpu(bd->u.data.chunk_ptr[i]),
3775 le16_to_cpu(bd->u.data.chunk_len[i]),
3776 DMA_TO_DEVICE);
3777 if (txq->txb[txq->q.last_used]) {
3778 libipw_txb_free(txq->txb[txq->q.last_used]);
3779 txq->txb[txq->q.last_used] = NULL;
3780 }
3781 }
3782 }
3783
3784 /*
3785 * Deallocate DMA queue.
3786 *
3787 * Empty queue by removing and destroying all BD's.
3788 * Free all buffers.
3789 *
3790 * @param dev
3791 * @param q
3792 */
ipw_queue_tx_free(struct ipw_priv * priv,struct clx2_tx_queue * txq)3793 static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
3794 {
3795 struct clx2_queue *q = &txq->q;
3796 struct pci_dev *dev = priv->pci_dev;
3797
3798 if (q->n_bd == 0)
3799 return;
3800
3801 /* first, empty all BD's */
3802 for (; q->first_empty != q->last_used;
3803 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3804 ipw_queue_tx_free_tfd(priv, txq);
3805 }
3806
3807 /* free buffers belonging to queue itself */
3808 dma_free_coherent(&dev->dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
3809 q->dma_addr);
3810 kfree(txq->txb);
3811
3812 /* 0 fill whole structure */
3813 memset(txq, 0, sizeof(*txq));
3814 }
3815
3816 /*
3817 * Destroy all DMA queues and structures
3818 *
3819 * @param priv
3820 */
ipw_tx_queue_free(struct ipw_priv * priv)3821 static void ipw_tx_queue_free(struct ipw_priv *priv)
3822 {
3823 /* Tx CMD queue */
3824 ipw_queue_tx_free(priv, &priv->txq_cmd);
3825
3826 /* Tx queues */
3827 ipw_queue_tx_free(priv, &priv->txq[0]);
3828 ipw_queue_tx_free(priv, &priv->txq[1]);
3829 ipw_queue_tx_free(priv, &priv->txq[2]);
3830 ipw_queue_tx_free(priv, &priv->txq[3]);
3831 }
3832
ipw_create_bssid(struct ipw_priv * priv,u8 * bssid)3833 static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
3834 {
3835 /* First 3 bytes are manufacturer */
3836 bssid[0] = priv->mac_addr[0];
3837 bssid[1] = priv->mac_addr[1];
3838 bssid[2] = priv->mac_addr[2];
3839
3840 /* Last bytes are random */
3841 get_random_bytes(&bssid[3], ETH_ALEN - 3);
3842
3843 bssid[0] &= 0xfe; /* clear multicast bit */
3844 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
3845 }
3846
ipw_add_station(struct ipw_priv * priv,u8 * bssid)3847 static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
3848 {
3849 struct ipw_station_entry entry;
3850 int i;
3851
3852 for (i = 0; i < priv->num_stations; i++) {
3853 if (ether_addr_equal(priv->stations[i], bssid)) {
3854 /* Another node is active in network */
3855 priv->missed_adhoc_beacons = 0;
3856 if (!(priv->config & CFG_STATIC_CHANNEL))
3857 /* when other nodes drop out, we drop out */
3858 priv->config &= ~CFG_ADHOC_PERSIST;
3859
3860 return i;
3861 }
3862 }
3863
3864 if (i == MAX_STATIONS)
3865 return IPW_INVALID_STATION;
3866
3867 IPW_DEBUG_SCAN("Adding AdHoc station: %pM\n", bssid);
3868
3869 entry.reserved = 0;
3870 entry.support_mode = 0;
3871 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3872 memcpy(priv->stations[i], bssid, ETH_ALEN);
3873 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
3874 &entry, sizeof(entry));
3875 priv->num_stations++;
3876
3877 return i;
3878 }
3879
ipw_find_station(struct ipw_priv * priv,u8 * bssid)3880 static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
3881 {
3882 int i;
3883
3884 for (i = 0; i < priv->num_stations; i++)
3885 if (ether_addr_equal(priv->stations[i], bssid))
3886 return i;
3887
3888 return IPW_INVALID_STATION;
3889 }
3890
ipw_send_disassociate(struct ipw_priv * priv,int quiet)3891 static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3892 {
3893 int err;
3894
3895 if (priv->status & STATUS_ASSOCIATING) {
3896 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3897 schedule_work(&priv->disassociate);
3898 return;
3899 }
3900
3901 if (!(priv->status & STATUS_ASSOCIATED)) {
3902 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3903 return;
3904 }
3905
3906 IPW_DEBUG_ASSOC("Disassociation attempt from %pM "
3907 "on channel %d.\n",
3908 priv->assoc_request.bssid,
3909 priv->assoc_request.channel);
3910
3911 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3912 priv->status |= STATUS_DISASSOCIATING;
3913
3914 if (quiet)
3915 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3916 else
3917 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
3918
3919 err = ipw_send_associate(priv, &priv->assoc_request);
3920 if (err) {
3921 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3922 "failed.\n");
3923 return;
3924 }
3925
3926 }
3927
ipw_disassociate(void * data)3928 static int ipw_disassociate(void *data)
3929 {
3930 struct ipw_priv *priv = data;
3931 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3932 return 0;
3933 ipw_send_disassociate(data, 0);
3934 netif_carrier_off(priv->net_dev);
3935 return 1;
3936 }
3937
ipw_bg_disassociate(struct work_struct * work)3938 static void ipw_bg_disassociate(struct work_struct *work)
3939 {
3940 struct ipw_priv *priv =
3941 container_of(work, struct ipw_priv, disassociate);
3942 mutex_lock(&priv->mutex);
3943 ipw_disassociate(priv);
3944 mutex_unlock(&priv->mutex);
3945 }
3946
ipw_system_config(struct work_struct * work)3947 static void ipw_system_config(struct work_struct *work)
3948 {
3949 struct ipw_priv *priv =
3950 container_of(work, struct ipw_priv, system_config);
3951
3952 #ifdef CONFIG_IPW2200_PROMISCUOUS
3953 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
3954 priv->sys_config.accept_all_data_frames = 1;
3955 priv->sys_config.accept_non_directed_frames = 1;
3956 priv->sys_config.accept_all_mgmt_bcpr = 1;
3957 priv->sys_config.accept_all_mgmt_frames = 1;
3958 }
3959 #endif
3960
3961 ipw_send_system_config(priv);
3962 }
3963
3964 struct ipw_status_code {
3965 u16 status;
3966 const char *reason;
3967 };
3968
3969 static const struct ipw_status_code ipw_status_codes[] = {
3970 {0x00, "Successful"},
3971 {0x01, "Unspecified failure"},
3972 {0x0A, "Cannot support all requested capabilities in the "
3973 "Capability information field"},
3974 {0x0B, "Reassociation denied due to inability to confirm that "
3975 "association exists"},
3976 {0x0C, "Association denied due to reason outside the scope of this "
3977 "standard"},
3978 {0x0D,
3979 "Responding station does not support the specified authentication "
3980 "algorithm"},
3981 {0x0E,
3982 "Received an Authentication frame with authentication sequence "
3983 "transaction sequence number out of expected sequence"},
3984 {0x0F, "Authentication rejected because of challenge failure"},
3985 {0x10, "Authentication rejected due to timeout waiting for next "
3986 "frame in sequence"},
3987 {0x11, "Association denied because AP is unable to handle additional "
3988 "associated stations"},
3989 {0x12,
3990 "Association denied due to requesting station not supporting all "
3991 "of the datarates in the BSSBasicServiceSet Parameter"},
3992 {0x13,
3993 "Association denied due to requesting station not supporting "
3994 "short preamble operation"},
3995 {0x14,
3996 "Association denied due to requesting station not supporting "
3997 "PBCC encoding"},
3998 {0x15,
3999 "Association denied due to requesting station not supporting "
4000 "channel agility"},
4001 {0x19,
4002 "Association denied due to requesting station not supporting "
4003 "short slot operation"},
4004 {0x1A,
4005 "Association denied due to requesting station not supporting "
4006 "DSSS-OFDM operation"},
4007 {0x28, "Invalid Information Element"},
4008 {0x29, "Group Cipher is not valid"},
4009 {0x2A, "Pairwise Cipher is not valid"},
4010 {0x2B, "AKMP is not valid"},
4011 {0x2C, "Unsupported RSN IE version"},
4012 {0x2D, "Invalid RSN IE Capabilities"},
4013 {0x2E, "Cipher suite is rejected per security policy"},
4014 };
4015
ipw_get_status_code(u16 status)4016 static const char *ipw_get_status_code(u16 status)
4017 {
4018 int i;
4019 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
4020 if (ipw_status_codes[i].status == (status & 0xff))
4021 return ipw_status_codes[i].reason;
4022 return "Unknown status value.";
4023 }
4024
average_init(struct average * avg)4025 static inline void average_init(struct average *avg)
4026 {
4027 memset(avg, 0, sizeof(*avg));
4028 }
4029
4030 #define DEPTH_RSSI 8
4031 #define DEPTH_NOISE 16
exponential_average(s16 prev_avg,s16 val,u8 depth)4032 static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
4033 {
4034 return ((depth-1)*prev_avg + val)/depth;
4035 }
4036
average_add(struct average * avg,s16 val)4037 static void average_add(struct average *avg, s16 val)
4038 {
4039 avg->sum -= avg->entries[avg->pos];
4040 avg->sum += val;
4041 avg->entries[avg->pos++] = val;
4042 if (unlikely(avg->pos == AVG_ENTRIES)) {
4043 avg->init = 1;
4044 avg->pos = 0;
4045 }
4046 }
4047
average_value(struct average * avg)4048 static s16 average_value(struct average *avg)
4049 {
4050 if (!unlikely(avg->init)) {
4051 if (avg->pos)
4052 return avg->sum / avg->pos;
4053 return 0;
4054 }
4055
4056 return avg->sum / AVG_ENTRIES;
4057 }
4058
ipw_reset_stats(struct ipw_priv * priv)4059 static void ipw_reset_stats(struct ipw_priv *priv)
4060 {
4061 u32 len = sizeof(u32);
4062
4063 priv->quality = 0;
4064
4065 average_init(&priv->average_missed_beacons);
4066 priv->exp_avg_rssi = -60;
4067 priv->exp_avg_noise = -85 + 0x100;
4068
4069 priv->last_rate = 0;
4070 priv->last_missed_beacons = 0;
4071 priv->last_rx_packets = 0;
4072 priv->last_tx_packets = 0;
4073 priv->last_tx_failures = 0;
4074
4075 /* Firmware managed, reset only when NIC is restarted, so we have to
4076 * normalize on the current value */
4077 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
4078 &priv->last_rx_err, &len);
4079 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
4080 &priv->last_tx_failures, &len);
4081
4082 /* Driver managed, reset with each association */
4083 priv->missed_adhoc_beacons = 0;
4084 priv->missed_beacons = 0;
4085 priv->tx_packets = 0;
4086 priv->rx_packets = 0;
4087
4088 }
4089
ipw_get_max_rate(struct ipw_priv * priv)4090 static u32 ipw_get_max_rate(struct ipw_priv *priv)
4091 {
4092 u32 i = 0x80000000;
4093 u32 mask = priv->rates_mask;
4094 /* If currently associated in B mode, restrict the maximum
4095 * rate match to B rates */
4096 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
4097 mask &= LIBIPW_CCK_RATES_MASK;
4098
4099 /* TODO: Verify that the rate is supported by the current rates
4100 * list. */
4101
4102 while (i && !(mask & i))
4103 i >>= 1;
4104 switch (i) {
4105 case LIBIPW_CCK_RATE_1MB_MASK:
4106 return 1000000;
4107 case LIBIPW_CCK_RATE_2MB_MASK:
4108 return 2000000;
4109 case LIBIPW_CCK_RATE_5MB_MASK:
4110 return 5500000;
4111 case LIBIPW_OFDM_RATE_6MB_MASK:
4112 return 6000000;
4113 case LIBIPW_OFDM_RATE_9MB_MASK:
4114 return 9000000;
4115 case LIBIPW_CCK_RATE_11MB_MASK:
4116 return 11000000;
4117 case LIBIPW_OFDM_RATE_12MB_MASK:
4118 return 12000000;
4119 case LIBIPW_OFDM_RATE_18MB_MASK:
4120 return 18000000;
4121 case LIBIPW_OFDM_RATE_24MB_MASK:
4122 return 24000000;
4123 case LIBIPW_OFDM_RATE_36MB_MASK:
4124 return 36000000;
4125 case LIBIPW_OFDM_RATE_48MB_MASK:
4126 return 48000000;
4127 case LIBIPW_OFDM_RATE_54MB_MASK:
4128 return 54000000;
4129 }
4130
4131 if (priv->ieee->mode == IEEE_B)
4132 return 11000000;
4133 else
4134 return 54000000;
4135 }
4136
ipw_get_current_rate(struct ipw_priv * priv)4137 static u32 ipw_get_current_rate(struct ipw_priv *priv)
4138 {
4139 u32 rate, len = sizeof(rate);
4140 int err;
4141
4142 if (!(priv->status & STATUS_ASSOCIATED))
4143 return 0;
4144
4145 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
4146 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
4147 &len);
4148 if (err) {
4149 IPW_DEBUG_INFO("failed querying ordinals.\n");
4150 return 0;
4151 }
4152 } else
4153 return ipw_get_max_rate(priv);
4154
4155 switch (rate) {
4156 case IPW_TX_RATE_1MB:
4157 return 1000000;
4158 case IPW_TX_RATE_2MB:
4159 return 2000000;
4160 case IPW_TX_RATE_5MB:
4161 return 5500000;
4162 case IPW_TX_RATE_6MB:
4163 return 6000000;
4164 case IPW_TX_RATE_9MB:
4165 return 9000000;
4166 case IPW_TX_RATE_11MB:
4167 return 11000000;
4168 case IPW_TX_RATE_12MB:
4169 return 12000000;
4170 case IPW_TX_RATE_18MB:
4171 return 18000000;
4172 case IPW_TX_RATE_24MB:
4173 return 24000000;
4174 case IPW_TX_RATE_36MB:
4175 return 36000000;
4176 case IPW_TX_RATE_48MB:
4177 return 48000000;
4178 case IPW_TX_RATE_54MB:
4179 return 54000000;
4180 }
4181
4182 return 0;
4183 }
4184
4185 #define IPW_STATS_INTERVAL (2 * HZ)
ipw_gather_stats(struct ipw_priv * priv)4186 static void ipw_gather_stats(struct ipw_priv *priv)
4187 {
4188 u32 rx_err, rx_err_delta, rx_packets_delta;
4189 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4190 u32 missed_beacons_percent, missed_beacons_delta;
4191 u32 quality = 0;
4192 u32 len = sizeof(u32);
4193 s16 rssi;
4194 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
4195 rate_quality;
4196 u32 max_rate;
4197
4198 if (!(priv->status & STATUS_ASSOCIATED)) {
4199 priv->quality = 0;
4200 return;
4201 }
4202
4203 /* Update the statistics */
4204 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
4205 &priv->missed_beacons, &len);
4206 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
4207 priv->last_missed_beacons = priv->missed_beacons;
4208 if (priv->assoc_request.beacon_interval) {
4209 missed_beacons_percent = missed_beacons_delta *
4210 (HZ * le16_to_cpu(priv->assoc_request.beacon_interval)) /
4211 (IPW_STATS_INTERVAL * 10);
4212 } else {
4213 missed_beacons_percent = 0;
4214 }
4215 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4216
4217 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4218 rx_err_delta = rx_err - priv->last_rx_err;
4219 priv->last_rx_err = rx_err;
4220
4221 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4222 tx_failures_delta = tx_failures - priv->last_tx_failures;
4223 priv->last_tx_failures = tx_failures;
4224
4225 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4226 priv->last_rx_packets = priv->rx_packets;
4227
4228 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4229 priv->last_tx_packets = priv->tx_packets;
4230
4231 /* Calculate quality based on the following:
4232 *
4233 * Missed beacon: 100% = 0, 0% = 70% missed
4234 * Rate: 60% = 1Mbs, 100% = Max
4235 * Rx and Tx errors represent a straight % of total Rx/Tx
4236 * RSSI: 100% = > -50, 0% = < -80
4237 * Rx errors: 100% = 0, 0% = 50% missed
4238 *
4239 * The lowest computed quality is used.
4240 *
4241 */
4242 #define BEACON_THRESHOLD 5
4243 beacon_quality = 100 - missed_beacons_percent;
4244 if (beacon_quality < BEACON_THRESHOLD)
4245 beacon_quality = 0;
4246 else
4247 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
4248 (100 - BEACON_THRESHOLD);
4249 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
4250 beacon_quality, missed_beacons_percent);
4251
4252 priv->last_rate = ipw_get_current_rate(priv);
4253 max_rate = ipw_get_max_rate(priv);
4254 rate_quality = priv->last_rate * 40 / max_rate + 60;
4255 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4256 rate_quality, priv->last_rate / 1000000);
4257
4258 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
4259 rx_quality = 100 - (rx_err_delta * 100) /
4260 (rx_packets_delta + rx_err_delta);
4261 else
4262 rx_quality = 100;
4263 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4264 rx_quality, rx_err_delta, rx_packets_delta);
4265
4266 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
4267 tx_quality = 100 - (tx_failures_delta * 100) /
4268 (tx_packets_delta + tx_failures_delta);
4269 else
4270 tx_quality = 100;
4271 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4272 tx_quality, tx_failures_delta, tx_packets_delta);
4273
4274 rssi = priv->exp_avg_rssi;
4275 signal_quality =
4276 (100 *
4277 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4278 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4279 (priv->ieee->perfect_rssi - rssi) *
4280 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4281 62 * (priv->ieee->perfect_rssi - rssi))) /
4282 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4283 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4284 if (signal_quality > 100)
4285 signal_quality = 100;
4286 else if (signal_quality < 1)
4287 signal_quality = 0;
4288
4289 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
4290 signal_quality, rssi);
4291
4292 quality = min(rx_quality, signal_quality);
4293 quality = min(tx_quality, quality);
4294 quality = min(rate_quality, quality);
4295 quality = min(beacon_quality, quality);
4296 if (quality == beacon_quality)
4297 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4298 quality);
4299 if (quality == rate_quality)
4300 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4301 quality);
4302 if (quality == tx_quality)
4303 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4304 quality);
4305 if (quality == rx_quality)
4306 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4307 quality);
4308 if (quality == signal_quality)
4309 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4310 quality);
4311
4312 priv->quality = quality;
4313
4314 schedule_delayed_work(&priv->gather_stats, IPW_STATS_INTERVAL);
4315 }
4316
ipw_bg_gather_stats(struct work_struct * work)4317 static void ipw_bg_gather_stats(struct work_struct *work)
4318 {
4319 struct ipw_priv *priv =
4320 container_of(work, struct ipw_priv, gather_stats.work);
4321 mutex_lock(&priv->mutex);
4322 ipw_gather_stats(priv);
4323 mutex_unlock(&priv->mutex);
4324 }
4325
4326 /* Missed beacon behavior:
4327 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4328 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4329 * Above disassociate threshold, give up and stop scanning.
4330 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
ipw_handle_missed_beacon(struct ipw_priv * priv,int missed_count)4331 static void ipw_handle_missed_beacon(struct ipw_priv *priv,
4332 int missed_count)
4333 {
4334 priv->notif_missed_beacons = missed_count;
4335
4336 if (missed_count > priv->disassociate_threshold &&
4337 priv->status & STATUS_ASSOCIATED) {
4338 /* If associated and we've hit the missed
4339 * beacon threshold, disassociate, turn
4340 * off roaming, and abort any active scans */
4341 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4342 IPW_DL_STATE | IPW_DL_ASSOC,
4343 "Missed beacon: %d - disassociate\n", missed_count);
4344 priv->status &= ~STATUS_ROAMING;
4345 if (priv->status & STATUS_SCANNING) {
4346 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4347 IPW_DL_STATE,
4348 "Aborting scan with missed beacon.\n");
4349 schedule_work(&priv->abort_scan);
4350 }
4351
4352 schedule_work(&priv->disassociate);
4353 return;
4354 }
4355
4356 if (priv->status & STATUS_ROAMING) {
4357 /* If we are currently roaming, then just
4358 * print a debug statement... */
4359 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4360 "Missed beacon: %d - roam in progress\n",
4361 missed_count);
4362 return;
4363 }
4364
4365 if (roaming &&
4366 (missed_count > priv->roaming_threshold &&
4367 missed_count <= priv->disassociate_threshold)) {
4368 /* If we are not already roaming, set the ROAM
4369 * bit in the status and kick off a scan.
4370 * This can happen several times before we reach
4371 * disassociate_threshold. */
4372 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4373 "Missed beacon: %d - initiate "
4374 "roaming\n", missed_count);
4375 if (!(priv->status & STATUS_ROAMING)) {
4376 priv->status |= STATUS_ROAMING;
4377 if (!(priv->status & STATUS_SCANNING))
4378 schedule_delayed_work(&priv->request_scan, 0);
4379 }
4380 return;
4381 }
4382
4383 if (priv->status & STATUS_SCANNING &&
4384 missed_count > IPW_MB_SCAN_CANCEL_THRESHOLD) {
4385 /* Stop scan to keep fw from getting
4386 * stuck (only if we aren't roaming --
4387 * otherwise we'll never scan more than 2 or 3
4388 * channels..) */
4389 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4390 "Aborting scan with missed beacon.\n");
4391 schedule_work(&priv->abort_scan);
4392 }
4393
4394 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
4395 }
4396
ipw_scan_event(struct work_struct * work)4397 static void ipw_scan_event(struct work_struct *work)
4398 {
4399 union iwreq_data wrqu;
4400
4401 struct ipw_priv *priv =
4402 container_of(work, struct ipw_priv, scan_event.work);
4403
4404 wrqu.data.length = 0;
4405 wrqu.data.flags = 0;
4406 wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
4407 }
4408
handle_scan_event(struct ipw_priv * priv)4409 static void handle_scan_event(struct ipw_priv *priv)
4410 {
4411 /* Only userspace-requested scan completion events go out immediately */
4412 if (!priv->user_requested_scan) {
4413 schedule_delayed_work(&priv->scan_event,
4414 round_jiffies_relative(msecs_to_jiffies(4000)));
4415 } else {
4416 priv->user_requested_scan = 0;
4417 mod_delayed_work(system_percpu_wq, &priv->scan_event, 0);
4418 }
4419 }
4420
4421 /*
4422 * Handle host notification packet.
4423 * Called from interrupt routine
4424 */
ipw_rx_notification(struct ipw_priv * priv,struct ipw_rx_notification * notif)4425 static void ipw_rx_notification(struct ipw_priv *priv,
4426 struct ipw_rx_notification *notif)
4427 {
4428 u16 size = le16_to_cpu(notif->size);
4429
4430 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, size);
4431
4432 switch (notif->subtype) {
4433 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4434 struct notif_association *assoc = ¬if->u.assoc;
4435
4436 switch (assoc->state) {
4437 case CMAS_ASSOCIATED:{
4438 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4439 IPW_DL_ASSOC,
4440 "associated: '%*pE' %pM\n",
4441 priv->essid_len, priv->essid,
4442 priv->bssid);
4443
4444 switch (priv->ieee->iw_mode) {
4445 case IW_MODE_INFRA:
4446 memcpy(priv->ieee->bssid,
4447 priv->bssid, ETH_ALEN);
4448 break;
4449
4450 case IW_MODE_ADHOC:
4451 memcpy(priv->ieee->bssid,
4452 priv->bssid, ETH_ALEN);
4453
4454 /* clear out the station table */
4455 priv->num_stations = 0;
4456
4457 IPW_DEBUG_ASSOC
4458 ("queueing adhoc check\n");
4459 schedule_delayed_work(
4460 &priv->adhoc_check,
4461 le16_to_cpu(priv->
4462 assoc_request.
4463 beacon_interval));
4464 break;
4465 }
4466
4467 priv->status &= ~STATUS_ASSOCIATING;
4468 priv->status |= STATUS_ASSOCIATED;
4469 schedule_work(&priv->system_config);
4470
4471 #ifdef CONFIG_IPW2200_QOS
4472 #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4473 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_control))
4474 if ((priv->status & STATUS_AUTH) &&
4475 (IPW_GET_PACKET_STYPE(¬if->u.raw)
4476 == IEEE80211_STYPE_ASSOC_RESP)) {
4477 if ((sizeof
4478 (struct
4479 libipw_assoc_response)
4480 <= size)
4481 && (size <= 2314)) {
4482 struct
4483 libipw_rx_stats
4484 stats = {
4485 .len = size - 1,
4486 };
4487
4488 IPW_DEBUG_QOS
4489 ("QoS Associate "
4490 "size %d\n", size);
4491 libipw_rx_mgt(priv->
4492 ieee,
4493 (struct
4494 libipw_hdr_4addr
4495 *)
4496 ¬if->u.raw, &stats);
4497 }
4498 }
4499 #endif
4500
4501 schedule_work(&priv->link_up);
4502
4503 break;
4504 }
4505
4506 case CMAS_AUTHENTICATED:{
4507 if (priv->
4508 status & (STATUS_ASSOCIATED |
4509 STATUS_AUTH)) {
4510 struct notif_authenticate *auth
4511 = ¬if->u.auth;
4512 IPW_DEBUG(IPW_DL_NOTIF |
4513 IPW_DL_STATE |
4514 IPW_DL_ASSOC,
4515 "deauthenticated: '%*pE' %pM: (0x%04X) - %s\n",
4516 priv->essid_len,
4517 priv->essid,
4518 priv->bssid,
4519 le16_to_cpu(auth->status),
4520 ipw_get_status_code
4521 (le16_to_cpu
4522 (auth->status)));
4523
4524 priv->status &=
4525 ~(STATUS_ASSOCIATING |
4526 STATUS_AUTH |
4527 STATUS_ASSOCIATED);
4528
4529 schedule_work(&priv->link_down);
4530 break;
4531 }
4532
4533 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4534 IPW_DL_ASSOC,
4535 "authenticated: '%*pE' %pM\n",
4536 priv->essid_len, priv->essid,
4537 priv->bssid);
4538 break;
4539 }
4540
4541 case CMAS_INIT:{
4542 if (priv->status & STATUS_AUTH) {
4543 struct
4544 libipw_assoc_response
4545 *resp;
4546 resp =
4547 (struct
4548 libipw_assoc_response
4549 *)¬if->u.raw;
4550 IPW_DEBUG(IPW_DL_NOTIF |
4551 IPW_DL_STATE |
4552 IPW_DL_ASSOC,
4553 "association failed (0x%04X): %s\n",
4554 le16_to_cpu(resp->status),
4555 ipw_get_status_code
4556 (le16_to_cpu
4557 (resp->status)));
4558 }
4559
4560 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4561 IPW_DL_ASSOC,
4562 "disassociated: '%*pE' %pM\n",
4563 priv->essid_len, priv->essid,
4564 priv->bssid);
4565
4566 priv->status &=
4567 ~(STATUS_DISASSOCIATING |
4568 STATUS_ASSOCIATING |
4569 STATUS_ASSOCIATED | STATUS_AUTH);
4570 if (priv->assoc_network
4571 && (priv->assoc_network->
4572 capability &
4573 WLAN_CAPABILITY_IBSS))
4574 ipw_remove_current_network
4575 (priv);
4576
4577 schedule_work(&priv->link_down);
4578
4579 break;
4580 }
4581
4582 case CMAS_RX_ASSOC_RESP:
4583 break;
4584
4585 default:
4586 IPW_ERROR("assoc: unknown (%d)\n",
4587 assoc->state);
4588 break;
4589 }
4590
4591 break;
4592 }
4593
4594 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4595 struct notif_authenticate *auth = ¬if->u.auth;
4596 switch (auth->state) {
4597 case CMAS_AUTHENTICATED:
4598 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4599 "authenticated: '%*pE' %pM\n",
4600 priv->essid_len, priv->essid,
4601 priv->bssid);
4602 priv->status |= STATUS_AUTH;
4603 break;
4604
4605 case CMAS_INIT:
4606 if (priv->status & STATUS_AUTH) {
4607 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4608 IPW_DL_ASSOC,
4609 "authentication failed (0x%04X): %s\n",
4610 le16_to_cpu(auth->status),
4611 ipw_get_status_code(le16_to_cpu
4612 (auth->
4613 status)));
4614 }
4615 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4616 IPW_DL_ASSOC,
4617 "deauthenticated: '%*pE' %pM\n",
4618 priv->essid_len, priv->essid,
4619 priv->bssid);
4620
4621 priv->status &= ~(STATUS_ASSOCIATING |
4622 STATUS_AUTH |
4623 STATUS_ASSOCIATED);
4624
4625 schedule_work(&priv->link_down);
4626 break;
4627
4628 case CMAS_TX_AUTH_SEQ_1:
4629 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4630 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4631 break;
4632 case CMAS_RX_AUTH_SEQ_2:
4633 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4634 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4635 break;
4636 case CMAS_AUTH_SEQ_1_PASS:
4637 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4638 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4639 break;
4640 case CMAS_AUTH_SEQ_1_FAIL:
4641 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4642 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4643 break;
4644 case CMAS_TX_AUTH_SEQ_3:
4645 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4646 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4647 break;
4648 case CMAS_RX_AUTH_SEQ_4:
4649 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4650 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4651 break;
4652 case CMAS_AUTH_SEQ_2_PASS:
4653 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4654 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4655 break;
4656 case CMAS_AUTH_SEQ_2_FAIL:
4657 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4658 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4659 break;
4660 case CMAS_TX_ASSOC:
4661 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4662 IPW_DL_ASSOC, "TX_ASSOC\n");
4663 break;
4664 case CMAS_RX_ASSOC_RESP:
4665 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4666 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
4667
4668 break;
4669 case CMAS_ASSOCIATED:
4670 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4671 IPW_DL_ASSOC, "ASSOCIATED\n");
4672 break;
4673 default:
4674 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4675 auth->state);
4676 break;
4677 }
4678 break;
4679 }
4680
4681 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4682 struct notif_channel_result *x =
4683 ¬if->u.channel_result;
4684
4685 if (size == sizeof(*x)) {
4686 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4687 x->channel_num);
4688 } else {
4689 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4690 "(should be %zd)\n",
4691 size, sizeof(*x));
4692 }
4693 break;
4694 }
4695
4696 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4697 struct notif_scan_complete *x = ¬if->u.scan_complete;
4698 if (size == sizeof(*x)) {
4699 IPW_DEBUG_SCAN
4700 ("Scan completed: type %d, %d channels, "
4701 "%d status\n", x->scan_type,
4702 x->num_channels, x->status);
4703 } else {
4704 IPW_ERROR("Scan completed of wrong size %d "
4705 "(should be %zd)\n",
4706 size, sizeof(*x));
4707 }
4708
4709 priv->status &=
4710 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4711
4712 wake_up_interruptible(&priv->wait_state);
4713 cancel_delayed_work(&priv->scan_check);
4714
4715 if (priv->status & STATUS_EXIT_PENDING)
4716 break;
4717
4718 priv->ieee->scans++;
4719
4720 #ifdef CONFIG_IPW2200_MONITOR
4721 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
4722 priv->status |= STATUS_SCAN_FORCED;
4723 schedule_delayed_work(&priv->request_scan, 0);
4724 break;
4725 }
4726 priv->status &= ~STATUS_SCAN_FORCED;
4727 #endif /* CONFIG_IPW2200_MONITOR */
4728
4729 /* Do queued direct scans first */
4730 if (priv->status & STATUS_DIRECT_SCAN_PENDING)
4731 schedule_delayed_work(&priv->request_direct_scan, 0);
4732
4733 if (!(priv->status & (STATUS_ASSOCIATED |
4734 STATUS_ASSOCIATING |
4735 STATUS_ROAMING |
4736 STATUS_DISASSOCIATING)))
4737 schedule_work(&priv->associate);
4738 else if (priv->status & STATUS_ROAMING) {
4739 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4740 /* If a scan completed and we are in roam mode, then
4741 * the scan that completed was the one requested as a
4742 * result of entering roam... so, schedule the
4743 * roam work */
4744 schedule_work(&priv->roam);
4745 else
4746 /* Don't schedule if we aborted the scan */
4747 priv->status &= ~STATUS_ROAMING;
4748 } else if (priv->status & STATUS_SCAN_PENDING)
4749 schedule_delayed_work(&priv->request_scan, 0);
4750 else if (priv->config & CFG_BACKGROUND_SCAN
4751 && priv->status & STATUS_ASSOCIATED)
4752 schedule_delayed_work(&priv->request_scan,
4753 round_jiffies_relative(HZ));
4754
4755 /* Send an empty event to user space.
4756 * We don't send the received data on the event because
4757 * it would require us to do complex transcoding, and
4758 * we want to minimise the work done in the irq handler
4759 * Use a request to extract the data.
4760 * Also, we generate this even for any scan, regardless
4761 * on how the scan was initiated. User space can just
4762 * sync on periodic scan to get fresh data...
4763 * Jean II */
4764 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4765 handle_scan_event(priv);
4766 break;
4767 }
4768
4769 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4770 struct notif_frag_length *x = ¬if->u.frag_len;
4771
4772 if (size == sizeof(*x))
4773 IPW_ERROR("Frag length: %d\n",
4774 le16_to_cpu(x->frag_length));
4775 else
4776 IPW_ERROR("Frag length of wrong size %d "
4777 "(should be %zd)\n",
4778 size, sizeof(*x));
4779 break;
4780 }
4781
4782 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4783 struct notif_link_deterioration *x =
4784 ¬if->u.link_deterioration;
4785
4786 if (size == sizeof(*x)) {
4787 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4788 "link deterioration: type %d, cnt %d\n",
4789 x->silence_notification_type,
4790 x->silence_count);
4791 memcpy(&priv->last_link_deterioration, x,
4792 sizeof(*x));
4793 } else {
4794 IPW_ERROR("Link Deterioration of wrong size %d "
4795 "(should be %zd)\n",
4796 size, sizeof(*x));
4797 }
4798 break;
4799 }
4800
4801 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4802 IPW_ERROR("Dino config\n");
4803 if (priv->hcmd
4804 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
4805 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
4806
4807 break;
4808 }
4809
4810 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4811 struct notif_beacon_state *x = ¬if->u.beacon_state;
4812 if (size != sizeof(*x)) {
4813 IPW_ERROR
4814 ("Beacon state of wrong size %d (should "
4815 "be %zd)\n", size, sizeof(*x));
4816 break;
4817 }
4818
4819 if (le32_to_cpu(x->state) ==
4820 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4821 ipw_handle_missed_beacon(priv,
4822 le32_to_cpu(x->
4823 number));
4824
4825 break;
4826 }
4827
4828 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4829 struct notif_tgi_tx_key *x = ¬if->u.tgi_tx_key;
4830 if (size == sizeof(*x)) {
4831 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4832 "0x%02x station %d\n",
4833 x->key_state, x->security_type,
4834 x->station_index);
4835 break;
4836 }
4837
4838 IPW_ERROR
4839 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4840 size, sizeof(*x));
4841 break;
4842 }
4843
4844 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4845 struct notif_calibration *x = ¬if->u.calibration;
4846
4847 if (size == sizeof(*x)) {
4848 memcpy(&priv->calib, x, sizeof(*x));
4849 IPW_DEBUG_INFO("TODO: Calibration\n");
4850 break;
4851 }
4852
4853 IPW_ERROR
4854 ("Calibration of wrong size %d (should be %zd)\n",
4855 size, sizeof(*x));
4856 break;
4857 }
4858
4859 case HOST_NOTIFICATION_NOISE_STATS:{
4860 if (size == sizeof(u32)) {
4861 priv->exp_avg_noise =
4862 exponential_average(priv->exp_avg_noise,
4863 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4864 DEPTH_NOISE);
4865 break;
4866 }
4867
4868 IPW_ERROR
4869 ("Noise stat is wrong size %d (should be %zd)\n",
4870 size, sizeof(u32));
4871 break;
4872 }
4873
4874 default:
4875 IPW_DEBUG_NOTIF("Unknown notification: "
4876 "subtype=%d,flags=0x%2x,size=%d\n",
4877 notif->subtype, notif->flags, size);
4878 }
4879 }
4880
4881 /*
4882 * Destroys all DMA structures and initialise them again
4883 *
4884 * @param priv
4885 * @return error code
4886 */
ipw_queue_reset(struct ipw_priv * priv)4887 static int ipw_queue_reset(struct ipw_priv *priv)
4888 {
4889 int rc = 0;
4890 /* @todo customize queue sizes */
4891 int nTx = 64, nTxCmd = 8;
4892 ipw_tx_queue_free(priv);
4893 /* Tx CMD queue */
4894 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
4895 IPW_TX_CMD_QUEUE_READ_INDEX,
4896 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4897 IPW_TX_CMD_QUEUE_BD_BASE,
4898 IPW_TX_CMD_QUEUE_BD_SIZE);
4899 if (rc) {
4900 IPW_ERROR("Tx Cmd queue init failed\n");
4901 goto error;
4902 }
4903 /* Tx queue(s) */
4904 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
4905 IPW_TX_QUEUE_0_READ_INDEX,
4906 IPW_TX_QUEUE_0_WRITE_INDEX,
4907 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
4908 if (rc) {
4909 IPW_ERROR("Tx 0 queue init failed\n");
4910 goto error;
4911 }
4912 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
4913 IPW_TX_QUEUE_1_READ_INDEX,
4914 IPW_TX_QUEUE_1_WRITE_INDEX,
4915 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
4916 if (rc) {
4917 IPW_ERROR("Tx 1 queue init failed\n");
4918 goto error;
4919 }
4920 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
4921 IPW_TX_QUEUE_2_READ_INDEX,
4922 IPW_TX_QUEUE_2_WRITE_INDEX,
4923 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
4924 if (rc) {
4925 IPW_ERROR("Tx 2 queue init failed\n");
4926 goto error;
4927 }
4928 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
4929 IPW_TX_QUEUE_3_READ_INDEX,
4930 IPW_TX_QUEUE_3_WRITE_INDEX,
4931 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
4932 if (rc) {
4933 IPW_ERROR("Tx 3 queue init failed\n");
4934 goto error;
4935 }
4936 /* statistics */
4937 priv->rx_bufs_min = 0;
4938 priv->rx_pend_max = 0;
4939 return rc;
4940
4941 error:
4942 ipw_tx_queue_free(priv);
4943 return rc;
4944 }
4945
4946 /*
4947 * Reclaim Tx queue entries no more used by NIC.
4948 *
4949 * When FW advances 'R' index, all entries between old and
4950 * new 'R' index need to be reclaimed. As result, some free space
4951 * forms. If there is enough free space (> low mark), wake Tx queue.
4952 *
4953 * @note Need to protect against garbage in 'R' index
4954 * @param priv
4955 * @param txq
4956 * @param qindex
4957 * @return Number of used entries remains in the queue
4958 */
ipw_queue_tx_reclaim(struct ipw_priv * priv,struct clx2_tx_queue * txq,int qindex)4959 static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
4960 struct clx2_tx_queue *txq, int qindex)
4961 {
4962 u32 hw_tail;
4963 int used;
4964 struct clx2_queue *q = &txq->q;
4965
4966 hw_tail = ipw_read32(priv, q->reg_r);
4967 if (hw_tail >= q->n_bd) {
4968 IPW_ERROR
4969 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4970 hw_tail, q->n_bd);
4971 goto done;
4972 }
4973 for (; q->last_used != hw_tail;
4974 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4975 ipw_queue_tx_free_tfd(priv, txq);
4976 priv->tx_packets++;
4977 }
4978 done:
4979 if ((ipw_tx_queue_space(q) > q->low_mark) &&
4980 (qindex >= 0))
4981 netif_wake_queue(priv->net_dev);
4982 used = q->first_empty - q->last_used;
4983 if (used < 0)
4984 used += q->n_bd;
4985
4986 return used;
4987 }
4988
ipw_queue_tx_hcmd(struct ipw_priv * priv,int hcmd,const void * buf,int len,int sync)4989 static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, const void *buf,
4990 int len, int sync)
4991 {
4992 struct clx2_tx_queue *txq = &priv->txq_cmd;
4993 struct clx2_queue *q = &txq->q;
4994 struct tfd_frame *tfd;
4995
4996 if (ipw_tx_queue_space(q) < (sync ? 1 : 2)) {
4997 IPW_ERROR("No space for Tx\n");
4998 return -EBUSY;
4999 }
5000
5001 tfd = &txq->bd[q->first_empty];
5002 txq->txb[q->first_empty] = NULL;
5003
5004 memset(tfd, 0, sizeof(*tfd));
5005 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
5006 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
5007 priv->hcmd_seq++;
5008 tfd->u.cmd.index = hcmd;
5009 tfd->u.cmd.length = len;
5010 memcpy(tfd->u.cmd.payload, buf, len);
5011 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
5012 ipw_write32(priv, q->reg_w, q->first_empty);
5013 _ipw_read32(priv, 0x90);
5014
5015 return 0;
5016 }
5017
5018 /*
5019 * Rx theory of operation
5020 *
5021 * The host allocates 32 DMA target addresses and passes the host address
5022 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
5023 * 0 to 31
5024 *
5025 * Rx Queue Indexes
5026 * The host/firmware share two index registers for managing the Rx buffers.
5027 *
5028 * The READ index maps to the first position that the firmware may be writing
5029 * to -- the driver can read up to (but not including) this position and get
5030 * good data.
5031 * The READ index is managed by the firmware once the card is enabled.
5032 *
5033 * The WRITE index maps to the last position the driver has read from -- the
5034 * position preceding WRITE is the last slot the firmware can place a packet.
5035 *
5036 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
5037 * WRITE = READ.
5038 *
5039 * During initialization the host sets up the READ queue position to the first
5040 * INDEX position, and WRITE to the last (READ - 1 wrapped)
5041 *
5042 * When the firmware places a packet in a buffer it will advance the READ index
5043 * and fire the RX interrupt. The driver can then query the READ index and
5044 * process as many packets as possible, moving the WRITE index forward as it
5045 * resets the Rx queue buffers with new memory.
5046 *
5047 * The management in the driver is as follows:
5048 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
5049 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
5050 * to replensish the ipw->rxq->rx_free.
5051 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
5052 * ipw->rxq is replenished and the READ INDEX is updated (updating the
5053 * 'processed' and 'read' driver indexes as well)
5054 * + A received packet is processed and handed to the kernel network stack,
5055 * detached from the ipw->rxq. The driver 'processed' index is updated.
5056 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
5057 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
5058 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
5059 * were enough free buffers and RX_STALLED is set it is cleared.
5060 *
5061 *
5062 * Driver sequence:
5063 *
5064 * ipw_rx_queue_alloc() Allocates rx_free
5065 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
5066 * ipw_rx_queue_restock
5067 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
5068 * queue, updates firmware pointers, and updates
5069 * the WRITE index. If insufficient rx_free buffers
5070 * are available, schedules ipw_rx_queue_replenish
5071 *
5072 * -- enable interrupts --
5073 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
5074 * READ INDEX, detaching the SKB from the pool.
5075 * Moves the packet buffer from queue to rx_used.
5076 * Calls ipw_rx_queue_restock to refill any empty
5077 * slots.
5078 * ...
5079 *
5080 */
5081
5082 /*
5083 * If there are slots in the RX queue that need to be restocked,
5084 * and we have free pre-allocated buffers, fill the ranks as much
5085 * as we can pulling from rx_free.
5086 *
5087 * This moves the 'write' index forward to catch up with 'processed', and
5088 * also updates the memory address in the firmware to reference the new
5089 * target buffer.
5090 */
ipw_rx_queue_restock(struct ipw_priv * priv)5091 static void ipw_rx_queue_restock(struct ipw_priv *priv)
5092 {
5093 struct ipw_rx_queue *rxq = priv->rxq;
5094 struct list_head *element;
5095 struct ipw_rx_mem_buffer *rxb;
5096 unsigned long flags;
5097 int write;
5098
5099 spin_lock_irqsave(&rxq->lock, flags);
5100 write = rxq->write;
5101 while ((ipw_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
5102 element = rxq->rx_free.next;
5103 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5104 list_del(element);
5105
5106 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
5107 rxb->dma_addr);
5108 rxq->queue[rxq->write] = rxb;
5109 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5110 rxq->free_count--;
5111 }
5112 spin_unlock_irqrestore(&rxq->lock, flags);
5113
5114 /* If the pre-allocated buffer pool is dropping low, schedule to
5115 * refill it */
5116 if (rxq->free_count <= RX_LOW_WATERMARK)
5117 schedule_work(&priv->rx_replenish);
5118
5119 /* If we've added more space for the firmware to place data, tell it */
5120 if (write != rxq->write)
5121 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
5122 }
5123
5124 /*
5125 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
5126 * Also restock the Rx queue via ipw_rx_queue_restock.
5127 *
5128 * This is called as a scheduled work item (except for during initialization)
5129 */
ipw_rx_queue_replenish(void * data)5130 static void ipw_rx_queue_replenish(void *data)
5131 {
5132 struct ipw_priv *priv = data;
5133 struct ipw_rx_queue *rxq = priv->rxq;
5134 struct list_head *element;
5135 struct ipw_rx_mem_buffer *rxb;
5136 unsigned long flags;
5137
5138 spin_lock_irqsave(&rxq->lock, flags);
5139 while (!list_empty(&rxq->rx_used)) {
5140 element = rxq->rx_used.next;
5141 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5142 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
5143 if (!rxb->skb) {
5144 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5145 priv->net_dev->name);
5146 /* We don't reschedule replenish work here -- we will
5147 * call the restock method and if it still needs
5148 * more buffers it will schedule replenish */
5149 break;
5150 }
5151 list_del(element);
5152
5153 rxb->dma_addr =
5154 dma_map_single(&priv->pci_dev->dev, rxb->skb->data,
5155 IPW_RX_BUF_SIZE, DMA_FROM_DEVICE);
5156
5157 list_add_tail(&rxb->list, &rxq->rx_free);
5158 rxq->free_count++;
5159 }
5160 spin_unlock_irqrestore(&rxq->lock, flags);
5161
5162 ipw_rx_queue_restock(priv);
5163 }
5164
ipw_bg_rx_queue_replenish(struct work_struct * work)5165 static void ipw_bg_rx_queue_replenish(struct work_struct *work)
5166 {
5167 struct ipw_priv *priv =
5168 container_of(work, struct ipw_priv, rx_replenish);
5169 mutex_lock(&priv->mutex);
5170 ipw_rx_queue_replenish(priv);
5171 mutex_unlock(&priv->mutex);
5172 }
5173
5174 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
5175 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
5176 * This free routine walks the list of POOL entries and if SKB is set to
5177 * non NULL it is unmapped and freed
5178 */
ipw_rx_queue_free(struct ipw_priv * priv,struct ipw_rx_queue * rxq)5179 static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
5180 {
5181 int i;
5182
5183 if (!rxq)
5184 return;
5185
5186 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5187 if (rxq->pool[i].skb != NULL) {
5188 dma_unmap_single(&priv->pci_dev->dev,
5189 rxq->pool[i].dma_addr,
5190 IPW_RX_BUF_SIZE, DMA_FROM_DEVICE);
5191 dev_kfree_skb(rxq->pool[i].skb);
5192 }
5193 }
5194
5195 kfree(rxq);
5196 }
5197
ipw_rx_queue_alloc(struct ipw_priv * priv)5198 static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5199 {
5200 struct ipw_rx_queue *rxq;
5201 int i;
5202
5203 rxq = kzalloc_obj(*rxq);
5204 if (unlikely(!rxq)) {
5205 IPW_ERROR("memory allocation failed\n");
5206 return NULL;
5207 }
5208 spin_lock_init(&rxq->lock);
5209 INIT_LIST_HEAD(&rxq->rx_free);
5210 INIT_LIST_HEAD(&rxq->rx_used);
5211
5212 /* Fill the rx_used queue with _all_ of the Rx buffers */
5213 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
5214 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5215
5216 /* Set us so that we have processed and used all buffers, but have
5217 * not restocked the Rx queue with fresh buffers */
5218 rxq->read = rxq->write = 0;
5219 rxq->free_count = 0;
5220
5221 return rxq;
5222 }
5223
ipw_is_rate_in_mask(struct ipw_priv * priv,int ieee_mode,u8 rate)5224 static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5225 {
5226 rate &= ~LIBIPW_BASIC_RATE_MASK;
5227 if (ieee_mode == IEEE_A) {
5228 switch (rate) {
5229 case LIBIPW_OFDM_RATE_6MB:
5230 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ?
5231 1 : 0;
5232 case LIBIPW_OFDM_RATE_9MB:
5233 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ?
5234 1 : 0;
5235 case LIBIPW_OFDM_RATE_12MB:
5236 return priv->
5237 rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5238 case LIBIPW_OFDM_RATE_18MB:
5239 return priv->
5240 rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5241 case LIBIPW_OFDM_RATE_24MB:
5242 return priv->
5243 rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5244 case LIBIPW_OFDM_RATE_36MB:
5245 return priv->
5246 rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5247 case LIBIPW_OFDM_RATE_48MB:
5248 return priv->
5249 rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5250 case LIBIPW_OFDM_RATE_54MB:
5251 return priv->
5252 rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
5253 default:
5254 return 0;
5255 }
5256 }
5257
5258 /* B and G mixed */
5259 switch (rate) {
5260 case LIBIPW_CCK_RATE_1MB:
5261 return priv->rates_mask & LIBIPW_CCK_RATE_1MB_MASK ? 1 : 0;
5262 case LIBIPW_CCK_RATE_2MB:
5263 return priv->rates_mask & LIBIPW_CCK_RATE_2MB_MASK ? 1 : 0;
5264 case LIBIPW_CCK_RATE_5MB:
5265 return priv->rates_mask & LIBIPW_CCK_RATE_5MB_MASK ? 1 : 0;
5266 case LIBIPW_CCK_RATE_11MB:
5267 return priv->rates_mask & LIBIPW_CCK_RATE_11MB_MASK ? 1 : 0;
5268 }
5269
5270 /* If we are limited to B modulations, bail at this point */
5271 if (ieee_mode == IEEE_B)
5272 return 0;
5273
5274 /* G */
5275 switch (rate) {
5276 case LIBIPW_OFDM_RATE_6MB:
5277 return priv->rates_mask & LIBIPW_OFDM_RATE_6MB_MASK ? 1 : 0;
5278 case LIBIPW_OFDM_RATE_9MB:
5279 return priv->rates_mask & LIBIPW_OFDM_RATE_9MB_MASK ? 1 : 0;
5280 case LIBIPW_OFDM_RATE_12MB:
5281 return priv->rates_mask & LIBIPW_OFDM_RATE_12MB_MASK ? 1 : 0;
5282 case LIBIPW_OFDM_RATE_18MB:
5283 return priv->rates_mask & LIBIPW_OFDM_RATE_18MB_MASK ? 1 : 0;
5284 case LIBIPW_OFDM_RATE_24MB:
5285 return priv->rates_mask & LIBIPW_OFDM_RATE_24MB_MASK ? 1 : 0;
5286 case LIBIPW_OFDM_RATE_36MB:
5287 return priv->rates_mask & LIBIPW_OFDM_RATE_36MB_MASK ? 1 : 0;
5288 case LIBIPW_OFDM_RATE_48MB:
5289 return priv->rates_mask & LIBIPW_OFDM_RATE_48MB_MASK ? 1 : 0;
5290 case LIBIPW_OFDM_RATE_54MB:
5291 return priv->rates_mask & LIBIPW_OFDM_RATE_54MB_MASK ? 1 : 0;
5292 }
5293
5294 return 0;
5295 }
5296
ipw_compatible_rates(struct ipw_priv * priv,const struct libipw_network * network,struct ipw_supported_rates * rates)5297 static int ipw_compatible_rates(struct ipw_priv *priv,
5298 const struct libipw_network *network,
5299 struct ipw_supported_rates *rates)
5300 {
5301 int num_rates, i;
5302
5303 memset(rates, 0, sizeof(*rates));
5304 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
5305 rates->num_rates = 0;
5306 for (i = 0; i < num_rates; i++) {
5307 if (!ipw_is_rate_in_mask(priv, network->mode,
5308 network->rates[i])) {
5309
5310 if (network->rates[i] & LIBIPW_BASIC_RATE_MASK) {
5311 IPW_DEBUG_SCAN("Adding masked mandatory "
5312 "rate %02X\n",
5313 network->rates[i]);
5314 rates->supported_rates[rates->num_rates++] =
5315 network->rates[i];
5316 continue;
5317 }
5318
5319 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5320 network->rates[i], priv->rates_mask);
5321 continue;
5322 }
5323
5324 rates->supported_rates[rates->num_rates++] = network->rates[i];
5325 }
5326
5327 num_rates = min(network->rates_ex_len,
5328 (u8) (IPW_MAX_RATES - num_rates));
5329 for (i = 0; i < num_rates; i++) {
5330 if (!ipw_is_rate_in_mask(priv, network->mode,
5331 network->rates_ex[i])) {
5332 if (network->rates_ex[i] & LIBIPW_BASIC_RATE_MASK) {
5333 IPW_DEBUG_SCAN("Adding masked mandatory "
5334 "rate %02X\n",
5335 network->rates_ex[i]);
5336 rates->supported_rates[rates->num_rates++] =
5337 network->rates[i];
5338 continue;
5339 }
5340
5341 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5342 network->rates_ex[i], priv->rates_mask);
5343 continue;
5344 }
5345
5346 rates->supported_rates[rates->num_rates++] =
5347 network->rates_ex[i];
5348 }
5349
5350 return 1;
5351 }
5352
ipw_copy_rates(struct ipw_supported_rates * dest,const struct ipw_supported_rates * src)5353 static void ipw_copy_rates(struct ipw_supported_rates *dest,
5354 const struct ipw_supported_rates *src)
5355 {
5356 u8 i;
5357 for (i = 0; i < src->num_rates; i++)
5358 dest->supported_rates[i] = src->supported_rates[i];
5359 dest->num_rates = src->num_rates;
5360 }
5361
5362 /* TODO: Look at sniffed packets in the air to determine if the basic rate
5363 * mask should ever be used -- right now all callers to add the scan rates are
5364 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
ipw_add_cck_scan_rates(struct ipw_supported_rates * rates,u8 modulation,u32 rate_mask)5365 static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
5366 u8 modulation, u32 rate_mask)
5367 {
5368 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5369 LIBIPW_BASIC_RATE_MASK : 0;
5370
5371 if (rate_mask & LIBIPW_CCK_RATE_1MB_MASK)
5372 rates->supported_rates[rates->num_rates++] =
5373 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_1MB;
5374
5375 if (rate_mask & LIBIPW_CCK_RATE_2MB_MASK)
5376 rates->supported_rates[rates->num_rates++] =
5377 LIBIPW_BASIC_RATE_MASK | LIBIPW_CCK_RATE_2MB;
5378
5379 if (rate_mask & LIBIPW_CCK_RATE_5MB_MASK)
5380 rates->supported_rates[rates->num_rates++] = basic_mask |
5381 LIBIPW_CCK_RATE_5MB;
5382
5383 if (rate_mask & LIBIPW_CCK_RATE_11MB_MASK)
5384 rates->supported_rates[rates->num_rates++] = basic_mask |
5385 LIBIPW_CCK_RATE_11MB;
5386 }
5387
ipw_add_ofdm_scan_rates(struct ipw_supported_rates * rates,u8 modulation,u32 rate_mask)5388 static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
5389 u8 modulation, u32 rate_mask)
5390 {
5391 u8 basic_mask = (LIBIPW_OFDM_MODULATION == modulation) ?
5392 LIBIPW_BASIC_RATE_MASK : 0;
5393
5394 if (rate_mask & LIBIPW_OFDM_RATE_6MB_MASK)
5395 rates->supported_rates[rates->num_rates++] = basic_mask |
5396 LIBIPW_OFDM_RATE_6MB;
5397
5398 if (rate_mask & LIBIPW_OFDM_RATE_9MB_MASK)
5399 rates->supported_rates[rates->num_rates++] =
5400 LIBIPW_OFDM_RATE_9MB;
5401
5402 if (rate_mask & LIBIPW_OFDM_RATE_12MB_MASK)
5403 rates->supported_rates[rates->num_rates++] = basic_mask |
5404 LIBIPW_OFDM_RATE_12MB;
5405
5406 if (rate_mask & LIBIPW_OFDM_RATE_18MB_MASK)
5407 rates->supported_rates[rates->num_rates++] =
5408 LIBIPW_OFDM_RATE_18MB;
5409
5410 if (rate_mask & LIBIPW_OFDM_RATE_24MB_MASK)
5411 rates->supported_rates[rates->num_rates++] = basic_mask |
5412 LIBIPW_OFDM_RATE_24MB;
5413
5414 if (rate_mask & LIBIPW_OFDM_RATE_36MB_MASK)
5415 rates->supported_rates[rates->num_rates++] =
5416 LIBIPW_OFDM_RATE_36MB;
5417
5418 if (rate_mask & LIBIPW_OFDM_RATE_48MB_MASK)
5419 rates->supported_rates[rates->num_rates++] =
5420 LIBIPW_OFDM_RATE_48MB;
5421
5422 if (rate_mask & LIBIPW_OFDM_RATE_54MB_MASK)
5423 rates->supported_rates[rates->num_rates++] =
5424 LIBIPW_OFDM_RATE_54MB;
5425 }
5426
5427 struct ipw_network_match {
5428 struct libipw_network *network;
5429 struct ipw_supported_rates rates;
5430 };
5431
ipw_find_adhoc_network(struct ipw_priv * priv,struct ipw_network_match * match,struct libipw_network * network,int roaming)5432 static int ipw_find_adhoc_network(struct ipw_priv *priv,
5433 struct ipw_network_match *match,
5434 struct libipw_network *network,
5435 int roaming)
5436 {
5437 struct ipw_supported_rates rates;
5438
5439 /* Verify that this network's capability is compatible with the
5440 * current mode (AdHoc or Infrastructure) */
5441 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5442 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5443 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded due to capability mismatch.\n",
5444 network->ssid_len, network->ssid,
5445 network->bssid);
5446 return 0;
5447 }
5448
5449 if (unlikely(roaming)) {
5450 /* If we are roaming, then ensure check if this is a valid
5451 * network to try and roam to */
5452 if ((network->ssid_len != match->network->ssid_len) ||
5453 memcmp(network->ssid, match->network->ssid,
5454 network->ssid_len)) {
5455 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because of non-network ESSID.\n",
5456 network->ssid_len, network->ssid,
5457 network->bssid);
5458 return 0;
5459 }
5460 } else {
5461 /* If an ESSID has been configured then compare the broadcast
5462 * ESSID to ours */
5463 if ((priv->config & CFG_STATIC_ESSID) &&
5464 ((network->ssid_len != priv->essid_len) ||
5465 memcmp(network->ssid, priv->essid,
5466 min(network->ssid_len, priv->essid_len)))) {
5467 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because of ESSID mismatch: '%*pE'.\n",
5468 network->ssid_len, network->ssid,
5469 network->bssid, priv->essid_len,
5470 priv->essid);
5471 return 0;
5472 }
5473 }
5474
5475 /* If the old network rate is better than this one, don't bother
5476 * testing everything else. */
5477
5478 if (network->time_stamp[0] < match->network->time_stamp[0]) {
5479 IPW_DEBUG_MERGE("Network '%*pE excluded because newer than current network.\n",
5480 match->network->ssid_len, match->network->ssid);
5481 return 0;
5482 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
5483 IPW_DEBUG_MERGE("Network '%*pE excluded because newer than current network.\n",
5484 match->network->ssid_len, match->network->ssid);
5485 return 0;
5486 }
5487
5488 /* Now go through and see if the requested network is valid... */
5489 if (priv->ieee->scan_age != 0 &&
5490 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5491 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because of age: %ums.\n",
5492 network->ssid_len, network->ssid,
5493 network->bssid,
5494 jiffies_to_msecs(jiffies -
5495 network->last_scanned));
5496 return 0;
5497 }
5498
5499 if ((priv->config & CFG_STATIC_CHANNEL) &&
5500 (network->channel != priv->channel)) {
5501 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because of channel mismatch: %d != %d.\n",
5502 network->ssid_len, network->ssid,
5503 network->bssid,
5504 network->channel, priv->channel);
5505 return 0;
5506 }
5507
5508 /* Verify privacy compatibility */
5509 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5510 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5511 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because of privacy mismatch: %s != %s.\n",
5512 network->ssid_len, network->ssid,
5513 network->bssid,
5514 priv->
5515 capability & CAP_PRIVACY_ON ? "on" : "off",
5516 network->
5517 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5518 "off");
5519 return 0;
5520 }
5521
5522 if (ether_addr_equal(network->bssid, priv->bssid)) {
5523 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because of the same BSSID match: %pM.\n",
5524 network->ssid_len, network->ssid,
5525 network->bssid, priv->bssid);
5526 return 0;
5527 }
5528
5529 /* Filter out any incompatible freq / mode combinations */
5530 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
5531 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because of invalid frequency/mode combination.\n",
5532 network->ssid_len, network->ssid,
5533 network->bssid);
5534 return 0;
5535 }
5536
5537 /* Ensure that the rates supported by the driver are compatible with
5538 * this AP, including verification of basic rates (mandatory) */
5539 if (!ipw_compatible_rates(priv, network, &rates)) {
5540 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because configured rate mask excludes AP mandatory rate.\n",
5541 network->ssid_len, network->ssid,
5542 network->bssid);
5543 return 0;
5544 }
5545
5546 if (rates.num_rates == 0) {
5547 IPW_DEBUG_MERGE("Network '%*pE (%pM)' excluded because of no compatible rates.\n",
5548 network->ssid_len, network->ssid,
5549 network->bssid);
5550 return 0;
5551 }
5552
5553 /* TODO: Perform any further minimal comparititive tests. We do not
5554 * want to put too much policy logic here; intelligent scan selection
5555 * should occur within a generic IEEE 802.11 user space tool. */
5556
5557 /* Set up 'new' AP to this network */
5558 ipw_copy_rates(&match->rates, &rates);
5559 match->network = network;
5560 IPW_DEBUG_MERGE("Network '%*pE (%pM)' is a viable match.\n",
5561 network->ssid_len, network->ssid, network->bssid);
5562
5563 return 1;
5564 }
5565
ipw_merge_adhoc_network(struct work_struct * work)5566 static void ipw_merge_adhoc_network(struct work_struct *work)
5567 {
5568 struct ipw_priv *priv =
5569 container_of(work, struct ipw_priv, merge_networks);
5570 struct libipw_network *network = NULL;
5571 struct ipw_network_match match = {
5572 .network = priv->assoc_network
5573 };
5574
5575 if ((priv->status & STATUS_ASSOCIATED) &&
5576 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5577 /* First pass through ROAM process -- look for a better
5578 * network */
5579 unsigned long flags;
5580
5581 spin_lock_irqsave(&priv->ieee->lock, flags);
5582 list_for_each_entry(network, &priv->ieee->network_list, list) {
5583 if (network != priv->assoc_network)
5584 ipw_find_adhoc_network(priv, &match, network,
5585 1);
5586 }
5587 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5588
5589 if (match.network == priv->assoc_network) {
5590 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5591 "merge to.\n");
5592 return;
5593 }
5594
5595 mutex_lock(&priv->mutex);
5596 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5597 IPW_DEBUG_MERGE("remove network %*pE\n",
5598 priv->essid_len, priv->essid);
5599 ipw_remove_current_network(priv);
5600 }
5601
5602 ipw_disassociate(priv);
5603 priv->assoc_network = match.network;
5604 mutex_unlock(&priv->mutex);
5605 return;
5606 }
5607 }
5608
ipw_best_network(struct ipw_priv * priv,struct ipw_network_match * match,struct libipw_network * network,int roaming)5609 static int ipw_best_network(struct ipw_priv *priv,
5610 struct ipw_network_match *match,
5611 struct libipw_network *network, int roaming)
5612 {
5613 struct ipw_supported_rates rates;
5614
5615 /* Verify that this network's capability is compatible with the
5616 * current mode (AdHoc or Infrastructure) */
5617 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
5618 !(network->capability & WLAN_CAPABILITY_ESS)) ||
5619 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5620 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5621 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded due to capability mismatch.\n",
5622 network->ssid_len, network->ssid,
5623 network->bssid);
5624 return 0;
5625 }
5626
5627 if (unlikely(roaming)) {
5628 /* If we are roaming, then ensure check if this is a valid
5629 * network to try and roam to */
5630 if ((network->ssid_len != match->network->ssid_len) ||
5631 memcmp(network->ssid, match->network->ssid,
5632 network->ssid_len)) {
5633 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of non-network ESSID.\n",
5634 network->ssid_len, network->ssid,
5635 network->bssid);
5636 return 0;
5637 }
5638 } else {
5639 /* If an ESSID has been configured then compare the broadcast
5640 * ESSID to ours */
5641 if ((priv->config & CFG_STATIC_ESSID) &&
5642 ((network->ssid_len != priv->essid_len) ||
5643 memcmp(network->ssid, priv->essid,
5644 min(network->ssid_len, priv->essid_len)))) {
5645 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of ESSID mismatch: '%*pE'.\n",
5646 network->ssid_len, network->ssid,
5647 network->bssid, priv->essid_len,
5648 priv->essid);
5649 return 0;
5650 }
5651 }
5652
5653 /* If the old network rate is better than this one, don't bother
5654 * testing everything else. */
5655 if (match->network && match->network->stats.rssi > network->stats.rssi) {
5656 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because '%*pE (%pM)' has a stronger signal.\n",
5657 network->ssid_len, network->ssid,
5658 network->bssid, match->network->ssid_len,
5659 match->network->ssid, match->network->bssid);
5660 return 0;
5661 }
5662
5663 /* If this network has already had an association attempt within the
5664 * last 3 seconds, do not try and associate again... */
5665 if (network->last_associate &&
5666 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
5667 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of storming (%ums since last assoc attempt).\n",
5668 network->ssid_len, network->ssid,
5669 network->bssid,
5670 jiffies_to_msecs(jiffies -
5671 network->last_associate));
5672 return 0;
5673 }
5674
5675 /* Now go through and see if the requested network is valid... */
5676 if (priv->ieee->scan_age != 0 &&
5677 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5678 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of age: %ums.\n",
5679 network->ssid_len, network->ssid,
5680 network->bssid,
5681 jiffies_to_msecs(jiffies -
5682 network->last_scanned));
5683 return 0;
5684 }
5685
5686 if ((priv->config & CFG_STATIC_CHANNEL) &&
5687 (network->channel != priv->channel)) {
5688 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of channel mismatch: %d != %d.\n",
5689 network->ssid_len, network->ssid,
5690 network->bssid,
5691 network->channel, priv->channel);
5692 return 0;
5693 }
5694
5695 /* Verify privacy compatibility */
5696 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5697 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5698 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of privacy mismatch: %s != %s.\n",
5699 network->ssid_len, network->ssid,
5700 network->bssid,
5701 priv->capability & CAP_PRIVACY_ON ? "on" :
5702 "off",
5703 network->capability &
5704 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
5705 return 0;
5706 }
5707
5708 if ((priv->config & CFG_STATIC_BSSID) &&
5709 !ether_addr_equal(network->bssid, priv->bssid)) {
5710 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of BSSID mismatch: %pM.\n",
5711 network->ssid_len, network->ssid,
5712 network->bssid, priv->bssid);
5713 return 0;
5714 }
5715
5716 /* Filter out any incompatible freq / mode combinations */
5717 if (!libipw_is_valid_mode(priv->ieee, network->mode)) {
5718 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of invalid frequency/mode combination.\n",
5719 network->ssid_len, network->ssid,
5720 network->bssid);
5721 return 0;
5722 }
5723
5724 /* Filter out invalid channel in current GEO */
5725 if (!libipw_is_valid_channel(priv->ieee, network->channel)) {
5726 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of invalid channel in current GEO\n",
5727 network->ssid_len, network->ssid,
5728 network->bssid);
5729 return 0;
5730 }
5731
5732 /* Ensure that the rates supported by the driver are compatible with
5733 * this AP, including verification of basic rates (mandatory) */
5734 if (!ipw_compatible_rates(priv, network, &rates)) {
5735 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because configured rate mask excludes AP mandatory rate.\n",
5736 network->ssid_len, network->ssid,
5737 network->bssid);
5738 return 0;
5739 }
5740
5741 if (rates.num_rates == 0) {
5742 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' excluded because of no compatible rates.\n",
5743 network->ssid_len, network->ssid,
5744 network->bssid);
5745 return 0;
5746 }
5747
5748 /* TODO: Perform any further minimal comparititive tests. We do not
5749 * want to put too much policy logic here; intelligent scan selection
5750 * should occur within a generic IEEE 802.11 user space tool. */
5751
5752 /* Set up 'new' AP to this network */
5753 ipw_copy_rates(&match->rates, &rates);
5754 match->network = network;
5755
5756 IPW_DEBUG_ASSOC("Network '%*pE (%pM)' is a viable match.\n",
5757 network->ssid_len, network->ssid, network->bssid);
5758
5759 return 1;
5760 }
5761
ipw_adhoc_create(struct ipw_priv * priv,struct libipw_network * network)5762 static void ipw_adhoc_create(struct ipw_priv *priv,
5763 struct libipw_network *network)
5764 {
5765 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
5766 int i;
5767
5768 /*
5769 * For the purposes of scanning, we can set our wireless mode
5770 * to trigger scans across combinations of bands, but when it
5771 * comes to creating a new ad-hoc network, we have tell the FW
5772 * exactly which band to use.
5773 *
5774 * We also have the possibility of an invalid channel for the
5775 * chossen band. Attempting to create a new ad-hoc network
5776 * with an invalid channel for wireless mode will trigger a
5777 * FW fatal error.
5778 *
5779 */
5780 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
5781 case LIBIPW_52GHZ_BAND:
5782 network->mode = IEEE_A;
5783 i = libipw_channel_to_index(priv->ieee, priv->channel);
5784 BUG_ON(i == -1);
5785 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
5786 IPW_WARNING("Overriding invalid channel\n");
5787 priv->channel = geo->a[0].channel;
5788 }
5789 break;
5790
5791 case LIBIPW_24GHZ_BAND:
5792 if (priv->ieee->mode & IEEE_G)
5793 network->mode = IEEE_G;
5794 else
5795 network->mode = IEEE_B;
5796 i = libipw_channel_to_index(priv->ieee, priv->channel);
5797 BUG_ON(i == -1);
5798 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY) {
5799 IPW_WARNING("Overriding invalid channel\n");
5800 priv->channel = geo->bg[0].channel;
5801 }
5802 break;
5803
5804 default:
5805 IPW_WARNING("Overriding invalid channel\n");
5806 if (priv->ieee->mode & IEEE_A) {
5807 network->mode = IEEE_A;
5808 priv->channel = geo->a[0].channel;
5809 } else if (priv->ieee->mode & IEEE_G) {
5810 network->mode = IEEE_G;
5811 priv->channel = geo->bg[0].channel;
5812 } else {
5813 network->mode = IEEE_B;
5814 priv->channel = geo->bg[0].channel;
5815 }
5816 break;
5817 }
5818
5819 network->channel = priv->channel;
5820 priv->config |= CFG_ADHOC_PERSIST;
5821 ipw_create_bssid(priv, network->bssid);
5822 network->ssid_len = priv->essid_len;
5823 memcpy(network->ssid, priv->essid, priv->essid_len);
5824 memset(&network->stats, 0, sizeof(network->stats));
5825 network->capability = WLAN_CAPABILITY_IBSS;
5826 if (!(priv->config & CFG_PREAMBLE_LONG))
5827 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
5828 if (priv->capability & CAP_PRIVACY_ON)
5829 network->capability |= WLAN_CAPABILITY_PRIVACY;
5830 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
5831 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
5832 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
5833 memcpy(network->rates_ex,
5834 &priv->rates.supported_rates[network->rates_len],
5835 network->rates_ex_len);
5836 network->last_scanned = 0;
5837 network->flags = 0;
5838 network->last_associate = 0;
5839 network->time_stamp[0] = 0;
5840 network->time_stamp[1] = 0;
5841 network->beacon_interval = 100; /* Default */
5842 network->listen_interval = 10; /* Default */
5843 network->atim_window = 0; /* Default */
5844 network->wpa_ie_len = 0;
5845 network->rsn_ie_len = 0;
5846 }
5847
ipw_send_tgi_tx_key(struct ipw_priv * priv,int type,int index)5848 static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5849 {
5850 struct ipw_tgi_tx_key key;
5851
5852 if (!(priv->ieee->sec.flags & (1 << index)))
5853 return;
5854
5855 key.key_id = index;
5856 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5857 key.security_type = type;
5858 key.station_index = 0; /* always 0 for BSS */
5859 key.flags = 0;
5860 /* 0 for new key; previous value of counter (after fatal error) */
5861 key.tx_counter[0] = cpu_to_le32(0);
5862 key.tx_counter[1] = cpu_to_le32(0);
5863
5864 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
5865 }
5866
ipw_send_wep_keys(struct ipw_priv * priv,int type)5867 static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
5868 {
5869 struct ipw_wep_key key;
5870 int i;
5871
5872 key.cmd_id = DINO_CMD_WEP_KEY;
5873 key.seq_num = 0;
5874
5875 /* Note: AES keys cannot be set for multiple times.
5876 * Only set it at the first time. */
5877 for (i = 0; i < 4; i++) {
5878 key.key_index = i | type;
5879 if (!(priv->ieee->sec.flags & (1 << i))) {
5880 key.key_size = 0;
5881 continue;
5882 }
5883
5884 key.key_size = priv->ieee->sec.key_sizes[i];
5885 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
5886
5887 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
5888 }
5889 }
5890
ipw_set_hw_decrypt_unicast(struct ipw_priv * priv,int level)5891 static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5892 {
5893 if (priv->ieee->host_encrypt)
5894 return;
5895
5896 switch (level) {
5897 case SEC_LEVEL_3:
5898 priv->sys_config.disable_unicast_decryption = 0;
5899 priv->ieee->host_decrypt = 0;
5900 break;
5901 case SEC_LEVEL_2:
5902 priv->sys_config.disable_unicast_decryption = 1;
5903 priv->ieee->host_decrypt = 1;
5904 break;
5905 case SEC_LEVEL_1:
5906 priv->sys_config.disable_unicast_decryption = 0;
5907 priv->ieee->host_decrypt = 0;
5908 break;
5909 case SEC_LEVEL_0:
5910 priv->sys_config.disable_unicast_decryption = 1;
5911 break;
5912 default:
5913 break;
5914 }
5915 }
5916
ipw_set_hw_decrypt_multicast(struct ipw_priv * priv,int level)5917 static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5918 {
5919 if (priv->ieee->host_encrypt)
5920 return;
5921
5922 switch (level) {
5923 case SEC_LEVEL_3:
5924 priv->sys_config.disable_multicast_decryption = 0;
5925 break;
5926 case SEC_LEVEL_2:
5927 priv->sys_config.disable_multicast_decryption = 1;
5928 break;
5929 case SEC_LEVEL_1:
5930 priv->sys_config.disable_multicast_decryption = 0;
5931 break;
5932 case SEC_LEVEL_0:
5933 priv->sys_config.disable_multicast_decryption = 1;
5934 break;
5935 default:
5936 break;
5937 }
5938 }
5939
ipw_set_hwcrypto_keys(struct ipw_priv * priv)5940 static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5941 {
5942 switch (priv->ieee->sec.level) {
5943 case SEC_LEVEL_3:
5944 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5945 ipw_send_tgi_tx_key(priv,
5946 DCT_FLAG_EXT_SECURITY_CCM,
5947 priv->ieee->sec.active_key);
5948
5949 if (!priv->ieee->host_mc_decrypt)
5950 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
5951 break;
5952 case SEC_LEVEL_2:
5953 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5954 ipw_send_tgi_tx_key(priv,
5955 DCT_FLAG_EXT_SECURITY_TKIP,
5956 priv->ieee->sec.active_key);
5957 break;
5958 case SEC_LEVEL_1:
5959 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
5960 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5961 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
5962 break;
5963 case SEC_LEVEL_0:
5964 default:
5965 break;
5966 }
5967 }
5968
ipw_adhoc_check(void * data)5969 static void ipw_adhoc_check(void *data)
5970 {
5971 struct ipw_priv *priv = data;
5972
5973 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
5974 !(priv->config & CFG_ADHOC_PERSIST)) {
5975 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5976 IPW_DL_STATE | IPW_DL_ASSOC,
5977 "Missed beacon: %d - disassociate\n",
5978 priv->missed_adhoc_beacons);
5979 ipw_remove_current_network(priv);
5980 ipw_disassociate(priv);
5981 return;
5982 }
5983
5984 schedule_delayed_work(&priv->adhoc_check,
5985 le16_to_cpu(priv->assoc_request.beacon_interval));
5986 }
5987
ipw_bg_adhoc_check(struct work_struct * work)5988 static void ipw_bg_adhoc_check(struct work_struct *work)
5989 {
5990 struct ipw_priv *priv =
5991 container_of(work, struct ipw_priv, adhoc_check.work);
5992 mutex_lock(&priv->mutex);
5993 ipw_adhoc_check(priv);
5994 mutex_unlock(&priv->mutex);
5995 }
5996
ipw_debug_config(struct ipw_priv * priv)5997 static void ipw_debug_config(struct ipw_priv *priv)
5998 {
5999 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
6000 "[CFG 0x%08X]\n", priv->config);
6001 if (priv->config & CFG_STATIC_CHANNEL)
6002 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
6003 else
6004 IPW_DEBUG_INFO("Channel unlocked.\n");
6005 if (priv->config & CFG_STATIC_ESSID)
6006 IPW_DEBUG_INFO("ESSID locked to '%*pE'\n",
6007 priv->essid_len, priv->essid);
6008 else
6009 IPW_DEBUG_INFO("ESSID unlocked.\n");
6010 if (priv->config & CFG_STATIC_BSSID)
6011 IPW_DEBUG_INFO("BSSID locked to %pM\n", priv->bssid);
6012 else
6013 IPW_DEBUG_INFO("BSSID unlocked.\n");
6014 if (priv->capability & CAP_PRIVACY_ON)
6015 IPW_DEBUG_INFO("PRIVACY on\n");
6016 else
6017 IPW_DEBUG_INFO("PRIVACY off\n");
6018 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
6019 }
6020
ipw_set_fixed_rate(struct ipw_priv * priv,int mode)6021 static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
6022 {
6023 /* TODO: Verify that this works... */
6024 struct ipw_fixed_rate fr;
6025 u32 reg;
6026 u16 mask = 0;
6027 u16 new_tx_rates = priv->rates_mask;
6028
6029 /* Identify 'current FW band' and match it with the fixed
6030 * Tx rates */
6031
6032 switch (priv->ieee->freq_band) {
6033 case LIBIPW_52GHZ_BAND: /* A only */
6034 /* IEEE_A */
6035 if (priv->rates_mask & ~LIBIPW_OFDM_RATES_MASK) {
6036 /* Invalid fixed rate mask */
6037 IPW_DEBUG_WX
6038 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
6039 new_tx_rates = 0;
6040 break;
6041 }
6042
6043 new_tx_rates >>= LIBIPW_OFDM_SHIFT_MASK_A;
6044 break;
6045
6046 default: /* 2.4Ghz or Mixed */
6047 /* IEEE_B */
6048 if (mode == IEEE_B) {
6049 if (new_tx_rates & ~LIBIPW_CCK_RATES_MASK) {
6050 /* Invalid fixed rate mask */
6051 IPW_DEBUG_WX
6052 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
6053 new_tx_rates = 0;
6054 }
6055 break;
6056 }
6057
6058 /* IEEE_G */
6059 if (new_tx_rates & ~(LIBIPW_CCK_RATES_MASK |
6060 LIBIPW_OFDM_RATES_MASK)) {
6061 /* Invalid fixed rate mask */
6062 IPW_DEBUG_WX
6063 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
6064 new_tx_rates = 0;
6065 break;
6066 }
6067
6068 if (LIBIPW_OFDM_RATE_6MB_MASK & new_tx_rates) {
6069 mask |= (LIBIPW_OFDM_RATE_6MB_MASK >> 1);
6070 new_tx_rates &= ~LIBIPW_OFDM_RATE_6MB_MASK;
6071 }
6072
6073 if (LIBIPW_OFDM_RATE_9MB_MASK & new_tx_rates) {
6074 mask |= (LIBIPW_OFDM_RATE_9MB_MASK >> 1);
6075 new_tx_rates &= ~LIBIPW_OFDM_RATE_9MB_MASK;
6076 }
6077
6078 if (LIBIPW_OFDM_RATE_12MB_MASK & new_tx_rates) {
6079 mask |= (LIBIPW_OFDM_RATE_12MB_MASK >> 1);
6080 new_tx_rates &= ~LIBIPW_OFDM_RATE_12MB_MASK;
6081 }
6082
6083 new_tx_rates |= mask;
6084 break;
6085 }
6086
6087 fr.tx_rates = cpu_to_le16(new_tx_rates);
6088
6089 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
6090 ipw_write_reg32(priv, reg, *(u32 *) & fr);
6091 }
6092
ipw_abort_scan(struct ipw_priv * priv)6093 static void ipw_abort_scan(struct ipw_priv *priv)
6094 {
6095 int err;
6096
6097 if (priv->status & STATUS_SCAN_ABORTING) {
6098 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6099 return;
6100 }
6101 priv->status |= STATUS_SCAN_ABORTING;
6102
6103 err = ipw_send_scan_abort(priv);
6104 if (err)
6105 IPW_DEBUG_HC("Request to abort scan failed.\n");
6106 }
6107
ipw_add_scan_channels(struct ipw_priv * priv,struct ipw_scan_request_ext * scan,int scan_type)6108 static void ipw_add_scan_channels(struct ipw_priv *priv,
6109 struct ipw_scan_request_ext *scan,
6110 int scan_type)
6111 {
6112 int channel_index = 0;
6113 const struct libipw_geo *geo;
6114 int i;
6115
6116 geo = libipw_get_geo(priv->ieee);
6117
6118 if (priv->ieee->freq_band & LIBIPW_52GHZ_BAND) {
6119 int start = channel_index;
6120 for (i = 0; i < geo->a_channels; i++) {
6121 if ((priv->status & STATUS_ASSOCIATED) &&
6122 geo->a[i].channel == priv->channel)
6123 continue;
6124 channel_index++;
6125 scan->channels_list[channel_index] = geo->a[i].channel;
6126 ipw_set_scan_type(scan, channel_index,
6127 geo->a[i].
6128 flags & LIBIPW_CH_PASSIVE_ONLY ?
6129 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6130 scan_type);
6131 }
6132
6133 if (start != channel_index) {
6134 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6135 (channel_index - start);
6136 channel_index++;
6137 }
6138 }
6139
6140 if (priv->ieee->freq_band & LIBIPW_24GHZ_BAND) {
6141 int start = channel_index;
6142 if (priv->config & CFG_SPEED_SCAN) {
6143 int index;
6144 u8 channels[LIBIPW_24GHZ_CHANNELS] = {
6145 /* nop out the list */
6146 [0] = 0
6147 };
6148
6149 u8 channel;
6150 while (channel_index < IPW_SCAN_CHANNELS - 1) {
6151 channel =
6152 priv->speed_scan[priv->speed_scan_pos];
6153 if (channel == 0) {
6154 priv->speed_scan_pos = 0;
6155 channel = priv->speed_scan[0];
6156 }
6157 if ((priv->status & STATUS_ASSOCIATED) &&
6158 channel == priv->channel) {
6159 priv->speed_scan_pos++;
6160 continue;
6161 }
6162
6163 /* If this channel has already been
6164 * added in scan, break from loop
6165 * and this will be the first channel
6166 * in the next scan.
6167 */
6168 if (channels[channel - 1] != 0)
6169 break;
6170
6171 channels[channel - 1] = 1;
6172 priv->speed_scan_pos++;
6173 channel_index++;
6174 scan->channels_list[channel_index] = channel;
6175 index =
6176 libipw_channel_to_index(priv->ieee, channel);
6177 ipw_set_scan_type(scan, channel_index,
6178 geo->bg[index].
6179 flags &
6180 LIBIPW_CH_PASSIVE_ONLY ?
6181 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6182 : scan_type);
6183 }
6184 } else {
6185 for (i = 0; i < geo->bg_channels; i++) {
6186 if ((priv->status & STATUS_ASSOCIATED) &&
6187 geo->bg[i].channel == priv->channel)
6188 continue;
6189 channel_index++;
6190 scan->channels_list[channel_index] =
6191 geo->bg[i].channel;
6192 ipw_set_scan_type(scan, channel_index,
6193 geo->bg[i].
6194 flags &
6195 LIBIPW_CH_PASSIVE_ONLY ?
6196 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6197 : scan_type);
6198 }
6199 }
6200
6201 if (start != channel_index) {
6202 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6203 (channel_index - start);
6204 }
6205 }
6206 }
6207
ipw_passive_dwell_time(struct ipw_priv * priv)6208 static int ipw_passive_dwell_time(struct ipw_priv *priv)
6209 {
6210 /* staying on passive channels longer than the DTIM interval during a
6211 * scan, while associated, causes the firmware to cancel the scan
6212 * without notification. Hence, don't stay on passive channels longer
6213 * than the beacon interval.
6214 */
6215 if (priv->status & STATUS_ASSOCIATED
6216 && priv->assoc_network->beacon_interval > 10)
6217 return priv->assoc_network->beacon_interval - 10;
6218 else
6219 return 120;
6220 }
6221
ipw_request_scan_helper(struct ipw_priv * priv,int type,int direct)6222 static int ipw_request_scan_helper(struct ipw_priv *priv, int type, int direct)
6223 {
6224 struct ipw_scan_request_ext scan;
6225 int err = 0, scan_type;
6226
6227 if (!(priv->status & STATUS_INIT) ||
6228 (priv->status & STATUS_EXIT_PENDING))
6229 return 0;
6230
6231 mutex_lock(&priv->mutex);
6232
6233 if (direct && (priv->direct_scan_ssid_len == 0)) {
6234 IPW_DEBUG_HC("Direct scan requested but no SSID to scan for\n");
6235 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6236 goto done;
6237 }
6238
6239 if (priv->status & STATUS_SCANNING) {
6240 IPW_DEBUG_HC("Concurrent scan requested. Queuing.\n");
6241 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6242 STATUS_SCAN_PENDING;
6243 goto done;
6244 }
6245
6246 if (!(priv->status & STATUS_SCAN_FORCED) &&
6247 priv->status & STATUS_SCAN_ABORTING) {
6248 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6249 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6250 STATUS_SCAN_PENDING;
6251 goto done;
6252 }
6253
6254 if (priv->status & STATUS_RF_KILL_MASK) {
6255 IPW_DEBUG_HC("Queuing scan due to RF Kill activation\n");
6256 priv->status |= direct ? STATUS_DIRECT_SCAN_PENDING :
6257 STATUS_SCAN_PENDING;
6258 goto done;
6259 }
6260
6261 memset(&scan, 0, sizeof(scan));
6262 scan.full_scan_index = cpu_to_le32(libipw_get_scans(priv->ieee));
6263
6264 if (type == IW_SCAN_TYPE_PASSIVE) {
6265 IPW_DEBUG_WX("use passive scanning\n");
6266 scan_type = IPW_SCAN_PASSIVE_FULL_DWELL_SCAN;
6267 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6268 cpu_to_le16(ipw_passive_dwell_time(priv));
6269 ipw_add_scan_channels(priv, &scan, scan_type);
6270 goto send_request;
6271 }
6272
6273 /* Use active scan by default. */
6274 if (priv->config & CFG_SPEED_SCAN)
6275 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6276 cpu_to_le16(30);
6277 else
6278 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6279 cpu_to_le16(20);
6280
6281 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6282 cpu_to_le16(20);
6283
6284 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6285 cpu_to_le16(ipw_passive_dwell_time(priv));
6286 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
6287
6288 #ifdef CONFIG_IPW2200_MONITOR
6289 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
6290 u8 channel;
6291 u8 band = 0;
6292
6293 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
6294 case LIBIPW_52GHZ_BAND:
6295 band = (u8) (IPW_A_MODE << 6) | 1;
6296 channel = priv->channel;
6297 break;
6298
6299 case LIBIPW_24GHZ_BAND:
6300 band = (u8) (IPW_B_MODE << 6) | 1;
6301 channel = priv->channel;
6302 break;
6303
6304 default:
6305 band = (u8) (IPW_B_MODE << 6) | 1;
6306 channel = 9;
6307 break;
6308 }
6309
6310 scan.channels_list[0] = band;
6311 scan.channels_list[1] = channel;
6312 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
6313
6314 /* NOTE: The card will sit on this channel for this time
6315 * period. Scan aborts are timing sensitive and frequently
6316 * result in firmware restarts. As such, it is best to
6317 * set a small dwell_time here and just keep re-issuing
6318 * scans. Otherwise fast channel hopping will not actually
6319 * hop channels.
6320 *
6321 * TODO: Move SPEED SCAN support to all modes and bands */
6322 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6323 cpu_to_le16(2000);
6324 } else {
6325 #endif /* CONFIG_IPW2200_MONITOR */
6326 /* Honor direct scans first, otherwise if we are roaming make
6327 * this a direct scan for the current network. Finally,
6328 * ensure that every other scan is a fast channel hop scan */
6329 if (direct) {
6330 err = ipw_send_ssid(priv, priv->direct_scan_ssid,
6331 priv->direct_scan_ssid_len);
6332 if (err) {
6333 IPW_DEBUG_HC("Attempt to send SSID command "
6334 "failed\n");
6335 goto done;
6336 }
6337
6338 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6339 } else if ((priv->status & STATUS_ROAMING)
6340 || (!(priv->status & STATUS_ASSOCIATED)
6341 && (priv->config & CFG_STATIC_ESSID)
6342 && (le32_to_cpu(scan.full_scan_index) % 2))) {
6343 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6344 if (err) {
6345 IPW_DEBUG_HC("Attempt to send SSID command "
6346 "failed.\n");
6347 goto done;
6348 }
6349
6350 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6351 } else
6352 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
6353
6354 ipw_add_scan_channels(priv, &scan, scan_type);
6355 #ifdef CONFIG_IPW2200_MONITOR
6356 }
6357 #endif
6358
6359 send_request:
6360 err = ipw_send_scan_request_ext(priv, &scan);
6361 if (err) {
6362 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
6363 goto done;
6364 }
6365
6366 priv->status |= STATUS_SCANNING;
6367 if (direct) {
6368 priv->status &= ~STATUS_DIRECT_SCAN_PENDING;
6369 priv->direct_scan_ssid_len = 0;
6370 } else
6371 priv->status &= ~STATUS_SCAN_PENDING;
6372
6373 schedule_delayed_work(&priv->scan_check, IPW_SCAN_CHECK_WATCHDOG);
6374 done:
6375 mutex_unlock(&priv->mutex);
6376 return err;
6377 }
6378
ipw_request_passive_scan(struct work_struct * work)6379 static void ipw_request_passive_scan(struct work_struct *work)
6380 {
6381 struct ipw_priv *priv =
6382 container_of(work, struct ipw_priv, request_passive_scan.work);
6383 ipw_request_scan_helper(priv, IW_SCAN_TYPE_PASSIVE, 0);
6384 }
6385
ipw_request_scan(struct work_struct * work)6386 static void ipw_request_scan(struct work_struct *work)
6387 {
6388 struct ipw_priv *priv =
6389 container_of(work, struct ipw_priv, request_scan.work);
6390 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 0);
6391 }
6392
ipw_request_direct_scan(struct work_struct * work)6393 static void ipw_request_direct_scan(struct work_struct *work)
6394 {
6395 struct ipw_priv *priv =
6396 container_of(work, struct ipw_priv, request_direct_scan.work);
6397 ipw_request_scan_helper(priv, IW_SCAN_TYPE_ACTIVE, 1);
6398 }
6399
ipw_bg_abort_scan(struct work_struct * work)6400 static void ipw_bg_abort_scan(struct work_struct *work)
6401 {
6402 struct ipw_priv *priv =
6403 container_of(work, struct ipw_priv, abort_scan);
6404 mutex_lock(&priv->mutex);
6405 ipw_abort_scan(priv);
6406 mutex_unlock(&priv->mutex);
6407 }
6408
ipw_wpa_enable(struct ipw_priv * priv,int value)6409 static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6410 {
6411 /* This is called when wpa_supplicant loads and closes the driver
6412 * interface. */
6413 priv->ieee->wpa_enabled = value;
6414 return 0;
6415 }
6416
ipw_wpa_set_auth_algs(struct ipw_priv * priv,int value)6417 static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6418 {
6419 struct libipw_device *ieee = priv->ieee;
6420 struct libipw_security sec = {
6421 .flags = SEC_AUTH_MODE,
6422 };
6423 int ret = 0;
6424
6425 if (value & IW_AUTH_ALG_SHARED_KEY) {
6426 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6427 ieee->open_wep = 0;
6428 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
6429 sec.auth_mode = WLAN_AUTH_OPEN;
6430 ieee->open_wep = 1;
6431 } else if (value & IW_AUTH_ALG_LEAP) {
6432 sec.auth_mode = WLAN_AUTH_LEAP;
6433 ieee->open_wep = 1;
6434 } else
6435 return -EINVAL;
6436
6437 if (ieee->set_security)
6438 ieee->set_security(ieee->dev, &sec);
6439 else
6440 ret = -EOPNOTSUPP;
6441
6442 return ret;
6443 }
6444
ipw_wpa_assoc_frame(struct ipw_priv * priv,char * wpa_ie,int wpa_ie_len)6445 static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6446 int wpa_ie_len)
6447 {
6448 /* make sure WPA is enabled */
6449 ipw_wpa_enable(priv, 1);
6450 }
6451
ipw_set_rsn_capa(struct ipw_priv * priv,char * capabilities,int length)6452 static int ipw_set_rsn_capa(struct ipw_priv *priv,
6453 char *capabilities, int length)
6454 {
6455 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6456
6457 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
6458 capabilities);
6459 }
6460
6461 /*
6462 * WE-18 support
6463 */
6464
ipw_wx_get_name(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6465 static int ipw_wx_get_name(struct net_device *dev,
6466 struct iw_request_info *info,
6467 union iwreq_data *wrqu, char *extra)
6468 {
6469 strcpy(wrqu->name, "IEEE 802.11");
6470 return 0;
6471 }
6472
6473 /* SIOCSIWGENIE */
ipw_wx_set_genie(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6474 static int ipw_wx_set_genie(struct net_device *dev,
6475 struct iw_request_info *info,
6476 union iwreq_data *wrqu, char *extra)
6477 {
6478 struct ipw_priv *priv = libipw_priv(dev);
6479 struct libipw_device *ieee = priv->ieee;
6480 u8 *buf;
6481 int err = 0;
6482
6483 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6484 (wrqu->data.length && extra == NULL))
6485 return -EINVAL;
6486
6487 if (wrqu->data.length) {
6488 buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
6489 if (buf == NULL) {
6490 err = -ENOMEM;
6491 goto out;
6492 }
6493
6494 kfree(ieee->wpa_ie);
6495 ieee->wpa_ie = buf;
6496 ieee->wpa_ie_len = wrqu->data.length;
6497 } else {
6498 kfree(ieee->wpa_ie);
6499 ieee->wpa_ie = NULL;
6500 ieee->wpa_ie_len = 0;
6501 }
6502
6503 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6504 out:
6505 return err;
6506 }
6507
6508 /* SIOCGIWGENIE */
ipw_wx_get_genie(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6509 static int ipw_wx_get_genie(struct net_device *dev,
6510 struct iw_request_info *info,
6511 union iwreq_data *wrqu, char *extra)
6512 {
6513 struct ipw_priv *priv = libipw_priv(dev);
6514 struct libipw_device *ieee = priv->ieee;
6515 int err = 0;
6516
6517 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6518 wrqu->data.length = 0;
6519 goto out;
6520 }
6521
6522 if (wrqu->data.length < ieee->wpa_ie_len) {
6523 err = -E2BIG;
6524 goto out;
6525 }
6526
6527 wrqu->data.length = ieee->wpa_ie_len;
6528 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6529
6530 out:
6531 return err;
6532 }
6533
wext_cipher2level(int cipher)6534 static int wext_cipher2level(int cipher)
6535 {
6536 switch (cipher) {
6537 case IW_AUTH_CIPHER_NONE:
6538 return SEC_LEVEL_0;
6539 case IW_AUTH_CIPHER_WEP40:
6540 case IW_AUTH_CIPHER_WEP104:
6541 return SEC_LEVEL_1;
6542 case IW_AUTH_CIPHER_TKIP:
6543 return SEC_LEVEL_2;
6544 case IW_AUTH_CIPHER_CCMP:
6545 return SEC_LEVEL_3;
6546 default:
6547 return -1;
6548 }
6549 }
6550
6551 /* SIOCSIWAUTH */
ipw_wx_set_auth(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6552 static int ipw_wx_set_auth(struct net_device *dev,
6553 struct iw_request_info *info,
6554 union iwreq_data *wrqu, char *extra)
6555 {
6556 struct ipw_priv *priv = libipw_priv(dev);
6557 struct libipw_device *ieee = priv->ieee;
6558 struct iw_param *param = &wrqu->param;
6559 struct libipw_crypt_data *crypt;
6560 unsigned long flags;
6561 int ret = 0;
6562
6563 switch (param->flags & IW_AUTH_INDEX) {
6564 case IW_AUTH_WPA_VERSION:
6565 break;
6566 case IW_AUTH_CIPHER_PAIRWISE:
6567 ipw_set_hw_decrypt_unicast(priv,
6568 wext_cipher2level(param->value));
6569 break;
6570 case IW_AUTH_CIPHER_GROUP:
6571 ipw_set_hw_decrypt_multicast(priv,
6572 wext_cipher2level(param->value));
6573 break;
6574 case IW_AUTH_KEY_MGMT:
6575 /*
6576 * ipw2200 does not use these parameters
6577 */
6578 break;
6579
6580 case IW_AUTH_TKIP_COUNTERMEASURES:
6581 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
6582 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
6583 break;
6584
6585 flags = crypt->ops->get_flags(crypt->priv);
6586
6587 if (param->value)
6588 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6589 else
6590 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6591
6592 crypt->ops->set_flags(flags, crypt->priv);
6593
6594 break;
6595
6596 case IW_AUTH_DROP_UNENCRYPTED:{
6597 /* HACK:
6598 *
6599 * wpa_supplicant calls set_wpa_enabled when the driver
6600 * is loaded and unloaded, regardless of if WPA is being
6601 * used. No other calls are made which can be used to
6602 * determine if encryption will be used or not prior to
6603 * association being expected. If encryption is not being
6604 * used, drop_unencrypted is set to false, else true -- we
6605 * can use this to determine if the CAP_PRIVACY_ON bit should
6606 * be set.
6607 */
6608 struct libipw_security sec = {
6609 .flags = SEC_ENABLED,
6610 .enabled = param->value,
6611 };
6612 priv->ieee->drop_unencrypted = param->value;
6613 /* We only change SEC_LEVEL for open mode. Others
6614 * are set by ipw_wpa_set_encryption.
6615 */
6616 if (!param->value) {
6617 sec.flags |= SEC_LEVEL;
6618 sec.level = SEC_LEVEL_0;
6619 } else {
6620 sec.flags |= SEC_LEVEL;
6621 sec.level = SEC_LEVEL_1;
6622 }
6623 if (priv->ieee->set_security)
6624 priv->ieee->set_security(priv->ieee->dev, &sec);
6625 break;
6626 }
6627
6628 case IW_AUTH_80211_AUTH_ALG:
6629 ret = ipw_wpa_set_auth_algs(priv, param->value);
6630 break;
6631
6632 case IW_AUTH_WPA_ENABLED:
6633 ret = ipw_wpa_enable(priv, param->value);
6634 ipw_disassociate(priv);
6635 break;
6636
6637 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6638 ieee->ieee802_1x = param->value;
6639 break;
6640
6641 case IW_AUTH_PRIVACY_INVOKED:
6642 ieee->privacy_invoked = param->value;
6643 break;
6644
6645 default:
6646 return -EOPNOTSUPP;
6647 }
6648 return ret;
6649 }
6650
6651 /* SIOCGIWAUTH */
ipw_wx_get_auth(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6652 static int ipw_wx_get_auth(struct net_device *dev,
6653 struct iw_request_info *info,
6654 union iwreq_data *wrqu, char *extra)
6655 {
6656 struct ipw_priv *priv = libipw_priv(dev);
6657 struct libipw_device *ieee = priv->ieee;
6658 struct libipw_crypt_data *crypt;
6659 struct iw_param *param = &wrqu->param;
6660
6661 switch (param->flags & IW_AUTH_INDEX) {
6662 case IW_AUTH_WPA_VERSION:
6663 case IW_AUTH_CIPHER_PAIRWISE:
6664 case IW_AUTH_CIPHER_GROUP:
6665 case IW_AUTH_KEY_MGMT:
6666 /*
6667 * wpa_supplicant will control these internally
6668 */
6669 return -EOPNOTSUPP;
6670
6671 case IW_AUTH_TKIP_COUNTERMEASURES:
6672 crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
6673 if (!crypt || !crypt->ops->get_flags)
6674 break;
6675
6676 param->value = (crypt->ops->get_flags(crypt->priv) &
6677 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6678
6679 break;
6680
6681 case IW_AUTH_DROP_UNENCRYPTED:
6682 param->value = ieee->drop_unencrypted;
6683 break;
6684
6685 case IW_AUTH_80211_AUTH_ALG:
6686 param->value = ieee->sec.auth_mode;
6687 break;
6688
6689 case IW_AUTH_WPA_ENABLED:
6690 param->value = ieee->wpa_enabled;
6691 break;
6692
6693 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6694 param->value = ieee->ieee802_1x;
6695 break;
6696
6697 case IW_AUTH_ROAMING_CONTROL:
6698 case IW_AUTH_PRIVACY_INVOKED:
6699 param->value = ieee->privacy_invoked;
6700 break;
6701
6702 default:
6703 return -EOPNOTSUPP;
6704 }
6705 return 0;
6706 }
6707
6708 /* SIOCSIWENCODEEXT */
ipw_wx_set_encodeext(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6709 static int ipw_wx_set_encodeext(struct net_device *dev,
6710 struct iw_request_info *info,
6711 union iwreq_data *wrqu, char *extra)
6712 {
6713 struct ipw_priv *priv = libipw_priv(dev);
6714 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6715
6716 if (hwcrypto) {
6717 if (ext->alg == IW_ENCODE_ALG_TKIP) {
6718 /* IPW HW can't build TKIP MIC,
6719 host decryption still needed */
6720 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6721 priv->ieee->host_mc_decrypt = 1;
6722 else {
6723 priv->ieee->host_encrypt = 0;
6724 priv->ieee->host_encrypt_msdu = 1;
6725 priv->ieee->host_decrypt = 1;
6726 }
6727 } else {
6728 priv->ieee->host_encrypt = 0;
6729 priv->ieee->host_encrypt_msdu = 0;
6730 priv->ieee->host_decrypt = 0;
6731 priv->ieee->host_mc_decrypt = 0;
6732 }
6733 }
6734
6735 return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6736 }
6737
6738 /* SIOCGIWENCODEEXT */
ipw_wx_get_encodeext(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6739 static int ipw_wx_get_encodeext(struct net_device *dev,
6740 struct iw_request_info *info,
6741 union iwreq_data *wrqu, char *extra)
6742 {
6743 struct ipw_priv *priv = libipw_priv(dev);
6744 return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6745 }
6746
6747 /* SIOCSIWMLME */
ipw_wx_set_mlme(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)6748 static int ipw_wx_set_mlme(struct net_device *dev,
6749 struct iw_request_info *info,
6750 union iwreq_data *wrqu, char *extra)
6751 {
6752 struct ipw_priv *priv = libipw_priv(dev);
6753 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6754
6755 switch (mlme->cmd) {
6756 case IW_MLME_DEAUTH:
6757 /* silently ignore */
6758 break;
6759
6760 case IW_MLME_DISASSOC:
6761 ipw_disassociate(priv);
6762 break;
6763
6764 default:
6765 return -EOPNOTSUPP;
6766 }
6767 return 0;
6768 }
6769
6770 #ifdef CONFIG_IPW2200_QOS
6771
6772 /* QoS */
6773 /*
6774 * get the modulation type of the current network or
6775 * the card current mode
6776 */
ipw_qos_current_mode(struct ipw_priv * priv)6777 static u8 ipw_qos_current_mode(struct ipw_priv * priv)
6778 {
6779 u8 mode = 0;
6780
6781 if (priv->status & STATUS_ASSOCIATED) {
6782 unsigned long flags;
6783
6784 spin_lock_irqsave(&priv->ieee->lock, flags);
6785 mode = priv->assoc_network->mode;
6786 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6787 } else {
6788 mode = priv->ieee->mode;
6789 }
6790 IPW_DEBUG_QOS("QoS network/card mode %d\n", mode);
6791 return mode;
6792 }
6793
6794 /*
6795 * Handle management frame beacon and probe response
6796 */
ipw_qos_handle_probe_response(struct ipw_priv * priv,int active_network,struct libipw_network * network)6797 static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6798 int active_network,
6799 struct libipw_network *network)
6800 {
6801 u32 size = sizeof(struct libipw_qos_parameters);
6802
6803 if (network->capability & WLAN_CAPABILITY_IBSS)
6804 network->qos_data.active = network->qos_data.supported;
6805
6806 if (network->flags & NETWORK_HAS_QOS_MASK) {
6807 if (active_network &&
6808 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
6809 network->qos_data.active = network->qos_data.supported;
6810
6811 if ((network->qos_data.active == 1) && (active_network == 1) &&
6812 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6813 (network->qos_data.old_param_count !=
6814 network->qos_data.param_count)) {
6815 network->qos_data.old_param_count =
6816 network->qos_data.param_count;
6817 schedule_work(&priv->qos_activate);
6818 IPW_DEBUG_QOS("QoS parameters change call "
6819 "qos_activate\n");
6820 }
6821 } else {
6822 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6823 memcpy(&network->qos_data.parameters,
6824 &def_parameters_CCK, size);
6825 else
6826 memcpy(&network->qos_data.parameters,
6827 &def_parameters_OFDM, size);
6828
6829 if ((network->qos_data.active == 1) && (active_network == 1)) {
6830 IPW_DEBUG_QOS("QoS was disabled call qos_activate\n");
6831 schedule_work(&priv->qos_activate);
6832 }
6833
6834 network->qos_data.active = 0;
6835 network->qos_data.supported = 0;
6836 }
6837 if ((priv->status & STATUS_ASSOCIATED) &&
6838 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6839 if (!ether_addr_equal(network->bssid, priv->bssid))
6840 if (network->capability & WLAN_CAPABILITY_IBSS)
6841 if ((network->ssid_len ==
6842 priv->assoc_network->ssid_len) &&
6843 !memcmp(network->ssid,
6844 priv->assoc_network->ssid,
6845 network->ssid_len)) {
6846 schedule_work(&priv->merge_networks);
6847 }
6848 }
6849
6850 return 0;
6851 }
6852
6853 /*
6854 * This function set up the firmware to support QoS. It sends
6855 * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6856 */
ipw_qos_activate(struct ipw_priv * priv,struct libipw_qos_data * qos_network_data)6857 static int ipw_qos_activate(struct ipw_priv *priv,
6858 struct libipw_qos_data *qos_network_data)
6859 {
6860 int err;
6861 struct libipw_qos_parameters qos_parameters[QOS_QOS_SETS];
6862 struct libipw_qos_parameters *active_one = NULL;
6863 u32 size = sizeof(struct libipw_qos_parameters);
6864 u32 burst_duration;
6865 int i;
6866 u8 type;
6867
6868 type = ipw_qos_current_mode(priv);
6869
6870 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6871 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6872 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6873 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6874
6875 if (qos_network_data == NULL) {
6876 if (type == IEEE_B) {
6877 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6878 active_one = &def_parameters_CCK;
6879 } else
6880 active_one = &def_parameters_OFDM;
6881
6882 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6883 burst_duration = ipw_qos_get_burst_duration(priv);
6884 for (i = 0; i < QOS_QUEUE_NUM; i++)
6885 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6886 cpu_to_le16(burst_duration);
6887 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6888 if (type == IEEE_B) {
6889 IPW_DEBUG_QOS("QoS activate IBSS network mode %d\n",
6890 type);
6891 if (priv->qos_data.qos_enable == 0)
6892 active_one = &def_parameters_CCK;
6893 else
6894 active_one = priv->qos_data.def_qos_parm_CCK;
6895 } else {
6896 if (priv->qos_data.qos_enable == 0)
6897 active_one = &def_parameters_OFDM;
6898 else
6899 active_one = priv->qos_data.def_qos_parm_OFDM;
6900 }
6901 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6902 } else {
6903 unsigned long flags;
6904 int active;
6905
6906 spin_lock_irqsave(&priv->ieee->lock, flags);
6907 active_one = &(qos_network_data->parameters);
6908 qos_network_data->old_param_count =
6909 qos_network_data->param_count;
6910 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6911 active = qos_network_data->supported;
6912 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6913
6914 if (active == 0) {
6915 burst_duration = ipw_qos_get_burst_duration(priv);
6916 for (i = 0; i < QOS_QUEUE_NUM; i++)
6917 qos_parameters[QOS_PARAM_SET_ACTIVE].
6918 tx_op_limit[i] = cpu_to_le16(burst_duration);
6919 }
6920 }
6921
6922 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
6923 err = ipw_send_qos_params_command(priv, &qos_parameters[0]);
6924 if (err)
6925 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6926
6927 return err;
6928 }
6929
6930 /*
6931 * send IPW_CMD_WME_INFO to the firmware
6932 */
ipw_qos_set_info_element(struct ipw_priv * priv)6933 static int ipw_qos_set_info_element(struct ipw_priv *priv)
6934 {
6935 int ret = 0;
6936 struct libipw_qos_information_element qos_info;
6937
6938 if (priv == NULL)
6939 return -1;
6940
6941 qos_info.elementID = QOS_ELEMENT_ID;
6942 qos_info.length = sizeof(struct libipw_qos_information_element) - 2;
6943
6944 qos_info.version = QOS_VERSION_1;
6945 qos_info.ac_info = 0;
6946
6947 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6948 qos_info.qui_type = QOS_OUI_TYPE;
6949 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6950
6951 ret = ipw_send_qos_info_command(priv, &qos_info);
6952 if (ret != 0) {
6953 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6954 }
6955 return ret;
6956 }
6957
6958 /*
6959 * Set the QoS parameter with the association request structure
6960 */
ipw_qos_association(struct ipw_priv * priv,struct libipw_network * network)6961 static int ipw_qos_association(struct ipw_priv *priv,
6962 struct libipw_network *network)
6963 {
6964 int err = 0;
6965 struct libipw_qos_data *qos_data = NULL;
6966 struct libipw_qos_data ibss_data = {
6967 .supported = 1,
6968 .active = 1,
6969 };
6970
6971 switch (priv->ieee->iw_mode) {
6972 case IW_MODE_ADHOC:
6973 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
6974
6975 qos_data = &ibss_data;
6976 break;
6977
6978 case IW_MODE_INFRA:
6979 qos_data = &network->qos_data;
6980 break;
6981
6982 default:
6983 BUG();
6984 break;
6985 }
6986
6987 err = ipw_qos_activate(priv, qos_data);
6988 if (err) {
6989 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6990 return err;
6991 }
6992
6993 if (priv->qos_data.qos_enable && qos_data->supported) {
6994 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6995 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6996 return ipw_qos_set_info_element(priv);
6997 }
6998
6999 return 0;
7000 }
7001
7002 /*
7003 * handling the beaconing responses. if we get different QoS setting
7004 * off the network from the associated setting, adjust the QoS
7005 * setting
7006 */
ipw_qos_association_resp(struct ipw_priv * priv,struct libipw_network * network)7007 static void ipw_qos_association_resp(struct ipw_priv *priv,
7008 struct libipw_network *network)
7009 {
7010 unsigned long flags;
7011 u32 size = sizeof(struct libipw_qos_parameters);
7012 int set_qos_param = 0;
7013
7014 if ((priv == NULL) || (network == NULL) ||
7015 (priv->assoc_network == NULL))
7016 return;
7017
7018 if (!(priv->status & STATUS_ASSOCIATED))
7019 return;
7020
7021 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
7022 return;
7023
7024 spin_lock_irqsave(&priv->ieee->lock, flags);
7025 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
7026 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
7027 sizeof(struct libipw_qos_data));
7028 priv->assoc_network->qos_data.active = 1;
7029 if ((network->qos_data.old_param_count !=
7030 network->qos_data.param_count)) {
7031 set_qos_param = 1;
7032 network->qos_data.old_param_count =
7033 network->qos_data.param_count;
7034 }
7035
7036 } else {
7037 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
7038 memcpy(&priv->assoc_network->qos_data.parameters,
7039 &def_parameters_CCK, size);
7040 else
7041 memcpy(&priv->assoc_network->qos_data.parameters,
7042 &def_parameters_OFDM, size);
7043 priv->assoc_network->qos_data.active = 0;
7044 priv->assoc_network->qos_data.supported = 0;
7045 set_qos_param = 1;
7046 }
7047
7048 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7049
7050 if (set_qos_param == 1)
7051 schedule_work(&priv->qos_activate);
7052 }
7053
ipw_qos_get_burst_duration(struct ipw_priv * priv)7054 static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
7055 {
7056 u32 ret = 0;
7057
7058 if (!priv)
7059 return 0;
7060
7061 if (!(priv->ieee->modulation & LIBIPW_OFDM_MODULATION))
7062 ret = priv->qos_data.burst_duration_CCK;
7063 else
7064 ret = priv->qos_data.burst_duration_OFDM;
7065
7066 return ret;
7067 }
7068
7069 /*
7070 * Initialize the setting of QoS global
7071 */
ipw_qos_init(struct ipw_priv * priv,int enable,int burst_enable,u32 burst_duration_CCK,u32 burst_duration_OFDM)7072 static void ipw_qos_init(struct ipw_priv *priv, int enable,
7073 int burst_enable, u32 burst_duration_CCK,
7074 u32 burst_duration_OFDM)
7075 {
7076 priv->qos_data.qos_enable = enable;
7077
7078 if (priv->qos_data.qos_enable) {
7079 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7080 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7081 IPW_DEBUG_QOS("QoS is enabled\n");
7082 } else {
7083 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7084 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7085 IPW_DEBUG_QOS("QoS is not enabled\n");
7086 }
7087
7088 priv->qos_data.burst_enable = burst_enable;
7089
7090 if (burst_enable) {
7091 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7092 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7093 } else {
7094 priv->qos_data.burst_duration_CCK = 0;
7095 priv->qos_data.burst_duration_OFDM = 0;
7096 }
7097 }
7098
7099 /*
7100 * map the packet priority to the right TX Queue
7101 */
ipw_get_tx_queue_number(struct ipw_priv * priv,u16 priority)7102 static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7103 {
7104 if (priority > 7 || !priv->qos_data.qos_enable)
7105 priority = 0;
7106
7107 return from_priority_to_tx_queue[priority] - 1;
7108 }
7109
ipw_is_qos_active(struct net_device * dev,struct sk_buff * skb)7110 static int ipw_is_qos_active(struct net_device *dev,
7111 struct sk_buff *skb)
7112 {
7113 struct ipw_priv *priv = libipw_priv(dev);
7114 struct libipw_qos_data *qos_data = NULL;
7115 int active, supported;
7116 u8 *daddr = skb->data + ETH_ALEN;
7117 int unicast = !is_multicast_ether_addr(daddr);
7118
7119 if (!(priv->status & STATUS_ASSOCIATED))
7120 return 0;
7121
7122 qos_data = &priv->assoc_network->qos_data;
7123
7124 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7125 if (unicast == 0)
7126 qos_data->active = 0;
7127 else
7128 qos_data->active = qos_data->supported;
7129 }
7130 active = qos_data->active;
7131 supported = qos_data->supported;
7132 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7133 "unicast %d\n",
7134 priv->qos_data.qos_enable, active, supported, unicast);
7135 if (active && priv->qos_data.qos_enable)
7136 return 1;
7137
7138 return 0;
7139
7140 }
7141 /*
7142 * add QoS parameter to the TX command
7143 */
ipw_qos_set_tx_queue_command(struct ipw_priv * priv,u16 priority,struct tfd_data * tfd)7144 static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7145 u16 priority,
7146 struct tfd_data *tfd)
7147 {
7148 int tx_queue_id = 0;
7149
7150
7151 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7152 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7153
7154 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7155 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
7156 tfd->tfd.tfd_26.mchdr.qos_ctrl |= cpu_to_le16(CTRL_QOS_NO_ACK);
7157 }
7158 return 0;
7159 }
7160
7161 /*
7162 * background support to run QoS activate functionality
7163 */
ipw_bg_qos_activate(struct work_struct * work)7164 static void ipw_bg_qos_activate(struct work_struct *work)
7165 {
7166 struct ipw_priv *priv =
7167 container_of(work, struct ipw_priv, qos_activate);
7168
7169 mutex_lock(&priv->mutex);
7170
7171 if (priv->status & STATUS_ASSOCIATED)
7172 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7173
7174 mutex_unlock(&priv->mutex);
7175 }
7176
ipw_handle_probe_response(struct net_device * dev,struct libipw_probe_response * resp,struct libipw_network * network)7177 static int ipw_handle_probe_response(struct net_device *dev,
7178 struct libipw_probe_response *resp,
7179 struct libipw_network *network)
7180 {
7181 struct ipw_priv *priv = libipw_priv(dev);
7182 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7183 (network == priv->assoc_network));
7184
7185 ipw_qos_handle_probe_response(priv, active_network, network);
7186
7187 return 0;
7188 }
7189
ipw_handle_beacon(struct net_device * dev,struct libipw_beacon * resp,struct libipw_network * network)7190 static int ipw_handle_beacon(struct net_device *dev,
7191 struct libipw_beacon *resp,
7192 struct libipw_network *network)
7193 {
7194 struct ipw_priv *priv = libipw_priv(dev);
7195 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7196 (network == priv->assoc_network));
7197
7198 ipw_qos_handle_probe_response(priv, active_network, network);
7199
7200 return 0;
7201 }
7202
ipw_handle_assoc_response(struct net_device * dev,struct libipw_assoc_response * resp,struct libipw_network * network)7203 static int ipw_handle_assoc_response(struct net_device *dev,
7204 struct libipw_assoc_response *resp,
7205 struct libipw_network *network)
7206 {
7207 struct ipw_priv *priv = libipw_priv(dev);
7208 ipw_qos_association_resp(priv, network);
7209 return 0;
7210 }
7211
ipw_send_qos_params_command(struct ipw_priv * priv,struct libipw_qos_parameters * qos_param)7212 static int ipw_send_qos_params_command(struct ipw_priv *priv, struct libipw_qos_parameters
7213 *qos_param)
7214 {
7215 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7216 sizeof(*qos_param) * 3, qos_param);
7217 }
7218
ipw_send_qos_info_command(struct ipw_priv * priv,struct libipw_qos_information_element * qos_param)7219 static int ipw_send_qos_info_command(struct ipw_priv *priv, struct libipw_qos_information_element
7220 *qos_param)
7221 {
7222 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7223 qos_param);
7224 }
7225
7226 #endif /* CONFIG_IPW2200_QOS */
7227
ipw_associate_network(struct ipw_priv * priv,struct libipw_network * network,struct ipw_supported_rates * rates,int roaming)7228 static int ipw_associate_network(struct ipw_priv *priv,
7229 struct libipw_network *network,
7230 struct ipw_supported_rates *rates, int roaming)
7231 {
7232 int err;
7233
7234 if (priv->config & CFG_FIXED_RATE)
7235 ipw_set_fixed_rate(priv, network->mode);
7236
7237 if (!(priv->config & CFG_STATIC_ESSID)) {
7238 priv->essid_len = min(network->ssid_len,
7239 (u8) IW_ESSID_MAX_SIZE);
7240 memcpy(priv->essid, network->ssid, priv->essid_len);
7241 }
7242
7243 network->last_associate = jiffies;
7244
7245 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7246 priv->assoc_request.channel = network->channel;
7247 priv->assoc_request.auth_key = 0;
7248
7249 if ((priv->capability & CAP_PRIVACY_ON) &&
7250 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
7251 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
7252 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7253
7254 if (priv->ieee->sec.level == SEC_LEVEL_1)
7255 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
7256
7257 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7258 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7259 priv->assoc_request.auth_type = AUTH_LEAP;
7260 else
7261 priv->assoc_request.auth_type = AUTH_OPEN;
7262
7263 if (priv->ieee->wpa_ie_len) {
7264 priv->assoc_request.policy_support = cpu_to_le16(0x02); /* RSN active */
7265 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7266 priv->ieee->wpa_ie_len);
7267 }
7268
7269 /*
7270 * It is valid for our ieee device to support multiple modes, but
7271 * when it comes to associating to a given network we have to choose
7272 * just one mode.
7273 */
7274 if (network->mode & priv->ieee->mode & IEEE_A)
7275 priv->assoc_request.ieee_mode = IPW_A_MODE;
7276 else if (network->mode & priv->ieee->mode & IEEE_G)
7277 priv->assoc_request.ieee_mode = IPW_G_MODE;
7278 else if (network->mode & priv->ieee->mode & IEEE_B)
7279 priv->assoc_request.ieee_mode = IPW_B_MODE;
7280
7281 priv->assoc_request.capability = cpu_to_le16(network->capability);
7282 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7283 && !(priv->config & CFG_PREAMBLE_LONG)) {
7284 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7285 } else {
7286 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7287
7288 /* Clear the short preamble if we won't be supporting it */
7289 priv->assoc_request.capability &=
7290 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE);
7291 }
7292
7293 /* Clear capability bits that aren't used in Ad Hoc */
7294 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7295 priv->assoc_request.capability &=
7296 ~cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME);
7297
7298 IPW_DEBUG_ASSOC("%ssociation attempt: '%*pE', channel %d, 802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
7299 roaming ? "Rea" : "A",
7300 priv->essid_len, priv->essid,
7301 network->channel,
7302 ipw_modes[priv->assoc_request.ieee_mode],
7303 rates->num_rates,
7304 (priv->assoc_request.preamble_length ==
7305 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7306 network->capability &
7307 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
7308 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
7309 priv->capability & CAP_PRIVACY_ON ?
7310 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
7311 "(open)") : "",
7312 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
7313 priv->capability & CAP_PRIVACY_ON ?
7314 '1' + priv->ieee->sec.active_key : '.',
7315 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
7316
7317 priv->assoc_request.beacon_interval = cpu_to_le16(network->beacon_interval);
7318 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
7319 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
7320 priv->assoc_request.assoc_type = HC_IBSS_START;
7321 priv->assoc_request.assoc_tsf_msw = 0;
7322 priv->assoc_request.assoc_tsf_lsw = 0;
7323 } else {
7324 if (unlikely(roaming))
7325 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7326 else
7327 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7328 priv->assoc_request.assoc_tsf_msw = cpu_to_le32(network->time_stamp[1]);
7329 priv->assoc_request.assoc_tsf_lsw = cpu_to_le32(network->time_stamp[0]);
7330 }
7331
7332 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
7333
7334 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7335 eth_broadcast_addr(priv->assoc_request.dest);
7336 priv->assoc_request.atim_window = cpu_to_le16(network->atim_window);
7337 } else {
7338 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
7339 priv->assoc_request.atim_window = 0;
7340 }
7341
7342 priv->assoc_request.listen_interval = cpu_to_le16(network->listen_interval);
7343
7344 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7345 if (err) {
7346 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7347 return err;
7348 }
7349
7350 rates->ieee_mode = priv->assoc_request.ieee_mode;
7351 rates->purpose = IPW_RATE_CONNECT;
7352 ipw_send_supported_rates(priv, rates);
7353
7354 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7355 priv->sys_config.dot11g_auto_detection = 1;
7356 else
7357 priv->sys_config.dot11g_auto_detection = 0;
7358
7359 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7360 priv->sys_config.answer_broadcast_ssid_probe = 1;
7361 else
7362 priv->sys_config.answer_broadcast_ssid_probe = 0;
7363
7364 err = ipw_send_system_config(priv);
7365 if (err) {
7366 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7367 return err;
7368 }
7369
7370 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
7371 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
7372 if (err) {
7373 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7374 return err;
7375 }
7376
7377 /*
7378 * If preemption is enabled, it is possible for the association
7379 * to complete before we return from ipw_send_associate. Therefore
7380 * we have to be sure and update our priviate data first.
7381 */
7382 priv->channel = network->channel;
7383 memcpy(priv->bssid, network->bssid, ETH_ALEN);
7384 priv->status |= STATUS_ASSOCIATING;
7385 priv->status &= ~STATUS_SECURITY_UPDATED;
7386
7387 priv->assoc_network = network;
7388
7389 #ifdef CONFIG_IPW2200_QOS
7390 ipw_qos_association(priv, network);
7391 #endif
7392
7393 err = ipw_send_associate(priv, &priv->assoc_request);
7394 if (err) {
7395 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7396 return err;
7397 }
7398
7399 IPW_DEBUG(IPW_DL_STATE, "associating: '%*pE' %pM\n",
7400 priv->essid_len, priv->essid, priv->bssid);
7401
7402 return 0;
7403 }
7404
ipw_roam(void * data)7405 static void ipw_roam(void *data)
7406 {
7407 struct ipw_priv *priv = data;
7408 struct libipw_network *network = NULL;
7409 struct ipw_network_match match = {
7410 .network = priv->assoc_network
7411 };
7412
7413 /* The roaming process is as follows:
7414 *
7415 * 1. Missed beacon threshold triggers the roaming process by
7416 * setting the status ROAM bit and requesting a scan.
7417 * 2. When the scan completes, it schedules the ROAM work
7418 * 3. The ROAM work looks at all of the known networks for one that
7419 * is a better network than the currently associated. If none
7420 * found, the ROAM process is over (ROAM bit cleared)
7421 * 4. If a better network is found, a disassociation request is
7422 * sent.
7423 * 5. When the disassociation completes, the roam work is again
7424 * scheduled. The second time through, the driver is no longer
7425 * associated, and the newly selected network is sent an
7426 * association request.
7427 * 6. At this point ,the roaming process is complete and the ROAM
7428 * status bit is cleared.
7429 */
7430
7431 /* If we are no longer associated, and the roaming bit is no longer
7432 * set, then we are not actively roaming, so just return */
7433 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7434 return;
7435
7436 if (priv->status & STATUS_ASSOCIATED) {
7437 /* First pass through ROAM process -- look for a better
7438 * network */
7439 unsigned long flags;
7440 u8 rssi = priv->assoc_network->stats.rssi;
7441 priv->assoc_network->stats.rssi = -128;
7442 spin_lock_irqsave(&priv->ieee->lock, flags);
7443 list_for_each_entry(network, &priv->ieee->network_list, list) {
7444 if (network != priv->assoc_network)
7445 ipw_best_network(priv, &match, network, 1);
7446 }
7447 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7448 priv->assoc_network->stats.rssi = rssi;
7449
7450 if (match.network == priv->assoc_network) {
7451 IPW_DEBUG_ASSOC("No better APs in this network to "
7452 "roam to.\n");
7453 priv->status &= ~STATUS_ROAMING;
7454 ipw_debug_config(priv);
7455 return;
7456 }
7457
7458 ipw_send_disassociate(priv, 1);
7459 priv->assoc_network = match.network;
7460
7461 return;
7462 }
7463
7464 /* Second pass through ROAM process -- request association */
7465 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7466 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7467 priv->status &= ~STATUS_ROAMING;
7468 }
7469
ipw_bg_roam(struct work_struct * work)7470 static void ipw_bg_roam(struct work_struct *work)
7471 {
7472 struct ipw_priv *priv =
7473 container_of(work, struct ipw_priv, roam);
7474 mutex_lock(&priv->mutex);
7475 ipw_roam(priv);
7476 mutex_unlock(&priv->mutex);
7477 }
7478
ipw_associate(void * data)7479 static int ipw_associate(void *data)
7480 {
7481 struct ipw_priv *priv = data;
7482
7483 struct libipw_network *network = NULL;
7484 struct ipw_network_match match = {
7485 .network = NULL
7486 };
7487 struct ipw_supported_rates *rates;
7488 struct list_head *element;
7489 unsigned long flags;
7490
7491 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7492 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7493 return 0;
7494 }
7495
7496 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
7497 IPW_DEBUG_ASSOC("Not attempting association (already in "
7498 "progress)\n");
7499 return 0;
7500 }
7501
7502 if (priv->status & STATUS_DISASSOCIATING) {
7503 IPW_DEBUG_ASSOC("Not attempting association (in disassociating)\n");
7504 schedule_work(&priv->associate);
7505 return 0;
7506 }
7507
7508 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
7509 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7510 "initialized)\n");
7511 return 0;
7512 }
7513
7514 if (!(priv->config & CFG_ASSOCIATE) &&
7515 !(priv->config & (CFG_STATIC_ESSID | CFG_STATIC_BSSID))) {
7516 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
7517 return 0;
7518 }
7519
7520 /* Protect our use of the network_list */
7521 spin_lock_irqsave(&priv->ieee->lock, flags);
7522 list_for_each_entry(network, &priv->ieee->network_list, list)
7523 ipw_best_network(priv, &match, network, 0);
7524
7525 network = match.network;
7526 rates = &match.rates;
7527
7528 if (network == NULL &&
7529 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7530 priv->config & CFG_ADHOC_CREATE &&
7531 priv->config & CFG_STATIC_ESSID &&
7532 priv->config & CFG_STATIC_CHANNEL) {
7533 /* Use oldest network if the free list is empty */
7534 if (list_empty(&priv->ieee->network_free_list)) {
7535 struct libipw_network *oldest = NULL;
7536 struct libipw_network *target;
7537
7538 list_for_each_entry(target, &priv->ieee->network_list, list) {
7539 if ((oldest == NULL) ||
7540 (target->last_scanned < oldest->last_scanned))
7541 oldest = target;
7542 }
7543
7544 /* If there are no more slots, expire the oldest */
7545 list_del(&oldest->list);
7546 target = oldest;
7547 IPW_DEBUG_ASSOC("Expired '%*pE' (%pM) from network list.\n",
7548 target->ssid_len, target->ssid,
7549 target->bssid);
7550 list_add_tail(&target->list,
7551 &priv->ieee->network_free_list);
7552 }
7553
7554 element = priv->ieee->network_free_list.next;
7555 network = list_entry(element, struct libipw_network, list);
7556 ipw_adhoc_create(priv, network);
7557 rates = &priv->rates;
7558 list_del(element);
7559 list_add_tail(&network->list, &priv->ieee->network_list);
7560 }
7561 spin_unlock_irqrestore(&priv->ieee->lock, flags);
7562
7563 /* If we reached the end of the list, then we don't have any valid
7564 * matching APs */
7565 if (!network) {
7566 ipw_debug_config(priv);
7567
7568 if (!(priv->status & STATUS_SCANNING)) {
7569 if (!(priv->config & CFG_SPEED_SCAN))
7570 schedule_delayed_work(&priv->request_scan,
7571 SCAN_INTERVAL);
7572 else
7573 schedule_delayed_work(&priv->request_scan, 0);
7574 }
7575
7576 return 0;
7577 }
7578
7579 ipw_associate_network(priv, network, rates, 0);
7580
7581 return 1;
7582 }
7583
ipw_bg_associate(struct work_struct * work)7584 static void ipw_bg_associate(struct work_struct *work)
7585 {
7586 struct ipw_priv *priv =
7587 container_of(work, struct ipw_priv, associate);
7588 mutex_lock(&priv->mutex);
7589 ipw_associate(priv);
7590 mutex_unlock(&priv->mutex);
7591 }
7592
ipw_rebuild_decrypted_skb(struct ipw_priv * priv,struct sk_buff * skb)7593 static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7594 struct sk_buff *skb)
7595 {
7596 struct ieee80211_hdr *hdr;
7597 u16 fc;
7598
7599 hdr = (struct ieee80211_hdr *)skb->data;
7600 fc = le16_to_cpu(hdr->frame_control);
7601 if (!(fc & IEEE80211_FCTL_PROTECTED))
7602 return;
7603
7604 fc &= ~IEEE80211_FCTL_PROTECTED;
7605 hdr->frame_control = cpu_to_le16(fc);
7606 switch (priv->ieee->sec.level) {
7607 case SEC_LEVEL_3:
7608 /* Remove CCMP HDR */
7609 memmove(skb->data + LIBIPW_3ADDR_LEN,
7610 skb->data + LIBIPW_3ADDR_LEN + 8,
7611 skb->len - LIBIPW_3ADDR_LEN - 8);
7612 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
7613 break;
7614 case SEC_LEVEL_2:
7615 break;
7616 case SEC_LEVEL_1:
7617 /* Remove IV */
7618 memmove(skb->data + LIBIPW_3ADDR_LEN,
7619 skb->data + LIBIPW_3ADDR_LEN + 4,
7620 skb->len - LIBIPW_3ADDR_LEN - 4);
7621 skb_trim(skb, skb->len - 8); /* IV + ICV */
7622 break;
7623 case SEC_LEVEL_0:
7624 break;
7625 default:
7626 printk(KERN_ERR "Unknown security level %d\n",
7627 priv->ieee->sec.level);
7628 break;
7629 }
7630 }
7631
ipw_handle_data_packet(struct ipw_priv * priv,struct ipw_rx_mem_buffer * rxb,struct libipw_rx_stats * stats)7632 static void ipw_handle_data_packet(struct ipw_priv *priv,
7633 struct ipw_rx_mem_buffer *rxb,
7634 struct libipw_rx_stats *stats)
7635 {
7636 struct net_device *dev = priv->net_dev;
7637 struct libipw_hdr_4addr *hdr;
7638 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7639
7640 /* We received data from the HW, so stop the watchdog */
7641 netif_trans_update(dev);
7642
7643 /* We only process data packets if the
7644 * interface is open */
7645 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7646 skb_tailroom(rxb->skb))) {
7647 dev->stats.rx_errors++;
7648 priv->wstats.discard.misc++;
7649 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7650 return;
7651 } else if (unlikely(!netif_running(priv->net_dev))) {
7652 dev->stats.rx_dropped++;
7653 priv->wstats.discard.misc++;
7654 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7655 return;
7656 }
7657
7658 /* Advance skb->data to the start of the actual payload */
7659 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
7660
7661 /* Set the size of the skb to the size of the frame */
7662 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
7663
7664 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7665
7666 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
7667 hdr = (struct libipw_hdr_4addr *)rxb->skb->data;
7668 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
7669 (is_multicast_ether_addr(hdr->addr1) ?
7670 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
7671 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7672
7673 if (!libipw_rx(priv->ieee, rxb->skb, stats))
7674 dev->stats.rx_errors++;
7675 else { /* libipw_rx succeeded, so it now owns the SKB */
7676 rxb->skb = NULL;
7677 __ipw_led_activity_on(priv);
7678 }
7679 }
7680
7681 #ifdef CONFIG_IPW2200_RADIOTAP
ipw_handle_data_packet_monitor(struct ipw_priv * priv,struct ipw_rx_mem_buffer * rxb,struct libipw_rx_stats * stats)7682 static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7683 struct ipw_rx_mem_buffer *rxb,
7684 struct libipw_rx_stats *stats)
7685 {
7686 struct net_device *dev = priv->net_dev;
7687 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7688 struct ipw_rx_frame *frame = &pkt->u.frame;
7689
7690 /* initial pull of some data */
7691 u16 received_channel = frame->received_channel;
7692 u8 antennaAndPhy = frame->antennaAndPhy;
7693 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7694 u16 pktrate = frame->rate;
7695
7696 /* Magic struct that slots into the radiotap header -- no reason
7697 * to build this manually element by element, we can write it much
7698 * more efficiently than we can parse it. ORDER MATTERS HERE */
7699 struct ipw_rt_hdr *ipw_rt;
7700
7701 unsigned short len = le16_to_cpu(pkt->u.frame.length);
7702
7703 /* We received data from the HW, so stop the watchdog */
7704 netif_trans_update(dev);
7705
7706 /* We only process data packets if the
7707 * interface is open */
7708 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7709 skb_tailroom(rxb->skb))) {
7710 dev->stats.rx_errors++;
7711 priv->wstats.discard.misc++;
7712 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7713 return;
7714 } else if (unlikely(!netif_running(priv->net_dev))) {
7715 dev->stats.rx_dropped++;
7716 priv->wstats.discard.misc++;
7717 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7718 return;
7719 }
7720
7721 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7722 * that now */
7723 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7724 /* FIXME: Should alloc bigger skb instead */
7725 dev->stats.rx_dropped++;
7726 priv->wstats.discard.misc++;
7727 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7728 return;
7729 }
7730
7731 /* copy the frame itself */
7732 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7733 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7734
7735 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7736
7737 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7738 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7739 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total header+data */
7740
7741 /* Big bitfield of all the fields we provide in radiotap */
7742 ipw_rt->rt_hdr.it_present = cpu_to_le32(
7743 (1 << IEEE80211_RADIOTAP_TSFT) |
7744 (1 << IEEE80211_RADIOTAP_FLAGS) |
7745 (1 << IEEE80211_RADIOTAP_RATE) |
7746 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7747 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7748 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
7749 (1 << IEEE80211_RADIOTAP_ANTENNA));
7750
7751 /* Zero the flags, we'll add to them as we go */
7752 ipw_rt->rt_flags = 0;
7753 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
7754 frame->parent_tsf[2] << 16 |
7755 frame->parent_tsf[1] << 8 |
7756 frame->parent_tsf[0]);
7757
7758 /* Convert signal to DBM */
7759 ipw_rt->rt_dbmsignal = antsignal;
7760 ipw_rt->rt_dbmnoise = (s8) le16_to_cpu(frame->noise);
7761
7762 /* Convert the channel data and set the flags */
7763 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7764 if (received_channel > 14) { /* 802.11a */
7765 ipw_rt->rt_chbitmask =
7766 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7767 } else if (antennaAndPhy & 32) { /* 802.11b */
7768 ipw_rt->rt_chbitmask =
7769 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7770 } else { /* 802.11g */
7771 ipw_rt->rt_chbitmask =
7772 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7773 }
7774
7775 /* set the rate in multiples of 500k/s */
7776 switch (pktrate) {
7777 case IPW_TX_RATE_1MB:
7778 ipw_rt->rt_rate = 2;
7779 break;
7780 case IPW_TX_RATE_2MB:
7781 ipw_rt->rt_rate = 4;
7782 break;
7783 case IPW_TX_RATE_5MB:
7784 ipw_rt->rt_rate = 10;
7785 break;
7786 case IPW_TX_RATE_6MB:
7787 ipw_rt->rt_rate = 12;
7788 break;
7789 case IPW_TX_RATE_9MB:
7790 ipw_rt->rt_rate = 18;
7791 break;
7792 case IPW_TX_RATE_11MB:
7793 ipw_rt->rt_rate = 22;
7794 break;
7795 case IPW_TX_RATE_12MB:
7796 ipw_rt->rt_rate = 24;
7797 break;
7798 case IPW_TX_RATE_18MB:
7799 ipw_rt->rt_rate = 36;
7800 break;
7801 case IPW_TX_RATE_24MB:
7802 ipw_rt->rt_rate = 48;
7803 break;
7804 case IPW_TX_RATE_36MB:
7805 ipw_rt->rt_rate = 72;
7806 break;
7807 case IPW_TX_RATE_48MB:
7808 ipw_rt->rt_rate = 96;
7809 break;
7810 case IPW_TX_RATE_54MB:
7811 ipw_rt->rt_rate = 108;
7812 break;
7813 default:
7814 ipw_rt->rt_rate = 0;
7815 break;
7816 }
7817
7818 /* antenna number */
7819 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7820
7821 /* set the preamble flag if we have it */
7822 if ((antennaAndPhy & 64))
7823 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7824
7825 /* Set the size of the skb to the size of the frame */
7826 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
7827
7828 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7829
7830 if (!libipw_rx(priv->ieee, rxb->skb, stats))
7831 dev->stats.rx_errors++;
7832 else { /* libipw_rx succeeded, so it now owns the SKB */
7833 rxb->skb = NULL;
7834 /* no LED during capture */
7835 }
7836 }
7837 #endif
7838
7839 #ifdef CONFIG_IPW2200_PROMISCUOUS
7840 #define libipw_is_probe_response(fc) \
7841 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7842 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7843
7844 #define libipw_is_management(fc) \
7845 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7846
7847 #define libipw_is_control(fc) \
7848 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7849
7850 #define libipw_is_data(fc) \
7851 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
7852
7853 #define libipw_is_assoc_request(fc) \
7854 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
7855
7856 #define libipw_is_reassoc_request(fc) \
7857 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
7858
ipw_handle_promiscuous_rx(struct ipw_priv * priv,struct ipw_rx_mem_buffer * rxb,struct libipw_rx_stats * stats)7859 static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
7860 struct ipw_rx_mem_buffer *rxb,
7861 struct libipw_rx_stats *stats)
7862 {
7863 struct net_device *dev = priv->prom_net_dev;
7864 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7865 struct ipw_rx_frame *frame = &pkt->u.frame;
7866 struct ipw_rt_hdr *ipw_rt;
7867
7868 /* First cache any information we need before we overwrite
7869 * the information provided in the skb from the hardware */
7870 struct ieee80211_hdr *hdr;
7871 u16 channel = frame->received_channel;
7872 u8 phy_flags = frame->antennaAndPhy;
7873 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
7874 s8 noise = (s8) le16_to_cpu(frame->noise);
7875 u8 rate = frame->rate;
7876 unsigned short len = le16_to_cpu(pkt->u.frame.length);
7877 struct sk_buff *skb;
7878 int hdr_only = 0;
7879 u16 filter = priv->prom_priv->filter;
7880
7881 /* If the filter is set to not include Rx frames then return */
7882 if (filter & IPW_PROM_NO_RX)
7883 return;
7884
7885 /* We received data from the HW, so stop the watchdog */
7886 netif_trans_update(dev);
7887
7888 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
7889 dev->stats.rx_errors++;
7890 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7891 return;
7892 }
7893
7894 /* We only process data packets if the interface is open */
7895 if (unlikely(!netif_running(dev))) {
7896 dev->stats.rx_dropped++;
7897 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7898 return;
7899 }
7900
7901 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7902 * that now */
7903 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7904 /* FIXME: Should alloc bigger skb instead */
7905 dev->stats.rx_dropped++;
7906 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7907 return;
7908 }
7909
7910 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
7911 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
7912 if (filter & IPW_PROM_NO_MGMT)
7913 return;
7914 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
7915 hdr_only = 1;
7916 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
7917 if (filter & IPW_PROM_NO_CTL)
7918 return;
7919 if (filter & IPW_PROM_CTL_HEADER_ONLY)
7920 hdr_only = 1;
7921 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
7922 if (filter & IPW_PROM_NO_DATA)
7923 return;
7924 if (filter & IPW_PROM_DATA_HEADER_ONLY)
7925 hdr_only = 1;
7926 }
7927
7928 /* Copy the SKB since this is for the promiscuous side */
7929 skb = skb_copy(rxb->skb, GFP_ATOMIC);
7930 if (skb == NULL) {
7931 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
7932 return;
7933 }
7934
7935 /* copy the frame data to write after where the radiotap header goes */
7936 ipw_rt = (void *)skb->data;
7937
7938 if (hdr_only)
7939 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
7940
7941 memcpy(ipw_rt->payload, hdr, len);
7942
7943 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7944 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7945 ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*ipw_rt)); /* total header+data */
7946
7947 /* Set the size of the skb to the size of the frame */
7948 skb_put(skb, sizeof(*ipw_rt) + len);
7949
7950 /* Big bitfield of all the fields we provide in radiotap */
7951 ipw_rt->rt_hdr.it_present = cpu_to_le32(
7952 (1 << IEEE80211_RADIOTAP_TSFT) |
7953 (1 << IEEE80211_RADIOTAP_FLAGS) |
7954 (1 << IEEE80211_RADIOTAP_RATE) |
7955 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7956 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7957 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
7958 (1 << IEEE80211_RADIOTAP_ANTENNA));
7959
7960 /* Zero the flags, we'll add to them as we go */
7961 ipw_rt->rt_flags = 0;
7962 ipw_rt->rt_tsf = (u64)(frame->parent_tsf[3] << 24 |
7963 frame->parent_tsf[2] << 16 |
7964 frame->parent_tsf[1] << 8 |
7965 frame->parent_tsf[0]);
7966
7967 /* Convert to DBM */
7968 ipw_rt->rt_dbmsignal = signal;
7969 ipw_rt->rt_dbmnoise = noise;
7970
7971 /* Convert the channel data and set the flags */
7972 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
7973 if (channel > 14) { /* 802.11a */
7974 ipw_rt->rt_chbitmask =
7975 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7976 } else if (phy_flags & (1 << 5)) { /* 802.11b */
7977 ipw_rt->rt_chbitmask =
7978 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7979 } else { /* 802.11g */
7980 ipw_rt->rt_chbitmask =
7981 cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7982 }
7983
7984 /* set the rate in multiples of 500k/s */
7985 switch (rate) {
7986 case IPW_TX_RATE_1MB:
7987 ipw_rt->rt_rate = 2;
7988 break;
7989 case IPW_TX_RATE_2MB:
7990 ipw_rt->rt_rate = 4;
7991 break;
7992 case IPW_TX_RATE_5MB:
7993 ipw_rt->rt_rate = 10;
7994 break;
7995 case IPW_TX_RATE_6MB:
7996 ipw_rt->rt_rate = 12;
7997 break;
7998 case IPW_TX_RATE_9MB:
7999 ipw_rt->rt_rate = 18;
8000 break;
8001 case IPW_TX_RATE_11MB:
8002 ipw_rt->rt_rate = 22;
8003 break;
8004 case IPW_TX_RATE_12MB:
8005 ipw_rt->rt_rate = 24;
8006 break;
8007 case IPW_TX_RATE_18MB:
8008 ipw_rt->rt_rate = 36;
8009 break;
8010 case IPW_TX_RATE_24MB:
8011 ipw_rt->rt_rate = 48;
8012 break;
8013 case IPW_TX_RATE_36MB:
8014 ipw_rt->rt_rate = 72;
8015 break;
8016 case IPW_TX_RATE_48MB:
8017 ipw_rt->rt_rate = 96;
8018 break;
8019 case IPW_TX_RATE_54MB:
8020 ipw_rt->rt_rate = 108;
8021 break;
8022 default:
8023 ipw_rt->rt_rate = 0;
8024 break;
8025 }
8026
8027 /* antenna number */
8028 ipw_rt->rt_antenna = (phy_flags & 3);
8029
8030 /* set the preamble flag if we have it */
8031 if (phy_flags & (1 << 6))
8032 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
8033
8034 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
8035
8036 if (!libipw_rx(priv->prom_priv->ieee, skb, stats)) {
8037 dev->stats.rx_errors++;
8038 dev_kfree_skb_any(skb);
8039 }
8040 }
8041 #endif
8042
is_network_packet(struct ipw_priv * priv,struct libipw_hdr_4addr * header)8043 static int is_network_packet(struct ipw_priv *priv,
8044 struct libipw_hdr_4addr *header)
8045 {
8046 /* Filter incoming packets to determine if they are targeted toward
8047 * this network, discarding packets coming from ourselves */
8048 switch (priv->ieee->iw_mode) {
8049 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
8050 /* packets from our adapter are dropped (echo) */
8051 if (ether_addr_equal(header->addr2, priv->net_dev->dev_addr))
8052 return 0;
8053
8054 /* {broad,multi}cast packets to our BSSID go through */
8055 if (is_multicast_ether_addr(header->addr1))
8056 return ether_addr_equal(header->addr3, priv->bssid);
8057
8058 /* packets to our adapter go through */
8059 return ether_addr_equal(header->addr1,
8060 priv->net_dev->dev_addr);
8061
8062 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
8063 /* packets from our adapter are dropped (echo) */
8064 if (ether_addr_equal(header->addr3, priv->net_dev->dev_addr))
8065 return 0;
8066
8067 /* {broad,multi}cast packets to our BSS go through */
8068 if (is_multicast_ether_addr(header->addr1))
8069 return ether_addr_equal(header->addr2, priv->bssid);
8070
8071 /* packets to our adapter go through */
8072 return ether_addr_equal(header->addr1,
8073 priv->net_dev->dev_addr);
8074 }
8075
8076 return 1;
8077 }
8078
8079 #define IPW_PACKET_RETRY_TIME HZ
8080
is_duplicate_packet(struct ipw_priv * priv,struct libipw_hdr_4addr * header)8081 static int is_duplicate_packet(struct ipw_priv *priv,
8082 struct libipw_hdr_4addr *header)
8083 {
8084 u16 sc = le16_to_cpu(header->seq_ctl);
8085 u16 seq = WLAN_GET_SEQ_SEQ(sc);
8086 u16 frag = WLAN_GET_SEQ_FRAG(sc);
8087 u16 *last_seq, *last_frag;
8088 unsigned long *last_time;
8089
8090 switch (priv->ieee->iw_mode) {
8091 case IW_MODE_ADHOC:
8092 {
8093 struct list_head *p;
8094 struct ipw_ibss_seq *entry = NULL;
8095 u8 *mac = header->addr2;
8096 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8097
8098 list_for_each(p, &priv->ibss_mac_hash[index]) {
8099 entry =
8100 list_entry(p, struct ipw_ibss_seq, list);
8101 if (ether_addr_equal(entry->mac, mac))
8102 break;
8103 }
8104 if (p == &priv->ibss_mac_hash[index]) {
8105 entry = kmalloc_obj(*entry, GFP_ATOMIC);
8106 if (!entry) {
8107 IPW_ERROR
8108 ("Cannot malloc new mac entry\n");
8109 return 0;
8110 }
8111 memcpy(entry->mac, mac, ETH_ALEN);
8112 entry->seq_num = seq;
8113 entry->frag_num = frag;
8114 entry->packet_time = jiffies;
8115 list_add(&entry->list,
8116 &priv->ibss_mac_hash[index]);
8117 return 0;
8118 }
8119 last_seq = &entry->seq_num;
8120 last_frag = &entry->frag_num;
8121 last_time = &entry->packet_time;
8122 break;
8123 }
8124 case IW_MODE_INFRA:
8125 last_seq = &priv->last_seq_num;
8126 last_frag = &priv->last_frag_num;
8127 last_time = &priv->last_packet_time;
8128 break;
8129 default:
8130 return 0;
8131 }
8132 if ((*last_seq == seq) &&
8133 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8134 if (*last_frag == frag)
8135 goto drop;
8136 if (*last_frag + 1 != frag)
8137 /* out-of-order fragment */
8138 goto drop;
8139 } else
8140 *last_seq = seq;
8141
8142 *last_frag = frag;
8143 *last_time = jiffies;
8144 return 0;
8145
8146 drop:
8147 /* Comment this line now since we observed the card receives
8148 * duplicate packets but the FCTL_RETRY bit is not set in the
8149 * IBSS mode with fragmentation enabled.
8150 BUG_ON(!(le16_to_cpu(header->frame_control) & IEEE80211_FCTL_RETRY)); */
8151 return 1;
8152 }
8153
ipw_handle_mgmt_packet(struct ipw_priv * priv,struct ipw_rx_mem_buffer * rxb,struct libipw_rx_stats * stats)8154 static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8155 struct ipw_rx_mem_buffer *rxb,
8156 struct libipw_rx_stats *stats)
8157 {
8158 struct sk_buff *skb = rxb->skb;
8159 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
8160 struct libipw_hdr_4addr *header = (struct libipw_hdr_4addr *)
8161 (skb->data + IPW_RX_FRAME_SIZE);
8162
8163 libipw_rx_mgt(priv->ieee, header, stats);
8164
8165 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8166 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8167 IEEE80211_STYPE_PROBE_RESP) ||
8168 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8169 IEEE80211_STYPE_BEACON))) {
8170 if (ether_addr_equal(header->addr3, priv->bssid))
8171 ipw_add_station(priv, header->addr2);
8172 }
8173
8174 if (priv->config & CFG_NET_STATS) {
8175 IPW_DEBUG_HC("sending stat packet\n");
8176
8177 /* Set the size of the skb to the size of the full
8178 * ipw header and 802.11 frame */
8179 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8180 IPW_RX_FRAME_SIZE);
8181
8182 /* Advance past the ipw packet header to the 802.11 frame */
8183 skb_pull(skb, IPW_RX_FRAME_SIZE);
8184
8185 /* Push the libipw_rx_stats before the 802.11 frame */
8186 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8187
8188 skb->dev = priv->ieee->dev;
8189
8190 /* Point raw at the libipw_stats */
8191 skb_reset_mac_header(skb);
8192
8193 skb->pkt_type = PACKET_OTHERHOST;
8194 skb->protocol = cpu_to_be16(ETH_P_80211_STATS);
8195 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8196 netif_rx(skb);
8197 rxb->skb = NULL;
8198 }
8199 }
8200
8201 /*
8202 * Main entry function for receiving a packet with 80211 headers. This
8203 * should be called when ever the FW has notified us that there is a new
8204 * skb in the receive queue.
8205 */
ipw_rx(struct ipw_priv * priv)8206 static void ipw_rx(struct ipw_priv *priv)
8207 {
8208 struct ipw_rx_mem_buffer *rxb;
8209 struct ipw_rx_packet *pkt;
8210 struct libipw_hdr_4addr *header;
8211 u32 r, i;
8212 u8 network_packet;
8213 u8 fill_rx = 0;
8214
8215 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8216 ipw_read32(priv, IPW_RX_WRITE_INDEX);
8217 i = priv->rxq->read;
8218
8219 if (ipw_rx_queue_space (priv->rxq) > (RX_QUEUE_SIZE / 2))
8220 fill_rx = 1;
8221
8222 while (i != r) {
8223 rxb = priv->rxq->queue[i];
8224 if (unlikely(rxb == NULL)) {
8225 printk(KERN_CRIT "Queue not allocated!\n");
8226 break;
8227 }
8228 priv->rxq->queue[i] = NULL;
8229
8230 dma_sync_single_for_cpu(&priv->pci_dev->dev, rxb->dma_addr,
8231 IPW_RX_BUF_SIZE, DMA_FROM_DEVICE);
8232
8233 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8234 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8235 pkt->header.message_type,
8236 pkt->header.rx_seq_num, pkt->header.control_bits);
8237
8238 switch (pkt->header.message_type) {
8239 case RX_FRAME_TYPE: /* 802.11 frame */ {
8240 struct libipw_rx_stats stats = {
8241 .rssi = pkt->u.frame.rssi_dbm -
8242 IPW_RSSI_TO_DBM,
8243 .signal =
8244 pkt->u.frame.rssi_dbm -
8245 IPW_RSSI_TO_DBM + 0x100,
8246 .noise =
8247 le16_to_cpu(pkt->u.frame.noise),
8248 .rate = pkt->u.frame.rate,
8249 .mac_time = jiffies,
8250 .received_channel =
8251 pkt->u.frame.received_channel,
8252 .freq =
8253 (pkt->u.frame.
8254 control & (1 << 0)) ?
8255 LIBIPW_24GHZ_BAND :
8256 LIBIPW_52GHZ_BAND,
8257 .len = le16_to_cpu(pkt->u.frame.length),
8258 };
8259
8260 if (stats.rssi != 0)
8261 stats.mask |= LIBIPW_STATMASK_RSSI;
8262 if (stats.signal != 0)
8263 stats.mask |= LIBIPW_STATMASK_SIGNAL;
8264 if (stats.noise != 0)
8265 stats.mask |= LIBIPW_STATMASK_NOISE;
8266 if (stats.rate != 0)
8267 stats.mask |= LIBIPW_STATMASK_RATE;
8268
8269 priv->rx_packets++;
8270
8271 #ifdef CONFIG_IPW2200_PROMISCUOUS
8272 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8273 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8274 #endif
8275
8276 #ifdef CONFIG_IPW2200_MONITOR
8277 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
8278 #ifdef CONFIG_IPW2200_RADIOTAP
8279
8280 ipw_handle_data_packet_monitor(priv,
8281 rxb,
8282 &stats);
8283 #else
8284 ipw_handle_data_packet(priv, rxb,
8285 &stats);
8286 #endif
8287 break;
8288 }
8289 #endif
8290
8291 header =
8292 (struct libipw_hdr_4addr *)(rxb->skb->
8293 data +
8294 IPW_RX_FRAME_SIZE);
8295 /* TODO: Check Ad-Hoc dest/source and make sure
8296 * that we are actually parsing these packets
8297 * correctly -- we should probably use the
8298 * frame control of the packet and disregard
8299 * the current iw_mode */
8300
8301 network_packet =
8302 is_network_packet(priv, header);
8303 if (network_packet && priv->assoc_network) {
8304 priv->assoc_network->stats.rssi =
8305 stats.rssi;
8306 priv->exp_avg_rssi =
8307 exponential_average(priv->exp_avg_rssi,
8308 stats.rssi, DEPTH_RSSI);
8309 }
8310
8311 IPW_DEBUG_RX("Frame: len=%u\n",
8312 le16_to_cpu(pkt->u.frame.length));
8313
8314 if (le16_to_cpu(pkt->u.frame.length) <
8315 libipw_get_hdrlen(le16_to_cpu(
8316 header->frame_ctl))) {
8317 IPW_DEBUG_DROP
8318 ("Received packet is too small. "
8319 "Dropping.\n");
8320 priv->net_dev->stats.rx_errors++;
8321 priv->wstats.discard.misc++;
8322 break;
8323 }
8324
8325 if (unlikely(le16_to_cpu(pkt->u.frame.length) >
8326 IPW_RX_BUF_SIZE -
8327 IPW_RX_FRAME_SIZE)) {
8328 IPW_DEBUG_DROP("Received oversized packet. Dropping.\n");
8329 priv->net_dev->stats.rx_errors++;
8330 priv->wstats.discard.misc++;
8331 break;
8332 }
8333
8334 switch (WLAN_FC_GET_TYPE
8335 (le16_to_cpu(header->frame_ctl))) {
8336
8337 case IEEE80211_FTYPE_MGMT:
8338 ipw_handle_mgmt_packet(priv, rxb,
8339 &stats);
8340 break;
8341
8342 case IEEE80211_FTYPE_CTL:
8343 break;
8344
8345 case IEEE80211_FTYPE_DATA:
8346 if (unlikely(!network_packet ||
8347 is_duplicate_packet(priv,
8348 header)))
8349 {
8350 IPW_DEBUG_DROP("Dropping: "
8351 "%pM, "
8352 "%pM, "
8353 "%pM\n",
8354 header->addr1,
8355 header->addr2,
8356 header->addr3);
8357 break;
8358 }
8359
8360 ipw_handle_data_packet(priv, rxb,
8361 &stats);
8362
8363 break;
8364 }
8365 break;
8366 }
8367
8368 case RX_HOST_NOTIFICATION_TYPE:{
8369 IPW_DEBUG_RX
8370 ("Notification: subtype=%02X flags=%02X size=%d\n",
8371 pkt->u.notification.subtype,
8372 pkt->u.notification.flags,
8373 le16_to_cpu(pkt->u.notification.size));
8374 ipw_rx_notification(priv, &pkt->u.notification);
8375 break;
8376 }
8377
8378 default:
8379 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8380 pkt->header.message_type);
8381 break;
8382 }
8383
8384 /* For now we just don't re-use anything. We can tweak this
8385 * later to try and re-use notification packets and SKBs that
8386 * fail to Rx correctly */
8387 if (rxb->skb != NULL) {
8388 dev_kfree_skb_any(rxb->skb);
8389 rxb->skb = NULL;
8390 }
8391
8392 dma_unmap_single(&priv->pci_dev->dev, rxb->dma_addr,
8393 IPW_RX_BUF_SIZE, DMA_FROM_DEVICE);
8394 list_add_tail(&rxb->list, &priv->rxq->rx_used);
8395
8396 i = (i + 1) % RX_QUEUE_SIZE;
8397
8398 /* If there are a lot of unsued frames, restock the Rx queue
8399 * so the ucode won't assert */
8400 if (fill_rx) {
8401 priv->rxq->read = i;
8402 ipw_rx_queue_replenish(priv);
8403 }
8404 }
8405
8406 /* Backtrack one entry */
8407 priv->rxq->read = i;
8408 ipw_rx_queue_restock(priv);
8409 }
8410
8411 #define DEFAULT_RTS_THRESHOLD 2304U
8412 #define MIN_RTS_THRESHOLD 1U
8413 #define MAX_RTS_THRESHOLD 2304U
8414 #define DEFAULT_BEACON_INTERVAL 100U
8415 #define DEFAULT_SHORT_RETRY_LIMIT 7U
8416 #define DEFAULT_LONG_RETRY_LIMIT 4U
8417
8418 /*
8419 * ipw_sw_reset
8420 * @option: options to control different reset behaviour
8421 * 0 = reset everything except the 'disable' module_param
8422 * 1 = reset everything and print out driver info (for probe only)
8423 * 2 = reset everything
8424 */
ipw_sw_reset(struct ipw_priv * priv,int option)8425 static int ipw_sw_reset(struct ipw_priv *priv, int option)
8426 {
8427 int band, modulation;
8428 int old_mode = priv->ieee->iw_mode;
8429
8430 /* Initialize module parameter values here */
8431 priv->config = 0;
8432
8433 /* We default to disabling the LED code as right now it causes
8434 * too many systems to lock up... */
8435 if (!led_support)
8436 priv->config |= CFG_NO_LED;
8437
8438 if (associate)
8439 priv->config |= CFG_ASSOCIATE;
8440 else
8441 IPW_DEBUG_INFO("Auto associate disabled.\n");
8442
8443 if (auto_create)
8444 priv->config |= CFG_ADHOC_CREATE;
8445 else
8446 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8447
8448 priv->config &= ~CFG_STATIC_ESSID;
8449 priv->essid_len = 0;
8450 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8451
8452 if (disable && option) {
8453 priv->status |= STATUS_RF_KILL_SW;
8454 IPW_DEBUG_INFO("Radio disabled.\n");
8455 }
8456
8457 if (default_channel != 0) {
8458 priv->config |= CFG_STATIC_CHANNEL;
8459 priv->channel = default_channel;
8460 IPW_DEBUG_INFO("Bind to static channel %d\n", default_channel);
8461 /* TODO: Validate that provided channel is in range */
8462 }
8463 #ifdef CONFIG_IPW2200_QOS
8464 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8465 burst_duration_CCK, burst_duration_OFDM);
8466 #endif /* CONFIG_IPW2200_QOS */
8467
8468 switch (network_mode) {
8469 case 1:
8470 priv->ieee->iw_mode = IW_MODE_ADHOC;
8471 priv->net_dev->type = ARPHRD_ETHER;
8472
8473 break;
8474 #ifdef CONFIG_IPW2200_MONITOR
8475 case 2:
8476 priv->ieee->iw_mode = IW_MODE_MONITOR;
8477 #ifdef CONFIG_IPW2200_RADIOTAP
8478 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8479 #else
8480 priv->net_dev->type = ARPHRD_IEEE80211;
8481 #endif
8482 break;
8483 #endif
8484 default:
8485 case 0:
8486 priv->net_dev->type = ARPHRD_ETHER;
8487 priv->ieee->iw_mode = IW_MODE_INFRA;
8488 break;
8489 }
8490
8491 if (hwcrypto) {
8492 priv->ieee->host_encrypt = 0;
8493 priv->ieee->host_encrypt_msdu = 0;
8494 priv->ieee->host_decrypt = 0;
8495 priv->ieee->host_mc_decrypt = 0;
8496 }
8497 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
8498
8499 /* IPW2200/2915 is abled to do hardware fragmentation. */
8500 priv->ieee->host_open_frag = 0;
8501
8502 if ((priv->pci_dev->device == 0x4223) ||
8503 (priv->pci_dev->device == 0x4224)) {
8504 if (option == 1)
8505 printk(KERN_INFO DRV_NAME
8506 ": Detected Intel PRO/Wireless 2915ABG Network "
8507 "Connection\n");
8508 priv->ieee->abg_true = 1;
8509 band = LIBIPW_52GHZ_BAND | LIBIPW_24GHZ_BAND;
8510 modulation = LIBIPW_OFDM_MODULATION |
8511 LIBIPW_CCK_MODULATION;
8512 priv->adapter = IPW_2915ABG;
8513 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
8514 } else {
8515 if (option == 1)
8516 printk(KERN_INFO DRV_NAME
8517 ": Detected Intel PRO/Wireless 2200BG Network "
8518 "Connection\n");
8519
8520 priv->ieee->abg_true = 0;
8521 band = LIBIPW_24GHZ_BAND;
8522 modulation = LIBIPW_OFDM_MODULATION |
8523 LIBIPW_CCK_MODULATION;
8524 priv->adapter = IPW_2200BG;
8525 priv->ieee->mode = IEEE_G | IEEE_B;
8526 }
8527
8528 priv->ieee->freq_band = band;
8529 priv->ieee->modulation = modulation;
8530
8531 priv->rates_mask = LIBIPW_DEFAULT_RATES_MASK;
8532
8533 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8534 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8535
8536 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8537 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8538 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
8539
8540 /* If power management is turned on, default to AC mode */
8541 priv->power_mode = IPW_POWER_AC;
8542 priv->tx_power = IPW_TX_POWER_DEFAULT;
8543
8544 return old_mode == priv->ieee->iw_mode;
8545 }
8546
8547 /*
8548 * This file defines the Wireless Extension handlers. It does not
8549 * define any methods of hardware manipulation and relies on the
8550 * functions defined in ipw_main to provide the HW interaction.
8551 *
8552 * The exception to this is the use of the ipw_get_ordinal()
8553 * function used to poll the hardware vs. making unnecessary calls.
8554 *
8555 */
8556
ipw_set_channel(struct ipw_priv * priv,u8 channel)8557 static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8558 {
8559 if (channel == 0) {
8560 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8561 priv->config &= ~CFG_STATIC_CHANNEL;
8562 IPW_DEBUG_ASSOC("Attempting to associate with new "
8563 "parameters.\n");
8564 ipw_associate(priv);
8565 return 0;
8566 }
8567
8568 priv->config |= CFG_STATIC_CHANNEL;
8569
8570 if (priv->channel == channel) {
8571 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8572 channel);
8573 return 0;
8574 }
8575
8576 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8577 priv->channel = channel;
8578
8579 #ifdef CONFIG_IPW2200_MONITOR
8580 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
8581 int i;
8582 if (priv->status & STATUS_SCANNING) {
8583 IPW_DEBUG_SCAN("Scan abort triggered due to "
8584 "channel change.\n");
8585 ipw_abort_scan(priv);
8586 }
8587
8588 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8589 udelay(10);
8590
8591 if (priv->status & STATUS_SCANNING)
8592 IPW_DEBUG_SCAN("Still scanning...\n");
8593 else
8594 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8595 1000 - i);
8596
8597 return 0;
8598 }
8599 #endif /* CONFIG_IPW2200_MONITOR */
8600
8601 /* Network configuration changed -- force [re]association */
8602 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8603 if (!ipw_disassociate(priv))
8604 ipw_associate(priv);
8605
8606 return 0;
8607 }
8608
ipw_wx_set_freq(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)8609 static int ipw_wx_set_freq(struct net_device *dev,
8610 struct iw_request_info *info,
8611 union iwreq_data *wrqu, char *extra)
8612 {
8613 struct ipw_priv *priv = libipw_priv(dev);
8614 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
8615 struct iw_freq *fwrq = &wrqu->freq;
8616 int ret = 0, i;
8617 u8 channel, flags;
8618 int band;
8619
8620 if (fwrq->m == 0) {
8621 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
8622 mutex_lock(&priv->mutex);
8623 ret = ipw_set_channel(priv, 0);
8624 mutex_unlock(&priv->mutex);
8625 return ret;
8626 }
8627 /* if setting by freq convert to channel */
8628 if (fwrq->e == 1) {
8629 channel = libipw_freq_to_channel(priv->ieee, fwrq->m);
8630 if (channel == 0)
8631 return -EINVAL;
8632 } else
8633 channel = fwrq->m;
8634
8635 if (!(band = libipw_is_valid_channel(priv->ieee, channel)))
8636 return -EINVAL;
8637
8638 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
8639 i = libipw_channel_to_index(priv->ieee, channel);
8640 if (i == -1)
8641 return -EINVAL;
8642
8643 flags = (band == LIBIPW_24GHZ_BAND) ?
8644 geo->bg[i].flags : geo->a[i].flags;
8645 if (flags & LIBIPW_CH_PASSIVE_ONLY) {
8646 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8647 return -EINVAL;
8648 }
8649 }
8650
8651 IPW_DEBUG_WX("SET Freq/Channel -> %d\n", fwrq->m);
8652 mutex_lock(&priv->mutex);
8653 ret = ipw_set_channel(priv, channel);
8654 mutex_unlock(&priv->mutex);
8655 return ret;
8656 }
8657
ipw_wx_get_freq(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)8658 static int ipw_wx_get_freq(struct net_device *dev,
8659 struct iw_request_info *info,
8660 union iwreq_data *wrqu, char *extra)
8661 {
8662 struct ipw_priv *priv = libipw_priv(dev);
8663
8664 wrqu->freq.e = 0;
8665
8666 /* If we are associated, trying to associate, or have a statically
8667 * configured CHANNEL then return that; otherwise return ANY */
8668 mutex_lock(&priv->mutex);
8669 if (priv->config & CFG_STATIC_CHANNEL ||
8670 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) {
8671 int i;
8672
8673 i = libipw_channel_to_index(priv->ieee, priv->channel);
8674 BUG_ON(i == -1);
8675 wrqu->freq.e = 1;
8676
8677 switch (libipw_is_valid_channel(priv->ieee, priv->channel)) {
8678 case LIBIPW_52GHZ_BAND:
8679 wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000;
8680 break;
8681
8682 case LIBIPW_24GHZ_BAND:
8683 wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000;
8684 break;
8685
8686 default:
8687 BUG();
8688 }
8689 } else
8690 wrqu->freq.m = 0;
8691
8692 mutex_unlock(&priv->mutex);
8693 IPW_DEBUG_WX("GET Freq/Channel -> %d\n", priv->channel);
8694 return 0;
8695 }
8696
ipw_wx_set_mode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)8697 static int ipw_wx_set_mode(struct net_device *dev,
8698 struct iw_request_info *info,
8699 union iwreq_data *wrqu, char *extra)
8700 {
8701 struct ipw_priv *priv = libipw_priv(dev);
8702 int err = 0;
8703
8704 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8705
8706 switch (wrqu->mode) {
8707 #ifdef CONFIG_IPW2200_MONITOR
8708 case IW_MODE_MONITOR:
8709 #endif
8710 case IW_MODE_ADHOC:
8711 case IW_MODE_INFRA:
8712 break;
8713 case IW_MODE_AUTO:
8714 wrqu->mode = IW_MODE_INFRA;
8715 break;
8716 default:
8717 return -EINVAL;
8718 }
8719 if (wrqu->mode == priv->ieee->iw_mode)
8720 return 0;
8721
8722 mutex_lock(&priv->mutex);
8723
8724 ipw_sw_reset(priv, 0);
8725
8726 #ifdef CONFIG_IPW2200_MONITOR
8727 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
8728 priv->net_dev->type = ARPHRD_ETHER;
8729
8730 if (wrqu->mode == IW_MODE_MONITOR)
8731 #ifdef CONFIG_IPW2200_RADIOTAP
8732 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8733 #else
8734 priv->net_dev->type = ARPHRD_IEEE80211;
8735 #endif
8736 #endif /* CONFIG_IPW2200_MONITOR */
8737
8738 /* Free the existing firmware and reset the fw_loaded
8739 * flag so ipw_load() will bring in the new firmware */
8740 free_firmware();
8741
8742 priv->ieee->iw_mode = wrqu->mode;
8743
8744 schedule_work(&priv->adapter_restart);
8745 mutex_unlock(&priv->mutex);
8746 return err;
8747 }
8748
ipw_wx_get_mode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)8749 static int ipw_wx_get_mode(struct net_device *dev,
8750 struct iw_request_info *info,
8751 union iwreq_data *wrqu, char *extra)
8752 {
8753 struct ipw_priv *priv = libipw_priv(dev);
8754 mutex_lock(&priv->mutex);
8755 wrqu->mode = priv->ieee->iw_mode;
8756 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
8757 mutex_unlock(&priv->mutex);
8758 return 0;
8759 }
8760
8761 /* Values are in microsecond */
8762 static const s32 timeout_duration[] = {
8763 350000,
8764 250000,
8765 75000,
8766 37000,
8767 25000,
8768 };
8769
8770 static const s32 period_duration[] = {
8771 400000,
8772 700000,
8773 1000000,
8774 1000000,
8775 1000000
8776 };
8777
ipw_wx_get_range(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)8778 static int ipw_wx_get_range(struct net_device *dev,
8779 struct iw_request_info *info,
8780 union iwreq_data *wrqu, char *extra)
8781 {
8782 struct ipw_priv *priv = libipw_priv(dev);
8783 struct iw_range *range = (struct iw_range *)extra;
8784 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
8785 int i = 0, j;
8786
8787 wrqu->data.length = sizeof(*range);
8788 memset(range, 0, sizeof(*range));
8789
8790 /* 54Mbs == ~27 Mb/s real (802.11g) */
8791 range->throughput = 27 * 1000 * 1000;
8792
8793 range->max_qual.qual = 100;
8794 /* TODO: Find real max RSSI and stick here */
8795 range->max_qual.level = 0;
8796 range->max_qual.noise = 0;
8797 range->max_qual.updated = 7; /* Updated all three */
8798
8799 range->avg_qual.qual = 70;
8800 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
8801 range->avg_qual.level = 0; /* FIXME to real average level */
8802 range->avg_qual.noise = 0;
8803 range->avg_qual.updated = 7; /* Updated all three */
8804 mutex_lock(&priv->mutex);
8805 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
8806
8807 for (i = 0; i < range->num_bitrates; i++)
8808 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
8809 500000;
8810
8811 range->max_rts = DEFAULT_RTS_THRESHOLD;
8812 range->min_frag = MIN_FRAG_THRESHOLD;
8813 range->max_frag = MAX_FRAG_THRESHOLD;
8814
8815 range->encoding_size[0] = 5;
8816 range->encoding_size[1] = 13;
8817 range->num_encoding_sizes = 2;
8818 range->max_encoding_tokens = WEP_KEYS;
8819
8820 /* Set the Wireless Extension versions */
8821 range->we_version_compiled = WIRELESS_EXT;
8822 range->we_version_source = 18;
8823
8824 i = 0;
8825 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
8826 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8827 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8828 (geo->bg[j].flags & LIBIPW_CH_PASSIVE_ONLY))
8829 continue;
8830
8831 range->freq[i].i = geo->bg[j].channel;
8832 range->freq[i].m = geo->bg[j].freq * 100000;
8833 range->freq[i].e = 1;
8834 i++;
8835 }
8836 }
8837
8838 if (priv->ieee->mode & IEEE_A) {
8839 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8840 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8841 (geo->a[j].flags & LIBIPW_CH_PASSIVE_ONLY))
8842 continue;
8843
8844 range->freq[i].i = geo->a[j].channel;
8845 range->freq[i].m = geo->a[j].freq * 100000;
8846 range->freq[i].e = 1;
8847 i++;
8848 }
8849 }
8850
8851 range->num_channels = i;
8852 range->num_frequency = i;
8853
8854 mutex_unlock(&priv->mutex);
8855
8856 /* Event capability (kernel + driver) */
8857 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8858 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
8859 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
8860 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
8861 range->event_capa[1] = IW_EVENT_CAPA_K_1;
8862
8863 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8864 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8865
8866 range->scan_capa = IW_SCAN_CAPA_ESSID | IW_SCAN_CAPA_TYPE;
8867
8868 IPW_DEBUG_WX("GET Range\n");
8869 return 0;
8870 }
8871
ipw_wx_set_wap(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)8872 static int ipw_wx_set_wap(struct net_device *dev,
8873 struct iw_request_info *info,
8874 union iwreq_data *wrqu, char *extra)
8875 {
8876 struct ipw_priv *priv = libipw_priv(dev);
8877
8878 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
8879 return -EINVAL;
8880 mutex_lock(&priv->mutex);
8881 if (is_broadcast_ether_addr(wrqu->ap_addr.sa_data) ||
8882 is_zero_ether_addr(wrqu->ap_addr.sa_data)) {
8883 /* we disable mandatory BSSID association */
8884 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8885 priv->config &= ~CFG_STATIC_BSSID;
8886 IPW_DEBUG_ASSOC("Attempting to associate with new "
8887 "parameters.\n");
8888 ipw_associate(priv);
8889 mutex_unlock(&priv->mutex);
8890 return 0;
8891 }
8892
8893 priv->config |= CFG_STATIC_BSSID;
8894 if (ether_addr_equal(priv->bssid, wrqu->ap_addr.sa_data)) {
8895 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
8896 mutex_unlock(&priv->mutex);
8897 return 0;
8898 }
8899
8900 IPW_DEBUG_WX("Setting mandatory BSSID to %pM\n",
8901 wrqu->ap_addr.sa_data);
8902
8903 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8904
8905 /* Network configuration changed -- force [re]association */
8906 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8907 if (!ipw_disassociate(priv))
8908 ipw_associate(priv);
8909
8910 mutex_unlock(&priv->mutex);
8911 return 0;
8912 }
8913
ipw_wx_get_wap(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)8914 static int ipw_wx_get_wap(struct net_device *dev,
8915 struct iw_request_info *info,
8916 union iwreq_data *wrqu, char *extra)
8917 {
8918 struct ipw_priv *priv = libipw_priv(dev);
8919
8920 /* If we are associated, trying to associate, or have a statically
8921 * configured BSSID then return that; otherwise return ANY */
8922 mutex_lock(&priv->mutex);
8923 if (priv->config & CFG_STATIC_BSSID ||
8924 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8925 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
8926 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
8927 } else
8928 eth_zero_addr(wrqu->ap_addr.sa_data);
8929
8930 IPW_DEBUG_WX("Getting WAP BSSID: %pM\n",
8931 wrqu->ap_addr.sa_data);
8932 mutex_unlock(&priv->mutex);
8933 return 0;
8934 }
8935
ipw_wx_set_essid(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)8936 static int ipw_wx_set_essid(struct net_device *dev,
8937 struct iw_request_info *info,
8938 union iwreq_data *wrqu, char *extra)
8939 {
8940 struct ipw_priv *priv = libipw_priv(dev);
8941 int length;
8942
8943 mutex_lock(&priv->mutex);
8944
8945 if (!wrqu->essid.flags)
8946 {
8947 IPW_DEBUG_WX("Setting ESSID to ANY\n");
8948 ipw_disassociate(priv);
8949 priv->config &= ~CFG_STATIC_ESSID;
8950 ipw_associate(priv);
8951 mutex_unlock(&priv->mutex);
8952 return 0;
8953 }
8954
8955 length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE);
8956
8957 priv->config |= CFG_STATIC_ESSID;
8958
8959 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)
8960 && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
8961 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
8962 mutex_unlock(&priv->mutex);
8963 return 0;
8964 }
8965
8966 IPW_DEBUG_WX("Setting ESSID: '%*pE' (%d)\n", length, extra, length);
8967
8968 priv->essid_len = length;
8969 memcpy(priv->essid, extra, priv->essid_len);
8970
8971 /* Network configuration changed -- force [re]association */
8972 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8973 if (!ipw_disassociate(priv))
8974 ipw_associate(priv);
8975
8976 mutex_unlock(&priv->mutex);
8977 return 0;
8978 }
8979
ipw_wx_get_essid(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)8980 static int ipw_wx_get_essid(struct net_device *dev,
8981 struct iw_request_info *info,
8982 union iwreq_data *wrqu, char *extra)
8983 {
8984 struct ipw_priv *priv = libipw_priv(dev);
8985
8986 /* If we are associated, trying to associate, or have a statically
8987 * configured ESSID then return that; otherwise return ANY */
8988 mutex_lock(&priv->mutex);
8989 if (priv->config & CFG_STATIC_ESSID ||
8990 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8991 IPW_DEBUG_WX("Getting essid: '%*pE'\n",
8992 priv->essid_len, priv->essid);
8993 memcpy(extra, priv->essid, priv->essid_len);
8994 wrqu->essid.length = priv->essid_len;
8995 wrqu->essid.flags = 1; /* active */
8996 } else {
8997 IPW_DEBUG_WX("Getting essid: ANY\n");
8998 wrqu->essid.length = 0;
8999 wrqu->essid.flags = 0; /* active */
9000 }
9001 mutex_unlock(&priv->mutex);
9002 return 0;
9003 }
9004
ipw_wx_set_nick(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9005 static int ipw_wx_set_nick(struct net_device *dev,
9006 struct iw_request_info *info,
9007 union iwreq_data *wrqu, char *extra)
9008 {
9009 struct ipw_priv *priv = libipw_priv(dev);
9010
9011 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
9012 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
9013 return -E2BIG;
9014 mutex_lock(&priv->mutex);
9015 wrqu->data.length = min_t(size_t, wrqu->data.length, sizeof(priv->nick));
9016 memset(priv->nick, 0, sizeof(priv->nick));
9017 memcpy(priv->nick, extra, wrqu->data.length);
9018 IPW_DEBUG_TRACE("<<\n");
9019 mutex_unlock(&priv->mutex);
9020 return 0;
9021
9022 }
9023
ipw_wx_get_nick(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9024 static int ipw_wx_get_nick(struct net_device *dev,
9025 struct iw_request_info *info,
9026 union iwreq_data *wrqu, char *extra)
9027 {
9028 struct ipw_priv *priv = libipw_priv(dev);
9029 IPW_DEBUG_WX("Getting nick\n");
9030 mutex_lock(&priv->mutex);
9031 wrqu->data.length = strlen(priv->nick);
9032 memcpy(extra, priv->nick, wrqu->data.length);
9033 wrqu->data.flags = 1; /* active */
9034 mutex_unlock(&priv->mutex);
9035 return 0;
9036 }
9037
ipw_wx_set_sens(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9038 static int ipw_wx_set_sens(struct net_device *dev,
9039 struct iw_request_info *info,
9040 union iwreq_data *wrqu, char *extra)
9041 {
9042 struct ipw_priv *priv = libipw_priv(dev);
9043 int err = 0;
9044
9045 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
9046 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
9047 mutex_lock(&priv->mutex);
9048
9049 if (wrqu->sens.fixed == 0)
9050 {
9051 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
9052 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
9053 goto out;
9054 }
9055 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
9056 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
9057 err = -EINVAL;
9058 goto out;
9059 }
9060
9061 priv->roaming_threshold = wrqu->sens.value;
9062 priv->disassociate_threshold = 3*wrqu->sens.value;
9063 out:
9064 mutex_unlock(&priv->mutex);
9065 return err;
9066 }
9067
ipw_wx_get_sens(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9068 static int ipw_wx_get_sens(struct net_device *dev,
9069 struct iw_request_info *info,
9070 union iwreq_data *wrqu, char *extra)
9071 {
9072 struct ipw_priv *priv = libipw_priv(dev);
9073 mutex_lock(&priv->mutex);
9074 wrqu->sens.fixed = 1;
9075 wrqu->sens.value = priv->roaming_threshold;
9076 mutex_unlock(&priv->mutex);
9077
9078 IPW_DEBUG_WX("GET roaming threshold -> %s %d\n",
9079 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9080
9081 return 0;
9082 }
9083
ipw_wx_set_rate(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9084 static int ipw_wx_set_rate(struct net_device *dev,
9085 struct iw_request_info *info,
9086 union iwreq_data *wrqu, char *extra)
9087 {
9088 /* TODO: We should use semaphores or locks for access to priv */
9089 struct ipw_priv *priv = libipw_priv(dev);
9090 u32 target_rate = wrqu->bitrate.value;
9091 u32 fixed, mask;
9092
9093 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
9094 /* value = X, fixed = 1 means only rate X */
9095 /* value = X, fixed = 0 means all rates lower equal X */
9096
9097 if (target_rate == -1) {
9098 fixed = 0;
9099 mask = LIBIPW_DEFAULT_RATES_MASK;
9100 /* Now we should reassociate */
9101 goto apply;
9102 }
9103
9104 mask = 0;
9105 fixed = wrqu->bitrate.fixed;
9106
9107 if (target_rate == 1000000 || !fixed)
9108 mask |= LIBIPW_CCK_RATE_1MB_MASK;
9109 if (target_rate == 1000000)
9110 goto apply;
9111
9112 if (target_rate == 2000000 || !fixed)
9113 mask |= LIBIPW_CCK_RATE_2MB_MASK;
9114 if (target_rate == 2000000)
9115 goto apply;
9116
9117 if (target_rate == 5500000 || !fixed)
9118 mask |= LIBIPW_CCK_RATE_5MB_MASK;
9119 if (target_rate == 5500000)
9120 goto apply;
9121
9122 if (target_rate == 6000000 || !fixed)
9123 mask |= LIBIPW_OFDM_RATE_6MB_MASK;
9124 if (target_rate == 6000000)
9125 goto apply;
9126
9127 if (target_rate == 9000000 || !fixed)
9128 mask |= LIBIPW_OFDM_RATE_9MB_MASK;
9129 if (target_rate == 9000000)
9130 goto apply;
9131
9132 if (target_rate == 11000000 || !fixed)
9133 mask |= LIBIPW_CCK_RATE_11MB_MASK;
9134 if (target_rate == 11000000)
9135 goto apply;
9136
9137 if (target_rate == 12000000 || !fixed)
9138 mask |= LIBIPW_OFDM_RATE_12MB_MASK;
9139 if (target_rate == 12000000)
9140 goto apply;
9141
9142 if (target_rate == 18000000 || !fixed)
9143 mask |= LIBIPW_OFDM_RATE_18MB_MASK;
9144 if (target_rate == 18000000)
9145 goto apply;
9146
9147 if (target_rate == 24000000 || !fixed)
9148 mask |= LIBIPW_OFDM_RATE_24MB_MASK;
9149 if (target_rate == 24000000)
9150 goto apply;
9151
9152 if (target_rate == 36000000 || !fixed)
9153 mask |= LIBIPW_OFDM_RATE_36MB_MASK;
9154 if (target_rate == 36000000)
9155 goto apply;
9156
9157 if (target_rate == 48000000 || !fixed)
9158 mask |= LIBIPW_OFDM_RATE_48MB_MASK;
9159 if (target_rate == 48000000)
9160 goto apply;
9161
9162 if (target_rate == 54000000 || !fixed)
9163 mask |= LIBIPW_OFDM_RATE_54MB_MASK;
9164 if (target_rate == 54000000)
9165 goto apply;
9166
9167 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9168 return -EINVAL;
9169
9170 apply:
9171 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9172 mask, fixed ? "fixed" : "sub-rates");
9173 mutex_lock(&priv->mutex);
9174 if (mask == LIBIPW_DEFAULT_RATES_MASK) {
9175 priv->config &= ~CFG_FIXED_RATE;
9176 ipw_set_fixed_rate(priv, priv->ieee->mode);
9177 } else
9178 priv->config |= CFG_FIXED_RATE;
9179
9180 if (priv->rates_mask == mask) {
9181 IPW_DEBUG_WX("Mask set to current mask.\n");
9182 mutex_unlock(&priv->mutex);
9183 return 0;
9184 }
9185
9186 priv->rates_mask = mask;
9187
9188 /* Network configuration changed -- force [re]association */
9189 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9190 if (!ipw_disassociate(priv))
9191 ipw_associate(priv);
9192
9193 mutex_unlock(&priv->mutex);
9194 return 0;
9195 }
9196
ipw_wx_get_rate(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9197 static int ipw_wx_get_rate(struct net_device *dev,
9198 struct iw_request_info *info,
9199 union iwreq_data *wrqu, char *extra)
9200 {
9201 struct ipw_priv *priv = libipw_priv(dev);
9202 mutex_lock(&priv->mutex);
9203 wrqu->bitrate.value = priv->last_rate;
9204 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
9205 mutex_unlock(&priv->mutex);
9206 IPW_DEBUG_WX("GET Rate -> %d\n", wrqu->bitrate.value);
9207 return 0;
9208 }
9209
ipw_wx_set_rts(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9210 static int ipw_wx_set_rts(struct net_device *dev,
9211 struct iw_request_info *info,
9212 union iwreq_data *wrqu, char *extra)
9213 {
9214 struct ipw_priv *priv = libipw_priv(dev);
9215 mutex_lock(&priv->mutex);
9216 if (wrqu->rts.disabled || !wrqu->rts.fixed)
9217 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9218 else {
9219 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
9220 wrqu->rts.value > MAX_RTS_THRESHOLD) {
9221 mutex_unlock(&priv->mutex);
9222 return -EINVAL;
9223 }
9224 priv->rts_threshold = wrqu->rts.value;
9225 }
9226
9227 ipw_send_rts_threshold(priv, priv->rts_threshold);
9228 mutex_unlock(&priv->mutex);
9229 IPW_DEBUG_WX("SET RTS Threshold -> %d\n", priv->rts_threshold);
9230 return 0;
9231 }
9232
ipw_wx_get_rts(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9233 static int ipw_wx_get_rts(struct net_device *dev,
9234 struct iw_request_info *info,
9235 union iwreq_data *wrqu, char *extra)
9236 {
9237 struct ipw_priv *priv = libipw_priv(dev);
9238 mutex_lock(&priv->mutex);
9239 wrqu->rts.value = priv->rts_threshold;
9240 wrqu->rts.fixed = 0; /* no auto select */
9241 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
9242 mutex_unlock(&priv->mutex);
9243 IPW_DEBUG_WX("GET RTS Threshold -> %d\n", wrqu->rts.value);
9244 return 0;
9245 }
9246
ipw_wx_set_txpow(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9247 static int ipw_wx_set_txpow(struct net_device *dev,
9248 struct iw_request_info *info,
9249 union iwreq_data *wrqu, char *extra)
9250 {
9251 struct ipw_priv *priv = libipw_priv(dev);
9252 int err = 0;
9253
9254 mutex_lock(&priv->mutex);
9255 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
9256 err = -EINPROGRESS;
9257 goto out;
9258 }
9259
9260 if (!wrqu->power.fixed)
9261 wrqu->power.value = IPW_TX_POWER_DEFAULT;
9262
9263 if (wrqu->power.flags != IW_TXPOW_DBM) {
9264 err = -EINVAL;
9265 goto out;
9266 }
9267
9268 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
9269 (wrqu->power.value < IPW_TX_POWER_MIN)) {
9270 err = -EINVAL;
9271 goto out;
9272 }
9273
9274 priv->tx_power = wrqu->power.value;
9275 err = ipw_set_tx_power(priv);
9276 out:
9277 mutex_unlock(&priv->mutex);
9278 return err;
9279 }
9280
ipw_wx_get_txpow(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9281 static int ipw_wx_get_txpow(struct net_device *dev,
9282 struct iw_request_info *info,
9283 union iwreq_data *wrqu, char *extra)
9284 {
9285 struct ipw_priv *priv = libipw_priv(dev);
9286 mutex_lock(&priv->mutex);
9287 wrqu->power.value = priv->tx_power;
9288 wrqu->power.fixed = 1;
9289 wrqu->power.flags = IW_TXPOW_DBM;
9290 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
9291 mutex_unlock(&priv->mutex);
9292
9293 IPW_DEBUG_WX("GET TX Power -> %s %d\n",
9294 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9295
9296 return 0;
9297 }
9298
ipw_wx_set_frag(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9299 static int ipw_wx_set_frag(struct net_device *dev,
9300 struct iw_request_info *info,
9301 union iwreq_data *wrqu, char *extra)
9302 {
9303 struct ipw_priv *priv = libipw_priv(dev);
9304 mutex_lock(&priv->mutex);
9305 if (wrqu->frag.disabled || !wrqu->frag.fixed)
9306 priv->ieee->fts = DEFAULT_FTS;
9307 else {
9308 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
9309 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
9310 mutex_unlock(&priv->mutex);
9311 return -EINVAL;
9312 }
9313
9314 priv->ieee->fts = wrqu->frag.value & ~0x1;
9315 }
9316
9317 ipw_send_frag_threshold(priv, wrqu->frag.value);
9318 mutex_unlock(&priv->mutex);
9319 IPW_DEBUG_WX("SET Frag Threshold -> %d\n", wrqu->frag.value);
9320 return 0;
9321 }
9322
ipw_wx_get_frag(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9323 static int ipw_wx_get_frag(struct net_device *dev,
9324 struct iw_request_info *info,
9325 union iwreq_data *wrqu, char *extra)
9326 {
9327 struct ipw_priv *priv = libipw_priv(dev);
9328 mutex_lock(&priv->mutex);
9329 wrqu->frag.value = priv->ieee->fts;
9330 wrqu->frag.fixed = 0; /* no auto select */
9331 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
9332 mutex_unlock(&priv->mutex);
9333 IPW_DEBUG_WX("GET Frag Threshold -> %d\n", wrqu->frag.value);
9334
9335 return 0;
9336 }
9337
ipw_wx_set_retry(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9338 static int ipw_wx_set_retry(struct net_device *dev,
9339 struct iw_request_info *info,
9340 union iwreq_data *wrqu, char *extra)
9341 {
9342 struct ipw_priv *priv = libipw_priv(dev);
9343
9344 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9345 return -EINVAL;
9346
9347 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9348 return 0;
9349
9350 if (wrqu->retry.value < 0 || wrqu->retry.value >= 255)
9351 return -EINVAL;
9352
9353 mutex_lock(&priv->mutex);
9354 if (wrqu->retry.flags & IW_RETRY_SHORT)
9355 priv->short_retry_limit = (u8) wrqu->retry.value;
9356 else if (wrqu->retry.flags & IW_RETRY_LONG)
9357 priv->long_retry_limit = (u8) wrqu->retry.value;
9358 else {
9359 priv->short_retry_limit = (u8) wrqu->retry.value;
9360 priv->long_retry_limit = (u8) wrqu->retry.value;
9361 }
9362
9363 ipw_send_retry_limit(priv, priv->short_retry_limit,
9364 priv->long_retry_limit);
9365 mutex_unlock(&priv->mutex);
9366 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9367 priv->short_retry_limit, priv->long_retry_limit);
9368 return 0;
9369 }
9370
ipw_wx_get_retry(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9371 static int ipw_wx_get_retry(struct net_device *dev,
9372 struct iw_request_info *info,
9373 union iwreq_data *wrqu, char *extra)
9374 {
9375 struct ipw_priv *priv = libipw_priv(dev);
9376
9377 mutex_lock(&priv->mutex);
9378 wrqu->retry.disabled = 0;
9379
9380 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
9381 mutex_unlock(&priv->mutex);
9382 return -EINVAL;
9383 }
9384
9385 if (wrqu->retry.flags & IW_RETRY_LONG) {
9386 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
9387 wrqu->retry.value = priv->long_retry_limit;
9388 } else if (wrqu->retry.flags & IW_RETRY_SHORT) {
9389 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
9390 wrqu->retry.value = priv->short_retry_limit;
9391 } else {
9392 wrqu->retry.flags = IW_RETRY_LIMIT;
9393 wrqu->retry.value = priv->short_retry_limit;
9394 }
9395 mutex_unlock(&priv->mutex);
9396
9397 IPW_DEBUG_WX("GET retry -> %d\n", wrqu->retry.value);
9398
9399 return 0;
9400 }
9401
ipw_wx_set_scan(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9402 static int ipw_wx_set_scan(struct net_device *dev,
9403 struct iw_request_info *info,
9404 union iwreq_data *wrqu, char *extra)
9405 {
9406 struct ipw_priv *priv = libipw_priv(dev);
9407 struct iw_scan_req *req = (struct iw_scan_req *)extra;
9408 struct delayed_work *work = NULL;
9409
9410 mutex_lock(&priv->mutex);
9411
9412 priv->user_requested_scan = 1;
9413
9414 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
9415 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9416 int len = min((int)req->essid_len,
9417 (int)sizeof(priv->direct_scan_ssid));
9418 memcpy(priv->direct_scan_ssid, req->essid, len);
9419 priv->direct_scan_ssid_len = len;
9420 work = &priv->request_direct_scan;
9421 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) {
9422 work = &priv->request_passive_scan;
9423 }
9424 } else {
9425 /* Normal active broadcast scan */
9426 work = &priv->request_scan;
9427 }
9428
9429 mutex_unlock(&priv->mutex);
9430
9431 IPW_DEBUG_WX("Start scan\n");
9432
9433 schedule_delayed_work(work, 0);
9434
9435 return 0;
9436 }
9437
ipw_wx_get_scan(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9438 static int ipw_wx_get_scan(struct net_device *dev,
9439 struct iw_request_info *info,
9440 union iwreq_data *wrqu, char *extra)
9441 {
9442 struct ipw_priv *priv = libipw_priv(dev);
9443 return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
9444 }
9445
ipw_wx_set_encode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * key)9446 static int ipw_wx_set_encode(struct net_device *dev,
9447 struct iw_request_info *info,
9448 union iwreq_data *wrqu, char *key)
9449 {
9450 struct ipw_priv *priv = libipw_priv(dev);
9451 int ret;
9452 u32 cap = priv->capability;
9453
9454 mutex_lock(&priv->mutex);
9455 ret = libipw_wx_set_encode(priv->ieee, info, wrqu, key);
9456
9457 /* In IBSS mode, we need to notify the firmware to update
9458 * the beacon info after we changed the capability. */
9459 if (cap != priv->capability &&
9460 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9461 priv->status & STATUS_ASSOCIATED)
9462 ipw_disassociate(priv);
9463
9464 mutex_unlock(&priv->mutex);
9465 return ret;
9466 }
9467
ipw_wx_get_encode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * key)9468 static int ipw_wx_get_encode(struct net_device *dev,
9469 struct iw_request_info *info,
9470 union iwreq_data *wrqu, char *key)
9471 {
9472 struct ipw_priv *priv = libipw_priv(dev);
9473 return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
9474 }
9475
ipw_wx_set_power(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9476 static int ipw_wx_set_power(struct net_device *dev,
9477 struct iw_request_info *info,
9478 union iwreq_data *wrqu, char *extra)
9479 {
9480 struct ipw_priv *priv = libipw_priv(dev);
9481 int err;
9482 mutex_lock(&priv->mutex);
9483 if (wrqu->power.disabled) {
9484 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9485 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9486 if (err) {
9487 IPW_DEBUG_WX("failed setting power mode.\n");
9488 mutex_unlock(&priv->mutex);
9489 return err;
9490 }
9491 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
9492 mutex_unlock(&priv->mutex);
9493 return 0;
9494 }
9495
9496 switch (wrqu->power.flags & IW_POWER_MODE) {
9497 case IW_POWER_ON: /* If not specified */
9498 case IW_POWER_MODE: /* If set all mask */
9499 case IW_POWER_ALL_R: /* If explicitly state all */
9500 break;
9501 default: /* Otherwise we don't support it */
9502 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9503 wrqu->power.flags);
9504 mutex_unlock(&priv->mutex);
9505 return -EOPNOTSUPP;
9506 }
9507
9508 /* If the user hasn't specified a power management mode yet, default
9509 * to BATTERY */
9510 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
9511 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
9512 else
9513 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9514
9515 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9516 if (err) {
9517 IPW_DEBUG_WX("failed setting power mode.\n");
9518 mutex_unlock(&priv->mutex);
9519 return err;
9520 }
9521
9522 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
9523 mutex_unlock(&priv->mutex);
9524 return 0;
9525 }
9526
ipw_wx_get_power(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9527 static int ipw_wx_get_power(struct net_device *dev,
9528 struct iw_request_info *info,
9529 union iwreq_data *wrqu, char *extra)
9530 {
9531 struct ipw_priv *priv = libipw_priv(dev);
9532 mutex_lock(&priv->mutex);
9533 if (!(priv->power_mode & IPW_POWER_ENABLED))
9534 wrqu->power.disabled = 1;
9535 else
9536 wrqu->power.disabled = 0;
9537
9538 mutex_unlock(&priv->mutex);
9539 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
9540
9541 return 0;
9542 }
9543
ipw_wx_set_powermode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9544 static int ipw_wx_set_powermode(struct net_device *dev,
9545 struct iw_request_info *info,
9546 union iwreq_data *wrqu, char *extra)
9547 {
9548 struct ipw_priv *priv = libipw_priv(dev);
9549 int mode = *(int *)extra;
9550 int err;
9551
9552 mutex_lock(&priv->mutex);
9553 if ((mode < 1) || (mode > IPW_POWER_LIMIT))
9554 mode = IPW_POWER_AC;
9555
9556 if (IPW_POWER_LEVEL(priv->power_mode) != mode) {
9557 err = ipw_send_power_mode(priv, mode);
9558 if (err) {
9559 IPW_DEBUG_WX("failed setting power mode.\n");
9560 mutex_unlock(&priv->mutex);
9561 return err;
9562 }
9563 priv->power_mode = IPW_POWER_ENABLED | mode;
9564 }
9565 mutex_unlock(&priv->mutex);
9566 return 0;
9567 }
9568
9569 #define MAX_WX_STRING 80
ipw_wx_get_powermode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9570 static int ipw_wx_get_powermode(struct net_device *dev,
9571 struct iw_request_info *info,
9572 union iwreq_data *wrqu, char *extra)
9573 {
9574 struct ipw_priv *priv = libipw_priv(dev);
9575 int level = IPW_POWER_LEVEL(priv->power_mode);
9576 char *p = extra;
9577
9578 p += scnprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9579
9580 switch (level) {
9581 case IPW_POWER_AC:
9582 p += scnprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9583 break;
9584 case IPW_POWER_BATTERY:
9585 p += scnprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9586 break;
9587 default:
9588 p += scnprintf(p, MAX_WX_STRING - (p - extra),
9589 "(Timeout %dms, Period %dms)",
9590 timeout_duration[level - 1] / 1000,
9591 period_duration[level - 1] / 1000);
9592 }
9593
9594 if (!(priv->power_mode & IPW_POWER_ENABLED))
9595 p += scnprintf(p, MAX_WX_STRING - (p - extra), " OFF");
9596
9597 wrqu->data.length = p - extra + 1;
9598
9599 return 0;
9600 }
9601
ipw_wx_set_wireless_mode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9602 static int ipw_wx_set_wireless_mode(struct net_device *dev,
9603 struct iw_request_info *info,
9604 union iwreq_data *wrqu, char *extra)
9605 {
9606 struct ipw_priv *priv = libipw_priv(dev);
9607 int mode = *(int *)extra;
9608 u8 band = 0, modulation = 0;
9609
9610 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
9611 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
9612 return -EINVAL;
9613 }
9614 mutex_lock(&priv->mutex);
9615 if (priv->adapter == IPW_2915ABG) {
9616 priv->ieee->abg_true = 1;
9617 if (mode & IEEE_A) {
9618 band |= LIBIPW_52GHZ_BAND;
9619 modulation |= LIBIPW_OFDM_MODULATION;
9620 } else
9621 priv->ieee->abg_true = 0;
9622 } else {
9623 if (mode & IEEE_A) {
9624 IPW_WARNING("Attempt to set 2200BG into "
9625 "802.11a mode\n");
9626 mutex_unlock(&priv->mutex);
9627 return -EINVAL;
9628 }
9629
9630 priv->ieee->abg_true = 0;
9631 }
9632
9633 if (mode & IEEE_B) {
9634 band |= LIBIPW_24GHZ_BAND;
9635 modulation |= LIBIPW_CCK_MODULATION;
9636 } else
9637 priv->ieee->abg_true = 0;
9638
9639 if (mode & IEEE_G) {
9640 band |= LIBIPW_24GHZ_BAND;
9641 modulation |= LIBIPW_OFDM_MODULATION;
9642 } else
9643 priv->ieee->abg_true = 0;
9644
9645 priv->ieee->mode = mode;
9646 priv->ieee->freq_band = band;
9647 priv->ieee->modulation = modulation;
9648 init_supported_rates(priv, &priv->rates);
9649
9650 /* Network configuration changed -- force [re]association */
9651 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9652 if (!ipw_disassociate(priv)) {
9653 ipw_send_supported_rates(priv, &priv->rates);
9654 ipw_associate(priv);
9655 }
9656
9657 /* Update the band LEDs */
9658 ipw_led_band_on(priv);
9659
9660 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
9661 mode & IEEE_A ? 'a' : '.',
9662 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
9663 mutex_unlock(&priv->mutex);
9664 return 0;
9665 }
9666
ipw_wx_get_wireless_mode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9667 static int ipw_wx_get_wireless_mode(struct net_device *dev,
9668 struct iw_request_info *info,
9669 union iwreq_data *wrqu, char *extra)
9670 {
9671 struct ipw_priv *priv = libipw_priv(dev);
9672 mutex_lock(&priv->mutex);
9673 switch (priv->ieee->mode) {
9674 case IEEE_A:
9675 strscpy_pad(extra, "802.11a (1)", MAX_WX_STRING);
9676 break;
9677 case IEEE_B:
9678 strscpy_pad(extra, "802.11b (2)", MAX_WX_STRING);
9679 break;
9680 case IEEE_A | IEEE_B:
9681 strscpy_pad(extra, "802.11ab (3)", MAX_WX_STRING);
9682 break;
9683 case IEEE_G:
9684 strscpy_pad(extra, "802.11g (4)", MAX_WX_STRING);
9685 break;
9686 case IEEE_A | IEEE_G:
9687 strscpy_pad(extra, "802.11ag (5)", MAX_WX_STRING);
9688 break;
9689 case IEEE_B | IEEE_G:
9690 strscpy_pad(extra, "802.11bg (6)", MAX_WX_STRING);
9691 break;
9692 case IEEE_A | IEEE_B | IEEE_G:
9693 strscpy_pad(extra, "802.11abg (7)", MAX_WX_STRING);
9694 break;
9695 default:
9696 strscpy_pad(extra, "unknown", MAX_WX_STRING);
9697 break;
9698 }
9699
9700 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9701
9702 wrqu->data.length = strlen(extra) + 1;
9703 mutex_unlock(&priv->mutex);
9704
9705 return 0;
9706 }
9707
ipw_wx_set_preamble(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9708 static int ipw_wx_set_preamble(struct net_device *dev,
9709 struct iw_request_info *info,
9710 union iwreq_data *wrqu, char *extra)
9711 {
9712 struct ipw_priv *priv = libipw_priv(dev);
9713 int mode = *(int *)extra;
9714 mutex_lock(&priv->mutex);
9715 /* Switching from SHORT -> LONG requires a disassociation */
9716 if (mode == 1) {
9717 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9718 priv->config |= CFG_PREAMBLE_LONG;
9719
9720 /* Network configuration changed -- force [re]association */
9721 IPW_DEBUG_ASSOC
9722 ("[re]association triggered due to preamble change.\n");
9723 if (!ipw_disassociate(priv))
9724 ipw_associate(priv);
9725 }
9726 goto done;
9727 }
9728
9729 if (mode == 0) {
9730 priv->config &= ~CFG_PREAMBLE_LONG;
9731 goto done;
9732 }
9733 mutex_unlock(&priv->mutex);
9734 return -EINVAL;
9735
9736 done:
9737 mutex_unlock(&priv->mutex);
9738 return 0;
9739 }
9740
ipw_wx_get_preamble(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9741 static int ipw_wx_get_preamble(struct net_device *dev,
9742 struct iw_request_info *info,
9743 union iwreq_data *wrqu, char *extra)
9744 {
9745 struct ipw_priv *priv = libipw_priv(dev);
9746 mutex_lock(&priv->mutex);
9747 if (priv->config & CFG_PREAMBLE_LONG)
9748 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9749 else
9750 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
9751 mutex_unlock(&priv->mutex);
9752 return 0;
9753 }
9754
9755 #ifdef CONFIG_IPW2200_MONITOR
ipw_wx_set_monitor(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9756 static int ipw_wx_set_monitor(struct net_device *dev,
9757 struct iw_request_info *info,
9758 union iwreq_data *wrqu, char *extra)
9759 {
9760 struct ipw_priv *priv = libipw_priv(dev);
9761 int *parms = (int *)extra;
9762 int enable = (parms[0] > 0);
9763 mutex_lock(&priv->mutex);
9764 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
9765 if (enable) {
9766 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9767 #ifdef CONFIG_IPW2200_RADIOTAP
9768 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9769 #else
9770 priv->net_dev->type = ARPHRD_IEEE80211;
9771 #endif
9772 schedule_work(&priv->adapter_restart);
9773 }
9774
9775 ipw_set_channel(priv, parms[1]);
9776 } else {
9777 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9778 mutex_unlock(&priv->mutex);
9779 return 0;
9780 }
9781 priv->net_dev->type = ARPHRD_ETHER;
9782 schedule_work(&priv->adapter_restart);
9783 }
9784 mutex_unlock(&priv->mutex);
9785 return 0;
9786 }
9787
9788 #endif /* CONFIG_IPW2200_MONITOR */
9789
ipw_wx_reset(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9790 static int ipw_wx_reset(struct net_device *dev,
9791 struct iw_request_info *info,
9792 union iwreq_data *wrqu, char *extra)
9793 {
9794 struct ipw_priv *priv = libipw_priv(dev);
9795 IPW_DEBUG_WX("RESET\n");
9796 schedule_work(&priv->adapter_restart);
9797 return 0;
9798 }
9799
ipw_wx_sw_reset(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)9800 static int ipw_wx_sw_reset(struct net_device *dev,
9801 struct iw_request_info *info,
9802 union iwreq_data *wrqu, char *extra)
9803 {
9804 struct ipw_priv *priv = libipw_priv(dev);
9805 union iwreq_data wrqu_sec = {
9806 .encoding = {
9807 .flags = IW_ENCODE_DISABLED,
9808 },
9809 };
9810 int ret;
9811
9812 IPW_DEBUG_WX("SW_RESET\n");
9813
9814 mutex_lock(&priv->mutex);
9815
9816 ret = ipw_sw_reset(priv, 2);
9817 if (!ret) {
9818 free_firmware();
9819 ipw_adapter_restart(priv);
9820 }
9821
9822 /* The SW reset bit might have been toggled on by the 'disable'
9823 * module parameter, so take appropriate action */
9824 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9825
9826 mutex_unlock(&priv->mutex);
9827 libipw_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
9828 mutex_lock(&priv->mutex);
9829
9830 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9831 /* Configuration likely changed -- force [re]association */
9832 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9833 "reset.\n");
9834 if (!ipw_disassociate(priv))
9835 ipw_associate(priv);
9836 }
9837
9838 mutex_unlock(&priv->mutex);
9839
9840 return 0;
9841 }
9842
9843 /* Rebase the WE IOCTLs to zero for the handler array */
9844 static iw_handler ipw_wx_handlers[] = {
9845 IW_HANDLER(SIOCGIWNAME, ipw_wx_get_name),
9846 IW_HANDLER(SIOCSIWFREQ, ipw_wx_set_freq),
9847 IW_HANDLER(SIOCGIWFREQ, ipw_wx_get_freq),
9848 IW_HANDLER(SIOCSIWMODE, ipw_wx_set_mode),
9849 IW_HANDLER(SIOCGIWMODE, ipw_wx_get_mode),
9850 IW_HANDLER(SIOCSIWSENS, ipw_wx_set_sens),
9851 IW_HANDLER(SIOCGIWSENS, ipw_wx_get_sens),
9852 IW_HANDLER(SIOCGIWRANGE, ipw_wx_get_range),
9853 IW_HANDLER(SIOCSIWAP, ipw_wx_set_wap),
9854 IW_HANDLER(SIOCGIWAP, ipw_wx_get_wap),
9855 IW_HANDLER(SIOCSIWSCAN, ipw_wx_set_scan),
9856 IW_HANDLER(SIOCGIWSCAN, ipw_wx_get_scan),
9857 IW_HANDLER(SIOCSIWESSID, ipw_wx_set_essid),
9858 IW_HANDLER(SIOCGIWESSID, ipw_wx_get_essid),
9859 IW_HANDLER(SIOCSIWNICKN, ipw_wx_set_nick),
9860 IW_HANDLER(SIOCGIWNICKN, ipw_wx_get_nick),
9861 IW_HANDLER(SIOCSIWRATE, ipw_wx_set_rate),
9862 IW_HANDLER(SIOCGIWRATE, ipw_wx_get_rate),
9863 IW_HANDLER(SIOCSIWRTS, ipw_wx_set_rts),
9864 IW_HANDLER(SIOCGIWRTS, ipw_wx_get_rts),
9865 IW_HANDLER(SIOCSIWFRAG, ipw_wx_set_frag),
9866 IW_HANDLER(SIOCGIWFRAG, ipw_wx_get_frag),
9867 IW_HANDLER(SIOCSIWTXPOW, ipw_wx_set_txpow),
9868 IW_HANDLER(SIOCGIWTXPOW, ipw_wx_get_txpow),
9869 IW_HANDLER(SIOCSIWRETRY, ipw_wx_set_retry),
9870 IW_HANDLER(SIOCGIWRETRY, ipw_wx_get_retry),
9871 IW_HANDLER(SIOCSIWENCODE, ipw_wx_set_encode),
9872 IW_HANDLER(SIOCGIWENCODE, ipw_wx_get_encode),
9873 IW_HANDLER(SIOCSIWPOWER, ipw_wx_set_power),
9874 IW_HANDLER(SIOCGIWPOWER, ipw_wx_get_power),
9875 IW_HANDLER(SIOCSIWSPY, ipw_wx_set_spy),
9876 IW_HANDLER(SIOCGIWSPY, ipw_wx_get_spy),
9877 IW_HANDLER(SIOCSIWTHRSPY, ipw_wx_set_thrspy),
9878 IW_HANDLER(SIOCGIWTHRSPY, ipw_wx_get_thrspy),
9879 IW_HANDLER(SIOCSIWGENIE, ipw_wx_set_genie),
9880 IW_HANDLER(SIOCGIWGENIE, ipw_wx_get_genie),
9881 IW_HANDLER(SIOCSIWMLME, ipw_wx_set_mlme),
9882 IW_HANDLER(SIOCSIWAUTH, ipw_wx_set_auth),
9883 IW_HANDLER(SIOCGIWAUTH, ipw_wx_get_auth),
9884 IW_HANDLER(SIOCSIWENCODEEXT, ipw_wx_set_encodeext),
9885 IW_HANDLER(SIOCGIWENCODEEXT, ipw_wx_get_encodeext),
9886 };
9887
9888 enum {
9889 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9890 IPW_PRIV_GET_POWER,
9891 IPW_PRIV_SET_MODE,
9892 IPW_PRIV_GET_MODE,
9893 IPW_PRIV_SET_PREAMBLE,
9894 IPW_PRIV_GET_PREAMBLE,
9895 IPW_PRIV_RESET,
9896 IPW_PRIV_SW_RESET,
9897 #ifdef CONFIG_IPW2200_MONITOR
9898 IPW_PRIV_SET_MONITOR,
9899 #endif
9900 };
9901
9902 static struct iw_priv_args ipw_priv_args[] = {
9903 {
9904 .cmd = IPW_PRIV_SET_POWER,
9905 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9906 .name = "set_power"},
9907 {
9908 .cmd = IPW_PRIV_GET_POWER,
9909 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9910 .name = "get_power"},
9911 {
9912 .cmd = IPW_PRIV_SET_MODE,
9913 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9914 .name = "set_mode"},
9915 {
9916 .cmd = IPW_PRIV_GET_MODE,
9917 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9918 .name = "get_mode"},
9919 {
9920 .cmd = IPW_PRIV_SET_PREAMBLE,
9921 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9922 .name = "set_preamble"},
9923 {
9924 .cmd = IPW_PRIV_GET_PREAMBLE,
9925 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9926 .name = "get_preamble"},
9927 {
9928 IPW_PRIV_RESET,
9929 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
9930 {
9931 IPW_PRIV_SW_RESET,
9932 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9933 #ifdef CONFIG_IPW2200_MONITOR
9934 {
9935 IPW_PRIV_SET_MONITOR,
9936 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9937 #endif /* CONFIG_IPW2200_MONITOR */
9938 };
9939
9940 static iw_handler ipw_priv_handler[] = {
9941 ipw_wx_set_powermode,
9942 ipw_wx_get_powermode,
9943 ipw_wx_set_wireless_mode,
9944 ipw_wx_get_wireless_mode,
9945 ipw_wx_set_preamble,
9946 ipw_wx_get_preamble,
9947 ipw_wx_reset,
9948 ipw_wx_sw_reset,
9949 #ifdef CONFIG_IPW2200_MONITOR
9950 ipw_wx_set_monitor,
9951 #endif
9952 };
9953
9954 static const struct iw_handler_def ipw_wx_handler_def = {
9955 .standard = ipw_wx_handlers,
9956 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9957 .num_private = ARRAY_SIZE(ipw_priv_handler),
9958 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9959 .private = ipw_priv_handler,
9960 .private_args = ipw_priv_args,
9961 .get_wireless_stats = ipw_get_wireless_stats,
9962 };
9963
9964 /*
9965 * Get wireless statistics.
9966 * Called by /proc/net/wireless
9967 * Also called by SIOCGIWSTATS
9968 */
ipw_get_wireless_stats(struct net_device * dev)9969 static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
9970 {
9971 struct ipw_priv *priv = libipw_priv(dev);
9972 struct iw_statistics *wstats;
9973
9974 wstats = &priv->wstats;
9975
9976 /* if hw is disabled, then ipw_get_ordinal() can't be called.
9977 * netdev->get_wireless_stats seems to be called before fw is
9978 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9979 * and associated; if not associcated, the values are all meaningless
9980 * anyway, so set them all to NULL and INVALID */
9981 if (!(priv->status & STATUS_ASSOCIATED)) {
9982 wstats->miss.beacon = 0;
9983 wstats->discard.retries = 0;
9984 wstats->qual.qual = 0;
9985 wstats->qual.level = 0;
9986 wstats->qual.noise = 0;
9987 wstats->qual.updated = 7;
9988 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
9989 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
9990 return wstats;
9991 }
9992
9993 wstats->qual.qual = priv->quality;
9994 wstats->qual.level = priv->exp_avg_rssi;
9995 wstats->qual.noise = priv->exp_avg_noise;
9996 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
9997 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
9998
9999 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
10000 wstats->discard.retries = priv->last_tx_failures;
10001 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
10002
10003 /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
10004 goto fail_get_ordinal;
10005 wstats->discard.retries += tx_retry; */
10006
10007 return wstats;
10008 }
10009
10010 /* net device stuff */
10011
init_sys_config(struct ipw_sys_config * sys_config)10012 static void init_sys_config(struct ipw_sys_config *sys_config)
10013 {
10014 memset(sys_config, 0, sizeof(struct ipw_sys_config));
10015 sys_config->bt_coexistence = 0;
10016 sys_config->answer_broadcast_ssid_probe = 0;
10017 sys_config->accept_all_data_frames = 0;
10018 sys_config->accept_non_directed_frames = 1;
10019 sys_config->exclude_unicast_unencrypted = 0;
10020 sys_config->disable_unicast_decryption = 1;
10021 sys_config->exclude_multicast_unencrypted = 0;
10022 sys_config->disable_multicast_decryption = 1;
10023 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
10024 antenna = CFG_SYS_ANTENNA_BOTH;
10025 sys_config->antenna_diversity = antenna;
10026 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
10027 sys_config->dot11g_auto_detection = 0;
10028 sys_config->enable_cts_to_self = 0;
10029 sys_config->bt_coexist_collision_thr = 0;
10030 sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */
10031 sys_config->silence_threshold = 0x1e;
10032 }
10033
ipw_net_open(struct net_device * dev)10034 static int ipw_net_open(struct net_device *dev)
10035 {
10036 IPW_DEBUG_INFO("dev->open\n");
10037 netif_start_queue(dev);
10038 return 0;
10039 }
10040
ipw_net_stop(struct net_device * dev)10041 static int ipw_net_stop(struct net_device *dev)
10042 {
10043 IPW_DEBUG_INFO("dev->close\n");
10044 netif_stop_queue(dev);
10045 return 0;
10046 }
10047
10048 /*
10049 todo:
10050
10051 modify to send one tfd per fragment instead of using chunking. otherwise
10052 we need to heavily modify the libipw_skb_to_txb.
10053 */
10054
ipw_tx_skb(struct ipw_priv * priv,struct libipw_txb * txb,int pri)10055 static int ipw_tx_skb(struct ipw_priv *priv, struct libipw_txb *txb,
10056 int pri)
10057 {
10058 struct libipw_hdr_3addrqos *hdr = (struct libipw_hdr_3addrqos *)
10059 txb->fragments[0]->data;
10060 int i = 0;
10061 struct tfd_frame *tfd;
10062 #ifdef CONFIG_IPW2200_QOS
10063 int tx_id = ipw_get_tx_queue_number(priv, pri);
10064 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10065 #else
10066 struct clx2_tx_queue *txq = &priv->txq[0];
10067 #endif
10068 struct clx2_queue *q = &txq->q;
10069 u8 id, hdr_len, unicast;
10070 int fc;
10071
10072 if (!(priv->status & STATUS_ASSOCIATED))
10073 goto drop;
10074
10075 hdr_len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
10076 switch (priv->ieee->iw_mode) {
10077 case IW_MODE_ADHOC:
10078 unicast = !is_multicast_ether_addr(hdr->addr1);
10079 id = ipw_find_station(priv, hdr->addr1);
10080 if (id == IPW_INVALID_STATION) {
10081 id = ipw_add_station(priv, hdr->addr1);
10082 if (id == IPW_INVALID_STATION) {
10083 IPW_WARNING("Attempt to send data to "
10084 "invalid cell: %pM\n",
10085 hdr->addr1);
10086 goto drop;
10087 }
10088 }
10089 break;
10090
10091 case IW_MODE_INFRA:
10092 default:
10093 unicast = !is_multicast_ether_addr(hdr->addr3);
10094 id = 0;
10095 break;
10096 }
10097
10098 tfd = &txq->bd[q->first_empty];
10099 txq->txb[q->first_empty] = txb;
10100 memset(tfd, 0, sizeof(*tfd));
10101 tfd->u.data.station_number = id;
10102
10103 tfd->control_flags.message_type = TX_FRAME_TYPE;
10104 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10105
10106 tfd->u.data.cmd_id = DINO_CMD_TX;
10107 tfd->u.data.len = cpu_to_le16(txb->payload_size);
10108
10109 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
10110 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
10111 else
10112 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
10113
10114 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10115 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
10116
10117 fc = le16_to_cpu(hdr->frame_ctl);
10118 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
10119
10120 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10121
10122 if (likely(unicast))
10123 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10124
10125 if (txb->encrypted && !priv->ieee->host_encrypt) {
10126 switch (priv->ieee->sec.level) {
10127 case SEC_LEVEL_3:
10128 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10129 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
10130 /* XXX: ACK flag must be set for CCMP even if it
10131 * is a multicast/broadcast packet, because CCMP
10132 * group communication encrypted by GTK is
10133 * actually done by the AP. */
10134 if (!unicast)
10135 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10136
10137 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10138 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10139 tfd->u.data.key_index = 0;
10140 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10141 break;
10142 case SEC_LEVEL_2:
10143 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10144 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
10145 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10146 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10147 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10148 break;
10149 case SEC_LEVEL_1:
10150 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10151 cpu_to_le16(IEEE80211_FCTL_PROTECTED);
10152 tfd->u.data.key_index = priv->ieee->crypt_info.tx_keyidx;
10153 if (priv->ieee->sec.key_sizes[priv->ieee->crypt_info.tx_keyidx] <=
10154 40)
10155 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10156 else
10157 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10158 break;
10159 case SEC_LEVEL_0:
10160 break;
10161 default:
10162 printk(KERN_ERR "Unknown security level %d\n",
10163 priv->ieee->sec.level);
10164 break;
10165 }
10166 } else
10167 /* No hardware encryption */
10168 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10169
10170 #ifdef CONFIG_IPW2200_QOS
10171 if (fc & IEEE80211_STYPE_QOS_DATA)
10172 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
10173 #endif /* CONFIG_IPW2200_QOS */
10174
10175 /* payload */
10176 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10177 txb->nr_frags));
10178 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10179 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10180 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10181 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10182 i, le32_to_cpu(tfd->u.data.num_chunks),
10183 txb->fragments[i]->len - hdr_len);
10184 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
10185 i, tfd->u.data.num_chunks,
10186 txb->fragments[i]->len - hdr_len);
10187 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
10188 txb->fragments[i]->len - hdr_len);
10189
10190 tfd->u.data.chunk_ptr[i] =
10191 cpu_to_le32(dma_map_single(&priv->pci_dev->dev,
10192 txb->fragments[i]->data + hdr_len,
10193 txb->fragments[i]->len - hdr_len,
10194 DMA_TO_DEVICE));
10195 tfd->u.data.chunk_len[i] =
10196 cpu_to_le16(txb->fragments[i]->len - hdr_len);
10197 }
10198
10199 if (i != txb->nr_frags) {
10200 struct sk_buff *skb;
10201 u16 remaining_bytes = 0;
10202 int j;
10203
10204 for (j = i; j < txb->nr_frags; j++)
10205 remaining_bytes += txb->fragments[j]->len - hdr_len;
10206
10207 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10208 remaining_bytes);
10209 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10210 if (skb != NULL) {
10211 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
10212 for (j = i; j < txb->nr_frags; j++) {
10213 int size = txb->fragments[j]->len - hdr_len;
10214
10215 printk(KERN_INFO "Adding frag %d %d...\n",
10216 j, size);
10217 skb_put_data(skb,
10218 txb->fragments[j]->data + hdr_len,
10219 size);
10220 }
10221 dev_kfree_skb_any(txb->fragments[i]);
10222 txb->fragments[i] = skb;
10223 tfd->u.data.chunk_ptr[i] =
10224 cpu_to_le32(dma_map_single(&priv->pci_dev->dev,
10225 skb->data,
10226 remaining_bytes,
10227 DMA_TO_DEVICE));
10228
10229 le32_add_cpu(&tfd->u.data.num_chunks, 1);
10230 }
10231 }
10232
10233 /* kick DMA */
10234 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10235 ipw_write32(priv, q->reg_w, q->first_empty);
10236
10237 if (ipw_tx_queue_space(q) < q->high_mark)
10238 netif_stop_queue(priv->net_dev);
10239
10240 return NETDEV_TX_OK;
10241
10242 drop:
10243 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
10244 libipw_txb_free(txb);
10245 return NETDEV_TX_OK;
10246 }
10247
ipw_net_is_queue_full(struct net_device * dev,int pri)10248 static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10249 {
10250 struct ipw_priv *priv = libipw_priv(dev);
10251 #ifdef CONFIG_IPW2200_QOS
10252 int tx_id = ipw_get_tx_queue_number(priv, pri);
10253 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10254 #else
10255 struct clx2_tx_queue *txq = &priv->txq[0];
10256 #endif /* CONFIG_IPW2200_QOS */
10257
10258 if (ipw_tx_queue_space(&txq->q) < txq->q.high_mark)
10259 return 1;
10260
10261 return 0;
10262 }
10263
10264 #ifdef CONFIG_IPW2200_PROMISCUOUS
ipw_handle_promiscuous_tx(struct ipw_priv * priv,struct libipw_txb * txb)10265 static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
10266 struct libipw_txb *txb)
10267 {
10268 struct libipw_rx_stats dummystats;
10269 struct ieee80211_hdr *hdr;
10270 u8 n;
10271 u16 filter = priv->prom_priv->filter;
10272 int hdr_only = 0;
10273
10274 if (filter & IPW_PROM_NO_TX)
10275 return;
10276
10277 memset(&dummystats, 0, sizeof(dummystats));
10278
10279 /* Filtering of fragment chains is done against the first fragment */
10280 hdr = (void *)txb->fragments[0]->data;
10281 if (libipw_is_management(le16_to_cpu(hdr->frame_control))) {
10282 if (filter & IPW_PROM_NO_MGMT)
10283 return;
10284 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10285 hdr_only = 1;
10286 } else if (libipw_is_control(le16_to_cpu(hdr->frame_control))) {
10287 if (filter & IPW_PROM_NO_CTL)
10288 return;
10289 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10290 hdr_only = 1;
10291 } else if (libipw_is_data(le16_to_cpu(hdr->frame_control))) {
10292 if (filter & IPW_PROM_NO_DATA)
10293 return;
10294 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10295 hdr_only = 1;
10296 }
10297
10298 for(n=0; n<txb->nr_frags; ++n) {
10299 struct sk_buff *src = txb->fragments[n];
10300 struct sk_buff *dst;
10301 struct ieee80211_radiotap_header *rt_hdr;
10302 int len;
10303
10304 if (hdr_only) {
10305 hdr = (void *)src->data;
10306 len = libipw_get_hdrlen(le16_to_cpu(hdr->frame_control));
10307 } else
10308 len = src->len;
10309
10310 dst = alloc_skb(len + sizeof(*rt_hdr) + sizeof(u16)*2, GFP_ATOMIC);
10311 if (!dst)
10312 continue;
10313
10314 rt_hdr = skb_put(dst, sizeof(*rt_hdr));
10315
10316 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10317 rt_hdr->it_pad = 0;
10318 rt_hdr->it_present = 0; /* after all, it's just an idea */
10319 rt_hdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_CHANNEL);
10320
10321 *(__le16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
10322 ieee80211chan2mhz(priv->channel));
10323 if (priv->channel > 14) /* 802.11a */
10324 *(__le16*)skb_put(dst, sizeof(u16)) =
10325 cpu_to_le16(IEEE80211_CHAN_OFDM |
10326 IEEE80211_CHAN_5GHZ);
10327 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
10328 *(__le16*)skb_put(dst, sizeof(u16)) =
10329 cpu_to_le16(IEEE80211_CHAN_CCK |
10330 IEEE80211_CHAN_2GHZ);
10331 else /* 802.11g */
10332 *(__le16*)skb_put(dst, sizeof(u16)) =
10333 cpu_to_le16(IEEE80211_CHAN_OFDM |
10334 IEEE80211_CHAN_2GHZ);
10335
10336 rt_hdr->it_len = cpu_to_le16(dst->len);
10337
10338 skb_copy_from_linear_data(src, skb_put(dst, len), len);
10339
10340 if (!libipw_rx(priv->prom_priv->ieee, dst, &dummystats))
10341 dev_kfree_skb_any(dst);
10342 }
10343 }
10344 #endif
10345
ipw_net_hard_start_xmit(struct libipw_txb * txb,struct net_device * dev,int pri)10346 static netdev_tx_t ipw_net_hard_start_xmit(struct libipw_txb *txb,
10347 struct net_device *dev, int pri)
10348 {
10349 struct ipw_priv *priv = libipw_priv(dev);
10350 unsigned long flags;
10351 netdev_tx_t ret;
10352
10353 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
10354 spin_lock_irqsave(&priv->lock, flags);
10355
10356 #ifdef CONFIG_IPW2200_PROMISCUOUS
10357 if (rtap_iface && netif_running(priv->prom_net_dev))
10358 ipw_handle_promiscuous_tx(priv, txb);
10359 #endif
10360
10361 ret = ipw_tx_skb(priv, txb, pri);
10362 if (ret == NETDEV_TX_OK)
10363 __ipw_led_activity_on(priv);
10364 spin_unlock_irqrestore(&priv->lock, flags);
10365
10366 return ret;
10367 }
10368
ipw_net_set_multicast_list(struct net_device * dev)10369 static void ipw_net_set_multicast_list(struct net_device *dev)
10370 {
10371
10372 }
10373
ipw_net_set_mac_address(struct net_device * dev,void * p)10374 static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10375 {
10376 struct ipw_priv *priv = libipw_priv(dev);
10377 struct sockaddr *addr = p;
10378
10379 if (!is_valid_ether_addr(addr->sa_data))
10380 return -EADDRNOTAVAIL;
10381 mutex_lock(&priv->mutex);
10382 priv->config |= CFG_CUSTOM_MAC;
10383 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
10384 printk(KERN_INFO "%s: Setting MAC to %pM\n",
10385 priv->net_dev->name, priv->mac_addr);
10386 schedule_work(&priv->adapter_restart);
10387 mutex_unlock(&priv->mutex);
10388 return 0;
10389 }
10390
ipw_ethtool_get_drvinfo(struct net_device * dev,struct ethtool_drvinfo * info)10391 static void ipw_ethtool_get_drvinfo(struct net_device *dev,
10392 struct ethtool_drvinfo *info)
10393 {
10394 struct ipw_priv *p = libipw_priv(dev);
10395 char vers[64];
10396 u32 len;
10397
10398 strscpy(info->driver, DRV_NAME, sizeof(info->driver));
10399 strscpy(info->version, DRV_VERSION, sizeof(info->version));
10400
10401 len = sizeof(vers);
10402 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10403
10404 strscpy(info->fw_version, vers, sizeof(info->fw_version));
10405 strscpy(info->bus_info, pci_name(p->pci_dev),
10406 sizeof(info->bus_info));
10407 }
10408
ipw_ethtool_get_link(struct net_device * dev)10409 static u32 ipw_ethtool_get_link(struct net_device *dev)
10410 {
10411 struct ipw_priv *priv = libipw_priv(dev);
10412 return (priv->status & STATUS_ASSOCIATED) != 0;
10413 }
10414
ipw_ethtool_get_eeprom_len(struct net_device * dev)10415 static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10416 {
10417 return IPW_EEPROM_IMAGE_SIZE;
10418 }
10419
ipw_ethtool_get_eeprom(struct net_device * dev,struct ethtool_eeprom * eeprom,u8 * bytes)10420 static int ipw_ethtool_get_eeprom(struct net_device *dev,
10421 struct ethtool_eeprom *eeprom, u8 * bytes)
10422 {
10423 struct ipw_priv *p = libipw_priv(dev);
10424
10425 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
10426 return -EINVAL;
10427 mutex_lock(&p->mutex);
10428 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
10429 mutex_unlock(&p->mutex);
10430 return 0;
10431 }
10432
ipw_ethtool_set_eeprom(struct net_device * dev,struct ethtool_eeprom * eeprom,u8 * bytes)10433 static int ipw_ethtool_set_eeprom(struct net_device *dev,
10434 struct ethtool_eeprom *eeprom, u8 * bytes)
10435 {
10436 struct ipw_priv *p = libipw_priv(dev);
10437 int i;
10438
10439 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
10440 return -EINVAL;
10441 mutex_lock(&p->mutex);
10442 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
10443 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10444 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
10445 mutex_unlock(&p->mutex);
10446 return 0;
10447 }
10448
10449 static const struct ethtool_ops ipw_ethtool_ops = {
10450 .get_link = ipw_ethtool_get_link,
10451 .get_drvinfo = ipw_ethtool_get_drvinfo,
10452 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10453 .get_eeprom = ipw_ethtool_get_eeprom,
10454 .set_eeprom = ipw_ethtool_set_eeprom,
10455 };
10456
ipw_isr(int irq,void * data)10457 static irqreturn_t ipw_isr(int irq, void *data)
10458 {
10459 struct ipw_priv *priv = data;
10460 u32 inta, inta_mask;
10461
10462 if (!priv)
10463 return IRQ_NONE;
10464
10465 spin_lock(&priv->irq_lock);
10466
10467 if (!(priv->status & STATUS_INT_ENABLED)) {
10468 /* IRQ is disabled */
10469 goto none;
10470 }
10471
10472 inta = ipw_read32(priv, IPW_INTA_RW);
10473 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
10474
10475 if (inta == 0xFFFFFFFF) {
10476 /* Hardware disappeared */
10477 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10478 goto none;
10479 }
10480
10481 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
10482 /* Shared interrupt */
10483 goto none;
10484 }
10485
10486 /* tell the device to stop sending interrupts */
10487 __ipw_disable_interrupts(priv);
10488
10489 /* ack current interrupts */
10490 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10491 ipw_write32(priv, IPW_INTA_RW, inta);
10492
10493 /* Cache INTA value for our tasklet */
10494 priv->isr_inta = inta;
10495
10496 tasklet_schedule(&priv->irq_tasklet);
10497
10498 spin_unlock(&priv->irq_lock);
10499
10500 return IRQ_HANDLED;
10501 none:
10502 spin_unlock(&priv->irq_lock);
10503 return IRQ_NONE;
10504 }
10505
ipw_rf_kill(void * adapter)10506 static void ipw_rf_kill(void *adapter)
10507 {
10508 struct ipw_priv *priv = adapter;
10509 unsigned long flags;
10510
10511 spin_lock_irqsave(&priv->lock, flags);
10512
10513 if (rf_kill_active(priv)) {
10514 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10515 schedule_delayed_work(&priv->rf_kill, 2 * HZ);
10516 goto exit_unlock;
10517 }
10518
10519 /* RF Kill is now disabled, so bring the device back up */
10520
10521 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10522 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10523 "device\n");
10524
10525 /* we can not do an adapter restart while inside an irq lock */
10526 schedule_work(&priv->adapter_restart);
10527 } else
10528 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10529 "enabled\n");
10530
10531 exit_unlock:
10532 spin_unlock_irqrestore(&priv->lock, flags);
10533 }
10534
ipw_bg_rf_kill(struct work_struct * work)10535 static void ipw_bg_rf_kill(struct work_struct *work)
10536 {
10537 struct ipw_priv *priv =
10538 container_of(work, struct ipw_priv, rf_kill.work);
10539 mutex_lock(&priv->mutex);
10540 ipw_rf_kill(priv);
10541 mutex_unlock(&priv->mutex);
10542 }
10543
ipw_link_up(struct ipw_priv * priv)10544 static void ipw_link_up(struct ipw_priv *priv)
10545 {
10546 priv->last_seq_num = -1;
10547 priv->last_frag_num = -1;
10548 priv->last_packet_time = 0;
10549
10550 netif_carrier_on(priv->net_dev);
10551
10552 cancel_delayed_work(&priv->request_scan);
10553 cancel_delayed_work(&priv->request_direct_scan);
10554 cancel_delayed_work(&priv->request_passive_scan);
10555 cancel_delayed_work(&priv->scan_event);
10556 ipw_reset_stats(priv);
10557 /* Ensure the rate is updated immediately */
10558 priv->last_rate = ipw_get_current_rate(priv);
10559 ipw_gather_stats(priv);
10560 ipw_led_link_up(priv);
10561 notify_wx_assoc_event(priv);
10562
10563 if (priv->config & CFG_BACKGROUND_SCAN)
10564 schedule_delayed_work(&priv->request_scan, HZ);
10565 }
10566
ipw_bg_link_up(struct work_struct * work)10567 static void ipw_bg_link_up(struct work_struct *work)
10568 {
10569 struct ipw_priv *priv =
10570 container_of(work, struct ipw_priv, link_up);
10571 mutex_lock(&priv->mutex);
10572 ipw_link_up(priv);
10573 mutex_unlock(&priv->mutex);
10574 }
10575
ipw_link_down(struct ipw_priv * priv)10576 static void ipw_link_down(struct ipw_priv *priv)
10577 {
10578 ipw_led_link_down(priv);
10579 netif_carrier_off(priv->net_dev);
10580 notify_wx_assoc_event(priv);
10581
10582 /* Cancel any queued work ... */
10583 cancel_delayed_work(&priv->request_scan);
10584 cancel_delayed_work(&priv->request_direct_scan);
10585 cancel_delayed_work(&priv->request_passive_scan);
10586 cancel_delayed_work(&priv->adhoc_check);
10587 cancel_delayed_work(&priv->gather_stats);
10588
10589 ipw_reset_stats(priv);
10590
10591 if (!(priv->status & STATUS_EXIT_PENDING)) {
10592 /* Queue up another scan... */
10593 schedule_delayed_work(&priv->request_scan, 0);
10594 } else
10595 cancel_delayed_work(&priv->scan_event);
10596 }
10597
ipw_bg_link_down(struct work_struct * work)10598 static void ipw_bg_link_down(struct work_struct *work)
10599 {
10600 struct ipw_priv *priv =
10601 container_of(work, struct ipw_priv, link_down);
10602 mutex_lock(&priv->mutex);
10603 ipw_link_down(priv);
10604 mutex_unlock(&priv->mutex);
10605 }
10606
ipw_setup_deferred_work(struct ipw_priv * priv)10607 static void ipw_setup_deferred_work(struct ipw_priv *priv)
10608 {
10609 init_waitqueue_head(&priv->wait_command_queue);
10610 init_waitqueue_head(&priv->wait_state);
10611
10612 INIT_DELAYED_WORK(&priv->adhoc_check, ipw_bg_adhoc_check);
10613 INIT_WORK(&priv->associate, ipw_bg_associate);
10614 INIT_WORK(&priv->disassociate, ipw_bg_disassociate);
10615 INIT_WORK(&priv->system_config, ipw_system_config);
10616 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish);
10617 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart);
10618 INIT_DELAYED_WORK(&priv->rf_kill, ipw_bg_rf_kill);
10619 INIT_WORK(&priv->up, ipw_bg_up);
10620 INIT_WORK(&priv->down, ipw_bg_down);
10621 INIT_DELAYED_WORK(&priv->request_scan, ipw_request_scan);
10622 INIT_DELAYED_WORK(&priv->request_direct_scan, ipw_request_direct_scan);
10623 INIT_DELAYED_WORK(&priv->request_passive_scan, ipw_request_passive_scan);
10624 INIT_DELAYED_WORK(&priv->scan_event, ipw_scan_event);
10625 INIT_DELAYED_WORK(&priv->gather_stats, ipw_bg_gather_stats);
10626 INIT_WORK(&priv->abort_scan, ipw_bg_abort_scan);
10627 INIT_WORK(&priv->roam, ipw_bg_roam);
10628 INIT_DELAYED_WORK(&priv->scan_check, ipw_bg_scan_check);
10629 INIT_WORK(&priv->link_up, ipw_bg_link_up);
10630 INIT_WORK(&priv->link_down, ipw_bg_link_down);
10631 INIT_DELAYED_WORK(&priv->led_link_on, ipw_bg_led_link_on);
10632 INIT_DELAYED_WORK(&priv->led_link_off, ipw_bg_led_link_off);
10633 INIT_DELAYED_WORK(&priv->led_act_off, ipw_bg_led_activity_off);
10634 INIT_WORK(&priv->merge_networks, ipw_merge_adhoc_network);
10635
10636 #ifdef CONFIG_IPW2200_QOS
10637 INIT_WORK(&priv->qos_activate, ipw_bg_qos_activate);
10638 #endif /* CONFIG_IPW2200_QOS */
10639
10640 tasklet_setup(&priv->irq_tasklet, ipw_irq_tasklet);
10641 }
10642
shim__set_security(struct net_device * dev,struct libipw_security * sec)10643 static void shim__set_security(struct net_device *dev,
10644 struct libipw_security *sec)
10645 {
10646 struct ipw_priv *priv = libipw_priv(dev);
10647 int i;
10648 for (i = 0; i < 4; i++) {
10649 if (sec->flags & (1 << i)) {
10650 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
10651 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
10652 if (sec->key_sizes[i] == 0)
10653 priv->ieee->sec.flags &= ~(1 << i);
10654 else {
10655 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
10656 sec->key_sizes[i]);
10657 priv->ieee->sec.flags |= (1 << i);
10658 }
10659 priv->status |= STATUS_SECURITY_UPDATED;
10660 } else if (sec->level != SEC_LEVEL_1)
10661 priv->ieee->sec.flags &= ~(1 << i);
10662 }
10663
10664 if (sec->flags & SEC_ACTIVE_KEY) {
10665 priv->ieee->sec.active_key = sec->active_key;
10666 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
10667 priv->status |= STATUS_SECURITY_UPDATED;
10668 } else
10669 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
10670
10671 if ((sec->flags & SEC_AUTH_MODE) &&
10672 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10673 priv->ieee->sec.auth_mode = sec->auth_mode;
10674 priv->ieee->sec.flags |= SEC_AUTH_MODE;
10675 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10676 priv->capability |= CAP_SHARED_KEY;
10677 else
10678 priv->capability &= ~CAP_SHARED_KEY;
10679 priv->status |= STATUS_SECURITY_UPDATED;
10680 }
10681
10682 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10683 priv->ieee->sec.flags |= SEC_ENABLED;
10684 priv->ieee->sec.enabled = sec->enabled;
10685 priv->status |= STATUS_SECURITY_UPDATED;
10686 if (sec->enabled)
10687 priv->capability |= CAP_PRIVACY_ON;
10688 else
10689 priv->capability &= ~CAP_PRIVACY_ON;
10690 }
10691
10692 if (sec->flags & SEC_ENCRYPT)
10693 priv->ieee->sec.encrypt = sec->encrypt;
10694
10695 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10696 priv->ieee->sec.level = sec->level;
10697 priv->ieee->sec.flags |= SEC_LEVEL;
10698 priv->status |= STATUS_SECURITY_UPDATED;
10699 }
10700
10701 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10702 ipw_set_hwcrypto_keys(priv);
10703
10704 /* To match current functionality of ipw2100 (which works well w/
10705 * various supplicants, we don't force a disassociate if the
10706 * privacy capability changes ... */
10707 #if 0
10708 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
10709 (((priv->assoc_request.capability &
10710 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && !sec->enabled) ||
10711 (!(priv->assoc_request.capability &
10712 cpu_to_le16(WLAN_CAPABILITY_PRIVACY)) && sec->enabled))) {
10713 IPW_DEBUG_ASSOC("Disassociating due to capability "
10714 "change.\n");
10715 ipw_disassociate(priv);
10716 }
10717 #endif
10718 }
10719
init_supported_rates(struct ipw_priv * priv,struct ipw_supported_rates * rates)10720 static int init_supported_rates(struct ipw_priv *priv,
10721 struct ipw_supported_rates *rates)
10722 {
10723 /* TODO: Mask out rates based on priv->rates_mask */
10724
10725 memset(rates, 0, sizeof(*rates));
10726 /* configure supported rates */
10727 switch (priv->ieee->freq_band) {
10728 case LIBIPW_52GHZ_BAND:
10729 rates->ieee_mode = IPW_A_MODE;
10730 rates->purpose = IPW_RATE_CAPABILITIES;
10731 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10732 LIBIPW_OFDM_DEFAULT_RATES_MASK);
10733 break;
10734
10735 default: /* Mixed or 2.4Ghz */
10736 rates->ieee_mode = IPW_G_MODE;
10737 rates->purpose = IPW_RATE_CAPABILITIES;
10738 ipw_add_cck_scan_rates(rates, LIBIPW_CCK_MODULATION,
10739 LIBIPW_CCK_DEFAULT_RATES_MASK);
10740 if (priv->ieee->modulation & LIBIPW_OFDM_MODULATION) {
10741 ipw_add_ofdm_scan_rates(rates, LIBIPW_CCK_MODULATION,
10742 LIBIPW_OFDM_DEFAULT_RATES_MASK);
10743 }
10744 break;
10745 }
10746
10747 return 0;
10748 }
10749
ipw_config(struct ipw_priv * priv)10750 static int ipw_config(struct ipw_priv *priv)
10751 {
10752 /* This is only called from ipw_up, which resets/reloads the firmware
10753 so, we don't need to first disable the card before we configure
10754 it */
10755 if (ipw_set_tx_power(priv))
10756 goto error;
10757
10758 /* initialize adapter address */
10759 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10760 goto error;
10761
10762 /* set basic system config settings */
10763 init_sys_config(&priv->sys_config);
10764
10765 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10766 * Does not support BT priority yet (don't abort or defer our Tx) */
10767 if (bt_coexist) {
10768 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
10769
10770 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10771 priv->sys_config.bt_coexistence
10772 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
10773 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10774 priv->sys_config.bt_coexistence
10775 |= CFG_BT_COEXISTENCE_OOB;
10776 }
10777
10778 #ifdef CONFIG_IPW2200_PROMISCUOUS
10779 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10780 priv->sys_config.accept_all_data_frames = 1;
10781 priv->sys_config.accept_non_directed_frames = 1;
10782 priv->sys_config.accept_all_mgmt_bcpr = 1;
10783 priv->sys_config.accept_all_mgmt_frames = 1;
10784 }
10785 #endif
10786
10787 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10788 priv->sys_config.answer_broadcast_ssid_probe = 1;
10789 else
10790 priv->sys_config.answer_broadcast_ssid_probe = 0;
10791
10792 if (ipw_send_system_config(priv))
10793 goto error;
10794
10795 init_supported_rates(priv, &priv->rates);
10796 if (ipw_send_supported_rates(priv, &priv->rates))
10797 goto error;
10798
10799 /* Set request-to-send threshold */
10800 if (priv->rts_threshold) {
10801 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10802 goto error;
10803 }
10804 #ifdef CONFIG_IPW2200_QOS
10805 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10806 ipw_qos_activate(priv, NULL);
10807 #endif /* CONFIG_IPW2200_QOS */
10808
10809 if (ipw_set_random_seed(priv))
10810 goto error;
10811
10812 /* final state transition to the RUN state */
10813 if (ipw_send_host_complete(priv))
10814 goto error;
10815
10816 priv->status |= STATUS_INIT;
10817
10818 ipw_led_init(priv);
10819 ipw_led_radio_on(priv);
10820 priv->notif_missed_beacons = 0;
10821
10822 /* Set hardware WEP key if it is configured. */
10823 if ((priv->capability & CAP_PRIVACY_ON) &&
10824 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10825 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10826 ipw_set_hwcrypto_keys(priv);
10827
10828 return 0;
10829
10830 error:
10831 return -EIO;
10832 }
10833
10834 /*
10835 * NOTE:
10836 *
10837 * These tables have been tested in conjunction with the
10838 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10839 *
10840 * Altering this values, using it on other hardware, or in geographies
10841 * not intended for resale of the above mentioned Intel adapters has
10842 * not been tested.
10843 *
10844 * Remember to update the table in README.ipw2200 when changing this
10845 * table.
10846 *
10847 */
10848 static const struct libipw_geo ipw_geos[] = {
10849 { /* Restricted */
10850 "---",
10851 .bg_channels = 11,
10852 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10853 {2427, 4}, {2432, 5}, {2437, 6},
10854 {2442, 7}, {2447, 8}, {2452, 9},
10855 {2457, 10}, {2462, 11}},
10856 },
10857
10858 { /* Custom US/Canada */
10859 "ZZF",
10860 .bg_channels = 11,
10861 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10862 {2427, 4}, {2432, 5}, {2437, 6},
10863 {2442, 7}, {2447, 8}, {2452, 9},
10864 {2457, 10}, {2462, 11}},
10865 .a_channels = 8,
10866 .a = {{5180, 36},
10867 {5200, 40},
10868 {5220, 44},
10869 {5240, 48},
10870 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
10871 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
10872 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
10873 {5320, 64, LIBIPW_CH_PASSIVE_ONLY}},
10874 },
10875
10876 { /* Rest of World */
10877 "ZZD",
10878 .bg_channels = 13,
10879 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10880 {2427, 4}, {2432, 5}, {2437, 6},
10881 {2442, 7}, {2447, 8}, {2452, 9},
10882 {2457, 10}, {2462, 11}, {2467, 12},
10883 {2472, 13}},
10884 },
10885
10886 { /* Custom USA & Europe & High */
10887 "ZZA",
10888 .bg_channels = 11,
10889 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10890 {2427, 4}, {2432, 5}, {2437, 6},
10891 {2442, 7}, {2447, 8}, {2452, 9},
10892 {2457, 10}, {2462, 11}},
10893 .a_channels = 13,
10894 .a = {{5180, 36},
10895 {5200, 40},
10896 {5220, 44},
10897 {5240, 48},
10898 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
10899 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
10900 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
10901 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
10902 {5745, 149},
10903 {5765, 153},
10904 {5785, 157},
10905 {5805, 161},
10906 {5825, 165}},
10907 },
10908
10909 { /* Custom NA & Europe */
10910 "ZZB",
10911 .bg_channels = 11,
10912 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10913 {2427, 4}, {2432, 5}, {2437, 6},
10914 {2442, 7}, {2447, 8}, {2452, 9},
10915 {2457, 10}, {2462, 11}},
10916 .a_channels = 13,
10917 .a = {{5180, 36},
10918 {5200, 40},
10919 {5220, 44},
10920 {5240, 48},
10921 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
10922 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
10923 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
10924 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
10925 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
10926 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
10927 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
10928 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
10929 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
10930 },
10931
10932 { /* Custom Japan */
10933 "ZZC",
10934 .bg_channels = 11,
10935 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10936 {2427, 4}, {2432, 5}, {2437, 6},
10937 {2442, 7}, {2447, 8}, {2452, 9},
10938 {2457, 10}, {2462, 11}},
10939 .a_channels = 4,
10940 .a = {{5170, 34}, {5190, 38},
10941 {5210, 42}, {5230, 46}},
10942 },
10943
10944 { /* Custom */
10945 "ZZM",
10946 .bg_channels = 11,
10947 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10948 {2427, 4}, {2432, 5}, {2437, 6},
10949 {2442, 7}, {2447, 8}, {2452, 9},
10950 {2457, 10}, {2462, 11}},
10951 },
10952
10953 { /* Europe */
10954 "ZZE",
10955 .bg_channels = 13,
10956 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10957 {2427, 4}, {2432, 5}, {2437, 6},
10958 {2442, 7}, {2447, 8}, {2452, 9},
10959 {2457, 10}, {2462, 11}, {2467, 12},
10960 {2472, 13}},
10961 .a_channels = 19,
10962 .a = {{5180, 36},
10963 {5200, 40},
10964 {5220, 44},
10965 {5240, 48},
10966 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
10967 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
10968 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
10969 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
10970 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
10971 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
10972 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
10973 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
10974 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
10975 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
10976 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
10977 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
10978 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
10979 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
10980 {5700, 140, LIBIPW_CH_PASSIVE_ONLY}},
10981 },
10982
10983 { /* Custom Japan */
10984 "ZZJ",
10985 .bg_channels = 14,
10986 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10987 {2427, 4}, {2432, 5}, {2437, 6},
10988 {2442, 7}, {2447, 8}, {2452, 9},
10989 {2457, 10}, {2462, 11}, {2467, 12},
10990 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY}},
10991 .a_channels = 4,
10992 .a = {{5170, 34}, {5190, 38},
10993 {5210, 42}, {5230, 46}},
10994 },
10995
10996 { /* Rest of World */
10997 "ZZR",
10998 .bg_channels = 14,
10999 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11000 {2427, 4}, {2432, 5}, {2437, 6},
11001 {2442, 7}, {2447, 8}, {2452, 9},
11002 {2457, 10}, {2462, 11}, {2467, 12},
11003 {2472, 13}, {2484, 14, LIBIPW_CH_B_ONLY |
11004 LIBIPW_CH_PASSIVE_ONLY}},
11005 },
11006
11007 { /* High Band */
11008 "ZZH",
11009 .bg_channels = 13,
11010 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11011 {2427, 4}, {2432, 5}, {2437, 6},
11012 {2442, 7}, {2447, 8}, {2452, 9},
11013 {2457, 10}, {2462, 11},
11014 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11015 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
11016 .a_channels = 4,
11017 .a = {{5745, 149}, {5765, 153},
11018 {5785, 157}, {5805, 161}},
11019 },
11020
11021 { /* Custom Europe */
11022 "ZZG",
11023 .bg_channels = 13,
11024 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11025 {2427, 4}, {2432, 5}, {2437, 6},
11026 {2442, 7}, {2447, 8}, {2452, 9},
11027 {2457, 10}, {2462, 11},
11028 {2467, 12}, {2472, 13}},
11029 .a_channels = 4,
11030 .a = {{5180, 36}, {5200, 40},
11031 {5220, 44}, {5240, 48}},
11032 },
11033
11034 { /* Europe */
11035 "ZZK",
11036 .bg_channels = 13,
11037 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11038 {2427, 4}, {2432, 5}, {2437, 6},
11039 {2442, 7}, {2447, 8}, {2452, 9},
11040 {2457, 10}, {2462, 11},
11041 {2467, 12, LIBIPW_CH_PASSIVE_ONLY},
11042 {2472, 13, LIBIPW_CH_PASSIVE_ONLY}},
11043 .a_channels = 24,
11044 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11045 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11046 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11047 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11048 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11049 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11050 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11051 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11052 {5500, 100, LIBIPW_CH_PASSIVE_ONLY},
11053 {5520, 104, LIBIPW_CH_PASSIVE_ONLY},
11054 {5540, 108, LIBIPW_CH_PASSIVE_ONLY},
11055 {5560, 112, LIBIPW_CH_PASSIVE_ONLY},
11056 {5580, 116, LIBIPW_CH_PASSIVE_ONLY},
11057 {5600, 120, LIBIPW_CH_PASSIVE_ONLY},
11058 {5620, 124, LIBIPW_CH_PASSIVE_ONLY},
11059 {5640, 128, LIBIPW_CH_PASSIVE_ONLY},
11060 {5660, 132, LIBIPW_CH_PASSIVE_ONLY},
11061 {5680, 136, LIBIPW_CH_PASSIVE_ONLY},
11062 {5700, 140, LIBIPW_CH_PASSIVE_ONLY},
11063 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11064 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11065 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11066 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11067 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
11068 },
11069
11070 { /* Europe */
11071 "ZZL",
11072 .bg_channels = 11,
11073 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11074 {2427, 4}, {2432, 5}, {2437, 6},
11075 {2442, 7}, {2447, 8}, {2452, 9},
11076 {2457, 10}, {2462, 11}},
11077 .a_channels = 13,
11078 .a = {{5180, 36, LIBIPW_CH_PASSIVE_ONLY},
11079 {5200, 40, LIBIPW_CH_PASSIVE_ONLY},
11080 {5220, 44, LIBIPW_CH_PASSIVE_ONLY},
11081 {5240, 48, LIBIPW_CH_PASSIVE_ONLY},
11082 {5260, 52, LIBIPW_CH_PASSIVE_ONLY},
11083 {5280, 56, LIBIPW_CH_PASSIVE_ONLY},
11084 {5300, 60, LIBIPW_CH_PASSIVE_ONLY},
11085 {5320, 64, LIBIPW_CH_PASSIVE_ONLY},
11086 {5745, 149, LIBIPW_CH_PASSIVE_ONLY},
11087 {5765, 153, LIBIPW_CH_PASSIVE_ONLY},
11088 {5785, 157, LIBIPW_CH_PASSIVE_ONLY},
11089 {5805, 161, LIBIPW_CH_PASSIVE_ONLY},
11090 {5825, 165, LIBIPW_CH_PASSIVE_ONLY}},
11091 }
11092 };
11093
ipw_set_geo(struct ipw_priv * priv)11094 static void ipw_set_geo(struct ipw_priv *priv)
11095 {
11096 int j;
11097
11098 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11099 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11100 ipw_geos[j].name, 3))
11101 break;
11102 }
11103
11104 if (j == ARRAY_SIZE(ipw_geos)) {
11105 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11106 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11107 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11108 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
11109 j = 0;
11110 }
11111
11112 libipw_set_geo(priv->ieee, &ipw_geos[j]);
11113 }
11114
11115 #define MAX_HW_RESTARTS 5
ipw_up(struct ipw_priv * priv)11116 static int ipw_up(struct ipw_priv *priv)
11117 {
11118 int rc, i;
11119
11120 /* Age scan list entries found before suspend */
11121 if (priv->suspend_time) {
11122 libipw_networks_age(priv->ieee, priv->suspend_time);
11123 priv->suspend_time = 0;
11124 }
11125
11126 if (priv->status & STATUS_EXIT_PENDING)
11127 return -EIO;
11128
11129 if (cmdlog && !priv->cmdlog) {
11130 priv->cmdlog = kzalloc_objs(*priv->cmdlog, cmdlog);
11131 if (priv->cmdlog == NULL) {
11132 IPW_ERROR("Error allocating %d command log entries.\n",
11133 cmdlog);
11134 return -ENOMEM;
11135 } else {
11136 priv->cmdlog_len = cmdlog;
11137 }
11138 }
11139
11140 for (i = 0; i < MAX_HW_RESTARTS; i++) {
11141 /* Load the microcode, firmware, and eeprom.
11142 * Also start the clocks. */
11143 rc = ipw_load(priv);
11144 if (rc) {
11145 IPW_ERROR("Unable to load firmware: %d\n", rc);
11146 return rc;
11147 }
11148
11149 ipw_init_ordinals(priv);
11150 if (!(priv->config & CFG_CUSTOM_MAC))
11151 eeprom_parse_mac(priv, priv->mac_addr);
11152 eth_hw_addr_set(priv->net_dev, priv->mac_addr);
11153
11154 ipw_set_geo(priv);
11155
11156 if (priv->status & STATUS_RF_KILL_SW) {
11157 IPW_WARNING("Radio disabled by module parameter.\n");
11158 return 0;
11159 } else if (rf_kill_active(priv)) {
11160 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11161 "Kill switch must be turned off for "
11162 "wireless networking to work.\n");
11163 schedule_delayed_work(&priv->rf_kill, 2 * HZ);
11164 return 0;
11165 }
11166
11167 rc = ipw_config(priv);
11168 if (!rc) {
11169 IPW_DEBUG_INFO("Configured device on count %i\n", i);
11170
11171 /* If configure to try and auto-associate, kick
11172 * off a scan. */
11173 schedule_delayed_work(&priv->request_scan, 0);
11174
11175 return 0;
11176 }
11177
11178 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
11179 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11180 i, MAX_HW_RESTARTS);
11181
11182 /* We had an error bringing up the hardware, so take it
11183 * all the way back down so we can try again */
11184 ipw_down(priv);
11185 }
11186
11187 /* tried to restart and config the device for as long as our
11188 * patience could withstand */
11189 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
11190
11191 return -EIO;
11192 }
11193
ipw_bg_up(struct work_struct * work)11194 static void ipw_bg_up(struct work_struct *work)
11195 {
11196 struct ipw_priv *priv =
11197 container_of(work, struct ipw_priv, up);
11198 mutex_lock(&priv->mutex);
11199 ipw_up(priv);
11200 mutex_unlock(&priv->mutex);
11201 }
11202
ipw_deinit(struct ipw_priv * priv)11203 static void ipw_deinit(struct ipw_priv *priv)
11204 {
11205 int i;
11206
11207 if (priv->status & STATUS_SCANNING) {
11208 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11209 ipw_abort_scan(priv);
11210 }
11211
11212 if (priv->status & STATUS_ASSOCIATED) {
11213 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11214 ipw_disassociate(priv);
11215 }
11216
11217 ipw_led_shutdown(priv);
11218
11219 /* Wait up to 1s for status to change to not scanning and not
11220 * associated (disassociation can take a while for a ful 802.11
11221 * exchange */
11222 for (i = 1000; i && (priv->status &
11223 (STATUS_DISASSOCIATING |
11224 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11225 udelay(10);
11226
11227 if (priv->status & (STATUS_DISASSOCIATING |
11228 STATUS_ASSOCIATED | STATUS_SCANNING))
11229 IPW_DEBUG_INFO("Still associated or scanning...\n");
11230 else
11231 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11232
11233 /* Attempt to disable the card */
11234 ipw_send_card_disable(priv, 0);
11235
11236 priv->status &= ~STATUS_INIT;
11237 }
11238
ipw_down(struct ipw_priv * priv)11239 static void ipw_down(struct ipw_priv *priv)
11240 {
11241 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11242
11243 priv->status |= STATUS_EXIT_PENDING;
11244
11245 if (ipw_is_init(priv))
11246 ipw_deinit(priv);
11247
11248 /* Wipe out the EXIT_PENDING status bit if we are not actually
11249 * exiting the module */
11250 if (!exit_pending)
11251 priv->status &= ~STATUS_EXIT_PENDING;
11252
11253 /* tell the device to stop sending interrupts */
11254 ipw_disable_interrupts(priv);
11255
11256 /* Clear all bits but the RF Kill */
11257 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
11258 netif_carrier_off(priv->net_dev);
11259
11260 ipw_stop_nic(priv);
11261
11262 ipw_led_radio_off(priv);
11263 }
11264
ipw_bg_down(struct work_struct * work)11265 static void ipw_bg_down(struct work_struct *work)
11266 {
11267 struct ipw_priv *priv =
11268 container_of(work, struct ipw_priv, down);
11269 mutex_lock(&priv->mutex);
11270 ipw_down(priv);
11271 mutex_unlock(&priv->mutex);
11272 }
11273
ipw_wdev_init(struct net_device * dev)11274 static int ipw_wdev_init(struct net_device *dev)
11275 {
11276 int i, rc = 0;
11277 struct ipw_priv *priv = libipw_priv(dev);
11278 const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
11279 struct wireless_dev *wdev = &priv->ieee->wdev;
11280
11281 memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
11282
11283 /* fill-out priv->ieee->bg_band */
11284 if (geo->bg_channels) {
11285 struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
11286
11287 bg_band->band = NL80211_BAND_2GHZ;
11288 bg_band->n_channels = geo->bg_channels;
11289 bg_band->channels = kzalloc_objs(struct ieee80211_channel,
11290 geo->bg_channels);
11291 if (!bg_band->channels) {
11292 rc = -ENOMEM;
11293 goto out;
11294 }
11295 /* translate geo->bg to bg_band.channels */
11296 for (i = 0; i < geo->bg_channels; i++) {
11297 bg_band->channels[i].band = NL80211_BAND_2GHZ;
11298 bg_band->channels[i].center_freq = geo->bg[i].freq;
11299 bg_band->channels[i].hw_value = geo->bg[i].channel;
11300 bg_band->channels[i].max_power = geo->bg[i].max_power;
11301 if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11302 bg_band->channels[i].flags |=
11303 IEEE80211_CHAN_NO_IR;
11304 if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
11305 bg_band->channels[i].flags |=
11306 IEEE80211_CHAN_NO_IR;
11307 if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
11308 bg_band->channels[i].flags |=
11309 IEEE80211_CHAN_RADAR;
11310 /* No equivalent for LIBIPW_CH_80211H_RULES,
11311 LIBIPW_CH_UNIFORM_SPREADING, or
11312 LIBIPW_CH_B_ONLY... */
11313 }
11314 /* point at bitrate info */
11315 bg_band->bitrates = ipw2200_bg_rates;
11316 bg_band->n_bitrates = ipw2200_num_bg_rates;
11317
11318 wdev->wiphy->bands[NL80211_BAND_2GHZ] = bg_band;
11319 }
11320
11321 /* fill-out priv->ieee->a_band */
11322 if (geo->a_channels) {
11323 struct ieee80211_supported_band *a_band = &priv->ieee->a_band;
11324
11325 a_band->band = NL80211_BAND_5GHZ;
11326 a_band->n_channels = geo->a_channels;
11327 a_band->channels = kzalloc_objs(struct ieee80211_channel,
11328 geo->a_channels);
11329 if (!a_band->channels) {
11330 rc = -ENOMEM;
11331 goto out;
11332 }
11333 /* translate geo->a to a_band.channels */
11334 for (i = 0; i < geo->a_channels; i++) {
11335 a_band->channels[i].band = NL80211_BAND_5GHZ;
11336 a_band->channels[i].center_freq = geo->a[i].freq;
11337 a_band->channels[i].hw_value = geo->a[i].channel;
11338 a_band->channels[i].max_power = geo->a[i].max_power;
11339 if (geo->a[i].flags & LIBIPW_CH_PASSIVE_ONLY)
11340 a_band->channels[i].flags |=
11341 IEEE80211_CHAN_NO_IR;
11342 if (geo->a[i].flags & LIBIPW_CH_NO_IBSS)
11343 a_band->channels[i].flags |=
11344 IEEE80211_CHAN_NO_IR;
11345 if (geo->a[i].flags & LIBIPW_CH_RADAR_DETECT)
11346 a_band->channels[i].flags |=
11347 IEEE80211_CHAN_RADAR;
11348 /* No equivalent for LIBIPW_CH_80211H_RULES,
11349 LIBIPW_CH_UNIFORM_SPREADING, or
11350 LIBIPW_CH_B_ONLY... */
11351 }
11352 /* point at bitrate info */
11353 a_band->bitrates = ipw2200_a_rates;
11354 a_band->n_bitrates = ipw2200_num_a_rates;
11355
11356 wdev->wiphy->bands[NL80211_BAND_5GHZ] = a_band;
11357 }
11358
11359 wdev->wiphy->cipher_suites = ipw_cipher_suites;
11360 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(ipw_cipher_suites);
11361
11362 set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
11363
11364 /* With that information in place, we can now register the wiphy... */
11365 rc = wiphy_register(wdev->wiphy);
11366 if (rc)
11367 goto out;
11368
11369 return 0;
11370 out:
11371 kfree(priv->ieee->a_band.channels);
11372 kfree(priv->ieee->bg_band.channels);
11373 return rc;
11374 }
11375
11376 /* PCI driver stuff */
11377 static const struct pci_device_id card_ids[] = {
11378 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x8086, 0x2701) },
11379 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x8086, 0x2702) },
11380 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x8086, 0x2711) },
11381 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x8086, 0x2712) },
11382 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x8086, 0x2721) },
11383 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x8086, 0x2722) },
11384 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x8086, 0x2731) },
11385 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x8086, 0x2732) },
11386 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x8086, 0x2741) },
11387 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x103c, 0x2741) },
11388 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x8086, 0x2742) },
11389 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x8086, 0x2751) },
11390 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x8086, 0x2752) },
11391 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x8086, 0x2753) },
11392 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x8086, 0x2754) },
11393 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x8086, 0x2761) },
11394 { PCI_VDEVICE_SUB(INTEL, 0x1043, 0x8086, 0x2762) },
11395
11396 /*
11397 * This ID conflicts with i40e, but the devices can be differentiated
11398 * because i40e devices use PCI_CLASS_NETWORK_ETHERNET and ipw2200
11399 * devices use PCI_CLASS_NETWORK_OTHER.
11400 */
11401 {
11402 PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x104f),
11403 .class = PCI_CLASS_NETWORK_OTHER << 8,
11404 .class_mask = 0xffff00,
11405 },
11406 { PCI_VDEVICE(INTEL, 0x4220) }, /* BG */
11407 { PCI_VDEVICE(INTEL, 0x4221) }, /* BG */
11408 { PCI_VDEVICE(INTEL, 0x4223) }, /* ABG */
11409 { PCI_VDEVICE(INTEL, 0x4224) }, /* ABG */
11410
11411 /* required last entry */
11412 { }
11413 };
11414
11415 MODULE_DEVICE_TABLE(pci, card_ids);
11416
11417 static struct attribute *ipw_sysfs_entries[] = {
11418 &dev_attr_rf_kill.attr,
11419 &dev_attr_direct_dword.attr,
11420 &dev_attr_indirect_byte.attr,
11421 &dev_attr_indirect_dword.attr,
11422 &dev_attr_mem_gpio_reg.attr,
11423 &dev_attr_command_event_reg.attr,
11424 &dev_attr_nic_type.attr,
11425 &dev_attr_status.attr,
11426 &dev_attr_cfg.attr,
11427 &dev_attr_error.attr,
11428 &dev_attr_event_log.attr,
11429 &dev_attr_cmd_log.attr,
11430 &dev_attr_eeprom_delay.attr,
11431 &dev_attr_ucode_version.attr,
11432 &dev_attr_rtc.attr,
11433 &dev_attr_scan_age.attr,
11434 &dev_attr_led.attr,
11435 &dev_attr_speed_scan.attr,
11436 &dev_attr_net_stats.attr,
11437 &dev_attr_channels.attr,
11438 #ifdef CONFIG_IPW2200_PROMISCUOUS
11439 &dev_attr_rtap_iface.attr,
11440 &dev_attr_rtap_filter.attr,
11441 #endif
11442 NULL
11443 };
11444
11445 static const struct attribute_group ipw_attribute_group = {
11446 .name = NULL, /* put in device directory */
11447 .attrs = ipw_sysfs_entries,
11448 };
11449
11450 #ifdef CONFIG_IPW2200_PROMISCUOUS
ipw_prom_open(struct net_device * dev)11451 static int ipw_prom_open(struct net_device *dev)
11452 {
11453 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
11454 struct ipw_priv *priv = prom_priv->priv;
11455
11456 IPW_DEBUG_INFO("prom dev->open\n");
11457 netif_carrier_off(dev);
11458
11459 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11460 priv->sys_config.accept_all_data_frames = 1;
11461 priv->sys_config.accept_non_directed_frames = 1;
11462 priv->sys_config.accept_all_mgmt_bcpr = 1;
11463 priv->sys_config.accept_all_mgmt_frames = 1;
11464
11465 ipw_send_system_config(priv);
11466 }
11467
11468 return 0;
11469 }
11470
ipw_prom_stop(struct net_device * dev)11471 static int ipw_prom_stop(struct net_device *dev)
11472 {
11473 struct ipw_prom_priv *prom_priv = libipw_priv(dev);
11474 struct ipw_priv *priv = prom_priv->priv;
11475
11476 IPW_DEBUG_INFO("prom dev->stop\n");
11477
11478 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11479 priv->sys_config.accept_all_data_frames = 0;
11480 priv->sys_config.accept_non_directed_frames = 0;
11481 priv->sys_config.accept_all_mgmt_bcpr = 0;
11482 priv->sys_config.accept_all_mgmt_frames = 0;
11483
11484 ipw_send_system_config(priv);
11485 }
11486
11487 return 0;
11488 }
11489
ipw_prom_hard_start_xmit(struct sk_buff * skb,struct net_device * dev)11490 static netdev_tx_t ipw_prom_hard_start_xmit(struct sk_buff *skb,
11491 struct net_device *dev)
11492 {
11493 IPW_DEBUG_INFO("prom dev->xmit\n");
11494 dev_kfree_skb(skb);
11495 return NETDEV_TX_OK;
11496 }
11497
11498 static const struct net_device_ops ipw_prom_netdev_ops = {
11499 .ndo_open = ipw_prom_open,
11500 .ndo_stop = ipw_prom_stop,
11501 .ndo_start_xmit = ipw_prom_hard_start_xmit,
11502 .ndo_set_mac_address = eth_mac_addr,
11503 .ndo_validate_addr = eth_validate_addr,
11504 };
11505
ipw_prom_alloc(struct ipw_priv * priv)11506 static int ipw_prom_alloc(struct ipw_priv *priv)
11507 {
11508 int rc = 0;
11509
11510 if (priv->prom_net_dev)
11511 return -EPERM;
11512
11513 priv->prom_net_dev = alloc_libipw(sizeof(struct ipw_prom_priv), 1);
11514 if (priv->prom_net_dev == NULL)
11515 return -ENOMEM;
11516
11517 priv->prom_priv = libipw_priv(priv->prom_net_dev);
11518 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11519 priv->prom_priv->priv = priv;
11520
11521 strcpy(priv->prom_net_dev->name, "rtap%d");
11522 eth_hw_addr_set(priv->prom_net_dev, priv->mac_addr);
11523
11524 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
11525 priv->prom_net_dev->netdev_ops = &ipw_prom_netdev_ops;
11526
11527 priv->prom_net_dev->min_mtu = 68;
11528 priv->prom_net_dev->max_mtu = LIBIPW_DATA_LEN;
11529
11530 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
11531 SET_NETDEV_DEV(priv->prom_net_dev, &priv->pci_dev->dev);
11532
11533 rc = register_netdev(priv->prom_net_dev);
11534 if (rc) {
11535 free_libipw(priv->prom_net_dev, 1);
11536 priv->prom_net_dev = NULL;
11537 return rc;
11538 }
11539
11540 return 0;
11541 }
11542
ipw_prom_free(struct ipw_priv * priv)11543 static void ipw_prom_free(struct ipw_priv *priv)
11544 {
11545 if (!priv->prom_net_dev)
11546 return;
11547
11548 unregister_netdev(priv->prom_net_dev);
11549 free_libipw(priv->prom_net_dev, 1);
11550
11551 priv->prom_net_dev = NULL;
11552 }
11553
11554 #endif
11555
11556 static const struct net_device_ops ipw_netdev_ops = {
11557 .ndo_open = ipw_net_open,
11558 .ndo_stop = ipw_net_stop,
11559 .ndo_set_rx_mode = ipw_net_set_multicast_list,
11560 .ndo_set_mac_address = ipw_net_set_mac_address,
11561 .ndo_start_xmit = libipw_xmit,
11562 .ndo_validate_addr = eth_validate_addr,
11563 };
11564
ipw_pci_probe(struct pci_dev * pdev,const struct pci_device_id * ent)11565 static int ipw_pci_probe(struct pci_dev *pdev,
11566 const struct pci_device_id *ent)
11567 {
11568 int err = 0;
11569 struct net_device *net_dev;
11570 void __iomem *base;
11571 u32 length, val;
11572 struct ipw_priv *priv;
11573 int i;
11574
11575 net_dev = alloc_libipw(sizeof(struct ipw_priv), 0);
11576 if (net_dev == NULL) {
11577 err = -ENOMEM;
11578 goto out;
11579 }
11580
11581 priv = libipw_priv(net_dev);
11582 priv->ieee = netdev_priv(net_dev);
11583
11584 priv->net_dev = net_dev;
11585 priv->pci_dev = pdev;
11586 ipw_debug_level = debug;
11587 spin_lock_init(&priv->irq_lock);
11588 spin_lock_init(&priv->lock);
11589 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11590 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
11591
11592 mutex_init(&priv->mutex);
11593 if (pci_enable_device(pdev)) {
11594 err = -ENODEV;
11595 goto out_free_libipw;
11596 }
11597
11598 pci_set_master(pdev);
11599
11600 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
11601 if (!err)
11602 err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
11603 if (err) {
11604 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11605 goto out_pci_disable_device;
11606 }
11607
11608 pci_set_drvdata(pdev, priv);
11609
11610 err = pci_request_regions(pdev, DRV_NAME);
11611 if (err)
11612 goto out_pci_disable_device;
11613
11614 /* We disable the RETRY_TIMEOUT register (0x41) to keep
11615 * PCI Tx retries from interfering with C3 CPU state */
11616 pci_read_config_dword(pdev, 0x40, &val);
11617 if ((val & 0x0000ff00) != 0)
11618 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11619
11620 length = pci_resource_len(pdev, 0);
11621 priv->hw_len = length;
11622
11623 base = pci_ioremap_bar(pdev, 0);
11624 if (!base) {
11625 err = -ENODEV;
11626 goto out_pci_release_regions;
11627 }
11628
11629 priv->hw_base = base;
11630 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11631 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11632
11633 ipw_setup_deferred_work(priv);
11634
11635 ipw_sw_reset(priv, 1);
11636
11637 err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv);
11638 if (err) {
11639 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11640 goto out_iounmap;
11641 }
11642
11643 SET_NETDEV_DEV(net_dev, &pdev->dev);
11644
11645 mutex_lock(&priv->mutex);
11646
11647 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11648 priv->ieee->set_security = shim__set_security;
11649 priv->ieee->is_queue_full = ipw_net_is_queue_full;
11650
11651 #ifdef CONFIG_IPW2200_QOS
11652 priv->ieee->is_qos_active = ipw_is_qos_active;
11653 priv->ieee->handle_probe_response = ipw_handle_beacon;
11654 priv->ieee->handle_beacon = ipw_handle_probe_response;
11655 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
11656 #endif /* CONFIG_IPW2200_QOS */
11657
11658 priv->ieee->perfect_rssi = -20;
11659 priv->ieee->worst_rssi = -85;
11660
11661 net_dev->netdev_ops = &ipw_netdev_ops;
11662 priv->ieee->spy_enabled = true;
11663 net_dev->wireless_handlers = &ipw_wx_handler_def;
11664 net_dev->ethtool_ops = &ipw_ethtool_ops;
11665
11666 net_dev->min_mtu = 68;
11667 net_dev->max_mtu = LIBIPW_DATA_LEN;
11668
11669 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11670 if (err) {
11671 IPW_ERROR("failed to create sysfs device attributes\n");
11672 mutex_unlock(&priv->mutex);
11673 goto out_release_irq;
11674 }
11675
11676 if (ipw_up(priv)) {
11677 mutex_unlock(&priv->mutex);
11678 err = -EIO;
11679 goto out_remove_sysfs;
11680 }
11681
11682 mutex_unlock(&priv->mutex);
11683
11684 err = ipw_wdev_init(net_dev);
11685 if (err) {
11686 IPW_ERROR("failed to register wireless device\n");
11687 goto out_remove_sysfs;
11688 }
11689
11690 err = register_netdev(net_dev);
11691 if (err) {
11692 IPW_ERROR("failed to register network device\n");
11693 goto out_unregister_wiphy;
11694 }
11695
11696 #ifdef CONFIG_IPW2200_PROMISCUOUS
11697 if (rtap_iface) {
11698 err = ipw_prom_alloc(priv);
11699 if (err) {
11700 IPW_ERROR("Failed to register promiscuous network "
11701 "device (error %d).\n", err);
11702 unregister_netdev(priv->net_dev);
11703 goto out_unregister_wiphy;
11704 }
11705 }
11706 #endif
11707
11708 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11709 "channels, %d 802.11a channels)\n",
11710 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11711 priv->ieee->geo.a_channels);
11712
11713 return 0;
11714
11715 out_unregister_wiphy:
11716 wiphy_unregister(priv->ieee->wdev.wiphy);
11717 kfree(priv->ieee->a_band.channels);
11718 kfree(priv->ieee->bg_band.channels);
11719 out_remove_sysfs:
11720 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11721 out_release_irq:
11722 free_irq(pdev->irq, priv);
11723 out_iounmap:
11724 iounmap(priv->hw_base);
11725 out_pci_release_regions:
11726 pci_release_regions(pdev);
11727 out_pci_disable_device:
11728 pci_disable_device(pdev);
11729 out_free_libipw:
11730 free_libipw(priv->net_dev, 0);
11731 out:
11732 return err;
11733 }
11734
ipw_pci_remove(struct pci_dev * pdev)11735 static void ipw_pci_remove(struct pci_dev *pdev)
11736 {
11737 struct ipw_priv *priv = pci_get_drvdata(pdev);
11738 struct list_head *p, *q;
11739 int i;
11740
11741 if (!priv)
11742 return;
11743
11744 mutex_lock(&priv->mutex);
11745
11746 priv->status |= STATUS_EXIT_PENDING;
11747 ipw_down(priv);
11748 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11749
11750 mutex_unlock(&priv->mutex);
11751
11752 unregister_netdev(priv->net_dev);
11753
11754 if (priv->rxq) {
11755 ipw_rx_queue_free(priv, priv->rxq);
11756 priv->rxq = NULL;
11757 }
11758 ipw_tx_queue_free(priv);
11759
11760 if (priv->cmdlog) {
11761 kfree(priv->cmdlog);
11762 priv->cmdlog = NULL;
11763 }
11764
11765 /* make sure all works are inactive */
11766 cancel_delayed_work_sync(&priv->adhoc_check);
11767 cancel_work_sync(&priv->associate);
11768 cancel_work_sync(&priv->disassociate);
11769 cancel_work_sync(&priv->system_config);
11770 cancel_work_sync(&priv->rx_replenish);
11771 cancel_work_sync(&priv->adapter_restart);
11772 cancel_delayed_work_sync(&priv->rf_kill);
11773 cancel_work_sync(&priv->up);
11774 cancel_work_sync(&priv->down);
11775 cancel_delayed_work_sync(&priv->request_scan);
11776 cancel_delayed_work_sync(&priv->request_direct_scan);
11777 cancel_delayed_work_sync(&priv->request_passive_scan);
11778 cancel_delayed_work_sync(&priv->scan_event);
11779 cancel_delayed_work_sync(&priv->gather_stats);
11780 cancel_work_sync(&priv->abort_scan);
11781 cancel_work_sync(&priv->roam);
11782 cancel_delayed_work_sync(&priv->scan_check);
11783 cancel_work_sync(&priv->link_up);
11784 cancel_work_sync(&priv->link_down);
11785 cancel_delayed_work_sync(&priv->led_link_on);
11786 cancel_delayed_work_sync(&priv->led_link_off);
11787 cancel_delayed_work_sync(&priv->led_act_off);
11788 cancel_work_sync(&priv->merge_networks);
11789
11790 /* Free MAC hash list for ADHOC */
11791 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11792 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
11793 list_del(p);
11794 kfree(list_entry(p, struct ipw_ibss_seq, list));
11795 }
11796 }
11797
11798 kfree(priv->error);
11799 priv->error = NULL;
11800
11801 #ifdef CONFIG_IPW2200_PROMISCUOUS
11802 ipw_prom_free(priv);
11803 #endif
11804
11805 free_irq(pdev->irq, priv);
11806 iounmap(priv->hw_base);
11807 pci_release_regions(pdev);
11808 pci_disable_device(pdev);
11809 /* wiphy_unregister needs to be here, before free_libipw */
11810 wiphy_unregister(priv->ieee->wdev.wiphy);
11811 kfree(priv->ieee->a_band.channels);
11812 kfree(priv->ieee->bg_band.channels);
11813 free_libipw(priv->net_dev, 0);
11814 free_firmware();
11815 }
11816
ipw_pci_suspend(struct device * dev_d)11817 static int __maybe_unused ipw_pci_suspend(struct device *dev_d)
11818 {
11819 struct ipw_priv *priv = dev_get_drvdata(dev_d);
11820 struct net_device *dev = priv->net_dev;
11821
11822 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11823
11824 /* Take down the device; powers it off, etc. */
11825 ipw_down(priv);
11826
11827 /* Remove the PRESENT state of the device */
11828 netif_device_detach(dev);
11829
11830 priv->suspend_at = ktime_get_boottime_seconds();
11831
11832 return 0;
11833 }
11834
ipw_pci_resume(struct device * dev_d)11835 static int __maybe_unused ipw_pci_resume(struct device *dev_d)
11836 {
11837 struct pci_dev *pdev = to_pci_dev(dev_d);
11838 struct ipw_priv *priv = pci_get_drvdata(pdev);
11839 struct net_device *dev = priv->net_dev;
11840 u32 val;
11841
11842 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11843
11844 /*
11845 * Suspend/Resume resets the PCI configuration space, so we have to
11846 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11847 * from interfering with C3 CPU state. pci_restore_state won't help
11848 * here since it only restores the first 64 bytes pci config header.
11849 */
11850 pci_read_config_dword(pdev, 0x40, &val);
11851 if ((val & 0x0000ff00) != 0)
11852 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11853
11854 /* Set the device back into the PRESENT state; this will also wake
11855 * the queue of needed */
11856 netif_device_attach(dev);
11857
11858 priv->suspend_time = ktime_get_boottime_seconds() - priv->suspend_at;
11859
11860 /* Bring the device back up */
11861 schedule_work(&priv->up);
11862
11863 return 0;
11864 }
11865
ipw_pci_shutdown(struct pci_dev * pdev)11866 static void ipw_pci_shutdown(struct pci_dev *pdev)
11867 {
11868 struct ipw_priv *priv = pci_get_drvdata(pdev);
11869
11870 /* Take down the device; powers it off, etc. */
11871 ipw_down(priv);
11872
11873 pci_disable_device(pdev);
11874 }
11875
11876 static SIMPLE_DEV_PM_OPS(ipw_pci_pm_ops, ipw_pci_suspend, ipw_pci_resume);
11877
11878 /* driver initialization stuff */
11879 static struct pci_driver ipw_driver = {
11880 .name = DRV_NAME,
11881 .id_table = card_ids,
11882 .probe = ipw_pci_probe,
11883 .remove = ipw_pci_remove,
11884 .driver.pm = &ipw_pci_pm_ops,
11885 .shutdown = ipw_pci_shutdown,
11886 };
11887
ipw_init(void)11888 static int __init ipw_init(void)
11889 {
11890 int ret;
11891
11892 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11893 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11894
11895 ret = pci_register_driver(&ipw_driver);
11896 if (ret) {
11897 IPW_ERROR("Unable to initialize PCI module\n");
11898 return ret;
11899 }
11900
11901 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
11902 if (ret) {
11903 IPW_ERROR("Unable to create driver sysfs file\n");
11904 pci_unregister_driver(&ipw_driver);
11905 return ret;
11906 }
11907
11908 return ret;
11909 }
11910
ipw_exit(void)11911 static void __exit ipw_exit(void)
11912 {
11913 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11914 pci_unregister_driver(&ipw_driver);
11915 }
11916
11917 module_param(disable, int, 0444);
11918 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11919
11920 module_param(associate, int, 0444);
11921 MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
11922
11923 module_param(auto_create, int, 0444);
11924 MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11925
11926 module_param_named(led, led_support, int, 0444);
11927 MODULE_PARM_DESC(led, "enable led control on some systems (default 1 on)");
11928
11929 module_param(debug, int, 0444);
11930 MODULE_PARM_DESC(debug, "debug output mask");
11931
11932 module_param_named(channel, default_channel, int, 0444);
11933 MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
11934
11935 #ifdef CONFIG_IPW2200_PROMISCUOUS
11936 module_param(rtap_iface, int, 0444);
11937 MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
11938 #endif
11939
11940 #ifdef CONFIG_IPW2200_QOS
11941 module_param(qos_enable, int, 0444);
11942 MODULE_PARM_DESC(qos_enable, "enable all QoS functionalities");
11943
11944 module_param(qos_burst_enable, int, 0444);
11945 MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11946
11947 module_param(qos_no_ack_mask, int, 0444);
11948 MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11949
11950 module_param(burst_duration_CCK, int, 0444);
11951 MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11952
11953 module_param(burst_duration_OFDM, int, 0444);
11954 MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11955 #endif /* CONFIG_IPW2200_QOS */
11956
11957 #ifdef CONFIG_IPW2200_MONITOR
11958 module_param_named(mode, network_mode, int, 0444);
11959 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11960 #else
11961 module_param_named(mode, network_mode, int, 0444);
11962 MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11963 #endif
11964
11965 module_param(bt_coexist, int, 0444);
11966 MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
11967
11968 module_param(hwcrypto, int, 0444);
11969 MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
11970
11971 module_param(cmdlog, int, 0444);
11972 MODULE_PARM_DESC(cmdlog,
11973 "allocate a ring buffer for logging firmware commands");
11974
11975 module_param(roaming, int, 0444);
11976 MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
11977
11978 module_param(antenna, int, 0444);
11979 MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
11980
11981 module_exit(ipw_exit);
11982 module_init(ipw_init);
11983