~asac/intellinuxwireless/ipw2200.upstream

« back to all changes in this revision

Viewing changes to ipw2200.c

  • Committer: Alexander Sack
  • Date: 2007-09-12 14:51:51 UTC
  • Revision ID: asac@jwsdot.com-20070912145151-r6ll6icpjia3fjty
upstream 1.2.1 release

Show diffs side-by-side

added added

removed removed

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