blob: 3db0c32afe82d1965186654f443c85b23846f6fb [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
35#define IPW2200_VERSION "1.0.0"
36#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
37#define DRV_COPYRIGHT "Copyright(c) 2003-2004 Intel Corporation"
38#define DRV_VERSION IPW2200_VERSION
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;
47static char *ifname;
48static int mode = 0;
49
50static u32 ipw_debug_level;
51static int associate = 1;
52static int auto_create = 1;
53static int disable = 0;
54static const char ipw_modes[] = {
55 'a', 'b', 'g', '?'
56};
57
58static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040059static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060060 struct clx2_tx_queue *txq, int qindex);
61static int ipw_queue_reset(struct ipw_priv *priv);
62
63static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
64 int len, int sync);
65
66static void ipw_tx_queue_free(struct ipw_priv *);
67
68static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
69static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
70static void ipw_rx_queue_replenish(void *);
71
72static int ipw_up(struct ipw_priv *);
73static void ipw_down(struct ipw_priv *);
74static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040075static int init_supported_rates(struct ipw_priv *priv,
76 struct ipw_supported_rates *prates);
James Ketrenos43f66a62005-03-25 12:31:53 -060077
78static u8 band_b_active_channel[MAX_B_CHANNELS] = {
79 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0
80};
81static u8 band_a_active_channel[MAX_A_CHANNELS] = {
82 36, 40, 44, 48, 149, 153, 157, 161, 165, 52, 56, 60, 64, 0
83};
84
85static int is_valid_channel(int mode_mask, int channel)
86{
87 int i;
88
89 if (!channel)
90 return 0;
91
92 if (mode_mask & IEEE_A)
93 for (i = 0; i < MAX_A_CHANNELS; i++)
94 if (band_a_active_channel[i] == channel)
95 return IEEE_A;
96
97 if (mode_mask & (IEEE_B | IEEE_G))
98 for (i = 0; i < MAX_B_CHANNELS; i++)
99 if (band_b_active_channel[i] == channel)
100 return mode_mask & (IEEE_B | IEEE_G);
101
102 return 0;
103}
104
Jeff Garzikbf794512005-07-31 13:07:26 -0400105static char *snprint_line(char *buf, size_t count,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400106 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600107{
108 int out, i, j, l;
109 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400110
James Ketrenos43f66a62005-03-25 12:31:53 -0600111 out = snprintf(buf, count, "%08X", ofs);
112
113 for (l = 0, i = 0; i < 2; i++) {
114 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400115 for (j = 0; j < 8 && l < len; j++, l++)
116 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600117 data[(i * 8 + j)]);
118 for (; j < 8; j++)
119 out += snprintf(buf + out, count - out, " ");
120 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400121
James Ketrenos43f66a62005-03-25 12:31:53 -0600122 out += snprintf(buf + out, count - out, " ");
123 for (l = 0, i = 0; i < 2; i++) {
124 out += snprintf(buf + out, count - out, " ");
125 for (j = 0; j < 8 && l < len; j++, l++) {
126 c = data[(i * 8 + j)];
127 if (!isascii(c) || !isprint(c))
128 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400129
James Ketrenos43f66a62005-03-25 12:31:53 -0600130 out += snprintf(buf + out, count - out, "%c", c);
131 }
132
133 for (; j < 8; j++)
134 out += snprintf(buf + out, count - out, " ");
135 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400136
James Ketrenos43f66a62005-03-25 12:31:53 -0600137 return buf;
138}
139
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400140static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600141{
142 char line[81];
143 u32 ofs = 0;
144 if (!(ipw_debug_level & level))
145 return;
146
147 while (len) {
148 printk(KERN_DEBUG "%s\n",
Jeff Garzikbf794512005-07-31 13:07:26 -0400149 snprint_line(line, sizeof(line), &data[ofs],
James Ketrenos43f66a62005-03-25 12:31:53 -0600150 min(len, 16U), ofs));
151 ofs += 16;
152 len -= min(len, 16U);
153 }
154}
155
156static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
157#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
158
159static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
160#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
161
162static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
163static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
164{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400165 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
166 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600167 _ipw_write_reg8(a, b, c);
168}
169
170static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
171static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
172{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400173 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
174 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600175 _ipw_write_reg16(a, b, c);
176}
177
178static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
179static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
180{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400181 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
182 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600183 _ipw_write_reg32(a, b, c);
184}
185
186#define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
187#define ipw_write8(ipw, ofs, val) \
188 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
189 _ipw_write8(ipw, ofs, val)
190
191#define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
192#define ipw_write16(ipw, ofs, val) \
193 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
194 _ipw_write16(ipw, ofs, val)
195
196#define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
197#define ipw_write32(ipw, ofs, val) \
198 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
199 _ipw_write32(ipw, ofs, val)
200
201#define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400202static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
203{
204 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600205 return _ipw_read8(ipw, ofs);
206}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400207
James Ketrenos43f66a62005-03-25 12:31:53 -0600208#define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
209
210#define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400211static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
212{
213 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600214 return _ipw_read16(ipw, ofs);
215}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400216
James Ketrenos43f66a62005-03-25 12:31:53 -0600217#define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
218
219#define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400220static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
221{
222 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600223 return _ipw_read32(ipw, ofs);
224}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400225
James Ketrenos43f66a62005-03-25 12:31:53 -0600226#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
227
228static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
229#define ipw_read_indirect(a, b, c, d) \
230 IPW_DEBUG_IO("%s %d: read_inddirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
231 _ipw_read_indirect(a, b, c, d)
232
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400233static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
234 int num);
James Ketrenos43f66a62005-03-25 12:31:53 -0600235#define ipw_write_indirect(a, b, c, d) \
236 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
237 _ipw_write_indirect(a, b, c, d)
238
239/* indirect write s */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400240static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600241{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400242 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600243 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg);
244 _ipw_write32(priv, CX2_INDIRECT_DATA, value);
245}
246
James Ketrenos43f66a62005-03-25 12:31:53 -0600247static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
248{
249 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
250 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK);
251 _ipw_write8(priv, CX2_INDIRECT_DATA, value);
Jeff Garzikbf794512005-07-31 13:07:26 -0400252 IPW_DEBUG_IO(" reg = 0x%8lX : value = 0x%8X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400253 (unsigned long)(priv->hw_base + CX2_INDIRECT_DATA), value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600254}
255
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400256static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600257{
258 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
259 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK);
260 _ipw_write16(priv, CX2_INDIRECT_DATA, value);
261}
262
263/* indirect read s */
264
265static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
266{
267 u32 word;
268 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg & CX2_INDIRECT_ADDR_MASK);
269 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
270 word = _ipw_read32(priv, CX2_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400271 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600272}
273
274static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
275{
276 u32 value;
277
278 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
279
280 _ipw_write32(priv, CX2_INDIRECT_ADDR, reg);
281 value = _ipw_read32(priv, CX2_INDIRECT_DATA);
282 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
283 return value;
284}
285
286/* iterative/auto-increment 32 bit reads and writes */
287static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
288 int num)
289{
290 u32 aligned_addr = addr & CX2_INDIRECT_ADDR_MASK;
291 u32 dif_len = addr - aligned_addr;
292 u32 aligned_len;
293 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400294
James Ketrenos43f66a62005-03-25 12:31:53 -0600295 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
296
297 /* Read the first nibble byte by byte */
298 if (unlikely(dif_len)) {
299 /* Start reading at aligned_addr + dif_len */
300 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
301 for (i = dif_len; i < 4; i++, buf++)
302 *buf = _ipw_read8(priv, CX2_INDIRECT_DATA + i);
303 num -= dif_len;
304 aligned_addr += 4;
305 }
306
307 /* Read DWs through autoinc register */
308 _ipw_write32(priv, CX2_AUTOINC_ADDR, aligned_addr);
309 aligned_len = num & CX2_INDIRECT_ADDR_MASK;
310 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400311 *(u32 *) buf = ipw_read32(priv, CX2_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400312
James Ketrenos43f66a62005-03-25 12:31:53 -0600313 /* Copy the last nibble */
314 dif_len = num - aligned_len;
315 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
316 for (i = 0; i < dif_len; i++, buf++)
317 *buf = ipw_read8(priv, CX2_INDIRECT_DATA + i);
318}
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;
325 u32 aligned_len;
326 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400327
James Ketrenos43f66a62005-03-25 12:31:53 -0600328 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400329
James Ketrenos43f66a62005-03-25 12:31:53 -0600330 /* Write the first nibble byte by byte */
331 if (unlikely(dif_len)) {
332 /* Start writing at aligned_addr + dif_len */
333 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
334 for (i = dif_len; i < 4; i++, buf++)
335 _ipw_write8(priv, CX2_INDIRECT_DATA + i, *buf);
336 num -= dif_len;
337 aligned_addr += 4;
338 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400339
James Ketrenos43f66a62005-03-25 12:31:53 -0600340 /* Write DWs through autoinc register */
341 _ipw_write32(priv, CX2_AUTOINC_ADDR, aligned_addr);
342 aligned_len = num & CX2_INDIRECT_ADDR_MASK;
343 for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 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 */
347 dif_len = num - aligned_len;
348 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
349 for (i = 0; i < dif_len; i++, buf++)
350 _ipw_write8(priv, CX2_INDIRECT_DATA + i, *buf);
351}
352
Jeff Garzikbf794512005-07-31 13:07:26 -0400353static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600354 int num)
355{
356 memcpy_toio((priv->hw_base + addr), buf, num);
357}
358
359static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
360{
361 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
362}
363
364static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
365{
366 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
367}
368
369static inline void ipw_enable_interrupts(struct ipw_priv *priv)
370{
371 if (priv->status & STATUS_INT_ENABLED)
372 return;
373 priv->status |= STATUS_INT_ENABLED;
374 ipw_write32(priv, CX2_INTA_MASK_R, CX2_INTA_MASK_ALL);
375}
376
377static inline void ipw_disable_interrupts(struct ipw_priv *priv)
378{
379 if (!(priv->status & STATUS_INT_ENABLED))
380 return;
381 priv->status &= ~STATUS_INT_ENABLED;
382 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL);
383}
384
385static char *ipw_error_desc(u32 val)
386{
387 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400388 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600389 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400390 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600391 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400392 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600393 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400394 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600395 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400396 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenos43f66a62005-03-25 12:31:53 -0600397 return "ERROR_BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400398 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenos43f66a62005-03-25 12:31:53 -0600399 return "ERROR_BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400400 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenos43f66a62005-03-25 12:31:53 -0600401 return "ERROR_NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400402 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenos43f66a62005-03-25 12:31:53 -0600403 return "ERROR_BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400404 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600405 return "ERROR_ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400406 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenos43f66a62005-03-25 12:31:53 -0600407 return "ERROR_DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400408 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenos43f66a62005-03-25 12:31:53 -0600409 return "ERROR_DMA_STATUS";
Jeff Garzikbf794512005-07-31 13:07:26 -0400410 case IPW_FW_ERROR_DINOSTATUS_ERROR:
James Ketrenos43f66a62005-03-25 12:31:53 -0600411 return "ERROR_DINOSTATUS_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400412 case IPW_FW_ERROR_EEPROMSTATUS_ERROR:
James Ketrenos43f66a62005-03-25 12:31:53 -0600413 return "ERROR_EEPROMSTATUS_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400414 case IPW_FW_ERROR_SYSASSERT:
James Ketrenos43f66a62005-03-25 12:31:53 -0600415 return "ERROR_SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400416 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenos43f66a62005-03-25 12:31:53 -0600417 return "ERROR_FATALSTATUS_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400418 default:
James Ketrenos43f66a62005-03-25 12:31:53 -0600419 return "UNKNOWNSTATUS_ERROR";
420 }
421}
422
423static void ipw_dump_nic_error_log(struct ipw_priv *priv)
424{
425 u32 desc, time, blink1, blink2, ilink1, ilink2, idata, i, count, base;
426
427 base = ipw_read32(priv, IPWSTATUS_ERROR_LOG);
428 count = ipw_read_reg32(priv, base);
Jeff Garzikbf794512005-07-31 13:07:26 -0400429
James Ketrenos43f66a62005-03-25 12:31:53 -0600430 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
431 IPW_ERROR("Start IPW Error Log Dump:\n");
432 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
433 priv->status, priv->config);
434 }
435
Jeff Garzikbf794512005-07-31 13:07:26 -0400436 for (i = ERROR_START_OFFSET;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400437 i <= count * ERROR_ELEM_SIZE; i += ERROR_ELEM_SIZE) {
438 desc = ipw_read_reg32(priv, base + i);
439 time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
440 blink1 = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
441 blink2 = ipw_read_reg32(priv, base + i + 3 * sizeof(u32));
442 ilink1 = ipw_read_reg32(priv, base + i + 4 * sizeof(u32));
443 ilink2 = ipw_read_reg32(priv, base + i + 5 * sizeof(u32));
444 idata = ipw_read_reg32(priv, base + i + 6 * sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600445
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400446 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
447 ipw_error_desc(desc), time, blink1, blink2,
448 ilink1, ilink2, idata);
James Ketrenos43f66a62005-03-25 12:31:53 -0600449 }
450}
451
452static void ipw_dump_nic_event_log(struct ipw_priv *priv)
453{
454 u32 ev, time, data, i, count, base;
455
456 base = ipw_read32(priv, IPW_EVENT_LOG);
457 count = ipw_read_reg32(priv, base);
Jeff Garzikbf794512005-07-31 13:07:26 -0400458
James Ketrenos43f66a62005-03-25 12:31:53 -0600459 if (EVENT_START_OFFSET <= count * EVENT_ELEM_SIZE)
460 IPW_ERROR("Start IPW Event Log Dump:\n");
461
Jeff Garzikbf794512005-07-31 13:07:26 -0400462 for (i = EVENT_START_OFFSET;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400463 i <= count * EVENT_ELEM_SIZE; i += EVENT_ELEM_SIZE) {
James Ketrenos43f66a62005-03-25 12:31:53 -0600464 ev = ipw_read_reg32(priv, base + i);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400465 time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
466 data = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600467
468#ifdef CONFIG_IPW_DEBUG
469 IPW_ERROR("%i\t0x%08x\t%i\n", time, data, ev);
470#endif
471 }
472}
473
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400474static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600475{
476 u32 addr, field_info, field_len, field_count, total_len;
477
478 IPW_DEBUG_ORD("ordinal = %i\n", ord);
479
480 if (!priv || !val || !len) {
481 IPW_DEBUG_ORD("Invalid argument\n");
482 return -EINVAL;
483 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400484
James Ketrenos43f66a62005-03-25 12:31:53 -0600485 /* verify device ordinal tables have been initialized */
486 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
487 IPW_DEBUG_ORD("Access ordinals before initialization\n");
488 return -EINVAL;
489 }
490
491 switch (IPW_ORD_TABLE_ID_MASK & ord) {
492 case IPW_ORD_TABLE_0_MASK:
493 /*
494 * TABLE 0: Direct access to a table of 32 bit values
495 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400496 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600497 * read from the table
498 */
499
500 /* remove the table id from the ordinal */
501 ord &= IPW_ORD_TABLE_VALUE_MASK;
502
503 /* boundary check */
504 if (ord > priv->table0_len) {
505 IPW_DEBUG_ORD("ordinal value (%i) longer then "
506 "max (%i)\n", ord, priv->table0_len);
507 return -EINVAL;
508 }
509
510 /* verify we have enough room to store the value */
511 if (*len < sizeof(u32)) {
512 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200513 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600514 return -EINVAL;
515 }
516
517 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400518 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600519
520 *len = sizeof(u32);
521 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400522 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600523 break;
524
525 case IPW_ORD_TABLE_1_MASK:
526 /*
527 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400528 *
529 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600530 * representing starting addr for the data (which is
531 * also a u32)
532 */
533
534 /* remove the table id from the ordinal */
535 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400536
James Ketrenos43f66a62005-03-25 12:31:53 -0600537 /* boundary check */
538 if (ord > priv->table1_len) {
539 IPW_DEBUG_ORD("ordinal value too long\n");
540 return -EINVAL;
541 }
542
543 /* verify we have enough room to store the value */
544 if (*len < sizeof(u32)) {
545 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200546 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600547 return -EINVAL;
548 }
549
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400550 *((u32 *) val) =
551 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600552 *len = sizeof(u32);
553 break;
554
555 case IPW_ORD_TABLE_2_MASK:
556 /*
557 * TABLE 2: Indirect access to a table of variable sized values
558 *
559 * This table consist of six values, each containing
560 * - dword containing the starting offset of the data
561 * - dword containing the lengh in the first 16bits
562 * and the count in the second 16bits
563 */
564
565 /* remove the table id from the ordinal */
566 ord &= IPW_ORD_TABLE_VALUE_MASK;
567
568 /* boundary check */
569 if (ord > priv->table2_len) {
570 IPW_DEBUG_ORD("ordinal value too long\n");
571 return -EINVAL;
572 }
573
574 /* get the address of statistic */
575 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400576
577 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600578 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400579 field_info =
580 ipw_read_reg32(priv,
581 priv->table2_addr + (ord << 3) +
582 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400583
James Ketrenos43f66a62005-03-25 12:31:53 -0600584 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400585 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400586
James Ketrenos43f66a62005-03-25 12:31:53 -0600587 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400588 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400589
James Ketrenos43f66a62005-03-25 12:31:53 -0600590 /* abort if not enought memory */
591 total_len = field_len * field_count;
592 if (total_len > *len) {
593 *len = total_len;
594 return -EINVAL;
595 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400596
James Ketrenos43f66a62005-03-25 12:31:53 -0600597 *len = total_len;
598 if (!total_len)
599 return 0;
600
601 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400602 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600603 addr, total_len, field_info);
604 ipw_read_indirect(priv, addr, val, total_len);
605 break;
606
607 default:
608 IPW_DEBUG_ORD("Invalid ordinal!\n");
609 return -EINVAL;
610
611 }
612
James Ketrenos43f66a62005-03-25 12:31:53 -0600613 return 0;
614}
615
616static void ipw_init_ordinals(struct ipw_priv *priv)
617{
618 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400619 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600620
621 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
622 priv->table0_addr, priv->table0_len);
623
624 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
625 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
626
627 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
628 priv->table1_addr, priv->table1_len);
629
630 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
631 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400632 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600633
634 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
635 priv->table2_addr, priv->table2_len);
636
637}
638
639/*
640 * The following adds a new attribute to the sysfs representation
641 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
642 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -0400643 *
James Ketrenos43f66a62005-03-25 12:31:53 -0600644 * See the level definitions in ipw for details.
645 */
646static ssize_t show_debug_level(struct device_driver *d, char *buf)
647{
648 return sprintf(buf, "0x%08X\n", ipw_debug_level);
649}
Andrew Mortonad3fee52005-06-20 14:30:36 -0700650static ssize_t store_debug_level(struct device_driver *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400651 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600652{
653 char *p = (char *)buf;
654 u32 val;
655
656 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
657 p++;
658 if (p[0] == 'x' || p[0] == 'X')
659 p++;
660 val = simple_strtoul(p, &p, 16);
661 } else
662 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -0400663 if (p == buf)
664 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -0600665 ": %s is not in hex or decimal form.\n", buf);
666 else
667 ipw_debug_level = val;
668
669 return strnlen(buf, count);
670}
671
Jeff Garzikbf794512005-07-31 13:07:26 -0400672static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -0600673 show_debug_level, store_debug_level);
674
Andrew Mortonad3fee52005-06-20 14:30:36 -0700675static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400676 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600677{
Andrew Mortonad3fee52005-06-20 14:30:36 -0700678 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600679 return sprintf(buf, "0x%08x\n", (int)p->status);
680}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400681
James Ketrenos43f66a62005-03-25 12:31:53 -0600682static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
683
Andrew Mortonad3fee52005-06-20 14:30:36 -0700684static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
685 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600686{
Andrew Mortonad3fee52005-06-20 14:30:36 -0700687 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600688 return sprintf(buf, "0x%08x\n", (int)p->config);
689}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400690
James Ketrenos43f66a62005-03-25 12:31:53 -0600691static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
692
Andrew Mortonad3fee52005-06-20 14:30:36 -0700693static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400694 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600695{
Andrew Mortonad3fee52005-06-20 14:30:36 -0700696 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600697 u8 type = p->eeprom[EEPROM_NIC_TYPE];
698
699 switch (type) {
700 case EEPROM_NIC_TYPE_STANDARD:
701 return sprintf(buf, "STANDARD\n");
702 case EEPROM_NIC_TYPE_DELL:
703 return sprintf(buf, "DELL\n");
704 case EEPROM_NIC_TYPE_FUJITSU:
705 return sprintf(buf, "FUJITSU\n");
706 case EEPROM_NIC_TYPE_IBM:
707 return sprintf(buf, "IBM\n");
708 case EEPROM_NIC_TYPE_HP:
709 return sprintf(buf, "HP\n");
710 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400711
James Ketrenos43f66a62005-03-25 12:31:53 -0600712 return sprintf(buf, "UNKNOWN\n");
713}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400714
James Ketrenos43f66a62005-03-25 12:31:53 -0600715static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
716
Andrew Mortonad3fee52005-06-20 14:30:36 -0700717static ssize_t dump_error_log(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400718 struct device_attribute *attr, const char *buf,
719 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600720{
721 char *p = (char *)buf;
722
Jeff Garzikbf794512005-07-31 13:07:26 -0400723 if (p[0] == '1')
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400724 ipw_dump_nic_error_log((struct ipw_priv *)d->driver_data);
James Ketrenos43f66a62005-03-25 12:31:53 -0600725
726 return strnlen(buf, count);
727}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400728
James Ketrenos43f66a62005-03-25 12:31:53 -0600729static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
730
Andrew Mortonad3fee52005-06-20 14:30:36 -0700731static ssize_t dump_event_log(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400732 struct device_attribute *attr, const char *buf,
733 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600734{
735 char *p = (char *)buf;
736
Jeff Garzikbf794512005-07-31 13:07:26 -0400737 if (p[0] == '1')
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400738 ipw_dump_nic_event_log((struct ipw_priv *)d->driver_data);
James Ketrenos43f66a62005-03-25 12:31:53 -0600739
740 return strnlen(buf, count);
741}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400742
James Ketrenos43f66a62005-03-25 12:31:53 -0600743static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
744
Andrew Mortonad3fee52005-06-20 14:30:36 -0700745static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400746 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600747{
748 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700749 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600750
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400751 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -0600752 return 0;
753
754 return sprintf(buf, "0x%08x\n", tmp);
755}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400756
757static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600758
Andrew Mortonad3fee52005-06-20 14:30:36 -0700759static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
760 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600761{
762 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700763 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600764
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400765 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -0600766 return 0;
767
768 return sprintf(buf, "0x%08x\n", tmp);
769}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400770
771static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600772
773/*
774 * Add a device attribute to view/control the delay between eeprom
775 * operations.
776 */
Andrew Mortonad3fee52005-06-20 14:30:36 -0700777static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400778 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600779{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400780 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -0600781 return sprintf(buf, "%i\n", n);
782}
Andrew Mortonad3fee52005-06-20 14:30:36 -0700783static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400784 struct device_attribute *attr,
785 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600786{
Andrew Mortonad3fee52005-06-20 14:30:36 -0700787 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600788 sscanf(buf, "%i", &p->eeprom_delay);
789 return strnlen(buf, count);
790}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400791
792static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
793 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -0600794
Andrew Mortonad3fee52005-06-20 14:30:36 -0700795static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400796 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600797{
798 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700799 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600800
801 reg = ipw_read_reg32(p, CX2_INTERNAL_CMD_EVENT);
802 return sprintf(buf, "0x%08x\n", reg);
803}
Andrew Mortonad3fee52005-06-20 14:30:36 -0700804static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400805 struct device_attribute *attr,
806 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600807{
808 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700809 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600810
811 sscanf(buf, "%x", &reg);
812 ipw_write_reg32(p, CX2_INTERNAL_CMD_EVENT, reg);
813 return strnlen(buf, count);
814}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400815
816static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
817 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -0600818
Andrew Mortonad3fee52005-06-20 14:30:36 -0700819static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400820 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600821{
822 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700823 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600824
825 reg = ipw_read_reg32(p, 0x301100);
826 return sprintf(buf, "0x%08x\n", reg);
827}
Andrew Mortonad3fee52005-06-20 14:30:36 -0700828static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400829 struct device_attribute *attr,
830 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600831{
832 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700833 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600834
835 sscanf(buf, "%x", &reg);
836 ipw_write_reg32(p, 0x301100, reg);
837 return strnlen(buf, count);
838}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400839
840static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
841 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -0600842
Andrew Mortonad3fee52005-06-20 14:30:36 -0700843static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400844 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600845{
846 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700847 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -0400848 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -0600849 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -0400850 else
James Ketrenos43f66a62005-03-25 12:31:53 -0600851 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -0400852
James Ketrenos43f66a62005-03-25 12:31:53 -0600853 return sprintf(buf, "0x%08x\n", reg);
854}
Andrew Mortonad3fee52005-06-20 14:30:36 -0700855static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400856 struct device_attribute *attr,
857 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600858{
Andrew Mortonad3fee52005-06-20 14:30:36 -0700859 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600860
861 sscanf(buf, "%x", &priv->indirect_dword);
862 priv->status |= STATUS_INDIRECT_DWORD;
863 return strnlen(buf, count);
864}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400865
866static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
867 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -0600868
Andrew Mortonad3fee52005-06-20 14:30:36 -0700869static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400870 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600871{
872 u8 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700873 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -0400874 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -0600875 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -0400876 else
James Ketrenos43f66a62005-03-25 12:31:53 -0600877 reg = 0;
878
879 return sprintf(buf, "0x%02x\n", reg);
880}
Andrew Mortonad3fee52005-06-20 14:30:36 -0700881static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400882 struct device_attribute *attr,
883 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600884{
Andrew Mortonad3fee52005-06-20 14:30:36 -0700885 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600886
887 sscanf(buf, "%x", &priv->indirect_byte);
888 priv->status |= STATUS_INDIRECT_BYTE;
889 return strnlen(buf, count);
890}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400891
892static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -0600893 show_indirect_byte, store_indirect_byte);
894
Andrew Mortonad3fee52005-06-20 14:30:36 -0700895static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400896 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600897{
898 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -0700899 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600900
Jeff Garzikbf794512005-07-31 13:07:26 -0400901 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -0600902 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -0400903 else
James Ketrenos43f66a62005-03-25 12:31:53 -0600904 reg = 0;
905
906 return sprintf(buf, "0x%08x\n", reg);
907}
Andrew Mortonad3fee52005-06-20 14:30:36 -0700908static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400909 struct device_attribute *attr,
910 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600911{
Andrew Mortonad3fee52005-06-20 14:30:36 -0700912 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600913
914 sscanf(buf, "%x", &priv->direct_dword);
915 priv->status |= STATUS_DIRECT_DWORD;
916 return strnlen(buf, count);
917}
James Ketrenos43f66a62005-03-25 12:31:53 -0600918
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400919static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
920 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -0600921
922static inline int rf_kill_active(struct ipw_priv *priv)
923{
924 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
925 priv->status |= STATUS_RF_KILL_HW;
926 else
927 priv->status &= ~STATUS_RF_KILL_HW;
928
929 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
930}
931
Andrew Mortonad3fee52005-06-20 14:30:36 -0700932static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400933 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -0600934{
935 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -0400936 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600937 2 - HW based RF kill active
938 3 - Both HW and SW baed RF kill active */
Andrew Mortonad3fee52005-06-20 14:30:36 -0700939 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -0600940 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400941 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -0600942 return sprintf(buf, "%i\n", val);
943}
944
945static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
946{
Jeff Garzikbf794512005-07-31 13:07:26 -0400947 if ((disable_radio ? 1 : 0) ==
James Ketrenos43f66a62005-03-25 12:31:53 -0600948 (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400949 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600950
951 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
952 disable_radio ? "OFF" : "ON");
953
954 if (disable_radio) {
955 priv->status |= STATUS_RF_KILL_SW;
956
Jeff Garzikbf794512005-07-31 13:07:26 -0400957 if (priv->workqueue) {
James Ketrenos43f66a62005-03-25 12:31:53 -0600958 cancel_delayed_work(&priv->request_scan);
959 }
960 wake_up_interruptible(&priv->wait_command_queue);
961 queue_work(priv->workqueue, &priv->down);
962 } else {
963 priv->status &= ~STATUS_RF_KILL_SW;
964 if (rf_kill_active(priv)) {
965 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
966 "disabled by HW switch\n");
967 /* Make sure the RF_KILL check timer is running */
968 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -0400969 queue_delayed_work(priv->workqueue, &priv->rf_kill,
James Ketrenos43f66a62005-03-25 12:31:53 -0600970 2 * HZ);
Jeff Garzikbf794512005-07-31 13:07:26 -0400971 } else
James Ketrenos43f66a62005-03-25 12:31:53 -0600972 queue_work(priv->workqueue, &priv->up);
973 }
974
975 return 1;
976}
977
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400978static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
979 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600980{
Andrew Mortonad3fee52005-06-20 14:30:36 -0700981 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -0400982
James Ketrenos43f66a62005-03-25 12:31:53 -0600983 ipw_radio_kill_sw(priv, buf[0] == '1');
984
985 return count;
986}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400987
988static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -0600989
990static void ipw_irq_tasklet(struct ipw_priv *priv)
991{
992 u32 inta, inta_mask, handled = 0;
993 unsigned long flags;
994 int rc = 0;
995
996 spin_lock_irqsave(&priv->lock, flags);
997
998 inta = ipw_read32(priv, CX2_INTA_RW);
999 inta_mask = ipw_read32(priv, CX2_INTA_MASK_R);
1000 inta &= (CX2_INTA_MASK_ALL & inta_mask);
1001
1002 /* Add any cached INTA values that need to be handled */
1003 inta |= priv->isr_inta;
1004
1005 /* handle all the justifications for the interrupt */
1006 if (inta & CX2_INTA_BIT_RX_TRANSFER) {
1007 ipw_rx(priv);
1008 handled |= CX2_INTA_BIT_RX_TRANSFER;
1009 }
1010
1011 if (inta & CX2_INTA_BIT_TX_CMD_QUEUE) {
1012 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001013 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001014 priv->status &= ~STATUS_HCMD_ACTIVE;
1015 wake_up_interruptible(&priv->wait_command_queue);
1016 handled |= CX2_INTA_BIT_TX_CMD_QUEUE;
1017 }
1018
1019 if (inta & CX2_INTA_BIT_TX_QUEUE_1) {
1020 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001021 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001022 handled |= CX2_INTA_BIT_TX_QUEUE_1;
1023 }
1024
1025 if (inta & CX2_INTA_BIT_TX_QUEUE_2) {
1026 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001027 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001028 handled |= CX2_INTA_BIT_TX_QUEUE_2;
1029 }
1030
1031 if (inta & CX2_INTA_BIT_TX_QUEUE_3) {
1032 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001033 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenos43f66a62005-03-25 12:31:53 -06001034 handled |= CX2_INTA_BIT_TX_QUEUE_3;
1035 }
1036
1037 if (inta & CX2_INTA_BIT_TX_QUEUE_4) {
1038 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001039 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06001040 handled |= CX2_INTA_BIT_TX_QUEUE_4;
1041 }
1042
1043 if (inta & CX2_INTA_BIT_STATUS_CHANGE) {
1044 IPW_WARNING("STATUS_CHANGE\n");
1045 handled |= CX2_INTA_BIT_STATUS_CHANGE;
1046 }
1047
1048 if (inta & CX2_INTA_BIT_BEACON_PERIOD_EXPIRED) {
1049 IPW_WARNING("TX_PERIOD_EXPIRED\n");
1050 handled |= CX2_INTA_BIT_BEACON_PERIOD_EXPIRED;
1051 }
1052
1053 if (inta & CX2_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
1054 IPW_WARNING("HOST_CMD_DONE\n");
1055 handled |= CX2_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
1056 }
1057
1058 if (inta & CX2_INTA_BIT_FW_INITIALIZATION_DONE) {
1059 IPW_WARNING("FW_INITIALIZATION_DONE\n");
1060 handled |= CX2_INTA_BIT_FW_INITIALIZATION_DONE;
1061 }
1062
1063 if (inta & CX2_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
1064 IPW_WARNING("PHY_OFF_DONE\n");
1065 handled |= CX2_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
1066 }
1067
1068 if (inta & CX2_INTA_BIT_RF_KILL_DONE) {
1069 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1070 priv->status |= STATUS_RF_KILL_HW;
1071 wake_up_interruptible(&priv->wait_command_queue);
1072 netif_carrier_off(priv->net_dev);
1073 netif_stop_queue(priv->net_dev);
1074 cancel_delayed_work(&priv->request_scan);
1075 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
1076 handled |= CX2_INTA_BIT_RF_KILL_DONE;
1077 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001078
James Ketrenos43f66a62005-03-25 12:31:53 -06001079 if (inta & CX2_INTA_BIT_FATAL_ERROR) {
1080 IPW_ERROR("Firmware error detected. Restarting.\n");
1081#ifdef CONFIG_IPW_DEBUG
1082 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1083 ipw_dump_nic_error_log(priv);
1084 ipw_dump_nic_event_log(priv);
1085 }
1086#endif
1087 queue_work(priv->workqueue, &priv->adapter_restart);
1088 handled |= CX2_INTA_BIT_FATAL_ERROR;
1089 }
1090
1091 if (inta & CX2_INTA_BIT_PARITY_ERROR) {
1092 IPW_ERROR("Parity error\n");
1093 handled |= CX2_INTA_BIT_PARITY_ERROR;
1094 }
1095
1096 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001097 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06001098 }
1099
1100 /* enable all interrupts */
1101 ipw_enable_interrupts(priv);
1102
1103 spin_unlock_irqrestore(&priv->lock, flags);
1104}
Jeff Garzikbf794512005-07-31 13:07:26 -04001105
James Ketrenos43f66a62005-03-25 12:31:53 -06001106#ifdef CONFIG_IPW_DEBUG
1107#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1108static char *get_cmd_string(u8 cmd)
1109{
1110 switch (cmd) {
1111 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04001112 IPW_CMD(POWER_DOWN);
1113 IPW_CMD(SYSTEM_CONFIG);
1114 IPW_CMD(MULTICAST_ADDRESS);
1115 IPW_CMD(SSID);
1116 IPW_CMD(ADAPTER_ADDRESS);
1117 IPW_CMD(PORT_TYPE);
1118 IPW_CMD(RTS_THRESHOLD);
1119 IPW_CMD(FRAG_THRESHOLD);
1120 IPW_CMD(POWER_MODE);
1121 IPW_CMD(WEP_KEY);
1122 IPW_CMD(TGI_TX_KEY);
1123 IPW_CMD(SCAN_REQUEST);
1124 IPW_CMD(SCAN_REQUEST_EXT);
1125 IPW_CMD(ASSOCIATE);
1126 IPW_CMD(SUPPORTED_RATES);
1127 IPW_CMD(SCAN_ABORT);
1128 IPW_CMD(TX_FLUSH);
1129 IPW_CMD(QOS_PARAMETERS);
1130 IPW_CMD(DINO_CONFIG);
1131 IPW_CMD(RSN_CAPABILITIES);
1132 IPW_CMD(RX_KEY);
1133 IPW_CMD(CARD_DISABLE);
1134 IPW_CMD(SEED_NUMBER);
1135 IPW_CMD(TX_POWER);
1136 IPW_CMD(COUNTRY_INFO);
1137 IPW_CMD(AIRONET_INFO);
1138 IPW_CMD(AP_TX_POWER);
1139 IPW_CMD(CCKM_INFO);
1140 IPW_CMD(CCX_VER_INFO);
1141 IPW_CMD(SET_CALIBRATION);
1142 IPW_CMD(SENSITIVITY_CALIB);
1143 IPW_CMD(RETRY_LIMIT);
1144 IPW_CMD(IPW_PRE_POWER_DOWN);
1145 IPW_CMD(VAP_BEACON_TEMPLATE);
1146 IPW_CMD(VAP_DTIM_PERIOD);
1147 IPW_CMD(EXT_SUPPORTED_RATES);
1148 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
1149 IPW_CMD(VAP_QUIET_INTERVALS);
1150 IPW_CMD(VAP_CHANNEL_SWITCH);
1151 IPW_CMD(VAP_MANDATORY_CHANNELS);
1152 IPW_CMD(VAP_CELL_PWR_LIMIT);
1153 IPW_CMD(VAP_CF_PARAM_SET);
1154 IPW_CMD(VAP_SET_BEACONING_STATE);
1155 IPW_CMD(MEASUREMENT);
1156 IPW_CMD(POWER_CAPABILITY);
1157 IPW_CMD(SUPPORTED_CHANNELS);
1158 IPW_CMD(TPC_REPORT);
1159 IPW_CMD(WME_INFO);
1160 IPW_CMD(PRODUCTION_COMMAND);
1161 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06001162 return "UNKNOWN";
1163 }
1164}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001165#endif /* CONFIG_IPW_DEBUG */
James Ketrenos43f66a62005-03-25 12:31:53 -06001166
1167#define HOST_COMPLETE_TIMEOUT HZ
1168static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
1169{
1170 int rc = 0;
1171
1172 if (priv->status & STATUS_HCMD_ACTIVE) {
1173 IPW_ERROR("Already sending a command\n");
1174 return -1;
1175 }
1176
1177 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04001178
1179 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06001180 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001181 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
James Ketrenos43f66a62005-03-25 12:31:53 -06001182
1183 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0);
1184 if (rc)
1185 return rc;
1186
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001187 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1188 !(priv->
1189 status & STATUS_HCMD_ACTIVE),
1190 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001191 if (rc == 0) {
1192 IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
Jeff Garzik9bd481f2005-06-28 01:46:35 -04001193 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
James Ketrenos43f66a62005-03-25 12:31:53 -06001194 priv->status &= ~STATUS_HCMD_ACTIVE;
1195 return -EIO;
1196 }
1197 if (priv->status & STATUS_RF_KILL_MASK) {
1198 IPW_DEBUG_INFO("Command aborted due to RF Kill Switch\n");
1199 return -EIO;
1200 }
1201
1202 return 0;
1203}
1204
1205static int ipw_send_host_complete(struct ipw_priv *priv)
1206{
1207 struct host_cmd cmd = {
1208 .cmd = IPW_CMD_HOST_COMPLETE,
1209 .len = 0
1210 };
1211
1212 if (!priv) {
1213 IPW_ERROR("Invalid args\n");
1214 return -1;
1215 }
1216
1217 if (ipw_send_cmd(priv, &cmd)) {
1218 IPW_ERROR("failed to send HOST_COMPLETE command\n");
1219 return -1;
1220 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001221
James Ketrenos43f66a62005-03-25 12:31:53 -06001222 return 0;
1223}
1224
Jeff Garzikbf794512005-07-31 13:07:26 -04001225static int ipw_send_system_config(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06001226 struct ipw_sys_config *config)
1227{
1228 struct host_cmd cmd = {
1229 .cmd = IPW_CMD_SYSTEM_CONFIG,
1230 .len = sizeof(*config)
1231 };
1232
1233 if (!priv || !config) {
1234 IPW_ERROR("Invalid args\n");
1235 return -1;
1236 }
1237
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001238 memcpy(&cmd.param, config, sizeof(*config));
James Ketrenos43f66a62005-03-25 12:31:53 -06001239 if (ipw_send_cmd(priv, &cmd)) {
1240 IPW_ERROR("failed to send SYSTEM_CONFIG command\n");
1241 return -1;
1242 }
1243
1244 return 0;
1245}
1246
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001247static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06001248{
1249 struct host_cmd cmd = {
1250 .cmd = IPW_CMD_SSID,
1251 .len = min(len, IW_ESSID_MAX_SIZE)
1252 };
1253
1254 if (!priv || !ssid) {
1255 IPW_ERROR("Invalid args\n");
1256 return -1;
1257 }
1258
1259 memcpy(&cmd.param, ssid, cmd.len);
1260 if (ipw_send_cmd(priv, &cmd)) {
1261 IPW_ERROR("failed to send SSID command\n");
1262 return -1;
1263 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001264
James Ketrenos43f66a62005-03-25 12:31:53 -06001265 return 0;
1266}
1267
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001268static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06001269{
1270 struct host_cmd cmd = {
1271 .cmd = IPW_CMD_ADAPTER_ADDRESS,
1272 .len = ETH_ALEN
1273 };
1274
1275 if (!priv || !mac) {
1276 IPW_ERROR("Invalid args\n");
1277 return -1;
1278 }
1279
1280 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
1281 priv->net_dev->name, MAC_ARG(mac));
1282
1283 memcpy(&cmd.param, mac, ETH_ALEN);
1284
1285 if (ipw_send_cmd(priv, &cmd)) {
1286 IPW_ERROR("failed to send ADAPTER_ADDRESS command\n");
1287 return -1;
1288 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001289
James Ketrenos43f66a62005-03-25 12:31:53 -06001290 return 0;
1291}
1292
1293static void ipw_adapter_restart(void *adapter)
1294{
1295 struct ipw_priv *priv = adapter;
1296
1297 if (priv->status & STATUS_RF_KILL_MASK)
1298 return;
1299
1300 ipw_down(priv);
1301 if (ipw_up(priv)) {
1302 IPW_ERROR("Failed to up device\n");
1303 return;
1304 }
1305}
1306
James Ketrenos43f66a62005-03-25 12:31:53 -06001307#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
1308
1309static void ipw_scan_check(void *data)
1310{
1311 struct ipw_priv *priv = data;
1312 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
1313 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Jeff Garzikbf794512005-07-31 13:07:26 -04001314 "adapter (%dms).\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06001315 IPW_SCAN_CHECK_WATCHDOG / 100);
1316 ipw_adapter_restart(priv);
1317 }
1318}
1319
1320static int ipw_send_scan_request_ext(struct ipw_priv *priv,
1321 struct ipw_scan_request_ext *request)
1322{
1323 struct host_cmd cmd = {
1324 .cmd = IPW_CMD_SCAN_REQUEST_EXT,
1325 .len = sizeof(*request)
1326 };
1327
1328 if (!priv || !request) {
1329 IPW_ERROR("Invalid args\n");
1330 return -1;
1331 }
1332
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001333 memcpy(&cmd.param, request, sizeof(*request));
James Ketrenos43f66a62005-03-25 12:31:53 -06001334 if (ipw_send_cmd(priv, &cmd)) {
1335 IPW_ERROR("failed to send SCAN_REQUEST_EXT command\n");
1336 return -1;
1337 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001338
1339 queue_delayed_work(priv->workqueue, &priv->scan_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06001340 IPW_SCAN_CHECK_WATCHDOG);
1341 return 0;
1342}
1343
1344static int ipw_send_scan_abort(struct ipw_priv *priv)
1345{
1346 struct host_cmd cmd = {
1347 .cmd = IPW_CMD_SCAN_ABORT,
1348 .len = 0
1349 };
1350
1351 if (!priv) {
1352 IPW_ERROR("Invalid args\n");
1353 return -1;
1354 }
1355
1356 if (ipw_send_cmd(priv, &cmd)) {
1357 IPW_ERROR("failed to send SCAN_ABORT command\n");
1358 return -1;
1359 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001360
James Ketrenos43f66a62005-03-25 12:31:53 -06001361 return 0;
1362}
1363
1364static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
1365{
1366 struct host_cmd cmd = {
1367 .cmd = IPW_CMD_SENSITIVITY_CALIB,
1368 .len = sizeof(struct ipw_sensitivity_calib)
1369 };
1370 struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001371 &cmd.param;
James Ketrenos43f66a62005-03-25 12:31:53 -06001372 calib->beacon_rssi_raw = sens;
1373 if (ipw_send_cmd(priv, &cmd)) {
1374 IPW_ERROR("failed to send SENSITIVITY CALIB command\n");
1375 return -1;
1376 }
1377
1378 return 0;
1379}
1380
1381static int ipw_send_associate(struct ipw_priv *priv,
1382 struct ipw_associate *associate)
1383{
1384 struct host_cmd cmd = {
1385 .cmd = IPW_CMD_ASSOCIATE,
1386 .len = sizeof(*associate)
1387 };
1388
1389 if (!priv || !associate) {
1390 IPW_ERROR("Invalid args\n");
1391 return -1;
1392 }
1393
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001394 memcpy(&cmd.param, associate, sizeof(*associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06001395 if (ipw_send_cmd(priv, &cmd)) {
1396 IPW_ERROR("failed to send ASSOCIATE command\n");
1397 return -1;
1398 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001399
James Ketrenos43f66a62005-03-25 12:31:53 -06001400 return 0;
1401}
1402
1403static int ipw_send_supported_rates(struct ipw_priv *priv,
1404 struct ipw_supported_rates *rates)
1405{
1406 struct host_cmd cmd = {
1407 .cmd = IPW_CMD_SUPPORTED_RATES,
1408 .len = sizeof(*rates)
1409 };
1410
1411 if (!priv || !rates) {
1412 IPW_ERROR("Invalid args\n");
1413 return -1;
1414 }
1415
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001416 memcpy(&cmd.param, rates, sizeof(*rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06001417 if (ipw_send_cmd(priv, &cmd)) {
1418 IPW_ERROR("failed to send SUPPORTED_RATES command\n");
1419 return -1;
1420 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001421
James Ketrenos43f66a62005-03-25 12:31:53 -06001422 return 0;
1423}
1424
1425static int ipw_set_random_seed(struct ipw_priv *priv)
1426{
1427 struct host_cmd cmd = {
1428 .cmd = IPW_CMD_SEED_NUMBER,
1429 .len = sizeof(u32)
1430 };
1431
1432 if (!priv) {
1433 IPW_ERROR("Invalid args\n");
1434 return -1;
1435 }
1436
1437 get_random_bytes(&cmd.param, sizeof(u32));
1438
1439 if (ipw_send_cmd(priv, &cmd)) {
1440 IPW_ERROR("failed to send SEED_NUMBER command\n");
1441 return -1;
1442 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001443
James Ketrenos43f66a62005-03-25 12:31:53 -06001444 return 0;
1445}
1446
1447#if 0
1448static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
1449{
1450 struct host_cmd cmd = {
1451 .cmd = IPW_CMD_CARD_DISABLE,
1452 .len = sizeof(u32)
1453 };
1454
1455 if (!priv) {
1456 IPW_ERROR("Invalid args\n");
1457 return -1;
1458 }
1459
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001460 *((u32 *) & cmd.param) = phy_off;
James Ketrenos43f66a62005-03-25 12:31:53 -06001461
1462 if (ipw_send_cmd(priv, &cmd)) {
1463 IPW_ERROR("failed to send CARD_DISABLE command\n");
1464 return -1;
1465 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001466
James Ketrenos43f66a62005-03-25 12:31:53 -06001467 return 0;
1468}
1469#endif
1470
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001471static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06001472{
1473 struct host_cmd cmd = {
1474 .cmd = IPW_CMD_TX_POWER,
1475 .len = sizeof(*power)
1476 };
1477
1478 if (!priv || !power) {
1479 IPW_ERROR("Invalid args\n");
1480 return -1;
1481 }
1482
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001483 memcpy(&cmd.param, power, sizeof(*power));
James Ketrenos43f66a62005-03-25 12:31:53 -06001484 if (ipw_send_cmd(priv, &cmd)) {
1485 IPW_ERROR("failed to send TX_POWER command\n");
1486 return -1;
1487 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001488
James Ketrenos43f66a62005-03-25 12:31:53 -06001489 return 0;
1490}
1491
1492static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
1493{
1494 struct ipw_rts_threshold rts_threshold = {
1495 .rts_threshold = rts,
1496 };
1497 struct host_cmd cmd = {
1498 .cmd = IPW_CMD_RTS_THRESHOLD,
1499 .len = sizeof(rts_threshold)
1500 };
1501
1502 if (!priv) {
1503 IPW_ERROR("Invalid args\n");
1504 return -1;
1505 }
1506
1507 memcpy(&cmd.param, &rts_threshold, sizeof(rts_threshold));
1508 if (ipw_send_cmd(priv, &cmd)) {
1509 IPW_ERROR("failed to send RTS_THRESHOLD command\n");
1510 return -1;
1511 }
1512
1513 return 0;
1514}
1515
1516static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
1517{
1518 struct ipw_frag_threshold frag_threshold = {
1519 .frag_threshold = frag,
1520 };
1521 struct host_cmd cmd = {
1522 .cmd = IPW_CMD_FRAG_THRESHOLD,
1523 .len = sizeof(frag_threshold)
1524 };
1525
1526 if (!priv) {
1527 IPW_ERROR("Invalid args\n");
1528 return -1;
1529 }
1530
1531 memcpy(&cmd.param, &frag_threshold, sizeof(frag_threshold));
1532 if (ipw_send_cmd(priv, &cmd)) {
1533 IPW_ERROR("failed to send FRAG_THRESHOLD command\n");
1534 return -1;
1535 }
1536
1537 return 0;
1538}
1539
1540static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
1541{
1542 struct host_cmd cmd = {
1543 .cmd = IPW_CMD_POWER_MODE,
1544 .len = sizeof(u32)
1545 };
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001546 u32 *param = (u32 *) (&cmd.param);
James Ketrenos43f66a62005-03-25 12:31:53 -06001547
1548 if (!priv) {
1549 IPW_ERROR("Invalid args\n");
1550 return -1;
1551 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001552
James Ketrenos43f66a62005-03-25 12:31:53 -06001553 /* If on battery, set to 3, if AC set to CAM, else user
1554 * level */
1555 switch (mode) {
1556 case IPW_POWER_BATTERY:
1557 *param = IPW_POWER_INDEX_3;
1558 break;
1559 case IPW_POWER_AC:
1560 *param = IPW_POWER_MODE_CAM;
1561 break;
1562 default:
1563 *param = mode;
1564 break;
1565 }
1566
1567 if (ipw_send_cmd(priv, &cmd)) {
1568 IPW_ERROR("failed to send POWER_MODE command\n");
1569 return -1;
1570 }
1571
1572 return 0;
1573}
1574
1575/*
1576 * The IPW device contains a Microwire compatible EEPROM that stores
1577 * various data like the MAC address. Usually the firmware has exclusive
1578 * access to the eeprom, but during device initialization (before the
1579 * device driver has sent the HostComplete command to the firmware) the
1580 * device driver has read access to the EEPROM by way of indirect addressing
1581 * through a couple of memory mapped registers.
1582 *
1583 * The following is a simplified implementation for pulling data out of the
1584 * the eeprom, along with some helper functions to find information in
1585 * the per device private data's copy of the eeprom.
1586 *
1587 * NOTE: To better understand how these functions work (i.e what is a chip
1588 * select and why do have to keep driving the eeprom clock?), read
1589 * just about any data sheet for a Microwire compatible EEPROM.
1590 */
1591
1592/* write a 32 bit value into the indirect accessor register */
1593static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
1594{
1595 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04001596
James Ketrenos43f66a62005-03-25 12:31:53 -06001597 /* the eeprom requires some time to complete the operation */
1598 udelay(p->eeprom_delay);
1599
1600 return;
1601}
1602
1603/* perform a chip select operation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001604static inline void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001605{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001606 eeprom_write_reg(priv, 0);
1607 eeprom_write_reg(priv, EEPROM_BIT_CS);
1608 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
1609 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06001610}
1611
1612/* perform a chip select operation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001613static inline void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001614{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001615 eeprom_write_reg(priv, EEPROM_BIT_CS);
1616 eeprom_write_reg(priv, 0);
1617 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06001618}
1619
1620/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001621static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06001622{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001623 int d = (bit ? EEPROM_BIT_DI : 0);
1624 eeprom_write_reg(p, EEPROM_BIT_CS | d);
1625 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06001626}
1627
1628/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001629static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06001630{
1631 int i;
1632
1633 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001634 eeprom_write_bit(priv, 1);
1635 eeprom_write_bit(priv, op & 2);
1636 eeprom_write_bit(priv, op & 1);
1637 for (i = 7; i >= 0; i--) {
1638 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06001639 }
1640}
1641
1642/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001643static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06001644{
1645 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001646 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001647
James Ketrenos43f66a62005-03-25 12:31:53 -06001648 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001649 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06001650
1651 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001652 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06001653
1654 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001655 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001656 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001657 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
1658 eeprom_write_reg(priv, EEPROM_BIT_CS);
1659 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
1660 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001661 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001662
James Ketrenos43f66a62005-03-25 12:31:53 -06001663 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001664 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001665 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04001666
James Ketrenos43f66a62005-03-25 12:31:53 -06001667 return r;
1668}
1669
1670/* helper function for pulling the mac address out of the private */
1671/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001672static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06001673{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001674 u8 *ee = (u8 *) priv->eeprom;
James Ketrenos43f66a62005-03-25 12:31:53 -06001675 memcpy(mac, &ee[EEPROM_MAC_ADDRESS], 6);
1676}
1677
1678/*
1679 * Either the device driver (i.e. the host) or the firmware can
1680 * load eeprom data into the designated region in SRAM. If neither
1681 * happens then the FW will shutdown with a fatal error.
1682 *
1683 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
1684 * bit needs region of shared SRAM needs to be non-zero.
1685 */
1686static void ipw_eeprom_init_sram(struct ipw_priv *priv)
1687{
1688 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001689 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04001690
James Ketrenos43f66a62005-03-25 12:31:53 -06001691 IPW_DEBUG_TRACE(">>\n");
1692
1693 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001694 for (i = 0; i < 128; i++)
1695 eeprom[i] = eeprom_read_u16(priv, (u8) i);
James Ketrenos43f66a62005-03-25 12:31:53 -06001696
Jeff Garzikbf794512005-07-31 13:07:26 -04001697 /*
1698 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06001699 copy. Otherwise let the firmware know to perform the operation
1700 on it's own
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001701 */
James Ketrenos43f66a62005-03-25 12:31:53 -06001702 if ((priv->eeprom + EEPROM_VERSION) != 0) {
1703 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
1704
1705 /* write the eeprom data to sram */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001706 for (i = 0; i < CX2_EEPROM_IMAGE_SIZE; i++)
1707 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06001708
1709 /* Do not load eeprom data on fatal error or suspend */
1710 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
1711 } else {
1712 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
1713
1714 /* Load eeprom data on fatal error or suspend */
1715 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
1716 }
1717
1718 IPW_DEBUG_TRACE("<<\n");
1719}
1720
James Ketrenos43f66a62005-03-25 12:31:53 -06001721static inline void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
1722{
1723 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001724 if (!count)
1725 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06001726 _ipw_write32(priv, CX2_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04001727 while (count--)
James Ketrenos43f66a62005-03-25 12:31:53 -06001728 _ipw_write32(priv, CX2_AUTOINC_DATA, 0);
1729}
1730
1731static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
1732{
1733 ipw_zero_memory(priv, CX2_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04001734 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06001735 sizeof(struct command_block));
1736}
1737
1738static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001739{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06001740
1741 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04001742
James Ketrenos43f66a62005-03-25 12:31:53 -06001743 /* Start the dma */
1744 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04001745
James Ketrenos43f66a62005-03-25 12:31:53 -06001746 /* Write CB base address */
1747 ipw_write_reg32(priv, CX2_DMA_I_CB_BASE, CX2_SHARED_SRAM_DMA_CONTROL);
1748
1749 IPW_DEBUG_FW("<< : \n");
1750 return 0;
1751}
1752
1753static void ipw_fw_dma_abort(struct ipw_priv *priv)
1754{
1755 u32 control = 0;
1756
1757 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04001758
1759 //set the Stop and Abort bit
James Ketrenos43f66a62005-03-25 12:31:53 -06001760 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
1761 ipw_write_reg32(priv, CX2_DMA_I_DMA_CONTROL, control);
1762 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001763
James Ketrenos43f66a62005-03-25 12:31:53 -06001764 IPW_DEBUG_FW("<< \n");
1765}
1766
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001767static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
1768 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06001769{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001770 u32 address =
1771 CX2_SHARED_SRAM_DMA_CONTROL +
1772 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06001773 IPW_DEBUG_FW(">> :\n");
1774
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001775 ipw_write_indirect(priv, address, (u8 *) cb,
1776 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06001777
1778 IPW_DEBUG_FW("<< :\n");
1779 return 0;
1780
1781}
1782
1783static int ipw_fw_dma_kick(struct ipw_priv *priv)
1784{
1785 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001786 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001787
1788 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04001789
James Ketrenos43f66a62005-03-25 12:31:53 -06001790 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001791 ipw_fw_dma_write_command_block(priv, index,
1792 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06001793
1794 /* Enable the DMA in the CSR register */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001795 ipw_clear_bit(priv, CX2_RESET_REG,
1796 CX2_RESET_REG_MASTER_DISABLED |
1797 CX2_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04001798
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001799 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06001800 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
1801 ipw_write_reg32(priv, CX2_DMA_I_DMA_CONTROL, control);
1802
1803 IPW_DEBUG_FW("<< :\n");
1804 return 0;
1805}
1806
1807static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
1808{
1809 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001810 u32 register_value = 0;
1811 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001812
1813 IPW_DEBUG_FW(">> :\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001814 address = ipw_read_reg32(priv, CX2_DMA_I_CURRENT_CB);
1815 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06001816
1817 /* Read the DMA Controlor register */
1818 register_value = ipw_read_reg32(priv, CX2_DMA_I_DMA_CONTROL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001819 IPW_DEBUG_FW_INFO("CX2_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06001820
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001821 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06001822 cb_fields_address = address;
1823 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001824 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06001825
1826 cb_fields_address += sizeof(u32);
1827 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001828 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06001829
1830 cb_fields_address += sizeof(u32);
1831 register_value = ipw_read_reg32(priv, cb_fields_address);
1832 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
1833 register_value);
1834
1835 cb_fields_address += sizeof(u32);
1836 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001837 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06001838
1839 IPW_DEBUG_FW(">> :\n");
1840}
1841
1842static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
1843{
1844 u32 current_cb_address = 0;
1845 u32 current_cb_index = 0;
1846
1847 IPW_DEBUG_FW("<< :\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001848 current_cb_address = ipw_read_reg32(priv, CX2_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04001849
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001850 current_cb_index = (current_cb_address - CX2_SHARED_SRAM_DMA_CONTROL) /
1851 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04001852
James Ketrenos43f66a62005-03-25 12:31:53 -06001853 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001854 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06001855
1856 IPW_DEBUG_FW(">> :\n");
1857 return current_cb_index;
1858
1859}
1860
1861static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
1862 u32 src_address,
1863 u32 dest_address,
1864 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001865 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06001866{
1867
Jeff Garzikbf794512005-07-31 13:07:26 -04001868 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001869 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
1870 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06001871 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001872 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001873
1874 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
1875 src_address, dest_address, length);
1876
1877 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
1878 return -1;
1879
1880 last_cb_element = priv->sram_desc.last_cb_index;
1881 cb = &priv->sram_desc.cb_list[last_cb_element];
1882 priv->sram_desc.last_cb_index++;
1883
1884 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001885 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06001886 control |= CB_INT_ENABLED;
1887
1888 if (is_last)
1889 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04001890
James Ketrenos43f66a62005-03-25 12:31:53 -06001891 control |= length;
1892
1893 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001894 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06001895
1896 /* Copy the Source and Destination addresses */
1897 cb->dest_addr = dest_address;
1898 cb->source_addr = src_address;
1899
1900 /* Copy the Control Word last */
1901 cb->control = control;
1902
1903 return 0;
1904}
1905
1906static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001907 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06001908{
1909 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001910 u32 src_offset = 0;
1911 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001912 int status = 0;
1913 IPW_DEBUG_FW(">> \n");
1914 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
1915 src_phys, dest_address, length);
1916 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001917 status = ipw_fw_dma_add_command_block(priv,
1918 src_phys + src_offset,
1919 dest_address +
1920 dest_offset,
1921 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001922 if (status) {
1923 IPW_DEBUG_FW_INFO(": Failed\n");
1924 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04001925 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001926 IPW_DEBUG_FW_INFO(": Added new cb\n");
1927
1928 src_offset += CB_MAX_LENGTH;
1929 dest_offset += CB_MAX_LENGTH;
1930 bytes_left -= CB_MAX_LENGTH;
1931 }
1932
1933 /* add the buffer tail */
1934 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001935 status =
1936 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
1937 dest_address + dest_offset,
1938 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001939 if (status) {
1940 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
1941 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04001942 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001943 IPW_DEBUG_FW_INFO
1944 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06001945 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001946
James Ketrenos43f66a62005-03-25 12:31:53 -06001947 IPW_DEBUG_FW("<< \n");
1948 return 0;
1949}
1950
1951static int ipw_fw_dma_wait(struct ipw_priv *priv)
1952{
1953 u32 current_index = 0;
1954 u32 watchdog = 0;
1955
1956 IPW_DEBUG_FW(">> : \n");
1957
1958 current_index = ipw_fw_dma_command_block_index(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04001959 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001960 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06001961
1962 while (current_index < priv->sram_desc.last_cb_index) {
1963 udelay(50);
1964 current_index = ipw_fw_dma_command_block_index(priv);
1965
1966 watchdog++;
1967
1968 if (watchdog > 400) {
1969 IPW_DEBUG_FW_INFO("Timeout\n");
1970 ipw_fw_dma_dump_command_block(priv);
1971 ipw_fw_dma_abort(priv);
1972 return -1;
1973 }
1974 }
1975
1976 ipw_fw_dma_abort(priv);
1977
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001978 /*Disable the DMA in the CSR register */
1979 ipw_set_bit(priv, CX2_RESET_REG,
James Ketrenos43f66a62005-03-25 12:31:53 -06001980 CX2_RESET_REG_MASTER_DISABLED | CX2_RESET_REG_STOP_MASTER);
1981
1982 IPW_DEBUG_FW("<< dmaWaitSync \n");
1983 return 0;
1984}
1985
Jeff Garzikbf794512005-07-31 13:07:26 -04001986static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001987{
1988 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04001989 struct ieee80211_network *network = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06001990 list_for_each_safe(element, safe, &priv->ieee->network_list) {
1991 network = list_entry(element, struct ieee80211_network, list);
1992 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
1993 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04001994 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06001995 &priv->ieee->network_free_list);
1996 }
1997 }
1998}
1999
2000/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002001 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002002 * Reads debug register from domain0.
2003 * If card is present, pre-defined value should
2004 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002005 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002006 * @param priv
2007 * @return 1 if card is present, 0 otherwise
2008 */
2009static inline int ipw_alive(struct ipw_priv *priv)
2010{
2011 return ipw_read32(priv, 0x90) == 0xd55555d5;
2012}
2013
2014static inline int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2015 int timeout)
2016{
2017 int i = 0;
2018
2019 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002020 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002021 return i;
2022 mdelay(10);
2023 i += 10;
2024 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002025
James Ketrenos43f66a62005-03-25 12:31:53 -06002026 return -ETIME;
2027}
2028
Jeff Garzikbf794512005-07-31 13:07:26 -04002029/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002030 * the ipw hardware. It assumes the buffer has all the bits for the
2031 * image and the caller is handling the memory allocation and clean up.
2032 */
2033
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002034static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002035{
2036 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002037
James Ketrenos43f66a62005-03-25 12:31:53 -06002038 IPW_DEBUG_TRACE(">> \n");
2039 /* stop master. typical delay - 0 */
2040 ipw_set_bit(priv, CX2_RESET_REG, CX2_RESET_REG_STOP_MASTER);
2041
2042 rc = ipw_poll_bit(priv, CX2_RESET_REG,
2043 CX2_RESET_REG_MASTER_DISABLED, 100);
2044 if (rc < 0) {
2045 IPW_ERROR("stop master failed in 10ms\n");
2046 return -1;
2047 }
2048
2049 IPW_DEBUG_INFO("stop master %dms\n", rc);
2050
2051 return rc;
2052}
2053
2054static void ipw_arc_release(struct ipw_priv *priv)
2055{
2056 IPW_DEBUG_TRACE(">> \n");
2057 mdelay(5);
2058
2059 ipw_clear_bit(priv, CX2_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
2060
2061 /* no one knows timing, for safety add some delay */
2062 mdelay(5);
2063}
2064
2065struct fw_header {
2066 u32 version;
2067 u32 mode;
2068};
2069
2070struct fw_chunk {
2071 u32 address;
2072 u32 length;
2073};
2074
2075#define IPW_FW_MAJOR_VERSION 2
2076#define IPW_FW_MINOR_VERSION 2
2077
2078#define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
2079#define IPW_FW_MAJOR(x) (x & 0xff)
2080
2081#define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | \
2082 IPW_FW_MAJOR_VERSION)
2083
2084#define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
2085"." __stringify(IPW_FW_MINOR_VERSION) "-"
2086
2087#if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
2088#define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
2089#else
2090#define IPW_FW_NAME(x) "ipw2200_" x ".fw"
2091#endif
2092
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002093static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002094{
2095 int rc = 0, i, addr;
2096 u8 cr = 0;
2097 u16 *image;
2098
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002099 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002100
James Ketrenos43f66a62005-03-25 12:31:53 -06002101 IPW_DEBUG_TRACE(">> \n");
2102
2103 rc = ipw_stop_master(priv);
2104
2105 if (rc < 0)
2106 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002107
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002108// spin_lock_irqsave(&priv->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04002109
James Ketrenos43f66a62005-03-25 12:31:53 -06002110 for (addr = CX2_SHARED_LOWER_BOUND;
2111 addr < CX2_REGISTER_DOMAIN1_END; addr += 4) {
2112 ipw_write32(priv, addr, 0);
2113 }
2114
2115 /* no ucode (yet) */
2116 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2117 /* destroy DMA queues */
2118 /* reset sequence */
2119
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002120 ipw_write_reg32(priv, CX2_MEM_HALT_AND_RESET, CX2_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06002121 ipw_arc_release(priv);
2122 ipw_write_reg32(priv, CX2_MEM_HALT_AND_RESET, CX2_BIT_HALT_RESET_OFF);
2123 mdelay(1);
2124
2125 /* reset PHY */
2126 ipw_write_reg32(priv, CX2_INTERNAL_CMD_EVENT, CX2_BASEBAND_POWER_DOWN);
2127 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002128
James Ketrenos43f66a62005-03-25 12:31:53 -06002129 ipw_write_reg32(priv, CX2_INTERNAL_CMD_EVENT, 0);
2130 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002131
James Ketrenos43f66a62005-03-25 12:31:53 -06002132 /* enable ucode store */
2133 ipw_write_reg8(priv, DINO_CONTROL_REG, 0x0);
2134 ipw_write_reg8(priv, DINO_CONTROL_REG, DINO_ENABLE_CS);
2135 mdelay(1);
2136
2137 /* write ucode */
2138 /**
2139 * @bug
2140 * Do NOT set indirect address register once and then
2141 * store data to indirect data register in the loop.
2142 * It seems very reasonable, but in this case DINO do not
2143 * accept ucode. It is essential to set address each time.
2144 */
2145 /* load new ipw uCode */
2146 for (i = 0; i < len / 2; i++)
2147 ipw_write_reg16(priv, CX2_BASEBAND_CONTROL_STORE, image[i]);
2148
James Ketrenos43f66a62005-03-25 12:31:53 -06002149 /* enable DINO */
2150 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 0);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002151 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002152
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002153 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002154
2155 /* wait for alive response */
2156 for (i = 0; i < 100; i++) {
2157 /* poll for incoming data */
2158 cr = ipw_read_reg8(priv, CX2_BASEBAND_CONTROL_STATUS);
2159 if (cr & DINO_RXFIFO_DATA)
2160 break;
2161 mdelay(1);
2162 }
2163
2164 if (cr & DINO_RXFIFO_DATA) {
2165 /* alive_command_responce size is NOT multiple of 4 */
2166 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04002167
2168 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06002169 response_buffer[i] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002170 ipw_read_reg32(priv, CX2_BASEBAND_RX_FIFO_READ);
James Ketrenos43f66a62005-03-25 12:31:53 -06002171 memcpy(&priv->dino_alive, response_buffer,
2172 sizeof(priv->dino_alive));
2173 if (priv->dino_alive.alive_command == 1
2174 && priv->dino_alive.ucode_valid == 1) {
2175 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002176 IPW_DEBUG_INFO
2177 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2178 "of %02d/%02d/%02d %02d:%02d\n",
2179 priv->dino_alive.software_revision,
2180 priv->dino_alive.software_revision,
2181 priv->dino_alive.device_identifier,
2182 priv->dino_alive.device_identifier,
2183 priv->dino_alive.time_stamp[0],
2184 priv->dino_alive.time_stamp[1],
2185 priv->dino_alive.time_stamp[2],
2186 priv->dino_alive.time_stamp[3],
2187 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002188 } else {
2189 IPW_DEBUG_INFO("Microcode is not alive\n");
2190 rc = -EINVAL;
2191 }
2192 } else {
2193 IPW_DEBUG_INFO("No alive response from DINO\n");
2194 rc = -ETIME;
2195 }
2196
2197 /* disable DINO, otherwise for some reason
2198 firmware have problem getting alive resp. */
2199 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 0);
2200
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002201// spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002202
2203 return rc;
2204}
2205
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002206static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002207{
2208 int rc = -1;
2209 int offset = 0;
2210 struct fw_chunk *chunk;
2211 dma_addr_t shared_phys;
2212 u8 *shared_virt;
2213
2214 IPW_DEBUG_TRACE("<< : \n");
2215 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
2216
2217 if (!shared_virt)
2218 return -ENOMEM;
2219
2220 memmove(shared_virt, data, len);
2221
2222 /* Start the Dma */
2223 rc = ipw_fw_dma_enable(priv);
2224
2225 if (priv->sram_desc.last_cb_index > 0) {
2226 /* the DMA is already ready this would be a bug. */
2227 BUG();
2228 goto out;
2229 }
2230
2231 do {
2232 chunk = (struct fw_chunk *)(data + offset);
2233 offset += sizeof(struct fw_chunk);
2234 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04002235 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06002236 * offeset*/
2237 /* Dma loading */
2238 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
2239 chunk->address, chunk->length);
2240 if (rc) {
2241 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
2242 goto out;
2243 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002244
James Ketrenos43f66a62005-03-25 12:31:53 -06002245 offset += chunk->length;
2246 } while (offset < len);
2247
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002248 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06002249 rc = ipw_fw_dma_kick(priv);
2250 if (rc) {
2251 IPW_ERROR("dmaKick Failed\n");
2252 goto out;
2253 }
2254
2255 rc = ipw_fw_dma_wait(priv);
2256 if (rc) {
2257 IPW_ERROR("dmaWaitSync Failed\n");
2258 goto out;
2259 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002260 out:
2261 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06002262 return rc;
2263}
2264
2265/* stop nic */
2266static int ipw_stop_nic(struct ipw_priv *priv)
2267{
2268 int rc = 0;
2269
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002270 /* stop */
James Ketrenos43f66a62005-03-25 12:31:53 -06002271 ipw_write32(priv, CX2_RESET_REG, CX2_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002272
2273 rc = ipw_poll_bit(priv, CX2_RESET_REG,
2274 CX2_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06002275 if (rc < 0) {
2276 IPW_ERROR("wait for reg master disabled failed\n");
2277 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002278 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002279
2280 ipw_set_bit(priv, CX2_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04002281
James Ketrenos43f66a62005-03-25 12:31:53 -06002282 return rc;
2283}
2284
2285static void ipw_start_nic(struct ipw_priv *priv)
2286{
2287 IPW_DEBUG_TRACE(">>\n");
2288
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002289 /* prvHwStartNic release ARC */
James Ketrenos43f66a62005-03-25 12:31:53 -06002290 ipw_clear_bit(priv, CX2_RESET_REG,
Jeff Garzikbf794512005-07-31 13:07:26 -04002291 CX2_RESET_REG_MASTER_DISABLED |
2292 CX2_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06002293 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04002294
James Ketrenos43f66a62005-03-25 12:31:53 -06002295 /* enable power management */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002296 ipw_set_bit(priv, CX2_GP_CNTRL_RW,
2297 CX2_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06002298
2299 IPW_DEBUG_TRACE("<<\n");
2300}
Jeff Garzikbf794512005-07-31 13:07:26 -04002301
James Ketrenos43f66a62005-03-25 12:31:53 -06002302static int ipw_init_nic(struct ipw_priv *priv)
2303{
2304 int rc;
2305
2306 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002307 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06002308 /*prvHwInitNic */
2309 /* set "initialization complete" bit to move adapter to D0 state */
2310 ipw_set_bit(priv, CX2_GP_CNTRL_RW, CX2_GP_CNTRL_BIT_INIT_DONE);
2311
2312 /* low-level PLL activation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002313 ipw_write32(priv, CX2_READ_INT_REGISTER,
2314 CX2_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002315
2316 /* wait for clock stabilization */
Jeff Garzikbf794512005-07-31 13:07:26 -04002317 rc = ipw_poll_bit(priv, CX2_GP_CNTRL_RW,
2318 CX2_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002319 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06002320 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
2321
2322 /* assert SW reset */
2323 ipw_set_bit(priv, CX2_RESET_REG, CX2_RESET_REG_SW_RESET);
2324
2325 udelay(10);
2326
2327 /* set "initialization complete" bit to move adapter to D0 state */
2328 ipw_set_bit(priv, CX2_GP_CNTRL_RW, CX2_GP_CNTRL_BIT_INIT_DONE);
2329
2330 IPW_DEBUG_TRACE(">>\n");
2331 return 0;
2332}
2333
Jeff Garzikbf794512005-07-31 13:07:26 -04002334/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06002335 * Probe is an ok place to call this from.
2336 */
2337static int ipw_reset_nic(struct ipw_priv *priv)
2338{
2339 int rc = 0;
2340
2341 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002342
James Ketrenos43f66a62005-03-25 12:31:53 -06002343 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002344
James Ketrenos43f66a62005-03-25 12:31:53 -06002345 /* Clear the 'host command active' bit... */
2346 priv->status &= ~STATUS_HCMD_ACTIVE;
2347 wake_up_interruptible(&priv->wait_command_queue);
2348
2349 IPW_DEBUG_TRACE("<<\n");
2350 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002351}
James Ketrenos43f66a62005-03-25 12:31:53 -06002352
Jeff Garzikbf794512005-07-31 13:07:26 -04002353static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06002354 const struct firmware **fw, const char *name)
2355{
2356 struct fw_header *header;
2357 int rc;
2358
2359 /* ask firmware_class module to get the boot firmware off disk */
2360 rc = request_firmware(fw, name, &priv->pci_dev->dev);
2361 if (rc < 0) {
2362 IPW_ERROR("%s load failed: Reason %d\n", name, rc);
2363 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002364 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002365
2366 header = (struct fw_header *)(*fw)->data;
2367 if (IPW_FW_MAJOR(header->version) != IPW_FW_MAJOR_VERSION) {
2368 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
2369 name,
2370 IPW_FW_MAJOR(header->version), IPW_FW_MAJOR_VERSION);
2371 return -EINVAL;
2372 }
2373
Jiri Bencaaa4d302005-06-07 14:58:41 +02002374 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06002375 name,
2376 IPW_FW_MAJOR(header->version),
2377 IPW_FW_MINOR(header->version),
2378 (*fw)->size - sizeof(struct fw_header));
2379 return 0;
2380}
2381
2382#define CX2_RX_BUF_SIZE (3000)
2383
2384static inline void ipw_rx_queue_reset(struct ipw_priv *priv,
2385 struct ipw_rx_queue *rxq)
2386{
2387 unsigned long flags;
2388 int i;
2389
2390 spin_lock_irqsave(&rxq->lock, flags);
2391
2392 INIT_LIST_HEAD(&rxq->rx_free);
2393 INIT_LIST_HEAD(&rxq->rx_used);
2394
2395 /* Fill the rx_used queue with _all_ of the Rx buffers */
2396 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
2397 /* In the reset function, these buffers may have been allocated
2398 * to an SKB, so we need to unmap and free potential storage */
2399 if (rxq->pool[i].skb != NULL) {
2400 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002401 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002402 dev_kfree_skb(rxq->pool[i].skb);
2403 }
2404 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
2405 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002406
James Ketrenos43f66a62005-03-25 12:31:53 -06002407 /* Set us so that we have processed and used all buffers, but have
2408 * not restocked the Rx queue with fresh buffers */
2409 rxq->read = rxq->write = 0;
2410 rxq->processed = RX_QUEUE_SIZE - 1;
2411 rxq->free_count = 0;
2412 spin_unlock_irqrestore(&rxq->lock, flags);
2413}
2414
2415#ifdef CONFIG_PM
2416static int fw_loaded = 0;
2417static const struct firmware *bootfw = NULL;
2418static const struct firmware *firmware = NULL;
2419static const struct firmware *ucode = NULL;
2420#endif
2421
2422static int ipw_load(struct ipw_priv *priv)
2423{
2424#ifndef CONFIG_PM
2425 const struct firmware *bootfw = NULL;
2426 const struct firmware *firmware = NULL;
2427 const struct firmware *ucode = NULL;
2428#endif
2429 int rc = 0, retries = 3;
2430
2431#ifdef CONFIG_PM
2432 if (!fw_loaded) {
2433#endif
2434 rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot"));
Jeff Garzikbf794512005-07-31 13:07:26 -04002435 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06002436 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04002437
James Ketrenos43f66a62005-03-25 12:31:53 -06002438 switch (priv->ieee->iw_mode) {
2439 case IW_MODE_ADHOC:
Jeff Garzikbf794512005-07-31 13:07:26 -04002440 rc = ipw_get_fw(priv, &ucode,
James Ketrenos43f66a62005-03-25 12:31:53 -06002441 IPW_FW_NAME("ibss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04002442 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06002443 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04002444
James Ketrenos43f66a62005-03-25 12:31:53 -06002445 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss"));
2446 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04002447
James Ketrenos43f66a62005-03-25 12:31:53 -06002448#ifdef CONFIG_IPW_PROMISC
2449 case IW_MODE_MONITOR:
Jeff Garzikbf794512005-07-31 13:07:26 -04002450 rc = ipw_get_fw(priv, &ucode,
James Ketrenos43f66a62005-03-25 12:31:53 -06002451 IPW_FW_NAME("ibss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04002452 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06002453 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04002454
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002455 rc = ipw_get_fw(priv, &firmware,
2456 IPW_FW_NAME("sniffer"));
James Ketrenos43f66a62005-03-25 12:31:53 -06002457 break;
2458#endif
2459 case IW_MODE_INFRA:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002460 rc = ipw_get_fw(priv, &ucode, IPW_FW_NAME("bss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04002461 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06002462 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04002463
James Ketrenos43f66a62005-03-25 12:31:53 -06002464 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("bss"));
2465 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04002466
James Ketrenos43f66a62005-03-25 12:31:53 -06002467 default:
2468 rc = -EINVAL;
2469 }
2470
Jeff Garzikbf794512005-07-31 13:07:26 -04002471 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06002472 goto error;
2473
2474#ifdef CONFIG_PM
2475 fw_loaded = 1;
2476 }
2477#endif
2478
2479 if (!priv->rxq)
2480 priv->rxq = ipw_rx_queue_alloc(priv);
2481 else
2482 ipw_rx_queue_reset(priv, priv->rxq);
2483 if (!priv->rxq) {
2484 IPW_ERROR("Unable to initialize Rx queue\n");
2485 goto error;
2486 }
2487
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002488 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06002489 /* Ensure interrupts are disabled */
2490 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL);
2491 priv->status &= ~STATUS_INT_ENABLED;
2492
2493 /* ack pending interrupts */
2494 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04002495
James Ketrenos43f66a62005-03-25 12:31:53 -06002496 ipw_stop_nic(priv);
2497
2498 rc = ipw_reset_nic(priv);
2499 if (rc) {
2500 IPW_ERROR("Unable to reset NIC\n");
2501 goto error;
2502 }
2503
Jeff Garzikbf794512005-07-31 13:07:26 -04002504 ipw_zero_memory(priv, CX2_NIC_SRAM_LOWER_BOUND,
James Ketrenos43f66a62005-03-25 12:31:53 -06002505 CX2_NIC_SRAM_UPPER_BOUND - CX2_NIC_SRAM_LOWER_BOUND);
2506
2507 /* DMA the initial boot firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04002508 rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06002509 bootfw->size - sizeof(struct fw_header));
2510 if (rc < 0) {
2511 IPW_ERROR("Unable to load boot firmware\n");
2512 goto error;
2513 }
2514
2515 /* kick start the device */
2516 ipw_start_nic(priv);
2517
2518 /* wait for the device to finish it's initial startup sequence */
Jeff Garzikbf794512005-07-31 13:07:26 -04002519 rc = ipw_poll_bit(priv, CX2_INTA_RW,
2520 CX2_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06002521 if (rc < 0) {
2522 IPW_ERROR("device failed to boot initial fw image\n");
2523 goto error;
2524 }
2525 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
2526
Jeff Garzikbf794512005-07-31 13:07:26 -04002527 /* ack fw init done interrupt */
James Ketrenos43f66a62005-03-25 12:31:53 -06002528 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_BIT_FW_INITIALIZATION_DONE);
2529
2530 /* DMA the ucode into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04002531 rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06002532 ucode->size - sizeof(struct fw_header));
2533 if (rc < 0) {
2534 IPW_ERROR("Unable to load ucode\n");
2535 goto error;
2536 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002537
James Ketrenos43f66a62005-03-25 12:31:53 -06002538 /* stop nic */
2539 ipw_stop_nic(priv);
2540
2541 /* DMA bss firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04002542 rc = ipw_load_firmware(priv, firmware->data +
2543 sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06002544 firmware->size - sizeof(struct fw_header));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002545 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002546 IPW_ERROR("Unable to load firmware\n");
2547 goto error;
2548 }
2549
2550 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2551
2552 rc = ipw_queue_reset(priv);
2553 if (rc) {
2554 IPW_ERROR("Unable to initialize queues\n");
2555 goto error;
2556 }
2557
2558 /* Ensure interrupts are disabled */
2559 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04002560
James Ketrenos43f66a62005-03-25 12:31:53 -06002561 /* kick start the device */
2562 ipw_start_nic(priv);
2563
2564 if (ipw_read32(priv, CX2_INTA_RW) & CX2_INTA_BIT_PARITY_ERROR) {
2565 if (retries > 0) {
2566 IPW_WARNING("Parity error. Retrying init.\n");
2567 retries--;
2568 goto retry;
2569 }
2570
2571 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
2572 rc = -EIO;
2573 goto error;
2574 }
2575
2576 /* wait for the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04002577 rc = ipw_poll_bit(priv, CX2_INTA_RW,
2578 CX2_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06002579 if (rc < 0) {
2580 IPW_ERROR("device failed to start after 500ms\n");
2581 goto error;
2582 }
2583 IPW_DEBUG_INFO("device response after %dms\n", rc);
2584
2585 /* ack fw init done interrupt */
2586 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_BIT_FW_INITIALIZATION_DONE);
2587
2588 /* read eeprom data and initialize the eeprom region of sram */
2589 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002590 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06002591
2592 /* enable interrupts */
2593 ipw_enable_interrupts(priv);
2594
2595 /* Ensure our queue has valid packets */
2596 ipw_rx_queue_replenish(priv);
2597
2598 ipw_write32(priv, CX2_RX_READ_INDEX, priv->rxq->read);
2599
2600 /* ack pending interrupts */
2601 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_MASK_ALL);
2602
2603#ifndef CONFIG_PM
2604 release_firmware(bootfw);
2605 release_firmware(ucode);
2606 release_firmware(firmware);
2607#endif
2608 return 0;
2609
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002610 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06002611 if (priv->rxq) {
2612 ipw_rx_queue_free(priv, priv->rxq);
2613 priv->rxq = NULL;
2614 }
2615 ipw_tx_queue_free(priv);
2616 if (bootfw)
2617 release_firmware(bootfw);
2618 if (ucode)
2619 release_firmware(ucode);
2620 if (firmware)
2621 release_firmware(firmware);
2622#ifdef CONFIG_PM
2623 fw_loaded = 0;
2624 bootfw = ucode = firmware = NULL;
2625#endif
2626
2627 return rc;
2628}
2629
Jeff Garzikbf794512005-07-31 13:07:26 -04002630/**
James Ketrenos43f66a62005-03-25 12:31:53 -06002631 * DMA services
2632 *
2633 * Theory of operation
2634 *
2635 * A queue is a circular buffers with 'Read' and 'Write' pointers.
2636 * 2 empty entries always kept in the buffer to protect from overflow.
2637 *
2638 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04002639 * the packet for Tx, free space become < low mark, Tx queue stopped. When
2640 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06002641 * Tx queue resumed.
2642 *
2643 * The IPW operates with six queues, one receive queue in the device's
2644 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04002645 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06002646 *
Jeff Garzikbf794512005-07-31 13:07:26 -04002647 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06002648 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04002649 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06002650 * we only utilize the first data transmit queue (queue1).
2651 */
2652
2653/**
2654 * Driver allocates buffers of this size for Rx
2655 */
2656
2657static inline int ipw_queue_space(const struct clx2_queue *q)
2658{
2659 int s = q->last_used - q->first_empty;
2660 if (s <= 0)
2661 s += q->n_bd;
2662 s -= 2; /* keep some reserve to not confuse empty and full situations */
2663 if (s < 0)
2664 s = 0;
2665 return s;
2666}
2667
2668static inline int ipw_queue_inc_wrap(int index, int n_bd)
2669{
2670 return (++index == n_bd) ? 0 : index;
2671}
2672
2673/**
2674 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04002675 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002676 * @param q queue to init
2677 * @param count Number of BD's to allocate. Should be power of 2
2678 * @param read_register Address for 'read' register
2679 * (not offset within BAR, full address)
2680 * @param write_register Address for 'write' register
2681 * (not offset within BAR, full address)
2682 * @param base_register Address for 'base' register
2683 * (not offset within BAR, full address)
2684 * @param size Address for 'size' register
2685 * (not offset within BAR, full address)
2686 */
Jeff Garzikbf794512005-07-31 13:07:26 -04002687static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002688 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06002689{
2690 q->n_bd = count;
2691
2692 q->low_mark = q->n_bd / 4;
2693 if (q->low_mark < 4)
2694 q->low_mark = 4;
2695
2696 q->high_mark = q->n_bd / 8;
2697 if (q->high_mark < 2)
2698 q->high_mark = 2;
2699
2700 q->first_empty = q->last_used = 0;
2701 q->reg_r = read;
2702 q->reg_w = write;
2703
2704 ipw_write32(priv, base, q->dma_addr);
2705 ipw_write32(priv, size, count);
2706 ipw_write32(priv, read, 0);
2707 ipw_write32(priv, write, 0);
2708
2709 _ipw_read32(priv, 0x90);
2710}
2711
Jeff Garzikbf794512005-07-31 13:07:26 -04002712static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06002713 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002714 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06002715{
2716 struct pci_dev *dev = priv->pci_dev;
2717
2718 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
2719 if (!q->txb) {
2720 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
2721 return -ENOMEM;
2722 }
2723
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002724 q->bd =
2725 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002726 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02002727 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002728 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06002729 kfree(q->txb);
2730 q->txb = NULL;
2731 return -ENOMEM;
2732 }
2733
2734 ipw_queue_init(priv, &q->q, count, read, write, base, size);
2735 return 0;
2736}
2737
2738/**
2739 * Free one TFD, those at index [txq->q.last_used].
2740 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04002741 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002742 * @param dev
2743 * @param txq
2744 */
2745static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
2746 struct clx2_tx_queue *txq)
2747{
2748 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
2749 struct pci_dev *dev = priv->pci_dev;
2750 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04002751
James Ketrenos43f66a62005-03-25 12:31:53 -06002752 /* classify bd */
2753 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
2754 /* nothing to cleanup after for host commands */
2755 return;
2756
2757 /* sanity check */
2758 if (bd->u.data.num_chunks > NUM_TFD_CHUNKS) {
2759 IPW_ERROR("Too many chunks: %i\n", bd->u.data.num_chunks);
2760 /** @todo issue fatal error, it is quite serious situation */
2761 return;
2762 }
2763
2764 /* unmap chunks if any */
2765 for (i = 0; i < bd->u.data.num_chunks; i++) {
2766 pci_unmap_single(dev, bd->u.data.chunk_ptr[i],
2767 bd->u.data.chunk_len[i], PCI_DMA_TODEVICE);
2768 if (txq->txb[txq->q.last_used]) {
2769 ieee80211_txb_free(txq->txb[txq->q.last_used]);
2770 txq->txb[txq->q.last_used] = NULL;
2771 }
2772 }
2773}
2774
2775/**
2776 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04002777 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002778 * Empty queue by removing and destroying all BD's.
2779 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04002780 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002781 * @param dev
2782 * @param q
2783 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002784static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06002785{
2786 struct clx2_queue *q = &txq->q;
2787 struct pci_dev *dev = priv->pci_dev;
2788
Jeff Garzikbf794512005-07-31 13:07:26 -04002789 if (q->n_bd == 0)
2790 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06002791
2792 /* first, empty all BD's */
2793 for (; q->first_empty != q->last_used;
2794 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
2795 ipw_queue_tx_free_tfd(priv, txq);
2796 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002797
James Ketrenos43f66a62005-03-25 12:31:53 -06002798 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002799 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06002800 q->dma_addr);
2801 kfree(txq->txb);
2802
2803 /* 0 fill whole structure */
2804 memset(txq, 0, sizeof(*txq));
2805}
2806
James Ketrenos43f66a62005-03-25 12:31:53 -06002807/**
2808 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04002809 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002810 * @param priv
2811 */
2812static void ipw_tx_queue_free(struct ipw_priv *priv)
2813{
2814 /* Tx CMD queue */
2815 ipw_queue_tx_free(priv, &priv->txq_cmd);
2816
2817 /* Tx queues */
2818 ipw_queue_tx_free(priv, &priv->txq[0]);
2819 ipw_queue_tx_free(priv, &priv->txq[1]);
2820 ipw_queue_tx_free(priv, &priv->txq[2]);
2821 ipw_queue_tx_free(priv, &priv->txq[3]);
2822}
2823
2824static void inline __maybe_wake_tx(struct ipw_priv *priv)
2825{
2826 if (netif_running(priv->net_dev)) {
2827 switch (priv->port_type) {
2828 case DCR_TYPE_MU_BSS:
2829 case DCR_TYPE_MU_IBSS:
2830 if (!(priv->status & STATUS_ASSOCIATED)) {
2831 return;
2832 }
2833 }
2834 netif_wake_queue(priv->net_dev);
2835 }
2836
2837}
2838
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002839static inline void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06002840{
2841 /* First 3 bytes are manufacturer */
2842 bssid[0] = priv->mac_addr[0];
2843 bssid[1] = priv->mac_addr[1];
2844 bssid[2] = priv->mac_addr[2];
2845
2846 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002847 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06002848
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002849 bssid[0] &= 0xfe; /* clear multicast bit */
2850 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06002851}
2852
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002853static inline u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06002854{
2855 struct ipw_station_entry entry;
2856 int i;
2857
2858 for (i = 0; i < priv->num_stations; i++) {
2859 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
2860 /* Another node is active in network */
2861 priv->missed_adhoc_beacons = 0;
2862 if (!(priv->config & CFG_STATIC_CHANNEL))
2863 /* when other nodes drop out, we drop out */
2864 priv->config &= ~CFG_ADHOC_PERSIST;
2865
2866 return i;
2867 }
2868 }
2869
2870 if (i == MAX_STATIONS)
2871 return IPW_INVALID_STATION;
2872
2873 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
2874
2875 entry.reserved = 0;
2876 entry.support_mode = 0;
2877 memcpy(entry.mac_addr, bssid, ETH_ALEN);
2878 memcpy(priv->stations[i], bssid, ETH_ALEN);
2879 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002880 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06002881 priv->num_stations++;
2882
2883 return i;
2884}
2885
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002886static inline u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06002887{
2888 int i;
2889
Jeff Garzikbf794512005-07-31 13:07:26 -04002890 for (i = 0; i < priv->num_stations; i++)
2891 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06002892 return i;
2893
2894 return IPW_INVALID_STATION;
2895}
2896
2897static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
2898{
2899 int err;
2900
2901 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))) {
2902 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
2903 return;
2904 }
2905
2906 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
2907 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04002908 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06002909 priv->assoc_request.channel);
2910
2911 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
2912 priv->status |= STATUS_DISASSOCIATING;
2913
2914 if (quiet)
2915 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
2916 else
2917 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
2918 err = ipw_send_associate(priv, &priv->assoc_request);
2919 if (err) {
2920 IPW_DEBUG_HC("Attempt to send [dis]associate command "
2921 "failed.\n");
2922 return;
2923 }
2924
2925}
2926
2927static void ipw_disassociate(void *data)
2928{
2929 ipw_send_disassociate(data, 0);
2930}
2931
2932static void notify_wx_assoc_event(struct ipw_priv *priv)
2933{
2934 union iwreq_data wrqu;
2935 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
2936 if (priv->status & STATUS_ASSOCIATED)
2937 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
2938 else
2939 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
2940 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
2941}
2942
2943struct ipw_status_code {
2944 u16 status;
2945 const char *reason;
2946};
2947
2948static const struct ipw_status_code ipw_status_codes[] = {
2949 {0x00, "Successful"},
2950 {0x01, "Unspecified failure"},
2951 {0x0A, "Cannot support all requested capabilities in the "
2952 "Capability information field"},
2953 {0x0B, "Reassociation denied due to inability to confirm that "
2954 "association exists"},
2955 {0x0C, "Association denied due to reason outside the scope of this "
2956 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002957 {0x0D,
2958 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06002959 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002960 {0x0E,
2961 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06002962 "transaction sequence number out of expected sequence"},
2963 {0x0F, "Authentication rejected because of challenge failure"},
2964 {0x10, "Authentication rejected due to timeout waiting for next "
2965 "frame in sequence"},
2966 {0x11, "Association denied because AP is unable to handle additional "
2967 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002968 {0x12,
2969 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06002970 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002971 {0x13,
2972 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06002973 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002974 {0x14,
2975 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06002976 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002977 {0x15,
2978 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06002979 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002980 {0x19,
2981 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06002982 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002983 {0x1A,
2984 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06002985 "DSSS-OFDM operation"},
2986 {0x28, "Invalid Information Element"},
2987 {0x29, "Group Cipher is not valid"},
2988 {0x2A, "Pairwise Cipher is not valid"},
2989 {0x2B, "AKMP is not valid"},
2990 {0x2C, "Unsupported RSN IE version"},
2991 {0x2D, "Invalid RSN IE Capabilities"},
2992 {0x2E, "Cipher suite is rejected per security policy"},
2993};
2994
2995#ifdef CONFIG_IPW_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04002996static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06002997{
2998 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04002999 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06003000 if (ipw_status_codes[i].status == status)
3001 return ipw_status_codes[i].reason;
3002 return "Unknown status value.";
3003}
3004#endif
3005
3006static void inline average_init(struct average *avg)
3007{
3008 memset(avg, 0, sizeof(*avg));
3009}
3010
3011static void inline average_add(struct average *avg, s16 val)
3012{
3013 avg->sum -= avg->entries[avg->pos];
3014 avg->sum += val;
3015 avg->entries[avg->pos++] = val;
3016 if (unlikely(avg->pos == AVG_ENTRIES)) {
3017 avg->init = 1;
3018 avg->pos = 0;
3019 }
3020}
3021
3022static s16 inline average_value(struct average *avg)
3023{
3024 if (!unlikely(avg->init)) {
3025 if (avg->pos)
3026 return avg->sum / avg->pos;
3027 return 0;
3028 }
3029
3030 return avg->sum / AVG_ENTRIES;
3031}
3032
3033static void ipw_reset_stats(struct ipw_priv *priv)
3034{
3035 u32 len = sizeof(u32);
3036
3037 priv->quality = 0;
3038
3039 average_init(&priv->average_missed_beacons);
3040 average_init(&priv->average_rssi);
3041 average_init(&priv->average_noise);
3042
3043 priv->last_rate = 0;
3044 priv->last_missed_beacons = 0;
3045 priv->last_rx_packets = 0;
3046 priv->last_tx_packets = 0;
3047 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003048
James Ketrenos43f66a62005-03-25 12:31:53 -06003049 /* Firmware managed, reset only when NIC is restarted, so we have to
3050 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003051 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003052 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003053 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003054 &priv->last_tx_failures, &len);
3055
3056 /* Driver managed, reset with each association */
3057 priv->missed_adhoc_beacons = 0;
3058 priv->missed_beacons = 0;
3059 priv->tx_packets = 0;
3060 priv->rx_packets = 0;
3061
3062}
3063
James Ketrenos43f66a62005-03-25 12:31:53 -06003064static inline u32 ipw_get_max_rate(struct ipw_priv *priv)
3065{
3066 u32 i = 0x80000000;
3067 u32 mask = priv->rates_mask;
3068 /* If currently associated in B mode, restrict the maximum
3069 * rate match to B rates */
3070 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3071 mask &= IEEE80211_CCK_RATES_MASK;
3072
3073 /* TODO: Verify that the rate is supported by the current rates
3074 * list. */
3075
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003076 while (i && !(mask & i))
3077 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003078 switch (i) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003079 case IEEE80211_CCK_RATE_1MB_MASK: return 1000000;
3080 case IEEE80211_CCK_RATE_2MB_MASK: return 2000000;
3081 case IEEE80211_CCK_RATE_5MB_MASK: return 5500000;
3082 case IEEE80211_OFDM_RATE_6MB_MASK: return 6000000;
3083 case IEEE80211_OFDM_RATE_9MB_MASK: return 9000000;
3084 case IEEE80211_CCK_RATE_11MB_MASK: return 11000000;
3085 case IEEE80211_OFDM_RATE_12MB_MASK: return 12000000;
3086 case IEEE80211_OFDM_RATE_18MB_MASK: return 18000000;
3087 case IEEE80211_OFDM_RATE_24MB_MASK: return 24000000;
3088 case IEEE80211_OFDM_RATE_36MB_MASK: return 36000000;
3089 case IEEE80211_OFDM_RATE_48MB_MASK: return 48000000;
3090 case IEEE80211_OFDM_RATE_54MB_MASK: return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003091 }
3092
Jeff Garzikbf794512005-07-31 13:07:26 -04003093 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06003094 return 11000000;
3095 else
3096 return 54000000;
3097}
3098
3099static u32 ipw_get_current_rate(struct ipw_priv *priv)
3100{
3101 u32 rate, len = sizeof(rate);
3102 int err;
3103
Jeff Garzikbf794512005-07-31 13:07:26 -04003104 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003105 return 0;
3106
3107 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04003108 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06003109 &len);
3110 if (err) {
3111 IPW_DEBUG_INFO("failed querying ordinals.\n");
3112 return 0;
3113 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003114 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06003115 return ipw_get_max_rate(priv);
3116
3117 switch (rate) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003118 case IPW_TX_RATE_1MB: return 1000000;
3119 case IPW_TX_RATE_2MB: return 2000000;
3120 case IPW_TX_RATE_5MB: return 5500000;
3121 case IPW_TX_RATE_6MB: return 6000000;
3122 case IPW_TX_RATE_9MB: return 9000000;
3123 case IPW_TX_RATE_11MB: return 11000000;
3124 case IPW_TX_RATE_12MB: return 12000000;
3125 case IPW_TX_RATE_18MB: return 18000000;
3126 case IPW_TX_RATE_24MB: return 24000000;
3127 case IPW_TX_RATE_36MB: return 36000000;
3128 case IPW_TX_RATE_48MB: return 48000000;
3129 case IPW_TX_RATE_54MB: return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003130 }
3131
3132 return 0;
3133}
3134
3135#define PERFECT_RSSI (-50)
3136#define WORST_RSSI (-85)
3137#define IPW_STATS_INTERVAL (2 * HZ)
3138static void ipw_gather_stats(struct ipw_priv *priv)
3139{
3140 u32 rx_err, rx_err_delta, rx_packets_delta;
3141 u32 tx_failures, tx_failures_delta, tx_packets_delta;
3142 u32 missed_beacons_percent, missed_beacons_delta;
3143 u32 quality = 0;
3144 u32 len = sizeof(u32);
3145 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04003146 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003147 rate_quality;
James Ketrenos43f66a62005-03-25 12:31:53 -06003148
3149 if (!(priv->status & STATUS_ASSOCIATED)) {
3150 priv->quality = 0;
3151 return;
3152 }
3153
3154 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04003155 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06003156 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003157 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06003158 priv->last_missed_beacons = priv->missed_beacons;
3159 if (priv->assoc_request.beacon_interval) {
3160 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003161 (HZ * priv->assoc_request.beacon_interval) /
3162 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06003163 } else {
3164 missed_beacons_percent = 0;
3165 }
3166 average_add(&priv->average_missed_beacons, missed_beacons_percent);
3167
3168 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
3169 rx_err_delta = rx_err - priv->last_rx_err;
3170 priv->last_rx_err = rx_err;
3171
3172 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
3173 tx_failures_delta = tx_failures - priv->last_tx_failures;
3174 priv->last_tx_failures = tx_failures;
3175
3176 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
3177 priv->last_rx_packets = priv->rx_packets;
3178
3179 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
3180 priv->last_tx_packets = priv->tx_packets;
3181
3182 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04003183 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003184 * Missed beacon: 100% = 0, 0% = 70% missed
3185 * Rate: 60% = 1Mbs, 100% = Max
3186 * Rx and Tx errors represent a straight % of total Rx/Tx
3187 * RSSI: 100% = > -50, 0% = < -80
3188 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04003189 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003190 * The lowest computed quality is used.
3191 *
3192 */
3193#define BEACON_THRESHOLD 5
3194 beacon_quality = 100 - missed_beacons_percent;
3195 if (beacon_quality < BEACON_THRESHOLD)
3196 beacon_quality = 0;
3197 else
Jeff Garzikbf794512005-07-31 13:07:26 -04003198 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003199 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04003200 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003201 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04003202
James Ketrenos43f66a62005-03-25 12:31:53 -06003203 priv->last_rate = ipw_get_current_rate(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003204 rate_quality = priv->last_rate * 40 / priv->last_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06003205 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
3206 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04003207
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003208 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04003209 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003210 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06003211 else
3212 rx_quality = 100;
3213 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
3214 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04003215
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003216 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04003217 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003218 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06003219 else
3220 tx_quality = 100;
3221 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
3222 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04003223
James Ketrenos43f66a62005-03-25 12:31:53 -06003224 rssi = average_value(&priv->average_rssi);
3225 if (rssi > PERFECT_RSSI)
3226 signal_quality = 100;
3227 else if (rssi < WORST_RSSI)
3228 signal_quality = 0;
3229 else
Jeff Garzikbf794512005-07-31 13:07:26 -04003230 signal_quality = (rssi - WORST_RSSI) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003231 (PERFECT_RSSI - WORST_RSSI);
James Ketrenos43f66a62005-03-25 12:31:53 -06003232 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
3233 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04003234
3235 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06003236 min(rate_quality,
3237 min(tx_quality, min(rx_quality, signal_quality))));
3238 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003239 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
3240 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003241 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003242 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
3243 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003244 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003245 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
3246 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003247 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003248 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
3249 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003250 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003251 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
3252 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003253
3254 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04003255
3256 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06003257 IPW_STATS_INTERVAL);
3258}
3259
3260/**
3261 * Handle host notification packet.
3262 * Called from interrupt routine
3263 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003264static inline void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003265 struct ipw_rx_notification *notif)
3266{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003267 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04003268
James Ketrenos43f66a62005-03-25 12:31:53 -06003269 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003270 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
3271 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003272
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003273 switch (assoc->state) {
3274 case CMAS_ASSOCIATED:{
3275 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3276 IPW_DL_ASSOC,
3277 "associated: '%s' " MAC_FMT
3278 " \n",
3279 escape_essid(priv->essid,
3280 priv->essid_len),
3281 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04003282
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003283 switch (priv->ieee->iw_mode) {
3284 case IW_MODE_INFRA:
3285 memcpy(priv->ieee->bssid,
3286 priv->bssid, ETH_ALEN);
3287 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003288
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003289 case IW_MODE_ADHOC:
3290 memcpy(priv->ieee->bssid,
3291 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04003292
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003293 /* clear out the station table */
3294 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003295
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003296 IPW_DEBUG_ASSOC
3297 ("queueing adhoc check\n");
3298 queue_delayed_work(priv->
3299 workqueue,
3300 &priv->
3301 adhoc_check,
3302 priv->
3303 assoc_request.
3304 beacon_interval);
3305 break;
3306 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003307
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003308 priv->status &= ~STATUS_ASSOCIATING;
3309 priv->status |= STATUS_ASSOCIATED;
James Ketrenos43f66a62005-03-25 12:31:53 -06003310
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003311 netif_carrier_on(priv->net_dev);
3312 if (netif_queue_stopped(priv->net_dev)) {
3313 IPW_DEBUG_NOTIF
3314 ("waking queue\n");
3315 netif_wake_queue(priv->net_dev);
3316 } else {
3317 IPW_DEBUG_NOTIF
3318 ("starting queue\n");
3319 netif_start_queue(priv->
3320 net_dev);
3321 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003322
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003323 ipw_reset_stats(priv);
3324 /* Ensure the rate is updated immediately */
3325 priv->last_rate =
3326 ipw_get_current_rate(priv);
3327 schedule_work(&priv->gather_stats);
3328 notify_wx_assoc_event(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003329
Jeff Garzikbf794512005-07-31 13:07:26 -04003330/* queue_delayed_work(priv->workqueue,
James Ketrenos43f66a62005-03-25 12:31:53 -06003331 &priv->request_scan,
3332 SCAN_ASSOCIATED_INTERVAL);
3333*/
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003334 break;
3335 }
3336
3337 case CMAS_AUTHENTICATED:{
3338 if (priv->
3339 status & (STATUS_ASSOCIATED |
3340 STATUS_AUTH)) {
3341#ifdef CONFIG_IPW_DEBUG
3342 struct notif_authenticate *auth
3343 = &notif->u.auth;
3344 IPW_DEBUG(IPW_DL_NOTIF |
3345 IPW_DL_STATE |
3346 IPW_DL_ASSOC,
3347 "deauthenticated: '%s' "
3348 MAC_FMT
3349 ": (0x%04X) - %s \n",
3350 escape_essid(priv->
3351 essid,
3352 priv->
3353 essid_len),
3354 MAC_ARG(priv->bssid),
3355 ntohs(auth->status),
3356 ipw_get_status_code
3357 (ntohs
3358 (auth->status)));
3359#endif
3360
3361 priv->status &=
3362 ~(STATUS_ASSOCIATING |
3363 STATUS_AUTH |
3364 STATUS_ASSOCIATED);
3365
3366 netif_carrier_off(priv->
3367 net_dev);
3368 netif_stop_queue(priv->net_dev);
3369 queue_work(priv->workqueue,
3370 &priv->request_scan);
3371 notify_wx_assoc_event(priv);
3372 break;
3373 }
3374
3375 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3376 IPW_DL_ASSOC,
3377 "authenticated: '%s' " MAC_FMT
3378 "\n",
3379 escape_essid(priv->essid,
3380 priv->essid_len),
3381 MAC_ARG(priv->bssid));
3382 break;
3383 }
3384
3385 case CMAS_INIT:{
3386 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3387 IPW_DL_ASSOC,
3388 "disassociated: '%s' " MAC_FMT
3389 " \n",
3390 escape_essid(priv->essid,
3391 priv->essid_len),
3392 MAC_ARG(priv->bssid));
3393
3394 priv->status &=
3395 ~(STATUS_DISASSOCIATING |
3396 STATUS_ASSOCIATING |
3397 STATUS_ASSOCIATED | STATUS_AUTH);
3398
3399 netif_stop_queue(priv->net_dev);
3400 if (!(priv->status & STATUS_ROAMING)) {
3401 netif_carrier_off(priv->
3402 net_dev);
3403 notify_wx_assoc_event(priv);
3404
3405 /* Cancel any queued work ... */
3406 cancel_delayed_work(&priv->
3407 request_scan);
3408 cancel_delayed_work(&priv->
3409 adhoc_check);
3410
3411 /* Queue up another scan... */
3412 queue_work(priv->workqueue,
3413 &priv->request_scan);
3414
3415 cancel_delayed_work(&priv->
3416 gather_stats);
3417 } else {
3418 priv->status |= STATUS_ROAMING;
3419 queue_work(priv->workqueue,
3420 &priv->request_scan);
3421 }
3422
3423 ipw_reset_stats(priv);
3424 break;
3425 }
3426
3427 default:
3428 IPW_ERROR("assoc: unknown (%d)\n",
3429 assoc->state);
3430 break;
3431 }
3432
James Ketrenos43f66a62005-03-25 12:31:53 -06003433 break;
3434 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003435
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003436 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
3437 struct notif_authenticate *auth = &notif->u.auth;
3438 switch (auth->state) {
3439 case CMAS_AUTHENTICATED:
3440 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3441 "authenticated: '%s' " MAC_FMT " \n",
3442 escape_essid(priv->essid,
3443 priv->essid_len),
3444 MAC_ARG(priv->bssid));
3445 priv->status |= STATUS_AUTH;
3446 break;
3447
3448 case CMAS_INIT:
3449 if (priv->status & STATUS_AUTH) {
3450 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3451 IPW_DL_ASSOC,
3452 "authentication failed (0x%04X): %s\n",
3453 ntohs(auth->status),
3454 ipw_get_status_code(ntohs
3455 (auth->
3456 status)));
3457 }
3458 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3459 IPW_DL_ASSOC,
3460 "deauthenticated: '%s' " MAC_FMT "\n",
3461 escape_essid(priv->essid,
3462 priv->essid_len),
3463 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06003464
3465 priv->status &= ~(STATUS_ASSOCIATING |
3466 STATUS_AUTH |
3467 STATUS_ASSOCIATED);
3468
3469 netif_carrier_off(priv->net_dev);
3470 netif_stop_queue(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003471 queue_work(priv->workqueue,
3472 &priv->request_scan);
Jeff Garzikbf794512005-07-31 13:07:26 -04003473 notify_wx_assoc_event(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003474 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003475
3476 case CMAS_TX_AUTH_SEQ_1:
3477 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3478 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
3479 break;
3480 case CMAS_RX_AUTH_SEQ_2:
3481 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3482 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
3483 break;
3484 case CMAS_AUTH_SEQ_1_PASS:
3485 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3486 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
3487 break;
3488 case CMAS_AUTH_SEQ_1_FAIL:
3489 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3490 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
3491 break;
3492 case CMAS_TX_AUTH_SEQ_3:
3493 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3494 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
3495 break;
3496 case CMAS_RX_AUTH_SEQ_4:
3497 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3498 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
3499 break;
3500 case CMAS_AUTH_SEQ_2_PASS:
3501 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3502 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
3503 break;
3504 case CMAS_AUTH_SEQ_2_FAIL:
3505 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3506 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
3507 break;
3508 case CMAS_TX_ASSOC:
3509 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3510 IPW_DL_ASSOC, "TX_ASSOC\n");
3511 break;
3512 case CMAS_RX_ASSOC_RESP:
3513 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3514 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
3515 break;
3516 case CMAS_ASSOCIATED:
3517 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3518 IPW_DL_ASSOC, "ASSOCIATED\n");
3519 break;
3520 default:
3521 IPW_DEBUG_NOTIF("auth: failure - %d\n",
3522 auth->state);
3523 break;
3524 }
3525 break;
3526 }
3527
3528 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
3529 struct notif_channel_result *x =
3530 &notif->u.channel_result;
3531
3532 if (notif->size == sizeof(*x)) {
3533 IPW_DEBUG_SCAN("Scan result for channel %d\n",
3534 x->channel_num);
3535 } else {
3536 IPW_DEBUG_SCAN("Scan result of wrong size %d "
3537 "(should be %zd)\n",
3538 notif->size, sizeof(*x));
3539 }
3540 break;
3541 }
3542
3543 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
3544 struct notif_scan_complete *x = &notif->u.scan_complete;
3545 if (notif->size == sizeof(*x)) {
3546 IPW_DEBUG_SCAN
3547 ("Scan completed: type %d, %d channels, "
3548 "%d status\n", x->scan_type,
3549 x->num_channels, x->status);
3550 } else {
3551 IPW_ERROR("Scan completed of wrong size %d "
3552 "(should be %zd)\n",
3553 notif->size, sizeof(*x));
3554 }
3555
3556 priv->status &=
3557 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3558
3559 cancel_delayed_work(&priv->scan_check);
3560
3561 if (!(priv->status & (STATUS_ASSOCIATED |
3562 STATUS_ASSOCIATING |
3563 STATUS_ROAMING |
3564 STATUS_DISASSOCIATING)))
3565 queue_work(priv->workqueue, &priv->associate);
3566 else if (priv->status & STATUS_ROAMING) {
3567 /* If a scan completed and we are in roam mode, then
3568 * the scan that completed was the one requested as a
3569 * result of entering roam... so, schedule the
3570 * roam work */
3571 queue_work(priv->workqueue, &priv->roam);
3572 } else if (priv->status & STATUS_SCAN_PENDING)
3573 queue_work(priv->workqueue,
3574 &priv->request_scan);
3575
3576 priv->ieee->scans++;
3577 break;
3578 }
3579
3580 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
3581 struct notif_frag_length *x = &notif->u.frag_len;
3582
3583 if (notif->size == sizeof(*x)) {
3584 IPW_ERROR("Frag length: %d\n", x->frag_length);
3585 } else {
3586 IPW_ERROR("Frag length of wrong size %d "
3587 "(should be %zd)\n",
3588 notif->size, sizeof(*x));
3589 }
3590 break;
3591 }
3592
3593 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
3594 struct notif_link_deterioration *x =
3595 &notif->u.link_deterioration;
3596 if (notif->size == sizeof(*x)) {
3597 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3598 "link deterioration: '%s' " MAC_FMT
3599 " \n", escape_essid(priv->essid,
3600 priv->essid_len),
3601 MAC_ARG(priv->bssid));
3602 memcpy(&priv->last_link_deterioration, x,
3603 sizeof(*x));
3604 } else {
3605 IPW_ERROR("Link Deterioration of wrong size %d "
3606 "(should be %zd)\n",
3607 notif->size, sizeof(*x));
3608 }
3609 break;
3610 }
3611
3612 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
3613 IPW_ERROR("Dino config\n");
3614 if (priv->hcmd
3615 && priv->hcmd->cmd == HOST_CMD_DINO_CONFIG) {
3616 /* TODO: Do anything special? */
3617 } else {
3618 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
3619 }
3620 break;
3621 }
3622
3623 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
3624 struct notif_beacon_state *x = &notif->u.beacon_state;
3625 if (notif->size != sizeof(*x)) {
3626 IPW_ERROR
3627 ("Beacon state of wrong size %d (should "
3628 "be %zd)\n", notif->size, sizeof(*x));
3629 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003630 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003631
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003632 if (x->state == HOST_NOTIFICATION_STATUS_BEACON_MISSING) {
3633 if (priv->status & STATUS_SCANNING) {
3634 /* Stop scan to keep fw from getting
3635 * stuck... */
3636 queue_work(priv->workqueue,
3637 &priv->abort_scan);
3638 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003639
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003640 if (x->number > priv->missed_beacon_threshold &&
3641 priv->status & STATUS_ASSOCIATED) {
3642 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
3643 IPW_DL_STATE,
3644 "Missed beacon: %d - disassociate\n",
3645 x->number);
3646 queue_work(priv->workqueue,
3647 &priv->disassociate);
3648 } else if (x->number > priv->roaming_threshold) {
3649 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3650 "Missed beacon: %d - initiate "
3651 "roaming\n", x->number);
3652 queue_work(priv->workqueue,
3653 &priv->roam);
3654 } else {
3655 IPW_DEBUG_NOTIF("Missed beacon: %d\n",
3656 x->number);
3657 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003658
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003659 priv->notif_missed_beacons = x->number;
Jeff Garzikbf794512005-07-31 13:07:26 -04003660
James Ketrenos43f66a62005-03-25 12:31:53 -06003661 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003662
James Ketrenos43f66a62005-03-25 12:31:53 -06003663 break;
3664 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003665
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003666 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
3667 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
3668 if (notif->size == sizeof(*x)) {
3669 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
3670 "0x%02x station %d\n",
3671 x->key_state, x->security_type,
3672 x->station_index);
3673 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003674 }
3675
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003676 IPW_ERROR
3677 ("TGi Tx Key of wrong size %d (should be %zd)\n",
3678 notif->size, sizeof(*x));
3679 break;
3680 }
3681
3682 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
3683 struct notif_calibration *x = &notif->u.calibration;
3684
3685 if (notif->size == sizeof(*x)) {
3686 memcpy(&priv->calib, x, sizeof(*x));
3687 IPW_DEBUG_INFO("TODO: Calibration\n");
3688 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003689 }
3690
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003691 IPW_ERROR
3692 ("Calibration of wrong size %d (should be %zd)\n",
3693 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06003694 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003695 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003696
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003697 case HOST_NOTIFICATION_NOISE_STATS:{
3698 if (notif->size == sizeof(u32)) {
3699 priv->last_noise =
3700 (u8) (notif->u.noise.value & 0xff);
3701 average_add(&priv->average_noise,
3702 priv->last_noise);
3703 break;
3704 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003705
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003706 IPW_ERROR
3707 ("Noise stat is wrong size %d (should be %zd)\n",
3708 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06003709 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04003710 }
3711
James Ketrenos43f66a62005-03-25 12:31:53 -06003712 default:
3713 IPW_ERROR("Unknown notification: "
3714 "subtype=%d,flags=0x%2x,size=%d\n",
3715 notif->subtype, notif->flags, notif->size);
3716 }
3717}
3718
3719/**
3720 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04003721 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003722 * @param priv
3723 * @return error code
3724 */
3725static int ipw_queue_reset(struct ipw_priv *priv)
3726{
3727 int rc = 0;
3728 /** @todo customize queue sizes */
3729 int nTx = 64, nTxCmd = 8;
3730 ipw_tx_queue_free(priv);
3731 /* Tx CMD queue */
3732 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
3733 CX2_TX_CMD_QUEUE_READ_INDEX,
3734 CX2_TX_CMD_QUEUE_WRITE_INDEX,
3735 CX2_TX_CMD_QUEUE_BD_BASE,
3736 CX2_TX_CMD_QUEUE_BD_SIZE);
3737 if (rc) {
3738 IPW_ERROR("Tx Cmd queue init failed\n");
3739 goto error;
3740 }
3741 /* Tx queue(s) */
3742 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
3743 CX2_TX_QUEUE_0_READ_INDEX,
3744 CX2_TX_QUEUE_0_WRITE_INDEX,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003745 CX2_TX_QUEUE_0_BD_BASE, CX2_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003746 if (rc) {
3747 IPW_ERROR("Tx 0 queue init failed\n");
3748 goto error;
3749 }
3750 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
3751 CX2_TX_QUEUE_1_READ_INDEX,
3752 CX2_TX_QUEUE_1_WRITE_INDEX,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003753 CX2_TX_QUEUE_1_BD_BASE, CX2_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003754 if (rc) {
3755 IPW_ERROR("Tx 1 queue init failed\n");
3756 goto error;
3757 }
3758 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
3759 CX2_TX_QUEUE_2_READ_INDEX,
3760 CX2_TX_QUEUE_2_WRITE_INDEX,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003761 CX2_TX_QUEUE_2_BD_BASE, CX2_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003762 if (rc) {
3763 IPW_ERROR("Tx 2 queue init failed\n");
3764 goto error;
3765 }
3766 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
3767 CX2_TX_QUEUE_3_READ_INDEX,
3768 CX2_TX_QUEUE_3_WRITE_INDEX,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003769 CX2_TX_QUEUE_3_BD_BASE, CX2_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003770 if (rc) {
3771 IPW_ERROR("Tx 3 queue init failed\n");
3772 goto error;
3773 }
3774 /* statistics */
3775 priv->rx_bufs_min = 0;
3776 priv->rx_pend_max = 0;
3777 return rc;
3778
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003779 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003780 ipw_tx_queue_free(priv);
3781 return rc;
3782}
3783
3784/**
3785 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04003786 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003787 * When FW adwances 'R' index, all entries between old and
3788 * new 'R' index need to be reclaimed. As result, some free space
3789 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003790 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003791 * @note Need to protect against garbage in 'R' index
3792 * @param priv
3793 * @param txq
3794 * @param qindex
3795 * @return Number of used entries remains in the queue
3796 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003797static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003798 struct clx2_tx_queue *txq, int qindex)
3799{
3800 u32 hw_tail;
3801 int used;
3802 struct clx2_queue *q = &txq->q;
3803
3804 hw_tail = ipw_read32(priv, q->reg_r);
3805 if (hw_tail >= q->n_bd) {
3806 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003807 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
3808 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06003809 goto done;
3810 }
3811 for (; q->last_used != hw_tail;
3812 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3813 ipw_queue_tx_free_tfd(priv, txq);
3814 priv->tx_packets++;
3815 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003816 done:
James Ketrenos43f66a62005-03-25 12:31:53 -06003817 if (ipw_queue_space(q) > q->low_mark && qindex >= 0) {
3818 __maybe_wake_tx(priv);
3819 }
3820 used = q->first_empty - q->last_used;
3821 if (used < 0)
3822 used += q->n_bd;
3823
3824 return used;
3825}
3826
3827static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
3828 int len, int sync)
3829{
3830 struct clx2_tx_queue *txq = &priv->txq_cmd;
3831 struct clx2_queue *q = &txq->q;
3832 struct tfd_frame *tfd;
3833
3834 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
3835 IPW_ERROR("No space for Tx\n");
3836 return -EBUSY;
3837 }
3838
3839 tfd = &txq->bd[q->first_empty];
3840 txq->txb[q->first_empty] = NULL;
3841
3842 memset(tfd, 0, sizeof(*tfd));
3843 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
3844 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
3845 priv->hcmd_seq++;
3846 tfd->u.cmd.index = hcmd;
3847 tfd->u.cmd.length = len;
3848 memcpy(tfd->u.cmd.payload, buf, len);
3849 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
3850 ipw_write32(priv, q->reg_w, q->first_empty);
3851 _ipw_read32(priv, 0x90);
3852
3853 return 0;
3854}
3855
Jeff Garzikbf794512005-07-31 13:07:26 -04003856/*
James Ketrenos43f66a62005-03-25 12:31:53 -06003857 * Rx theory of operation
3858 *
3859 * The host allocates 32 DMA target addresses and passes the host address
3860 * to the firmware at register CX2_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
3861 * 0 to 31
3862 *
3863 * Rx Queue Indexes
3864 * The host/firmware share two index registers for managing the Rx buffers.
3865 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003866 * The READ index maps to the first position that the firmware may be writing
3867 * to -- the driver can read up to (but not including) this position and get
3868 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003869 * The READ index is managed by the firmware once the card is enabled.
3870 *
3871 * The WRITE index maps to the last position the driver has read from -- the
3872 * position preceding WRITE is the last slot the firmware can place a packet.
3873 *
3874 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04003875 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06003876 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003877 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06003878 * INDEX position, and WRITE to the last (READ - 1 wrapped)
3879 *
3880 * When the firmware places a packet in a buffer it will advance the READ index
3881 * and fire the RX interrupt. The driver can then query the READ index and
3882 * process as many packets as possible, moving the WRITE index forward as it
3883 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04003884 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003885 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04003886 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06003887 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04003888 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06003889 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
3890 * ipw->rxq is replenished and the READ INDEX is updated (updating the
3891 * 'processed' and 'read' driver indexes as well)
3892 * + A received packet is processed and handed to the kernel network stack,
3893 * detached from the ipw->rxq. The driver 'processed' index is updated.
3894 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04003895 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
3896 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06003897 * were enough free buffers and RX_STALLED is set it is cleared.
3898 *
3899 *
3900 * Driver sequence:
3901 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003902 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06003903 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
3904 * ipw_rx_queue_restock
3905 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
3906 * queue, updates firmware pointers, and updates
3907 * the WRITE index. If insufficient rx_free buffers
3908 * are available, schedules ipw_rx_queue_replenish
3909 *
3910 * -- enable interrupts --
3911 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04003912 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06003913 * Moves the packet buffer from queue to rx_used.
3914 * Calls ipw_rx_queue_restock to refill any empty
3915 * slots.
3916 * ...
3917 *
3918 */
3919
Jeff Garzikbf794512005-07-31 13:07:26 -04003920/*
James Ketrenos43f66a62005-03-25 12:31:53 -06003921 * If there are slots in the RX queue that need to be restocked,
3922 * and we have free pre-allocated buffers, fill the ranks as much
3923 * as we can pulling from rx_free.
3924 *
3925 * This moves the 'write' index forward to catch up with 'processed', and
3926 * also updates the memory address in the firmware to reference the new
3927 * target buffer.
3928 */
3929static void ipw_rx_queue_restock(struct ipw_priv *priv)
3930{
3931 struct ipw_rx_queue *rxq = priv->rxq;
3932 struct list_head *element;
3933 struct ipw_rx_mem_buffer *rxb;
3934 unsigned long flags;
3935 int write;
3936
3937 spin_lock_irqsave(&rxq->lock, flags);
3938 write = rxq->write;
3939 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
3940 element = rxq->rx_free.next;
3941 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
3942 list_del(element);
3943
3944 ipw_write32(priv, CX2_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
3945 rxb->dma_addr);
3946 rxq->queue[rxq->write] = rxb;
3947 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
3948 rxq->free_count--;
3949 }
3950 spin_unlock_irqrestore(&rxq->lock, flags);
3951
Jeff Garzikbf794512005-07-31 13:07:26 -04003952 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06003953 * refill it */
3954 if (rxq->free_count <= RX_LOW_WATERMARK)
3955 queue_work(priv->workqueue, &priv->rx_replenish);
3956
3957 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04003958 if (write != rxq->write)
James Ketrenos43f66a62005-03-25 12:31:53 -06003959 ipw_write32(priv, CX2_RX_WRITE_INDEX, rxq->write);
3960}
3961
3962/*
3963 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04003964 * Also restock the Rx queue via ipw_rx_queue_restock.
3965 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003966 * This is called as a scheduled work item (except for during intialization)
3967 */
3968static void ipw_rx_queue_replenish(void *data)
3969{
3970 struct ipw_priv *priv = data;
3971 struct ipw_rx_queue *rxq = priv->rxq;
3972 struct list_head *element;
3973 struct ipw_rx_mem_buffer *rxb;
3974 unsigned long flags;
3975
3976 spin_lock_irqsave(&rxq->lock, flags);
3977 while (!list_empty(&rxq->rx_used)) {
3978 element = rxq->rx_used.next;
3979 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
3980 rxb->skb = alloc_skb(CX2_RX_BUF_SIZE, GFP_ATOMIC);
3981 if (!rxb->skb) {
3982 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
3983 priv->net_dev->name);
3984 /* We don't reschedule replenish work here -- we will
3985 * call the restock method and if it still needs
3986 * more buffers it will schedule replenish */
3987 break;
3988 }
3989 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04003990
James Ketrenos43f66a62005-03-25 12:31:53 -06003991 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003992 rxb->dma_addr =
3993 pci_map_single(priv->pci_dev, rxb->skb->data,
3994 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04003995
James Ketrenos43f66a62005-03-25 12:31:53 -06003996 list_add_tail(&rxb->list, &rxq->rx_free);
3997 rxq->free_count++;
3998 }
3999 spin_unlock_irqrestore(&rxq->lock, flags);
4000
4001 ipw_rx_queue_restock(priv);
4002}
4003
4004/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4005 * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04004006 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06004007 * non NULL it is unmapped and freed
4008 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004009static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06004010{
4011 int i;
4012
4013 if (!rxq)
4014 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04004015
James Ketrenos43f66a62005-03-25 12:31:53 -06004016 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4017 if (rxq->pool[i].skb != NULL) {
4018 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004019 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004020 dev_kfree_skb(rxq->pool[i].skb);
4021 }
4022 }
4023
4024 kfree(rxq);
4025}
4026
4027static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4028{
4029 struct ipw_rx_queue *rxq;
4030 int i;
4031
4032 rxq = (struct ipw_rx_queue *)kmalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02004033 if (unlikely(!rxq)) {
4034 IPW_ERROR("memory allocation failed\n");
4035 return NULL;
4036 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004037 memset(rxq, 0, sizeof(*rxq));
4038 spin_lock_init(&rxq->lock);
4039 INIT_LIST_HEAD(&rxq->rx_free);
4040 INIT_LIST_HEAD(&rxq->rx_used);
4041
4042 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04004043 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06004044 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4045
4046 /* Set us so that we have processed and used all buffers, but have
4047 * not restocked the Rx queue with fresh buffers */
4048 rxq->read = rxq->write = 0;
4049 rxq->processed = RX_QUEUE_SIZE - 1;
4050 rxq->free_count = 0;
4051
4052 return rxq;
4053}
4054
4055static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
4056{
4057 rate &= ~IEEE80211_BASIC_RATE_MASK;
4058 if (ieee_mode == IEEE_A) {
4059 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004060 case IEEE80211_OFDM_RATE_6MB:
4061 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004062 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004063 case IEEE80211_OFDM_RATE_9MB:
4064 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004065 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004066 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004067 return priv->
4068 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004069 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004070 return priv->
4071 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004072 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004073 return priv->
4074 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004075 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004076 return priv->
4077 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004078 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004079 return priv->
4080 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004081 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004082 return priv->
4083 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004084 default:
4085 return 0;
4086 }
4087 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004088
James Ketrenos43f66a62005-03-25 12:31:53 -06004089 /* B and G mixed */
4090 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004091 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004092 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004093 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004094 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004095 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004096 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004097 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004098 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
4099 }
4100
4101 /* If we are limited to B modulations, bail at this point */
4102 if (ieee_mode == IEEE_B)
4103 return 0;
4104
4105 /* G */
4106 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004107 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004108 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004109 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004110 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004111 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004112 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004113 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004114 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004115 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004116 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004117 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004118 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004119 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004120 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004121 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004122 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
4123 }
4124
4125 return 0;
4126}
4127
Jeff Garzikbf794512005-07-31 13:07:26 -04004128static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004129 const struct ieee80211_network *network,
4130 struct ipw_supported_rates *rates)
4131{
4132 int num_rates, i;
4133
4134 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004135 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06004136 rates->num_rates = 0;
4137 for (i = 0; i < num_rates; i++) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004138 if (!ipw_is_rate_in_mask
4139 (priv, network->mode, network->rates[i])) {
James Ketrenos43f66a62005-03-25 12:31:53 -06004140 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4141 network->rates[i], priv->rates_mask);
4142 continue;
4143 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004144
James Ketrenos43f66a62005-03-25 12:31:53 -06004145 rates->supported_rates[rates->num_rates++] = network->rates[i];
4146 }
4147
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004148 num_rates =
4149 min(network->rates_ex_len, (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06004150 for (i = 0; i < num_rates; i++) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004151 if (!ipw_is_rate_in_mask
4152 (priv, network->mode, network->rates_ex[i])) {
James Ketrenos43f66a62005-03-25 12:31:53 -06004153 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4154 network->rates_ex[i], priv->rates_mask);
4155 continue;
4156 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004157
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004158 rates->supported_rates[rates->num_rates++] =
4159 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06004160 }
4161
4162 return rates->num_rates;
4163}
4164
4165static inline void ipw_copy_rates(struct ipw_supported_rates *dest,
4166 const struct ipw_supported_rates *src)
4167{
4168 u8 i;
4169 for (i = 0; i < src->num_rates; i++)
4170 dest->supported_rates[i] = src->supported_rates[i];
4171 dest->num_rates = src->num_rates;
4172}
4173
4174/* TODO: Look at sniffed packets in the air to determine if the basic rate
4175 * mask should ever be used -- right now all callers to add the scan rates are
4176 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
4177static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004178 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06004179{
Jeff Garzikbf794512005-07-31 13:07:26 -04004180 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004181 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004182
James Ketrenos43f66a62005-03-25 12:31:53 -06004183 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004184 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004185 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004186
4187 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004188 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004189 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004190
4191 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004192 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004193 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004194
4195 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004196 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004197 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004198}
4199
4200static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004201 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06004202{
Jeff Garzikbf794512005-07-31 13:07:26 -04004203 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004204 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004205
4206 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004207 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004208 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004209
4210 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004211 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004212 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004213
4214 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004215 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004216 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004217
4218 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004219 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004220 IEEE80211_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004221
4222 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004223 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004224 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004225
4226 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004227 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004228 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004229
4230 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004231 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004232 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004233
4234 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004235 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004236 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004237}
4238
4239struct ipw_network_match {
4240 struct ieee80211_network *network;
4241 struct ipw_supported_rates rates;
4242};
4243
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004244static int ipw_best_network(struct ipw_priv *priv,
4245 struct ipw_network_match *match,
4246 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06004247{
4248 struct ipw_supported_rates rates;
4249
4250 /* Verify that this network's capability is compatible with the
4251 * current mode (AdHoc or Infrastructure) */
4252 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07004253 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06004254 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
4255 !(network->capability & WLAN_CAPABILITY_IBSS))) {
4256 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04004257 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004258 escape_essid(network->ssid, network->ssid_len),
4259 MAC_ARG(network->bssid));
4260 return 0;
4261 }
4262
4263 /* If we do not have an ESSID for this AP, we can not associate with
4264 * it */
4265 if (network->flags & NETWORK_EMPTY_ESSID) {
4266 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4267 "because of hidden ESSID.\n",
4268 escape_essid(network->ssid, network->ssid_len),
4269 MAC_ARG(network->bssid));
4270 return 0;
4271 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004272
James Ketrenos43f66a62005-03-25 12:31:53 -06004273 if (unlikely(roaming)) {
4274 /* If we are roaming, then ensure check if this is a valid
4275 * network to try and roam to */
4276 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04004277 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06004278 network->ssid_len)) {
4279 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
4280 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04004281 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06004282 network->ssid_len),
4283 MAC_ARG(network->bssid));
4284 return 0;
4285 }
4286 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04004287 /* If an ESSID has been configured then compare the broadcast
4288 * ESSID to ours */
4289 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06004290 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04004291 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06004292 min(network->ssid_len, priv->essid_len)))) {
4293 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004294 strncpy(escaped,
4295 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06004296 sizeof(escaped));
4297 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04004298 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004299 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004300 escape_essid(priv->essid,
4301 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06004302 return 0;
4303 }
4304 }
4305
4306 /* If the old network rate is better than this one, don't bother
4307 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004308 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06004309 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04004310 strncpy(escaped,
4311 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06004312 sizeof(escaped));
4313 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
4314 "'%s (" MAC_FMT ")' has a stronger signal.\n",
4315 escaped, MAC_ARG(network->bssid),
4316 escape_essid(match->network->ssid,
4317 match->network->ssid_len),
4318 MAC_ARG(match->network->bssid));
4319 return 0;
4320 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004321
James Ketrenos43f66a62005-03-25 12:31:53 -06004322 /* If this network has already had an association attempt within the
4323 * last 3 seconds, do not try and associate again... */
4324 if (network->last_associate &&
4325 time_after(network->last_associate + (HZ * 5UL), jiffies)) {
4326 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4327 "because of storming (%lu since last "
4328 "assoc attempt).\n",
4329 escape_essid(network->ssid, network->ssid_len),
4330 MAC_ARG(network->bssid),
4331 (jiffies - network->last_associate) / HZ);
4332 return 0;
4333 }
4334
4335 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04004336 if (priv->ieee->scan_age != 0 &&
James Ketrenos43f66a62005-03-25 12:31:53 -06004337 jiffies - network->last_scanned > priv->ieee->scan_age) {
4338 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4339 "because of age: %lums.\n",
4340 escape_essid(network->ssid, network->ssid_len),
4341 MAC_ARG(network->bssid),
4342 (jiffies - network->last_scanned) / (HZ / 100));
4343 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004344 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004345
Jeff Garzikbf794512005-07-31 13:07:26 -04004346 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06004347 (network->channel != priv->channel)) {
4348 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4349 "because of channel mismatch: %d != %d.\n",
4350 escape_essid(network->ssid, network->ssid_len),
4351 MAC_ARG(network->bssid),
4352 network->channel, priv->channel);
4353 return 0;
4354 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004355
James Ketrenos43f66a62005-03-25 12:31:53 -06004356 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04004357 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06004358 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
4359 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4360 "because of privacy mismatch: %s != %s.\n",
4361 escape_essid(network->ssid, network->ssid_len),
4362 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04004363 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06004364 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04004365 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004366 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06004367 return 0;
4368 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004369
4370 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06004371 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
4372 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4373 "because of BSSID mismatch: " MAC_FMT ".\n",
4374 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004375 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004376 return 0;
4377 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004378
James Ketrenos43f66a62005-03-25 12:31:53 -06004379 /* Filter out any incompatible freq / mode combinations */
4380 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
4381 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4382 "because of invalid frequency/mode "
4383 "combination.\n",
4384 escape_essid(network->ssid, network->ssid_len),
4385 MAC_ARG(network->bssid));
4386 return 0;
4387 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004388
James Ketrenos43f66a62005-03-25 12:31:53 -06004389 ipw_compatible_rates(priv, network, &rates);
4390 if (rates.num_rates == 0) {
4391 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4392 "because of no compatible rates.\n",
4393 escape_essid(network->ssid, network->ssid_len),
4394 MAC_ARG(network->bssid));
4395 return 0;
4396 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004397
James Ketrenos43f66a62005-03-25 12:31:53 -06004398 /* TODO: Perform any further minimal comparititive tests. We do not
4399 * want to put too much policy logic here; intelligent scan selection
4400 * should occur within a generic IEEE 802.11 user space tool. */
4401
4402 /* Set up 'new' AP to this network */
4403 ipw_copy_rates(&match->rates, &rates);
4404 match->network = network;
4405
4406 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
4407 escape_essid(network->ssid, network->ssid_len),
4408 MAC_ARG(network->bssid));
4409
4410 return 1;
4411}
4412
Jeff Garzikbf794512005-07-31 13:07:26 -04004413static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004414 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06004415{
4416 /*
4417 * For the purposes of scanning, we can set our wireless mode
4418 * to trigger scans across combinations of bands, but when it
4419 * comes to creating a new ad-hoc network, we have tell the FW
4420 * exactly which band to use.
4421 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004422 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06004423 * chossen band. Attempting to create a new ad-hoc network
4424 * with an invalid channel for wireless mode will trigger a
4425 * FW fatal error.
4426 */
4427 network->mode = is_valid_channel(priv->ieee->mode, priv->channel);
4428 if (network->mode) {
4429 network->channel = priv->channel;
4430 } else {
4431 IPW_WARNING("Overriding invalid channel\n");
4432 if (priv->ieee->mode & IEEE_A) {
4433 network->mode = IEEE_A;
4434 priv->channel = band_a_active_channel[0];
4435 } else if (priv->ieee->mode & IEEE_G) {
4436 network->mode = IEEE_G;
4437 priv->channel = band_b_active_channel[0];
4438 } else {
4439 network->mode = IEEE_B;
4440 priv->channel = band_b_active_channel[0];
4441 }
4442 }
4443
4444 network->channel = priv->channel;
4445 priv->config |= CFG_ADHOC_PERSIST;
4446 ipw_create_bssid(priv, network->bssid);
4447 network->ssid_len = priv->essid_len;
4448 memcpy(network->ssid, priv->essid, priv->essid_len);
4449 memset(&network->stats, 0, sizeof(network->stats));
4450 network->capability = WLAN_CAPABILITY_IBSS;
4451 if (priv->capability & CAP_PRIVACY_ON)
4452 network->capability |= WLAN_CAPABILITY_PRIVACY;
4453 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004454 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06004455 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04004456 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06004457 &priv->rates.supported_rates[network->rates_len],
4458 network->rates_ex_len);
4459 network->last_scanned = 0;
4460 network->flags = 0;
4461 network->last_associate = 0;
4462 network->time_stamp[0] = 0;
4463 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004464 network->beacon_interval = 100; /* Default */
4465 network->listen_interval = 10; /* Default */
4466 network->atim_window = 0; /* Default */
Jeff Garzikbf794512005-07-31 13:07:26 -04004467#ifdef CONFIG_IEEE80211_WPA
James Ketrenos43f66a62005-03-25 12:31:53 -06004468 network->wpa_ie_len = 0;
4469 network->rsn_ie_len = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004470#endif /* CONFIG_IEEE80211_WPA */
James Ketrenos43f66a62005-03-25 12:31:53 -06004471}
4472
4473static void ipw_send_wep_keys(struct ipw_priv *priv)
4474{
4475 struct ipw_wep_key *key;
4476 int i;
4477 struct host_cmd cmd = {
4478 .cmd = IPW_CMD_WEP_KEY,
4479 .len = sizeof(*key)
4480 };
4481
4482 key = (struct ipw_wep_key *)&cmd.param;
4483 key->cmd_id = DINO_CMD_WEP_KEY;
4484 key->seq_num = 0;
4485
Jeff Garzikbf794512005-07-31 13:07:26 -04004486 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06004487 key->key_index = i;
4488 if (!(priv->sec.flags & (1 << i))) {
4489 key->key_size = 0;
4490 } else {
4491 key->key_size = priv->sec.key_sizes[i];
4492 memcpy(key->key, priv->sec.keys[i], key->key_size);
4493 }
4494
4495 if (ipw_send_cmd(priv, &cmd)) {
4496 IPW_ERROR("failed to send WEP_KEY command\n");
4497 return;
4498 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004499 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004500}
4501
4502static void ipw_adhoc_check(void *data)
4503{
4504 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04004505
James Ketrenos43f66a62005-03-25 12:31:53 -06004506 if (priv->missed_adhoc_beacons++ > priv->missed_beacon_threshold &&
4507 !(priv->config & CFG_ADHOC_PERSIST)) {
4508 IPW_DEBUG_SCAN("Disassociating due to missed beacons\n");
4509 ipw_remove_current_network(priv);
4510 ipw_disassociate(priv);
4511 return;
4512 }
4513
Jeff Garzikbf794512005-07-31 13:07:26 -04004514 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06004515 priv->assoc_request.beacon_interval);
4516}
4517
4518#ifdef CONFIG_IPW_DEBUG
4519static void ipw_debug_config(struct ipw_priv *priv)
4520{
4521 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
4522 "[CFG 0x%08X]\n", priv->config);
4523 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004524 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06004525 else
4526 IPW_DEBUG_INFO("Channel unlocked.\n");
4527 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04004528 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004529 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06004530 else
4531 IPW_DEBUG_INFO("ESSID unlocked.\n");
4532 if (priv->config & CFG_STATIC_BSSID)
4533 IPW_DEBUG_INFO("BSSID locked to %d\n", priv->channel);
4534 else
4535 IPW_DEBUG_INFO("BSSID unlocked.\n");
4536 if (priv->capability & CAP_PRIVACY_ON)
4537 IPW_DEBUG_INFO("PRIVACY on\n");
4538 else
4539 IPW_DEBUG_INFO("PRIVACY off\n");
4540 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
4541}
4542#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04004543#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06004544#endif
4545
4546static inline void ipw_set_fixed_rate(struct ipw_priv *priv,
4547 struct ieee80211_network *network)
4548{
4549 /* TODO: Verify that this works... */
4550 struct ipw_fixed_rate fr = {
4551 .tx_rates = priv->rates_mask
4552 };
4553 u32 reg;
4554 u16 mask = 0;
4555
Jeff Garzikbf794512005-07-31 13:07:26 -04004556 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06004557 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04004558
James Ketrenos43f66a62005-03-25 12:31:53 -06004559 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004560 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06004561 /* IEEE_A */
4562 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
4563 /* Invalid fixed rate mask */
4564 fr.tx_rates = 0;
4565 break;
4566 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004567
James Ketrenos43f66a62005-03-25 12:31:53 -06004568 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
4569 break;
4570
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004571 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06004572 /* IEEE_B */
4573 if (network->mode == IEEE_B) {
4574 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
4575 /* Invalid fixed rate mask */
4576 fr.tx_rates = 0;
4577 }
4578 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004579 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004580
4581 /* IEEE_G */
4582 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
4583 IEEE80211_OFDM_RATES_MASK)) {
4584 /* Invalid fixed rate mask */
4585 fr.tx_rates = 0;
4586 break;
4587 }
4588
4589 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
4590 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
4591 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
4592 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004593
James Ketrenos43f66a62005-03-25 12:31:53 -06004594 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
4595 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
4596 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
4597 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004598
James Ketrenos43f66a62005-03-25 12:31:53 -06004599 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
4600 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
4601 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
4602 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004603
James Ketrenos43f66a62005-03-25 12:31:53 -06004604 fr.tx_rates |= mask;
4605 break;
4606 }
4607
4608 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004609 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06004610}
4611
4612static int ipw_associate_network(struct ipw_priv *priv,
4613 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004614 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06004615{
4616 int err;
4617
4618 if (priv->config & CFG_FIXED_RATE)
4619 ipw_set_fixed_rate(priv, network);
4620
4621 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004622 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004623 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004624 memcpy(priv->essid, network->ssid, priv->essid_len);
4625 }
4626
4627 network->last_associate = jiffies;
4628
4629 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
4630 priv->assoc_request.channel = network->channel;
4631 if ((priv->capability & CAP_PRIVACY_ON) &&
4632 (priv->capability & CAP_SHARED_KEY)) {
4633 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
4634 priv->assoc_request.auth_key = priv->sec.active_key;
4635 } else {
4636 priv->assoc_request.auth_type = AUTH_OPEN;
4637 priv->assoc_request.auth_key = 0;
4638 }
4639
Jeff Garzikbf794512005-07-31 13:07:26 -04004640 if (priv->capability & CAP_PRIVACY_ON)
James Ketrenos43f66a62005-03-25 12:31:53 -06004641 ipw_send_wep_keys(priv);
4642
Jeff Garzikbf794512005-07-31 13:07:26 -04004643 /*
4644 * It is valid for our ieee device to support multiple modes, but
4645 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06004646 * just one mode.
4647 */
4648 if (network->mode & priv->ieee->mode & IEEE_A)
4649 priv->assoc_request.ieee_mode = IPW_A_MODE;
4650 else if (network->mode & priv->ieee->mode & IEEE_G)
4651 priv->assoc_request.ieee_mode = IPW_G_MODE;
4652 else if (network->mode & priv->ieee->mode & IEEE_B)
4653 priv->assoc_request.ieee_mode = IPW_B_MODE;
4654
4655 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
4656 "802.11%c [%d], enc=%s%s%s%c%c\n",
4657 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04004658 escape_essid(priv->essid, priv->essid_len),
4659 network->channel,
4660 ipw_modes[priv->assoc_request.ieee_mode],
4661 rates->num_rates,
James Ketrenos43f66a62005-03-25 12:31:53 -06004662 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04004663 priv->capability & CAP_PRIVACY_ON ?
4664 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06004665 "(open)") : "",
4666 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04004667 priv->capability & CAP_PRIVACY_ON ?
James Ketrenos43f66a62005-03-25 12:31:53 -06004668 '1' + priv->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004669 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06004670
4671 priv->assoc_request.beacon_interval = network->beacon_interval;
4672 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004673 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06004674 priv->assoc_request.assoc_type = HC_IBSS_START;
4675 priv->assoc_request.assoc_tsf_msw = 0;
4676 priv->assoc_request.assoc_tsf_lsw = 0;
4677 } else {
4678 if (unlikely(roaming))
4679 priv->assoc_request.assoc_type = HC_REASSOCIATE;
4680 else
4681 priv->assoc_request.assoc_type = HC_ASSOCIATE;
4682 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
4683 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
4684 }
4685
4686 memcpy(&priv->assoc_request.bssid, network->bssid, ETH_ALEN);
4687
4688 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
4689 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
4690 priv->assoc_request.atim_window = network->atim_window;
4691 } else {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004692 memcpy(&priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06004693 priv->assoc_request.atim_window = 0;
4694 }
4695
4696 priv->assoc_request.capability = network->capability;
4697 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04004698
James Ketrenos43f66a62005-03-25 12:31:53 -06004699 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
4700 if (err) {
4701 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
4702 return err;
4703 }
4704
4705 rates->ieee_mode = priv->assoc_request.ieee_mode;
4706 rates->purpose = IPW_RATE_CONNECT;
4707 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04004708
James Ketrenos43f66a62005-03-25 12:31:53 -06004709 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
4710 priv->sys_config.dot11g_auto_detection = 1;
4711 else
4712 priv->sys_config.dot11g_auto_detection = 0;
4713 err = ipw_send_system_config(priv, &priv->sys_config);
4714 if (err) {
4715 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
4716 return err;
4717 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004718
James Ketrenos43f66a62005-03-25 12:31:53 -06004719 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
4720 err = ipw_set_sensitivity(priv, network->stats.rssi);
4721 if (err) {
4722 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
4723 return err;
4724 }
4725
4726 /*
4727 * If preemption is enabled, it is possible for the association
4728 * to complete before we return from ipw_send_associate. Therefore
4729 * we have to be sure and update our priviate data first.
4730 */
4731 priv->channel = network->channel;
4732 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004733 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06004734 priv->status &= ~STATUS_SECURITY_UPDATED;
4735
4736 priv->assoc_network = network;
4737
4738 err = ipw_send_associate(priv, &priv->assoc_request);
4739 if (err) {
4740 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
4741 return err;
4742 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004743
4744 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004745 escape_essid(priv->essid, priv->essid_len),
4746 MAC_ARG(priv->bssid));
4747
4748 return 0;
4749}
4750
4751static void ipw_roam(void *data)
4752{
4753 struct ipw_priv *priv = data;
4754 struct ieee80211_network *network = NULL;
4755 struct ipw_network_match match = {
4756 .network = priv->assoc_network
4757 };
4758
4759 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004760 *
4761 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06004762 * setting the status ROAM bit and requesting a scan.
4763 * 2. When the scan completes, it schedules the ROAM work
4764 * 3. The ROAM work looks at all of the known networks for one that
4765 * is a better network than the currently associated. If none
4766 * found, the ROAM process is over (ROAM bit cleared)
4767 * 4. If a better network is found, a disassociation request is
4768 * sent.
4769 * 5. When the disassociation completes, the roam work is again
4770 * scheduled. The second time through, the driver is no longer
4771 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04004772 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06004773 * 6. At this point ,the roaming process is complete and the ROAM
4774 * status bit is cleared.
4775 */
4776
4777 /* If we are no longer associated, and the roaming bit is no longer
4778 * set, then we are not actively roaming, so just return */
4779 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
4780 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04004781
James Ketrenos43f66a62005-03-25 12:31:53 -06004782 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004783 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06004784 * network */
4785 u8 rssi = priv->assoc_network->stats.rssi;
4786 priv->assoc_network->stats.rssi = -128;
4787 list_for_each_entry(network, &priv->ieee->network_list, list) {
4788 if (network != priv->assoc_network)
4789 ipw_best_network(priv, &match, network, 1);
4790 }
4791 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004792
James Ketrenos43f66a62005-03-25 12:31:53 -06004793 if (match.network == priv->assoc_network) {
4794 IPW_DEBUG_ASSOC("No better APs in this network to "
4795 "roam to.\n");
4796 priv->status &= ~STATUS_ROAMING;
4797 ipw_debug_config(priv);
4798 return;
4799 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004800
James Ketrenos43f66a62005-03-25 12:31:53 -06004801 ipw_send_disassociate(priv, 1);
4802 priv->assoc_network = match.network;
4803
4804 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04004805 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004806
4807 /* Second pass through ROAM process -- request association */
4808 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
4809 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
4810 priv->status &= ~STATUS_ROAMING;
4811}
4812
4813static void ipw_associate(void *data)
4814{
4815 struct ipw_priv *priv = data;
4816
4817 struct ieee80211_network *network = NULL;
4818 struct ipw_network_match match = {
4819 .network = NULL
4820 };
4821 struct ipw_supported_rates *rates;
4822 struct list_head *element;
4823
4824 if (!(priv->config & CFG_ASSOCIATE) &&
4825 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004826 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06004827 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
4828 return;
4829 }
4830
Jeff Garzikbf794512005-07-31 13:07:26 -04004831 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004832 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06004833
4834 network = match.network;
4835 rates = &match.rates;
4836
4837 if (network == NULL &&
4838 priv->ieee->iw_mode == IW_MODE_ADHOC &&
4839 priv->config & CFG_ADHOC_CREATE &&
4840 priv->config & CFG_STATIC_ESSID &&
4841 !list_empty(&priv->ieee->network_free_list)) {
4842 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004843 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06004844 ipw_adhoc_create(priv, network);
4845 rates = &priv->rates;
4846 list_del(element);
4847 list_add_tail(&network->list, &priv->ieee->network_list);
4848 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004849
James Ketrenos43f66a62005-03-25 12:31:53 -06004850 /* If we reached the end of the list, then we don't have any valid
4851 * matching APs */
4852 if (!network) {
4853 ipw_debug_config(priv);
4854
Jeff Garzikbf794512005-07-31 13:07:26 -04004855 queue_delayed_work(priv->workqueue, &priv->request_scan,
James Ketrenos43f66a62005-03-25 12:31:53 -06004856 SCAN_INTERVAL);
Jeff Garzikbf794512005-07-31 13:07:26 -04004857
James Ketrenos43f66a62005-03-25 12:31:53 -06004858 return;
4859 }
4860
4861 ipw_associate_network(priv, network, rates, 0);
4862}
Jeff Garzikbf794512005-07-31 13:07:26 -04004863
4864static inline void ipw_handle_data_packet(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004865 struct ipw_rx_mem_buffer *rxb,
4866 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06004867{
4868 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
4869
4870 /* We received data from the HW, so stop the watchdog */
4871 priv->net_dev->trans_start = jiffies;
4872
Jeff Garzikbf794512005-07-31 13:07:26 -04004873 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06004874 * interface is open */
Jeff Garzikbf794512005-07-31 13:07:26 -04004875 if (unlikely((pkt->u.frame.length + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06004876 skb_tailroom(rxb->skb))) {
4877 priv->ieee->stats.rx_errors++;
4878 priv->wstats.discard.misc++;
4879 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
4880 return;
4881 } else if (unlikely(!netif_running(priv->net_dev))) {
4882 priv->ieee->stats.rx_dropped++;
4883 priv->wstats.discard.misc++;
4884 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
4885 return;
4886 }
4887
4888 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02004889 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06004890
4891 /* Set the size of the skb to the size of the frame */
4892 skb_put(rxb->skb, pkt->u.frame.length);
4893
4894 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
4895
Jeff Garzikbf794512005-07-31 13:07:26 -04004896 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06004897 priv->ieee->stats.rx_errors++;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004898 else /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06004899 rxb->skb = NULL;
4900}
4901
James Ketrenos43f66a62005-03-25 12:31:53 -06004902/*
4903 * Main entry function for recieving a packet with 80211 headers. This
4904 * should be called when ever the FW has notified us that there is a new
4905 * skb in the recieve queue.
4906 */
4907static void ipw_rx(struct ipw_priv *priv)
4908{
4909 struct ipw_rx_mem_buffer *rxb;
4910 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05004911 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06004912 u32 r, w, i;
4913 u8 network_packet;
4914
4915 r = ipw_read32(priv, CX2_RX_READ_INDEX);
4916 w = ipw_read32(priv, CX2_RX_WRITE_INDEX);
4917 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
4918
4919 while (i != r) {
4920 rxb = priv->rxq->queue[i];
4921#ifdef CONFIG_IPW_DEBUG
4922 if (unlikely(rxb == NULL)) {
4923 printk(KERN_CRIT "Queue not allocated!\n");
4924 break;
4925 }
4926#endif
4927 priv->rxq->queue[i] = NULL;
4928
4929 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
Jeff Garzikbf794512005-07-31 13:07:26 -04004930 CX2_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004931 PCI_DMA_FROMDEVICE);
4932
4933 pkt = (struct ipw_rx_packet *)rxb->skb->data;
4934 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
4935 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004936 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06004937
4938 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004939 case RX_FRAME_TYPE: /* 802.11 frame */ {
4940 struct ieee80211_rx_stats stats = {
4941 .rssi = pkt->u.frame.rssi_dbm -
4942 IPW_RSSI_TO_DBM,
4943 .signal = pkt->u.frame.signal,
4944 .rate = pkt->u.frame.rate,
4945 .mac_time = jiffies,
4946 .received_channel =
4947 pkt->u.frame.received_channel,
4948 .freq =
4949 (pkt->u.frame.
4950 control & (1 << 0)) ?
4951 IEEE80211_24GHZ_BAND :
4952 IEEE80211_52GHZ_BAND,
4953 .len = pkt->u.frame.length,
4954 };
James Ketrenos43f66a62005-03-25 12:31:53 -06004955
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004956 if (stats.rssi != 0)
4957 stats.mask |= IEEE80211_STATMASK_RSSI;
4958 if (stats.signal != 0)
4959 stats.mask |= IEEE80211_STATMASK_SIGNAL;
4960 if (stats.rate != 0)
4961 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06004962
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004963 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06004964
4965#ifdef CONFIG_IPW_PROMISC
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004966 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
4967 ipw_handle_data_packet(priv, rxb,
4968 &stats);
4969 break;
4970 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004971#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04004972
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004973 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05004974 (struct ieee80211_hdr_4addr *)(rxb->skb->
4975 data +
4976 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004977 /* TODO: Check Ad-Hoc dest/source and make sure
4978 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04004979 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06004980 * frame control of the packet and disregard
4981 * the current iw_mode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004982 switch (priv->ieee->iw_mode) {
4983 case IW_MODE_ADHOC:
4984 network_packet =
4985 !memcmp(header->addr1,
4986 priv->net_dev->dev_addr,
4987 ETH_ALEN) ||
4988 !memcmp(header->addr3,
4989 priv->bssid, ETH_ALEN) ||
4990 is_broadcast_ether_addr(header->
4991 addr1)
4992 || is_multicast_ether_addr(header->
4993 addr1);
4994 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004995
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004996 case IW_MODE_INFRA:
4997 default:
4998 network_packet =
4999 !memcmp(header->addr3,
5000 priv->bssid, ETH_ALEN) ||
5001 !memcmp(header->addr1,
5002 priv->net_dev->dev_addr,
5003 ETH_ALEN) ||
5004 is_broadcast_ether_addr(header->
5005 addr1)
5006 || is_multicast_ether_addr(header->
5007 addr1);
5008 break;
5009 }
5010
5011 if (network_packet && priv->assoc_network) {
5012 priv->assoc_network->stats.rssi =
5013 stats.rssi;
5014 average_add(&priv->average_rssi,
5015 stats.rssi);
5016 priv->last_rx_rssi = stats.rssi;
5017 }
5018
5019 IPW_DEBUG_RX("Frame: len=%u\n",
5020 pkt->u.frame.length);
5021
5022 if (pkt->u.frame.length < frame_hdr_len(header)) {
5023 IPW_DEBUG_DROP
5024 ("Received packet is too small. "
5025 "Dropping.\n");
5026 priv->ieee->stats.rx_errors++;
5027 priv->wstats.discard.misc++;
5028 break;
5029 }
5030
5031 switch (WLAN_FC_GET_TYPE(header->frame_ctl)) {
5032 case IEEE80211_FTYPE_MGMT:
5033 ieee80211_rx_mgt(priv->ieee, header,
5034 &stats);
5035 if (priv->ieee->iw_mode == IW_MODE_ADHOC
5036 &&
5037 ((WLAN_FC_GET_STYPE
5038 (header->frame_ctl) ==
5039 IEEE80211_STYPE_PROBE_RESP)
5040 ||
5041 (WLAN_FC_GET_STYPE
5042 (header->frame_ctl) ==
5043 IEEE80211_STYPE_BEACON))
5044 && !memcmp(header->addr3,
5045 priv->bssid, ETH_ALEN))
5046 ipw_add_station(priv,
5047 header->addr2);
5048 break;
5049
5050 case IEEE80211_FTYPE_CTL:
5051 break;
5052
5053 case IEEE80211_FTYPE_DATA:
5054 if (network_packet)
5055 ipw_handle_data_packet(priv,
5056 rxb,
5057 &stats);
5058 else
5059 IPW_DEBUG_DROP("Dropping: "
5060 MAC_FMT ", "
5061 MAC_FMT ", "
5062 MAC_FMT "\n",
5063 MAC_ARG(header->
5064 addr1),
5065 MAC_ARG(header->
5066 addr2),
5067 MAC_ARG(header->
5068 addr3));
5069 break;
5070 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005071 break;
5072 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005073
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005074 case RX_HOST_NOTIFICATION_TYPE:{
5075 IPW_DEBUG_RX
5076 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005077 pkt->u.notification.subtype,
5078 pkt->u.notification.flags,
5079 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005080 ipw_rx_notification(priv, &pkt->u.notification);
5081 break;
5082 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005083
5084 default:
5085 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
5086 pkt->header.message_type);
5087 break;
5088 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005089
5090 /* For now we just don't re-use anything. We can tweak this
5091 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06005092 * fail to Rx correctly */
5093 if (rxb->skb != NULL) {
5094 dev_kfree_skb_any(rxb->skb);
5095 rxb->skb = NULL;
5096 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005097
James Ketrenos43f66a62005-03-25 12:31:53 -06005098 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
5099 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
5100 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04005101
James Ketrenos43f66a62005-03-25 12:31:53 -06005102 i = (i + 1) % RX_QUEUE_SIZE;
5103 }
5104
5105 /* Backtrack one entry */
5106 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
5107
5108 ipw_rx_queue_restock(priv);
5109}
5110
5111static void ipw_abort_scan(struct ipw_priv *priv)
5112{
5113 int err;
5114
5115 if (priv->status & STATUS_SCAN_ABORTING) {
5116 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5117 return;
5118 }
5119 priv->status |= STATUS_SCAN_ABORTING;
5120
5121 err = ipw_send_scan_abort(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04005122 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -06005123 IPW_DEBUG_HC("Request to abort scan failed.\n");
5124}
5125
5126static int ipw_request_scan(struct ipw_priv *priv)
5127{
5128 struct ipw_scan_request_ext scan;
5129 int channel_index = 0;
5130 int i, err, scan_type;
Jeff Garzikbf794512005-07-31 13:07:26 -04005131
James Ketrenos43f66a62005-03-25 12:31:53 -06005132 if (priv->status & STATUS_EXIT_PENDING) {
5133 IPW_DEBUG_SCAN("Aborting scan due to device shutdown\n");
5134 priv->status |= STATUS_SCAN_PENDING;
5135 return 0;
5136 }
5137
5138 if (priv->status & STATUS_SCANNING) {
5139 IPW_DEBUG_HC("Concurrent scan requested. Aborting first.\n");
5140 priv->status |= STATUS_SCAN_PENDING;
5141 ipw_abort_scan(priv);
5142 return 0;
5143 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005144
James Ketrenos43f66a62005-03-25 12:31:53 -06005145 if (priv->status & STATUS_SCAN_ABORTING) {
5146 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
5147 priv->status |= STATUS_SCAN_PENDING;
5148 return 0;
5149 }
5150
5151 if (priv->status & STATUS_RF_KILL_MASK) {
5152 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
5153 priv->status |= STATUS_SCAN_PENDING;
5154 return 0;
5155 }
5156
5157 memset(&scan, 0, sizeof(scan));
5158
5159 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = 20;
5160 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] = 20;
5161 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = 20;
5162
5163 scan.full_scan_index = ieee80211_get_scans(priv->ieee);
5164 /* If we are roaming, then make this a directed scan for the current
Jeff Garzikbf794512005-07-31 13:07:26 -04005165 * network. Otherwise, ensure that every other scan is a fast
James Ketrenos43f66a62005-03-25 12:31:53 -06005166 * channel hop scan */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005167 if ((priv->status & STATUS_ROAMING)
5168 || (!(priv->status & STATUS_ASSOCIATED)
5169 && (priv->config & CFG_STATIC_ESSID)
5170 && (scan.full_scan_index % 2))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005171 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
5172 if (err) {
5173 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
5174 return err;
5175 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005176
James Ketrenos43f66a62005-03-25 12:31:53 -06005177 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
5178 } else {
5179 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
5180 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005181
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005182 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005183 int start = channel_index;
5184 for (i = 0; i < MAX_A_CHANNELS; i++) {
5185 if (band_a_active_channel[i] == 0)
5186 break;
5187 if ((priv->status & STATUS_ASSOCIATED) &&
5188 band_a_active_channel[i] == priv->channel)
5189 continue;
5190 channel_index++;
Jeff Garzikbf794512005-07-31 13:07:26 -04005191 scan.channels_list[channel_index] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005192 band_a_active_channel[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005193 ipw_set_scan_type(&scan, channel_index, scan_type);
5194 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005195
James Ketrenos43f66a62005-03-25 12:31:53 -06005196 if (start != channel_index) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005197 scan.channels_list[start] = (u8) (IPW_A_MODE << 6) |
5198 (channel_index - start);
James Ketrenos43f66a62005-03-25 12:31:53 -06005199 channel_index++;
5200 }
5201 }
5202
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005203 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005204 int start = channel_index;
5205 for (i = 0; i < MAX_B_CHANNELS; i++) {
5206 if (band_b_active_channel[i] == 0)
5207 break;
5208 if ((priv->status & STATUS_ASSOCIATED) &&
5209 band_b_active_channel[i] == priv->channel)
5210 continue;
5211 channel_index++;
Jeff Garzikbf794512005-07-31 13:07:26 -04005212 scan.channels_list[channel_index] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005213 band_b_active_channel[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005214 ipw_set_scan_type(&scan, channel_index, scan_type);
5215 }
5216
5217 if (start != channel_index) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005218 scan.channels_list[start] = (u8) (IPW_B_MODE << 6) |
5219 (channel_index - start);
James Ketrenos43f66a62005-03-25 12:31:53 -06005220 }
5221 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005222
James Ketrenos43f66a62005-03-25 12:31:53 -06005223 err = ipw_send_scan_request_ext(priv, &scan);
5224 if (err) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005225 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenos43f66a62005-03-25 12:31:53 -06005226 return -EIO;
5227 }
5228
5229 priv->status |= STATUS_SCANNING;
5230 priv->status &= ~STATUS_SCAN_PENDING;
5231
5232 return 0;
5233}
5234
5235/*
5236 * This file defines the Wireless Extension handlers. It does not
5237 * define any methods of hardware manipulation and relies on the
5238 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04005239 *
5240 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06005241 * function used to poll the hardware vs. making unecessary calls.
5242 *
5243 */
5244
Jeff Garzikbf794512005-07-31 13:07:26 -04005245static int ipw_wx_get_name(struct net_device *dev,
5246 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005247 union iwreq_data *wrqu, char *extra)
5248{
5249 struct ipw_priv *priv = ieee80211_priv(dev);
5250 if (!(priv->status & STATUS_ASSOCIATED))
5251 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04005252 else
James Ketrenos43f66a62005-03-25 12:31:53 -06005253 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
5254 ipw_modes[priv->assoc_request.ieee_mode]);
5255 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
5256 return 0;
5257}
5258
5259static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
5260{
5261 if (channel == 0) {
5262 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
5263 priv->config &= ~CFG_STATIC_CHANNEL;
5264 if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED |
5265 STATUS_ASSOCIATING))) {
5266 IPW_DEBUG_ASSOC("Attempting to associate with new "
5267 "parameters.\n");
5268 ipw_associate(priv);
5269 }
5270
5271 return 0;
5272 }
5273
5274 priv->config |= CFG_STATIC_CHANNEL;
5275
5276 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005277 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
5278 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005279 return 0;
5280 }
5281
5282 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
5283 priv->channel = channel;
5284
5285 /* If we are currently associated, or trying to associate
5286 * then see if this is a new channel (causing us to disassociate) */
5287 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
5288 IPW_DEBUG_ASSOC("Disassociating due to channel change.\n");
5289 ipw_disassociate(priv);
5290 } else {
5291 ipw_associate(priv);
5292 }
5293
5294 return 0;
5295}
5296
Jeff Garzikbf794512005-07-31 13:07:26 -04005297static int ipw_wx_set_freq(struct net_device *dev,
5298 struct iw_request_info *info,
5299 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06005300{
5301 struct ipw_priv *priv = ieee80211_priv(dev);
5302 struct iw_freq *fwrq = &wrqu->freq;
Jeff Garzikbf794512005-07-31 13:07:26 -04005303
James Ketrenos43f66a62005-03-25 12:31:53 -06005304 /* if setting by freq convert to channel */
5305 if (fwrq->e == 1) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005306 if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005307 int f = fwrq->m / 100000;
5308 int c = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005309
James Ketrenos43f66a62005-03-25 12:31:53 -06005310 while ((c < REG_MAX_CHANNEL) &&
5311 (f != ipw_frequencies[c]))
5312 c++;
Jeff Garzikbf794512005-07-31 13:07:26 -04005313
James Ketrenos43f66a62005-03-25 12:31:53 -06005314 /* hack to fall through */
5315 fwrq->e = 0;
5316 fwrq->m = c + 1;
5317 }
5318 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005319
5320 if (fwrq->e > 0 || fwrq->m > 1000)
James Ketrenos43f66a62005-03-25 12:31:53 -06005321 return -EOPNOTSUPP;
5322
5323 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005324 return ipw_set_channel(priv, (u8) fwrq->m);
James Ketrenos43f66a62005-03-25 12:31:53 -06005325}
5326
Jeff Garzikbf794512005-07-31 13:07:26 -04005327static int ipw_wx_get_freq(struct net_device *dev,
5328 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005329 union iwreq_data *wrqu, char *extra)
5330{
5331 struct ipw_priv *priv = ieee80211_priv(dev);
5332
5333 wrqu->freq.e = 0;
5334
5335 /* If we are associated, trying to associate, or have a statically
5336 * configured CHANNEL then return that; otherwise return ANY */
5337 if (priv->config & CFG_STATIC_CHANNEL ||
5338 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
5339 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04005340 else
James Ketrenos43f66a62005-03-25 12:31:53 -06005341 wrqu->freq.m = 0;
5342
5343 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
5344 return 0;
5345}
5346
Jeff Garzikbf794512005-07-31 13:07:26 -04005347static int ipw_wx_set_mode(struct net_device *dev,
5348 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005349 union iwreq_data *wrqu, char *extra)
5350{
5351 struct ipw_priv *priv = ieee80211_priv(dev);
5352 int err = 0;
5353
5354 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
5355
5356 if (wrqu->mode == priv->ieee->iw_mode)
5357 return 0;
5358
5359 switch (wrqu->mode) {
5360#ifdef CONFIG_IPW_PROMISC
5361 case IW_MODE_MONITOR:
5362#endif
5363 case IW_MODE_ADHOC:
5364 case IW_MODE_INFRA:
5365 break;
5366 case IW_MODE_AUTO:
5367 wrqu->mode = IW_MODE_INFRA;
5368 break;
5369 default:
5370 return -EINVAL;
5371 }
5372
5373#ifdef CONFIG_IPW_PROMISC
Jeff Garzikbf794512005-07-31 13:07:26 -04005374 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06005375 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04005376
5377 if (wrqu->mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06005378 priv->net_dev->type = ARPHRD_IEEE80211;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005379#endif /* CONFIG_IPW_PROMISC */
Jeff Garzikbf794512005-07-31 13:07:26 -04005380
James Ketrenos43f66a62005-03-25 12:31:53 -06005381#ifdef CONFIG_PM
Jeff Garzikbf794512005-07-31 13:07:26 -04005382 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06005383 * flag so ipw_load() will bring in the new firmawre */
5384 if (fw_loaded) {
5385 fw_loaded = 0;
5386 }
5387
5388 release_firmware(bootfw);
5389 release_firmware(ucode);
5390 release_firmware(firmware);
5391 bootfw = ucode = firmware = NULL;
5392#endif
5393
5394 priv->ieee->iw_mode = wrqu->mode;
5395 ipw_adapter_restart(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04005396
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005397 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06005398}
5399
Jeff Garzikbf794512005-07-31 13:07:26 -04005400static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005401 struct iw_request_info *info,
5402 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06005403{
5404 struct ipw_priv *priv = ieee80211_priv(dev);
5405
5406 wrqu->mode = priv->ieee->iw_mode;
5407 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
5408
5409 return 0;
5410}
5411
James Ketrenos43f66a62005-03-25 12:31:53 -06005412#define DEFAULT_RTS_THRESHOLD 2304U
5413#define MIN_RTS_THRESHOLD 1U
5414#define MAX_RTS_THRESHOLD 2304U
5415#define DEFAULT_BEACON_INTERVAL 100U
5416#define DEFAULT_SHORT_RETRY_LIMIT 7U
5417#define DEFAULT_LONG_RETRY_LIMIT 4U
5418
5419/* Values are in microsecond */
5420static const s32 timeout_duration[] = {
5421 350000,
5422 250000,
5423 75000,
5424 37000,
5425 25000,
5426};
5427
5428static const s32 period_duration[] = {
5429 400000,
5430 700000,
5431 1000000,
5432 1000000,
5433 1000000
5434};
5435
Jeff Garzikbf794512005-07-31 13:07:26 -04005436static int ipw_wx_get_range(struct net_device *dev,
5437 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005438 union iwreq_data *wrqu, char *extra)
5439{
5440 struct ipw_priv *priv = ieee80211_priv(dev);
5441 struct iw_range *range = (struct iw_range *)extra;
5442 u16 val;
5443 int i;
5444
5445 wrqu->data.length = sizeof(*range);
5446 memset(range, 0, sizeof(*range));
5447
5448 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04005449 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06005450
5451 range->max_qual.qual = 100;
5452 /* TODO: Find real max RSSI and stick here */
5453 range->max_qual.level = 0;
5454 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005455 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06005456
5457 range->avg_qual.qual = 70;
5458 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005459 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06005460 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005461 range->avg_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06005462
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005463 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005464
Jeff Garzikbf794512005-07-31 13:07:26 -04005465 for (i = 0; i < range->num_bitrates; i++)
5466 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005467 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04005468
James Ketrenos43f66a62005-03-25 12:31:53 -06005469 range->max_rts = DEFAULT_RTS_THRESHOLD;
5470 range->min_frag = MIN_FRAG_THRESHOLD;
5471 range->max_frag = MAX_FRAG_THRESHOLD;
5472
5473 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04005474 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06005475 range->num_encoding_sizes = 2;
5476 range->max_encoding_tokens = WEP_KEYS;
5477
5478 /* Set the Wireless Extension versions */
5479 range->we_version_compiled = WIRELESS_EXT;
5480 range->we_version_source = 16;
5481
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005482 range->num_channels = FREQ_COUNT;
James Ketrenos43f66a62005-03-25 12:31:53 -06005483
5484 val = 0;
5485 for (i = 0; i < FREQ_COUNT; i++) {
5486 range->freq[val].i = i + 1;
5487 range->freq[val].m = ipw_frequencies[i] * 100000;
5488 range->freq[val].e = 1;
5489 val++;
5490
5491 if (val == IW_MAX_FREQUENCIES)
5492 break;
5493 }
5494 range->num_frequency = val;
5495
5496 IPW_DEBUG_WX("GET Range\n");
5497 return 0;
5498}
5499
Jeff Garzikbf794512005-07-31 13:07:26 -04005500static int ipw_wx_set_wap(struct net_device *dev,
5501 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005502 union iwreq_data *wrqu, char *extra)
5503{
5504 struct ipw_priv *priv = ieee80211_priv(dev);
5505
5506 static const unsigned char any[] = {
5507 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
5508 };
5509 static const unsigned char off[] = {
5510 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
5511 };
5512
Jeff Garzikbf794512005-07-31 13:07:26 -04005513 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06005514 return -EINVAL;
5515
5516 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
5517 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
5518 /* we disable mandatory BSSID association */
5519 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
5520 priv->config &= ~CFG_STATIC_BSSID;
5521 if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED |
5522 STATUS_ASSOCIATING))) {
5523 IPW_DEBUG_ASSOC("Attempting to associate with new "
5524 "parameters.\n");
5525 ipw_associate(priv);
5526 }
5527
5528 return 0;
5529 }
5530
5531 priv->config |= CFG_STATIC_BSSID;
5532 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
5533 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
5534 return 0;
5535 }
5536
5537 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
5538 MAC_ARG(wrqu->ap_addr.sa_data));
5539
5540 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
5541
5542 /* If we are currently associated, or trying to associate
5543 * then see if this is a new BSSID (causing us to disassociate) */
5544 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
5545 IPW_DEBUG_ASSOC("Disassociating due to BSSID change.\n");
5546 ipw_disassociate(priv);
5547 } else {
5548 ipw_associate(priv);
5549 }
5550
5551 return 0;
5552}
5553
Jeff Garzikbf794512005-07-31 13:07:26 -04005554static int ipw_wx_get_wap(struct net_device *dev,
5555 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005556 union iwreq_data *wrqu, char *extra)
5557{
5558 struct ipw_priv *priv = ieee80211_priv(dev);
5559 /* If we are associated, trying to associate, or have a statically
5560 * configured BSSID then return that; otherwise return ANY */
Jeff Garzikbf794512005-07-31 13:07:26 -04005561 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005562 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
5563 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
5564 memcpy(wrqu->ap_addr.sa_data, &priv->bssid, ETH_ALEN);
5565 } else
5566 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
5567
5568 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
5569 MAC_ARG(wrqu->ap_addr.sa_data));
5570 return 0;
5571}
5572
Jeff Garzikbf794512005-07-31 13:07:26 -04005573static int ipw_wx_set_essid(struct net_device *dev,
5574 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005575 union iwreq_data *wrqu, char *extra)
5576{
5577 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005578 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06005579 int length = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005580
James Ketrenos43f66a62005-03-25 12:31:53 -06005581 if (wrqu->essid.flags && wrqu->essid.length) {
5582 length = wrqu->essid.length - 1;
5583 essid = extra;
5584 }
5585 if (length == 0) {
5586 IPW_DEBUG_WX("Setting ESSID to ANY\n");
5587 priv->config &= ~CFG_STATIC_ESSID;
5588 if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED |
5589 STATUS_ASSOCIATING))) {
5590 IPW_DEBUG_ASSOC("Attempting to associate with new "
5591 "parameters.\n");
5592 ipw_associate(priv);
5593 }
5594
5595 return 0;
5596 }
5597
5598 length = min(length, IW_ESSID_MAX_SIZE);
5599
5600 priv->config |= CFG_STATIC_ESSID;
5601
5602 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
5603 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
5604 return 0;
5605 }
5606
5607 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
5608 length);
5609
5610 priv->essid_len = length;
5611 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04005612
James Ketrenos43f66a62005-03-25 12:31:53 -06005613 /* If we are currently associated, or trying to associate
5614 * then see if this is a new ESSID (causing us to disassociate) */
5615 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
5616 IPW_DEBUG_ASSOC("Disassociating due to ESSID change.\n");
5617 ipw_disassociate(priv);
5618 } else {
5619 ipw_associate(priv);
5620 }
5621
5622 return 0;
5623}
5624
Jeff Garzikbf794512005-07-31 13:07:26 -04005625static int ipw_wx_get_essid(struct net_device *dev,
5626 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005627 union iwreq_data *wrqu, char *extra)
5628{
5629 struct ipw_priv *priv = ieee80211_priv(dev);
5630
5631 /* If we are associated, trying to associate, or have a statically
5632 * configured ESSID then return that; otherwise return ANY */
5633 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005634 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
5635 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005636 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04005637 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005638 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005639 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06005640 } else {
5641 IPW_DEBUG_WX("Getting essid: ANY\n");
5642 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005643 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06005644 }
5645
5646 return 0;
5647}
5648
Jeff Garzikbf794512005-07-31 13:07:26 -04005649static int ipw_wx_set_nick(struct net_device *dev,
5650 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005651 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04005652{
James Ketrenos43f66a62005-03-25 12:31:53 -06005653 struct ipw_priv *priv = ieee80211_priv(dev);
5654
5655 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
5656 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
5657 return -E2BIG;
5658
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005659 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06005660 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005661 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06005662 IPW_DEBUG_TRACE("<<\n");
5663 return 0;
5664
5665}
5666
Jeff Garzikbf794512005-07-31 13:07:26 -04005667static int ipw_wx_get_nick(struct net_device *dev,
5668 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005669 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04005670{
James Ketrenos43f66a62005-03-25 12:31:53 -06005671 struct ipw_priv *priv = ieee80211_priv(dev);
5672 IPW_DEBUG_WX("Getting nick\n");
5673 wrqu->data.length = strlen(priv->nick) + 1;
5674 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005675 wrqu->data.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06005676 return 0;
5677}
5678
James Ketrenos43f66a62005-03-25 12:31:53 -06005679static int ipw_wx_set_rate(struct net_device *dev,
5680 struct iw_request_info *info,
5681 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04005682{
James Ketrenos43f66a62005-03-25 12:31:53 -06005683 IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu);
Jeff Garzikbf794512005-07-31 13:07:26 -04005684 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06005685}
5686
Jeff Garzikbf794512005-07-31 13:07:26 -04005687static int ipw_wx_get_rate(struct net_device *dev,
5688 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005689 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04005690{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005691 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06005692 wrqu->bitrate.value = priv->last_rate;
5693
5694 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
5695 return 0;
5696}
5697
Jeff Garzikbf794512005-07-31 13:07:26 -04005698static int ipw_wx_set_rts(struct net_device *dev,
5699 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005700 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04005701{
James Ketrenos43f66a62005-03-25 12:31:53 -06005702 struct ipw_priv *priv = ieee80211_priv(dev);
5703
5704 if (wrqu->rts.disabled)
5705 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
5706 else {
5707 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
5708 wrqu->rts.value > MAX_RTS_THRESHOLD)
5709 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04005710
James Ketrenos43f66a62005-03-25 12:31:53 -06005711 priv->rts_threshold = wrqu->rts.value;
5712 }
5713
5714 ipw_send_rts_threshold(priv, priv->rts_threshold);
5715 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
5716 return 0;
5717}
5718
Jeff Garzikbf794512005-07-31 13:07:26 -04005719static int ipw_wx_get_rts(struct net_device *dev,
5720 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005721 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04005722{
James Ketrenos43f66a62005-03-25 12:31:53 -06005723 struct ipw_priv *priv = ieee80211_priv(dev);
5724 wrqu->rts.value = priv->rts_threshold;
5725 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005726 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
James Ketrenos43f66a62005-03-25 12:31:53 -06005727
5728 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
5729 return 0;
5730}
5731
Jeff Garzikbf794512005-07-31 13:07:26 -04005732static int ipw_wx_set_txpow(struct net_device *dev,
5733 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005734 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04005735{
James Ketrenos43f66a62005-03-25 12:31:53 -06005736 struct ipw_priv *priv = ieee80211_priv(dev);
5737 struct ipw_tx_power tx_power;
5738 int i;
5739
5740 if (ipw_radio_kill_sw(priv, wrqu->power.disabled))
5741 return -EINPROGRESS;
5742
5743 if (wrqu->power.flags != IW_TXPOW_DBM)
5744 return -EINVAL;
5745
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005746 if ((wrqu->power.value > 20) || (wrqu->power.value < -12))
James Ketrenos43f66a62005-03-25 12:31:53 -06005747 return -EINVAL;
5748
5749 priv->tx_power = wrqu->power.value;
5750
5751 memset(&tx_power, 0, sizeof(tx_power));
5752
5753 /* configure device for 'G' band */
5754 tx_power.ieee_mode = IPW_G_MODE;
5755 tx_power.num_channels = 11;
5756 for (i = 0; i < 11; i++) {
5757 tx_power.channels_tx_power[i].channel_number = i + 1;
5758 tx_power.channels_tx_power[i].tx_power = priv->tx_power;
5759 }
5760 if (ipw_send_tx_power(priv, &tx_power))
5761 goto error;
5762
5763 /* configure device to also handle 'B' band */
5764 tx_power.ieee_mode = IPW_B_MODE;
5765 if (ipw_send_tx_power(priv, &tx_power))
5766 goto error;
5767
5768 return 0;
5769
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005770 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06005771 return -EIO;
5772}
5773
Jeff Garzikbf794512005-07-31 13:07:26 -04005774static int ipw_wx_get_txpow(struct net_device *dev,
5775 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005776 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04005777{
James Ketrenos43f66a62005-03-25 12:31:53 -06005778 struct ipw_priv *priv = ieee80211_priv(dev);
5779
5780 wrqu->power.value = priv->tx_power;
5781 wrqu->power.fixed = 1;
5782 wrqu->power.flags = IW_TXPOW_DBM;
5783 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
5784
Jeff Garzikbf794512005-07-31 13:07:26 -04005785 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005786 wrqu->power.disabled ? "ON" : "OFF", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06005787
5788 return 0;
5789}
5790
Jeff Garzikbf794512005-07-31 13:07:26 -04005791static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005792 struct iw_request_info *info,
5793 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06005794{
5795 struct ipw_priv *priv = ieee80211_priv(dev);
5796
5797 if (wrqu->frag.disabled)
5798 priv->ieee->fts = DEFAULT_FTS;
5799 else {
5800 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
5801 wrqu->frag.value > MAX_FRAG_THRESHOLD)
5802 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04005803
James Ketrenos43f66a62005-03-25 12:31:53 -06005804 priv->ieee->fts = wrqu->frag.value & ~0x1;
5805 }
5806
5807 ipw_send_frag_threshold(priv, wrqu->frag.value);
5808 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
5809 return 0;
5810}
5811
Jeff Garzikbf794512005-07-31 13:07:26 -04005812static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005813 struct iw_request_info *info,
5814 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06005815{
5816 struct ipw_priv *priv = ieee80211_priv(dev);
5817 wrqu->frag.value = priv->ieee->fts;
5818 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005819 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
James Ketrenos43f66a62005-03-25 12:31:53 -06005820
5821 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
5822
5823 return 0;
5824}
5825
Jeff Garzikbf794512005-07-31 13:07:26 -04005826static int ipw_wx_set_retry(struct net_device *dev,
5827 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005828 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04005829{
James Ketrenos43f66a62005-03-25 12:31:53 -06005830 IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu);
Jeff Garzikbf794512005-07-31 13:07:26 -04005831 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06005832}
5833
Jeff Garzikbf794512005-07-31 13:07:26 -04005834static int ipw_wx_get_retry(struct net_device *dev,
5835 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005836 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04005837{
James Ketrenos43f66a62005-03-25 12:31:53 -06005838 IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu);
Jeff Garzikbf794512005-07-31 13:07:26 -04005839 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06005840}
5841
Jeff Garzikbf794512005-07-31 13:07:26 -04005842static int ipw_wx_set_scan(struct net_device *dev,
5843 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005844 union iwreq_data *wrqu, char *extra)
5845{
5846 struct ipw_priv *priv = ieee80211_priv(dev);
5847 IPW_DEBUG_WX("Start scan\n");
5848 if (ipw_request_scan(priv))
5849 return -EIO;
5850 return 0;
5851}
5852
Jeff Garzikbf794512005-07-31 13:07:26 -04005853static int ipw_wx_get_scan(struct net_device *dev,
5854 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06005855 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04005856{
James Ketrenos43f66a62005-03-25 12:31:53 -06005857 struct ipw_priv *priv = ieee80211_priv(dev);
5858 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
5859}
5860
Jeff Garzikbf794512005-07-31 13:07:26 -04005861static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005862 struct iw_request_info *info,
5863 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06005864{
5865 struct ipw_priv *priv = ieee80211_priv(dev);
5866 return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
5867}
5868
Jeff Garzikbf794512005-07-31 13:07:26 -04005869static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005870 struct iw_request_info *info,
5871 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06005872{
5873 struct ipw_priv *priv = ieee80211_priv(dev);
5874 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
5875}
5876
Jeff Garzikbf794512005-07-31 13:07:26 -04005877static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005878 struct iw_request_info *info,
5879 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06005880{
5881 struct ipw_priv *priv = ieee80211_priv(dev);
5882 int err;
5883
5884 if (wrqu->power.disabled) {
5885 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
5886 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
5887 if (err) {
5888 IPW_DEBUG_WX("failed setting power mode.\n");
5889 return err;
5890 }
5891
5892 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
5893
5894 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005895 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005896
5897 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005898 case IW_POWER_ON: /* If not specified */
5899 case IW_POWER_MODE: /* If set all mask */
5900 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06005901 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005902 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06005903 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
5904 wrqu->power.flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04005905 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06005906 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005907
James Ketrenos43f66a62005-03-25 12:31:53 -06005908 /* If the user hasn't specified a power management mode yet, default
5909 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005910 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06005911 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04005912 else
James Ketrenos43f66a62005-03-25 12:31:53 -06005913 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
5914 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
5915 if (err) {
5916 IPW_DEBUG_WX("failed setting power mode.\n");
5917 return err;
5918 }
5919
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005920 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04005921
James Ketrenos43f66a62005-03-25 12:31:53 -06005922 return 0;
5923}
5924
Jeff Garzikbf794512005-07-31 13:07:26 -04005925static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005926 struct iw_request_info *info,
5927 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06005928{
5929 struct ipw_priv *priv = ieee80211_priv(dev);
5930
5931 if (!(priv->power_mode & IPW_POWER_ENABLED)) {
5932 wrqu->power.disabled = 1;
5933 } else {
5934 wrqu->power.disabled = 0;
5935 }
5936
5937 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04005938
James Ketrenos43f66a62005-03-25 12:31:53 -06005939 return 0;
5940}
5941
Jeff Garzikbf794512005-07-31 13:07:26 -04005942static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005943 struct iw_request_info *info,
5944 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06005945{
5946 struct ipw_priv *priv = ieee80211_priv(dev);
5947 int mode = *(int *)extra;
5948 int err;
Jeff Garzikbf794512005-07-31 13:07:26 -04005949
James Ketrenos43f66a62005-03-25 12:31:53 -06005950 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
5951 mode = IPW_POWER_AC;
5952 priv->power_mode = mode;
5953 } else {
5954 priv->power_mode = IPW_POWER_ENABLED | mode;
5955 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005956
James Ketrenos43f66a62005-03-25 12:31:53 -06005957 if (priv->power_mode != mode) {
5958 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04005959
James Ketrenos43f66a62005-03-25 12:31:53 -06005960 if (err) {
5961 IPW_DEBUG_WX("failed setting power mode.\n");
5962 return err;
5963 }
5964 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005965
James Ketrenos43f66a62005-03-25 12:31:53 -06005966 return 0;
5967}
5968
5969#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04005970static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005971 struct iw_request_info *info,
5972 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06005973{
5974 struct ipw_priv *priv = ieee80211_priv(dev);
5975 int level = IPW_POWER_LEVEL(priv->power_mode);
5976 char *p = extra;
5977
5978 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
5979
5980 switch (level) {
5981 case IPW_POWER_AC:
5982 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
5983 break;
5984 case IPW_POWER_BATTERY:
5985 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
5986 break;
5987 default:
5988 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04005989 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06005990 timeout_duration[level - 1] / 1000,
5991 period_duration[level - 1] / 1000);
5992 }
5993
5994 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005995 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06005996
5997 wrqu->data.length = p - extra + 1;
5998
5999 return 0;
6000}
6001
6002static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006003 struct iw_request_info *info,
6004 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06006005{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006006 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06006007 int mode = *(int *)extra;
6008 u8 band = 0, modulation = 0;
6009
6010 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006011 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06006012 return -EINVAL;
6013 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006014
James Ketrenos43f66a62005-03-25 12:31:53 -06006015 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05006016 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06006017 if (mode & IEEE_A) {
6018 band |= IEEE80211_52GHZ_BAND;
6019 modulation |= IEEE80211_OFDM_MODULATION;
6020 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05006021 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006022 } else {
6023 if (mode & IEEE_A) {
6024 IPW_WARNING("Attempt to set 2200BG into "
6025 "802.11a mode\n");
6026 return -EINVAL;
6027 }
6028
James Ketrenosa33a1982005-09-14 14:28:59 -05006029 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006030 }
6031
6032 if (mode & IEEE_B) {
6033 band |= IEEE80211_24GHZ_BAND;
6034 modulation |= IEEE80211_CCK_MODULATION;
6035 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05006036 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04006037
James Ketrenos43f66a62005-03-25 12:31:53 -06006038 if (mode & IEEE_G) {
6039 band |= IEEE80211_24GHZ_BAND;
6040 modulation |= IEEE80211_OFDM_MODULATION;
6041 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05006042 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006043
6044 priv->ieee->mode = mode;
6045 priv->ieee->freq_band = band;
6046 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006047 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06006048
6049 /* If we are currently associated, or trying to associate
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006050 * then see if this is a new configuration (causing us to
James Ketrenos43f66a62005-03-25 12:31:53 -06006051 * disassociate) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006052 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04006053 /* The resulting association will trigger
James Ketrenos43f66a62005-03-25 12:31:53 -06006054 * the new rates to be sent to the device */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006055 IPW_DEBUG_ASSOC("Disassociating due to mode change.\n");
6056 ipw_disassociate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06006057 } else
6058 ipw_send_supported_rates(priv, &priv->rates);
6059
Jeff Garzikbf794512005-07-31 13:07:26 -04006060 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06006061 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006062 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
James Ketrenos43f66a62005-03-25 12:31:53 -06006063 return 0;
6064}
6065
6066static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006067 struct iw_request_info *info,
6068 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06006069{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006070 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06006071
6072 switch (priv->ieee->freq_band) {
6073 case IEEE80211_24GHZ_BAND:
6074 switch (priv->ieee->modulation) {
6075 case IEEE80211_CCK_MODULATION:
6076 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
6077 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006078 case IEEE80211_OFDM_MODULATION:
James Ketrenos43f66a62005-03-25 12:31:53 -06006079 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
6080 break;
6081 default:
6082 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
6083 break;
6084 }
6085 break;
6086
Jeff Garzikbf794512005-07-31 13:07:26 -04006087 case IEEE80211_52GHZ_BAND:
James Ketrenos43f66a62005-03-25 12:31:53 -06006088 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
6089 break;
6090
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006091 default: /* Mixed Band */
James Ketrenos43f66a62005-03-25 12:31:53 -06006092 switch (priv->ieee->modulation) {
6093 case IEEE80211_CCK_MODULATION:
6094 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
6095 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006096 case IEEE80211_OFDM_MODULATION:
James Ketrenos43f66a62005-03-25 12:31:53 -06006097 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
6098 break;
6099 default:
6100 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
6101 break;
6102 }
6103 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006104 }
6105
James Ketrenos43f66a62005-03-25 12:31:53 -06006106 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
6107
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006108 wrqu->data.length = strlen(extra) + 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06006109
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006110 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006111}
6112
6113#ifdef CONFIG_IPW_PROMISC
Jeff Garzikbf794512005-07-31 13:07:26 -04006114static int ipw_wx_set_promisc(struct net_device *dev,
6115 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006116 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006117{
James Ketrenos43f66a62005-03-25 12:31:53 -06006118 struct ipw_priv *priv = ieee80211_priv(dev);
6119 int *parms = (int *)extra;
6120 int enable = (parms[0] > 0);
6121
6122 IPW_DEBUG_WX("SET PROMISC: %d %d\n", enable, parms[1]);
6123 if (enable) {
6124 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
6125 priv->net_dev->type = ARPHRD_IEEE80211;
6126 ipw_adapter_restart(priv);
6127 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006128
James Ketrenos43f66a62005-03-25 12:31:53 -06006129 ipw_set_channel(priv, parms[1]);
6130 } else {
6131 if (priv->ieee->iw_mode != IW_MODE_MONITOR)
6132 return 0;
6133 priv->net_dev->type = ARPHRD_ETHER;
6134 ipw_adapter_restart(priv);
6135 }
6136 return 0;
6137}
6138
Jeff Garzikbf794512005-07-31 13:07:26 -04006139static int ipw_wx_reset(struct net_device *dev,
6140 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006141 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006142{
James Ketrenos43f66a62005-03-25 12:31:53 -06006143 struct ipw_priv *priv = ieee80211_priv(dev);
6144 IPW_DEBUG_WX("RESET\n");
6145 ipw_adapter_restart(priv);
6146 return 0;
6147}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006148#endif // CONFIG_IPW_PROMISC
James Ketrenos43f66a62005-03-25 12:31:53 -06006149
6150/* Rebase the WE IOCTLs to zero for the handler array */
6151#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006152static iw_handler ipw_wx_handlers[] = {
6153 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
6154 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
6155 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
6156 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
6157 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
6158 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
6159 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
6160 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
6161 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
6162 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
6163 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
6164 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
6165 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
6166 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
6167 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
6168 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
6169 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
6170 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
6171 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
6172 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
6173 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
6174 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
6175 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
6176 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
6177 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
6178 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
6179 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
6180 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenos43f66a62005-03-25 12:31:53 -06006181};
6182
6183#define IPW_PRIV_SET_POWER SIOCIWFIRSTPRIV
6184#define IPW_PRIV_GET_POWER SIOCIWFIRSTPRIV+1
6185#define IPW_PRIV_SET_MODE SIOCIWFIRSTPRIV+2
6186#define IPW_PRIV_GET_MODE SIOCIWFIRSTPRIV+3
6187#define IPW_PRIV_SET_PROMISC SIOCIWFIRSTPRIV+4
6188#define IPW_PRIV_RESET SIOCIWFIRSTPRIV+5
6189
Jeff Garzikbf794512005-07-31 13:07:26 -04006190static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06006191 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006192 .cmd = IPW_PRIV_SET_POWER,
6193 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
6194 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06006195 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006196 .cmd = IPW_PRIV_GET_POWER,
6197 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
6198 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06006199 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006200 .cmd = IPW_PRIV_SET_MODE,
6201 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
6202 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06006203 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006204 .cmd = IPW_PRIV_GET_MODE,
6205 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
6206 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06006207#ifdef CONFIG_IPW_PROMISC
6208 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006209 IPW_PRIV_SET_PROMISC,
6210 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
James Ketrenos43f66a62005-03-25 12:31:53 -06006211 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006212 IPW_PRIV_RESET,
6213 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
6214#endif /* CONFIG_IPW_PROMISC */
James Ketrenos43f66a62005-03-25 12:31:53 -06006215};
6216
6217static iw_handler ipw_priv_handler[] = {
6218 ipw_wx_set_powermode,
6219 ipw_wx_get_powermode,
6220 ipw_wx_set_wireless_mode,
6221 ipw_wx_get_wireless_mode,
6222#ifdef CONFIG_IPW_PROMISC
6223 ipw_wx_set_promisc,
Jeff Garzikbf794512005-07-31 13:07:26 -04006224 ipw_wx_reset,
James Ketrenos43f66a62005-03-25 12:31:53 -06006225#endif
6226};
6227
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006228static struct iw_handler_def ipw_wx_handler_def = {
6229 .standard = ipw_wx_handlers,
6230 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
6231 .num_private = ARRAY_SIZE(ipw_priv_handler),
6232 .num_private_args = ARRAY_SIZE(ipw_priv_args),
6233 .private = ipw_priv_handler,
6234 .private_args = ipw_priv_args,
James Ketrenos43f66a62005-03-25 12:31:53 -06006235};
6236
James Ketrenos43f66a62005-03-25 12:31:53 -06006237/*
6238 * Get wireless statistics.
6239 * Called by /proc/net/wireless
6240 * Also called by SIOCGIWSTATS
6241 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006242static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06006243{
6244 struct ipw_priv *priv = ieee80211_priv(dev);
6245 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04006246
James Ketrenos43f66a62005-03-25 12:31:53 -06006247 wstats = &priv->wstats;
6248
6249 /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
Jeff Garzikbf794512005-07-31 13:07:26 -04006250 * ipw2100_wx_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06006251 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
6252 * and associated; if not associcated, the values are all meaningless
6253 * anyway, so set them all to NULL and INVALID */
6254 if (!(priv->status & STATUS_ASSOCIATED)) {
6255 wstats->miss.beacon = 0;
6256 wstats->discard.retries = 0;
6257 wstats->qual.qual = 0;
6258 wstats->qual.level = 0;
6259 wstats->qual.noise = 0;
6260 wstats->qual.updated = 7;
6261 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006262 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06006263 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04006264 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006265
6266 wstats->qual.qual = priv->quality;
6267 wstats->qual.level = average_value(&priv->average_rssi);
6268 wstats->qual.noise = average_value(&priv->average_noise);
6269 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006270 IW_QUAL_NOISE_UPDATED;
James Ketrenos43f66a62005-03-25 12:31:53 -06006271
6272 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
6273 wstats->discard.retries = priv->last_tx_failures;
6274 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04006275
James Ketrenos43f66a62005-03-25 12:31:53 -06006276/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
6277 goto fail_get_ordinal;
6278 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04006279
James Ketrenos43f66a62005-03-25 12:31:53 -06006280 return wstats;
6281}
6282
James Ketrenos43f66a62005-03-25 12:31:53 -06006283/* net device stuff */
6284
6285static inline void init_sys_config(struct ipw_sys_config *sys_config)
6286{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006287 memset(sys_config, 0, sizeof(struct ipw_sys_config));
6288 sys_config->bt_coexistence = 1; /* We may need to look into prvStaBtConfig */
James Ketrenos43f66a62005-03-25 12:31:53 -06006289 sys_config->answer_broadcast_ssid_probe = 0;
6290 sys_config->accept_all_data_frames = 0;
6291 sys_config->accept_non_directed_frames = 1;
6292 sys_config->exclude_unicast_unencrypted = 0;
6293 sys_config->disable_unicast_decryption = 1;
6294 sys_config->exclude_multicast_unencrypted = 0;
6295 sys_config->disable_multicast_decryption = 1;
6296 sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006297 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -06006298 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04006299 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006300 sys_config->bt_coexist_collision_thr = 0;
6301 sys_config->pass_noise_stats_to_host = 1;
6302}
6303
6304static int ipw_net_open(struct net_device *dev)
6305{
6306 struct ipw_priv *priv = ieee80211_priv(dev);
6307 IPW_DEBUG_INFO("dev->open\n");
6308 /* we should be verifying the device is ready to be opened */
Jeff Garzikbf794512005-07-31 13:07:26 -04006309 if (!(priv->status & STATUS_RF_KILL_MASK) &&
6310 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06006311 netif_start_queue(dev);
6312 return 0;
6313}
6314
6315static int ipw_net_stop(struct net_device *dev)
6316{
6317 IPW_DEBUG_INFO("dev->close\n");
6318 netif_stop_queue(dev);
6319 return 0;
6320}
6321
6322/*
6323todo:
6324
6325modify to send one tfd per fragment instead of using chunking. otherwise
6326we need to heavily modify the ieee80211_skb_to_txb.
6327*/
6328
6329static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
6330{
James Ketrenos0dacca12005-09-21 12:23:41 -05006331 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006332 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -06006333 int i = 0;
6334 struct tfd_frame *tfd;
6335 struct clx2_tx_queue *txq = &priv->txq[0];
6336 struct clx2_queue *q = &txq->q;
6337 u8 id, hdr_len, unicast;
6338 u16 remaining_bytes;
6339
6340 switch (priv->ieee->iw_mode) {
6341 case IW_MODE_ADHOC:
6342 hdr_len = IEEE80211_3ADDR_LEN;
6343 unicast = !is_broadcast_ether_addr(hdr->addr1) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006344 !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -06006345 id = ipw_find_station(priv, hdr->addr1);
6346 if (id == IPW_INVALID_STATION) {
6347 id = ipw_add_station(priv, hdr->addr1);
6348 if (id == IPW_INVALID_STATION) {
6349 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -04006350 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06006351 MAC_ARG(hdr->addr1));
6352 goto drop;
6353 }
6354 }
6355 break;
6356
6357 case IW_MODE_INFRA:
6358 default:
6359 unicast = !is_broadcast_ether_addr(hdr->addr3) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006360 !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -06006361 hdr_len = IEEE80211_3ADDR_LEN;
6362 id = 0;
6363 break;
6364 }
6365
6366 tfd = &txq->bd[q->first_empty];
6367 txq->txb[q->first_empty] = txb;
6368 memset(tfd, 0, sizeof(*tfd));
6369 tfd->u.data.station_number = id;
6370
6371 tfd->control_flags.message_type = TX_FRAME_TYPE;
6372 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
6373
6374 tfd->u.data.cmd_id = DINO_CMD_TX;
6375 tfd->u.data.len = txb->payload_size;
6376 remaining_bytes = txb->payload_size;
6377 if (unlikely(!unicast))
6378 tfd->u.data.tx_flags = DCT_FLAG_NO_WEP;
6379 else
6380 tfd->u.data.tx_flags = DCT_FLAG_NO_WEP | DCT_FLAG_ACK_REQD;
Jeff Garzikbf794512005-07-31 13:07:26 -04006381
James Ketrenos43f66a62005-03-25 12:31:53 -06006382 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
6383 tfd->u.data.tx_flags_ext = DCT_FLAG_EXT_MODE_CCK;
6384 else
6385 tfd->u.data.tx_flags_ext = DCT_FLAG_EXT_MODE_OFDM;
6386
6387 if (priv->config & CFG_PREAMBLE)
6388 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREMBL;
6389
6390 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
6391
6392 /* payload */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006393 tfd->u.data.num_chunks = min((u8) (NUM_TFD_CHUNKS - 2), txb->nr_frags);
James Ketrenos43f66a62005-03-25 12:31:53 -06006394 for (i = 0; i < tfd->u.data.num_chunks; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -04006395 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06006396 i, tfd->u.data.num_chunks,
6397 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04006398 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -06006399 txb->fragments[i]->len - hdr_len);
6400
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006401 tfd->u.data.chunk_ptr[i] =
6402 pci_map_single(priv->pci_dev,
6403 txb->fragments[i]->data + hdr_len,
6404 txb->fragments[i]->len - hdr_len,
6405 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06006406 tfd->u.data.chunk_len[i] = txb->fragments[i]->len - hdr_len;
6407 }
6408
6409 if (i != txb->nr_frags) {
6410 struct sk_buff *skb;
6411 u16 remaining_bytes = 0;
6412 int j;
6413
6414 for (j = i; j < txb->nr_frags; j++)
6415 remaining_bytes += txb->fragments[j]->len - hdr_len;
6416
6417 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
6418 remaining_bytes);
6419 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
6420 if (skb != NULL) {
6421 tfd->u.data.chunk_len[i] = remaining_bytes;
6422 for (j = i; j < txb->nr_frags; j++) {
6423 int size = txb->fragments[j]->len - hdr_len;
6424 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006425 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06006426 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006427 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06006428 }
6429 dev_kfree_skb_any(txb->fragments[i]);
6430 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006431 tfd->u.data.chunk_ptr[i] =
6432 pci_map_single(priv->pci_dev, skb->data,
6433 tfd->u.data.chunk_len[i],
6434 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06006435 tfd->u.data.num_chunks++;
Jeff Garzikbf794512005-07-31 13:07:26 -04006436 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006437 }
6438
6439 /* kick DMA */
6440 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
6441 ipw_write32(priv, q->reg_w, q->first_empty);
6442
Jeff Garzikbf794512005-07-31 13:07:26 -04006443 if (ipw_queue_space(q) < q->high_mark)
James Ketrenos43f66a62005-03-25 12:31:53 -06006444 netif_stop_queue(priv->net_dev);
6445
6446 return;
6447
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006448 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -06006449 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
6450 ieee80211_txb_free(txb);
6451}
6452
6453static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -05006454 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06006455{
6456 struct ipw_priv *priv = ieee80211_priv(dev);
6457 unsigned long flags;
6458
6459 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
6460
6461 spin_lock_irqsave(&priv->lock, flags);
6462
6463 if (!(priv->status & STATUS_ASSOCIATED)) {
6464 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
6465 priv->ieee->stats.tx_carrier_errors++;
6466 netif_stop_queue(dev);
6467 goto fail_unlock;
6468 }
6469
6470 ipw_tx_skb(priv, txb);
6471
6472 spin_unlock_irqrestore(&priv->lock, flags);
6473 return 0;
6474
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006475 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -06006476 spin_unlock_irqrestore(&priv->lock, flags);
6477 return 1;
6478}
6479
6480static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
6481{
6482 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -04006483
James Ketrenos43f66a62005-03-25 12:31:53 -06006484 priv->ieee->stats.tx_packets = priv->tx_packets;
6485 priv->ieee->stats.rx_packets = priv->rx_packets;
6486 return &priv->ieee->stats;
6487}
6488
6489static void ipw_net_set_multicast_list(struct net_device *dev)
6490{
6491
6492}
6493
6494static int ipw_net_set_mac_address(struct net_device *dev, void *p)
6495{
6496 struct ipw_priv *priv = ieee80211_priv(dev);
6497 struct sockaddr *addr = p;
6498 if (!is_valid_ether_addr(addr->sa_data))
6499 return -EADDRNOTAVAIL;
6500 priv->config |= CFG_CUSTOM_MAC;
6501 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
6502 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
6503 priv->net_dev->name, MAC_ARG(priv->mac_addr));
6504 ipw_adapter_restart(priv);
6505 return 0;
6506}
6507
Jeff Garzikbf794512005-07-31 13:07:26 -04006508static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -06006509 struct ethtool_drvinfo *info)
6510{
6511 struct ipw_priv *p = ieee80211_priv(dev);
6512 char vers[64];
6513 char date[32];
6514 u32 len;
6515
6516 strcpy(info->driver, DRV_NAME);
6517 strcpy(info->version, DRV_VERSION);
6518
6519 len = sizeof(vers);
6520 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
6521 len = sizeof(date);
6522 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
6523
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006524 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -06006525 vers, date);
6526 strcpy(info->bus_info, pci_name(p->pci_dev));
6527 info->eedump_len = CX2_EEPROM_IMAGE_SIZE;
6528}
6529
6530static u32 ipw_ethtool_get_link(struct net_device *dev)
6531{
6532 struct ipw_priv *priv = ieee80211_priv(dev);
6533 return (priv->status & STATUS_ASSOCIATED) != 0;
6534}
6535
6536static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
6537{
6538 return CX2_EEPROM_IMAGE_SIZE;
6539}
6540
6541static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006542 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -06006543{
6544 struct ipw_priv *p = ieee80211_priv(dev);
6545
6546 if (eeprom->offset + eeprom->len > CX2_EEPROM_IMAGE_SIZE)
6547 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04006548
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006549 memcpy(bytes, &((u8 *) p->eeprom)[eeprom->offset], eeprom->len);
James Ketrenos43f66a62005-03-25 12:31:53 -06006550 return 0;
6551}
6552
6553static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006554 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -06006555{
6556 struct ipw_priv *p = ieee80211_priv(dev);
6557 int i;
6558
6559 if (eeprom->offset + eeprom->len > CX2_EEPROM_IMAGE_SIZE)
6560 return -EINVAL;
6561
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006562 memcpy(&((u8 *) p->eeprom)[eeprom->offset], bytes, eeprom->len);
Jeff Garzikbf794512005-07-31 13:07:26 -04006563 for (i = IPW_EEPROM_DATA;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006564 i < IPW_EEPROM_DATA + CX2_EEPROM_IMAGE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06006565 ipw_write8(p, i, p->eeprom[i]);
6566
6567 return 0;
6568}
6569
6570static struct ethtool_ops ipw_ethtool_ops = {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006571 .get_link = ipw_ethtool_get_link,
6572 .get_drvinfo = ipw_ethtool_get_drvinfo,
6573 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
6574 .get_eeprom = ipw_ethtool_get_eeprom,
6575 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -06006576};
6577
6578static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
6579{
6580 struct ipw_priv *priv = data;
6581 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -04006582
James Ketrenos43f66a62005-03-25 12:31:53 -06006583 if (!priv)
6584 return IRQ_NONE;
6585
6586 spin_lock(&priv->lock);
6587
6588 if (!(priv->status & STATUS_INT_ENABLED)) {
6589 /* Shared IRQ */
6590 goto none;
6591 }
6592
6593 inta = ipw_read32(priv, CX2_INTA_RW);
6594 inta_mask = ipw_read32(priv, CX2_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -04006595
James Ketrenos43f66a62005-03-25 12:31:53 -06006596 if (inta == 0xFFFFFFFF) {
6597 /* Hardware disappeared */
6598 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
6599 goto none;
6600 }
6601
6602 if (!(inta & (CX2_INTA_MASK_ALL & inta_mask))) {
6603 /* Shared interrupt */
6604 goto none;
6605 }
6606
6607 /* tell the device to stop sending interrupts */
6608 ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04006609
James Ketrenos43f66a62005-03-25 12:31:53 -06006610 /* ack current interrupts */
6611 inta &= (CX2_INTA_MASK_ALL & inta_mask);
6612 ipw_write32(priv, CX2_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -04006613
James Ketrenos43f66a62005-03-25 12:31:53 -06006614 /* Cache INTA value for our tasklet */
6615 priv->isr_inta = inta;
6616
6617 tasklet_schedule(&priv->irq_tasklet);
6618
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006619 spin_unlock(&priv->lock);
James Ketrenos43f66a62005-03-25 12:31:53 -06006620
6621 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006622 none:
James Ketrenos43f66a62005-03-25 12:31:53 -06006623 spin_unlock(&priv->lock);
6624 return IRQ_NONE;
6625}
6626
6627static void ipw_rf_kill(void *adapter)
6628{
6629 struct ipw_priv *priv = adapter;
6630 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -04006631
James Ketrenos43f66a62005-03-25 12:31:53 -06006632 spin_lock_irqsave(&priv->lock, flags);
6633
6634 if (rf_kill_active(priv)) {
6635 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
6636 if (priv->workqueue)
6637 queue_delayed_work(priv->workqueue,
6638 &priv->rf_kill, 2 * HZ);
6639 goto exit_unlock;
6640 }
6641
6642 /* RF Kill is now disabled, so bring the device back up */
6643
6644 if (!(priv->status & STATUS_RF_KILL_MASK)) {
6645 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
6646 "device\n");
6647
6648 /* we can not do an adapter restart while inside an irq lock */
6649 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -04006650 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06006651 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
6652 "enabled\n");
6653
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006654 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -06006655 spin_unlock_irqrestore(&priv->lock, flags);
6656}
6657
6658static int ipw_setup_deferred_work(struct ipw_priv *priv)
6659{
6660 int ret = 0;
6661
James Ketrenos43f66a62005-03-25 12:31:53 -06006662 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -06006663 init_waitqueue_head(&priv->wait_command_queue);
6664
6665 INIT_WORK(&priv->adhoc_check, ipw_adhoc_check, priv);
6666 INIT_WORK(&priv->associate, ipw_associate, priv);
6667 INIT_WORK(&priv->disassociate, ipw_disassociate, priv);
6668 INIT_WORK(&priv->rx_replenish, ipw_rx_queue_replenish, priv);
6669 INIT_WORK(&priv->adapter_restart, ipw_adapter_restart, priv);
6670 INIT_WORK(&priv->rf_kill, ipw_rf_kill, priv);
6671 INIT_WORK(&priv->up, (void (*)(void *))ipw_up, priv);
6672 INIT_WORK(&priv->down, (void (*)(void *))ipw_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04006673 INIT_WORK(&priv->request_scan,
James Ketrenos43f66a62005-03-25 12:31:53 -06006674 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04006675 INIT_WORK(&priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06006676 (void (*)(void *))ipw_gather_stats, priv);
6677 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_abort_scan, priv);
6678 INIT_WORK(&priv->roam, ipw_roam, priv);
6679 INIT_WORK(&priv->scan_check, ipw_scan_check, priv);
6680
6681 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
6682 ipw_irq_tasklet, (unsigned long)priv);
6683
6684 return ret;
6685}
6686
James Ketrenos43f66a62005-03-25 12:31:53 -06006687static void shim__set_security(struct net_device *dev,
6688 struct ieee80211_security *sec)
6689{
6690 struct ipw_priv *priv = ieee80211_priv(dev);
6691 int i;
6692
Jeff Garzikbf794512005-07-31 13:07:26 -04006693 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006694 if (sec->flags & (1 << i)) {
6695 priv->sec.key_sizes[i] = sec->key_sizes[i];
6696 if (sec->key_sizes[i] == 0)
6697 priv->sec.flags &= ~(1 << i);
6698 else
Jeff Garzikbf794512005-07-31 13:07:26 -04006699 memcpy(priv->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -06006700 sec->key_sizes[i]);
6701 priv->sec.flags |= (1 << i);
6702 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -04006703 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006704 }
6705
6706 if ((sec->flags & SEC_ACTIVE_KEY) &&
6707 priv->sec.active_key != sec->active_key) {
6708 if (sec->active_key <= 3) {
6709 priv->sec.active_key = sec->active_key;
6710 priv->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -04006711 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06006712 priv->sec.flags &= ~SEC_ACTIVE_KEY;
6713 priv->status |= STATUS_SECURITY_UPDATED;
6714 }
6715
6716 if ((sec->flags & SEC_AUTH_MODE) &&
6717 (priv->sec.auth_mode != sec->auth_mode)) {
6718 priv->sec.auth_mode = sec->auth_mode;
6719 priv->sec.flags |= SEC_AUTH_MODE;
6720 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
6721 priv->capability |= CAP_SHARED_KEY;
6722 else
6723 priv->capability &= ~CAP_SHARED_KEY;
6724 priv->status |= STATUS_SECURITY_UPDATED;
6725 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006726
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006727 if (sec->flags & SEC_ENABLED && priv->sec.enabled != sec->enabled) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006728 priv->sec.flags |= SEC_ENABLED;
6729 priv->sec.enabled = sec->enabled;
6730 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -04006731 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06006732 priv->capability |= CAP_PRIVACY_ON;
6733 else
6734 priv->capability &= ~CAP_PRIVACY_ON;
6735 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006736
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006737 if (sec->flags & SEC_LEVEL && priv->sec.level != sec->level) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006738 priv->sec.level = sec->level;
6739 priv->sec.flags |= SEC_LEVEL;
6740 priv->status |= STATUS_SECURITY_UPDATED;
6741 }
6742
Jeff Garzikbf794512005-07-31 13:07:26 -04006743 /* To match current functionality of ipw2100 (which works well w/
6744 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -06006745 * privacy capability changes ... */
6746#if 0
6747 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -04006748 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -06006749 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04006750 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006751 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006752 IPW_DEBUG_ASSOC("Disassociating due to capability "
6753 "change.\n");
6754 ipw_disassociate(priv);
6755 }
6756#endif
6757}
6758
Jeff Garzikbf794512005-07-31 13:07:26 -04006759static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06006760 struct ipw_supported_rates *rates)
6761{
6762 /* TODO: Mask out rates based on priv->rates_mask */
6763
6764 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006765 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -06006766 switch (priv->ieee->freq_band) {
6767 case IEEE80211_52GHZ_BAND:
6768 rates->ieee_mode = IPW_A_MODE;
6769 rates->purpose = IPW_RATE_CAPABILITIES;
6770 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
6771 IEEE80211_OFDM_DEFAULT_RATES_MASK);
6772 break;
6773
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006774 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -06006775 rates->ieee_mode = IPW_G_MODE;
6776 rates->purpose = IPW_RATE_CAPABILITIES;
6777 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
6778 IEEE80211_CCK_DEFAULT_RATES_MASK);
6779 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
6780 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
6781 IEEE80211_OFDM_DEFAULT_RATES_MASK);
6782 }
6783 break;
6784 }
6785
6786 return 0;
6787}
6788
Jeff Garzikbf794512005-07-31 13:07:26 -04006789static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06006790{
6791 int i;
6792 struct ipw_tx_power tx_power;
6793
6794 memset(&priv->sys_config, 0, sizeof(priv->sys_config));
6795 memset(&tx_power, 0, sizeof(tx_power));
6796
6797 /* This is only called from ipw_up, which resets/reloads the firmware
6798 so, we don't need to first disable the card before we configure
6799 it */
6800
6801 /* configure device for 'G' band */
6802 tx_power.ieee_mode = IPW_G_MODE;
6803 tx_power.num_channels = 11;
6804 for (i = 0; i < 11; i++) {
6805 tx_power.channels_tx_power[i].channel_number = i + 1;
6806 tx_power.channels_tx_power[i].tx_power = priv->tx_power;
6807 }
6808 if (ipw_send_tx_power(priv, &tx_power))
6809 goto error;
6810
6811 /* configure device to also handle 'B' band */
6812 tx_power.ieee_mode = IPW_B_MODE;
6813 if (ipw_send_tx_power(priv, &tx_power))
6814 goto error;
6815
6816 /* initialize adapter address */
6817 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
6818 goto error;
6819
6820 /* set basic system config settings */
6821 init_sys_config(&priv->sys_config);
6822 if (ipw_send_system_config(priv, &priv->sys_config))
6823 goto error;
6824
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006825 init_supported_rates(priv, &priv->rates);
6826 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -06006827 goto error;
6828
6829 /* Set request-to-send threshold */
6830 if (priv->rts_threshold) {
6831 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
6832 goto error;
6833 }
6834
6835 if (ipw_set_random_seed(priv))
6836 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04006837
James Ketrenos43f66a62005-03-25 12:31:53 -06006838 /* final state transition to the RUN state */
6839 if (ipw_send_host_complete(priv))
6840 goto error;
6841
6842 /* If configured to try and auto-associate, kick off a scan */
6843 if ((priv->config & CFG_ASSOCIATE) && ipw_request_scan(priv))
6844 goto error;
6845
6846 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04006847
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006848 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06006849 return -EIO;
6850}
6851
6852#define MAX_HW_RESTARTS 5
6853static int ipw_up(struct ipw_priv *priv)
6854{
6855 int rc, i;
6856
6857 if (priv->status & STATUS_EXIT_PENDING)
6858 return -EIO;
6859
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006860 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -04006861 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -06006862 * Also start the clocks. */
6863 rc = ipw_load(priv);
6864 if (rc) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006865 IPW_ERROR("Unable to load firmware: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06006866 return rc;
6867 }
6868
6869 ipw_init_ordinals(priv);
6870 if (!(priv->config & CFG_CUSTOM_MAC))
6871 eeprom_parse_mac(priv, priv->mac_addr);
6872 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
6873
6874 if (priv->status & STATUS_RF_KILL_MASK)
6875 return 0;
6876
6877 rc = ipw_config(priv);
6878 if (!rc) {
6879 IPW_DEBUG_INFO("Configured device on count %i\n", i);
6880 priv->notif_missed_beacons = 0;
6881 netif_start_queue(priv->net_dev);
6882 return 0;
6883 } else {
6884 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n",
6885 rc);
6886 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006887
James Ketrenos43f66a62005-03-25 12:31:53 -06006888 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
6889 i, MAX_HW_RESTARTS);
6890
6891 /* We had an error bringing up the hardware, so take it
6892 * all the way back down so we can try again */
6893 ipw_down(priv);
6894 }
6895
Jeff Garzikbf794512005-07-31 13:07:26 -04006896 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -06006897 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006898 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenos43f66a62005-03-25 12:31:53 -06006899 return -EIO;
6900}
6901
6902static void ipw_down(struct ipw_priv *priv)
6903{
6904 /* Attempt to disable the card */
6905#if 0
6906 ipw_send_card_disable(priv, 0);
6907#endif
6908
6909 /* tell the device to stop sending interrupts */
6910 ipw_disable_interrupts(priv);
6911
6912 /* Clear all bits but the RF Kill */
6913 priv->status &= STATUS_RF_KILL_MASK;
6914
6915 netif_carrier_off(priv->net_dev);
6916 netif_stop_queue(priv->net_dev);
6917
6918 ipw_stop_nic(priv);
6919}
6920
6921/* Called by register_netdev() */
6922static int ipw_net_init(struct net_device *dev)
6923{
6924 struct ipw_priv *priv = ieee80211_priv(dev);
6925
6926 if (priv->status & STATUS_RF_KILL_SW) {
6927 IPW_WARNING("Radio disabled by module parameter.\n");
6928 return 0;
6929 } else if (rf_kill_active(priv)) {
6930 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
6931 "Kill switch must be turned off for "
6932 "wireless networking to work.\n");
6933 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
6934 return 0;
6935 }
6936
6937 if (ipw_up(priv))
6938 return -EIO;
6939
6940 return 0;
6941}
6942
6943/* PCI driver stuff */
6944static struct pci_device_id card_ids[] = {
6945 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
6946 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
6947 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
6948 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
6949 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
6950 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
6951 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
6952 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
6953 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
6954 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
6955 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
6956 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
6957 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
6958 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
6959 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
6960 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
6961 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
6962 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006963 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
6964 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* 2225BG */
6965 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
6966 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -04006967
James Ketrenos43f66a62005-03-25 12:31:53 -06006968 /* required last entry */
6969 {0,}
6970};
6971
6972MODULE_DEVICE_TABLE(pci, card_ids);
6973
6974static struct attribute *ipw_sysfs_entries[] = {
6975 &dev_attr_rf_kill.attr,
6976 &dev_attr_direct_dword.attr,
6977 &dev_attr_indirect_byte.attr,
6978 &dev_attr_indirect_dword.attr,
6979 &dev_attr_mem_gpio_reg.attr,
6980 &dev_attr_command_event_reg.attr,
6981 &dev_attr_nic_type.attr,
6982 &dev_attr_status.attr,
6983 &dev_attr_cfg.attr,
6984 &dev_attr_dump_errors.attr,
6985 &dev_attr_dump_events.attr,
6986 &dev_attr_eeprom_delay.attr,
6987 &dev_attr_ucode_version.attr,
6988 &dev_attr_rtc.attr,
6989 NULL
6990};
6991
6992static struct attribute_group ipw_attribute_group = {
6993 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006994 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -06006995};
6996
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006997static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -06006998{
6999 int err = 0;
7000 struct net_device *net_dev;
7001 void __iomem *base;
7002 u32 length, val;
7003 struct ipw_priv *priv;
7004 int band, modulation;
7005
7006 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
7007 if (net_dev == NULL) {
7008 err = -ENOMEM;
7009 goto out;
7010 }
7011
7012 priv = ieee80211_priv(net_dev);
7013 priv->ieee = netdev_priv(net_dev);
7014 priv->net_dev = net_dev;
7015 priv->pci_dev = pdev;
7016#ifdef CONFIG_IPW_DEBUG
7017 ipw_debug_level = debug;
7018#endif
7019 spin_lock_init(&priv->lock);
7020
7021 if (pci_enable_device(pdev)) {
7022 err = -ENODEV;
7023 goto out_free_ieee80211;
7024 }
7025
7026 pci_set_master(pdev);
7027
Tobias Klauser0e08b442005-06-20 14:28:41 -07007028 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -04007029 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -07007030 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -06007031 if (err) {
7032 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
7033 goto out_pci_disable_device;
7034 }
7035
7036 pci_set_drvdata(pdev, priv);
7037
7038 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -04007039 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -06007040 goto out_pci_disable_device;
7041
Jeff Garzikbf794512005-07-31 13:07:26 -04007042 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -06007043 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -04007044 pci_read_config_dword(pdev, 0x40, &val);
7045 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06007046 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -04007047
James Ketrenos43f66a62005-03-25 12:31:53 -06007048 length = pci_resource_len(pdev, 0);
7049 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -04007050
James Ketrenos43f66a62005-03-25 12:31:53 -06007051 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
7052 if (!base) {
7053 err = -ENODEV;
7054 goto out_pci_release_regions;
7055 }
7056
7057 priv->hw_base = base;
7058 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
7059 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
7060
7061 err = ipw_setup_deferred_work(priv);
7062 if (err) {
7063 IPW_ERROR("Unable to setup deferred work\n");
7064 goto out_iounmap;
7065 }
7066
7067 /* Initialize module parameter values here */
7068 if (ifname)
7069 strncpy(net_dev->name, ifname, IFNAMSIZ);
7070
Jeff Garzikbf794512005-07-31 13:07:26 -04007071 if (associate)
James Ketrenos43f66a62005-03-25 12:31:53 -06007072 priv->config |= CFG_ASSOCIATE;
7073 else
7074 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04007075
7076 if (auto_create)
James Ketrenos43f66a62005-03-25 12:31:53 -06007077 priv->config |= CFG_ADHOC_CREATE;
7078 else
7079 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04007080
James Ketrenos43f66a62005-03-25 12:31:53 -06007081 if (disable) {
7082 priv->status |= STATUS_RF_KILL_SW;
7083 IPW_DEBUG_INFO("Radio disabled.\n");
7084 }
7085
7086 if (channel != 0) {
7087 priv->config |= CFG_STATIC_CHANNEL;
7088 priv->channel = channel;
7089 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007090 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06007091 /* TODO: Validate that provided channel is in range */
7092 }
7093
7094 switch (mode) {
7095 case 1:
7096 priv->ieee->iw_mode = IW_MODE_ADHOC;
7097 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04007098#ifdef CONFIG_IPW_PROMISC
James Ketrenos43f66a62005-03-25 12:31:53 -06007099 case 2:
7100 priv->ieee->iw_mode = IW_MODE_MONITOR;
7101 break;
7102#endif
7103 default:
7104 case 0:
7105 priv->ieee->iw_mode = IW_MODE_INFRA;
7106 break;
7107 }
7108
7109 if ((priv->pci_dev->device == 0x4223) ||
7110 (priv->pci_dev->device == 0x4224)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007111 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06007112 ": Detected Intel PRO/Wireless 2915ABG Network "
7113 "Connection\n");
James Ketrenosa33a1982005-09-14 14:28:59 -05007114 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007115 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
7116 modulation = IEEE80211_OFDM_MODULATION |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007117 IEEE80211_CCK_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06007118 priv->adapter = IPW_2915ABG;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007119 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06007120 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04007121 if (priv->pci_dev->device == 0x4221)
7122 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06007123 ": Detected Intel PRO/Wireless 2225BG Network "
7124 "Connection\n");
7125 else
Jeff Garzikbf794512005-07-31 13:07:26 -04007126 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06007127 ": Detected Intel PRO/Wireless 2200BG Network "
7128 "Connection\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04007129
James Ketrenosa33a1982005-09-14 14:28:59 -05007130 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007131 band = IEEE80211_24GHZ_BAND;
7132 modulation = IEEE80211_OFDM_MODULATION |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007133 IEEE80211_CCK_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06007134 priv->adapter = IPW_2200BG;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007135 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06007136 }
7137
7138 priv->ieee->freq_band = band;
7139 priv->ieee->modulation = modulation;
7140
7141 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
7142
7143 priv->missed_beacon_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
7144 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
7145
7146 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
7147
7148 /* If power management is turned on, default to AC mode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007149 priv->power_mode = IPW_POWER_AC;
James Ketrenos43f66a62005-03-25 12:31:53 -06007150 priv->tx_power = IPW_DEFAULT_TX_POWER;
7151
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007152 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007153 if (err) {
7154 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
7155 goto out_destroy_workqueue;
7156 }
7157
7158 SET_MODULE_OWNER(net_dev);
7159 SET_NETDEV_DEV(net_dev, &pdev->dev);
7160
7161 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
7162 priv->ieee->set_security = shim__set_security;
7163
7164 net_dev->open = ipw_net_open;
7165 net_dev->stop = ipw_net_stop;
7166 net_dev->init = ipw_net_init;
7167 net_dev->get_stats = ipw_net_get_stats;
7168 net_dev->set_multicast_list = ipw_net_set_multicast_list;
7169 net_dev->set_mac_address = ipw_net_set_mac_address;
7170 net_dev->get_wireless_stats = ipw_get_wireless_stats;
7171 net_dev->wireless_handlers = &ipw_wx_handler_def;
7172 net_dev->ethtool_ops = &ipw_ethtool_ops;
7173 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007174 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -06007175 net_dev->mem_start = pci_resource_start(pdev, 0);
7176 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
7177
7178 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
7179 if (err) {
7180 IPW_ERROR("failed to create sysfs device attributes\n");
7181 goto out_release_irq;
7182 }
7183
7184 err = register_netdev(net_dev);
7185 if (err) {
7186 IPW_ERROR("failed to register network device\n");
7187 goto out_remove_group;
7188 }
7189
7190 return 0;
7191
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007192 out_remove_group:
James Ketrenos43f66a62005-03-25 12:31:53 -06007193 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007194 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -06007195 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007196 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -06007197 destroy_workqueue(priv->workqueue);
7198 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007199 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -06007200 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007201 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -06007202 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007203 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -06007204 pci_disable_device(pdev);
7205 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007206 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -06007207 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007208 out:
James Ketrenos43f66a62005-03-25 12:31:53 -06007209 return err;
7210}
7211
7212static void ipw_pci_remove(struct pci_dev *pdev)
7213{
7214 struct ipw_priv *priv = pci_get_drvdata(pdev);
7215 if (!priv)
7216 return;
7217
7218 priv->status |= STATUS_EXIT_PENDING;
7219
7220 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
7221
7222 ipw_down(priv);
7223
7224 unregister_netdev(priv->net_dev);
7225
7226 if (priv->rxq) {
7227 ipw_rx_queue_free(priv, priv->rxq);
7228 priv->rxq = NULL;
7229 }
7230 ipw_tx_queue_free(priv);
7231
7232 /* ipw_down will ensure that there is no more pending work
7233 * in the workqueue's, so we can safely remove them now. */
Jeff Garzikbf794512005-07-31 13:07:26 -04007234 if (priv->workqueue) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007235 cancel_delayed_work(&priv->adhoc_check);
7236 cancel_delayed_work(&priv->gather_stats);
7237 cancel_delayed_work(&priv->request_scan);
7238 cancel_delayed_work(&priv->rf_kill);
7239 cancel_delayed_work(&priv->scan_check);
7240 destroy_workqueue(priv->workqueue);
7241 priv->workqueue = NULL;
7242 }
7243
7244 free_irq(pdev->irq, priv);
7245 iounmap(priv->hw_base);
7246 pci_release_regions(pdev);
7247 pci_disable_device(pdev);
7248 pci_set_drvdata(pdev, NULL);
7249 free_ieee80211(priv->net_dev);
7250
7251#ifdef CONFIG_PM
7252 if (fw_loaded) {
7253 release_firmware(bootfw);
7254 release_firmware(ucode);
7255 release_firmware(firmware);
7256 fw_loaded = 0;
7257 }
7258#endif
7259}
7260
James Ketrenos43f66a62005-03-25 12:31:53 -06007261#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -07007262static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -06007263{
7264 struct ipw_priv *priv = pci_get_drvdata(pdev);
7265 struct net_device *dev = priv->net_dev;
7266
7267 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
7268
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007269 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -06007270 ipw_down(priv);
7271
7272 /* Remove the PRESENT state of the device */
7273 netif_device_detach(dev);
7274
James Ketrenos43f66a62005-03-25 12:31:53 -06007275 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -06007276 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -07007277 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -04007278
James Ketrenos43f66a62005-03-25 12:31:53 -06007279 return 0;
7280}
7281
7282static int ipw_pci_resume(struct pci_dev *pdev)
7283{
7284 struct ipw_priv *priv = pci_get_drvdata(pdev);
7285 struct net_device *dev = priv->net_dev;
7286 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -04007287
James Ketrenos43f66a62005-03-25 12:31:53 -06007288 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
7289
7290 pci_set_power_state(pdev, 0);
7291 pci_enable_device(pdev);
7292#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
7293 pci_restore_state(pdev, priv->pm_state);
7294#else
7295 pci_restore_state(pdev);
7296#endif
7297 /*
7298 * Suspend/Resume resets the PCI configuration space, so we have to
7299 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
7300 * from interfering with C3 CPU state. pci_restore_state won't help
7301 * here since it only restores the first 64 bytes pci config header.
7302 */
Jeff Garzikbf794512005-07-31 13:07:26 -04007303 pci_read_config_dword(pdev, 0x40, &val);
7304 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06007305 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
7306
7307 /* Set the device back into the PRESENT state; this will also wake
7308 * the queue of needed */
7309 netif_device_attach(dev);
7310
7311 /* Bring the device back up */
7312 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -04007313
James Ketrenos43f66a62005-03-25 12:31:53 -06007314 return 0;
7315}
7316#endif
7317
7318/* driver initialization stuff */
7319static struct pci_driver ipw_driver = {
7320 .name = DRV_NAME,
7321 .id_table = card_ids,
7322 .probe = ipw_pci_probe,
7323 .remove = __devexit_p(ipw_pci_remove),
7324#ifdef CONFIG_PM
7325 .suspend = ipw_pci_suspend,
7326 .resume = ipw_pci_resume,
7327#endif
7328};
7329
7330static int __init ipw_init(void)
7331{
7332 int ret;
7333
7334 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
7335 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
7336
7337 ret = pci_module_init(&ipw_driver);
7338 if (ret) {
7339 IPW_ERROR("Unable to initialize PCI module\n");
7340 return ret;
7341 }
7342
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007343 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -06007344 if (ret) {
7345 IPW_ERROR("Unable to create driver sysfs file\n");
7346 pci_unregister_driver(&ipw_driver);
7347 return ret;
7348 }
7349
7350 return ret;
7351}
7352
7353static void __exit ipw_exit(void)
7354{
7355 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
7356 pci_unregister_driver(&ipw_driver);
7357}
7358
7359module_param(disable, int, 0444);
7360MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
7361
7362module_param(associate, int, 0444);
7363MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
7364
7365module_param(auto_create, int, 0444);
7366MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
7367
7368module_param(debug, int, 0444);
7369MODULE_PARM_DESC(debug, "debug output mask");
7370
7371module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -04007372MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -06007373
7374module_param(ifname, charp, 0444);
7375MODULE_PARM_DESC(ifname, "network device name (default eth%d)");
7376
Jeff Garzikbf794512005-07-31 13:07:26 -04007377#ifdef CONFIG_IPW_PROMISC
James Ketrenos43f66a62005-03-25 12:31:53 -06007378module_param(mode, int, 0444);
7379MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
7380#else
7381module_param(mode, int, 0444);
7382MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
7383#endif
7384
7385module_exit(ipw_exit);
7386module_init(ipw_init);