aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/ipw2200.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2005-11-09 11:34:36 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-11-09 11:34:36 -0500
commita7c243b544c0e9f6775c2607decaa59d54fb9e11 (patch)
tree86fdb4d2d6cef932af7497f28827e7d52b29e48c /drivers/net/wireless/ipw2200.c
parent7df446e7e043b2ba5fd5de42529f9d797e8b501a (diff)
parentf406db8cba6bbce42b96490e6d31bdec229ad994 (diff)
Merge branch 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik/netdev-2.6
Diffstat (limited to 'drivers/net/wireless/ipw2200.c')
-rw-r--r--drivers/net/wireless/ipw2200.c6609
1 files changed, 5258 insertions, 1351 deletions
diff --git a/drivers/net/wireless/ipw2200.c b/drivers/net/wireless/ipw2200.c
index 589aef8ba4e6..b0d195d1721a 100644
--- a/drivers/net/wireless/ipw2200.c
+++ b/drivers/net/wireless/ipw2200.c
@@ -1,6 +1,6 @@
1/****************************************************************************** 1/******************************************************************************
2 2
3 Copyright(c) 2003 - 2004 Intel Corporation. All rights reserved. 3 Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
4 4
5 802.11 status code portion of this file from ethereal-0.10.6: 5 802.11 status code portion of this file from ethereal-0.10.6:
6 Copyright 2000, Axis Communications AB 6 Copyright 2000, Axis Communications AB
@@ -33,29 +33,101 @@
33#include "ipw2200.h" 33#include "ipw2200.h"
34#include <linux/version.h> 34#include <linux/version.h>
35 35
36#define IPW2200_VERSION "1.0.0" 36#define IPW2200_VERSION "git-1.0.8"
37#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver" 37#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
38#define DRV_COPYRIGHT "Copyright(c) 2003-2004 Intel Corporation" 38#define DRV_COPYRIGHT "Copyright(c) 2003-2005 Intel Corporation"
39#define DRV_VERSION IPW2200_VERSION 39#define DRV_VERSION IPW2200_VERSION
40 40
41#define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
42
41MODULE_DESCRIPTION(DRV_DESCRIPTION); 43MODULE_DESCRIPTION(DRV_DESCRIPTION);
42MODULE_VERSION(DRV_VERSION); 44MODULE_VERSION(DRV_VERSION);
43MODULE_AUTHOR(DRV_COPYRIGHT); 45MODULE_AUTHOR(DRV_COPYRIGHT);
44MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
45 47
48static int cmdlog = 0;
46static int debug = 0; 49static int debug = 0;
47static int channel = 0; 50static int channel = 0;
48static char *ifname;
49static int mode = 0; 51static int mode = 0;
50 52
51static u32 ipw_debug_level; 53static u32 ipw_debug_level;
52static int associate = 1; 54static int associate = 1;
53static int auto_create = 1; 55static int auto_create = 1;
56static int led = 0;
54static int disable = 0; 57static int disable = 0;
58static int hwcrypto = 1;
55static const char ipw_modes[] = { 59static const char ipw_modes[] = {
56 'a', 'b', 'g', '?' 60 'a', 'b', 'g', '?'
57}; 61};
58 62
63#ifdef CONFIG_IPW_QOS
64static int qos_enable = 0;
65static int qos_burst_enable = 0;
66static int qos_no_ack_mask = 0;
67static int burst_duration_CCK = 0;
68static int burst_duration_OFDM = 0;
69
70static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
71 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
72 QOS_TX3_CW_MIN_OFDM},
73 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
74 QOS_TX3_CW_MAX_OFDM},
75 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
76 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
77 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
78 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
79};
80
81static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
82 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
83 QOS_TX3_CW_MIN_CCK},
84 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
85 QOS_TX3_CW_MAX_CCK},
86 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
87 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
88 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
89 QOS_TX3_TXOP_LIMIT_CCK}
90};
91
92static struct ieee80211_qos_parameters def_parameters_OFDM = {
93 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
94 DEF_TX3_CW_MIN_OFDM},
95 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
96 DEF_TX3_CW_MAX_OFDM},
97 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
98 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
99 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
100 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
101};
102
103static struct ieee80211_qos_parameters def_parameters_CCK = {
104 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
105 DEF_TX3_CW_MIN_CCK},
106 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
107 DEF_TX3_CW_MAX_CCK},
108 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
109 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
110 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
111 DEF_TX3_TXOP_LIMIT_CCK}
112};
113
114static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
115
116static int from_priority_to_tx_queue[] = {
117 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
118 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
119};
120
121static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
122
123static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
124 *qos_param);
125static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
126 *qos_param);
127#endif /* CONFIG_IPW_QOS */
128
129static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
130static void ipw_remove_current_network(struct ipw_priv *priv);
59static void ipw_rx(struct ipw_priv *priv); 131static void ipw_rx(struct ipw_priv *priv);
60static int ipw_queue_tx_reclaim(struct ipw_priv *priv, 132static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
61 struct clx2_tx_queue *txq, int qindex); 133 struct clx2_tx_queue *txq, int qindex);
@@ -69,42 +141,24 @@ static void ipw_tx_queue_free(struct ipw_priv *);
69static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *); 141static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
70static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *); 142static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
71static void ipw_rx_queue_replenish(void *); 143static void ipw_rx_queue_replenish(void *);
72
73static int ipw_up(struct ipw_priv *); 144static int ipw_up(struct ipw_priv *);
145static void ipw_bg_up(void *);
74static void ipw_down(struct ipw_priv *); 146static void ipw_down(struct ipw_priv *);
147static void ipw_bg_down(void *);
75static int ipw_config(struct ipw_priv *); 148static int ipw_config(struct ipw_priv *);
76static int init_supported_rates(struct ipw_priv *priv, 149static int init_supported_rates(struct ipw_priv *priv,
77 struct ipw_supported_rates *prates); 150 struct ipw_supported_rates *prates);
151static void ipw_set_hwcrypto_keys(struct ipw_priv *);
152static void ipw_send_wep_keys(struct ipw_priv *, int);
78 153
79static u8 band_b_active_channel[MAX_B_CHANNELS] = { 154static int ipw_is_valid_channel(struct ieee80211_device *, u8);
80 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0 155static int ipw_channel_to_index(struct ieee80211_device *, u8);
81}; 156static u8 ipw_freq_to_channel(struct ieee80211_device *, u32);
82static u8 band_a_active_channel[MAX_A_CHANNELS] = { 157static int ipw_set_geo(struct ieee80211_device *, const struct ieee80211_geo *);
83 36, 40, 44, 48, 149, 153, 157, 161, 165, 52, 56, 60, 64, 0 158static const struct ieee80211_geo *ipw_get_geo(struct ieee80211_device *);
84};
85 159
86static int is_valid_channel(int mode_mask, int channel) 160static int snprint_line(char *buf, size_t count,
87{ 161 const u8 * data, u32 len, u32 ofs)
88 int i;
89
90 if (!channel)
91 return 0;
92
93 if (mode_mask & IEEE_A)
94 for (i = 0; i < MAX_A_CHANNELS; i++)
95 if (band_a_active_channel[i] == channel)
96 return IEEE_A;
97
98 if (mode_mask & (IEEE_B | IEEE_G))
99 for (i = 0; i < MAX_B_CHANNELS; i++)
100 if (band_b_active_channel[i] == channel)
101 return mode_mask & (IEEE_B | IEEE_G);
102
103 return 0;
104}
105
106static char *snprint_line(char *buf, size_t count,
107 const u8 * data, u32 len, u32 ofs)
108{ 162{
109 int out, i, j, l; 163 int out, i, j, l;
110 char c; 164 char c;
@@ -135,7 +189,7 @@ static char *snprint_line(char *buf, size_t count,
135 out += snprintf(buf + out, count - out, " "); 189 out += snprintf(buf + out, count - out, " ");
136 } 190 }
137 191
138 return buf; 192 return out;
139} 193}
140 194
141static void printk_buf(int level, const u8 * data, u32 len) 195static void printk_buf(int level, const u8 * data, u32 len)
@@ -146,14 +200,33 @@ static void printk_buf(int level, const u8 * data, u32 len)
146 return; 200 return;
147 201
148 while (len) { 202 while (len) {
149 printk(KERN_DEBUG "%s\n", 203 snprint_line(line, sizeof(line), &data[ofs],
150 snprint_line(line, sizeof(line), &data[ofs], 204 min(len, 16U), ofs);
151 min(len, 16U), ofs)); 205 printk(KERN_DEBUG "%s\n", line);
152 ofs += 16; 206 ofs += 16;
153 len -= min(len, 16U); 207 len -= min(len, 16U);
154 } 208 }
155} 209}
156 210
211static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
212{
213 size_t out = size;
214 u32 ofs = 0;
215 int total = 0;
216
217 while (size && len) {
218 out = snprint_line(output, size, &data[ofs],
219 min_t(size_t, len, 16U), ofs);
220
221 ofs += 16;
222 output += out;
223 size -= out;
224 len -= min_t(size_t, len, 16U);
225 total += out;
226 }
227 return total;
228}
229
157static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg); 230static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
158#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b) 231#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
159 232
@@ -227,38 +300,42 @@ static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
227#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs) 300#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
228 301
229static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int); 302static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
230#define ipw_read_indirect(a, b, c, d) \ 303static inline void __ipw_read_indirect(const char *f, int l,
231 IPW_DEBUG_IO("%s %d: read_inddirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \ 304 struct ipw_priv *a, u32 b, u8 * c, int d)
232 _ipw_read_indirect(a, b, c, d) 305{
306 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
307 d);
308 _ipw_read_indirect(a, b, c, d);
309}
310
311#define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
233 312
234static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data, 313static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
235 int num); 314 int num);
236#define ipw_write_indirect(a, b, c, d) \ 315#define ipw_write_indirect(a, b, c, d) \
237 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \ 316 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
238 _ipw_write_indirect(a, b, c, d) 317 _ipw_write_indirect(a, b, c, d)
239 318
240/* indirect write s */ 319/* indirect write s */
241static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value) 320static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
242{ 321{
243 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value); 322 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
244 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg); 323 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
245 _ipw_write32(priv, CX2_INDIRECT_DATA, value); 324 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
246} 325}
247 326
248static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value) 327static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
249{ 328{
250 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); 329 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
251 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK); 330 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
252 _ipw_write8(priv, CX2_INDIRECT_DATA, value); 331 _ipw_write8(priv, IPW_INDIRECT_DATA, value);
253 IPW_DEBUG_IO(" reg = 0x%8lX : value = 0x%8X\n",
254 (unsigned long)(priv->hw_base + CX2_INDIRECT_DATA), value);
255} 332}
256 333
257static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value) 334static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
258{ 335{
259 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value); 336 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
260 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK); 337 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
261 _ipw_write16(priv, CX2_INDIRECT_DATA, value); 338 _ipw_write16(priv, IPW_INDIRECT_DATA, value);
262} 339}
263 340
264/* indirect read s */ 341/* indirect read s */
@@ -266,9 +343,9 @@ static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
266static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg) 343static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
267{ 344{
268 u32 word; 345 u32 word;
269 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK); 346 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
270 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg); 347 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
271 word = _ipw_read32(priv, CX2_INDIRECT_DATA); 348 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
272 return (word >> ((reg & 0x3) * 8)) & 0xff; 349 return (word >> ((reg & 0x3) * 8)) & 0xff;
273} 350}
274 351
@@ -278,8 +355,8 @@ static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
278 355
279 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg); 356 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
280 357
281 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg); 358 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
282 value = _ipw_read32(priv, CX2_INDIRECT_DATA); 359 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
283 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value); 360 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
284 return value; 361 return value;
285} 362}
@@ -288,67 +365,69 @@ static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
288static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, 365static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
289 int num) 366 int num)
290{ 367{
291 u32 aligned_addr = addr & CX2_INDIRECT_ADDR_MASK; 368 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK;
292 u32 dif_len = addr - aligned_addr; 369 u32 dif_len = addr - aligned_addr;
293 u32 aligned_len;
294 u32 i; 370 u32 i;
295 371
296 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); 372 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
297 373
374 if (num <= 0) {
375 return;
376 }
377
298 /* Read the first nibble byte by byte */ 378 /* Read the first nibble byte by byte */
299 if (unlikely(dif_len)) { 379 if (unlikely(dif_len)) {
380 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
300 /* Start reading at aligned_addr + dif_len */ 381 /* Start reading at aligned_addr + dif_len */
301 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr); 382 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
302 for (i = dif_len; i < 4; i++, buf++) 383 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
303 *buf = _ipw_read8(priv, CX2_INDIRECT_DATA + i);
304 num -= dif_len;
305 aligned_addr += 4; 384 aligned_addr += 4;
306 } 385 }
307 386
308 /* Read DWs through autoinc register */ 387 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
309 _ipw_write32(priv, CX2_AUTOINC_ADDR, aligned_addr); 388 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
310 aligned_len = num & CX2_INDIRECT_ADDR_MASK; 389 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
311 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
312 *(u32 *) buf = ipw_read32(priv, CX2_AUTOINC_DATA);
313 390
314 /* Copy the last nibble */ 391 /* Copy the last nibble */
315 dif_len = num - aligned_len; 392 if (unlikely(num)) {
316 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr); 393 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
317 for (i = 0; i < dif_len; i++, buf++) 394 for (i = 0; num > 0; i++, num--)
318 *buf = ipw_read8(priv, CX2_INDIRECT_DATA + i); 395 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
396 }
319} 397}
320 398
321static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf, 399static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
322 int num) 400 int num)
323{ 401{
324 u32 aligned_addr = addr & CX2_INDIRECT_ADDR_MASK; 402 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK;
325 u32 dif_len = addr - aligned_addr; 403 u32 dif_len = addr - aligned_addr;
326 u32 aligned_len;
327 u32 i; 404 u32 i;
328 405
329 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num); 406 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
330 407
408 if (num <= 0) {
409 return;
410 }
411
331 /* Write the first nibble byte by byte */ 412 /* Write the first nibble byte by byte */
332 if (unlikely(dif_len)) { 413 if (unlikely(dif_len)) {
333 /* Start writing at aligned_addr + dif_len */ 414 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
334 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr); 415 /* Start reading at aligned_addr + dif_len */
335 for (i = dif_len; i < 4; i++, buf++) 416 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
336 _ipw_write8(priv, CX2_INDIRECT_DATA + i, *buf); 417 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
337 num -= dif_len;
338 aligned_addr += 4; 418 aligned_addr += 4;
339 } 419 }
340 420
341 /* Write DWs through autoinc register */ 421 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
342 _ipw_write32(priv, CX2_AUTOINC_ADDR, aligned_addr); 422 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
343 aligned_len = num & CX2_INDIRECT_ADDR_MASK; 423 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
344 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
345 _ipw_write32(priv, CX2_AUTOINC_DATA, *(u32 *) buf);
346 424
347 /* Copy the last nibble */ 425 /* Copy the last nibble */
348 dif_len = num - aligned_len; 426 if (unlikely(num)) {
349 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr); 427 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
350 for (i = 0; i < dif_len; i++, buf++) 428 for (i = 0; num > 0; i++, num--, buf++)
351 _ipw_write8(priv, CX2_INDIRECT_DATA + i, *buf); 429 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
430 }
352} 431}
353 432
354static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf, 433static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
@@ -372,7 +451,7 @@ static inline void ipw_enable_interrupts(struct ipw_priv *priv)
372 if (priv->status & STATUS_INT_ENABLED) 451 if (priv->status & STATUS_INT_ENABLED)
373 return; 452 return;
374 priv->status |= STATUS_INT_ENABLED; 453 priv->status |= STATUS_INT_ENABLED;
375 ipw_write32(priv, CX2_INTA_MASK_R, CX2_INTA_MASK_ALL); 454 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
376} 455}
377 456
378static inline void ipw_disable_interrupts(struct ipw_priv *priv) 457static inline void ipw_disable_interrupts(struct ipw_priv *priv)
@@ -380,9 +459,10 @@ static inline void ipw_disable_interrupts(struct ipw_priv *priv)
380 if (!(priv->status & STATUS_INT_ENABLED)) 459 if (!(priv->status & STATUS_INT_ENABLED))
381 return; 460 return;
382 priv->status &= ~STATUS_INT_ENABLED; 461 priv->status &= ~STATUS_INT_ENABLED;
383 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL); 462 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
384} 463}
385 464
465#ifdef CONFIG_IPW_DEBUG
386static char *ipw_error_desc(u32 val) 466static char *ipw_error_desc(u32 val)
387{ 467{
388 switch (val) { 468 switch (val) {
@@ -395,81 +475,65 @@ static char *ipw_error_desc(u32 val)
395 case IPW_FW_ERROR_MEMORY_OVERFLOW: 475 case IPW_FW_ERROR_MEMORY_OVERFLOW:
396 return "MEMORY_OVERFLOW"; 476 return "MEMORY_OVERFLOW";
397 case IPW_FW_ERROR_BAD_PARAM: 477 case IPW_FW_ERROR_BAD_PARAM:
398 return "ERROR_BAD_PARAM"; 478 return "BAD_PARAM";
399 case IPW_FW_ERROR_BAD_CHECKSUM: 479 case IPW_FW_ERROR_BAD_CHECKSUM:
400 return "ERROR_BAD_CHECKSUM"; 480 return "BAD_CHECKSUM";
401 case IPW_FW_ERROR_NMI_INTERRUPT: 481 case IPW_FW_ERROR_NMI_INTERRUPT:
402 return "ERROR_NMI_INTERRUPT"; 482 return "NMI_INTERRUPT";
403 case IPW_FW_ERROR_BAD_DATABASE: 483 case IPW_FW_ERROR_BAD_DATABASE:
404 return "ERROR_BAD_DATABASE"; 484 return "BAD_DATABASE";
405 case IPW_FW_ERROR_ALLOC_FAIL: 485 case IPW_FW_ERROR_ALLOC_FAIL:
406 return "ERROR_ALLOC_FAIL"; 486 return "ALLOC_FAIL";
407 case IPW_FW_ERROR_DMA_UNDERRUN: 487 case IPW_FW_ERROR_DMA_UNDERRUN:
408 return "ERROR_DMA_UNDERRUN"; 488 return "DMA_UNDERRUN";
409 case IPW_FW_ERROR_DMA_STATUS: 489 case IPW_FW_ERROR_DMA_STATUS:
410 return "ERROR_DMA_STATUS"; 490 return "DMA_STATUS";
411 case IPW_FW_ERROR_DINOSTATUS_ERROR: 491 case IPW_FW_ERROR_DINO_ERROR:
412 return "ERROR_DINOSTATUS_ERROR"; 492 return "DINO_ERROR";
413 case IPW_FW_ERROR_EEPROMSTATUS_ERROR: 493 case IPW_FW_ERROR_EEPROM_ERROR:
414 return "ERROR_EEPROMSTATUS_ERROR"; 494 return "EEPROM_ERROR";
415 case IPW_FW_ERROR_SYSASSERT: 495 case IPW_FW_ERROR_SYSASSERT:
416 return "ERROR_SYSASSERT"; 496 return "SYSASSERT";
417 case IPW_FW_ERROR_FATAL_ERROR: 497 case IPW_FW_ERROR_FATAL_ERROR:
418 return "ERROR_FATALSTATUS_ERROR"; 498 return "FATAL_ERROR";
419 default: 499 default:
420 return "UNKNOWNSTATUS_ERROR"; 500 return "UNKNOWN_ERROR";
421 } 501 }
422} 502}
423 503
424static void ipw_dump_nic_error_log(struct ipw_priv *priv) 504static void ipw_dump_error_log(struct ipw_priv *priv,
505 struct ipw_fw_error *error)
425{ 506{
426 u32 desc, time, blink1, blink2, ilink1, ilink2, idata, i, count, base; 507 u32 i;
427
428 base = ipw_read32(priv, IPWSTATUS_ERROR_LOG);
429 count = ipw_read_reg32(priv, base);
430 508
431 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { 509 if (!error) {
432 IPW_ERROR("Start IPW Error Log Dump:\n"); 510 IPW_ERROR("Error allocating and capturing error log. "
433 IPW_ERROR("Status: 0x%08X, Config: %08X\n", 511 "Nothing to dump.\n");
434 priv->status, priv->config); 512 return;
435 } 513 }
436 514
437 for (i = ERROR_START_OFFSET; 515 IPW_ERROR("Start IPW Error Log Dump:\n");
438 i <= count * ERROR_ELEM_SIZE; i += ERROR_ELEM_SIZE) { 516 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
439 desc = ipw_read_reg32(priv, base + i); 517 error->status, error->config);
440 time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
441 blink1 = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
442 blink2 = ipw_read_reg32(priv, base + i + 3 * sizeof(u32));
443 ilink1 = ipw_read_reg32(priv, base + i + 4 * sizeof(u32));
444 ilink2 = ipw_read_reg32(priv, base + i + 5 * sizeof(u32));
445 idata = ipw_read_reg32(priv, base + i + 6 * sizeof(u32));
446 518
519 for (i = 0; i < error->elem_len; i++)
447 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n", 520 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
448 ipw_error_desc(desc), time, blink1, blink2, 521 ipw_error_desc(error->elem[i].desc),
449 ilink1, ilink2, idata); 522 error->elem[i].time,
450 } 523 error->elem[i].blink1,
524 error->elem[i].blink2,
525 error->elem[i].link1,
526 error->elem[i].link2, error->elem[i].data);
527 for (i = 0; i < error->log_len; i++)
528 IPW_ERROR("%i\t0x%08x\t%i\n",
529 error->log[i].time,
530 error->log[i].data, error->log[i].event);
451} 531}
532#endif
452 533
453static void ipw_dump_nic_event_log(struct ipw_priv *priv) 534static inline int ipw_is_init(struct ipw_priv *priv)
454{ 535{
455 u32 ev, time, data, i, count, base; 536 return (priv->status & STATUS_INIT) ? 1 : 0;
456
457 base = ipw_read32(priv, IPW_EVENT_LOG);
458 count = ipw_read_reg32(priv, base);
459
460 if (EVENT_START_OFFSET <= count * EVENT_ELEM_SIZE)
461 IPW_ERROR("Start IPW Event Log Dump:\n");
462
463 for (i = EVENT_START_OFFSET;
464 i <= count * EVENT_ELEM_SIZE; i += EVENT_ELEM_SIZE) {
465 ev = ipw_read_reg32(priv, base + i);
466 time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
467 data = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
468
469#ifdef CONFIG_IPW_DEBUG
470 IPW_ERROR("%i\t0x%08x\t%i\n", time, data, ev);
471#endif
472 }
473} 537}
474 538
475static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len) 539static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
@@ -637,6 +701,340 @@ static void ipw_init_ordinals(struct ipw_priv *priv)
637 701
638} 702}
639 703
704u32 ipw_register_toggle(u32 reg)
705{
706 reg &= ~IPW_START_STANDBY;
707 if (reg & IPW_GATE_ODMA)
708 reg &= ~IPW_GATE_ODMA;
709 if (reg & IPW_GATE_IDMA)
710 reg &= ~IPW_GATE_IDMA;
711 if (reg & IPW_GATE_ADMA)
712 reg &= ~IPW_GATE_ADMA;
713 return reg;
714}
715
716/*
717 * LED behavior:
718 * - On radio ON, turn on any LEDs that require to be on during start
719 * - On initialization, start unassociated blink
720 * - On association, disable unassociated blink
721 * - On disassociation, start unassociated blink
722 * - On radio OFF, turn off any LEDs started during radio on
723 *
724 */
725#define LD_TIME_LINK_ON 300
726#define LD_TIME_LINK_OFF 2700
727#define LD_TIME_ACT_ON 250
728
729void ipw_led_link_on(struct ipw_priv *priv)
730{
731 unsigned long flags;
732 u32 led;
733
734 /* If configured to not use LEDs, or nic_type is 1,
735 * then we don't toggle a LINK led */
736 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
737 return;
738
739 spin_lock_irqsave(&priv->lock, flags);
740
741 if (!(priv->status & STATUS_RF_KILL_MASK) &&
742 !(priv->status & STATUS_LED_LINK_ON)) {
743 IPW_DEBUG_LED("Link LED On\n");
744 led = ipw_read_reg32(priv, IPW_EVENT_REG);
745 led |= priv->led_association_on;
746
747 led = ipw_register_toggle(led);
748
749 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
750 ipw_write_reg32(priv, IPW_EVENT_REG, led);
751
752 priv->status |= STATUS_LED_LINK_ON;
753
754 /* If we aren't associated, schedule turning the LED off */
755 if (!(priv->status & STATUS_ASSOCIATED))
756 queue_delayed_work(priv->workqueue,
757 &priv->led_link_off,
758 LD_TIME_LINK_ON);
759 }
760
761 spin_unlock_irqrestore(&priv->lock, flags);
762}
763
764static void ipw_bg_led_link_on(void *data)
765{
766 struct ipw_priv *priv = data;
767 down(&priv->sem);
768 ipw_led_link_on(data);
769 up(&priv->sem);
770}
771
772void ipw_led_link_off(struct ipw_priv *priv)
773{
774 unsigned long flags;
775 u32 led;
776
777 /* If configured not to use LEDs, or nic type is 1,
778 * then we don't goggle the LINK led. */
779 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
780 return;
781
782 spin_lock_irqsave(&priv->lock, flags);
783
784 if (priv->status & STATUS_LED_LINK_ON) {
785 led = ipw_read_reg32(priv, IPW_EVENT_REG);
786 led &= priv->led_association_off;
787 led = ipw_register_toggle(led);
788
789 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
790 ipw_write_reg32(priv, IPW_EVENT_REG, led);
791
792 IPW_DEBUG_LED("Link LED Off\n");
793
794 priv->status &= ~STATUS_LED_LINK_ON;
795
796 /* If we aren't associated and the radio is on, schedule
797 * turning the LED on (blink while unassociated) */
798 if (!(priv->status & STATUS_RF_KILL_MASK) &&
799 !(priv->status & STATUS_ASSOCIATED))
800 queue_delayed_work(priv->workqueue, &priv->led_link_on,
801 LD_TIME_LINK_OFF);
802
803 }
804
805 spin_unlock_irqrestore(&priv->lock, flags);
806}
807
808static void ipw_bg_led_link_off(void *data)
809{
810 struct ipw_priv *priv = data;
811 down(&priv->sem);
812 ipw_led_link_off(data);
813 up(&priv->sem);
814}
815
816static inline void __ipw_led_activity_on(struct ipw_priv *priv)
817{
818 u32 led;
819
820 if (priv->config & CFG_NO_LED)
821 return;
822
823 if (priv->status & STATUS_RF_KILL_MASK)
824 return;
825
826 if (!(priv->status & STATUS_LED_ACT_ON)) {
827 led = ipw_read_reg32(priv, IPW_EVENT_REG);
828 led |= priv->led_activity_on;
829
830 led = ipw_register_toggle(led);
831
832 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
833 ipw_write_reg32(priv, IPW_EVENT_REG, led);
834
835 IPW_DEBUG_LED("Activity LED On\n");
836
837 priv->status |= STATUS_LED_ACT_ON;
838
839 cancel_delayed_work(&priv->led_act_off);
840 queue_delayed_work(priv->workqueue, &priv->led_act_off,
841 LD_TIME_ACT_ON);
842 } else {
843 /* Reschedule LED off for full time period */
844 cancel_delayed_work(&priv->led_act_off);
845 queue_delayed_work(priv->workqueue, &priv->led_act_off,
846 LD_TIME_ACT_ON);
847 }
848}
849
850void ipw_led_activity_on(struct ipw_priv *priv)
851{
852 unsigned long flags;
853 spin_lock_irqsave(&priv->lock, flags);
854 __ipw_led_activity_on(priv);
855 spin_unlock_irqrestore(&priv->lock, flags);
856}
857
858void ipw_led_activity_off(struct ipw_priv *priv)
859{
860 unsigned long flags;
861 u32 led;
862
863 if (priv->config & CFG_NO_LED)
864 return;
865
866 spin_lock_irqsave(&priv->lock, flags);
867
868 if (priv->status & STATUS_LED_ACT_ON) {
869 led = ipw_read_reg32(priv, IPW_EVENT_REG);
870 led &= priv->led_activity_off;
871
872 led = ipw_register_toggle(led);
873
874 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
875 ipw_write_reg32(priv, IPW_EVENT_REG, led);
876
877 IPW_DEBUG_LED("Activity LED Off\n");
878
879 priv->status &= ~STATUS_LED_ACT_ON;
880 }
881
882 spin_unlock_irqrestore(&priv->lock, flags);
883}
884
885static void ipw_bg_led_activity_off(void *data)
886{
887 struct ipw_priv *priv = data;
888 down(&priv->sem);
889 ipw_led_activity_off(data);
890 up(&priv->sem);
891}
892
893void ipw_led_band_on(struct ipw_priv *priv)
894{
895 unsigned long flags;
896 u32 led;
897
898 /* Only nic type 1 supports mode LEDs */
899 if (priv->config & CFG_NO_LED ||
900 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
901 return;
902
903 spin_lock_irqsave(&priv->lock, flags);
904
905 led = ipw_read_reg32(priv, IPW_EVENT_REG);
906 if (priv->assoc_network->mode == IEEE_A) {
907 led |= priv->led_ofdm_on;
908 led &= priv->led_association_off;
909 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
910 } else if (priv->assoc_network->mode == IEEE_G) {
911 led |= priv->led_ofdm_on;
912 led |= priv->led_association_on;
913 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
914 } else {
915 led &= priv->led_ofdm_off;
916 led |= priv->led_association_on;
917 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
918 }
919
920 led = ipw_register_toggle(led);
921
922 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
923 ipw_write_reg32(priv, IPW_EVENT_REG, led);
924
925 spin_unlock_irqrestore(&priv->lock, flags);
926}
927
928void ipw_led_band_off(struct ipw_priv *priv)
929{
930 unsigned long flags;
931 u32 led;
932
933 /* Only nic type 1 supports mode LEDs */
934 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
935 return;
936
937 spin_lock_irqsave(&priv->lock, flags);
938
939 led = ipw_read_reg32(priv, IPW_EVENT_REG);
940 led &= priv->led_ofdm_off;
941 led &= priv->led_association_off;
942
943 led = ipw_register_toggle(led);
944
945 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
946 ipw_write_reg32(priv, IPW_EVENT_REG, led);
947
948 spin_unlock_irqrestore(&priv->lock, flags);
949}
950
951void ipw_led_radio_on(struct ipw_priv *priv)
952{
953 ipw_led_link_on(priv);
954}
955
956void ipw_led_radio_off(struct ipw_priv *priv)
957{
958 ipw_led_activity_off(priv);
959 ipw_led_link_off(priv);
960}
961
962void ipw_led_link_up(struct ipw_priv *priv)
963{
964 /* Set the Link Led on for all nic types */
965 ipw_led_link_on(priv);
966}
967
968void ipw_led_link_down(struct ipw_priv *priv)
969{
970 ipw_led_activity_off(priv);
971 ipw_led_link_off(priv);
972
973 if (priv->status & STATUS_RF_KILL_MASK)
974 ipw_led_radio_off(priv);
975}
976
977void ipw_led_init(struct ipw_priv *priv)
978{
979 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
980
981 /* Set the default PINs for the link and activity leds */
982 priv->led_activity_on = IPW_ACTIVITY_LED;
983 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
984
985 priv->led_association_on = IPW_ASSOCIATED_LED;
986 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
987
988 /* Set the default PINs for the OFDM leds */
989 priv->led_ofdm_on = IPW_OFDM_LED;
990 priv->led_ofdm_off = ~(IPW_OFDM_LED);
991
992 switch (priv->nic_type) {
993 case EEPROM_NIC_TYPE_1:
994 /* In this NIC type, the LEDs are reversed.... */
995 priv->led_activity_on = IPW_ASSOCIATED_LED;
996 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
997 priv->led_association_on = IPW_ACTIVITY_LED;
998 priv->led_association_off = ~(IPW_ACTIVITY_LED);
999
1000 if (!(priv->config & CFG_NO_LED))
1001 ipw_led_band_on(priv);
1002
1003 /* And we don't blink link LEDs for this nic, so
1004 * just return here */
1005 return;
1006
1007 case EEPROM_NIC_TYPE_3:
1008 case EEPROM_NIC_TYPE_2:
1009 case EEPROM_NIC_TYPE_4:
1010 case EEPROM_NIC_TYPE_0:
1011 break;
1012
1013 default:
1014 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1015 priv->nic_type);
1016 priv->nic_type = EEPROM_NIC_TYPE_0;
1017 break;
1018 }
1019
1020 if (!(priv->config & CFG_NO_LED)) {
1021 if (priv->status & STATUS_ASSOCIATED)
1022 ipw_led_link_on(priv);
1023 else
1024 ipw_led_link_off(priv);
1025 }
1026}
1027
1028void ipw_led_shutdown(struct ipw_priv *priv)
1029{
1030 ipw_led_activity_off(priv);
1031 ipw_led_link_off(priv);
1032 ipw_led_band_off(priv);
1033 cancel_delayed_work(&priv->led_link_on);
1034 cancel_delayed_work(&priv->led_link_off);
1035 cancel_delayed_work(&priv->led_act_off);
1036}
1037
640/* 1038/*
641 * The following adds a new attribute to the sysfs representation 1039 * The following adds a new attribute to the sysfs representation
642 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/) 1040 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
@@ -648,8 +1046,9 @@ static ssize_t show_debug_level(struct device_driver *d, char *buf)
648{ 1046{
649 return sprintf(buf, "0x%08X\n", ipw_debug_level); 1047 return sprintf(buf, "0x%08X\n", ipw_debug_level);
650} 1048}
651static ssize_t store_debug_level(struct device_driver *d, 1049
652 const char *buf, size_t count) 1050static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1051 size_t count)
653{ 1052{
654 char *p = (char *)buf; 1053 char *p = (char *)buf;
655 u32 val; 1054 u32 val;
@@ -673,75 +1072,263 @@ static ssize_t store_debug_level(struct device_driver *d,
673static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, 1072static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
674 show_debug_level, store_debug_level); 1073 show_debug_level, store_debug_level);
675 1074
676static ssize_t show_status(struct device *d, 1075static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
677 struct device_attribute *attr, char *buf)
678{ 1076{
679 struct ipw_priv *p = d->driver_data; 1077 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
680 return sprintf(buf, "0x%08x\n", (int)p->status);
681} 1078}
682 1079
683static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); 1080static void ipw_capture_event_log(struct ipw_priv *priv,
1081 u32 log_len, struct ipw_event *log)
1082{
1083 u32 base;
684 1084
685static ssize_t show_cfg(struct device *d, struct device_attribute *attr, 1085 if (log_len) {
686 char *buf) 1086 base = ipw_read32(priv, IPW_EVENT_LOG);
1087 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1088 (u8 *) log, sizeof(*log) * log_len);
1089 }
1090}
1091
1092static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
687{ 1093{
688 struct ipw_priv *p = d->driver_data; 1094 struct ipw_fw_error *error;
689 return sprintf(buf, "0x%08x\n", (int)p->config); 1095 u32 log_len = ipw_get_event_log_len(priv);
1096 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1097 u32 elem_len = ipw_read_reg32(priv, base);
1098
1099 error = kmalloc(sizeof(*error) +
1100 sizeof(*error->elem) * elem_len +
1101 sizeof(*error->log) * log_len, GFP_ATOMIC);
1102 if (!error) {
1103 IPW_ERROR("Memory allocation for firmware error log "
1104 "failed.\n");
1105 return NULL;
1106 }
1107 error->jiffies = jiffies;
1108 error->status = priv->status;
1109 error->config = priv->config;
1110 error->elem_len = elem_len;
1111 error->log_len = log_len;
1112 error->elem = (struct ipw_error_elem *)error->payload;
1113 error->log = (struct ipw_event *)(error->elem +
1114 (sizeof(*error->elem) * elem_len));
1115
1116 ipw_capture_event_log(priv, log_len, error->log);
1117
1118 if (elem_len)
1119 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1120 sizeof(*error->elem) * elem_len);
1121
1122 return error;
690} 1123}
691 1124
692static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL); 1125static void ipw_free_error_log(struct ipw_fw_error *error)
1126{
1127 if (error)
1128 kfree(error);
1129}
693 1130
694static ssize_t show_nic_type(struct device *d, 1131static ssize_t show_event_log(struct device *d,
695 struct device_attribute *attr, char *buf) 1132 struct device_attribute *attr, char *buf)
696{ 1133{
697 struct ipw_priv *p = d->driver_data; 1134 struct ipw_priv *priv = dev_get_drvdata(d);
698 u8 type = p->eeprom[EEPROM_NIC_TYPE]; 1135 u32 log_len = ipw_get_event_log_len(priv);
1136 struct ipw_event log[log_len];
1137 u32 len = 0, i;
1138
1139 ipw_capture_event_log(priv, log_len, log);
1140
1141 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1142 for (i = 0; i < log_len; i++)
1143 len += snprintf(buf + len, PAGE_SIZE - len,
1144 "\n%08X%08X%08X",
1145 log[i].time, log[i].event, log[i].data);
1146 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1147 return len;
1148}
699 1149
700 switch (type) { 1150static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
701 case EEPROM_NIC_TYPE_STANDARD: 1151
702 return sprintf(buf, "STANDARD\n"); 1152static ssize_t show_error(struct device *d,
703 case EEPROM_NIC_TYPE_DELL: 1153 struct device_attribute *attr, char *buf)
704 return sprintf(buf, "DELL\n"); 1154{
705 case EEPROM_NIC_TYPE_FUJITSU: 1155 struct ipw_priv *priv = dev_get_drvdata(d);
706 return sprintf(buf, "FUJITSU\n"); 1156 u32 len = 0, i;
707 case EEPROM_NIC_TYPE_IBM: 1157 if (!priv->error)
708 return sprintf(buf, "IBM\n"); 1158 return 0;
709 case EEPROM_NIC_TYPE_HP: 1159 len += snprintf(buf + len, PAGE_SIZE - len,
710 return sprintf(buf, "HP\n"); 1160 "%08lX%08X%08X%08X",
1161 priv->error->jiffies,
1162 priv->error->status,
1163 priv->error->config, priv->error->elem_len);
1164 for (i = 0; i < priv->error->elem_len; i++)
1165 len += snprintf(buf + len, PAGE_SIZE - len,
1166 "\n%08X%08X%08X%08X%08X%08X%08X",
1167 priv->error->elem[i].time,
1168 priv->error->elem[i].desc,
1169 priv->error->elem[i].blink1,
1170 priv->error->elem[i].blink2,
1171 priv->error->elem[i].link1,
1172 priv->error->elem[i].link2,
1173 priv->error->elem[i].data);
1174
1175 len += snprintf(buf + len, PAGE_SIZE - len,
1176 "\n%08X", priv->error->log_len);
1177 for (i = 0; i < priv->error->log_len; i++)
1178 len += snprintf(buf + len, PAGE_SIZE - len,
1179 "\n%08X%08X%08X",
1180 priv->error->log[i].time,
1181 priv->error->log[i].event,
1182 priv->error->log[i].data);
1183 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1184 return len;
1185}
1186
1187static ssize_t clear_error(struct device *d,
1188 struct device_attribute *attr,
1189 const char *buf, size_t count)
1190{
1191 struct ipw_priv *priv = dev_get_drvdata(d);
1192 if (priv->error) {
1193 ipw_free_error_log(priv->error);
1194 priv->error = NULL;
711 } 1195 }
1196 return count;
1197}
1198
1199static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
712 1200
713 return sprintf(buf, "UNKNOWN\n"); 1201static ssize_t show_cmd_log(struct device *d,
1202 struct device_attribute *attr, char *buf)
1203{
1204 struct ipw_priv *priv = dev_get_drvdata(d);
1205 u32 len = 0, i;
1206 if (!priv->cmdlog)
1207 return 0;
1208 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1209 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1210 i = (i + 1) % priv->cmdlog_len) {
1211 len +=
1212 snprintf(buf + len, PAGE_SIZE - len,
1213 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1214 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1215 priv->cmdlog[i].cmd.len);
1216 len +=
1217 snprintk_buf(buf + len, PAGE_SIZE - len,
1218 (u8 *) priv->cmdlog[i].cmd.param,
1219 priv->cmdlog[i].cmd.len);
1220 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1221 }
1222 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1223 return len;
714} 1224}
715 1225
716static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL); 1226static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
717 1227
718static ssize_t dump_error_log(struct device *d, 1228static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
719 struct device_attribute *attr, const char *buf, 1229 char *buf)
720 size_t count)
721{ 1230{
722 char *p = (char *)buf; 1231 struct ipw_priv *priv = dev_get_drvdata(d);
1232 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1233}
723 1234
724 if (p[0] == '1') 1235static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
725 ipw_dump_nic_error_log((struct ipw_priv *)d->driver_data); 1236 const char *buf, size_t count)
1237{
1238 struct ipw_priv *priv = dev_get_drvdata(d);
1239#ifdef CONFIG_IPW_DEBUG
1240 struct net_device *dev = priv->net_dev;
1241#endif
1242 char buffer[] = "00000000";
1243 unsigned long len =
1244 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1245 unsigned long val;
1246 char *p = buffer;
726 1247
727 return strnlen(buf, count); 1248 IPW_DEBUG_INFO("enter\n");
1249
1250 strncpy(buffer, buf, len);
1251 buffer[len] = 0;
1252
1253 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1254 p++;
1255 if (p[0] == 'x' || p[0] == 'X')
1256 p++;
1257 val = simple_strtoul(p, &p, 16);
1258 } else
1259 val = simple_strtoul(p, &p, 10);
1260 if (p == buffer) {
1261 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1262 } else {
1263 priv->ieee->scan_age = val;
1264 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1265 }
1266
1267 IPW_DEBUG_INFO("exit\n");
1268 return len;
728} 1269}
729 1270
730static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); 1271static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
731 1272
732static ssize_t dump_event_log(struct device *d, 1273static ssize_t show_led(struct device *d, struct device_attribute *attr,
733 struct device_attribute *attr, const char *buf, 1274 char *buf)
734 size_t count)
735{ 1275{
736 char *p = (char *)buf; 1276 struct ipw_priv *priv = dev_get_drvdata(d);
1277 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1278}
737 1279
738 if (p[0] == '1') 1280static ssize_t store_led(struct device *d, struct device_attribute *attr,
739 ipw_dump_nic_event_log((struct ipw_priv *)d->driver_data); 1281 const char *buf, size_t count)
1282{
1283 struct ipw_priv *priv = dev_get_drvdata(d);
740 1284
741 return strnlen(buf, count); 1285 IPW_DEBUG_INFO("enter\n");
1286
1287 if (count == 0)
1288 return 0;
1289
1290 if (*buf == 0) {
1291 IPW_DEBUG_LED("Disabling LED control.\n");
1292 priv->config |= CFG_NO_LED;
1293 ipw_led_shutdown(priv);
1294 } else {
1295 IPW_DEBUG_LED("Enabling LED control.\n");
1296 priv->config &= ~CFG_NO_LED;
1297 ipw_led_init(priv);
1298 }
1299
1300 IPW_DEBUG_INFO("exit\n");
1301 return count;
1302}
1303
1304static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1305
1306static ssize_t show_status(struct device *d,
1307 struct device_attribute *attr, char *buf)
1308{
1309 struct ipw_priv *p = d->driver_data;
1310 return sprintf(buf, "0x%08x\n", (int)p->status);
742} 1311}
743 1312
744static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); 1313static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1314
1315static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1316 char *buf)
1317{
1318 struct ipw_priv *p = d->driver_data;
1319 return sprintf(buf, "0x%08x\n", (int)p->config);
1320}
1321
1322static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1323
1324static ssize_t show_nic_type(struct device *d,
1325 struct device_attribute *attr, char *buf)
1326{
1327 struct ipw_priv *priv = d->driver_data;
1328 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
1329}
1330
1331static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
745 1332
746static ssize_t show_ucode_version(struct device *d, 1333static ssize_t show_ucode_version(struct device *d,
747 struct device_attribute *attr, char *buf) 1334 struct device_attribute *attr, char *buf)
@@ -799,7 +1386,7 @@ static ssize_t show_command_event_reg(struct device *d,
799 u32 reg = 0; 1386 u32 reg = 0;
800 struct ipw_priv *p = d->driver_data; 1387 struct ipw_priv *p = d->driver_data;
801 1388
802 reg = ipw_read_reg32(p, CX2_INTERNAL_CMD_EVENT); 1389 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
803 return sprintf(buf, "0x%08x\n", reg); 1390 return sprintf(buf, "0x%08x\n", reg);
804} 1391}
805static ssize_t store_command_event_reg(struct device *d, 1392static ssize_t store_command_event_reg(struct device *d,
@@ -810,7 +1397,7 @@ static ssize_t store_command_event_reg(struct device *d,
810 struct ipw_priv *p = d->driver_data; 1397 struct ipw_priv *p = d->driver_data;
811 1398
812 sscanf(buf, "%x", &reg); 1399 sscanf(buf, "%x", &reg);
813 ipw_write_reg32(p, CX2_INTERNAL_CMD_EVENT, reg); 1400 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
814 return strnlen(buf, count); 1401 return strnlen(buf, count);
815} 1402}
816 1403
@@ -846,6 +1433,7 @@ static ssize_t show_indirect_dword(struct device *d,
846{ 1433{
847 u32 reg = 0; 1434 u32 reg = 0;
848 struct ipw_priv *priv = d->driver_data; 1435 struct ipw_priv *priv = d->driver_data;
1436
849 if (priv->status & STATUS_INDIRECT_DWORD) 1437 if (priv->status & STATUS_INDIRECT_DWORD)
850 reg = ipw_read_reg32(priv, priv->indirect_dword); 1438 reg = ipw_read_reg32(priv, priv->indirect_dword);
851 else 1439 else
@@ -872,6 +1460,7 @@ static ssize_t show_indirect_byte(struct device *d,
872{ 1460{
873 u8 reg = 0; 1461 u8 reg = 0;
874 struct ipw_priv *priv = d->driver_data; 1462 struct ipw_priv *priv = d->driver_data;
1463
875 if (priv->status & STATUS_INDIRECT_BYTE) 1464 if (priv->status & STATUS_INDIRECT_BYTE)
876 reg = ipw_read_reg8(priv, priv->indirect_byte); 1465 reg = ipw_read_reg8(priv, priv->indirect_byte);
877 else 1466 else
@@ -946,7 +1535,7 @@ static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
946static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio) 1535static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
947{ 1536{
948 if ((disable_radio ? 1 : 0) == 1537 if ((disable_radio ? 1 : 0) ==
949 (priv->status & STATUS_RF_KILL_SW ? 1 : 0)) 1538 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
950 return 0; 1539 return 0;
951 1540
952 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n", 1541 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
@@ -955,10 +1544,8 @@ static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
955 if (disable_radio) { 1544 if (disable_radio) {
956 priv->status |= STATUS_RF_KILL_SW; 1545 priv->status |= STATUS_RF_KILL_SW;
957 1546
958 if (priv->workqueue) { 1547 if (priv->workqueue)
959 cancel_delayed_work(&priv->request_scan); 1548 cancel_delayed_work(&priv->request_scan);
960 }
961 wake_up_interruptible(&priv->wait_command_queue);
962 queue_work(priv->workqueue, &priv->down); 1549 queue_work(priv->workqueue, &priv->down);
963 } else { 1550 } else {
964 priv->status &= ~STATUS_RF_KILL_SW; 1551 priv->status &= ~STATUS_RF_KILL_SW;
@@ -988,6 +1575,93 @@ static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
988 1575
989static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); 1576static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
990 1577
1578static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1579 char *buf)
1580{
1581 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1582 int pos = 0, len = 0;
1583 if (priv->config & CFG_SPEED_SCAN) {
1584 while (priv->speed_scan[pos] != 0)
1585 len += sprintf(&buf[len], "%d ",
1586 priv->speed_scan[pos++]);
1587 return len + sprintf(&buf[len], "\n");
1588 }
1589
1590 return sprintf(buf, "0\n");
1591}
1592
1593static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1594 const char *buf, size_t count)
1595{
1596 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1597 int channel, pos = 0;
1598 const char *p = buf;
1599
1600 /* list of space separated channels to scan, optionally ending with 0 */
1601 while ((channel = simple_strtol(p, NULL, 0))) {
1602 if (pos == MAX_SPEED_SCAN - 1) {
1603 priv->speed_scan[pos] = 0;
1604 break;
1605 }
1606
1607 if (ipw_is_valid_channel(priv->ieee, channel))
1608 priv->speed_scan[pos++] = channel;
1609 else
1610 IPW_WARNING("Skipping invalid channel request: %d\n",
1611 channel);
1612 p = strchr(p, ' ');
1613 if (!p)
1614 break;
1615 while (*p == ' ' || *p == '\t')
1616 p++;
1617 }
1618
1619 if (pos == 0)
1620 priv->config &= ~CFG_SPEED_SCAN;
1621 else {
1622 priv->speed_scan_pos = 0;
1623 priv->config |= CFG_SPEED_SCAN;
1624 }
1625
1626 return count;
1627}
1628
1629static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1630 store_speed_scan);
1631
1632static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1633 char *buf)
1634{
1635 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1636 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1637}
1638
1639static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1640 const char *buf, size_t count)
1641{
1642 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1643 if (buf[0] == '1')
1644 priv->config |= CFG_NET_STATS;
1645 else
1646 priv->config &= ~CFG_NET_STATS;
1647
1648 return count;
1649}
1650
1651static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1652 show_net_stats, store_net_stats);
1653
1654static void notify_wx_assoc_event(struct ipw_priv *priv)
1655{
1656 union iwreq_data wrqu;
1657 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1658 if (priv->status & STATUS_ASSOCIATED)
1659 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1660 else
1661 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1662 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1663}
1664
991static void ipw_irq_tasklet(struct ipw_priv *priv) 1665static void ipw_irq_tasklet(struct ipw_priv *priv)
992{ 1666{
993 u32 inta, inta_mask, handled = 0; 1667 u32 inta, inta_mask, handled = 0;
@@ -996,102 +1670,135 @@ static void ipw_irq_tasklet(struct ipw_priv *priv)
996 1670
997 spin_lock_irqsave(&priv->lock, flags); 1671 spin_lock_irqsave(&priv->lock, flags);
998 1672
999 inta = ipw_read32(priv, CX2_INTA_RW); 1673 inta = ipw_read32(priv, IPW_INTA_RW);
1000 inta_mask = ipw_read32(priv, CX2_INTA_MASK_R); 1674 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1001 inta &= (CX2_INTA_MASK_ALL & inta_mask); 1675 inta &= (IPW_INTA_MASK_ALL & inta_mask);
1002 1676
1003 /* Add any cached INTA values that need to be handled */ 1677 /* Add any cached INTA values that need to be handled */
1004 inta |= priv->isr_inta; 1678 inta |= priv->isr_inta;
1005 1679
1006 /* handle all the justifications for the interrupt */ 1680 /* handle all the justifications for the interrupt */
1007 if (inta & CX2_INTA_BIT_RX_TRANSFER) { 1681 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
1008 ipw_rx(priv); 1682 ipw_rx(priv);
1009 handled |= CX2_INTA_BIT_RX_TRANSFER; 1683 handled |= IPW_INTA_BIT_RX_TRANSFER;
1010 } 1684 }
1011 1685
1012 if (inta & CX2_INTA_BIT_TX_CMD_QUEUE) { 1686 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
1013 IPW_DEBUG_HC("Command completed.\n"); 1687 IPW_DEBUG_HC("Command completed.\n");
1014 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1); 1688 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
1015 priv->status &= ~STATUS_HCMD_ACTIVE; 1689 priv->status &= ~STATUS_HCMD_ACTIVE;
1016 wake_up_interruptible(&priv->wait_command_queue); 1690 wake_up_interruptible(&priv->wait_command_queue);
1017 handled |= CX2_INTA_BIT_TX_CMD_QUEUE; 1691 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
1018 } 1692 }
1019 1693
1020 if (inta & CX2_INTA_BIT_TX_QUEUE_1) { 1694 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
1021 IPW_DEBUG_TX("TX_QUEUE_1\n"); 1695 IPW_DEBUG_TX("TX_QUEUE_1\n");
1022 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0); 1696 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
1023 handled |= CX2_INTA_BIT_TX_QUEUE_1; 1697 handled |= IPW_INTA_BIT_TX_QUEUE_1;
1024 } 1698 }
1025 1699
1026 if (inta & CX2_INTA_BIT_TX_QUEUE_2) { 1700 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
1027 IPW_DEBUG_TX("TX_QUEUE_2\n"); 1701 IPW_DEBUG_TX("TX_QUEUE_2\n");
1028 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1); 1702 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
1029 handled |= CX2_INTA_BIT_TX_QUEUE_2; 1703 handled |= IPW_INTA_BIT_TX_QUEUE_2;
1030 } 1704 }
1031 1705
1032 if (inta & CX2_INTA_BIT_TX_QUEUE_3) { 1706 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
1033 IPW_DEBUG_TX("TX_QUEUE_3\n"); 1707 IPW_DEBUG_TX("TX_QUEUE_3\n");
1034 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2); 1708 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
1035 handled |= CX2_INTA_BIT_TX_QUEUE_3; 1709 handled |= IPW_INTA_BIT_TX_QUEUE_3;
1036 } 1710 }
1037 1711
1038 if (inta & CX2_INTA_BIT_TX_QUEUE_4) { 1712 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
1039 IPW_DEBUG_TX("TX_QUEUE_4\n"); 1713 IPW_DEBUG_TX("TX_QUEUE_4\n");
1040 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3); 1714 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
1041 handled |= CX2_INTA_BIT_TX_QUEUE_4; 1715 handled |= IPW_INTA_BIT_TX_QUEUE_4;
1042 } 1716 }
1043 1717
1044 if (inta & CX2_INTA_BIT_STATUS_CHANGE) { 1718 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
1045 IPW_WARNING("STATUS_CHANGE\n"); 1719 IPW_WARNING("STATUS_CHANGE\n");
1046 handled |= CX2_INTA_BIT_STATUS_CHANGE; 1720 handled |= IPW_INTA_BIT_STATUS_CHANGE;
1047 } 1721 }
1048 1722
1049 if (inta & CX2_INTA_BIT_BEACON_PERIOD_EXPIRED) { 1723 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
1050 IPW_WARNING("TX_PERIOD_EXPIRED\n"); 1724 IPW_WARNING("TX_PERIOD_EXPIRED\n");
1051 handled |= CX2_INTA_BIT_BEACON_PERIOD_EXPIRED; 1725 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
1052 } 1726 }
1053 1727
1054 if (inta & CX2_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) { 1728 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
1055 IPW_WARNING("HOST_CMD_DONE\n"); 1729 IPW_WARNING("HOST_CMD_DONE\n");
1056 handled |= CX2_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE; 1730 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
1057 } 1731 }
1058 1732
1059 if (inta & CX2_INTA_BIT_FW_INITIALIZATION_DONE) { 1733 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
1060 IPW_WARNING("FW_INITIALIZATION_DONE\n"); 1734 IPW_WARNING("FW_INITIALIZATION_DONE\n");
1061 handled |= CX2_INTA_BIT_FW_INITIALIZATION_DONE; 1735 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
1062 } 1736 }
1063 1737
1064 if (inta & CX2_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) { 1738 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
1065 IPW_WARNING("PHY_OFF_DONE\n"); 1739 IPW_WARNING("PHY_OFF_DONE\n");
1066 handled |= CX2_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE; 1740 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
1067 } 1741 }
1068 1742
1069 if (inta & CX2_INTA_BIT_RF_KILL_DONE) { 1743 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
1070 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n"); 1744 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1071 priv->status |= STATUS_RF_KILL_HW; 1745 priv->status |= STATUS_RF_KILL_HW;
1072 wake_up_interruptible(&priv->wait_command_queue); 1746 wake_up_interruptible(&priv->wait_command_queue);
1073 netif_carrier_off(priv->net_dev); 1747 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1074 netif_stop_queue(priv->net_dev);
1075 cancel_delayed_work(&priv->request_scan); 1748 cancel_delayed_work(&priv->request_scan);
1749 schedule_work(&priv->link_down);
1076 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ); 1750 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
1077 handled |= CX2_INTA_BIT_RF_KILL_DONE; 1751 handled |= IPW_INTA_BIT_RF_KILL_DONE;
1078 } 1752 }
1079 1753
1080 if (inta & CX2_INTA_BIT_FATAL_ERROR) { 1754 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
1081 IPW_ERROR("Firmware error detected. Restarting.\n"); 1755 IPW_ERROR("Firmware error detected. Restarting.\n");
1756 if (priv->error) {
1757 IPW_ERROR("Sysfs 'error' log already exists.\n");
1082#ifdef CONFIG_IPW_DEBUG 1758#ifdef CONFIG_IPW_DEBUG
1083 if (ipw_debug_level & IPW_DL_FW_ERRORS) { 1759 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1084 ipw_dump_nic_error_log(priv); 1760 struct ipw_fw_error *error =
1085 ipw_dump_nic_event_log(priv); 1761 ipw_alloc_error_log(priv);
1086 } 1762 ipw_dump_error_log(priv, error);
1763 if (error)
1764 ipw_free_error_log(error);
1765 }
1087#endif 1766#endif
1767 } else {
1768 priv->error = ipw_alloc_error_log(priv);
1769 if (priv->error)
1770 IPW_ERROR("Sysfs 'error' log captured.\n");
1771 else
1772 IPW_ERROR("Error allocating sysfs 'error' "
1773 "log.\n");
1774#ifdef CONFIG_IPW_DEBUG
1775 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1776 ipw_dump_error_log(priv, priv->error);
1777#endif
1778 }
1779
1780 /* XXX: If hardware encryption is for WPA/WPA2,
1781 * we have to notify the supplicant. */
1782 if (priv->ieee->sec.encrypt) {
1783 priv->status &= ~STATUS_ASSOCIATED;
1784 notify_wx_assoc_event(priv);
1785 }
1786
1787 /* Keep the restart process from trying to send host
1788 * commands by clearing the INIT status bit */
1789 priv->status &= ~STATUS_INIT;
1790
1791 /* Cancel currently queued command. */
1792 priv->status &= ~STATUS_HCMD_ACTIVE;
1793 wake_up_interruptible(&priv->wait_command_queue);
1794
1088 queue_work(priv->workqueue, &priv->adapter_restart); 1795 queue_work(priv->workqueue, &priv->adapter_restart);
1089 handled |= CX2_INTA_BIT_FATAL_ERROR; 1796 handled |= IPW_INTA_BIT_FATAL_ERROR;
1090 } 1797 }
1091 1798
1092 if (inta & CX2_INTA_BIT_PARITY_ERROR) { 1799 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
1093 IPW_ERROR("Parity error\n"); 1800 IPW_ERROR("Parity error\n");
1094 handled |= CX2_INTA_BIT_PARITY_ERROR; 1801 handled |= IPW_INTA_BIT_PARITY_ERROR;
1095 } 1802 }
1096 1803
1097 if (handled != inta) { 1804 if (handled != inta) {
@@ -1104,7 +1811,6 @@ static void ipw_irq_tasklet(struct ipw_priv *priv)
1104 spin_unlock_irqrestore(&priv->lock, flags); 1811 spin_unlock_irqrestore(&priv->lock, flags);
1105} 1812}
1106 1813
1107#ifdef CONFIG_IPW_DEBUG
1108#define IPW_CMD(x) case IPW_CMD_ ## x : return #x 1814#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1109static char *get_cmd_string(u8 cmd) 1815static char *get_cmd_string(u8 cmd)
1110{ 1816{
@@ -1163,44 +1869,78 @@ static char *get_cmd_string(u8 cmd)
1163 return "UNKNOWN"; 1869 return "UNKNOWN";
1164 } 1870 }
1165} 1871}
1166#endif /* CONFIG_IPW_DEBUG */
1167 1872
1168#define HOST_COMPLETE_TIMEOUT HZ 1873#define HOST_COMPLETE_TIMEOUT HZ
1169static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd) 1874static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
1170{ 1875{
1171 int rc = 0; 1876 int rc = 0;
1877 unsigned long flags;
1172 1878
1879 spin_lock_irqsave(&priv->lock, flags);
1173 if (priv->status & STATUS_HCMD_ACTIVE) { 1880 if (priv->status & STATUS_HCMD_ACTIVE) {
1174 IPW_ERROR("Already sending a command\n"); 1881 IPW_ERROR("Failed to send %s: Already sending a command.\n",
1175 return -1; 1882 get_cmd_string(cmd->cmd));
1883 spin_unlock_irqrestore(&priv->lock, flags);
1884 return -EAGAIN;
1176 } 1885 }
1177 1886
1178 priv->status |= STATUS_HCMD_ACTIVE; 1887 priv->status |= STATUS_HCMD_ACTIVE;
1179 1888
1180 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n", 1889 if (priv->cmdlog) {
1181 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len); 1890 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
1891 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
1892 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
1893 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
1894 cmd->len);
1895 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
1896 }
1897
1898 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
1899 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
1900 priv->status);
1182 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len); 1901 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
1183 1902
1184 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0); 1903 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0);
1185 if (rc) 1904 if (rc) {
1186 return rc; 1905 priv->status &= ~STATUS_HCMD_ACTIVE;
1906 IPW_ERROR("Failed to send %s: Reason %d\n",
1907 get_cmd_string(cmd->cmd), rc);
1908 spin_unlock_irqrestore(&priv->lock, flags);
1909 goto exit;
1910 }
1911 spin_unlock_irqrestore(&priv->lock, flags);
1187 1912
1188 rc = wait_event_interruptible_timeout(priv->wait_command_queue, 1913 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1189 !(priv-> 1914 !(priv->
1190 status & STATUS_HCMD_ACTIVE), 1915 status & STATUS_HCMD_ACTIVE),
1191 HOST_COMPLETE_TIMEOUT); 1916 HOST_COMPLETE_TIMEOUT);
1192 if (rc == 0) { 1917 if (rc == 0) {
1193 IPW_DEBUG_INFO("Command completion failed out after %dms.\n", 1918 spin_lock_irqsave(&priv->lock, flags);
1194 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT)); 1919 if (priv->status & STATUS_HCMD_ACTIVE) {
1195 priv->status &= ~STATUS_HCMD_ACTIVE; 1920 IPW_ERROR("Failed to send %s: Command timed out.\n",
1196 return -EIO; 1921 get_cmd_string(cmd->cmd));
1197 } 1922 priv->status &= ~STATUS_HCMD_ACTIVE;
1198 if (priv->status & STATUS_RF_KILL_MASK) { 1923 spin_unlock_irqrestore(&priv->lock, flags);
1199 IPW_DEBUG_INFO("Command aborted due to RF Kill Switch\n"); 1924 rc = -EIO;
1200 return -EIO; 1925 goto exit;
1926 }
1927 spin_unlock_irqrestore(&priv->lock, flags);
1928 } else
1929 rc = 0;
1930
1931 if (priv->status & STATUS_RF_KILL_HW) {
1932 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
1933 get_cmd_string(cmd->cmd));
1934 rc = -EIO;
1935 goto exit;
1201 } 1936 }
1202 1937
1203 return 0; 1938 exit:
1939 if (priv->cmdlog) {
1940 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
1941 priv->cmdlog_pos %= priv->cmdlog_len;
1942 }
1943 return rc;
1204} 1944}
1205 1945
1206static int ipw_send_host_complete(struct ipw_priv *priv) 1946static int ipw_send_host_complete(struct ipw_priv *priv)
@@ -1215,12 +1955,7 @@ static int ipw_send_host_complete(struct ipw_priv *priv)
1215 return -1; 1955 return -1;
1216 } 1956 }
1217 1957
1218 if (ipw_send_cmd(priv, &cmd)) { 1958 return ipw_send_cmd(priv, &cmd);
1219 IPW_ERROR("failed to send HOST_COMPLETE command\n");
1220 return -1;
1221 }
1222
1223 return 0;
1224} 1959}
1225 1960
1226static int ipw_send_system_config(struct ipw_priv *priv, 1961static int ipw_send_system_config(struct ipw_priv *priv,
@@ -1236,13 +1971,8 @@ static int ipw_send_system_config(struct ipw_priv *priv,
1236 return -1; 1971 return -1;
1237 } 1972 }
1238 1973
1239 memcpy(&cmd.param, config, sizeof(*config)); 1974 memcpy(cmd.param, config, sizeof(*config));
1240 if (ipw_send_cmd(priv, &cmd)) { 1975 return ipw_send_cmd(priv, &cmd);
1241 IPW_ERROR("failed to send SYSTEM_CONFIG command\n");
1242 return -1;
1243 }
1244
1245 return 0;
1246} 1976}
1247 1977
1248static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len) 1978static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
@@ -1257,13 +1987,8 @@ static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
1257 return -1; 1987 return -1;
1258 } 1988 }
1259 1989
1260 memcpy(&cmd.param, ssid, cmd.len); 1990 memcpy(cmd.param, ssid, cmd.len);
1261 if (ipw_send_cmd(priv, &cmd)) { 1991 return ipw_send_cmd(priv, &cmd);
1262 IPW_ERROR("failed to send SSID command\n");
1263 return -1;
1264 }
1265
1266 return 0;
1267} 1992}
1268 1993
1269static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac) 1994static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
@@ -1281,16 +2006,15 @@ static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
1281 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n", 2006 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
1282 priv->net_dev->name, MAC_ARG(mac)); 2007 priv->net_dev->name, MAC_ARG(mac));
1283 2008
1284 memcpy(&cmd.param, mac, ETH_ALEN); 2009 memcpy(cmd.param, mac, ETH_ALEN);
1285 2010 return ipw_send_cmd(priv, &cmd);
1286 if (ipw_send_cmd(priv, &cmd)) {
1287 IPW_ERROR("failed to send ADAPTER_ADDRESS command\n");
1288 return -1;
1289 }
1290
1291 return 0;
1292} 2011}
1293 2012
2013/*
2014 * NOTE: This must be executed from our workqueue as it results in udelay
2015 * being called which may corrupt the keyboard if executed on default
2016 * workqueue
2017 */
1294static void ipw_adapter_restart(void *adapter) 2018static void ipw_adapter_restart(void *adapter)
1295{ 2019{
1296 struct ipw_priv *priv = adapter; 2020 struct ipw_priv *priv = adapter;
@@ -1299,12 +2023,25 @@ static void ipw_adapter_restart(void *adapter)
1299 return; 2023 return;
1300 2024
1301 ipw_down(priv); 2025 ipw_down(priv);
2026
2027 if (priv->assoc_network &&
2028 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2029 ipw_remove_current_network(priv);
2030
1302 if (ipw_up(priv)) { 2031 if (ipw_up(priv)) {
1303 IPW_ERROR("Failed to up device\n"); 2032 IPW_ERROR("Failed to up device\n");
1304 return; 2033 return;
1305 } 2034 }
1306} 2035}
1307 2036
2037static void ipw_bg_adapter_restart(void *data)
2038{
2039 struct ipw_priv *priv = data;
2040 down(&priv->sem);
2041 ipw_adapter_restart(data);
2042 up(&priv->sem);
2043}
2044
1308#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ) 2045#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
1309 2046
1310static void ipw_scan_check(void *data) 2047static void ipw_scan_check(void *data)
@@ -1314,10 +2051,18 @@ static void ipw_scan_check(void *data)
1314 IPW_DEBUG_SCAN("Scan completion watchdog resetting " 2051 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
1315 "adapter (%dms).\n", 2052 "adapter (%dms).\n",
1316 IPW_SCAN_CHECK_WATCHDOG / 100); 2053 IPW_SCAN_CHECK_WATCHDOG / 100);
1317 ipw_adapter_restart(priv); 2054 queue_work(priv->workqueue, &priv->adapter_restart);
1318 } 2055 }
1319} 2056}
1320 2057
2058static void ipw_bg_scan_check(void *data)
2059{
2060 struct ipw_priv *priv = data;
2061 down(&priv->sem);
2062 ipw_scan_check(data);
2063 up(&priv->sem);
2064}
2065
1321static int ipw_send_scan_request_ext(struct ipw_priv *priv, 2066static int ipw_send_scan_request_ext(struct ipw_priv *priv,
1322 struct ipw_scan_request_ext *request) 2067 struct ipw_scan_request_ext *request)
1323{ 2068{
@@ -1326,20 +2071,8 @@ static int ipw_send_scan_request_ext(struct ipw_priv *priv,
1326 .len = sizeof(*request) 2071 .len = sizeof(*request)
1327 }; 2072 };
1328 2073
1329 if (!priv || !request) { 2074 memcpy(cmd.param, request, sizeof(*request));
1330 IPW_ERROR("Invalid args\n"); 2075 return ipw_send_cmd(priv, &cmd);
1331 return -1;
1332 }
1333
1334 memcpy(&cmd.param, request, sizeof(*request));
1335 if (ipw_send_cmd(priv, &cmd)) {
1336 IPW_ERROR("failed to send SCAN_REQUEST_EXT command\n");
1337 return -1;
1338 }
1339
1340 queue_delayed_work(priv->workqueue, &priv->scan_check,
1341 IPW_SCAN_CHECK_WATCHDOG);
1342 return 0;
1343} 2076}
1344 2077
1345static int ipw_send_scan_abort(struct ipw_priv *priv) 2078static int ipw_send_scan_abort(struct ipw_priv *priv)
@@ -1354,12 +2087,7 @@ static int ipw_send_scan_abort(struct ipw_priv *priv)
1354 return -1; 2087 return -1;
1355 } 2088 }
1356 2089
1357 if (ipw_send_cmd(priv, &cmd)) { 2090 return ipw_send_cmd(priv, &cmd);
1358 IPW_ERROR("failed to send SCAN_ABORT command\n");
1359 return -1;
1360 }
1361
1362 return 0;
1363} 2091}
1364 2092
1365static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens) 2093static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
@@ -1371,12 +2099,7 @@ static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
1371 struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *) 2099 struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *)
1372 &cmd.param; 2100 &cmd.param;
1373 calib->beacon_rssi_raw = sens; 2101 calib->beacon_rssi_raw = sens;
1374 if (ipw_send_cmd(priv, &cmd)) { 2102 return ipw_send_cmd(priv, &cmd);
1375 IPW_ERROR("failed to send SENSITIVITY CALIB command\n");
1376 return -1;
1377 }
1378
1379 return 0;
1380} 2103}
1381 2104
1382static int ipw_send_associate(struct ipw_priv *priv, 2105static int ipw_send_associate(struct ipw_priv *priv,
@@ -1387,18 +2110,26 @@ static int ipw_send_associate(struct ipw_priv *priv,
1387 .len = sizeof(*associate) 2110 .len = sizeof(*associate)
1388 }; 2111 };
1389 2112
2113 struct ipw_associate tmp_associate;
2114 memcpy(&tmp_associate, associate, sizeof(*associate));
2115 tmp_associate.policy_support =
2116 cpu_to_le16(tmp_associate.policy_support);
2117 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2118 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2119 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2120 tmp_associate.listen_interval =
2121 cpu_to_le16(tmp_associate.listen_interval);
2122 tmp_associate.beacon_interval =
2123 cpu_to_le16(tmp_associate.beacon_interval);
2124 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2125
1390 if (!priv || !associate) { 2126 if (!priv || !associate) {
1391 IPW_ERROR("Invalid args\n"); 2127 IPW_ERROR("Invalid args\n");
1392 return -1; 2128 return -1;
1393 } 2129 }
1394 2130
1395 memcpy(&cmd.param, associate, sizeof(*associate)); 2131 memcpy(cmd.param, &tmp_associate, sizeof(*associate));
1396 if (ipw_send_cmd(priv, &cmd)) { 2132 return ipw_send_cmd(priv, &cmd);
1397 IPW_ERROR("failed to send ASSOCIATE command\n");
1398 return -1;
1399 }
1400
1401 return 0;
1402} 2133}
1403 2134
1404static int ipw_send_supported_rates(struct ipw_priv *priv, 2135static int ipw_send_supported_rates(struct ipw_priv *priv,
@@ -1414,13 +2145,8 @@ static int ipw_send_supported_rates(struct ipw_priv *priv,
1414 return -1; 2145 return -1;
1415 } 2146 }
1416 2147
1417 memcpy(&cmd.param, rates, sizeof(*rates)); 2148 memcpy(cmd.param, rates, sizeof(*rates));
1418 if (ipw_send_cmd(priv, &cmd)) { 2149 return ipw_send_cmd(priv, &cmd);
1419 IPW_ERROR("failed to send SUPPORTED_RATES command\n");
1420 return -1;
1421 }
1422
1423 return 0;
1424} 2150}
1425 2151
1426static int ipw_set_random_seed(struct ipw_priv *priv) 2152static int ipw_set_random_seed(struct ipw_priv *priv)
@@ -1437,15 +2163,9 @@ static int ipw_set_random_seed(struct ipw_priv *priv)
1437 2163
1438 get_random_bytes(&cmd.param, sizeof(u32)); 2164 get_random_bytes(&cmd.param, sizeof(u32));
1439 2165
1440 if (ipw_send_cmd(priv, &cmd)) { 2166 return ipw_send_cmd(priv, &cmd);
1441 IPW_ERROR("failed to send SEED_NUMBER command\n");
1442 return -1;
1443 }
1444
1445 return 0;
1446} 2167}
1447 2168
1448#if 0
1449static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off) 2169static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
1450{ 2170{
1451 struct host_cmd cmd = { 2171 struct host_cmd cmd = {
@@ -1460,14 +2180,8 @@ static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
1460 2180
1461 *((u32 *) & cmd.param) = phy_off; 2181 *((u32 *) & cmd.param) = phy_off;
1462 2182
1463 if (ipw_send_cmd(priv, &cmd)) { 2183 return ipw_send_cmd(priv, &cmd);
1464 IPW_ERROR("failed to send CARD_DISABLE command\n");
1465 return -1;
1466 }
1467
1468 return 0;
1469} 2184}
1470#endif
1471 2185
1472static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power) 2186static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
1473{ 2187{
@@ -1481,12 +2195,51 @@ static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
1481 return -1; 2195 return -1;
1482 } 2196 }
1483 2197
1484 memcpy(&cmd.param, power, sizeof(*power)); 2198 memcpy(cmd.param, power, sizeof(*power));
1485 if (ipw_send_cmd(priv, &cmd)) { 2199 return ipw_send_cmd(priv, &cmd);
1486 IPW_ERROR("failed to send TX_POWER command\n"); 2200}
1487 return -1; 2201
2202static int ipw_set_tx_power(struct ipw_priv *priv)
2203{
2204 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
2205 struct ipw_tx_power tx_power;
2206 s8 max_power;
2207 int i;
2208
2209 memset(&tx_power, 0, sizeof(tx_power));
2210
2211 /* configure device for 'G' band */
2212 tx_power.ieee_mode = IPW_G_MODE;
2213 tx_power.num_channels = geo->bg_channels;
2214 for (i = 0; i < geo->bg_channels; i++) {
2215 max_power = geo->bg[i].max_power;
2216 tx_power.channels_tx_power[i].channel_number =
2217 geo->bg[i].channel;
2218 tx_power.channels_tx_power[i].tx_power = max_power ?
2219 min(max_power, priv->tx_power) : priv->tx_power;
1488 } 2220 }
2221 if (ipw_send_tx_power(priv, &tx_power))
2222 return -EIO;
2223
2224 /* configure device to also handle 'B' band */
2225 tx_power.ieee_mode = IPW_B_MODE;
2226 if (ipw_send_tx_power(priv, &tx_power))
2227 return -EIO;
1489 2228
2229 /* configure device to also handle 'A' band */
2230 if (priv->ieee->abg_true) {
2231 tx_power.ieee_mode = IPW_A_MODE;
2232 tx_power.num_channels = geo->a_channels;
2233 for (i = 0; i < tx_power.num_channels; i++) {
2234 max_power = geo->a[i].max_power;
2235 tx_power.channels_tx_power[i].channel_number =
2236 geo->a[i].channel;
2237 tx_power.channels_tx_power[i].tx_power = max_power ?
2238 min(max_power, priv->tx_power) : priv->tx_power;
2239 }
2240 if (ipw_send_tx_power(priv, &tx_power))
2241 return -EIO;
2242 }
1490 return 0; 2243 return 0;
1491} 2244}
1492 2245
@@ -1505,13 +2258,8 @@ static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
1505 return -1; 2258 return -1;
1506 } 2259 }
1507 2260
1508 memcpy(&cmd.param, &rts_threshold, sizeof(rts_threshold)); 2261 memcpy(cmd.param, &rts_threshold, sizeof(rts_threshold));
1509 if (ipw_send_cmd(priv, &cmd)) { 2262 return ipw_send_cmd(priv, &cmd);
1510 IPW_ERROR("failed to send RTS_THRESHOLD command\n");
1511 return -1;
1512 }
1513
1514 return 0;
1515} 2263}
1516 2264
1517static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag) 2265static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
@@ -1529,13 +2277,8 @@ static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
1529 return -1; 2277 return -1;
1530 } 2278 }
1531 2279
1532 memcpy(&cmd.param, &frag_threshold, sizeof(frag_threshold)); 2280 memcpy(cmd.param, &frag_threshold, sizeof(frag_threshold));
1533 if (ipw_send_cmd(priv, &cmd)) { 2281 return ipw_send_cmd(priv, &cmd);
1534 IPW_ERROR("failed to send FRAG_THRESHOLD command\n");
1535 return -1;
1536 }
1537
1538 return 0;
1539} 2282}
1540 2283
1541static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode) 2284static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
@@ -1565,12 +2308,27 @@ static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
1565 break; 2308 break;
1566 } 2309 }
1567 2310
1568 if (ipw_send_cmd(priv, &cmd)) { 2311 return ipw_send_cmd(priv, &cmd);
1569 IPW_ERROR("failed to send POWER_MODE command\n"); 2312}
2313
2314static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2315{
2316 struct ipw_retry_limit retry_limit = {
2317 .short_retry_limit = slimit,
2318 .long_retry_limit = llimit
2319 };
2320 struct host_cmd cmd = {
2321 .cmd = IPW_CMD_RETRY_LIMIT,
2322 .len = sizeof(retry_limit)
2323 };
2324
2325 if (!priv) {
2326 IPW_ERROR("Invalid args\n");
1570 return -1; 2327 return -1;
1571 } 2328 }
1572 2329
1573 return 0; 2330 memcpy(cmd.param, &retry_limit, sizeof(retry_limit));
2331 return ipw_send_cmd(priv, &cmd);
1574} 2332}
1575 2333
1576/* 2334/*
@@ -1672,8 +2430,7 @@ static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
1672/* data's copy of the eeprom data */ 2430/* data's copy of the eeprom data */
1673static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac) 2431static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
1674{ 2432{
1675 u8 *ee = (u8 *) priv->eeprom; 2433 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
1676 memcpy(mac, &ee[EEPROM_MAC_ADDRESS], 6);
1677} 2434}
1678 2435
1679/* 2436/*
@@ -1693,7 +2450,7 @@ static void ipw_eeprom_init_sram(struct ipw_priv *priv)
1693 2450
1694 /* read entire contents of eeprom into private buffer */ 2451 /* read entire contents of eeprom into private buffer */
1695 for (i = 0; i < 128; i++) 2452 for (i = 0; i < 128; i++)
1696 eeprom[i] = eeprom_read_u16(priv, (u8) i); 2453 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
1697 2454
1698 /* 2455 /*
1699 If the data looks correct, then copy it to our private 2456 If the data looks correct, then copy it to our private
@@ -1704,7 +2461,7 @@ static void ipw_eeprom_init_sram(struct ipw_priv *priv)
1704 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n"); 2461 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
1705 2462
1706 /* write the eeprom data to sram */ 2463 /* write the eeprom data to sram */
1707 for (i = 0; i < CX2_EEPROM_IMAGE_SIZE; i++) 2464 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
1708 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]); 2465 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
1709 2466
1710 /* Do not load eeprom data on fatal error or suspend */ 2467 /* Do not load eeprom data on fatal error or suspend */
@@ -1724,14 +2481,14 @@ static inline void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
1724 count >>= 2; 2481 count >>= 2;
1725 if (!count) 2482 if (!count)
1726 return; 2483 return;
1727 _ipw_write32(priv, CX2_AUTOINC_ADDR, start); 2484 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
1728 while (count--) 2485 while (count--)
1729 _ipw_write32(priv, CX2_AUTOINC_DATA, 0); 2486 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
1730} 2487}
1731 2488
1732static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv) 2489static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
1733{ 2490{
1734 ipw_zero_memory(priv, CX2_SHARED_SRAM_DMA_CONTROL, 2491 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
1735 CB_NUMBER_OF_ELEMENTS_SMALL * 2492 CB_NUMBER_OF_ELEMENTS_SMALL *
1736 sizeof(struct command_block)); 2493 sizeof(struct command_block));
1737} 2494}
@@ -1745,7 +2502,7 @@ static int ipw_fw_dma_enable(struct ipw_priv *priv)
1745 ipw_fw_dma_reset_command_blocks(priv); 2502 ipw_fw_dma_reset_command_blocks(priv);
1746 2503
1747 /* Write CB base address */ 2504 /* Write CB base address */
1748 ipw_write_reg32(priv, CX2_DMA_I_CB_BASE, CX2_SHARED_SRAM_DMA_CONTROL); 2505 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
1749 2506
1750 IPW_DEBUG_FW("<< : \n"); 2507 IPW_DEBUG_FW("<< : \n");
1751 return 0; 2508 return 0;
@@ -1759,7 +2516,7 @@ static void ipw_fw_dma_abort(struct ipw_priv *priv)
1759 2516
1760 //set the Stop and Abort bit 2517 //set the Stop and Abort bit
1761 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT; 2518 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
1762 ipw_write_reg32(priv, CX2_DMA_I_DMA_CONTROL, control); 2519 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
1763 priv->sram_desc.last_cb_index = 0; 2520 priv->sram_desc.last_cb_index = 0;
1764 2521
1765 IPW_DEBUG_FW("<< \n"); 2522 IPW_DEBUG_FW("<< \n");
@@ -1769,7 +2526,7 @@ static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
1769 struct command_block *cb) 2526 struct command_block *cb)
1770{ 2527{
1771 u32 address = 2528 u32 address =
1772 CX2_SHARED_SRAM_DMA_CONTROL + 2529 IPW_SHARED_SRAM_DMA_CONTROL +
1773 (sizeof(struct command_block) * index); 2530 (sizeof(struct command_block) * index);
1774 IPW_DEBUG_FW(">> :\n"); 2531 IPW_DEBUG_FW(">> :\n");
1775 2532
@@ -1793,13 +2550,13 @@ static int ipw_fw_dma_kick(struct ipw_priv *priv)
1793 &priv->sram_desc.cb_list[index]); 2550 &priv->sram_desc.cb_list[index]);
1794 2551
1795 /* Enable the DMA in the CSR register */ 2552 /* Enable the DMA in the CSR register */
1796 ipw_clear_bit(priv, CX2_RESET_REG, 2553 ipw_clear_bit(priv, IPW_RESET_REG,
1797 CX2_RESET_REG_MASTER_DISABLED | 2554 IPW_RESET_REG_MASTER_DISABLED |
1798 CX2_RESET_REG_STOP_MASTER); 2555 IPW_RESET_REG_STOP_MASTER);
1799 2556
1800 /* Set the Start bit. */ 2557 /* Set the Start bit. */
1801 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START; 2558 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
1802 ipw_write_reg32(priv, CX2_DMA_I_DMA_CONTROL, control); 2559 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
1803 2560
1804 IPW_DEBUG_FW("<< :\n"); 2561 IPW_DEBUG_FW("<< :\n");
1805 return 0; 2562 return 0;
@@ -1812,12 +2569,12 @@ static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
1812 u32 cb_fields_address = 0; 2569 u32 cb_fields_address = 0;
1813 2570
1814 IPW_DEBUG_FW(">> :\n"); 2571 IPW_DEBUG_FW(">> :\n");
1815 address = ipw_read_reg32(priv, CX2_DMA_I_CURRENT_CB); 2572 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
1816 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address); 2573 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
1817 2574
1818 /* Read the DMA Controlor register */ 2575 /* Read the DMA Controlor register */
1819 register_value = ipw_read_reg32(priv, CX2_DMA_I_DMA_CONTROL); 2576 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
1820 IPW_DEBUG_FW_INFO("CX2_DMA_I_DMA_CONTROL is 0x%x \n", register_value); 2577 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
1821 2578
1822 /* Print the CB values */ 2579 /* Print the CB values */
1823 cb_fields_address = address; 2580 cb_fields_address = address;
@@ -1846,9 +2603,9 @@ static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
1846 u32 current_cb_index = 0; 2603 u32 current_cb_index = 0;
1847 2604
1848 IPW_DEBUG_FW("<< :\n"); 2605 IPW_DEBUG_FW("<< :\n");
1849 current_cb_address = ipw_read_reg32(priv, CX2_DMA_I_CURRENT_CB); 2606 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
1850 2607
1851 current_cb_index = (current_cb_address - CX2_SHARED_SRAM_DMA_CONTROL) / 2608 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
1852 sizeof(struct command_block); 2609 sizeof(struct command_block);
1853 2610
1854 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n", 2611 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
@@ -1977,8 +2734,8 @@ static int ipw_fw_dma_wait(struct ipw_priv *priv)
1977 ipw_fw_dma_abort(priv); 2734 ipw_fw_dma_abort(priv);
1978 2735
1979 /*Disable the DMA in the CSR register */ 2736 /*Disable the DMA in the CSR register */
1980 ipw_set_bit(priv, CX2_RESET_REG, 2737 ipw_set_bit(priv, IPW_RESET_REG,
1981 CX2_RESET_REG_MASTER_DISABLED | CX2_RESET_REG_STOP_MASTER); 2738 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
1982 2739
1983 IPW_DEBUG_FW("<< dmaWaitSync \n"); 2740 IPW_DEBUG_FW("<< dmaWaitSync \n");
1984 return 0; 2741 return 0;
@@ -1988,6 +2745,9 @@ static void ipw_remove_current_network(struct ipw_priv *priv)
1988{ 2745{
1989 struct list_head *element, *safe; 2746 struct list_head *element, *safe;
1990 struct ieee80211_network *network = NULL; 2747 struct ieee80211_network *network = NULL;
2748 unsigned long flags;
2749
2750 spin_lock_irqsave(&priv->ieee->lock, flags);
1991 list_for_each_safe(element, safe, &priv->ieee->network_list) { 2751 list_for_each_safe(element, safe, &priv->ieee->network_list) {
1992 network = list_entry(element, struct ieee80211_network, list); 2752 network = list_entry(element, struct ieee80211_network, list);
1993 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) { 2753 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
@@ -1996,6 +2756,7 @@ static void ipw_remove_current_network(struct ipw_priv *priv)
1996 &priv->ieee->network_free_list); 2756 &priv->ieee->network_free_list);
1997 } 2757 }
1998 } 2758 }
2759 spin_unlock_irqrestore(&priv->ieee->lock, flags);
1999} 2760}
2000 2761
2001/** 2762/**
@@ -2038,10 +2799,10 @@ static int ipw_stop_master(struct ipw_priv *priv)
2038 2799
2039 IPW_DEBUG_TRACE(">> \n"); 2800 IPW_DEBUG_TRACE(">> \n");
2040 /* stop master. typical delay - 0 */ 2801 /* stop master. typical delay - 0 */
2041 ipw_set_bit(priv, CX2_RESET_REG, CX2_RESET_REG_STOP_MASTER); 2802 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
2042 2803
2043 rc = ipw_poll_bit(priv, CX2_RESET_REG, 2804 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2044 CX2_RESET_REG_MASTER_DISABLED, 100); 2805 IPW_RESET_REG_MASTER_DISABLED, 100);
2045 if (rc < 0) { 2806 if (rc < 0) {
2046 IPW_ERROR("stop master failed in 10ms\n"); 2807 IPW_ERROR("stop master failed in 10ms\n");
2047 return -1; 2808 return -1;
@@ -2057,7 +2818,7 @@ static void ipw_arc_release(struct ipw_priv *priv)
2057 IPW_DEBUG_TRACE(">> \n"); 2818 IPW_DEBUG_TRACE(">> \n");
2058 mdelay(5); 2819 mdelay(5);
2059 2820
2060 ipw_clear_bit(priv, CX2_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); 2821 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
2061 2822
2062 /* no one knows timing, for safety add some delay */ 2823 /* no one knows timing, for safety add some delay */
2063 mdelay(5); 2824 mdelay(5);
@@ -2074,13 +2835,12 @@ struct fw_chunk {
2074}; 2835};
2075 2836
2076#define IPW_FW_MAJOR_VERSION 2 2837#define IPW_FW_MAJOR_VERSION 2
2077#define IPW_FW_MINOR_VERSION 2 2838#define IPW_FW_MINOR_VERSION 4
2078 2839
2079#define IPW_FW_MINOR(x) ((x & 0xff) >> 8) 2840#define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
2080#define IPW_FW_MAJOR(x) (x & 0xff) 2841#define IPW_FW_MAJOR(x) (x & 0xff)
2081 2842
2082#define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | \ 2843#define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | IPW_FW_MAJOR_VERSION)
2083 IPW_FW_MAJOR_VERSION)
2084 2844
2085#define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \ 2845#define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
2086"." __stringify(IPW_FW_MINOR_VERSION) "-" 2846"." __stringify(IPW_FW_MINOR_VERSION) "-"
@@ -2108,8 +2868,8 @@ static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
2108 2868
2109// spin_lock_irqsave(&priv->lock, flags); 2869// spin_lock_irqsave(&priv->lock, flags);
2110 2870
2111 for (addr = CX2_SHARED_LOWER_BOUND; 2871 for (addr = IPW_SHARED_LOWER_BOUND;
2112 addr < CX2_REGISTER_DOMAIN1_END; addr += 4) { 2872 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
2113 ipw_write32(priv, addr, 0); 2873 ipw_write32(priv, addr, 0);
2114 } 2874 }
2115 2875
@@ -2118,16 +2878,16 @@ static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
2118 /* destroy DMA queues */ 2878 /* destroy DMA queues */
2119 /* reset sequence */ 2879 /* reset sequence */
2120 2880
2121 ipw_write_reg32(priv, CX2_MEM_HALT_AND_RESET, CX2_BIT_HALT_RESET_ON); 2881 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
2122 ipw_arc_release(priv); 2882 ipw_arc_release(priv);
2123 ipw_write_reg32(priv, CX2_MEM_HALT_AND_RESET, CX2_BIT_HALT_RESET_OFF); 2883 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
2124 mdelay(1); 2884 mdelay(1);
2125 2885
2126 /* reset PHY */ 2886 /* reset PHY */
2127 ipw_write_reg32(priv, CX2_INTERNAL_CMD_EVENT, CX2_BASEBAND_POWER_DOWN); 2887 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
2128 mdelay(1); 2888 mdelay(1);
2129 2889
2130 ipw_write_reg32(priv, CX2_INTERNAL_CMD_EVENT, 0); 2890 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
2131 mdelay(1); 2891 mdelay(1);
2132 2892
2133 /* enable ucode store */ 2893 /* enable ucode store */
@@ -2145,18 +2905,19 @@ static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
2145 */ 2905 */
2146 /* load new ipw uCode */ 2906 /* load new ipw uCode */
2147 for (i = 0; i < len / 2; i++) 2907 for (i = 0; i < len / 2; i++)
2148 ipw_write_reg16(priv, CX2_BASEBAND_CONTROL_STORE, image[i]); 2908 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
2909 cpu_to_le16(image[i]));
2149 2910
2150 /* enable DINO */ 2911 /* enable DINO */
2151 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 0); 2912 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2152 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM); 2913 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
2153 2914
2154 /* this is where the igx / win driver deveates from the VAP driver. */ 2915 /* this is where the igx / win driver deveates from the VAP driver. */
2155 2916
2156 /* wait for alive response */ 2917 /* wait for alive response */
2157 for (i = 0; i < 100; i++) { 2918 for (i = 0; i < 100; i++) {
2158 /* poll for incoming data */ 2919 /* poll for incoming data */
2159 cr = ipw_read_reg8(priv, CX2_BASEBAND_CONTROL_STATUS); 2920 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
2160 if (cr & DINO_RXFIFO_DATA) 2921 if (cr & DINO_RXFIFO_DATA)
2161 break; 2922 break;
2162 mdelay(1); 2923 mdelay(1);
@@ -2168,7 +2929,8 @@ static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
2168 2929
2169 for (i = 0; i < ARRAY_SIZE(response_buffer); i++) 2930 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
2170 response_buffer[i] = 2931 response_buffer[i] =
2171 ipw_read_reg32(priv, CX2_BASEBAND_RX_FIFO_READ); 2932 le32_to_cpu(ipw_read_reg32(priv,
2933 IPW_BASEBAND_RX_FIFO_READ));
2172 memcpy(&priv->dino_alive, response_buffer, 2934 memcpy(&priv->dino_alive, response_buffer,
2173 sizeof(priv->dino_alive)); 2935 sizeof(priv->dino_alive));
2174 if (priv->dino_alive.alive_command == 1 2936 if (priv->dino_alive.alive_command == 1
@@ -2197,7 +2959,7 @@ static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
2197 2959
2198 /* disable DINO, otherwise for some reason 2960 /* disable DINO, otherwise for some reason
2199 firmware have problem getting alive resp. */ 2961 firmware have problem getting alive resp. */
2200 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 0); 2962 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2201 2963
2202// spin_unlock_irqrestore(&priv->lock, flags); 2964// spin_unlock_irqrestore(&priv->lock, flags);
2203 2965
@@ -2237,13 +2999,14 @@ static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
2237 * offeset*/ 2999 * offeset*/
2238 /* Dma loading */ 3000 /* Dma loading */
2239 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset, 3001 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
2240 chunk->address, chunk->length); 3002 le32_to_cpu(chunk->address),
3003 le32_to_cpu(chunk->length));
2241 if (rc) { 3004 if (rc) {
2242 IPW_DEBUG_INFO("dmaAddBuffer Failed\n"); 3005 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
2243 goto out; 3006 goto out;
2244 } 3007 }
2245 3008
2246 offset += chunk->length; 3009 offset += le32_to_cpu(chunk->length);
2247 } while (offset < len); 3010 } while (offset < len);
2248 3011
2249 /* Run the DMA and wait for the answer */ 3012 /* Run the DMA and wait for the answer */
@@ -2269,16 +3032,16 @@ static int ipw_stop_nic(struct ipw_priv *priv)
2269 int rc = 0; 3032 int rc = 0;
2270 3033
2271 /* stop */ 3034 /* stop */
2272 ipw_write32(priv, CX2_RESET_REG, CX2_RESET_REG_STOP_MASTER); 3035 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
2273 3036
2274 rc = ipw_poll_bit(priv, CX2_RESET_REG, 3037 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2275 CX2_RESET_REG_MASTER_DISABLED, 500); 3038 IPW_RESET_REG_MASTER_DISABLED, 500);
2276 if (rc < 0) { 3039 if (rc < 0) {
2277 IPW_ERROR("wait for reg master disabled failed\n"); 3040 IPW_ERROR("wait for reg master disabled failed\n");
2278 return rc; 3041 return rc;
2279 } 3042 }
2280 3043
2281 ipw_set_bit(priv, CX2_RESET_REG, CBD_RESET_REG_PRINCETON_RESET); 3044 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
2282 3045
2283 return rc; 3046 return rc;
2284} 3047}
@@ -2288,14 +3051,14 @@ static void ipw_start_nic(struct ipw_priv *priv)
2288 IPW_DEBUG_TRACE(">>\n"); 3051 IPW_DEBUG_TRACE(">>\n");
2289 3052
2290 /* prvHwStartNic release ARC */ 3053 /* prvHwStartNic release ARC */
2291 ipw_clear_bit(priv, CX2_RESET_REG, 3054 ipw_clear_bit(priv, IPW_RESET_REG,
2292 CX2_RESET_REG_MASTER_DISABLED | 3055 IPW_RESET_REG_MASTER_DISABLED |
2293 CX2_RESET_REG_STOP_MASTER | 3056 IPW_RESET_REG_STOP_MASTER |
2294 CBD_RESET_REG_PRINCETON_RESET); 3057 CBD_RESET_REG_PRINCETON_RESET);
2295 3058
2296 /* enable power management */ 3059 /* enable power management */
2297 ipw_set_bit(priv, CX2_GP_CNTRL_RW, 3060 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
2298 CX2_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY); 3061 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
2299 3062
2300 IPW_DEBUG_TRACE("<<\n"); 3063 IPW_DEBUG_TRACE("<<\n");
2301} 3064}
@@ -2308,25 +3071,25 @@ static int ipw_init_nic(struct ipw_priv *priv)
2308 /* reset */ 3071 /* reset */
2309 /*prvHwInitNic */ 3072 /*prvHwInitNic */
2310 /* set "initialization complete" bit to move adapter to D0 state */ 3073 /* set "initialization complete" bit to move adapter to D0 state */
2311 ipw_set_bit(priv, CX2_GP_CNTRL_RW, CX2_GP_CNTRL_BIT_INIT_DONE); 3074 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
2312 3075
2313 /* low-level PLL activation */ 3076 /* low-level PLL activation */
2314 ipw_write32(priv, CX2_READ_INT_REGISTER, 3077 ipw_write32(priv, IPW_READ_INT_REGISTER,
2315 CX2_BIT_INT_HOST_SRAM_READ_INT_REGISTER); 3078 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
2316 3079
2317 /* wait for clock stabilization */ 3080 /* wait for clock stabilization */
2318 rc = ipw_poll_bit(priv, CX2_GP_CNTRL_RW, 3081 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
2319 CX2_GP_CNTRL_BIT_CLOCK_READY, 250); 3082 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
2320 if (rc < 0) 3083 if (rc < 0)
2321 IPW_DEBUG_INFO("FAILED wait for clock stablization\n"); 3084 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
2322 3085
2323 /* assert SW reset */ 3086 /* assert SW reset */
2324 ipw_set_bit(priv, CX2_RESET_REG, CX2_RESET_REG_SW_RESET); 3087 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
2325 3088
2326 udelay(10); 3089 udelay(10);
2327 3090
2328 /* set "initialization complete" bit to move adapter to D0 state */ 3091 /* set "initialization complete" bit to move adapter to D0 state */
2329 ipw_set_bit(priv, CX2_GP_CNTRL_RW, CX2_GP_CNTRL_BIT_INIT_DONE); 3092 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
2330 3093
2331 IPW_DEBUG_TRACE(">>\n"); 3094 IPW_DEBUG_TRACE(">>\n");
2332 return 0; 3095 return 0;
@@ -2338,14 +3101,19 @@ static int ipw_init_nic(struct ipw_priv *priv)
2338static int ipw_reset_nic(struct ipw_priv *priv) 3101static int ipw_reset_nic(struct ipw_priv *priv)
2339{ 3102{
2340 int rc = 0; 3103 int rc = 0;
3104 unsigned long flags;
2341 3105
2342 IPW_DEBUG_TRACE(">>\n"); 3106 IPW_DEBUG_TRACE(">>\n");
2343 3107
2344 rc = ipw_init_nic(priv); 3108 rc = ipw_init_nic(priv);
2345 3109
3110 spin_lock_irqsave(&priv->lock, flags);
2346 /* Clear the 'host command active' bit... */ 3111 /* Clear the 'host command active' bit... */
2347 priv->status &= ~STATUS_HCMD_ACTIVE; 3112 priv->status &= ~STATUS_HCMD_ACTIVE;
2348 wake_up_interruptible(&priv->wait_command_queue); 3113 wake_up_interruptible(&priv->wait_command_queue);
3114 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3115 wake_up_interruptible(&priv->wait_state);
3116 spin_unlock_irqrestore(&priv->lock, flags);
2349 3117
2350 IPW_DEBUG_TRACE("<<\n"); 3118 IPW_DEBUG_TRACE("<<\n");
2351 return rc; 3119 return rc;
@@ -2365,22 +3133,23 @@ static int ipw_get_fw(struct ipw_priv *priv,
2365 } 3133 }
2366 3134
2367 header = (struct fw_header *)(*fw)->data; 3135 header = (struct fw_header *)(*fw)->data;
2368 if (IPW_FW_MAJOR(header->version) != IPW_FW_MAJOR_VERSION) { 3136 if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) {
2369 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n", 3137 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
2370 name, 3138 name,
2371 IPW_FW_MAJOR(header->version), IPW_FW_MAJOR_VERSION); 3139 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3140 IPW_FW_MAJOR_VERSION);
2372 return -EINVAL; 3141 return -EINVAL;
2373 } 3142 }
2374 3143
2375 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n", 3144 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
2376 name, 3145 name,
2377 IPW_FW_MAJOR(header->version), 3146 IPW_FW_MAJOR(le32_to_cpu(header->version)),
2378 IPW_FW_MINOR(header->version), 3147 IPW_FW_MINOR(le32_to_cpu(header->version)),
2379 (*fw)->size - sizeof(struct fw_header)); 3148 (*fw)->size - sizeof(struct fw_header));
2380 return 0; 3149 return 0;
2381} 3150}
2382 3151
2383#define CX2_RX_BUF_SIZE (3000) 3152#define IPW_RX_BUF_SIZE (3000)
2384 3153
2385static inline void ipw_rx_queue_reset(struct ipw_priv *priv, 3154static inline void ipw_rx_queue_reset(struct ipw_priv *priv,
2386 struct ipw_rx_queue *rxq) 3155 struct ipw_rx_queue *rxq)
@@ -2399,8 +3168,9 @@ static inline void ipw_rx_queue_reset(struct ipw_priv *priv,
2399 * to an SKB, so we need to unmap and free potential storage */ 3168 * to an SKB, so we need to unmap and free potential storage */
2400 if (rxq->pool[i].skb != NULL) { 3169 if (rxq->pool[i].skb != NULL) {
2401 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, 3170 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
2402 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); 3171 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
2403 dev_kfree_skb(rxq->pool[i].skb); 3172 dev_kfree_skb(rxq->pool[i].skb);
3173 rxq->pool[i].skb = NULL;
2404 } 3174 }
2405 list_add_tail(&rxq->pool[i].list, &rxq->rx_used); 3175 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
2406 } 3176 }
@@ -2418,6 +3188,19 @@ static int fw_loaded = 0;
2418static const struct firmware *bootfw = NULL; 3188static const struct firmware *bootfw = NULL;
2419static const struct firmware *firmware = NULL; 3189static const struct firmware *firmware = NULL;
2420static const struct firmware *ucode = NULL; 3190static const struct firmware *ucode = NULL;
3191
3192static void free_firmware(void)
3193{
3194 if (fw_loaded) {
3195 release_firmware(bootfw);
3196 release_firmware(ucode);
3197 release_firmware(firmware);
3198 bootfw = ucode = firmware = NULL;
3199 fw_loaded = 0;
3200 }
3201}
3202#else
3203#define free_firmware() do {} while (0)
2421#endif 3204#endif
2422 3205
2423static int ipw_load(struct ipw_priv *priv) 3206static int ipw_load(struct ipw_priv *priv)
@@ -2446,10 +3229,10 @@ static int ipw_load(struct ipw_priv *priv)
2446 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss")); 3229 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss"));
2447 break; 3230 break;
2448 3231
2449#ifdef CONFIG_IPW_PROMISC 3232#ifdef CONFIG_IPW2200_MONITOR
2450 case IW_MODE_MONITOR: 3233 case IW_MODE_MONITOR:
2451 rc = ipw_get_fw(priv, &ucode, 3234 rc = ipw_get_fw(priv, &ucode,
2452 IPW_FW_NAME("ibss_ucode")); 3235 IPW_FW_NAME("sniffer_ucode"));
2453 if (rc) 3236 if (rc)
2454 goto error; 3237 goto error;
2455 3238
@@ -2488,11 +3271,11 @@ static int ipw_load(struct ipw_priv *priv)
2488 3271
2489 retry: 3272 retry:
2490 /* Ensure interrupts are disabled */ 3273 /* Ensure interrupts are disabled */
2491 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL); 3274 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
2492 priv->status &= ~STATUS_INT_ENABLED; 3275 priv->status &= ~STATUS_INT_ENABLED;
2493 3276
2494 /* ack pending interrupts */ 3277 /* ack pending interrupts */
2495 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_MASK_ALL); 3278 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
2496 3279
2497 ipw_stop_nic(priv); 3280 ipw_stop_nic(priv);
2498 3281
@@ -2502,14 +3285,14 @@ static int ipw_load(struct ipw_priv *priv)
2502 goto error; 3285 goto error;
2503 } 3286 }
2504 3287
2505 ipw_zero_memory(priv, CX2_NIC_SRAM_LOWER_BOUND, 3288 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
2506 CX2_NIC_SRAM_UPPER_BOUND - CX2_NIC_SRAM_LOWER_BOUND); 3289 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
2507 3290
2508 /* DMA the initial boot firmware into the device */ 3291 /* DMA the initial boot firmware into the device */
2509 rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header), 3292 rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
2510 bootfw->size - sizeof(struct fw_header)); 3293 bootfw->size - sizeof(struct fw_header));
2511 if (rc < 0) { 3294 if (rc < 0) {
2512 IPW_ERROR("Unable to load boot firmware\n"); 3295 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
2513 goto error; 3296 goto error;
2514 } 3297 }
2515 3298
@@ -2517,8 +3300,8 @@ static int ipw_load(struct ipw_priv *priv)
2517 ipw_start_nic(priv); 3300 ipw_start_nic(priv);
2518 3301
2519 /* wait for the device to finish it's initial startup sequence */ 3302 /* wait for the device to finish it's initial startup sequence */
2520 rc = ipw_poll_bit(priv, CX2_INTA_RW, 3303 rc = ipw_poll_bit(priv, IPW_INTA_RW,
2521 CX2_INTA_BIT_FW_INITIALIZATION_DONE, 500); 3304 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
2522 if (rc < 0) { 3305 if (rc < 0) {
2523 IPW_ERROR("device failed to boot initial fw image\n"); 3306 IPW_ERROR("device failed to boot initial fw image\n");
2524 goto error; 3307 goto error;
@@ -2526,13 +3309,13 @@ static int ipw_load(struct ipw_priv *priv)
2526 IPW_DEBUG_INFO("initial device response after %dms\n", rc); 3309 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
2527 3310
2528 /* ack fw init done interrupt */ 3311 /* ack fw init done interrupt */
2529 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_BIT_FW_INITIALIZATION_DONE); 3312 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
2530 3313
2531 /* DMA the ucode into the device */ 3314 /* DMA the ucode into the device */
2532 rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header), 3315 rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
2533 ucode->size - sizeof(struct fw_header)); 3316 ucode->size - sizeof(struct fw_header));
2534 if (rc < 0) { 3317 if (rc < 0) {
2535 IPW_ERROR("Unable to load ucode\n"); 3318 IPW_ERROR("Unable to load ucode: %d\n", rc);
2536 goto error; 3319 goto error;
2537 } 3320 }
2538 3321
@@ -2544,7 +3327,7 @@ static int ipw_load(struct ipw_priv *priv)
2544 sizeof(struct fw_header), 3327 sizeof(struct fw_header),
2545 firmware->size - sizeof(struct fw_header)); 3328 firmware->size - sizeof(struct fw_header));
2546 if (rc < 0) { 3329 if (rc < 0) {
2547 IPW_ERROR("Unable to load firmware\n"); 3330 IPW_ERROR("Unable to load firmware: %d\n", rc);
2548 goto error; 3331 goto error;
2549 } 3332 }
2550 3333
@@ -2557,12 +3340,14 @@ static int ipw_load(struct ipw_priv *priv)
2557 } 3340 }
2558 3341
2559 /* Ensure interrupts are disabled */ 3342 /* Ensure interrupts are disabled */
2560 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL); 3343 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
3344 /* ack pending interrupts */
3345 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
2561 3346
2562 /* kick start the device */ 3347 /* kick start the device */
2563 ipw_start_nic(priv); 3348 ipw_start_nic(priv);
2564 3349
2565 if (ipw_read32(priv, CX2_INTA_RW) & CX2_INTA_BIT_PARITY_ERROR) { 3350 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
2566 if (retries > 0) { 3351 if (retries > 0) {
2567 IPW_WARNING("Parity error. Retrying init.\n"); 3352 IPW_WARNING("Parity error. Retrying init.\n");
2568 retries--; 3353 retries--;
@@ -2575,8 +3360,8 @@ static int ipw_load(struct ipw_priv *priv)
2575 } 3360 }
2576 3361
2577 /* wait for the device */ 3362 /* wait for the device */
2578 rc = ipw_poll_bit(priv, CX2_INTA_RW, 3363 rc = ipw_poll_bit(priv, IPW_INTA_RW,
2579 CX2_INTA_BIT_FW_INITIALIZATION_DONE, 500); 3364 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
2580 if (rc < 0) { 3365 if (rc < 0) {
2581 IPW_ERROR("device failed to start after 500ms\n"); 3366 IPW_ERROR("device failed to start after 500ms\n");
2582 goto error; 3367 goto error;
@@ -2584,7 +3369,7 @@ static int ipw_load(struct ipw_priv *priv)
2584 IPW_DEBUG_INFO("device response after %dms\n", rc); 3369 IPW_DEBUG_INFO("device response after %dms\n", rc);
2585 3370
2586 /* ack fw init done interrupt */ 3371 /* ack fw init done interrupt */
2587 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_BIT_FW_INITIALIZATION_DONE); 3372 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
2588 3373
2589 /* read eeprom data and initialize the eeprom region of sram */ 3374 /* read eeprom data and initialize the eeprom region of sram */
2590 priv->eeprom_delay = 1; 3375 priv->eeprom_delay = 1;
@@ -2596,10 +3381,10 @@ static int ipw_load(struct ipw_priv *priv)
2596 /* Ensure our queue has valid packets */ 3381 /* Ensure our queue has valid packets */
2597 ipw_rx_queue_replenish(priv); 3382 ipw_rx_queue_replenish(priv);
2598 3383
2599 ipw_write32(priv, CX2_RX_READ_INDEX, priv->rxq->read); 3384 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
2600 3385
2601 /* ack pending interrupts */ 3386 /* ack pending interrupts */
2602 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_MASK_ALL); 3387 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
2603 3388
2604#ifndef CONFIG_PM 3389#ifndef CONFIG_PM
2605 release_firmware(bootfw); 3390 release_firmware(bootfw);
@@ -2756,16 +3541,18 @@ static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
2756 return; 3541 return;
2757 3542
2758 /* sanity check */ 3543 /* sanity check */
2759 if (bd->u.data.num_chunks > NUM_TFD_CHUNKS) { 3544 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
2760 IPW_ERROR("Too many chunks: %i\n", bd->u.data.num_chunks); 3545 IPW_ERROR("Too many chunks: %i\n",
3546 le32_to_cpu(bd->u.data.num_chunks));
2761 /** @todo issue fatal error, it is quite serious situation */ 3547 /** @todo issue fatal error, it is quite serious situation */
2762 return; 3548 return;
2763 } 3549 }
2764 3550
2765 /* unmap chunks if any */ 3551 /* unmap chunks if any */
2766 for (i = 0; i < bd->u.data.num_chunks; i++) { 3552 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
2767 pci_unmap_single(dev, bd->u.data.chunk_ptr[i], 3553 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
2768 bd->u.data.chunk_len[i], PCI_DMA_TODEVICE); 3554 le16_to_cpu(bd->u.data.chunk_len[i]),
3555 PCI_DMA_TODEVICE);
2769 if (txq->txb[txq->q.last_used]) { 3556 if (txq->txb[txq->q.last_used]) {
2770 ieee80211_txb_free(txq->txb[txq->q.last_used]); 3557 ieee80211_txb_free(txq->txb[txq->q.last_used]);
2771 txq->txb[txq->q.last_used] = NULL; 3558 txq->txb[txq->q.last_used] = NULL;
@@ -2822,21 +3609,6 @@ static void ipw_tx_queue_free(struct ipw_priv *priv)
2822 ipw_queue_tx_free(priv, &priv->txq[3]); 3609 ipw_queue_tx_free(priv, &priv->txq[3]);
2823} 3610}
2824 3611
2825static void inline __maybe_wake_tx(struct ipw_priv *priv)
2826{
2827 if (netif_running(priv->net_dev)) {
2828 switch (priv->port_type) {
2829 case DCR_TYPE_MU_BSS:
2830 case DCR_TYPE_MU_IBSS:
2831 if (!(priv->status & STATUS_ASSOCIATED)) {
2832 return;
2833 }
2834 }
2835 netif_wake_queue(priv->net_dev);
2836 }
2837
2838}
2839
2840static inline void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid) 3612static inline void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
2841{ 3613{
2842 /* First 3 bytes are manufacturer */ 3614 /* First 3 bytes are manufacturer */
@@ -2899,7 +3671,13 @@ static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
2899{ 3671{
2900 int err; 3672 int err;
2901 3673
2902 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))) { 3674 if (priv->status & STATUS_ASSOCIATING) {
3675 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3676 queue_work(priv->workqueue, &priv->disassociate);
3677 return;
3678 }
3679
3680 if (!(priv->status & STATUS_ASSOCIATED)) {
2903 IPW_DEBUG_ASSOC("Disassociating while not associated.\n"); 3681 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
2904 return; 3682 return;
2905 } 3683 }
@@ -2916,6 +3694,7 @@ static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
2916 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET; 3694 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
2917 else 3695 else
2918 priv->assoc_request.assoc_type = HC_DISASSOCIATE; 3696 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
3697
2919 err = ipw_send_associate(priv, &priv->assoc_request); 3698 err = ipw_send_associate(priv, &priv->assoc_request);
2920 if (err) { 3699 if (err) {
2921 IPW_DEBUG_HC("Attempt to send [dis]associate command " 3700 IPW_DEBUG_HC("Attempt to send [dis]associate command "
@@ -2925,20 +3704,27 @@ static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
2925 3704
2926} 3705}
2927 3706
2928static void ipw_disassociate(void *data) 3707static int ipw_disassociate(void *data)
2929{ 3708{
3709 struct ipw_priv *priv = data;
3710 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3711 return 0;
2930 ipw_send_disassociate(data, 0); 3712 ipw_send_disassociate(data, 0);
3713 return 1;
2931} 3714}
2932 3715
2933static void notify_wx_assoc_event(struct ipw_priv *priv) 3716static void ipw_bg_disassociate(void *data)
2934{ 3717{
2935 union iwreq_data wrqu; 3718 struct ipw_priv *priv = data;
2936 wrqu.ap_addr.sa_family = ARPHRD_ETHER; 3719 down(&priv->sem);
2937 if (priv->status & STATUS_ASSOCIATED) 3720 ipw_disassociate(data);
2938 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN); 3721 up(&priv->sem);
2939 else 3722}
2940 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN); 3723
2941 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL); 3724static void ipw_system_config(void *data)
3725{
3726 struct ipw_priv *priv = data;
3727 ipw_send_system_config(priv, &priv->sys_config);
2942} 3728}
2943 3729
2944struct ipw_status_code { 3730struct ipw_status_code {
@@ -2998,7 +3784,7 @@ static const char *ipw_get_status_code(u16 status)
2998{ 3784{
2999 int i; 3785 int i;
3000 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++) 3786 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
3001 if (ipw_status_codes[i].status == status) 3787 if (ipw_status_codes[i].status == (status & 0xff))
3002 return ipw_status_codes[i].reason; 3788 return ipw_status_codes[i].reason;
3003 return "Unknown status value."; 3789 return "Unknown status value.";
3004} 3790}
@@ -3077,18 +3863,30 @@ static inline u32 ipw_get_max_rate(struct ipw_priv *priv)
3077 while (i && !(mask & i)) 3863 while (i && !(mask & i))
3078 i >>= 1; 3864 i >>= 1;
3079 switch (i) { 3865 switch (i) {
3080 case IEEE80211_CCK_RATE_1MB_MASK: return 1000000; 3866 case IEEE80211_CCK_RATE_1MB_MASK:
3081 case IEEE80211_CCK_RATE_2MB_MASK: return 2000000; 3867 return 1000000;
3082 case IEEE80211_CCK_RATE_5MB_MASK: return 5500000; 3868 case IEEE80211_CCK_RATE_2MB_MASK:
3083 case IEEE80211_OFDM_RATE_6MB_MASK: return 6000000; 3869 return 2000000;
3084 case IEEE80211_OFDM_RATE_9MB_MASK: return 9000000; 3870 case IEEE80211_CCK_RATE_5MB_MASK:
3085 case IEEE80211_CCK_RATE_11MB_MASK: return 11000000; 3871 return 5500000;
3086 case IEEE80211_OFDM_RATE_12MB_MASK: return 12000000; 3872 case IEEE80211_OFDM_RATE_6MB_MASK:
3087 case IEEE80211_OFDM_RATE_18MB_MASK: return 18000000; 3873 return 6000000;
3088 case IEEE80211_OFDM_RATE_24MB_MASK: return 24000000; 3874 case IEEE80211_OFDM_RATE_9MB_MASK:
3089 case IEEE80211_OFDM_RATE_36MB_MASK: return 36000000; 3875 return 9000000;
3090 case IEEE80211_OFDM_RATE_48MB_MASK: return 48000000; 3876 case IEEE80211_CCK_RATE_11MB_MASK:
3091 case IEEE80211_OFDM_RATE_54MB_MASK: return 54000000; 3877 return 11000000;
3878 case IEEE80211_OFDM_RATE_12MB_MASK:
3879 return 12000000;
3880 case IEEE80211_OFDM_RATE_18MB_MASK:
3881 return 18000000;
3882 case IEEE80211_OFDM_RATE_24MB_MASK:
3883 return 24000000;
3884 case IEEE80211_OFDM_RATE_36MB_MASK:
3885 return 36000000;
3886 case IEEE80211_OFDM_RATE_48MB_MASK:
3887 return 48000000;
3888 case IEEE80211_OFDM_RATE_54MB_MASK:
3889 return 54000000;
3092 } 3890 }
3093 3891
3094 if (priv->ieee->mode == IEEE_B) 3892 if (priv->ieee->mode == IEEE_B)
@@ -3116,25 +3914,35 @@ static u32 ipw_get_current_rate(struct ipw_priv *priv)
3116 return ipw_get_max_rate(priv); 3914 return ipw_get_max_rate(priv);
3117 3915
3118 switch (rate) { 3916 switch (rate) {
3119 case IPW_TX_RATE_1MB: return 1000000; 3917 case IPW_TX_RATE_1MB:
3120 case IPW_TX_RATE_2MB: return 2000000; 3918 return 1000000;
3121 case IPW_TX_RATE_5MB: return 5500000; 3919 case IPW_TX_RATE_2MB:
3122 case IPW_TX_RATE_6MB: return 6000000; 3920 return 2000000;
3123 case IPW_TX_RATE_9MB: return 9000000; 3921 case IPW_TX_RATE_5MB:
3124 case IPW_TX_RATE_11MB: return 11000000; 3922 return 5500000;
3125 case IPW_TX_RATE_12MB: return 12000000; 3923 case IPW_TX_RATE_6MB:
3126 case IPW_TX_RATE_18MB: return 18000000; 3924 return 6000000;
3127 case IPW_TX_RATE_24MB: return 24000000; 3925 case IPW_TX_RATE_9MB:
3128 case IPW_TX_RATE_36MB: return 36000000; 3926 return 9000000;
3129 case IPW_TX_RATE_48MB: return 48000000; 3927 case IPW_TX_RATE_11MB:
3130 case IPW_TX_RATE_54MB: return 54000000; 3928 return 11000000;
3929 case IPW_TX_RATE_12MB:
3930 return 12000000;
3931 case IPW_TX_RATE_18MB:
3932 return 18000000;
3933 case IPW_TX_RATE_24MB:
3934 return 24000000;
3935 case IPW_TX_RATE_36MB:
3936 return 36000000;
3937 case IPW_TX_RATE_48MB:
3938 return 48000000;
3939 case IPW_TX_RATE_54MB:
3940 return 54000000;
3131 } 3941 }
3132 3942
3133 return 0; 3943 return 0;
3134} 3944}
3135 3945
3136#define PERFECT_RSSI (-50)
3137#define WORST_RSSI (-85)
3138#define IPW_STATS_INTERVAL (2 * HZ) 3946#define IPW_STATS_INTERVAL (2 * HZ)
3139static void ipw_gather_stats(struct ipw_priv *priv) 3947static void ipw_gather_stats(struct ipw_priv *priv)
3140{ 3948{
@@ -3146,6 +3954,7 @@ static void ipw_gather_stats(struct ipw_priv *priv)
3146 s16 rssi; 3954 s16 rssi;
3147 u32 beacon_quality, signal_quality, tx_quality, rx_quality, 3955 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
3148 rate_quality; 3956 rate_quality;
3957 u32 max_rate;
3149 3958
3150 if (!(priv->status & STATUS_ASSOCIATED)) { 3959 if (!(priv->status & STATUS_ASSOCIATED)) {
3151 priv->quality = 0; 3960 priv->quality = 0;
@@ -3202,7 +4011,8 @@ static void ipw_gather_stats(struct ipw_priv *priv)
3202 beacon_quality, missed_beacons_percent); 4011 beacon_quality, missed_beacons_percent);
3203 4012
3204 priv->last_rate = ipw_get_current_rate(priv); 4013 priv->last_rate = ipw_get_current_rate(priv);
3205 rate_quality = priv->last_rate * 40 / priv->last_rate + 60; 4014 max_rate = ipw_get_max_rate(priv);
4015 rate_quality = priv->last_rate * 40 / max_rate + 60;
3206 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n", 4016 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
3207 rate_quality, priv->last_rate / 1000000); 4017 rate_quality, priv->last_rate / 1000000);
3208 4018
@@ -3223,13 +4033,20 @@ static void ipw_gather_stats(struct ipw_priv *priv)
3223 tx_quality, tx_failures_delta, tx_packets_delta); 4033 tx_quality, tx_failures_delta, tx_packets_delta);
3224 4034
3225 rssi = average_value(&priv->average_rssi); 4035 rssi = average_value(&priv->average_rssi);
3226 if (rssi > PERFECT_RSSI) 4036 signal_quality =
4037 (100 *
4038 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4039 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4040 (priv->ieee->perfect_rssi - rssi) *
4041 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4042 62 * (priv->ieee->perfect_rssi - rssi))) /
4043 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4044 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4045 if (signal_quality > 100)
3227 signal_quality = 100; 4046 signal_quality = 100;
3228 else if (rssi < WORST_RSSI) 4047 else if (signal_quality < 1)
3229 signal_quality = 0; 4048 signal_quality = 0;
3230 else 4049
3231 signal_quality = (rssi - WORST_RSSI) * 100 /
3232 (PERFECT_RSSI - WORST_RSSI);
3233 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n", 4050 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
3234 signal_quality, rssi); 4051 signal_quality, rssi);
3235 4052
@@ -3258,6 +4075,85 @@ static void ipw_gather_stats(struct ipw_priv *priv)
3258 IPW_STATS_INTERVAL); 4075 IPW_STATS_INTERVAL);
3259} 4076}
3260 4077
4078static void ipw_bg_gather_stats(void *data)
4079{
4080 struct ipw_priv *priv = data;
4081 down(&priv->sem);
4082 ipw_gather_stats(data);
4083 up(&priv->sem);
4084}
4085
4086/* Missed beacon behavior:
4087 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4088 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4089 * Above disassociate threshold, give up and stop scanning.
4090 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
4091static inline void ipw_handle_missed_beacon(struct ipw_priv *priv,
4092 int missed_count)
4093{
4094 priv->notif_missed_beacons = missed_count;
4095
4096 if (missed_count > priv->disassociate_threshold &&
4097 priv->status & STATUS_ASSOCIATED) {
4098 /* If associated and we've hit the missed
4099 * beacon threshold, disassociate, turn
4100 * off roaming, and abort any active scans */
4101 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4102 IPW_DL_STATE | IPW_DL_ASSOC,
4103 "Missed beacon: %d - disassociate\n", missed_count);
4104 priv->status &= ~STATUS_ROAMING;
4105 if (priv->status & STATUS_SCANNING) {
4106 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4107 IPW_DL_STATE,
4108 "Aborting scan with missed beacon.\n");
4109 queue_work(priv->workqueue, &priv->abort_scan);
4110 }
4111
4112 queue_work(priv->workqueue, &priv->disassociate);
4113 return;
4114 }
4115
4116 if (priv->status & STATUS_ROAMING) {
4117 /* If we are currently roaming, then just
4118 * print a debug statement... */
4119 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4120 "Missed beacon: %d - roam in progress\n",
4121 missed_count);
4122 return;
4123 }
4124
4125 if (missed_count > priv->roaming_threshold &&
4126 missed_count <= priv->disassociate_threshold) {
4127 /* If we are not already roaming, set the ROAM
4128 * bit in the status and kick off a scan.
4129 * This can happen several times before we reach
4130 * disassociate_threshold. */
4131 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4132 "Missed beacon: %d - initiate "
4133 "roaming\n", missed_count);
4134 if (!(priv->status & STATUS_ROAMING)) {
4135 priv->status |= STATUS_ROAMING;
4136 if (!(priv->status & STATUS_SCANNING))
4137 queue_work(priv->workqueue,
4138 &priv->request_scan);
4139 }
4140 return;
4141 }
4142
4143 if (priv->status & STATUS_SCANNING) {
4144 /* Stop scan to keep fw from getting
4145 * stuck (only if we aren't roaming --
4146 * otherwise we'll never scan more than 2 or 3
4147 * channels..) */
4148 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4149 "Aborting scan with missed beacon.\n");
4150 queue_work(priv->workqueue, &priv->abort_scan);
4151 }
4152
4153 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
4154
4155}
4156
3261/** 4157/**
3262 * Handle host notification packet. 4158 * Handle host notification packet.
3263 * Called from interrupt routine 4159 * Called from interrupt routine
@@ -3265,6 +4161,8 @@ static void ipw_gather_stats(struct ipw_priv *priv)
3265static inline void ipw_rx_notification(struct ipw_priv *priv, 4161static inline void ipw_rx_notification(struct ipw_priv *priv,
3266 struct ipw_rx_notification *notif) 4162 struct ipw_rx_notification *notif)
3267{ 4163{
4164 notif->size = le16_to_cpu(notif->size);
4165
3268 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size); 4166 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
3269 4167
3270 switch (notif->subtype) { 4168 switch (notif->subtype) {
@@ -3308,30 +4206,44 @@ static inline void ipw_rx_notification(struct ipw_priv *priv,
3308 4206
3309 priv->status &= ~STATUS_ASSOCIATING; 4207 priv->status &= ~STATUS_ASSOCIATING;
3310 priv->status |= STATUS_ASSOCIATED; 4208 priv->status |= STATUS_ASSOCIATED;
3311 4209 queue_work(priv->workqueue,
3312 netif_carrier_on(priv->net_dev); 4210 &priv->system_config);
3313 if (netif_queue_stopped(priv->net_dev)) { 4211
3314 IPW_DEBUG_NOTIF 4212#ifdef CONFIG_IPW_QOS
3315 ("waking queue\n"); 4213#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
3316 netif_wake_queue(priv->net_dev); 4214 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
3317 } else { 4215 if ((priv->status & STATUS_AUTH) &&
3318 IPW_DEBUG_NOTIF 4216 (IPW_GET_PACKET_STYPE(&notif->u.raw)
3319 ("starting queue\n"); 4217 == IEEE80211_STYPE_ASSOC_RESP)) {
3320 netif_start_queue(priv-> 4218 if ((sizeof
3321 net_dev); 4219 (struct
4220 ieee80211_assoc_response)
4221 <= notif->size)
4222 && (notif->size <= 2314)) {
4223 struct
4224 ieee80211_rx_stats
4225 stats = {
4226 .len =
4227 notif->
4228 size - 1,
4229 };
4230
4231 IPW_DEBUG_QOS
4232 ("QoS Associate "
4233 "size %d\n",
4234 notif->size);
4235 ieee80211_rx_mgt(priv->
4236 ieee,
4237 (struct
4238 ieee80211_hdr_4addr
4239 *)
4240 &notif->u.raw, &stats);
4241 }
3322 } 4242 }
4243#endif
3323 4244
3324 ipw_reset_stats(priv); 4245 schedule_work(&priv->link_up);
3325 /* Ensure the rate is updated immediately */
3326 priv->last_rate =
3327 ipw_get_current_rate(priv);
3328 schedule_work(&priv->gather_stats);
3329 notify_wx_assoc_event(priv);
3330 4246
3331/* queue_delayed_work(priv->workqueue,
3332 &priv->request_scan,
3333 SCAN_ASSOCIATED_INTERVAL);
3334*/
3335 break; 4247 break;
3336 } 4248 }
3337 4249
@@ -3364,12 +4276,7 @@ static inline void ipw_rx_notification(struct ipw_priv *priv,
3364 STATUS_AUTH | 4276 STATUS_AUTH |
3365 STATUS_ASSOCIATED); 4277 STATUS_ASSOCIATED);
3366 4278
3367 netif_carrier_off(priv-> 4279 schedule_work(&priv->link_down);
3368 net_dev);
3369 netif_stop_queue(priv->net_dev);
3370 queue_work(priv->workqueue,
3371 &priv->request_scan);
3372 notify_wx_assoc_event(priv);
3373 break; 4280 break;
3374 } 4281 }
3375 4282
@@ -3384,6 +4291,24 @@ static inline void ipw_rx_notification(struct ipw_priv *priv,
3384 } 4291 }
3385 4292
3386 case CMAS_INIT:{ 4293 case CMAS_INIT:{
4294 if (priv->status & STATUS_AUTH) {
4295 struct
4296 ieee80211_assoc_response
4297 *resp;
4298 resp =
4299 (struct
4300 ieee80211_assoc_response
4301 *)&notif->u.raw;
4302 IPW_DEBUG(IPW_DL_NOTIF |
4303 IPW_DL_STATE |
4304 IPW_DL_ASSOC,
4305 "association failed (0x%04X): %s\n",
4306 ntohs(resp->status),
4307 ipw_get_status_code
4308 (ntohs
4309 (resp->status)));
4310 }
4311
3387 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4312 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3388 IPW_DL_ASSOC, 4313 IPW_DL_ASSOC,
3389 "disassociated: '%s' " MAC_FMT 4314 "disassociated: '%s' " MAC_FMT
@@ -3396,35 +4321,21 @@ static inline void ipw_rx_notification(struct ipw_priv *priv,
3396 ~(STATUS_DISASSOCIATING | 4321 ~(STATUS_DISASSOCIATING |
3397 STATUS_ASSOCIATING | 4322 STATUS_ASSOCIATING |
3398 STATUS_ASSOCIATED | STATUS_AUTH); 4323 STATUS_ASSOCIATED | STATUS_AUTH);
4324 if (priv->assoc_network
4325 && (priv->assoc_network->
4326 capability &
4327 WLAN_CAPABILITY_IBSS))
4328 ipw_remove_current_network
4329 (priv);
3399 4330
3400 netif_stop_queue(priv->net_dev); 4331 schedule_work(&priv->link_down);
3401 if (!(priv->status & STATUS_ROAMING)) {
3402 netif_carrier_off(priv->
3403 net_dev);
3404 notify_wx_assoc_event(priv);
3405
3406 /* Cancel any queued work ... */
3407 cancel_delayed_work(&priv->
3408 request_scan);
3409 cancel_delayed_work(&priv->
3410 adhoc_check);
3411
3412 /* Queue up another scan... */
3413 queue_work(priv->workqueue,
3414 &priv->request_scan);
3415
3416 cancel_delayed_work(&priv->
3417 gather_stats);
3418 } else {
3419 priv->status |= STATUS_ROAMING;
3420 queue_work(priv->workqueue,
3421 &priv->request_scan);
3422 }
3423 4332
3424 ipw_reset_stats(priv);
3425 break; 4333 break;
3426 } 4334 }
3427 4335
4336 case CMAS_RX_ASSOC_RESP:
4337 break;
4338
3428 default: 4339 default:
3429 IPW_ERROR("assoc: unknown (%d)\n", 4340 IPW_ERROR("assoc: unknown (%d)\n",
3430 assoc->state); 4341 assoc->state);
@@ -3467,11 +4378,7 @@ static inline void ipw_rx_notification(struct ipw_priv *priv,
3467 STATUS_AUTH | 4378 STATUS_AUTH |
3468 STATUS_ASSOCIATED); 4379 STATUS_ASSOCIATED);
3469 4380
3470 netif_carrier_off(priv->net_dev); 4381 schedule_work(&priv->link_down);
3471 netif_stop_queue(priv->net_dev);
3472 queue_work(priv->workqueue,
3473 &priv->request_scan);
3474 notify_wx_assoc_event(priv);
3475 break; 4382 break;
3476 4383
3477 case CMAS_TX_AUTH_SEQ_1: 4384 case CMAS_TX_AUTH_SEQ_1:
@@ -3513,6 +4420,7 @@ static inline void ipw_rx_notification(struct ipw_priv *priv,
3513 case CMAS_RX_ASSOC_RESP: 4420 case CMAS_RX_ASSOC_RESP:
3514 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4421 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3515 IPW_DL_ASSOC, "RX_ASSOC_RESP\n"); 4422 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
4423
3516 break; 4424 break;
3517 case CMAS_ASSOCIATED: 4425 case CMAS_ASSOCIATED:
3518 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | 4426 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
@@ -3557,43 +4465,67 @@ static inline void ipw_rx_notification(struct ipw_priv *priv,
3557 priv->status &= 4465 priv->status &=
3558 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING); 4466 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3559 4467
4468 wake_up_interruptible(&priv->wait_state);
3560 cancel_delayed_work(&priv->scan_check); 4469 cancel_delayed_work(&priv->scan_check);
3561 4470
4471 if (priv->status & STATUS_EXIT_PENDING)
4472 break;
4473
4474 priv->ieee->scans++;
4475
4476#ifdef CONFIG_IPW2200_MONITOR
4477 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
4478 priv->status |= STATUS_SCAN_FORCED;
4479 queue_work(priv->workqueue,
4480 &priv->request_scan);
4481 break;
4482 }
4483 priv->status &= ~STATUS_SCAN_FORCED;
4484#endif /* CONFIG_IPW2200_MONITOR */
4485
3562 if (!(priv->status & (STATUS_ASSOCIATED | 4486 if (!(priv->status & (STATUS_ASSOCIATED |
3563 STATUS_ASSOCIATING | 4487 STATUS_ASSOCIATING |
3564 STATUS_ROAMING | 4488 STATUS_ROAMING |
3565 STATUS_DISASSOCIATING))) 4489 STATUS_DISASSOCIATING)))
3566 queue_work(priv->workqueue, &priv->associate); 4490 queue_work(priv->workqueue, &priv->associate);
3567 else if (priv->status & STATUS_ROAMING) { 4491 else if (priv->status & STATUS_ROAMING) {
3568 /* If a scan completed and we are in roam mode, then 4492 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
3569 * the scan that completed was the one requested as a 4493 /* If a scan completed and we are in roam mode, then
3570 * result of entering roam... so, schedule the 4494 * the scan that completed was the one requested as a
3571 * roam work */ 4495 * result of entering roam... so, schedule the
3572 queue_work(priv->workqueue, &priv->roam); 4496 * roam work */
4497 queue_work(priv->workqueue,
4498 &priv->roam);
4499 else
4500 /* Don't schedule if we aborted the scan */
4501 priv->status &= ~STATUS_ROAMING;
3573 } else if (priv->status & STATUS_SCAN_PENDING) 4502 } else if (priv->status & STATUS_SCAN_PENDING)
3574 queue_work(priv->workqueue, 4503 queue_work(priv->workqueue,
3575 &priv->request_scan); 4504 &priv->request_scan);
3576 4505 else if (priv->config & CFG_BACKGROUND_SCAN
3577 priv->ieee->scans++; 4506 && priv->status & STATUS_ASSOCIATED)
4507 queue_delayed_work(priv->workqueue,
4508 &priv->request_scan, HZ);
3578 break; 4509 break;
3579 } 4510 }
3580 4511
3581 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{ 4512 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
3582 struct notif_frag_length *x = &notif->u.frag_len; 4513 struct notif_frag_length *x = &notif->u.frag_len;
3583 4514
3584 if (notif->size == sizeof(*x)) { 4515 if (notif->size == sizeof(*x))
3585 IPW_ERROR("Frag length: %d\n", x->frag_length); 4516 IPW_ERROR("Frag length: %d\n",
3586 } else { 4517 le16_to_cpu(x->frag_length));
4518 else
3587 IPW_ERROR("Frag length of wrong size %d " 4519 IPW_ERROR("Frag length of wrong size %d "
3588 "(should be %zd)\n", 4520 "(should be %zd)\n",
3589 notif->size, sizeof(*x)); 4521 notif->size, sizeof(*x));
3590 }
3591 break; 4522 break;
3592 } 4523 }
3593 4524
3594 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{ 4525 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
3595 struct notif_link_deterioration *x = 4526 struct notif_link_deterioration *x =
3596 &notif->u.link_deterioration; 4527 &notif->u.link_deterioration;
4528
3597 if (notif->size == sizeof(*x)) { 4529 if (notif->size == sizeof(*x)) {
3598 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE, 4530 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3599 "link deterioration: '%s' " MAC_FMT 4531 "link deterioration: '%s' " MAC_FMT
@@ -3613,11 +4545,9 @@ static inline void ipw_rx_notification(struct ipw_priv *priv,
3613 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{ 4545 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
3614 IPW_ERROR("Dino config\n"); 4546 IPW_ERROR("Dino config\n");
3615 if (priv->hcmd 4547 if (priv->hcmd
3616 && priv->hcmd->cmd == HOST_CMD_DINO_CONFIG) { 4548 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
3617 /* TODO: Do anything special? */
3618 } else {
3619 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n"); 4549 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
3620 } 4550
3621 break; 4551 break;
3622 } 4552 }
3623 4553
@@ -3630,36 +4560,11 @@ static inline void ipw_rx_notification(struct ipw_priv *priv,
3630 break; 4560 break;
3631 } 4561 }
3632 4562
3633 if (x->state == HOST_NOTIFICATION_STATUS_BEACON_MISSING) { 4563 if (le32_to_cpu(x->state) ==
3634 if (priv->status & STATUS_SCANNING) { 4564 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
3635 /* Stop scan to keep fw from getting 4565 ipw_handle_missed_beacon(priv,
3636 * stuck... */ 4566 le32_to_cpu(x->
3637 queue_work(priv->workqueue, 4567 number));
3638 &priv->abort_scan);
3639 }
3640
3641 if (x->number > priv->missed_beacon_threshold &&
3642 priv->status & STATUS_ASSOCIATED) {
3643 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
3644 IPW_DL_STATE,
3645 "Missed beacon: %d - disassociate\n",
3646 x->number);
3647 queue_work(priv->workqueue,
3648 &priv->disassociate);
3649 } else if (x->number > priv->roaming_threshold) {
3650 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3651 "Missed beacon: %d - initiate "
3652 "roaming\n", x->number);
3653 queue_work(priv->workqueue,
3654 &priv->roam);
3655 } else {
3656 IPW_DEBUG_NOTIF("Missed beacon: %d\n",
3657 x->number);
3658 }
3659
3660 priv->notif_missed_beacons = x->number;
3661
3662 }
3663 4568
3664 break; 4569 break;
3665 } 4570 }
@@ -3698,7 +4603,8 @@ static inline void ipw_rx_notification(struct ipw_priv *priv,
3698 case HOST_NOTIFICATION_NOISE_STATS:{ 4603 case HOST_NOTIFICATION_NOISE_STATS:{
3699 if (notif->size == sizeof(u32)) { 4604 if (notif->size == sizeof(u32)) {
3700 priv->last_noise = 4605 priv->last_noise =
3701 (u8) (notif->u.noise.value & 0xff); 4606 (u8) (le32_to_cpu(notif->u.noise.value) &
4607 0xff);
3702 average_add(&priv->average_noise, 4608 average_add(&priv->average_noise,
3703 priv->last_noise); 4609 priv->last_noise);
3704 break; 4610 break;
@@ -3731,43 +4637,43 @@ static int ipw_queue_reset(struct ipw_priv *priv)
3731 ipw_tx_queue_free(priv); 4637 ipw_tx_queue_free(priv);
3732 /* Tx CMD queue */ 4638 /* Tx CMD queue */
3733 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd, 4639 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
3734 CX2_TX_CMD_QUEUE_READ_INDEX, 4640 IPW_TX_CMD_QUEUE_READ_INDEX,
3735 CX2_TX_CMD_QUEUE_WRITE_INDEX, 4641 IPW_TX_CMD_QUEUE_WRITE_INDEX,
3736 CX2_TX_CMD_QUEUE_BD_BASE, 4642 IPW_TX_CMD_QUEUE_BD_BASE,
3737 CX2_TX_CMD_QUEUE_BD_SIZE); 4643 IPW_TX_CMD_QUEUE_BD_SIZE);
3738 if (rc) { 4644 if (rc) {
3739 IPW_ERROR("Tx Cmd queue init failed\n"); 4645 IPW_ERROR("Tx Cmd queue init failed\n");
3740 goto error; 4646 goto error;
3741 } 4647 }
3742 /* Tx queue(s) */ 4648 /* Tx queue(s) */
3743 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx, 4649 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
3744 CX2_TX_QUEUE_0_READ_INDEX, 4650 IPW_TX_QUEUE_0_READ_INDEX,
3745 CX2_TX_QUEUE_0_WRITE_INDEX, 4651 IPW_TX_QUEUE_0_WRITE_INDEX,
3746 CX2_TX_QUEUE_0_BD_BASE, CX2_TX_QUEUE_0_BD_SIZE); 4652 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
3747 if (rc) { 4653 if (rc) {
3748 IPW_ERROR("Tx 0 queue init failed\n"); 4654 IPW_ERROR("Tx 0 queue init failed\n");
3749 goto error; 4655 goto error;
3750 } 4656 }
3751 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx, 4657 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
3752 CX2_TX_QUEUE_1_READ_INDEX, 4658 IPW_TX_QUEUE_1_READ_INDEX,
3753 CX2_TX_QUEUE_1_WRITE_INDEX, 4659 IPW_TX_QUEUE_1_WRITE_INDEX,
3754 CX2_TX_QUEUE_1_BD_BASE, CX2_TX_QUEUE_1_BD_SIZE); 4660 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
3755 if (rc) { 4661 if (rc) {
3756 IPW_ERROR("Tx 1 queue init failed\n"); 4662 IPW_ERROR("Tx 1 queue init failed\n");
3757 goto error; 4663 goto error;
3758 } 4664 }
3759 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx, 4665 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
3760 CX2_TX_QUEUE_2_READ_INDEX, 4666 IPW_TX_QUEUE_2_READ_INDEX,
3761 CX2_TX_QUEUE_2_WRITE_INDEX, 4667 IPW_TX_QUEUE_2_WRITE_INDEX,
3762 CX2_TX_QUEUE_2_BD_BASE, CX2_TX_QUEUE_2_BD_SIZE); 4668 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
3763 if (rc) { 4669 if (rc) {
3764 IPW_ERROR("Tx 2 queue init failed\n"); 4670 IPW_ERROR("Tx 2 queue init failed\n");
3765 goto error; 4671 goto error;
3766 } 4672 }
3767 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx, 4673 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
3768 CX2_TX_QUEUE_3_READ_INDEX, 4674 IPW_TX_QUEUE_3_READ_INDEX,
3769 CX2_TX_QUEUE_3_WRITE_INDEX, 4675 IPW_TX_QUEUE_3_WRITE_INDEX,
3770 CX2_TX_QUEUE_3_BD_BASE, CX2_TX_QUEUE_3_BD_SIZE); 4676 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
3771 if (rc) { 4677 if (rc) {
3772 IPW_ERROR("Tx 3 queue init failed\n"); 4678 IPW_ERROR("Tx 3 queue init failed\n");
3773 goto error; 4679 goto error;
@@ -3815,9 +4721,10 @@ static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
3815 priv->tx_packets++; 4721 priv->tx_packets++;
3816 } 4722 }
3817 done: 4723 done:
3818 if (ipw_queue_space(q) > q->low_mark && qindex >= 0) { 4724 if ((ipw_queue_space(q) > q->low_mark) &&
3819 __maybe_wake_tx(priv); 4725 (qindex >= 0) &&
3820 } 4726 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4727 netif_wake_queue(priv->net_dev);
3821 used = q->first_empty - q->last_used; 4728 used = q->first_empty - q->last_used;
3822 if (used < 0) 4729 if (used < 0)
3823 used += q->n_bd; 4730 used += q->n_bd;
@@ -3858,7 +4765,7 @@ static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
3858 * Rx theory of operation 4765 * Rx theory of operation
3859 * 4766 *
3860 * The host allocates 32 DMA target addresses and passes the host address 4767 * The host allocates 32 DMA target addresses and passes the host address
3861 * to the firmware at register CX2_RFDS_TABLE_LOWER + N * RFD_SIZE where N is 4768 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
3862 * 0 to 31 4769 * 0 to 31
3863 * 4770 *
3864 * Rx Queue Indexes 4771 * Rx Queue Indexes
@@ -3942,7 +4849,7 @@ static void ipw_rx_queue_restock(struct ipw_priv *priv)
3942 rxb = list_entry(element, struct ipw_rx_mem_buffer, list); 4849 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
3943 list_del(element); 4850 list_del(element);
3944 4851
3945 ipw_write32(priv, CX2_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE, 4852 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
3946 rxb->dma_addr); 4853 rxb->dma_addr);
3947 rxq->queue[rxq->write] = rxb; 4854 rxq->queue[rxq->write] = rxb;
3948 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE; 4855 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
@@ -3957,7 +4864,7 @@ static void ipw_rx_queue_restock(struct ipw_priv *priv)
3957 4864
3958 /* If we've added more space for the firmware to place data, tell it */ 4865 /* If we've added more space for the firmware to place data, tell it */
3959 if (write != rxq->write) 4866 if (write != rxq->write)
3960 ipw_write32(priv, CX2_RX_WRITE_INDEX, rxq->write); 4867 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
3961} 4868}
3962 4869
3963/* 4870/*
@@ -3978,7 +4885,7 @@ static void ipw_rx_queue_replenish(void *data)
3978 while (!list_empty(&rxq->rx_used)) { 4885 while (!list_empty(&rxq->rx_used)) {
3979 element = rxq->rx_used.next; 4886 element = rxq->rx_used.next;
3980 rxb = list_entry(element, struct ipw_rx_mem_buffer, list); 4887 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
3981 rxb->skb = alloc_skb(CX2_RX_BUF_SIZE, GFP_ATOMIC); 4888 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
3982 if (!rxb->skb) { 4889 if (!rxb->skb) {
3983 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n", 4890 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
3984 priv->net_dev->name); 4891 priv->net_dev->name);
@@ -3992,7 +4899,7 @@ static void ipw_rx_queue_replenish(void *data)
3992 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data; 4899 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
3993 rxb->dma_addr = 4900 rxb->dma_addr =
3994 pci_map_single(priv->pci_dev, rxb->skb->data, 4901 pci_map_single(priv->pci_dev, rxb->skb->data,
3995 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); 4902 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
3996 4903
3997 list_add_tail(&rxb->list, &rxq->rx_free); 4904 list_add_tail(&rxb->list, &rxq->rx_free);
3998 rxq->free_count++; 4905 rxq->free_count++;
@@ -4002,6 +4909,14 @@ static void ipw_rx_queue_replenish(void *data)
4002 ipw_rx_queue_restock(priv); 4909 ipw_rx_queue_restock(priv);
4003} 4910}
4004 4911
4912static void ipw_bg_rx_queue_replenish(void *data)
4913{
4914 struct ipw_priv *priv = data;
4915 down(&priv->sem);
4916 ipw_rx_queue_replenish(data);
4917 up(&priv->sem);
4918}
4919
4005/* Assumes that the skb field of the buffers in 'pool' is kept accurate. 4920/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4006 * If an SKB has been detached, the POOL needs to have it's SKB set to NULL 4921 * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
4007 * This free routine walks the list of POOL entries and if SKB is set to 4922 * This free routine walks the list of POOL entries and if SKB is set to
@@ -4017,7 +4932,7 @@ static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
4017 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { 4932 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4018 if (rxq->pool[i].skb != NULL) { 4933 if (rxq->pool[i].skb != NULL) {
4019 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr, 4934 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
4020 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); 4935 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
4021 dev_kfree_skb(rxq->pool[i].skb); 4936 dev_kfree_skb(rxq->pool[i].skb);
4022 } 4937 }
4023 } 4938 }
@@ -4136,8 +5051,18 @@ static int ipw_compatible_rates(struct ipw_priv *priv,
4136 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES); 5051 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
4137 rates->num_rates = 0; 5052 rates->num_rates = 0;
4138 for (i = 0; i < num_rates; i++) { 5053 for (i = 0; i < num_rates; i++) {
4139 if (!ipw_is_rate_in_mask 5054 if (!ipw_is_rate_in_mask(priv, network->mode,
4140 (priv, network->mode, network->rates[i])) { 5055 network->rates[i])) {
5056
5057 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
5058 IPW_DEBUG_SCAN("Adding masked mandatory "
5059 "rate %02X\n",
5060 network->rates[i]);
5061 rates->supported_rates[rates->num_rates++] =
5062 network->rates[i];
5063 continue;
5064 }
5065
4141 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", 5066 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4142 network->rates[i], priv->rates_mask); 5067 network->rates[i], priv->rates_mask);
4143 continue; 5068 continue;
@@ -4146,11 +5071,20 @@ static int ipw_compatible_rates(struct ipw_priv *priv,
4146 rates->supported_rates[rates->num_rates++] = network->rates[i]; 5071 rates->supported_rates[rates->num_rates++] = network->rates[i];
4147 } 5072 }
4148 5073
4149 num_rates = 5074 num_rates = min(network->rates_ex_len,
4150 min(network->rates_ex_len, (u8) (IPW_MAX_RATES - num_rates)); 5075 (u8) (IPW_MAX_RATES - num_rates));
4151 for (i = 0; i < num_rates; i++) { 5076 for (i = 0; i < num_rates; i++) {
4152 if (!ipw_is_rate_in_mask 5077 if (!ipw_is_rate_in_mask(priv, network->mode,
4153 (priv, network->mode, network->rates_ex[i])) { 5078 network->rates_ex[i])) {
5079 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
5080 IPW_DEBUG_SCAN("Adding masked mandatory "
5081 "rate %02X\n",
5082 network->rates_ex[i]);
5083 rates->supported_rates[rates->num_rates++] =
5084 network->rates[i];
5085 continue;
5086 }
5087
4154 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n", 5088 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4155 network->rates_ex[i], priv->rates_mask); 5089 network->rates_ex[i], priv->rates_mask);
4156 continue; 5090 continue;
@@ -4160,7 +5094,7 @@ static int ipw_compatible_rates(struct ipw_priv *priv,
4160 network->rates_ex[i]; 5094 network->rates_ex[i];
4161 } 5095 }
4162 5096
4163 return rates->num_rates; 5097 return 1;
4164} 5098}
4165 5099
4166static inline void ipw_copy_rates(struct ipw_supported_rates *dest, 5100static inline void ipw_copy_rates(struct ipw_supported_rates *dest,
@@ -4242,6 +5176,216 @@ struct ipw_network_match {
4242 struct ipw_supported_rates rates; 5176 struct ipw_supported_rates rates;
4243}; 5177};
4244 5178
5179static int ipw_find_adhoc_network(struct ipw_priv *priv,
5180 struct ipw_network_match *match,
5181 struct ieee80211_network *network,
5182 int roaming)
5183{
5184 struct ipw_supported_rates rates;
5185
5186 /* Verify that this network's capability is compatible with the
5187 * current mode (AdHoc or Infrastructure) */
5188 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5189 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5190 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5191 "capability mismatch.\n",
5192 escape_essid(network->ssid, network->ssid_len),
5193 MAC_ARG(network->bssid));
5194 return 0;
5195 }
5196
5197 /* If we do not have an ESSID for this AP, we can not associate with
5198 * it */
5199 if (network->flags & NETWORK_EMPTY_ESSID) {
5200 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5201 "because of hidden ESSID.\n",
5202 escape_essid(network->ssid, network->ssid_len),
5203 MAC_ARG(network->bssid));
5204 return 0;
5205 }
5206
5207 if (unlikely(roaming)) {
5208 /* If we are roaming, then ensure check if this is a valid
5209 * network to try and roam to */
5210 if ((network->ssid_len != match->network->ssid_len) ||
5211 memcmp(network->ssid, match->network->ssid,
5212 network->ssid_len)) {
5213 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5214 "because of non-network ESSID.\n",
5215 escape_essid(network->ssid,
5216 network->ssid_len),
5217 MAC_ARG(network->bssid));
5218 return 0;
5219 }
5220 } else {
5221 /* If an ESSID has been configured then compare the broadcast
5222 * ESSID to ours */
5223 if ((priv->config & CFG_STATIC_ESSID) &&
5224 ((network->ssid_len != priv->essid_len) ||
5225 memcmp(network->ssid, priv->essid,
5226 min(network->ssid_len, priv->essid_len)))) {
5227 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
5228
5229 strncpy(escaped,
5230 escape_essid(network->ssid, network->ssid_len),
5231 sizeof(escaped));
5232 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5233 "because of ESSID mismatch: '%s'.\n",
5234 escaped, MAC_ARG(network->bssid),
5235 escape_essid(priv->essid,
5236 priv->essid_len));
5237 return 0;
5238 }
5239 }
5240
5241 /* If the old network rate is better than this one, don't bother
5242 * testing everything else. */
5243
5244 if (network->time_stamp[0] < match->network->time_stamp[0]) {
5245 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5246 "current network.\n",
5247 escape_essid(match->network->ssid,
5248 match->network->ssid_len));
5249 return 0;
5250 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
5251 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5252 "current network.\n",
5253 escape_essid(match->network->ssid,
5254 match->network->ssid_len));
5255 return 0;
5256 }
5257
5258 /* Now go through and see if the requested network is valid... */
5259 if (priv->ieee->scan_age != 0 &&
5260 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5261 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5262 "because of age: %lums.\n",
5263 escape_essid(network->ssid, network->ssid_len),
5264 MAC_ARG(network->bssid),
5265 1000 * (jiffies - network->last_scanned) / HZ);
5266 return 0;
5267 }
5268
5269 if ((priv->config & CFG_STATIC_CHANNEL) &&
5270 (network->channel != priv->channel)) {
5271 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5272 "because of channel mismatch: %d != %d.\n",
5273 escape_essid(network->ssid, network->ssid_len),
5274 MAC_ARG(network->bssid),
5275 network->channel, priv->channel);
5276 return 0;
5277 }
5278
5279 /* Verify privacy compatability */
5280 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5281 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5282 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5283 "because of privacy mismatch: %s != %s.\n",
5284 escape_essid(network->ssid, network->ssid_len),
5285 MAC_ARG(network->bssid),
5286 priv->
5287 capability & CAP_PRIVACY_ON ? "on" : "off",
5288 network->
5289 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5290 "off");
5291 return 0;
5292 }
5293
5294 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5295 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5296 "because of the same BSSID match: " MAC_FMT
5297 ".\n", escape_essid(network->ssid,
5298 network->ssid_len),
5299 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5300 return 0;
5301 }
5302
5303 /* Filter out any incompatible freq / mode combinations */
5304 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5305 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5306 "because of invalid frequency/mode "
5307 "combination.\n",
5308 escape_essid(network->ssid, network->ssid_len),
5309 MAC_ARG(network->bssid));
5310 return 0;
5311 }
5312
5313 /* Ensure that the rates supported by the driver are compatible with
5314 * this AP, including verification of basic rates (mandatory) */
5315 if (!ipw_compatible_rates(priv, network, &rates)) {
5316 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5317 "because configured rate mask excludes "
5318 "AP mandatory rate.\n",
5319 escape_essid(network->ssid, network->ssid_len),
5320 MAC_ARG(network->bssid));
5321 return 0;
5322 }
5323
5324 if (rates.num_rates == 0) {
5325 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5326 "because of no compatible rates.\n",
5327 escape_essid(network->ssid, network->ssid_len),
5328 MAC_ARG(network->bssid));
5329 return 0;
5330 }
5331
5332 /* TODO: Perform any further minimal comparititive tests. We do not
5333 * want to put too much policy logic here; intelligent scan selection
5334 * should occur within a generic IEEE 802.11 user space tool. */
5335
5336 /* Set up 'new' AP to this network */
5337 ipw_copy_rates(&match->rates, &rates);
5338 match->network = network;
5339 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5340 escape_essid(network->ssid, network->ssid_len),
5341 MAC_ARG(network->bssid));
5342
5343 return 1;
5344}
5345
5346static void ipw_merge_adhoc_network(void *data)
5347{
5348 struct ipw_priv *priv = data;
5349 struct ieee80211_network *network = NULL;
5350 struct ipw_network_match match = {
5351 .network = priv->assoc_network
5352 };
5353
5354 if ((priv->status & STATUS_ASSOCIATED) &&
5355 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5356 /* First pass through ROAM process -- look for a better
5357 * network */
5358 unsigned long flags;
5359
5360 spin_lock_irqsave(&priv->ieee->lock, flags);
5361 list_for_each_entry(network, &priv->ieee->network_list, list) {
5362 if (network != priv->assoc_network)
5363 ipw_find_adhoc_network(priv, &match, network,
5364 1);
5365 }
5366 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5367
5368 if (match.network == priv->assoc_network) {
5369 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5370 "merge to.\n");
5371 return;
5372 }
5373
5374 down(&priv->sem);
5375 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5376 IPW_DEBUG_MERGE("remove network %s\n",
5377 escape_essid(priv->essid,
5378 priv->essid_len));
5379 ipw_remove_current_network(priv);
5380 }
5381
5382 ipw_disassociate(priv);
5383 priv->assoc_network = match.network;
5384 up(&priv->sem);
5385 return;
5386 }
5387}
5388
4245static int ipw_best_network(struct ipw_priv *priv, 5389static int ipw_best_network(struct ipw_priv *priv,
4246 struct ipw_network_match *match, 5390 struct ipw_network_match *match,
4247 struct ieee80211_network *network, int roaming) 5391 struct ieee80211_network *network, int roaming)
@@ -4323,9 +5467,9 @@ static int ipw_best_network(struct ipw_priv *priv,
4323 /* If this network has already had an association attempt within the 5467 /* If this network has already had an association attempt within the
4324 * last 3 seconds, do not try and associate again... */ 5468 * last 3 seconds, do not try and associate again... */
4325 if (network->last_associate && 5469 if (network->last_associate &&
4326 time_after(network->last_associate + (HZ * 5UL), jiffies)) { 5470 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
4327 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " 5471 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4328 "because of storming (%lu since last " 5472 "because of storming (%lus since last "
4329 "assoc attempt).\n", 5473 "assoc attempt).\n",
4330 escape_essid(network->ssid, network->ssid_len), 5474 escape_essid(network->ssid, network->ssid_len),
4331 MAC_ARG(network->bssid), 5475 MAC_ARG(network->bssid),
@@ -4335,12 +5479,12 @@ static int ipw_best_network(struct ipw_priv *priv,
4335 5479
4336 /* Now go through and see if the requested network is valid... */ 5480 /* Now go through and see if the requested network is valid... */
4337 if (priv->ieee->scan_age != 0 && 5481 if (priv->ieee->scan_age != 0 &&
4338 jiffies - network->last_scanned > priv->ieee->scan_age) { 5482 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
4339 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " 5483 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4340 "because of age: %lums.\n", 5484 "because of age: %lums.\n",
4341 escape_essid(network->ssid, network->ssid_len), 5485 escape_essid(network->ssid, network->ssid_len),
4342 MAC_ARG(network->bssid), 5486 MAC_ARG(network->bssid),
4343 (jiffies - network->last_scanned) / (HZ / 100)); 5487 1000 * (jiffies - network->last_scanned) / HZ);
4344 return 0; 5488 return 0;
4345 } 5489 }
4346 5490
@@ -4368,6 +5512,15 @@ static int ipw_best_network(struct ipw_priv *priv,
4368 return 0; 5512 return 0;
4369 } 5513 }
4370 5514
5515 if (!priv->ieee->wpa_enabled && (network->wpa_ie_len > 0 ||
5516 network->rsn_ie_len > 0)) {
5517 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5518 "because of WPA capability mismatch.\n",
5519 escape_essid(network->ssid, network->ssid_len),
5520 MAC_ARG(network->bssid));
5521 return 0;
5522 }
5523
4371 if ((priv->config & CFG_STATIC_BSSID) && 5524 if ((priv->config & CFG_STATIC_BSSID) &&
4372 memcmp(network->bssid, priv->bssid, ETH_ALEN)) { 5525 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
4373 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " 5526 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
@@ -4387,7 +5540,26 @@ static int ipw_best_network(struct ipw_priv *priv,
4387 return 0; 5540 return 0;
4388 } 5541 }
4389 5542
4390 ipw_compatible_rates(priv, network, &rates); 5543 /* Filter out invalid channel in current GEO */
5544 if (!ipw_is_valid_channel(priv->ieee, network->channel)) {
5545 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5546 "because of invalid channel in current GEO\n",
5547 escape_essid(network->ssid, network->ssid_len),
5548 MAC_ARG(network->bssid));
5549 return 0;
5550 }
5551
5552 /* Ensure that the rates supported by the driver are compatible with
5553 * this AP, including verification of basic rates (mandatory) */
5554 if (!ipw_compatible_rates(priv, network, &rates)) {
5555 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5556 "because configured rate mask excludes "
5557 "AP mandatory rate.\n",
5558 escape_essid(network->ssid, network->ssid_len),
5559 MAC_ARG(network->bssid));
5560 return 0;
5561 }
5562
4391 if (rates.num_rates == 0) { 5563 if (rates.num_rates == 0) {
4392 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded " 5564 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4393 "because of no compatible rates.\n", 5565 "because of no compatible rates.\n",
@@ -4414,6 +5586,9 @@ static int ipw_best_network(struct ipw_priv *priv,
4414static void ipw_adhoc_create(struct ipw_priv *priv, 5586static void ipw_adhoc_create(struct ipw_priv *priv,
4415 struct ieee80211_network *network) 5587 struct ieee80211_network *network)
4416{ 5588{
5589 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
5590 int i;
5591
4417 /* 5592 /*
4418 * For the purposes of scanning, we can set our wireless mode 5593 * For the purposes of scanning, we can set our wireless mode
4419 * to trigger scans across combinations of bands, but when it 5594 * to trigger scans across combinations of bands, but when it
@@ -4424,22 +5599,47 @@ static void ipw_adhoc_create(struct ipw_priv *priv,
4424 * chossen band. Attempting to create a new ad-hoc network 5599 * chossen band. Attempting to create a new ad-hoc network
4425 * with an invalid channel for wireless mode will trigger a 5600 * with an invalid channel for wireless mode will trigger a
4426 * FW fatal error. 5601 * FW fatal error.
5602 *
4427 */ 5603 */
4428 network->mode = is_valid_channel(priv->ieee->mode, priv->channel); 5604 switch (ipw_is_valid_channel(priv->ieee, priv->channel)) {
4429 if (network->mode) { 5605 case IEEE80211_52GHZ_BAND:
4430 network->channel = priv->channel; 5606 network->mode = IEEE_A;
4431 } else { 5607 i = ipw_channel_to_index(priv->ieee, priv->channel);
5608 if (i == -1)
5609 BUG();
5610 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5611 IPW_WARNING("Overriding invalid channel\n");
5612 priv->channel = geo->a[0].channel;
5613 }
5614 break;
5615
5616 case IEEE80211_24GHZ_BAND:
5617 if (priv->ieee->mode & IEEE_G)
5618 network->mode = IEEE_G;
5619 else
5620 network->mode = IEEE_B;
5621 i = ipw_channel_to_index(priv->ieee, priv->channel);
5622 if (i == -1)
5623 BUG();
5624 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5625 IPW_WARNING("Overriding invalid channel\n");
5626 priv->channel = geo->bg[0].channel;
5627 }
5628 break;
5629
5630 default:
4432 IPW_WARNING("Overriding invalid channel\n"); 5631 IPW_WARNING("Overriding invalid channel\n");
4433 if (priv->ieee->mode & IEEE_A) { 5632 if (priv->ieee->mode & IEEE_A) {
4434 network->mode = IEEE_A; 5633 network->mode = IEEE_A;
4435 priv->channel = band_a_active_channel[0]; 5634 priv->channel = geo->a[0].channel;
4436 } else if (priv->ieee->mode & IEEE_G) { 5635 } else if (priv->ieee->mode & IEEE_G) {
4437 network->mode = IEEE_G; 5636 network->mode = IEEE_G;
4438 priv->channel = band_b_active_channel[0]; 5637 priv->channel = geo->bg[0].channel;
4439 } else { 5638 } else {
4440 network->mode = IEEE_B; 5639 network->mode = IEEE_B;
4441 priv->channel = band_b_active_channel[0]; 5640 priv->channel = geo->bg[0].channel;
4442 } 5641 }
5642 break;
4443 } 5643 }
4444 5644
4445 network->channel = priv->channel; 5645 network->channel = priv->channel;
@@ -4449,6 +5649,8 @@ static void ipw_adhoc_create(struct ipw_priv *priv,
4449 memcpy(network->ssid, priv->essid, priv->essid_len); 5649 memcpy(network->ssid, priv->essid, priv->essid_len);
4450 memset(&network->stats, 0, sizeof(network->stats)); 5650 memset(&network->stats, 0, sizeof(network->stats));
4451 network->capability = WLAN_CAPABILITY_IBSS; 5651 network->capability = WLAN_CAPABILITY_IBSS;
5652 if (!(priv->config & CFG_PREAMBLE_LONG))
5653 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
4452 if (priv->capability & CAP_PRIVACY_ON) 5654 if (priv->capability & CAP_PRIVACY_ON)
4453 network->capability |= WLAN_CAPABILITY_PRIVACY; 5655 network->capability |= WLAN_CAPABILITY_PRIVACY;
4454 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH); 5656 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
@@ -4465,13 +5667,35 @@ static void ipw_adhoc_create(struct ipw_priv *priv,
4465 network->beacon_interval = 100; /* Default */ 5667 network->beacon_interval = 100; /* Default */
4466 network->listen_interval = 10; /* Default */ 5668 network->listen_interval = 10; /* Default */
4467 network->atim_window = 0; /* Default */ 5669 network->atim_window = 0; /* Default */
4468#ifdef CONFIG_IEEE80211_WPA
4469 network->wpa_ie_len = 0; 5670 network->wpa_ie_len = 0;
4470 network->rsn_ie_len = 0; 5671 network->rsn_ie_len = 0;
4471#endif /* CONFIG_IEEE80211_WPA */
4472} 5672}
4473 5673
4474static void ipw_send_wep_keys(struct ipw_priv *priv) 5674static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5675{
5676 struct ipw_tgi_tx_key *key;
5677 struct host_cmd cmd = {
5678 .cmd = IPW_CMD_TGI_TX_KEY,
5679 .len = sizeof(*key)
5680 };
5681
5682 if (!(priv->ieee->sec.flags & (1 << index)))
5683 return;
5684
5685 key = (struct ipw_tgi_tx_key *)&cmd.param;
5686 key->key_id = index;
5687 memcpy(key->key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5688 key->security_type = type;
5689 key->station_index = 0; /* always 0 for BSS */
5690 key->flags = 0;
5691 /* 0 for new key; previous value of counter (after fatal error) */
5692 key->tx_counter[0] = 0;
5693 key->tx_counter[1] = 0;
5694
5695 ipw_send_cmd(priv, &cmd);
5696}
5697
5698static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
4475{ 5699{
4476 struct ipw_wep_key *key; 5700 struct ipw_wep_key *key;
4477 int i; 5701 int i;
@@ -4484,19 +5708,97 @@ static void ipw_send_wep_keys(struct ipw_priv *priv)
4484 key->cmd_id = DINO_CMD_WEP_KEY; 5708 key->cmd_id = DINO_CMD_WEP_KEY;
4485 key->seq_num = 0; 5709 key->seq_num = 0;
4486 5710
5711 /* Note: AES keys cannot be set for multiple times.
5712 * Only set it at the first time. */
4487 for (i = 0; i < 4; i++) { 5713 for (i = 0; i < 4; i++) {
4488 key->key_index = i; 5714 key->key_index = i | type;
4489 if (!(priv->sec.flags & (1 << i))) { 5715 if (!(priv->ieee->sec.flags & (1 << i))) {
4490 key->key_size = 0; 5716 key->key_size = 0;
4491 } else { 5717 continue;
4492 key->key_size = priv->sec.key_sizes[i];
4493 memcpy(key->key, priv->sec.keys[i], key->key_size);
4494 } 5718 }
4495 5719
4496 if (ipw_send_cmd(priv, &cmd)) { 5720 key->key_size = priv->ieee->sec.key_sizes[i];
4497 IPW_ERROR("failed to send WEP_KEY command\n"); 5721 memcpy(key->key, priv->ieee->sec.keys[i], key->key_size);
4498 return; 5722
4499 } 5723 ipw_send_cmd(priv, &cmd);
5724 }
5725}
5726
5727static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5728{
5729 if (priv->ieee->host_encrypt)
5730 return;
5731
5732 switch (level) {
5733 case SEC_LEVEL_3:
5734 priv->sys_config.disable_unicast_decryption = 0;
5735 priv->ieee->host_decrypt = 0;
5736 break;
5737 case SEC_LEVEL_2:
5738 priv->sys_config.disable_unicast_decryption = 1;
5739 priv->ieee->host_decrypt = 1;
5740 break;
5741 case SEC_LEVEL_1:
5742 priv->sys_config.disable_unicast_decryption = 0;
5743 priv->ieee->host_decrypt = 0;
5744 break;
5745 case SEC_LEVEL_0:
5746 priv->sys_config.disable_unicast_decryption = 1;
5747 break;
5748 default:
5749 break;
5750 }
5751}
5752
5753static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5754{
5755 if (priv->ieee->host_encrypt)
5756 return;
5757
5758 switch (level) {
5759 case SEC_LEVEL_3:
5760 priv->sys_config.disable_multicast_decryption = 0;
5761 break;
5762 case SEC_LEVEL_2:
5763 priv->sys_config.disable_multicast_decryption = 1;
5764 break;
5765 case SEC_LEVEL_1:
5766 priv->sys_config.disable_multicast_decryption = 0;
5767 break;
5768 case SEC_LEVEL_0:
5769 priv->sys_config.disable_multicast_decryption = 1;
5770 break;
5771 default:
5772 break;
5773 }
5774}
5775
5776static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5777{
5778 switch (priv->ieee->sec.level) {
5779 case SEC_LEVEL_3:
5780 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5781 ipw_send_tgi_tx_key(priv,
5782 DCT_FLAG_EXT_SECURITY_CCM,
5783 priv->ieee->sec.active_key);
5784
5785 if (!priv->ieee->host_mc_decrypt)
5786 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
5787 break;
5788 case SEC_LEVEL_2:
5789 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5790 ipw_send_tgi_tx_key(priv,
5791 DCT_FLAG_EXT_SECURITY_TKIP,
5792 priv->ieee->sec.active_key);
5793 break;
5794 case SEC_LEVEL_1:
5795 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
5796 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5797 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
5798 break;
5799 case SEC_LEVEL_0:
5800 default:
5801 break;
4500 } 5802 }
4501} 5803}
4502 5804
@@ -4504,9 +5806,12 @@ static void ipw_adhoc_check(void *data)
4504{ 5806{
4505 struct ipw_priv *priv = data; 5807 struct ipw_priv *priv = data;
4506 5808
4507 if (priv->missed_adhoc_beacons++ > priv->missed_beacon_threshold && 5809 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
4508 !(priv->config & CFG_ADHOC_PERSIST)) { 5810 !(priv->config & CFG_ADHOC_PERSIST)) {
4509 IPW_DEBUG_SCAN("Disassociating due to missed beacons\n"); 5811 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5812 IPW_DL_STATE | IPW_DL_ASSOC,
5813 "Missed beacon: %d - disassociate\n",
5814 priv->missed_adhoc_beacons);
4510 ipw_remove_current_network(priv); 5815 ipw_remove_current_network(priv);
4511 ipw_disassociate(priv); 5816 ipw_disassociate(priv);
4512 return; 5817 return;
@@ -4516,6 +5821,14 @@ static void ipw_adhoc_check(void *data)
4516 priv->assoc_request.beacon_interval); 5821 priv->assoc_request.beacon_interval);
4517} 5822}
4518 5823
5824static void ipw_bg_adhoc_check(void *data)
5825{
5826 struct ipw_priv *priv = data;
5827 down(&priv->sem);
5828 ipw_adhoc_check(data);
5829 up(&priv->sem);
5830}
5831
4519#ifdef CONFIG_IPW_DEBUG 5832#ifdef CONFIG_IPW_DEBUG
4520static void ipw_debug_config(struct ipw_priv *priv) 5833static void ipw_debug_config(struct ipw_priv *priv)
4521{ 5834{
@@ -4531,7 +5844,8 @@ static void ipw_debug_config(struct ipw_priv *priv)
4531 else 5844 else
4532 IPW_DEBUG_INFO("ESSID unlocked.\n"); 5845 IPW_DEBUG_INFO("ESSID unlocked.\n");
4533 if (priv->config & CFG_STATIC_BSSID) 5846 if (priv->config & CFG_STATIC_BSSID)
4534 IPW_DEBUG_INFO("BSSID locked to %d\n", priv->channel); 5847 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5848 MAC_ARG(priv->bssid));
4535 else 5849 else
4536 IPW_DEBUG_INFO("BSSID unlocked.\n"); 5850 IPW_DEBUG_INFO("BSSID unlocked.\n");
4537 if (priv->capability & CAP_PRIVACY_ON) 5851 if (priv->capability & CAP_PRIVACY_ON)
@@ -4544,8 +5858,7 @@ static void ipw_debug_config(struct ipw_priv *priv)
4544#define ipw_debug_config(x) do {} while (0) 5858#define ipw_debug_config(x) do {} while (0)
4545#endif 5859#endif
4546 5860
4547static inline void ipw_set_fixed_rate(struct ipw_priv *priv, 5861static inline void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
4548 struct ieee80211_network *network)
4549{ 5862{
4550 /* TODO: Verify that this works... */ 5863 /* TODO: Verify that this works... */
4551 struct ipw_fixed_rate fr = { 5864 struct ipw_fixed_rate fr = {
@@ -4562,6 +5875,8 @@ static inline void ipw_set_fixed_rate(struct ipw_priv *priv,
4562 /* IEEE_A */ 5875 /* IEEE_A */
4563 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) { 5876 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
4564 /* Invalid fixed rate mask */ 5877 /* Invalid fixed rate mask */
5878 IPW_DEBUG_WX
5879 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
4565 fr.tx_rates = 0; 5880 fr.tx_rates = 0;
4566 break; 5881 break;
4567 } 5882 }
@@ -4571,9 +5886,11 @@ static inline void ipw_set_fixed_rate(struct ipw_priv *priv,
4571 5886
4572 default: /* 2.4Ghz or Mixed */ 5887 default: /* 2.4Ghz or Mixed */
4573 /* IEEE_B */ 5888 /* IEEE_B */
4574 if (network->mode == IEEE_B) { 5889 if (mode == IEEE_B) {
4575 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) { 5890 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
4576 /* Invalid fixed rate mask */ 5891 /* Invalid fixed rate mask */
5892 IPW_DEBUG_WX
5893 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
4577 fr.tx_rates = 0; 5894 fr.tx_rates = 0;
4578 } 5895 }
4579 break; 5896 break;
@@ -4583,6 +5900,8 @@ static inline void ipw_set_fixed_rate(struct ipw_priv *priv,
4583 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK | 5900 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
4584 IEEE80211_OFDM_RATES_MASK)) { 5901 IEEE80211_OFDM_RATES_MASK)) {
4585 /* Invalid fixed rate mask */ 5902 /* Invalid fixed rate mask */
5903 IPW_DEBUG_WX
5904 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
4586 fr.tx_rates = 0; 5905 fr.tx_rates = 0;
4587 break; 5906 break;
4588 } 5907 }
@@ -4610,6 +5929,1112 @@ static inline void ipw_set_fixed_rate(struct ipw_priv *priv,
4610 ipw_write_reg32(priv, reg, *(u32 *) & fr); 5929 ipw_write_reg32(priv, reg, *(u32 *) & fr);
4611} 5930}
4612 5931
5932static void ipw_abort_scan(struct ipw_priv *priv)
5933{
5934 int err;
5935
5936 if (priv->status & STATUS_SCAN_ABORTING) {
5937 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5938 return;
5939 }
5940 priv->status |= STATUS_SCAN_ABORTING;
5941
5942 err = ipw_send_scan_abort(priv);
5943 if (err)
5944 IPW_DEBUG_HC("Request to abort scan failed.\n");
5945}
5946
5947static void ipw_add_scan_channels(struct ipw_priv *priv,
5948 struct ipw_scan_request_ext *scan,
5949 int scan_type)
5950{
5951 int channel_index = 0;
5952 const struct ieee80211_geo *geo;
5953 int i;
5954
5955 geo = ipw_get_geo(priv->ieee);
5956
5957 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
5958 int start = channel_index;
5959 for (i = 0; i < geo->a_channels; i++) {
5960 if ((priv->status & STATUS_ASSOCIATED) &&
5961 geo->a[i].channel == priv->channel)
5962 continue;
5963 channel_index++;
5964 scan->channels_list[channel_index] = geo->a[i].channel;
5965 ipw_set_scan_type(scan, channel_index,
5966 geo->a[i].
5967 flags & IEEE80211_CH_PASSIVE_ONLY ?
5968 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
5969 scan_type);
5970 }
5971
5972 if (start != channel_index) {
5973 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
5974 (channel_index - start);
5975 channel_index++;
5976 }
5977 }
5978
5979 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
5980 int start = channel_index;
5981 if (priv->config & CFG_SPEED_SCAN) {
5982 int index;
5983 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
5984 /* nop out the list */
5985 [0] = 0
5986 };
5987
5988 u8 channel;
5989 while (channel_index < IPW_SCAN_CHANNELS) {
5990 channel =
5991 priv->speed_scan[priv->speed_scan_pos];
5992 if (channel == 0) {
5993 priv->speed_scan_pos = 0;
5994 channel = priv->speed_scan[0];
5995 }
5996 if ((priv->status & STATUS_ASSOCIATED) &&
5997 channel == priv->channel) {
5998 priv->speed_scan_pos++;
5999 continue;
6000 }
6001
6002 /* If this channel has already been
6003 * added in scan, break from loop
6004 * and this will be the first channel
6005 * in the next scan.
6006 */
6007 if (channels[channel - 1] != 0)
6008 break;
6009
6010 channels[channel - 1] = 1;
6011 priv->speed_scan_pos++;
6012 channel_index++;
6013 scan->channels_list[channel_index] = channel;
6014 index =
6015 ipw_channel_to_index(priv->ieee, channel);
6016 ipw_set_scan_type(scan, channel_index,
6017 geo->bg[index].
6018 flags &
6019 IEEE80211_CH_PASSIVE_ONLY ?
6020 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6021 : scan_type);
6022 }
6023 } else {
6024 for (i = 0; i < geo->bg_channels; i++) {
6025 if ((priv->status & STATUS_ASSOCIATED) &&
6026 geo->bg[i].channel == priv->channel)
6027 continue;
6028 channel_index++;
6029 scan->channels_list[channel_index] =
6030 geo->bg[i].channel;
6031 ipw_set_scan_type(scan, channel_index,
6032 geo->bg[i].
6033 flags &
6034 IEEE80211_CH_PASSIVE_ONLY ?
6035 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6036 : scan_type);
6037 }
6038 }
6039
6040 if (start != channel_index) {
6041 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6042 (channel_index - start);
6043 }
6044 }
6045}
6046
6047static int ipw_request_scan(struct ipw_priv *priv)
6048{
6049 struct ipw_scan_request_ext scan;
6050 int err = 0, scan_type;
6051
6052 if (!(priv->status & STATUS_INIT) ||
6053 (priv->status & STATUS_EXIT_PENDING))
6054 return 0;
6055
6056 down(&priv->sem);
6057
6058 if (priv->status & STATUS_SCANNING) {
6059 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
6060 priv->status |= STATUS_SCAN_PENDING;
6061 goto done;
6062 }
6063
6064 if (!(priv->status & STATUS_SCAN_FORCED) &&
6065 priv->status & STATUS_SCAN_ABORTING) {
6066 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6067 priv->status |= STATUS_SCAN_PENDING;
6068 goto done;
6069 }
6070
6071 if (priv->status & STATUS_RF_KILL_MASK) {
6072 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6073 priv->status |= STATUS_SCAN_PENDING;
6074 goto done;
6075 }
6076
6077 memset(&scan, 0, sizeof(scan));
6078
6079 if (priv->config & CFG_SPEED_SCAN)
6080 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6081 cpu_to_le16(30);
6082 else
6083 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6084 cpu_to_le16(20);
6085
6086 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6087 cpu_to_le16(20);
6088 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
6089
6090 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
6091
6092#ifdef CONFIG_IPW2200_MONITOR
6093 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
6094 u8 channel;
6095 u8 band = 0;
6096
6097 switch (ipw_is_valid_channel(priv->ieee, priv->channel)) {
6098 case IEEE80211_52GHZ_BAND:
6099 band = (u8) (IPW_A_MODE << 6) | 1;
6100 channel = priv->channel;
6101 break;
6102
6103 case IEEE80211_24GHZ_BAND:
6104 band = (u8) (IPW_B_MODE << 6) | 1;
6105 channel = priv->channel;
6106 break;
6107
6108 default:
6109 band = (u8) (IPW_B_MODE << 6) | 1;
6110 channel = 9;
6111 break;
6112 }
6113
6114 scan.channels_list[0] = band;
6115 scan.channels_list[1] = channel;
6116 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
6117
6118 /* NOTE: The card will sit on this channel for this time
6119 * period. Scan aborts are timing sensitive and frequently
6120 * result in firmware restarts. As such, it is best to
6121 * set a small dwell_time here and just keep re-issuing
6122 * scans. Otherwise fast channel hopping will not actually
6123 * hop channels.
6124 *
6125 * TODO: Move SPEED SCAN support to all modes and bands */
6126 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6127 cpu_to_le16(2000);
6128 } else {
6129#endif /* CONFIG_IPW2200_MONITOR */
6130 /* If we are roaming, then make this a directed scan for the
6131 * current network. Otherwise, ensure that every other scan
6132 * is a fast channel hop scan */
6133 if ((priv->status & STATUS_ROAMING)
6134 || (!(priv->status & STATUS_ASSOCIATED)
6135 && (priv->config & CFG_STATIC_ESSID)
6136 && (le32_to_cpu(scan.full_scan_index) % 2))) {
6137 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6138 if (err) {
6139 IPW_DEBUG_HC("Attempt to send SSID command "
6140 "failed.\n");
6141 goto done;
6142 }
6143
6144 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
6145 } else
6146 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
6147
6148 ipw_add_scan_channels(priv, &scan, scan_type);
6149#ifdef CONFIG_IPW2200_MONITOR
6150 }
6151#endif
6152
6153 err = ipw_send_scan_request_ext(priv, &scan);
6154 if (err) {
6155 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
6156 goto done;
6157 }
6158
6159 priv->status |= STATUS_SCANNING;
6160 priv->status &= ~STATUS_SCAN_PENDING;
6161 queue_delayed_work(priv->workqueue, &priv->scan_check,
6162 IPW_SCAN_CHECK_WATCHDOG);
6163 done:
6164 up(&priv->sem);
6165 return err;
6166}
6167
6168static void ipw_bg_abort_scan(void *data)
6169{
6170 struct ipw_priv *priv = data;
6171 down(&priv->sem);
6172 ipw_abort_scan(data);
6173 up(&priv->sem);
6174}
6175
6176static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6177{
6178 /* This is called when wpa_supplicant loads and closes the driver
6179 * interface. */
6180 priv->ieee->wpa_enabled = value;
6181 return 0;
6182}
6183
6184static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6185{
6186 struct ieee80211_device *ieee = priv->ieee;
6187 struct ieee80211_security sec = {
6188 .flags = SEC_AUTH_MODE,
6189 };
6190 int ret = 0;
6191
6192 if (value & IW_AUTH_ALG_SHARED_KEY) {
6193 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6194 ieee->open_wep = 0;
6195 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
6196 sec.auth_mode = WLAN_AUTH_OPEN;
6197 ieee->open_wep = 1;
6198 } else
6199 return -EINVAL;
6200
6201 if (ieee->set_security)
6202 ieee->set_security(ieee->dev, &sec);
6203 else
6204 ret = -EOPNOTSUPP;
6205
6206 return ret;
6207}
6208
6209void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, int wpa_ie_len)
6210{
6211 /* make sure WPA is enabled */
6212 ipw_wpa_enable(priv, 1);
6213
6214 ipw_disassociate(priv);
6215}
6216
6217static int ipw_set_rsn_capa(struct ipw_priv *priv,
6218 char *capabilities, int length)
6219{
6220 struct host_cmd cmd = {
6221 .cmd = IPW_CMD_RSN_CAPABILITIES,
6222 .len = length,
6223 };
6224
6225 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6226
6227 memcpy(cmd.param, capabilities, length);
6228 return ipw_send_cmd(priv, &cmd);
6229}
6230
6231/*
6232 * WE-18 support
6233 */
6234
6235/* SIOCSIWGENIE */
6236static int ipw_wx_set_genie(struct net_device *dev,
6237 struct iw_request_info *info,
6238 union iwreq_data *wrqu, char *extra)
6239{
6240 struct ipw_priv *priv = ieee80211_priv(dev);
6241 struct ieee80211_device *ieee = priv->ieee;
6242 u8 *buf;
6243 int err = 0;
6244
6245 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6246 (wrqu->data.length && extra == NULL))
6247 return -EINVAL;
6248
6249 //down(&priv->sem);
6250
6251 //if (!ieee->wpa_enabled) {
6252 // err = -EOPNOTSUPP;
6253 // goto out;
6254 //}
6255
6256 if (wrqu->data.length) {
6257 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6258 if (buf == NULL) {
6259 err = -ENOMEM;
6260 goto out;
6261 }
6262
6263 memcpy(buf, extra, wrqu->data.length);
6264 kfree(ieee->wpa_ie);
6265 ieee->wpa_ie = buf;
6266 ieee->wpa_ie_len = wrqu->data.length;
6267 } else {
6268 kfree(ieee->wpa_ie);
6269 ieee->wpa_ie = NULL;
6270 ieee->wpa_ie_len = 0;
6271 }
6272
6273 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6274 out:
6275 //up(&priv->sem);
6276 return err;
6277}
6278
6279/* SIOCGIWGENIE */
6280static int ipw_wx_get_genie(struct net_device *dev,
6281 struct iw_request_info *info,
6282 union iwreq_data *wrqu, char *extra)
6283{
6284 struct ipw_priv *priv = ieee80211_priv(dev);
6285 struct ieee80211_device *ieee = priv->ieee;
6286 int err = 0;
6287
6288 //down(&priv->sem);
6289
6290 //if (!ieee->wpa_enabled) {
6291 // err = -EOPNOTSUPP;
6292 // goto out;
6293 //}
6294
6295 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6296 wrqu->data.length = 0;
6297 goto out;
6298 }
6299
6300 if (wrqu->data.length < ieee->wpa_ie_len) {
6301 err = -E2BIG;
6302 goto out;
6303 }
6304
6305 wrqu->data.length = ieee->wpa_ie_len;
6306 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6307
6308 out:
6309 //up(&priv->sem);
6310 return err;
6311}
6312
6313static int wext_cipher2level(int cipher)
6314{
6315 switch (cipher) {
6316 case IW_AUTH_CIPHER_NONE:
6317 return SEC_LEVEL_0;
6318 case IW_AUTH_CIPHER_WEP40:
6319 case IW_AUTH_CIPHER_WEP104:
6320 return SEC_LEVEL_1;
6321 case IW_AUTH_CIPHER_TKIP:
6322 return SEC_LEVEL_2;
6323 case IW_AUTH_CIPHER_CCMP:
6324 return SEC_LEVEL_3;
6325 default:
6326 return -1;
6327 }
6328}
6329
6330/* SIOCSIWAUTH */
6331static int ipw_wx_set_auth(struct net_device *dev,
6332 struct iw_request_info *info,
6333 union iwreq_data *wrqu, char *extra)
6334{
6335 struct ipw_priv *priv = ieee80211_priv(dev);
6336 struct ieee80211_device *ieee = priv->ieee;
6337 struct iw_param *param = &wrqu->param;
6338 struct ieee80211_crypt_data *crypt;
6339 unsigned long flags;
6340 int ret = 0;
6341
6342 switch (param->flags & IW_AUTH_INDEX) {
6343 case IW_AUTH_WPA_VERSION:
6344 break;
6345 case IW_AUTH_CIPHER_PAIRWISE:
6346 ipw_set_hw_decrypt_unicast(priv,
6347 wext_cipher2level(param->value));
6348 break;
6349 case IW_AUTH_CIPHER_GROUP:
6350 ipw_set_hw_decrypt_multicast(priv,
6351 wext_cipher2level(param->value));
6352 break;
6353 case IW_AUTH_KEY_MGMT:
6354 /*
6355 * ipw2200 does not use these parameters
6356 */
6357 break;
6358
6359 case IW_AUTH_TKIP_COUNTERMEASURES:
6360 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6361 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
6362 break;
6363
6364 flags = crypt->ops->get_flags(crypt->priv);
6365
6366 if (param->value)
6367 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6368 else
6369 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6370
6371 crypt->ops->set_flags(flags, crypt->priv);
6372
6373 break;
6374
6375 case IW_AUTH_DROP_UNENCRYPTED:{
6376 /* HACK:
6377 *
6378 * wpa_supplicant calls set_wpa_enabled when the driver
6379 * is loaded and unloaded, regardless of if WPA is being
6380 * used. No other calls are made which can be used to
6381 * determine if encryption will be used or not prior to
6382 * association being expected. If encryption is not being
6383 * used, drop_unencrypted is set to false, else true -- we
6384 * can use this to determine if the CAP_PRIVACY_ON bit should
6385 * be set.
6386 */
6387 struct ieee80211_security sec = {
6388 .flags = SEC_ENABLED,
6389 .enabled = param->value,
6390 };
6391 priv->ieee->drop_unencrypted = param->value;
6392 /* We only change SEC_LEVEL for open mode. Others
6393 * are set by ipw_wpa_set_encryption.
6394 */
6395 if (!param->value) {
6396 sec.flags |= SEC_LEVEL;
6397 sec.level = SEC_LEVEL_0;
6398 } else {
6399 sec.flags |= SEC_LEVEL;
6400 sec.level = SEC_LEVEL_1;
6401 }
6402 if (priv->ieee->set_security)
6403 priv->ieee->set_security(priv->ieee->dev, &sec);
6404 break;
6405 }
6406
6407 case IW_AUTH_80211_AUTH_ALG:
6408 ret = ipw_wpa_set_auth_algs(priv, param->value);
6409 break;
6410
6411 case IW_AUTH_WPA_ENABLED:
6412 ret = ipw_wpa_enable(priv, param->value);
6413 break;
6414
6415 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6416 ieee->ieee802_1x = param->value;
6417 break;
6418
6419 //case IW_AUTH_ROAMING_CONTROL:
6420 case IW_AUTH_PRIVACY_INVOKED:
6421 ieee->privacy_invoked = param->value;
6422 break;
6423
6424 default:
6425 return -EOPNOTSUPP;
6426 }
6427 return ret;
6428}
6429
6430/* SIOCGIWAUTH */
6431static int ipw_wx_get_auth(struct net_device *dev,
6432 struct iw_request_info *info,
6433 union iwreq_data *wrqu, char *extra)
6434{
6435 struct ipw_priv *priv = ieee80211_priv(dev);
6436 struct ieee80211_device *ieee = priv->ieee;
6437 struct ieee80211_crypt_data *crypt;
6438 struct iw_param *param = &wrqu->param;
6439 int ret = 0;
6440
6441 switch (param->flags & IW_AUTH_INDEX) {
6442 case IW_AUTH_WPA_VERSION:
6443 case IW_AUTH_CIPHER_PAIRWISE:
6444 case IW_AUTH_CIPHER_GROUP:
6445 case IW_AUTH_KEY_MGMT:
6446 /*
6447 * wpa_supplicant will control these internally
6448 */
6449 ret = -EOPNOTSUPP;
6450 break;
6451
6452 case IW_AUTH_TKIP_COUNTERMEASURES:
6453 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
6454 if (!crypt || !crypt->ops->get_flags)
6455 break;
6456
6457 param->value = (crypt->ops->get_flags(crypt->priv) &
6458 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6459
6460 break;
6461
6462 case IW_AUTH_DROP_UNENCRYPTED:
6463 param->value = ieee->drop_unencrypted;
6464 break;
6465
6466 case IW_AUTH_80211_AUTH_ALG:
6467 param->value = ieee->sec.auth_mode;
6468 break;
6469
6470 case IW_AUTH_WPA_ENABLED:
6471 param->value = ieee->wpa_enabled;
6472 break;
6473
6474 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6475 param->value = ieee->ieee802_1x;
6476 break;
6477
6478 case IW_AUTH_ROAMING_CONTROL:
6479 case IW_AUTH_PRIVACY_INVOKED:
6480 param->value = ieee->privacy_invoked;
6481 break;
6482
6483 default:
6484 return -EOPNOTSUPP;
6485 }
6486 return 0;
6487}
6488
6489/* SIOCSIWENCODEEXT */
6490static int ipw_wx_set_encodeext(struct net_device *dev,
6491 struct iw_request_info *info,
6492 union iwreq_data *wrqu, char *extra)
6493{
6494 struct ipw_priv *priv = ieee80211_priv(dev);
6495 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6496
6497 if (hwcrypto) {
6498 if (ext->alg == IW_ENCODE_ALG_TKIP) {
6499 /* IPW HW can't build TKIP MIC,
6500 host decryption still needed */
6501 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6502 priv->ieee->host_mc_decrypt = 1;
6503 else {
6504 priv->ieee->host_encrypt = 0;
6505 priv->ieee->host_encrypt_msdu = 1;
6506 priv->ieee->host_decrypt = 1;
6507 }
6508 } else {
6509 priv->ieee->host_encrypt = 0;
6510 priv->ieee->host_encrypt_msdu = 0;
6511 priv->ieee->host_decrypt = 0;
6512 priv->ieee->host_mc_decrypt = 0;
6513 }
6514 }
6515
6516 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6517}
6518
6519/* SIOCGIWENCODEEXT */
6520static int ipw_wx_get_encodeext(struct net_device *dev,
6521 struct iw_request_info *info,
6522 union iwreq_data *wrqu, char *extra)
6523{
6524 struct ipw_priv *priv = ieee80211_priv(dev);
6525 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6526}
6527
6528/* SIOCSIWMLME */
6529static int ipw_wx_set_mlme(struct net_device *dev,
6530 struct iw_request_info *info,
6531 union iwreq_data *wrqu, char *extra)
6532{
6533 struct ipw_priv *priv = ieee80211_priv(dev);
6534 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6535 u16 reason;
6536
6537 reason = cpu_to_le16(mlme->reason_code);
6538
6539 switch (mlme->cmd) {
6540 case IW_MLME_DEAUTH:
6541 // silently ignore
6542 break;
6543
6544 case IW_MLME_DISASSOC:
6545 ipw_disassociate(priv);
6546 break;
6547
6548 default:
6549 return -EOPNOTSUPP;
6550 }
6551 return 0;
6552}
6553
6554#ifdef CONFIG_IPW_QOS
6555
6556/* QoS */
6557/*
6558* get the modulation type of the current network or
6559* the card current mode
6560*/
6561u8 ipw_qos_current_mode(struct ipw_priv * priv)
6562{
6563 u8 mode = 0;
6564
6565 if (priv->status & STATUS_ASSOCIATED) {
6566 unsigned long flags;
6567
6568 spin_lock_irqsave(&priv->ieee->lock, flags);
6569 mode = priv->assoc_network->mode;
6570 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6571 } else {
6572 mode = priv->ieee->mode;
6573 }
6574 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6575 return mode;
6576}
6577
6578/*
6579* Handle management frame beacon and probe response
6580*/
6581static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6582 int active_network,
6583 struct ieee80211_network *network)
6584{
6585 u32 size = sizeof(struct ieee80211_qos_parameters);
6586
6587 if (network->capability & WLAN_CAPABILITY_IBSS)
6588 network->qos_data.active = network->qos_data.supported;
6589
6590 if (network->flags & NETWORK_HAS_QOS_MASK) {
6591 if (active_network &&
6592 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
6593 network->qos_data.active = network->qos_data.supported;
6594
6595 if ((network->qos_data.active == 1) && (active_network == 1) &&
6596 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6597 (network->qos_data.old_param_count !=
6598 network->qos_data.param_count)) {
6599 network->qos_data.old_param_count =
6600 network->qos_data.param_count;
6601 schedule_work(&priv->qos_activate);
6602 IPW_DEBUG_QOS("QoS parameters change call "
6603 "qos_activate\n");
6604 }
6605 } else {
6606 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6607 memcpy(&network->qos_data.parameters,
6608 &def_parameters_CCK, size);
6609 else
6610 memcpy(&network->qos_data.parameters,
6611 &def_parameters_OFDM, size);
6612
6613 if ((network->qos_data.active == 1) && (active_network == 1)) {
6614 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6615 schedule_work(&priv->qos_activate);
6616 }
6617
6618 network->qos_data.active = 0;
6619 network->qos_data.supported = 0;
6620 }
6621 if ((priv->status & STATUS_ASSOCIATED) &&
6622 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6623 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6624 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6625 !(network->flags & NETWORK_EMPTY_ESSID))
6626 if ((network->ssid_len ==
6627 priv->assoc_network->ssid_len) &&
6628 !memcmp(network->ssid,
6629 priv->assoc_network->ssid,
6630 network->ssid_len)) {
6631 queue_work(priv->workqueue,
6632 &priv->merge_networks);
6633 }
6634 }
6635
6636 return 0;
6637}
6638
6639/*
6640* This function set up the firmware to support QoS. It sends
6641* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6642*/
6643static int ipw_qos_activate(struct ipw_priv *priv,
6644 struct ieee80211_qos_data *qos_network_data)
6645{
6646 int err;
6647 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6648 struct ieee80211_qos_parameters *active_one = NULL;
6649 u32 size = sizeof(struct ieee80211_qos_parameters);
6650 u32 burst_duration;
6651 int i;
6652 u8 type;
6653
6654 type = ipw_qos_current_mode(priv);
6655
6656 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6657 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6658 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6659 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6660
6661 if (qos_network_data == NULL) {
6662 if (type == IEEE_B) {
6663 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6664 active_one = &def_parameters_CCK;
6665 } else
6666 active_one = &def_parameters_OFDM;
6667
6668 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6669 burst_duration = ipw_qos_get_burst_duration(priv);
6670 for (i = 0; i < QOS_QUEUE_NUM; i++)
6671 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6672 (u16) burst_duration;
6673 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6674 if (type == IEEE_B) {
6675 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6676 type);
6677 if (priv->qos_data.qos_enable == 0)
6678 active_one = &def_parameters_CCK;
6679 else
6680 active_one = priv->qos_data.def_qos_parm_CCK;
6681 } else {
6682 if (priv->qos_data.qos_enable == 0)
6683 active_one = &def_parameters_OFDM;
6684 else
6685 active_one = priv->qos_data.def_qos_parm_OFDM;
6686 }
6687 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6688 } else {
6689 unsigned long flags;
6690 int active;
6691
6692 spin_lock_irqsave(&priv->ieee->lock, flags);
6693 active_one = &(qos_network_data->parameters);
6694 qos_network_data->old_param_count =
6695 qos_network_data->param_count;
6696 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
6697 active = qos_network_data->supported;
6698 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6699
6700 if (active == 0) {
6701 burst_duration = ipw_qos_get_burst_duration(priv);
6702 for (i = 0; i < QOS_QUEUE_NUM; i++)
6703 qos_parameters[QOS_PARAM_SET_ACTIVE].
6704 tx_op_limit[i] = (u16) burst_duration;
6705 }
6706 }
6707
6708 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
6709 err = ipw_send_qos_params_command(priv,
6710 (struct ieee80211_qos_parameters *)
6711 &(qos_parameters[0]));
6712 if (err)
6713 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6714
6715 return err;
6716}
6717
6718/*
6719* send IPW_CMD_WME_INFO to the firmware
6720*/
6721static int ipw_qos_set_info_element(struct ipw_priv *priv)
6722{
6723 int ret = 0;
6724 struct ieee80211_qos_information_element qos_info;
6725
6726 if (priv == NULL)
6727 return -1;
6728
6729 qos_info.elementID = QOS_ELEMENT_ID;
6730 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6731
6732 qos_info.version = QOS_VERSION_1;
6733 qos_info.ac_info = 0;
6734
6735 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6736 qos_info.qui_type = QOS_OUI_TYPE;
6737 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6738
6739 ret = ipw_send_qos_info_command(priv, &qos_info);
6740 if (ret != 0) {
6741 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6742 }
6743 return ret;
6744}
6745
6746/*
6747* Set the QoS parameter with the association request structure
6748*/
6749static int ipw_qos_association(struct ipw_priv *priv,
6750 struct ieee80211_network *network)
6751{
6752 int err = 0;
6753 struct ieee80211_qos_data *qos_data = NULL;
6754 struct ieee80211_qos_data ibss_data = {
6755 .supported = 1,
6756 .active = 1,
6757 };
6758
6759 switch (priv->ieee->iw_mode) {
6760 case IW_MODE_ADHOC:
6761 if (!(network->capability & WLAN_CAPABILITY_IBSS))
6762 BUG();
6763
6764 qos_data = &ibss_data;
6765 break;
6766
6767 case IW_MODE_INFRA:
6768 qos_data = &network->qos_data;
6769 break;
6770
6771 default:
6772 BUG();
6773 break;
6774 }
6775
6776 err = ipw_qos_activate(priv, qos_data);
6777 if (err) {
6778 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6779 return err;
6780 }
6781
6782 if (priv->qos_data.qos_enable && qos_data->supported) {
6783 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6784 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6785 return ipw_qos_set_info_element(priv);
6786 }
6787
6788 return 0;
6789}
6790
6791/*
6792* handling the beaconing responces. if we get different QoS setting
6793* of the network from the the associated setting adjust the QoS
6794* setting
6795*/
6796static int ipw_qos_association_resp(struct ipw_priv *priv,
6797 struct ieee80211_network *network)
6798{
6799 int ret = 0;
6800 unsigned long flags;
6801 u32 size = sizeof(struct ieee80211_qos_parameters);
6802 int set_qos_param = 0;
6803
6804 if ((priv == NULL) || (network == NULL) ||
6805 (priv->assoc_network == NULL))
6806 return ret;
6807
6808 if (!(priv->status & STATUS_ASSOCIATED))
6809 return ret;
6810
6811 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
6812 return ret;
6813
6814 spin_lock_irqsave(&priv->ieee->lock, flags);
6815 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
6816 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
6817 sizeof(struct ieee80211_qos_data));
6818 priv->assoc_network->qos_data.active = 1;
6819 if ((network->qos_data.old_param_count !=
6820 network->qos_data.param_count)) {
6821 set_qos_param = 1;
6822 network->qos_data.old_param_count =
6823 network->qos_data.param_count;
6824 }
6825
6826 } else {
6827 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
6828 memcpy(&priv->assoc_network->qos_data.parameters,
6829 &def_parameters_CCK, size);
6830 else
6831 memcpy(&priv->assoc_network->qos_data.parameters,
6832 &def_parameters_OFDM, size);
6833 priv->assoc_network->qos_data.active = 0;
6834 priv->assoc_network->qos_data.supported = 0;
6835 set_qos_param = 1;
6836 }
6837
6838 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6839
6840 if (set_qos_param == 1)
6841 schedule_work(&priv->qos_activate);
6842
6843 return ret;
6844}
6845
6846static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
6847{
6848 u32 ret = 0;
6849
6850 if ((priv == NULL))
6851 return 0;
6852
6853 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
6854 ret = priv->qos_data.burst_duration_CCK;
6855 else
6856 ret = priv->qos_data.burst_duration_OFDM;
6857
6858 return ret;
6859}
6860
6861/*
6862* Initialize the setting of QoS global
6863*/
6864static void ipw_qos_init(struct ipw_priv *priv, int enable,
6865 int burst_enable, u32 burst_duration_CCK,
6866 u32 burst_duration_OFDM)
6867{
6868 priv->qos_data.qos_enable = enable;
6869
6870 if (priv->qos_data.qos_enable) {
6871 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
6872 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
6873 IPW_DEBUG_QOS("QoS is enabled\n");
6874 } else {
6875 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
6876 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
6877 IPW_DEBUG_QOS("QoS is not enabled\n");
6878 }
6879
6880 priv->qos_data.burst_enable = burst_enable;
6881
6882 if (burst_enable) {
6883 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
6884 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
6885 } else {
6886 priv->qos_data.burst_duration_CCK = 0;
6887 priv->qos_data.burst_duration_OFDM = 0;
6888 }
6889}
6890
6891/*
6892* map the packet priority to the right TX Queue
6893*/
6894static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
6895{
6896 if (priority > 7 || !priv->qos_data.qos_enable)
6897 priority = 0;
6898
6899 return from_priority_to_tx_queue[priority] - 1;
6900}
6901
6902/*
6903* add QoS parameter to the TX command
6904*/
6905static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
6906 u16 priority,
6907 struct tfd_data *tfd, u8 unicast)
6908{
6909 int ret = 0;
6910 int tx_queue_id = 0;
6911 struct ieee80211_qos_data *qos_data = NULL;
6912 int active, supported;
6913 unsigned long flags;
6914
6915 if (!(priv->status & STATUS_ASSOCIATED))
6916 return 0;
6917
6918 qos_data = &priv->assoc_network->qos_data;
6919
6920 spin_lock_irqsave(&priv->ieee->lock, flags);
6921
6922 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6923 if (unicast == 0)
6924 qos_data->active = 0;
6925 else
6926 qos_data->active = qos_data->supported;
6927 }
6928
6929 active = qos_data->active;
6930 supported = qos_data->supported;
6931
6932 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6933
6934 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
6935 "unicast %d\n",
6936 priv->qos_data.qos_enable, active, supported, unicast);
6937 if (active && priv->qos_data.qos_enable) {
6938 ret = from_priority_to_tx_queue[priority];
6939 tx_queue_id = ret - 1;
6940 IPW_DEBUG_QOS("QoS packet priority is %d \n", priority);
6941 if (priority <= 7) {
6942 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
6943 tfd->tfd.tfd_26.mchdr.qos_ctrl = priority;
6944 tfd->tfd.tfd_26.mchdr.frame_ctl |=
6945 IEEE80211_STYPE_QOS_DATA;
6946
6947 if (priv->qos_data.qos_no_ack_mask &
6948 (1UL << tx_queue_id)) {
6949 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
6950 tfd->tfd.tfd_26.mchdr.qos_ctrl |=
6951 CTRL_QOS_NO_ACK;
6952 }
6953 }
6954 }
6955
6956 return ret;
6957}
6958
6959/*
6960* background support to run QoS activate functionality
6961*/
6962static void ipw_bg_qos_activate(void *data)
6963{
6964 struct ipw_priv *priv = data;
6965
6966 if (priv == NULL)
6967 return;
6968
6969 down(&priv->sem);
6970
6971 if (priv->status & STATUS_ASSOCIATED)
6972 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
6973
6974 up(&priv->sem);
6975}
6976
6977static int ipw_handle_probe_response(struct net_device *dev,
6978 struct ieee80211_probe_response *resp,
6979 struct ieee80211_network *network)
6980{
6981 struct ipw_priv *priv = ieee80211_priv(dev);
6982 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
6983 (network == priv->assoc_network));
6984
6985 ipw_qos_handle_probe_response(priv, active_network, network);
6986
6987 return 0;
6988}
6989
6990static int ipw_handle_beacon(struct net_device *dev,
6991 struct ieee80211_beacon *resp,
6992 struct ieee80211_network *network)
6993{
6994 struct ipw_priv *priv = ieee80211_priv(dev);
6995 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
6996 (network == priv->assoc_network));
6997
6998 ipw_qos_handle_probe_response(priv, active_network, network);
6999
7000 return 0;
7001}
7002
7003static int ipw_handle_assoc_response(struct net_device *dev,
7004 struct ieee80211_assoc_response *resp,
7005 struct ieee80211_network *network)
7006{
7007 struct ipw_priv *priv = ieee80211_priv(dev);
7008 ipw_qos_association_resp(priv, network);
7009 return 0;
7010}
7011
7012static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7013 *qos_param)
7014{
7015 struct host_cmd cmd = {
7016 .cmd = IPW_CMD_QOS_PARAMETERS,
7017 .len = (sizeof(struct ieee80211_qos_parameters) * 3)
7018 };
7019
7020 memcpy(cmd.param, qos_param, sizeof(*qos_param) * 3);
7021 return ipw_send_cmd(priv, &cmd);
7022}
7023
7024static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7025 *qos_param)
7026{
7027 struct host_cmd cmd = {
7028 .cmd = IPW_CMD_WME_INFO,
7029 .len = sizeof(*qos_param)
7030 };
7031
7032 memcpy(cmd.param, qos_param, sizeof(*qos_param));
7033 return ipw_send_cmd(priv, &cmd);
7034}
7035
7036#endif /* CONFIG_IPW_QOS */
7037
4613static int ipw_associate_network(struct ipw_priv *priv, 7038static int ipw_associate_network(struct ipw_priv *priv,
4614 struct ieee80211_network *network, 7039 struct ieee80211_network *network,
4615 struct ipw_supported_rates *rates, int roaming) 7040 struct ipw_supported_rates *rates, int roaming)
@@ -4617,7 +7042,7 @@ static int ipw_associate_network(struct ipw_priv *priv,
4617 int err; 7042 int err;
4618 7043
4619 if (priv->config & CFG_FIXED_RATE) 7044 if (priv->config & CFG_FIXED_RATE)
4620 ipw_set_fixed_rate(priv, network); 7045 ipw_set_fixed_rate(priv, network->mode);
4621 7046
4622 if (!(priv->config & CFG_STATIC_ESSID)) { 7047 if (!(priv->config & CFG_STATIC_ESSID)) {
4623 priv->essid_len = min(network->ssid_len, 7048 priv->essid_len = min(network->ssid_len,
@@ -4632,14 +7057,22 @@ static int ipw_associate_network(struct ipw_priv *priv,
4632 if ((priv->capability & CAP_PRIVACY_ON) && 7057 if ((priv->capability & CAP_PRIVACY_ON) &&
4633 (priv->capability & CAP_SHARED_KEY)) { 7058 (priv->capability & CAP_SHARED_KEY)) {
4634 priv->assoc_request.auth_type = AUTH_SHARED_KEY; 7059 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
4635 priv->assoc_request.auth_key = priv->sec.active_key; 7060 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7061
7062 if ((priv->capability & CAP_PRIVACY_ON) &&
7063 (priv->ieee->sec.level == SEC_LEVEL_1) &&
7064 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
7065 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
4636 } else { 7066 } else {
4637 priv->assoc_request.auth_type = AUTH_OPEN; 7067 priv->assoc_request.auth_type = AUTH_OPEN;
4638 priv->assoc_request.auth_key = 0; 7068 priv->assoc_request.auth_key = 0;
4639 } 7069 }
4640 7070
4641 if (priv->capability & CAP_PRIVACY_ON) 7071 if (priv->ieee->wpa_ie_len) {
4642 ipw_send_wep_keys(priv); 7072 priv->assoc_request.policy_support = 0x02; /* RSN active */
7073 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7074 priv->ieee->wpa_ie_len);
7075 }
4643 7076
4644 /* 7077 /*
4645 * It is valid for our ieee device to support multiple modes, but 7078 * It is valid for our ieee device to support multiple modes, but
@@ -4653,20 +7086,41 @@ static int ipw_associate_network(struct ipw_priv *priv,
4653 else if (network->mode & priv->ieee->mode & IEEE_B) 7086 else if (network->mode & priv->ieee->mode & IEEE_B)
4654 priv->assoc_request.ieee_mode = IPW_B_MODE; 7087 priv->assoc_request.ieee_mode = IPW_B_MODE;
4655 7088
7089 priv->assoc_request.capability = network->capability;
7090 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7091 && !(priv->config & CFG_PREAMBLE_LONG)) {
7092 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7093 } else {
7094 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7095
7096 /* Clear the short preamble if we won't be supporting it */
7097 priv->assoc_request.capability &=
7098 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7099 }
7100
7101 /* Clear capability bits that aren't used in Ad Hoc */
7102 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7103 priv->assoc_request.capability &=
7104 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7105
4656 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, " 7106 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
4657 "802.11%c [%d], enc=%s%s%s%c%c\n", 7107 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
4658 roaming ? "Rea" : "A", 7108 roaming ? "Rea" : "A",
4659 escape_essid(priv->essid, priv->essid_len), 7109 escape_essid(priv->essid, priv->essid_len),
4660 network->channel, 7110 network->channel,
4661 ipw_modes[priv->assoc_request.ieee_mode], 7111 ipw_modes[priv->assoc_request.ieee_mode],
4662 rates->num_rates, 7112 rates->num_rates,
7113 (priv->assoc_request.preamble_length ==
7114 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7115 network->capability &
7116 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
4663 priv->capability & CAP_PRIVACY_ON ? "on " : "off", 7117 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
4664 priv->capability & CAP_PRIVACY_ON ? 7118 priv->capability & CAP_PRIVACY_ON ?
4665 (priv->capability & CAP_SHARED_KEY ? "(shared)" : 7119 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
4666 "(open)") : "", 7120 "(open)") : "",
4667 priv->capability & CAP_PRIVACY_ON ? " key=" : "", 7121 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
4668 priv->capability & CAP_PRIVACY_ON ? 7122 priv->capability & CAP_PRIVACY_ON ?
4669 '1' + priv->sec.active_key : '.', 7123 '1' + priv->ieee->sec.active_key : '.',
4670 priv->capability & CAP_PRIVACY_ON ? '.' : ' '); 7124 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
4671 7125
4672 priv->assoc_request.beacon_interval = network->beacon_interval; 7126 priv->assoc_request.beacon_interval = network->beacon_interval;
@@ -4684,17 +7138,16 @@ static int ipw_associate_network(struct ipw_priv *priv,
4684 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0]; 7138 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
4685 } 7139 }
4686 7140
4687 memcpy(&priv->assoc_request.bssid, network->bssid, ETH_ALEN); 7141 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
4688 7142
4689 if (priv->ieee->iw_mode == IW_MODE_ADHOC) { 7143 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
4690 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN); 7144 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
4691 priv->assoc_request.atim_window = network->atim_window; 7145 priv->assoc_request.atim_window = network->atim_window;
4692 } else { 7146 } else {
4693 memcpy(&priv->assoc_request.dest, network->bssid, ETH_ALEN); 7147 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
4694 priv->assoc_request.atim_window = 0; 7148 priv->assoc_request.atim_window = 0;
4695 } 7149 }
4696 7150
4697 priv->assoc_request.capability = network->capability;
4698 priv->assoc_request.listen_interval = network->listen_interval; 7151 priv->assoc_request.listen_interval = network->listen_interval;
4699 7152
4700 err = ipw_send_ssid(priv, priv->essid, priv->essid_len); 7153 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
@@ -4711,6 +7164,12 @@ static int ipw_associate_network(struct ipw_priv *priv,
4711 priv->sys_config.dot11g_auto_detection = 1; 7164 priv->sys_config.dot11g_auto_detection = 1;
4712 else 7165 else
4713 priv->sys_config.dot11g_auto_detection = 0; 7166 priv->sys_config.dot11g_auto_detection = 0;
7167
7168 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7169 priv->sys_config.answer_broadcast_ssid_probe = 1;
7170 else
7171 priv->sys_config.answer_broadcast_ssid_probe = 0;
7172
4714 err = ipw_send_system_config(priv, &priv->sys_config); 7173 err = ipw_send_system_config(priv, &priv->sys_config);
4715 if (err) { 7174 if (err) {
4716 IPW_DEBUG_HC("Attempt to send sys config command failed.\n"); 7175 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
@@ -4718,7 +7177,7 @@ static int ipw_associate_network(struct ipw_priv *priv,
4718 } 7177 }
4719 7178
4720 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi); 7179 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
4721 err = ipw_set_sensitivity(priv, network->stats.rssi); 7180 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
4722 if (err) { 7181 if (err) {
4723 IPW_DEBUG_HC("Attempt to send associate command failed.\n"); 7182 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
4724 return err; 7183 return err;
@@ -4736,6 +7195,10 @@ static int ipw_associate_network(struct ipw_priv *priv,
4736 7195
4737 priv->assoc_network = network; 7196 priv->assoc_network = network;
4738 7197
7198#ifdef CONFIG_IPW_QOS
7199 ipw_qos_association(priv, network);
7200#endif
7201
4739 err = ipw_send_associate(priv, &priv->assoc_request); 7202 err = ipw_send_associate(priv, &priv->assoc_request);
4740 if (err) { 7203 if (err) {
4741 IPW_DEBUG_HC("Attempt to send associate command failed.\n"); 7204 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
@@ -4783,12 +7246,15 @@ static void ipw_roam(void *data)
4783 if (priv->status & STATUS_ASSOCIATED) { 7246 if (priv->status & STATUS_ASSOCIATED) {
4784 /* First pass through ROAM process -- look for a better 7247 /* First pass through ROAM process -- look for a better
4785 * network */ 7248 * network */
7249 unsigned long flags;
4786 u8 rssi = priv->assoc_network->stats.rssi; 7250 u8 rssi = priv->assoc_network->stats.rssi;
4787 priv->assoc_network->stats.rssi = -128; 7251 priv->assoc_network->stats.rssi = -128;
7252 spin_lock_irqsave(&priv->ieee->lock, flags);
4788 list_for_each_entry(network, &priv->ieee->network_list, list) { 7253 list_for_each_entry(network, &priv->ieee->network_list, list) {
4789 if (network != priv->assoc_network) 7254 if (network != priv->assoc_network)
4790 ipw_best_network(priv, &match, network, 1); 7255 ipw_best_network(priv, &match, network, 1);
4791 } 7256 }
7257 spin_unlock_irqrestore(&priv->ieee->lock, flags);
4792 priv->assoc_network->stats.rssi = rssi; 7258 priv->assoc_network->stats.rssi = rssi;
4793 7259
4794 if (match.network == priv->assoc_network) { 7260 if (match.network == priv->assoc_network) {
@@ -4811,7 +7277,15 @@ static void ipw_roam(void *data)
4811 priv->status &= ~STATUS_ROAMING; 7277 priv->status &= ~STATUS_ROAMING;
4812} 7278}
4813 7279
4814static void ipw_associate(void *data) 7280static void ipw_bg_roam(void *data)
7281{
7282 struct ipw_priv *priv = data;
7283 down(&priv->sem);
7284 ipw_roam(data);
7285 up(&priv->sem);
7286}
7287
7288static int ipw_associate(void *data)
4815{ 7289{
4816 struct ipw_priv *priv = data; 7290 struct ipw_priv *priv = data;
4817 7291
@@ -4821,14 +7295,41 @@ static void ipw_associate(void *data)
4821 }; 7295 };
4822 struct ipw_supported_rates *rates; 7296 struct ipw_supported_rates *rates;
4823 struct list_head *element; 7297 struct list_head *element;
7298 unsigned long flags;
7299
7300 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7301 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7302 return 0;
7303 }
7304
7305 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
7306 IPW_DEBUG_ASSOC("Not attempting association (already in "
7307 "progress)\n");
7308 return 0;
7309 }
7310
7311 if (priv->status & STATUS_DISASSOCIATING) {
7312 IPW_DEBUG_ASSOC("Not attempting association (in "
7313 "disassociating)\n ");
7314 queue_work(priv->workqueue, &priv->associate);
7315 return 0;
7316 }
7317
7318 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
7319 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7320 "initialized)\n");
7321 return 0;
7322 }
4824 7323
4825 if (!(priv->config & CFG_ASSOCIATE) && 7324 if (!(priv->config & CFG_ASSOCIATE) &&
4826 !(priv->config & (CFG_STATIC_ESSID | 7325 !(priv->config & (CFG_STATIC_ESSID |
4827 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) { 7326 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
4828 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n"); 7327 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
4829 return; 7328 return 0;
4830 } 7329 }
4831 7330
7331 /* Protect our use of the network_list */
7332 spin_lock_irqsave(&priv->ieee->lock, flags);
4832 list_for_each_entry(network, &priv->ieee->network_list, list) 7333 list_for_each_entry(network, &priv->ieee->network_list, list)
4833 ipw_best_network(priv, &match, network, 0); 7334 ipw_best_network(priv, &match, network, 0);
4834 7335
@@ -4839,6 +7340,7 @@ static void ipw_associate(void *data)
4839 priv->ieee->iw_mode == IW_MODE_ADHOC && 7340 priv->ieee->iw_mode == IW_MODE_ADHOC &&
4840 priv->config & CFG_ADHOC_CREATE && 7341 priv->config & CFG_ADHOC_CREATE &&
4841 priv->config & CFG_STATIC_ESSID && 7342 priv->config & CFG_STATIC_ESSID &&
7343 priv->config & CFG_STATIC_CHANNEL &&
4842 !list_empty(&priv->ieee->network_free_list)) { 7344 !list_empty(&priv->ieee->network_free_list)) {
4843 element = priv->ieee->network_free_list.next; 7345 element = priv->ieee->network_free_list.next;
4844 network = list_entry(element, struct ieee80211_network, list); 7346 network = list_entry(element, struct ieee80211_network, list);
@@ -4847,25 +7349,83 @@ static void ipw_associate(void *data)
4847 list_del(element); 7349 list_del(element);
4848 list_add_tail(&network->list, &priv->ieee->network_list); 7350 list_add_tail(&network->list, &priv->ieee->network_list);
4849 } 7351 }
7352 spin_unlock_irqrestore(&priv->ieee->lock, flags);
4850 7353
4851 /* If we reached the end of the list, then we don't have any valid 7354 /* If we reached the end of the list, then we don't have any valid
4852 * matching APs */ 7355 * matching APs */
4853 if (!network) { 7356 if (!network) {
4854 ipw_debug_config(priv); 7357 ipw_debug_config(priv);
4855 7358
4856 queue_delayed_work(priv->workqueue, &priv->request_scan, 7359 if (!(priv->status & STATUS_SCANNING)) {
4857 SCAN_INTERVAL); 7360 if (!(priv->config & CFG_SPEED_SCAN))
7361 queue_delayed_work(priv->workqueue,
7362 &priv->request_scan,
7363 SCAN_INTERVAL);
7364 else
7365 queue_work(priv->workqueue,
7366 &priv->request_scan);
7367 }
4858 7368
4859 return; 7369 return 0;
4860 } 7370 }
4861 7371
4862 ipw_associate_network(priv, network, rates, 0); 7372 ipw_associate_network(priv, network, rates, 0);
7373
7374 return 1;
4863} 7375}
4864 7376
4865static inline void ipw_handle_data_packet(struct ipw_priv *priv, 7377static void ipw_bg_associate(void *data)
4866 struct ipw_rx_mem_buffer *rxb,
4867 struct ieee80211_rx_stats *stats)
4868{ 7378{
7379 struct ipw_priv *priv = data;
7380 down(&priv->sem);
7381 ipw_associate(data);
7382 up(&priv->sem);
7383}
7384
7385static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7386 struct sk_buff *skb)
7387{
7388 struct ieee80211_hdr *hdr;
7389 u16 fc;
7390
7391 hdr = (struct ieee80211_hdr *)skb->data;
7392 fc = le16_to_cpu(hdr->frame_ctl);
7393 if (!(fc & IEEE80211_FCTL_PROTECTED))
7394 return;
7395
7396 fc &= ~IEEE80211_FCTL_PROTECTED;
7397 hdr->frame_ctl = cpu_to_le16(fc);
7398 switch (priv->ieee->sec.level) {
7399 case SEC_LEVEL_3:
7400 /* Remove CCMP HDR */
7401 memmove(skb->data + IEEE80211_3ADDR_LEN,
7402 skb->data + IEEE80211_3ADDR_LEN + 8,
7403 skb->len - IEEE80211_3ADDR_LEN - 8);
7404 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
7405 break;
7406 case SEC_LEVEL_2:
7407 break;
7408 case SEC_LEVEL_1:
7409 /* Remove IV */
7410 memmove(skb->data + IEEE80211_3ADDR_LEN,
7411 skb->data + IEEE80211_3ADDR_LEN + 4,
7412 skb->len - IEEE80211_3ADDR_LEN - 4);
7413 skb_trim(skb, skb->len - 8); /* IV + ICV */
7414 break;
7415 case SEC_LEVEL_0:
7416 break;
7417 default:
7418 printk(KERN_ERR "Unknow security level %d\n",
7419 priv->ieee->sec.level);
7420 break;
7421 }
7422}
7423
7424static void ipw_handle_data_packet(struct ipw_priv *priv,
7425 struct ipw_rx_mem_buffer *rxb,
7426 struct ieee80211_rx_stats *stats)
7427{
7428 struct ieee80211_hdr_4addr *hdr;
4869 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data; 7429 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
4870 7430
4871 /* We received data from the HW, so stop the watchdog */ 7431 /* We received data from the HW, so stop the watchdog */
@@ -4873,7 +7433,7 @@ static inline void ipw_handle_data_packet(struct ipw_priv *priv,
4873 7433
4874 /* We only process data packets if the 7434 /* We only process data packets if the
4875 * interface is open */ 7435 * interface is open */
4876 if (unlikely((pkt->u.frame.length + IPW_RX_FRAME_SIZE) > 7436 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
4877 skb_tailroom(rxb->skb))) { 7437 skb_tailroom(rxb->skb))) {
4878 priv->ieee->stats.rx_errors++; 7438 priv->ieee->stats.rx_errors++;
4879 priv->wstats.discard.misc++; 7439 priv->wstats.discard.misc++;
@@ -4890,14 +7450,351 @@ static inline void ipw_handle_data_packet(struct ipw_priv *priv,
4890 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data)); 7450 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
4891 7451
4892 /* Set the size of the skb to the size of the frame */ 7452 /* Set the size of the skb to the size of the frame */
4893 skb_put(rxb->skb, pkt->u.frame.length); 7453 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
4894 7454
4895 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len); 7455 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
4896 7456
7457 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
7458 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7459 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
7460 ((is_multicast_ether_addr(hdr->addr1) ||
7461 is_broadcast_ether_addr(hdr->addr1)) ?
7462 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
7463 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7464
4897 if (!ieee80211_rx(priv->ieee, rxb->skb, stats)) 7465 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
4898 priv->ieee->stats.rx_errors++; 7466 priv->ieee->stats.rx_errors++;
4899 else /* ieee80211_rx succeeded, so it now owns the SKB */ 7467 else { /* ieee80211_rx succeeded, so it now owns the SKB */
4900 rxb->skb = NULL; 7468 rxb->skb = NULL;
7469 __ipw_led_activity_on(priv);
7470 }
7471}
7472
7473#ifdef CONFIG_IEEE80211_RADIOTAP
7474static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7475 struct ipw_rx_mem_buffer *rxb,
7476 struct ieee80211_rx_stats *stats)
7477{
7478 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7479 struct ipw_rx_frame *frame = &pkt->u.frame;
7480
7481 /* initial pull of some data */
7482 u16 received_channel = frame->received_channel;
7483 u8 antennaAndPhy = frame->antennaAndPhy;
7484 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7485 u16 pktrate = frame->rate;
7486
7487 /* Magic struct that slots into the radiotap header -- no reason
7488 * to build this manually element by element, we can write it much
7489 * more efficiently than we can parse it. ORDER MATTERS HERE */
7490 struct ipw_rt_hdr {
7491 struct ieee80211_radiotap_header rt_hdr;
7492 u8 rt_flags; /* radiotap packet flags */
7493 u8 rt_rate; /* rate in 500kb/s */
7494 u16 rt_channel; /* channel in mhz */
7495 u16 rt_chbitmask; /* channel bitfield */
7496 s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
7497 u8 rt_antenna; /* antenna number */
7498 } *ipw_rt;
7499
7500 short len = le16_to_cpu(pkt->u.frame.length);
7501
7502 /* We received data from the HW, so stop the watchdog */
7503 priv->net_dev->trans_start = jiffies;
7504
7505 /* We only process data packets if the
7506 * interface is open */
7507 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7508 skb_tailroom(rxb->skb))) {
7509 priv->ieee->stats.rx_errors++;
7510 priv->wstats.discard.misc++;
7511 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7512 return;
7513 } else if (unlikely(!netif_running(priv->net_dev))) {
7514 priv->ieee->stats.rx_dropped++;
7515 priv->wstats.discard.misc++;
7516 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7517 return;
7518 }
7519
7520 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7521 * that now */
7522 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7523 /* FIXME: Should alloc bigger skb instead */
7524 priv->ieee->stats.rx_dropped++;
7525 priv->wstats.discard.misc++;
7526 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7527 return;
7528 }
7529
7530 /* copy the frame itself */
7531 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7532 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7533
7534 /* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7535 * part of our real header, saves a little time.
7536 *
7537 * No longer necessary since we fill in all our data. Purge before merging
7538 * patch officially.
7539 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7540 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7541 */
7542
7543 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7544
7545 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7546 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7547 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7548
7549 /* Big bitfield of all the fields we provide in radiotap */
7550 ipw_rt->rt_hdr.it_present =
7551 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7552 (1 << IEEE80211_RADIOTAP_RATE) |
7553 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7554 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7555 (1 << IEEE80211_RADIOTAP_ANTENNA));
7556
7557 /* Zero the flags, we'll add to them as we go */
7558 ipw_rt->rt_flags = 0;
7559
7560 /* Convert signal to DBM */
7561 ipw_rt->rt_dbmsignal = antsignal;
7562
7563 /* Convert the channel data and set the flags */
7564 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7565 if (received_channel > 14) { /* 802.11a */
7566 ipw_rt->rt_chbitmask =
7567 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7568 } else if (antennaAndPhy & 32) { /* 802.11b */
7569 ipw_rt->rt_chbitmask =
7570 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7571 } else { /* 802.11g */
7572 ipw_rt->rt_chbitmask =
7573 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7574 }
7575
7576 /* set the rate in multiples of 500k/s */
7577 switch (pktrate) {
7578 case IPW_TX_RATE_1MB:
7579 ipw_rt->rt_rate = 2;
7580 break;
7581 case IPW_TX_RATE_2MB:
7582 ipw_rt->rt_rate = 4;
7583 break;
7584 case IPW_TX_RATE_5MB:
7585 ipw_rt->rt_rate = 10;
7586 break;
7587 case IPW_TX_RATE_6MB:
7588 ipw_rt->rt_rate = 12;
7589 break;
7590 case IPW_TX_RATE_9MB:
7591 ipw_rt->rt_rate = 18;
7592 break;
7593 case IPW_TX_RATE_11MB:
7594 ipw_rt->rt_rate = 22;
7595 break;
7596 case IPW_TX_RATE_12MB:
7597 ipw_rt->rt_rate = 24;
7598 break;
7599 case IPW_TX_RATE_18MB:
7600 ipw_rt->rt_rate = 36;
7601 break;
7602 case IPW_TX_RATE_24MB:
7603 ipw_rt->rt_rate = 48;
7604 break;
7605 case IPW_TX_RATE_36MB:
7606 ipw_rt->rt_rate = 72;
7607 break;
7608 case IPW_TX_RATE_48MB:
7609 ipw_rt->rt_rate = 96;
7610 break;
7611 case IPW_TX_RATE_54MB:
7612 ipw_rt->rt_rate = 108;
7613 break;
7614 default:
7615 ipw_rt->rt_rate = 0;
7616 break;
7617 }
7618
7619 /* antenna number */
7620 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7621
7622 /* set the preamble flag if we have it */
7623 if ((antennaAndPhy & 64))
7624 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7625
7626 /* Set the size of the skb to the size of the frame */
7627 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
7628
7629 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7630
7631 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7632 priv->ieee->stats.rx_errors++;
7633 else { /* ieee80211_rx succeeded, so it now owns the SKB */
7634 rxb->skb = NULL;
7635 /* no LED during capture */
7636 }
7637}
7638#endif
7639
7640static inline int is_network_packet(struct ipw_priv *priv,
7641 struct ieee80211_hdr_4addr *header)
7642{
7643 /* Filter incoming packets to determine if they are targetted toward
7644 * this network, discarding packets coming from ourselves */
7645 switch (priv->ieee->iw_mode) {
7646 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
7647 /* packets from our adapter are dropped (echo) */
7648 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7649 return 0;
7650
7651 /* {broad,multi}cast packets to our BSSID go through */
7652 if (is_multicast_ether_addr(header->addr1) ||
7653 is_broadcast_ether_addr(header->addr1))
7654 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
7655
7656 /* packets to our adapter go through */
7657 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7658 ETH_ALEN);
7659
7660 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
7661 /* packets from our adapter are dropped (echo) */
7662 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7663 return 0;
7664
7665 /* {broad,multi}cast packets to our BSS go through */
7666 if (is_multicast_ether_addr(header->addr1) ||
7667 is_broadcast_ether_addr(header->addr1))
7668 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7669
7670 /* packets to our adapter go through */
7671 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7672 ETH_ALEN);
7673 }
7674
7675 return 1;
7676}
7677
7678#define IPW_PACKET_RETRY_TIME HZ
7679
7680static inline int is_duplicate_packet(struct ipw_priv *priv,
7681 struct ieee80211_hdr_4addr *header)
7682{
7683 u16 sc = le16_to_cpu(header->seq_ctl);
7684 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7685 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7686 u16 *last_seq, *last_frag;
7687 unsigned long *last_time;
7688
7689 switch (priv->ieee->iw_mode) {
7690 case IW_MODE_ADHOC:
7691 {
7692 struct list_head *p;
7693 struct ipw_ibss_seq *entry = NULL;
7694 u8 *mac = header->addr2;
7695 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
7696
7697 __list_for_each(p, &priv->ibss_mac_hash[index]) {
7698 entry =
7699 list_entry(p, struct ipw_ibss_seq, list);
7700 if (!memcmp(entry->mac, mac, ETH_ALEN))
7701 break;
7702 }
7703 if (p == &priv->ibss_mac_hash[index]) {
7704 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
7705 if (!entry) {
7706 IPW_ERROR
7707 ("Cannot malloc new mac entry\n");
7708 return 0;
7709 }
7710 memcpy(entry->mac, mac, ETH_ALEN);
7711 entry->seq_num = seq;
7712 entry->frag_num = frag;
7713 entry->packet_time = jiffies;
7714 list_add(&entry->list,
7715 &priv->ibss_mac_hash[index]);
7716 return 0;
7717 }
7718 last_seq = &entry->seq_num;
7719 last_frag = &entry->frag_num;
7720 last_time = &entry->packet_time;
7721 break;
7722 }
7723 case IW_MODE_INFRA:
7724 last_seq = &priv->last_seq_num;
7725 last_frag = &priv->last_frag_num;
7726 last_time = &priv->last_packet_time;
7727 break;
7728 default:
7729 return 0;
7730 }
7731 if ((*last_seq == seq) &&
7732 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
7733 if (*last_frag == frag)
7734 goto drop;
7735 if (*last_frag + 1 != frag)
7736 /* out-of-order fragment */
7737 goto drop;
7738 } else
7739 *last_seq = seq;
7740
7741 *last_frag = frag;
7742 *last_time = jiffies;
7743 return 0;
7744
7745 drop:
7746 /* Comment this line now since we observed the card receives
7747 * duplicate packets but the FCTL_RETRY bit is not set in the
7748 * IBSS mode with fragmentation enabled.
7749 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
7750 return 1;
7751}
7752
7753static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
7754 struct ipw_rx_mem_buffer *rxb,
7755 struct ieee80211_rx_stats *stats)
7756{
7757 struct sk_buff *skb = rxb->skb;
7758 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
7759 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
7760 (skb->data + IPW_RX_FRAME_SIZE);
7761
7762 ieee80211_rx_mgt(priv->ieee, header, stats);
7763
7764 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
7765 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7766 IEEE80211_STYPE_PROBE_RESP) ||
7767 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7768 IEEE80211_STYPE_BEACON))) {
7769 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
7770 ipw_add_station(priv, header->addr2);
7771 }
7772
7773 if (priv->config & CFG_NET_STATS) {
7774 IPW_DEBUG_HC("sending stat packet\n");
7775
7776 /* Set the size of the skb to the size of the full
7777 * ipw header and 802.11 frame */
7778 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
7779 IPW_RX_FRAME_SIZE);
7780
7781 /* Advance past the ipw packet header to the 802.11 frame */
7782 skb_pull(skb, IPW_RX_FRAME_SIZE);
7783
7784 /* Push the ieee80211_rx_stats before the 802.11 frame */
7785 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
7786
7787 skb->dev = priv->ieee->dev;
7788
7789 /* Point raw at the ieee80211_stats */
7790 skb->mac.raw = skb->data;
7791
7792 skb->pkt_type = PACKET_OTHERHOST;
7793 skb->protocol = __constant_htons(ETH_P_80211_STATS);
7794 memset(skb->cb, 0, sizeof(rxb->skb->cb));
7795 netif_rx(skb);
7796 rxb->skb = NULL;
7797 }
4901} 7798}
4902 7799
4903/* 7800/*
@@ -4913,8 +7810,8 @@ static void ipw_rx(struct ipw_priv *priv)
4913 u32 r, w, i; 7810 u32 r, w, i;
4914 u8 network_packet; 7811 u8 network_packet;
4915 7812
4916 r = ipw_read32(priv, CX2_RX_READ_INDEX); 7813 r = ipw_read32(priv, IPW_RX_READ_INDEX);
4917 w = ipw_read32(priv, CX2_RX_WRITE_INDEX); 7814 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
4918 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE; 7815 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
4919 7816
4920 while (i != r) { 7817 while (i != r) {
@@ -4928,7 +7825,7 @@ static void ipw_rx(struct ipw_priv *priv)
4928 priv->rxq->queue[i] = NULL; 7825 priv->rxq->queue[i] = NULL;
4929 7826
4930 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, 7827 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
4931 CX2_RX_BUF_SIZE, 7828 IPW_RX_BUF_SIZE,
4932 PCI_DMA_FROMDEVICE); 7829 PCI_DMA_FROMDEVICE);
4933 7830
4934 pkt = (struct ipw_rx_packet *)rxb->skb->data; 7831 pkt = (struct ipw_rx_packet *)rxb->skb->data;
@@ -4939,9 +7836,13 @@ static void ipw_rx(struct ipw_priv *priv)
4939 switch (pkt->header.message_type) { 7836 switch (pkt->header.message_type) {
4940 case RX_FRAME_TYPE: /* 802.11 frame */ { 7837 case RX_FRAME_TYPE: /* 802.11 frame */ {
4941 struct ieee80211_rx_stats stats = { 7838 struct ieee80211_rx_stats stats = {
4942 .rssi = pkt->u.frame.rssi_dbm - 7839 .rssi =
7840 le16_to_cpu(pkt->u.frame.rssi_dbm) -
4943 IPW_RSSI_TO_DBM, 7841 IPW_RSSI_TO_DBM,
4944 .signal = pkt->u.frame.signal, 7842 .signal =
7843 le16_to_cpu(pkt->u.frame.signal),
7844 .noise =
7845 le16_to_cpu(pkt->u.frame.noise),
4945 .rate = pkt->u.frame.rate, 7846 .rate = pkt->u.frame.rate,
4946 .mac_time = jiffies, 7847 .mac_time = jiffies,
4947 .received_channel = 7848 .received_channel =
@@ -4951,22 +7852,30 @@ static void ipw_rx(struct ipw_priv *priv)
4951 control & (1 << 0)) ? 7852 control & (1 << 0)) ?
4952 IEEE80211_24GHZ_BAND : 7853 IEEE80211_24GHZ_BAND :
4953 IEEE80211_52GHZ_BAND, 7854 IEEE80211_52GHZ_BAND,
4954 .len = pkt->u.frame.length, 7855 .len = le16_to_cpu(pkt->u.frame.length),
4955 }; 7856 };
4956 7857
4957 if (stats.rssi != 0) 7858 if (stats.rssi != 0)
4958 stats.mask |= IEEE80211_STATMASK_RSSI; 7859 stats.mask |= IEEE80211_STATMASK_RSSI;
4959 if (stats.signal != 0) 7860 if (stats.signal != 0)
4960 stats.mask |= IEEE80211_STATMASK_SIGNAL; 7861 stats.mask |= IEEE80211_STATMASK_SIGNAL;
7862 if (stats.noise != 0)
7863 stats.mask |= IEEE80211_STATMASK_NOISE;
4961 if (stats.rate != 0) 7864 if (stats.rate != 0)
4962 stats.mask |= IEEE80211_STATMASK_RATE; 7865 stats.mask |= IEEE80211_STATMASK_RATE;
4963 7866
4964 priv->rx_packets++; 7867 priv->rx_packets++;
4965 7868
4966#ifdef CONFIG_IPW_PROMISC 7869#ifdef CONFIG_IPW2200_MONITOR
4967 if (priv->ieee->iw_mode == IW_MODE_MONITOR) { 7870 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7871#ifdef CONFIG_IEEE80211_RADIOTAP
7872 ipw_handle_data_packet_monitor(priv,
7873 rxb,
7874 &stats);
7875#else
4968 ipw_handle_data_packet(priv, rxb, 7876 ipw_handle_data_packet(priv, rxb,
4969 &stats); 7877 &stats);
7878#endif
4970 break; 7879 break;
4971 } 7880 }
4972#endif 7881#endif
@@ -4980,35 +7889,9 @@ static void ipw_rx(struct ipw_priv *priv)
4980 * correctly -- we should probably use the 7889 * correctly -- we should probably use the
4981 * frame control of the packet and disregard 7890 * frame control of the packet and disregard
4982 * the current iw_mode */ 7891 * the current iw_mode */
4983 switch (priv->ieee->iw_mode) {
4984 case IW_MODE_ADHOC:
4985 network_packet =
4986 !memcmp(header->addr1,
4987 priv->net_dev->dev_addr,
4988 ETH_ALEN) ||
4989 !memcmp(header->addr3,
4990 priv->bssid, ETH_ALEN) ||
4991 is_broadcast_ether_addr(header->
4992 addr1)
4993 || is_multicast_ether_addr(header->
4994 addr1);
4995 break;
4996
4997 case IW_MODE_INFRA:
4998 default:
4999 network_packet =
5000 !memcmp(header->addr3,
5001 priv->bssid, ETH_ALEN) ||
5002 !memcmp(header->addr1,
5003 priv->net_dev->dev_addr,
5004 ETH_ALEN) ||
5005 is_broadcast_ether_addr(header->
5006 addr1)
5007 || is_multicast_ether_addr(header->
5008 addr1);
5009 break;
5010 }
5011 7892
7893 network_packet =
7894 is_network_packet(priv, header);
5012 if (network_packet && priv->assoc_network) { 7895 if (network_packet && priv->assoc_network) {
5013 priv->assoc_network->stats.rssi = 7896 priv->assoc_network->stats.rssi =
5014 stats.rssi; 7897 stats.rssi;
@@ -5018,9 +7901,10 @@ static void ipw_rx(struct ipw_priv *priv)
5018 } 7901 }
5019 7902
5020 IPW_DEBUG_RX("Frame: len=%u\n", 7903 IPW_DEBUG_RX("Frame: len=%u\n",
5021 pkt->u.frame.length); 7904 le16_to_cpu(pkt->u.frame.length));
5022 7905
5023 if (pkt->u.frame.length < frame_hdr_len(header)) { 7906 if (le16_to_cpu(pkt->u.frame.length) <
7907 frame_hdr_len(header)) {
5024 IPW_DEBUG_DROP 7908 IPW_DEBUG_DROP
5025 ("Received packet is too small. " 7909 ("Received packet is too small. "
5026 "Dropping.\n"); 7910 "Dropping.\n");
@@ -5029,34 +7913,22 @@ static void ipw_rx(struct ipw_priv *priv)
5029 break; 7913 break;
5030 } 7914 }
5031 7915
5032 switch (WLAN_FC_GET_TYPE(header->frame_ctl)) { 7916 switch (WLAN_FC_GET_TYPE
7917 (le16_to_cpu(header->frame_ctl))) {
7918
5033 case IEEE80211_FTYPE_MGMT: 7919 case IEEE80211_FTYPE_MGMT:
5034 ieee80211_rx_mgt(priv->ieee, header, 7920 ipw_handle_mgmt_packet(priv, rxb,
5035 &stats); 7921 &stats);
5036 if (priv->ieee->iw_mode == IW_MODE_ADHOC
5037 &&
5038 ((WLAN_FC_GET_STYPE
5039 (header->frame_ctl) ==
5040 IEEE80211_STYPE_PROBE_RESP)
5041 ||
5042 (WLAN_FC_GET_STYPE
5043 (header->frame_ctl) ==
5044 IEEE80211_STYPE_BEACON))
5045 && !memcmp(header->addr3,
5046 priv->bssid, ETH_ALEN))
5047 ipw_add_station(priv,
5048 header->addr2);
5049 break; 7922 break;
5050 7923
5051 case IEEE80211_FTYPE_CTL: 7924 case IEEE80211_FTYPE_CTL:
5052 break; 7925 break;
5053 7926
5054 case IEEE80211_FTYPE_DATA: 7927 case IEEE80211_FTYPE_DATA:
5055 if (network_packet) 7928 if (unlikely(!network_packet ||
5056 ipw_handle_data_packet(priv, 7929 is_duplicate_packet(priv,
5057 rxb, 7930 header)))
5058 &stats); 7931 {
5059 else
5060 IPW_DEBUG_DROP("Dropping: " 7932 IPW_DEBUG_DROP("Dropping: "
5061 MAC_FMT ", " 7933 MAC_FMT ", "
5062 MAC_FMT ", " 7934 MAC_FMT ", "
@@ -5067,6 +7939,12 @@ static void ipw_rx(struct ipw_priv *priv)
5067 addr2), 7939 addr2),
5068 MAC_ARG(header-> 7940 MAC_ARG(header->
5069 addr3)); 7941 addr3));
7942 break;
7943 }
7944
7945 ipw_handle_data_packet(priv, rxb,
7946 &stats);
7947
5070 break; 7948 break;
5071 } 7949 }
5072 break; 7950 break;
@@ -5097,7 +7975,7 @@ static void ipw_rx(struct ipw_priv *priv)
5097 } 7975 }
5098 7976
5099 pci_unmap_single(priv->pci_dev, rxb->dma_addr, 7977 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
5100 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); 7978 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
5101 list_add_tail(&rxb->list, &priv->rxq->rx_used); 7979 list_add_tail(&rxb->list, &priv->rxq->rx_used);
5102 7980
5103 i = (i + 1) % RX_QUEUE_SIZE; 7981 i = (i + 1) % RX_QUEUE_SIZE;
@@ -5109,128 +7987,129 @@ static void ipw_rx(struct ipw_priv *priv)
5109 ipw_rx_queue_restock(priv); 7987 ipw_rx_queue_restock(priv);
5110} 7988}
5111 7989
5112static void ipw_abort_scan(struct ipw_priv *priv) 7990#define DEFAULT_RTS_THRESHOLD 2304U
7991#define MIN_RTS_THRESHOLD 1U
7992#define MAX_RTS_THRESHOLD 2304U
7993#define DEFAULT_BEACON_INTERVAL 100U
7994#define DEFAULT_SHORT_RETRY_LIMIT 7U
7995#define DEFAULT_LONG_RETRY_LIMIT 4U
7996
7997static int ipw_sw_reset(struct ipw_priv *priv, int init)
5113{ 7998{
5114 int err; 7999 int band, modulation;
8000 int old_mode = priv->ieee->iw_mode;
5115 8001
5116 if (priv->status & STATUS_SCAN_ABORTING) { 8002 /* Initialize module parameter values here */
5117 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n"); 8003 priv->config = 0;
5118 return;
5119 }
5120 priv->status |= STATUS_SCAN_ABORTING;
5121 8004
5122 err = ipw_send_scan_abort(priv); 8005 /* We default to disabling the LED code as right now it causes
5123 if (err) 8006 * too many systems to lock up... */
5124 IPW_DEBUG_HC("Request to abort scan failed.\n"); 8007 if (!led)
5125} 8008 priv->config |= CFG_NO_LED;
5126 8009
5127static int ipw_request_scan(struct ipw_priv *priv) 8010 if (associate)
5128{ 8011 priv->config |= CFG_ASSOCIATE;
5129 struct ipw_scan_request_ext scan; 8012 else
5130 int channel_index = 0; 8013 IPW_DEBUG_INFO("Auto associate disabled.\n");
5131 int i, err, scan_type;
5132 8014
5133 if (priv->status & STATUS_EXIT_PENDING) { 8015 if (auto_create)
5134 IPW_DEBUG_SCAN("Aborting scan due to device shutdown\n"); 8016 priv->config |= CFG_ADHOC_CREATE;
5135 priv->status |= STATUS_SCAN_PENDING; 8017 else
5136 return 0; 8018 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
5137 }
5138 8019
5139 if (priv->status & STATUS_SCANNING) { 8020 if (disable) {
5140 IPW_DEBUG_HC("Concurrent scan requested. Aborting first.\n"); 8021 priv->status |= STATUS_RF_KILL_SW;
5141 priv->status |= STATUS_SCAN_PENDING; 8022 IPW_DEBUG_INFO("Radio disabled.\n");
5142 ipw_abort_scan(priv);
5143 return 0;
5144 } 8023 }
5145 8024
5146 if (priv->status & STATUS_SCAN_ABORTING) { 8025 if (channel != 0) {
5147 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n"); 8026 priv->config |= CFG_STATIC_CHANNEL;
5148 priv->status |= STATUS_SCAN_PENDING; 8027 priv->channel = channel;
5149 return 0; 8028 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8029 /* TODO: Validate that provided channel is in range */
5150 } 8030 }
8031#ifdef CONFIG_IPW_QOS
8032 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8033 burst_duration_CCK, burst_duration_OFDM);
8034#endif /* CONFIG_IPW_QOS */
5151 8035
5152 if (priv->status & STATUS_RF_KILL_MASK) { 8036 switch (mode) {
5153 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n"); 8037 case 1:
5154 priv->status |= STATUS_SCAN_PENDING; 8038 priv->ieee->iw_mode = IW_MODE_ADHOC;
5155 return 0; 8039 priv->net_dev->type = ARPHRD_ETHER;
8040
8041 break;
8042#ifdef CONFIG_IPW2200_MONITOR
8043 case 2:
8044 priv->ieee->iw_mode = IW_MODE_MONITOR;
8045#ifdef CONFIG_IEEE80211_RADIOTAP
8046 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8047#else
8048 priv->net_dev->type = ARPHRD_IEEE80211;
8049#endif
8050 break;
8051#endif
8052 default:
8053 case 0:
8054 priv->net_dev->type = ARPHRD_ETHER;
8055 priv->ieee->iw_mode = IW_MODE_INFRA;
8056 break;
5156 } 8057 }
5157 8058
5158 memset(&scan, 0, sizeof(scan)); 8059 if (hwcrypto) {
8060 priv->ieee->host_encrypt = 0;
8061 priv->ieee->host_encrypt_msdu = 0;
8062 priv->ieee->host_decrypt = 0;
8063 priv->ieee->host_mc_decrypt = 0;
8064 }
8065 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
5159 8066
5160 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = 20; 8067 /* IPW2200/2915 is abled to do hardware fragmentation. */
5161 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = 20; 8068 priv->ieee->host_open_frag = 0;
5162 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = 20;
5163
5164 scan.full_scan_index = ieee80211_get_scans(priv->ieee);
5165 /* If we are roaming, then make this a directed scan for the current
5166 * network. Otherwise, ensure that every other scan is a fast
5167 * channel hop scan */
5168 if ((priv->status & STATUS_ROAMING)
5169 || (!(priv->status & STATUS_ASSOCIATED)
5170 && (priv->config & CFG_STATIC_ESSID)
5171 && (scan.full_scan_index % 2))) {
5172 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
5173 if (err) {
5174 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
5175 return err;
5176 }
5177 8069
5178 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN; 8070 if ((priv->pci_dev->device == 0x4223) ||
8071 (priv->pci_dev->device == 0x4224)) {
8072 if (init)
8073 printk(KERN_INFO DRV_NAME
8074 ": Detected Intel PRO/Wireless 2915ABG Network "
8075 "Connection\n");
8076 priv->ieee->abg_true = 1;
8077 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8078 modulation = IEEE80211_OFDM_MODULATION |
8079 IEEE80211_CCK_MODULATION;
8080 priv->adapter = IPW_2915ABG;
8081 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
5179 } else { 8082 } else {
5180 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN; 8083 if (init)
5181 } 8084 printk(KERN_INFO DRV_NAME
5182 8085 ": Detected Intel PRO/Wireless 2200BG Network "
5183 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) { 8086 "Connection\n");
5184 int start = channel_index;
5185 for (i = 0; i < MAX_A_CHANNELS; i++) {
5186 if (band_a_active_channel[i] == 0)
5187 break;
5188 if ((priv->status & STATUS_ASSOCIATED) &&
5189 band_a_active_channel[i] == priv->channel)
5190 continue;
5191 channel_index++;
5192 scan.channels_list[channel_index] =
5193 band_a_active_channel[i];
5194 ipw_set_scan_type(&scan, channel_index, scan_type);
5195 }
5196 8087
5197 if (start != channel_index) { 8088 priv->ieee->abg_true = 0;
5198 scan.channels_list[start] = (u8) (IPW_A_MODE << 6) | 8089 band = IEEE80211_24GHZ_BAND;
5199 (channel_index - start); 8090 modulation = IEEE80211_OFDM_MODULATION |
5200 channel_index++; 8091 IEEE80211_CCK_MODULATION;
5201 } 8092 priv->adapter = IPW_2200BG;
8093 priv->ieee->mode = IEEE_G | IEEE_B;
5202 } 8094 }
5203 8095
5204 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) { 8096 priv->ieee->freq_band = band;
5205 int start = channel_index; 8097 priv->ieee->modulation = modulation;
5206 for (i = 0; i < MAX_B_CHANNELS; i++) {
5207 if (band_b_active_channel[i] == 0)
5208 break;
5209 if ((priv->status & STATUS_ASSOCIATED) &&
5210 band_b_active_channel[i] == priv->channel)
5211 continue;
5212 channel_index++;
5213 scan.channels_list[channel_index] =
5214 band_b_active_channel[i];
5215 ipw_set_scan_type(&scan, channel_index, scan_type);
5216 }
5217 8098
5218 if (start != channel_index) { 8099 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
5219 scan.channels_list[start] = (u8) (IPW_B_MODE << 6) |
5220 (channel_index - start);
5221 }
5222 }
5223 8100
5224 err = ipw_send_scan_request_ext(priv, &scan); 8101 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
5225 if (err) { 8102 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
5226 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
5227 return -EIO;
5228 }
5229 8103
5230 priv->status |= STATUS_SCANNING; 8104 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
5231 priv->status &= ~STATUS_SCAN_PENDING; 8105 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8106 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
5232 8107
5233 return 0; 8108 /* If power management is turned on, default to AC mode */
8109 priv->power_mode = IPW_POWER_AC;
8110 priv->tx_power = IPW_TX_POWER_DEFAULT;
8111
8112 return old_mode == priv->ieee->iw_mode;
5234} 8113}
5235 8114
5236/* 8115/*
@@ -5248,12 +8127,16 @@ static int ipw_wx_get_name(struct net_device *dev,
5248 union iwreq_data *wrqu, char *extra) 8127 union iwreq_data *wrqu, char *extra)
5249{ 8128{
5250 struct ipw_priv *priv = ieee80211_priv(dev); 8129 struct ipw_priv *priv = ieee80211_priv(dev);
5251 if (!(priv->status & STATUS_ASSOCIATED)) 8130 down(&priv->sem);
8131 if (priv->status & STATUS_RF_KILL_MASK)
8132 strcpy(wrqu->name, "radio off");
8133 else if (!(priv->status & STATUS_ASSOCIATED))
5252 strcpy(wrqu->name, "unassociated"); 8134 strcpy(wrqu->name, "unassociated");
5253 else 8135 else
5254 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c", 8136 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
5255 ipw_modes[priv->assoc_request.ieee_mode]); 8137 ipw_modes[priv->assoc_request.ieee_mode]);
5256 IPW_DEBUG_WX("Name: %s\n", wrqu->name); 8138 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
8139 up(&priv->sem);
5257 return 0; 8140 return 0;
5258} 8141}
5259 8142
@@ -5262,13 +8145,9 @@ static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
5262 if (channel == 0) { 8145 if (channel == 0) {
5263 IPW_DEBUG_INFO("Setting channel to ANY (0)\n"); 8146 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
5264 priv->config &= ~CFG_STATIC_CHANNEL; 8147 priv->config &= ~CFG_STATIC_CHANNEL;
5265 if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED | 8148 IPW_DEBUG_ASSOC("Attempting to associate with new "
5266 STATUS_ASSOCIATING))) { 8149 "parameters.\n");
5267 IPW_DEBUG_ASSOC("Attempting to associate with new " 8150 ipw_associate(priv);
5268 "parameters.\n");
5269 ipw_associate(priv);
5270 }
5271
5272 return 0; 8151 return 0;
5273 } 8152 }
5274 8153
@@ -5283,14 +8162,32 @@ static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
5283 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel); 8162 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
5284 priv->channel = channel; 8163 priv->channel = channel;
5285 8164
5286 /* If we are currently associated, or trying to associate 8165#ifdef CONFIG_IPW2200_MONITOR
5287 * then see if this is a new channel (causing us to disassociate) */ 8166 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5288 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { 8167 int i;
5289 IPW_DEBUG_ASSOC("Disassociating due to channel change.\n"); 8168 if (priv->status & STATUS_SCANNING) {
5290 ipw_disassociate(priv); 8169 IPW_DEBUG_SCAN("Scan abort triggered due to "
5291 } else { 8170 "channel change.\n");
5292 ipw_associate(priv); 8171 ipw_abort_scan(priv);
8172 }
8173
8174 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8175 udelay(10);
8176
8177 if (priv->status & STATUS_SCANNING)
8178 IPW_DEBUG_SCAN("Still scanning...\n");
8179 else
8180 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8181 1000 - i);
8182
8183 return 0;
5293 } 8184 }
8185#endif /* CONFIG_IPW2200_MONITOR */
8186
8187 /* Network configuration changed -- force [re]association */
8188 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8189 if (!ipw_disassociate(priv))
8190 ipw_associate(priv);
5294 8191
5295 return 0; 8192 return 0;
5296} 8193}
@@ -5300,29 +8197,48 @@ static int ipw_wx_set_freq(struct net_device *dev,
5300 union iwreq_data *wrqu, char *extra) 8197 union iwreq_data *wrqu, char *extra)
5301{ 8198{
5302 struct ipw_priv *priv = ieee80211_priv(dev); 8199 struct ipw_priv *priv = ieee80211_priv(dev);
8200 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
5303 struct iw_freq *fwrq = &wrqu->freq; 8201 struct iw_freq *fwrq = &wrqu->freq;
5304 8202 int ret = 0, i;
8203 u8 channel, flags;
8204 int band;
8205
8206 if (fwrq->m == 0) {
8207 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
8208 down(&priv->sem);
8209 ret = ipw_set_channel(priv, 0);
8210 up(&priv->sem);
8211 return ret;
8212 }
5305 /* if setting by freq convert to channel */ 8213 /* if setting by freq convert to channel */
5306 if (fwrq->e == 1) { 8214 if (fwrq->e == 1) {
5307 if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) { 8215 channel = ipw_freq_to_channel(priv->ieee, fwrq->m);
5308 int f = fwrq->m / 100000; 8216 if (channel == 0)
5309 int c = 0; 8217 return -EINVAL;
8218 } else
8219 channel = fwrq->m;
8220
8221 if (!(band = ipw_is_valid_channel(priv->ieee, channel)))
8222 return -EINVAL;
5310 8223
5311 while ((c < REG_MAX_CHANNEL) && 8224 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5312 (f != ipw_frequencies[c])) 8225 i = ipw_channel_to_index(priv->ieee, channel);
5313 c++; 8226 if (i == -1)
8227 return -EINVAL;
5314 8228
5315 /* hack to fall through */ 8229 flags = (band == IEEE80211_24GHZ_BAND) ?
5316 fwrq->e = 0; 8230 geo->bg[i].flags : geo->a[i].flags;
5317 fwrq->m = c + 1; 8231 if (flags & IEEE80211_CH_PASSIVE_ONLY) {
8232 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8233 return -EINVAL;
5318 } 8234 }
5319 } 8235 }
5320 8236
5321 if (fwrq->e > 0 || fwrq->m > 1000)
5322 return -EOPNOTSUPP;
5323
5324 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m); 8237 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
5325 return ipw_set_channel(priv, (u8) fwrq->m); 8238 down(&priv->sem);
8239 ret = ipw_set_channel(priv, channel);
8240 up(&priv->sem);
8241 return ret;
5326} 8242}
5327 8243
5328static int ipw_wx_get_freq(struct net_device *dev, 8244static int ipw_wx_get_freq(struct net_device *dev,
@@ -5335,12 +8251,14 @@ static int ipw_wx_get_freq(struct net_device *dev,
5335 8251
5336 /* If we are associated, trying to associate, or have a statically 8252 /* If we are associated, trying to associate, or have a statically
5337 * configured CHANNEL then return that; otherwise return ANY */ 8253 * configured CHANNEL then return that; otherwise return ANY */
8254 down(&priv->sem);
5338 if (priv->config & CFG_STATIC_CHANNEL || 8255 if (priv->config & CFG_STATIC_CHANNEL ||
5339 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) 8256 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
5340 wrqu->freq.m = priv->channel; 8257 wrqu->freq.m = priv->channel;
5341 else 8258 else
5342 wrqu->freq.m = 0; 8259 wrqu->freq.m = 0;
5343 8260
8261 up(&priv->sem);
5344 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel); 8262 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
5345 return 0; 8263 return 0;
5346} 8264}
@@ -5354,11 +8272,8 @@ static int ipw_wx_set_mode(struct net_device *dev,
5354 8272
5355 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode); 8273 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
5356 8274
5357 if (wrqu->mode == priv->ieee->iw_mode)
5358 return 0;
5359
5360 switch (wrqu->mode) { 8275 switch (wrqu->mode) {
5361#ifdef CONFIG_IPW_PROMISC 8276#ifdef CONFIG_IPW2200_MONITOR
5362 case IW_MODE_MONITOR: 8277 case IW_MODE_MONITOR:
5363#endif 8278#endif
5364 case IW_MODE_ADHOC: 8279 case IW_MODE_ADHOC:
@@ -5370,31 +8285,33 @@ static int ipw_wx_set_mode(struct net_device *dev,
5370 default: 8285 default:
5371 return -EINVAL; 8286 return -EINVAL;
5372 } 8287 }
8288 if (wrqu->mode == priv->ieee->iw_mode)
8289 return 0;
8290
8291 down(&priv->sem);
8292
8293 ipw_sw_reset(priv, 0);
5373 8294
5374#ifdef CONFIG_IPW_PROMISC 8295#ifdef CONFIG_IPW2200_MONITOR
5375 if (priv->ieee->iw_mode == IW_MODE_MONITOR) 8296 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
5376 priv->net_dev->type = ARPHRD_ETHER; 8297 priv->net_dev->type = ARPHRD_ETHER;
5377 8298
5378 if (wrqu->mode == IW_MODE_MONITOR) 8299 if (wrqu->mode == IW_MODE_MONITOR)
8300#ifdef CONFIG_IEEE80211_RADIOTAP
8301 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8302#else
5379 priv->net_dev->type = ARPHRD_IEEE80211; 8303 priv->net_dev->type = ARPHRD_IEEE80211;
5380#endif /* CONFIG_IPW_PROMISC */ 8304#endif
8305#endif /* CONFIG_IPW2200_MONITOR */
5381 8306
5382#ifdef CONFIG_PM
5383 /* Free the existing firmware and reset the fw_loaded 8307 /* Free the existing firmware and reset the fw_loaded
5384 * flag so ipw_load() will bring in the new firmawre */ 8308 * flag so ipw_load() will bring in the new firmawre */
5385 if (fw_loaded) { 8309 free_firmware();
5386 fw_loaded = 0;
5387 }
5388
5389 release_firmware(bootfw);
5390 release_firmware(ucode);
5391 release_firmware(firmware);
5392 bootfw = ucode = firmware = NULL;
5393#endif
5394 8310
5395 priv->ieee->iw_mode = wrqu->mode; 8311 priv->ieee->iw_mode = wrqu->mode;
5396 ipw_adapter_restart(priv);
5397 8312
8313 queue_work(priv->workqueue, &priv->adapter_restart);
8314 up(&priv->sem);
5398 return err; 8315 return err;
5399} 8316}
5400 8317
@@ -5403,20 +8320,13 @@ static int ipw_wx_get_mode(struct net_device *dev,
5403 union iwreq_data *wrqu, char *extra) 8320 union iwreq_data *wrqu, char *extra)
5404{ 8321{
5405 struct ipw_priv *priv = ieee80211_priv(dev); 8322 struct ipw_priv *priv = ieee80211_priv(dev);
5406 8323 down(&priv->sem);
5407 wrqu->mode = priv->ieee->iw_mode; 8324 wrqu->mode = priv->ieee->iw_mode;
5408 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode); 8325 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
5409 8326 up(&priv->sem);
5410 return 0; 8327 return 0;
5411} 8328}
5412 8329
5413#define DEFAULT_RTS_THRESHOLD 2304U
5414#define MIN_RTS_THRESHOLD 1U
5415#define MAX_RTS_THRESHOLD 2304U
5416#define DEFAULT_BEACON_INTERVAL 100U
5417#define DEFAULT_SHORT_RETRY_LIMIT 7U
5418#define DEFAULT_LONG_RETRY_LIMIT 4U
5419
5420/* Values are in microsecond */ 8330/* Values are in microsecond */
5421static const s32 timeout_duration[] = { 8331static const s32 timeout_duration[] = {
5422 350000, 8332 350000,
@@ -5440,8 +8350,8 @@ static int ipw_wx_get_range(struct net_device *dev,
5440{ 8350{
5441 struct ipw_priv *priv = ieee80211_priv(dev); 8351 struct ipw_priv *priv = ieee80211_priv(dev);
5442 struct iw_range *range = (struct iw_range *)extra; 8352 struct iw_range *range = (struct iw_range *)extra;
5443 u16 val; 8353 const struct ieee80211_geo *geo = ipw_get_geo(priv->ieee);
5444 int i; 8354 int i = 0, j;
5445 8355
5446 wrqu->data.length = sizeof(*range); 8356 wrqu->data.length = sizeof(*range);
5447 memset(range, 0, sizeof(*range)); 8357 memset(range, 0, sizeof(*range));
@@ -5452,7 +8362,7 @@ static int ipw_wx_get_range(struct net_device *dev,
5452 range->max_qual.qual = 100; 8362 range->max_qual.qual = 100;
5453 /* TODO: Find real max RSSI and stick here */ 8363 /* TODO: Find real max RSSI and stick here */
5454 range->max_qual.level = 0; 8364 range->max_qual.level = 0;
5455 range->max_qual.noise = 0; 8365 range->max_qual.noise = priv->ieee->worst_rssi + 0x100;
5456 range->max_qual.updated = 7; /* Updated all three */ 8366 range->max_qual.updated = 7; /* Updated all three */
5457 8367
5458 range->avg_qual.qual = 70; 8368 range->avg_qual.qual = 70;
@@ -5460,7 +8370,7 @@ static int ipw_wx_get_range(struct net_device *dev,
5460 range->avg_qual.level = 0; /* FIXME to real average level */ 8370 range->avg_qual.level = 0; /* FIXME to real average level */
5461 range->avg_qual.noise = 0; 8371 range->avg_qual.noise = 0;
5462 range->avg_qual.updated = 7; /* Updated all three */ 8372 range->avg_qual.updated = 7; /* Updated all three */
5463 8373 down(&priv->sem);
5464 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES); 8374 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
5465 8375
5466 for (i = 0; i < range->num_bitrates; i++) 8376 for (i = 0; i < range->num_bitrates; i++)
@@ -5480,19 +8390,35 @@ static int ipw_wx_get_range(struct net_device *dev,
5480 range->we_version_compiled = WIRELESS_EXT; 8390 range->we_version_compiled = WIRELESS_EXT;
5481 range->we_version_source = 16; 8391 range->we_version_source = 16;
5482 8392
5483 range->num_channels = FREQ_COUNT; 8393 i = 0;
5484 8394 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
5485 val = 0; 8395 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES;
5486 for (i = 0; i < FREQ_COUNT; i++) { 8396 i++, j++) {
5487 range->freq[val].i = i + 1; 8397 range->freq[i].i = geo->bg[j].channel;
5488 range->freq[val].m = ipw_frequencies[i] * 100000; 8398 range->freq[i].m = geo->bg[j].freq * 100000;
5489 range->freq[val].e = 1; 8399 range->freq[i].e = 1;
5490 val++; 8400 }
8401 }
5491 8402
5492 if (val == IW_MAX_FREQUENCIES) 8403 if (priv->ieee->mode & IEEE_A) {
5493 break; 8404 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES;
8405 i++, j++) {
8406 range->freq[i].i = geo->a[j].channel;
8407 range->freq[i].m = geo->a[j].freq * 100000;
8408 range->freq[i].e = 1;
8409 }
5494 } 8410 }
5495 range->num_frequency = val; 8411
8412 range->num_channels = i;
8413 range->num_frequency = i;
8414
8415 up(&priv->sem);
8416
8417 /* Event capability (kernel + driver) */
8418 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8419 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
8420 IW_EVENT_CAPA_MASK(SIOCGIWAP));
8421 range->event_capa[1] = IW_EVENT_CAPA_K_1;
5496 8422
5497 IPW_DEBUG_WX("GET Range\n"); 8423 IPW_DEBUG_WX("GET Range\n");
5498 return 0; 8424 return 0;
@@ -5513,25 +8439,23 @@ static int ipw_wx_set_wap(struct net_device *dev,
5513 8439
5514 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER) 8440 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
5515 return -EINVAL; 8441 return -EINVAL;
5516 8442 down(&priv->sem);
5517 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) || 8443 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
5518 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) { 8444 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
5519 /* we disable mandatory BSSID association */ 8445 /* we disable mandatory BSSID association */
5520 IPW_DEBUG_WX("Setting AP BSSID to ANY\n"); 8446 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
5521 priv->config &= ~CFG_STATIC_BSSID; 8447 priv->config &= ~CFG_STATIC_BSSID;
5522 if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED | 8448 IPW_DEBUG_ASSOC("Attempting to associate with new "
5523 STATUS_ASSOCIATING))) { 8449 "parameters.\n");
5524 IPW_DEBUG_ASSOC("Attempting to associate with new " 8450 ipw_associate(priv);
5525 "parameters.\n"); 8451 up(&priv->sem);
5526 ipw_associate(priv);
5527 }
5528
5529 return 0; 8452 return 0;
5530 } 8453 }
5531 8454
5532 priv->config |= CFG_STATIC_BSSID; 8455 priv->config |= CFG_STATIC_BSSID;
5533 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) { 8456 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
5534 IPW_DEBUG_WX("BSSID set to current BSSID.\n"); 8457 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
8458 up(&priv->sem);
5535 return 0; 8459 return 0;
5536 } 8460 }
5537 8461
@@ -5540,15 +8464,12 @@ static int ipw_wx_set_wap(struct net_device *dev,
5540 8464
5541 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN); 8465 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
5542 8466
5543 /* If we are currently associated, or trying to associate 8467 /* Network configuration changed -- force [re]association */
5544 * then see if this is a new BSSID (causing us to disassociate) */ 8468 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
5545 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { 8469 if (!ipw_disassociate(priv))
5546 IPW_DEBUG_ASSOC("Disassociating due to BSSID change.\n");
5547 ipw_disassociate(priv);
5548 } else {
5549 ipw_associate(priv); 8470 ipw_associate(priv);
5550 }
5551 8471
8472 up(&priv->sem);
5552 return 0; 8473 return 0;
5553} 8474}
5554 8475
@@ -5559,15 +8480,17 @@ static int ipw_wx_get_wap(struct net_device *dev,
5559 struct ipw_priv *priv = ieee80211_priv(dev); 8480 struct ipw_priv *priv = ieee80211_priv(dev);
5560 /* If we are associated, trying to associate, or have a statically 8481 /* If we are associated, trying to associate, or have a statically
5561 * configured BSSID then return that; otherwise return ANY */ 8482 * configured BSSID then return that; otherwise return ANY */
8483 down(&priv->sem);
5562 if (priv->config & CFG_STATIC_BSSID || 8484 if (priv->config & CFG_STATIC_BSSID ||
5563 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { 8485 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
5564 wrqu->ap_addr.sa_family = ARPHRD_ETHER; 8486 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
5565 memcpy(wrqu->ap_addr.sa_data, &priv->bssid, ETH_ALEN); 8487 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
5566 } else 8488 } else
5567 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); 8489 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
5568 8490
5569 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n", 8491 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
5570 MAC_ARG(wrqu->ap_addr.sa_data)); 8492 MAC_ARG(wrqu->ap_addr.sa_data));
8493 up(&priv->sem);
5571 return 0; 8494 return 0;
5572} 8495}
5573 8496
@@ -5578,21 +8501,22 @@ static int ipw_wx_set_essid(struct net_device *dev,
5578 struct ipw_priv *priv = ieee80211_priv(dev); 8501 struct ipw_priv *priv = ieee80211_priv(dev);
5579 char *essid = ""; /* ANY */ 8502 char *essid = ""; /* ANY */
5580 int length = 0; 8503 int length = 0;
5581 8504 down(&priv->sem);
5582 if (wrqu->essid.flags && wrqu->essid.length) { 8505 if (wrqu->essid.flags && wrqu->essid.length) {
5583 length = wrqu->essid.length - 1; 8506 length = wrqu->essid.length - 1;
5584 essid = extra; 8507 essid = extra;
5585 } 8508 }
5586 if (length == 0) { 8509 if (length == 0) {
5587 IPW_DEBUG_WX("Setting ESSID to ANY\n"); 8510 IPW_DEBUG_WX("Setting ESSID to ANY\n");
5588 priv->config &= ~CFG_STATIC_ESSID; 8511 if ((priv->config & CFG_STATIC_ESSID) &&
5589 if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED | 8512 !(priv->status & (STATUS_ASSOCIATED |
5590 STATUS_ASSOCIATING))) { 8513 STATUS_ASSOCIATING))) {
5591 IPW_DEBUG_ASSOC("Attempting to associate with new " 8514 IPW_DEBUG_ASSOC("Attempting to associate with new "
5592 "parameters.\n"); 8515 "parameters.\n");
8516 priv->config &= ~CFG_STATIC_ESSID;
5593 ipw_associate(priv); 8517 ipw_associate(priv);
5594 } 8518 }
5595 8519 up(&priv->sem);
5596 return 0; 8520 return 0;
5597 } 8521 }
5598 8522
@@ -5602,6 +8526,7 @@ static int ipw_wx_set_essid(struct net_device *dev,
5602 8526
5603 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) { 8527 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
5604 IPW_DEBUG_WX("ESSID set to current ESSID.\n"); 8528 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
8529 up(&priv->sem);
5605 return 0; 8530 return 0;
5606 } 8531 }
5607 8532
@@ -5611,15 +8536,12 @@ static int ipw_wx_set_essid(struct net_device *dev,
5611 priv->essid_len = length; 8536 priv->essid_len = length;
5612 memcpy(priv->essid, essid, priv->essid_len); 8537 memcpy(priv->essid, essid, priv->essid_len);
5613 8538
5614 /* If we are currently associated, or trying to associate 8539 /* Network configuration changed -- force [re]association */
5615 * then see if this is a new ESSID (causing us to disassociate) */ 8540 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
5616 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { 8541 if (!ipw_disassociate(priv))
5617 IPW_DEBUG_ASSOC("Disassociating due to ESSID change.\n");
5618 ipw_disassociate(priv);
5619 } else {
5620 ipw_associate(priv); 8542 ipw_associate(priv);
5621 }
5622 8543
8544 up(&priv->sem);
5623 return 0; 8545 return 0;
5624} 8546}
5625 8547
@@ -5631,6 +8553,7 @@ static int ipw_wx_get_essid(struct net_device *dev,
5631 8553
5632 /* If we are associated, trying to associate, or have a statically 8554 /* If we are associated, trying to associate, or have a statically
5633 * configured ESSID then return that; otherwise return ANY */ 8555 * configured ESSID then return that; otherwise return ANY */
8556 down(&priv->sem);
5634 if (priv->config & CFG_STATIC_ESSID || 8557 if (priv->config & CFG_STATIC_ESSID ||
5635 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) { 8558 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
5636 IPW_DEBUG_WX("Getting essid: '%s'\n", 8559 IPW_DEBUG_WX("Getting essid: '%s'\n",
@@ -5643,7 +8566,7 @@ static int ipw_wx_get_essid(struct net_device *dev,
5643 wrqu->essid.length = 0; 8566 wrqu->essid.length = 0;
5644 wrqu->essid.flags = 0; /* active */ 8567 wrqu->essid.flags = 0; /* active */
5645 } 8568 }
5646 8569 up(&priv->sem);
5647 return 0; 8570 return 0;
5648} 8571}
5649 8572
@@ -5656,11 +8579,12 @@ static int ipw_wx_set_nick(struct net_device *dev,
5656 IPW_DEBUG_WX("Setting nick to '%s'\n", extra); 8579 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
5657 if (wrqu->data.length > IW_ESSID_MAX_SIZE) 8580 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
5658 return -E2BIG; 8581 return -E2BIG;
5659 8582 down(&priv->sem);
5660 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick)); 8583 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
5661 memset(priv->nick, 0, sizeof(priv->nick)); 8584 memset(priv->nick, 0, sizeof(priv->nick));
5662 memcpy(priv->nick, extra, wrqu->data.length); 8585 memcpy(priv->nick, extra, wrqu->data.length);
5663 IPW_DEBUG_TRACE("<<\n"); 8586 IPW_DEBUG_TRACE("<<\n");
8587 up(&priv->sem);
5664 return 0; 8588 return 0;
5665 8589
5666} 8590}
@@ -5671,9 +8595,11 @@ static int ipw_wx_get_nick(struct net_device *dev,
5671{ 8595{
5672 struct ipw_priv *priv = ieee80211_priv(dev); 8596 struct ipw_priv *priv = ieee80211_priv(dev);
5673 IPW_DEBUG_WX("Getting nick\n"); 8597 IPW_DEBUG_WX("Getting nick\n");
8598 down(&priv->sem);
5674 wrqu->data.length = strlen(priv->nick) + 1; 8599 wrqu->data.length = strlen(priv->nick) + 1;
5675 memcpy(extra, priv->nick, wrqu->data.length); 8600 memcpy(extra, priv->nick, wrqu->data.length);
5676 wrqu->data.flags = 1; /* active */ 8601 wrqu->data.flags = 1; /* active */
8602 up(&priv->sem);
5677 return 0; 8603 return 0;
5678} 8604}
5679 8605
@@ -5681,8 +8607,113 @@ static int ipw_wx_set_rate(struct net_device *dev,
5681 struct iw_request_info *info, 8607 struct iw_request_info *info,
5682 union iwreq_data *wrqu, char *extra) 8608 union iwreq_data *wrqu, char *extra)
5683{ 8609{
5684 IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu); 8610 /* TODO: We should use semaphores or locks for access to priv */
5685 return -EOPNOTSUPP; 8611 struct ipw_priv *priv = ieee80211_priv(dev);
8612 u32 target_rate = wrqu->bitrate.value;
8613 u32 fixed, mask;
8614
8615 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8616 /* value = X, fixed = 1 means only rate X */
8617 /* value = X, fixed = 0 means all rates lower equal X */
8618
8619 if (target_rate == -1) {
8620 fixed = 0;
8621 mask = IEEE80211_DEFAULT_RATES_MASK;
8622 /* Now we should reassociate */
8623 goto apply;
8624 }
8625
8626 mask = 0;
8627 fixed = wrqu->bitrate.fixed;
8628
8629 if (target_rate == 1000000 || !fixed)
8630 mask |= IEEE80211_CCK_RATE_1MB_MASK;
8631 if (target_rate == 1000000)
8632 goto apply;
8633
8634 if (target_rate == 2000000 || !fixed)
8635 mask |= IEEE80211_CCK_RATE_2MB_MASK;
8636 if (target_rate == 2000000)
8637 goto apply;
8638
8639 if (target_rate == 5500000 || !fixed)
8640 mask |= IEEE80211_CCK_RATE_5MB_MASK;
8641 if (target_rate == 5500000)
8642 goto apply;
8643
8644 if (target_rate == 6000000 || !fixed)
8645 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
8646 if (target_rate == 6000000)
8647 goto apply;
8648
8649 if (target_rate == 9000000 || !fixed)
8650 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
8651 if (target_rate == 9000000)
8652 goto apply;
8653
8654 if (target_rate == 11000000 || !fixed)
8655 mask |= IEEE80211_CCK_RATE_11MB_MASK;
8656 if (target_rate == 11000000)
8657 goto apply;
8658
8659 if (target_rate == 12000000 || !fixed)
8660 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
8661 if (target_rate == 12000000)
8662 goto apply;
8663
8664 if (target_rate == 18000000 || !fixed)
8665 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
8666 if (target_rate == 18000000)
8667 goto apply;
8668
8669 if (target_rate == 24000000 || !fixed)
8670 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
8671 if (target_rate == 24000000)
8672 goto apply;
8673
8674 if (target_rate == 36000000 || !fixed)
8675 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
8676 if (target_rate == 36000000)
8677 goto apply;
8678
8679 if (target_rate == 48000000 || !fixed)
8680 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
8681 if (target_rate == 48000000)
8682 goto apply;
8683
8684 if (target_rate == 54000000 || !fixed)
8685 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
8686 if (target_rate == 54000000)
8687 goto apply;
8688
8689 IPW_DEBUG_WX("invalid rate specified, returning error\n");
8690 return -EINVAL;
8691
8692 apply:
8693 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
8694 mask, fixed ? "fixed" : "sub-rates");
8695 down(&priv->sem);
8696 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
8697 priv->config &= ~CFG_FIXED_RATE;
8698 ipw_set_fixed_rate(priv, priv->ieee->mode);
8699 } else
8700 priv->config |= CFG_FIXED_RATE;
8701
8702 if (priv->rates_mask == mask) {
8703 IPW_DEBUG_WX("Mask set to current mask.\n");
8704 up(&priv->sem);
8705 return 0;
8706 }
8707
8708 priv->rates_mask = mask;
8709
8710 /* Network configuration changed -- force [re]association */
8711 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
8712 if (!ipw_disassociate(priv))
8713 ipw_associate(priv);
8714
8715 up(&priv->sem);
8716 return 0;
5686} 8717}
5687 8718
5688static int ipw_wx_get_rate(struct net_device *dev, 8719static int ipw_wx_get_rate(struct net_device *dev,
@@ -5690,8 +8721,9 @@ static int ipw_wx_get_rate(struct net_device *dev,
5690 union iwreq_data *wrqu, char *extra) 8721 union iwreq_data *wrqu, char *extra)
5691{ 8722{
5692 struct ipw_priv *priv = ieee80211_priv(dev); 8723 struct ipw_priv *priv = ieee80211_priv(dev);
8724 down(&priv->sem);
5693 wrqu->bitrate.value = priv->last_rate; 8725 wrqu->bitrate.value = priv->last_rate;
5694 8726 up(&priv->sem);
5695 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value); 8727 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
5696 return 0; 8728 return 0;
5697} 8729}
@@ -5701,18 +8733,20 @@ static int ipw_wx_set_rts(struct net_device *dev,
5701 union iwreq_data *wrqu, char *extra) 8733 union iwreq_data *wrqu, char *extra)
5702{ 8734{
5703 struct ipw_priv *priv = ieee80211_priv(dev); 8735 struct ipw_priv *priv = ieee80211_priv(dev);
5704 8736 down(&priv->sem);
5705 if (wrqu->rts.disabled) 8737 if (wrqu->rts.disabled)
5706 priv->rts_threshold = DEFAULT_RTS_THRESHOLD; 8738 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
5707 else { 8739 else {
5708 if (wrqu->rts.value < MIN_RTS_THRESHOLD || 8740 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
5709 wrqu->rts.value > MAX_RTS_THRESHOLD) 8741 wrqu->rts.value > MAX_RTS_THRESHOLD) {
8742 up(&priv->sem);
5710 return -EINVAL; 8743 return -EINVAL;
5711 8744 }
5712 priv->rts_threshold = wrqu->rts.value; 8745 priv->rts_threshold = wrqu->rts.value;
5713 } 8746 }
5714 8747
5715 ipw_send_rts_threshold(priv, priv->rts_threshold); 8748 ipw_send_rts_threshold(priv, priv->rts_threshold);
8749 up(&priv->sem);
5716 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold); 8750 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
5717 return 0; 8751 return 0;
5718} 8752}
@@ -5722,10 +8756,11 @@ static int ipw_wx_get_rts(struct net_device *dev,
5722 union iwreq_data *wrqu, char *extra) 8756 union iwreq_data *wrqu, char *extra)
5723{ 8757{
5724 struct ipw_priv *priv = ieee80211_priv(dev); 8758 struct ipw_priv *priv = ieee80211_priv(dev);
8759 down(&priv->sem);
5725 wrqu->rts.value = priv->rts_threshold; 8760 wrqu->rts.value = priv->rts_threshold;
5726 wrqu->rts.fixed = 0; /* no auto select */ 8761 wrqu->rts.fixed = 0; /* no auto select */
5727 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD); 8762 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
5728 8763 up(&priv->sem);
5729 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value); 8764 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
5730 return 0; 8765 return 0;
5731} 8766}
@@ -5735,41 +8770,33 @@ static int ipw_wx_set_txpow(struct net_device *dev,
5735 union iwreq_data *wrqu, char *extra) 8770 union iwreq_data *wrqu, char *extra)
5736{ 8771{
5737 struct ipw_priv *priv = ieee80211_priv(dev); 8772 struct ipw_priv *priv = ieee80211_priv(dev);
5738 struct ipw_tx_power tx_power; 8773 int err = 0;
5739 int i;
5740
5741 if (ipw_radio_kill_sw(priv, wrqu->power.disabled))
5742 return -EINPROGRESS;
5743
5744 if (wrqu->power.flags != IW_TXPOW_DBM)
5745 return -EINVAL;
5746 8774
5747 if ((wrqu->power.value > 20) || (wrqu->power.value < -12)) 8775 down(&priv->sem);
5748 return -EINVAL; 8776 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
8777 err = -EINPROGRESS;
8778 goto out;
8779 }
5749 8780
5750 priv->tx_power = wrqu->power.value; 8781 if (!wrqu->power.fixed)
8782 wrqu->power.value = IPW_TX_POWER_DEFAULT;
5751 8783
5752 memset(&tx_power, 0, sizeof(tx_power)); 8784 if (wrqu->power.flags != IW_TXPOW_DBM) {
5753 8785 err = -EINVAL;
5754 /* configure device for 'G' band */ 8786 goto out;
5755 tx_power.ieee_mode = IPW_G_MODE;
5756 tx_power.num_channels = 11;
5757 for (i = 0; i < 11; i++) {
5758 tx_power.channels_tx_power[i].channel_number = i + 1;
5759 tx_power.channels_tx_power[i].tx_power = priv->tx_power;
5760 } 8787 }
5761 if (ipw_send_tx_power(priv, &tx_power))
5762 goto error;
5763 8788
5764 /* configure device to also handle 'B' band */ 8789 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
5765 tx_power.ieee_mode = IPW_B_MODE; 8790 (wrqu->power.value < IPW_TX_POWER_MIN)) {
5766 if (ipw_send_tx_power(priv, &tx_power)) 8791 err = -EINVAL;
5767 goto error; 8792 goto out;
5768 8793 }
5769 return 0;
5770 8794
5771 error: 8795 priv->tx_power = wrqu->power.value;
5772 return -EIO; 8796 err = ipw_set_tx_power(priv);
8797 out:
8798 up(&priv->sem);
8799 return err;
5773} 8800}
5774 8801
5775static int ipw_wx_get_txpow(struct net_device *dev, 8802static int ipw_wx_get_txpow(struct net_device *dev,
@@ -5777,14 +8804,15 @@ static int ipw_wx_get_txpow(struct net_device *dev,
5777 union iwreq_data *wrqu, char *extra) 8804 union iwreq_data *wrqu, char *extra)
5778{ 8805{
5779 struct ipw_priv *priv = ieee80211_priv(dev); 8806 struct ipw_priv *priv = ieee80211_priv(dev);
5780 8807 down(&priv->sem);
5781 wrqu->power.value = priv->tx_power; 8808 wrqu->power.value = priv->tx_power;
5782 wrqu->power.fixed = 1; 8809 wrqu->power.fixed = 1;
5783 wrqu->power.flags = IW_TXPOW_DBM; 8810 wrqu->power.flags = IW_TXPOW_DBM;
5784 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0; 8811 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
8812 up(&priv->sem);
5785 8813
5786 IPW_DEBUG_WX("GET TX Power -> %s %d \n", 8814 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
5787 wrqu->power.disabled ? "ON" : "OFF", wrqu->power.value); 8815 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
5788 8816
5789 return 0; 8817 return 0;
5790} 8818}
@@ -5794,18 +8822,21 @@ static int ipw_wx_set_frag(struct net_device *dev,
5794 union iwreq_data *wrqu, char *extra) 8822 union iwreq_data *wrqu, char *extra)
5795{ 8823{
5796 struct ipw_priv *priv = ieee80211_priv(dev); 8824 struct ipw_priv *priv = ieee80211_priv(dev);
5797 8825 down(&priv->sem);
5798 if (wrqu->frag.disabled) 8826 if (wrqu->frag.disabled)
5799 priv->ieee->fts = DEFAULT_FTS; 8827 priv->ieee->fts = DEFAULT_FTS;
5800 else { 8828 else {
5801 if (wrqu->frag.value < MIN_FRAG_THRESHOLD || 8829 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
5802 wrqu->frag.value > MAX_FRAG_THRESHOLD) 8830 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
8831 up(&priv->sem);
5803 return -EINVAL; 8832 return -EINVAL;
8833 }
5804 8834
5805 priv->ieee->fts = wrqu->frag.value & ~0x1; 8835 priv->ieee->fts = wrqu->frag.value & ~0x1;
5806 } 8836 }
5807 8837
5808 ipw_send_frag_threshold(priv, wrqu->frag.value); 8838 ipw_send_frag_threshold(priv, wrqu->frag.value);
8839 up(&priv->sem);
5809 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value); 8840 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
5810 return 0; 8841 return 0;
5811} 8842}
@@ -5815,10 +8846,11 @@ static int ipw_wx_get_frag(struct net_device *dev,
5815 union iwreq_data *wrqu, char *extra) 8846 union iwreq_data *wrqu, char *extra)
5816{ 8847{
5817 struct ipw_priv *priv = ieee80211_priv(dev); 8848 struct ipw_priv *priv = ieee80211_priv(dev);
8849 down(&priv->sem);
5818 wrqu->frag.value = priv->ieee->fts; 8850 wrqu->frag.value = priv->ieee->fts;
5819 wrqu->frag.fixed = 0; /* no auto select */ 8851 wrqu->frag.fixed = 0; /* no auto select */
5820 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS); 8852 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
5821 8853 up(&priv->sem);
5822 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value); 8854 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
5823 8855
5824 return 0; 8856 return 0;
@@ -5828,16 +8860,128 @@ static int ipw_wx_set_retry(struct net_device *dev,
5828 struct iw_request_info *info, 8860 struct iw_request_info *info,
5829 union iwreq_data *wrqu, char *extra) 8861 union iwreq_data *wrqu, char *extra)
5830{ 8862{
5831 IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu); 8863 struct ipw_priv *priv = ieee80211_priv(dev);
5832 return -EOPNOTSUPP; 8864
8865 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
8866 return -EINVAL;
8867
8868 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
8869 return 0;
8870
8871 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
8872 return -EINVAL;
8873
8874 down(&priv->sem);
8875 if (wrqu->retry.flags & IW_RETRY_MIN)
8876 priv->short_retry_limit = (u8) wrqu->retry.value;
8877 else if (wrqu->retry.flags & IW_RETRY_MAX)
8878 priv->long_retry_limit = (u8) wrqu->retry.value;
8879 else {
8880 priv->short_retry_limit = (u8) wrqu->retry.value;
8881 priv->long_retry_limit = (u8) wrqu->retry.value;
8882 }
8883
8884 ipw_send_retry_limit(priv, priv->short_retry_limit,
8885 priv->long_retry_limit);
8886 up(&priv->sem);
8887 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
8888 priv->short_retry_limit, priv->long_retry_limit);
8889 return 0;
5833} 8890}
5834 8891
5835static int ipw_wx_get_retry(struct net_device *dev, 8892static int ipw_wx_get_retry(struct net_device *dev,
5836 struct iw_request_info *info, 8893 struct iw_request_info *info,
5837 union iwreq_data *wrqu, char *extra) 8894 union iwreq_data *wrqu, char *extra)
5838{ 8895{
5839 IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu); 8896 struct ipw_priv *priv = ieee80211_priv(dev);
5840 return -EOPNOTSUPP; 8897
8898 down(&priv->sem);
8899 wrqu->retry.disabled = 0;
8900
8901 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
8902 up(&priv->sem);
8903 return -EINVAL;
8904 }
8905
8906 if (wrqu->retry.flags & IW_RETRY_MAX) {
8907 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
8908 wrqu->retry.value = priv->long_retry_limit;
8909 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
8910 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
8911 wrqu->retry.value = priv->short_retry_limit;
8912 } else {
8913 wrqu->retry.flags = IW_RETRY_LIMIT;
8914 wrqu->retry.value = priv->short_retry_limit;
8915 }
8916 up(&priv->sem);
8917
8918 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
8919
8920 return 0;
8921}
8922
8923static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
8924 int essid_len)
8925{
8926 struct ipw_scan_request_ext scan;
8927 int err = 0, scan_type;
8928
8929 down(&priv->sem);
8930
8931 if (priv->status & STATUS_RF_KILL_MASK) {
8932 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
8933 priv->status |= STATUS_SCAN_PENDING;
8934 goto done;
8935 }
8936
8937 IPW_DEBUG_HC("starting request direct scan!\n");
8938
8939 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
8940 err = wait_event_interruptible(priv->wait_state,
8941 !(priv->
8942 status & (STATUS_SCANNING |
8943 STATUS_SCAN_ABORTING)));
8944 if (err) {
8945 IPW_DEBUG_HC("aborting direct scan");
8946 goto done;
8947 }
8948 }
8949 memset(&scan, 0, sizeof(scan));
8950
8951 if (priv->config & CFG_SPEED_SCAN)
8952 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
8953 cpu_to_le16(30);
8954 else
8955 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
8956 cpu_to_le16(20);
8957
8958 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
8959 cpu_to_le16(20);
8960 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
8961 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
8962
8963 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
8964
8965 err = ipw_send_ssid(priv, essid, essid_len);
8966 if (err) {
8967 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
8968 goto done;
8969 }
8970 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
8971
8972 ipw_add_scan_channels(priv, &scan, scan_type);
8973
8974 err = ipw_send_scan_request_ext(priv, &scan);
8975 if (err) {
8976 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
8977 goto done;
8978 }
8979
8980 priv->status |= STATUS_SCANNING;
8981
8982 done:
8983 up(&priv->sem);
8984 return err;
5841} 8985}
5842 8986
5843static int ipw_wx_set_scan(struct net_device *dev, 8987static int ipw_wx_set_scan(struct net_device *dev,
@@ -5845,9 +8989,21 @@ static int ipw_wx_set_scan(struct net_device *dev,
5845 union iwreq_data *wrqu, char *extra) 8989 union iwreq_data *wrqu, char *extra)
5846{ 8990{
5847 struct ipw_priv *priv = ieee80211_priv(dev); 8991 struct ipw_priv *priv = ieee80211_priv(dev);
8992 struct iw_scan_req *req = NULL;
8993 if (wrqu->data.length
8994 && wrqu->data.length == sizeof(struct iw_scan_req)) {
8995 req = (struct iw_scan_req *)extra;
8996 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
8997 ipw_request_direct_scan(priv, req->essid,
8998 req->essid_len);
8999 return 0;
9000 }
9001 }
9002
5848 IPW_DEBUG_WX("Start scan\n"); 9003 IPW_DEBUG_WX("Start scan\n");
5849 if (ipw_request_scan(priv)) 9004
5850 return -EIO; 9005 queue_work(priv->workqueue, &priv->request_scan);
9006
5851 return 0; 9007 return 0;
5852} 9008}
5853 9009
@@ -5864,7 +9020,21 @@ static int ipw_wx_set_encode(struct net_device *dev,
5864 union iwreq_data *wrqu, char *key) 9020 union iwreq_data *wrqu, char *key)
5865{ 9021{
5866 struct ipw_priv *priv = ieee80211_priv(dev); 9022 struct ipw_priv *priv = ieee80211_priv(dev);
5867 return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key); 9023 int ret;
9024 u32 cap = priv->capability;
9025
9026 down(&priv->sem);
9027 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
9028
9029 /* In IBSS mode, we need to notify the firmware to update
9030 * the beacon info after we changed the capability. */
9031 if (cap != priv->capability &&
9032 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9033 priv->status & STATUS_ASSOCIATED)
9034 ipw_disassociate(priv);
9035
9036 up(&priv->sem);
9037 return ret;
5868} 9038}
5869 9039
5870static int ipw_wx_get_encode(struct net_device *dev, 9040static int ipw_wx_get_encode(struct net_device *dev,
@@ -5881,17 +9051,17 @@ static int ipw_wx_set_power(struct net_device *dev,
5881{ 9051{
5882 struct ipw_priv *priv = ieee80211_priv(dev); 9052 struct ipw_priv *priv = ieee80211_priv(dev);
5883 int err; 9053 int err;
5884 9054 down(&priv->sem);
5885 if (wrqu->power.disabled) { 9055 if (wrqu->power.disabled) {
5886 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode); 9056 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
5887 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM); 9057 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
5888 if (err) { 9058 if (err) {
5889 IPW_DEBUG_WX("failed setting power mode.\n"); 9059 IPW_DEBUG_WX("failed setting power mode.\n");
9060 up(&priv->sem);
5890 return err; 9061 return err;
5891 } 9062 }
5892
5893 IPW_DEBUG_WX("SET Power Management Mode -> off\n"); 9063 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
5894 9064 up(&priv->sem);
5895 return 0; 9065 return 0;
5896 } 9066 }
5897 9067
@@ -5903,6 +9073,7 @@ static int ipw_wx_set_power(struct net_device *dev,
5903 default: /* Otherwise we don't support it */ 9073 default: /* Otherwise we don't support it */
5904 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n", 9074 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
5905 wrqu->power.flags); 9075 wrqu->power.flags);
9076 up(&priv->sem);
5906 return -EOPNOTSUPP; 9077 return -EOPNOTSUPP;
5907 } 9078 }
5908 9079
@@ -5915,11 +9086,12 @@ static int ipw_wx_set_power(struct net_device *dev,
5915 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode)); 9086 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
5916 if (err) { 9087 if (err) {
5917 IPW_DEBUG_WX("failed setting power mode.\n"); 9088 IPW_DEBUG_WX("failed setting power mode.\n");
9089 up(&priv->sem);
5918 return err; 9090 return err;
5919 } 9091 }
5920 9092
5921 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode); 9093 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
5922 9094 up(&priv->sem);
5923 return 0; 9095 return 0;
5924} 9096}
5925 9097
@@ -5928,13 +9100,13 @@ static int ipw_wx_get_power(struct net_device *dev,
5928 union iwreq_data *wrqu, char *extra) 9100 union iwreq_data *wrqu, char *extra)
5929{ 9101{
5930 struct ipw_priv *priv = ieee80211_priv(dev); 9102 struct ipw_priv *priv = ieee80211_priv(dev);
5931 9103 down(&priv->sem);
5932 if (!(priv->power_mode & IPW_POWER_ENABLED)) { 9104 if (!(priv->power_mode & IPW_POWER_ENABLED))
5933 wrqu->power.disabled = 1; 9105 wrqu->power.disabled = 1;
5934 } else { 9106 else
5935 wrqu->power.disabled = 0; 9107 wrqu->power.disabled = 0;
5936 }
5937 9108
9109 up(&priv->sem);
5938 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode); 9110 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
5939 9111
5940 return 0; 9112 return 0;
@@ -5947,7 +9119,7 @@ static int ipw_wx_set_powermode(struct net_device *dev,
5947 struct ipw_priv *priv = ieee80211_priv(dev); 9119 struct ipw_priv *priv = ieee80211_priv(dev);
5948 int mode = *(int *)extra; 9120 int mode = *(int *)extra;
5949 int err; 9121 int err;
5950 9122 down(&priv->sem);
5951 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) { 9123 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
5952 mode = IPW_POWER_AC; 9124 mode = IPW_POWER_AC;
5953 priv->power_mode = mode; 9125 priv->power_mode = mode;
@@ -5960,10 +9132,11 @@ static int ipw_wx_set_powermode(struct net_device *dev,
5960 9132
5961 if (err) { 9133 if (err) {
5962 IPW_DEBUG_WX("failed setting power mode.\n"); 9134 IPW_DEBUG_WX("failed setting power mode.\n");
9135 up(&priv->sem);
5963 return err; 9136 return err;
5964 } 9137 }
5965 } 9138 }
5966 9139 up(&priv->sem);
5967 return 0; 9140 return 0;
5968} 9141}
5969 9142
@@ -6012,7 +9185,7 @@ static int ipw_wx_set_wireless_mode(struct net_device *dev,
6012 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode); 9185 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
6013 return -EINVAL; 9186 return -EINVAL;
6014 } 9187 }
6015 9188 down(&priv->sem);
6016 if (priv->adapter == IPW_2915ABG) { 9189 if (priv->adapter == IPW_2915ABG) {
6017 priv->ieee->abg_true = 1; 9190 priv->ieee->abg_true = 1;
6018 if (mode & IEEE_A) { 9191 if (mode & IEEE_A) {
@@ -6024,6 +9197,7 @@ static int ipw_wx_set_wireless_mode(struct net_device *dev,
6024 if (mode & IEEE_A) { 9197 if (mode & IEEE_A) {
6025 IPW_WARNING("Attempt to set 2200BG into " 9198 IPW_WARNING("Attempt to set 2200BG into "
6026 "802.11a mode\n"); 9199 "802.11a mode\n");
9200 up(&priv->sem);
6027 return -EINVAL; 9201 return -EINVAL;
6028 } 9202 }
6029 9203
@@ -6047,20 +9221,20 @@ static int ipw_wx_set_wireless_mode(struct net_device *dev,
6047 priv->ieee->modulation = modulation; 9221 priv->ieee->modulation = modulation;
6048 init_supported_rates(priv, &priv->rates); 9222 init_supported_rates(priv, &priv->rates);
6049 9223
6050 /* If we are currently associated, or trying to associate 9224 /* Network configuration changed -- force [re]association */
6051 * then see if this is a new configuration (causing us to 9225 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
6052 * disassociate) */ 9226 if (!ipw_disassociate(priv)) {
6053 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
6054 /* The resulting association will trigger
6055 * the new rates to be sent to the device */
6056 IPW_DEBUG_ASSOC("Disassociating due to mode change.\n");
6057 ipw_disassociate(priv);
6058 } else
6059 ipw_send_supported_rates(priv, &priv->rates); 9227 ipw_send_supported_rates(priv, &priv->rates);
9228 ipw_associate(priv);
9229 }
9230
9231 /* Update the band LEDs */
9232 ipw_led_band_on(priv);
6060 9233
6061 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n", 9234 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
6062 mode & IEEE_A ? 'a' : '.', 9235 mode & IEEE_A ? 'a' : '.',
6063 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.'); 9236 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
9237 up(&priv->sem);
6064 return 0; 9238 return 0;
6065} 9239}
6066 9240
@@ -6069,124 +9243,234 @@ static int ipw_wx_get_wireless_mode(struct net_device *dev,
6069 union iwreq_data *wrqu, char *extra) 9243 union iwreq_data *wrqu, char *extra)
6070{ 9244{
6071 struct ipw_priv *priv = ieee80211_priv(dev); 9245 struct ipw_priv *priv = ieee80211_priv(dev);
6072 9246 down(&priv->sem);
6073 switch (priv->ieee->freq_band) { 9247 switch (priv->ieee->mode) {
6074 case IEEE80211_24GHZ_BAND: 9248 case IEEE_A:
6075 switch (priv->ieee->modulation) {
6076 case IEEE80211_CCK_MODULATION:
6077 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
6078 break;
6079 case IEEE80211_OFDM_MODULATION:
6080 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
6081 break;
6082 default:
6083 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
6084 break;
6085 }
6086 break;
6087
6088 case IEEE80211_52GHZ_BAND:
6089 strncpy(extra, "802.11a (1)", MAX_WX_STRING); 9249 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
6090 break; 9250 break;
6091 9251 case IEEE_B:
6092 default: /* Mixed Band */ 9252 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
6093 switch (priv->ieee->modulation) { 9253 break;
6094 case IEEE80211_CCK_MODULATION: 9254 case IEEE_A | IEEE_B:
6095 strncpy(extra, "802.11ab (3)", MAX_WX_STRING); 9255 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
6096 break; 9256 break;
6097 case IEEE80211_OFDM_MODULATION: 9257 case IEEE_G:
6098 strncpy(extra, "802.11ag (5)", MAX_WX_STRING); 9258 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
6099 break; 9259 break;
6100 default: 9260 case IEEE_A | IEEE_G:
6101 strncpy(extra, "802.11abg (7)", MAX_WX_STRING); 9261 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
6102 break; 9262 break;
6103 } 9263 case IEEE_B | IEEE_G:
9264 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9265 break;
9266 case IEEE_A | IEEE_B | IEEE_G:
9267 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9268 break;
9269 default:
9270 strncpy(extra, "unknown", MAX_WX_STRING);
6104 break; 9271 break;
6105 } 9272 }
6106 9273
6107 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra); 9274 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
6108 9275
6109 wrqu->data.length = strlen(extra) + 1; 9276 wrqu->data.length = strlen(extra) + 1;
9277 up(&priv->sem);
6110 9278
6111 return 0; 9279 return 0;
6112} 9280}
6113 9281
6114#ifdef CONFIG_IPW_PROMISC 9282static int ipw_wx_set_preamble(struct net_device *dev,
6115static int ipw_wx_set_promisc(struct net_device *dev, 9283 struct iw_request_info *info,
9284 union iwreq_data *wrqu, char *extra)
9285{
9286 struct ipw_priv *priv = ieee80211_priv(dev);
9287 int mode = *(int *)extra;
9288 down(&priv->sem);
9289 /* Switching from SHORT -> LONG requires a disassociation */
9290 if (mode == 1) {
9291 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9292 priv->config |= CFG_PREAMBLE_LONG;
9293
9294 /* Network configuration changed -- force [re]association */
9295 IPW_DEBUG_ASSOC
9296 ("[re]association triggered due to preamble change.\n");
9297 if (!ipw_disassociate(priv))
9298 ipw_associate(priv);
9299 }
9300 goto done;
9301 }
9302
9303 if (mode == 0) {
9304 priv->config &= ~CFG_PREAMBLE_LONG;
9305 goto done;
9306 }
9307 up(&priv->sem);
9308 return -EINVAL;
9309
9310 done:
9311 up(&priv->sem);
9312 return 0;
9313}
9314
9315static int ipw_wx_get_preamble(struct net_device *dev,
9316 struct iw_request_info *info,
9317 union iwreq_data *wrqu, char *extra)
9318{
9319 struct ipw_priv *priv = ieee80211_priv(dev);
9320 down(&priv->sem);
9321 if (priv->config & CFG_PREAMBLE_LONG)
9322 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9323 else
9324 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
9325 up(&priv->sem);
9326 return 0;
9327}
9328
9329#ifdef CONFIG_IPW2200_MONITOR
9330static int ipw_wx_set_monitor(struct net_device *dev,
6116 struct iw_request_info *info, 9331 struct iw_request_info *info,
6117 union iwreq_data *wrqu, char *extra) 9332 union iwreq_data *wrqu, char *extra)
6118{ 9333{
6119 struct ipw_priv *priv = ieee80211_priv(dev); 9334 struct ipw_priv *priv = ieee80211_priv(dev);
6120 int *parms = (int *)extra; 9335 int *parms = (int *)extra;
6121 int enable = (parms[0] > 0); 9336 int enable = (parms[0] > 0);
6122 9337 down(&priv->sem);
6123 IPW_DEBUG_WX("SET PROMISC: %d %d\n", enable, parms[1]); 9338 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
6124 if (enable) { 9339 if (enable) {
6125 if (priv->ieee->iw_mode != IW_MODE_MONITOR) { 9340 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9341#ifdef CONFIG_IEEE80211_RADIOTAP
9342 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9343#else
6126 priv->net_dev->type = ARPHRD_IEEE80211; 9344 priv->net_dev->type = ARPHRD_IEEE80211;
6127 ipw_adapter_restart(priv); 9345#endif
9346 queue_work(priv->workqueue, &priv->adapter_restart);
6128 } 9347 }
6129 9348
6130 ipw_set_channel(priv, parms[1]); 9349 ipw_set_channel(priv, parms[1]);
6131 } else { 9350 } else {
6132 if (priv->ieee->iw_mode != IW_MODE_MONITOR) 9351 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
9352 up(&priv->sem);
6133 return 0; 9353 return 0;
9354 }
6134 priv->net_dev->type = ARPHRD_ETHER; 9355 priv->net_dev->type = ARPHRD_ETHER;
6135 ipw_adapter_restart(priv); 9356 queue_work(priv->workqueue, &priv->adapter_restart);
6136 } 9357 }
9358 up(&priv->sem);
6137 return 0; 9359 return 0;
6138} 9360}
6139 9361
9362#endif // CONFIG_IPW2200_MONITOR
9363
6140static int ipw_wx_reset(struct net_device *dev, 9364static int ipw_wx_reset(struct net_device *dev,
6141 struct iw_request_info *info, 9365 struct iw_request_info *info,
6142 union iwreq_data *wrqu, char *extra) 9366 union iwreq_data *wrqu, char *extra)
6143{ 9367{
6144 struct ipw_priv *priv = ieee80211_priv(dev); 9368 struct ipw_priv *priv = ieee80211_priv(dev);
6145 IPW_DEBUG_WX("RESET\n"); 9369 IPW_DEBUG_WX("RESET\n");
6146 ipw_adapter_restart(priv); 9370 queue_work(priv->workqueue, &priv->adapter_restart);
9371 return 0;
9372}
9373
9374static int ipw_wx_sw_reset(struct net_device *dev,
9375 struct iw_request_info *info,
9376 union iwreq_data *wrqu, char *extra)
9377{
9378 struct ipw_priv *priv = ieee80211_priv(dev);
9379 union iwreq_data wrqu_sec = {
9380 .encoding = {
9381 .flags = IW_ENCODE_DISABLED,
9382 },
9383 };
9384 int ret;
9385
9386 IPW_DEBUG_WX("SW_RESET\n");
9387
9388 down(&priv->sem);
9389
9390 ret = ipw_sw_reset(priv, 0);
9391 if (!ret) {
9392 free_firmware();
9393 ipw_adapter_restart(priv);
9394 }
9395
9396 /* The SW reset bit might have been toggled on by the 'disable'
9397 * module parameter, so take appropriate action */
9398 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9399
9400 up(&priv->sem);
9401 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
9402 down(&priv->sem);
9403
9404 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9405 /* Configuration likely changed -- force [re]association */
9406 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9407 "reset.\n");
9408 if (!ipw_disassociate(priv))
9409 ipw_associate(priv);
9410 }
9411
9412 up(&priv->sem);
9413
6147 return 0; 9414 return 0;
6148} 9415}
6149#endif // CONFIG_IPW_PROMISC
6150 9416
6151/* Rebase the WE IOCTLs to zero for the handler array */ 9417/* Rebase the WE IOCTLs to zero for the handler array */
6152#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT] 9418#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
6153static iw_handler ipw_wx_handlers[] = { 9419static iw_handler ipw_wx_handlers[] = {
6154 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name, 9420 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
6155 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq, 9421 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
6156 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq, 9422 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
6157 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode, 9423 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
6158 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode, 9424 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
6159 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range, 9425 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
6160 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap, 9426 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
6161 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap, 9427 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
6162 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan, 9428 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
6163 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan, 9429 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
6164 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid, 9430 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
6165 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid, 9431 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
6166 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick, 9432 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
6167 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick, 9433 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
6168 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate, 9434 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
6169 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate, 9435 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
6170 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts, 9436 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
6171 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts, 9437 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
6172 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag, 9438 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
6173 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag, 9439 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
6174 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow, 9440 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
6175 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow, 9441 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
6176 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry, 9442 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
6177 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry, 9443 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
6178 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode, 9444 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
6179 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode, 9445 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
6180 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power, 9446 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
6181 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power, 9447 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
9448 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9449 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9450 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9451 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
9452 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9453 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9454 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9455 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9456 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9457 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9458 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
6182}; 9459};
6183 9460
6184#define IPW_PRIV_SET_POWER SIOCIWFIRSTPRIV 9461enum {
6185#define IPW_PRIV_GET_POWER SIOCIWFIRSTPRIV+1 9462 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
6186#define IPW_PRIV_SET_MODE SIOCIWFIRSTPRIV+2 9463 IPW_PRIV_GET_POWER,
6187#define IPW_PRIV_GET_MODE SIOCIWFIRSTPRIV+3 9464 IPW_PRIV_SET_MODE,
6188#define IPW_PRIV_SET_PROMISC SIOCIWFIRSTPRIV+4 9465 IPW_PRIV_GET_MODE,
6189#define IPW_PRIV_RESET SIOCIWFIRSTPRIV+5 9466 IPW_PRIV_SET_PREAMBLE,
9467 IPW_PRIV_GET_PREAMBLE,
9468 IPW_PRIV_RESET,
9469 IPW_PRIV_SW_RESET,
9470#ifdef CONFIG_IPW2200_MONITOR
9471 IPW_PRIV_SET_MONITOR,
9472#endif
9473};
6190 9474
6191static struct iw_priv_args ipw_priv_args[] = { 9475static struct iw_priv_args ipw_priv_args[] = {
6192 { 9476 {
@@ -6205,14 +9489,25 @@ static struct iw_priv_args ipw_priv_args[] = {
6205 .cmd = IPW_PRIV_GET_MODE, 9489 .cmd = IPW_PRIV_GET_MODE,
6206 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING, 9490 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
6207 .name = "get_mode"}, 9491 .name = "get_mode"},
6208#ifdef CONFIG_IPW_PROMISC
6209 { 9492 {
6210 IPW_PRIV_SET_PROMISC, 9493 .cmd = IPW_PRIV_SET_PREAMBLE,
6211 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"}, 9494 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9495 .name = "set_preamble"},
9496 {
9497 .cmd = IPW_PRIV_GET_PREAMBLE,
9498 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9499 .name = "get_preamble"},
6212 { 9500 {
6213 IPW_PRIV_RESET, 9501 IPW_PRIV_RESET,
6214 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"}, 9502 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
6215#endif /* CONFIG_IPW_PROMISC */ 9503 {
9504 IPW_PRIV_SW_RESET,
9505 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9506#ifdef CONFIG_IPW2200_MONITOR
9507 {
9508 IPW_PRIV_SET_MONITOR,
9509 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9510#endif /* CONFIG_IPW2200_MONITOR */
6216}; 9511};
6217 9512
6218static iw_handler ipw_priv_handler[] = { 9513static iw_handler ipw_priv_handler[] = {
@@ -6220,19 +9515,23 @@ static iw_handler ipw_priv_handler[] = {
6220 ipw_wx_get_powermode, 9515 ipw_wx_get_powermode,
6221 ipw_wx_set_wireless_mode, 9516 ipw_wx_set_wireless_mode,
6222 ipw_wx_get_wireless_mode, 9517 ipw_wx_get_wireless_mode,
6223#ifdef CONFIG_IPW_PROMISC 9518 ipw_wx_set_preamble,
6224 ipw_wx_set_promisc, 9519 ipw_wx_get_preamble,
6225 ipw_wx_reset, 9520 ipw_wx_reset,
9521 ipw_wx_sw_reset,
9522#ifdef CONFIG_IPW2200_MONITOR
9523 ipw_wx_set_monitor,
6226#endif 9524#endif
6227}; 9525};
6228 9526
6229static struct iw_handler_def ipw_wx_handler_def = { 9527static struct iw_handler_def ipw_wx_handler_def = {
6230 .standard = ipw_wx_handlers, 9528 .standard = ipw_wx_handlers,
6231 .num_standard = ARRAY_SIZE(ipw_wx_handlers), 9529 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
6232 .num_private = ARRAY_SIZE(ipw_priv_handler), 9530 .num_private = ARRAY_SIZE(ipw_priv_handler),
6233 .num_private_args = ARRAY_SIZE(ipw_priv_args), 9531 .num_private_args = ARRAY_SIZE(ipw_priv_args),
6234 .private = ipw_priv_handler, 9532 .private = ipw_priv_handler,
6235 .private_args = ipw_priv_args, 9533 .private_args = ipw_priv_args,
9534 .get_wireless_stats = ipw_get_wireless_stats,
6236}; 9535};
6237 9536
6238/* 9537/*
@@ -6247,8 +9546,8 @@ static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
6247 9546
6248 wstats = &priv->wstats; 9547 wstats = &priv->wstats;
6249 9548
6250 /* if hw is disabled, then ipw2100_get_ordinal() can't be called. 9549 /* if hw is disabled, then ipw_get_ordinal() can't be called.
6251 * ipw2100_wx_wireless_stats seems to be called before fw is 9550 * netdev->get_wireless_stats seems to be called before fw is
6252 * initialized. STATUS_ASSOCIATED will only be set if the hw is up 9551 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
6253 * and associated; if not associcated, the values are all meaningless 9552 * and associated; if not associcated, the values are all meaningless
6254 * anyway, so set them all to NULL and INVALID */ 9553 * anyway, so set them all to NULL and INVALID */
@@ -6299,7 +9598,7 @@ static inline void init_sys_config(struct ipw_sys_config *sys_config)
6299 sys_config->dot11g_auto_detection = 0; 9598 sys_config->dot11g_auto_detection = 0;
6300 sys_config->enable_cts_to_self = 0; 9599 sys_config->enable_cts_to_self = 0;
6301 sys_config->bt_coexist_collision_thr = 0; 9600 sys_config->bt_coexist_collision_thr = 0;
6302 sys_config->pass_noise_stats_to_host = 1; 9601 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
6303} 9602}
6304 9603
6305static int ipw_net_open(struct net_device *dev) 9604static int ipw_net_open(struct net_device *dev)
@@ -6307,9 +9606,11 @@ static int ipw_net_open(struct net_device *dev)
6307 struct ipw_priv *priv = ieee80211_priv(dev); 9606 struct ipw_priv *priv = ieee80211_priv(dev);
6308 IPW_DEBUG_INFO("dev->open\n"); 9607 IPW_DEBUG_INFO("dev->open\n");
6309 /* we should be verifying the device is ready to be opened */ 9608 /* we should be verifying the device is ready to be opened */
9609 down(&priv->sem);
6310 if (!(priv->status & STATUS_RF_KILL_MASK) && 9610 if (!(priv->status & STATUS_RF_KILL_MASK) &&
6311 (priv->status & STATUS_ASSOCIATED)) 9611 (priv->status & STATUS_ASSOCIATED))
6312 netif_start_queue(dev); 9612 netif_start_queue(dev);
9613 up(&priv->sem);
6313 return 0; 9614 return 0;
6314} 9615}
6315 9616
@@ -6327,22 +9628,34 @@ modify to send one tfd per fragment instead of using chunking. otherwise
6327we need to heavily modify the ieee80211_skb_to_txb. 9628we need to heavily modify the ieee80211_skb_to_txb.
6328*/ 9629*/
6329 9630
6330static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb) 9631static inline int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
9632 int pri)
6331{ 9633{
6332 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) 9634 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
6333 txb->fragments[0]->data; 9635 txb->fragments[0]->data;
6334 int i = 0; 9636 int i = 0;
6335 struct tfd_frame *tfd; 9637 struct tfd_frame *tfd;
9638#ifdef CONFIG_IPW_QOS
9639 int tx_id = ipw_get_tx_queue_number(priv, pri);
9640 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9641#else
6336 struct clx2_tx_queue *txq = &priv->txq[0]; 9642 struct clx2_tx_queue *txq = &priv->txq[0];
9643#endif
6337 struct clx2_queue *q = &txq->q; 9644 struct clx2_queue *q = &txq->q;
6338 u8 id, hdr_len, unicast; 9645 u8 id, hdr_len, unicast;
6339 u16 remaining_bytes; 9646 u16 remaining_bytes;
9647 int fc;
9648
9649 /* If there isn't room in the queue, we return busy and let the
9650 * network stack requeue the packet for us */
9651 if (ipw_queue_space(q) < q->high_mark)
9652 return NETDEV_TX_BUSY;
6340 9653
6341 switch (priv->ieee->iw_mode) { 9654 switch (priv->ieee->iw_mode) {
6342 case IW_MODE_ADHOC: 9655 case IW_MODE_ADHOC:
6343 hdr_len = IEEE80211_3ADDR_LEN; 9656 hdr_len = IEEE80211_3ADDR_LEN;
6344 unicast = !is_broadcast_ether_addr(hdr->addr1) && 9657 unicast = !(is_multicast_ether_addr(hdr->addr1) ||
6345 !is_multicast_ether_addr(hdr->addr1); 9658 is_broadcast_ether_addr(hdr->addr1));
6346 id = ipw_find_station(priv, hdr->addr1); 9659 id = ipw_find_station(priv, hdr->addr1);
6347 if (id == IPW_INVALID_STATION) { 9660 if (id == IPW_INVALID_STATION) {
6348 id = ipw_add_station(priv, hdr->addr1); 9661 id = ipw_add_station(priv, hdr->addr1);
@@ -6357,8 +9670,8 @@ static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
6357 9670
6358 case IW_MODE_INFRA: 9671 case IW_MODE_INFRA:
6359 default: 9672 default:
6360 unicast = !is_broadcast_ether_addr(hdr->addr3) && 9673 unicast = !(is_multicast_ether_addr(hdr->addr3) ||
6361 !is_multicast_ether_addr(hdr->addr3); 9674 is_broadcast_ether_addr(hdr->addr3));
6362 hdr_len = IEEE80211_3ADDR_LEN; 9675 hdr_len = IEEE80211_3ADDR_LEN;
6363 id = 0; 9676 id = 0;
6364 break; 9677 break;
@@ -6373,26 +9686,83 @@ static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
6373 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK; 9686 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
6374 9687
6375 tfd->u.data.cmd_id = DINO_CMD_TX; 9688 tfd->u.data.cmd_id = DINO_CMD_TX;
6376 tfd->u.data.len = txb->payload_size; 9689 tfd->u.data.len = cpu_to_le16(txb->payload_size);
6377 remaining_bytes = txb->payload_size; 9690 remaining_bytes = txb->payload_size;
6378 if (unlikely(!unicast))
6379 tfd->u.data.tx_flags = DCT_FLAG_NO_WEP;
6380 else
6381 tfd->u.data.tx_flags = DCT_FLAG_NO_WEP | DCT_FLAG_ACK_REQD;
6382 9691
6383 if (priv->assoc_request.ieee_mode == IPW_B_MODE) 9692 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
6384 tfd->u.data.tx_flags_ext = DCT_FLAG_EXT_MODE_CCK; 9693 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
6385 else 9694 else
6386 tfd->u.data.tx_flags_ext = DCT_FLAG_EXT_MODE_OFDM; 9695 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
6387 9696
6388 if (priv->config & CFG_PREAMBLE) 9697 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
6389 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREMBL; 9698 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
9699
9700 fc = le16_to_cpu(hdr->frame_ctl);
9701 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
6390 9702
6391 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len); 9703 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
6392 9704
9705 if (likely(unicast))
9706 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9707
9708 if (txb->encrypted && !priv->ieee->host_encrypt) {
9709 switch (priv->ieee->sec.level) {
9710 case SEC_LEVEL_3:
9711 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9712 IEEE80211_FCTL_PROTECTED;
9713 /* XXX: ACK flag must be set for CCMP even if it
9714 * is a multicast/broadcast packet, because CCMP
9715 * group communication encrypted by GTK is
9716 * actually done by the AP. */
9717 if (!unicast)
9718 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9719
9720 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9721 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
9722 tfd->u.data.key_index = 0;
9723 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
9724 break;
9725 case SEC_LEVEL_2:
9726 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9727 IEEE80211_FCTL_PROTECTED;
9728 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9729 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
9730 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
9731 break;
9732 case SEC_LEVEL_1:
9733 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9734 IEEE80211_FCTL_PROTECTED;
9735 tfd->u.data.key_index = priv->ieee->tx_keyidx;
9736 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
9737 40)
9738 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
9739 else
9740 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
9741 break;
9742 case SEC_LEVEL_0:
9743 break;
9744 default:
9745 printk(KERN_ERR "Unknow security level %d\n",
9746 priv->ieee->sec.level);
9747 break;
9748 }
9749 } else
9750 /* No hardware encryption */
9751 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
9752
9753#ifdef CONFIG_IPW_QOS
9754 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast);
9755#endif /* CONFIG_IPW_QOS */
9756
6393 /* payload */ 9757 /* payload */
6394 tfd->u.data.num_chunks = min((u8) (NUM_TFD_CHUNKS - 2), txb->nr_frags); 9758 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
6395 for (i = 0; i < tfd->u.data.num_chunks; i++) { 9759 txb->nr_frags));
9760 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
9761 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
9762 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
9763 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
9764 i, le32_to_cpu(tfd->u.data.num_chunks),
9765 txb->fragments[i]->len - hdr_len);
6396 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n", 9766 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
6397 i, tfd->u.data.num_chunks, 9767 i, tfd->u.data.num_chunks,
6398 txb->fragments[i]->len - hdr_len); 9768 txb->fragments[i]->len - hdr_len);
@@ -6400,11 +9770,13 @@ static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
6400 txb->fragments[i]->len - hdr_len); 9770 txb->fragments[i]->len - hdr_len);
6401 9771
6402 tfd->u.data.chunk_ptr[i] = 9772 tfd->u.data.chunk_ptr[i] =
6403 pci_map_single(priv->pci_dev, 9773 cpu_to_le32(pci_map_single
6404 txb->fragments[i]->data + hdr_len, 9774 (priv->pci_dev,
6405 txb->fragments[i]->len - hdr_len, 9775 txb->fragments[i]->data + hdr_len,
6406 PCI_DMA_TODEVICE); 9776 txb->fragments[i]->len - hdr_len,
6407 tfd->u.data.chunk_len[i] = txb->fragments[i]->len - hdr_len; 9777 PCI_DMA_TODEVICE));
9778 tfd->u.data.chunk_len[i] =
9779 cpu_to_le16(txb->fragments[i]->len - hdr_len);
6408 } 9780 }
6409 9781
6410 if (i != txb->nr_frags) { 9782 if (i != txb->nr_frags) {
@@ -6419,9 +9791,10 @@ static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
6419 remaining_bytes); 9791 remaining_bytes);
6420 skb = alloc_skb(remaining_bytes, GFP_ATOMIC); 9792 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
6421 if (skb != NULL) { 9793 if (skb != NULL) {
6422 tfd->u.data.chunk_len[i] = remaining_bytes; 9794 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
6423 for (j = i; j < txb->nr_frags; j++) { 9795 for (j = i; j < txb->nr_frags; j++) {
6424 int size = txb->fragments[j]->len - hdr_len; 9796 int size = txb->fragments[j]->len - hdr_len;
9797
6425 printk(KERN_INFO "Adding frag %d %d...\n", 9798 printk(KERN_INFO "Adding frag %d %d...\n",
6426 j, size); 9799 j, size);
6427 memcpy(skb_put(skb, size), 9800 memcpy(skb_put(skb, size),
@@ -6430,10 +9803,14 @@ static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
6430 dev_kfree_skb_any(txb->fragments[i]); 9803 dev_kfree_skb_any(txb->fragments[i]);
6431 txb->fragments[i] = skb; 9804 txb->fragments[i] = skb;
6432 tfd->u.data.chunk_ptr[i] = 9805 tfd->u.data.chunk_ptr[i] =
6433 pci_map_single(priv->pci_dev, skb->data, 9806 cpu_to_le32(pci_map_single
6434 tfd->u.data.chunk_len[i], 9807 (priv->pci_dev, skb->data,
6435 PCI_DMA_TODEVICE); 9808 tfd->u.data.chunk_len[i],
6436 tfd->u.data.num_chunks++; 9809 PCI_DMA_TODEVICE));
9810
9811 tfd->u.data.num_chunks =
9812 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
9813 1);
6437 } 9814 }
6438 } 9815 }
6439 9816
@@ -6441,14 +9818,28 @@ static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
6441 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd); 9818 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
6442 ipw_write32(priv, q->reg_w, q->first_empty); 9819 ipw_write32(priv, q->reg_w, q->first_empty);
6443 9820
6444 if (ipw_queue_space(q) < q->high_mark) 9821 return NETDEV_TX_OK;
6445 netif_stop_queue(priv->net_dev);
6446
6447 return;
6448 9822
6449 drop: 9823 drop:
6450 IPW_DEBUG_DROP("Silently dropping Tx packet.\n"); 9824 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
6451 ieee80211_txb_free(txb); 9825 ieee80211_txb_free(txb);
9826 return NETDEV_TX_OK;
9827}
9828
9829static int ipw_net_is_queue_full(struct net_device *dev, int pri)
9830{
9831 struct ipw_priv *priv = ieee80211_priv(dev);
9832#ifdef CONFIG_IPW_QOS
9833 int tx_id = ipw_get_tx_queue_number(priv, pri);
9834 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9835#else
9836 struct clx2_tx_queue *txq = &priv->txq[0];
9837#endif /* CONFIG_IPW_QOS */
9838
9839 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
9840 return 1;
9841
9842 return 0;
6452} 9843}
6453 9844
6454static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb, 9845static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
@@ -6456,9 +9847,9 @@ static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
6456{ 9847{
6457 struct ipw_priv *priv = ieee80211_priv(dev); 9848 struct ipw_priv *priv = ieee80211_priv(dev);
6458 unsigned long flags; 9849 unsigned long flags;
9850 int ret;
6459 9851
6460 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size); 9852 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
6461
6462 spin_lock_irqsave(&priv->lock, flags); 9853 spin_lock_irqsave(&priv->lock, flags);
6463 9854
6464 if (!(priv->status & STATUS_ASSOCIATED)) { 9855 if (!(priv->status & STATUS_ASSOCIATED)) {
@@ -6468,10 +9859,12 @@ static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
6468 goto fail_unlock; 9859 goto fail_unlock;
6469 } 9860 }
6470 9861
6471 ipw_tx_skb(priv, txb); 9862 ret = ipw_tx_skb(priv, txb, pri);
6472 9863 if (ret == NETDEV_TX_OK)
9864 __ipw_led_activity_on(priv);
6473 spin_unlock_irqrestore(&priv->lock, flags); 9865 spin_unlock_irqrestore(&priv->lock, flags);
6474 return 0; 9866
9867 return ret;
6475 9868
6476 fail_unlock: 9869 fail_unlock:
6477 spin_unlock_irqrestore(&priv->lock, flags); 9870 spin_unlock_irqrestore(&priv->lock, flags);
@@ -6498,11 +9891,13 @@ static int ipw_net_set_mac_address(struct net_device *dev, void *p)
6498 struct sockaddr *addr = p; 9891 struct sockaddr *addr = p;
6499 if (!is_valid_ether_addr(addr->sa_data)) 9892 if (!is_valid_ether_addr(addr->sa_data))
6500 return -EADDRNOTAVAIL; 9893 return -EADDRNOTAVAIL;
9894 down(&priv->sem);
6501 priv->config |= CFG_CUSTOM_MAC; 9895 priv->config |= CFG_CUSTOM_MAC;
6502 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN); 9896 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
6503 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n", 9897 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
6504 priv->net_dev->name, MAC_ARG(priv->mac_addr)); 9898 priv->net_dev->name, MAC_ARG(priv->mac_addr));
6505 ipw_adapter_restart(priv); 9899 queue_work(priv->workqueue, &priv->adapter_restart);
9900 up(&priv->sem);
6506 return 0; 9901 return 0;
6507} 9902}
6508 9903
@@ -6525,7 +9920,7 @@ static void ipw_ethtool_get_drvinfo(struct net_device *dev,
6525 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)", 9920 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
6526 vers, date); 9921 vers, date);
6527 strcpy(info->bus_info, pci_name(p->pci_dev)); 9922 strcpy(info->bus_info, pci_name(p->pci_dev));
6528 info->eedump_len = CX2_EEPROM_IMAGE_SIZE; 9923 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
6529} 9924}
6530 9925
6531static u32 ipw_ethtool_get_link(struct net_device *dev) 9926static u32 ipw_ethtool_get_link(struct net_device *dev)
@@ -6536,7 +9931,7 @@ static u32 ipw_ethtool_get_link(struct net_device *dev)
6536 9931
6537static int ipw_ethtool_get_eeprom_len(struct net_device *dev) 9932static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
6538{ 9933{
6539 return CX2_EEPROM_IMAGE_SIZE; 9934 return IPW_EEPROM_IMAGE_SIZE;
6540} 9935}
6541 9936
6542static int ipw_ethtool_get_eeprom(struct net_device *dev, 9937static int ipw_ethtool_get_eeprom(struct net_device *dev,
@@ -6544,10 +9939,11 @@ static int ipw_ethtool_get_eeprom(struct net_device *dev,
6544{ 9939{
6545 struct ipw_priv *p = ieee80211_priv(dev); 9940 struct ipw_priv *p = ieee80211_priv(dev);
6546 9941
6547 if (eeprom->offset + eeprom->len > CX2_EEPROM_IMAGE_SIZE) 9942 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
6548 return -EINVAL; 9943 return -EINVAL;
6549 9944 down(&p->sem);
6550 memcpy(bytes, &((u8 *) p->eeprom)[eeprom->offset], eeprom->len); 9945 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
9946 up(&p->sem);
6551 return 0; 9947 return 0;
6552} 9948}
6553 9949
@@ -6557,23 +9953,23 @@ static int ipw_ethtool_set_eeprom(struct net_device *dev,
6557 struct ipw_priv *p = ieee80211_priv(dev); 9953 struct ipw_priv *p = ieee80211_priv(dev);
6558 int i; 9954 int i;
6559 9955
6560 if (eeprom->offset + eeprom->len > CX2_EEPROM_IMAGE_SIZE) 9956 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
6561 return -EINVAL; 9957 return -EINVAL;
6562 9958 down(&p->sem);
6563 memcpy(&((u8 *) p->eeprom)[eeprom->offset], bytes, eeprom->len); 9959 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
6564 for (i = IPW_EEPROM_DATA; 9960 for (i = IPW_EEPROM_DATA;
6565 i < IPW_EEPROM_DATA + CX2_EEPROM_IMAGE_SIZE; i++) 9961 i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++)
6566 ipw_write8(p, i, p->eeprom[i]); 9962 ipw_write8(p, i, p->eeprom[i]);
6567 9963 up(&p->sem);
6568 return 0; 9964 return 0;
6569} 9965}
6570 9966
6571static struct ethtool_ops ipw_ethtool_ops = { 9967static struct ethtool_ops ipw_ethtool_ops = {
6572 .get_link = ipw_ethtool_get_link, 9968 .get_link = ipw_ethtool_get_link,
6573 .get_drvinfo = ipw_ethtool_get_drvinfo, 9969 .get_drvinfo = ipw_ethtool_get_drvinfo,
6574 .get_eeprom_len = ipw_ethtool_get_eeprom_len, 9970 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
6575 .get_eeprom = ipw_ethtool_get_eeprom, 9971 .get_eeprom = ipw_ethtool_get_eeprom,
6576 .set_eeprom = ipw_ethtool_set_eeprom, 9972 .set_eeprom = ipw_ethtool_set_eeprom,
6577}; 9973};
6578 9974
6579static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs) 9975static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
@@ -6591,8 +9987,8 @@ static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
6591 goto none; 9987 goto none;
6592 } 9988 }
6593 9989
6594 inta = ipw_read32(priv, CX2_INTA_RW); 9990 inta = ipw_read32(priv, IPW_INTA_RW);
6595 inta_mask = ipw_read32(priv, CX2_INTA_MASK_R); 9991 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
6596 9992
6597 if (inta == 0xFFFFFFFF) { 9993 if (inta == 0xFFFFFFFF) {
6598 /* Hardware disappeared */ 9994 /* Hardware disappeared */
@@ -6600,7 +9996,7 @@ static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
6600 goto none; 9996 goto none;
6601 } 9997 }
6602 9998
6603 if (!(inta & (CX2_INTA_MASK_ALL & inta_mask))) { 9999 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
6604 /* Shared interrupt */ 10000 /* Shared interrupt */
6605 goto none; 10001 goto none;
6606 } 10002 }
@@ -6609,8 +10005,8 @@ static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
6609 ipw_disable_interrupts(priv); 10005 ipw_disable_interrupts(priv);
6610 10006
6611 /* ack current interrupts */ 10007 /* ack current interrupts */
6612 inta &= (CX2_INTA_MASK_ALL & inta_mask); 10008 inta &= (IPW_INTA_MASK_ALL & inta_mask);
6613 ipw_write32(priv, CX2_INTA_RW, inta); 10009 ipw_write32(priv, IPW_INTA_RW, inta);
6614 10010
6615 /* Cache INTA value for our tasklet */ 10011 /* Cache INTA value for our tasklet */
6616 priv->isr_inta = inta; 10012 priv->isr_inta = inta;
@@ -6656,28 +10052,116 @@ static void ipw_rf_kill(void *adapter)
6656 spin_unlock_irqrestore(&priv->lock, flags); 10052 spin_unlock_irqrestore(&priv->lock, flags);
6657} 10053}
6658 10054
10055static void ipw_bg_rf_kill(void *data)
10056{
10057 struct ipw_priv *priv = data;
10058 down(&priv->sem);
10059 ipw_rf_kill(data);
10060 up(&priv->sem);
10061}
10062
10063void ipw_link_up(struct ipw_priv *priv)
10064{
10065 priv->last_seq_num = -1;
10066 priv->last_frag_num = -1;
10067 priv->last_packet_time = 0;
10068
10069 netif_carrier_on(priv->net_dev);
10070 if (netif_queue_stopped(priv->net_dev)) {
10071 IPW_DEBUG_NOTIF("waking queue\n");
10072 netif_wake_queue(priv->net_dev);
10073 } else {
10074 IPW_DEBUG_NOTIF("starting queue\n");
10075 netif_start_queue(priv->net_dev);
10076 }
10077
10078 cancel_delayed_work(&priv->request_scan);
10079 ipw_reset_stats(priv);
10080 /* Ensure the rate is updated immediately */
10081 priv->last_rate = ipw_get_current_rate(priv);
10082 ipw_gather_stats(priv);
10083 ipw_led_link_up(priv);
10084 notify_wx_assoc_event(priv);
10085
10086 if (priv->config & CFG_BACKGROUND_SCAN)
10087 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10088}
10089
10090static void ipw_bg_link_up(void *data)
10091{
10092 struct ipw_priv *priv = data;
10093 down(&priv->sem);
10094 ipw_link_up(data);
10095 up(&priv->sem);
10096}
10097
10098void ipw_link_down(struct ipw_priv *priv)
10099{
10100 ipw_led_link_down(priv);
10101 netif_carrier_off(priv->net_dev);
10102 netif_stop_queue(priv->net_dev);
10103 notify_wx_assoc_event(priv);
10104
10105 /* Cancel any queued work ... */
10106 cancel_delayed_work(&priv->request_scan);
10107 cancel_delayed_work(&priv->adhoc_check);
10108 cancel_delayed_work(&priv->gather_stats);
10109
10110 ipw_reset_stats(priv);
10111
10112 if (!(priv->status & STATUS_EXIT_PENDING)) {
10113 /* Queue up another scan... */
10114 queue_work(priv->workqueue, &priv->request_scan);
10115 }
10116}
10117
10118static void ipw_bg_link_down(void *data)
10119{
10120 struct ipw_priv *priv = data;
10121 down(&priv->sem);
10122 ipw_link_down(data);
10123 up(&priv->sem);
10124}
10125
6659static int ipw_setup_deferred_work(struct ipw_priv *priv) 10126static int ipw_setup_deferred_work(struct ipw_priv *priv)
6660{ 10127{
6661 int ret = 0; 10128 int ret = 0;
6662 10129
6663 priv->workqueue = create_workqueue(DRV_NAME); 10130 priv->workqueue = create_workqueue(DRV_NAME);
6664 init_waitqueue_head(&priv->wait_command_queue); 10131 init_waitqueue_head(&priv->wait_command_queue);
6665 10132 init_waitqueue_head(&priv->wait_state);
6666 INIT_WORK(&priv->adhoc_check, ipw_adhoc_check, priv); 10133
6667 INIT_WORK(&priv->associate, ipw_associate, priv); 10134 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
6668 INIT_WORK(&priv->disassociate, ipw_disassociate, priv); 10135 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
6669 INIT_WORK(&priv->rx_replenish, ipw_rx_queue_replenish, priv); 10136 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
6670 INIT_WORK(&priv->adapter_restart, ipw_adapter_restart, priv); 10137 INIT_WORK(&priv->system_config, ipw_system_config, priv);
6671 INIT_WORK(&priv->rf_kill, ipw_rf_kill, priv); 10138 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
6672 INIT_WORK(&priv->up, (void (*)(void *))ipw_up, priv); 10139 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
6673 INIT_WORK(&priv->down, (void (*)(void *))ipw_down, priv); 10140 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10141 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10142 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
6674 INIT_WORK(&priv->request_scan, 10143 INIT_WORK(&priv->request_scan,
6675 (void (*)(void *))ipw_request_scan, priv); 10144 (void (*)(void *))ipw_request_scan, priv);
6676 INIT_WORK(&priv->gather_stats, 10145 INIT_WORK(&priv->gather_stats,
6677 (void (*)(void *))ipw_gather_stats, priv); 10146 (void (*)(void *))ipw_bg_gather_stats, priv);
6678 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_abort_scan, priv); 10147 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
6679 INIT_WORK(&priv->roam, ipw_roam, priv); 10148 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
6680 INIT_WORK(&priv->scan_check, ipw_scan_check, priv); 10149 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10150 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10151 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10152 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
10153 priv);
10154 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
10155 priv);
10156 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10157 priv);
10158 INIT_WORK(&priv->merge_networks,
10159 (void (*)(void *))ipw_merge_adhoc_network, priv);
10160
10161#ifdef CONFIG_IPW_QOS
10162 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10163 priv);
10164#endif /* CONFIG_IPW_QOS */
6681 10165
6682 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) 10166 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
6683 ipw_irq_tasklet, (unsigned long)priv); 10167 ipw_irq_tasklet, (unsigned long)priv);
@@ -6690,34 +10174,36 @@ static void shim__set_security(struct net_device *dev,
6690{ 10174{
6691 struct ipw_priv *priv = ieee80211_priv(dev); 10175 struct ipw_priv *priv = ieee80211_priv(dev);
6692 int i; 10176 int i;
6693
6694 for (i = 0; i < 4; i++) { 10177 for (i = 0; i < 4; i++) {
6695 if (sec->flags & (1 << i)) { 10178 if (sec->flags & (1 << i)) {
6696 priv->sec.key_sizes[i] = sec->key_sizes[i]; 10179 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
10180 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
6697 if (sec->key_sizes[i] == 0) 10181 if (sec->key_sizes[i] == 0)
6698 priv->sec.flags &= ~(1 << i); 10182 priv->ieee->sec.flags &= ~(1 << i);
6699 else 10183 else {
6700 memcpy(priv->sec.keys[i], sec->keys[i], 10184 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
6701 sec->key_sizes[i]); 10185 sec->key_sizes[i]);
6702 priv->sec.flags |= (1 << i); 10186 priv->ieee->sec.flags |= (1 << i);
10187 }
6703 priv->status |= STATUS_SECURITY_UPDATED; 10188 priv->status |= STATUS_SECURITY_UPDATED;
6704 } 10189 } else if (sec->level != SEC_LEVEL_1)
10190 priv->ieee->sec.flags &= ~(1 << i);
6705 } 10191 }
6706 10192
6707 if ((sec->flags & SEC_ACTIVE_KEY) && 10193 if (sec->flags & SEC_ACTIVE_KEY) {
6708 priv->sec.active_key != sec->active_key) {
6709 if (sec->active_key <= 3) { 10194 if (sec->active_key <= 3) {
6710 priv->sec.active_key = sec->active_key; 10195 priv->ieee->sec.active_key = sec->active_key;
6711 priv->sec.flags |= SEC_ACTIVE_KEY; 10196 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
6712 } else 10197 } else
6713 priv->sec.flags &= ~SEC_ACTIVE_KEY; 10198 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
6714 priv->status |= STATUS_SECURITY_UPDATED; 10199 priv->status |= STATUS_SECURITY_UPDATED;
6715 } 10200 } else
10201 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
6716 10202
6717 if ((sec->flags & SEC_AUTH_MODE) && 10203 if ((sec->flags & SEC_AUTH_MODE) &&
6718 (priv->sec.auth_mode != sec->auth_mode)) { 10204 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
6719 priv->sec.auth_mode = sec->auth_mode; 10205 priv->ieee->sec.auth_mode = sec->auth_mode;
6720 priv->sec.flags |= SEC_AUTH_MODE; 10206 priv->ieee->sec.flags |= SEC_AUTH_MODE;
6721 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY) 10207 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
6722 priv->capability |= CAP_SHARED_KEY; 10208 priv->capability |= CAP_SHARED_KEY;
6723 else 10209 else
@@ -6725,9 +10211,9 @@ static void shim__set_security(struct net_device *dev,
6725 priv->status |= STATUS_SECURITY_UPDATED; 10211 priv->status |= STATUS_SECURITY_UPDATED;
6726 } 10212 }
6727 10213
6728 if (sec->flags & SEC_ENABLED && priv->sec.enabled != sec->enabled) { 10214 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
6729 priv->sec.flags |= SEC_ENABLED; 10215 priv->ieee->sec.flags |= SEC_ENABLED;
6730 priv->sec.enabled = sec->enabled; 10216 priv->ieee->sec.enabled = sec->enabled;
6731 priv->status |= STATUS_SECURITY_UPDATED; 10217 priv->status |= STATUS_SECURITY_UPDATED;
6732 if (sec->enabled) 10218 if (sec->enabled)
6733 priv->capability |= CAP_PRIVACY_ON; 10219 priv->capability |= CAP_PRIVACY_ON;
@@ -6735,12 +10221,18 @@ static void shim__set_security(struct net_device *dev,
6735 priv->capability &= ~CAP_PRIVACY_ON; 10221 priv->capability &= ~CAP_PRIVACY_ON;
6736 } 10222 }
6737 10223
6738 if (sec->flags & SEC_LEVEL && priv->sec.level != sec->level) { 10224 if (sec->flags & SEC_ENCRYPT)
6739 priv->sec.level = sec->level; 10225 priv->ieee->sec.encrypt = sec->encrypt;
6740 priv->sec.flags |= SEC_LEVEL; 10226
10227 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10228 priv->ieee->sec.level = sec->level;
10229 priv->ieee->sec.flags |= SEC_LEVEL;
6741 priv->status |= STATUS_SECURITY_UPDATED; 10230 priv->status |= STATUS_SECURITY_UPDATED;
6742 } 10231 }
6743 10232
10233 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10234 ipw_set_hwcrypto_keys(priv);
10235
6744 /* To match current functionality of ipw2100 (which works well w/ 10236 /* To match current functionality of ipw2100 (which works well w/
6745 * various supplicants, we don't force a disassociate if the 10237 * various supplicants, we don't force a disassociate if the
6746 * privacy capability changes ... */ 10238 * privacy capability changes ... */
@@ -6789,29 +10281,10 @@ static int init_supported_rates(struct ipw_priv *priv,
6789 10281
6790static int ipw_config(struct ipw_priv *priv) 10282static int ipw_config(struct ipw_priv *priv)
6791{ 10283{
6792 int i;
6793 struct ipw_tx_power tx_power;
6794
6795 memset(&priv->sys_config, 0, sizeof(priv->sys_config));
6796 memset(&tx_power, 0, sizeof(tx_power));
6797
6798 /* This is only called from ipw_up, which resets/reloads the firmware 10284 /* This is only called from ipw_up, which resets/reloads the firmware
6799 so, we don't need to first disable the card before we configure 10285 so, we don't need to first disable the card before we configure
6800 it */ 10286 it */
6801 10287 if (ipw_set_tx_power(priv))
6802 /* configure device for 'G' band */
6803 tx_power.ieee_mode = IPW_G_MODE;
6804 tx_power.num_channels = 11;
6805 for (i = 0; i < 11; i++) {
6806 tx_power.channels_tx_power[i].channel_number = i + 1;
6807 tx_power.channels_tx_power[i].tx_power = priv->tx_power;
6808 }
6809 if (ipw_send_tx_power(priv, &tx_power))
6810 goto error;
6811
6812 /* configure device to also handle 'B' band */
6813 tx_power.ieee_mode = IPW_B_MODE;
6814 if (ipw_send_tx_power(priv, &tx_power))
6815 goto error; 10288 goto error;
6816 10289
6817 /* initialize adapter address */ 10290 /* initialize adapter address */
@@ -6820,6 +10293,11 @@ static int ipw_config(struct ipw_priv *priv)
6820 10293
6821 /* set basic system config settings */ 10294 /* set basic system config settings */
6822 init_sys_config(&priv->sys_config); 10295 init_sys_config(&priv->sys_config);
10296 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10297 priv->sys_config.answer_broadcast_ssid_probe = 1;
10298 else
10299 priv->sys_config.answer_broadcast_ssid_probe = 0;
10300
6823 if (ipw_send_system_config(priv, &priv->sys_config)) 10301 if (ipw_send_system_config(priv, &priv->sys_config))
6824 goto error; 10302 goto error;
6825 10303
@@ -6832,6 +10310,10 @@ static int ipw_config(struct ipw_priv *priv)
6832 if (ipw_send_rts_threshold(priv, priv->rts_threshold)) 10310 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
6833 goto error; 10311 goto error;
6834 } 10312 }
10313#ifdef CONFIG_IPW_QOS
10314 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10315 ipw_qos_activate(priv, NULL);
10316#endif /* CONFIG_IPW_QOS */
6835 10317
6836 if (ipw_set_random_seed(priv)) 10318 if (ipw_set_random_seed(priv))
6837 goto error; 10319 goto error;
@@ -6840,9 +10322,17 @@ static int ipw_config(struct ipw_priv *priv)
6840 if (ipw_send_host_complete(priv)) 10322 if (ipw_send_host_complete(priv))
6841 goto error; 10323 goto error;
6842 10324
6843 /* If configured to try and auto-associate, kick off a scan */ 10325 priv->status |= STATUS_INIT;
6844 if ((priv->config & CFG_ASSOCIATE) && ipw_request_scan(priv)) 10326
6845 goto error; 10327 ipw_led_init(priv);
10328 ipw_led_radio_on(priv);
10329 priv->notif_missed_beacons = 0;
10330
10331 /* Set hardware WEP key if it is configured. */
10332 if ((priv->capability & CAP_PRIVACY_ON) &&
10333 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10334 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10335 ipw_set_hwcrypto_keys(priv);
6846 10336
6847 return 0; 10337 return 0;
6848 10338
@@ -6850,20 +10340,379 @@ static int ipw_config(struct ipw_priv *priv)
6850 return -EIO; 10340 return -EIO;
6851} 10341}
6852 10342
10343/*
10344 * NOTE:
10345 *
10346 * These tables have been tested in conjunction with the
10347 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10348 *
10349 * Altering this values, using it on other hardware, or in geographies
10350 * not intended for resale of the above mentioned Intel adapters has
10351 * not been tested.
10352 *
10353 */
10354static const struct ieee80211_geo ipw_geos[] = {
10355 { /* Restricted */
10356 "---",
10357 .bg_channels = 11,
10358 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10359 {2427, 4}, {2432, 5}, {2437, 6},
10360 {2442, 7}, {2447, 8}, {2452, 9},
10361 {2457, 10}, {2462, 11}},
10362 },
10363
10364 { /* Custom US/Canada */
10365 "ZZF",
10366 .bg_channels = 11,
10367 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10368 {2427, 4}, {2432, 5}, {2437, 6},
10369 {2442, 7}, {2447, 8}, {2452, 9},
10370 {2457, 10}, {2462, 11}},
10371 .a_channels = 8,
10372 .a = {{5180, 36},
10373 {5200, 40},
10374 {5220, 44},
10375 {5240, 48},
10376 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10377 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10378 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10379 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10380 },
10381
10382 { /* Rest of World */
10383 "ZZD",
10384 .bg_channels = 13,
10385 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10386 {2427, 4}, {2432, 5}, {2437, 6},
10387 {2442, 7}, {2447, 8}, {2452, 9},
10388 {2457, 10}, {2462, 11}, {2467, 12},
10389 {2472, 13}},
10390 },
10391
10392 { /* Custom USA & Europe & High */
10393 "ZZA",
10394 .bg_channels = 11,
10395 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10396 {2427, 4}, {2432, 5}, {2437, 6},
10397 {2442, 7}, {2447, 8}, {2452, 9},
10398 {2457, 10}, {2462, 11}},
10399 .a_channels = 13,
10400 .a = {{5180, 36},
10401 {5200, 40},
10402 {5220, 44},
10403 {5240, 48},
10404 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10405 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10406 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10407 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10408 {5745, 149},
10409 {5765, 153},
10410 {5785, 157},
10411 {5805, 161},
10412 {5825, 165}},
10413 },
10414
10415 { /* Custom NA & Europe */
10416 "ZZB",
10417 .bg_channels = 11,
10418 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10419 {2427, 4}, {2432, 5}, {2437, 6},
10420 {2442, 7}, {2447, 8}, {2452, 9},
10421 {2457, 10}, {2462, 11}},
10422 .a_channels = 13,
10423 .a = {{5180, 36},
10424 {5200, 40},
10425 {5220, 44},
10426 {5240, 48},
10427 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10428 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10429 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10430 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10431 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10432 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10433 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10434 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10435 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10436 },
10437
10438 { /* Custom Japan */
10439 "ZZC",
10440 .bg_channels = 11,
10441 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10442 {2427, 4}, {2432, 5}, {2437, 6},
10443 {2442, 7}, {2447, 8}, {2452, 9},
10444 {2457, 10}, {2462, 11}},
10445 .a_channels = 4,
10446 .a = {{5170, 34}, {5190, 38},
10447 {5210, 42}, {5230, 46}},
10448 },
10449
10450 { /* Custom */
10451 "ZZM",
10452 .bg_channels = 11,
10453 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10454 {2427, 4}, {2432, 5}, {2437, 6},
10455 {2442, 7}, {2447, 8}, {2452, 9},
10456 {2457, 10}, {2462, 11}},
10457 },
10458
10459 { /* Europe */
10460 "ZZE",
10461 .bg_channels = 13,
10462 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10463 {2427, 4}, {2432, 5}, {2437, 6},
10464 {2442, 7}, {2447, 8}, {2452, 9},
10465 {2457, 10}, {2462, 11}, {2467, 12},
10466 {2472, 13}},
10467 .a_channels = 19,
10468 .a = {{5180, 36},
10469 {5200, 40},
10470 {5220, 44},
10471 {5240, 48},
10472 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10473 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10474 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10475 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10476 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10477 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10478 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10479 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10480 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10481 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10482 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10483 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10484 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10485 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10486 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10487 },
10488
10489 { /* Custom Japan */
10490 "ZZJ",
10491 .bg_channels = 14,
10492 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10493 {2427, 4}, {2432, 5}, {2437, 6},
10494 {2442, 7}, {2447, 8}, {2452, 9},
10495 {2457, 10}, {2462, 11}, {2467, 12},
10496 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10497 .a_channels = 4,
10498 .a = {{5170, 34}, {5190, 38},
10499 {5210, 42}, {5230, 46}},
10500 },
10501
10502 { /* Rest of World */
10503 "ZZR",
10504 .bg_channels = 14,
10505 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10506 {2427, 4}, {2432, 5}, {2437, 6},
10507 {2442, 7}, {2447, 8}, {2452, 9},
10508 {2457, 10}, {2462, 11}, {2467, 12},
10509 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
10510 IEEE80211_CH_PASSIVE_ONLY}},
10511 },
10512
10513 { /* High Band */
10514 "ZZH",
10515 .bg_channels = 13,
10516 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10517 {2427, 4}, {2432, 5}, {2437, 6},
10518 {2442, 7}, {2447, 8}, {2452, 9},
10519 {2457, 10}, {2462, 11},
10520 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10521 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10522 .a_channels = 4,
10523 .a = {{5745, 149}, {5765, 153},
10524 {5785, 157}, {5805, 161}},
10525 },
10526
10527 { /* Custom Europe */
10528 "ZZG",
10529 .bg_channels = 13,
10530 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10531 {2427, 4}, {2432, 5}, {2437, 6},
10532 {2442, 7}, {2447, 8}, {2452, 9},
10533 {2457, 10}, {2462, 11},
10534 {2467, 12}, {2472, 13}},
10535 .a_channels = 4,
10536 .a = {{5180, 36}, {5200, 40},
10537 {5220, 44}, {5240, 48}},
10538 },
10539
10540 { /* Europe */
10541 "ZZK",
10542 .bg_channels = 13,
10543 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10544 {2427, 4}, {2432, 5}, {2437, 6},
10545 {2442, 7}, {2447, 8}, {2452, 9},
10546 {2457, 10}, {2462, 11},
10547 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10548 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10549 .a_channels = 24,
10550 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10551 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10552 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10553 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10554 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10555 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10556 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10557 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10558 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10559 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10560 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10561 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10562 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10563 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10564 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10565 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10566 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10567 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10568 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
10569 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10570 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10571 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10572 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10573 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10574 },
10575
10576 { /* Europe */
10577 "ZZL",
10578 .bg_channels = 11,
10579 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10580 {2427, 4}, {2432, 5}, {2437, 6},
10581 {2442, 7}, {2447, 8}, {2452, 9},
10582 {2457, 10}, {2462, 11}},
10583 .a_channels = 13,
10584 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10585 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10586 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10587 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10588 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10589 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10590 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10591 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10592 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10593 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10594 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10595 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10596 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10597 }
10598};
10599
10600/* GEO code borrowed from ieee80211_geo.c */
10601static int ipw_is_valid_channel(struct ieee80211_device *ieee, u8 channel)
10602{
10603 int i;
10604
10605 /* Driver needs to initialize the geography map before using
10606 * these helper functions */
10607 BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
10608
10609 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
10610 for (i = 0; i < ieee->geo.bg_channels; i++)
10611 /* NOTE: If G mode is currently supported but
10612 * this is a B only channel, we don't see it
10613 * as valid. */
10614 if ((ieee->geo.bg[i].channel == channel) &&
10615 (!(ieee->mode & IEEE_G) ||
10616 !(ieee->geo.bg[i].flags & IEEE80211_CH_B_ONLY)))
10617 return IEEE80211_24GHZ_BAND;
10618
10619 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
10620 for (i = 0; i < ieee->geo.a_channels; i++)
10621 if (ieee->geo.a[i].channel == channel)
10622 return IEEE80211_52GHZ_BAND;
10623
10624 return 0;
10625}
10626
10627static int ipw_channel_to_index(struct ieee80211_device *ieee, u8 channel)
10628{
10629 int i;
10630
10631 /* Driver needs to initialize the geography map before using
10632 * these helper functions */
10633 BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
10634
10635 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
10636 for (i = 0; i < ieee->geo.bg_channels; i++)
10637 if (ieee->geo.bg[i].channel == channel)
10638 return i;
10639
10640 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
10641 for (i = 0; i < ieee->geo.a_channels; i++)
10642 if (ieee->geo.a[i].channel == channel)
10643 return i;
10644
10645 return -1;
10646}
10647
10648static u8 ipw_freq_to_channel(struct ieee80211_device *ieee, u32 freq)
10649{
10650 int i;
10651
10652 /* Driver needs to initialize the geography map before using
10653 * these helper functions */
10654 BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
10655
10656 freq /= 100000;
10657
10658 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
10659 for (i = 0; i < ieee->geo.bg_channels; i++)
10660 if (ieee->geo.bg[i].freq == freq)
10661 return ieee->geo.bg[i].channel;
10662
10663 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
10664 for (i = 0; i < ieee->geo.a_channels; i++)
10665 if (ieee->geo.a[i].freq == freq)
10666 return ieee->geo.a[i].channel;
10667
10668 return 0;
10669}
10670
10671static int ipw_set_geo(struct ieee80211_device *ieee,
10672 const struct ieee80211_geo *geo)
10673{
10674 memcpy(ieee->geo.name, geo->name, 3);
10675 ieee->geo.name[3] = '\0';
10676 ieee->geo.bg_channels = geo->bg_channels;
10677 ieee->geo.a_channels = geo->a_channels;
10678 memcpy(ieee->geo.bg, geo->bg, geo->bg_channels *
10679 sizeof(struct ieee80211_channel));
10680 memcpy(ieee->geo.a, geo->a, ieee->geo.a_channels *
10681 sizeof(struct ieee80211_channel));
10682 return 0;
10683}
10684
10685static const struct ieee80211_geo *ipw_get_geo(struct ieee80211_device *ieee)
10686{
10687 return &ieee->geo;
10688}
10689
6853#define MAX_HW_RESTARTS 5 10690#define MAX_HW_RESTARTS 5
6854static int ipw_up(struct ipw_priv *priv) 10691static int ipw_up(struct ipw_priv *priv)
6855{ 10692{
6856 int rc, i; 10693 int rc, i, j;
6857 10694
6858 if (priv->status & STATUS_EXIT_PENDING) 10695 if (priv->status & STATUS_EXIT_PENDING)
6859 return -EIO; 10696 return -EIO;
6860 10697
10698 if (cmdlog && !priv->cmdlog) {
10699 priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
10700 GFP_KERNEL);
10701 if (priv->cmdlog == NULL) {
10702 IPW_ERROR("Error allocating %d command log entries.\n",
10703 cmdlog);
10704 } else {
10705 memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
10706 priv->cmdlog_len = cmdlog;
10707 }
10708 }
10709
6861 for (i = 0; i < MAX_HW_RESTARTS; i++) { 10710 for (i = 0; i < MAX_HW_RESTARTS; i++) {
6862 /* Load the microcode, firmware, and eeprom. 10711 /* Load the microcode, firmware, and eeprom.
6863 * Also start the clocks. */ 10712 * Also start the clocks. */
6864 rc = ipw_load(priv); 10713 rc = ipw_load(priv);
6865 if (rc) { 10714 if (rc) {
6866 IPW_ERROR("Unable to load firmware: 0x%08X\n", rc); 10715 IPW_ERROR("Unable to load firmware: %d\n", rc);
6867 return rc; 10716 return rc;
6868 } 10717 }
6869 10718
@@ -6872,20 +10721,50 @@ static int ipw_up(struct ipw_priv *priv)
6872 eeprom_parse_mac(priv, priv->mac_addr); 10721 eeprom_parse_mac(priv, priv->mac_addr);
6873 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN); 10722 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
6874 10723
6875 if (priv->status & STATUS_RF_KILL_MASK) 10724 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
10725 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
10726 ipw_geos[j].name, 3))
10727 break;
10728 }
10729 if (j == ARRAY_SIZE(ipw_geos)) {
10730 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
10731 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
10732 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
10733 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
10734 j = 0;
10735 }
10736 if (ipw_set_geo(priv->ieee, &ipw_geos[j])) {
10737 IPW_WARNING("Could not set geography.");
10738 return 0;
10739 }
10740
10741 IPW_DEBUG_INFO("Geography %03d [%s] detected.\n",
10742 j, priv->ieee->geo.name);
10743
10744 if (priv->status & STATUS_RF_KILL_SW) {
10745 IPW_WARNING("Radio disabled by module parameter.\n");
10746 return 0;
10747 } else if (rf_kill_active(priv)) {
10748 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
10749 "Kill switch must be turned off for "
10750 "wireless networking to work.\n");
10751 queue_delayed_work(priv->workqueue, &priv->rf_kill,
10752 2 * HZ);
6876 return 0; 10753 return 0;
10754 }
6877 10755
6878 rc = ipw_config(priv); 10756 rc = ipw_config(priv);
6879 if (!rc) { 10757 if (!rc) {
6880 IPW_DEBUG_INFO("Configured device on count %i\n", i); 10758 IPW_DEBUG_INFO("Configured device on count %i\n", i);
6881 priv->notif_missed_beacons = 0; 10759
6882 netif_start_queue(priv->net_dev); 10760 /* If configure to try and auto-associate, kick
10761 * off a scan. */
10762 queue_work(priv->workqueue, &priv->request_scan);
10763
6883 return 0; 10764 return 0;
6884 } else {
6885 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n",
6886 rc);
6887 } 10765 }
6888 10766
10767 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
6889 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n", 10768 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
6890 i, MAX_HW_RESTARTS); 10769 i, MAX_HW_RESTARTS);
6891 10770
@@ -6897,47 +10776,101 @@ static int ipw_up(struct ipw_priv *priv)
6897 /* tried to restart and config the device for as long as our 10776 /* tried to restart and config the device for as long as our
6898 * patience could withstand */ 10777 * patience could withstand */
6899 IPW_ERROR("Unable to initialize device after %d attempts.\n", i); 10778 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
10779
6900 return -EIO; 10780 return -EIO;
6901} 10781}
6902 10782
6903static void ipw_down(struct ipw_priv *priv) 10783static void ipw_bg_up(void *data)
10784{
10785 struct ipw_priv *priv = data;
10786 down(&priv->sem);
10787 ipw_up(data);
10788 up(&priv->sem);
10789}
10790
10791static void ipw_deinit(struct ipw_priv *priv)
6904{ 10792{
10793 int i;
10794
10795 if (priv->status & STATUS_SCANNING) {
10796 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
10797 ipw_abort_scan(priv);
10798 }
10799
10800 if (priv->status & STATUS_ASSOCIATED) {
10801 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
10802 ipw_disassociate(priv);
10803 }
10804
10805 ipw_led_shutdown(priv);
10806
10807 /* Wait up to 1s for status to change to not scanning and not
10808 * associated (disassociation can take a while for a ful 802.11
10809 * exchange */
10810 for (i = 1000; i && (priv->status &
10811 (STATUS_DISASSOCIATING |
10812 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
10813 udelay(10);
10814
10815 if (priv->status & (STATUS_DISASSOCIATING |
10816 STATUS_ASSOCIATED | STATUS_SCANNING))
10817 IPW_DEBUG_INFO("Still associated or scanning...\n");
10818 else
10819 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
10820
6905 /* Attempt to disable the card */ 10821 /* Attempt to disable the card */
6906#if 0
6907 ipw_send_card_disable(priv, 0); 10822 ipw_send_card_disable(priv, 0);
6908#endif 10823
10824 priv->status &= ~STATUS_INIT;
10825}
10826
10827static void ipw_down(struct ipw_priv *priv)
10828{
10829 int exit_pending = priv->status & STATUS_EXIT_PENDING;
10830
10831 priv->status |= STATUS_EXIT_PENDING;
10832
10833 if (ipw_is_init(priv))
10834 ipw_deinit(priv);
10835
10836 /* Wipe out the EXIT_PENDING status bit if we are not actually
10837 * exiting the module */
10838 if (!exit_pending)
10839 priv->status &= ~STATUS_EXIT_PENDING;
6909 10840
6910 /* tell the device to stop sending interrupts */ 10841 /* tell the device to stop sending interrupts */
6911 ipw_disable_interrupts(priv); 10842 ipw_disable_interrupts(priv);
6912 10843
6913 /* Clear all bits but the RF Kill */ 10844 /* Clear all bits but the RF Kill */
6914 priv->status &= STATUS_RF_KILL_MASK; 10845 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
6915
6916 netif_carrier_off(priv->net_dev); 10846 netif_carrier_off(priv->net_dev);
6917 netif_stop_queue(priv->net_dev); 10847 netif_stop_queue(priv->net_dev);
6918 10848
6919 ipw_stop_nic(priv); 10849 ipw_stop_nic(priv);
10850
10851 ipw_led_radio_off(priv);
10852}
10853
10854static void ipw_bg_down(void *data)
10855{
10856 struct ipw_priv *priv = data;
10857 down(&priv->sem);
10858 ipw_down(data);
10859 up(&priv->sem);
6920} 10860}
6921 10861
6922/* Called by register_netdev() */ 10862/* Called by register_netdev() */
6923static int ipw_net_init(struct net_device *dev) 10863static int ipw_net_init(struct net_device *dev)
6924{ 10864{
6925 struct ipw_priv *priv = ieee80211_priv(dev); 10865 struct ipw_priv *priv = ieee80211_priv(dev);
10866 down(&priv->sem);
6926 10867
6927 if (priv->status & STATUS_RF_KILL_SW) { 10868 if (ipw_up(priv)) {
6928 IPW_WARNING("Radio disabled by module parameter.\n"); 10869 up(&priv->sem);
6929 return 0;
6930 } else if (rf_kill_active(priv)) {
6931 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
6932 "Kill switch must be turned off for "
6933 "wireless networking to work.\n");
6934 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
6935 return 0;
6936 }
6937
6938 if (ipw_up(priv))
6939 return -EIO; 10870 return -EIO;
10871 }
6940 10872
10873 up(&priv->sem);
6941 return 0; 10874 return 0;
6942} 10875}
6943 10876
@@ -6962,7 +10895,7 @@ static struct pci_device_id card_ids[] = {
6962 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0}, 10895 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
6963 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 10896 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
6964 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */ 10897 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
6965 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 2225BG */ 10898 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
6966 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ 10899 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
6967 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */ 10900 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
6968 10901
@@ -6982,11 +10915,16 @@ static struct attribute *ipw_sysfs_entries[] = {
6982 &dev_attr_nic_type.attr, 10915 &dev_attr_nic_type.attr,
6983 &dev_attr_status.attr, 10916 &dev_attr_status.attr,
6984 &dev_attr_cfg.attr, 10917 &dev_attr_cfg.attr,
6985 &dev_attr_dump_errors.attr, 10918 &dev_attr_error.attr,
6986 &dev_attr_dump_events.attr, 10919 &dev_attr_event_log.attr,
10920 &dev_attr_cmd_log.attr,
6987 &dev_attr_eeprom_delay.attr, 10921 &dev_attr_eeprom_delay.attr,
6988 &dev_attr_ucode_version.attr, 10922 &dev_attr_ucode_version.attr,
6989 &dev_attr_rtc.attr, 10923 &dev_attr_rtc.attr,
10924 &dev_attr_scan_age.attr,
10925 &dev_attr_led.attr,
10926 &dev_attr_speed_scan.attr,
10927 &dev_attr_net_stats.attr,
6990 NULL 10928 NULL
6991}; 10929};
6992 10930
@@ -7002,7 +10940,7 @@ static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7002 void __iomem *base; 10940 void __iomem *base;
7003 u32 length, val; 10941 u32 length, val;
7004 struct ipw_priv *priv; 10942 struct ipw_priv *priv;
7005 int band, modulation; 10943 int i;
7006 10944
7007 net_dev = alloc_ieee80211(sizeof(struct ipw_priv)); 10945 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
7008 if (net_dev == NULL) { 10946 if (net_dev == NULL) {
@@ -7012,13 +10950,17 @@ static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7012 10950
7013 priv = ieee80211_priv(net_dev); 10951 priv = ieee80211_priv(net_dev);
7014 priv->ieee = netdev_priv(net_dev); 10952 priv->ieee = netdev_priv(net_dev);
10953
7015 priv->net_dev = net_dev; 10954 priv->net_dev = net_dev;
7016 priv->pci_dev = pdev; 10955 priv->pci_dev = pdev;
7017#ifdef CONFIG_IPW_DEBUG 10956#ifdef CONFIG_IPW_DEBUG
7018 ipw_debug_level = debug; 10957 ipw_debug_level = debug;
7019#endif 10958#endif
7020 spin_lock_init(&priv->lock); 10959 spin_lock_init(&priv->lock);
10960 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
10961 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
7021 10962
10963 init_MUTEX(&priv->sem);
7022 if (pci_enable_device(pdev)) { 10964 if (pci_enable_device(pdev)) {
7023 err = -ENODEV; 10965 err = -ENODEV;
7024 goto out_free_ieee80211; 10966 goto out_free_ieee80211;
@@ -7065,90 +11007,7 @@ static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7065 goto out_iounmap; 11007 goto out_iounmap;
7066 } 11008 }
7067 11009
7068 /* Initialize module parameter values here */ 11010 ipw_sw_reset(priv, 1);
7069 if (ifname)
7070 strncpy(net_dev->name, ifname, IFNAMSIZ);
7071
7072 if (associate)
7073 priv->config |= CFG_ASSOCIATE;
7074 else
7075 IPW_DEBUG_INFO("Auto associate disabled.\n");
7076
7077 if (auto_create)
7078 priv->config |= CFG_ADHOC_CREATE;
7079 else
7080 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
7081
7082 if (disable) {
7083 priv->status |= STATUS_RF_KILL_SW;
7084 IPW_DEBUG_INFO("Radio disabled.\n");
7085 }
7086
7087 if (channel != 0) {
7088 priv->config |= CFG_STATIC_CHANNEL;
7089 priv->channel = channel;
7090 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
7091 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
7092 /* TODO: Validate that provided channel is in range */
7093 }
7094
7095 switch (mode) {
7096 case 1:
7097 priv->ieee->iw_mode = IW_MODE_ADHOC;
7098 break;
7099#ifdef CONFIG_IPW_PROMISC
7100 case 2:
7101 priv->ieee->iw_mode = IW_MODE_MONITOR;
7102 break;
7103#endif
7104 default:
7105 case 0:
7106 priv->ieee->iw_mode = IW_MODE_INFRA;
7107 break;
7108 }
7109
7110 if ((priv->pci_dev->device == 0x4223) ||
7111 (priv->pci_dev->device == 0x4224)) {
7112 printk(KERN_INFO DRV_NAME
7113 ": Detected Intel PRO/Wireless 2915ABG Network "
7114 "Connection\n");
7115 priv->ieee->abg_true = 1;
7116 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
7117 modulation = IEEE80211_OFDM_MODULATION |
7118 IEEE80211_CCK_MODULATION;
7119 priv->adapter = IPW_2915ABG;
7120 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
7121 } else {
7122 if (priv->pci_dev->device == 0x4221)
7123 printk(KERN_INFO DRV_NAME
7124 ": Detected Intel PRO/Wireless 2225BG Network "
7125 "Connection\n");
7126 else
7127 printk(KERN_INFO DRV_NAME
7128 ": Detected Intel PRO/Wireless 2200BG Network "
7129 "Connection\n");
7130
7131 priv->ieee->abg_true = 0;
7132 band = IEEE80211_24GHZ_BAND;
7133 modulation = IEEE80211_OFDM_MODULATION |
7134 IEEE80211_CCK_MODULATION;
7135 priv->adapter = IPW_2200BG;
7136 priv->ieee->mode = IEEE_G | IEEE_B;
7137 }
7138
7139 priv->ieee->freq_band = band;
7140 priv->ieee->modulation = modulation;
7141
7142 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
7143
7144 priv->missed_beacon_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
7145 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
7146
7147 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
7148
7149 /* If power management is turned on, default to AC mode */
7150 priv->power_mode = IPW_POWER_AC;
7151 priv->tx_power = IPW_DEFAULT_TX_POWER;
7152 11011
7153 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv); 11012 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
7154 if (err) { 11013 if (err) {
@@ -7159,8 +11018,20 @@ static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7159 SET_MODULE_OWNER(net_dev); 11018 SET_MODULE_OWNER(net_dev);
7160 SET_NETDEV_DEV(net_dev, &pdev->dev); 11019 SET_NETDEV_DEV(net_dev, &pdev->dev);
7161 11020
11021 down(&priv->sem);
11022
7162 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit; 11023 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
7163 priv->ieee->set_security = shim__set_security; 11024 priv->ieee->set_security = shim__set_security;
11025 priv->ieee->is_queue_full = ipw_net_is_queue_full;
11026
11027#ifdef CONFIG_IPW_QOS
11028 priv->ieee->handle_probe_response = ipw_handle_beacon;
11029 priv->ieee->handle_beacon = ipw_handle_probe_response;
11030 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
11031#endif /* CONFIG_IPW_QOS */
11032
11033 priv->ieee->perfect_rssi = -20;
11034 priv->ieee->worst_rssi = -85;
7164 11035
7165 net_dev->open = ipw_net_open; 11036 net_dev->open = ipw_net_open;
7166 net_dev->stop = ipw_net_stop; 11037 net_dev->stop = ipw_net_stop;
@@ -7168,7 +11039,9 @@ static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7168 net_dev->get_stats = ipw_net_get_stats; 11039 net_dev->get_stats = ipw_net_get_stats;
7169 net_dev->set_multicast_list = ipw_net_set_multicast_list; 11040 net_dev->set_multicast_list = ipw_net_set_multicast_list;
7170 net_dev->set_mac_address = ipw_net_set_mac_address; 11041 net_dev->set_mac_address = ipw_net_set_mac_address;
7171 net_dev->get_wireless_stats = ipw_get_wireless_stats; 11042 priv->wireless_data.spy_data = &priv->ieee->spy_data;
11043 priv->wireless_data.ieee80211 = priv->ieee;
11044 net_dev->wireless_data = &priv->wireless_data;
7172 net_dev->wireless_handlers = &ipw_wx_handler_def; 11045 net_dev->wireless_handlers = &ipw_wx_handler_def;
7173 net_dev->ethtool_ops = &ipw_ethtool_ops; 11046 net_dev->ethtool_ops = &ipw_ethtool_ops;
7174 net_dev->irq = pdev->irq; 11047 net_dev->irq = pdev->irq;
@@ -7179,18 +11052,19 @@ static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7179 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group); 11052 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
7180 if (err) { 11053 if (err) {
7181 IPW_ERROR("failed to create sysfs device attributes\n"); 11054 IPW_ERROR("failed to create sysfs device attributes\n");
11055 up(&priv->sem);
7182 goto out_release_irq; 11056 goto out_release_irq;
7183 } 11057 }
7184 11058
11059 up(&priv->sem);
7185 err = register_netdev(net_dev); 11060 err = register_netdev(net_dev);
7186 if (err) { 11061 if (err) {
7187 IPW_ERROR("failed to register network device\n"); 11062 IPW_ERROR("failed to register network device\n");
7188 goto out_remove_group; 11063 goto out_remove_sysfs;
7189 } 11064 }
7190
7191 return 0; 11065 return 0;
7192 11066
7193 out_remove_group: 11067 out_remove_sysfs:
7194 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); 11068 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
7195 out_release_irq: 11069 out_release_irq:
7196 free_irq(pdev->irq, priv); 11070 free_irq(pdev->irq, priv);
@@ -7213,14 +11087,19 @@ static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7213static void ipw_pci_remove(struct pci_dev *pdev) 11087static void ipw_pci_remove(struct pci_dev *pdev)
7214{ 11088{
7215 struct ipw_priv *priv = pci_get_drvdata(pdev); 11089 struct ipw_priv *priv = pci_get_drvdata(pdev);
11090 struct list_head *p, *q;
11091 int i;
11092
7216 if (!priv) 11093 if (!priv)
7217 return; 11094 return;
7218 11095
7219 priv->status |= STATUS_EXIT_PENDING; 11096 down(&priv->sem);
7220 11097
11098 priv->status |= STATUS_EXIT_PENDING;
11099 ipw_down(priv);
7221 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group); 11100 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
7222 11101
7223 ipw_down(priv); 11102 up(&priv->sem);
7224 11103
7225 unregister_netdev(priv->net_dev); 11104 unregister_netdev(priv->net_dev);
7226 11105
@@ -7230,16 +11109,31 @@ static void ipw_pci_remove(struct pci_dev *pdev)
7230 } 11109 }
7231 ipw_tx_queue_free(priv); 11110 ipw_tx_queue_free(priv);
7232 11111
11112 if (priv->cmdlog) {
11113 kfree(priv->cmdlog);
11114 priv->cmdlog = NULL;
11115 }
7233 /* ipw_down will ensure that there is no more pending work 11116 /* ipw_down will ensure that there is no more pending work
7234 * in the workqueue's, so we can safely remove them now. */ 11117 * in the workqueue's, so we can safely remove them now. */
7235 if (priv->workqueue) { 11118 cancel_delayed_work(&priv->adhoc_check);
7236 cancel_delayed_work(&priv->adhoc_check); 11119 cancel_delayed_work(&priv->gather_stats);
7237 cancel_delayed_work(&priv->gather_stats); 11120 cancel_delayed_work(&priv->request_scan);
7238 cancel_delayed_work(&priv->request_scan); 11121 cancel_delayed_work(&priv->rf_kill);
7239 cancel_delayed_work(&priv->rf_kill); 11122 cancel_delayed_work(&priv->scan_check);
7240 cancel_delayed_work(&priv->scan_check); 11123 destroy_workqueue(priv->workqueue);
7241 destroy_workqueue(priv->workqueue); 11124 priv->workqueue = NULL;
7242 priv->workqueue = NULL; 11125
11126 /* Free MAC hash list for ADHOC */
11127 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11128 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
11129 kfree(list_entry(p, struct ipw_ibss_seq, list));
11130 list_del(p);
11131 }
11132 }
11133
11134 if (priv->error) {
11135 ipw_free_error_log(priv->error);
11136 priv->error = NULL;
7243 } 11137 }
7244 11138
7245 free_irq(pdev->irq, priv); 11139 free_irq(pdev->irq, priv);
@@ -7248,15 +11142,7 @@ static void ipw_pci_remove(struct pci_dev *pdev)
7248 pci_disable_device(pdev); 11142 pci_disable_device(pdev);
7249 pci_set_drvdata(pdev, NULL); 11143 pci_set_drvdata(pdev, NULL);
7250 free_ieee80211(priv->net_dev); 11144 free_ieee80211(priv->net_dev);
7251 11145 free_firmware();
7252#ifdef CONFIG_PM
7253 if (fw_loaded) {
7254 release_firmware(bootfw);
7255 release_firmware(ucode);
7256 release_firmware(firmware);
7257 fw_loaded = 0;
7258 }
7259#endif
7260} 11146}
7261 11147
7262#ifdef CONFIG_PM 11148#ifdef CONFIG_PM
@@ -7288,13 +11174,10 @@ static int ipw_pci_resume(struct pci_dev *pdev)
7288 11174
7289 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name); 11175 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
7290 11176
7291 pci_set_power_state(pdev, 0); 11177 pci_set_power_state(pdev, PCI_D0);
7292 pci_enable_device(pdev); 11178 pci_enable_device(pdev);
7293#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
7294 pci_restore_state(pdev, priv->pm_state);
7295#else
7296 pci_restore_state(pdev); 11179 pci_restore_state(pdev);
7297#endif 11180
7298 /* 11181 /*
7299 * Suspend/Resume resets the PCI configuration space, so we have to 11182 * Suspend/Resume resets the PCI configuration space, so we have to
7300 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries 11183 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
@@ -7366,16 +11249,33 @@ MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
7366module_param(auto_create, int, 0444); 11249module_param(auto_create, int, 0444);
7367MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)"); 11250MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
7368 11251
11252module_param(led, int, 0444);
11253MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
11254
7369module_param(debug, int, 0444); 11255module_param(debug, int, 0444);
7370MODULE_PARM_DESC(debug, "debug output mask"); 11256MODULE_PARM_DESC(debug, "debug output mask");
7371 11257
7372module_param(channel, int, 0444); 11258module_param(channel, int, 0444);
7373MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])"); 11259MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
7374 11260
7375module_param(ifname, charp, 0444); 11261#ifdef CONFIG_IPW_QOS
7376MODULE_PARM_DESC(ifname, "network device name (default eth%d)"); 11262module_param(qos_enable, int, 0444);
11263MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
11264
11265module_param(qos_burst_enable, int, 0444);
11266MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11267
11268module_param(qos_no_ack_mask, int, 0444);
11269MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
7377 11270
7378#ifdef CONFIG_IPW_PROMISC 11271module_param(burst_duration_CCK, int, 0444);
11272MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11273
11274module_param(burst_duration_OFDM, int, 0444);
11275MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11276#endif /* CONFIG_IPW_QOS */
11277
11278#ifdef CONFIG_IPW2200_MONITOR
7379module_param(mode, int, 0444); 11279module_param(mode, int, 0444);
7380MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)"); 11280MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
7381#else 11281#else
@@ -7383,5 +11283,12 @@ module_param(mode, int, 0444);
7383MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)"); 11283MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
7384#endif 11284#endif
7385 11285
11286module_param(hwcrypto, int, 0444);
11287MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default on)");
11288
11289module_param(cmdlog, int, 0444);
11290MODULE_PARM_DESC(cmdlog,
11291 "allocate a ring buffer for logging firmware commands");
11292
7386module_exit(ipw_exit); 11293module_exit(ipw_exit);
7387module_init(ipw_init); 11294module_init(ipw_init);