blob: ddbee3edcd8c5fa9e90c12e59aedf25f3da2f847 [file] [log] [blame]
James Ketrenos43f66a62005-03-25 12:31:53 -06001/******************************************************************************
Jeff Garzikbf794512005-07-31 13:07:26 -04002
James Ketrenos43f66a62005-03-25 12:31:53 -06003 Copyright(c) 2003 - 2004 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
Jeff Garzikbf794512005-07-31 13:07:26 -040011 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
James Ketrenos43f66a62005-03-25 12:31:53 -060013 published by the Free Software Foundation.
Jeff Garzikbf794512005-07-31 13:07:26 -040014
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
James Ketrenos43f66a62005-03-25 12:31:53 -060018 more details.
Jeff Garzikbf794512005-07-31 13:07:26 -040019
James Ketrenos43f66a62005-03-25 12:31:53 -060020 You should have received a copy of the GNU General Public License along with
Jeff Garzikbf794512005-07-31 13:07:26 -040021 this program; if not, write to the Free Software Foundation, Inc., 59
James Ketrenos43f66a62005-03-25 12:31:53 -060022 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Jeff Garzikbf794512005-07-31 13:07:26 -040023
James Ketrenos43f66a62005-03-25 12:31:53 -060024 The full GNU General Public License is included in this distribution in the
25 file called LICENSE.
Jeff Garzikbf794512005-07-31 13:07:26 -040026
James Ketrenos43f66a62005-03-25 12:31:53 -060027 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
James Ketrenosea2b26e2005-08-24 21:25:16 -050035#define IPW2200_VERSION "1.0.1"
James Ketrenos43f66a62005-03-25 12:31:53 -060036#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
37#define DRV_COPYRIGHT "Copyright(c) 2003-2004 Intel Corporation"
38#define DRV_VERSION IPW2200_VERSION
39
40MODULE_DESCRIPTION(DRV_DESCRIPTION);
41MODULE_VERSION(DRV_VERSION);
42MODULE_AUTHOR(DRV_COPYRIGHT);
43MODULE_LICENSE("GPL");
44
45static int debug = 0;
46static int channel = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060047static int mode = 0;
48
49static u32 ipw_debug_level;
50static int associate = 1;
51static int auto_create = 1;
52static int disable = 0;
53static const char ipw_modes[] = {
54 'a', 'b', 'g', '?'
55};
56
57static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040058static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060059 struct clx2_tx_queue *txq, int qindex);
60static int ipw_queue_reset(struct ipw_priv *priv);
61
62static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
63 int len, int sync);
64
65static void ipw_tx_queue_free(struct ipw_priv *);
66
67static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
68static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
69static void ipw_rx_queue_replenish(void *);
70
71static int ipw_up(struct ipw_priv *);
72static void ipw_down(struct ipw_priv *);
73static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040074static int init_supported_rates(struct ipw_priv *priv,
75 struct ipw_supported_rates *prates);
James Ketrenos43f66a62005-03-25 12:31:53 -060076
77static u8 band_b_active_channel[MAX_B_CHANNELS] = {
78 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0
79};
80static u8 band_a_active_channel[MAX_A_CHANNELS] = {
81 36, 40, 44, 48, 149, 153, 157, 161, 165, 52, 56, 60, 64, 0
82};
83
84static int is_valid_channel(int mode_mask, int channel)
85{
86 int i;
87
88 if (!channel)
89 return 0;
90
91 if (mode_mask & IEEE_A)
92 for (i = 0; i < MAX_A_CHANNELS; i++)
93 if (band_a_active_channel[i] == channel)
94 return IEEE_A;
95
96 if (mode_mask & (IEEE_B | IEEE_G))
97 for (i = 0; i < MAX_B_CHANNELS; i++)
98 if (band_b_active_channel[i] == channel)
99 return mode_mask & (IEEE_B | IEEE_G);
100
101 return 0;
102}
103
Jeff Garzikbf794512005-07-31 13:07:26 -0400104static char *snprint_line(char *buf, size_t count,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400105 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600106{
107 int out, i, j, l;
108 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400109
James Ketrenos43f66a62005-03-25 12:31:53 -0600110 out = snprintf(buf, count, "%08X", ofs);
111
112 for (l = 0, i = 0; i < 2; i++) {
113 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400114 for (j = 0; j < 8 && l < len; j++, l++)
115 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600116 data[(i * 8 + j)]);
117 for (; j < 8; j++)
118 out += snprintf(buf + out, count - out, " ");
119 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400120
James Ketrenos43f66a62005-03-25 12:31:53 -0600121 out += snprintf(buf + out, count - out, " ");
122 for (l = 0, i = 0; i < 2; i++) {
123 out += snprintf(buf + out, count - out, " ");
124 for (j = 0; j < 8 && l < len; j++, l++) {
125 c = data[(i * 8 + j)];
126 if (!isascii(c) || !isprint(c))
127 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400128
James Ketrenos43f66a62005-03-25 12:31:53 -0600129 out += snprintf(buf + out, count - out, "%c", c);
130 }
131
132 for (; j < 8; j++)
133 out += snprintf(buf + out, count - out, " ");
134 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400135
James Ketrenos43f66a62005-03-25 12:31:53 -0600136 return buf;
137}
138
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400139static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600140{
141 char line[81];
142 u32 ofs = 0;
143 if (!(ipw_debug_level & level))
144 return;
145
146 while (len) {
147 printk(KERN_DEBUG "%s\n",
Jeff Garzikbf794512005-07-31 13:07:26 -0400148 snprint_line(line, sizeof(line), &data[ofs],
James Ketrenos43f66a62005-03-25 12:31:53 -0600149 min(len, 16U), ofs));
150 ofs += 16;
151 len -= min(len, 16U);
152 }
153}
154
155static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
156#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
157
158static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
159#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
160
161static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
162static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
163{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400164 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
165 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600166 _ipw_write_reg8(a, b, c);
167}
168
169static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
170static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
171{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400172 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
173 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600174 _ipw_write_reg16(a, b, c);
175}
176
177static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
178static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
179{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400180 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
181 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600182 _ipw_write_reg32(a, b, c);
183}
184
185#define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
186#define ipw_write8(ipw, ofs, val) \
187 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
188 _ipw_write8(ipw, ofs, val)
189
190#define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
191#define ipw_write16(ipw, ofs, val) \
192 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
193 _ipw_write16(ipw, ofs, val)
194
195#define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
196#define ipw_write32(ipw, ofs, val) \
197 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
198 _ipw_write32(ipw, ofs, val)
199
200#define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400201static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
202{
203 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600204 return _ipw_read8(ipw, ofs);
205}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400206
James Ketrenos43f66a62005-03-25 12:31:53 -0600207#define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
208
209#define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400210static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
211{
212 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600213 return _ipw_read16(ipw, ofs);
214}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400215
James Ketrenos43f66a62005-03-25 12:31:53 -0600216#define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
217
218#define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400219static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
220{
221 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600222 return _ipw_read32(ipw, ofs);
223}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400224
James Ketrenos43f66a62005-03-25 12:31:53 -0600225#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
226
227static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
228#define ipw_read_indirect(a, b, c, d) \
229 IPW_DEBUG_IO("%s %d: read_inddirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
230 _ipw_read_indirect(a, b, c, d)
231
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400232static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
233 int num);
James Ketrenos43f66a62005-03-25 12:31:53 -0600234#define ipw_write_indirect(a, b, c, d) \
235 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
236 _ipw_write_indirect(a, b, c, d)
237
238/* indirect write s */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400239static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600240{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400241 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600242 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg);
243 _ipw_write32(priv, CX2_INDIRECT_DATA, value);
244}
245
James Ketrenos43f66a62005-03-25 12:31:53 -0600246static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
247{
248 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
249 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK);
250 _ipw_write8(priv, CX2_INDIRECT_DATA, value);
Jeff Garzikbf794512005-07-31 13:07:26 -0400251 IPW_DEBUG_IO(" reg = 0x%8lX : value = 0x%8X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400252 (unsigned long)(priv->hw_base + CX2_INDIRECT_DATA), value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600253}
254
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400255static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600256{
257 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
258 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK);
259 _ipw_write16(priv, CX2_INDIRECT_DATA, value);
260}
261
262/* indirect read s */
263
264static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
265{
266 u32 word;
267 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK);
268 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
269 word = _ipw_read32(priv, CX2_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400270 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600271}
272
273static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
274{
275 u32 value;
276
277 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
278
279 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg);
280 value = _ipw_read32(priv, CX2_INDIRECT_DATA);
281 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
282 return value;
283}
284
285/* iterative/auto-increment 32 bit reads and writes */
286static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
287 int num)
288{
289 u32 aligned_addr = addr & CX2_INDIRECT_ADDR_MASK;
290 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600291 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400292
James Ketrenos43f66a62005-03-25 12:31:53 -0600293 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
294
James Ketrenosea2b26e2005-08-24 21:25:16 -0500295 if (num <= 0) {
296 return;
297 }
298
James Ketrenos43f66a62005-03-25 12:31:53 -0600299 /* Read the first nibble byte by byte */
300 if (unlikely(dif_len)) {
James Ketrenos43f66a62005-03-25 12:31:53 -0600301 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500302 /* Start reading at aligned_addr + dif_len */
303 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
304 *buf++ = _ipw_read8(priv, CX2_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600305 aligned_addr += 4;
306 }
307
James Ketrenos43f66a62005-03-25 12:31:53 -0600308 _ipw_write32(priv, CX2_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500309 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
310 *(u32 *) buf = _ipw_read32(priv, CX2_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400311
James Ketrenos43f66a62005-03-25 12:31:53 -0600312 /* Copy the last nibble */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500313 if (unlikely(num)) {
314 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
315 for (i = 0; num > 0; i++, num--)
316 *buf++ = ipw_read8(priv, CX2_INDIRECT_DATA + i);
317 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600318}
319
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400320static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600321 int num)
322{
323 u32 aligned_addr = addr & CX2_INDIRECT_ADDR_MASK;
324 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600325 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400326
James Ketrenos43f66a62005-03-25 12:31:53 -0600327 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400328
James Ketrenosea2b26e2005-08-24 21:25:16 -0500329 if (num <= 0) {
330 return;
331 }
332
James Ketrenos43f66a62005-03-25 12:31:53 -0600333 /* Write the first nibble byte by byte */
334 if (unlikely(dif_len)) {
James Ketrenos43f66a62005-03-25 12:31:53 -0600335 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500336 /* Start reading at aligned_addr + dif_len */
337 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenos43f66a62005-03-25 12:31:53 -0600338 _ipw_write8(priv, CX2_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600339 aligned_addr += 4;
340 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400341
James Ketrenos43f66a62005-03-25 12:31:53 -0600342 _ipw_write32(priv, CX2_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500343 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400344 _ipw_write32(priv, CX2_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400345
James Ketrenos43f66a62005-03-25 12:31:53 -0600346 /* Copy the last nibble */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500347 if (unlikely(num)) {
348 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
349 for (i = 0; num > 0; i++, num--, buf++)
350 _ipw_write8(priv, CX2_INDIRECT_DATA + i, *buf);
351 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600352}
353
Jeff Garzikbf794512005-07-31 13:07:26 -0400354static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600355 int num)
356{
357 memcpy_toio((priv->hw_base + addr), buf, num);
358}
359
360static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
361{
362 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
363}
364
365static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
366{
367 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
368}
369
370static inline void ipw_enable_interrupts(struct ipw_priv *priv)
371{
372 if (priv->status & STATUS_INT_ENABLED)
373 return;
374 priv->status |= STATUS_INT_ENABLED;
375 ipw_write32(priv, CX2_INTA_MASK_R, CX2_INTA_MASK_ALL);
376}
377
378static inline void ipw_disable_interrupts(struct ipw_priv *priv)
379{
380 if (!(priv->status & STATUS_INT_ENABLED))
381 return;
382 priv->status &= ~STATUS_INT_ENABLED;
383 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL);
384}
385
386static char *ipw_error_desc(u32 val)
387{
388 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400389 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600390 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400391 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600392 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400393 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600394 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400395 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600396 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400397 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenos43f66a62005-03-25 12:31:53 -0600398 return "ERROR_BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400399 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenos43f66a62005-03-25 12:31:53 -0600400 return "ERROR_BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400401 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenos43f66a62005-03-25 12:31:53 -0600402 return "ERROR_NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400403 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenos43f66a62005-03-25 12:31:53 -0600404 return "ERROR_BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400405 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600406 return "ERROR_ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400407 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenos43f66a62005-03-25 12:31:53 -0600408 return "ERROR_DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400409 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenos43f66a62005-03-25 12:31:53 -0600410 return "ERROR_DMA_STATUS";
Jeff Garzikbf794512005-07-31 13:07:26 -0400411 case IPW_FW_ERROR_DINOSTATUS_ERROR:
James Ketrenos43f66a62005-03-25 12:31:53 -0600412 return "ERROR_DINOSTATUS_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400413 case IPW_FW_ERROR_EEPROMSTATUS_ERROR:
James Ketrenos43f66a62005-03-25 12:31:53 -0600414 return "ERROR_EEPROMSTATUS_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400415 case IPW_FW_ERROR_SYSASSERT:
James Ketrenos43f66a62005-03-25 12:31:53 -0600416 return "ERROR_SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400417 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenos43f66a62005-03-25 12:31:53 -0600418 return "ERROR_FATALSTATUS_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400419 default:
James Ketrenos43f66a62005-03-25 12:31:53 -0600420 return "UNKNOWNSTATUS_ERROR";
421 }
422}
423
424static void ipw_dump_nic_error_log(struct ipw_priv *priv)
425{
426 u32 desc, time, blink1, blink2, ilink1, ilink2, idata, i, count, base;
427
428 base = ipw_read32(priv, IPWSTATUS_ERROR_LOG);
429 count = ipw_read_reg32(priv, base);
Jeff Garzikbf794512005-07-31 13:07:26 -0400430
James Ketrenos43f66a62005-03-25 12:31:53 -0600431 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
432 IPW_ERROR("Start IPW Error Log Dump:\n");
433 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
434 priv->status, priv->config);
435 }
436
Jeff Garzikbf794512005-07-31 13:07:26 -0400437 for (i = ERROR_START_OFFSET;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400438 i <= count * ERROR_ELEM_SIZE; i += ERROR_ELEM_SIZE) {
439 desc = ipw_read_reg32(priv, base + i);
440 time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
441 blink1 = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
442 blink2 = ipw_read_reg32(priv, base + i + 3 * sizeof(u32));
443 ilink1 = ipw_read_reg32(priv, base + i + 4 * sizeof(u32));
444 ilink2 = ipw_read_reg32(priv, base + i + 5 * sizeof(u32));
445 idata = ipw_read_reg32(priv, base + i + 6 * sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600446
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400447 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
448 ipw_error_desc(desc), time, blink1, blink2,
449 ilink1, ilink2, idata);
James Ketrenos43f66a62005-03-25 12:31:53 -0600450 }
451}
452
453static void ipw_dump_nic_event_log(struct ipw_priv *priv)
454{
455 u32 ev, time, data, i, count, base;
456
457 base = ipw_read32(priv, IPW_EVENT_LOG);
458 count = ipw_read_reg32(priv, base);
Jeff Garzikbf794512005-07-31 13:07:26 -0400459
James Ketrenos43f66a62005-03-25 12:31:53 -0600460 if (EVENT_START_OFFSET <= count * EVENT_ELEM_SIZE)
461 IPW_ERROR("Start IPW Event Log Dump:\n");
462
Jeff Garzikbf794512005-07-31 13:07:26 -0400463 for (i = EVENT_START_OFFSET;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400464 i <= count * EVENT_ELEM_SIZE; i += EVENT_ELEM_SIZE) {
James Ketrenos43f66a62005-03-25 12:31:53 -0600465 ev = ipw_read_reg32(priv, base + i);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400466 time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
467 data = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600468
469#ifdef CONFIG_IPW_DEBUG
470 IPW_ERROR("%i\t0x%08x\t%i\n", time, data, ev);
471#endif
472 }
473}
474
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400475static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600476{
477 u32 addr, field_info, field_len, field_count, total_len;
478
479 IPW_DEBUG_ORD("ordinal = %i\n", ord);
480
481 if (!priv || !val || !len) {
482 IPW_DEBUG_ORD("Invalid argument\n");
483 return -EINVAL;
484 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400485
James Ketrenos43f66a62005-03-25 12:31:53 -0600486 /* verify device ordinal tables have been initialized */
487 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
488 IPW_DEBUG_ORD("Access ordinals before initialization\n");
489 return -EINVAL;
490 }
491
492 switch (IPW_ORD_TABLE_ID_MASK & ord) {
493 case IPW_ORD_TABLE_0_MASK:
494 /*
495 * TABLE 0: Direct access to a table of 32 bit values
496 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400497 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600498 * read from the table
499 */
500
501 /* remove the table id from the ordinal */
502 ord &= IPW_ORD_TABLE_VALUE_MASK;
503
504 /* boundary check */
505 if (ord > priv->table0_len) {
506 IPW_DEBUG_ORD("ordinal value (%i) longer then "
507 "max (%i)\n", ord, priv->table0_len);
508 return -EINVAL;
509 }
510
511 /* verify we have enough room to store the value */
512 if (*len < sizeof(u32)) {
513 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200514 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600515 return -EINVAL;
516 }
517
518 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400519 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600520
521 *len = sizeof(u32);
522 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400523 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600524 break;
525
526 case IPW_ORD_TABLE_1_MASK:
527 /*
528 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400529 *
530 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600531 * representing starting addr for the data (which is
532 * also a u32)
533 */
534
535 /* remove the table id from the ordinal */
536 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400537
James Ketrenos43f66a62005-03-25 12:31:53 -0600538 /* boundary check */
539 if (ord > priv->table1_len) {
540 IPW_DEBUG_ORD("ordinal value too long\n");
541 return -EINVAL;
542 }
543
544 /* verify we have enough room to store the value */
545 if (*len < sizeof(u32)) {
546 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200547 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600548 return -EINVAL;
549 }
550
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400551 *((u32 *) val) =
552 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600553 *len = sizeof(u32);
554 break;
555
556 case IPW_ORD_TABLE_2_MASK:
557 /*
558 * TABLE 2: Indirect access to a table of variable sized values
559 *
560 * This table consist of six values, each containing
561 * - dword containing the starting offset of the data
562 * - dword containing the lengh in the first 16bits
563 * and the count in the second 16bits
564 */
565
566 /* remove the table id from the ordinal */
567 ord &= IPW_ORD_TABLE_VALUE_MASK;
568
569 /* boundary check */
570 if (ord > priv->table2_len) {
571 IPW_DEBUG_ORD("ordinal value too long\n");
572 return -EINVAL;
573 }
574
575 /* get the address of statistic */
576 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400577
578 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600579 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400580 field_info =
581 ipw_read_reg32(priv,
582 priv->table2_addr + (ord << 3) +
583 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400584
James Ketrenos43f66a62005-03-25 12:31:53 -0600585 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400586 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400587
James Ketrenos43f66a62005-03-25 12:31:53 -0600588 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400589 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400590
James Ketrenos43f66a62005-03-25 12:31:53 -0600591 /* abort if not enought memory */
592 total_len = field_len * field_count;
593 if (total_len > *len) {
594 *len = total_len;
595 return -EINVAL;
596 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400597
James Ketrenos43f66a62005-03-25 12:31:53 -0600598 *len = total_len;
599 if (!total_len)
600 return 0;
601
602 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400603 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600604 addr, total_len, field_info);
605 ipw_read_indirect(priv, addr, val, total_len);
606 break;
607
608 default:
609 IPW_DEBUG_ORD("Invalid ordinal!\n");
610 return -EINVAL;
611
612 }
613
James Ketrenos43f66a62005-03-25 12:31:53 -0600614 return 0;
615}
616
617static void ipw_init_ordinals(struct ipw_priv *priv)
618{
619 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400620 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600621
622 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
623 priv->table0_addr, priv->table0_len);
624
625 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
626 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
627
628 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
629 priv->table1_addr, priv->table1_len);
630
631 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
632 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400633 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600634
635 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
636 priv->table2_addr, priv->table2_len);
637
638}
639
640/*
641 * The following adds a new attribute to the sysfs representation
642 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
643 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -0400644 *
James Ketrenos43f66a62005-03-25 12:31:53 -0600645 * See the level definitions in ipw for details.
646 */
647static ssize_t show_debug_level(struct device_driver *d, char *buf)
648{
649 return sprintf(buf, "0x%08X\n", ipw_debug_level);
650}
Andrew Mortonad3fee52005-06-20 14:30:36 -0700651static ssize_t store_debug_level(struct device_driver *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400652 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600653{
654 char *p = (char *)buf;
655 u32 val;
656
657 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
658 p++;
659 if (p[0] == 'x' || p[0] == 'X')
660 p++;
661 val = simple_strtoul(p, &p, 16);
662 } else
663 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -0400664 if (p == buf)
665 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -0600666 ": %s is not in hex or decimal form.\n", buf);
667 else
668 ipw_debug_level = val;
669
670 return strnlen(buf, count);
671}
672
Jeff Garzikbf794512005-07-31 13:07:26 -0400673static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -0600674 show_debug_level, store_debug_level);
675
Andrew Mortonad3fee52005-06-20 14:30:36 -0700676static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400677 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600678{
Andrew Mortonad3fee52005-06-20 14:30:36 -0700679 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600680 return sprintf(buf, "0x%08x\n", (int)p->status);
681}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400682
James Ketrenos43f66a62005-03-25 12:31:53 -0600683static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
684
Andrew Mortonad3fee52005-06-20 14:30:36 -0700685static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
686 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600687{
Andrew Mortonad3fee52005-06-20 14:30:36 -0700688 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600689 return sprintf(buf, "0x%08x\n", (int)p->config);
690}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400691
James Ketrenos43f66a62005-03-25 12:31:53 -0600692static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
693
Andrew Mortonad3fee52005-06-20 14:30:36 -0700694static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400695 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600696{
Andrew Mortonad3fee52005-06-20 14:30:36 -0700697 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600698 u8 type = p->eeprom[EEPROM_NIC_TYPE];
699
700 switch (type) {
701 case EEPROM_NIC_TYPE_STANDARD:
702 return sprintf(buf, "STANDARD\n");
703 case EEPROM_NIC_TYPE_DELL:
704 return sprintf(buf, "DELL\n");
705 case EEPROM_NIC_TYPE_FUJITSU:
706 return sprintf(buf, "FUJITSU\n");
707 case EEPROM_NIC_TYPE_IBM:
708 return sprintf(buf, "IBM\n");
709 case EEPROM_NIC_TYPE_HP:
710 return sprintf(buf, "HP\n");
711 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400712
James Ketrenos43f66a62005-03-25 12:31:53 -0600713 return sprintf(buf, "UNKNOWN\n");
714}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400715
James Ketrenos43f66a62005-03-25 12:31:53 -0600716static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
717
Andrew Mortonad3fee52005-06-20 14:30:36 -0700718static ssize_t dump_error_log(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400719 struct device_attribute *attr, const char *buf,
720 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600721{
722 char *p = (char *)buf;
723
Jeff Garzikbf794512005-07-31 13:07:26 -0400724 if (p[0] == '1')
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400725 ipw_dump_nic_error_log((struct ipw_priv *)d->driver_data);
James Ketrenos43f66a62005-03-25 12:31:53 -0600726
727 return strnlen(buf, count);
728}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400729
James Ketrenos43f66a62005-03-25 12:31:53 -0600730static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
731
Andrew Mortonad3fee52005-06-20 14:30:36 -0700732static ssize_t dump_event_log(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400733 struct device_attribute *attr, const char *buf,
734 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600735{
736 char *p = (char *)buf;
737
Jeff Garzikbf794512005-07-31 13:07:26 -0400738 if (p[0] == '1')
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400739 ipw_dump_nic_event_log((struct ipw_priv *)d->driver_data);
James Ketrenos43f66a62005-03-25 12:31:53 -0600740
741 return strnlen(buf, count);
742}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400743
James Ketrenos43f66a62005-03-25 12:31:53 -0600744static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
745
Andrew Mortonad3fee52005-06-20 14:30:36 -0700746static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400747 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600748{
749 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700750 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600751
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400752 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -0600753 return 0;
754
755 return sprintf(buf, "0x%08x\n", tmp);
756}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400757
758static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600759
Andrew Mortonad3fee52005-06-20 14:30:36 -0700760static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
761 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600762{
763 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700764 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600765
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400766 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -0600767 return 0;
768
769 return sprintf(buf, "0x%08x\n", tmp);
770}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400771
772static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600773
774/*
775 * Add a device attribute to view/control the delay between eeprom
776 * operations.
777 */
Andrew Mortonad3fee52005-06-20 14:30:36 -0700778static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400779 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600780{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400781 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -0600782 return sprintf(buf, "%i\n", n);
783}
Andrew Mortonad3fee52005-06-20 14:30:36 -0700784static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400785 struct device_attribute *attr,
786 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600787{
Andrew Mortonad3fee52005-06-20 14:30:36 -0700788 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600789 sscanf(buf, "%i", &p->eeprom_delay);
790 return strnlen(buf, count);
791}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400792
793static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
794 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -0600795
Andrew Mortonad3fee52005-06-20 14:30:36 -0700796static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400797 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600798{
799 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700800 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600801
802 reg = ipw_read_reg32(p, CX2_INTERNAL_CMD_EVENT);
803 return sprintf(buf, "0x%08x\n", reg);
804}
Andrew Mortonad3fee52005-06-20 14:30:36 -0700805static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400806 struct device_attribute *attr,
807 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600808{
809 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700810 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600811
812 sscanf(buf, "%x", &reg);
813 ipw_write_reg32(p, CX2_INTERNAL_CMD_EVENT, reg);
814 return strnlen(buf, count);
815}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400816
817static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
818 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -0600819
Andrew Mortonad3fee52005-06-20 14:30:36 -0700820static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400821 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600822{
823 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700824 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600825
826 reg = ipw_read_reg32(p, 0x301100);
827 return sprintf(buf, "0x%08x\n", reg);
828}
Andrew Mortonad3fee52005-06-20 14:30:36 -0700829static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400830 struct device_attribute *attr,
831 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600832{
833 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700834 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600835
836 sscanf(buf, "%x", &reg);
837 ipw_write_reg32(p, 0x301100, reg);
838 return strnlen(buf, count);
839}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400840
841static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
842 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -0600843
Andrew Mortonad3fee52005-06-20 14:30:36 -0700844static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400845 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600846{
847 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700848 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -0400849 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -0600850 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -0400851 else
James Ketrenos43f66a62005-03-25 12:31:53 -0600852 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -0400853
James Ketrenos43f66a62005-03-25 12:31:53 -0600854 return sprintf(buf, "0x%08x\n", reg);
855}
Andrew Mortonad3fee52005-06-20 14:30:36 -0700856static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400857 struct device_attribute *attr,
858 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600859{
Andrew Mortonad3fee52005-06-20 14:30:36 -0700860 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600861
862 sscanf(buf, "%x", &priv->indirect_dword);
863 priv->status |= STATUS_INDIRECT_DWORD;
864 return strnlen(buf, count);
865}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400866
867static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
868 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -0600869
Andrew Mortonad3fee52005-06-20 14:30:36 -0700870static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400871 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600872{
873 u8 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700874 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -0400875 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -0600876 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -0400877 else
James Ketrenos43f66a62005-03-25 12:31:53 -0600878 reg = 0;
879
880 return sprintf(buf, "0x%02x\n", reg);
881}
Andrew Mortonad3fee52005-06-20 14:30:36 -0700882static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400883 struct device_attribute *attr,
884 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600885{
Andrew Mortonad3fee52005-06-20 14:30:36 -0700886 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600887
888 sscanf(buf, "%x", &priv->indirect_byte);
889 priv->status |= STATUS_INDIRECT_BYTE;
890 return strnlen(buf, count);
891}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400892
893static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -0600894 show_indirect_byte, store_indirect_byte);
895
Andrew Mortonad3fee52005-06-20 14:30:36 -0700896static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400897 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600898{
899 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700900 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600901
Jeff Garzikbf794512005-07-31 13:07:26 -0400902 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -0600903 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -0400904 else
James Ketrenos43f66a62005-03-25 12:31:53 -0600905 reg = 0;
906
907 return sprintf(buf, "0x%08x\n", reg);
908}
Andrew Mortonad3fee52005-06-20 14:30:36 -0700909static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400910 struct device_attribute *attr,
911 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600912{
Andrew Mortonad3fee52005-06-20 14:30:36 -0700913 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600914
915 sscanf(buf, "%x", &priv->direct_dword);
916 priv->status |= STATUS_DIRECT_DWORD;
917 return strnlen(buf, count);
918}
James Ketrenos43f66a62005-03-25 12:31:53 -0600919
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400920static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
921 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -0600922
923static inline int rf_kill_active(struct ipw_priv *priv)
924{
925 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
926 priv->status |= STATUS_RF_KILL_HW;
927 else
928 priv->status &= ~STATUS_RF_KILL_HW;
929
930 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
931}
932
Andrew Mortonad3fee52005-06-20 14:30:36 -0700933static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400934 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600935{
936 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -0400937 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600938 2 - HW based RF kill active
939 3 - Both HW and SW baed RF kill active */
Andrew Mortonad3fee52005-06-20 14:30:36 -0700940 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600941 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400942 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -0600943 return sprintf(buf, "%i\n", val);
944}
945
946static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
947{
Jeff Garzikbf794512005-07-31 13:07:26 -0400948 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -0500949 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400950 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600951
952 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
953 disable_radio ? "OFF" : "ON");
954
955 if (disable_radio) {
956 priv->status |= STATUS_RF_KILL_SW;
957
Jeff Garzikbf794512005-07-31 13:07:26 -0400958 if (priv->workqueue) {
James Ketrenos43f66a62005-03-25 12:31:53 -0600959 cancel_delayed_work(&priv->request_scan);
960 }
961 wake_up_interruptible(&priv->wait_command_queue);
962 queue_work(priv->workqueue, &priv->down);
963 } else {
964 priv->status &= ~STATUS_RF_KILL_SW;
965 if (rf_kill_active(priv)) {
966 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
967 "disabled by HW switch\n");
968 /* Make sure the RF_KILL check timer is running */
969 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -0400970 queue_delayed_work(priv->workqueue, &priv->rf_kill,
James Ketrenos43f66a62005-03-25 12:31:53 -0600971 2 * HZ);
Jeff Garzikbf794512005-07-31 13:07:26 -0400972 } else
James Ketrenos43f66a62005-03-25 12:31:53 -0600973 queue_work(priv->workqueue, &priv->up);
974 }
975
976 return 1;
977}
978
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400979static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
980 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600981{
Andrew Mortonad3fee52005-06-20 14:30:36 -0700982 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -0400983
James Ketrenos43f66a62005-03-25 12:31:53 -0600984 ipw_radio_kill_sw(priv, buf[0] == '1');
985
986 return count;
987}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400988
989static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -0600990
James Ketrenosea2b26e2005-08-24 21:25:16 -0500991static void notify_wx_assoc_event(struct ipw_priv *priv)
992{
993 union iwreq_data wrqu;
994 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
995 if (priv->status & STATUS_ASSOCIATED)
996 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
997 else
998 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
999 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1000}
1001
James Ketrenos43f66a62005-03-25 12:31:53 -06001002static void ipw_irq_tasklet(struct ipw_priv *priv)
1003{
1004 u32 inta, inta_mask, handled = 0;
1005 unsigned long flags;
1006 int rc = 0;
1007
1008 spin_lock_irqsave(&priv->lock, flags);
1009
1010 inta = ipw_read32(priv, CX2_INTA_RW);
1011 inta_mask = ipw_read32(priv, CX2_INTA_MASK_R);
1012 inta &= (CX2_INTA_MASK_ALL & inta_mask);
1013
1014 /* Add any cached INTA values that need to be handled */
1015 inta |= priv->isr_inta;
1016
1017 /* handle all the justifications for the interrupt */
1018 if (inta & CX2_INTA_BIT_RX_TRANSFER) {
1019 ipw_rx(priv);
1020 handled |= CX2_INTA_BIT_RX_TRANSFER;
1021 }
1022
1023 if (inta & CX2_INTA_BIT_TX_CMD_QUEUE) {
1024 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001025 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001026 priv->status &= ~STATUS_HCMD_ACTIVE;
1027 wake_up_interruptible(&priv->wait_command_queue);
1028 handled |= CX2_INTA_BIT_TX_CMD_QUEUE;
1029 }
1030
1031 if (inta & CX2_INTA_BIT_TX_QUEUE_1) {
1032 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001033 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001034 handled |= CX2_INTA_BIT_TX_QUEUE_1;
1035 }
1036
1037 if (inta & CX2_INTA_BIT_TX_QUEUE_2) {
1038 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001039 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001040 handled |= CX2_INTA_BIT_TX_QUEUE_2;
1041 }
1042
1043 if (inta & CX2_INTA_BIT_TX_QUEUE_3) {
1044 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001045 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenos43f66a62005-03-25 12:31:53 -06001046 handled |= CX2_INTA_BIT_TX_QUEUE_3;
1047 }
1048
1049 if (inta & CX2_INTA_BIT_TX_QUEUE_4) {
1050 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001051 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06001052 handled |= CX2_INTA_BIT_TX_QUEUE_4;
1053 }
1054
1055 if (inta & CX2_INTA_BIT_STATUS_CHANGE) {
1056 IPW_WARNING("STATUS_CHANGE\n");
1057 handled |= CX2_INTA_BIT_STATUS_CHANGE;
1058 }
1059
1060 if (inta & CX2_INTA_BIT_BEACON_PERIOD_EXPIRED) {
1061 IPW_WARNING("TX_PERIOD_EXPIRED\n");
1062 handled |= CX2_INTA_BIT_BEACON_PERIOD_EXPIRED;
1063 }
1064
1065 if (inta & CX2_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
1066 IPW_WARNING("HOST_CMD_DONE\n");
1067 handled |= CX2_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
1068 }
1069
1070 if (inta & CX2_INTA_BIT_FW_INITIALIZATION_DONE) {
1071 IPW_WARNING("FW_INITIALIZATION_DONE\n");
1072 handled |= CX2_INTA_BIT_FW_INITIALIZATION_DONE;
1073 }
1074
1075 if (inta & CX2_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
1076 IPW_WARNING("PHY_OFF_DONE\n");
1077 handled |= CX2_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
1078 }
1079
1080 if (inta & CX2_INTA_BIT_RF_KILL_DONE) {
1081 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1082 priv->status |= STATUS_RF_KILL_HW;
1083 wake_up_interruptible(&priv->wait_command_queue);
1084 netif_carrier_off(priv->net_dev);
1085 netif_stop_queue(priv->net_dev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05001086 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
1087 notify_wx_assoc_event(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06001088 cancel_delayed_work(&priv->request_scan);
1089 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
1090 handled |= CX2_INTA_BIT_RF_KILL_DONE;
1091 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001092
James Ketrenos43f66a62005-03-25 12:31:53 -06001093 if (inta & CX2_INTA_BIT_FATAL_ERROR) {
1094 IPW_ERROR("Firmware error detected. Restarting.\n");
1095#ifdef CONFIG_IPW_DEBUG
1096 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1097 ipw_dump_nic_error_log(priv);
1098 ipw_dump_nic_event_log(priv);
1099 }
1100#endif
1101 queue_work(priv->workqueue, &priv->adapter_restart);
1102 handled |= CX2_INTA_BIT_FATAL_ERROR;
1103 }
1104
1105 if (inta & CX2_INTA_BIT_PARITY_ERROR) {
1106 IPW_ERROR("Parity error\n");
1107 handled |= CX2_INTA_BIT_PARITY_ERROR;
1108 }
1109
1110 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001111 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06001112 }
1113
1114 /* enable all interrupts */
1115 ipw_enable_interrupts(priv);
1116
1117 spin_unlock_irqrestore(&priv->lock, flags);
1118}
Jeff Garzikbf794512005-07-31 13:07:26 -04001119
James Ketrenos43f66a62005-03-25 12:31:53 -06001120#ifdef CONFIG_IPW_DEBUG
1121#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1122static char *get_cmd_string(u8 cmd)
1123{
1124 switch (cmd) {
1125 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04001126 IPW_CMD(POWER_DOWN);
1127 IPW_CMD(SYSTEM_CONFIG);
1128 IPW_CMD(MULTICAST_ADDRESS);
1129 IPW_CMD(SSID);
1130 IPW_CMD(ADAPTER_ADDRESS);
1131 IPW_CMD(PORT_TYPE);
1132 IPW_CMD(RTS_THRESHOLD);
1133 IPW_CMD(FRAG_THRESHOLD);
1134 IPW_CMD(POWER_MODE);
1135 IPW_CMD(WEP_KEY);
1136 IPW_CMD(TGI_TX_KEY);
1137 IPW_CMD(SCAN_REQUEST);
1138 IPW_CMD(SCAN_REQUEST_EXT);
1139 IPW_CMD(ASSOCIATE);
1140 IPW_CMD(SUPPORTED_RATES);
1141 IPW_CMD(SCAN_ABORT);
1142 IPW_CMD(TX_FLUSH);
1143 IPW_CMD(QOS_PARAMETERS);
1144 IPW_CMD(DINO_CONFIG);
1145 IPW_CMD(RSN_CAPABILITIES);
1146 IPW_CMD(RX_KEY);
1147 IPW_CMD(CARD_DISABLE);
1148 IPW_CMD(SEED_NUMBER);
1149 IPW_CMD(TX_POWER);
1150 IPW_CMD(COUNTRY_INFO);
1151 IPW_CMD(AIRONET_INFO);
1152 IPW_CMD(AP_TX_POWER);
1153 IPW_CMD(CCKM_INFO);
1154 IPW_CMD(CCX_VER_INFO);
1155 IPW_CMD(SET_CALIBRATION);
1156 IPW_CMD(SENSITIVITY_CALIB);
1157 IPW_CMD(RETRY_LIMIT);
1158 IPW_CMD(IPW_PRE_POWER_DOWN);
1159 IPW_CMD(VAP_BEACON_TEMPLATE);
1160 IPW_CMD(VAP_DTIM_PERIOD);
1161 IPW_CMD(EXT_SUPPORTED_RATES);
1162 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
1163 IPW_CMD(VAP_QUIET_INTERVALS);
1164 IPW_CMD(VAP_CHANNEL_SWITCH);
1165 IPW_CMD(VAP_MANDATORY_CHANNELS);
1166 IPW_CMD(VAP_CELL_PWR_LIMIT);
1167 IPW_CMD(VAP_CF_PARAM_SET);
1168 IPW_CMD(VAP_SET_BEACONING_STATE);
1169 IPW_CMD(MEASUREMENT);
1170 IPW_CMD(POWER_CAPABILITY);
1171 IPW_CMD(SUPPORTED_CHANNELS);
1172 IPW_CMD(TPC_REPORT);
1173 IPW_CMD(WME_INFO);
1174 IPW_CMD(PRODUCTION_COMMAND);
1175 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06001176 return "UNKNOWN";
1177 }
1178}
James Ketrenosea2b26e2005-08-24 21:25:16 -05001179#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06001180
1181#define HOST_COMPLETE_TIMEOUT HZ
1182static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
1183{
1184 int rc = 0;
1185
1186 if (priv->status & STATUS_HCMD_ACTIVE) {
1187 IPW_ERROR("Already sending a command\n");
1188 return -1;
1189 }
1190
1191 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04001192
1193 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06001194 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001195 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
James Ketrenos43f66a62005-03-25 12:31:53 -06001196
1197 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0);
1198 if (rc)
1199 return rc;
1200
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001201 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1202 !(priv->
1203 status & STATUS_HCMD_ACTIVE),
1204 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001205 if (rc == 0) {
1206 IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
Jeff Garzik9bd481f2005-06-28 01:46:35 -04001207 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
James Ketrenos43f66a62005-03-25 12:31:53 -06001208 priv->status &= ~STATUS_HCMD_ACTIVE;
1209 return -EIO;
1210 }
1211 if (priv->status & STATUS_RF_KILL_MASK) {
1212 IPW_DEBUG_INFO("Command aborted due to RF Kill Switch\n");
1213 return -EIO;
1214 }
1215
1216 return 0;
1217}
1218
1219static int ipw_send_host_complete(struct ipw_priv *priv)
1220{
1221 struct host_cmd cmd = {
1222 .cmd = IPW_CMD_HOST_COMPLETE,
1223 .len = 0
1224 };
1225
1226 if (!priv) {
1227 IPW_ERROR("Invalid args\n");
1228 return -1;
1229 }
1230
1231 if (ipw_send_cmd(priv, &cmd)) {
1232 IPW_ERROR("failed to send HOST_COMPLETE command\n");
1233 return -1;
1234 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001235
James Ketrenos43f66a62005-03-25 12:31:53 -06001236 return 0;
1237}
1238
Jeff Garzikbf794512005-07-31 13:07:26 -04001239static int ipw_send_system_config(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06001240 struct ipw_sys_config *config)
1241{
1242 struct host_cmd cmd = {
1243 .cmd = IPW_CMD_SYSTEM_CONFIG,
1244 .len = sizeof(*config)
1245 };
1246
1247 if (!priv || !config) {
1248 IPW_ERROR("Invalid args\n");
1249 return -1;
1250 }
1251
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001252 memcpy(&cmd.param, config, sizeof(*config));
James Ketrenos43f66a62005-03-25 12:31:53 -06001253 if (ipw_send_cmd(priv, &cmd)) {
1254 IPW_ERROR("failed to send SYSTEM_CONFIG command\n");
1255 return -1;
1256 }
1257
1258 return 0;
1259}
1260
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001261static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06001262{
1263 struct host_cmd cmd = {
1264 .cmd = IPW_CMD_SSID,
1265 .len = min(len, IW_ESSID_MAX_SIZE)
1266 };
1267
1268 if (!priv || !ssid) {
1269 IPW_ERROR("Invalid args\n");
1270 return -1;
1271 }
1272
1273 memcpy(&cmd.param, ssid, cmd.len);
1274 if (ipw_send_cmd(priv, &cmd)) {
1275 IPW_ERROR("failed to send SSID command\n");
1276 return -1;
1277 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001278
James Ketrenos43f66a62005-03-25 12:31:53 -06001279 return 0;
1280}
1281
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001282static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06001283{
1284 struct host_cmd cmd = {
1285 .cmd = IPW_CMD_ADAPTER_ADDRESS,
1286 .len = ETH_ALEN
1287 };
1288
1289 if (!priv || !mac) {
1290 IPW_ERROR("Invalid args\n");
1291 return -1;
1292 }
1293
1294 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
1295 priv->net_dev->name, MAC_ARG(mac));
1296
1297 memcpy(&cmd.param, mac, ETH_ALEN);
1298
1299 if (ipw_send_cmd(priv, &cmd)) {
1300 IPW_ERROR("failed to send ADAPTER_ADDRESS command\n");
1301 return -1;
1302 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001303
James Ketrenos43f66a62005-03-25 12:31:53 -06001304 return 0;
1305}
1306
1307static void ipw_adapter_restart(void *adapter)
1308{
1309 struct ipw_priv *priv = adapter;
1310
1311 if (priv->status & STATUS_RF_KILL_MASK)
1312 return;
1313
1314 ipw_down(priv);
1315 if (ipw_up(priv)) {
1316 IPW_ERROR("Failed to up device\n");
1317 return;
1318 }
1319}
1320
James Ketrenos43f66a62005-03-25 12:31:53 -06001321#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
1322
1323static void ipw_scan_check(void *data)
1324{
1325 struct ipw_priv *priv = data;
1326 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
1327 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Jeff Garzikbf794512005-07-31 13:07:26 -04001328 "adapter (%dms).\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06001329 IPW_SCAN_CHECK_WATCHDOG / 100);
1330 ipw_adapter_restart(priv);
1331 }
1332}
1333
1334static int ipw_send_scan_request_ext(struct ipw_priv *priv,
1335 struct ipw_scan_request_ext *request)
1336{
1337 struct host_cmd cmd = {
1338 .cmd = IPW_CMD_SCAN_REQUEST_EXT,
1339 .len = sizeof(*request)
1340 };
1341
1342 if (!priv || !request) {
1343 IPW_ERROR("Invalid args\n");
1344 return -1;
1345 }
1346
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001347 memcpy(&cmd.param, request, sizeof(*request));
James Ketrenos43f66a62005-03-25 12:31:53 -06001348 if (ipw_send_cmd(priv, &cmd)) {
1349 IPW_ERROR("failed to send SCAN_REQUEST_EXT command\n");
1350 return -1;
1351 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001352
1353 queue_delayed_work(priv->workqueue, &priv->scan_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06001354 IPW_SCAN_CHECK_WATCHDOG);
1355 return 0;
1356}
1357
1358static int ipw_send_scan_abort(struct ipw_priv *priv)
1359{
1360 struct host_cmd cmd = {
1361 .cmd = IPW_CMD_SCAN_ABORT,
1362 .len = 0
1363 };
1364
1365 if (!priv) {
1366 IPW_ERROR("Invalid args\n");
1367 return -1;
1368 }
1369
1370 if (ipw_send_cmd(priv, &cmd)) {
1371 IPW_ERROR("failed to send SCAN_ABORT command\n");
1372 return -1;
1373 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001374
James Ketrenos43f66a62005-03-25 12:31:53 -06001375 return 0;
1376}
1377
1378static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
1379{
1380 struct host_cmd cmd = {
1381 .cmd = IPW_CMD_SENSITIVITY_CALIB,
1382 .len = sizeof(struct ipw_sensitivity_calib)
1383 };
1384 struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001385 &cmd.param;
James Ketrenos43f66a62005-03-25 12:31:53 -06001386 calib->beacon_rssi_raw = sens;
1387 if (ipw_send_cmd(priv, &cmd)) {
1388 IPW_ERROR("failed to send SENSITIVITY CALIB command\n");
1389 return -1;
1390 }
1391
1392 return 0;
1393}
1394
1395static int ipw_send_associate(struct ipw_priv *priv,
1396 struct ipw_associate *associate)
1397{
1398 struct host_cmd cmd = {
1399 .cmd = IPW_CMD_ASSOCIATE,
1400 .len = sizeof(*associate)
1401 };
1402
1403 if (!priv || !associate) {
1404 IPW_ERROR("Invalid args\n");
1405 return -1;
1406 }
1407
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001408 memcpy(&cmd.param, associate, sizeof(*associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06001409 if (ipw_send_cmd(priv, &cmd)) {
1410 IPW_ERROR("failed to send ASSOCIATE command\n");
1411 return -1;
1412 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001413
James Ketrenos43f66a62005-03-25 12:31:53 -06001414 return 0;
1415}
1416
1417static int ipw_send_supported_rates(struct ipw_priv *priv,
1418 struct ipw_supported_rates *rates)
1419{
1420 struct host_cmd cmd = {
1421 .cmd = IPW_CMD_SUPPORTED_RATES,
1422 .len = sizeof(*rates)
1423 };
1424
1425 if (!priv || !rates) {
1426 IPW_ERROR("Invalid args\n");
1427 return -1;
1428 }
1429
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001430 memcpy(&cmd.param, rates, sizeof(*rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06001431 if (ipw_send_cmd(priv, &cmd)) {
1432 IPW_ERROR("failed to send SUPPORTED_RATES command\n");
1433 return -1;
1434 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001435
James Ketrenos43f66a62005-03-25 12:31:53 -06001436 return 0;
1437}
1438
1439static int ipw_set_random_seed(struct ipw_priv *priv)
1440{
1441 struct host_cmd cmd = {
1442 .cmd = IPW_CMD_SEED_NUMBER,
1443 .len = sizeof(u32)
1444 };
1445
1446 if (!priv) {
1447 IPW_ERROR("Invalid args\n");
1448 return -1;
1449 }
1450
1451 get_random_bytes(&cmd.param, sizeof(u32));
1452
1453 if (ipw_send_cmd(priv, &cmd)) {
1454 IPW_ERROR("failed to send SEED_NUMBER command\n");
1455 return -1;
1456 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001457
James Ketrenos43f66a62005-03-25 12:31:53 -06001458 return 0;
1459}
1460
1461#if 0
1462static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
1463{
1464 struct host_cmd cmd = {
1465 .cmd = IPW_CMD_CARD_DISABLE,
1466 .len = sizeof(u32)
1467 };
1468
1469 if (!priv) {
1470 IPW_ERROR("Invalid args\n");
1471 return -1;
1472 }
1473
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001474 *((u32 *) & cmd.param) = phy_off;
James Ketrenos43f66a62005-03-25 12:31:53 -06001475
1476 if (ipw_send_cmd(priv, &cmd)) {
1477 IPW_ERROR("failed to send CARD_DISABLE command\n");
1478 return -1;
1479 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001480
James Ketrenos43f66a62005-03-25 12:31:53 -06001481 return 0;
1482}
1483#endif
1484
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001485static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06001486{
1487 struct host_cmd cmd = {
1488 .cmd = IPW_CMD_TX_POWER,
1489 .len = sizeof(*power)
1490 };
1491
1492 if (!priv || !power) {
1493 IPW_ERROR("Invalid args\n");
1494 return -1;
1495 }
1496
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001497 memcpy(&cmd.param, power, sizeof(*power));
James Ketrenos43f66a62005-03-25 12:31:53 -06001498 if (ipw_send_cmd(priv, &cmd)) {
1499 IPW_ERROR("failed to send TX_POWER command\n");
1500 return -1;
1501 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001502
James Ketrenos43f66a62005-03-25 12:31:53 -06001503 return 0;
1504}
1505
1506static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
1507{
1508 struct ipw_rts_threshold rts_threshold = {
1509 .rts_threshold = rts,
1510 };
1511 struct host_cmd cmd = {
1512 .cmd = IPW_CMD_RTS_THRESHOLD,
1513 .len = sizeof(rts_threshold)
1514 };
1515
1516 if (!priv) {
1517 IPW_ERROR("Invalid args\n");
1518 return -1;
1519 }
1520
1521 memcpy(&cmd.param, &rts_threshold, sizeof(rts_threshold));
1522 if (ipw_send_cmd(priv, &cmd)) {
1523 IPW_ERROR("failed to send RTS_THRESHOLD command\n");
1524 return -1;
1525 }
1526
1527 return 0;
1528}
1529
1530static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
1531{
1532 struct ipw_frag_threshold frag_threshold = {
1533 .frag_threshold = frag,
1534 };
1535 struct host_cmd cmd = {
1536 .cmd = IPW_CMD_FRAG_THRESHOLD,
1537 .len = sizeof(frag_threshold)
1538 };
1539
1540 if (!priv) {
1541 IPW_ERROR("Invalid args\n");
1542 return -1;
1543 }
1544
1545 memcpy(&cmd.param, &frag_threshold, sizeof(frag_threshold));
1546 if (ipw_send_cmd(priv, &cmd)) {
1547 IPW_ERROR("failed to send FRAG_THRESHOLD command\n");
1548 return -1;
1549 }
1550
1551 return 0;
1552}
1553
1554static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
1555{
1556 struct host_cmd cmd = {
1557 .cmd = IPW_CMD_POWER_MODE,
1558 .len = sizeof(u32)
1559 };
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001560 u32 *param = (u32 *) (&cmd.param);
James Ketrenos43f66a62005-03-25 12:31:53 -06001561
1562 if (!priv) {
1563 IPW_ERROR("Invalid args\n");
1564 return -1;
1565 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001566
James Ketrenos43f66a62005-03-25 12:31:53 -06001567 /* If on battery, set to 3, if AC set to CAM, else user
1568 * level */
1569 switch (mode) {
1570 case IPW_POWER_BATTERY:
1571 *param = IPW_POWER_INDEX_3;
1572 break;
1573 case IPW_POWER_AC:
1574 *param = IPW_POWER_MODE_CAM;
1575 break;
1576 default:
1577 *param = mode;
1578 break;
1579 }
1580
1581 if (ipw_send_cmd(priv, &cmd)) {
1582 IPW_ERROR("failed to send POWER_MODE command\n");
1583 return -1;
1584 }
1585
1586 return 0;
1587}
1588
1589/*
1590 * The IPW device contains a Microwire compatible EEPROM that stores
1591 * various data like the MAC address. Usually the firmware has exclusive
1592 * access to the eeprom, but during device initialization (before the
1593 * device driver has sent the HostComplete command to the firmware) the
1594 * device driver has read access to the EEPROM by way of indirect addressing
1595 * through a couple of memory mapped registers.
1596 *
1597 * The following is a simplified implementation for pulling data out of the
1598 * the eeprom, along with some helper functions to find information in
1599 * the per device private data's copy of the eeprom.
1600 *
1601 * NOTE: To better understand how these functions work (i.e what is a chip
1602 * select and why do have to keep driving the eeprom clock?), read
1603 * just about any data sheet for a Microwire compatible EEPROM.
1604 */
1605
1606/* write a 32 bit value into the indirect accessor register */
1607static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
1608{
1609 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04001610
James Ketrenos43f66a62005-03-25 12:31:53 -06001611 /* the eeprom requires some time to complete the operation */
1612 udelay(p->eeprom_delay);
1613
1614 return;
1615}
1616
1617/* perform a chip select operation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001618static inline void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001619{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001620 eeprom_write_reg(priv, 0);
1621 eeprom_write_reg(priv, EEPROM_BIT_CS);
1622 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
1623 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06001624}
1625
1626/* perform a chip select operation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001627static inline void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001628{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001629 eeprom_write_reg(priv, EEPROM_BIT_CS);
1630 eeprom_write_reg(priv, 0);
1631 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06001632}
1633
1634/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001635static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06001636{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001637 int d = (bit ? EEPROM_BIT_DI : 0);
1638 eeprom_write_reg(p, EEPROM_BIT_CS | d);
1639 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06001640}
1641
1642/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001643static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06001644{
1645 int i;
1646
1647 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001648 eeprom_write_bit(priv, 1);
1649 eeprom_write_bit(priv, op & 2);
1650 eeprom_write_bit(priv, op & 1);
1651 for (i = 7; i >= 0; i--) {
1652 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06001653 }
1654}
1655
1656/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001657static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06001658{
1659 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001660 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001661
James Ketrenos43f66a62005-03-25 12:31:53 -06001662 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001663 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06001664
1665 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001666 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06001667
1668 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001669 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001670 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001671 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
1672 eeprom_write_reg(priv, EEPROM_BIT_CS);
1673 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
1674 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001675 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001676
James Ketrenos43f66a62005-03-25 12:31:53 -06001677 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001678 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001679 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04001680
James Ketrenos43f66a62005-03-25 12:31:53 -06001681 return r;
1682}
1683
1684/* helper function for pulling the mac address out of the private */
1685/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001686static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06001687{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001688 u8 *ee = (u8 *) priv->eeprom;
James Ketrenos43f66a62005-03-25 12:31:53 -06001689 memcpy(mac, &ee[EEPROM_MAC_ADDRESS], 6);
1690}
1691
1692/*
1693 * Either the device driver (i.e. the host) or the firmware can
1694 * load eeprom data into the designated region in SRAM. If neither
1695 * happens then the FW will shutdown with a fatal error.
1696 *
1697 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
1698 * bit needs region of shared SRAM needs to be non-zero.
1699 */
1700static void ipw_eeprom_init_sram(struct ipw_priv *priv)
1701{
1702 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001703 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04001704
James Ketrenos43f66a62005-03-25 12:31:53 -06001705 IPW_DEBUG_TRACE(">>\n");
1706
1707 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001708 for (i = 0; i < 128; i++)
1709 eeprom[i] = eeprom_read_u16(priv, (u8) i);
James Ketrenos43f66a62005-03-25 12:31:53 -06001710
Jeff Garzikbf794512005-07-31 13:07:26 -04001711 /*
1712 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06001713 copy. Otherwise let the firmware know to perform the operation
1714 on it's own
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001715 */
James Ketrenos43f66a62005-03-25 12:31:53 -06001716 if ((priv->eeprom + EEPROM_VERSION) != 0) {
1717 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
1718
1719 /* write the eeprom data to sram */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001720 for (i = 0; i < CX2_EEPROM_IMAGE_SIZE; i++)
1721 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06001722
1723 /* Do not load eeprom data on fatal error or suspend */
1724 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
1725 } else {
1726 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
1727
1728 /* Load eeprom data on fatal error or suspend */
1729 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
1730 }
1731
1732 IPW_DEBUG_TRACE("<<\n");
1733}
1734
James Ketrenos43f66a62005-03-25 12:31:53 -06001735static inline void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
1736{
1737 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001738 if (!count)
1739 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06001740 _ipw_write32(priv, CX2_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04001741 while (count--)
James Ketrenos43f66a62005-03-25 12:31:53 -06001742 _ipw_write32(priv, CX2_AUTOINC_DATA, 0);
1743}
1744
1745static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
1746{
1747 ipw_zero_memory(priv, CX2_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04001748 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06001749 sizeof(struct command_block));
1750}
1751
1752static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001753{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06001754
1755 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04001756
James Ketrenos43f66a62005-03-25 12:31:53 -06001757 /* Start the dma */
1758 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04001759
James Ketrenos43f66a62005-03-25 12:31:53 -06001760 /* Write CB base address */
1761 ipw_write_reg32(priv, CX2_DMA_I_CB_BASE, CX2_SHARED_SRAM_DMA_CONTROL);
1762
1763 IPW_DEBUG_FW("<< : \n");
1764 return 0;
1765}
1766
1767static void ipw_fw_dma_abort(struct ipw_priv *priv)
1768{
1769 u32 control = 0;
1770
1771 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04001772
1773 //set the Stop and Abort bit
James Ketrenos43f66a62005-03-25 12:31:53 -06001774 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
1775 ipw_write_reg32(priv, CX2_DMA_I_DMA_CONTROL, control);
1776 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001777
James Ketrenos43f66a62005-03-25 12:31:53 -06001778 IPW_DEBUG_FW("<< \n");
1779}
1780
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001781static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
1782 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06001783{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001784 u32 address =
1785 CX2_SHARED_SRAM_DMA_CONTROL +
1786 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06001787 IPW_DEBUG_FW(">> :\n");
1788
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001789 ipw_write_indirect(priv, address, (u8 *) cb,
1790 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06001791
1792 IPW_DEBUG_FW("<< :\n");
1793 return 0;
1794
1795}
1796
1797static int ipw_fw_dma_kick(struct ipw_priv *priv)
1798{
1799 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001800 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001801
1802 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04001803
James Ketrenos43f66a62005-03-25 12:31:53 -06001804 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001805 ipw_fw_dma_write_command_block(priv, index,
1806 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06001807
1808 /* Enable the DMA in the CSR register */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001809 ipw_clear_bit(priv, CX2_RESET_REG,
1810 CX2_RESET_REG_MASTER_DISABLED |
1811 CX2_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04001812
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001813 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06001814 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
1815 ipw_write_reg32(priv, CX2_DMA_I_DMA_CONTROL, control);
1816
1817 IPW_DEBUG_FW("<< :\n");
1818 return 0;
1819}
1820
1821static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
1822{
1823 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001824 u32 register_value = 0;
1825 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001826
1827 IPW_DEBUG_FW(">> :\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001828 address = ipw_read_reg32(priv, CX2_DMA_I_CURRENT_CB);
1829 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06001830
1831 /* Read the DMA Controlor register */
1832 register_value = ipw_read_reg32(priv, CX2_DMA_I_DMA_CONTROL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001833 IPW_DEBUG_FW_INFO("CX2_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06001834
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001835 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06001836 cb_fields_address = address;
1837 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001838 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06001839
1840 cb_fields_address += sizeof(u32);
1841 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001842 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06001843
1844 cb_fields_address += sizeof(u32);
1845 register_value = ipw_read_reg32(priv, cb_fields_address);
1846 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
1847 register_value);
1848
1849 cb_fields_address += sizeof(u32);
1850 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001851 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06001852
1853 IPW_DEBUG_FW(">> :\n");
1854}
1855
1856static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
1857{
1858 u32 current_cb_address = 0;
1859 u32 current_cb_index = 0;
1860
1861 IPW_DEBUG_FW("<< :\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001862 current_cb_address = ipw_read_reg32(priv, CX2_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04001863
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001864 current_cb_index = (current_cb_address - CX2_SHARED_SRAM_DMA_CONTROL) /
1865 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04001866
James Ketrenos43f66a62005-03-25 12:31:53 -06001867 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001868 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06001869
1870 IPW_DEBUG_FW(">> :\n");
1871 return current_cb_index;
1872
1873}
1874
1875static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
1876 u32 src_address,
1877 u32 dest_address,
1878 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001879 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06001880{
1881
Jeff Garzikbf794512005-07-31 13:07:26 -04001882 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001883 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
1884 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06001885 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001886 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001887
1888 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
1889 src_address, dest_address, length);
1890
1891 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
1892 return -1;
1893
1894 last_cb_element = priv->sram_desc.last_cb_index;
1895 cb = &priv->sram_desc.cb_list[last_cb_element];
1896 priv->sram_desc.last_cb_index++;
1897
1898 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001899 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06001900 control |= CB_INT_ENABLED;
1901
1902 if (is_last)
1903 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04001904
James Ketrenos43f66a62005-03-25 12:31:53 -06001905 control |= length;
1906
1907 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001908 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06001909
1910 /* Copy the Source and Destination addresses */
1911 cb->dest_addr = dest_address;
1912 cb->source_addr = src_address;
1913
1914 /* Copy the Control Word last */
1915 cb->control = control;
1916
1917 return 0;
1918}
1919
1920static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001921 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06001922{
1923 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001924 u32 src_offset = 0;
1925 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001926 int status = 0;
1927 IPW_DEBUG_FW(">> \n");
1928 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
1929 src_phys, dest_address, length);
1930 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001931 status = ipw_fw_dma_add_command_block(priv,
1932 src_phys + src_offset,
1933 dest_address +
1934 dest_offset,
1935 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001936 if (status) {
1937 IPW_DEBUG_FW_INFO(": Failed\n");
1938 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04001939 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001940 IPW_DEBUG_FW_INFO(": Added new cb\n");
1941
1942 src_offset += CB_MAX_LENGTH;
1943 dest_offset += CB_MAX_LENGTH;
1944 bytes_left -= CB_MAX_LENGTH;
1945 }
1946
1947 /* add the buffer tail */
1948 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001949 status =
1950 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
1951 dest_address + dest_offset,
1952 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001953 if (status) {
1954 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
1955 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04001956 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001957 IPW_DEBUG_FW_INFO
1958 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06001959 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001960
James Ketrenos43f66a62005-03-25 12:31:53 -06001961 IPW_DEBUG_FW("<< \n");
1962 return 0;
1963}
1964
1965static int ipw_fw_dma_wait(struct ipw_priv *priv)
1966{
1967 u32 current_index = 0;
1968 u32 watchdog = 0;
1969
1970 IPW_DEBUG_FW(">> : \n");
1971
1972 current_index = ipw_fw_dma_command_block_index(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04001973 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001974 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06001975
1976 while (current_index < priv->sram_desc.last_cb_index) {
1977 udelay(50);
1978 current_index = ipw_fw_dma_command_block_index(priv);
1979
1980 watchdog++;
1981
1982 if (watchdog > 400) {
1983 IPW_DEBUG_FW_INFO("Timeout\n");
1984 ipw_fw_dma_dump_command_block(priv);
1985 ipw_fw_dma_abort(priv);
1986 return -1;
1987 }
1988 }
1989
1990 ipw_fw_dma_abort(priv);
1991
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001992 /*Disable the DMA in the CSR register */
1993 ipw_set_bit(priv, CX2_RESET_REG,
James Ketrenos43f66a62005-03-25 12:31:53 -06001994 CX2_RESET_REG_MASTER_DISABLED | CX2_RESET_REG_STOP_MASTER);
1995
1996 IPW_DEBUG_FW("<< dmaWaitSync \n");
1997 return 0;
1998}
1999
Jeff Garzikbf794512005-07-31 13:07:26 -04002000static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002001{
2002 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002003 struct ieee80211_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06002004 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2005 network = list_entry(element, struct ieee80211_network, list);
2006 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2007 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002008 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002009 &priv->ieee->network_free_list);
2010 }
2011 }
2012}
2013
2014/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002015 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002016 * Reads debug register from domain0.
2017 * If card is present, pre-defined value should
2018 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002019 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002020 * @param priv
2021 * @return 1 if card is present, 0 otherwise
2022 */
2023static inline int ipw_alive(struct ipw_priv *priv)
2024{
2025 return ipw_read32(priv, 0x90) == 0xd55555d5;
2026}
2027
2028static inline int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2029 int timeout)
2030{
2031 int i = 0;
2032
2033 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002034 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002035 return i;
2036 mdelay(10);
2037 i += 10;
2038 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002039
James Ketrenos43f66a62005-03-25 12:31:53 -06002040 return -ETIME;
2041}
2042
Jeff Garzikbf794512005-07-31 13:07:26 -04002043/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002044 * the ipw hardware. It assumes the buffer has all the bits for the
2045 * image and the caller is handling the memory allocation and clean up.
2046 */
2047
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002048static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002049{
2050 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002051
James Ketrenos43f66a62005-03-25 12:31:53 -06002052 IPW_DEBUG_TRACE(">> \n");
2053 /* stop master. typical delay - 0 */
2054 ipw_set_bit(priv, CX2_RESET_REG, CX2_RESET_REG_STOP_MASTER);
2055
2056 rc = ipw_poll_bit(priv, CX2_RESET_REG,
2057 CX2_RESET_REG_MASTER_DISABLED, 100);
2058 if (rc < 0) {
2059 IPW_ERROR("stop master failed in 10ms\n");
2060 return -1;
2061 }
2062
2063 IPW_DEBUG_INFO("stop master %dms\n", rc);
2064
2065 return rc;
2066}
2067
2068static void ipw_arc_release(struct ipw_priv *priv)
2069{
2070 IPW_DEBUG_TRACE(">> \n");
2071 mdelay(5);
2072
2073 ipw_clear_bit(priv, CX2_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
2074
2075 /* no one knows timing, for safety add some delay */
2076 mdelay(5);
2077}
2078
2079struct fw_header {
2080 u32 version;
2081 u32 mode;
2082};
2083
2084struct fw_chunk {
2085 u32 address;
2086 u32 length;
2087};
2088
2089#define IPW_FW_MAJOR_VERSION 2
2090#define IPW_FW_MINOR_VERSION 2
2091
2092#define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
2093#define IPW_FW_MAJOR(x) (x & 0xff)
2094
2095#define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | \
2096 IPW_FW_MAJOR_VERSION)
2097
2098#define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
2099"." __stringify(IPW_FW_MINOR_VERSION) "-"
2100
2101#if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
2102#define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
2103#else
2104#define IPW_FW_NAME(x) "ipw2200_" x ".fw"
2105#endif
2106
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002107static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002108{
2109 int rc = 0, i, addr;
2110 u8 cr = 0;
2111 u16 *image;
2112
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002113 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002114
James Ketrenos43f66a62005-03-25 12:31:53 -06002115 IPW_DEBUG_TRACE(">> \n");
2116
2117 rc = ipw_stop_master(priv);
2118
2119 if (rc < 0)
2120 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002121
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002122// spin_lock_irqsave(&priv->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04002123
James Ketrenos43f66a62005-03-25 12:31:53 -06002124 for (addr = CX2_SHARED_LOWER_BOUND;
2125 addr < CX2_REGISTER_DOMAIN1_END; addr += 4) {
2126 ipw_write32(priv, addr, 0);
2127 }
2128
2129 /* no ucode (yet) */
2130 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2131 /* destroy DMA queues */
2132 /* reset sequence */
2133
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002134 ipw_write_reg32(priv, CX2_MEM_HALT_AND_RESET, CX2_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06002135 ipw_arc_release(priv);
2136 ipw_write_reg32(priv, CX2_MEM_HALT_AND_RESET, CX2_BIT_HALT_RESET_OFF);
2137 mdelay(1);
2138
2139 /* reset PHY */
2140 ipw_write_reg32(priv, CX2_INTERNAL_CMD_EVENT, CX2_BASEBAND_POWER_DOWN);
2141 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002142
James Ketrenos43f66a62005-03-25 12:31:53 -06002143 ipw_write_reg32(priv, CX2_INTERNAL_CMD_EVENT, 0);
2144 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002145
James Ketrenos43f66a62005-03-25 12:31:53 -06002146 /* enable ucode store */
2147 ipw_write_reg8(priv, DINO_CONTROL_REG, 0x0);
2148 ipw_write_reg8(priv, DINO_CONTROL_REG, DINO_ENABLE_CS);
2149 mdelay(1);
2150
2151 /* write ucode */
2152 /**
2153 * @bug
2154 * Do NOT set indirect address register once and then
2155 * store data to indirect data register in the loop.
2156 * It seems very reasonable, but in this case DINO do not
2157 * accept ucode. It is essential to set address each time.
2158 */
2159 /* load new ipw uCode */
2160 for (i = 0; i < len / 2; i++)
2161 ipw_write_reg16(priv, CX2_BASEBAND_CONTROL_STORE, image[i]);
2162
James Ketrenos43f66a62005-03-25 12:31:53 -06002163 /* enable DINO */
2164 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 0);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002165 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002166
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002167 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002168
2169 /* wait for alive response */
2170 for (i = 0; i < 100; i++) {
2171 /* poll for incoming data */
2172 cr = ipw_read_reg8(priv, CX2_BASEBAND_CONTROL_STATUS);
2173 if (cr & DINO_RXFIFO_DATA)
2174 break;
2175 mdelay(1);
2176 }
2177
2178 if (cr & DINO_RXFIFO_DATA) {
2179 /* alive_command_responce size is NOT multiple of 4 */
2180 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04002181
2182 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06002183 response_buffer[i] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002184 ipw_read_reg32(priv, CX2_BASEBAND_RX_FIFO_READ);
James Ketrenos43f66a62005-03-25 12:31:53 -06002185 memcpy(&priv->dino_alive, response_buffer,
2186 sizeof(priv->dino_alive));
2187 if (priv->dino_alive.alive_command == 1
2188 && priv->dino_alive.ucode_valid == 1) {
2189 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002190 IPW_DEBUG_INFO
2191 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2192 "of %02d/%02d/%02d %02d:%02d\n",
2193 priv->dino_alive.software_revision,
2194 priv->dino_alive.software_revision,
2195 priv->dino_alive.device_identifier,
2196 priv->dino_alive.device_identifier,
2197 priv->dino_alive.time_stamp[0],
2198 priv->dino_alive.time_stamp[1],
2199 priv->dino_alive.time_stamp[2],
2200 priv->dino_alive.time_stamp[3],
2201 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002202 } else {
2203 IPW_DEBUG_INFO("Microcode is not alive\n");
2204 rc = -EINVAL;
2205 }
2206 } else {
2207 IPW_DEBUG_INFO("No alive response from DINO\n");
2208 rc = -ETIME;
2209 }
2210
2211 /* disable DINO, otherwise for some reason
2212 firmware have problem getting alive resp. */
2213 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 0);
2214
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002215// spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002216
2217 return rc;
2218}
2219
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002220static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002221{
2222 int rc = -1;
2223 int offset = 0;
2224 struct fw_chunk *chunk;
2225 dma_addr_t shared_phys;
2226 u8 *shared_virt;
2227
2228 IPW_DEBUG_TRACE("<< : \n");
2229 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
2230
2231 if (!shared_virt)
2232 return -ENOMEM;
2233
2234 memmove(shared_virt, data, len);
2235
2236 /* Start the Dma */
2237 rc = ipw_fw_dma_enable(priv);
2238
2239 if (priv->sram_desc.last_cb_index > 0) {
2240 /* the DMA is already ready this would be a bug. */
2241 BUG();
2242 goto out;
2243 }
2244
2245 do {
2246 chunk = (struct fw_chunk *)(data + offset);
2247 offset += sizeof(struct fw_chunk);
2248 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04002249 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06002250 * offeset*/
2251 /* Dma loading */
2252 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
2253 chunk->address, chunk->length);
2254 if (rc) {
2255 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
2256 goto out;
2257 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002258
James Ketrenos43f66a62005-03-25 12:31:53 -06002259 offset += chunk->length;
2260 } while (offset < len);
2261
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002262 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06002263 rc = ipw_fw_dma_kick(priv);
2264 if (rc) {
2265 IPW_ERROR("dmaKick Failed\n");
2266 goto out;
2267 }
2268
2269 rc = ipw_fw_dma_wait(priv);
2270 if (rc) {
2271 IPW_ERROR("dmaWaitSync Failed\n");
2272 goto out;
2273 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002274 out:
2275 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06002276 return rc;
2277}
2278
2279/* stop nic */
2280static int ipw_stop_nic(struct ipw_priv *priv)
2281{
2282 int rc = 0;
2283
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002284 /* stop */
James Ketrenos43f66a62005-03-25 12:31:53 -06002285 ipw_write32(priv, CX2_RESET_REG, CX2_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002286
2287 rc = ipw_poll_bit(priv, CX2_RESET_REG,
2288 CX2_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06002289 if (rc < 0) {
2290 IPW_ERROR("wait for reg master disabled failed\n");
2291 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002292 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002293
2294 ipw_set_bit(priv, CX2_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04002295
James Ketrenos43f66a62005-03-25 12:31:53 -06002296 return rc;
2297}
2298
2299static void ipw_start_nic(struct ipw_priv *priv)
2300{
2301 IPW_DEBUG_TRACE(">>\n");
2302
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002303 /* prvHwStartNic release ARC */
James Ketrenos43f66a62005-03-25 12:31:53 -06002304 ipw_clear_bit(priv, CX2_RESET_REG,
Jeff Garzikbf794512005-07-31 13:07:26 -04002305 CX2_RESET_REG_MASTER_DISABLED |
2306 CX2_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06002307 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04002308
James Ketrenos43f66a62005-03-25 12:31:53 -06002309 /* enable power management */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002310 ipw_set_bit(priv, CX2_GP_CNTRL_RW,
2311 CX2_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06002312
2313 IPW_DEBUG_TRACE("<<\n");
2314}
Jeff Garzikbf794512005-07-31 13:07:26 -04002315
James Ketrenos43f66a62005-03-25 12:31:53 -06002316static int ipw_init_nic(struct ipw_priv *priv)
2317{
2318 int rc;
2319
2320 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002321 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06002322 /*prvHwInitNic */
2323 /* set "initialization complete" bit to move adapter to D0 state */
2324 ipw_set_bit(priv, CX2_GP_CNTRL_RW, CX2_GP_CNTRL_BIT_INIT_DONE);
2325
2326 /* low-level PLL activation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002327 ipw_write32(priv, CX2_READ_INT_REGISTER,
2328 CX2_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002329
2330 /* wait for clock stabilization */
Jeff Garzikbf794512005-07-31 13:07:26 -04002331 rc = ipw_poll_bit(priv, CX2_GP_CNTRL_RW,
2332 CX2_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002333 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06002334 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
2335
2336 /* assert SW reset */
2337 ipw_set_bit(priv, CX2_RESET_REG, CX2_RESET_REG_SW_RESET);
2338
2339 udelay(10);
2340
2341 /* set "initialization complete" bit to move adapter to D0 state */
2342 ipw_set_bit(priv, CX2_GP_CNTRL_RW, CX2_GP_CNTRL_BIT_INIT_DONE);
2343
2344 IPW_DEBUG_TRACE(">>\n");
2345 return 0;
2346}
2347
Jeff Garzikbf794512005-07-31 13:07:26 -04002348/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06002349 * Probe is an ok place to call this from.
2350 */
2351static int ipw_reset_nic(struct ipw_priv *priv)
2352{
2353 int rc = 0;
2354
2355 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002356
James Ketrenos43f66a62005-03-25 12:31:53 -06002357 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002358
James Ketrenos43f66a62005-03-25 12:31:53 -06002359 /* Clear the 'host command active' bit... */
2360 priv->status &= ~STATUS_HCMD_ACTIVE;
2361 wake_up_interruptible(&priv->wait_command_queue);
2362
2363 IPW_DEBUG_TRACE("<<\n");
2364 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002365}
James Ketrenos43f66a62005-03-25 12:31:53 -06002366
Jeff Garzikbf794512005-07-31 13:07:26 -04002367static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06002368 const struct firmware **fw, const char *name)
2369{
2370 struct fw_header *header;
2371 int rc;
2372
2373 /* ask firmware_class module to get the boot firmware off disk */
2374 rc = request_firmware(fw, name, &priv->pci_dev->dev);
2375 if (rc < 0) {
2376 IPW_ERROR("%s load failed: Reason %d\n", name, rc);
2377 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002378 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002379
2380 header = (struct fw_header *)(*fw)->data;
2381 if (IPW_FW_MAJOR(header->version) != IPW_FW_MAJOR_VERSION) {
2382 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
2383 name,
2384 IPW_FW_MAJOR(header->version), IPW_FW_MAJOR_VERSION);
2385 return -EINVAL;
2386 }
2387
Jiri Bencaaa4d302005-06-07 14:58:41 +02002388 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06002389 name,
2390 IPW_FW_MAJOR(header->version),
2391 IPW_FW_MINOR(header->version),
2392 (*fw)->size - sizeof(struct fw_header));
2393 return 0;
2394}
2395
2396#define CX2_RX_BUF_SIZE (3000)
2397
2398static inline void ipw_rx_queue_reset(struct ipw_priv *priv,
2399 struct ipw_rx_queue *rxq)
2400{
2401 unsigned long flags;
2402 int i;
2403
2404 spin_lock_irqsave(&rxq->lock, flags);
2405
2406 INIT_LIST_HEAD(&rxq->rx_free);
2407 INIT_LIST_HEAD(&rxq->rx_used);
2408
2409 /* Fill the rx_used queue with _all_ of the Rx buffers */
2410 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
2411 /* In the reset function, these buffers may have been allocated
2412 * to an SKB, so we need to unmap and free potential storage */
2413 if (rxq->pool[i].skb != NULL) {
2414 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002415 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002416 dev_kfree_skb(rxq->pool[i].skb);
2417 }
2418 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
2419 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002420
James Ketrenos43f66a62005-03-25 12:31:53 -06002421 /* Set us so that we have processed and used all buffers, but have
2422 * not restocked the Rx queue with fresh buffers */
2423 rxq->read = rxq->write = 0;
2424 rxq->processed = RX_QUEUE_SIZE - 1;
2425 rxq->free_count = 0;
2426 spin_unlock_irqrestore(&rxq->lock, flags);
2427}
2428
2429#ifdef CONFIG_PM
2430static int fw_loaded = 0;
2431static const struct firmware *bootfw = NULL;
2432static const struct firmware *firmware = NULL;
2433static const struct firmware *ucode = NULL;
2434#endif
2435
2436static int ipw_load(struct ipw_priv *priv)
2437{
2438#ifndef CONFIG_PM
2439 const struct firmware *bootfw = NULL;
2440 const struct firmware *firmware = NULL;
2441 const struct firmware *ucode = NULL;
2442#endif
2443 int rc = 0, retries = 3;
2444
2445#ifdef CONFIG_PM
2446 if (!fw_loaded) {
2447#endif
2448 rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot"));
Jeff Garzikbf794512005-07-31 13:07:26 -04002449 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06002450 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04002451
James Ketrenos43f66a62005-03-25 12:31:53 -06002452 switch (priv->ieee->iw_mode) {
2453 case IW_MODE_ADHOC:
Jeff Garzikbf794512005-07-31 13:07:26 -04002454 rc = ipw_get_fw(priv, &ucode,
James Ketrenos43f66a62005-03-25 12:31:53 -06002455 IPW_FW_NAME("ibss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04002456 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06002457 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04002458
James Ketrenos43f66a62005-03-25 12:31:53 -06002459 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss"));
2460 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04002461
James Ketrenosea2b26e2005-08-24 21:25:16 -05002462#ifdef CONFIG_IPW_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06002463 case IW_MODE_MONITOR:
Jeff Garzikbf794512005-07-31 13:07:26 -04002464 rc = ipw_get_fw(priv, &ucode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05002465 IPW_FW_NAME("sniffer_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04002466 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06002467 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04002468
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002469 rc = ipw_get_fw(priv, &firmware,
2470 IPW_FW_NAME("sniffer"));
James Ketrenos43f66a62005-03-25 12:31:53 -06002471 break;
2472#endif
2473 case IW_MODE_INFRA:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002474 rc = ipw_get_fw(priv, &ucode, IPW_FW_NAME("bss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04002475 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06002476 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04002477
James Ketrenos43f66a62005-03-25 12:31:53 -06002478 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("bss"));
2479 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04002480
James Ketrenos43f66a62005-03-25 12:31:53 -06002481 default:
2482 rc = -EINVAL;
2483 }
2484
Jeff Garzikbf794512005-07-31 13:07:26 -04002485 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06002486 goto error;
2487
2488#ifdef CONFIG_PM
2489 fw_loaded = 1;
2490 }
2491#endif
2492
2493 if (!priv->rxq)
2494 priv->rxq = ipw_rx_queue_alloc(priv);
2495 else
2496 ipw_rx_queue_reset(priv, priv->rxq);
2497 if (!priv->rxq) {
2498 IPW_ERROR("Unable to initialize Rx queue\n");
2499 goto error;
2500 }
2501
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002502 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06002503 /* Ensure interrupts are disabled */
2504 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL);
2505 priv->status &= ~STATUS_INT_ENABLED;
2506
2507 /* ack pending interrupts */
2508 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04002509
James Ketrenos43f66a62005-03-25 12:31:53 -06002510 ipw_stop_nic(priv);
2511
2512 rc = ipw_reset_nic(priv);
2513 if (rc) {
2514 IPW_ERROR("Unable to reset NIC\n");
2515 goto error;
2516 }
2517
Jeff Garzikbf794512005-07-31 13:07:26 -04002518 ipw_zero_memory(priv, CX2_NIC_SRAM_LOWER_BOUND,
James Ketrenos43f66a62005-03-25 12:31:53 -06002519 CX2_NIC_SRAM_UPPER_BOUND - CX2_NIC_SRAM_LOWER_BOUND);
2520
2521 /* DMA the initial boot firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04002522 rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06002523 bootfw->size - sizeof(struct fw_header));
2524 if (rc < 0) {
2525 IPW_ERROR("Unable to load boot firmware\n");
2526 goto error;
2527 }
2528
2529 /* kick start the device */
2530 ipw_start_nic(priv);
2531
2532 /* wait for the device to finish it's initial startup sequence */
Jeff Garzikbf794512005-07-31 13:07:26 -04002533 rc = ipw_poll_bit(priv, CX2_INTA_RW,
2534 CX2_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06002535 if (rc < 0) {
2536 IPW_ERROR("device failed to boot initial fw image\n");
2537 goto error;
2538 }
2539 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
2540
Jeff Garzikbf794512005-07-31 13:07:26 -04002541 /* ack fw init done interrupt */
James Ketrenos43f66a62005-03-25 12:31:53 -06002542 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_BIT_FW_INITIALIZATION_DONE);
2543
2544 /* DMA the ucode into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04002545 rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06002546 ucode->size - sizeof(struct fw_header));
2547 if (rc < 0) {
2548 IPW_ERROR("Unable to load ucode\n");
2549 goto error;
2550 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002551
James Ketrenos43f66a62005-03-25 12:31:53 -06002552 /* stop nic */
2553 ipw_stop_nic(priv);
2554
2555 /* DMA bss firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04002556 rc = ipw_load_firmware(priv, firmware->data +
2557 sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06002558 firmware->size - sizeof(struct fw_header));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002559 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002560 IPW_ERROR("Unable to load firmware\n");
2561 goto error;
2562 }
2563
2564 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2565
2566 rc = ipw_queue_reset(priv);
2567 if (rc) {
2568 IPW_ERROR("Unable to initialize queues\n");
2569 goto error;
2570 }
2571
2572 /* Ensure interrupts are disabled */
2573 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04002574
James Ketrenos43f66a62005-03-25 12:31:53 -06002575 /* kick start the device */
2576 ipw_start_nic(priv);
2577
2578 if (ipw_read32(priv, CX2_INTA_RW) & CX2_INTA_BIT_PARITY_ERROR) {
2579 if (retries > 0) {
2580 IPW_WARNING("Parity error. Retrying init.\n");
2581 retries--;
2582 goto retry;
2583 }
2584
2585 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
2586 rc = -EIO;
2587 goto error;
2588 }
2589
2590 /* wait for the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04002591 rc = ipw_poll_bit(priv, CX2_INTA_RW,
2592 CX2_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06002593 if (rc < 0) {
2594 IPW_ERROR("device failed to start after 500ms\n");
2595 goto error;
2596 }
2597 IPW_DEBUG_INFO("device response after %dms\n", rc);
2598
2599 /* ack fw init done interrupt */
2600 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_BIT_FW_INITIALIZATION_DONE);
2601
2602 /* read eeprom data and initialize the eeprom region of sram */
2603 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002604 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06002605
2606 /* enable interrupts */
2607 ipw_enable_interrupts(priv);
2608
2609 /* Ensure our queue has valid packets */
2610 ipw_rx_queue_replenish(priv);
2611
2612 ipw_write32(priv, CX2_RX_READ_INDEX, priv->rxq->read);
2613
2614 /* ack pending interrupts */
2615 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_MASK_ALL);
2616
2617#ifndef CONFIG_PM
2618 release_firmware(bootfw);
2619 release_firmware(ucode);
2620 release_firmware(firmware);
2621#endif
2622 return 0;
2623
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002624 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06002625 if (priv->rxq) {
2626 ipw_rx_queue_free(priv, priv->rxq);
2627 priv->rxq = NULL;
2628 }
2629 ipw_tx_queue_free(priv);
2630 if (bootfw)
2631 release_firmware(bootfw);
2632 if (ucode)
2633 release_firmware(ucode);
2634 if (firmware)
2635 release_firmware(firmware);
2636#ifdef CONFIG_PM
2637 fw_loaded = 0;
2638 bootfw = ucode = firmware = NULL;
2639#endif
2640
2641 return rc;
2642}
2643
Jeff Garzikbf794512005-07-31 13:07:26 -04002644/**
James Ketrenos43f66a62005-03-25 12:31:53 -06002645 * DMA services
2646 *
2647 * Theory of operation
2648 *
2649 * A queue is a circular buffers with 'Read' and 'Write' pointers.
2650 * 2 empty entries always kept in the buffer to protect from overflow.
2651 *
2652 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04002653 * the packet for Tx, free space become < low mark, Tx queue stopped. When
2654 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06002655 * Tx queue resumed.
2656 *
2657 * The IPW operates with six queues, one receive queue in the device's
2658 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04002659 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06002660 *
Jeff Garzikbf794512005-07-31 13:07:26 -04002661 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06002662 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04002663 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06002664 * we only utilize the first data transmit queue (queue1).
2665 */
2666
2667/**
2668 * Driver allocates buffers of this size for Rx
2669 */
2670
2671static inline int ipw_queue_space(const struct clx2_queue *q)
2672{
2673 int s = q->last_used - q->first_empty;
2674 if (s <= 0)
2675 s += q->n_bd;
2676 s -= 2; /* keep some reserve to not confuse empty and full situations */
2677 if (s < 0)
2678 s = 0;
2679 return s;
2680}
2681
2682static inline int ipw_queue_inc_wrap(int index, int n_bd)
2683{
2684 return (++index == n_bd) ? 0 : index;
2685}
2686
2687/**
2688 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04002689 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002690 * @param q queue to init
2691 * @param count Number of BD's to allocate. Should be power of 2
2692 * @param read_register Address for 'read' register
2693 * (not offset within BAR, full address)
2694 * @param write_register Address for 'write' register
2695 * (not offset within BAR, full address)
2696 * @param base_register Address for 'base' register
2697 * (not offset within BAR, full address)
2698 * @param size Address for 'size' register
2699 * (not offset within BAR, full address)
2700 */
Jeff Garzikbf794512005-07-31 13:07:26 -04002701static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002702 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06002703{
2704 q->n_bd = count;
2705
2706 q->low_mark = q->n_bd / 4;
2707 if (q->low_mark < 4)
2708 q->low_mark = 4;
2709
2710 q->high_mark = q->n_bd / 8;
2711 if (q->high_mark < 2)
2712 q->high_mark = 2;
2713
2714 q->first_empty = q->last_used = 0;
2715 q->reg_r = read;
2716 q->reg_w = write;
2717
2718 ipw_write32(priv, base, q->dma_addr);
2719 ipw_write32(priv, size, count);
2720 ipw_write32(priv, read, 0);
2721 ipw_write32(priv, write, 0);
2722
2723 _ipw_read32(priv, 0x90);
2724}
2725
Jeff Garzikbf794512005-07-31 13:07:26 -04002726static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06002727 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002728 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06002729{
2730 struct pci_dev *dev = priv->pci_dev;
2731
2732 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
2733 if (!q->txb) {
2734 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
2735 return -ENOMEM;
2736 }
2737
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002738 q->bd =
2739 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002740 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02002741 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002742 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06002743 kfree(q->txb);
2744 q->txb = NULL;
2745 return -ENOMEM;
2746 }
2747
2748 ipw_queue_init(priv, &q->q, count, read, write, base, size);
2749 return 0;
2750}
2751
2752/**
2753 * Free one TFD, those at index [txq->q.last_used].
2754 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04002755 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002756 * @param dev
2757 * @param txq
2758 */
2759static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
2760 struct clx2_tx_queue *txq)
2761{
2762 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
2763 struct pci_dev *dev = priv->pci_dev;
2764 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04002765
James Ketrenos43f66a62005-03-25 12:31:53 -06002766 /* classify bd */
2767 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
2768 /* nothing to cleanup after for host commands */
2769 return;
2770
2771 /* sanity check */
2772 if (bd->u.data.num_chunks > NUM_TFD_CHUNKS) {
2773 IPW_ERROR("Too many chunks: %i\n", bd->u.data.num_chunks);
2774 /** @todo issue fatal error, it is quite serious situation */
2775 return;
2776 }
2777
2778 /* unmap chunks if any */
2779 for (i = 0; i < bd->u.data.num_chunks; i++) {
2780 pci_unmap_single(dev, bd->u.data.chunk_ptr[i],
2781 bd->u.data.chunk_len[i], PCI_DMA_TODEVICE);
2782 if (txq->txb[txq->q.last_used]) {
2783 ieee80211_txb_free(txq->txb[txq->q.last_used]);
2784 txq->txb[txq->q.last_used] = NULL;
2785 }
2786 }
2787}
2788
2789/**
2790 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04002791 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002792 * Empty queue by removing and destroying all BD's.
2793 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04002794 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002795 * @param dev
2796 * @param q
2797 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002798static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06002799{
2800 struct clx2_queue *q = &txq->q;
2801 struct pci_dev *dev = priv->pci_dev;
2802
Jeff Garzikbf794512005-07-31 13:07:26 -04002803 if (q->n_bd == 0)
2804 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06002805
2806 /* first, empty all BD's */
2807 for (; q->first_empty != q->last_used;
2808 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
2809 ipw_queue_tx_free_tfd(priv, txq);
2810 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002811
James Ketrenos43f66a62005-03-25 12:31:53 -06002812 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002813 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06002814 q->dma_addr);
2815 kfree(txq->txb);
2816
2817 /* 0 fill whole structure */
2818 memset(txq, 0, sizeof(*txq));
2819}
2820
James Ketrenos43f66a62005-03-25 12:31:53 -06002821/**
2822 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04002823 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002824 * @param priv
2825 */
2826static void ipw_tx_queue_free(struct ipw_priv *priv)
2827{
2828 /* Tx CMD queue */
2829 ipw_queue_tx_free(priv, &priv->txq_cmd);
2830
2831 /* Tx queues */
2832 ipw_queue_tx_free(priv, &priv->txq[0]);
2833 ipw_queue_tx_free(priv, &priv->txq[1]);
2834 ipw_queue_tx_free(priv, &priv->txq[2]);
2835 ipw_queue_tx_free(priv, &priv->txq[3]);
2836}
2837
2838static void inline __maybe_wake_tx(struct ipw_priv *priv)
2839{
2840 if (netif_running(priv->net_dev)) {
2841 switch (priv->port_type) {
2842 case DCR_TYPE_MU_BSS:
2843 case DCR_TYPE_MU_IBSS:
2844 if (!(priv->status & STATUS_ASSOCIATED)) {
2845 return;
2846 }
2847 }
2848 netif_wake_queue(priv->net_dev);
2849 }
2850
2851}
2852
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002853static inline void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06002854{
2855 /* First 3 bytes are manufacturer */
2856 bssid[0] = priv->mac_addr[0];
2857 bssid[1] = priv->mac_addr[1];
2858 bssid[2] = priv->mac_addr[2];
2859
2860 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002861 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06002862
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002863 bssid[0] &= 0xfe; /* clear multicast bit */
2864 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06002865}
2866
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002867static inline u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06002868{
2869 struct ipw_station_entry entry;
2870 int i;
2871
2872 for (i = 0; i < priv->num_stations; i++) {
2873 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
2874 /* Another node is active in network */
2875 priv->missed_adhoc_beacons = 0;
2876 if (!(priv->config & CFG_STATIC_CHANNEL))
2877 /* when other nodes drop out, we drop out */
2878 priv->config &= ~CFG_ADHOC_PERSIST;
2879
2880 return i;
2881 }
2882 }
2883
2884 if (i == MAX_STATIONS)
2885 return IPW_INVALID_STATION;
2886
2887 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
2888
2889 entry.reserved = 0;
2890 entry.support_mode = 0;
2891 memcpy(entry.mac_addr, bssid, ETH_ALEN);
2892 memcpy(priv->stations[i], bssid, ETH_ALEN);
2893 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002894 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06002895 priv->num_stations++;
2896
2897 return i;
2898}
2899
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002900static inline u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06002901{
2902 int i;
2903
Jeff Garzikbf794512005-07-31 13:07:26 -04002904 for (i = 0; i < priv->num_stations; i++)
2905 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06002906 return i;
2907
2908 return IPW_INVALID_STATION;
2909}
2910
2911static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
2912{
2913 int err;
2914
2915 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))) {
2916 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
2917 return;
2918 }
2919
2920 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
2921 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04002922 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06002923 priv->assoc_request.channel);
2924
2925 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
2926 priv->status |= STATUS_DISASSOCIATING;
2927
2928 if (quiet)
2929 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
2930 else
2931 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
2932 err = ipw_send_associate(priv, &priv->assoc_request);
2933 if (err) {
2934 IPW_DEBUG_HC("Attempt to send [dis]associate command "
2935 "failed.\n");
2936 return;
2937 }
2938
2939}
2940
2941static void ipw_disassociate(void *data)
2942{
2943 ipw_send_disassociate(data, 0);
2944}
2945
James Ketrenos43f66a62005-03-25 12:31:53 -06002946struct ipw_status_code {
2947 u16 status;
2948 const char *reason;
2949};
2950
2951static const struct ipw_status_code ipw_status_codes[] = {
2952 {0x00, "Successful"},
2953 {0x01, "Unspecified failure"},
2954 {0x0A, "Cannot support all requested capabilities in the "
2955 "Capability information field"},
2956 {0x0B, "Reassociation denied due to inability to confirm that "
2957 "association exists"},
2958 {0x0C, "Association denied due to reason outside the scope of this "
2959 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002960 {0x0D,
2961 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06002962 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002963 {0x0E,
2964 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06002965 "transaction sequence number out of expected sequence"},
2966 {0x0F, "Authentication rejected because of challenge failure"},
2967 {0x10, "Authentication rejected due to timeout waiting for next "
2968 "frame in sequence"},
2969 {0x11, "Association denied because AP is unable to handle additional "
2970 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002971 {0x12,
2972 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06002973 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002974 {0x13,
2975 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06002976 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002977 {0x14,
2978 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06002979 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002980 {0x15,
2981 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06002982 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002983 {0x19,
2984 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06002985 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002986 {0x1A,
2987 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06002988 "DSSS-OFDM operation"},
2989 {0x28, "Invalid Information Element"},
2990 {0x29, "Group Cipher is not valid"},
2991 {0x2A, "Pairwise Cipher is not valid"},
2992 {0x2B, "AKMP is not valid"},
2993 {0x2C, "Unsupported RSN IE version"},
2994 {0x2D, "Invalid RSN IE Capabilities"},
2995 {0x2E, "Cipher suite is rejected per security policy"},
2996};
2997
2998#ifdef CONFIG_IPW_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04002999static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003000{
3001 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003002 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003003 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003004 return ipw_status_codes[i].reason;
3005 return "Unknown status value.";
3006}
3007#endif
3008
3009static void inline average_init(struct average *avg)
3010{
3011 memset(avg, 0, sizeof(*avg));
3012}
3013
3014static void inline average_add(struct average *avg, s16 val)
3015{
3016 avg->sum -= avg->entries[avg->pos];
3017 avg->sum += val;
3018 avg->entries[avg->pos++] = val;
3019 if (unlikely(avg->pos == AVG_ENTRIES)) {
3020 avg->init = 1;
3021 avg->pos = 0;
3022 }
3023}
3024
3025static s16 inline average_value(struct average *avg)
3026{
3027 if (!unlikely(avg->init)) {
3028 if (avg->pos)
3029 return avg->sum / avg->pos;
3030 return 0;
3031 }
3032
3033 return avg->sum / AVG_ENTRIES;
3034}
3035
3036static void ipw_reset_stats(struct ipw_priv *priv)
3037{
3038 u32 len = sizeof(u32);
3039
3040 priv->quality = 0;
3041
3042 average_init(&priv->average_missed_beacons);
3043 average_init(&priv->average_rssi);
3044 average_init(&priv->average_noise);
3045
3046 priv->last_rate = 0;
3047 priv->last_missed_beacons = 0;
3048 priv->last_rx_packets = 0;
3049 priv->last_tx_packets = 0;
3050 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003051
James Ketrenos43f66a62005-03-25 12:31:53 -06003052 /* Firmware managed, reset only when NIC is restarted, so we have to
3053 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003054 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003055 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003056 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003057 &priv->last_tx_failures, &len);
3058
3059 /* Driver managed, reset with each association */
3060 priv->missed_adhoc_beacons = 0;
3061 priv->missed_beacons = 0;
3062 priv->tx_packets = 0;
3063 priv->rx_packets = 0;
3064
3065}
3066
James Ketrenos43f66a62005-03-25 12:31:53 -06003067static inline u32 ipw_get_max_rate(struct ipw_priv *priv)
3068{
3069 u32 i = 0x80000000;
3070 u32 mask = priv->rates_mask;
3071 /* If currently associated in B mode, restrict the maximum
3072 * rate match to B rates */
3073 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3074 mask &= IEEE80211_CCK_RATES_MASK;
3075
3076 /* TODO: Verify that the rate is supported by the current rates
3077 * list. */
3078
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003079 while (i && !(mask & i))
3080 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003081 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003082 case IEEE80211_CCK_RATE_1MB_MASK:
3083 return 1000000;
3084 case IEEE80211_CCK_RATE_2MB_MASK:
3085 return 2000000;
3086 case IEEE80211_CCK_RATE_5MB_MASK:
3087 return 5500000;
3088 case IEEE80211_OFDM_RATE_6MB_MASK:
3089 return 6000000;
3090 case IEEE80211_OFDM_RATE_9MB_MASK:
3091 return 9000000;
3092 case IEEE80211_CCK_RATE_11MB_MASK:
3093 return 11000000;
3094 case IEEE80211_OFDM_RATE_12MB_MASK:
3095 return 12000000;
3096 case IEEE80211_OFDM_RATE_18MB_MASK:
3097 return 18000000;
3098 case IEEE80211_OFDM_RATE_24MB_MASK:
3099 return 24000000;
3100 case IEEE80211_OFDM_RATE_36MB_MASK:
3101 return 36000000;
3102 case IEEE80211_OFDM_RATE_48MB_MASK:
3103 return 48000000;
3104 case IEEE80211_OFDM_RATE_54MB_MASK:
3105 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003106 }
3107
Jeff Garzikbf794512005-07-31 13:07:26 -04003108 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06003109 return 11000000;
3110 else
3111 return 54000000;
3112}
3113
3114static u32 ipw_get_current_rate(struct ipw_priv *priv)
3115{
3116 u32 rate, len = sizeof(rate);
3117 int err;
3118
Jeff Garzikbf794512005-07-31 13:07:26 -04003119 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003120 return 0;
3121
3122 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04003123 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06003124 &len);
3125 if (err) {
3126 IPW_DEBUG_INFO("failed querying ordinals.\n");
3127 return 0;
3128 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003129 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06003130 return ipw_get_max_rate(priv);
3131
3132 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003133 case IPW_TX_RATE_1MB:
3134 return 1000000;
3135 case IPW_TX_RATE_2MB:
3136 return 2000000;
3137 case IPW_TX_RATE_5MB:
3138 return 5500000;
3139 case IPW_TX_RATE_6MB:
3140 return 6000000;
3141 case IPW_TX_RATE_9MB:
3142 return 9000000;
3143 case IPW_TX_RATE_11MB:
3144 return 11000000;
3145 case IPW_TX_RATE_12MB:
3146 return 12000000;
3147 case IPW_TX_RATE_18MB:
3148 return 18000000;
3149 case IPW_TX_RATE_24MB:
3150 return 24000000;
3151 case IPW_TX_RATE_36MB:
3152 return 36000000;
3153 case IPW_TX_RATE_48MB:
3154 return 48000000;
3155 case IPW_TX_RATE_54MB:
3156 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003157 }
3158
3159 return 0;
3160}
3161
James Ketrenosea2b26e2005-08-24 21:25:16 -05003162#define PERFECT_RSSI (-20)
James Ketrenos43f66a62005-03-25 12:31:53 -06003163#define WORST_RSSI (-85)
3164#define IPW_STATS_INTERVAL (2 * HZ)
3165static void ipw_gather_stats(struct ipw_priv *priv)
3166{
3167 u32 rx_err, rx_err_delta, rx_packets_delta;
3168 u32 tx_failures, tx_failures_delta, tx_packets_delta;
3169 u32 missed_beacons_percent, missed_beacons_delta;
3170 u32 quality = 0;
3171 u32 len = sizeof(u32);
3172 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04003173 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003174 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05003175 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06003176
3177 if (!(priv->status & STATUS_ASSOCIATED)) {
3178 priv->quality = 0;
3179 return;
3180 }
3181
3182 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04003183 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06003184 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003185 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06003186 priv->last_missed_beacons = priv->missed_beacons;
3187 if (priv->assoc_request.beacon_interval) {
3188 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003189 (HZ * priv->assoc_request.beacon_interval) /
3190 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06003191 } else {
3192 missed_beacons_percent = 0;
3193 }
3194 average_add(&priv->average_missed_beacons, missed_beacons_percent);
3195
3196 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
3197 rx_err_delta = rx_err - priv->last_rx_err;
3198 priv->last_rx_err = rx_err;
3199
3200 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
3201 tx_failures_delta = tx_failures - priv->last_tx_failures;
3202 priv->last_tx_failures = tx_failures;
3203
3204 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
3205 priv->last_rx_packets = priv->rx_packets;
3206
3207 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
3208 priv->last_tx_packets = priv->tx_packets;
3209
3210 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04003211 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003212 * Missed beacon: 100% = 0, 0% = 70% missed
3213 * Rate: 60% = 1Mbs, 100% = Max
3214 * Rx and Tx errors represent a straight % of total Rx/Tx
3215 * RSSI: 100% = > -50, 0% = < -80
3216 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04003217 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003218 * The lowest computed quality is used.
3219 *
3220 */
3221#define BEACON_THRESHOLD 5
3222 beacon_quality = 100 - missed_beacons_percent;
3223 if (beacon_quality < BEACON_THRESHOLD)
3224 beacon_quality = 0;
3225 else
Jeff Garzikbf794512005-07-31 13:07:26 -04003226 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003227 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04003228 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003229 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04003230
James Ketrenos43f66a62005-03-25 12:31:53 -06003231 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05003232 max_rate = ipw_get_max_rate(priv);
3233 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06003234 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
3235 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04003236
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003237 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04003238 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003239 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06003240 else
3241 rx_quality = 100;
3242 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
3243 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04003244
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003245 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04003246 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003247 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06003248 else
3249 tx_quality = 100;
3250 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
3251 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04003252
James Ketrenos43f66a62005-03-25 12:31:53 -06003253 rssi = average_value(&priv->average_rssi);
3254 if (rssi > PERFECT_RSSI)
3255 signal_quality = 100;
3256 else if (rssi < WORST_RSSI)
3257 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05003258 else /* qual = 100a^2 - 15ab + 62b^2 / a^2 */
3259 signal_quality =
3260 (100 *
3261 (PERFECT_RSSI - WORST_RSSI) *
3262 (PERFECT_RSSI - WORST_RSSI) -
3263 (PERFECT_RSSI - rssi) *
3264 (15 * (PERFECT_RSSI - WORST_RSSI) +
3265 62 * (PERFECT_RSSI - rssi))) /
3266 ((PERFECT_RSSI - WORST_RSSI) * (PERFECT_RSSI - WORST_RSSI));
3267
James Ketrenos43f66a62005-03-25 12:31:53 -06003268 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
3269 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04003270
3271 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06003272 min(rate_quality,
3273 min(tx_quality, min(rx_quality, signal_quality))));
3274 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003275 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
3276 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003277 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003278 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
3279 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003280 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003281 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
3282 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003283 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003284 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
3285 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003286 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003287 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
3288 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003289
3290 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04003291
3292 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06003293 IPW_STATS_INTERVAL);
3294}
3295
James Ketrenosea2b26e2005-08-24 21:25:16 -05003296static inline void ipw_handle_missed_beacon(struct ipw_priv *priv,
3297 int missed_count)
3298{
3299 priv->notif_missed_beacons = missed_count;
3300
3301 if (missed_count > priv->missed_beacon_threshold &&
3302 priv->status & STATUS_ASSOCIATED) {
3303 /* If associated and we've hit the missed
3304 * beacon threshold, disassociate, turn
3305 * off roaming, and abort any active scans */
3306 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
3307 IPW_DL_STATE,
3308 "Missed beacon: %d - disassociate\n", missed_count);
3309 priv->status &= ~STATUS_ROAMING;
3310 if (priv->status & STATUS_SCANNING)
3311 queue_work(priv->workqueue, &priv->abort_scan);
3312 queue_work(priv->workqueue, &priv->disassociate);
3313 return;
3314 }
3315
3316 if (priv->status & STATUS_ROAMING) {
3317 /* If we are currently roaming, then just
3318 * print a debug statement... */
3319 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3320 "Missed beacon: %d - roam in progress\n",
3321 missed_count);
3322 return;
3323 }
3324
3325 if (missed_count > priv->roaming_threshold) {
3326 /* If we are not already roaming, set the ROAM
3327 * bit in the status and kick off a scan */
3328 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3329 "Missed beacon: %d - initiate "
3330 "roaming\n", missed_count);
3331 if (!(priv->status & STATUS_ROAMING)) {
3332 priv->status |= STATUS_ROAMING;
3333 if (!(priv->status & STATUS_SCANNING))
3334 queue_work(priv->workqueue,
3335 &priv->request_scan);
3336 }
3337 return;
3338 }
3339
3340 if (priv->status & STATUS_SCANNING) {
3341 /* Stop scan to keep fw from getting
3342 * stuck (only if we aren't roaming --
3343 * otherwise we'll never scan more than 2 or 3
3344 * channels..) */
3345 queue_work(priv->workqueue, &priv->abort_scan);
3346 }
3347
3348 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
3349
3350}
3351
James Ketrenos43f66a62005-03-25 12:31:53 -06003352/**
3353 * Handle host notification packet.
3354 * Called from interrupt routine
3355 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003356static inline void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003357 struct ipw_rx_notification *notif)
3358{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003359 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04003360
James Ketrenos43f66a62005-03-25 12:31:53 -06003361 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003362 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
3363 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003364
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003365 switch (assoc->state) {
3366 case CMAS_ASSOCIATED:{
3367 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3368 IPW_DL_ASSOC,
3369 "associated: '%s' " MAC_FMT
3370 " \n",
3371 escape_essid(priv->essid,
3372 priv->essid_len),
3373 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04003374
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003375 switch (priv->ieee->iw_mode) {
3376 case IW_MODE_INFRA:
3377 memcpy(priv->ieee->bssid,
3378 priv->bssid, ETH_ALEN);
3379 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003380
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003381 case IW_MODE_ADHOC:
3382 memcpy(priv->ieee->bssid,
3383 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04003384
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003385 /* clear out the station table */
3386 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003387
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003388 IPW_DEBUG_ASSOC
3389 ("queueing adhoc check\n");
3390 queue_delayed_work(priv->
3391 workqueue,
3392 &priv->
3393 adhoc_check,
3394 priv->
3395 assoc_request.
3396 beacon_interval);
3397 break;
3398 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003399
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003400 priv->status &= ~STATUS_ASSOCIATING;
3401 priv->status |= STATUS_ASSOCIATED;
James Ketrenos43f66a62005-03-25 12:31:53 -06003402
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003403 netif_carrier_on(priv->net_dev);
3404 if (netif_queue_stopped(priv->net_dev)) {
3405 IPW_DEBUG_NOTIF
3406 ("waking queue\n");
3407 netif_wake_queue(priv->net_dev);
3408 } else {
3409 IPW_DEBUG_NOTIF
3410 ("starting queue\n");
3411 netif_start_queue(priv->
3412 net_dev);
3413 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003414
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003415 ipw_reset_stats(priv);
3416 /* Ensure the rate is updated immediately */
3417 priv->last_rate =
3418 ipw_get_current_rate(priv);
3419 schedule_work(&priv->gather_stats);
3420 notify_wx_assoc_event(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003421
Jeff Garzikbf794512005-07-31 13:07:26 -04003422/* queue_delayed_work(priv->workqueue,
James Ketrenos43f66a62005-03-25 12:31:53 -06003423 &priv->request_scan,
3424 SCAN_ASSOCIATED_INTERVAL);
3425*/
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003426 break;
3427 }
3428
3429 case CMAS_AUTHENTICATED:{
3430 if (priv->
3431 status & (STATUS_ASSOCIATED |
3432 STATUS_AUTH)) {
3433#ifdef CONFIG_IPW_DEBUG
3434 struct notif_authenticate *auth
3435 = &notif->u.auth;
3436 IPW_DEBUG(IPW_DL_NOTIF |
3437 IPW_DL_STATE |
3438 IPW_DL_ASSOC,
3439 "deauthenticated: '%s' "
3440 MAC_FMT
3441 ": (0x%04X) - %s \n",
3442 escape_essid(priv->
3443 essid,
3444 priv->
3445 essid_len),
3446 MAC_ARG(priv->bssid),
3447 ntohs(auth->status),
3448 ipw_get_status_code
3449 (ntohs
3450 (auth->status)));
3451#endif
3452
3453 priv->status &=
3454 ~(STATUS_ASSOCIATING |
3455 STATUS_AUTH |
3456 STATUS_ASSOCIATED);
3457
3458 netif_carrier_off(priv->
3459 net_dev);
3460 netif_stop_queue(priv->net_dev);
3461 queue_work(priv->workqueue,
3462 &priv->request_scan);
3463 notify_wx_assoc_event(priv);
3464 break;
3465 }
3466
3467 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3468 IPW_DL_ASSOC,
3469 "authenticated: '%s' " MAC_FMT
3470 "\n",
3471 escape_essid(priv->essid,
3472 priv->essid_len),
3473 MAC_ARG(priv->bssid));
3474 break;
3475 }
3476
3477 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05003478 if (priv->status & STATUS_AUTH) {
3479 struct
3480 ieee80211_assoc_response
3481 *resp;
3482 resp =
3483 (struct
3484 ieee80211_assoc_response
3485 *)&notif->u.raw;
3486 IPW_DEBUG(IPW_DL_NOTIF |
3487 IPW_DL_STATE |
3488 IPW_DL_ASSOC,
3489 "association failed (0x%04X): %s\n",
3490 ntohs(resp->status),
3491 ipw_get_status_code
3492 (ntohs
3493 (resp->status)));
3494 }
3495
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003496 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3497 IPW_DL_ASSOC,
3498 "disassociated: '%s' " MAC_FMT
3499 " \n",
3500 escape_essid(priv->essid,
3501 priv->essid_len),
3502 MAC_ARG(priv->bssid));
3503
3504 priv->status &=
3505 ~(STATUS_DISASSOCIATING |
3506 STATUS_ASSOCIATING |
3507 STATUS_ASSOCIATED | STATUS_AUTH);
3508
3509 netif_stop_queue(priv->net_dev);
3510 if (!(priv->status & STATUS_ROAMING)) {
3511 netif_carrier_off(priv->
3512 net_dev);
3513 notify_wx_assoc_event(priv);
3514
3515 /* Cancel any queued work ... */
3516 cancel_delayed_work(&priv->
3517 request_scan);
3518 cancel_delayed_work(&priv->
3519 adhoc_check);
3520
3521 /* Queue up another scan... */
3522 queue_work(priv->workqueue,
3523 &priv->request_scan);
3524
3525 cancel_delayed_work(&priv->
3526 gather_stats);
3527 } else {
3528 priv->status |= STATUS_ROAMING;
3529 queue_work(priv->workqueue,
3530 &priv->request_scan);
3531 }
3532
3533 ipw_reset_stats(priv);
3534 break;
3535 }
3536
3537 default:
3538 IPW_ERROR("assoc: unknown (%d)\n",
3539 assoc->state);
3540 break;
3541 }
3542
James Ketrenos43f66a62005-03-25 12:31:53 -06003543 break;
3544 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003545
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003546 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
3547 struct notif_authenticate *auth = &notif->u.auth;
3548 switch (auth->state) {
3549 case CMAS_AUTHENTICATED:
3550 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3551 "authenticated: '%s' " MAC_FMT " \n",
3552 escape_essid(priv->essid,
3553 priv->essid_len),
3554 MAC_ARG(priv->bssid));
3555 priv->status |= STATUS_AUTH;
3556 break;
3557
3558 case CMAS_INIT:
3559 if (priv->status & STATUS_AUTH) {
3560 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3561 IPW_DL_ASSOC,
3562 "authentication failed (0x%04X): %s\n",
3563 ntohs(auth->status),
3564 ipw_get_status_code(ntohs
3565 (auth->
3566 status)));
3567 }
3568 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3569 IPW_DL_ASSOC,
3570 "deauthenticated: '%s' " MAC_FMT "\n",
3571 escape_essid(priv->essid,
3572 priv->essid_len),
3573 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06003574
3575 priv->status &= ~(STATUS_ASSOCIATING |
3576 STATUS_AUTH |
3577 STATUS_ASSOCIATED);
3578
3579 netif_carrier_off(priv->net_dev);
3580 netif_stop_queue(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003581 queue_work(priv->workqueue,
3582 &priv->request_scan);
Jeff Garzikbf794512005-07-31 13:07:26 -04003583 notify_wx_assoc_event(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003584 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003585
3586 case CMAS_TX_AUTH_SEQ_1:
3587 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3588 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
3589 break;
3590 case CMAS_RX_AUTH_SEQ_2:
3591 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3592 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
3593 break;
3594 case CMAS_AUTH_SEQ_1_PASS:
3595 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3596 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
3597 break;
3598 case CMAS_AUTH_SEQ_1_FAIL:
3599 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3600 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
3601 break;
3602 case CMAS_TX_AUTH_SEQ_3:
3603 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3604 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
3605 break;
3606 case CMAS_RX_AUTH_SEQ_4:
3607 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3608 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
3609 break;
3610 case CMAS_AUTH_SEQ_2_PASS:
3611 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3612 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
3613 break;
3614 case CMAS_AUTH_SEQ_2_FAIL:
3615 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3616 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
3617 break;
3618 case CMAS_TX_ASSOC:
3619 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3620 IPW_DL_ASSOC, "TX_ASSOC\n");
3621 break;
3622 case CMAS_RX_ASSOC_RESP:
3623 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3624 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
3625 break;
3626 case CMAS_ASSOCIATED:
3627 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3628 IPW_DL_ASSOC, "ASSOCIATED\n");
3629 break;
3630 default:
3631 IPW_DEBUG_NOTIF("auth: failure - %d\n",
3632 auth->state);
3633 break;
3634 }
3635 break;
3636 }
3637
3638 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
3639 struct notif_channel_result *x =
3640 &notif->u.channel_result;
3641
3642 if (notif->size == sizeof(*x)) {
3643 IPW_DEBUG_SCAN("Scan result for channel %d\n",
3644 x->channel_num);
3645 } else {
3646 IPW_DEBUG_SCAN("Scan result of wrong size %d "
3647 "(should be %zd)\n",
3648 notif->size, sizeof(*x));
3649 }
3650 break;
3651 }
3652
3653 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
3654 struct notif_scan_complete *x = &notif->u.scan_complete;
3655 if (notif->size == sizeof(*x)) {
3656 IPW_DEBUG_SCAN
3657 ("Scan completed: type %d, %d channels, "
3658 "%d status\n", x->scan_type,
3659 x->num_channels, x->status);
3660 } else {
3661 IPW_ERROR("Scan completed of wrong size %d "
3662 "(should be %zd)\n",
3663 notif->size, sizeof(*x));
3664 }
3665
3666 priv->status &=
3667 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3668
3669 cancel_delayed_work(&priv->scan_check);
3670
3671 if (!(priv->status & (STATUS_ASSOCIATED |
3672 STATUS_ASSOCIATING |
3673 STATUS_ROAMING |
3674 STATUS_DISASSOCIATING)))
3675 queue_work(priv->workqueue, &priv->associate);
3676 else if (priv->status & STATUS_ROAMING) {
3677 /* If a scan completed and we are in roam mode, then
3678 * the scan that completed was the one requested as a
3679 * result of entering roam... so, schedule the
3680 * roam work */
3681 queue_work(priv->workqueue, &priv->roam);
3682 } else if (priv->status & STATUS_SCAN_PENDING)
3683 queue_work(priv->workqueue,
3684 &priv->request_scan);
3685
3686 priv->ieee->scans++;
3687 break;
3688 }
3689
3690 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
3691 struct notif_frag_length *x = &notif->u.frag_len;
3692
3693 if (notif->size == sizeof(*x)) {
3694 IPW_ERROR("Frag length: %d\n", x->frag_length);
3695 } else {
3696 IPW_ERROR("Frag length of wrong size %d "
3697 "(should be %zd)\n",
3698 notif->size, sizeof(*x));
3699 }
3700 break;
3701 }
3702
3703 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
3704 struct notif_link_deterioration *x =
3705 &notif->u.link_deterioration;
3706 if (notif->size == sizeof(*x)) {
3707 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3708 "link deterioration: '%s' " MAC_FMT
3709 " \n", escape_essid(priv->essid,
3710 priv->essid_len),
3711 MAC_ARG(priv->bssid));
3712 memcpy(&priv->last_link_deterioration, x,
3713 sizeof(*x));
3714 } else {
3715 IPW_ERROR("Link Deterioration of wrong size %d "
3716 "(should be %zd)\n",
3717 notif->size, sizeof(*x));
3718 }
3719 break;
3720 }
3721
3722 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
3723 IPW_ERROR("Dino config\n");
3724 if (priv->hcmd
3725 && priv->hcmd->cmd == HOST_CMD_DINO_CONFIG) {
3726 /* TODO: Do anything special? */
3727 } else {
3728 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
3729 }
3730 break;
3731 }
3732
3733 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
3734 struct notif_beacon_state *x = &notif->u.beacon_state;
3735 if (notif->size != sizeof(*x)) {
3736 IPW_ERROR
3737 ("Beacon state of wrong size %d (should "
3738 "be %zd)\n", notif->size, sizeof(*x));
3739 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003740 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003741
James Ketrenosea2b26e2005-08-24 21:25:16 -05003742 if (x->state == HOST_NOTIFICATION_STATUS_BEACON_MISSING)
3743 ipw_handle_missed_beacon(priv, x->number);
Jeff Garzikbf794512005-07-31 13:07:26 -04003744
James Ketrenos43f66a62005-03-25 12:31:53 -06003745 break;
3746 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003747
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003748 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
3749 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
3750 if (notif->size == sizeof(*x)) {
3751 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
3752 "0x%02x station %d\n",
3753 x->key_state, x->security_type,
3754 x->station_index);
3755 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003756 }
3757
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003758 IPW_ERROR
3759 ("TGi Tx Key of wrong size %d (should be %zd)\n",
3760 notif->size, sizeof(*x));
3761 break;
3762 }
3763
3764 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
3765 struct notif_calibration *x = &notif->u.calibration;
3766
3767 if (notif->size == sizeof(*x)) {
3768 memcpy(&priv->calib, x, sizeof(*x));
3769 IPW_DEBUG_INFO("TODO: Calibration\n");
3770 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003771 }
3772
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003773 IPW_ERROR
3774 ("Calibration of wrong size %d (should be %zd)\n",
3775 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06003776 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003777 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003778
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003779 case HOST_NOTIFICATION_NOISE_STATS:{
3780 if (notif->size == sizeof(u32)) {
3781 priv->last_noise =
3782 (u8) (notif->u.noise.value & 0xff);
3783 average_add(&priv->average_noise,
3784 priv->last_noise);
3785 break;
3786 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003787
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003788 IPW_ERROR
3789 ("Noise stat is wrong size %d (should be %zd)\n",
3790 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06003791 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003792 }
3793
James Ketrenos43f66a62005-03-25 12:31:53 -06003794 default:
3795 IPW_ERROR("Unknown notification: "
3796 "subtype=%d,flags=0x%2x,size=%d\n",
3797 notif->subtype, notif->flags, notif->size);
3798 }
3799}
3800
3801/**
3802 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04003803 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003804 * @param priv
3805 * @return error code
3806 */
3807static int ipw_queue_reset(struct ipw_priv *priv)
3808{
3809 int rc = 0;
3810 /** @todo customize queue sizes */
3811 int nTx = 64, nTxCmd = 8;
3812 ipw_tx_queue_free(priv);
3813 /* Tx CMD queue */
3814 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
3815 CX2_TX_CMD_QUEUE_READ_INDEX,
3816 CX2_TX_CMD_QUEUE_WRITE_INDEX,
3817 CX2_TX_CMD_QUEUE_BD_BASE,
3818 CX2_TX_CMD_QUEUE_BD_SIZE);
3819 if (rc) {
3820 IPW_ERROR("Tx Cmd queue init failed\n");
3821 goto error;
3822 }
3823 /* Tx queue(s) */
3824 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
3825 CX2_TX_QUEUE_0_READ_INDEX,
3826 CX2_TX_QUEUE_0_WRITE_INDEX,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003827 CX2_TX_QUEUE_0_BD_BASE, CX2_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003828 if (rc) {
3829 IPW_ERROR("Tx 0 queue init failed\n");
3830 goto error;
3831 }
3832 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
3833 CX2_TX_QUEUE_1_READ_INDEX,
3834 CX2_TX_QUEUE_1_WRITE_INDEX,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003835 CX2_TX_QUEUE_1_BD_BASE, CX2_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003836 if (rc) {
3837 IPW_ERROR("Tx 1 queue init failed\n");
3838 goto error;
3839 }
3840 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
3841 CX2_TX_QUEUE_2_READ_INDEX,
3842 CX2_TX_QUEUE_2_WRITE_INDEX,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003843 CX2_TX_QUEUE_2_BD_BASE, CX2_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003844 if (rc) {
3845 IPW_ERROR("Tx 2 queue init failed\n");
3846 goto error;
3847 }
3848 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
3849 CX2_TX_QUEUE_3_READ_INDEX,
3850 CX2_TX_QUEUE_3_WRITE_INDEX,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003851 CX2_TX_QUEUE_3_BD_BASE, CX2_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003852 if (rc) {
3853 IPW_ERROR("Tx 3 queue init failed\n");
3854 goto error;
3855 }
3856 /* statistics */
3857 priv->rx_bufs_min = 0;
3858 priv->rx_pend_max = 0;
3859 return rc;
3860
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003861 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003862 ipw_tx_queue_free(priv);
3863 return rc;
3864}
3865
3866/**
3867 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04003868 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003869 * When FW adwances 'R' index, all entries between old and
3870 * new 'R' index need to be reclaimed. As result, some free space
3871 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003872 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003873 * @note Need to protect against garbage in 'R' index
3874 * @param priv
3875 * @param txq
3876 * @param qindex
3877 * @return Number of used entries remains in the queue
3878 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003879static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003880 struct clx2_tx_queue *txq, int qindex)
3881{
3882 u32 hw_tail;
3883 int used;
3884 struct clx2_queue *q = &txq->q;
3885
3886 hw_tail = ipw_read32(priv, q->reg_r);
3887 if (hw_tail >= q->n_bd) {
3888 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003889 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
3890 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06003891 goto done;
3892 }
3893 for (; q->last_used != hw_tail;
3894 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3895 ipw_queue_tx_free_tfd(priv, txq);
3896 priv->tx_packets++;
3897 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003898 done:
James Ketrenos43f66a62005-03-25 12:31:53 -06003899 if (ipw_queue_space(q) > q->low_mark && qindex >= 0) {
3900 __maybe_wake_tx(priv);
3901 }
3902 used = q->first_empty - q->last_used;
3903 if (used < 0)
3904 used += q->n_bd;
3905
3906 return used;
3907}
3908
3909static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
3910 int len, int sync)
3911{
3912 struct clx2_tx_queue *txq = &priv->txq_cmd;
3913 struct clx2_queue *q = &txq->q;
3914 struct tfd_frame *tfd;
3915
3916 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
3917 IPW_ERROR("No space for Tx\n");
3918 return -EBUSY;
3919 }
3920
3921 tfd = &txq->bd[q->first_empty];
3922 txq->txb[q->first_empty] = NULL;
3923
3924 memset(tfd, 0, sizeof(*tfd));
3925 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
3926 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
3927 priv->hcmd_seq++;
3928 tfd->u.cmd.index = hcmd;
3929 tfd->u.cmd.length = len;
3930 memcpy(tfd->u.cmd.payload, buf, len);
3931 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
3932 ipw_write32(priv, q->reg_w, q->first_empty);
3933 _ipw_read32(priv, 0x90);
3934
3935 return 0;
3936}
3937
Jeff Garzikbf794512005-07-31 13:07:26 -04003938/*
James Ketrenos43f66a62005-03-25 12:31:53 -06003939 * Rx theory of operation
3940 *
3941 * The host allocates 32 DMA target addresses and passes the host address
3942 * to the firmware at register CX2_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
3943 * 0 to 31
3944 *
3945 * Rx Queue Indexes
3946 * The host/firmware share two index registers for managing the Rx buffers.
3947 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003948 * The READ index maps to the first position that the firmware may be writing
3949 * to -- the driver can read up to (but not including) this position and get
3950 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003951 * The READ index is managed by the firmware once the card is enabled.
3952 *
3953 * The WRITE index maps to the last position the driver has read from -- the
3954 * position preceding WRITE is the last slot the firmware can place a packet.
3955 *
3956 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04003957 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06003958 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003959 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06003960 * INDEX position, and WRITE to the last (READ - 1 wrapped)
3961 *
3962 * When the firmware places a packet in a buffer it will advance the READ index
3963 * and fire the RX interrupt. The driver can then query the READ index and
3964 * process as many packets as possible, moving the WRITE index forward as it
3965 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04003966 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003967 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04003968 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06003969 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04003970 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06003971 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
3972 * ipw->rxq is replenished and the READ INDEX is updated (updating the
3973 * 'processed' and 'read' driver indexes as well)
3974 * + A received packet is processed and handed to the kernel network stack,
3975 * detached from the ipw->rxq. The driver 'processed' index is updated.
3976 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04003977 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
3978 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06003979 * were enough free buffers and RX_STALLED is set it is cleared.
3980 *
3981 *
3982 * Driver sequence:
3983 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003984 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06003985 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
3986 * ipw_rx_queue_restock
3987 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
3988 * queue, updates firmware pointers, and updates
3989 * the WRITE index. If insufficient rx_free buffers
3990 * are available, schedules ipw_rx_queue_replenish
3991 *
3992 * -- enable interrupts --
3993 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04003994 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06003995 * Moves the packet buffer from queue to rx_used.
3996 * Calls ipw_rx_queue_restock to refill any empty
3997 * slots.
3998 * ...
3999 *
4000 */
4001
Jeff Garzikbf794512005-07-31 13:07:26 -04004002/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004003 * If there are slots in the RX queue that need to be restocked,
4004 * and we have free pre-allocated buffers, fill the ranks as much
4005 * as we can pulling from rx_free.
4006 *
4007 * This moves the 'write' index forward to catch up with 'processed', and
4008 * also updates the memory address in the firmware to reference the new
4009 * target buffer.
4010 */
4011static void ipw_rx_queue_restock(struct ipw_priv *priv)
4012{
4013 struct ipw_rx_queue *rxq = priv->rxq;
4014 struct list_head *element;
4015 struct ipw_rx_mem_buffer *rxb;
4016 unsigned long flags;
4017 int write;
4018
4019 spin_lock_irqsave(&rxq->lock, flags);
4020 write = rxq->write;
4021 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4022 element = rxq->rx_free.next;
4023 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4024 list_del(element);
4025
4026 ipw_write32(priv, CX2_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
4027 rxb->dma_addr);
4028 rxq->queue[rxq->write] = rxb;
4029 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4030 rxq->free_count--;
4031 }
4032 spin_unlock_irqrestore(&rxq->lock, flags);
4033
Jeff Garzikbf794512005-07-31 13:07:26 -04004034 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06004035 * refill it */
4036 if (rxq->free_count <= RX_LOW_WATERMARK)
4037 queue_work(priv->workqueue, &priv->rx_replenish);
4038
4039 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04004040 if (write != rxq->write)
James Ketrenos43f66a62005-03-25 12:31:53 -06004041 ipw_write32(priv, CX2_RX_WRITE_INDEX, rxq->write);
4042}
4043
4044/*
4045 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04004046 * Also restock the Rx queue via ipw_rx_queue_restock.
4047 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004048 * This is called as a scheduled work item (except for during intialization)
4049 */
4050static void ipw_rx_queue_replenish(void *data)
4051{
4052 struct ipw_priv *priv = data;
4053 struct ipw_rx_queue *rxq = priv->rxq;
4054 struct list_head *element;
4055 struct ipw_rx_mem_buffer *rxb;
4056 unsigned long flags;
4057
4058 spin_lock_irqsave(&rxq->lock, flags);
4059 while (!list_empty(&rxq->rx_used)) {
4060 element = rxq->rx_used.next;
4061 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4062 rxb->skb = alloc_skb(CX2_RX_BUF_SIZE, GFP_ATOMIC);
4063 if (!rxb->skb) {
4064 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
4065 priv->net_dev->name);
4066 /* We don't reschedule replenish work here -- we will
4067 * call the restock method and if it still needs
4068 * more buffers it will schedule replenish */
4069 break;
4070 }
4071 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04004072
James Ketrenos43f66a62005-03-25 12:31:53 -06004073 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004074 rxb->dma_addr =
4075 pci_map_single(priv->pci_dev, rxb->skb->data,
4076 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04004077
James Ketrenos43f66a62005-03-25 12:31:53 -06004078 list_add_tail(&rxb->list, &rxq->rx_free);
4079 rxq->free_count++;
4080 }
4081 spin_unlock_irqrestore(&rxq->lock, flags);
4082
4083 ipw_rx_queue_restock(priv);
4084}
4085
4086/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4087 * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04004088 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06004089 * non NULL it is unmapped and freed
4090 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004091static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06004092{
4093 int i;
4094
4095 if (!rxq)
4096 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04004097
James Ketrenos43f66a62005-03-25 12:31:53 -06004098 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4099 if (rxq->pool[i].skb != NULL) {
4100 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004101 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004102 dev_kfree_skb(rxq->pool[i].skb);
4103 }
4104 }
4105
4106 kfree(rxq);
4107}
4108
4109static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4110{
4111 struct ipw_rx_queue *rxq;
4112 int i;
4113
4114 rxq = (struct ipw_rx_queue *)kmalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02004115 if (unlikely(!rxq)) {
4116 IPW_ERROR("memory allocation failed\n");
4117 return NULL;
4118 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004119 memset(rxq, 0, sizeof(*rxq));
4120 spin_lock_init(&rxq->lock);
4121 INIT_LIST_HEAD(&rxq->rx_free);
4122 INIT_LIST_HEAD(&rxq->rx_used);
4123
4124 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04004125 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06004126 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4127
4128 /* Set us so that we have processed and used all buffers, but have
4129 * not restocked the Rx queue with fresh buffers */
4130 rxq->read = rxq->write = 0;
4131 rxq->processed = RX_QUEUE_SIZE - 1;
4132 rxq->free_count = 0;
4133
4134 return rxq;
4135}
4136
4137static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
4138{
4139 rate &= ~IEEE80211_BASIC_RATE_MASK;
4140 if (ieee_mode == IEEE_A) {
4141 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004142 case IEEE80211_OFDM_RATE_6MB:
4143 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004144 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004145 case IEEE80211_OFDM_RATE_9MB:
4146 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004147 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004148 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004149 return priv->
4150 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004151 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004152 return priv->
4153 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004154 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004155 return priv->
4156 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004157 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004158 return priv->
4159 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004160 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004161 return priv->
4162 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004163 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004164 return priv->
4165 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004166 default:
4167 return 0;
4168 }
4169 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004170
James Ketrenos43f66a62005-03-25 12:31:53 -06004171 /* B and G mixed */
4172 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004173 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004174 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004175 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004176 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004177 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004178 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004179 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004180 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
4181 }
4182
4183 /* If we are limited to B modulations, bail at this point */
4184 if (ieee_mode == IEEE_B)
4185 return 0;
4186
4187 /* G */
4188 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004189 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004190 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004191 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004192 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004193 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004194 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004195 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004196 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004197 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004198 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004199 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004200 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004201 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004202 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004203 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004204 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
4205 }
4206
4207 return 0;
4208}
4209
Jeff Garzikbf794512005-07-31 13:07:26 -04004210static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004211 const struct ieee80211_network *network,
4212 struct ipw_supported_rates *rates)
4213{
4214 int num_rates, i;
4215
4216 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004217 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06004218 rates->num_rates = 0;
4219 for (i = 0; i < num_rates; i++) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004220 if (!ipw_is_rate_in_mask
4221 (priv, network->mode, network->rates[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004222 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
4223 IPW_DEBUG_SCAN
4224 ("Basic rate %02X masked: 0x%08X\n",
4225 network->rates[i], priv->rates_mask);
4226 return 0;
4227 }
4228
James Ketrenos43f66a62005-03-25 12:31:53 -06004229 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4230 network->rates[i], priv->rates_mask);
4231 continue;
4232 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004233
James Ketrenos43f66a62005-03-25 12:31:53 -06004234 rates->supported_rates[rates->num_rates++] = network->rates[i];
4235 }
4236
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004237 num_rates =
4238 min(network->rates_ex_len, (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06004239 for (i = 0; i < num_rates; i++) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004240 if (!ipw_is_rate_in_mask
4241 (priv, network->mode, network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004242 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
4243 IPW_DEBUG_SCAN
4244 ("Basic rate %02X masked: 0x%08X\n",
4245 network->rates_ex[i], priv->rates_mask);
4246 return 0;
4247 }
4248
James Ketrenos43f66a62005-03-25 12:31:53 -06004249 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4250 network->rates_ex[i], priv->rates_mask);
4251 continue;
4252 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004253
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004254 rates->supported_rates[rates->num_rates++] =
4255 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06004256 }
4257
James Ketrenosea2b26e2005-08-24 21:25:16 -05004258 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004259}
4260
4261static inline void ipw_copy_rates(struct ipw_supported_rates *dest,
4262 const struct ipw_supported_rates *src)
4263{
4264 u8 i;
4265 for (i = 0; i < src->num_rates; i++)
4266 dest->supported_rates[i] = src->supported_rates[i];
4267 dest->num_rates = src->num_rates;
4268}
4269
4270/* TODO: Look at sniffed packets in the air to determine if the basic rate
4271 * mask should ever be used -- right now all callers to add the scan rates are
4272 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
4273static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004274 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06004275{
Jeff Garzikbf794512005-07-31 13:07:26 -04004276 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004277 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004278
James Ketrenos43f66a62005-03-25 12:31:53 -06004279 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004280 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004281 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004282
4283 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004284 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004285 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004286
4287 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004288 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004289 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004290
4291 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004292 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004293 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004294}
4295
4296static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004297 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06004298{
Jeff Garzikbf794512005-07-31 13:07:26 -04004299 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004300 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004301
4302 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004303 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004304 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004305
4306 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004307 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004308 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004309
4310 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004311 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004312 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004313
4314 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004315 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004316 IEEE80211_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004317
4318 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004319 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004320 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004321
4322 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004323 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004324 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004325
4326 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004327 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004328 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004329
4330 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004331 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004332 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004333}
4334
4335struct ipw_network_match {
4336 struct ieee80211_network *network;
4337 struct ipw_supported_rates rates;
4338};
4339
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004340static int ipw_best_network(struct ipw_priv *priv,
4341 struct ipw_network_match *match,
4342 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06004343{
4344 struct ipw_supported_rates rates;
4345
4346 /* Verify that this network's capability is compatible with the
4347 * current mode (AdHoc or Infrastructure) */
4348 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07004349 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06004350 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
4351 !(network->capability & WLAN_CAPABILITY_IBSS))) {
4352 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04004353 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004354 escape_essid(network->ssid, network->ssid_len),
4355 MAC_ARG(network->bssid));
4356 return 0;
4357 }
4358
4359 /* If we do not have an ESSID for this AP, we can not associate with
4360 * it */
4361 if (network->flags & NETWORK_EMPTY_ESSID) {
4362 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4363 "because of hidden ESSID.\n",
4364 escape_essid(network->ssid, network->ssid_len),
4365 MAC_ARG(network->bssid));
4366 return 0;
4367 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004368
James Ketrenos43f66a62005-03-25 12:31:53 -06004369 if (unlikely(roaming)) {
4370 /* If we are roaming, then ensure check if this is a valid
4371 * network to try and roam to */
4372 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04004373 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06004374 network->ssid_len)) {
4375 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
4376 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04004377 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06004378 network->ssid_len),
4379 MAC_ARG(network->bssid));
4380 return 0;
4381 }
4382 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04004383 /* If an ESSID has been configured then compare the broadcast
4384 * ESSID to ours */
4385 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06004386 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04004387 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06004388 min(network->ssid_len, priv->essid_len)))) {
4389 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004390 strncpy(escaped,
4391 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06004392 sizeof(escaped));
4393 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04004394 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004395 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004396 escape_essid(priv->essid,
4397 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06004398 return 0;
4399 }
4400 }
4401
4402 /* If the old network rate is better than this one, don't bother
4403 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004404 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06004405 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04004406 strncpy(escaped,
4407 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06004408 sizeof(escaped));
4409 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
4410 "'%s (" MAC_FMT ")' has a stronger signal.\n",
4411 escaped, MAC_ARG(network->bssid),
4412 escape_essid(match->network->ssid,
4413 match->network->ssid_len),
4414 MAC_ARG(match->network->bssid));
4415 return 0;
4416 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004417
James Ketrenos43f66a62005-03-25 12:31:53 -06004418 /* If this network has already had an association attempt within the
4419 * last 3 seconds, do not try and associate again... */
4420 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004421 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06004422 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4423 "because of storming (%lu since last "
4424 "assoc attempt).\n",
4425 escape_essid(network->ssid, network->ssid_len),
4426 MAC_ARG(network->bssid),
4427 (jiffies - network->last_associate) / HZ);
4428 return 0;
4429 }
4430
4431 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04004432 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004433 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06004434 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4435 "because of age: %lums.\n",
4436 escape_essid(network->ssid, network->ssid_len),
4437 MAC_ARG(network->bssid),
4438 (jiffies - network->last_scanned) / (HZ / 100));
4439 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004440 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004441
Jeff Garzikbf794512005-07-31 13:07:26 -04004442 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06004443 (network->channel != priv->channel)) {
4444 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4445 "because of channel mismatch: %d != %d.\n",
4446 escape_essid(network->ssid, network->ssid_len),
4447 MAC_ARG(network->bssid),
4448 network->channel, priv->channel);
4449 return 0;
4450 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004451
James Ketrenos43f66a62005-03-25 12:31:53 -06004452 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04004453 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06004454 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
4455 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4456 "because of privacy mismatch: %s != %s.\n",
4457 escape_essid(network->ssid, network->ssid_len),
4458 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04004459 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06004460 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04004461 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004462 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06004463 return 0;
4464 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004465
4466 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06004467 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
4468 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4469 "because of BSSID mismatch: " MAC_FMT ".\n",
4470 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004471 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004472 return 0;
4473 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004474
James Ketrenos43f66a62005-03-25 12:31:53 -06004475 /* Filter out any incompatible freq / mode combinations */
4476 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
4477 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4478 "because of invalid frequency/mode "
4479 "combination.\n",
4480 escape_essid(network->ssid, network->ssid_len),
4481 MAC_ARG(network->bssid));
4482 return 0;
4483 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004484
James Ketrenosea2b26e2005-08-24 21:25:16 -05004485 /* Ensure that the rates supported by the driver are compatible with
4486 * this AP, including verification of basic rates (mandatory) */
4487 if (!ipw_compatible_rates(priv, network, &rates)) {
4488 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4489 "because configured rate mask excludes "
4490 "AP mandatory rate.\n",
4491 escape_essid(network->ssid, network->ssid_len),
4492 MAC_ARG(network->bssid));
4493 return 0;
4494 }
4495
James Ketrenos43f66a62005-03-25 12:31:53 -06004496 if (rates.num_rates == 0) {
4497 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4498 "because of no compatible rates.\n",
4499 escape_essid(network->ssid, network->ssid_len),
4500 MAC_ARG(network->bssid));
4501 return 0;
4502 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004503
James Ketrenos43f66a62005-03-25 12:31:53 -06004504 /* TODO: Perform any further minimal comparititive tests. We do not
4505 * want to put too much policy logic here; intelligent scan selection
4506 * should occur within a generic IEEE 802.11 user space tool. */
4507
4508 /* Set up 'new' AP to this network */
4509 ipw_copy_rates(&match->rates, &rates);
4510 match->network = network;
4511
4512 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
4513 escape_essid(network->ssid, network->ssid_len),
4514 MAC_ARG(network->bssid));
4515
4516 return 1;
4517}
4518
Jeff Garzikbf794512005-07-31 13:07:26 -04004519static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004520 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06004521{
4522 /*
4523 * For the purposes of scanning, we can set our wireless mode
4524 * to trigger scans across combinations of bands, but when it
4525 * comes to creating a new ad-hoc network, we have tell the FW
4526 * exactly which band to use.
4527 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004528 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06004529 * chossen band. Attempting to create a new ad-hoc network
4530 * with an invalid channel for wireless mode will trigger a
4531 * FW fatal error.
4532 */
4533 network->mode = is_valid_channel(priv->ieee->mode, priv->channel);
4534 if (network->mode) {
4535 network->channel = priv->channel;
4536 } else {
4537 IPW_WARNING("Overriding invalid channel\n");
4538 if (priv->ieee->mode & IEEE_A) {
4539 network->mode = IEEE_A;
4540 priv->channel = band_a_active_channel[0];
4541 } else if (priv->ieee->mode & IEEE_G) {
4542 network->mode = IEEE_G;
4543 priv->channel = band_b_active_channel[0];
4544 } else {
4545 network->mode = IEEE_B;
4546 priv->channel = band_b_active_channel[0];
4547 }
4548 }
4549
4550 network->channel = priv->channel;
4551 priv->config |= CFG_ADHOC_PERSIST;
4552 ipw_create_bssid(priv, network->bssid);
4553 network->ssid_len = priv->essid_len;
4554 memcpy(network->ssid, priv->essid, priv->essid_len);
4555 memset(&network->stats, 0, sizeof(network->stats));
4556 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004557 if (!(priv->config & CFG_PREAMBLE_LONG))
4558 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06004559 if (priv->capability & CAP_PRIVACY_ON)
4560 network->capability |= WLAN_CAPABILITY_PRIVACY;
4561 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004562 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06004563 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04004564 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06004565 &priv->rates.supported_rates[network->rates_len],
4566 network->rates_ex_len);
4567 network->last_scanned = 0;
4568 network->flags = 0;
4569 network->last_associate = 0;
4570 network->time_stamp[0] = 0;
4571 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004572 network->beacon_interval = 100; /* Default */
4573 network->listen_interval = 10; /* Default */
4574 network->atim_window = 0; /* Default */
Jeff Garzikbf794512005-07-31 13:07:26 -04004575#ifdef CONFIG_IEEE80211_WPA
James Ketrenos43f66a62005-03-25 12:31:53 -06004576 network->wpa_ie_len = 0;
4577 network->rsn_ie_len = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004578#endif /* CONFIG_IEEE80211_WPA */
James Ketrenos43f66a62005-03-25 12:31:53 -06004579}
4580
4581static void ipw_send_wep_keys(struct ipw_priv *priv)
4582{
4583 struct ipw_wep_key *key;
4584 int i;
4585 struct host_cmd cmd = {
4586 .cmd = IPW_CMD_WEP_KEY,
4587 .len = sizeof(*key)
4588 };
4589
4590 key = (struct ipw_wep_key *)&cmd.param;
4591 key->cmd_id = DINO_CMD_WEP_KEY;
4592 key->seq_num = 0;
4593
Jeff Garzikbf794512005-07-31 13:07:26 -04004594 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06004595 key->key_index = i;
4596 if (!(priv->sec.flags & (1 << i))) {
4597 key->key_size = 0;
4598 } else {
4599 key->key_size = priv->sec.key_sizes[i];
4600 memcpy(key->key, priv->sec.keys[i], key->key_size);
4601 }
4602
4603 if (ipw_send_cmd(priv, &cmd)) {
4604 IPW_ERROR("failed to send WEP_KEY command\n");
4605 return;
4606 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004607 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004608}
4609
4610static void ipw_adhoc_check(void *data)
4611{
4612 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04004613
James Ketrenos43f66a62005-03-25 12:31:53 -06004614 if (priv->missed_adhoc_beacons++ > priv->missed_beacon_threshold &&
4615 !(priv->config & CFG_ADHOC_PERSIST)) {
4616 IPW_DEBUG_SCAN("Disassociating due to missed beacons\n");
4617 ipw_remove_current_network(priv);
4618 ipw_disassociate(priv);
4619 return;
4620 }
4621
Jeff Garzikbf794512005-07-31 13:07:26 -04004622 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06004623 priv->assoc_request.beacon_interval);
4624}
4625
4626#ifdef CONFIG_IPW_DEBUG
4627static void ipw_debug_config(struct ipw_priv *priv)
4628{
4629 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
4630 "[CFG 0x%08X]\n", priv->config);
4631 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004632 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06004633 else
4634 IPW_DEBUG_INFO("Channel unlocked.\n");
4635 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04004636 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004637 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06004638 else
4639 IPW_DEBUG_INFO("ESSID unlocked.\n");
4640 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05004641 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
4642 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004643 else
4644 IPW_DEBUG_INFO("BSSID unlocked.\n");
4645 if (priv->capability & CAP_PRIVACY_ON)
4646 IPW_DEBUG_INFO("PRIVACY on\n");
4647 else
4648 IPW_DEBUG_INFO("PRIVACY off\n");
4649 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
4650}
4651#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04004652#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06004653#endif
4654
4655static inline void ipw_set_fixed_rate(struct ipw_priv *priv,
4656 struct ieee80211_network *network)
4657{
4658 /* TODO: Verify that this works... */
4659 struct ipw_fixed_rate fr = {
4660 .tx_rates = priv->rates_mask
4661 };
4662 u32 reg;
4663 u16 mask = 0;
4664
Jeff Garzikbf794512005-07-31 13:07:26 -04004665 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06004666 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04004667
James Ketrenos43f66a62005-03-25 12:31:53 -06004668 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004669 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06004670 /* IEEE_A */
4671 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
4672 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004673 IPW_DEBUG_WX
4674 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06004675 fr.tx_rates = 0;
4676 break;
4677 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004678
James Ketrenos43f66a62005-03-25 12:31:53 -06004679 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
4680 break;
4681
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004682 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06004683 /* IEEE_B */
4684 if (network->mode == IEEE_B) {
4685 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
4686 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004687 IPW_DEBUG_WX
4688 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06004689 fr.tx_rates = 0;
4690 }
4691 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004692 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004693
4694 /* IEEE_G */
4695 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
4696 IEEE80211_OFDM_RATES_MASK)) {
4697 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004698 IPW_DEBUG_WX
4699 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06004700 fr.tx_rates = 0;
4701 break;
4702 }
4703
4704 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
4705 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
4706 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
4707 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004708
James Ketrenos43f66a62005-03-25 12:31:53 -06004709 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
4710 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
4711 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
4712 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004713
James Ketrenos43f66a62005-03-25 12:31:53 -06004714 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
4715 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
4716 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
4717 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004718
James Ketrenos43f66a62005-03-25 12:31:53 -06004719 fr.tx_rates |= mask;
4720 break;
4721 }
4722
4723 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004724 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06004725}
4726
James Ketrenosea2b26e2005-08-24 21:25:16 -05004727static void ipw_abort_scan(struct ipw_priv *priv)
4728{
4729 int err;
4730
4731 if (priv->status & STATUS_SCAN_ABORTING) {
4732 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
4733 return;
4734 }
4735 priv->status |= STATUS_SCAN_ABORTING;
4736
4737 err = ipw_send_scan_abort(priv);
4738 if (err)
4739 IPW_DEBUG_HC("Request to abort scan failed.\n");
4740}
4741
4742static int ipw_request_scan(struct ipw_priv *priv)
4743{
4744 struct ipw_scan_request_ext scan;
4745 int channel_index = 0;
4746 int i, err, scan_type;
4747
4748 if (priv->status & STATUS_EXIT_PENDING) {
4749 IPW_DEBUG_SCAN("Aborting scan due to device shutdown\n");
4750 priv->status |= STATUS_SCAN_PENDING;
4751 return 0;
4752 }
4753
4754 if (priv->status & STATUS_SCANNING) {
4755 IPW_DEBUG_HC("Concurrent scan requested. Aborting first.\n");
4756 priv->status |= STATUS_SCAN_PENDING;
4757 ipw_abort_scan(priv);
4758 return 0;
4759 }
4760
4761 if (priv->status & STATUS_SCAN_ABORTING) {
4762 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
4763 priv->status |= STATUS_SCAN_PENDING;
4764 return 0;
4765 }
4766
4767 if (priv->status & STATUS_RF_KILL_MASK) {
4768 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
4769 priv->status |= STATUS_SCAN_PENDING;
4770 return 0;
4771 }
4772
4773 memset(&scan, 0, sizeof(scan));
4774
4775 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = 20;
4776 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = 20;
4777 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = 20;
4778
4779 scan.full_scan_index = ieee80211_get_scans(priv->ieee);
4780
4781#ifdef CONFIG_IPW_MONITOR
4782 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
4783 u8 band = 0, channel = priv->channel;
4784
4785 if (is_valid_channel(IEEE_A, channel))
4786 band = (u8) (IPW_A_MODE << 6) | 1;
4787
4788 if (is_valid_channel(IEEE_B | IEEE_G, channel))
4789 band = (u8) (IPW_B_MODE << 6) | 1;
4790
4791 if (band == 0) {
4792 band = (u8) (IPW_B_MODE << 6) | 1;
4793 channel = 9;
4794 }
4795
4796 scan.channels_list[channel_index++] = band;
4797 scan.channels_list[channel_index] = channel;
4798 ipw_set_scan_type(&scan, channel_index,
4799 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
4800
4801 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = 2000;
4802 } else {
4803#endif /* CONFIG_IPW_MONITOR */
4804 /* If we are roaming, then make this a directed scan for the current
4805 * network. Otherwise, ensure that every other scan is a fast
4806 * channel hop scan */
4807 if ((priv->status & STATUS_ROAMING)
4808 || (!(priv->status & STATUS_ASSOCIATED)
4809 && (priv->config & CFG_STATIC_ESSID)
4810 && (scan.full_scan_index % 2))) {
4811 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
4812 if (err) {
4813 IPW_DEBUG_HC
4814 ("Attempt to send SSID command failed.\n");
4815 return err;
4816 }
4817
4818 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
4819 } else {
4820 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
4821 }
4822
4823 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
4824 int start = channel_index;
4825 for (i = 0; i < MAX_A_CHANNELS; i++) {
4826 if (band_a_active_channel[i] == 0)
4827 break;
4828 if ((priv->status & STATUS_ASSOCIATED) &&
4829 band_a_active_channel[i] == priv->channel)
4830 continue;
4831 channel_index++;
4832 scan.channels_list[channel_index] =
4833 band_a_active_channel[i];
4834 ipw_set_scan_type(&scan, channel_index,
4835 scan_type);
4836 }
4837
4838 if (start != channel_index) {
4839 scan.channels_list[start] =
4840 (u8) (IPW_A_MODE << 6) | (channel_index -
4841 start);
4842 channel_index++;
4843 }
4844 }
4845
4846 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
4847 int start = channel_index;
4848 for (i = 0; i < MAX_B_CHANNELS; i++) {
4849 if (band_b_active_channel[i] == 0)
4850 break;
4851 if ((priv->status & STATUS_ASSOCIATED) &&
4852 band_b_active_channel[i] == priv->channel)
4853 continue;
4854 channel_index++;
4855 scan.channels_list[channel_index] =
4856 band_b_active_channel[i];
4857 ipw_set_scan_type(&scan, channel_index,
4858 scan_type);
4859 }
4860
4861 if (start != channel_index) {
4862 scan.channels_list[start] =
4863 (u8) (IPW_B_MODE << 6) | (channel_index -
4864 start);
4865 }
4866 }
4867#ifdef CONFIG_IPW_MONITOR
4868 }
4869#endif
4870
4871 err = ipw_send_scan_request_ext(priv, &scan);
4872 if (err) {
4873 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
4874 return -EIO;
4875 }
4876
4877 priv->status |= STATUS_SCANNING;
4878 priv->status &= ~STATUS_SCAN_PENDING;
4879
4880 return 0;
4881}
4882
4883/* Support for wpa_supplicant. Will be replaced with WEXT once
4884 * they get WPA support. */
4885#ifdef CONFIG_IEEE80211_WPA
4886
4887/* following definitions must match definitions in driver_ipw.c */
4888
4889#define IPW_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
4890
4891#define IPW_CMD_SET_WPA_PARAM 1
4892#define IPW_CMD_SET_WPA_IE 2
4893#define IPW_CMD_SET_ENCRYPTION 3
4894#define IPW_CMD_MLME 4
4895
4896#define IPW_PARAM_WPA_ENABLED 1
4897#define IPW_PARAM_TKIP_COUNTERMEASURES 2
4898#define IPW_PARAM_DROP_UNENCRYPTED 3
4899#define IPW_PARAM_PRIVACY_INVOKED 4
4900#define IPW_PARAM_AUTH_ALGS 5
4901#define IPW_PARAM_IEEE_802_1X 6
4902
4903#define IPW_MLME_STA_DEAUTH 1
4904#define IPW_MLME_STA_DISASSOC 2
4905
4906#define IPW_CRYPT_ERR_UNKNOWN_ALG 2
4907#define IPW_CRYPT_ERR_UNKNOWN_ADDR 3
4908#define IPW_CRYPT_ERR_CRYPT_INIT_FAILED 4
4909#define IPW_CRYPT_ERR_KEY_SET_FAILED 5
4910#define IPW_CRYPT_ERR_TX_KEY_SET_FAILED 6
4911#define IPW_CRYPT_ERR_CARD_CONF_FAILED 7
4912
4913#define IPW_CRYPT_ALG_NAME_LEN 16
4914
4915struct ipw_param {
4916 u32 cmd;
4917 u8 sta_addr[ETH_ALEN];
4918 union {
4919 struct {
4920 u8 name;
4921 u32 value;
4922 } wpa_param;
4923 struct {
4924 u32 len;
4925 u8 *data;
4926 } wpa_ie;
4927 struct {
4928 int command;
4929 int reason_code;
4930 } mlme;
4931 struct {
4932 u8 alg[IPW_CRYPT_ALG_NAME_LEN];
4933 u8 set_tx;
4934 u32 err;
4935 u8 idx;
4936 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
4937 u16 key_len;
4938 u8 key[0];
4939 } crypt;
4940
4941 } u;
4942};
4943
4944/* end of driver_ipw.c code */
4945
4946static int ipw_wpa_enable(struct ipw_priv *priv, int value)
4947{
4948 struct ieee80211_device *ieee = priv->ieee;
4949 struct ieee80211_security sec = {
4950 .flags = SEC_LEVEL | SEC_ENABLED,
4951 };
4952 int ret = 0;
4953
4954 ieee->wpa_enabled = value;
4955
4956 if (value) {
4957 sec.level = SEC_LEVEL_3;
4958 sec.enabled = 1;
4959 } else {
4960 sec.level = SEC_LEVEL_0;
4961 sec.enabled = 0;
4962 }
4963
4964 if (ieee->set_security)
4965 ieee->set_security(ieee->dev, &sec);
4966 else
4967 ret = -EOPNOTSUPP;
4968
4969 return ret;
4970}
4971
4972#define AUTH_ALG_OPEN_SYSTEM 0x1
4973#define AUTH_ALG_SHARED_KEY 0x2
4974
4975static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
4976{
4977 struct ieee80211_device *ieee = priv->ieee;
4978 struct ieee80211_security sec = {
4979 .flags = SEC_AUTH_MODE,
4980 };
4981 int ret = 0;
4982
4983 if (value & AUTH_ALG_SHARED_KEY) {
4984 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
4985 ieee->open_wep = 0;
4986 } else {
4987 sec.auth_mode = WLAN_AUTH_OPEN;
4988 ieee->open_wep = 1;
4989 }
4990
4991 if (ieee->set_security)
4992 ieee->set_security(ieee->dev, &sec);
4993 else
4994 ret = -EOPNOTSUPP;
4995
4996 return ret;
4997}
4998
4999static int ipw_wpa_set_param(struct net_device *dev, u8 name, u32 value)
5000{
5001 struct ipw_priv *priv = ieee80211_priv(dev);
5002 int ret = 0;
5003
5004 switch (name) {
5005 case IPW_PARAM_WPA_ENABLED:
5006 ret = ipw_wpa_enable(priv, value);
5007 break;
5008
5009 case IPW_PARAM_TKIP_COUNTERMEASURES:
5010 priv->ieee->tkip_countermeasures = value;
5011 break;
5012
5013 case IPW_PARAM_DROP_UNENCRYPTED:
5014 priv->ieee->drop_unencrypted = value;
5015 break;
5016
5017 case IPW_PARAM_PRIVACY_INVOKED:
5018 priv->ieee->privacy_invoked = value;
5019 break;
5020
5021 case IPW_PARAM_AUTH_ALGS:
5022 ret = ipw_wpa_set_auth_algs(priv, value);
5023 break;
5024
5025 case IPW_PARAM_IEEE_802_1X:
5026 priv->ieee->ieee802_1x = value;
5027 break;
5028
5029 default:
5030 IPW_ERROR("%s: Unknown WPA param: %d\n", dev->name, name);
5031 ret = -EOPNOTSUPP;
5032 }
5033
5034 return ret;
5035}
5036
5037static int ipw_wpa_mlme(struct net_device *dev, int command, int reason)
5038{
5039 struct ipw_priv *priv = ieee80211_priv(dev);
5040 int ret = 0;
5041
5042 switch (command) {
5043 case IPW_MLME_STA_DEAUTH:
5044 // silently ignore
5045 break;
5046
5047 case IPW_MLME_STA_DISASSOC:
5048 ipw_disassociate(priv);
5049 break;
5050
5051 default:
5052 IPW_ERROR("%s: Unknown MLME request: %d\n", dev->name, command);
5053 ret = -EOPNOTSUPP;
5054 }
5055
5056 return ret;
5057}
5058
5059static int ipw_set_rsn_capa(struct ipw_priv *priv,
5060 char *capabilities, int length)
5061{
5062 struct host_cmd cmd = {
5063 .cmd = IPW_CMD_RSN_CAPABILITIES,
5064 .len = length,
5065 };
5066
5067 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
5068
5069 memcpy(&cmd.param, capabilities, length);
5070 if (ipw_send_cmd(priv, &cmd)) {
5071 IPW_ERROR("failed to send HOST_CMD_RSN_CAPABILITIES command\n");
5072 return -1;
5073 }
5074 return 0;
5075}
5076
5077void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, int wpa_ie_len)
5078{
5079 /* make sure WPA is enabled */
5080 ipw_wpa_enable(priv, 1);
5081
5082 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))
5083 ipw_disassociate(priv);
5084}
5085
5086static int ipw_wpa_set_wpa_ie(struct net_device *dev,
5087 struct ipw_param *param, int plen)
5088{
5089 struct ipw_priv *priv = ieee80211_priv(dev);
5090 struct ieee80211_device *ieee = priv->ieee;
5091 u8 *buf;
5092
5093 if (!ieee->wpa_enabled)
5094 return -EOPNOTSUPP;
5095
5096 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
5097 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
5098 return -EINVAL;
5099
5100 if (param->u.wpa_ie.len) {
5101 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
5102 if (buf == NULL)
5103 return -ENOMEM;
5104
5105 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
5106 kfree(ieee->wpa_ie);
5107 ieee->wpa_ie = buf;
5108 ieee->wpa_ie_len = param->u.wpa_ie.len;
5109 } else {
5110 kfree(ieee->wpa_ie);
5111 ieee->wpa_ie = NULL;
5112 ieee->wpa_ie_len = 0;
5113 }
5114
5115 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
5116 return 0;
5117}
5118
5119/* implementation borrowed from hostap driver */
5120
5121static int ipw_wpa_set_encryption(struct net_device *dev,
5122 struct ipw_param *param, int param_len)
5123{
5124 int ret = 0;
5125 struct ipw_priv *priv = ieee80211_priv(dev);
5126 struct ieee80211_device *ieee = priv->ieee;
5127 struct ieee80211_crypto_ops *ops;
5128 struct ieee80211_crypt_data **crypt;
5129
5130 struct ieee80211_security sec = {
5131 .flags = 0,
5132 };
5133
5134 param->u.crypt.err = 0;
5135 param->u.crypt.alg[IPW_CRYPT_ALG_NAME_LEN - 1] = '\0';
5136
5137 if (param_len !=
5138 (int)((char *)param->u.crypt.key - (char *)param) +
5139 param->u.crypt.key_len) {
5140 IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len,
5141 param->u.crypt.key_len);
5142 return -EINVAL;
5143 }
5144 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
5145 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
5146 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
5147 if (param->u.crypt.idx >= WEP_KEYS)
5148 return -EINVAL;
5149 crypt = &ieee->crypt[param->u.crypt.idx];
5150 } else {
5151 return -EINVAL;
5152 }
5153
5154 if (strcmp(param->u.crypt.alg, "none") == 0) {
5155 if (crypt) {
5156 sec.enabled = 0;
5157 sec.level = SEC_LEVEL_0;
5158 sec.flags |= SEC_ENABLED | SEC_LEVEL;
5159 ieee80211_crypt_delayed_deinit(ieee, crypt);
5160 }
5161 goto done;
5162 }
5163 sec.enabled = 1;
5164 sec.flags |= SEC_ENABLED;
5165
5166 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
5167 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
5168 request_module("ieee80211_crypt_wep");
5169 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
5170 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
5171 request_module("ieee80211_crypt_tkip");
5172 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
5173 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
5174 request_module("ieee80211_crypt_ccmp");
5175 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
5176 }
5177 if (ops == NULL) {
5178 IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
5179 dev->name, param->u.crypt.alg);
5180 param->u.crypt.err = IPW_CRYPT_ERR_UNKNOWN_ALG;
5181 ret = -EINVAL;
5182 goto done;
5183 }
5184
5185 if (*crypt == NULL || (*crypt)->ops != ops) {
5186 struct ieee80211_crypt_data *new_crypt;
5187
5188 ieee80211_crypt_delayed_deinit(ieee, crypt);
5189
5190 new_crypt = (struct ieee80211_crypt_data *)
5191 kmalloc(sizeof(*new_crypt), GFP_KERNEL);
5192 if (new_crypt == NULL) {
5193 ret = -ENOMEM;
5194 goto done;
5195 }
5196 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
5197 new_crypt->ops = ops;
5198 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
5199 new_crypt->priv =
5200 new_crypt->ops->init(param->u.crypt.idx);
5201
5202 if (new_crypt->priv == NULL) {
5203 kfree(new_crypt);
5204 param->u.crypt.err = IPW_CRYPT_ERR_CRYPT_INIT_FAILED;
5205 ret = -EINVAL;
5206 goto done;
5207 }
5208
5209 *crypt = new_crypt;
5210 }
5211
5212 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
5213 (*crypt)->ops->set_key(param->u.crypt.key,
5214 param->u.crypt.key_len, param->u.crypt.seq,
5215 (*crypt)->priv) < 0) {
5216 IPW_DEBUG_INFO("%s: key setting failed\n", dev->name);
5217 param->u.crypt.err = IPW_CRYPT_ERR_KEY_SET_FAILED;
5218 ret = -EINVAL;
5219 goto done;
5220 }
5221
5222 if (param->u.crypt.set_tx) {
5223 ieee->tx_keyidx = param->u.crypt.idx;
5224 sec.active_key = param->u.crypt.idx;
5225 sec.flags |= SEC_ACTIVE_KEY;
5226 }
5227
5228 if (ops->name != NULL) {
5229 if (strcmp(ops->name, "WEP") == 0) {
5230 memcpy(sec.keys[param->u.crypt.idx],
5231 param->u.crypt.key, param->u.crypt.key_len);
5232 sec.key_sizes[param->u.crypt.idx] =
5233 param->u.crypt.key_len;
5234 sec.flags |= (1 << param->u.crypt.idx);
5235 sec.flags |= SEC_LEVEL;
5236 sec.level = SEC_LEVEL_1;
5237 } else if (strcmp(ops->name, "TKIP") == 0) {
5238 sec.flags |= SEC_LEVEL;
5239 sec.level = SEC_LEVEL_2;
5240 } else if (strcmp(ops->name, "CCMP") == 0) {
5241 sec.flags |= SEC_LEVEL;
5242 sec.level = SEC_LEVEL_3;
5243 }
5244 }
5245 done:
5246 if (ieee->set_security)
5247 ieee->set_security(ieee->dev, &sec);
5248
5249 /* Do not reset port if card is in Managed mode since resetting will
5250 * generate new IEEE 802.11 authentication which may end up in looping
5251 * with IEEE 802.1X. If your hardware requires a reset after WEP
5252 * configuration (for example... Prism2), implement the reset_port in
5253 * the callbacks structures used to initialize the 802.11 stack. */
5254 if (ieee->reset_on_keychange &&
5255 ieee->iw_mode != IW_MODE_INFRA &&
5256 ieee->reset_port && ieee->reset_port(dev)) {
5257 IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
5258 param->u.crypt.err = IPW_CRYPT_ERR_CARD_CONF_FAILED;
5259 return -EINVAL;
5260 }
5261
5262 return ret;
5263}
5264
5265static int ipw_wpa_supplicant(struct net_device *dev, struct iw_point *p)
5266{
5267 struct ipw_param *param;
5268 int ret = 0;
5269
5270 IPW_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
5271
5272 if (p->length < sizeof(struct ipw_param) || !p->pointer)
5273 return -EINVAL;
5274
5275 param = (struct ipw_param *)kmalloc(p->length, GFP_KERNEL);
5276 if (param == NULL)
5277 return -ENOMEM;
5278
5279 if (copy_from_user(param, p->pointer, p->length)) {
5280 kfree(param);
5281 return -EFAULT;
5282 }
5283
5284 switch (param->cmd) {
5285
5286 case IPW_CMD_SET_WPA_PARAM:
5287 ret = ipw_wpa_set_param(dev, param->u.wpa_param.name,
5288 param->u.wpa_param.value);
5289 break;
5290
5291 case IPW_CMD_SET_WPA_IE:
5292 ret = ipw_wpa_set_wpa_ie(dev, param, p->length);
5293 break;
5294
5295 case IPW_CMD_SET_ENCRYPTION:
5296 ret = ipw_wpa_set_encryption(dev, param, p->length);
5297 break;
5298
5299 case IPW_CMD_MLME:
5300 ret = ipw_wpa_mlme(dev, param->u.mlme.command,
5301 param->u.mlme.reason_code);
5302 break;
5303
5304 default:
5305 IPW_ERROR("%s: Unknown WPA supplicant request: %d\n",
5306 dev->name, param->cmd);
5307 ret = -EOPNOTSUPP;
5308 }
5309
5310 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
5311 ret = -EFAULT;
5312
5313 kfree(param);
5314 return ret;
5315}
5316#endif /* CONFIG_IEEE80211_WPA */
5317
James Ketrenos43f66a62005-03-25 12:31:53 -06005318static int ipw_associate_network(struct ipw_priv *priv,
5319 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005320 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005321{
5322 int err;
5323
5324 if (priv->config & CFG_FIXED_RATE)
5325 ipw_set_fixed_rate(priv, network);
5326
5327 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005328 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005329 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005330 memcpy(priv->essid, network->ssid, priv->essid_len);
5331 }
5332
5333 network->last_associate = jiffies;
5334
5335 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
5336 priv->assoc_request.channel = network->channel;
5337 if ((priv->capability & CAP_PRIVACY_ON) &&
5338 (priv->capability & CAP_SHARED_KEY)) {
5339 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
5340 priv->assoc_request.auth_key = priv->sec.active_key;
5341 } else {
5342 priv->assoc_request.auth_type = AUTH_OPEN;
5343 priv->assoc_request.auth_key = 0;
5344 }
5345
Jeff Garzikbf794512005-07-31 13:07:26 -04005346 if (priv->capability & CAP_PRIVACY_ON)
James Ketrenos43f66a62005-03-25 12:31:53 -06005347 ipw_send_wep_keys(priv);
5348
James Ketrenosea2b26e2005-08-24 21:25:16 -05005349#ifdef CONFIG_IEEE80211_WPA
5350 if (priv->ieee->wpa_enabled) {
5351 priv->assoc_request.policy_support = 0x02; /* RSN active */
5352 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
5353 priv->ieee->wpa_ie_len);
5354 }
5355#endif
5356
Jeff Garzikbf794512005-07-31 13:07:26 -04005357 /*
5358 * It is valid for our ieee device to support multiple modes, but
5359 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06005360 * just one mode.
5361 */
5362 if (network->mode & priv->ieee->mode & IEEE_A)
5363 priv->assoc_request.ieee_mode = IPW_A_MODE;
5364 else if (network->mode & priv->ieee->mode & IEEE_G)
5365 priv->assoc_request.ieee_mode = IPW_G_MODE;
5366 else if (network->mode & priv->ieee->mode & IEEE_B)
5367 priv->assoc_request.ieee_mode = IPW_B_MODE;
5368
James Ketrenosea2b26e2005-08-24 21:25:16 -05005369 priv->assoc_request.capability = network->capability;
5370 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
5371 && !(priv->config & CFG_PREAMBLE_LONG)) {
5372 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
5373 } else {
5374 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
5375
5376 /* Clear the short preamble if we won't be supporting it */
5377 priv->assoc_request.capability &=
5378 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
5379 }
5380
James Ketrenos43f66a62005-03-25 12:31:53 -06005381 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05005382 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005383 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04005384 escape_essid(priv->essid, priv->essid_len),
5385 network->channel,
5386 ipw_modes[priv->assoc_request.ieee_mode],
5387 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05005388 (priv->assoc_request.preamble_length ==
5389 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
5390 network->capability &
5391 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06005392 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005393 priv->capability & CAP_PRIVACY_ON ?
5394 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005395 "(open)") : "",
5396 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04005397 priv->capability & CAP_PRIVACY_ON ?
James Ketrenos43f66a62005-03-25 12:31:53 -06005398 '1' + priv->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005399 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06005400
5401 priv->assoc_request.beacon_interval = network->beacon_interval;
5402 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005403 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005404 priv->assoc_request.assoc_type = HC_IBSS_START;
5405 priv->assoc_request.assoc_tsf_msw = 0;
5406 priv->assoc_request.assoc_tsf_lsw = 0;
5407 } else {
5408 if (unlikely(roaming))
5409 priv->assoc_request.assoc_type = HC_REASSOCIATE;
5410 else
5411 priv->assoc_request.assoc_type = HC_ASSOCIATE;
5412 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
5413 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
5414 }
5415
5416 memcpy(&priv->assoc_request.bssid, network->bssid, ETH_ALEN);
5417
5418 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5419 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
5420 priv->assoc_request.atim_window = network->atim_window;
5421 } else {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005422 memcpy(&priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06005423 priv->assoc_request.atim_window = 0;
5424 }
5425
James Ketrenos43f66a62005-03-25 12:31:53 -06005426 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04005427
James Ketrenos43f66a62005-03-25 12:31:53 -06005428 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
5429 if (err) {
5430 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
5431 return err;
5432 }
5433
5434 rates->ieee_mode = priv->assoc_request.ieee_mode;
5435 rates->purpose = IPW_RATE_CONNECT;
5436 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04005437
James Ketrenos43f66a62005-03-25 12:31:53 -06005438 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
5439 priv->sys_config.dot11g_auto_detection = 1;
5440 else
5441 priv->sys_config.dot11g_auto_detection = 0;
5442 err = ipw_send_system_config(priv, &priv->sys_config);
5443 if (err) {
5444 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
5445 return err;
5446 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005447
James Ketrenos43f66a62005-03-25 12:31:53 -06005448 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005449 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06005450 if (err) {
5451 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
5452 return err;
5453 }
5454
5455 /*
5456 * If preemption is enabled, it is possible for the association
5457 * to complete before we return from ipw_send_associate. Therefore
5458 * we have to be sure and update our priviate data first.
5459 */
5460 priv->channel = network->channel;
5461 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04005462 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06005463 priv->status &= ~STATUS_SECURITY_UPDATED;
5464
5465 priv->assoc_network = network;
5466
5467 err = ipw_send_associate(priv, &priv->assoc_request);
5468 if (err) {
5469 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
5470 return err;
5471 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005472
5473 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005474 escape_essid(priv->essid, priv->essid_len),
5475 MAC_ARG(priv->bssid));
5476
5477 return 0;
5478}
5479
5480static void ipw_roam(void *data)
5481{
5482 struct ipw_priv *priv = data;
5483 struct ieee80211_network *network = NULL;
5484 struct ipw_network_match match = {
5485 .network = priv->assoc_network
5486 };
5487
5488 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04005489 *
5490 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06005491 * setting the status ROAM bit and requesting a scan.
5492 * 2. When the scan completes, it schedules the ROAM work
5493 * 3. The ROAM work looks at all of the known networks for one that
5494 * is a better network than the currently associated. If none
5495 * found, the ROAM process is over (ROAM bit cleared)
5496 * 4. If a better network is found, a disassociation request is
5497 * sent.
5498 * 5. When the disassociation completes, the roam work is again
5499 * scheduled. The second time through, the driver is no longer
5500 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04005501 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06005502 * 6. At this point ,the roaming process is complete and the ROAM
5503 * status bit is cleared.
5504 */
5505
5506 /* If we are no longer associated, and the roaming bit is no longer
5507 * set, then we are not actively roaming, so just return */
5508 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
5509 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005510
James Ketrenos43f66a62005-03-25 12:31:53 -06005511 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005512 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06005513 * network */
5514 u8 rssi = priv->assoc_network->stats.rssi;
5515 priv->assoc_network->stats.rssi = -128;
5516 list_for_each_entry(network, &priv->ieee->network_list, list) {
5517 if (network != priv->assoc_network)
5518 ipw_best_network(priv, &match, network, 1);
5519 }
5520 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04005521
James Ketrenos43f66a62005-03-25 12:31:53 -06005522 if (match.network == priv->assoc_network) {
5523 IPW_DEBUG_ASSOC("No better APs in this network to "
5524 "roam to.\n");
5525 priv->status &= ~STATUS_ROAMING;
5526 ipw_debug_config(priv);
5527 return;
5528 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005529
James Ketrenos43f66a62005-03-25 12:31:53 -06005530 ipw_send_disassociate(priv, 1);
5531 priv->assoc_network = match.network;
5532
5533 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005534 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005535
5536 /* Second pass through ROAM process -- request association */
5537 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
5538 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
5539 priv->status &= ~STATUS_ROAMING;
5540}
5541
5542static void ipw_associate(void *data)
5543{
5544 struct ipw_priv *priv = data;
5545
5546 struct ieee80211_network *network = NULL;
5547 struct ipw_network_match match = {
5548 .network = NULL
5549 };
5550 struct ipw_supported_rates *rates;
5551 struct list_head *element;
5552
5553 if (!(priv->config & CFG_ASSOCIATE) &&
5554 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005555 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005556 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
5557 return;
5558 }
5559
Jeff Garzikbf794512005-07-31 13:07:26 -04005560 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005561 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06005562
5563 network = match.network;
5564 rates = &match.rates;
5565
5566 if (network == NULL &&
5567 priv->ieee->iw_mode == IW_MODE_ADHOC &&
5568 priv->config & CFG_ADHOC_CREATE &&
5569 priv->config & CFG_STATIC_ESSID &&
5570 !list_empty(&priv->ieee->network_free_list)) {
5571 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005572 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06005573 ipw_adhoc_create(priv, network);
5574 rates = &priv->rates;
5575 list_del(element);
5576 list_add_tail(&network->list, &priv->ieee->network_list);
5577 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005578
James Ketrenos43f66a62005-03-25 12:31:53 -06005579 /* If we reached the end of the list, then we don't have any valid
5580 * matching APs */
5581 if (!network) {
5582 ipw_debug_config(priv);
5583
Jeff Garzikbf794512005-07-31 13:07:26 -04005584 queue_delayed_work(priv->workqueue, &priv->request_scan,
James Ketrenos43f66a62005-03-25 12:31:53 -06005585 SCAN_INTERVAL);
Jeff Garzikbf794512005-07-31 13:07:26 -04005586
James Ketrenos43f66a62005-03-25 12:31:53 -06005587 return;
5588 }
5589
5590 ipw_associate_network(priv, network, rates, 0);
5591}
Jeff Garzikbf794512005-07-31 13:07:26 -04005592
5593static inline void ipw_handle_data_packet(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005594 struct ipw_rx_mem_buffer *rxb,
5595 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06005596{
5597 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
5598
5599 /* We received data from the HW, so stop the watchdog */
5600 priv->net_dev->trans_start = jiffies;
5601
Jeff Garzikbf794512005-07-31 13:07:26 -04005602 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06005603 * interface is open */
Jeff Garzikbf794512005-07-31 13:07:26 -04005604 if (unlikely((pkt->u.frame.length + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06005605 skb_tailroom(rxb->skb))) {
5606 priv->ieee->stats.rx_errors++;
5607 priv->wstats.discard.misc++;
5608 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
5609 return;
5610 } else if (unlikely(!netif_running(priv->net_dev))) {
5611 priv->ieee->stats.rx_dropped++;
5612 priv->wstats.discard.misc++;
5613 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
5614 return;
5615 }
5616
5617 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02005618 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06005619
5620 /* Set the size of the skb to the size of the frame */
5621 skb_put(rxb->skb, pkt->u.frame.length);
5622
5623 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
5624
Jeff Garzikbf794512005-07-31 13:07:26 -04005625 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06005626 priv->ieee->stats.rx_errors++;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005627 else /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06005628 rxb->skb = NULL;
5629}
5630
James Ketrenosea2b26e2005-08-24 21:25:16 -05005631static inline int is_network_packet(struct ipw_priv *priv,
5632 struct ieee80211_hdr_4addr *header)
5633{
5634 /* Filter incoming packets to determine if they are targetted toward
5635 * this network, discarding packets coming from ourselves */
5636 switch (priv->ieee->iw_mode) {
5637 case IW_MODE_ADHOC:
5638 if (is_broadcast_ether_addr(header->addr1) ||
5639 is_multicast_ether_addr(header->addr1))
5640 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
5641 else
5642 return memcmp(header->addr1, priv->net_dev->dev_addr,
5643 ETH_ALEN);
5644 break;
5645 case IW_MODE_INFRA:
5646 if (is_broadcast_ether_addr(header->addr3) ||
5647 is_multicast_ether_addr(header->addr3))
5648 return !memcmp(header->addr1, priv->bssid, ETH_ALEN);
5649 else
5650 return memcmp(header->addr3, priv->net_dev->dev_addr,
5651 ETH_ALEN);
5652 break;
5653 }
5654 return 1;
5655}
5656
James Ketrenos43f66a62005-03-25 12:31:53 -06005657/*
5658 * Main entry function for recieving a packet with 80211 headers. This
5659 * should be called when ever the FW has notified us that there is a new
5660 * skb in the recieve queue.
5661 */
5662static void ipw_rx(struct ipw_priv *priv)
5663{
5664 struct ipw_rx_mem_buffer *rxb;
5665 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05005666 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06005667 u32 r, w, i;
5668 u8 network_packet;
5669
5670 r = ipw_read32(priv, CX2_RX_READ_INDEX);
5671 w = ipw_read32(priv, CX2_RX_WRITE_INDEX);
5672 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
5673
5674 while (i != r) {
5675 rxb = priv->rxq->queue[i];
5676#ifdef CONFIG_IPW_DEBUG
5677 if (unlikely(rxb == NULL)) {
5678 printk(KERN_CRIT "Queue not allocated!\n");
5679 break;
5680 }
5681#endif
5682 priv->rxq->queue[i] = NULL;
5683
5684 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
Jeff Garzikbf794512005-07-31 13:07:26 -04005685 CX2_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06005686 PCI_DMA_FROMDEVICE);
5687
5688 pkt = (struct ipw_rx_packet *)rxb->skb->data;
5689 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
5690 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005691 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06005692
5693 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005694 case RX_FRAME_TYPE: /* 802.11 frame */ {
5695 struct ieee80211_rx_stats stats = {
5696 .rssi = pkt->u.frame.rssi_dbm -
5697 IPW_RSSI_TO_DBM,
5698 .signal = pkt->u.frame.signal,
5699 .rate = pkt->u.frame.rate,
5700 .mac_time = jiffies,
5701 .received_channel =
5702 pkt->u.frame.received_channel,
5703 .freq =
5704 (pkt->u.frame.
5705 control & (1 << 0)) ?
5706 IEEE80211_24GHZ_BAND :
5707 IEEE80211_52GHZ_BAND,
5708 .len = pkt->u.frame.length,
5709 };
James Ketrenos43f66a62005-03-25 12:31:53 -06005710
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005711 if (stats.rssi != 0)
5712 stats.mask |= IEEE80211_STATMASK_RSSI;
5713 if (stats.signal != 0)
5714 stats.mask |= IEEE80211_STATMASK_SIGNAL;
5715 if (stats.rate != 0)
5716 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005717
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005718 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06005719
James Ketrenosea2b26e2005-08-24 21:25:16 -05005720#ifdef CONFIG_IPW_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005721 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5722 ipw_handle_data_packet(priv, rxb,
5723 &stats);
5724 break;
5725 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005726#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04005727
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005728 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05005729 (struct ieee80211_hdr_4addr *)(rxb->skb->
5730 data +
5731 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005732 /* TODO: Check Ad-Hoc dest/source and make sure
5733 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04005734 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06005735 * frame control of the packet and disregard
5736 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06005737
James Ketrenosea2b26e2005-08-24 21:25:16 -05005738 network_packet =
5739 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005740 if (network_packet && priv->assoc_network) {
5741 priv->assoc_network->stats.rssi =
5742 stats.rssi;
5743 average_add(&priv->average_rssi,
5744 stats.rssi);
5745 priv->last_rx_rssi = stats.rssi;
5746 }
5747
5748 IPW_DEBUG_RX("Frame: len=%u\n",
5749 pkt->u.frame.length);
5750
5751 if (pkt->u.frame.length < frame_hdr_len(header)) {
5752 IPW_DEBUG_DROP
5753 ("Received packet is too small. "
5754 "Dropping.\n");
5755 priv->ieee->stats.rx_errors++;
5756 priv->wstats.discard.misc++;
5757 break;
5758 }
5759
5760 switch (WLAN_FC_GET_TYPE(header->frame_ctl)) {
5761 case IEEE80211_FTYPE_MGMT:
5762 ieee80211_rx_mgt(priv->ieee, header,
5763 &stats);
5764 if (priv->ieee->iw_mode == IW_MODE_ADHOC
5765 &&
5766 ((WLAN_FC_GET_STYPE
5767 (header->frame_ctl) ==
5768 IEEE80211_STYPE_PROBE_RESP)
5769 ||
5770 (WLAN_FC_GET_STYPE
5771 (header->frame_ctl) ==
5772 IEEE80211_STYPE_BEACON))
5773 && !memcmp(header->addr3,
5774 priv->bssid, ETH_ALEN))
5775 ipw_add_station(priv,
5776 header->addr2);
5777 break;
5778
5779 case IEEE80211_FTYPE_CTL:
5780 break;
5781
5782 case IEEE80211_FTYPE_DATA:
5783 if (network_packet)
5784 ipw_handle_data_packet(priv,
5785 rxb,
5786 &stats);
5787 else
5788 IPW_DEBUG_DROP("Dropping: "
5789 MAC_FMT ", "
5790 MAC_FMT ", "
5791 MAC_FMT "\n",
5792 MAC_ARG(header->
5793 addr1),
5794 MAC_ARG(header->
5795 addr2),
5796 MAC_ARG(header->
5797 addr3));
5798 break;
5799 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005800 break;
5801 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005802
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005803 case RX_HOST_NOTIFICATION_TYPE:{
5804 IPW_DEBUG_RX
5805 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005806 pkt->u.notification.subtype,
5807 pkt->u.notification.flags,
5808 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005809 ipw_rx_notification(priv, &pkt->u.notification);
5810 break;
5811 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005812
5813 default:
5814 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
5815 pkt->header.message_type);
5816 break;
5817 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005818
5819 /* For now we just don't re-use anything. We can tweak this
5820 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06005821 * fail to Rx correctly */
5822 if (rxb->skb != NULL) {
5823 dev_kfree_skb_any(rxb->skb);
5824 rxb->skb = NULL;
5825 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005826
James Ketrenos43f66a62005-03-25 12:31:53 -06005827 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
5828 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
5829 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04005830
James Ketrenos43f66a62005-03-25 12:31:53 -06005831 i = (i + 1) % RX_QUEUE_SIZE;
5832 }
5833
5834 /* Backtrack one entry */
5835 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
5836
5837 ipw_rx_queue_restock(priv);
5838}
5839
James Ketrenos43f66a62005-03-25 12:31:53 -06005840/*
5841 * This file defines the Wireless Extension handlers. It does not
5842 * define any methods of hardware manipulation and relies on the
5843 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04005844 *
5845 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06005846 * function used to poll the hardware vs. making unecessary calls.
5847 *
5848 */
5849
Jeff Garzikbf794512005-07-31 13:07:26 -04005850static int ipw_wx_get_name(struct net_device *dev,
5851 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005852 union iwreq_data *wrqu, char *extra)
5853{
5854 struct ipw_priv *priv = ieee80211_priv(dev);
5855 if (!(priv->status & STATUS_ASSOCIATED))
5856 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04005857 else
James Ketrenos43f66a62005-03-25 12:31:53 -06005858 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
5859 ipw_modes[priv->assoc_request.ieee_mode]);
5860 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
5861 return 0;
5862}
5863
5864static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
5865{
5866 if (channel == 0) {
5867 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
5868 priv->config &= ~CFG_STATIC_CHANNEL;
5869 if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED |
5870 STATUS_ASSOCIATING))) {
5871 IPW_DEBUG_ASSOC("Attempting to associate with new "
5872 "parameters.\n");
5873 ipw_associate(priv);
5874 }
5875
5876 return 0;
5877 }
5878
5879 priv->config |= CFG_STATIC_CHANNEL;
5880
5881 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005882 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
5883 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005884 return 0;
5885 }
5886
5887 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
5888 priv->channel = channel;
5889
5890 /* If we are currently associated, or trying to associate
5891 * then see if this is a new channel (causing us to disassociate) */
5892 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
5893 IPW_DEBUG_ASSOC("Disassociating due to channel change.\n");
5894 ipw_disassociate(priv);
5895 } else {
5896 ipw_associate(priv);
5897 }
5898
5899 return 0;
5900}
5901
Jeff Garzikbf794512005-07-31 13:07:26 -04005902static int ipw_wx_set_freq(struct net_device *dev,
5903 struct iw_request_info *info,
5904 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06005905{
5906 struct ipw_priv *priv = ieee80211_priv(dev);
5907 struct iw_freq *fwrq = &wrqu->freq;
Jeff Garzikbf794512005-07-31 13:07:26 -04005908
James Ketrenos43f66a62005-03-25 12:31:53 -06005909 /* if setting by freq convert to channel */
5910 if (fwrq->e == 1) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005911 if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005912 int f = fwrq->m / 100000;
5913 int c = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005914
James Ketrenos43f66a62005-03-25 12:31:53 -06005915 while ((c < REG_MAX_CHANNEL) &&
5916 (f != ipw_frequencies[c]))
5917 c++;
Jeff Garzikbf794512005-07-31 13:07:26 -04005918
James Ketrenos43f66a62005-03-25 12:31:53 -06005919 /* hack to fall through */
5920 fwrq->e = 0;
5921 fwrq->m = c + 1;
5922 }
5923 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005924
5925 if (fwrq->e > 0 || fwrq->m > 1000)
James Ketrenos43f66a62005-03-25 12:31:53 -06005926 return -EOPNOTSUPP;
5927
5928 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005929 return ipw_set_channel(priv, (u8) fwrq->m);
James Ketrenos43f66a62005-03-25 12:31:53 -06005930}
5931
Jeff Garzikbf794512005-07-31 13:07:26 -04005932static int ipw_wx_get_freq(struct net_device *dev,
5933 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005934 union iwreq_data *wrqu, char *extra)
5935{
5936 struct ipw_priv *priv = ieee80211_priv(dev);
5937
5938 wrqu->freq.e = 0;
5939
5940 /* If we are associated, trying to associate, or have a statically
5941 * configured CHANNEL then return that; otherwise return ANY */
5942 if (priv->config & CFG_STATIC_CHANNEL ||
5943 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
5944 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04005945 else
James Ketrenos43f66a62005-03-25 12:31:53 -06005946 wrqu->freq.m = 0;
5947
5948 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
5949 return 0;
5950}
5951
Jeff Garzikbf794512005-07-31 13:07:26 -04005952static int ipw_wx_set_mode(struct net_device *dev,
5953 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005954 union iwreq_data *wrqu, char *extra)
5955{
5956 struct ipw_priv *priv = ieee80211_priv(dev);
5957 int err = 0;
5958
5959 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
5960
5961 if (wrqu->mode == priv->ieee->iw_mode)
5962 return 0;
5963
5964 switch (wrqu->mode) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005965#ifdef CONFIG_IPW_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06005966 case IW_MODE_MONITOR:
5967#endif
5968 case IW_MODE_ADHOC:
5969 case IW_MODE_INFRA:
5970 break;
5971 case IW_MODE_AUTO:
5972 wrqu->mode = IW_MODE_INFRA;
5973 break;
5974 default:
5975 return -EINVAL;
5976 }
5977
James Ketrenosea2b26e2005-08-24 21:25:16 -05005978#ifdef CONFIG_IPW_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04005979 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06005980 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04005981
5982 if (wrqu->mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06005983 priv->net_dev->type = ARPHRD_IEEE80211;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005984#endif /* CONFIG_IPW_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04005985
James Ketrenos43f66a62005-03-25 12:31:53 -06005986#ifdef CONFIG_PM
Jeff Garzikbf794512005-07-31 13:07:26 -04005987 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06005988 * flag so ipw_load() will bring in the new firmawre */
5989 if (fw_loaded) {
5990 fw_loaded = 0;
5991 }
5992
5993 release_firmware(bootfw);
5994 release_firmware(ucode);
5995 release_firmware(firmware);
5996 bootfw = ucode = firmware = NULL;
5997#endif
5998
5999 priv->ieee->iw_mode = wrqu->mode;
6000 ipw_adapter_restart(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04006001
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006002 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06006003}
6004
Jeff Garzikbf794512005-07-31 13:07:26 -04006005static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006006 struct iw_request_info *info,
6007 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06006008{
6009 struct ipw_priv *priv = ieee80211_priv(dev);
6010
6011 wrqu->mode = priv->ieee->iw_mode;
6012 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
6013
6014 return 0;
6015}
6016
James Ketrenos43f66a62005-03-25 12:31:53 -06006017#define DEFAULT_RTS_THRESHOLD 2304U
6018#define MIN_RTS_THRESHOLD 1U
6019#define MAX_RTS_THRESHOLD 2304U
6020#define DEFAULT_BEACON_INTERVAL 100U
6021#define DEFAULT_SHORT_RETRY_LIMIT 7U
6022#define DEFAULT_LONG_RETRY_LIMIT 4U
6023
6024/* Values are in microsecond */
6025static const s32 timeout_duration[] = {
6026 350000,
6027 250000,
6028 75000,
6029 37000,
6030 25000,
6031};
6032
6033static const s32 period_duration[] = {
6034 400000,
6035 700000,
6036 1000000,
6037 1000000,
6038 1000000
6039};
6040
Jeff Garzikbf794512005-07-31 13:07:26 -04006041static int ipw_wx_get_range(struct net_device *dev,
6042 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006043 union iwreq_data *wrqu, char *extra)
6044{
6045 struct ipw_priv *priv = ieee80211_priv(dev);
6046 struct iw_range *range = (struct iw_range *)extra;
6047 u16 val;
6048 int i;
6049
6050 wrqu->data.length = sizeof(*range);
6051 memset(range, 0, sizeof(*range));
6052
6053 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04006054 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06006055
6056 range->max_qual.qual = 100;
6057 /* TODO: Find real max RSSI and stick here */
6058 range->max_qual.level = 0;
6059 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006060 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06006061
6062 range->avg_qual.qual = 70;
6063 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006064 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06006065 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006066 range->avg_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06006067
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006068 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06006069
Jeff Garzikbf794512005-07-31 13:07:26 -04006070 for (i = 0; i < range->num_bitrates; i++)
6071 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006072 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04006073
James Ketrenos43f66a62005-03-25 12:31:53 -06006074 range->max_rts = DEFAULT_RTS_THRESHOLD;
6075 range->min_frag = MIN_FRAG_THRESHOLD;
6076 range->max_frag = MAX_FRAG_THRESHOLD;
6077
6078 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04006079 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06006080 range->num_encoding_sizes = 2;
6081 range->max_encoding_tokens = WEP_KEYS;
6082
6083 /* Set the Wireless Extension versions */
6084 range->we_version_compiled = WIRELESS_EXT;
6085 range->we_version_source = 16;
6086
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006087 range->num_channels = FREQ_COUNT;
James Ketrenos43f66a62005-03-25 12:31:53 -06006088
6089 val = 0;
6090 for (i = 0; i < FREQ_COUNT; i++) {
6091 range->freq[val].i = i + 1;
6092 range->freq[val].m = ipw_frequencies[i] * 100000;
6093 range->freq[val].e = 1;
6094 val++;
6095
6096 if (val == IW_MAX_FREQUENCIES)
6097 break;
6098 }
6099 range->num_frequency = val;
6100
6101 IPW_DEBUG_WX("GET Range\n");
6102 return 0;
6103}
6104
Jeff Garzikbf794512005-07-31 13:07:26 -04006105static int ipw_wx_set_wap(struct net_device *dev,
6106 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006107 union iwreq_data *wrqu, char *extra)
6108{
6109 struct ipw_priv *priv = ieee80211_priv(dev);
6110
6111 static const unsigned char any[] = {
6112 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
6113 };
6114 static const unsigned char off[] = {
6115 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
6116 };
6117
Jeff Garzikbf794512005-07-31 13:07:26 -04006118 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06006119 return -EINVAL;
6120
6121 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
6122 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
6123 /* we disable mandatory BSSID association */
6124 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
6125 priv->config &= ~CFG_STATIC_BSSID;
6126 if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED |
6127 STATUS_ASSOCIATING))) {
6128 IPW_DEBUG_ASSOC("Attempting to associate with new "
6129 "parameters.\n");
6130 ipw_associate(priv);
6131 }
6132
6133 return 0;
6134 }
6135
6136 priv->config |= CFG_STATIC_BSSID;
6137 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
6138 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
6139 return 0;
6140 }
6141
6142 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
6143 MAC_ARG(wrqu->ap_addr.sa_data));
6144
6145 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
6146
6147 /* If we are currently associated, or trying to associate
6148 * then see if this is a new BSSID (causing us to disassociate) */
6149 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
6150 IPW_DEBUG_ASSOC("Disassociating due to BSSID change.\n");
6151 ipw_disassociate(priv);
6152 } else {
6153 ipw_associate(priv);
6154 }
6155
6156 return 0;
6157}
6158
Jeff Garzikbf794512005-07-31 13:07:26 -04006159static int ipw_wx_get_wap(struct net_device *dev,
6160 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006161 union iwreq_data *wrqu, char *extra)
6162{
6163 struct ipw_priv *priv = ieee80211_priv(dev);
6164 /* If we are associated, trying to associate, or have a statically
6165 * configured BSSID then return that; otherwise return ANY */
Jeff Garzikbf794512005-07-31 13:07:26 -04006166 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06006167 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
6168 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
6169 memcpy(wrqu->ap_addr.sa_data, &priv->bssid, ETH_ALEN);
6170 } else
6171 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
6172
6173 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
6174 MAC_ARG(wrqu->ap_addr.sa_data));
6175 return 0;
6176}
6177
Jeff Garzikbf794512005-07-31 13:07:26 -04006178static int ipw_wx_set_essid(struct net_device *dev,
6179 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006180 union iwreq_data *wrqu, char *extra)
6181{
6182 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006183 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06006184 int length = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04006185
James Ketrenos43f66a62005-03-25 12:31:53 -06006186 if (wrqu->essid.flags && wrqu->essid.length) {
6187 length = wrqu->essid.length - 1;
6188 essid = extra;
6189 }
6190 if (length == 0) {
6191 IPW_DEBUG_WX("Setting ESSID to ANY\n");
6192 priv->config &= ~CFG_STATIC_ESSID;
6193 if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED |
6194 STATUS_ASSOCIATING))) {
6195 IPW_DEBUG_ASSOC("Attempting to associate with new "
6196 "parameters.\n");
6197 ipw_associate(priv);
6198 }
6199
6200 return 0;
6201 }
6202
6203 length = min(length, IW_ESSID_MAX_SIZE);
6204
6205 priv->config |= CFG_STATIC_ESSID;
6206
6207 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
6208 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
6209 return 0;
6210 }
6211
6212 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
6213 length);
6214
6215 priv->essid_len = length;
6216 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04006217
James Ketrenos43f66a62005-03-25 12:31:53 -06006218 /* If we are currently associated, or trying to associate
6219 * then see if this is a new ESSID (causing us to disassociate) */
6220 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
6221 IPW_DEBUG_ASSOC("Disassociating due to ESSID change.\n");
6222 ipw_disassociate(priv);
6223 } else {
6224 ipw_associate(priv);
6225 }
6226
6227 return 0;
6228}
6229
Jeff Garzikbf794512005-07-31 13:07:26 -04006230static int ipw_wx_get_essid(struct net_device *dev,
6231 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006232 union iwreq_data *wrqu, char *extra)
6233{
6234 struct ipw_priv *priv = ieee80211_priv(dev);
6235
6236 /* If we are associated, trying to associate, or have a statically
6237 * configured ESSID then return that; otherwise return ANY */
6238 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04006239 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
6240 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06006241 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04006242 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06006243 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006244 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06006245 } else {
6246 IPW_DEBUG_WX("Getting essid: ANY\n");
6247 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006248 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06006249 }
6250
6251 return 0;
6252}
6253
Jeff Garzikbf794512005-07-31 13:07:26 -04006254static int ipw_wx_set_nick(struct net_device *dev,
6255 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006256 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006257{
James Ketrenos43f66a62005-03-25 12:31:53 -06006258 struct ipw_priv *priv = ieee80211_priv(dev);
6259
6260 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
6261 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
6262 return -E2BIG;
6263
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006264 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06006265 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006266 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06006267 IPW_DEBUG_TRACE("<<\n");
6268 return 0;
6269
6270}
6271
Jeff Garzikbf794512005-07-31 13:07:26 -04006272static int ipw_wx_get_nick(struct net_device *dev,
6273 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006274 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006275{
James Ketrenos43f66a62005-03-25 12:31:53 -06006276 struct ipw_priv *priv = ieee80211_priv(dev);
6277 IPW_DEBUG_WX("Getting nick\n");
6278 wrqu->data.length = strlen(priv->nick) + 1;
6279 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006280 wrqu->data.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06006281 return 0;
6282}
6283
James Ketrenos43f66a62005-03-25 12:31:53 -06006284static int ipw_wx_set_rate(struct net_device *dev,
6285 struct iw_request_info *info,
6286 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006287{
James Ketrenosea2b26e2005-08-24 21:25:16 -05006288 /* TODO: We should use semaphores or locks for access to priv */
6289 struct ipw_priv *priv = ieee80211_priv(dev);
6290 u32 target_rate = wrqu->bitrate.value;
6291 u32 fixed, mask;
6292
6293 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
6294 /* value = X, fixed = 1 means only rate X */
6295 /* value = X, fixed = 0 means all rates lower equal X */
6296
6297 if (target_rate == -1) {
6298 fixed = 0;
6299 mask = IEEE80211_DEFAULT_RATES_MASK;
6300 /* Now we should reassociate */
6301 goto apply;
6302 }
6303
6304 mask = 0;
6305 fixed = wrqu->bitrate.fixed;
6306
6307 if (target_rate == 1000000 || !fixed)
6308 mask |= IEEE80211_CCK_RATE_1MB_MASK;
6309 if (target_rate == 1000000)
6310 goto apply;
6311
6312 if (target_rate == 2000000 || !fixed)
6313 mask |= IEEE80211_CCK_RATE_2MB_MASK;
6314 if (target_rate == 2000000)
6315 goto apply;
6316
6317 if (target_rate == 5500000 || !fixed)
6318 mask |= IEEE80211_CCK_RATE_5MB_MASK;
6319 if (target_rate == 5500000)
6320 goto apply;
6321
6322 if (target_rate == 6000000 || !fixed)
6323 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
6324 if (target_rate == 6000000)
6325 goto apply;
6326
6327 if (target_rate == 9000000 || !fixed)
6328 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
6329 if (target_rate == 9000000)
6330 goto apply;
6331
6332 if (target_rate == 11000000 || !fixed)
6333 mask |= IEEE80211_CCK_RATE_11MB_MASK;
6334 if (target_rate == 11000000)
6335 goto apply;
6336
6337 if (target_rate == 12000000 || !fixed)
6338 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
6339 if (target_rate == 12000000)
6340 goto apply;
6341
6342 if (target_rate == 18000000 || !fixed)
6343 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
6344 if (target_rate == 18000000)
6345 goto apply;
6346
6347 if (target_rate == 24000000 || !fixed)
6348 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
6349 if (target_rate == 24000000)
6350 goto apply;
6351
6352 if (target_rate == 36000000 || !fixed)
6353 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
6354 if (target_rate == 36000000)
6355 goto apply;
6356
6357 if (target_rate == 48000000 || !fixed)
6358 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
6359 if (target_rate == 48000000)
6360 goto apply;
6361
6362 if (target_rate == 54000000 || !fixed)
6363 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
6364 if (target_rate == 54000000)
6365 goto apply;
6366
6367 IPW_DEBUG_WX("invalid rate specified, returning error\n");
6368 return -EINVAL;
6369
6370 apply:
6371 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
6372 mask, fixed ? "fixed" : "sub-rates");
6373
6374 if (mask == IEEE80211_DEFAULT_RATES_MASK)
6375 priv->config &= ~CFG_FIXED_RATE;
6376 else
6377 priv->config |= CFG_FIXED_RATE;
6378
6379 if (priv->rates_mask != mask) {
6380 priv->rates_mask = mask;
6381 /* If we are already associated or are currently trying to
6382 * associate, disassociate and try again */
6383 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
6384 IPW_DEBUG_ASSOC("Disassociating due to RATE change.\n");
6385 ipw_disassociate(priv);
6386 }
6387 } else {
6388 /* We are not yet associated, so kick one off... */
6389 ipw_associate(priv);
6390 }
6391
6392 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006393}
6394
Jeff Garzikbf794512005-07-31 13:07:26 -04006395static int ipw_wx_get_rate(struct net_device *dev,
6396 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006397 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006398{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006399 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06006400 wrqu->bitrate.value = priv->last_rate;
6401
6402 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
6403 return 0;
6404}
6405
Jeff Garzikbf794512005-07-31 13:07:26 -04006406static int ipw_wx_set_rts(struct net_device *dev,
6407 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006408 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006409{
James Ketrenos43f66a62005-03-25 12:31:53 -06006410 struct ipw_priv *priv = ieee80211_priv(dev);
6411
6412 if (wrqu->rts.disabled)
6413 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
6414 else {
6415 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
6416 wrqu->rts.value > MAX_RTS_THRESHOLD)
6417 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04006418
James Ketrenos43f66a62005-03-25 12:31:53 -06006419 priv->rts_threshold = wrqu->rts.value;
6420 }
6421
6422 ipw_send_rts_threshold(priv, priv->rts_threshold);
6423 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
6424 return 0;
6425}
6426
Jeff Garzikbf794512005-07-31 13:07:26 -04006427static int ipw_wx_get_rts(struct net_device *dev,
6428 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006429 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006430{
James Ketrenos43f66a62005-03-25 12:31:53 -06006431 struct ipw_priv *priv = ieee80211_priv(dev);
6432 wrqu->rts.value = priv->rts_threshold;
6433 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006434 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
James Ketrenos43f66a62005-03-25 12:31:53 -06006435
6436 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
6437 return 0;
6438}
6439
Jeff Garzikbf794512005-07-31 13:07:26 -04006440static int ipw_wx_set_txpow(struct net_device *dev,
6441 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006442 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006443{
James Ketrenos43f66a62005-03-25 12:31:53 -06006444 struct ipw_priv *priv = ieee80211_priv(dev);
6445 struct ipw_tx_power tx_power;
6446 int i;
6447
6448 if (ipw_radio_kill_sw(priv, wrqu->power.disabled))
6449 return -EINPROGRESS;
6450
6451 if (wrqu->power.flags != IW_TXPOW_DBM)
6452 return -EINVAL;
6453
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006454 if ((wrqu->power.value > 20) || (wrqu->power.value < -12))
James Ketrenos43f66a62005-03-25 12:31:53 -06006455 return -EINVAL;
6456
6457 priv->tx_power = wrqu->power.value;
6458
6459 memset(&tx_power, 0, sizeof(tx_power));
6460
6461 /* configure device for 'G' band */
6462 tx_power.ieee_mode = IPW_G_MODE;
6463 tx_power.num_channels = 11;
6464 for (i = 0; i < 11; i++) {
6465 tx_power.channels_tx_power[i].channel_number = i + 1;
6466 tx_power.channels_tx_power[i].tx_power = priv->tx_power;
6467 }
6468 if (ipw_send_tx_power(priv, &tx_power))
6469 goto error;
6470
6471 /* configure device to also handle 'B' band */
6472 tx_power.ieee_mode = IPW_B_MODE;
6473 if (ipw_send_tx_power(priv, &tx_power))
6474 goto error;
6475
6476 return 0;
6477
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006478 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06006479 return -EIO;
6480}
6481
Jeff Garzikbf794512005-07-31 13:07:26 -04006482static int ipw_wx_get_txpow(struct net_device *dev,
6483 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006484 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006485{
James Ketrenos43f66a62005-03-25 12:31:53 -06006486 struct ipw_priv *priv = ieee80211_priv(dev);
6487
6488 wrqu->power.value = priv->tx_power;
6489 wrqu->power.fixed = 1;
6490 wrqu->power.flags = IW_TXPOW_DBM;
6491 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
6492
Jeff Garzikbf794512005-07-31 13:07:26 -04006493 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006494 wrqu->power.disabled ? "ON" : "OFF", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06006495
6496 return 0;
6497}
6498
Jeff Garzikbf794512005-07-31 13:07:26 -04006499static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006500 struct iw_request_info *info,
6501 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06006502{
6503 struct ipw_priv *priv = ieee80211_priv(dev);
6504
6505 if (wrqu->frag.disabled)
6506 priv->ieee->fts = DEFAULT_FTS;
6507 else {
6508 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
6509 wrqu->frag.value > MAX_FRAG_THRESHOLD)
6510 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04006511
James Ketrenos43f66a62005-03-25 12:31:53 -06006512 priv->ieee->fts = wrqu->frag.value & ~0x1;
6513 }
6514
6515 ipw_send_frag_threshold(priv, wrqu->frag.value);
6516 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
6517 return 0;
6518}
6519
Jeff Garzikbf794512005-07-31 13:07:26 -04006520static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006521 struct iw_request_info *info,
6522 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06006523{
6524 struct ipw_priv *priv = ieee80211_priv(dev);
6525 wrqu->frag.value = priv->ieee->fts;
6526 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006527 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
James Ketrenos43f66a62005-03-25 12:31:53 -06006528
6529 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
6530
6531 return 0;
6532}
6533
Jeff Garzikbf794512005-07-31 13:07:26 -04006534static int ipw_wx_set_retry(struct net_device *dev,
6535 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006536 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006537{
James Ketrenos43f66a62005-03-25 12:31:53 -06006538 IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu);
Jeff Garzikbf794512005-07-31 13:07:26 -04006539 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06006540}
6541
Jeff Garzikbf794512005-07-31 13:07:26 -04006542static int ipw_wx_get_retry(struct net_device *dev,
6543 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006544 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006545{
James Ketrenos43f66a62005-03-25 12:31:53 -06006546 IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu);
Jeff Garzikbf794512005-07-31 13:07:26 -04006547 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06006548}
6549
Jeff Garzikbf794512005-07-31 13:07:26 -04006550static int ipw_wx_set_scan(struct net_device *dev,
6551 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006552 union iwreq_data *wrqu, char *extra)
6553{
6554 struct ipw_priv *priv = ieee80211_priv(dev);
6555 IPW_DEBUG_WX("Start scan\n");
6556 if (ipw_request_scan(priv))
6557 return -EIO;
6558 return 0;
6559}
6560
Jeff Garzikbf794512005-07-31 13:07:26 -04006561static int ipw_wx_get_scan(struct net_device *dev,
6562 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006563 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006564{
James Ketrenos43f66a62005-03-25 12:31:53 -06006565 struct ipw_priv *priv = ieee80211_priv(dev);
6566 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
6567}
6568
Jeff Garzikbf794512005-07-31 13:07:26 -04006569static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006570 struct iw_request_info *info,
6571 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06006572{
6573 struct ipw_priv *priv = ieee80211_priv(dev);
6574 return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
6575}
6576
Jeff Garzikbf794512005-07-31 13:07:26 -04006577static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006578 struct iw_request_info *info,
6579 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06006580{
6581 struct ipw_priv *priv = ieee80211_priv(dev);
6582 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
6583}
6584
Jeff Garzikbf794512005-07-31 13:07:26 -04006585static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006586 struct iw_request_info *info,
6587 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06006588{
6589 struct ipw_priv *priv = ieee80211_priv(dev);
6590 int err;
6591
6592 if (wrqu->power.disabled) {
6593 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
6594 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
6595 if (err) {
6596 IPW_DEBUG_WX("failed setting power mode.\n");
6597 return err;
6598 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006599 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
6600
6601 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04006602 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006603
6604 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006605 case IW_POWER_ON: /* If not specified */
6606 case IW_POWER_MODE: /* If set all mask */
6607 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06006608 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006609 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06006610 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
6611 wrqu->power.flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04006612 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06006613 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006614
James Ketrenos43f66a62005-03-25 12:31:53 -06006615 /* If the user hasn't specified a power management mode yet, default
6616 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006617 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06006618 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04006619 else
James Ketrenos43f66a62005-03-25 12:31:53 -06006620 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
6621 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
6622 if (err) {
6623 IPW_DEBUG_WX("failed setting power mode.\n");
6624 return err;
6625 }
6626
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006627 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04006628
James Ketrenos43f66a62005-03-25 12:31:53 -06006629 return 0;
6630}
6631
Jeff Garzikbf794512005-07-31 13:07:26 -04006632static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006633 struct iw_request_info *info,
6634 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06006635{
6636 struct ipw_priv *priv = ieee80211_priv(dev);
6637
6638 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
6639 wrqu->power.disabled = 1;
6640 } else {
6641 wrqu->power.disabled = 0;
6642 }
6643
6644 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04006645
James Ketrenos43f66a62005-03-25 12:31:53 -06006646 return 0;
6647}
6648
Jeff Garzikbf794512005-07-31 13:07:26 -04006649static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006650 struct iw_request_info *info,
6651 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06006652{
6653 struct ipw_priv *priv = ieee80211_priv(dev);
6654 int mode = *(int *)extra;
6655 int err;
Jeff Garzikbf794512005-07-31 13:07:26 -04006656
James Ketrenos43f66a62005-03-25 12:31:53 -06006657 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
6658 mode = IPW_POWER_AC;
6659 priv->power_mode = mode;
6660 } else {
6661 priv->power_mode = IPW_POWER_ENABLED | mode;
6662 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006663
James Ketrenos43f66a62005-03-25 12:31:53 -06006664 if (priv->power_mode != mode) {
6665 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04006666
James Ketrenos43f66a62005-03-25 12:31:53 -06006667 if (err) {
6668 IPW_DEBUG_WX("failed setting power mode.\n");
6669 return err;
6670 }
6671 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006672
James Ketrenos43f66a62005-03-25 12:31:53 -06006673 return 0;
6674}
6675
6676#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04006677static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006678 struct iw_request_info *info,
6679 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06006680{
6681 struct ipw_priv *priv = ieee80211_priv(dev);
6682 int level = IPW_POWER_LEVEL(priv->power_mode);
6683 char *p = extra;
6684
6685 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
6686
6687 switch (level) {
6688 case IPW_POWER_AC:
6689 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
6690 break;
6691 case IPW_POWER_BATTERY:
6692 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
6693 break;
6694 default:
6695 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04006696 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06006697 timeout_duration[level - 1] / 1000,
6698 period_duration[level - 1] / 1000);
6699 }
6700
6701 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006702 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06006703
6704 wrqu->data.length = p - extra + 1;
6705
6706 return 0;
6707}
6708
6709static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006710 struct iw_request_info *info,
6711 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06006712{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006713 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06006714 int mode = *(int *)extra;
6715 u8 band = 0, modulation = 0;
6716
6717 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006718 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06006719 return -EINVAL;
6720 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006721
James Ketrenos43f66a62005-03-25 12:31:53 -06006722 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05006723 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06006724 if (mode & IEEE_A) {
6725 band |= IEEE80211_52GHZ_BAND;
6726 modulation |= IEEE80211_OFDM_MODULATION;
6727 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05006728 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006729 } else {
6730 if (mode & IEEE_A) {
6731 IPW_WARNING("Attempt to set 2200BG into "
6732 "802.11a mode\n");
6733 return -EINVAL;
6734 }
6735
James Ketrenosa33a1982005-09-14 14:28:59 -05006736 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006737 }
6738
6739 if (mode & IEEE_B) {
6740 band |= IEEE80211_24GHZ_BAND;
6741 modulation |= IEEE80211_CCK_MODULATION;
6742 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05006743 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04006744
James Ketrenos43f66a62005-03-25 12:31:53 -06006745 if (mode & IEEE_G) {
6746 band |= IEEE80211_24GHZ_BAND;
6747 modulation |= IEEE80211_OFDM_MODULATION;
6748 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05006749 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006750
6751 priv->ieee->mode = mode;
6752 priv->ieee->freq_band = band;
6753 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006754 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06006755
6756 /* If we are currently associated, or trying to associate
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006757 * then see if this is a new configuration (causing us to
James Ketrenos43f66a62005-03-25 12:31:53 -06006758 * disassociate) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006759 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04006760 /* The resulting association will trigger
James Ketrenos43f66a62005-03-25 12:31:53 -06006761 * the new rates to be sent to the device */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006762 IPW_DEBUG_ASSOC("Disassociating due to mode change.\n");
6763 ipw_disassociate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06006764 } else
6765 ipw_send_supported_rates(priv, &priv->rates);
6766
Jeff Garzikbf794512005-07-31 13:07:26 -04006767 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06006768 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006769 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
James Ketrenos43f66a62005-03-25 12:31:53 -06006770 return 0;
6771}
6772
6773static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006774 struct iw_request_info *info,
6775 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06006776{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006777 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06006778
James Ketrenosea2b26e2005-08-24 21:25:16 -05006779 switch (priv->ieee->mode) {
6780 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06006781 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
6782 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006783 case IEEE_B:
6784 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
6785 break;
6786 case IEEE_A | IEEE_B:
6787 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
6788 break;
6789 case IEEE_G:
6790 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
6791 break;
6792 case IEEE_A | IEEE_G:
6793 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
6794 break;
6795 case IEEE_B | IEEE_G:
6796 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
6797 break;
6798 case IEEE_A | IEEE_B | IEEE_G:
6799 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
6800 break;
6801 default:
6802 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06006803 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006804 }
6805
James Ketrenos43f66a62005-03-25 12:31:53 -06006806 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
6807
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006808 wrqu->data.length = strlen(extra) + 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06006809
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006810 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006811}
6812
James Ketrenosea2b26e2005-08-24 21:25:16 -05006813static int ipw_wx_set_preamble(struct net_device *dev,
6814 struct iw_request_info *info,
6815 union iwreq_data *wrqu, char *extra)
6816{
6817 struct ipw_priv *priv = ieee80211_priv(dev);
6818 int mode = *(int *)extra;
6819
6820 /* Switching from SHORT -> LONG requires a disassociation */
6821 if (mode == 1) {
6822 if (!(priv->config & CFG_PREAMBLE_LONG)) {
6823 priv->config |= CFG_PREAMBLE_LONG;
6824 if (priv->status &
6825 (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
6826 IPW_DEBUG_ASSOC
6827 ("Disassociating due to preamble "
6828 "change.\n");
6829 ipw_disassociate(priv);
6830 }
6831 }
6832 goto done;
6833 }
6834
6835 if (mode == 0) {
6836 priv->config &= ~CFG_PREAMBLE_LONG;
6837 goto done;
6838 }
6839
6840 return -EINVAL;
6841
6842 done:
6843 return 0;
6844}
6845
6846static int ipw_wx_get_preamble(struct net_device *dev,
6847 struct iw_request_info *info,
6848 union iwreq_data *wrqu, char *extra)
6849{
6850 struct ipw_priv *priv = ieee80211_priv(dev);
6851
6852 if (priv->config & CFG_PREAMBLE_LONG)
6853 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
6854 else
6855 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
6856
6857 return 0;
6858}
6859
6860#ifdef CONFIG_IPW_MONITOR
6861static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04006862 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006863 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006864{
James Ketrenos43f66a62005-03-25 12:31:53 -06006865 struct ipw_priv *priv = ieee80211_priv(dev);
6866 int *parms = (int *)extra;
6867 int enable = (parms[0] > 0);
6868
James Ketrenosea2b26e2005-08-24 21:25:16 -05006869 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06006870 if (enable) {
6871 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
6872 priv->net_dev->type = ARPHRD_IEEE80211;
6873 ipw_adapter_restart(priv);
6874 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006875
James Ketrenos43f66a62005-03-25 12:31:53 -06006876 ipw_set_channel(priv, parms[1]);
6877 } else {
6878 if (priv->ieee->iw_mode != IW_MODE_MONITOR)
6879 return 0;
6880 priv->net_dev->type = ARPHRD_ETHER;
6881 ipw_adapter_restart(priv);
6882 }
6883 return 0;
6884}
6885
Jeff Garzikbf794512005-07-31 13:07:26 -04006886static int ipw_wx_reset(struct net_device *dev,
6887 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006888 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006889{
James Ketrenos43f66a62005-03-25 12:31:53 -06006890 struct ipw_priv *priv = ieee80211_priv(dev);
6891 IPW_DEBUG_WX("RESET\n");
6892 ipw_adapter_restart(priv);
6893 return 0;
6894}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006895#endif // CONFIG_IPW_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06006896
6897/* Rebase the WE IOCTLs to zero for the handler array */
6898#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006899static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006900 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
6901 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
6902 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
6903 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
6904 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
6905 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
6906 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
6907 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
6908 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
6909 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
6910 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
6911 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
6912 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
6913 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
6914 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
6915 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
6916 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
6917 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
6918 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
6919 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
6920 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
6921 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
6922 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
6923 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
6924 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
6925 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
6926 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
6927 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenos43f66a62005-03-25 12:31:53 -06006928};
6929
6930#define IPW_PRIV_SET_POWER SIOCIWFIRSTPRIV
6931#define IPW_PRIV_GET_POWER SIOCIWFIRSTPRIV+1
6932#define IPW_PRIV_SET_MODE SIOCIWFIRSTPRIV+2
6933#define IPW_PRIV_GET_MODE SIOCIWFIRSTPRIV+3
James Ketrenosea2b26e2005-08-24 21:25:16 -05006934#define IPW_PRIV_SET_PREAMBLE SIOCIWFIRSTPRIV+4
6935#define IPW_PRIV_GET_PREAMBLE SIOCIWFIRSTPRIV+5
6936#define IPW_PRIV_SET_MONITOR SIOCIWFIRSTPRIV+6
6937#define IPW_PRIV_RESET SIOCIWFIRSTPRIV+7
James Ketrenos43f66a62005-03-25 12:31:53 -06006938
Jeff Garzikbf794512005-07-31 13:07:26 -04006939static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06006940 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006941 .cmd = IPW_PRIV_SET_POWER,
6942 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
6943 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06006944 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006945 .cmd = IPW_PRIV_GET_POWER,
6946 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
6947 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06006948 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006949 .cmd = IPW_PRIV_SET_MODE,
6950 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
6951 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06006952 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006953 .cmd = IPW_PRIV_GET_MODE,
6954 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
6955 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06006956 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006957 .cmd = IPW_PRIV_SET_PREAMBLE,
6958 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
6959 .name = "set_preamble"},
6960 {
6961 .cmd = IPW_PRIV_GET_PREAMBLE,
6962 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
6963 .name = "get_preamble"},
6964#ifdef CONFIG_IPW_MONITOR
6965 {
6966 IPW_PRIV_SET_MONITOR,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006967 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
James Ketrenos43f66a62005-03-25 12:31:53 -06006968 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006969 IPW_PRIV_RESET,
6970 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosea2b26e2005-08-24 21:25:16 -05006971#endif /* CONFIG_IPW_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06006972};
6973
6974static iw_handler ipw_priv_handler[] = {
6975 ipw_wx_set_powermode,
6976 ipw_wx_get_powermode,
6977 ipw_wx_set_wireless_mode,
6978 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05006979 ipw_wx_set_preamble,
6980 ipw_wx_get_preamble,
6981#ifdef CONFIG_IPW_MONITOR
6982 ipw_wx_set_monitor,
Jeff Garzikbf794512005-07-31 13:07:26 -04006983 ipw_wx_reset,
James Ketrenos43f66a62005-03-25 12:31:53 -06006984#endif
6985};
6986
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006987static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006988 .standard = ipw_wx_handlers,
6989 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
6990 .num_private = ARRAY_SIZE(ipw_priv_handler),
6991 .num_private_args = ARRAY_SIZE(ipw_priv_args),
6992 .private = ipw_priv_handler,
6993 .private_args = ipw_priv_args,
James Ketrenos43f66a62005-03-25 12:31:53 -06006994};
6995
James Ketrenos43f66a62005-03-25 12:31:53 -06006996/*
6997 * Get wireless statistics.
6998 * Called by /proc/net/wireless
6999 * Also called by SIOCGIWSTATS
7000 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007001static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06007002{
7003 struct ipw_priv *priv = ieee80211_priv(dev);
7004 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04007005
James Ketrenos43f66a62005-03-25 12:31:53 -06007006 wstats = &priv->wstats;
7007
James Ketrenosea2b26e2005-08-24 21:25:16 -05007008 /* if hw is disabled, then ipw_get_ordinal() can't be called.
Jeff Garzikbf794512005-07-31 13:07:26 -04007009 * ipw2100_wx_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06007010 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
7011 * and associated; if not associcated, the values are all meaningless
7012 * anyway, so set them all to NULL and INVALID */
7013 if (!(priv->status & STATUS_ASSOCIATED)) {
7014 wstats->miss.beacon = 0;
7015 wstats->discard.retries = 0;
7016 wstats->qual.qual = 0;
7017 wstats->qual.level = 0;
7018 wstats->qual.noise = 0;
7019 wstats->qual.updated = 7;
7020 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007021 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06007022 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04007023 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007024
7025 wstats->qual.qual = priv->quality;
7026 wstats->qual.level = average_value(&priv->average_rssi);
7027 wstats->qual.noise = average_value(&priv->average_noise);
7028 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007029 IW_QUAL_NOISE_UPDATED;
James Ketrenos43f66a62005-03-25 12:31:53 -06007030
7031 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
7032 wstats->discard.retries = priv->last_tx_failures;
7033 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04007034
James Ketrenos43f66a62005-03-25 12:31:53 -06007035/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
7036 goto fail_get_ordinal;
7037 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04007038
James Ketrenos43f66a62005-03-25 12:31:53 -06007039 return wstats;
7040}
7041
James Ketrenos43f66a62005-03-25 12:31:53 -06007042/* net device stuff */
7043
7044static inline void init_sys_config(struct ipw_sys_config *sys_config)
7045{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007046 memset(sys_config, 0, sizeof(struct ipw_sys_config));
7047 sys_config->bt_coexistence = 1; /* We may need to look into prvStaBtConfig */
James Ketrenos43f66a62005-03-25 12:31:53 -06007048 sys_config->answer_broadcast_ssid_probe = 0;
7049 sys_config->accept_all_data_frames = 0;
7050 sys_config->accept_non_directed_frames = 1;
7051 sys_config->exclude_unicast_unencrypted = 0;
7052 sys_config->disable_unicast_decryption = 1;
7053 sys_config->exclude_multicast_unencrypted = 0;
7054 sys_config->disable_multicast_decryption = 1;
7055 sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007056 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -06007057 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04007058 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007059 sys_config->bt_coexist_collision_thr = 0;
7060 sys_config->pass_noise_stats_to_host = 1;
7061}
7062
7063static int ipw_net_open(struct net_device *dev)
7064{
7065 struct ipw_priv *priv = ieee80211_priv(dev);
7066 IPW_DEBUG_INFO("dev->open\n");
7067 /* we should be verifying the device is ready to be opened */
Jeff Garzikbf794512005-07-31 13:07:26 -04007068 if (!(priv->status & STATUS_RF_KILL_MASK) &&
7069 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06007070 netif_start_queue(dev);
7071 return 0;
7072}
7073
7074static int ipw_net_stop(struct net_device *dev)
7075{
7076 IPW_DEBUG_INFO("dev->close\n");
7077 netif_stop_queue(dev);
7078 return 0;
7079}
7080
7081/*
7082todo:
7083
7084modify to send one tfd per fragment instead of using chunking. otherwise
7085we need to heavily modify the ieee80211_skb_to_txb.
7086*/
7087
7088static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
7089{
James Ketrenos0dacca12005-09-21 12:23:41 -05007090 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007091 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -06007092 int i = 0;
7093 struct tfd_frame *tfd;
7094 struct clx2_tx_queue *txq = &priv->txq[0];
7095 struct clx2_queue *q = &txq->q;
7096 u8 id, hdr_len, unicast;
7097 u16 remaining_bytes;
7098
7099 switch (priv->ieee->iw_mode) {
7100 case IW_MODE_ADHOC:
7101 hdr_len = IEEE80211_3ADDR_LEN;
7102 unicast = !is_broadcast_ether_addr(hdr->addr1) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007103 !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -06007104 id = ipw_find_station(priv, hdr->addr1);
7105 if (id == IPW_INVALID_STATION) {
7106 id = ipw_add_station(priv, hdr->addr1);
7107 if (id == IPW_INVALID_STATION) {
7108 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -04007109 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007110 MAC_ARG(hdr->addr1));
7111 goto drop;
7112 }
7113 }
7114 break;
7115
7116 case IW_MODE_INFRA:
7117 default:
7118 unicast = !is_broadcast_ether_addr(hdr->addr3) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007119 !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -06007120 hdr_len = IEEE80211_3ADDR_LEN;
7121 id = 0;
7122 break;
7123 }
7124
7125 tfd = &txq->bd[q->first_empty];
7126 txq->txb[q->first_empty] = txb;
7127 memset(tfd, 0, sizeof(*tfd));
7128 tfd->u.data.station_number = id;
7129
7130 tfd->control_flags.message_type = TX_FRAME_TYPE;
7131 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
7132
7133 tfd->u.data.cmd_id = DINO_CMD_TX;
7134 tfd->u.data.len = txb->payload_size;
7135 remaining_bytes = txb->payload_size;
7136 if (unlikely(!unicast))
7137 tfd->u.data.tx_flags = DCT_FLAG_NO_WEP;
7138 else
7139 tfd->u.data.tx_flags = DCT_FLAG_NO_WEP | DCT_FLAG_ACK_REQD;
Jeff Garzikbf794512005-07-31 13:07:26 -04007140
James Ketrenos43f66a62005-03-25 12:31:53 -06007141 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
7142 tfd->u.data.tx_flags_ext = DCT_FLAG_EXT_MODE_CCK;
7143 else
7144 tfd->u.data.tx_flags_ext = DCT_FLAG_EXT_MODE_OFDM;
7145
James Ketrenosea2b26e2005-08-24 21:25:16 -05007146 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
7147 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06007148
7149 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
7150
7151 /* payload */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007152 tfd->u.data.num_chunks = min((u8) (NUM_TFD_CHUNKS - 2), txb->nr_frags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007153 for (i = 0; i < tfd->u.data.num_chunks; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007154 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007155 i, tfd->u.data.num_chunks,
7156 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04007157 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -06007158 txb->fragments[i]->len - hdr_len);
7159
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007160 tfd->u.data.chunk_ptr[i] =
7161 pci_map_single(priv->pci_dev,
7162 txb->fragments[i]->data + hdr_len,
7163 txb->fragments[i]->len - hdr_len,
7164 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007165 tfd->u.data.chunk_len[i] = txb->fragments[i]->len - hdr_len;
7166 }
7167
7168 if (i != txb->nr_frags) {
7169 struct sk_buff *skb;
7170 u16 remaining_bytes = 0;
7171 int j;
7172
7173 for (j = i; j < txb->nr_frags; j++)
7174 remaining_bytes += txb->fragments[j]->len - hdr_len;
7175
7176 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
7177 remaining_bytes);
7178 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
7179 if (skb != NULL) {
7180 tfd->u.data.chunk_len[i] = remaining_bytes;
7181 for (j = i; j < txb->nr_frags; j++) {
7182 int size = txb->fragments[j]->len - hdr_len;
7183 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007184 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06007185 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007186 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06007187 }
7188 dev_kfree_skb_any(txb->fragments[i]);
7189 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007190 tfd->u.data.chunk_ptr[i] =
7191 pci_map_single(priv->pci_dev, skb->data,
7192 tfd->u.data.chunk_len[i],
7193 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007194 tfd->u.data.num_chunks++;
Jeff Garzikbf794512005-07-31 13:07:26 -04007195 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007196 }
7197
7198 /* kick DMA */
7199 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
7200 ipw_write32(priv, q->reg_w, q->first_empty);
7201
Jeff Garzikbf794512005-07-31 13:07:26 -04007202 if (ipw_queue_space(q) < q->high_mark)
James Ketrenos43f66a62005-03-25 12:31:53 -06007203 netif_stop_queue(priv->net_dev);
7204
7205 return;
7206
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007207 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -06007208 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
7209 ieee80211_txb_free(txb);
7210}
7211
7212static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -05007213 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06007214{
7215 struct ipw_priv *priv = ieee80211_priv(dev);
7216 unsigned long flags;
7217
7218 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
7219
7220 spin_lock_irqsave(&priv->lock, flags);
7221
7222 if (!(priv->status & STATUS_ASSOCIATED)) {
7223 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
7224 priv->ieee->stats.tx_carrier_errors++;
7225 netif_stop_queue(dev);
7226 goto fail_unlock;
7227 }
7228
7229 ipw_tx_skb(priv, txb);
7230
7231 spin_unlock_irqrestore(&priv->lock, flags);
7232 return 0;
7233
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007234 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -06007235 spin_unlock_irqrestore(&priv->lock, flags);
7236 return 1;
7237}
7238
7239static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
7240{
7241 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -04007242
James Ketrenos43f66a62005-03-25 12:31:53 -06007243 priv->ieee->stats.tx_packets = priv->tx_packets;
7244 priv->ieee->stats.rx_packets = priv->rx_packets;
7245 return &priv->ieee->stats;
7246}
7247
7248static void ipw_net_set_multicast_list(struct net_device *dev)
7249{
7250
7251}
7252
7253static int ipw_net_set_mac_address(struct net_device *dev, void *p)
7254{
7255 struct ipw_priv *priv = ieee80211_priv(dev);
7256 struct sockaddr *addr = p;
7257 if (!is_valid_ether_addr(addr->sa_data))
7258 return -EADDRNOTAVAIL;
7259 priv->config |= CFG_CUSTOM_MAC;
7260 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
7261 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
7262 priv->net_dev->name, MAC_ARG(priv->mac_addr));
7263 ipw_adapter_restart(priv);
7264 return 0;
7265}
7266
Jeff Garzikbf794512005-07-31 13:07:26 -04007267static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -06007268 struct ethtool_drvinfo *info)
7269{
7270 struct ipw_priv *p = ieee80211_priv(dev);
7271 char vers[64];
7272 char date[32];
7273 u32 len;
7274
7275 strcpy(info->driver, DRV_NAME);
7276 strcpy(info->version, DRV_VERSION);
7277
7278 len = sizeof(vers);
7279 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
7280 len = sizeof(date);
7281 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
7282
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007283 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -06007284 vers, date);
7285 strcpy(info->bus_info, pci_name(p->pci_dev));
7286 info->eedump_len = CX2_EEPROM_IMAGE_SIZE;
7287}
7288
7289static u32 ipw_ethtool_get_link(struct net_device *dev)
7290{
7291 struct ipw_priv *priv = ieee80211_priv(dev);
7292 return (priv->status & STATUS_ASSOCIATED) != 0;
7293}
7294
7295static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
7296{
7297 return CX2_EEPROM_IMAGE_SIZE;
7298}
7299
7300static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007301 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -06007302{
7303 struct ipw_priv *p = ieee80211_priv(dev);
7304
7305 if (eeprom->offset + eeprom->len > CX2_EEPROM_IMAGE_SIZE)
7306 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04007307
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007308 memcpy(bytes, &((u8 *) p->eeprom)[eeprom->offset], eeprom->len);
James Ketrenos43f66a62005-03-25 12:31:53 -06007309 return 0;
7310}
7311
7312static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007313 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -06007314{
7315 struct ipw_priv *p = ieee80211_priv(dev);
7316 int i;
7317
7318 if (eeprom->offset + eeprom->len > CX2_EEPROM_IMAGE_SIZE)
7319 return -EINVAL;
7320
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007321 memcpy(&((u8 *) p->eeprom)[eeprom->offset], bytes, eeprom->len);
Jeff Garzikbf794512005-07-31 13:07:26 -04007322 for (i = IPW_EEPROM_DATA;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007323 i < IPW_EEPROM_DATA + CX2_EEPROM_IMAGE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06007324 ipw_write8(p, i, p->eeprom[i]);
7325
7326 return 0;
7327}
7328
7329static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007330 .get_link = ipw_ethtool_get_link,
7331 .get_drvinfo = ipw_ethtool_get_drvinfo,
7332 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
7333 .get_eeprom = ipw_ethtool_get_eeprom,
7334 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -06007335};
7336
7337static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
7338{
7339 struct ipw_priv *priv = data;
7340 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -04007341
James Ketrenos43f66a62005-03-25 12:31:53 -06007342 if (!priv)
7343 return IRQ_NONE;
7344
7345 spin_lock(&priv->lock);
7346
7347 if (!(priv->status & STATUS_INT_ENABLED)) {
7348 /* Shared IRQ */
7349 goto none;
7350 }
7351
7352 inta = ipw_read32(priv, CX2_INTA_RW);
7353 inta_mask = ipw_read32(priv, CX2_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -04007354
James Ketrenos43f66a62005-03-25 12:31:53 -06007355 if (inta == 0xFFFFFFFF) {
7356 /* Hardware disappeared */
7357 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
7358 goto none;
7359 }
7360
7361 if (!(inta & (CX2_INTA_MASK_ALL & inta_mask))) {
7362 /* Shared interrupt */
7363 goto none;
7364 }
7365
7366 /* tell the device to stop sending interrupts */
7367 ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04007368
James Ketrenos43f66a62005-03-25 12:31:53 -06007369 /* ack current interrupts */
7370 inta &= (CX2_INTA_MASK_ALL & inta_mask);
7371 ipw_write32(priv, CX2_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -04007372
James Ketrenos43f66a62005-03-25 12:31:53 -06007373 /* Cache INTA value for our tasklet */
7374 priv->isr_inta = inta;
7375
7376 tasklet_schedule(&priv->irq_tasklet);
7377
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007378 spin_unlock(&priv->lock);
James Ketrenos43f66a62005-03-25 12:31:53 -06007379
7380 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007381 none:
James Ketrenos43f66a62005-03-25 12:31:53 -06007382 spin_unlock(&priv->lock);
7383 return IRQ_NONE;
7384}
7385
7386static void ipw_rf_kill(void *adapter)
7387{
7388 struct ipw_priv *priv = adapter;
7389 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -04007390
James Ketrenos43f66a62005-03-25 12:31:53 -06007391 spin_lock_irqsave(&priv->lock, flags);
7392
7393 if (rf_kill_active(priv)) {
7394 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
7395 if (priv->workqueue)
7396 queue_delayed_work(priv->workqueue,
7397 &priv->rf_kill, 2 * HZ);
7398 goto exit_unlock;
7399 }
7400
7401 /* RF Kill is now disabled, so bring the device back up */
7402
7403 if (!(priv->status & STATUS_RF_KILL_MASK)) {
7404 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
7405 "device\n");
7406
7407 /* we can not do an adapter restart while inside an irq lock */
7408 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -04007409 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06007410 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
7411 "enabled\n");
7412
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007413 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -06007414 spin_unlock_irqrestore(&priv->lock, flags);
7415}
7416
7417static int ipw_setup_deferred_work(struct ipw_priv *priv)
7418{
7419 int ret = 0;
7420
James Ketrenos43f66a62005-03-25 12:31:53 -06007421 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -06007422 init_waitqueue_head(&priv->wait_command_queue);
7423
7424 INIT_WORK(&priv->adhoc_check, ipw_adhoc_check, priv);
7425 INIT_WORK(&priv->associate, ipw_associate, priv);
7426 INIT_WORK(&priv->disassociate, ipw_disassociate, priv);
7427 INIT_WORK(&priv->rx_replenish, ipw_rx_queue_replenish, priv);
7428 INIT_WORK(&priv->adapter_restart, ipw_adapter_restart, priv);
7429 INIT_WORK(&priv->rf_kill, ipw_rf_kill, priv);
7430 INIT_WORK(&priv->up, (void (*)(void *))ipw_up, priv);
7431 INIT_WORK(&priv->down, (void (*)(void *))ipw_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04007432 INIT_WORK(&priv->request_scan,
James Ketrenos43f66a62005-03-25 12:31:53 -06007433 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04007434 INIT_WORK(&priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06007435 (void (*)(void *))ipw_gather_stats, priv);
7436 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_abort_scan, priv);
7437 INIT_WORK(&priv->roam, ipw_roam, priv);
7438 INIT_WORK(&priv->scan_check, ipw_scan_check, priv);
7439
7440 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
7441 ipw_irq_tasklet, (unsigned long)priv);
7442
7443 return ret;
7444}
7445
James Ketrenos43f66a62005-03-25 12:31:53 -06007446static void shim__set_security(struct net_device *dev,
7447 struct ieee80211_security *sec)
7448{
7449 struct ipw_priv *priv = ieee80211_priv(dev);
7450 int i;
7451
Jeff Garzikbf794512005-07-31 13:07:26 -04007452 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007453 if (sec->flags & (1 << i)) {
7454 priv->sec.key_sizes[i] = sec->key_sizes[i];
7455 if (sec->key_sizes[i] == 0)
7456 priv->sec.flags &= ~(1 << i);
7457 else
Jeff Garzikbf794512005-07-31 13:07:26 -04007458 memcpy(priv->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -06007459 sec->key_sizes[i]);
7460 priv->sec.flags |= (1 << i);
7461 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -04007462 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007463 }
7464
7465 if ((sec->flags & SEC_ACTIVE_KEY) &&
7466 priv->sec.active_key != sec->active_key) {
7467 if (sec->active_key <= 3) {
7468 priv->sec.active_key = sec->active_key;
7469 priv->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -04007470 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06007471 priv->sec.flags &= ~SEC_ACTIVE_KEY;
7472 priv->status |= STATUS_SECURITY_UPDATED;
7473 }
7474
7475 if ((sec->flags & SEC_AUTH_MODE) &&
7476 (priv->sec.auth_mode != sec->auth_mode)) {
7477 priv->sec.auth_mode = sec->auth_mode;
7478 priv->sec.flags |= SEC_AUTH_MODE;
7479 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
7480 priv->capability |= CAP_SHARED_KEY;
7481 else
7482 priv->capability &= ~CAP_SHARED_KEY;
7483 priv->status |= STATUS_SECURITY_UPDATED;
7484 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007485
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007486 if (sec->flags & SEC_ENABLED && priv->sec.enabled != sec->enabled) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007487 priv->sec.flags |= SEC_ENABLED;
7488 priv->sec.enabled = sec->enabled;
7489 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -04007490 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06007491 priv->capability |= CAP_PRIVACY_ON;
7492 else
7493 priv->capability &= ~CAP_PRIVACY_ON;
7494 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007495
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007496 if (sec->flags & SEC_LEVEL && priv->sec.level != sec->level) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007497 priv->sec.level = sec->level;
7498 priv->sec.flags |= SEC_LEVEL;
7499 priv->status |= STATUS_SECURITY_UPDATED;
7500 }
7501
Jeff Garzikbf794512005-07-31 13:07:26 -04007502 /* To match current functionality of ipw2100 (which works well w/
7503 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007504 * privacy capability changes ... */
7505#if 0
7506 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -04007507 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -06007508 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04007509 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007510 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007511 IPW_DEBUG_ASSOC("Disassociating due to capability "
7512 "change.\n");
7513 ipw_disassociate(priv);
7514 }
7515#endif
7516}
7517
Jeff Garzikbf794512005-07-31 13:07:26 -04007518static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06007519 struct ipw_supported_rates *rates)
7520{
7521 /* TODO: Mask out rates based on priv->rates_mask */
7522
7523 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007524 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -06007525 switch (priv->ieee->freq_band) {
7526 case IEEE80211_52GHZ_BAND:
7527 rates->ieee_mode = IPW_A_MODE;
7528 rates->purpose = IPW_RATE_CAPABILITIES;
7529 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
7530 IEEE80211_OFDM_DEFAULT_RATES_MASK);
7531 break;
7532
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007533 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -06007534 rates->ieee_mode = IPW_G_MODE;
7535 rates->purpose = IPW_RATE_CAPABILITIES;
7536 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
7537 IEEE80211_CCK_DEFAULT_RATES_MASK);
7538 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
7539 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
7540 IEEE80211_OFDM_DEFAULT_RATES_MASK);
7541 }
7542 break;
7543 }
7544
7545 return 0;
7546}
7547
Jeff Garzikbf794512005-07-31 13:07:26 -04007548static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06007549{
7550 int i;
7551 struct ipw_tx_power tx_power;
7552
7553 memset(&priv->sys_config, 0, sizeof(priv->sys_config));
7554 memset(&tx_power, 0, sizeof(tx_power));
7555
7556 /* This is only called from ipw_up, which resets/reloads the firmware
7557 so, we don't need to first disable the card before we configure
7558 it */
7559
7560 /* configure device for 'G' band */
7561 tx_power.ieee_mode = IPW_G_MODE;
7562 tx_power.num_channels = 11;
7563 for (i = 0; i < 11; i++) {
7564 tx_power.channels_tx_power[i].channel_number = i + 1;
7565 tx_power.channels_tx_power[i].tx_power = priv->tx_power;
7566 }
7567 if (ipw_send_tx_power(priv, &tx_power))
7568 goto error;
7569
7570 /* configure device to also handle 'B' band */
7571 tx_power.ieee_mode = IPW_B_MODE;
7572 if (ipw_send_tx_power(priv, &tx_power))
7573 goto error;
7574
7575 /* initialize adapter address */
7576 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
7577 goto error;
7578
7579 /* set basic system config settings */
7580 init_sys_config(&priv->sys_config);
7581 if (ipw_send_system_config(priv, &priv->sys_config))
7582 goto error;
7583
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007584 init_supported_rates(priv, &priv->rates);
7585 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -06007586 goto error;
7587
7588 /* Set request-to-send threshold */
7589 if (priv->rts_threshold) {
7590 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
7591 goto error;
7592 }
7593
7594 if (ipw_set_random_seed(priv))
7595 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04007596
James Ketrenos43f66a62005-03-25 12:31:53 -06007597 /* final state transition to the RUN state */
7598 if (ipw_send_host_complete(priv))
7599 goto error;
7600
7601 /* If configured to try and auto-associate, kick off a scan */
7602 if ((priv->config & CFG_ASSOCIATE) && ipw_request_scan(priv))
7603 goto error;
7604
7605 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04007606
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007607 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06007608 return -EIO;
7609}
7610
7611#define MAX_HW_RESTARTS 5
7612static int ipw_up(struct ipw_priv *priv)
7613{
7614 int rc, i;
7615
7616 if (priv->status & STATUS_EXIT_PENDING)
7617 return -EIO;
7618
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007619 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007620 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -06007621 * Also start the clocks. */
7622 rc = ipw_load(priv);
7623 if (rc) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007624 IPW_ERROR("Unable to load firmware: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06007625 return rc;
7626 }
7627
7628 ipw_init_ordinals(priv);
7629 if (!(priv->config & CFG_CUSTOM_MAC))
7630 eeprom_parse_mac(priv, priv->mac_addr);
7631 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
7632
7633 if (priv->status & STATUS_RF_KILL_MASK)
7634 return 0;
7635
7636 rc = ipw_config(priv);
7637 if (!rc) {
7638 IPW_DEBUG_INFO("Configured device on count %i\n", i);
7639 priv->notif_missed_beacons = 0;
7640 netif_start_queue(priv->net_dev);
7641 return 0;
7642 } else {
7643 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n",
7644 rc);
7645 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007646
James Ketrenos43f66a62005-03-25 12:31:53 -06007647 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
7648 i, MAX_HW_RESTARTS);
7649
7650 /* We had an error bringing up the hardware, so take it
7651 * all the way back down so we can try again */
7652 ipw_down(priv);
7653 }
7654
Jeff Garzikbf794512005-07-31 13:07:26 -04007655 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -06007656 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007657 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenos43f66a62005-03-25 12:31:53 -06007658 return -EIO;
7659}
7660
7661static void ipw_down(struct ipw_priv *priv)
7662{
7663 /* Attempt to disable the card */
7664#if 0
7665 ipw_send_card_disable(priv, 0);
7666#endif
7667
7668 /* tell the device to stop sending interrupts */
7669 ipw_disable_interrupts(priv);
7670
7671 /* Clear all bits but the RF Kill */
7672 priv->status &= STATUS_RF_KILL_MASK;
7673
7674 netif_carrier_off(priv->net_dev);
7675 netif_stop_queue(priv->net_dev);
7676
7677 ipw_stop_nic(priv);
7678}
7679
James Ketrenosea2b26e2005-08-24 21:25:16 -05007680static int ipw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
7681{
7682#ifdef CONFIG_IEEE80211_WPA
7683 struct iwreq *wrq = (struct iwreq *)rq;
7684 int ret = -1;
7685 switch (cmd) {
7686 case IPW_IOCTL_WPA_SUPPLICANT:
7687 ret = ipw_wpa_supplicant(dev, &wrq->u.data);
7688 return ret;
7689
7690 default:
7691 return -EOPNOTSUPP;
7692 }
7693
7694#endif /* CONFIG_IEEE80211_WPA */
7695
7696 return -EOPNOTSUPP;
7697}
7698
James Ketrenos43f66a62005-03-25 12:31:53 -06007699/* Called by register_netdev() */
7700static int ipw_net_init(struct net_device *dev)
7701{
7702 struct ipw_priv *priv = ieee80211_priv(dev);
7703
7704 if (priv->status & STATUS_RF_KILL_SW) {
7705 IPW_WARNING("Radio disabled by module parameter.\n");
7706 return 0;
7707 } else if (rf_kill_active(priv)) {
7708 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
7709 "Kill switch must be turned off for "
7710 "wireless networking to work.\n");
7711 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
7712 return 0;
7713 }
7714
7715 if (ipw_up(priv))
7716 return -EIO;
7717
7718 return 0;
7719}
7720
7721/* PCI driver stuff */
7722static struct pci_device_id card_ids[] = {
7723 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
7724 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
7725 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
7726 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
7727 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
7728 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
7729 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
7730 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
7731 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
7732 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
7733 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
7734 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
7735 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
7736 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
7737 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
7738 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
7739 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
7740 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007741 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
7742 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 2225BG */
7743 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
7744 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -04007745
James Ketrenos43f66a62005-03-25 12:31:53 -06007746 /* required last entry */
7747 {0,}
7748};
7749
7750MODULE_DEVICE_TABLE(pci, card_ids);
7751
7752static struct attribute *ipw_sysfs_entries[] = {
7753 &dev_attr_rf_kill.attr,
7754 &dev_attr_direct_dword.attr,
7755 &dev_attr_indirect_byte.attr,
7756 &dev_attr_indirect_dword.attr,
7757 &dev_attr_mem_gpio_reg.attr,
7758 &dev_attr_command_event_reg.attr,
7759 &dev_attr_nic_type.attr,
7760 &dev_attr_status.attr,
7761 &dev_attr_cfg.attr,
7762 &dev_attr_dump_errors.attr,
7763 &dev_attr_dump_events.attr,
7764 &dev_attr_eeprom_delay.attr,
7765 &dev_attr_ucode_version.attr,
7766 &dev_attr_rtc.attr,
7767 NULL
7768};
7769
7770static struct attribute_group ipw_attribute_group = {
7771 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007772 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -06007773};
7774
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007775static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -06007776{
7777 int err = 0;
7778 struct net_device *net_dev;
7779 void __iomem *base;
7780 u32 length, val;
7781 struct ipw_priv *priv;
7782 int band, modulation;
7783
7784 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
7785 if (net_dev == NULL) {
7786 err = -ENOMEM;
7787 goto out;
7788 }
7789
7790 priv = ieee80211_priv(net_dev);
7791 priv->ieee = netdev_priv(net_dev);
7792 priv->net_dev = net_dev;
7793 priv->pci_dev = pdev;
7794#ifdef CONFIG_IPW_DEBUG
7795 ipw_debug_level = debug;
7796#endif
7797 spin_lock_init(&priv->lock);
7798
7799 if (pci_enable_device(pdev)) {
7800 err = -ENODEV;
7801 goto out_free_ieee80211;
7802 }
7803
7804 pci_set_master(pdev);
7805
Tobias Klauser0e08b442005-06-20 14:28:41 -07007806 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -04007807 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -07007808 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -06007809 if (err) {
7810 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
7811 goto out_pci_disable_device;
7812 }
7813
7814 pci_set_drvdata(pdev, priv);
7815
7816 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -04007817 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -06007818 goto out_pci_disable_device;
7819
Jeff Garzikbf794512005-07-31 13:07:26 -04007820 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -06007821 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -04007822 pci_read_config_dword(pdev, 0x40, &val);
7823 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06007824 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -04007825
James Ketrenos43f66a62005-03-25 12:31:53 -06007826 length = pci_resource_len(pdev, 0);
7827 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -04007828
James Ketrenos43f66a62005-03-25 12:31:53 -06007829 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
7830 if (!base) {
7831 err = -ENODEV;
7832 goto out_pci_release_regions;
7833 }
7834
7835 priv->hw_base = base;
7836 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
7837 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
7838
7839 err = ipw_setup_deferred_work(priv);
7840 if (err) {
7841 IPW_ERROR("Unable to setup deferred work\n");
7842 goto out_iounmap;
7843 }
7844
7845 /* Initialize module parameter values here */
Jeff Garzikbf794512005-07-31 13:07:26 -04007846 if (associate)
James Ketrenos43f66a62005-03-25 12:31:53 -06007847 priv->config |= CFG_ASSOCIATE;
7848 else
7849 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04007850
7851 if (auto_create)
James Ketrenos43f66a62005-03-25 12:31:53 -06007852 priv->config |= CFG_ADHOC_CREATE;
7853 else
7854 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04007855
James Ketrenos43f66a62005-03-25 12:31:53 -06007856 if (disable) {
7857 priv->status |= STATUS_RF_KILL_SW;
7858 IPW_DEBUG_INFO("Radio disabled.\n");
7859 }
7860
7861 if (channel != 0) {
7862 priv->config |= CFG_STATIC_CHANNEL;
7863 priv->channel = channel;
7864 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007865 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06007866 /* TODO: Validate that provided channel is in range */
7867 }
7868
7869 switch (mode) {
7870 case 1:
7871 priv->ieee->iw_mode = IW_MODE_ADHOC;
7872 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05007873#ifdef CONFIG_IPW_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06007874 case 2:
7875 priv->ieee->iw_mode = IW_MODE_MONITOR;
7876 break;
7877#endif
7878 default:
7879 case 0:
7880 priv->ieee->iw_mode = IW_MODE_INFRA;
7881 break;
7882 }
7883
7884 if ((priv->pci_dev->device == 0x4223) ||
7885 (priv->pci_dev->device == 0x4224)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007886 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06007887 ": Detected Intel PRO/Wireless 2915ABG Network "
7888 "Connection\n");
James Ketrenosa33a1982005-09-14 14:28:59 -05007889 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007890 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
7891 modulation = IEEE80211_OFDM_MODULATION |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007892 IEEE80211_CCK_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06007893 priv->adapter = IPW_2915ABG;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007894 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06007895 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04007896 if (priv->pci_dev->device == 0x4221)
7897 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06007898 ": Detected Intel PRO/Wireless 2225BG Network "
7899 "Connection\n");
7900 else
Jeff Garzikbf794512005-07-31 13:07:26 -04007901 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06007902 ": Detected Intel PRO/Wireless 2200BG Network "
7903 "Connection\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04007904
James Ketrenosa33a1982005-09-14 14:28:59 -05007905 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007906 band = IEEE80211_24GHZ_BAND;
7907 modulation = IEEE80211_OFDM_MODULATION |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007908 IEEE80211_CCK_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06007909 priv->adapter = IPW_2200BG;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007910 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06007911 }
7912
7913 priv->ieee->freq_band = band;
7914 priv->ieee->modulation = modulation;
7915
7916 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
7917
7918 priv->missed_beacon_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
7919 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
7920
7921 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
7922
7923 /* If power management is turned on, default to AC mode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007924 priv->power_mode = IPW_POWER_AC;
James Ketrenos43f66a62005-03-25 12:31:53 -06007925 priv->tx_power = IPW_DEFAULT_TX_POWER;
7926
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007927 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007928 if (err) {
7929 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
7930 goto out_destroy_workqueue;
7931 }
7932
7933 SET_MODULE_OWNER(net_dev);
7934 SET_NETDEV_DEV(net_dev, &pdev->dev);
7935
7936 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
7937 priv->ieee->set_security = shim__set_security;
7938
7939 net_dev->open = ipw_net_open;
7940 net_dev->stop = ipw_net_stop;
7941 net_dev->init = ipw_net_init;
James Ketrenosea2b26e2005-08-24 21:25:16 -05007942 net_dev->do_ioctl = ipw_ioctl;
James Ketrenos43f66a62005-03-25 12:31:53 -06007943 net_dev->get_stats = ipw_net_get_stats;
7944 net_dev->set_multicast_list = ipw_net_set_multicast_list;
7945 net_dev->set_mac_address = ipw_net_set_mac_address;
7946 net_dev->get_wireless_stats = ipw_get_wireless_stats;
7947 net_dev->wireless_handlers = &ipw_wx_handler_def;
7948 net_dev->ethtool_ops = &ipw_ethtool_ops;
7949 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007950 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -06007951 net_dev->mem_start = pci_resource_start(pdev, 0);
7952 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
7953
7954 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
7955 if (err) {
7956 IPW_ERROR("failed to create sysfs device attributes\n");
7957 goto out_release_irq;
7958 }
7959
7960 err = register_netdev(net_dev);
7961 if (err) {
7962 IPW_ERROR("failed to register network device\n");
7963 goto out_remove_group;
7964 }
7965
7966 return 0;
7967
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007968 out_remove_group:
James Ketrenos43f66a62005-03-25 12:31:53 -06007969 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007970 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -06007971 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007972 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -06007973 destroy_workqueue(priv->workqueue);
7974 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007975 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -06007976 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007977 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -06007978 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007979 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -06007980 pci_disable_device(pdev);
7981 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007982 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -06007983 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007984 out:
James Ketrenos43f66a62005-03-25 12:31:53 -06007985 return err;
7986}
7987
7988static void ipw_pci_remove(struct pci_dev *pdev)
7989{
7990 struct ipw_priv *priv = pci_get_drvdata(pdev);
7991 if (!priv)
7992 return;
7993
7994 priv->status |= STATUS_EXIT_PENDING;
7995
7996 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
7997
7998 ipw_down(priv);
7999
8000 unregister_netdev(priv->net_dev);
8001
8002 if (priv->rxq) {
8003 ipw_rx_queue_free(priv, priv->rxq);
8004 priv->rxq = NULL;
8005 }
8006 ipw_tx_queue_free(priv);
8007
8008 /* ipw_down will ensure that there is no more pending work
8009 * in the workqueue's, so we can safely remove them now. */
Jeff Garzikbf794512005-07-31 13:07:26 -04008010 if (priv->workqueue) {
James Ketrenos43f66a62005-03-25 12:31:53 -06008011 cancel_delayed_work(&priv->adhoc_check);
8012 cancel_delayed_work(&priv->gather_stats);
8013 cancel_delayed_work(&priv->request_scan);
8014 cancel_delayed_work(&priv->rf_kill);
8015 cancel_delayed_work(&priv->scan_check);
8016 destroy_workqueue(priv->workqueue);
8017 priv->workqueue = NULL;
8018 }
8019
8020 free_irq(pdev->irq, priv);
8021 iounmap(priv->hw_base);
8022 pci_release_regions(pdev);
8023 pci_disable_device(pdev);
8024 pci_set_drvdata(pdev, NULL);
8025 free_ieee80211(priv->net_dev);
8026
8027#ifdef CONFIG_PM
8028 if (fw_loaded) {
8029 release_firmware(bootfw);
8030 release_firmware(ucode);
8031 release_firmware(firmware);
8032 fw_loaded = 0;
8033 }
8034#endif
8035}
8036
James Ketrenos43f66a62005-03-25 12:31:53 -06008037#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -07008038static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -06008039{
8040 struct ipw_priv *priv = pci_get_drvdata(pdev);
8041 struct net_device *dev = priv->net_dev;
8042
8043 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
8044
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008045 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -06008046 ipw_down(priv);
8047
8048 /* Remove the PRESENT state of the device */
8049 netif_device_detach(dev);
8050
James Ketrenos43f66a62005-03-25 12:31:53 -06008051 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008052 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -07008053 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -04008054
James Ketrenos43f66a62005-03-25 12:31:53 -06008055 return 0;
8056}
8057
8058static int ipw_pci_resume(struct pci_dev *pdev)
8059{
8060 struct ipw_priv *priv = pci_get_drvdata(pdev);
8061 struct net_device *dev = priv->net_dev;
8062 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -04008063
James Ketrenos43f66a62005-03-25 12:31:53 -06008064 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
8065
James Ketrenosea2b26e2005-08-24 21:25:16 -05008066 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -06008067 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008068 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008069
James Ketrenos43f66a62005-03-25 12:31:53 -06008070 /*
8071 * Suspend/Resume resets the PCI configuration space, so we have to
8072 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
8073 * from interfering with C3 CPU state. pci_restore_state won't help
8074 * here since it only restores the first 64 bytes pci config header.
8075 */
Jeff Garzikbf794512005-07-31 13:07:26 -04008076 pci_read_config_dword(pdev, 0x40, &val);
8077 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06008078 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
8079
8080 /* Set the device back into the PRESENT state; this will also wake
8081 * the queue of needed */
8082 netif_device_attach(dev);
8083
8084 /* Bring the device back up */
8085 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -04008086
James Ketrenos43f66a62005-03-25 12:31:53 -06008087 return 0;
8088}
8089#endif
8090
8091/* driver initialization stuff */
8092static struct pci_driver ipw_driver = {
8093 .name = DRV_NAME,
8094 .id_table = card_ids,
8095 .probe = ipw_pci_probe,
8096 .remove = __devexit_p(ipw_pci_remove),
8097#ifdef CONFIG_PM
8098 .suspend = ipw_pci_suspend,
8099 .resume = ipw_pci_resume,
8100#endif
8101};
8102
8103static int __init ipw_init(void)
8104{
8105 int ret;
8106
8107 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
8108 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
8109
8110 ret = pci_module_init(&ipw_driver);
8111 if (ret) {
8112 IPW_ERROR("Unable to initialize PCI module\n");
8113 return ret;
8114 }
8115
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008116 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -06008117 if (ret) {
8118 IPW_ERROR("Unable to create driver sysfs file\n");
8119 pci_unregister_driver(&ipw_driver);
8120 return ret;
8121 }
8122
8123 return ret;
8124}
8125
8126static void __exit ipw_exit(void)
8127{
8128 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
8129 pci_unregister_driver(&ipw_driver);
8130}
8131
8132module_param(disable, int, 0444);
8133MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
8134
8135module_param(associate, int, 0444);
8136MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
8137
8138module_param(auto_create, int, 0444);
8139MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
8140
8141module_param(debug, int, 0444);
8142MODULE_PARM_DESC(debug, "debug output mask");
8143
8144module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -04008145MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -06008146
James Ketrenosea2b26e2005-08-24 21:25:16 -05008147#ifdef CONFIG_IPW_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008148module_param(mode, int, 0444);
8149MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
8150#else
8151module_param(mode, int, 0444);
8152MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
8153#endif
8154
8155module_exit(ipw_exit);
8156module_init(ipw_init);