blob: ea7a3dcf1daa8352b97ba23712050dc8880ef040 [file] [log] [blame]
James Ketrenos43f66a62005-03-25 12:31:53 -06001/******************************************************************************
Jeff Garzikbf794512005-07-31 13:07:26 -04002
James Ketrenos43f66a62005-03-25 12:31:53 -06003 Copyright(c) 2003 - 2004 Intel Corporation. All rights reserved.
4
5 802.11 status code portion of this file from ethereal-0.10.6:
6 Copyright 2000, Axis Communications AB
7 Ethereal - Network traffic analyzer
8 By Gerald Combs <gerald@ethereal.com>
9 Copyright 1998 Gerald Combs
10
Jeff Garzikbf794512005-07-31 13:07:26 -040011 This program is free software; you can redistribute it and/or modify it
12 under the terms of version 2 of the GNU General Public License as
James Ketrenos43f66a62005-03-25 12:31:53 -060013 published by the Free Software Foundation.
Jeff Garzikbf794512005-07-31 13:07:26 -040014
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
James Ketrenos43f66a62005-03-25 12:31:53 -060018 more details.
Jeff Garzikbf794512005-07-31 13:07:26 -040019
James Ketrenos43f66a62005-03-25 12:31:53 -060020 You should have received a copy of the GNU General Public License along with
Jeff Garzikbf794512005-07-31 13:07:26 -040021 this program; if not, write to the Free Software Foundation, Inc., 59
James Ketrenos43f66a62005-03-25 12:31:53 -060022 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Jeff Garzikbf794512005-07-31 13:07:26 -040023
James Ketrenos43f66a62005-03-25 12:31:53 -060024 The full GNU General Public License is included in this distribution in the
25 file called LICENSE.
Jeff Garzikbf794512005-07-31 13:07:26 -040026
James Ketrenos43f66a62005-03-25 12:31:53 -060027 Contact Information:
28 James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30
31******************************************************************************/
32
33#include "ipw2200.h"
34
James Ketrenosa613bff2005-08-24 21:43:11 -050035#define IPW2200_VERSION "1.0.2"
James Ketrenos43f66a62005-03-25 12:31:53 -060036#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
37#define DRV_COPYRIGHT "Copyright(c) 2003-2004 Intel Corporation"
38#define DRV_VERSION IPW2200_VERSION
39
40MODULE_DESCRIPTION(DRV_DESCRIPTION);
41MODULE_VERSION(DRV_VERSION);
42MODULE_AUTHOR(DRV_COPYRIGHT);
43MODULE_LICENSE("GPL");
44
45static int debug = 0;
46static int channel = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060047static int mode = 0;
48
49static u32 ipw_debug_level;
50static int associate = 1;
51static int auto_create = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -050052static int led = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060053static 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;
James Ketrenos43f66a62005-03-25 12:31:53 -0600292 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400293
James Ketrenos43f66a62005-03-25 12:31:53 -0600294 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
295
James Ketrenosea2b26e2005-08-24 21:25:16 -0500296 if (num <= 0) {
297 return;
298 }
299
James Ketrenos43f66a62005-03-25 12:31:53 -0600300 /* Read the first nibble byte by byte */
301 if (unlikely(dif_len)) {
James Ketrenos43f66a62005-03-25 12:31:53 -0600302 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500303 /* Start reading at aligned_addr + dif_len */
304 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
305 *buf++ = _ipw_read8(priv, CX2_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600306 aligned_addr += 4;
307 }
308
James Ketrenos43f66a62005-03-25 12:31:53 -0600309 _ipw_write32(priv, CX2_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500310 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
311 *(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 */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500314 if (unlikely(num)) {
315 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
316 for (i = 0; num > 0; i++, num--)
317 *buf++ = ipw_read8(priv, CX2_INDIRECT_DATA + i);
318 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600319}
320
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400321static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600322 int num)
323{
324 u32 aligned_addr = addr & CX2_INDIRECT_ADDR_MASK;
325 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600326 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 Ketrenosea2b26e2005-08-24 21:25:16 -0500330 if (num <= 0) {
331 return;
332 }
333
James Ketrenos43f66a62005-03-25 12:31:53 -0600334 /* Write the first nibble byte by byte */
335 if (unlikely(dif_len)) {
James Ketrenos43f66a62005-03-25 12:31:53 -0600336 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500337 /* Start reading at aligned_addr + dif_len */
338 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenos43f66a62005-03-25 12:31:53 -0600339 _ipw_write8(priv, CX2_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600340 aligned_addr += 4;
341 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400342
James Ketrenos43f66a62005-03-25 12:31:53 -0600343 _ipw_write32(priv, CX2_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500344 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400345 _ipw_write32(priv, CX2_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400346
James Ketrenos43f66a62005-03-25 12:31:53 -0600347 /* Copy the last nibble */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500348 if (unlikely(num)) {
349 _ipw_write32(priv, CX2_INDIRECT_ADDR, aligned_addr);
350 for (i = 0; num > 0; i++, num--, buf++)
351 _ipw_write8(priv, CX2_INDIRECT_DATA + i, *buf);
352 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600353}
354
Jeff Garzikbf794512005-07-31 13:07:26 -0400355static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600356 int num)
357{
358 memcpy_toio((priv->hw_base + addr), buf, num);
359}
360
361static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
362{
363 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
364}
365
366static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
367{
368 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
369}
370
371static inline void ipw_enable_interrupts(struct ipw_priv *priv)
372{
373 if (priv->status & STATUS_INT_ENABLED)
374 return;
375 priv->status |= STATUS_INT_ENABLED;
376 ipw_write32(priv, CX2_INTA_MASK_R, CX2_INTA_MASK_ALL);
377}
378
379static inline void ipw_disable_interrupts(struct ipw_priv *priv)
380{
381 if (!(priv->status & STATUS_INT_ENABLED))
382 return;
383 priv->status &= ~STATUS_INT_ENABLED;
384 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL);
385}
386
387static char *ipw_error_desc(u32 val)
388{
389 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400390 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600391 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400392 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600393 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400394 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600395 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400396 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600397 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400398 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenos43f66a62005-03-25 12:31:53 -0600399 return "ERROR_BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400400 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenos43f66a62005-03-25 12:31:53 -0600401 return "ERROR_BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400402 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenos43f66a62005-03-25 12:31:53 -0600403 return "ERROR_NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400404 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenos43f66a62005-03-25 12:31:53 -0600405 return "ERROR_BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400406 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600407 return "ERROR_ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400408 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenos43f66a62005-03-25 12:31:53 -0600409 return "ERROR_DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400410 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenos43f66a62005-03-25 12:31:53 -0600411 return "ERROR_DMA_STATUS";
Jeff Garzikbf794512005-07-31 13:07:26 -0400412 case IPW_FW_ERROR_DINOSTATUS_ERROR:
James Ketrenos43f66a62005-03-25 12:31:53 -0600413 return "ERROR_DINOSTATUS_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400414 case IPW_FW_ERROR_EEPROMSTATUS_ERROR:
James Ketrenos43f66a62005-03-25 12:31:53 -0600415 return "ERROR_EEPROMSTATUS_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400416 case IPW_FW_ERROR_SYSASSERT:
James Ketrenos43f66a62005-03-25 12:31:53 -0600417 return "ERROR_SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400418 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenos43f66a62005-03-25 12:31:53 -0600419 return "ERROR_FATALSTATUS_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400420 default:
James Ketrenos43f66a62005-03-25 12:31:53 -0600421 return "UNKNOWNSTATUS_ERROR";
422 }
423}
424
425static void ipw_dump_nic_error_log(struct ipw_priv *priv)
426{
427 u32 desc, time, blink1, blink2, ilink1, ilink2, idata, i, count, base;
428
429 base = ipw_read32(priv, IPWSTATUS_ERROR_LOG);
430 count = ipw_read_reg32(priv, base);
Jeff Garzikbf794512005-07-31 13:07:26 -0400431
James Ketrenos43f66a62005-03-25 12:31:53 -0600432 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
433 IPW_ERROR("Start IPW Error Log Dump:\n");
434 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
435 priv->status, priv->config);
436 }
437
Jeff Garzikbf794512005-07-31 13:07:26 -0400438 for (i = ERROR_START_OFFSET;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400439 i <= count * ERROR_ELEM_SIZE; i += ERROR_ELEM_SIZE) {
440 desc = ipw_read_reg32(priv, base + i);
441 time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
442 blink1 = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
443 blink2 = ipw_read_reg32(priv, base + i + 3 * sizeof(u32));
444 ilink1 = ipw_read_reg32(priv, base + i + 4 * sizeof(u32));
445 ilink2 = ipw_read_reg32(priv, base + i + 5 * sizeof(u32));
446 idata = ipw_read_reg32(priv, base + i + 6 * sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600447
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400448 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
449 ipw_error_desc(desc), time, blink1, blink2,
450 ilink1, ilink2, idata);
James Ketrenos43f66a62005-03-25 12:31:53 -0600451 }
452}
453
454static void ipw_dump_nic_event_log(struct ipw_priv *priv)
455{
456 u32 ev, time, data, i, count, base;
457
458 base = ipw_read32(priv, IPW_EVENT_LOG);
459 count = ipw_read_reg32(priv, base);
Jeff Garzikbf794512005-07-31 13:07:26 -0400460
James Ketrenos43f66a62005-03-25 12:31:53 -0600461 if (EVENT_START_OFFSET <= count * EVENT_ELEM_SIZE)
462 IPW_ERROR("Start IPW Event Log Dump:\n");
463
Jeff Garzikbf794512005-07-31 13:07:26 -0400464 for (i = EVENT_START_OFFSET;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400465 i <= count * EVENT_ELEM_SIZE; i += EVENT_ELEM_SIZE) {
James Ketrenos43f66a62005-03-25 12:31:53 -0600466 ev = ipw_read_reg32(priv, base + i);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400467 time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
468 data = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600469
470#ifdef CONFIG_IPW_DEBUG
471 IPW_ERROR("%i\t0x%08x\t%i\n", time, data, ev);
472#endif
473 }
474}
475
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400476static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600477{
478 u32 addr, field_info, field_len, field_count, total_len;
479
480 IPW_DEBUG_ORD("ordinal = %i\n", ord);
481
482 if (!priv || !val || !len) {
483 IPW_DEBUG_ORD("Invalid argument\n");
484 return -EINVAL;
485 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400486
James Ketrenos43f66a62005-03-25 12:31:53 -0600487 /* verify device ordinal tables have been initialized */
488 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
489 IPW_DEBUG_ORD("Access ordinals before initialization\n");
490 return -EINVAL;
491 }
492
493 switch (IPW_ORD_TABLE_ID_MASK & ord) {
494 case IPW_ORD_TABLE_0_MASK:
495 /*
496 * TABLE 0: Direct access to a table of 32 bit values
497 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400498 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600499 * read from the table
500 */
501
502 /* remove the table id from the ordinal */
503 ord &= IPW_ORD_TABLE_VALUE_MASK;
504
505 /* boundary check */
506 if (ord > priv->table0_len) {
507 IPW_DEBUG_ORD("ordinal value (%i) longer then "
508 "max (%i)\n", ord, priv->table0_len);
509 return -EINVAL;
510 }
511
512 /* verify we have enough room to store the value */
513 if (*len < sizeof(u32)) {
514 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200515 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600516 return -EINVAL;
517 }
518
519 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400520 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600521
522 *len = sizeof(u32);
523 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400524 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600525 break;
526
527 case IPW_ORD_TABLE_1_MASK:
528 /*
529 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400530 *
531 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600532 * representing starting addr for the data (which is
533 * also a u32)
534 */
535
536 /* remove the table id from the ordinal */
537 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400538
James Ketrenos43f66a62005-03-25 12:31:53 -0600539 /* boundary check */
540 if (ord > priv->table1_len) {
541 IPW_DEBUG_ORD("ordinal value too long\n");
542 return -EINVAL;
543 }
544
545 /* verify we have enough room to store the value */
546 if (*len < sizeof(u32)) {
547 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200548 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600549 return -EINVAL;
550 }
551
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400552 *((u32 *) val) =
553 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600554 *len = sizeof(u32);
555 break;
556
557 case IPW_ORD_TABLE_2_MASK:
558 /*
559 * TABLE 2: Indirect access to a table of variable sized values
560 *
561 * This table consist of six values, each containing
562 * - dword containing the starting offset of the data
563 * - dword containing the lengh in the first 16bits
564 * and the count in the second 16bits
565 */
566
567 /* remove the table id from the ordinal */
568 ord &= IPW_ORD_TABLE_VALUE_MASK;
569
570 /* boundary check */
571 if (ord > priv->table2_len) {
572 IPW_DEBUG_ORD("ordinal value too long\n");
573 return -EINVAL;
574 }
575
576 /* get the address of statistic */
577 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400578
579 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600580 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400581 field_info =
582 ipw_read_reg32(priv,
583 priv->table2_addr + (ord << 3) +
584 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400585
James Ketrenos43f66a62005-03-25 12:31:53 -0600586 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400587 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400588
James Ketrenos43f66a62005-03-25 12:31:53 -0600589 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400590 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400591
James Ketrenos43f66a62005-03-25 12:31:53 -0600592 /* abort if not enought memory */
593 total_len = field_len * field_count;
594 if (total_len > *len) {
595 *len = total_len;
596 return -EINVAL;
597 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400598
James Ketrenos43f66a62005-03-25 12:31:53 -0600599 *len = total_len;
600 if (!total_len)
601 return 0;
602
603 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400604 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600605 addr, total_len, field_info);
606 ipw_read_indirect(priv, addr, val, total_len);
607 break;
608
609 default:
610 IPW_DEBUG_ORD("Invalid ordinal!\n");
611 return -EINVAL;
612
613 }
614
James Ketrenos43f66a62005-03-25 12:31:53 -0600615 return 0;
616}
617
618static void ipw_init_ordinals(struct ipw_priv *priv)
619{
620 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400621 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600622
623 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
624 priv->table0_addr, priv->table0_len);
625
626 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
627 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
628
629 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
630 priv->table1_addr, priv->table1_len);
631
632 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
633 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400634 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600635
636 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
637 priv->table2_addr, priv->table2_len);
638
639}
640
James Ketrenosa613bff2005-08-24 21:43:11 -0500641u32 ipw_register_toggle(u32 reg)
642{
643 reg &= ~CX2_START_STANDBY;
644 if (reg & CX2_GATE_ODMA)
645 reg &= ~CX2_GATE_ODMA;
646 if (reg & CX2_GATE_IDMA)
647 reg &= ~CX2_GATE_IDMA;
648 if (reg & CX2_GATE_ADMA)
649 reg &= ~CX2_GATE_ADMA;
650 return reg;
651}
652
653/*
654 * LED behavior:
655 * - On radio ON, turn on any LEDs that require to be on during start
656 * - On initialization, start unassociated blink
657 * - On association, disable unassociated blink
658 * - On disassociation, start unassociated blink
659 * - On radio OFF, turn off any LEDs started during radio on
660 *
661 */
662#define LD_TIME_LINK_ON 300
663#define LD_TIME_LINK_OFF 2700
664#define LD_TIME_ACT_ON 250
665
666void ipw_led_link_on(struct ipw_priv *priv)
667{
668 unsigned long flags;
669 u32 led;
670
671 /* If configured to not use LEDs, or nic_type is 1,
672 * then we don't toggle a LINK led */
673 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
674 return;
675
676 spin_lock_irqsave(&priv->lock, flags);
677
678 if (!(priv->status & STATUS_RF_KILL_MASK) &&
679 !(priv->status & STATUS_LED_LINK_ON)) {
680 IPW_DEBUG_LED("Link LED On\n");
681 led = ipw_read_reg32(priv, CX2_EVENT_REG);
682 led |= priv->led_association_on;
683
684 led = ipw_register_toggle(led);
685
686 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
687 ipw_write_reg32(priv, CX2_EVENT_REG, led);
688
689 priv->status |= STATUS_LED_LINK_ON;
690
691 /* If we aren't associated, schedule turning the LED off */
692 if (!(priv->status & STATUS_ASSOCIATED))
693 queue_delayed_work(priv->workqueue,
694 &priv->led_link_off,
695 LD_TIME_LINK_ON);
696 }
697
698 spin_unlock_irqrestore(&priv->lock, flags);
699}
700
701void ipw_led_link_off(struct ipw_priv *priv)
702{
703 unsigned long flags;
704 u32 led;
705
706 /* If configured not to use LEDs, or nic type is 1,
707 * then we don't goggle the LINK led. */
708 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
709 return;
710
711 spin_lock_irqsave(&priv->lock, flags);
712
713 if (priv->status & STATUS_LED_LINK_ON) {
714 led = ipw_read_reg32(priv, CX2_EVENT_REG);
715 led &= priv->led_association_off;
716 led = ipw_register_toggle(led);
717
718 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
719 ipw_write_reg32(priv, CX2_EVENT_REG, led);
720
721 IPW_DEBUG_LED("Link LED Off\n");
722
723 priv->status &= ~STATUS_LED_LINK_ON;
724
725 /* If we aren't associated and the radio is on, schedule
726 * turning the LED on (blink while unassociated) */
727 if (!(priv->status & STATUS_RF_KILL_MASK) &&
728 !(priv->status & STATUS_ASSOCIATED))
729 queue_delayed_work(priv->workqueue, &priv->led_link_on,
730 LD_TIME_LINK_OFF);
731
732 }
733
734 spin_unlock_irqrestore(&priv->lock, flags);
735}
736
737void ipw_led_activity_on(struct ipw_priv *priv)
738{
739 unsigned long flags;
740 u32 led;
741
742 if (priv->config & CFG_NO_LED)
743 return;
744
745 spin_lock_irqsave(&priv->lock, flags);
746
747 if (priv->status & STATUS_RF_KILL_MASK) {
748 spin_unlock_irqrestore(&priv->lock, flags);
749 return;
750 }
751
752 if (!(priv->status & STATUS_LED_ACT_ON)) {
753 led = ipw_read_reg32(priv, CX2_EVENT_REG);
754 led |= priv->led_activity_on;
755
756 led = ipw_register_toggle(led);
757
758 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
759 ipw_write_reg32(priv, CX2_EVENT_REG, led);
760
761 IPW_DEBUG_LED("Activity LED On\n");
762
763 priv->status |= STATUS_LED_ACT_ON;
764
765 queue_delayed_work(priv->workqueue, &priv->led_act_off,
766 LD_TIME_ACT_ON);
767 } else {
768 /* Reschedule LED off for full time period */
769 cancel_delayed_work(&priv->led_act_off);
770 queue_delayed_work(priv->workqueue, &priv->led_act_off,
771 LD_TIME_ACT_ON);
772 }
773
774 spin_unlock_irqrestore(&priv->lock, flags);
775}
776
777void ipw_led_activity_off(struct ipw_priv *priv)
778{
779 unsigned long flags;
780 u32 led;
781
782 if (priv->config & CFG_NO_LED)
783 return;
784
785 spin_lock_irqsave(&priv->lock, flags);
786
787 if (priv->status & STATUS_LED_ACT_ON) {
788 led = ipw_read_reg32(priv, CX2_EVENT_REG);
789 led &= priv->led_activity_off;
790
791 led = ipw_register_toggle(led);
792
793 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
794 ipw_write_reg32(priv, CX2_EVENT_REG, led);
795
796 IPW_DEBUG_LED("Activity LED Off\n");
797
798 priv->status &= ~STATUS_LED_ACT_ON;
799 }
800
801 spin_unlock_irqrestore(&priv->lock, flags);
802}
803
804void ipw_led_band_on(struct ipw_priv *priv)
805{
806 unsigned long flags;
807 u32 led;
808
809 /* Only nic type 1 supports mode LEDs */
810 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
811 return;
812
813 spin_lock_irqsave(&priv->lock, flags);
814
815 led = ipw_read_reg32(priv, CX2_EVENT_REG);
816 if (priv->assoc_network->mode == IEEE_A) {
817 led |= priv->led_ofdm_on;
818 led &= priv->led_association_off;
819 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
820 } else if (priv->assoc_network->mode == IEEE_G) {
821 led |= priv->led_ofdm_on;
822 led |= priv->led_association_on;
823 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
824 } else {
825 led &= priv->led_ofdm_off;
826 led |= priv->led_association_on;
827 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
828 }
829
830 led = ipw_register_toggle(led);
831
832 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
833 ipw_write_reg32(priv, CX2_EVENT_REG, led);
834
835 spin_unlock_irqrestore(&priv->lock, flags);
836}
837
838void ipw_led_band_off(struct ipw_priv *priv)
839{
840 unsigned long flags;
841 u32 led;
842
843 /* Only nic type 1 supports mode LEDs */
844 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
845 return;
846
847 spin_lock_irqsave(&priv->lock, flags);
848
849 led = ipw_read_reg32(priv, CX2_EVENT_REG);
850 led &= priv->led_ofdm_off;
851 led &= priv->led_association_off;
852
853 led = ipw_register_toggle(led);
854
855 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
856 ipw_write_reg32(priv, CX2_EVENT_REG, led);
857
858 spin_unlock_irqrestore(&priv->lock, flags);
859}
860
861void ipw_led_radio_on(struct ipw_priv *priv)
862{
863 ipw_led_link_on(priv);
864}
865
866void ipw_led_radio_off(struct ipw_priv *priv)
867{
868 ipw_led_activity_off(priv);
869 ipw_led_link_off(priv);
870}
871
872void ipw_led_link_up(struct ipw_priv *priv)
873{
874 /* Set the Link Led on for all nic types */
875 ipw_led_link_on(priv);
876}
877
878void ipw_led_link_down(struct ipw_priv *priv)
879{
880 ipw_led_activity_off(priv);
881 ipw_led_link_off(priv);
882
883 if (priv->status & STATUS_RF_KILL_MASK)
884 ipw_led_radio_off(priv);
885}
886
887void ipw_led_init(struct ipw_priv *priv)
888{
889 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
890
891 /* Set the default PINs for the link and activity leds */
892 priv->led_activity_on = CX2_ACTIVITY_LED;
893 priv->led_activity_off = ~(CX2_ACTIVITY_LED);
894
895 priv->led_association_on = CX2_ASSOCIATED_LED;
896 priv->led_association_off = ~(CX2_ASSOCIATED_LED);
897
898 /* Set the default PINs for the OFDM leds */
899 priv->led_ofdm_on = CX2_OFDM_LED;
900 priv->led_ofdm_off = ~(CX2_OFDM_LED);
901
902 switch (priv->nic_type) {
903 case EEPROM_NIC_TYPE_1:
904 /* In this NIC type, the LEDs are reversed.... */
905 priv->led_activity_on = CX2_ASSOCIATED_LED;
906 priv->led_activity_off = ~(CX2_ASSOCIATED_LED);
907 priv->led_association_on = CX2_ACTIVITY_LED;
908 priv->led_association_off = ~(CX2_ACTIVITY_LED);
909
910 if (!(priv->config & CFG_NO_LED))
911 ipw_led_band_on(priv);
912
913 /* And we don't blink link LEDs for this nic, so
914 * just return here */
915 return;
916
917 case EEPROM_NIC_TYPE_3:
918 case EEPROM_NIC_TYPE_2:
919 case EEPROM_NIC_TYPE_4:
920 case EEPROM_NIC_TYPE_0:
921 break;
922
923 default:
924 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
925 priv->nic_type);
926 priv->nic_type = EEPROM_NIC_TYPE_0;
927 break;
928 }
929
930 if (!(priv->config & CFG_NO_LED)) {
931 if (priv->status & STATUS_ASSOCIATED)
932 ipw_led_link_on(priv);
933 else
934 ipw_led_link_off(priv);
935 }
936}
937
938void ipw_led_shutdown(struct ipw_priv *priv)
939{
940 cancel_delayed_work(&priv->led_link_on);
941 cancel_delayed_work(&priv->led_link_off);
942 cancel_delayed_work(&priv->led_act_off);
943 ipw_led_activity_off(priv);
944 ipw_led_link_off(priv);
945 ipw_led_band_off(priv);
946}
947
James Ketrenos43f66a62005-03-25 12:31:53 -0600948/*
949 * The following adds a new attribute to the sysfs representation
950 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
951 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -0400952 *
James Ketrenos43f66a62005-03-25 12:31:53 -0600953 * See the level definitions in ipw for details.
954 */
955static ssize_t show_debug_level(struct device_driver *d, char *buf)
956{
957 return sprintf(buf, "0x%08X\n", ipw_debug_level);
958}
James Ketrenosa613bff2005-08-24 21:43:11 -0500959
960static ssize_t store_debug_level(struct device_driver *d, const char *buf,
961 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -0600962{
963 char *p = (char *)buf;
964 u32 val;
965
966 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
967 p++;
968 if (p[0] == 'x' || p[0] == 'X')
969 p++;
970 val = simple_strtoul(p, &p, 16);
971 } else
972 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -0400973 if (p == buf)
974 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -0600975 ": %s is not in hex or decimal form.\n", buf);
976 else
977 ipw_debug_level = val;
978
979 return strnlen(buf, count);
980}
981
Jeff Garzikbf794512005-07-31 13:07:26 -0400982static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -0600983 show_debug_level, store_debug_level);
984
James Ketrenosa613bff2005-08-24 21:43:11 -0500985static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
986 char *buf)
987{
988 struct ipw_priv *priv = dev_get_drvdata(d);
989 return sprintf(buf, "%d\n", priv->ieee->scan_age);
990}
991
992static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
993 const char *buf, size_t count)
994{
995 struct ipw_priv *priv = dev_get_drvdata(d);
996 struct net_device *dev = priv->net_dev;
997 char buffer[] = "00000000";
998 unsigned long len =
999 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1000 unsigned long val;
1001 char *p = buffer;
1002
1003 IPW_DEBUG_INFO("enter\n");
1004
1005 strncpy(buffer, buf, len);
1006 buffer[len] = 0;
1007
1008 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1009 p++;
1010 if (p[0] == 'x' || p[0] == 'X')
1011 p++;
1012 val = simple_strtoul(p, &p, 16);
1013 } else
1014 val = simple_strtoul(p, &p, 10);
1015 if (p == buffer) {
1016 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1017 } else {
1018 priv->ieee->scan_age = val;
1019 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1020 }
1021
1022 IPW_DEBUG_INFO("exit\n");
1023 return len;
1024}
1025
1026static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1027
1028static ssize_t show_led(struct device *d, struct device_attribute *attr,
1029 char *buf)
1030{
1031 struct ipw_priv *priv = dev_get_drvdata(d);
1032 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1033}
1034
1035static ssize_t store_led(struct device *d, struct device_attribute *attr,
1036 const char *buf, size_t count)
1037{
1038 struct ipw_priv *priv = dev_get_drvdata(d);
1039
1040 IPW_DEBUG_INFO("enter\n");
1041
1042 if (count == 0)
1043 return 0;
1044
1045 if (*buf == 0) {
1046 IPW_DEBUG_LED("Disabling LED control.\n");
1047 priv->config |= CFG_NO_LED;
1048 ipw_led_shutdown(priv);
1049 } else {
1050 IPW_DEBUG_LED("Enabling LED control.\n");
1051 priv->config &= ~CFG_NO_LED;
1052 ipw_led_init(priv);
1053 }
1054
1055 IPW_DEBUG_INFO("exit\n");
1056 return count;
1057}
1058
1059static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1060
Andrew Mortonad3fee52005-06-20 14:30:36 -07001061static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001062 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001063{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001064 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001065 return sprintf(buf, "0x%08x\n", (int)p->status);
1066}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001067
James Ketrenos43f66a62005-03-25 12:31:53 -06001068static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1069
Andrew Mortonad3fee52005-06-20 14:30:36 -07001070static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1071 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001072{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001073 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001074 return sprintf(buf, "0x%08x\n", (int)p->config);
1075}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001076
James Ketrenos43f66a62005-03-25 12:31:53 -06001077static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1078
Andrew Mortonad3fee52005-06-20 14:30:36 -07001079static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001080 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001081{
James Ketrenosa613bff2005-08-24 21:43:11 -05001082 struct ipw_priv *priv = d->driver_data;
1083 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001084}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001085
James Ketrenos43f66a62005-03-25 12:31:53 -06001086static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1087
Andrew Mortonad3fee52005-06-20 14:30:36 -07001088static ssize_t dump_error_log(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001089 struct device_attribute *attr, const char *buf,
1090 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001091{
1092 char *p = (char *)buf;
1093
Jeff Garzikbf794512005-07-31 13:07:26 -04001094 if (p[0] == '1')
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001095 ipw_dump_nic_error_log((struct ipw_priv *)d->driver_data);
James Ketrenos43f66a62005-03-25 12:31:53 -06001096
1097 return strnlen(buf, count);
1098}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001099
James Ketrenos43f66a62005-03-25 12:31:53 -06001100static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
1101
Andrew Mortonad3fee52005-06-20 14:30:36 -07001102static ssize_t dump_event_log(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001103 struct device_attribute *attr, const char *buf,
1104 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001105{
1106 char *p = (char *)buf;
1107
Jeff Garzikbf794512005-07-31 13:07:26 -04001108 if (p[0] == '1')
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001109 ipw_dump_nic_event_log((struct ipw_priv *)d->driver_data);
James Ketrenos43f66a62005-03-25 12:31:53 -06001110
1111 return strnlen(buf, count);
1112}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001113
James Ketrenos43f66a62005-03-25 12:31:53 -06001114static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
1115
Andrew Mortonad3fee52005-06-20 14:30:36 -07001116static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001117 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001118{
1119 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001120 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001121
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001122 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001123 return 0;
1124
1125 return sprintf(buf, "0x%08x\n", tmp);
1126}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001127
1128static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001129
Andrew Mortonad3fee52005-06-20 14:30:36 -07001130static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1131 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001132{
1133 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001134 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001135
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001136 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001137 return 0;
1138
1139 return sprintf(buf, "0x%08x\n", tmp);
1140}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001141
1142static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001143
1144/*
1145 * Add a device attribute to view/control the delay between eeprom
1146 * operations.
1147 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001148static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001149 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001150{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001151 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001152 return sprintf(buf, "%i\n", n);
1153}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001154static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001155 struct device_attribute *attr,
1156 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001157{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001158 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001159 sscanf(buf, "%i", &p->eeprom_delay);
1160 return strnlen(buf, count);
1161}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001162
1163static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1164 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001165
Andrew Mortonad3fee52005-06-20 14:30:36 -07001166static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001167 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001168{
1169 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001170 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001171
1172 reg = ipw_read_reg32(p, CX2_INTERNAL_CMD_EVENT);
1173 return sprintf(buf, "0x%08x\n", reg);
1174}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001175static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001176 struct device_attribute *attr,
1177 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001178{
1179 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001180 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001181
1182 sscanf(buf, "%x", &reg);
1183 ipw_write_reg32(p, CX2_INTERNAL_CMD_EVENT, reg);
1184 return strnlen(buf, count);
1185}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001186
1187static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1188 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001189
Andrew Mortonad3fee52005-06-20 14:30:36 -07001190static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001191 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001192{
1193 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001194 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001195
1196 reg = ipw_read_reg32(p, 0x301100);
1197 return sprintf(buf, "0x%08x\n", reg);
1198}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001199static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001200 struct device_attribute *attr,
1201 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001202{
1203 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001204 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001205
1206 sscanf(buf, "%x", &reg);
1207 ipw_write_reg32(p, 0x301100, reg);
1208 return strnlen(buf, count);
1209}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001210
1211static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1212 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001213
Andrew Mortonad3fee52005-06-20 14:30:36 -07001214static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001215 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001216{
1217 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001218 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -04001219 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001220 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001221 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001222 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001223
James Ketrenos43f66a62005-03-25 12:31:53 -06001224 return sprintf(buf, "0x%08x\n", reg);
1225}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001226static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001227 struct device_attribute *attr,
1228 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001229{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001230 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001231
1232 sscanf(buf, "%x", &priv->indirect_dword);
1233 priv->status |= STATUS_INDIRECT_DWORD;
1234 return strnlen(buf, count);
1235}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001236
1237static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1238 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001239
Andrew Mortonad3fee52005-06-20 14:30:36 -07001240static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001241 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001242{
1243 u8 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001244 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -04001245 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001246 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001247 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001248 reg = 0;
1249
1250 return sprintf(buf, "0x%02x\n", reg);
1251}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001252static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001253 struct device_attribute *attr,
1254 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001255{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001256 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001257
1258 sscanf(buf, "%x", &priv->indirect_byte);
1259 priv->status |= STATUS_INDIRECT_BYTE;
1260 return strnlen(buf, count);
1261}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001262
1263static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001264 show_indirect_byte, store_indirect_byte);
1265
Andrew Mortonad3fee52005-06-20 14:30:36 -07001266static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001267 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001268{
1269 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001270 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001271
Jeff Garzikbf794512005-07-31 13:07:26 -04001272 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001273 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001274 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001275 reg = 0;
1276
1277 return sprintf(buf, "0x%08x\n", reg);
1278}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001279static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001280 struct device_attribute *attr,
1281 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001282{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001283 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001284
1285 sscanf(buf, "%x", &priv->direct_dword);
1286 priv->status |= STATUS_DIRECT_DWORD;
1287 return strnlen(buf, count);
1288}
James Ketrenos43f66a62005-03-25 12:31:53 -06001289
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001290static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1291 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001292
1293static inline int rf_kill_active(struct ipw_priv *priv)
1294{
1295 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1296 priv->status |= STATUS_RF_KILL_HW;
1297 else
1298 priv->status &= ~STATUS_RF_KILL_HW;
1299
1300 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1301}
1302
Andrew Mortonad3fee52005-06-20 14:30:36 -07001303static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001304 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001305{
1306 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001307 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001308 2 - HW based RF kill active
1309 3 - Both HW and SW baed RF kill active */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001310 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001311 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001312 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001313 return sprintf(buf, "%i\n", val);
1314}
1315
1316static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1317{
Jeff Garzikbf794512005-07-31 13:07:26 -04001318 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001319 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001320 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001321
1322 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1323 disable_radio ? "OFF" : "ON");
1324
1325 if (disable_radio) {
1326 priv->status |= STATUS_RF_KILL_SW;
1327
James Ketrenosa613bff2005-08-24 21:43:11 -05001328 if (priv->workqueue)
James Ketrenos43f66a62005-03-25 12:31:53 -06001329 cancel_delayed_work(&priv->request_scan);
James Ketrenos43f66a62005-03-25 12:31:53 -06001330 wake_up_interruptible(&priv->wait_command_queue);
1331 queue_work(priv->workqueue, &priv->down);
1332 } else {
1333 priv->status &= ~STATUS_RF_KILL_SW;
1334 if (rf_kill_active(priv)) {
1335 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1336 "disabled by HW switch\n");
1337 /* Make sure the RF_KILL check timer is running */
1338 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001339 queue_delayed_work(priv->workqueue, &priv->rf_kill,
James Ketrenos43f66a62005-03-25 12:31:53 -06001340 2 * HZ);
Jeff Garzikbf794512005-07-31 13:07:26 -04001341 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001342 queue_work(priv->workqueue, &priv->up);
1343 }
1344
1345 return 1;
1346}
1347
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001348static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1349 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001350{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001351 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -04001352
James Ketrenos43f66a62005-03-25 12:31:53 -06001353 ipw_radio_kill_sw(priv, buf[0] == '1');
1354
1355 return count;
1356}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001357
1358static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001359
James Ketrenosea2b26e2005-08-24 21:25:16 -05001360static void notify_wx_assoc_event(struct ipw_priv *priv)
1361{
1362 union iwreq_data wrqu;
1363 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1364 if (priv->status & STATUS_ASSOCIATED)
1365 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1366 else
1367 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1368 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1369}
1370
James Ketrenos43f66a62005-03-25 12:31:53 -06001371static void ipw_irq_tasklet(struct ipw_priv *priv)
1372{
1373 u32 inta, inta_mask, handled = 0;
1374 unsigned long flags;
1375 int rc = 0;
1376
1377 spin_lock_irqsave(&priv->lock, flags);
1378
1379 inta = ipw_read32(priv, CX2_INTA_RW);
1380 inta_mask = ipw_read32(priv, CX2_INTA_MASK_R);
1381 inta &= (CX2_INTA_MASK_ALL & inta_mask);
1382
1383 /* Add any cached INTA values that need to be handled */
1384 inta |= priv->isr_inta;
1385
1386 /* handle all the justifications for the interrupt */
1387 if (inta & CX2_INTA_BIT_RX_TRANSFER) {
1388 ipw_rx(priv);
1389 handled |= CX2_INTA_BIT_RX_TRANSFER;
1390 }
1391
1392 if (inta & CX2_INTA_BIT_TX_CMD_QUEUE) {
1393 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001394 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001395 priv->status &= ~STATUS_HCMD_ACTIVE;
1396 wake_up_interruptible(&priv->wait_command_queue);
1397 handled |= CX2_INTA_BIT_TX_CMD_QUEUE;
1398 }
1399
1400 if (inta & CX2_INTA_BIT_TX_QUEUE_1) {
1401 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001402 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001403 handled |= CX2_INTA_BIT_TX_QUEUE_1;
1404 }
1405
1406 if (inta & CX2_INTA_BIT_TX_QUEUE_2) {
1407 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001408 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001409 handled |= CX2_INTA_BIT_TX_QUEUE_2;
1410 }
1411
1412 if (inta & CX2_INTA_BIT_TX_QUEUE_3) {
1413 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001414 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenos43f66a62005-03-25 12:31:53 -06001415 handled |= CX2_INTA_BIT_TX_QUEUE_3;
1416 }
1417
1418 if (inta & CX2_INTA_BIT_TX_QUEUE_4) {
1419 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001420 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06001421 handled |= CX2_INTA_BIT_TX_QUEUE_4;
1422 }
1423
1424 if (inta & CX2_INTA_BIT_STATUS_CHANGE) {
1425 IPW_WARNING("STATUS_CHANGE\n");
1426 handled |= CX2_INTA_BIT_STATUS_CHANGE;
1427 }
1428
1429 if (inta & CX2_INTA_BIT_BEACON_PERIOD_EXPIRED) {
1430 IPW_WARNING("TX_PERIOD_EXPIRED\n");
1431 handled |= CX2_INTA_BIT_BEACON_PERIOD_EXPIRED;
1432 }
1433
1434 if (inta & CX2_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
1435 IPW_WARNING("HOST_CMD_DONE\n");
1436 handled |= CX2_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
1437 }
1438
1439 if (inta & CX2_INTA_BIT_FW_INITIALIZATION_DONE) {
1440 IPW_WARNING("FW_INITIALIZATION_DONE\n");
1441 handled |= CX2_INTA_BIT_FW_INITIALIZATION_DONE;
1442 }
1443
1444 if (inta & CX2_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
1445 IPW_WARNING("PHY_OFF_DONE\n");
1446 handled |= CX2_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
1447 }
1448
1449 if (inta & CX2_INTA_BIT_RF_KILL_DONE) {
1450 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1451 priv->status |= STATUS_RF_KILL_HW;
1452 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05001453 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06001454 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05001455 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001456 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
1457 handled |= CX2_INTA_BIT_RF_KILL_DONE;
1458 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001459
James Ketrenos43f66a62005-03-25 12:31:53 -06001460 if (inta & CX2_INTA_BIT_FATAL_ERROR) {
1461 IPW_ERROR("Firmware error detected. Restarting.\n");
1462#ifdef CONFIG_IPW_DEBUG
1463 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1464 ipw_dump_nic_error_log(priv);
1465 ipw_dump_nic_event_log(priv);
1466 }
1467#endif
1468 queue_work(priv->workqueue, &priv->adapter_restart);
1469 handled |= CX2_INTA_BIT_FATAL_ERROR;
1470 }
1471
1472 if (inta & CX2_INTA_BIT_PARITY_ERROR) {
1473 IPW_ERROR("Parity error\n");
1474 handled |= CX2_INTA_BIT_PARITY_ERROR;
1475 }
1476
1477 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001478 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06001479 }
1480
1481 /* enable all interrupts */
1482 ipw_enable_interrupts(priv);
1483
1484 spin_unlock_irqrestore(&priv->lock, flags);
1485}
Jeff Garzikbf794512005-07-31 13:07:26 -04001486
James Ketrenos43f66a62005-03-25 12:31:53 -06001487#ifdef CONFIG_IPW_DEBUG
1488#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1489static char *get_cmd_string(u8 cmd)
1490{
1491 switch (cmd) {
1492 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04001493 IPW_CMD(POWER_DOWN);
1494 IPW_CMD(SYSTEM_CONFIG);
1495 IPW_CMD(MULTICAST_ADDRESS);
1496 IPW_CMD(SSID);
1497 IPW_CMD(ADAPTER_ADDRESS);
1498 IPW_CMD(PORT_TYPE);
1499 IPW_CMD(RTS_THRESHOLD);
1500 IPW_CMD(FRAG_THRESHOLD);
1501 IPW_CMD(POWER_MODE);
1502 IPW_CMD(WEP_KEY);
1503 IPW_CMD(TGI_TX_KEY);
1504 IPW_CMD(SCAN_REQUEST);
1505 IPW_CMD(SCAN_REQUEST_EXT);
1506 IPW_CMD(ASSOCIATE);
1507 IPW_CMD(SUPPORTED_RATES);
1508 IPW_CMD(SCAN_ABORT);
1509 IPW_CMD(TX_FLUSH);
1510 IPW_CMD(QOS_PARAMETERS);
1511 IPW_CMD(DINO_CONFIG);
1512 IPW_CMD(RSN_CAPABILITIES);
1513 IPW_CMD(RX_KEY);
1514 IPW_CMD(CARD_DISABLE);
1515 IPW_CMD(SEED_NUMBER);
1516 IPW_CMD(TX_POWER);
1517 IPW_CMD(COUNTRY_INFO);
1518 IPW_CMD(AIRONET_INFO);
1519 IPW_CMD(AP_TX_POWER);
1520 IPW_CMD(CCKM_INFO);
1521 IPW_CMD(CCX_VER_INFO);
1522 IPW_CMD(SET_CALIBRATION);
1523 IPW_CMD(SENSITIVITY_CALIB);
1524 IPW_CMD(RETRY_LIMIT);
1525 IPW_CMD(IPW_PRE_POWER_DOWN);
1526 IPW_CMD(VAP_BEACON_TEMPLATE);
1527 IPW_CMD(VAP_DTIM_PERIOD);
1528 IPW_CMD(EXT_SUPPORTED_RATES);
1529 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
1530 IPW_CMD(VAP_QUIET_INTERVALS);
1531 IPW_CMD(VAP_CHANNEL_SWITCH);
1532 IPW_CMD(VAP_MANDATORY_CHANNELS);
1533 IPW_CMD(VAP_CELL_PWR_LIMIT);
1534 IPW_CMD(VAP_CF_PARAM_SET);
1535 IPW_CMD(VAP_SET_BEACONING_STATE);
1536 IPW_CMD(MEASUREMENT);
1537 IPW_CMD(POWER_CAPABILITY);
1538 IPW_CMD(SUPPORTED_CHANNELS);
1539 IPW_CMD(TPC_REPORT);
1540 IPW_CMD(WME_INFO);
1541 IPW_CMD(PRODUCTION_COMMAND);
1542 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06001543 return "UNKNOWN";
1544 }
1545}
James Ketrenosea2b26e2005-08-24 21:25:16 -05001546#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06001547
1548#define HOST_COMPLETE_TIMEOUT HZ
1549static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
1550{
1551 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05001552 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06001553
James Ketrenosa613bff2005-08-24 21:43:11 -05001554 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001555 if (priv->status & STATUS_HCMD_ACTIVE) {
1556 IPW_ERROR("Already sending a command\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05001557 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001558 return -1;
1559 }
1560
1561 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04001562
1563 IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06001564 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001565 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
James Ketrenos43f66a62005-03-25 12:31:53 -06001566
1567 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05001568 if (rc) {
1569 priv->status &= ~STATUS_HCMD_ACTIVE;
1570 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001571 return rc;
James Ketrenosa613bff2005-08-24 21:43:11 -05001572 }
1573 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001574
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001575 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1576 !(priv->
1577 status & STATUS_HCMD_ACTIVE),
1578 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001579 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05001580 spin_lock_irqsave(&priv->lock, flags);
1581 if (priv->status & STATUS_HCMD_ACTIVE) {
1582 IPW_DEBUG_INFO("Command completion failed out after "
1583 "%dms.\n",
1584 1000 * (HOST_COMPLETE_TIMEOUT / HZ));
1585 priv->status &= ~STATUS_HCMD_ACTIVE;
1586 spin_unlock_irqrestore(&priv->lock, flags);
1587 return -EIO;
1588 }
1589 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001590 }
James Ketrenosa613bff2005-08-24 21:43:11 -05001591
James Ketrenos43f66a62005-03-25 12:31:53 -06001592 if (priv->status & STATUS_RF_KILL_MASK) {
1593 IPW_DEBUG_INFO("Command aborted due to RF Kill Switch\n");
1594 return -EIO;
1595 }
1596
1597 return 0;
1598}
1599
1600static int ipw_send_host_complete(struct ipw_priv *priv)
1601{
1602 struct host_cmd cmd = {
1603 .cmd = IPW_CMD_HOST_COMPLETE,
1604 .len = 0
1605 };
1606
1607 if (!priv) {
1608 IPW_ERROR("Invalid args\n");
1609 return -1;
1610 }
1611
1612 if (ipw_send_cmd(priv, &cmd)) {
1613 IPW_ERROR("failed to send HOST_COMPLETE command\n");
1614 return -1;
1615 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001616
James Ketrenos43f66a62005-03-25 12:31:53 -06001617 return 0;
1618}
1619
Jeff Garzikbf794512005-07-31 13:07:26 -04001620static int ipw_send_system_config(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06001621 struct ipw_sys_config *config)
1622{
1623 struct host_cmd cmd = {
1624 .cmd = IPW_CMD_SYSTEM_CONFIG,
1625 .len = sizeof(*config)
1626 };
1627
1628 if (!priv || !config) {
1629 IPW_ERROR("Invalid args\n");
1630 return -1;
1631 }
1632
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001633 memcpy(&cmd.param, config, sizeof(*config));
James Ketrenos43f66a62005-03-25 12:31:53 -06001634 if (ipw_send_cmd(priv, &cmd)) {
1635 IPW_ERROR("failed to send SYSTEM_CONFIG command\n");
1636 return -1;
1637 }
1638
1639 return 0;
1640}
1641
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001642static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06001643{
1644 struct host_cmd cmd = {
1645 .cmd = IPW_CMD_SSID,
1646 .len = min(len, IW_ESSID_MAX_SIZE)
1647 };
1648
1649 if (!priv || !ssid) {
1650 IPW_ERROR("Invalid args\n");
1651 return -1;
1652 }
1653
1654 memcpy(&cmd.param, ssid, cmd.len);
1655 if (ipw_send_cmd(priv, &cmd)) {
1656 IPW_ERROR("failed to send SSID command\n");
1657 return -1;
1658 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001659
James Ketrenos43f66a62005-03-25 12:31:53 -06001660 return 0;
1661}
1662
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001663static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06001664{
1665 struct host_cmd cmd = {
1666 .cmd = IPW_CMD_ADAPTER_ADDRESS,
1667 .len = ETH_ALEN
1668 };
1669
1670 if (!priv || !mac) {
1671 IPW_ERROR("Invalid args\n");
1672 return -1;
1673 }
1674
1675 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
1676 priv->net_dev->name, MAC_ARG(mac));
1677
1678 memcpy(&cmd.param, mac, ETH_ALEN);
1679
1680 if (ipw_send_cmd(priv, &cmd)) {
1681 IPW_ERROR("failed to send ADAPTER_ADDRESS command\n");
1682 return -1;
1683 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001684
James Ketrenos43f66a62005-03-25 12:31:53 -06001685 return 0;
1686}
1687
James Ketrenosa613bff2005-08-24 21:43:11 -05001688/*
1689 * NOTE: This must be executed from our workqueue as it results in udelay
1690 * being called which may corrupt the keyboard if executed on default
1691 * workqueue
1692 */
James Ketrenos43f66a62005-03-25 12:31:53 -06001693static void ipw_adapter_restart(void *adapter)
1694{
1695 struct ipw_priv *priv = adapter;
1696
1697 if (priv->status & STATUS_RF_KILL_MASK)
1698 return;
1699
1700 ipw_down(priv);
1701 if (ipw_up(priv)) {
1702 IPW_ERROR("Failed to up device\n");
1703 return;
1704 }
1705}
1706
James Ketrenos43f66a62005-03-25 12:31:53 -06001707#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
1708
1709static void ipw_scan_check(void *data)
1710{
1711 struct ipw_priv *priv = data;
1712 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
1713 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Jeff Garzikbf794512005-07-31 13:07:26 -04001714 "adapter (%dms).\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06001715 IPW_SCAN_CHECK_WATCHDOG / 100);
James Ketrenosa613bff2005-08-24 21:43:11 -05001716 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06001717 }
1718}
1719
1720static int ipw_send_scan_request_ext(struct ipw_priv *priv,
1721 struct ipw_scan_request_ext *request)
1722{
1723 struct host_cmd cmd = {
1724 .cmd = IPW_CMD_SCAN_REQUEST_EXT,
1725 .len = sizeof(*request)
1726 };
1727
1728 if (!priv || !request) {
1729 IPW_ERROR("Invalid args\n");
1730 return -1;
1731 }
1732
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001733 memcpy(&cmd.param, request, sizeof(*request));
James Ketrenos43f66a62005-03-25 12:31:53 -06001734 if (ipw_send_cmd(priv, &cmd)) {
1735 IPW_ERROR("failed to send SCAN_REQUEST_EXT command\n");
1736 return -1;
1737 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001738
1739 queue_delayed_work(priv->workqueue, &priv->scan_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06001740 IPW_SCAN_CHECK_WATCHDOG);
1741 return 0;
1742}
1743
1744static int ipw_send_scan_abort(struct ipw_priv *priv)
1745{
1746 struct host_cmd cmd = {
1747 .cmd = IPW_CMD_SCAN_ABORT,
1748 .len = 0
1749 };
1750
1751 if (!priv) {
1752 IPW_ERROR("Invalid args\n");
1753 return -1;
1754 }
1755
1756 if (ipw_send_cmd(priv, &cmd)) {
1757 IPW_ERROR("failed to send SCAN_ABORT command\n");
1758 return -1;
1759 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001760
James Ketrenos43f66a62005-03-25 12:31:53 -06001761 return 0;
1762}
1763
1764static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
1765{
1766 struct host_cmd cmd = {
1767 .cmd = IPW_CMD_SENSITIVITY_CALIB,
1768 .len = sizeof(struct ipw_sensitivity_calib)
1769 };
1770 struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001771 &cmd.param;
James Ketrenos43f66a62005-03-25 12:31:53 -06001772 calib->beacon_rssi_raw = sens;
1773 if (ipw_send_cmd(priv, &cmd)) {
1774 IPW_ERROR("failed to send SENSITIVITY CALIB command\n");
1775 return -1;
1776 }
1777
1778 return 0;
1779}
1780
1781static int ipw_send_associate(struct ipw_priv *priv,
1782 struct ipw_associate *associate)
1783{
1784 struct host_cmd cmd = {
1785 .cmd = IPW_CMD_ASSOCIATE,
1786 .len = sizeof(*associate)
1787 };
1788
James Ketrenosa613bff2005-08-24 21:43:11 -05001789 struct ipw_associate tmp_associate;
1790 memcpy(&tmp_associate, associate, sizeof(*associate));
1791 tmp_associate.policy_support =
1792 cpu_to_le16(tmp_associate.policy_support);
1793 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
1794 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
1795 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
1796 tmp_associate.listen_interval =
1797 cpu_to_le16(tmp_associate.listen_interval);
1798 tmp_associate.beacon_interval =
1799 cpu_to_le16(tmp_associate.beacon_interval);
1800 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
1801
James Ketrenos43f66a62005-03-25 12:31:53 -06001802 if (!priv || !associate) {
1803 IPW_ERROR("Invalid args\n");
1804 return -1;
1805 }
1806
James Ketrenosa613bff2005-08-24 21:43:11 -05001807 memcpy(&cmd.param, &tmp_associate, sizeof(*associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06001808 if (ipw_send_cmd(priv, &cmd)) {
1809 IPW_ERROR("failed to send ASSOCIATE command\n");
1810 return -1;
1811 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001812
James Ketrenos43f66a62005-03-25 12:31:53 -06001813 return 0;
1814}
1815
1816static int ipw_send_supported_rates(struct ipw_priv *priv,
1817 struct ipw_supported_rates *rates)
1818{
1819 struct host_cmd cmd = {
1820 .cmd = IPW_CMD_SUPPORTED_RATES,
1821 .len = sizeof(*rates)
1822 };
1823
1824 if (!priv || !rates) {
1825 IPW_ERROR("Invalid args\n");
1826 return -1;
1827 }
1828
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001829 memcpy(&cmd.param, rates, sizeof(*rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06001830 if (ipw_send_cmd(priv, &cmd)) {
1831 IPW_ERROR("failed to send SUPPORTED_RATES command\n");
1832 return -1;
1833 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001834
James Ketrenos43f66a62005-03-25 12:31:53 -06001835 return 0;
1836}
1837
1838static int ipw_set_random_seed(struct ipw_priv *priv)
1839{
1840 struct host_cmd cmd = {
1841 .cmd = IPW_CMD_SEED_NUMBER,
1842 .len = sizeof(u32)
1843 };
1844
1845 if (!priv) {
1846 IPW_ERROR("Invalid args\n");
1847 return -1;
1848 }
1849
1850 get_random_bytes(&cmd.param, sizeof(u32));
1851
1852 if (ipw_send_cmd(priv, &cmd)) {
1853 IPW_ERROR("failed to send SEED_NUMBER command\n");
1854 return -1;
1855 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001856
James Ketrenos43f66a62005-03-25 12:31:53 -06001857 return 0;
1858}
1859
1860#if 0
1861static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
1862{
1863 struct host_cmd cmd = {
1864 .cmd = IPW_CMD_CARD_DISABLE,
1865 .len = sizeof(u32)
1866 };
1867
1868 if (!priv) {
1869 IPW_ERROR("Invalid args\n");
1870 return -1;
1871 }
1872
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001873 *((u32 *) & cmd.param) = phy_off;
James Ketrenos43f66a62005-03-25 12:31:53 -06001874
1875 if (ipw_send_cmd(priv, &cmd)) {
1876 IPW_ERROR("failed to send CARD_DISABLE command\n");
1877 return -1;
1878 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001879
James Ketrenos43f66a62005-03-25 12:31:53 -06001880 return 0;
1881}
1882#endif
1883
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001884static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06001885{
1886 struct host_cmd cmd = {
1887 .cmd = IPW_CMD_TX_POWER,
1888 .len = sizeof(*power)
1889 };
1890
1891 if (!priv || !power) {
1892 IPW_ERROR("Invalid args\n");
1893 return -1;
1894 }
1895
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001896 memcpy(&cmd.param, power, sizeof(*power));
James Ketrenos43f66a62005-03-25 12:31:53 -06001897 if (ipw_send_cmd(priv, &cmd)) {
1898 IPW_ERROR("failed to send TX_POWER command\n");
1899 return -1;
1900 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001901
James Ketrenos43f66a62005-03-25 12:31:53 -06001902 return 0;
1903}
1904
1905static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
1906{
1907 struct ipw_rts_threshold rts_threshold = {
1908 .rts_threshold = rts,
1909 };
1910 struct host_cmd cmd = {
1911 .cmd = IPW_CMD_RTS_THRESHOLD,
1912 .len = sizeof(rts_threshold)
1913 };
1914
1915 if (!priv) {
1916 IPW_ERROR("Invalid args\n");
1917 return -1;
1918 }
1919
1920 memcpy(&cmd.param, &rts_threshold, sizeof(rts_threshold));
1921 if (ipw_send_cmd(priv, &cmd)) {
1922 IPW_ERROR("failed to send RTS_THRESHOLD command\n");
1923 return -1;
1924 }
1925
1926 return 0;
1927}
1928
1929static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
1930{
1931 struct ipw_frag_threshold frag_threshold = {
1932 .frag_threshold = frag,
1933 };
1934 struct host_cmd cmd = {
1935 .cmd = IPW_CMD_FRAG_THRESHOLD,
1936 .len = sizeof(frag_threshold)
1937 };
1938
1939 if (!priv) {
1940 IPW_ERROR("Invalid args\n");
1941 return -1;
1942 }
1943
1944 memcpy(&cmd.param, &frag_threshold, sizeof(frag_threshold));
1945 if (ipw_send_cmd(priv, &cmd)) {
1946 IPW_ERROR("failed to send FRAG_THRESHOLD command\n");
1947 return -1;
1948 }
1949
1950 return 0;
1951}
1952
1953static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
1954{
1955 struct host_cmd cmd = {
1956 .cmd = IPW_CMD_POWER_MODE,
1957 .len = sizeof(u32)
1958 };
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001959 u32 *param = (u32 *) (&cmd.param);
James Ketrenos43f66a62005-03-25 12:31:53 -06001960
1961 if (!priv) {
1962 IPW_ERROR("Invalid args\n");
1963 return -1;
1964 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001965
James Ketrenos43f66a62005-03-25 12:31:53 -06001966 /* If on battery, set to 3, if AC set to CAM, else user
1967 * level */
1968 switch (mode) {
1969 case IPW_POWER_BATTERY:
1970 *param = IPW_POWER_INDEX_3;
1971 break;
1972 case IPW_POWER_AC:
1973 *param = IPW_POWER_MODE_CAM;
1974 break;
1975 default:
1976 *param = mode;
1977 break;
1978 }
1979
1980 if (ipw_send_cmd(priv, &cmd)) {
1981 IPW_ERROR("failed to send POWER_MODE command\n");
1982 return -1;
1983 }
1984
1985 return 0;
1986}
1987
1988/*
1989 * The IPW device contains a Microwire compatible EEPROM that stores
1990 * various data like the MAC address. Usually the firmware has exclusive
1991 * access to the eeprom, but during device initialization (before the
1992 * device driver has sent the HostComplete command to the firmware) the
1993 * device driver has read access to the EEPROM by way of indirect addressing
1994 * through a couple of memory mapped registers.
1995 *
1996 * The following is a simplified implementation for pulling data out of the
1997 * the eeprom, along with some helper functions to find information in
1998 * the per device private data's copy of the eeprom.
1999 *
2000 * NOTE: To better understand how these functions work (i.e what is a chip
2001 * select and why do have to keep driving the eeprom clock?), read
2002 * just about any data sheet for a Microwire compatible EEPROM.
2003 */
2004
2005/* write a 32 bit value into the indirect accessor register */
2006static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2007{
2008 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002009
James Ketrenos43f66a62005-03-25 12:31:53 -06002010 /* the eeprom requires some time to complete the operation */
2011 udelay(p->eeprom_delay);
2012
2013 return;
2014}
2015
2016/* perform a chip select operation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002017static inline void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002018{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002019 eeprom_write_reg(priv, 0);
2020 eeprom_write_reg(priv, EEPROM_BIT_CS);
2021 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2022 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002023}
2024
2025/* perform a chip select operation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002026static inline void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002027{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002028 eeprom_write_reg(priv, EEPROM_BIT_CS);
2029 eeprom_write_reg(priv, 0);
2030 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002031}
2032
2033/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002034static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002035{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002036 int d = (bit ? EEPROM_BIT_DI : 0);
2037 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2038 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002039}
2040
2041/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002042static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002043{
2044 int i;
2045
2046 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002047 eeprom_write_bit(priv, 1);
2048 eeprom_write_bit(priv, op & 2);
2049 eeprom_write_bit(priv, op & 1);
2050 for (i = 7; i >= 0; i--) {
2051 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002052 }
2053}
2054
2055/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002056static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002057{
2058 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002059 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002060
James Ketrenos43f66a62005-03-25 12:31:53 -06002061 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002062 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002063
2064 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002065 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002066
2067 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002068 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002069 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002070 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2071 eeprom_write_reg(priv, EEPROM_BIT_CS);
2072 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2073 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002074 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002075
James Ketrenos43f66a62005-03-25 12:31:53 -06002076 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002077 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002078 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002079
James Ketrenos43f66a62005-03-25 12:31:53 -06002080 return r;
2081}
2082
2083/* helper function for pulling the mac address out of the private */
2084/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002085static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002086{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002087 u8 *ee = (u8 *) priv->eeprom;
James Ketrenos43f66a62005-03-25 12:31:53 -06002088 memcpy(mac, &ee[EEPROM_MAC_ADDRESS], 6);
2089}
2090
2091/*
2092 * Either the device driver (i.e. the host) or the firmware can
2093 * load eeprom data into the designated region in SRAM. If neither
2094 * happens then the FW will shutdown with a fatal error.
2095 *
2096 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2097 * bit needs region of shared SRAM needs to be non-zero.
2098 */
2099static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2100{
2101 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002102 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002103
James Ketrenos43f66a62005-03-25 12:31:53 -06002104 IPW_DEBUG_TRACE(">>\n");
2105
2106 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002107 for (i = 0; i < 128; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002108 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002109
Jeff Garzikbf794512005-07-31 13:07:26 -04002110 /*
2111 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002112 copy. Otherwise let the firmware know to perform the operation
2113 on it's own
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002114 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002115 if ((priv->eeprom + EEPROM_VERSION) != 0) {
2116 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2117
2118 /* write the eeprom data to sram */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002119 for (i = 0; i < CX2_EEPROM_IMAGE_SIZE; i++)
2120 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002121
2122 /* Do not load eeprom data on fatal error or suspend */
2123 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2124 } else {
2125 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2126
2127 /* Load eeprom data on fatal error or suspend */
2128 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2129 }
2130
2131 IPW_DEBUG_TRACE("<<\n");
2132}
2133
James Ketrenos43f66a62005-03-25 12:31:53 -06002134static inline void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
2135{
2136 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002137 if (!count)
2138 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06002139 _ipw_write32(priv, CX2_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002140 while (count--)
James Ketrenos43f66a62005-03-25 12:31:53 -06002141 _ipw_write32(priv, CX2_AUTOINC_DATA, 0);
2142}
2143
2144static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2145{
2146 ipw_zero_memory(priv, CX2_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002147 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002148 sizeof(struct command_block));
2149}
2150
2151static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002152{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002153
2154 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002155
James Ketrenos43f66a62005-03-25 12:31:53 -06002156 /* Start the dma */
2157 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002158
James Ketrenos43f66a62005-03-25 12:31:53 -06002159 /* Write CB base address */
2160 ipw_write_reg32(priv, CX2_DMA_I_CB_BASE, CX2_SHARED_SRAM_DMA_CONTROL);
2161
2162 IPW_DEBUG_FW("<< : \n");
2163 return 0;
2164}
2165
2166static void ipw_fw_dma_abort(struct ipw_priv *priv)
2167{
2168 u32 control = 0;
2169
2170 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002171
2172 //set the Stop and Abort bit
James Ketrenos43f66a62005-03-25 12:31:53 -06002173 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
2174 ipw_write_reg32(priv, CX2_DMA_I_DMA_CONTROL, control);
2175 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002176
James Ketrenos43f66a62005-03-25 12:31:53 -06002177 IPW_DEBUG_FW("<< \n");
2178}
2179
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002180static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2181 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002182{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002183 u32 address =
2184 CX2_SHARED_SRAM_DMA_CONTROL +
2185 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002186 IPW_DEBUG_FW(">> :\n");
2187
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002188 ipw_write_indirect(priv, address, (u8 *) cb,
2189 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002190
2191 IPW_DEBUG_FW("<< :\n");
2192 return 0;
2193
2194}
2195
2196static int ipw_fw_dma_kick(struct ipw_priv *priv)
2197{
2198 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002199 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002200
2201 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002202
James Ketrenos43f66a62005-03-25 12:31:53 -06002203 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002204 ipw_fw_dma_write_command_block(priv, index,
2205 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002206
2207 /* Enable the DMA in the CSR register */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002208 ipw_clear_bit(priv, CX2_RESET_REG,
2209 CX2_RESET_REG_MASTER_DISABLED |
2210 CX2_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002211
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002212 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002213 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
2214 ipw_write_reg32(priv, CX2_DMA_I_DMA_CONTROL, control);
2215
2216 IPW_DEBUG_FW("<< :\n");
2217 return 0;
2218}
2219
2220static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2221{
2222 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002223 u32 register_value = 0;
2224 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002225
2226 IPW_DEBUG_FW(">> :\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002227 address = ipw_read_reg32(priv, CX2_DMA_I_CURRENT_CB);
2228 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002229
2230 /* Read the DMA Controlor register */
2231 register_value = ipw_read_reg32(priv, CX2_DMA_I_DMA_CONTROL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002232 IPW_DEBUG_FW_INFO("CX2_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002233
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002234 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002235 cb_fields_address = address;
2236 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002237 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002238
2239 cb_fields_address += sizeof(u32);
2240 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002241 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002242
2243 cb_fields_address += sizeof(u32);
2244 register_value = ipw_read_reg32(priv, cb_fields_address);
2245 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2246 register_value);
2247
2248 cb_fields_address += sizeof(u32);
2249 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002250 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002251
2252 IPW_DEBUG_FW(">> :\n");
2253}
2254
2255static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2256{
2257 u32 current_cb_address = 0;
2258 u32 current_cb_index = 0;
2259
2260 IPW_DEBUG_FW("<< :\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002261 current_cb_address = ipw_read_reg32(priv, CX2_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002262
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002263 current_cb_index = (current_cb_address - CX2_SHARED_SRAM_DMA_CONTROL) /
2264 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002265
James Ketrenos43f66a62005-03-25 12:31:53 -06002266 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002267 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002268
2269 IPW_DEBUG_FW(">> :\n");
2270 return current_cb_index;
2271
2272}
2273
2274static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2275 u32 src_address,
2276 u32 dest_address,
2277 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002278 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002279{
2280
Jeff Garzikbf794512005-07-31 13:07:26 -04002281 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002282 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2283 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002284 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002285 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002286
2287 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2288 src_address, dest_address, length);
2289
2290 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2291 return -1;
2292
2293 last_cb_element = priv->sram_desc.last_cb_index;
2294 cb = &priv->sram_desc.cb_list[last_cb_element];
2295 priv->sram_desc.last_cb_index++;
2296
2297 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002298 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002299 control |= CB_INT_ENABLED;
2300
2301 if (is_last)
2302 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002303
James Ketrenos43f66a62005-03-25 12:31:53 -06002304 control |= length;
2305
2306 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002307 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002308
2309 /* Copy the Source and Destination addresses */
2310 cb->dest_addr = dest_address;
2311 cb->source_addr = src_address;
2312
2313 /* Copy the Control Word last */
2314 cb->control = control;
2315
2316 return 0;
2317}
2318
2319static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002320 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06002321{
2322 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002323 u32 src_offset = 0;
2324 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002325 int status = 0;
2326 IPW_DEBUG_FW(">> \n");
2327 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2328 src_phys, dest_address, length);
2329 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002330 status = ipw_fw_dma_add_command_block(priv,
2331 src_phys + src_offset,
2332 dest_address +
2333 dest_offset,
2334 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002335 if (status) {
2336 IPW_DEBUG_FW_INFO(": Failed\n");
2337 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002338 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002339 IPW_DEBUG_FW_INFO(": Added new cb\n");
2340
2341 src_offset += CB_MAX_LENGTH;
2342 dest_offset += CB_MAX_LENGTH;
2343 bytes_left -= CB_MAX_LENGTH;
2344 }
2345
2346 /* add the buffer tail */
2347 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002348 status =
2349 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2350 dest_address + dest_offset,
2351 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002352 if (status) {
2353 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2354 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002355 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002356 IPW_DEBUG_FW_INFO
2357 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002358 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002359
James Ketrenos43f66a62005-03-25 12:31:53 -06002360 IPW_DEBUG_FW("<< \n");
2361 return 0;
2362}
2363
2364static int ipw_fw_dma_wait(struct ipw_priv *priv)
2365{
2366 u32 current_index = 0;
2367 u32 watchdog = 0;
2368
2369 IPW_DEBUG_FW(">> : \n");
2370
2371 current_index = ipw_fw_dma_command_block_index(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002372 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002373 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002374
2375 while (current_index < priv->sram_desc.last_cb_index) {
2376 udelay(50);
2377 current_index = ipw_fw_dma_command_block_index(priv);
2378
2379 watchdog++;
2380
2381 if (watchdog > 400) {
2382 IPW_DEBUG_FW_INFO("Timeout\n");
2383 ipw_fw_dma_dump_command_block(priv);
2384 ipw_fw_dma_abort(priv);
2385 return -1;
2386 }
2387 }
2388
2389 ipw_fw_dma_abort(priv);
2390
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002391 /*Disable the DMA in the CSR register */
2392 ipw_set_bit(priv, CX2_RESET_REG,
James Ketrenos43f66a62005-03-25 12:31:53 -06002393 CX2_RESET_REG_MASTER_DISABLED | CX2_RESET_REG_STOP_MASTER);
2394
2395 IPW_DEBUG_FW("<< dmaWaitSync \n");
2396 return 0;
2397}
2398
Jeff Garzikbf794512005-07-31 13:07:26 -04002399static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002400{
2401 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002402 struct ieee80211_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002403 unsigned long flags;
2404
2405 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002406 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2407 network = list_entry(element, struct ieee80211_network, list);
2408 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2409 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002410 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002411 &priv->ieee->network_free_list);
2412 }
2413 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002414 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002415}
2416
2417/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002418 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002419 * Reads debug register from domain0.
2420 * If card is present, pre-defined value should
2421 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002422 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002423 * @param priv
2424 * @return 1 if card is present, 0 otherwise
2425 */
2426static inline int ipw_alive(struct ipw_priv *priv)
2427{
2428 return ipw_read32(priv, 0x90) == 0xd55555d5;
2429}
2430
2431static inline int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
2432 int timeout)
2433{
2434 int i = 0;
2435
2436 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002437 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002438 return i;
2439 mdelay(10);
2440 i += 10;
2441 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002442
James Ketrenos43f66a62005-03-25 12:31:53 -06002443 return -ETIME;
2444}
2445
Jeff Garzikbf794512005-07-31 13:07:26 -04002446/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002447 * the ipw hardware. It assumes the buffer has all the bits for the
2448 * image and the caller is handling the memory allocation and clean up.
2449 */
2450
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002451static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002452{
2453 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002454
James Ketrenos43f66a62005-03-25 12:31:53 -06002455 IPW_DEBUG_TRACE(">> \n");
2456 /* stop master. typical delay - 0 */
2457 ipw_set_bit(priv, CX2_RESET_REG, CX2_RESET_REG_STOP_MASTER);
2458
2459 rc = ipw_poll_bit(priv, CX2_RESET_REG,
2460 CX2_RESET_REG_MASTER_DISABLED, 100);
2461 if (rc < 0) {
2462 IPW_ERROR("stop master failed in 10ms\n");
2463 return -1;
2464 }
2465
2466 IPW_DEBUG_INFO("stop master %dms\n", rc);
2467
2468 return rc;
2469}
2470
2471static void ipw_arc_release(struct ipw_priv *priv)
2472{
2473 IPW_DEBUG_TRACE(">> \n");
2474 mdelay(5);
2475
2476 ipw_clear_bit(priv, CX2_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
2477
2478 /* no one knows timing, for safety add some delay */
2479 mdelay(5);
2480}
2481
2482struct fw_header {
2483 u32 version;
2484 u32 mode;
2485};
2486
2487struct fw_chunk {
2488 u32 address;
2489 u32 length;
2490};
2491
2492#define IPW_FW_MAJOR_VERSION 2
2493#define IPW_FW_MINOR_VERSION 2
2494
2495#define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
2496#define IPW_FW_MAJOR(x) (x & 0xff)
2497
2498#define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | \
2499 IPW_FW_MAJOR_VERSION)
2500
2501#define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
2502"." __stringify(IPW_FW_MINOR_VERSION) "-"
2503
2504#if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
2505#define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
2506#else
2507#define IPW_FW_NAME(x) "ipw2200_" x ".fw"
2508#endif
2509
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002510static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002511{
2512 int rc = 0, i, addr;
2513 u8 cr = 0;
2514 u16 *image;
2515
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002516 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002517
James Ketrenos43f66a62005-03-25 12:31:53 -06002518 IPW_DEBUG_TRACE(">> \n");
2519
2520 rc = ipw_stop_master(priv);
2521
2522 if (rc < 0)
2523 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002524
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002525// spin_lock_irqsave(&priv->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04002526
James Ketrenos43f66a62005-03-25 12:31:53 -06002527 for (addr = CX2_SHARED_LOWER_BOUND;
2528 addr < CX2_REGISTER_DOMAIN1_END; addr += 4) {
2529 ipw_write32(priv, addr, 0);
2530 }
2531
2532 /* no ucode (yet) */
2533 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2534 /* destroy DMA queues */
2535 /* reset sequence */
2536
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002537 ipw_write_reg32(priv, CX2_MEM_HALT_AND_RESET, CX2_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06002538 ipw_arc_release(priv);
2539 ipw_write_reg32(priv, CX2_MEM_HALT_AND_RESET, CX2_BIT_HALT_RESET_OFF);
2540 mdelay(1);
2541
2542 /* reset PHY */
2543 ipw_write_reg32(priv, CX2_INTERNAL_CMD_EVENT, CX2_BASEBAND_POWER_DOWN);
2544 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002545
James Ketrenos43f66a62005-03-25 12:31:53 -06002546 ipw_write_reg32(priv, CX2_INTERNAL_CMD_EVENT, 0);
2547 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002548
James Ketrenos43f66a62005-03-25 12:31:53 -06002549 /* enable ucode store */
2550 ipw_write_reg8(priv, DINO_CONTROL_REG, 0x0);
2551 ipw_write_reg8(priv, DINO_CONTROL_REG, DINO_ENABLE_CS);
2552 mdelay(1);
2553
2554 /* write ucode */
2555 /**
2556 * @bug
2557 * Do NOT set indirect address register once and then
2558 * store data to indirect data register in the loop.
2559 * It seems very reasonable, but in this case DINO do not
2560 * accept ucode. It is essential to set address each time.
2561 */
2562 /* load new ipw uCode */
2563 for (i = 0; i < len / 2; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002564 ipw_write_reg16(priv, CX2_BASEBAND_CONTROL_STORE,
2565 cpu_to_le16(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06002566
James Ketrenos43f66a62005-03-25 12:31:53 -06002567 /* enable DINO */
2568 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 0);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002569 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002570
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002571 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002572
2573 /* wait for alive response */
2574 for (i = 0; i < 100; i++) {
2575 /* poll for incoming data */
2576 cr = ipw_read_reg8(priv, CX2_BASEBAND_CONTROL_STATUS);
2577 if (cr & DINO_RXFIFO_DATA)
2578 break;
2579 mdelay(1);
2580 }
2581
2582 if (cr & DINO_RXFIFO_DATA) {
2583 /* alive_command_responce size is NOT multiple of 4 */
2584 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04002585
2586 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06002587 response_buffer[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05002588 le32_to_cpu(ipw_read_reg32(priv,
2589 CX2_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06002590 memcpy(&priv->dino_alive, response_buffer,
2591 sizeof(priv->dino_alive));
2592 if (priv->dino_alive.alive_command == 1
2593 && priv->dino_alive.ucode_valid == 1) {
2594 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002595 IPW_DEBUG_INFO
2596 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2597 "of %02d/%02d/%02d %02d:%02d\n",
2598 priv->dino_alive.software_revision,
2599 priv->dino_alive.software_revision,
2600 priv->dino_alive.device_identifier,
2601 priv->dino_alive.device_identifier,
2602 priv->dino_alive.time_stamp[0],
2603 priv->dino_alive.time_stamp[1],
2604 priv->dino_alive.time_stamp[2],
2605 priv->dino_alive.time_stamp[3],
2606 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002607 } else {
2608 IPW_DEBUG_INFO("Microcode is not alive\n");
2609 rc = -EINVAL;
2610 }
2611 } else {
2612 IPW_DEBUG_INFO("No alive response from DINO\n");
2613 rc = -ETIME;
2614 }
2615
2616 /* disable DINO, otherwise for some reason
2617 firmware have problem getting alive resp. */
2618 ipw_write_reg8(priv, CX2_BASEBAND_CONTROL_STATUS, 0);
2619
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002620// spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002621
2622 return rc;
2623}
2624
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002625static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002626{
2627 int rc = -1;
2628 int offset = 0;
2629 struct fw_chunk *chunk;
2630 dma_addr_t shared_phys;
2631 u8 *shared_virt;
2632
2633 IPW_DEBUG_TRACE("<< : \n");
2634 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
2635
2636 if (!shared_virt)
2637 return -ENOMEM;
2638
2639 memmove(shared_virt, data, len);
2640
2641 /* Start the Dma */
2642 rc = ipw_fw_dma_enable(priv);
2643
2644 if (priv->sram_desc.last_cb_index > 0) {
2645 /* the DMA is already ready this would be a bug. */
2646 BUG();
2647 goto out;
2648 }
2649
2650 do {
2651 chunk = (struct fw_chunk *)(data + offset);
2652 offset += sizeof(struct fw_chunk);
2653 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04002654 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06002655 * offeset*/
2656 /* Dma loading */
2657 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
James Ketrenosa613bff2005-08-24 21:43:11 -05002658 le32_to_cpu(chunk->address),
2659 le32_to_cpu(chunk->length));
James Ketrenos43f66a62005-03-25 12:31:53 -06002660 if (rc) {
2661 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
2662 goto out;
2663 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002664
James Ketrenosa613bff2005-08-24 21:43:11 -05002665 offset += le32_to_cpu(chunk->length);
James Ketrenos43f66a62005-03-25 12:31:53 -06002666 } while (offset < len);
2667
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002668 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06002669 rc = ipw_fw_dma_kick(priv);
2670 if (rc) {
2671 IPW_ERROR("dmaKick Failed\n");
2672 goto out;
2673 }
2674
2675 rc = ipw_fw_dma_wait(priv);
2676 if (rc) {
2677 IPW_ERROR("dmaWaitSync Failed\n");
2678 goto out;
2679 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002680 out:
2681 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06002682 return rc;
2683}
2684
2685/* stop nic */
2686static int ipw_stop_nic(struct ipw_priv *priv)
2687{
2688 int rc = 0;
2689
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002690 /* stop */
James Ketrenos43f66a62005-03-25 12:31:53 -06002691 ipw_write32(priv, CX2_RESET_REG, CX2_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002692
2693 rc = ipw_poll_bit(priv, CX2_RESET_REG,
2694 CX2_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06002695 if (rc < 0) {
2696 IPW_ERROR("wait for reg master disabled failed\n");
2697 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002698 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002699
2700 ipw_set_bit(priv, CX2_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04002701
James Ketrenos43f66a62005-03-25 12:31:53 -06002702 return rc;
2703}
2704
2705static void ipw_start_nic(struct ipw_priv *priv)
2706{
2707 IPW_DEBUG_TRACE(">>\n");
2708
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002709 /* prvHwStartNic release ARC */
James Ketrenos43f66a62005-03-25 12:31:53 -06002710 ipw_clear_bit(priv, CX2_RESET_REG,
Jeff Garzikbf794512005-07-31 13:07:26 -04002711 CX2_RESET_REG_MASTER_DISABLED |
2712 CX2_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06002713 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04002714
James Ketrenos43f66a62005-03-25 12:31:53 -06002715 /* enable power management */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002716 ipw_set_bit(priv, CX2_GP_CNTRL_RW,
2717 CX2_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06002718
2719 IPW_DEBUG_TRACE("<<\n");
2720}
Jeff Garzikbf794512005-07-31 13:07:26 -04002721
James Ketrenos43f66a62005-03-25 12:31:53 -06002722static int ipw_init_nic(struct ipw_priv *priv)
2723{
2724 int rc;
2725
2726 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002727 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06002728 /*prvHwInitNic */
2729 /* set "initialization complete" bit to move adapter to D0 state */
2730 ipw_set_bit(priv, CX2_GP_CNTRL_RW, CX2_GP_CNTRL_BIT_INIT_DONE);
2731
2732 /* low-level PLL activation */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002733 ipw_write32(priv, CX2_READ_INT_REGISTER,
2734 CX2_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002735
2736 /* wait for clock stabilization */
Jeff Garzikbf794512005-07-31 13:07:26 -04002737 rc = ipw_poll_bit(priv, CX2_GP_CNTRL_RW,
2738 CX2_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002739 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06002740 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
2741
2742 /* assert SW reset */
2743 ipw_set_bit(priv, CX2_RESET_REG, CX2_RESET_REG_SW_RESET);
2744
2745 udelay(10);
2746
2747 /* set "initialization complete" bit to move adapter to D0 state */
2748 ipw_set_bit(priv, CX2_GP_CNTRL_RW, CX2_GP_CNTRL_BIT_INIT_DONE);
2749
2750 IPW_DEBUG_TRACE(">>\n");
2751 return 0;
2752}
2753
Jeff Garzikbf794512005-07-31 13:07:26 -04002754/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06002755 * Probe is an ok place to call this from.
2756 */
2757static int ipw_reset_nic(struct ipw_priv *priv)
2758{
2759 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002760 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06002761
2762 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002763
James Ketrenos43f66a62005-03-25 12:31:53 -06002764 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002765
James Ketrenosa613bff2005-08-24 21:43:11 -05002766 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002767 /* Clear the 'host command active' bit... */
2768 priv->status &= ~STATUS_HCMD_ACTIVE;
2769 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosa613bff2005-08-24 21:43:11 -05002770 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002771
2772 IPW_DEBUG_TRACE("<<\n");
2773 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002774}
James Ketrenos43f66a62005-03-25 12:31:53 -06002775
Jeff Garzikbf794512005-07-31 13:07:26 -04002776static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06002777 const struct firmware **fw, const char *name)
2778{
2779 struct fw_header *header;
2780 int rc;
2781
2782 /* ask firmware_class module to get the boot firmware off disk */
2783 rc = request_firmware(fw, name, &priv->pci_dev->dev);
2784 if (rc < 0) {
2785 IPW_ERROR("%s load failed: Reason %d\n", name, rc);
2786 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002787 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002788
2789 header = (struct fw_header *)(*fw)->data;
James Ketrenosa613bff2005-08-24 21:43:11 -05002790 if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002791 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
2792 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05002793 IPW_FW_MAJOR(le32_to_cpu(header->version)),
2794 IPW_FW_MAJOR_VERSION);
James Ketrenos43f66a62005-03-25 12:31:53 -06002795 return -EINVAL;
2796 }
2797
Jiri Bencaaa4d302005-06-07 14:58:41 +02002798 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06002799 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05002800 IPW_FW_MAJOR(le32_to_cpu(header->version)),
2801 IPW_FW_MINOR(le32_to_cpu(header->version)),
James Ketrenos43f66a62005-03-25 12:31:53 -06002802 (*fw)->size - sizeof(struct fw_header));
2803 return 0;
2804}
2805
2806#define CX2_RX_BUF_SIZE (3000)
2807
2808static inline void ipw_rx_queue_reset(struct ipw_priv *priv,
2809 struct ipw_rx_queue *rxq)
2810{
2811 unsigned long flags;
2812 int i;
2813
2814 spin_lock_irqsave(&rxq->lock, flags);
2815
2816 INIT_LIST_HEAD(&rxq->rx_free);
2817 INIT_LIST_HEAD(&rxq->rx_used);
2818
2819 /* Fill the rx_used queue with _all_ of the Rx buffers */
2820 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
2821 /* In the reset function, these buffers may have been allocated
2822 * to an SKB, so we need to unmap and free potential storage */
2823 if (rxq->pool[i].skb != NULL) {
2824 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002825 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002826 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05002827 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06002828 }
2829 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
2830 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002831
James Ketrenos43f66a62005-03-25 12:31:53 -06002832 /* Set us so that we have processed and used all buffers, but have
2833 * not restocked the Rx queue with fresh buffers */
2834 rxq->read = rxq->write = 0;
2835 rxq->processed = RX_QUEUE_SIZE - 1;
2836 rxq->free_count = 0;
2837 spin_unlock_irqrestore(&rxq->lock, flags);
2838}
2839
2840#ifdef CONFIG_PM
2841static int fw_loaded = 0;
2842static const struct firmware *bootfw = NULL;
2843static const struct firmware *firmware = NULL;
2844static const struct firmware *ucode = NULL;
2845#endif
2846
2847static int ipw_load(struct ipw_priv *priv)
2848{
2849#ifndef CONFIG_PM
2850 const struct firmware *bootfw = NULL;
2851 const struct firmware *firmware = NULL;
2852 const struct firmware *ucode = NULL;
2853#endif
2854 int rc = 0, retries = 3;
2855
2856#ifdef CONFIG_PM
2857 if (!fw_loaded) {
2858#endif
2859 rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot"));
Jeff Garzikbf794512005-07-31 13:07:26 -04002860 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06002861 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04002862
James Ketrenos43f66a62005-03-25 12:31:53 -06002863 switch (priv->ieee->iw_mode) {
2864 case IW_MODE_ADHOC:
Jeff Garzikbf794512005-07-31 13:07:26 -04002865 rc = ipw_get_fw(priv, &ucode,
James Ketrenos43f66a62005-03-25 12:31:53 -06002866 IPW_FW_NAME("ibss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04002867 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06002868 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04002869
James Ketrenos43f66a62005-03-25 12:31:53 -06002870 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss"));
2871 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04002872
James Ketrenosea2b26e2005-08-24 21:25:16 -05002873#ifdef CONFIG_IPW_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06002874 case IW_MODE_MONITOR:
Jeff Garzikbf794512005-07-31 13:07:26 -04002875 rc = ipw_get_fw(priv, &ucode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05002876 IPW_FW_NAME("sniffer_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04002877 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06002878 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04002879
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002880 rc = ipw_get_fw(priv, &firmware,
2881 IPW_FW_NAME("sniffer"));
James Ketrenos43f66a62005-03-25 12:31:53 -06002882 break;
2883#endif
2884 case IW_MODE_INFRA:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002885 rc = ipw_get_fw(priv, &ucode, IPW_FW_NAME("bss_ucode"));
Jeff Garzikbf794512005-07-31 13:07:26 -04002886 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06002887 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04002888
James Ketrenos43f66a62005-03-25 12:31:53 -06002889 rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("bss"));
2890 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04002891
James Ketrenos43f66a62005-03-25 12:31:53 -06002892 default:
2893 rc = -EINVAL;
2894 }
2895
Jeff Garzikbf794512005-07-31 13:07:26 -04002896 if (rc)
James Ketrenos43f66a62005-03-25 12:31:53 -06002897 goto error;
2898
2899#ifdef CONFIG_PM
2900 fw_loaded = 1;
2901 }
2902#endif
2903
2904 if (!priv->rxq)
2905 priv->rxq = ipw_rx_queue_alloc(priv);
2906 else
2907 ipw_rx_queue_reset(priv, priv->rxq);
2908 if (!priv->rxq) {
2909 IPW_ERROR("Unable to initialize Rx queue\n");
2910 goto error;
2911 }
2912
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002913 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06002914 /* Ensure interrupts are disabled */
2915 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL);
2916 priv->status &= ~STATUS_INT_ENABLED;
2917
2918 /* ack pending interrupts */
2919 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04002920
James Ketrenos43f66a62005-03-25 12:31:53 -06002921 ipw_stop_nic(priv);
2922
2923 rc = ipw_reset_nic(priv);
2924 if (rc) {
2925 IPW_ERROR("Unable to reset NIC\n");
2926 goto error;
2927 }
2928
Jeff Garzikbf794512005-07-31 13:07:26 -04002929 ipw_zero_memory(priv, CX2_NIC_SRAM_LOWER_BOUND,
James Ketrenos43f66a62005-03-25 12:31:53 -06002930 CX2_NIC_SRAM_UPPER_BOUND - CX2_NIC_SRAM_LOWER_BOUND);
2931
2932 /* DMA the initial boot firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04002933 rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06002934 bootfw->size - sizeof(struct fw_header));
2935 if (rc < 0) {
2936 IPW_ERROR("Unable to load boot firmware\n");
2937 goto error;
2938 }
2939
2940 /* kick start the device */
2941 ipw_start_nic(priv);
2942
2943 /* wait for the device to finish it's initial startup sequence */
Jeff Garzikbf794512005-07-31 13:07:26 -04002944 rc = ipw_poll_bit(priv, CX2_INTA_RW,
2945 CX2_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06002946 if (rc < 0) {
2947 IPW_ERROR("device failed to boot initial fw image\n");
2948 goto error;
2949 }
2950 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
2951
Jeff Garzikbf794512005-07-31 13:07:26 -04002952 /* ack fw init done interrupt */
James Ketrenos43f66a62005-03-25 12:31:53 -06002953 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_BIT_FW_INITIALIZATION_DONE);
2954
2955 /* DMA the ucode into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04002956 rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06002957 ucode->size - sizeof(struct fw_header));
2958 if (rc < 0) {
2959 IPW_ERROR("Unable to load ucode\n");
2960 goto error;
2961 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002962
James Ketrenos43f66a62005-03-25 12:31:53 -06002963 /* stop nic */
2964 ipw_stop_nic(priv);
2965
2966 /* DMA bss firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04002967 rc = ipw_load_firmware(priv, firmware->data +
2968 sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06002969 firmware->size - sizeof(struct fw_header));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002970 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002971 IPW_ERROR("Unable to load firmware\n");
2972 goto error;
2973 }
2974
2975 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2976
2977 rc = ipw_queue_reset(priv);
2978 if (rc) {
2979 IPW_ERROR("Unable to initialize queues\n");
2980 goto error;
2981 }
2982
2983 /* Ensure interrupts are disabled */
2984 ipw_write32(priv, CX2_INTA_MASK_R, ~CX2_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04002985
James Ketrenos43f66a62005-03-25 12:31:53 -06002986 /* kick start the device */
2987 ipw_start_nic(priv);
2988
2989 if (ipw_read32(priv, CX2_INTA_RW) & CX2_INTA_BIT_PARITY_ERROR) {
2990 if (retries > 0) {
2991 IPW_WARNING("Parity error. Retrying init.\n");
2992 retries--;
2993 goto retry;
2994 }
2995
2996 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
2997 rc = -EIO;
2998 goto error;
2999 }
3000
3001 /* wait for the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003002 rc = ipw_poll_bit(priv, CX2_INTA_RW,
3003 CX2_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003004 if (rc < 0) {
3005 IPW_ERROR("device failed to start after 500ms\n");
3006 goto error;
3007 }
3008 IPW_DEBUG_INFO("device response after %dms\n", rc);
3009
3010 /* ack fw init done interrupt */
3011 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_BIT_FW_INITIALIZATION_DONE);
3012
3013 /* read eeprom data and initialize the eeprom region of sram */
3014 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003015 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003016
3017 /* enable interrupts */
3018 ipw_enable_interrupts(priv);
3019
3020 /* Ensure our queue has valid packets */
3021 ipw_rx_queue_replenish(priv);
3022
3023 ipw_write32(priv, CX2_RX_READ_INDEX, priv->rxq->read);
3024
3025 /* ack pending interrupts */
3026 ipw_write32(priv, CX2_INTA_RW, CX2_INTA_MASK_ALL);
3027
3028#ifndef CONFIG_PM
3029 release_firmware(bootfw);
3030 release_firmware(ucode);
3031 release_firmware(firmware);
3032#endif
3033 return 0;
3034
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003035 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003036 if (priv->rxq) {
3037 ipw_rx_queue_free(priv, priv->rxq);
3038 priv->rxq = NULL;
3039 }
3040 ipw_tx_queue_free(priv);
3041 if (bootfw)
3042 release_firmware(bootfw);
3043 if (ucode)
3044 release_firmware(ucode);
3045 if (firmware)
3046 release_firmware(firmware);
3047#ifdef CONFIG_PM
3048 fw_loaded = 0;
3049 bootfw = ucode = firmware = NULL;
3050#endif
3051
3052 return rc;
3053}
3054
Jeff Garzikbf794512005-07-31 13:07:26 -04003055/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003056 * DMA services
3057 *
3058 * Theory of operation
3059 *
3060 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3061 * 2 empty entries always kept in the buffer to protect from overflow.
3062 *
3063 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003064 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3065 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003066 * Tx queue resumed.
3067 *
3068 * The IPW operates with six queues, one receive queue in the device's
3069 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003070 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003071 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003072 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003073 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003074 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003075 * we only utilize the first data transmit queue (queue1).
3076 */
3077
3078/**
3079 * Driver allocates buffers of this size for Rx
3080 */
3081
3082static inline int ipw_queue_space(const struct clx2_queue *q)
3083{
3084 int s = q->last_used - q->first_empty;
3085 if (s <= 0)
3086 s += q->n_bd;
3087 s -= 2; /* keep some reserve to not confuse empty and full situations */
3088 if (s < 0)
3089 s = 0;
3090 return s;
3091}
3092
3093static inline int ipw_queue_inc_wrap(int index, int n_bd)
3094{
3095 return (++index == n_bd) ? 0 : index;
3096}
3097
3098/**
3099 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003100 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003101 * @param q queue to init
3102 * @param count Number of BD's to allocate. Should be power of 2
3103 * @param read_register Address for 'read' register
3104 * (not offset within BAR, full address)
3105 * @param write_register Address for 'write' register
3106 * (not offset within BAR, full address)
3107 * @param base_register Address for 'base' register
3108 * (not offset within BAR, full address)
3109 * @param size Address for 'size' register
3110 * (not offset within BAR, full address)
3111 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003112static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003113 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003114{
3115 q->n_bd = count;
3116
3117 q->low_mark = q->n_bd / 4;
3118 if (q->low_mark < 4)
3119 q->low_mark = 4;
3120
3121 q->high_mark = q->n_bd / 8;
3122 if (q->high_mark < 2)
3123 q->high_mark = 2;
3124
3125 q->first_empty = q->last_used = 0;
3126 q->reg_r = read;
3127 q->reg_w = write;
3128
3129 ipw_write32(priv, base, q->dma_addr);
3130 ipw_write32(priv, size, count);
3131 ipw_write32(priv, read, 0);
3132 ipw_write32(priv, write, 0);
3133
3134 _ipw_read32(priv, 0x90);
3135}
3136
Jeff Garzikbf794512005-07-31 13:07:26 -04003137static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003138 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003139 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003140{
3141 struct pci_dev *dev = priv->pci_dev;
3142
3143 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3144 if (!q->txb) {
3145 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3146 return -ENOMEM;
3147 }
3148
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003149 q->bd =
3150 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003151 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003152 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003153 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003154 kfree(q->txb);
3155 q->txb = NULL;
3156 return -ENOMEM;
3157 }
3158
3159 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3160 return 0;
3161}
3162
3163/**
3164 * Free one TFD, those at index [txq->q.last_used].
3165 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003166 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003167 * @param dev
3168 * @param txq
3169 */
3170static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3171 struct clx2_tx_queue *txq)
3172{
3173 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3174 struct pci_dev *dev = priv->pci_dev;
3175 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003176
James Ketrenos43f66a62005-03-25 12:31:53 -06003177 /* classify bd */
3178 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3179 /* nothing to cleanup after for host commands */
3180 return;
3181
3182 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003183 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3184 IPW_ERROR("Too many chunks: %i\n",
3185 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003186 /** @todo issue fatal error, it is quite serious situation */
3187 return;
3188 }
3189
3190 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003191 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3192 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3193 le16_to_cpu(bd->u.data.chunk_len[i]),
3194 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003195 if (txq->txb[txq->q.last_used]) {
3196 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3197 txq->txb[txq->q.last_used] = NULL;
3198 }
3199 }
3200}
3201
3202/**
3203 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003204 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003205 * Empty queue by removing and destroying all BD's.
3206 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003207 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003208 * @param dev
3209 * @param q
3210 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003211static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003212{
3213 struct clx2_queue *q = &txq->q;
3214 struct pci_dev *dev = priv->pci_dev;
3215
Jeff Garzikbf794512005-07-31 13:07:26 -04003216 if (q->n_bd == 0)
3217 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003218
3219 /* first, empty all BD's */
3220 for (; q->first_empty != q->last_used;
3221 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3222 ipw_queue_tx_free_tfd(priv, txq);
3223 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003224
James Ketrenos43f66a62005-03-25 12:31:53 -06003225 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003226 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003227 q->dma_addr);
3228 kfree(txq->txb);
3229
3230 /* 0 fill whole structure */
3231 memset(txq, 0, sizeof(*txq));
3232}
3233
James Ketrenos43f66a62005-03-25 12:31:53 -06003234/**
3235 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003236 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003237 * @param priv
3238 */
3239static void ipw_tx_queue_free(struct ipw_priv *priv)
3240{
3241 /* Tx CMD queue */
3242 ipw_queue_tx_free(priv, &priv->txq_cmd);
3243
3244 /* Tx queues */
3245 ipw_queue_tx_free(priv, &priv->txq[0]);
3246 ipw_queue_tx_free(priv, &priv->txq[1]);
3247 ipw_queue_tx_free(priv, &priv->txq[2]);
3248 ipw_queue_tx_free(priv, &priv->txq[3]);
3249}
3250
3251static void inline __maybe_wake_tx(struct ipw_priv *priv)
3252{
3253 if (netif_running(priv->net_dev)) {
3254 switch (priv->port_type) {
3255 case DCR_TYPE_MU_BSS:
3256 case DCR_TYPE_MU_IBSS:
James Ketrenosa613bff2005-08-24 21:43:11 -05003257 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003258 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003259 }
3260 netif_wake_queue(priv->net_dev);
3261 }
3262
3263}
3264
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003265static inline void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003266{
3267 /* First 3 bytes are manufacturer */
3268 bssid[0] = priv->mac_addr[0];
3269 bssid[1] = priv->mac_addr[1];
3270 bssid[2] = priv->mac_addr[2];
3271
3272 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003273 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003274
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003275 bssid[0] &= 0xfe; /* clear multicast bit */
3276 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003277}
3278
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003279static inline u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003280{
3281 struct ipw_station_entry entry;
3282 int i;
3283
3284 for (i = 0; i < priv->num_stations; i++) {
3285 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3286 /* Another node is active in network */
3287 priv->missed_adhoc_beacons = 0;
3288 if (!(priv->config & CFG_STATIC_CHANNEL))
3289 /* when other nodes drop out, we drop out */
3290 priv->config &= ~CFG_ADHOC_PERSIST;
3291
3292 return i;
3293 }
3294 }
3295
3296 if (i == MAX_STATIONS)
3297 return IPW_INVALID_STATION;
3298
3299 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3300
3301 entry.reserved = 0;
3302 entry.support_mode = 0;
3303 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3304 memcpy(priv->stations[i], bssid, ETH_ALEN);
3305 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003306 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003307 priv->num_stations++;
3308
3309 return i;
3310}
3311
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003312static inline u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003313{
3314 int i;
3315
Jeff Garzikbf794512005-07-31 13:07:26 -04003316 for (i = 0; i < priv->num_stations; i++)
3317 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003318 return i;
3319
3320 return IPW_INVALID_STATION;
3321}
3322
3323static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3324{
3325 int err;
3326
3327 if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))) {
3328 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3329 return;
3330 }
3331
3332 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3333 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04003334 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06003335 priv->assoc_request.channel);
3336
3337 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3338 priv->status |= STATUS_DISASSOCIATING;
3339
3340 if (quiet)
3341 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3342 else
3343 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
3344 err = ipw_send_associate(priv, &priv->assoc_request);
3345 if (err) {
3346 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3347 "failed.\n");
3348 return;
3349 }
3350
3351}
3352
3353static void ipw_disassociate(void *data)
3354{
3355 ipw_send_disassociate(data, 0);
3356}
3357
James Ketrenos43f66a62005-03-25 12:31:53 -06003358struct ipw_status_code {
3359 u16 status;
3360 const char *reason;
3361};
3362
3363static const struct ipw_status_code ipw_status_codes[] = {
3364 {0x00, "Successful"},
3365 {0x01, "Unspecified failure"},
3366 {0x0A, "Cannot support all requested capabilities in the "
3367 "Capability information field"},
3368 {0x0B, "Reassociation denied due to inability to confirm that "
3369 "association exists"},
3370 {0x0C, "Association denied due to reason outside the scope of this "
3371 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003372 {0x0D,
3373 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003374 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003375 {0x0E,
3376 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003377 "transaction sequence number out of expected sequence"},
3378 {0x0F, "Authentication rejected because of challenge failure"},
3379 {0x10, "Authentication rejected due to timeout waiting for next "
3380 "frame in sequence"},
3381 {0x11, "Association denied because AP is unable to handle additional "
3382 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003383 {0x12,
3384 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003385 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003386 {0x13,
3387 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003388 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003389 {0x14,
3390 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003391 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003392 {0x15,
3393 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003394 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003395 {0x19,
3396 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003397 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003398 {0x1A,
3399 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003400 "DSSS-OFDM operation"},
3401 {0x28, "Invalid Information Element"},
3402 {0x29, "Group Cipher is not valid"},
3403 {0x2A, "Pairwise Cipher is not valid"},
3404 {0x2B, "AKMP is not valid"},
3405 {0x2C, "Unsupported RSN IE version"},
3406 {0x2D, "Invalid RSN IE Capabilities"},
3407 {0x2E, "Cipher suite is rejected per security policy"},
3408};
3409
3410#ifdef CONFIG_IPW_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04003411static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003412{
3413 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003414 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003415 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003416 return ipw_status_codes[i].reason;
3417 return "Unknown status value.";
3418}
3419#endif
3420
3421static void inline average_init(struct average *avg)
3422{
3423 memset(avg, 0, sizeof(*avg));
3424}
3425
3426static void inline average_add(struct average *avg, s16 val)
3427{
3428 avg->sum -= avg->entries[avg->pos];
3429 avg->sum += val;
3430 avg->entries[avg->pos++] = val;
3431 if (unlikely(avg->pos == AVG_ENTRIES)) {
3432 avg->init = 1;
3433 avg->pos = 0;
3434 }
3435}
3436
3437static s16 inline average_value(struct average *avg)
3438{
3439 if (!unlikely(avg->init)) {
3440 if (avg->pos)
3441 return avg->sum / avg->pos;
3442 return 0;
3443 }
3444
3445 return avg->sum / AVG_ENTRIES;
3446}
3447
3448static void ipw_reset_stats(struct ipw_priv *priv)
3449{
3450 u32 len = sizeof(u32);
3451
3452 priv->quality = 0;
3453
3454 average_init(&priv->average_missed_beacons);
3455 average_init(&priv->average_rssi);
3456 average_init(&priv->average_noise);
3457
3458 priv->last_rate = 0;
3459 priv->last_missed_beacons = 0;
3460 priv->last_rx_packets = 0;
3461 priv->last_tx_packets = 0;
3462 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003463
James Ketrenos43f66a62005-03-25 12:31:53 -06003464 /* Firmware managed, reset only when NIC is restarted, so we have to
3465 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003466 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003467 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003468 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003469 &priv->last_tx_failures, &len);
3470
3471 /* Driver managed, reset with each association */
3472 priv->missed_adhoc_beacons = 0;
3473 priv->missed_beacons = 0;
3474 priv->tx_packets = 0;
3475 priv->rx_packets = 0;
3476
3477}
3478
James Ketrenos43f66a62005-03-25 12:31:53 -06003479static inline u32 ipw_get_max_rate(struct ipw_priv *priv)
3480{
3481 u32 i = 0x80000000;
3482 u32 mask = priv->rates_mask;
3483 /* If currently associated in B mode, restrict the maximum
3484 * rate match to B rates */
3485 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3486 mask &= IEEE80211_CCK_RATES_MASK;
3487
3488 /* TODO: Verify that the rate is supported by the current rates
3489 * list. */
3490
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003491 while (i && !(mask & i))
3492 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003493 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003494 case IEEE80211_CCK_RATE_1MB_MASK:
3495 return 1000000;
3496 case IEEE80211_CCK_RATE_2MB_MASK:
3497 return 2000000;
3498 case IEEE80211_CCK_RATE_5MB_MASK:
3499 return 5500000;
3500 case IEEE80211_OFDM_RATE_6MB_MASK:
3501 return 6000000;
3502 case IEEE80211_OFDM_RATE_9MB_MASK:
3503 return 9000000;
3504 case IEEE80211_CCK_RATE_11MB_MASK:
3505 return 11000000;
3506 case IEEE80211_OFDM_RATE_12MB_MASK:
3507 return 12000000;
3508 case IEEE80211_OFDM_RATE_18MB_MASK:
3509 return 18000000;
3510 case IEEE80211_OFDM_RATE_24MB_MASK:
3511 return 24000000;
3512 case IEEE80211_OFDM_RATE_36MB_MASK:
3513 return 36000000;
3514 case IEEE80211_OFDM_RATE_48MB_MASK:
3515 return 48000000;
3516 case IEEE80211_OFDM_RATE_54MB_MASK:
3517 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003518 }
3519
Jeff Garzikbf794512005-07-31 13:07:26 -04003520 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06003521 return 11000000;
3522 else
3523 return 54000000;
3524}
3525
3526static u32 ipw_get_current_rate(struct ipw_priv *priv)
3527{
3528 u32 rate, len = sizeof(rate);
3529 int err;
3530
Jeff Garzikbf794512005-07-31 13:07:26 -04003531 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003532 return 0;
3533
3534 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04003535 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06003536 &len);
3537 if (err) {
3538 IPW_DEBUG_INFO("failed querying ordinals.\n");
3539 return 0;
3540 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003541 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06003542 return ipw_get_max_rate(priv);
3543
3544 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003545 case IPW_TX_RATE_1MB:
3546 return 1000000;
3547 case IPW_TX_RATE_2MB:
3548 return 2000000;
3549 case IPW_TX_RATE_5MB:
3550 return 5500000;
3551 case IPW_TX_RATE_6MB:
3552 return 6000000;
3553 case IPW_TX_RATE_9MB:
3554 return 9000000;
3555 case IPW_TX_RATE_11MB:
3556 return 11000000;
3557 case IPW_TX_RATE_12MB:
3558 return 12000000;
3559 case IPW_TX_RATE_18MB:
3560 return 18000000;
3561 case IPW_TX_RATE_24MB:
3562 return 24000000;
3563 case IPW_TX_RATE_36MB:
3564 return 36000000;
3565 case IPW_TX_RATE_48MB:
3566 return 48000000;
3567 case IPW_TX_RATE_54MB:
3568 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003569 }
3570
3571 return 0;
3572}
3573
James Ketrenosea2b26e2005-08-24 21:25:16 -05003574#define PERFECT_RSSI (-20)
James Ketrenos43f66a62005-03-25 12:31:53 -06003575#define WORST_RSSI (-85)
3576#define IPW_STATS_INTERVAL (2 * HZ)
3577static void ipw_gather_stats(struct ipw_priv *priv)
3578{
3579 u32 rx_err, rx_err_delta, rx_packets_delta;
3580 u32 tx_failures, tx_failures_delta, tx_packets_delta;
3581 u32 missed_beacons_percent, missed_beacons_delta;
3582 u32 quality = 0;
3583 u32 len = sizeof(u32);
3584 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04003585 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003586 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05003587 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06003588
3589 if (!(priv->status & STATUS_ASSOCIATED)) {
3590 priv->quality = 0;
3591 return;
3592 }
3593
3594 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04003595 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06003596 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003597 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06003598 priv->last_missed_beacons = priv->missed_beacons;
3599 if (priv->assoc_request.beacon_interval) {
3600 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003601 (HZ * priv->assoc_request.beacon_interval) /
3602 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06003603 } else {
3604 missed_beacons_percent = 0;
3605 }
3606 average_add(&priv->average_missed_beacons, missed_beacons_percent);
3607
3608 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
3609 rx_err_delta = rx_err - priv->last_rx_err;
3610 priv->last_rx_err = rx_err;
3611
3612 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
3613 tx_failures_delta = tx_failures - priv->last_tx_failures;
3614 priv->last_tx_failures = tx_failures;
3615
3616 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
3617 priv->last_rx_packets = priv->rx_packets;
3618
3619 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
3620 priv->last_tx_packets = priv->tx_packets;
3621
3622 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04003623 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003624 * Missed beacon: 100% = 0, 0% = 70% missed
3625 * Rate: 60% = 1Mbs, 100% = Max
3626 * Rx and Tx errors represent a straight % of total Rx/Tx
3627 * RSSI: 100% = > -50, 0% = < -80
3628 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04003629 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003630 * The lowest computed quality is used.
3631 *
3632 */
3633#define BEACON_THRESHOLD 5
3634 beacon_quality = 100 - missed_beacons_percent;
3635 if (beacon_quality < BEACON_THRESHOLD)
3636 beacon_quality = 0;
3637 else
Jeff Garzikbf794512005-07-31 13:07:26 -04003638 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003639 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04003640 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003641 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04003642
James Ketrenos43f66a62005-03-25 12:31:53 -06003643 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05003644 max_rate = ipw_get_max_rate(priv);
3645 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06003646 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
3647 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04003648
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003649 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04003650 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003651 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06003652 else
3653 rx_quality = 100;
3654 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
3655 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04003656
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003657 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04003658 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003659 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06003660 else
3661 tx_quality = 100;
3662 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
3663 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04003664
James Ketrenos43f66a62005-03-25 12:31:53 -06003665 rssi = average_value(&priv->average_rssi);
3666 if (rssi > PERFECT_RSSI)
3667 signal_quality = 100;
3668 else if (rssi < WORST_RSSI)
3669 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05003670 else /* qual = 100a^2 - 15ab + 62b^2 / a^2 */
3671 signal_quality =
3672 (100 *
3673 (PERFECT_RSSI - WORST_RSSI) *
3674 (PERFECT_RSSI - WORST_RSSI) -
3675 (PERFECT_RSSI - rssi) *
3676 (15 * (PERFECT_RSSI - WORST_RSSI) +
3677 62 * (PERFECT_RSSI - rssi))) /
3678 ((PERFECT_RSSI - WORST_RSSI) * (PERFECT_RSSI - WORST_RSSI));
3679
James Ketrenos43f66a62005-03-25 12:31:53 -06003680 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
3681 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04003682
3683 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06003684 min(rate_quality,
3685 min(tx_quality, min(rx_quality, signal_quality))));
3686 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003687 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
3688 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003689 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003690 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
3691 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003692 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003693 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
3694 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003695 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003696 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
3697 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003698 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003699 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
3700 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06003701
3702 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04003703
3704 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06003705 IPW_STATS_INTERVAL);
3706}
3707
James Ketrenosea2b26e2005-08-24 21:25:16 -05003708static inline void ipw_handle_missed_beacon(struct ipw_priv *priv,
3709 int missed_count)
3710{
3711 priv->notif_missed_beacons = missed_count;
3712
3713 if (missed_count > priv->missed_beacon_threshold &&
3714 priv->status & STATUS_ASSOCIATED) {
3715 /* If associated and we've hit the missed
3716 * beacon threshold, disassociate, turn
3717 * off roaming, and abort any active scans */
3718 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
3719 IPW_DL_STATE,
3720 "Missed beacon: %d - disassociate\n", missed_count);
3721 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05003722 if (priv->status & STATUS_SCANNING) {
3723 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
3724 IPW_DL_STATE,
3725 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05003726 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05003727 }
3728
James Ketrenosea2b26e2005-08-24 21:25:16 -05003729 queue_work(priv->workqueue, &priv->disassociate);
3730 return;
3731 }
3732
3733 if (priv->status & STATUS_ROAMING) {
3734 /* If we are currently roaming, then just
3735 * print a debug statement... */
3736 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3737 "Missed beacon: %d - roam in progress\n",
3738 missed_count);
3739 return;
3740 }
3741
3742 if (missed_count > priv->roaming_threshold) {
3743 /* If we are not already roaming, set the ROAM
3744 * bit in the status and kick off a scan */
3745 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3746 "Missed beacon: %d - initiate "
3747 "roaming\n", missed_count);
3748 if (!(priv->status & STATUS_ROAMING)) {
3749 priv->status |= STATUS_ROAMING;
3750 if (!(priv->status & STATUS_SCANNING))
3751 queue_work(priv->workqueue,
3752 &priv->request_scan);
3753 }
3754 return;
3755 }
3756
3757 if (priv->status & STATUS_SCANNING) {
3758 /* Stop scan to keep fw from getting
3759 * stuck (only if we aren't roaming --
3760 * otherwise we'll never scan more than 2 or 3
3761 * channels..) */
James Ketrenosa613bff2005-08-24 21:43:11 -05003762 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
3763 IPW_DL_STATE, "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05003764 queue_work(priv->workqueue, &priv->abort_scan);
3765 }
3766
3767 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
3768
3769}
3770
James Ketrenos43f66a62005-03-25 12:31:53 -06003771/**
3772 * Handle host notification packet.
3773 * Called from interrupt routine
3774 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003775static inline void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003776 struct ipw_rx_notification *notif)
3777{
James Ketrenosa613bff2005-08-24 21:43:11 -05003778 notif->size = le16_to_cpu(notif->size);
3779
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003780 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04003781
James Ketrenos43f66a62005-03-25 12:31:53 -06003782 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003783 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
3784 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003785
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003786 switch (assoc->state) {
3787 case CMAS_ASSOCIATED:{
3788 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3789 IPW_DL_ASSOC,
3790 "associated: '%s' " MAC_FMT
3791 " \n",
3792 escape_essid(priv->essid,
3793 priv->essid_len),
3794 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04003795
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003796 switch (priv->ieee->iw_mode) {
3797 case IW_MODE_INFRA:
3798 memcpy(priv->ieee->bssid,
3799 priv->bssid, ETH_ALEN);
3800 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003801
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003802 case IW_MODE_ADHOC:
3803 memcpy(priv->ieee->bssid,
3804 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04003805
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003806 /* clear out the station table */
3807 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003808
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003809 IPW_DEBUG_ASSOC
3810 ("queueing adhoc check\n");
3811 queue_delayed_work(priv->
3812 workqueue,
3813 &priv->
3814 adhoc_check,
3815 priv->
3816 assoc_request.
3817 beacon_interval);
3818 break;
3819 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003820
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003821 priv->status &= ~STATUS_ASSOCIATING;
3822 priv->status |= STATUS_ASSOCIATED;
James Ketrenos43f66a62005-03-25 12:31:53 -06003823
James Ketrenosa613bff2005-08-24 21:43:11 -05003824 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06003825
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003826 break;
3827 }
3828
3829 case CMAS_AUTHENTICATED:{
3830 if (priv->
3831 status & (STATUS_ASSOCIATED |
3832 STATUS_AUTH)) {
3833#ifdef CONFIG_IPW_DEBUG
3834 struct notif_authenticate *auth
3835 = &notif->u.auth;
3836 IPW_DEBUG(IPW_DL_NOTIF |
3837 IPW_DL_STATE |
3838 IPW_DL_ASSOC,
3839 "deauthenticated: '%s' "
3840 MAC_FMT
3841 ": (0x%04X) - %s \n",
3842 escape_essid(priv->
3843 essid,
3844 priv->
3845 essid_len),
3846 MAC_ARG(priv->bssid),
3847 ntohs(auth->status),
3848 ipw_get_status_code
3849 (ntohs
3850 (auth->status)));
3851#endif
3852
3853 priv->status &=
3854 ~(STATUS_ASSOCIATING |
3855 STATUS_AUTH |
3856 STATUS_ASSOCIATED);
3857
James Ketrenosa613bff2005-08-24 21:43:11 -05003858 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003859 break;
3860 }
3861
3862 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3863 IPW_DL_ASSOC,
3864 "authenticated: '%s' " MAC_FMT
3865 "\n",
3866 escape_essid(priv->essid,
3867 priv->essid_len),
3868 MAC_ARG(priv->bssid));
3869 break;
3870 }
3871
3872 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05003873 if (priv->status & STATUS_AUTH) {
3874 struct
3875 ieee80211_assoc_response
3876 *resp;
3877 resp =
3878 (struct
3879 ieee80211_assoc_response
3880 *)&notif->u.raw;
3881 IPW_DEBUG(IPW_DL_NOTIF |
3882 IPW_DL_STATE |
3883 IPW_DL_ASSOC,
3884 "association failed (0x%04X): %s\n",
3885 ntohs(resp->status),
3886 ipw_get_status_code
3887 (ntohs
3888 (resp->status)));
3889 }
3890
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003891 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3892 IPW_DL_ASSOC,
3893 "disassociated: '%s' " MAC_FMT
3894 " \n",
3895 escape_essid(priv->essid,
3896 priv->essid_len),
3897 MAC_ARG(priv->bssid));
3898
3899 priv->status &=
3900 ~(STATUS_DISASSOCIATING |
3901 STATUS_ASSOCIATING |
3902 STATUS_ASSOCIATED | STATUS_AUTH);
3903
James Ketrenosa613bff2005-08-24 21:43:11 -05003904 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003905
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003906 break;
3907 }
3908
3909 default:
3910 IPW_ERROR("assoc: unknown (%d)\n",
3911 assoc->state);
3912 break;
3913 }
3914
James Ketrenos43f66a62005-03-25 12:31:53 -06003915 break;
3916 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003917
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003918 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
3919 struct notif_authenticate *auth = &notif->u.auth;
3920 switch (auth->state) {
3921 case CMAS_AUTHENTICATED:
3922 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
3923 "authenticated: '%s' " MAC_FMT " \n",
3924 escape_essid(priv->essid,
3925 priv->essid_len),
3926 MAC_ARG(priv->bssid));
3927 priv->status |= STATUS_AUTH;
3928 break;
3929
3930 case CMAS_INIT:
3931 if (priv->status & STATUS_AUTH) {
3932 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3933 IPW_DL_ASSOC,
3934 "authentication failed (0x%04X): %s\n",
3935 ntohs(auth->status),
3936 ipw_get_status_code(ntohs
3937 (auth->
3938 status)));
3939 }
3940 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3941 IPW_DL_ASSOC,
3942 "deauthenticated: '%s' " MAC_FMT "\n",
3943 escape_essid(priv->essid,
3944 priv->essid_len),
3945 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06003946
3947 priv->status &= ~(STATUS_ASSOCIATING |
3948 STATUS_AUTH |
3949 STATUS_ASSOCIATED);
3950
James Ketrenosa613bff2005-08-24 21:43:11 -05003951 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06003952 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003953
3954 case CMAS_TX_AUTH_SEQ_1:
3955 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3956 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
3957 break;
3958 case CMAS_RX_AUTH_SEQ_2:
3959 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3960 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
3961 break;
3962 case CMAS_AUTH_SEQ_1_PASS:
3963 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3964 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
3965 break;
3966 case CMAS_AUTH_SEQ_1_FAIL:
3967 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3968 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
3969 break;
3970 case CMAS_TX_AUTH_SEQ_3:
3971 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3972 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
3973 break;
3974 case CMAS_RX_AUTH_SEQ_4:
3975 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3976 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
3977 break;
3978 case CMAS_AUTH_SEQ_2_PASS:
3979 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3980 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
3981 break;
3982 case CMAS_AUTH_SEQ_2_FAIL:
3983 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3984 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
3985 break;
3986 case CMAS_TX_ASSOC:
3987 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3988 IPW_DL_ASSOC, "TX_ASSOC\n");
3989 break;
3990 case CMAS_RX_ASSOC_RESP:
3991 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3992 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
3993 break;
3994 case CMAS_ASSOCIATED:
3995 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
3996 IPW_DL_ASSOC, "ASSOCIATED\n");
3997 break;
3998 default:
3999 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4000 auth->state);
4001 break;
4002 }
4003 break;
4004 }
4005
4006 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4007 struct notif_channel_result *x =
4008 &notif->u.channel_result;
4009
4010 if (notif->size == sizeof(*x)) {
4011 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4012 x->channel_num);
4013 } else {
4014 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4015 "(should be %zd)\n",
4016 notif->size, sizeof(*x));
4017 }
4018 break;
4019 }
4020
4021 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4022 struct notif_scan_complete *x = &notif->u.scan_complete;
4023 if (notif->size == sizeof(*x)) {
4024 IPW_DEBUG_SCAN
4025 ("Scan completed: type %d, %d channels, "
4026 "%d status\n", x->scan_type,
4027 x->num_channels, x->status);
4028 } else {
4029 IPW_ERROR("Scan completed of wrong size %d "
4030 "(should be %zd)\n",
4031 notif->size, sizeof(*x));
4032 }
4033
4034 priv->status &=
4035 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4036
4037 cancel_delayed_work(&priv->scan_check);
4038
4039 if (!(priv->status & (STATUS_ASSOCIATED |
4040 STATUS_ASSOCIATING |
4041 STATUS_ROAMING |
4042 STATUS_DISASSOCIATING)))
4043 queue_work(priv->workqueue, &priv->associate);
4044 else if (priv->status & STATUS_ROAMING) {
4045 /* If a scan completed and we are in roam mode, then
4046 * the scan that completed was the one requested as a
4047 * result of entering roam... so, schedule the
4048 * roam work */
4049 queue_work(priv->workqueue, &priv->roam);
4050 } else if (priv->status & STATUS_SCAN_PENDING)
4051 queue_work(priv->workqueue,
4052 &priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004053 else if (priv->config & CFG_BACKGROUND_SCAN
4054 && priv->status & STATUS_ASSOCIATED)
4055 queue_delayed_work(priv->workqueue,
4056 &priv->request_scan, HZ);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004057
4058 priv->ieee->scans++;
4059 break;
4060 }
4061
4062 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4063 struct notif_frag_length *x = &notif->u.frag_len;
4064
James Ketrenosa613bff2005-08-24 21:43:11 -05004065 if (notif->size == sizeof(*x))
4066 IPW_ERROR("Frag length: %d\n",
4067 le16_to_cpu(x->frag_length));
4068 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004069 IPW_ERROR("Frag length of wrong size %d "
4070 "(should be %zd)\n",
4071 notif->size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004072 break;
4073 }
4074
4075 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4076 struct notif_link_deterioration *x =
4077 &notif->u.link_deterioration;
4078 if (notif->size == sizeof(*x)) {
4079 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4080 "link deterioration: '%s' " MAC_FMT
4081 " \n", escape_essid(priv->essid,
4082 priv->essid_len),
4083 MAC_ARG(priv->bssid));
4084 memcpy(&priv->last_link_deterioration, x,
4085 sizeof(*x));
4086 } else {
4087 IPW_ERROR("Link Deterioration of wrong size %d "
4088 "(should be %zd)\n",
4089 notif->size, sizeof(*x));
4090 }
4091 break;
4092 }
4093
4094 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4095 IPW_ERROR("Dino config\n");
4096 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004097 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004098 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004099
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004100 break;
4101 }
4102
4103 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4104 struct notif_beacon_state *x = &notif->u.beacon_state;
4105 if (notif->size != sizeof(*x)) {
4106 IPW_ERROR
4107 ("Beacon state of wrong size %d (should "
4108 "be %zd)\n", notif->size, sizeof(*x));
4109 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004110 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004111
James Ketrenosa613bff2005-08-24 21:43:11 -05004112 if (le32_to_cpu(x->state) ==
4113 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4114 ipw_handle_missed_beacon(priv,
4115 le32_to_cpu(x->
4116 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004117
James Ketrenos43f66a62005-03-25 12:31:53 -06004118 break;
4119 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004120
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004121 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4122 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
4123 if (notif->size == sizeof(*x)) {
4124 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4125 "0x%02x station %d\n",
4126 x->key_state, x->security_type,
4127 x->station_index);
4128 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004129 }
4130
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004131 IPW_ERROR
4132 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4133 notif->size, sizeof(*x));
4134 break;
4135 }
4136
4137 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4138 struct notif_calibration *x = &notif->u.calibration;
4139
4140 if (notif->size == sizeof(*x)) {
4141 memcpy(&priv->calib, x, sizeof(*x));
4142 IPW_DEBUG_INFO("TODO: Calibration\n");
4143 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004144 }
4145
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004146 IPW_ERROR
4147 ("Calibration of wrong size %d (should be %zd)\n",
4148 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004149 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004150 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004151
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004152 case HOST_NOTIFICATION_NOISE_STATS:{
4153 if (notif->size == sizeof(u32)) {
4154 priv->last_noise =
James Ketrenosa613bff2005-08-24 21:43:11 -05004155 (u8) (le32_to_cpu(notif->u.noise.value) &
4156 0xff);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004157 average_add(&priv->average_noise,
4158 priv->last_noise);
4159 break;
4160 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004161
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004162 IPW_ERROR
4163 ("Noise stat is wrong size %d (should be %zd)\n",
4164 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004165 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004166 }
4167
James Ketrenos43f66a62005-03-25 12:31:53 -06004168 default:
4169 IPW_ERROR("Unknown notification: "
4170 "subtype=%d,flags=0x%2x,size=%d\n",
4171 notif->subtype, notif->flags, notif->size);
4172 }
4173}
4174
4175/**
4176 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004177 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004178 * @param priv
4179 * @return error code
4180 */
4181static int ipw_queue_reset(struct ipw_priv *priv)
4182{
4183 int rc = 0;
4184 /** @todo customize queue sizes */
4185 int nTx = 64, nTxCmd = 8;
4186 ipw_tx_queue_free(priv);
4187 /* Tx CMD queue */
4188 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
4189 CX2_TX_CMD_QUEUE_READ_INDEX,
4190 CX2_TX_CMD_QUEUE_WRITE_INDEX,
4191 CX2_TX_CMD_QUEUE_BD_BASE,
4192 CX2_TX_CMD_QUEUE_BD_SIZE);
4193 if (rc) {
4194 IPW_ERROR("Tx Cmd queue init failed\n");
4195 goto error;
4196 }
4197 /* Tx queue(s) */
4198 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
4199 CX2_TX_QUEUE_0_READ_INDEX,
4200 CX2_TX_QUEUE_0_WRITE_INDEX,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004201 CX2_TX_QUEUE_0_BD_BASE, CX2_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004202 if (rc) {
4203 IPW_ERROR("Tx 0 queue init failed\n");
4204 goto error;
4205 }
4206 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
4207 CX2_TX_QUEUE_1_READ_INDEX,
4208 CX2_TX_QUEUE_1_WRITE_INDEX,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004209 CX2_TX_QUEUE_1_BD_BASE, CX2_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004210 if (rc) {
4211 IPW_ERROR("Tx 1 queue init failed\n");
4212 goto error;
4213 }
4214 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
4215 CX2_TX_QUEUE_2_READ_INDEX,
4216 CX2_TX_QUEUE_2_WRITE_INDEX,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004217 CX2_TX_QUEUE_2_BD_BASE, CX2_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004218 if (rc) {
4219 IPW_ERROR("Tx 2 queue init failed\n");
4220 goto error;
4221 }
4222 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
4223 CX2_TX_QUEUE_3_READ_INDEX,
4224 CX2_TX_QUEUE_3_WRITE_INDEX,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004225 CX2_TX_QUEUE_3_BD_BASE, CX2_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004226 if (rc) {
4227 IPW_ERROR("Tx 3 queue init failed\n");
4228 goto error;
4229 }
4230 /* statistics */
4231 priv->rx_bufs_min = 0;
4232 priv->rx_pend_max = 0;
4233 return rc;
4234
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004235 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004236 ipw_tx_queue_free(priv);
4237 return rc;
4238}
4239
4240/**
4241 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004242 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004243 * When FW adwances 'R' index, all entries between old and
4244 * new 'R' index need to be reclaimed. As result, some free space
4245 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004246 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004247 * @note Need to protect against garbage in 'R' index
4248 * @param priv
4249 * @param txq
4250 * @param qindex
4251 * @return Number of used entries remains in the queue
4252 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004253static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004254 struct clx2_tx_queue *txq, int qindex)
4255{
4256 u32 hw_tail;
4257 int used;
4258 struct clx2_queue *q = &txq->q;
4259
4260 hw_tail = ipw_read32(priv, q->reg_r);
4261 if (hw_tail >= q->n_bd) {
4262 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004263 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4264 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004265 goto done;
4266 }
4267 for (; q->last_used != hw_tail;
4268 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4269 ipw_queue_tx_free_tfd(priv, txq);
4270 priv->tx_packets++;
4271 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004272 done:
James Ketrenosa613bff2005-08-24 21:43:11 -05004273 if (ipw_queue_space(q) > q->low_mark && qindex >= 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06004274 __maybe_wake_tx(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06004275 used = q->first_empty - q->last_used;
4276 if (used < 0)
4277 used += q->n_bd;
4278
4279 return used;
4280}
4281
4282static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4283 int len, int sync)
4284{
4285 struct clx2_tx_queue *txq = &priv->txq_cmd;
4286 struct clx2_queue *q = &txq->q;
4287 struct tfd_frame *tfd;
4288
4289 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4290 IPW_ERROR("No space for Tx\n");
4291 return -EBUSY;
4292 }
4293
4294 tfd = &txq->bd[q->first_empty];
4295 txq->txb[q->first_empty] = NULL;
4296
4297 memset(tfd, 0, sizeof(*tfd));
4298 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4299 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4300 priv->hcmd_seq++;
4301 tfd->u.cmd.index = hcmd;
4302 tfd->u.cmd.length = len;
4303 memcpy(tfd->u.cmd.payload, buf, len);
4304 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4305 ipw_write32(priv, q->reg_w, q->first_empty);
4306 _ipw_read32(priv, 0x90);
4307
4308 return 0;
4309}
4310
Jeff Garzikbf794512005-07-31 13:07:26 -04004311/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004312 * Rx theory of operation
4313 *
4314 * The host allocates 32 DMA target addresses and passes the host address
4315 * to the firmware at register CX2_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
4316 * 0 to 31
4317 *
4318 * Rx Queue Indexes
4319 * The host/firmware share two index registers for managing the Rx buffers.
4320 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004321 * The READ index maps to the first position that the firmware may be writing
4322 * to -- the driver can read up to (but not including) this position and get
4323 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06004324 * The READ index is managed by the firmware once the card is enabled.
4325 *
4326 * The WRITE index maps to the last position the driver has read from -- the
4327 * position preceding WRITE is the last slot the firmware can place a packet.
4328 *
4329 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04004330 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06004331 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004332 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06004333 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4334 *
4335 * When the firmware places a packet in a buffer it will advance the READ index
4336 * and fire the RX interrupt. The driver can then query the READ index and
4337 * process as many packets as possible, moving the WRITE index forward as it
4338 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04004339 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004340 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004341 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06004342 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04004343 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06004344 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4345 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4346 * 'processed' and 'read' driver indexes as well)
4347 * + A received packet is processed and handed to the kernel network stack,
4348 * detached from the ipw->rxq. The driver 'processed' index is updated.
4349 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04004350 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4351 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06004352 * were enough free buffers and RX_STALLED is set it is cleared.
4353 *
4354 *
4355 * Driver sequence:
4356 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004357 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06004358 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4359 * ipw_rx_queue_restock
4360 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4361 * queue, updates firmware pointers, and updates
4362 * the WRITE index. If insufficient rx_free buffers
4363 * are available, schedules ipw_rx_queue_replenish
4364 *
4365 * -- enable interrupts --
4366 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04004367 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06004368 * Moves the packet buffer from queue to rx_used.
4369 * Calls ipw_rx_queue_restock to refill any empty
4370 * slots.
4371 * ...
4372 *
4373 */
4374
Jeff Garzikbf794512005-07-31 13:07:26 -04004375/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004376 * If there are slots in the RX queue that need to be restocked,
4377 * and we have free pre-allocated buffers, fill the ranks as much
4378 * as we can pulling from rx_free.
4379 *
4380 * This moves the 'write' index forward to catch up with 'processed', and
4381 * also updates the memory address in the firmware to reference the new
4382 * target buffer.
4383 */
4384static void ipw_rx_queue_restock(struct ipw_priv *priv)
4385{
4386 struct ipw_rx_queue *rxq = priv->rxq;
4387 struct list_head *element;
4388 struct ipw_rx_mem_buffer *rxb;
4389 unsigned long flags;
4390 int write;
4391
4392 spin_lock_irqsave(&rxq->lock, flags);
4393 write = rxq->write;
4394 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4395 element = rxq->rx_free.next;
4396 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4397 list_del(element);
4398
4399 ipw_write32(priv, CX2_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
4400 rxb->dma_addr);
4401 rxq->queue[rxq->write] = rxb;
4402 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4403 rxq->free_count--;
4404 }
4405 spin_unlock_irqrestore(&rxq->lock, flags);
4406
Jeff Garzikbf794512005-07-31 13:07:26 -04004407 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06004408 * refill it */
4409 if (rxq->free_count <= RX_LOW_WATERMARK)
4410 queue_work(priv->workqueue, &priv->rx_replenish);
4411
4412 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04004413 if (write != rxq->write)
James Ketrenos43f66a62005-03-25 12:31:53 -06004414 ipw_write32(priv, CX2_RX_WRITE_INDEX, rxq->write);
4415}
4416
4417/*
4418 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04004419 * Also restock the Rx queue via ipw_rx_queue_restock.
4420 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004421 * This is called as a scheduled work item (except for during intialization)
4422 */
4423static void ipw_rx_queue_replenish(void *data)
4424{
4425 struct ipw_priv *priv = data;
4426 struct ipw_rx_queue *rxq = priv->rxq;
4427 struct list_head *element;
4428 struct ipw_rx_mem_buffer *rxb;
4429 unsigned long flags;
4430
4431 spin_lock_irqsave(&rxq->lock, flags);
4432 while (!list_empty(&rxq->rx_used)) {
4433 element = rxq->rx_used.next;
4434 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4435 rxb->skb = alloc_skb(CX2_RX_BUF_SIZE, GFP_ATOMIC);
4436 if (!rxb->skb) {
4437 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
4438 priv->net_dev->name);
4439 /* We don't reschedule replenish work here -- we will
4440 * call the restock method and if it still needs
4441 * more buffers it will schedule replenish */
4442 break;
4443 }
4444 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04004445
James Ketrenos43f66a62005-03-25 12:31:53 -06004446 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004447 rxb->dma_addr =
4448 pci_map_single(priv->pci_dev, rxb->skb->data,
4449 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04004450
James Ketrenos43f66a62005-03-25 12:31:53 -06004451 list_add_tail(&rxb->list, &rxq->rx_free);
4452 rxq->free_count++;
4453 }
4454 spin_unlock_irqrestore(&rxq->lock, flags);
4455
4456 ipw_rx_queue_restock(priv);
4457}
4458
4459/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4460 * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04004461 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06004462 * non NULL it is unmapped and freed
4463 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004464static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06004465{
4466 int i;
4467
4468 if (!rxq)
4469 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04004470
James Ketrenos43f66a62005-03-25 12:31:53 -06004471 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4472 if (rxq->pool[i].skb != NULL) {
4473 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004474 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004475 dev_kfree_skb(rxq->pool[i].skb);
4476 }
4477 }
4478
4479 kfree(rxq);
4480}
4481
4482static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4483{
4484 struct ipw_rx_queue *rxq;
4485 int i;
4486
4487 rxq = (struct ipw_rx_queue *)kmalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02004488 if (unlikely(!rxq)) {
4489 IPW_ERROR("memory allocation failed\n");
4490 return NULL;
4491 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004492 memset(rxq, 0, sizeof(*rxq));
4493 spin_lock_init(&rxq->lock);
4494 INIT_LIST_HEAD(&rxq->rx_free);
4495 INIT_LIST_HEAD(&rxq->rx_used);
4496
4497 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04004498 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06004499 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4500
4501 /* Set us so that we have processed and used all buffers, but have
4502 * not restocked the Rx queue with fresh buffers */
4503 rxq->read = rxq->write = 0;
4504 rxq->processed = RX_QUEUE_SIZE - 1;
4505 rxq->free_count = 0;
4506
4507 return rxq;
4508}
4509
4510static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
4511{
4512 rate &= ~IEEE80211_BASIC_RATE_MASK;
4513 if (ieee_mode == IEEE_A) {
4514 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004515 case IEEE80211_OFDM_RATE_6MB:
4516 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004517 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004518 case IEEE80211_OFDM_RATE_9MB:
4519 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004520 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004521 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004522 return priv->
4523 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004524 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004525 return priv->
4526 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004527 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004528 return priv->
4529 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004530 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004531 return priv->
4532 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004533 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004534 return priv->
4535 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004536 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004537 return priv->
4538 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004539 default:
4540 return 0;
4541 }
4542 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004543
James Ketrenos43f66a62005-03-25 12:31:53 -06004544 /* B and G mixed */
4545 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004546 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004547 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004548 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004549 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004550 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004551 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004552 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004553 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
4554 }
4555
4556 /* If we are limited to B modulations, bail at this point */
4557 if (ieee_mode == IEEE_B)
4558 return 0;
4559
4560 /* G */
4561 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004562 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004563 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004564 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004565 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004566 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004567 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004568 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004569 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004570 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004571 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004572 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004573 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004574 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004575 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004576 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06004577 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
4578 }
4579
4580 return 0;
4581}
4582
Jeff Garzikbf794512005-07-31 13:07:26 -04004583static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004584 const struct ieee80211_network *network,
4585 struct ipw_supported_rates *rates)
4586{
4587 int num_rates, i;
4588
4589 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004590 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06004591 rates->num_rates = 0;
4592 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05004593 if (!ipw_is_rate_in_mask(priv, network->mode,
4594 network->rates[i])) {
4595
James Ketrenosea2b26e2005-08-24 21:25:16 -05004596 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05004597 IPW_DEBUG_SCAN("Adding masked mandatory "
4598 "rate %02X\n",
4599 network->rates[i]);
4600 rates->supported_rates[rates->num_rates++] =
4601 network->rates[i];
4602 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004603 }
4604
James Ketrenos43f66a62005-03-25 12:31:53 -06004605 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4606 network->rates[i], priv->rates_mask);
4607 continue;
4608 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004609
James Ketrenos43f66a62005-03-25 12:31:53 -06004610 rates->supported_rates[rates->num_rates++] = network->rates[i];
4611 }
4612
James Ketrenosa613bff2005-08-24 21:43:11 -05004613 num_rates = min(network->rates_ex_len,
4614 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06004615 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05004616 if (!ipw_is_rate_in_mask(priv, network->mode,
4617 network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004618 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05004619 IPW_DEBUG_SCAN("Adding masked mandatory "
4620 "rate %02X\n",
4621 network->rates_ex[i]);
4622 rates->supported_rates[rates->num_rates++] =
4623 network->rates[i];
4624 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004625 }
4626
James Ketrenos43f66a62005-03-25 12:31:53 -06004627 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
4628 network->rates_ex[i], priv->rates_mask);
4629 continue;
4630 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004631
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004632 rates->supported_rates[rates->num_rates++] =
4633 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06004634 }
4635
James Ketrenosea2b26e2005-08-24 21:25:16 -05004636 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004637}
4638
4639static inline void ipw_copy_rates(struct ipw_supported_rates *dest,
4640 const struct ipw_supported_rates *src)
4641{
4642 u8 i;
4643 for (i = 0; i < src->num_rates; i++)
4644 dest->supported_rates[i] = src->supported_rates[i];
4645 dest->num_rates = src->num_rates;
4646}
4647
4648/* TODO: Look at sniffed packets in the air to determine if the basic rate
4649 * mask should ever be used -- right now all callers to add the scan rates are
4650 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
4651static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004652 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06004653{
Jeff Garzikbf794512005-07-31 13:07:26 -04004654 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004655 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004656
James Ketrenos43f66a62005-03-25 12:31:53 -06004657 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004658 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004659 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004660
4661 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004662 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004663 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004664
4665 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004666 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004667 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004668
4669 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004670 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004671 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004672}
4673
4674static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004675 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06004676{
Jeff Garzikbf794512005-07-31 13:07:26 -04004677 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004678 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004679
4680 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004681 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004682 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004683
4684 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004685 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004686 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004687
4688 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004689 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004690 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004691
4692 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004693 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004694 IEEE80211_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004695
4696 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004697 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004698 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004699
4700 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004701 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004702 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004703
4704 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004705 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004706 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004707
4708 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04004709 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004710 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06004711}
4712
4713struct ipw_network_match {
4714 struct ieee80211_network *network;
4715 struct ipw_supported_rates rates;
4716};
4717
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004718static int ipw_best_network(struct ipw_priv *priv,
4719 struct ipw_network_match *match,
4720 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06004721{
4722 struct ipw_supported_rates rates;
4723
4724 /* Verify that this network's capability is compatible with the
4725 * current mode (AdHoc or Infrastructure) */
4726 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07004727 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06004728 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
4729 !(network->capability & WLAN_CAPABILITY_IBSS))) {
4730 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04004731 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004732 escape_essid(network->ssid, network->ssid_len),
4733 MAC_ARG(network->bssid));
4734 return 0;
4735 }
4736
4737 /* If we do not have an ESSID for this AP, we can not associate with
4738 * it */
4739 if (network->flags & NETWORK_EMPTY_ESSID) {
4740 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4741 "because of hidden ESSID.\n",
4742 escape_essid(network->ssid, network->ssid_len),
4743 MAC_ARG(network->bssid));
4744 return 0;
4745 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004746
James Ketrenos43f66a62005-03-25 12:31:53 -06004747 if (unlikely(roaming)) {
4748 /* If we are roaming, then ensure check if this is a valid
4749 * network to try and roam to */
4750 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04004751 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06004752 network->ssid_len)) {
4753 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
4754 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04004755 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06004756 network->ssid_len),
4757 MAC_ARG(network->bssid));
4758 return 0;
4759 }
4760 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04004761 /* If an ESSID has been configured then compare the broadcast
4762 * ESSID to ours */
4763 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06004764 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04004765 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06004766 min(network->ssid_len, priv->essid_len)))) {
4767 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004768 strncpy(escaped,
4769 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06004770 sizeof(escaped));
4771 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04004772 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004773 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004774 escape_essid(priv->essid,
4775 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06004776 return 0;
4777 }
4778 }
4779
4780 /* If the old network rate is better than this one, don't bother
4781 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004782 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06004783 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04004784 strncpy(escaped,
4785 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06004786 sizeof(escaped));
4787 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
4788 "'%s (" MAC_FMT ")' has a stronger signal.\n",
4789 escaped, MAC_ARG(network->bssid),
4790 escape_essid(match->network->ssid,
4791 match->network->ssid_len),
4792 MAC_ARG(match->network->bssid));
4793 return 0;
4794 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004795
James Ketrenos43f66a62005-03-25 12:31:53 -06004796 /* If this network has already had an association attempt within the
4797 * last 3 seconds, do not try and associate again... */
4798 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004799 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06004800 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4801 "because of storming (%lu since last "
4802 "assoc attempt).\n",
4803 escape_essid(network->ssid, network->ssid_len),
4804 MAC_ARG(network->bssid),
4805 (jiffies - network->last_associate) / HZ);
4806 return 0;
4807 }
4808
4809 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04004810 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004811 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06004812 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4813 "because of age: %lums.\n",
4814 escape_essid(network->ssid, network->ssid_len),
4815 MAC_ARG(network->bssid),
4816 (jiffies - network->last_scanned) / (HZ / 100));
4817 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004818 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004819
Jeff Garzikbf794512005-07-31 13:07:26 -04004820 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06004821 (network->channel != priv->channel)) {
4822 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4823 "because of channel mismatch: %d != %d.\n",
4824 escape_essid(network->ssid, network->ssid_len),
4825 MAC_ARG(network->bssid),
4826 network->channel, priv->channel);
4827 return 0;
4828 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004829
James Ketrenos43f66a62005-03-25 12:31:53 -06004830 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04004831 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06004832 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
4833 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4834 "because of privacy mismatch: %s != %s.\n",
4835 escape_essid(network->ssid, network->ssid_len),
4836 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04004837 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06004838 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04004839 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004840 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06004841 return 0;
4842 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004843
4844 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06004845 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
4846 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4847 "because of BSSID mismatch: " MAC_FMT ".\n",
4848 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004849 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004850 return 0;
4851 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004852
James Ketrenos43f66a62005-03-25 12:31:53 -06004853 /* Filter out any incompatible freq / mode combinations */
4854 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
4855 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4856 "because of invalid frequency/mode "
4857 "combination.\n",
4858 escape_essid(network->ssid, network->ssid_len),
4859 MAC_ARG(network->bssid));
4860 return 0;
4861 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004862
James Ketrenosea2b26e2005-08-24 21:25:16 -05004863 /* Ensure that the rates supported by the driver are compatible with
4864 * this AP, including verification of basic rates (mandatory) */
4865 if (!ipw_compatible_rates(priv, network, &rates)) {
4866 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4867 "because configured rate mask excludes "
4868 "AP mandatory rate.\n",
4869 escape_essid(network->ssid, network->ssid_len),
4870 MAC_ARG(network->bssid));
4871 return 0;
4872 }
4873
James Ketrenos43f66a62005-03-25 12:31:53 -06004874 if (rates.num_rates == 0) {
4875 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
4876 "because of no compatible rates.\n",
4877 escape_essid(network->ssid, network->ssid_len),
4878 MAC_ARG(network->bssid));
4879 return 0;
4880 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004881
James Ketrenos43f66a62005-03-25 12:31:53 -06004882 /* TODO: Perform any further minimal comparititive tests. We do not
4883 * want to put too much policy logic here; intelligent scan selection
4884 * should occur within a generic IEEE 802.11 user space tool. */
4885
4886 /* Set up 'new' AP to this network */
4887 ipw_copy_rates(&match->rates, &rates);
4888 match->network = network;
4889
4890 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
4891 escape_essid(network->ssid, network->ssid_len),
4892 MAC_ARG(network->bssid));
4893
4894 return 1;
4895}
4896
Jeff Garzikbf794512005-07-31 13:07:26 -04004897static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004898 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06004899{
4900 /*
4901 * For the purposes of scanning, we can set our wireless mode
4902 * to trigger scans across combinations of bands, but when it
4903 * comes to creating a new ad-hoc network, we have tell the FW
4904 * exactly which band to use.
4905 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004906 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06004907 * chossen band. Attempting to create a new ad-hoc network
4908 * with an invalid channel for wireless mode will trigger a
4909 * FW fatal error.
4910 */
4911 network->mode = is_valid_channel(priv->ieee->mode, priv->channel);
James Ketrenosa613bff2005-08-24 21:43:11 -05004912 if (!network->mode) {
James Ketrenos43f66a62005-03-25 12:31:53 -06004913 IPW_WARNING("Overriding invalid channel\n");
4914 if (priv->ieee->mode & IEEE_A) {
4915 network->mode = IEEE_A;
4916 priv->channel = band_a_active_channel[0];
4917 } else if (priv->ieee->mode & IEEE_G) {
4918 network->mode = IEEE_G;
4919 priv->channel = band_b_active_channel[0];
4920 } else {
4921 network->mode = IEEE_B;
4922 priv->channel = band_b_active_channel[0];
4923 }
4924 }
4925
4926 network->channel = priv->channel;
4927 priv->config |= CFG_ADHOC_PERSIST;
4928 ipw_create_bssid(priv, network->bssid);
4929 network->ssid_len = priv->essid_len;
4930 memcpy(network->ssid, priv->essid, priv->essid_len);
4931 memset(&network->stats, 0, sizeof(network->stats));
4932 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004933 if (!(priv->config & CFG_PREAMBLE_LONG))
4934 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06004935 if (priv->capability & CAP_PRIVACY_ON)
4936 network->capability |= WLAN_CAPABILITY_PRIVACY;
4937 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004938 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06004939 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04004940 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06004941 &priv->rates.supported_rates[network->rates_len],
4942 network->rates_ex_len);
4943 network->last_scanned = 0;
4944 network->flags = 0;
4945 network->last_associate = 0;
4946 network->time_stamp[0] = 0;
4947 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004948 network->beacon_interval = 100; /* Default */
4949 network->listen_interval = 10; /* Default */
4950 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06004951 network->wpa_ie_len = 0;
4952 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004953}
4954
4955static void ipw_send_wep_keys(struct ipw_priv *priv)
4956{
4957 struct ipw_wep_key *key;
4958 int i;
4959 struct host_cmd cmd = {
4960 .cmd = IPW_CMD_WEP_KEY,
4961 .len = sizeof(*key)
4962 };
4963
4964 key = (struct ipw_wep_key *)&cmd.param;
4965 key->cmd_id = DINO_CMD_WEP_KEY;
4966 key->seq_num = 0;
4967
Jeff Garzikbf794512005-07-31 13:07:26 -04004968 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06004969 key->key_index = i;
James Ketrenosa613bff2005-08-24 21:43:11 -05004970 if (!(priv->sec.flags & (1 << i)))
James Ketrenos43f66a62005-03-25 12:31:53 -06004971 key->key_size = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05004972 else {
James Ketrenos43f66a62005-03-25 12:31:53 -06004973 key->key_size = priv->sec.key_sizes[i];
4974 memcpy(key->key, priv->sec.keys[i], key->key_size);
4975 }
4976
4977 if (ipw_send_cmd(priv, &cmd)) {
4978 IPW_ERROR("failed to send WEP_KEY command\n");
4979 return;
4980 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004981 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004982}
4983
4984static void ipw_adhoc_check(void *data)
4985{
4986 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04004987
James Ketrenos43f66a62005-03-25 12:31:53 -06004988 if (priv->missed_adhoc_beacons++ > priv->missed_beacon_threshold &&
4989 !(priv->config & CFG_ADHOC_PERSIST)) {
4990 IPW_DEBUG_SCAN("Disassociating due to missed beacons\n");
4991 ipw_remove_current_network(priv);
4992 ipw_disassociate(priv);
4993 return;
4994 }
4995
Jeff Garzikbf794512005-07-31 13:07:26 -04004996 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06004997 priv->assoc_request.beacon_interval);
4998}
4999
5000#ifdef CONFIG_IPW_DEBUG
5001static void ipw_debug_config(struct ipw_priv *priv)
5002{
5003 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5004 "[CFG 0x%08X]\n", priv->config);
5005 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005006 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005007 else
5008 IPW_DEBUG_INFO("Channel unlocked.\n");
5009 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04005010 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005011 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005012 else
5013 IPW_DEBUG_INFO("ESSID unlocked.\n");
5014 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05005015 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5016 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005017 else
5018 IPW_DEBUG_INFO("BSSID unlocked.\n");
5019 if (priv->capability & CAP_PRIVACY_ON)
5020 IPW_DEBUG_INFO("PRIVACY on\n");
5021 else
5022 IPW_DEBUG_INFO("PRIVACY off\n");
5023 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5024}
5025#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04005026#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06005027#endif
5028
5029static inline void ipw_set_fixed_rate(struct ipw_priv *priv,
5030 struct ieee80211_network *network)
5031{
5032 /* TODO: Verify that this works... */
5033 struct ipw_fixed_rate fr = {
5034 .tx_rates = priv->rates_mask
5035 };
5036 u32 reg;
5037 u16 mask = 0;
5038
Jeff Garzikbf794512005-07-31 13:07:26 -04005039 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06005040 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04005041
James Ketrenos43f66a62005-03-25 12:31:53 -06005042 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005043 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06005044 /* IEEE_A */
5045 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5046 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005047 IPW_DEBUG_WX
5048 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005049 fr.tx_rates = 0;
5050 break;
5051 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005052
James Ketrenos43f66a62005-03-25 12:31:53 -06005053 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5054 break;
5055
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005056 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06005057 /* IEEE_B */
5058 if (network->mode == IEEE_B) {
5059 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
5060 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005061 IPW_DEBUG_WX
5062 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005063 fr.tx_rates = 0;
5064 }
5065 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04005066 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005067
5068 /* IEEE_G */
5069 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5070 IEEE80211_OFDM_RATES_MASK)) {
5071 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005072 IPW_DEBUG_WX
5073 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005074 fr.tx_rates = 0;
5075 break;
5076 }
5077
5078 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
5079 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
5080 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
5081 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005082
James Ketrenos43f66a62005-03-25 12:31:53 -06005083 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
5084 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
5085 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
5086 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005087
James Ketrenos43f66a62005-03-25 12:31:53 -06005088 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
5089 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
5090 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
5091 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005092
James Ketrenos43f66a62005-03-25 12:31:53 -06005093 fr.tx_rates |= mask;
5094 break;
5095 }
5096
5097 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005098 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06005099}
5100
James Ketrenosea2b26e2005-08-24 21:25:16 -05005101static void ipw_abort_scan(struct ipw_priv *priv)
5102{
5103 int err;
5104
5105 if (priv->status & STATUS_SCAN_ABORTING) {
5106 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5107 return;
5108 }
5109 priv->status |= STATUS_SCAN_ABORTING;
5110
5111 err = ipw_send_scan_abort(priv);
5112 if (err)
5113 IPW_DEBUG_HC("Request to abort scan failed.\n");
5114}
5115
5116static int ipw_request_scan(struct ipw_priv *priv)
5117{
5118 struct ipw_scan_request_ext scan;
5119 int channel_index = 0;
5120 int i, err, scan_type;
5121
5122 if (priv->status & STATUS_EXIT_PENDING) {
5123 IPW_DEBUG_SCAN("Aborting scan due to device shutdown\n");
5124 priv->status |= STATUS_SCAN_PENDING;
5125 return 0;
5126 }
5127
5128 if (priv->status & STATUS_SCANNING) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005129 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
5130// IPW_DEBUG_HC("Concurrent scan requested. Aborting first.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05005131 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosa613bff2005-08-24 21:43:11 -05005132// ipw_abort_scan(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005133 return 0;
5134 }
5135
5136 if (priv->status & STATUS_SCAN_ABORTING) {
5137 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
5138 priv->status |= STATUS_SCAN_PENDING;
5139 return 0;
5140 }
5141
5142 if (priv->status & STATUS_RF_KILL_MASK) {
5143 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
5144 priv->status |= STATUS_SCAN_PENDING;
5145 return 0;
5146 }
5147
5148 memset(&scan, 0, sizeof(scan));
5149
James Ketrenosa613bff2005-08-24 21:43:11 -05005150 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] = cpu_to_le16(20);
5151 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
5152 cpu_to_le16(20);
5153 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005154
James Ketrenosa613bff2005-08-24 21:43:11 -05005155 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05005156
5157#ifdef CONFIG_IPW_MONITOR
5158 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
5159 u8 band = 0, channel = priv->channel;
5160
5161 if (is_valid_channel(IEEE_A, channel))
5162 band = (u8) (IPW_A_MODE << 6) | 1;
5163
5164 if (is_valid_channel(IEEE_B | IEEE_G, channel))
5165 band = (u8) (IPW_B_MODE << 6) | 1;
5166
5167 if (band == 0) {
5168 band = (u8) (IPW_B_MODE << 6) | 1;
5169 channel = 9;
5170 }
5171
5172 scan.channels_list[channel_index++] = band;
5173 scan.channels_list[channel_index] = channel;
5174 ipw_set_scan_type(&scan, channel_index,
5175 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
5176
James Ketrenosa613bff2005-08-24 21:43:11 -05005177 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
5178 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005179 } else {
5180#endif /* CONFIG_IPW_MONITOR */
5181 /* If we are roaming, then make this a directed scan for the current
5182 * network. Otherwise, ensure that every other scan is a fast
5183 * channel hop scan */
5184 if ((priv->status & STATUS_ROAMING)
5185 || (!(priv->status & STATUS_ASSOCIATED)
5186 && (priv->config & CFG_STATIC_ESSID)
James Ketrenosa613bff2005-08-24 21:43:11 -05005187 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005188 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
5189 if (err) {
5190 IPW_DEBUG_HC
5191 ("Attempt to send SSID command failed.\n");
5192 return err;
5193 }
5194
5195 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
5196 } else {
5197 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
5198 }
5199
5200 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
5201 int start = channel_index;
5202 for (i = 0; i < MAX_A_CHANNELS; i++) {
5203 if (band_a_active_channel[i] == 0)
5204 break;
5205 if ((priv->status & STATUS_ASSOCIATED) &&
5206 band_a_active_channel[i] == priv->channel)
5207 continue;
5208 channel_index++;
5209 scan.channels_list[channel_index] =
5210 band_a_active_channel[i];
5211 ipw_set_scan_type(&scan, channel_index,
5212 scan_type);
5213 }
5214
5215 if (start != channel_index) {
5216 scan.channels_list[start] =
5217 (u8) (IPW_A_MODE << 6) | (channel_index -
5218 start);
5219 channel_index++;
5220 }
5221 }
5222
5223 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
5224 int start = channel_index;
5225 for (i = 0; i < MAX_B_CHANNELS; i++) {
5226 if (band_b_active_channel[i] == 0)
5227 break;
5228 if ((priv->status & STATUS_ASSOCIATED) &&
5229 band_b_active_channel[i] == priv->channel)
5230 continue;
5231 channel_index++;
5232 scan.channels_list[channel_index] =
5233 band_b_active_channel[i];
5234 ipw_set_scan_type(&scan, channel_index,
5235 scan_type);
5236 }
5237
5238 if (start != channel_index) {
5239 scan.channels_list[start] =
5240 (u8) (IPW_B_MODE << 6) | (channel_index -
5241 start);
5242 }
5243 }
5244#ifdef CONFIG_IPW_MONITOR
5245 }
5246#endif
5247
5248 err = ipw_send_scan_request_ext(priv, &scan);
5249 if (err) {
5250 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
5251 return -EIO;
5252 }
5253
5254 priv->status |= STATUS_SCANNING;
5255 priv->status &= ~STATUS_SCAN_PENDING;
5256
5257 return 0;
5258}
5259
5260/* Support for wpa_supplicant. Will be replaced with WEXT once
5261 * they get WPA support. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005262
5263/* following definitions must match definitions in driver_ipw.c */
5264
5265#define IPW_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
5266
5267#define IPW_CMD_SET_WPA_PARAM 1
5268#define IPW_CMD_SET_WPA_IE 2
5269#define IPW_CMD_SET_ENCRYPTION 3
5270#define IPW_CMD_MLME 4
5271
5272#define IPW_PARAM_WPA_ENABLED 1
5273#define IPW_PARAM_TKIP_COUNTERMEASURES 2
5274#define IPW_PARAM_DROP_UNENCRYPTED 3
5275#define IPW_PARAM_PRIVACY_INVOKED 4
5276#define IPW_PARAM_AUTH_ALGS 5
5277#define IPW_PARAM_IEEE_802_1X 6
5278
5279#define IPW_MLME_STA_DEAUTH 1
5280#define IPW_MLME_STA_DISASSOC 2
5281
5282#define IPW_CRYPT_ERR_UNKNOWN_ALG 2
5283#define IPW_CRYPT_ERR_UNKNOWN_ADDR 3
5284#define IPW_CRYPT_ERR_CRYPT_INIT_FAILED 4
5285#define IPW_CRYPT_ERR_KEY_SET_FAILED 5
5286#define IPW_CRYPT_ERR_TX_KEY_SET_FAILED 6
5287#define IPW_CRYPT_ERR_CARD_CONF_FAILED 7
5288
5289#define IPW_CRYPT_ALG_NAME_LEN 16
5290
5291struct ipw_param {
5292 u32 cmd;
5293 u8 sta_addr[ETH_ALEN];
5294 union {
5295 struct {
5296 u8 name;
5297 u32 value;
5298 } wpa_param;
5299 struct {
5300 u32 len;
5301 u8 *data;
5302 } wpa_ie;
5303 struct {
5304 int command;
5305 int reason_code;
5306 } mlme;
5307 struct {
5308 u8 alg[IPW_CRYPT_ALG_NAME_LEN];
5309 u8 set_tx;
5310 u32 err;
5311 u8 idx;
5312 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
5313 u16 key_len;
5314 u8 key[0];
5315 } crypt;
5316
5317 } u;
5318};
5319
5320/* end of driver_ipw.c code */
5321
5322static int ipw_wpa_enable(struct ipw_priv *priv, int value)
5323{
5324 struct ieee80211_device *ieee = priv->ieee;
5325 struct ieee80211_security sec = {
5326 .flags = SEC_LEVEL | SEC_ENABLED,
5327 };
5328 int ret = 0;
5329
5330 ieee->wpa_enabled = value;
5331
5332 if (value) {
5333 sec.level = SEC_LEVEL_3;
5334 sec.enabled = 1;
5335 } else {
5336 sec.level = SEC_LEVEL_0;
5337 sec.enabled = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05005338 ieee->wpa_ie_len = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005339 }
5340
5341 if (ieee->set_security)
5342 ieee->set_security(ieee->dev, &sec);
5343 else
5344 ret = -EOPNOTSUPP;
5345
5346 return ret;
5347}
5348
5349#define AUTH_ALG_OPEN_SYSTEM 0x1
5350#define AUTH_ALG_SHARED_KEY 0x2
5351
5352static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
5353{
5354 struct ieee80211_device *ieee = priv->ieee;
5355 struct ieee80211_security sec = {
5356 .flags = SEC_AUTH_MODE,
5357 };
5358 int ret = 0;
5359
5360 if (value & AUTH_ALG_SHARED_KEY) {
5361 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
5362 ieee->open_wep = 0;
5363 } else {
5364 sec.auth_mode = WLAN_AUTH_OPEN;
5365 ieee->open_wep = 1;
5366 }
5367
5368 if (ieee->set_security)
5369 ieee->set_security(ieee->dev, &sec);
5370 else
5371 ret = -EOPNOTSUPP;
5372
5373 return ret;
5374}
5375
5376static int ipw_wpa_set_param(struct net_device *dev, u8 name, u32 value)
5377{
5378 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosa613bff2005-08-24 21:43:11 -05005379 struct ieee80211_crypt_data *crypt;
5380 unsigned long flags;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005381 int ret = 0;
5382
5383 switch (name) {
5384 case IPW_PARAM_WPA_ENABLED:
5385 ret = ipw_wpa_enable(priv, value);
5386 break;
5387
5388 case IPW_PARAM_TKIP_COUNTERMEASURES:
James Ketrenosa613bff2005-08-24 21:43:11 -05005389 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
5390 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) {
5391 IPW_WARNING("Can't set TKIP countermeasures: "
5392 "crypt not set!\n");
5393 break;
5394 }
5395
5396 flags = crypt->ops->get_flags(crypt->priv);
5397
5398 if (value)
5399 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
5400 else
5401 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
5402
5403 crypt->ops->set_flags(flags, crypt->priv);
5404
James Ketrenosea2b26e2005-08-24 21:25:16 -05005405 break;
5406
5407 case IPW_PARAM_DROP_UNENCRYPTED:
5408 priv->ieee->drop_unencrypted = value;
5409 break;
5410
5411 case IPW_PARAM_PRIVACY_INVOKED:
5412 priv->ieee->privacy_invoked = value;
5413 break;
5414
5415 case IPW_PARAM_AUTH_ALGS:
5416 ret = ipw_wpa_set_auth_algs(priv, value);
5417 break;
5418
5419 case IPW_PARAM_IEEE_802_1X:
5420 priv->ieee->ieee802_1x = value;
5421 break;
5422
5423 default:
5424 IPW_ERROR("%s: Unknown WPA param: %d\n", dev->name, name);
5425 ret = -EOPNOTSUPP;
5426 }
5427
5428 return ret;
5429}
5430
5431static int ipw_wpa_mlme(struct net_device *dev, int command, int reason)
5432{
5433 struct ipw_priv *priv = ieee80211_priv(dev);
5434 int ret = 0;
5435
5436 switch (command) {
5437 case IPW_MLME_STA_DEAUTH:
5438 // silently ignore
5439 break;
5440
5441 case IPW_MLME_STA_DISASSOC:
5442 ipw_disassociate(priv);
5443 break;
5444
5445 default:
5446 IPW_ERROR("%s: Unknown MLME request: %d\n", dev->name, command);
5447 ret = -EOPNOTSUPP;
5448 }
5449
5450 return ret;
5451}
5452
5453static int ipw_set_rsn_capa(struct ipw_priv *priv,
5454 char *capabilities, int length)
5455{
5456 struct host_cmd cmd = {
5457 .cmd = IPW_CMD_RSN_CAPABILITIES,
5458 .len = length,
5459 };
5460
5461 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
5462
5463 memcpy(&cmd.param, capabilities, length);
5464 if (ipw_send_cmd(priv, &cmd)) {
5465 IPW_ERROR("failed to send HOST_CMD_RSN_CAPABILITIES command\n");
5466 return -1;
5467 }
5468 return 0;
5469}
5470
5471void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, int wpa_ie_len)
5472{
5473 /* make sure WPA is enabled */
5474 ipw_wpa_enable(priv, 1);
5475
5476 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))
5477 ipw_disassociate(priv);
5478}
5479
5480static int ipw_wpa_set_wpa_ie(struct net_device *dev,
5481 struct ipw_param *param, int plen)
5482{
5483 struct ipw_priv *priv = ieee80211_priv(dev);
5484 struct ieee80211_device *ieee = priv->ieee;
5485 u8 *buf;
5486
5487 if (!ieee->wpa_enabled)
5488 return -EOPNOTSUPP;
5489
5490 if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
5491 (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
5492 return -EINVAL;
5493
5494 if (param->u.wpa_ie.len) {
5495 buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
5496 if (buf == NULL)
5497 return -ENOMEM;
5498
5499 memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
5500 kfree(ieee->wpa_ie);
5501 ieee->wpa_ie = buf;
5502 ieee->wpa_ie_len = param->u.wpa_ie.len;
5503 } else {
5504 kfree(ieee->wpa_ie);
5505 ieee->wpa_ie = NULL;
5506 ieee->wpa_ie_len = 0;
5507 }
5508
5509 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
5510 return 0;
5511}
5512
5513/* implementation borrowed from hostap driver */
5514
5515static int ipw_wpa_set_encryption(struct net_device *dev,
5516 struct ipw_param *param, int param_len)
5517{
5518 int ret = 0;
5519 struct ipw_priv *priv = ieee80211_priv(dev);
5520 struct ieee80211_device *ieee = priv->ieee;
5521 struct ieee80211_crypto_ops *ops;
5522 struct ieee80211_crypt_data **crypt;
5523
5524 struct ieee80211_security sec = {
5525 .flags = 0,
5526 };
5527
5528 param->u.crypt.err = 0;
5529 param->u.crypt.alg[IPW_CRYPT_ALG_NAME_LEN - 1] = '\0';
5530
5531 if (param_len !=
5532 (int)((char *)param->u.crypt.key - (char *)param) +
5533 param->u.crypt.key_len) {
5534 IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len,
5535 param->u.crypt.key_len);
5536 return -EINVAL;
5537 }
5538 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
5539 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
5540 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
5541 if (param->u.crypt.idx >= WEP_KEYS)
5542 return -EINVAL;
5543 crypt = &ieee->crypt[param->u.crypt.idx];
5544 } else {
5545 return -EINVAL;
5546 }
5547
5548 if (strcmp(param->u.crypt.alg, "none") == 0) {
5549 if (crypt) {
5550 sec.enabled = 0;
5551 sec.level = SEC_LEVEL_0;
5552 sec.flags |= SEC_ENABLED | SEC_LEVEL;
5553 ieee80211_crypt_delayed_deinit(ieee, crypt);
5554 }
5555 goto done;
5556 }
5557 sec.enabled = 1;
5558 sec.flags |= SEC_ENABLED;
5559
5560 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
5561 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
5562 request_module("ieee80211_crypt_wep");
5563 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
5564 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
5565 request_module("ieee80211_crypt_tkip");
5566 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
5567 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
5568 request_module("ieee80211_crypt_ccmp");
5569 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
5570 }
5571 if (ops == NULL) {
5572 IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
5573 dev->name, param->u.crypt.alg);
5574 param->u.crypt.err = IPW_CRYPT_ERR_UNKNOWN_ALG;
5575 ret = -EINVAL;
5576 goto done;
5577 }
5578
5579 if (*crypt == NULL || (*crypt)->ops != ops) {
5580 struct ieee80211_crypt_data *new_crypt;
5581
5582 ieee80211_crypt_delayed_deinit(ieee, crypt);
5583
5584 new_crypt = (struct ieee80211_crypt_data *)
5585 kmalloc(sizeof(*new_crypt), GFP_KERNEL);
5586 if (new_crypt == NULL) {
5587 ret = -ENOMEM;
5588 goto done;
5589 }
5590 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
5591 new_crypt->ops = ops;
5592 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
5593 new_crypt->priv =
5594 new_crypt->ops->init(param->u.crypt.idx);
5595
5596 if (new_crypt->priv == NULL) {
5597 kfree(new_crypt);
5598 param->u.crypt.err = IPW_CRYPT_ERR_CRYPT_INIT_FAILED;
5599 ret = -EINVAL;
5600 goto done;
5601 }
5602
5603 *crypt = new_crypt;
5604 }
5605
5606 if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
5607 (*crypt)->ops->set_key(param->u.crypt.key,
5608 param->u.crypt.key_len, param->u.crypt.seq,
5609 (*crypt)->priv) < 0) {
5610 IPW_DEBUG_INFO("%s: key setting failed\n", dev->name);
5611 param->u.crypt.err = IPW_CRYPT_ERR_KEY_SET_FAILED;
5612 ret = -EINVAL;
5613 goto done;
5614 }
5615
5616 if (param->u.crypt.set_tx) {
5617 ieee->tx_keyidx = param->u.crypt.idx;
5618 sec.active_key = param->u.crypt.idx;
5619 sec.flags |= SEC_ACTIVE_KEY;
5620 }
5621
5622 if (ops->name != NULL) {
5623 if (strcmp(ops->name, "WEP") == 0) {
5624 memcpy(sec.keys[param->u.crypt.idx],
5625 param->u.crypt.key, param->u.crypt.key_len);
5626 sec.key_sizes[param->u.crypt.idx] =
5627 param->u.crypt.key_len;
5628 sec.flags |= (1 << param->u.crypt.idx);
5629 sec.flags |= SEC_LEVEL;
5630 sec.level = SEC_LEVEL_1;
5631 } else if (strcmp(ops->name, "TKIP") == 0) {
5632 sec.flags |= SEC_LEVEL;
5633 sec.level = SEC_LEVEL_2;
5634 } else if (strcmp(ops->name, "CCMP") == 0) {
5635 sec.flags |= SEC_LEVEL;
5636 sec.level = SEC_LEVEL_3;
5637 }
5638 }
5639 done:
5640 if (ieee->set_security)
5641 ieee->set_security(ieee->dev, &sec);
5642
5643 /* Do not reset port if card is in Managed mode since resetting will
5644 * generate new IEEE 802.11 authentication which may end up in looping
5645 * with IEEE 802.1X. If your hardware requires a reset after WEP
5646 * configuration (for example... Prism2), implement the reset_port in
5647 * the callbacks structures used to initialize the 802.11 stack. */
5648 if (ieee->reset_on_keychange &&
5649 ieee->iw_mode != IW_MODE_INFRA &&
5650 ieee->reset_port && ieee->reset_port(dev)) {
5651 IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
5652 param->u.crypt.err = IPW_CRYPT_ERR_CARD_CONF_FAILED;
5653 return -EINVAL;
5654 }
5655
5656 return ret;
5657}
5658
5659static int ipw_wpa_supplicant(struct net_device *dev, struct iw_point *p)
5660{
5661 struct ipw_param *param;
5662 int ret = 0;
5663
5664 IPW_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
5665
5666 if (p->length < sizeof(struct ipw_param) || !p->pointer)
5667 return -EINVAL;
5668
5669 param = (struct ipw_param *)kmalloc(p->length, GFP_KERNEL);
5670 if (param == NULL)
5671 return -ENOMEM;
5672
5673 if (copy_from_user(param, p->pointer, p->length)) {
5674 kfree(param);
5675 return -EFAULT;
5676 }
5677
5678 switch (param->cmd) {
5679
5680 case IPW_CMD_SET_WPA_PARAM:
5681 ret = ipw_wpa_set_param(dev, param->u.wpa_param.name,
5682 param->u.wpa_param.value);
5683 break;
5684
5685 case IPW_CMD_SET_WPA_IE:
5686 ret = ipw_wpa_set_wpa_ie(dev, param, p->length);
5687 break;
5688
5689 case IPW_CMD_SET_ENCRYPTION:
5690 ret = ipw_wpa_set_encryption(dev, param, p->length);
5691 break;
5692
5693 case IPW_CMD_MLME:
5694 ret = ipw_wpa_mlme(dev, param->u.mlme.command,
5695 param->u.mlme.reason_code);
5696 break;
5697
5698 default:
5699 IPW_ERROR("%s: Unknown WPA supplicant request: %d\n",
5700 dev->name, param->cmd);
5701 ret = -EOPNOTSUPP;
5702 }
5703
5704 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
5705 ret = -EFAULT;
5706
5707 kfree(param);
5708 return ret;
5709}
James Ketrenosea2b26e2005-08-24 21:25:16 -05005710
James Ketrenos43f66a62005-03-25 12:31:53 -06005711static int ipw_associate_network(struct ipw_priv *priv,
5712 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005713 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005714{
5715 int err;
5716
5717 if (priv->config & CFG_FIXED_RATE)
5718 ipw_set_fixed_rate(priv, network);
5719
5720 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005721 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005722 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005723 memcpy(priv->essid, network->ssid, priv->essid_len);
5724 }
5725
5726 network->last_associate = jiffies;
5727
5728 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
5729 priv->assoc_request.channel = network->channel;
5730 if ((priv->capability & CAP_PRIVACY_ON) &&
5731 (priv->capability & CAP_SHARED_KEY)) {
5732 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
5733 priv->assoc_request.auth_key = priv->sec.active_key;
5734 } else {
5735 priv->assoc_request.auth_type = AUTH_OPEN;
5736 priv->assoc_request.auth_key = 0;
5737 }
5738
Jeff Garzikbf794512005-07-31 13:07:26 -04005739 if (priv->capability & CAP_PRIVACY_ON)
James Ketrenos43f66a62005-03-25 12:31:53 -06005740 ipw_send_wep_keys(priv);
5741
James Ketrenosa613bff2005-08-24 21:43:11 -05005742 if (priv->ieee->wpa_ie_len) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005743 priv->assoc_request.policy_support = 0x02; /* RSN active */
5744 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
5745 priv->ieee->wpa_ie_len);
5746 }
James Ketrenosea2b26e2005-08-24 21:25:16 -05005747
Jeff Garzikbf794512005-07-31 13:07:26 -04005748 /*
5749 * It is valid for our ieee device to support multiple modes, but
5750 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06005751 * just one mode.
5752 */
5753 if (network->mode & priv->ieee->mode & IEEE_A)
5754 priv->assoc_request.ieee_mode = IPW_A_MODE;
5755 else if (network->mode & priv->ieee->mode & IEEE_G)
5756 priv->assoc_request.ieee_mode = IPW_G_MODE;
5757 else if (network->mode & priv->ieee->mode & IEEE_B)
5758 priv->assoc_request.ieee_mode = IPW_B_MODE;
5759
James Ketrenosea2b26e2005-08-24 21:25:16 -05005760 priv->assoc_request.capability = network->capability;
5761 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
5762 && !(priv->config & CFG_PREAMBLE_LONG)) {
5763 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
5764 } else {
5765 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
5766
5767 /* Clear the short preamble if we won't be supporting it */
5768 priv->assoc_request.capability &=
5769 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
5770 }
5771
James Ketrenos43f66a62005-03-25 12:31:53 -06005772 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05005773 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005774 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04005775 escape_essid(priv->essid, priv->essid_len),
5776 network->channel,
5777 ipw_modes[priv->assoc_request.ieee_mode],
5778 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05005779 (priv->assoc_request.preamble_length ==
5780 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
5781 network->capability &
5782 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06005783 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005784 priv->capability & CAP_PRIVACY_ON ?
5785 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005786 "(open)") : "",
5787 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04005788 priv->capability & CAP_PRIVACY_ON ?
James Ketrenos43f66a62005-03-25 12:31:53 -06005789 '1' + priv->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005790 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06005791
5792 priv->assoc_request.beacon_interval = network->beacon_interval;
5793 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005794 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005795 priv->assoc_request.assoc_type = HC_IBSS_START;
5796 priv->assoc_request.assoc_tsf_msw = 0;
5797 priv->assoc_request.assoc_tsf_lsw = 0;
5798 } else {
5799 if (unlikely(roaming))
5800 priv->assoc_request.assoc_type = HC_REASSOCIATE;
5801 else
5802 priv->assoc_request.assoc_type = HC_ASSOCIATE;
5803 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
5804 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
5805 }
5806
5807 memcpy(&priv->assoc_request.bssid, network->bssid, ETH_ALEN);
5808
5809 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
5810 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
5811 priv->assoc_request.atim_window = network->atim_window;
5812 } else {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005813 memcpy(&priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06005814 priv->assoc_request.atim_window = 0;
5815 }
5816
James Ketrenos43f66a62005-03-25 12:31:53 -06005817 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04005818
James Ketrenos43f66a62005-03-25 12:31:53 -06005819 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
5820 if (err) {
5821 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
5822 return err;
5823 }
5824
5825 rates->ieee_mode = priv->assoc_request.ieee_mode;
5826 rates->purpose = IPW_RATE_CONNECT;
5827 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04005828
James Ketrenos43f66a62005-03-25 12:31:53 -06005829 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
5830 priv->sys_config.dot11g_auto_detection = 1;
5831 else
5832 priv->sys_config.dot11g_auto_detection = 0;
5833 err = ipw_send_system_config(priv, &priv->sys_config);
5834 if (err) {
5835 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
5836 return err;
5837 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005838
James Ketrenos43f66a62005-03-25 12:31:53 -06005839 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05005840 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06005841 if (err) {
5842 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
5843 return err;
5844 }
5845
5846 /*
5847 * If preemption is enabled, it is possible for the association
5848 * to complete before we return from ipw_send_associate. Therefore
5849 * we have to be sure and update our priviate data first.
5850 */
5851 priv->channel = network->channel;
5852 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04005853 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06005854 priv->status &= ~STATUS_SECURITY_UPDATED;
5855
5856 priv->assoc_network = network;
5857
5858 err = ipw_send_associate(priv, &priv->assoc_request);
5859 if (err) {
5860 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
5861 return err;
5862 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005863
5864 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005865 escape_essid(priv->essid, priv->essid_len),
5866 MAC_ARG(priv->bssid));
5867
5868 return 0;
5869}
5870
5871static void ipw_roam(void *data)
5872{
5873 struct ipw_priv *priv = data;
5874 struct ieee80211_network *network = NULL;
5875 struct ipw_network_match match = {
5876 .network = priv->assoc_network
5877 };
5878
5879 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04005880 *
5881 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06005882 * setting the status ROAM bit and requesting a scan.
5883 * 2. When the scan completes, it schedules the ROAM work
5884 * 3. The ROAM work looks at all of the known networks for one that
5885 * is a better network than the currently associated. If none
5886 * found, the ROAM process is over (ROAM bit cleared)
5887 * 4. If a better network is found, a disassociation request is
5888 * sent.
5889 * 5. When the disassociation completes, the roam work is again
5890 * scheduled. The second time through, the driver is no longer
5891 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04005892 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06005893 * 6. At this point ,the roaming process is complete and the ROAM
5894 * status bit is cleared.
5895 */
5896
5897 /* If we are no longer associated, and the roaming bit is no longer
5898 * set, then we are not actively roaming, so just return */
5899 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
5900 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005901
James Ketrenos43f66a62005-03-25 12:31:53 -06005902 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005903 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06005904 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05005905 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06005906 u8 rssi = priv->assoc_network->stats.rssi;
5907 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05005908 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06005909 list_for_each_entry(network, &priv->ieee->network_list, list) {
5910 if (network != priv->assoc_network)
5911 ipw_best_network(priv, &match, network, 1);
5912 }
James Ketrenosa613bff2005-08-24 21:43:11 -05005913 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06005914 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04005915
James Ketrenos43f66a62005-03-25 12:31:53 -06005916 if (match.network == priv->assoc_network) {
5917 IPW_DEBUG_ASSOC("No better APs in this network to "
5918 "roam to.\n");
5919 priv->status &= ~STATUS_ROAMING;
5920 ipw_debug_config(priv);
5921 return;
5922 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005923
James Ketrenos43f66a62005-03-25 12:31:53 -06005924 ipw_send_disassociate(priv, 1);
5925 priv->assoc_network = match.network;
5926
5927 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005928 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005929
5930 /* Second pass through ROAM process -- request association */
5931 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
5932 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
5933 priv->status &= ~STATUS_ROAMING;
5934}
5935
5936static void ipw_associate(void *data)
5937{
5938 struct ipw_priv *priv = data;
5939
5940 struct ieee80211_network *network = NULL;
5941 struct ipw_network_match match = {
5942 .network = NULL
5943 };
5944 struct ipw_supported_rates *rates;
5945 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05005946 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06005947
5948 if (!(priv->config & CFG_ASSOCIATE) &&
5949 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005950 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005951 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
5952 return;
5953 }
5954
James Ketrenosa613bff2005-08-24 21:43:11 -05005955 /* Protect our use of the network_list */
5956 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04005957 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005958 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06005959
5960 network = match.network;
5961 rates = &match.rates;
5962
5963 if (network == NULL &&
5964 priv->ieee->iw_mode == IW_MODE_ADHOC &&
5965 priv->config & CFG_ADHOC_CREATE &&
5966 priv->config & CFG_STATIC_ESSID &&
James Ketrenosa613bff2005-08-24 21:43:11 -05005967 priv->config & CFG_STATIC_CHANNEL &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005968 !list_empty(&priv->ieee->network_free_list)) {
5969 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005970 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06005971 ipw_adhoc_create(priv, network);
5972 rates = &priv->rates;
5973 list_del(element);
5974 list_add_tail(&network->list, &priv->ieee->network_list);
5975 }
James Ketrenosa613bff2005-08-24 21:43:11 -05005976 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04005977
James Ketrenos43f66a62005-03-25 12:31:53 -06005978 /* If we reached the end of the list, then we don't have any valid
5979 * matching APs */
5980 if (!network) {
5981 ipw_debug_config(priv);
5982
James Ketrenosa613bff2005-08-24 21:43:11 -05005983 if (!(priv->status & STATUS_SCANNING))
5984 queue_delayed_work(priv->workqueue, &priv->request_scan,
5985 SCAN_INTERVAL);
Jeff Garzikbf794512005-07-31 13:07:26 -04005986
James Ketrenos43f66a62005-03-25 12:31:53 -06005987 return;
5988 }
5989
5990 ipw_associate_network(priv, network, rates, 0);
5991}
Jeff Garzikbf794512005-07-31 13:07:26 -04005992
5993static inline void ipw_handle_data_packet(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005994 struct ipw_rx_mem_buffer *rxb,
5995 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06005996{
5997 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
5998
5999 /* We received data from the HW, so stop the watchdog */
6000 priv->net_dev->trans_start = jiffies;
6001
Jeff Garzikbf794512005-07-31 13:07:26 -04006002 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06006003 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05006004 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06006005 skb_tailroom(rxb->skb))) {
6006 priv->ieee->stats.rx_errors++;
6007 priv->wstats.discard.misc++;
6008 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
6009 return;
6010 } else if (unlikely(!netif_running(priv->net_dev))) {
6011 priv->ieee->stats.rx_dropped++;
6012 priv->wstats.discard.misc++;
6013 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
6014 return;
6015 }
6016
6017 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02006018 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06006019
6020 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05006021 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06006022
6023 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
6024
Jeff Garzikbf794512005-07-31 13:07:26 -04006025 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06006026 priv->ieee->stats.rx_errors++;
James Ketrenosa613bff2005-08-24 21:43:11 -05006027 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06006028 rxb->skb = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05006029 ipw_led_activity_on(priv);
6030 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006031}
6032
James Ketrenosea2b26e2005-08-24 21:25:16 -05006033static inline int is_network_packet(struct ipw_priv *priv,
6034 struct ieee80211_hdr_4addr *header)
6035{
6036 /* Filter incoming packets to determine if they are targetted toward
6037 * this network, discarding packets coming from ourselves */
6038 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05006039 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
6040 /* {broad,multi}cast packets to our IBSS go through */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006041 if (is_broadcast_ether_addr(header->addr1) ||
6042 is_multicast_ether_addr(header->addr1))
6043 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05006044
6045 /* packets to our adapter go through */
6046 return !memcmp(header->addr1, priv->net_dev->dev_addr,
6047 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006048 break;
James Ketrenosa613bff2005-08-24 21:43:11 -05006049
6050 case IW_MODE_INFRA: /* Header: Dest. | AP{BSSID} | Source */
6051 /* {broad,multi}cast packets to our IBSS go through */
6052 if (is_broadcast_ether_addr(header->addr1) ||
6053 is_multicast_ether_addr(header->addr1))
6054 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
6055
6056 /* packets to our adapter go through */
6057 return !memcmp(header->addr1, priv->net_dev->dev_addr,
6058 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006059 break;
6060 }
James Ketrenosa613bff2005-08-24 21:43:11 -05006061
James Ketrenosea2b26e2005-08-24 21:25:16 -05006062 return 1;
6063}
6064
James Ketrenos43f66a62005-03-25 12:31:53 -06006065/*
6066 * Main entry function for recieving a packet with 80211 headers. This
6067 * should be called when ever the FW has notified us that there is a new
6068 * skb in the recieve queue.
6069 */
6070static void ipw_rx(struct ipw_priv *priv)
6071{
6072 struct ipw_rx_mem_buffer *rxb;
6073 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05006074 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06006075 u32 r, w, i;
6076 u8 network_packet;
6077
6078 r = ipw_read32(priv, CX2_RX_READ_INDEX);
6079 w = ipw_read32(priv, CX2_RX_WRITE_INDEX);
6080 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
6081
6082 while (i != r) {
6083 rxb = priv->rxq->queue[i];
6084#ifdef CONFIG_IPW_DEBUG
6085 if (unlikely(rxb == NULL)) {
6086 printk(KERN_CRIT "Queue not allocated!\n");
6087 break;
6088 }
6089#endif
6090 priv->rxq->queue[i] = NULL;
6091
6092 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
Jeff Garzikbf794512005-07-31 13:07:26 -04006093 CX2_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06006094 PCI_DMA_FROMDEVICE);
6095
6096 pkt = (struct ipw_rx_packet *)rxb->skb->data;
6097 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
6098 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006099 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06006100
6101 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006102 case RX_FRAME_TYPE: /* 802.11 frame */ {
6103 struct ieee80211_rx_stats stats = {
6104 .rssi = pkt->u.frame.rssi_dbm -
6105 IPW_RSSI_TO_DBM,
James Ketrenosa613bff2005-08-24 21:43:11 -05006106 /* .signal = le16_to_cpu(pkt->u.frame.signal), */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006107 .rate = pkt->u.frame.rate,
6108 .mac_time = jiffies,
6109 .received_channel =
6110 pkt->u.frame.received_channel,
6111 .freq =
6112 (pkt->u.frame.
6113 control & (1 << 0)) ?
6114 IEEE80211_24GHZ_BAND :
6115 IEEE80211_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05006116 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006117 };
James Ketrenos43f66a62005-03-25 12:31:53 -06006118
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006119 if (stats.rssi != 0)
6120 stats.mask |= IEEE80211_STATMASK_RSSI;
6121 if (stats.signal != 0)
6122 stats.mask |= IEEE80211_STATMASK_SIGNAL;
6123 if (stats.rate != 0)
6124 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06006125
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006126 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06006127
James Ketrenosea2b26e2005-08-24 21:25:16 -05006128#ifdef CONFIG_IPW_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006129 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
6130 ipw_handle_data_packet(priv, rxb,
6131 &stats);
6132 break;
6133 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006134#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04006135
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006136 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05006137 (struct ieee80211_hdr_4addr *)(rxb->skb->
6138 data +
6139 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06006140 /* TODO: Check Ad-Hoc dest/source and make sure
6141 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04006142 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06006143 * frame control of the packet and disregard
6144 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06006145
James Ketrenosea2b26e2005-08-24 21:25:16 -05006146 network_packet =
6147 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006148 if (network_packet && priv->assoc_network) {
6149 priv->assoc_network->stats.rssi =
6150 stats.rssi;
6151 average_add(&priv->average_rssi,
6152 stats.rssi);
6153 priv->last_rx_rssi = stats.rssi;
6154 }
6155
6156 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05006157 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006158
James Ketrenosa613bff2005-08-24 21:43:11 -05006159 if (le16_to_cpu(pkt->u.frame.length) <
6160 frame_hdr_len(header)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006161 IPW_DEBUG_DROP
6162 ("Received packet is too small. "
6163 "Dropping.\n");
6164 priv->ieee->stats.rx_errors++;
6165 priv->wstats.discard.misc++;
6166 break;
6167 }
6168
James Ketrenosa613bff2005-08-24 21:43:11 -05006169 switch (WLAN_FC_GET_TYPE
6170 (le16_to_cpu(header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006171 case IEEE80211_FTYPE_MGMT:
6172 ieee80211_rx_mgt(priv->ieee, header,
6173 &stats);
6174 if (priv->ieee->iw_mode == IW_MODE_ADHOC
6175 &&
6176 ((WLAN_FC_GET_STYPE
James Ketrenosa613bff2005-08-24 21:43:11 -05006177 (le16_to_cpu(header->frame_ctl))
6178 == IEEE80211_STYPE_PROBE_RESP)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006179 ||
6180 (WLAN_FC_GET_STYPE
James Ketrenosa613bff2005-08-24 21:43:11 -05006181 (le16_to_cpu(header->frame_ctl))
6182 == IEEE80211_STYPE_BEACON))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006183 && !memcmp(header->addr3,
6184 priv->bssid, ETH_ALEN))
6185 ipw_add_station(priv,
6186 header->addr2);
6187 break;
6188
6189 case IEEE80211_FTYPE_CTL:
6190 break;
6191
6192 case IEEE80211_FTYPE_DATA:
6193 if (network_packet)
6194 ipw_handle_data_packet(priv,
6195 rxb,
6196 &stats);
6197 else
6198 IPW_DEBUG_DROP("Dropping: "
6199 MAC_FMT ", "
6200 MAC_FMT ", "
6201 MAC_FMT "\n",
6202 MAC_ARG(header->
6203 addr1),
6204 MAC_ARG(header->
6205 addr2),
6206 MAC_ARG(header->
6207 addr3));
6208 break;
6209 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006210 break;
6211 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006212
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006213 case RX_HOST_NOTIFICATION_TYPE:{
6214 IPW_DEBUG_RX
6215 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06006216 pkt->u.notification.subtype,
6217 pkt->u.notification.flags,
6218 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006219 ipw_rx_notification(priv, &pkt->u.notification);
6220 break;
6221 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006222
6223 default:
6224 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
6225 pkt->header.message_type);
6226 break;
6227 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006228
6229 /* For now we just don't re-use anything. We can tweak this
6230 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06006231 * fail to Rx correctly */
6232 if (rxb->skb != NULL) {
6233 dev_kfree_skb_any(rxb->skb);
6234 rxb->skb = NULL;
6235 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006236
James Ketrenos43f66a62005-03-25 12:31:53 -06006237 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
6238 CX2_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
6239 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04006240
James Ketrenos43f66a62005-03-25 12:31:53 -06006241 i = (i + 1) % RX_QUEUE_SIZE;
6242 }
6243
6244 /* Backtrack one entry */
6245 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
6246
6247 ipw_rx_queue_restock(priv);
6248}
6249
James Ketrenos43f66a62005-03-25 12:31:53 -06006250/*
6251 * This file defines the Wireless Extension handlers. It does not
6252 * define any methods of hardware manipulation and relies on the
6253 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04006254 *
6255 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06006256 * function used to poll the hardware vs. making unecessary calls.
6257 *
6258 */
6259
Jeff Garzikbf794512005-07-31 13:07:26 -04006260static int ipw_wx_get_name(struct net_device *dev,
6261 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006262 union iwreq_data *wrqu, char *extra)
6263{
6264 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosa613bff2005-08-24 21:43:11 -05006265 if (priv->status & STATUS_RF_KILL_MASK) {
6266 strcpy(wrqu->name, "radio off");
6267 } else if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06006268 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04006269 else
James Ketrenos43f66a62005-03-25 12:31:53 -06006270 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
6271 ipw_modes[priv->assoc_request.ieee_mode]);
6272 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
6273 return 0;
6274}
6275
6276static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
6277{
6278 if (channel == 0) {
6279 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
6280 priv->config &= ~CFG_STATIC_CHANNEL;
6281 if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED |
6282 STATUS_ASSOCIATING))) {
6283 IPW_DEBUG_ASSOC("Attempting to associate with new "
6284 "parameters.\n");
6285 ipw_associate(priv);
6286 }
6287
6288 return 0;
6289 }
6290
6291 priv->config |= CFG_STATIC_CHANNEL;
6292
6293 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006294 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
6295 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06006296 return 0;
6297 }
6298
6299 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
6300 priv->channel = channel;
6301
6302 /* If we are currently associated, or trying to associate
6303 * then see if this is a new channel (causing us to disassociate) */
6304 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
6305 IPW_DEBUG_ASSOC("Disassociating due to channel change.\n");
6306 ipw_disassociate(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05006307 } else if (!(priv->status & (STATUS_SCANNING)))
James Ketrenos43f66a62005-03-25 12:31:53 -06006308 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06006309
6310 return 0;
6311}
6312
Jeff Garzikbf794512005-07-31 13:07:26 -04006313static int ipw_wx_set_freq(struct net_device *dev,
6314 struct iw_request_info *info,
6315 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06006316{
6317 struct ipw_priv *priv = ieee80211_priv(dev);
6318 struct iw_freq *fwrq = &wrqu->freq;
Jeff Garzikbf794512005-07-31 13:07:26 -04006319
James Ketrenos43f66a62005-03-25 12:31:53 -06006320 /* if setting by freq convert to channel */
6321 if (fwrq->e == 1) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006322 if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006323 int f = fwrq->m / 100000;
6324 int c = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04006325
James Ketrenos43f66a62005-03-25 12:31:53 -06006326 while ((c < REG_MAX_CHANNEL) &&
6327 (f != ipw_frequencies[c]))
6328 c++;
Jeff Garzikbf794512005-07-31 13:07:26 -04006329
James Ketrenos43f66a62005-03-25 12:31:53 -06006330 /* hack to fall through */
6331 fwrq->e = 0;
6332 fwrq->m = c + 1;
6333 }
6334 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006335
6336 if (fwrq->e > 0 || fwrq->m > 1000)
James Ketrenos43f66a62005-03-25 12:31:53 -06006337 return -EOPNOTSUPP;
6338
6339 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006340 return ipw_set_channel(priv, (u8) fwrq->m);
James Ketrenos43f66a62005-03-25 12:31:53 -06006341}
6342
Jeff Garzikbf794512005-07-31 13:07:26 -04006343static int ipw_wx_get_freq(struct net_device *dev,
6344 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006345 union iwreq_data *wrqu, char *extra)
6346{
6347 struct ipw_priv *priv = ieee80211_priv(dev);
6348
6349 wrqu->freq.e = 0;
6350
6351 /* If we are associated, trying to associate, or have a statically
6352 * configured CHANNEL then return that; otherwise return ANY */
6353 if (priv->config & CFG_STATIC_CHANNEL ||
6354 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
6355 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04006356 else
James Ketrenos43f66a62005-03-25 12:31:53 -06006357 wrqu->freq.m = 0;
6358
6359 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
6360 return 0;
6361}
6362
Jeff Garzikbf794512005-07-31 13:07:26 -04006363static int ipw_wx_set_mode(struct net_device *dev,
6364 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006365 union iwreq_data *wrqu, char *extra)
6366{
6367 struct ipw_priv *priv = ieee80211_priv(dev);
6368 int err = 0;
6369
6370 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
6371
6372 if (wrqu->mode == priv->ieee->iw_mode)
6373 return 0;
6374
6375 switch (wrqu->mode) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006376#ifdef CONFIG_IPW_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06006377 case IW_MODE_MONITOR:
6378#endif
6379 case IW_MODE_ADHOC:
6380 case IW_MODE_INFRA:
6381 break;
6382 case IW_MODE_AUTO:
6383 wrqu->mode = IW_MODE_INFRA;
6384 break;
6385 default:
6386 return -EINVAL;
6387 }
6388
James Ketrenosea2b26e2005-08-24 21:25:16 -05006389#ifdef CONFIG_IPW_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04006390 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06006391 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04006392
6393 if (wrqu->mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06006394 priv->net_dev->type = ARPHRD_IEEE80211;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006395#endif /* CONFIG_IPW_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04006396
James Ketrenos43f66a62005-03-25 12:31:53 -06006397#ifdef CONFIG_PM
Jeff Garzikbf794512005-07-31 13:07:26 -04006398 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06006399 * flag so ipw_load() will bring in the new firmawre */
James Ketrenosa613bff2005-08-24 21:43:11 -05006400 if (fw_loaded)
James Ketrenos43f66a62005-03-25 12:31:53 -06006401 fw_loaded = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006402
6403 release_firmware(bootfw);
6404 release_firmware(ucode);
6405 release_firmware(firmware);
6406 bootfw = ucode = firmware = NULL;
6407#endif
6408
6409 priv->ieee->iw_mode = wrqu->mode;
James Ketrenosa613bff2005-08-24 21:43:11 -05006410 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -04006411
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006412 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06006413}
6414
Jeff Garzikbf794512005-07-31 13:07:26 -04006415static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006416 struct iw_request_info *info,
6417 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06006418{
6419 struct ipw_priv *priv = ieee80211_priv(dev);
6420
6421 wrqu->mode = priv->ieee->iw_mode;
6422 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
6423
6424 return 0;
6425}
6426
James Ketrenos43f66a62005-03-25 12:31:53 -06006427#define DEFAULT_RTS_THRESHOLD 2304U
6428#define MIN_RTS_THRESHOLD 1U
6429#define MAX_RTS_THRESHOLD 2304U
6430#define DEFAULT_BEACON_INTERVAL 100U
6431#define DEFAULT_SHORT_RETRY_LIMIT 7U
6432#define DEFAULT_LONG_RETRY_LIMIT 4U
6433
6434/* Values are in microsecond */
6435static const s32 timeout_duration[] = {
6436 350000,
6437 250000,
6438 75000,
6439 37000,
6440 25000,
6441};
6442
6443static const s32 period_duration[] = {
6444 400000,
6445 700000,
6446 1000000,
6447 1000000,
6448 1000000
6449};
6450
Jeff Garzikbf794512005-07-31 13:07:26 -04006451static int ipw_wx_get_range(struct net_device *dev,
6452 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006453 union iwreq_data *wrqu, char *extra)
6454{
6455 struct ipw_priv *priv = ieee80211_priv(dev);
6456 struct iw_range *range = (struct iw_range *)extra;
6457 u16 val;
6458 int i;
6459
6460 wrqu->data.length = sizeof(*range);
6461 memset(range, 0, sizeof(*range));
6462
6463 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04006464 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06006465
6466 range->max_qual.qual = 100;
6467 /* TODO: Find real max RSSI and stick here */
6468 range->max_qual.level = 0;
6469 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006470 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06006471
6472 range->avg_qual.qual = 70;
6473 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006474 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06006475 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006476 range->avg_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06006477
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006478 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06006479
Jeff Garzikbf794512005-07-31 13:07:26 -04006480 for (i = 0; i < range->num_bitrates; i++)
6481 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006482 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04006483
James Ketrenos43f66a62005-03-25 12:31:53 -06006484 range->max_rts = DEFAULT_RTS_THRESHOLD;
6485 range->min_frag = MIN_FRAG_THRESHOLD;
6486 range->max_frag = MAX_FRAG_THRESHOLD;
6487
6488 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04006489 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06006490 range->num_encoding_sizes = 2;
6491 range->max_encoding_tokens = WEP_KEYS;
6492
6493 /* Set the Wireless Extension versions */
6494 range->we_version_compiled = WIRELESS_EXT;
6495 range->we_version_source = 16;
6496
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006497 range->num_channels = FREQ_COUNT;
James Ketrenos43f66a62005-03-25 12:31:53 -06006498
6499 val = 0;
6500 for (i = 0; i < FREQ_COUNT; i++) {
6501 range->freq[val].i = i + 1;
6502 range->freq[val].m = ipw_frequencies[i] * 100000;
6503 range->freq[val].e = 1;
6504 val++;
6505
6506 if (val == IW_MAX_FREQUENCIES)
6507 break;
6508 }
6509 range->num_frequency = val;
6510
6511 IPW_DEBUG_WX("GET Range\n");
6512 return 0;
6513}
6514
Jeff Garzikbf794512005-07-31 13:07:26 -04006515static int ipw_wx_set_wap(struct net_device *dev,
6516 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006517 union iwreq_data *wrqu, char *extra)
6518{
6519 struct ipw_priv *priv = ieee80211_priv(dev);
6520
6521 static const unsigned char any[] = {
6522 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
6523 };
6524 static const unsigned char off[] = {
6525 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
6526 };
6527
Jeff Garzikbf794512005-07-31 13:07:26 -04006528 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06006529 return -EINVAL;
6530
6531 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
6532 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
6533 /* we disable mandatory BSSID association */
6534 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
6535 priv->config &= ~CFG_STATIC_BSSID;
6536 if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED |
6537 STATUS_ASSOCIATING))) {
6538 IPW_DEBUG_ASSOC("Attempting to associate with new "
6539 "parameters.\n");
6540 ipw_associate(priv);
6541 }
6542
6543 return 0;
6544 }
6545
6546 priv->config |= CFG_STATIC_BSSID;
6547 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
6548 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
6549 return 0;
6550 }
6551
6552 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
6553 MAC_ARG(wrqu->ap_addr.sa_data));
6554
6555 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
6556
6557 /* If we are currently associated, or trying to associate
6558 * then see if this is a new BSSID (causing us to disassociate) */
6559 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
6560 IPW_DEBUG_ASSOC("Disassociating due to BSSID change.\n");
6561 ipw_disassociate(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05006562 } else if (!(priv->status & (STATUS_SCANNING)))
James Ketrenos43f66a62005-03-25 12:31:53 -06006563 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06006564
6565 return 0;
6566}
6567
Jeff Garzikbf794512005-07-31 13:07:26 -04006568static int ipw_wx_get_wap(struct net_device *dev,
6569 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006570 union iwreq_data *wrqu, char *extra)
6571{
6572 struct ipw_priv *priv = ieee80211_priv(dev);
6573 /* If we are associated, trying to associate, or have a statically
6574 * configured BSSID then return that; otherwise return ANY */
Jeff Garzikbf794512005-07-31 13:07:26 -04006575 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06006576 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
6577 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
6578 memcpy(wrqu->ap_addr.sa_data, &priv->bssid, ETH_ALEN);
6579 } else
6580 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
6581
6582 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
6583 MAC_ARG(wrqu->ap_addr.sa_data));
6584 return 0;
6585}
6586
Jeff Garzikbf794512005-07-31 13:07:26 -04006587static int ipw_wx_set_essid(struct net_device *dev,
6588 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006589 union iwreq_data *wrqu, char *extra)
6590{
6591 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006592 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06006593 int length = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04006594
James Ketrenos43f66a62005-03-25 12:31:53 -06006595 if (wrqu->essid.flags && wrqu->essid.length) {
6596 length = wrqu->essid.length - 1;
6597 essid = extra;
6598 }
6599 if (length == 0) {
6600 IPW_DEBUG_WX("Setting ESSID to ANY\n");
6601 priv->config &= ~CFG_STATIC_ESSID;
6602 if (!(priv->status & (STATUS_SCANNING | STATUS_ASSOCIATED |
6603 STATUS_ASSOCIATING))) {
6604 IPW_DEBUG_ASSOC("Attempting to associate with new "
6605 "parameters.\n");
6606 ipw_associate(priv);
6607 }
6608
6609 return 0;
6610 }
6611
6612 length = min(length, IW_ESSID_MAX_SIZE);
6613
6614 priv->config |= CFG_STATIC_ESSID;
6615
6616 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
6617 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
6618 return 0;
6619 }
6620
6621 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
6622 length);
6623
6624 priv->essid_len = length;
6625 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04006626
James Ketrenos43f66a62005-03-25 12:31:53 -06006627 /* If we are currently associated, or trying to associate
6628 * then see if this is a new ESSID (causing us to disassociate) */
6629 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
6630 IPW_DEBUG_ASSOC("Disassociating due to ESSID change.\n");
6631 ipw_disassociate(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05006632 } else if (!(priv->status & (STATUS_SCANNING)))
James Ketrenos43f66a62005-03-25 12:31:53 -06006633 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06006634
6635 return 0;
6636}
6637
Jeff Garzikbf794512005-07-31 13:07:26 -04006638static int ipw_wx_get_essid(struct net_device *dev,
6639 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006640 union iwreq_data *wrqu, char *extra)
6641{
6642 struct ipw_priv *priv = ieee80211_priv(dev);
6643
6644 /* If we are associated, trying to associate, or have a statically
6645 * configured ESSID then return that; otherwise return ANY */
6646 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04006647 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
6648 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06006649 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04006650 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06006651 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006652 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06006653 } else {
6654 IPW_DEBUG_WX("Getting essid: ANY\n");
6655 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006656 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06006657 }
6658
6659 return 0;
6660}
6661
Jeff Garzikbf794512005-07-31 13:07:26 -04006662static int ipw_wx_set_nick(struct net_device *dev,
6663 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006664 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006665{
James Ketrenos43f66a62005-03-25 12:31:53 -06006666 struct ipw_priv *priv = ieee80211_priv(dev);
6667
6668 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
6669 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
6670 return -E2BIG;
6671
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006672 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06006673 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006674 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06006675 IPW_DEBUG_TRACE("<<\n");
6676 return 0;
6677
6678}
6679
Jeff Garzikbf794512005-07-31 13:07:26 -04006680static int ipw_wx_get_nick(struct net_device *dev,
6681 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006682 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006683{
James Ketrenos43f66a62005-03-25 12:31:53 -06006684 struct ipw_priv *priv = ieee80211_priv(dev);
6685 IPW_DEBUG_WX("Getting nick\n");
6686 wrqu->data.length = strlen(priv->nick) + 1;
6687 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006688 wrqu->data.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06006689 return 0;
6690}
6691
James Ketrenos43f66a62005-03-25 12:31:53 -06006692static int ipw_wx_set_rate(struct net_device *dev,
6693 struct iw_request_info *info,
6694 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006695{
James Ketrenosea2b26e2005-08-24 21:25:16 -05006696 /* TODO: We should use semaphores or locks for access to priv */
6697 struct ipw_priv *priv = ieee80211_priv(dev);
6698 u32 target_rate = wrqu->bitrate.value;
6699 u32 fixed, mask;
6700
6701 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
6702 /* value = X, fixed = 1 means only rate X */
6703 /* value = X, fixed = 0 means all rates lower equal X */
6704
6705 if (target_rate == -1) {
6706 fixed = 0;
6707 mask = IEEE80211_DEFAULT_RATES_MASK;
6708 /* Now we should reassociate */
6709 goto apply;
6710 }
6711
6712 mask = 0;
6713 fixed = wrqu->bitrate.fixed;
6714
6715 if (target_rate == 1000000 || !fixed)
6716 mask |= IEEE80211_CCK_RATE_1MB_MASK;
6717 if (target_rate == 1000000)
6718 goto apply;
6719
6720 if (target_rate == 2000000 || !fixed)
6721 mask |= IEEE80211_CCK_RATE_2MB_MASK;
6722 if (target_rate == 2000000)
6723 goto apply;
6724
6725 if (target_rate == 5500000 || !fixed)
6726 mask |= IEEE80211_CCK_RATE_5MB_MASK;
6727 if (target_rate == 5500000)
6728 goto apply;
6729
6730 if (target_rate == 6000000 || !fixed)
6731 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
6732 if (target_rate == 6000000)
6733 goto apply;
6734
6735 if (target_rate == 9000000 || !fixed)
6736 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
6737 if (target_rate == 9000000)
6738 goto apply;
6739
6740 if (target_rate == 11000000 || !fixed)
6741 mask |= IEEE80211_CCK_RATE_11MB_MASK;
6742 if (target_rate == 11000000)
6743 goto apply;
6744
6745 if (target_rate == 12000000 || !fixed)
6746 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
6747 if (target_rate == 12000000)
6748 goto apply;
6749
6750 if (target_rate == 18000000 || !fixed)
6751 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
6752 if (target_rate == 18000000)
6753 goto apply;
6754
6755 if (target_rate == 24000000 || !fixed)
6756 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
6757 if (target_rate == 24000000)
6758 goto apply;
6759
6760 if (target_rate == 36000000 || !fixed)
6761 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
6762 if (target_rate == 36000000)
6763 goto apply;
6764
6765 if (target_rate == 48000000 || !fixed)
6766 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
6767 if (target_rate == 48000000)
6768 goto apply;
6769
6770 if (target_rate == 54000000 || !fixed)
6771 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
6772 if (target_rate == 54000000)
6773 goto apply;
6774
6775 IPW_DEBUG_WX("invalid rate specified, returning error\n");
6776 return -EINVAL;
6777
6778 apply:
6779 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
6780 mask, fixed ? "fixed" : "sub-rates");
6781
6782 if (mask == IEEE80211_DEFAULT_RATES_MASK)
6783 priv->config &= ~CFG_FIXED_RATE;
6784 else
6785 priv->config |= CFG_FIXED_RATE;
6786
6787 if (priv->rates_mask != mask) {
6788 priv->rates_mask = mask;
6789 /* If we are already associated or are currently trying to
6790 * associate, disassociate and try again */
6791 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
6792 IPW_DEBUG_ASSOC("Disassociating due to RATE change.\n");
6793 ipw_disassociate(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05006794 } else if (!(priv->status & (STATUS_SCANNING))) {
6795 /* We are not yet associated, so kick one off... */
6796 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006797 }
James Ketrenosea2b26e2005-08-24 21:25:16 -05006798 }
6799
6800 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06006801}
6802
Jeff Garzikbf794512005-07-31 13:07:26 -04006803static int ipw_wx_get_rate(struct net_device *dev,
6804 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006805 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006806{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006807 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06006808 wrqu->bitrate.value = priv->last_rate;
6809
6810 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
6811 return 0;
6812}
6813
Jeff Garzikbf794512005-07-31 13:07:26 -04006814static int ipw_wx_set_rts(struct net_device *dev,
6815 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006816 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006817{
James Ketrenos43f66a62005-03-25 12:31:53 -06006818 struct ipw_priv *priv = ieee80211_priv(dev);
6819
6820 if (wrqu->rts.disabled)
6821 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
6822 else {
6823 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
6824 wrqu->rts.value > MAX_RTS_THRESHOLD)
6825 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04006826
James Ketrenos43f66a62005-03-25 12:31:53 -06006827 priv->rts_threshold = wrqu->rts.value;
6828 }
6829
6830 ipw_send_rts_threshold(priv, priv->rts_threshold);
6831 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
6832 return 0;
6833}
6834
Jeff Garzikbf794512005-07-31 13:07:26 -04006835static int ipw_wx_get_rts(struct net_device *dev,
6836 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006837 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006838{
James Ketrenos43f66a62005-03-25 12:31:53 -06006839 struct ipw_priv *priv = ieee80211_priv(dev);
6840 wrqu->rts.value = priv->rts_threshold;
6841 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006842 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
James Ketrenos43f66a62005-03-25 12:31:53 -06006843
6844 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
6845 return 0;
6846}
6847
Jeff Garzikbf794512005-07-31 13:07:26 -04006848static int ipw_wx_set_txpow(struct net_device *dev,
6849 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006850 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006851{
James Ketrenos43f66a62005-03-25 12:31:53 -06006852 struct ipw_priv *priv = ieee80211_priv(dev);
6853 struct ipw_tx_power tx_power;
6854 int i;
6855
6856 if (ipw_radio_kill_sw(priv, wrqu->power.disabled))
6857 return -EINPROGRESS;
6858
6859 if (wrqu->power.flags != IW_TXPOW_DBM)
6860 return -EINVAL;
6861
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006862 if ((wrqu->power.value > 20) || (wrqu->power.value < -12))
James Ketrenos43f66a62005-03-25 12:31:53 -06006863 return -EINVAL;
6864
6865 priv->tx_power = wrqu->power.value;
6866
6867 memset(&tx_power, 0, sizeof(tx_power));
6868
6869 /* configure device for 'G' band */
6870 tx_power.ieee_mode = IPW_G_MODE;
6871 tx_power.num_channels = 11;
6872 for (i = 0; i < 11; i++) {
6873 tx_power.channels_tx_power[i].channel_number = i + 1;
6874 tx_power.channels_tx_power[i].tx_power = priv->tx_power;
6875 }
6876 if (ipw_send_tx_power(priv, &tx_power))
6877 goto error;
6878
6879 /* configure device to also handle 'B' band */
6880 tx_power.ieee_mode = IPW_B_MODE;
6881 if (ipw_send_tx_power(priv, &tx_power))
6882 goto error;
6883
6884 return 0;
6885
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006886 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06006887 return -EIO;
6888}
6889
Jeff Garzikbf794512005-07-31 13:07:26 -04006890static int ipw_wx_get_txpow(struct net_device *dev,
6891 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006892 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006893{
James Ketrenos43f66a62005-03-25 12:31:53 -06006894 struct ipw_priv *priv = ieee80211_priv(dev);
6895
6896 wrqu->power.value = priv->tx_power;
6897 wrqu->power.fixed = 1;
6898 wrqu->power.flags = IW_TXPOW_DBM;
6899 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
6900
Jeff Garzikbf794512005-07-31 13:07:26 -04006901 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006902 wrqu->power.disabled ? "ON" : "OFF", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06006903
6904 return 0;
6905}
6906
Jeff Garzikbf794512005-07-31 13:07:26 -04006907static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006908 struct iw_request_info *info,
6909 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06006910{
6911 struct ipw_priv *priv = ieee80211_priv(dev);
6912
6913 if (wrqu->frag.disabled)
6914 priv->ieee->fts = DEFAULT_FTS;
6915 else {
6916 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
6917 wrqu->frag.value > MAX_FRAG_THRESHOLD)
6918 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04006919
James Ketrenos43f66a62005-03-25 12:31:53 -06006920 priv->ieee->fts = wrqu->frag.value & ~0x1;
6921 }
6922
6923 ipw_send_frag_threshold(priv, wrqu->frag.value);
6924 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
6925 return 0;
6926}
6927
Jeff Garzikbf794512005-07-31 13:07:26 -04006928static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006929 struct iw_request_info *info,
6930 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06006931{
6932 struct ipw_priv *priv = ieee80211_priv(dev);
6933 wrqu->frag.value = priv->ieee->fts;
6934 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006935 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
James Ketrenos43f66a62005-03-25 12:31:53 -06006936
6937 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
6938
6939 return 0;
6940}
6941
Jeff Garzikbf794512005-07-31 13:07:26 -04006942static int ipw_wx_set_retry(struct net_device *dev,
6943 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006944 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006945{
James Ketrenos43f66a62005-03-25 12:31:53 -06006946 IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu);
Jeff Garzikbf794512005-07-31 13:07:26 -04006947 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06006948}
6949
Jeff Garzikbf794512005-07-31 13:07:26 -04006950static int ipw_wx_get_retry(struct net_device *dev,
6951 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006952 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006953{
James Ketrenos43f66a62005-03-25 12:31:53 -06006954 IPW_DEBUG_WX("0x%p, 0x%p, 0x%p\n", dev, info, wrqu);
Jeff Garzikbf794512005-07-31 13:07:26 -04006955 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06006956}
6957
Jeff Garzikbf794512005-07-31 13:07:26 -04006958static int ipw_wx_set_scan(struct net_device *dev,
6959 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006960 union iwreq_data *wrqu, char *extra)
6961{
6962 struct ipw_priv *priv = ieee80211_priv(dev);
6963 IPW_DEBUG_WX("Start scan\n");
6964 if (ipw_request_scan(priv))
6965 return -EIO;
6966 return 0;
6967}
6968
Jeff Garzikbf794512005-07-31 13:07:26 -04006969static int ipw_wx_get_scan(struct net_device *dev,
6970 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06006971 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04006972{
James Ketrenos43f66a62005-03-25 12:31:53 -06006973 struct ipw_priv *priv = ieee80211_priv(dev);
6974 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
6975}
6976
Jeff Garzikbf794512005-07-31 13:07:26 -04006977static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006978 struct iw_request_info *info,
6979 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06006980{
6981 struct ipw_priv *priv = ieee80211_priv(dev);
6982 return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
6983}
6984
Jeff Garzikbf794512005-07-31 13:07:26 -04006985static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006986 struct iw_request_info *info,
6987 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06006988{
6989 struct ipw_priv *priv = ieee80211_priv(dev);
6990 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
6991}
6992
Jeff Garzikbf794512005-07-31 13:07:26 -04006993static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006994 struct iw_request_info *info,
6995 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06006996{
6997 struct ipw_priv *priv = ieee80211_priv(dev);
6998 int err;
6999
7000 if (wrqu->power.disabled) {
7001 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
7002 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
7003 if (err) {
7004 IPW_DEBUG_WX("failed setting power mode.\n");
7005 return err;
7006 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007007 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
7008
7009 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04007010 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007011
7012 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007013 case IW_POWER_ON: /* If not specified */
7014 case IW_POWER_MODE: /* If set all mask */
7015 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06007016 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007017 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06007018 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
7019 wrqu->power.flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007020 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06007021 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007022
James Ketrenos43f66a62005-03-25 12:31:53 -06007023 /* If the user hasn't specified a power management mode yet, default
7024 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007025 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06007026 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04007027 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007028 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
7029 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
7030 if (err) {
7031 IPW_DEBUG_WX("failed setting power mode.\n");
7032 return err;
7033 }
7034
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007035 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04007036
James Ketrenos43f66a62005-03-25 12:31:53 -06007037 return 0;
7038}
7039
Jeff Garzikbf794512005-07-31 13:07:26 -04007040static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007041 struct iw_request_info *info,
7042 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06007043{
7044 struct ipw_priv *priv = ieee80211_priv(dev);
7045
James Ketrenosa613bff2005-08-24 21:43:11 -05007046 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06007047 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05007048 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007049 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007050
7051 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04007052
James Ketrenos43f66a62005-03-25 12:31:53 -06007053 return 0;
7054}
7055
Jeff Garzikbf794512005-07-31 13:07:26 -04007056static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007057 struct iw_request_info *info,
7058 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06007059{
7060 struct ipw_priv *priv = ieee80211_priv(dev);
7061 int mode = *(int *)extra;
7062 int err;
Jeff Garzikbf794512005-07-31 13:07:26 -04007063
James Ketrenos43f66a62005-03-25 12:31:53 -06007064 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
7065 mode = IPW_POWER_AC;
7066 priv->power_mode = mode;
7067 } else {
7068 priv->power_mode = IPW_POWER_ENABLED | mode;
7069 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007070
James Ketrenos43f66a62005-03-25 12:31:53 -06007071 if (priv->power_mode != mode) {
7072 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04007073
James Ketrenos43f66a62005-03-25 12:31:53 -06007074 if (err) {
7075 IPW_DEBUG_WX("failed setting power mode.\n");
7076 return err;
7077 }
7078 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007079
James Ketrenos43f66a62005-03-25 12:31:53 -06007080 return 0;
7081}
7082
7083#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04007084static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007085 struct iw_request_info *info,
7086 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06007087{
7088 struct ipw_priv *priv = ieee80211_priv(dev);
7089 int level = IPW_POWER_LEVEL(priv->power_mode);
7090 char *p = extra;
7091
7092 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
7093
7094 switch (level) {
7095 case IPW_POWER_AC:
7096 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
7097 break;
7098 case IPW_POWER_BATTERY:
7099 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
7100 break;
7101 default:
7102 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04007103 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06007104 timeout_duration[level - 1] / 1000,
7105 period_duration[level - 1] / 1000);
7106 }
7107
7108 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007109 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06007110
7111 wrqu->data.length = p - extra + 1;
7112
7113 return 0;
7114}
7115
7116static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007117 struct iw_request_info *info,
7118 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06007119{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007120 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06007121 int mode = *(int *)extra;
7122 u8 band = 0, modulation = 0;
7123
7124 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007125 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007126 return -EINVAL;
7127 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007128
James Ketrenos43f66a62005-03-25 12:31:53 -06007129 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05007130 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007131 if (mode & IEEE_A) {
7132 band |= IEEE80211_52GHZ_BAND;
7133 modulation |= IEEE80211_OFDM_MODULATION;
7134 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05007135 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007136 } else {
7137 if (mode & IEEE_A) {
7138 IPW_WARNING("Attempt to set 2200BG into "
7139 "802.11a mode\n");
7140 return -EINVAL;
7141 }
7142
James Ketrenosa33a1982005-09-14 14:28:59 -05007143 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007144 }
7145
7146 if (mode & IEEE_B) {
7147 band |= IEEE80211_24GHZ_BAND;
7148 modulation |= IEEE80211_CCK_MODULATION;
7149 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05007150 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04007151
James Ketrenos43f66a62005-03-25 12:31:53 -06007152 if (mode & IEEE_G) {
7153 band |= IEEE80211_24GHZ_BAND;
7154 modulation |= IEEE80211_OFDM_MODULATION;
7155 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05007156 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007157
7158 priv->ieee->mode = mode;
7159 priv->ieee->freq_band = band;
7160 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007161 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06007162
7163 /* If we are currently associated, or trying to associate
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007164 * then see if this is a new configuration (causing us to
James Ketrenos43f66a62005-03-25 12:31:53 -06007165 * disassociate) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007166 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007167 /* The resulting association will trigger
James Ketrenos43f66a62005-03-25 12:31:53 -06007168 * the new rates to be sent to the device */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007169 IPW_DEBUG_ASSOC("Disassociating due to mode change.\n");
7170 ipw_disassociate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007171 } else
7172 ipw_send_supported_rates(priv, &priv->rates);
7173
James Ketrenosa613bff2005-08-24 21:43:11 -05007174 /* Update the band LEDs */
7175 ipw_led_band_on(priv);
7176
Jeff Garzikbf794512005-07-31 13:07:26 -04007177 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007178 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007179 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
James Ketrenos43f66a62005-03-25 12:31:53 -06007180 return 0;
7181}
7182
7183static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007184 struct iw_request_info *info,
7185 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06007186{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007187 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06007188
James Ketrenosea2b26e2005-08-24 21:25:16 -05007189 switch (priv->ieee->mode) {
7190 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06007191 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
7192 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05007193 case IEEE_B:
7194 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
7195 break;
7196 case IEEE_A | IEEE_B:
7197 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
7198 break;
7199 case IEEE_G:
7200 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
7201 break;
7202 case IEEE_A | IEEE_G:
7203 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
7204 break;
7205 case IEEE_B | IEEE_G:
7206 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
7207 break;
7208 case IEEE_A | IEEE_B | IEEE_G:
7209 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
7210 break;
7211 default:
7212 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06007213 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04007214 }
7215
James Ketrenos43f66a62005-03-25 12:31:53 -06007216 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
7217
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007218 wrqu->data.length = strlen(extra) + 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007219
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007220 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007221}
7222
James Ketrenosea2b26e2005-08-24 21:25:16 -05007223static int ipw_wx_set_preamble(struct net_device *dev,
7224 struct iw_request_info *info,
7225 union iwreq_data *wrqu, char *extra)
7226{
7227 struct ipw_priv *priv = ieee80211_priv(dev);
7228 int mode = *(int *)extra;
7229
7230 /* Switching from SHORT -> LONG requires a disassociation */
7231 if (mode == 1) {
7232 if (!(priv->config & CFG_PREAMBLE_LONG)) {
7233 priv->config |= CFG_PREAMBLE_LONG;
7234 if (priv->status &
7235 (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
7236 IPW_DEBUG_ASSOC
7237 ("Disassociating due to preamble "
7238 "change.\n");
7239 ipw_disassociate(priv);
7240 }
7241 }
7242 goto done;
7243 }
7244
7245 if (mode == 0) {
7246 priv->config &= ~CFG_PREAMBLE_LONG;
7247 goto done;
7248 }
7249
7250 return -EINVAL;
7251
7252 done:
7253 return 0;
7254}
7255
7256static int ipw_wx_get_preamble(struct net_device *dev,
7257 struct iw_request_info *info,
7258 union iwreq_data *wrqu, char *extra)
7259{
7260 struct ipw_priv *priv = ieee80211_priv(dev);
7261
7262 if (priv->config & CFG_PREAMBLE_LONG)
7263 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
7264 else
7265 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
7266
7267 return 0;
7268}
7269
7270#ifdef CONFIG_IPW_MONITOR
7271static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04007272 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06007273 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04007274{
James Ketrenos43f66a62005-03-25 12:31:53 -06007275 struct ipw_priv *priv = ieee80211_priv(dev);
7276 int *parms = (int *)extra;
7277 int enable = (parms[0] > 0);
7278
James Ketrenosea2b26e2005-08-24 21:25:16 -05007279 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06007280 if (enable) {
7281 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
7282 priv->net_dev->type = ARPHRD_IEEE80211;
James Ketrenosa613bff2005-08-24 21:43:11 -05007283 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06007284 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007285
James Ketrenos43f66a62005-03-25 12:31:53 -06007286 ipw_set_channel(priv, parms[1]);
7287 } else {
7288 if (priv->ieee->iw_mode != IW_MODE_MONITOR)
7289 return 0;
7290 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05007291 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06007292 }
7293 return 0;
7294}
7295
Jeff Garzikbf794512005-07-31 13:07:26 -04007296static int ipw_wx_reset(struct net_device *dev,
7297 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06007298 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04007299{
James Ketrenos43f66a62005-03-25 12:31:53 -06007300 struct ipw_priv *priv = ieee80211_priv(dev);
7301 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05007302 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06007303 return 0;
7304}
James Ketrenosea2b26e2005-08-24 21:25:16 -05007305#endif // CONFIG_IPW_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06007306
7307/* Rebase the WE IOCTLs to zero for the handler array */
7308#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007309static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007310 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
7311 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
7312 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
7313 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
7314 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
7315 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
7316 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
7317 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
7318 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
7319 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
7320 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
7321 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
7322 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
7323 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
7324 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
7325 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
7326 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
7327 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
7328 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
7329 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
7330 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
7331 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
7332 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
7333 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
7334 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
7335 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
7336 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
7337 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -05007338 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
7339 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
7340 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
7341 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenos43f66a62005-03-25 12:31:53 -06007342};
7343
7344#define IPW_PRIV_SET_POWER SIOCIWFIRSTPRIV
7345#define IPW_PRIV_GET_POWER SIOCIWFIRSTPRIV+1
7346#define IPW_PRIV_SET_MODE SIOCIWFIRSTPRIV+2
7347#define IPW_PRIV_GET_MODE SIOCIWFIRSTPRIV+3
James Ketrenosea2b26e2005-08-24 21:25:16 -05007348#define IPW_PRIV_SET_PREAMBLE SIOCIWFIRSTPRIV+4
7349#define IPW_PRIV_GET_PREAMBLE SIOCIWFIRSTPRIV+5
7350#define IPW_PRIV_SET_MONITOR SIOCIWFIRSTPRIV+6
7351#define IPW_PRIV_RESET SIOCIWFIRSTPRIV+7
James Ketrenos43f66a62005-03-25 12:31:53 -06007352
Jeff Garzikbf794512005-07-31 13:07:26 -04007353static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06007354 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007355 .cmd = IPW_PRIV_SET_POWER,
7356 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
7357 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06007358 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007359 .cmd = IPW_PRIV_GET_POWER,
7360 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
7361 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06007362 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007363 .cmd = IPW_PRIV_SET_MODE,
7364 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
7365 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06007366 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007367 .cmd = IPW_PRIV_GET_MODE,
7368 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
7369 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06007370 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007371 .cmd = IPW_PRIV_SET_PREAMBLE,
7372 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
7373 .name = "set_preamble"},
7374 {
7375 .cmd = IPW_PRIV_GET_PREAMBLE,
7376 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
7377 .name = "get_preamble"},
7378#ifdef CONFIG_IPW_MONITOR
7379 {
7380 IPW_PRIV_SET_MONITOR,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007381 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
James Ketrenos43f66a62005-03-25 12:31:53 -06007382 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007383 IPW_PRIV_RESET,
7384 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosea2b26e2005-08-24 21:25:16 -05007385#endif /* CONFIG_IPW_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06007386};
7387
7388static iw_handler ipw_priv_handler[] = {
7389 ipw_wx_set_powermode,
7390 ipw_wx_get_powermode,
7391 ipw_wx_set_wireless_mode,
7392 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007393 ipw_wx_set_preamble,
7394 ipw_wx_get_preamble,
7395#ifdef CONFIG_IPW_MONITOR
7396 ipw_wx_set_monitor,
Jeff Garzikbf794512005-07-31 13:07:26 -04007397 ipw_wx_reset,
James Ketrenos43f66a62005-03-25 12:31:53 -06007398#endif
7399};
7400
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007401static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007402 .standard = ipw_wx_handlers,
7403 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
7404 .num_private = ARRAY_SIZE(ipw_priv_handler),
7405 .num_private_args = ARRAY_SIZE(ipw_priv_args),
7406 .private = ipw_priv_handler,
7407 .private_args = ipw_priv_args,
James Ketrenos43f66a62005-03-25 12:31:53 -06007408};
7409
James Ketrenosa613bff2005-08-24 21:43:11 -05007410static struct iw_public_data ipw_wx_data;
7411
James Ketrenos43f66a62005-03-25 12:31:53 -06007412/*
7413 * Get wireless statistics.
7414 * Called by /proc/net/wireless
7415 * Also called by SIOCGIWSTATS
7416 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007417static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06007418{
7419 struct ipw_priv *priv = ieee80211_priv(dev);
7420 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04007421
James Ketrenos43f66a62005-03-25 12:31:53 -06007422 wstats = &priv->wstats;
7423
James Ketrenosea2b26e2005-08-24 21:25:16 -05007424 /* if hw is disabled, then ipw_get_ordinal() can't be called.
Jeff Garzikbf794512005-07-31 13:07:26 -04007425 * ipw2100_wx_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06007426 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
7427 * and associated; if not associcated, the values are all meaningless
7428 * anyway, so set them all to NULL and INVALID */
7429 if (!(priv->status & STATUS_ASSOCIATED)) {
7430 wstats->miss.beacon = 0;
7431 wstats->discard.retries = 0;
7432 wstats->qual.qual = 0;
7433 wstats->qual.level = 0;
7434 wstats->qual.noise = 0;
7435 wstats->qual.updated = 7;
7436 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007437 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06007438 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04007439 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007440
7441 wstats->qual.qual = priv->quality;
7442 wstats->qual.level = average_value(&priv->average_rssi);
7443 wstats->qual.noise = average_value(&priv->average_noise);
7444 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007445 IW_QUAL_NOISE_UPDATED;
James Ketrenos43f66a62005-03-25 12:31:53 -06007446
7447 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
7448 wstats->discard.retries = priv->last_tx_failures;
7449 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04007450
James Ketrenos43f66a62005-03-25 12:31:53 -06007451/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
7452 goto fail_get_ordinal;
7453 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04007454
James Ketrenos43f66a62005-03-25 12:31:53 -06007455 return wstats;
7456}
7457
James Ketrenos43f66a62005-03-25 12:31:53 -06007458/* net device stuff */
7459
7460static inline void init_sys_config(struct ipw_sys_config *sys_config)
7461{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007462 memset(sys_config, 0, sizeof(struct ipw_sys_config));
7463 sys_config->bt_coexistence = 1; /* We may need to look into prvStaBtConfig */
James Ketrenos43f66a62005-03-25 12:31:53 -06007464 sys_config->answer_broadcast_ssid_probe = 0;
7465 sys_config->accept_all_data_frames = 0;
7466 sys_config->accept_non_directed_frames = 1;
7467 sys_config->exclude_unicast_unencrypted = 0;
7468 sys_config->disable_unicast_decryption = 1;
7469 sys_config->exclude_multicast_unencrypted = 0;
7470 sys_config->disable_multicast_decryption = 1;
7471 sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007472 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -06007473 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04007474 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007475 sys_config->bt_coexist_collision_thr = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05007476 sys_config->pass_noise_stats_to_host = 0; //1 -- fix for 256
James Ketrenos43f66a62005-03-25 12:31:53 -06007477}
7478
7479static int ipw_net_open(struct net_device *dev)
7480{
7481 struct ipw_priv *priv = ieee80211_priv(dev);
7482 IPW_DEBUG_INFO("dev->open\n");
7483 /* we should be verifying the device is ready to be opened */
Jeff Garzikbf794512005-07-31 13:07:26 -04007484 if (!(priv->status & STATUS_RF_KILL_MASK) &&
7485 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06007486 netif_start_queue(dev);
7487 return 0;
7488}
7489
7490static int ipw_net_stop(struct net_device *dev)
7491{
7492 IPW_DEBUG_INFO("dev->close\n");
7493 netif_stop_queue(dev);
7494 return 0;
7495}
7496
7497/*
7498todo:
7499
7500modify to send one tfd per fragment instead of using chunking. otherwise
7501we need to heavily modify the ieee80211_skb_to_txb.
7502*/
7503
7504static inline void ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb)
7505{
James Ketrenos0dacca12005-09-21 12:23:41 -05007506 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007507 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -06007508 int i = 0;
7509 struct tfd_frame *tfd;
7510 struct clx2_tx_queue *txq = &priv->txq[0];
7511 struct clx2_queue *q = &txq->q;
7512 u8 id, hdr_len, unicast;
7513 u16 remaining_bytes;
7514
7515 switch (priv->ieee->iw_mode) {
7516 case IW_MODE_ADHOC:
7517 hdr_len = IEEE80211_3ADDR_LEN;
7518 unicast = !is_broadcast_ether_addr(hdr->addr1) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007519 !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -06007520 id = ipw_find_station(priv, hdr->addr1);
7521 if (id == IPW_INVALID_STATION) {
7522 id = ipw_add_station(priv, hdr->addr1);
7523 if (id == IPW_INVALID_STATION) {
7524 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -04007525 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007526 MAC_ARG(hdr->addr1));
7527 goto drop;
7528 }
7529 }
7530 break;
7531
7532 case IW_MODE_INFRA:
7533 default:
7534 unicast = !is_broadcast_ether_addr(hdr->addr3) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007535 !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -06007536 hdr_len = IEEE80211_3ADDR_LEN;
7537 id = 0;
7538 break;
7539 }
7540
7541 tfd = &txq->bd[q->first_empty];
7542 txq->txb[q->first_empty] = txb;
7543 memset(tfd, 0, sizeof(*tfd));
7544 tfd->u.data.station_number = id;
7545
7546 tfd->control_flags.message_type = TX_FRAME_TYPE;
7547 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
7548
7549 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -05007550 tfd->u.data.len = cpu_to_le16(txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06007551 remaining_bytes = txb->payload_size;
7552 if (unlikely(!unicast))
7553 tfd->u.data.tx_flags = DCT_FLAG_NO_WEP;
7554 else
7555 tfd->u.data.tx_flags = DCT_FLAG_NO_WEP | DCT_FLAG_ACK_REQD;
Jeff Garzikbf794512005-07-31 13:07:26 -04007556
James Ketrenos43f66a62005-03-25 12:31:53 -06007557 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
7558 tfd->u.data.tx_flags_ext = DCT_FLAG_EXT_MODE_CCK;
7559 else
7560 tfd->u.data.tx_flags_ext = DCT_FLAG_EXT_MODE_OFDM;
7561
James Ketrenosea2b26e2005-08-24 21:25:16 -05007562 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
7563 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06007564
7565 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
7566
7567 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -05007568 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
7569 txb->nr_frags));
7570 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
7571 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
7572 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
7573 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
7574 i, le32_to_cpu(tfd->u.data.num_chunks),
7575 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04007576 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007577 i, tfd->u.data.num_chunks,
7578 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04007579 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -06007580 txb->fragments[i]->len - hdr_len);
7581
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007582 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05007583 cpu_to_le32(pci_map_single
7584 (priv->pci_dev,
7585 txb->fragments[i]->data + hdr_len,
7586 txb->fragments[i]->len - hdr_len,
7587 PCI_DMA_TODEVICE));
7588 tfd->u.data.chunk_len[i] =
7589 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06007590 }
7591
7592 if (i != txb->nr_frags) {
7593 struct sk_buff *skb;
7594 u16 remaining_bytes = 0;
7595 int j;
7596
7597 for (j = i; j < txb->nr_frags; j++)
7598 remaining_bytes += txb->fragments[j]->len - hdr_len;
7599
7600 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
7601 remaining_bytes);
7602 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
7603 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -05007604 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -06007605 for (j = i; j < txb->nr_frags; j++) {
7606 int size = txb->fragments[j]->len - hdr_len;
7607 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007608 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06007609 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007610 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06007611 }
7612 dev_kfree_skb_any(txb->fragments[i]);
7613 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007614 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05007615 cpu_to_le32(pci_map_single
7616 (priv->pci_dev, skb->data,
7617 tfd->u.data.chunk_len[i],
7618 PCI_DMA_TODEVICE));
7619
7620 tfd->u.data.num_chunks =
7621 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
7622 1);
Jeff Garzikbf794512005-07-31 13:07:26 -04007623 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007624 }
7625
7626 /* kick DMA */
7627 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
7628 ipw_write32(priv, q->reg_w, q->first_empty);
7629
Jeff Garzikbf794512005-07-31 13:07:26 -04007630 if (ipw_queue_space(q) < q->high_mark)
James Ketrenos43f66a62005-03-25 12:31:53 -06007631 netif_stop_queue(priv->net_dev);
7632
7633 return;
7634
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007635 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -06007636 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
7637 ieee80211_txb_free(txb);
7638}
7639
7640static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -05007641 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06007642{
7643 struct ipw_priv *priv = ieee80211_priv(dev);
7644 unsigned long flags;
7645
7646 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
7647
7648 spin_lock_irqsave(&priv->lock, flags);
7649
7650 if (!(priv->status & STATUS_ASSOCIATED)) {
7651 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
7652 priv->ieee->stats.tx_carrier_errors++;
7653 netif_stop_queue(dev);
7654 goto fail_unlock;
7655 }
7656
7657 ipw_tx_skb(priv, txb);
James Ketrenosa613bff2005-08-24 21:43:11 -05007658 ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007659
7660 spin_unlock_irqrestore(&priv->lock, flags);
7661 return 0;
7662
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007663 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -06007664 spin_unlock_irqrestore(&priv->lock, flags);
7665 return 1;
7666}
7667
7668static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
7669{
7670 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -04007671
James Ketrenos43f66a62005-03-25 12:31:53 -06007672 priv->ieee->stats.tx_packets = priv->tx_packets;
7673 priv->ieee->stats.rx_packets = priv->rx_packets;
7674 return &priv->ieee->stats;
7675}
7676
7677static void ipw_net_set_multicast_list(struct net_device *dev)
7678{
7679
7680}
7681
7682static int ipw_net_set_mac_address(struct net_device *dev, void *p)
7683{
7684 struct ipw_priv *priv = ieee80211_priv(dev);
7685 struct sockaddr *addr = p;
7686 if (!is_valid_ether_addr(addr->sa_data))
7687 return -EADDRNOTAVAIL;
7688 priv->config |= CFG_CUSTOM_MAC;
7689 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
7690 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
7691 priv->net_dev->name, MAC_ARG(priv->mac_addr));
James Ketrenosa613bff2005-08-24 21:43:11 -05007692 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06007693 return 0;
7694}
7695
Jeff Garzikbf794512005-07-31 13:07:26 -04007696static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -06007697 struct ethtool_drvinfo *info)
7698{
7699 struct ipw_priv *p = ieee80211_priv(dev);
7700 char vers[64];
7701 char date[32];
7702 u32 len;
7703
7704 strcpy(info->driver, DRV_NAME);
7705 strcpy(info->version, DRV_VERSION);
7706
7707 len = sizeof(vers);
7708 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
7709 len = sizeof(date);
7710 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
7711
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007712 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -06007713 vers, date);
7714 strcpy(info->bus_info, pci_name(p->pci_dev));
7715 info->eedump_len = CX2_EEPROM_IMAGE_SIZE;
7716}
7717
7718static u32 ipw_ethtool_get_link(struct net_device *dev)
7719{
7720 struct ipw_priv *priv = ieee80211_priv(dev);
7721 return (priv->status & STATUS_ASSOCIATED) != 0;
7722}
7723
7724static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
7725{
7726 return CX2_EEPROM_IMAGE_SIZE;
7727}
7728
7729static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007730 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -06007731{
7732 struct ipw_priv *p = ieee80211_priv(dev);
7733
7734 if (eeprom->offset + eeprom->len > CX2_EEPROM_IMAGE_SIZE)
7735 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04007736
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007737 memcpy(bytes, &((u8 *) p->eeprom)[eeprom->offset], eeprom->len);
James Ketrenos43f66a62005-03-25 12:31:53 -06007738 return 0;
7739}
7740
7741static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007742 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -06007743{
7744 struct ipw_priv *p = ieee80211_priv(dev);
7745 int i;
7746
7747 if (eeprom->offset + eeprom->len > CX2_EEPROM_IMAGE_SIZE)
7748 return -EINVAL;
7749
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007750 memcpy(&((u8 *) p->eeprom)[eeprom->offset], bytes, eeprom->len);
Jeff Garzikbf794512005-07-31 13:07:26 -04007751 for (i = IPW_EEPROM_DATA;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007752 i < IPW_EEPROM_DATA + CX2_EEPROM_IMAGE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06007753 ipw_write8(p, i, p->eeprom[i]);
7754
7755 return 0;
7756}
7757
7758static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007759 .get_link = ipw_ethtool_get_link,
7760 .get_drvinfo = ipw_ethtool_get_drvinfo,
7761 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
7762 .get_eeprom = ipw_ethtool_get_eeprom,
7763 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -06007764};
7765
7766static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
7767{
7768 struct ipw_priv *priv = data;
7769 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -04007770
James Ketrenos43f66a62005-03-25 12:31:53 -06007771 if (!priv)
7772 return IRQ_NONE;
7773
7774 spin_lock(&priv->lock);
7775
7776 if (!(priv->status & STATUS_INT_ENABLED)) {
7777 /* Shared IRQ */
7778 goto none;
7779 }
7780
7781 inta = ipw_read32(priv, CX2_INTA_RW);
7782 inta_mask = ipw_read32(priv, CX2_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -04007783
James Ketrenos43f66a62005-03-25 12:31:53 -06007784 if (inta == 0xFFFFFFFF) {
7785 /* Hardware disappeared */
7786 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
7787 goto none;
7788 }
7789
7790 if (!(inta & (CX2_INTA_MASK_ALL & inta_mask))) {
7791 /* Shared interrupt */
7792 goto none;
7793 }
7794
7795 /* tell the device to stop sending interrupts */
7796 ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04007797
James Ketrenos43f66a62005-03-25 12:31:53 -06007798 /* ack current interrupts */
7799 inta &= (CX2_INTA_MASK_ALL & inta_mask);
7800 ipw_write32(priv, CX2_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -04007801
James Ketrenos43f66a62005-03-25 12:31:53 -06007802 /* Cache INTA value for our tasklet */
7803 priv->isr_inta = inta;
7804
7805 tasklet_schedule(&priv->irq_tasklet);
7806
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007807 spin_unlock(&priv->lock);
James Ketrenos43f66a62005-03-25 12:31:53 -06007808
7809 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007810 none:
James Ketrenos43f66a62005-03-25 12:31:53 -06007811 spin_unlock(&priv->lock);
7812 return IRQ_NONE;
7813}
7814
7815static void ipw_rf_kill(void *adapter)
7816{
7817 struct ipw_priv *priv = adapter;
7818 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -04007819
James Ketrenos43f66a62005-03-25 12:31:53 -06007820 spin_lock_irqsave(&priv->lock, flags);
7821
7822 if (rf_kill_active(priv)) {
7823 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
7824 if (priv->workqueue)
7825 queue_delayed_work(priv->workqueue,
7826 &priv->rf_kill, 2 * HZ);
7827 goto exit_unlock;
7828 }
7829
7830 /* RF Kill is now disabled, so bring the device back up */
7831
7832 if (!(priv->status & STATUS_RF_KILL_MASK)) {
7833 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
7834 "device\n");
7835
7836 /* we can not do an adapter restart while inside an irq lock */
7837 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -04007838 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06007839 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
7840 "enabled\n");
7841
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007842 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -06007843 spin_unlock_irqrestore(&priv->lock, flags);
7844}
7845
James Ketrenosa613bff2005-08-24 21:43:11 -05007846void ipw_link_up(struct ipw_priv *priv)
7847{
7848 netif_carrier_on(priv->net_dev);
7849 if (netif_queue_stopped(priv->net_dev)) {
7850 IPW_DEBUG_NOTIF("waking queue\n");
7851 netif_wake_queue(priv->net_dev);
7852 } else {
7853 IPW_DEBUG_NOTIF("starting queue\n");
7854 netif_start_queue(priv->net_dev);
7855 }
7856
7857 ipw_reset_stats(priv);
7858 /* Ensure the rate is updated immediately */
7859 priv->last_rate = ipw_get_current_rate(priv);
7860 ipw_gather_stats(priv);
7861 ipw_led_link_up(priv);
7862 notify_wx_assoc_event(priv);
7863
7864 if (priv->config & CFG_BACKGROUND_SCAN)
7865 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
7866}
7867
7868void ipw_link_down(struct ipw_priv *priv)
7869{
7870 ipw_led_link_down(priv);
7871 netif_carrier_off(priv->net_dev);
7872 netif_stop_queue(priv->net_dev);
7873 notify_wx_assoc_event(priv);
7874
7875 /* Cancel any queued work ... */
7876 cancel_delayed_work(&priv->request_scan);
7877 cancel_delayed_work(&priv->adhoc_check);
7878 cancel_delayed_work(&priv->gather_stats);
7879
7880 ipw_reset_stats(priv);
7881
7882 /* Queue up another scan... */
7883 queue_work(priv->workqueue, &priv->request_scan);
7884}
7885
James Ketrenos43f66a62005-03-25 12:31:53 -06007886static int ipw_setup_deferred_work(struct ipw_priv *priv)
7887{
7888 int ret = 0;
7889
James Ketrenos43f66a62005-03-25 12:31:53 -06007890 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -06007891 init_waitqueue_head(&priv->wait_command_queue);
7892
7893 INIT_WORK(&priv->adhoc_check, ipw_adhoc_check, priv);
7894 INIT_WORK(&priv->associate, ipw_associate, priv);
7895 INIT_WORK(&priv->disassociate, ipw_disassociate, priv);
7896 INIT_WORK(&priv->rx_replenish, ipw_rx_queue_replenish, priv);
7897 INIT_WORK(&priv->adapter_restart, ipw_adapter_restart, priv);
7898 INIT_WORK(&priv->rf_kill, ipw_rf_kill, priv);
7899 INIT_WORK(&priv->up, (void (*)(void *))ipw_up, priv);
7900 INIT_WORK(&priv->down, (void (*)(void *))ipw_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04007901 INIT_WORK(&priv->request_scan,
James Ketrenos43f66a62005-03-25 12:31:53 -06007902 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04007903 INIT_WORK(&priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06007904 (void (*)(void *))ipw_gather_stats, priv);
7905 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_abort_scan, priv);
7906 INIT_WORK(&priv->roam, ipw_roam, priv);
7907 INIT_WORK(&priv->scan_check, ipw_scan_check, priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007908 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_link_up, priv);
7909 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_link_down, priv);
7910 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_led_link_on, priv);
7911 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_led_link_off,
7912 priv);
7913 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_led_activity_off,
7914 priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007915
7916 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
7917 ipw_irq_tasklet, (unsigned long)priv);
7918
7919 return ret;
7920}
7921
James Ketrenos43f66a62005-03-25 12:31:53 -06007922static void shim__set_security(struct net_device *dev,
7923 struct ieee80211_security *sec)
7924{
7925 struct ipw_priv *priv = ieee80211_priv(dev);
7926 int i;
7927
Jeff Garzikbf794512005-07-31 13:07:26 -04007928 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007929 if (sec->flags & (1 << i)) {
7930 priv->sec.key_sizes[i] = sec->key_sizes[i];
7931 if (sec->key_sizes[i] == 0)
7932 priv->sec.flags &= ~(1 << i);
7933 else
Jeff Garzikbf794512005-07-31 13:07:26 -04007934 memcpy(priv->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -06007935 sec->key_sizes[i]);
7936 priv->sec.flags |= (1 << i);
7937 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -04007938 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007939 }
7940
7941 if ((sec->flags & SEC_ACTIVE_KEY) &&
7942 priv->sec.active_key != sec->active_key) {
7943 if (sec->active_key <= 3) {
7944 priv->sec.active_key = sec->active_key;
7945 priv->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -04007946 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06007947 priv->sec.flags &= ~SEC_ACTIVE_KEY;
7948 priv->status |= STATUS_SECURITY_UPDATED;
7949 }
7950
7951 if ((sec->flags & SEC_AUTH_MODE) &&
7952 (priv->sec.auth_mode != sec->auth_mode)) {
7953 priv->sec.auth_mode = sec->auth_mode;
7954 priv->sec.flags |= SEC_AUTH_MODE;
7955 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
7956 priv->capability |= CAP_SHARED_KEY;
7957 else
7958 priv->capability &= ~CAP_SHARED_KEY;
7959 priv->status |= STATUS_SECURITY_UPDATED;
7960 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007961
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007962 if (sec->flags & SEC_ENABLED && priv->sec.enabled != sec->enabled) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007963 priv->sec.flags |= SEC_ENABLED;
7964 priv->sec.enabled = sec->enabled;
7965 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -04007966 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06007967 priv->capability |= CAP_PRIVACY_ON;
7968 else
7969 priv->capability &= ~CAP_PRIVACY_ON;
7970 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007971
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007972 if (sec->flags & SEC_LEVEL && priv->sec.level != sec->level) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007973 priv->sec.level = sec->level;
7974 priv->sec.flags |= SEC_LEVEL;
7975 priv->status |= STATUS_SECURITY_UPDATED;
7976 }
7977
Jeff Garzikbf794512005-07-31 13:07:26 -04007978 /* To match current functionality of ipw2100 (which works well w/
7979 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007980 * privacy capability changes ... */
7981#if 0
7982 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -04007983 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -06007984 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04007985 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007986 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007987 IPW_DEBUG_ASSOC("Disassociating due to capability "
7988 "change.\n");
7989 ipw_disassociate(priv);
7990 }
7991#endif
7992}
7993
Jeff Garzikbf794512005-07-31 13:07:26 -04007994static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06007995 struct ipw_supported_rates *rates)
7996{
7997 /* TODO: Mask out rates based on priv->rates_mask */
7998
7999 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008000 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -06008001 switch (priv->ieee->freq_band) {
8002 case IEEE80211_52GHZ_BAND:
8003 rates->ieee_mode = IPW_A_MODE;
8004 rates->purpose = IPW_RATE_CAPABILITIES;
8005 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
8006 IEEE80211_OFDM_DEFAULT_RATES_MASK);
8007 break;
8008
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008009 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -06008010 rates->ieee_mode = IPW_G_MODE;
8011 rates->purpose = IPW_RATE_CAPABILITIES;
8012 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
8013 IEEE80211_CCK_DEFAULT_RATES_MASK);
8014 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
8015 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
8016 IEEE80211_OFDM_DEFAULT_RATES_MASK);
8017 }
8018 break;
8019 }
8020
8021 return 0;
8022}
8023
Jeff Garzikbf794512005-07-31 13:07:26 -04008024static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06008025{
8026 int i;
8027 struct ipw_tx_power tx_power;
8028
8029 memset(&priv->sys_config, 0, sizeof(priv->sys_config));
8030 memset(&tx_power, 0, sizeof(tx_power));
8031
8032 /* This is only called from ipw_up, which resets/reloads the firmware
8033 so, we don't need to first disable the card before we configure
8034 it */
8035
8036 /* configure device for 'G' band */
8037 tx_power.ieee_mode = IPW_G_MODE;
8038 tx_power.num_channels = 11;
8039 for (i = 0; i < 11; i++) {
8040 tx_power.channels_tx_power[i].channel_number = i + 1;
8041 tx_power.channels_tx_power[i].tx_power = priv->tx_power;
8042 }
8043 if (ipw_send_tx_power(priv, &tx_power))
8044 goto error;
8045
8046 /* configure device to also handle 'B' band */
8047 tx_power.ieee_mode = IPW_B_MODE;
8048 if (ipw_send_tx_power(priv, &tx_power))
8049 goto error;
8050
8051 /* initialize adapter address */
8052 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
8053 goto error;
8054
8055 /* set basic system config settings */
8056 init_sys_config(&priv->sys_config);
8057 if (ipw_send_system_config(priv, &priv->sys_config))
8058 goto error;
8059
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008060 init_supported_rates(priv, &priv->rates);
8061 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -06008062 goto error;
8063
8064 /* Set request-to-send threshold */
8065 if (priv->rts_threshold) {
8066 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
8067 goto error;
8068 }
8069
8070 if (ipw_set_random_seed(priv))
8071 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -04008072
James Ketrenos43f66a62005-03-25 12:31:53 -06008073 /* final state transition to the RUN state */
8074 if (ipw_send_host_complete(priv))
8075 goto error;
8076
8077 /* If configured to try and auto-associate, kick off a scan */
8078 if ((priv->config & CFG_ASSOCIATE) && ipw_request_scan(priv))
8079 goto error;
8080
8081 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04008082
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008083 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06008084 return -EIO;
8085}
8086
8087#define MAX_HW_RESTARTS 5
8088static int ipw_up(struct ipw_priv *priv)
8089{
8090 int rc, i;
8091
8092 if (priv->status & STATUS_EXIT_PENDING)
8093 return -EIO;
8094
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008095 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -04008096 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -06008097 * Also start the clocks. */
8098 rc = ipw_load(priv);
8099 if (rc) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008100 IPW_ERROR("Unable to load firmware: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06008101 return rc;
8102 }
8103
8104 ipw_init_ordinals(priv);
8105 if (!(priv->config & CFG_CUSTOM_MAC))
8106 eeprom_parse_mac(priv, priv->mac_addr);
8107 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
8108
8109 if (priv->status & STATUS_RF_KILL_MASK)
8110 return 0;
8111
8112 rc = ipw_config(priv);
8113 if (!rc) {
8114 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosa613bff2005-08-24 21:43:11 -05008115 ipw_led_init(priv);
8116 ipw_led_radio_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008117 priv->notif_missed_beacons = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008118 return 0;
8119 } else {
8120 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n",
8121 rc);
8122 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008123
James Ketrenos43f66a62005-03-25 12:31:53 -06008124 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
8125 i, MAX_HW_RESTARTS);
8126
8127 /* We had an error bringing up the hardware, so take it
8128 * all the way back down so we can try again */
8129 ipw_down(priv);
8130 }
8131
Jeff Garzikbf794512005-07-31 13:07:26 -04008132 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -06008133 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008134 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenos43f66a62005-03-25 12:31:53 -06008135 return -EIO;
8136}
8137
8138static void ipw_down(struct ipw_priv *priv)
8139{
8140 /* Attempt to disable the card */
8141#if 0
8142 ipw_send_card_disable(priv, 0);
8143#endif
8144
8145 /* tell the device to stop sending interrupts */
8146 ipw_disable_interrupts(priv);
8147
8148 /* Clear all bits but the RF Kill */
8149 priv->status &= STATUS_RF_KILL_MASK;
8150
8151 netif_carrier_off(priv->net_dev);
8152 netif_stop_queue(priv->net_dev);
8153
8154 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05008155
8156 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008157}
8158
James Ketrenosea2b26e2005-08-24 21:25:16 -05008159static int ipw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
8160{
James Ketrenosea2b26e2005-08-24 21:25:16 -05008161 struct iwreq *wrq = (struct iwreq *)rq;
8162 int ret = -1;
8163 switch (cmd) {
8164 case IPW_IOCTL_WPA_SUPPLICANT:
8165 ret = ipw_wpa_supplicant(dev, &wrq->u.data);
8166 return ret;
8167
8168 default:
8169 return -EOPNOTSUPP;
8170 }
8171
James Ketrenosea2b26e2005-08-24 21:25:16 -05008172 return -EOPNOTSUPP;
8173}
8174
James Ketrenos43f66a62005-03-25 12:31:53 -06008175/* Called by register_netdev() */
8176static int ipw_net_init(struct net_device *dev)
8177{
8178 struct ipw_priv *priv = ieee80211_priv(dev);
8179
8180 if (priv->status & STATUS_RF_KILL_SW) {
8181 IPW_WARNING("Radio disabled by module parameter.\n");
8182 return 0;
8183 } else if (rf_kill_active(priv)) {
8184 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
8185 "Kill switch must be turned off for "
8186 "wireless networking to work.\n");
8187 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
8188 return 0;
8189 }
8190
8191 if (ipw_up(priv))
8192 return -EIO;
8193
8194 return 0;
8195}
8196
8197/* PCI driver stuff */
8198static struct pci_device_id card_ids[] = {
8199 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
8200 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
8201 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
8202 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
8203 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
8204 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
8205 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
8206 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
8207 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
8208 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
8209 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
8210 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
8211 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
8212 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
8213 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
8214 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
8215 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
8216 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008217 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
James Ketrenosa613bff2005-08-24 21:43:11 -05008218 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008219 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
8220 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -04008221
James Ketrenos43f66a62005-03-25 12:31:53 -06008222 /* required last entry */
8223 {0,}
8224};
8225
8226MODULE_DEVICE_TABLE(pci, card_ids);
8227
8228static struct attribute *ipw_sysfs_entries[] = {
8229 &dev_attr_rf_kill.attr,
8230 &dev_attr_direct_dword.attr,
8231 &dev_attr_indirect_byte.attr,
8232 &dev_attr_indirect_dword.attr,
8233 &dev_attr_mem_gpio_reg.attr,
8234 &dev_attr_command_event_reg.attr,
8235 &dev_attr_nic_type.attr,
8236 &dev_attr_status.attr,
8237 &dev_attr_cfg.attr,
8238 &dev_attr_dump_errors.attr,
8239 &dev_attr_dump_events.attr,
8240 &dev_attr_eeprom_delay.attr,
8241 &dev_attr_ucode_version.attr,
8242 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -05008243 &dev_attr_scan_age.attr,
8244 &dev_attr_led.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -06008245 NULL
8246};
8247
8248static struct attribute_group ipw_attribute_group = {
8249 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008250 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -06008251};
8252
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008253static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -06008254{
8255 int err = 0;
8256 struct net_device *net_dev;
8257 void __iomem *base;
8258 u32 length, val;
8259 struct ipw_priv *priv;
8260 int band, modulation;
8261
8262 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
8263 if (net_dev == NULL) {
8264 err = -ENOMEM;
8265 goto out;
8266 }
8267
8268 priv = ieee80211_priv(net_dev);
8269 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -05008270
James Ketrenos43f66a62005-03-25 12:31:53 -06008271 priv->net_dev = net_dev;
8272 priv->pci_dev = pdev;
8273#ifdef CONFIG_IPW_DEBUG
8274 ipw_debug_level = debug;
8275#endif
8276 spin_lock_init(&priv->lock);
8277
8278 if (pci_enable_device(pdev)) {
8279 err = -ENODEV;
8280 goto out_free_ieee80211;
8281 }
8282
8283 pci_set_master(pdev);
8284
Tobias Klauser0e08b442005-06-20 14:28:41 -07008285 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -04008286 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -07008287 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -06008288 if (err) {
8289 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
8290 goto out_pci_disable_device;
8291 }
8292
8293 pci_set_drvdata(pdev, priv);
8294
8295 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -04008296 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -06008297 goto out_pci_disable_device;
8298
Jeff Garzikbf794512005-07-31 13:07:26 -04008299 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -06008300 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -04008301 pci_read_config_dword(pdev, 0x40, &val);
8302 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06008303 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -04008304
James Ketrenos43f66a62005-03-25 12:31:53 -06008305 length = pci_resource_len(pdev, 0);
8306 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -04008307
James Ketrenos43f66a62005-03-25 12:31:53 -06008308 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
8309 if (!base) {
8310 err = -ENODEV;
8311 goto out_pci_release_regions;
8312 }
8313
8314 priv->hw_base = base;
8315 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
8316 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
8317
8318 err = ipw_setup_deferred_work(priv);
8319 if (err) {
8320 IPW_ERROR("Unable to setup deferred work\n");
8321 goto out_iounmap;
8322 }
8323
8324 /* Initialize module parameter values here */
James Ketrenosa613bff2005-08-24 21:43:11 -05008325
8326 /* We default to disabling the LED code as right now it causes
8327 * too many systems to lock up... */
8328 if (!led)
8329 priv->config |= CFG_NO_LED;
8330
Jeff Garzikbf794512005-07-31 13:07:26 -04008331 if (associate)
James Ketrenos43f66a62005-03-25 12:31:53 -06008332 priv->config |= CFG_ASSOCIATE;
8333 else
8334 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008335
8336 if (auto_create)
James Ketrenos43f66a62005-03-25 12:31:53 -06008337 priv->config |= CFG_ADHOC_CREATE;
8338 else
8339 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008340
James Ketrenos43f66a62005-03-25 12:31:53 -06008341 if (disable) {
8342 priv->status |= STATUS_RF_KILL_SW;
8343 IPW_DEBUG_INFO("Radio disabled.\n");
8344 }
8345
8346 if (channel != 0) {
8347 priv->config |= CFG_STATIC_CHANNEL;
8348 priv->channel = channel;
8349 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008350 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008351 /* TODO: Validate that provided channel is in range */
8352 }
8353
8354 switch (mode) {
8355 case 1:
8356 priv->ieee->iw_mode = IW_MODE_ADHOC;
8357 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05008358#ifdef CONFIG_IPW_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008359 case 2:
8360 priv->ieee->iw_mode = IW_MODE_MONITOR;
8361 break;
8362#endif
8363 default:
8364 case 0:
8365 priv->ieee->iw_mode = IW_MODE_INFRA;
8366 break;
8367 }
8368
8369 if ((priv->pci_dev->device == 0x4223) ||
8370 (priv->pci_dev->device == 0x4224)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04008371 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06008372 ": Detected Intel PRO/Wireless 2915ABG Network "
8373 "Connection\n");
James Ketrenosa33a1982005-09-14 14:28:59 -05008374 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008375 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8376 modulation = IEEE80211_OFDM_MODULATION |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008377 IEEE80211_CCK_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06008378 priv->adapter = IPW_2915ABG;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008379 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008380 } else {
James Ketrenosa613bff2005-08-24 21:43:11 -05008381 printk(KERN_INFO DRV_NAME
8382 ": Detected Intel PRO/Wireless 2200BG Network "
8383 "Connection\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008384
James Ketrenosa33a1982005-09-14 14:28:59 -05008385 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008386 band = IEEE80211_24GHZ_BAND;
8387 modulation = IEEE80211_OFDM_MODULATION |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008388 IEEE80211_CCK_MODULATION;
James Ketrenos43f66a62005-03-25 12:31:53 -06008389 priv->adapter = IPW_2200BG;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008390 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008391 }
8392
8393 priv->ieee->freq_band = band;
8394 priv->ieee->modulation = modulation;
8395
8396 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
8397
8398 priv->missed_beacon_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8399 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8400
8401 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8402
8403 /* If power management is turned on, default to AC mode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008404 priv->power_mode = IPW_POWER_AC;
James Ketrenos43f66a62005-03-25 12:31:53 -06008405 priv->tx_power = IPW_DEFAULT_TX_POWER;
8406
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008407 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008408 if (err) {
8409 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
8410 goto out_destroy_workqueue;
8411 }
8412
8413 SET_MODULE_OWNER(net_dev);
8414 SET_NETDEV_DEV(net_dev, &pdev->dev);
8415
James Ketrenosa613bff2005-08-24 21:43:11 -05008416 ipw_wx_data.spy_data = &priv->ieee->spy_data;
8417 ipw_wx_data.ieee80211 = priv->ieee;
8418
James Ketrenos43f66a62005-03-25 12:31:53 -06008419 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
8420 priv->ieee->set_security = shim__set_security;
8421
8422 net_dev->open = ipw_net_open;
8423 net_dev->stop = ipw_net_stop;
8424 net_dev->init = ipw_net_init;
James Ketrenosea2b26e2005-08-24 21:25:16 -05008425 net_dev->do_ioctl = ipw_ioctl;
James Ketrenos43f66a62005-03-25 12:31:53 -06008426 net_dev->get_stats = ipw_net_get_stats;
8427 net_dev->set_multicast_list = ipw_net_set_multicast_list;
8428 net_dev->set_mac_address = ipw_net_set_mac_address;
8429 net_dev->get_wireless_stats = ipw_get_wireless_stats;
James Ketrenosa613bff2005-08-24 21:43:11 -05008430 net_dev->wireless_data = &ipw_wx_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06008431 net_dev->wireless_handlers = &ipw_wx_handler_def;
8432 net_dev->ethtool_ops = &ipw_ethtool_ops;
8433 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008434 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -06008435 net_dev->mem_start = pci_resource_start(pdev, 0);
8436 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
8437
8438 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
8439 if (err) {
8440 IPW_ERROR("failed to create sysfs device attributes\n");
8441 goto out_release_irq;
8442 }
8443
8444 err = register_netdev(net_dev);
8445 if (err) {
8446 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05008447 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -06008448 }
8449
8450 return 0;
8451
James Ketrenosa613bff2005-08-24 21:43:11 -05008452 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -06008453 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008454 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -06008455 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008456 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -06008457 destroy_workqueue(priv->workqueue);
8458 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008459 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -06008460 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008461 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -06008462 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008463 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -06008464 pci_disable_device(pdev);
8465 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008466 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -06008467 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008468 out:
James Ketrenos43f66a62005-03-25 12:31:53 -06008469 return err;
8470}
8471
8472static void ipw_pci_remove(struct pci_dev *pdev)
8473{
8474 struct ipw_priv *priv = pci_get_drvdata(pdev);
8475 if (!priv)
8476 return;
8477
8478 priv->status |= STATUS_EXIT_PENDING;
8479
8480 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
8481
8482 ipw_down(priv);
8483
8484 unregister_netdev(priv->net_dev);
8485
8486 if (priv->rxq) {
8487 ipw_rx_queue_free(priv, priv->rxq);
8488 priv->rxq = NULL;
8489 }
8490 ipw_tx_queue_free(priv);
8491
James Ketrenosa613bff2005-08-24 21:43:11 -05008492 ipw_led_shutdown(priv);
8493
James Ketrenos43f66a62005-03-25 12:31:53 -06008494 /* ipw_down will ensure that there is no more pending work
8495 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -05008496 cancel_delayed_work(&priv->adhoc_check);
8497 cancel_delayed_work(&priv->gather_stats);
8498 cancel_delayed_work(&priv->request_scan);
8499 cancel_delayed_work(&priv->rf_kill);
8500 cancel_delayed_work(&priv->scan_check);
8501 destroy_workqueue(priv->workqueue);
8502 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008503
8504 free_irq(pdev->irq, priv);
8505 iounmap(priv->hw_base);
8506 pci_release_regions(pdev);
8507 pci_disable_device(pdev);
8508 pci_set_drvdata(pdev, NULL);
8509 free_ieee80211(priv->net_dev);
8510
8511#ifdef CONFIG_PM
8512 if (fw_loaded) {
8513 release_firmware(bootfw);
8514 release_firmware(ucode);
8515 release_firmware(firmware);
8516 fw_loaded = 0;
8517 }
8518#endif
8519}
8520
James Ketrenos43f66a62005-03-25 12:31:53 -06008521#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -07008522static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -06008523{
8524 struct ipw_priv *priv = pci_get_drvdata(pdev);
8525 struct net_device *dev = priv->net_dev;
8526
8527 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
8528
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008529 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -06008530 ipw_down(priv);
8531
8532 /* Remove the PRESENT state of the device */
8533 netif_device_detach(dev);
8534
James Ketrenos43f66a62005-03-25 12:31:53 -06008535 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008536 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -07008537 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -04008538
James Ketrenos43f66a62005-03-25 12:31:53 -06008539 return 0;
8540}
8541
8542static int ipw_pci_resume(struct pci_dev *pdev)
8543{
8544 struct ipw_priv *priv = pci_get_drvdata(pdev);
8545 struct net_device *dev = priv->net_dev;
8546 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -04008547
James Ketrenos43f66a62005-03-25 12:31:53 -06008548 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
8549
James Ketrenosea2b26e2005-08-24 21:25:16 -05008550 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -06008551 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -06008552 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008553
James Ketrenos43f66a62005-03-25 12:31:53 -06008554 /*
8555 * Suspend/Resume resets the PCI configuration space, so we have to
8556 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
8557 * from interfering with C3 CPU state. pci_restore_state won't help
8558 * here since it only restores the first 64 bytes pci config header.
8559 */
Jeff Garzikbf794512005-07-31 13:07:26 -04008560 pci_read_config_dword(pdev, 0x40, &val);
8561 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06008562 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
8563
8564 /* Set the device back into the PRESENT state; this will also wake
8565 * the queue of needed */
8566 netif_device_attach(dev);
8567
8568 /* Bring the device back up */
8569 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -04008570
James Ketrenos43f66a62005-03-25 12:31:53 -06008571 return 0;
8572}
8573#endif
8574
8575/* driver initialization stuff */
8576static struct pci_driver ipw_driver = {
8577 .name = DRV_NAME,
8578 .id_table = card_ids,
8579 .probe = ipw_pci_probe,
8580 .remove = __devexit_p(ipw_pci_remove),
8581#ifdef CONFIG_PM
8582 .suspend = ipw_pci_suspend,
8583 .resume = ipw_pci_resume,
8584#endif
8585};
8586
8587static int __init ipw_init(void)
8588{
8589 int ret;
8590
8591 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
8592 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
8593
8594 ret = pci_module_init(&ipw_driver);
8595 if (ret) {
8596 IPW_ERROR("Unable to initialize PCI module\n");
8597 return ret;
8598 }
8599
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008600 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -06008601 if (ret) {
8602 IPW_ERROR("Unable to create driver sysfs file\n");
8603 pci_unregister_driver(&ipw_driver);
8604 return ret;
8605 }
8606
8607 return ret;
8608}
8609
8610static void __exit ipw_exit(void)
8611{
8612 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
8613 pci_unregister_driver(&ipw_driver);
8614}
8615
8616module_param(disable, int, 0444);
8617MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
8618
8619module_param(associate, int, 0444);
8620MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
8621
8622module_param(auto_create, int, 0444);
8623MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
8624
James Ketrenosa613bff2005-08-24 21:43:11 -05008625module_param(led, int, 0444);
8626MODULE_PARM_DESC(auto_create,
8627 "enable led control on some systems (default 0 off)\n");
8628
James Ketrenos43f66a62005-03-25 12:31:53 -06008629module_param(debug, int, 0444);
8630MODULE_PARM_DESC(debug, "debug output mask");
8631
8632module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -04008633MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -06008634
James Ketrenosea2b26e2005-08-24 21:25:16 -05008635#ifdef CONFIG_IPW_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008636module_param(mode, int, 0444);
8637MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
8638#else
8639module_param(mode, int, 0444);
8640MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
8641#endif
8642
8643module_exit(ipw_exit);
8644module_init(ipw_init);