blob: a72f3e1e991bcd54410e4fa0bd992b5b1d7d3e7f [file] [log] [blame]
James Ketrenos43f66a62005-03-25 12:31:53 -06001/******************************************************************************
Jeff Garzikbf794512005-07-31 13:07:26 -04002
Zhu Yi171e7b22006-02-15 07:17:56 +08003 Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved.
James Ketrenos43f66a62005-03-25 12:31:53 -06004
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"
Olaf Hering733482e2005-11-08 21:34:55 -080034#include <linux/version.h>
James Ketrenos43f66a62005-03-25 12:31:53 -060035
Zhu Yiae4af612006-04-13 17:20:34 +080036
37#ifndef KBUILD_EXTMOD
38#define VK "k"
39#else
40#define VK
41#endif
42
43#ifdef CONFIG_IPW2200_DEBUG
44#define VD "d"
45#else
46#define VD
47#endif
48
49#ifdef CONFIG_IPW2200_MONITOR
50#define VM "m"
51#else
52#define VM
53#endif
54
55#ifdef CONFIG_IPW2200_PROMISCUOUS
56#define VP "p"
57#else
58#define VP
59#endif
60
Zhu Yi459d4082006-04-13 17:21:00 +080061#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yiae4af612006-04-13 17:20:34 +080062#define VR "r"
63#else
64#define VR
65#endif
66
67#ifdef CONFIG_IPW2200_QOS
68#define VQ "q"
69#else
70#define VQ
71#endif
72
Zhu Yi555fd912006-04-13 17:20:40 +080073#define IPW2200_VERSION "1.1.2" VK VD VM VP VR VQ
James Ketrenos43f66a62005-03-25 12:31:53 -060074#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
Zhu Yi171e7b22006-02-15 07:17:56 +080075#define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
James Ketrenos43f66a62005-03-25 12:31:53 -060076#define DRV_VERSION IPW2200_VERSION
77
James Ketrenosb095c382005-08-24 22:04:42 -050078#define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
79
James Ketrenos43f66a62005-03-25 12:31:53 -060080MODULE_DESCRIPTION(DRV_DESCRIPTION);
81MODULE_VERSION(DRV_VERSION);
82MODULE_AUTHOR(DRV_COPYRIGHT);
83MODULE_LICENSE("GPL");
84
James Ketrenosf6c5cb72005-08-25 00:39:09 -050085static int cmdlog = 0;
Zhu Yi5dc81c32006-04-13 17:19:44 +080086#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060087static int debug = 0;
Zhu Yi5dc81c32006-04-13 17:19:44 +080088#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060089static int channel = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060090static int mode = 0;
91
92static u32 ipw_debug_level;
93static int associate = 1;
94static int auto_create = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -050095static int led = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060096static int disable = 0;
Zhu Yi810dabd2006-01-24 16:36:59 +080097static int bt_coexist = 0;
Zhu Yibde37d02006-01-24 16:38:08 +080098static int hwcrypto = 0;
Zhu Yi4bfdb912006-01-24 16:37:16 +080099static int roaming = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -0600100static const char ipw_modes[] = {
101 'a', 'b', 'g', '?'
102};
Zhu Yid2b83e12006-04-13 17:19:36 +0800103static int antenna = CFG_SYS_ANTENNA_BOTH;
James Ketrenos43f66a62005-03-25 12:31:53 -0600104
Zhu Yid685b8c2006-04-13 17:20:27 +0800105#ifdef CONFIG_IPW2200_PROMISCUOUS
106static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */
107#endif
108
109
Zhu Yie43e3c12006-04-13 17:20:45 +0800110#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -0500111static int qos_enable = 0;
112static int qos_burst_enable = 0;
113static int qos_no_ack_mask = 0;
114static int burst_duration_CCK = 0;
115static int burst_duration_OFDM = 0;
116
117static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
118 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
119 QOS_TX3_CW_MIN_OFDM},
120 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
121 QOS_TX3_CW_MAX_OFDM},
122 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
123 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
124 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
125 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
126};
127
128static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
129 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
130 QOS_TX3_CW_MIN_CCK},
131 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
132 QOS_TX3_CW_MAX_CCK},
133 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
134 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
135 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
136 QOS_TX3_TXOP_LIMIT_CCK}
137};
138
139static struct ieee80211_qos_parameters def_parameters_OFDM = {
140 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
141 DEF_TX3_CW_MIN_OFDM},
142 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
143 DEF_TX3_CW_MAX_OFDM},
144 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
145 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
146 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
147 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
148};
149
150static struct ieee80211_qos_parameters def_parameters_CCK = {
151 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
152 DEF_TX3_CW_MIN_CCK},
153 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
154 DEF_TX3_CW_MAX_CCK},
155 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
156 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
157 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
158 DEF_TX3_TXOP_LIMIT_CCK}
159};
160
161static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
162
163static int from_priority_to_tx_queue[] = {
164 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
165 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
166};
167
168static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
169
170static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
171 *qos_param);
172static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
173 *qos_param);
Zhu Yie43e3c12006-04-13 17:20:45 +0800174#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -0500175
Benoit Boissinot97a78ca2005-09-15 17:30:28 +0000176static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
James Ketrenosb095c382005-08-24 22:04:42 -0500177static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600178static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400179static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600180 struct clx2_tx_queue *txq, int qindex);
181static int ipw_queue_reset(struct ipw_priv *priv);
182
183static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
184 int len, int sync);
185
186static void ipw_tx_queue_free(struct ipw_priv *);
187
188static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
189static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
190static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600191static int ipw_up(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500192static void ipw_bg_up(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600193static void ipw_down(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500194static void ipw_bg_down(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600195static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400196static int init_supported_rates(struct ipw_priv *priv,
197 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500198static void ipw_set_hwcrypto_keys(struct ipw_priv *);
199static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600200
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500201static int snprint_line(char *buf, size_t count,
202 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600203{
204 int out, i, j, l;
205 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400206
James Ketrenos43f66a62005-03-25 12:31:53 -0600207 out = snprintf(buf, count, "%08X", ofs);
208
209 for (l = 0, i = 0; i < 2; i++) {
210 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400211 for (j = 0; j < 8 && l < len; j++, l++)
212 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600213 data[(i * 8 + j)]);
214 for (; j < 8; j++)
215 out += snprintf(buf + out, count - out, " ");
216 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400217
James Ketrenos43f66a62005-03-25 12:31:53 -0600218 out += snprintf(buf + out, count - out, " ");
219 for (l = 0, i = 0; i < 2; i++) {
220 out += snprintf(buf + out, count - out, " ");
221 for (j = 0; j < 8 && l < len; j++, l++) {
222 c = data[(i * 8 + j)];
223 if (!isascii(c) || !isprint(c))
224 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400225
James Ketrenos43f66a62005-03-25 12:31:53 -0600226 out += snprintf(buf + out, count - out, "%c", c);
227 }
228
229 for (; j < 8; j++)
230 out += snprintf(buf + out, count - out, " ");
231 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400232
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500233 return out;
James Ketrenos43f66a62005-03-25 12:31:53 -0600234}
235
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400236static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600237{
238 char line[81];
239 u32 ofs = 0;
240 if (!(ipw_debug_level & level))
241 return;
242
243 while (len) {
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500244 snprint_line(line, sizeof(line), &data[ofs],
245 min(len, 16U), ofs);
246 printk(KERN_DEBUG "%s\n", line);
James Ketrenos43f66a62005-03-25 12:31:53 -0600247 ofs += 16;
248 len -= min(len, 16U);
249 }
250}
251
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500252static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
253{
254 size_t out = size;
255 u32 ofs = 0;
256 int total = 0;
257
258 while (size && len) {
259 out = snprint_line(output, size, &data[ofs],
260 min_t(size_t, len, 16U), ofs);
261
262 ofs += 16;
263 output += out;
264 size -= out;
265 len -= min_t(size_t, len, 16U);
266 total += out;
267 }
268 return total;
269}
270
Zhu Yic8fe6672006-01-24 16:36:36 +0800271/* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600272static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
273#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
274
Zhu Yic8fe6672006-01-24 16:36:36 +0800275/* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600276static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
277#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
278
Zhu Yic8fe6672006-01-24 16:36:36 +0800279/* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600280static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
281static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
282{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400283 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
284 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600285 _ipw_write_reg8(a, b, c);
286}
287
Zhu Yic8fe6672006-01-24 16:36:36 +0800288/* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600289static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
290static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
291{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400292 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
293 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600294 _ipw_write_reg16(a, b, c);
295}
296
Zhu Yic8fe6672006-01-24 16:36:36 +0800297/* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600298static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
299static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
300{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400301 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
302 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600303 _ipw_write_reg32(a, b, c);
304}
305
Zhu Yic8fe6672006-01-24 16:36:36 +0800306/* 8-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600307#define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800308
309/* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600310#define ipw_write8(ipw, ofs, val) \
311 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
312 _ipw_write8(ipw, ofs, val)
313
Zhu Yic8fe6672006-01-24 16:36:36 +0800314/* 16-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600315#define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800316
317/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600318#define ipw_write16(ipw, ofs, val) \
319 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
320 _ipw_write16(ipw, ofs, val)
321
Zhu Yic8fe6672006-01-24 16:36:36 +0800322/* 32-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600323#define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800324
325/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600326#define ipw_write32(ipw, ofs, val) \
327 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
328 _ipw_write32(ipw, ofs, val)
329
Zhu Yic8fe6672006-01-24 16:36:36 +0800330/* 8-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600331#define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800332
333/* 8-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400334static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
335{
336 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600337 return _ipw_read8(ipw, ofs);
338}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400339
Zhu Yic8fe6672006-01-24 16:36:36 +0800340/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600341#define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
342
Zhu Yic8fe6672006-01-24 16:36:36 +0800343/* 16-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600344#define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800345
346/* 16-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400347static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
348{
349 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600350 return _ipw_read16(ipw, ofs);
351}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400352
Zhu Yic8fe6672006-01-24 16:36:36 +0800353/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600354#define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
355
Zhu Yic8fe6672006-01-24 16:36:36 +0800356/* 32-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600357#define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800358
359/* 32-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400360static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
361{
362 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600363 return _ipw_read32(ipw, ofs);
364}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400365
Zhu Yic8fe6672006-01-24 16:36:36 +0800366/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600367#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
368
Zhu Yic8fe6672006-01-24 16:36:36 +0800369/* multi-byte read (above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600370static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500371static inline void __ipw_read_indirect(const char *f, int l,
372 struct ipw_priv *a, u32 b, u8 * c, int d)
373{
374 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
375 d);
376 _ipw_read_indirect(a, b, c, d);
377}
378
Zhu Yic8fe6672006-01-24 16:36:36 +0800379/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500380#define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600381
Zhu Yic8fe6672006-01-24 16:36:36 +0800382/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400383static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
384 int num);
James Ketrenos43f66a62005-03-25 12:31:53 -0600385#define ipw_write_indirect(a, b, c, d) \
386 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
James Ketrenosafbf30a2005-08-25 00:05:33 -0500387 _ipw_write_indirect(a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600388
Zhu Yic8fe6672006-01-24 16:36:36 +0800389/* 32-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400390static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600391{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400392 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500393 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
394 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600395}
396
Zhu Yic8fe6672006-01-24 16:36:36 +0800397/* 8-bit indirect write (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600398static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
399{
Zhu Yi2638bc32006-01-24 16:37:52 +0800400 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800401 u32 dif_len = reg - aligned_addr;
402
James Ketrenos43f66a62005-03-25 12:31:53 -0600403 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800404 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
405 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600406}
407
Zhu Yic8fe6672006-01-24 16:36:36 +0800408/* 16-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400409static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600410{
Zhu Yi2638bc32006-01-24 16:37:52 +0800411 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800412 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
413
James Ketrenos43f66a62005-03-25 12:31:53 -0600414 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800415 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
416 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600417}
418
Zhu Yic8fe6672006-01-24 16:36:36 +0800419/* 8-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600420static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
421{
422 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500423 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -0600424 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500425 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400426 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600427}
428
Zhu Yic8fe6672006-01-24 16:36:36 +0800429/* 32-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600430static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
431{
432 u32 value;
433
434 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
435
James Ketrenosb095c382005-08-24 22:04:42 -0500436 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
437 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
James Ketrenos43f66a62005-03-25 12:31:53 -0600438 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
439 return value;
440}
441
Zhu Yic8fe6672006-01-24 16:36:36 +0800442/* General purpose, no alignment requirement, iterative (multi-byte) read, */
443/* for area above 1st 4K of SRAM/reg space */
James Ketrenos43f66a62005-03-25 12:31:53 -0600444static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
445 int num)
446{
Zhu Yi2638bc32006-01-24 16:37:52 +0800447 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600448 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600449 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400450
James Ketrenos43f66a62005-03-25 12:31:53 -0600451 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
452
James Ketrenosea2b26e2005-08-24 21:25:16 -0500453 if (num <= 0) {
454 return;
455 }
456
Zhu Yic8fe6672006-01-24 16:36:36 +0800457 /* Read the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600458 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500459 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600460 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500461 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500462 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600463 aligned_addr += 4;
464 }
465
Zhu Yic8fe6672006-01-24 16:36:36 +0800466 /* Read all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500467 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500468 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500469 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400470
Zhu Yic8fe6672006-01-24 16:36:36 +0800471 /* Read the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500472 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500473 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500474 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500475 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500476 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600477}
478
Zhu Yic8fe6672006-01-24 16:36:36 +0800479/* General purpose, no alignment requirement, iterative (multi-byte) write, */
480/* for area above 1st 4K of SRAM/reg space */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400481static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600482 int num)
483{
Zhu Yi2638bc32006-01-24 16:37:52 +0800484 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600485 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600486 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400487
James Ketrenos43f66a62005-03-25 12:31:53 -0600488 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400489
James Ketrenosea2b26e2005-08-24 21:25:16 -0500490 if (num <= 0) {
491 return;
492 }
493
Zhu Yic8fe6672006-01-24 16:36:36 +0800494 /* Write the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600495 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500496 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
Zhu Yic8fe6672006-01-24 16:36:36 +0800497 /* Start writing at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500498 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500499 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600500 aligned_addr += 4;
501 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400502
Zhu Yic8fe6672006-01-24 16:36:36 +0800503 /* Write all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500504 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500505 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500506 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400507
Zhu Yic8fe6672006-01-24 16:36:36 +0800508 /* Write the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500509 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500510 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500511 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500512 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500513 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600514}
515
Zhu Yic8fe6672006-01-24 16:36:36 +0800516/* General purpose, no alignment requirement, iterative (multi-byte) write, */
517/* for 1st 4K of SRAM/regs space */
Jeff Garzikbf794512005-07-31 13:07:26 -0400518static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600519 int num)
520{
521 memcpy_toio((priv->hw_base + addr), buf, num);
522}
523
Zhu Yic8fe6672006-01-24 16:36:36 +0800524/* Set bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600525static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
526{
527 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
528}
529
Zhu Yic8fe6672006-01-24 16:36:36 +0800530/* Clear bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600531static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
532{
533 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
534}
535
Zhu Yi89c318e2006-06-08 22:19:49 -0700536static inline void __ipw_enable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600537{
538 if (priv->status & STATUS_INT_ENABLED)
539 return;
540 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500541 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600542}
543
Zhu Yi89c318e2006-06-08 22:19:49 -0700544static inline void __ipw_disable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600545{
546 if (!(priv->status & STATUS_INT_ENABLED))
547 return;
548 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500549 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600550}
551
Zhu Yi89c318e2006-06-08 22:19:49 -0700552static inline void ipw_enable_interrupts(struct ipw_priv *priv)
553{
554 unsigned long flags;
555
556 spin_lock_irqsave(&priv->irq_lock, flags);
557 __ipw_enable_interrupts(priv);
558 spin_unlock_irqrestore(&priv->irq_lock, flags);
559}
560
561static inline void ipw_disable_interrupts(struct ipw_priv *priv)
562{
563 unsigned long flags;
564
565 spin_lock_irqsave(&priv->irq_lock, flags);
566 __ipw_disable_interrupts(priv);
567 spin_unlock_irqrestore(&priv->irq_lock, flags);
568}
569
Brice Goglin0f52bf92005-12-01 01:41:46 -0800570#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -0600571static char *ipw_error_desc(u32 val)
572{
573 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400574 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600575 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400576 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600577 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400578 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600579 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400580 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600581 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400582 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500583 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400584 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500585 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400586 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500587 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400588 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500589 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400590 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500591 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400592 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500593 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400594 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500595 return "DMA_STATUS";
596 case IPW_FW_ERROR_DINO_ERROR:
597 return "DINO_ERROR";
598 case IPW_FW_ERROR_EEPROM_ERROR:
599 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400600 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500601 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400602 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500603 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400604 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500605 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600606 }
607}
608
James Ketrenosb39860c2005-08-12 09:36:32 -0500609static void ipw_dump_error_log(struct ipw_priv *priv,
610 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600611{
James Ketrenosb39860c2005-08-12 09:36:32 -0500612 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600613
James Ketrenosb39860c2005-08-12 09:36:32 -0500614 if (!error) {
615 IPW_ERROR("Error allocating and capturing error log. "
616 "Nothing to dump.\n");
617 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600618 }
619
James Ketrenosb39860c2005-08-12 09:36:32 -0500620 IPW_ERROR("Start IPW Error Log Dump:\n");
621 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
622 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600623
James Ketrenosb39860c2005-08-12 09:36:32 -0500624 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400625 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500626 ipw_error_desc(error->elem[i].desc),
627 error->elem[i].time,
628 error->elem[i].blink1,
629 error->elem[i].blink2,
630 error->elem[i].link1,
631 error->elem[i].link2, error->elem[i].data);
632 for (i = 0; i < error->log_len; i++)
633 IPW_ERROR("%i\t0x%08x\t%i\n",
634 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500635 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600636}
James Ketrenos43f66a62005-03-25 12:31:53 -0600637#endif
James Ketrenos43f66a62005-03-25 12:31:53 -0600638
James Ketrenosc848d0a2005-08-24 21:56:24 -0500639static inline int ipw_is_init(struct ipw_priv *priv)
640{
641 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600642}
643
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400644static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600645{
646 u32 addr, field_info, field_len, field_count, total_len;
647
648 IPW_DEBUG_ORD("ordinal = %i\n", ord);
649
650 if (!priv || !val || !len) {
651 IPW_DEBUG_ORD("Invalid argument\n");
652 return -EINVAL;
653 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400654
James Ketrenos43f66a62005-03-25 12:31:53 -0600655 /* verify device ordinal tables have been initialized */
656 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
657 IPW_DEBUG_ORD("Access ordinals before initialization\n");
658 return -EINVAL;
659 }
660
661 switch (IPW_ORD_TABLE_ID_MASK & ord) {
662 case IPW_ORD_TABLE_0_MASK:
663 /*
664 * TABLE 0: Direct access to a table of 32 bit values
665 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400666 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600667 * read from the table
668 */
669
670 /* remove the table id from the ordinal */
671 ord &= IPW_ORD_TABLE_VALUE_MASK;
672
673 /* boundary check */
674 if (ord > priv->table0_len) {
675 IPW_DEBUG_ORD("ordinal value (%i) longer then "
676 "max (%i)\n", ord, priv->table0_len);
677 return -EINVAL;
678 }
679
680 /* verify we have enough room to store the value */
681 if (*len < sizeof(u32)) {
682 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200683 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600684 return -EINVAL;
685 }
686
687 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400688 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600689
690 *len = sizeof(u32);
691 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400692 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600693 break;
694
695 case IPW_ORD_TABLE_1_MASK:
696 /*
697 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400698 *
699 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600700 * representing starting addr for the data (which is
701 * also a u32)
702 */
703
704 /* remove the table id from the ordinal */
705 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400706
James Ketrenos43f66a62005-03-25 12:31:53 -0600707 /* boundary check */
708 if (ord > priv->table1_len) {
709 IPW_DEBUG_ORD("ordinal value too long\n");
710 return -EINVAL;
711 }
712
713 /* verify we have enough room to store the value */
714 if (*len < sizeof(u32)) {
715 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200716 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600717 return -EINVAL;
718 }
719
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400720 *((u32 *) val) =
721 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600722 *len = sizeof(u32);
723 break;
724
725 case IPW_ORD_TABLE_2_MASK:
726 /*
727 * TABLE 2: Indirect access to a table of variable sized values
728 *
729 * This table consist of six values, each containing
730 * - dword containing the starting offset of the data
731 * - dword containing the lengh in the first 16bits
732 * and the count in the second 16bits
733 */
734
735 /* remove the table id from the ordinal */
736 ord &= IPW_ORD_TABLE_VALUE_MASK;
737
738 /* boundary check */
739 if (ord > priv->table2_len) {
740 IPW_DEBUG_ORD("ordinal value too long\n");
741 return -EINVAL;
742 }
743
744 /* get the address of statistic */
745 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400746
747 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600748 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400749 field_info =
750 ipw_read_reg32(priv,
751 priv->table2_addr + (ord << 3) +
752 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400753
James Ketrenos43f66a62005-03-25 12:31:53 -0600754 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400755 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400756
James Ketrenos43f66a62005-03-25 12:31:53 -0600757 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400758 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400759
James Ketrenos43f66a62005-03-25 12:31:53 -0600760 /* abort if not enought memory */
761 total_len = field_len * field_count;
762 if (total_len > *len) {
763 *len = total_len;
764 return -EINVAL;
765 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400766
James Ketrenos43f66a62005-03-25 12:31:53 -0600767 *len = total_len;
768 if (!total_len)
769 return 0;
770
771 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400772 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600773 addr, total_len, field_info);
774 ipw_read_indirect(priv, addr, val, total_len);
775 break;
776
777 default:
778 IPW_DEBUG_ORD("Invalid ordinal!\n");
779 return -EINVAL;
780
781 }
782
James Ketrenos43f66a62005-03-25 12:31:53 -0600783 return 0;
784}
785
786static void ipw_init_ordinals(struct ipw_priv *priv)
787{
788 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400789 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600790
791 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
792 priv->table0_addr, priv->table0_len);
793
794 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
795 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
796
797 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
798 priv->table1_addr, priv->table1_len);
799
800 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
801 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400802 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600803
804 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
805 priv->table2_addr, priv->table2_len);
806
807}
808
Adrian Bunka73e22b2006-01-21 01:39:42 +0100809static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500810{
James Ketrenosb095c382005-08-24 22:04:42 -0500811 reg &= ~IPW_START_STANDBY;
812 if (reg & IPW_GATE_ODMA)
813 reg &= ~IPW_GATE_ODMA;
814 if (reg & IPW_GATE_IDMA)
815 reg &= ~IPW_GATE_IDMA;
816 if (reg & IPW_GATE_ADMA)
817 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500818 return reg;
819}
820
821/*
822 * LED behavior:
823 * - On radio ON, turn on any LEDs that require to be on during start
824 * - On initialization, start unassociated blink
825 * - On association, disable unassociated blink
826 * - On disassociation, start unassociated blink
827 * - On radio OFF, turn off any LEDs started during radio on
828 *
829 */
Zhu Yiede61112006-01-24 16:37:10 +0800830#define LD_TIME_LINK_ON msecs_to_jiffies(300)
831#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
832#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500833
Adrian Bunka73e22b2006-01-21 01:39:42 +0100834static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500835{
836 unsigned long flags;
837 u32 led;
838
839 /* If configured to not use LEDs, or nic_type is 1,
840 * then we don't toggle a LINK led */
841 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
842 return;
843
844 spin_lock_irqsave(&priv->lock, flags);
845
846 if (!(priv->status & STATUS_RF_KILL_MASK) &&
847 !(priv->status & STATUS_LED_LINK_ON)) {
848 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500849 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500850 led |= priv->led_association_on;
851
852 led = ipw_register_toggle(led);
853
854 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500855 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500856
857 priv->status |= STATUS_LED_LINK_ON;
858
859 /* If we aren't associated, schedule turning the LED off */
860 if (!(priv->status & STATUS_ASSOCIATED))
861 queue_delayed_work(priv->workqueue,
862 &priv->led_link_off,
863 LD_TIME_LINK_ON);
864 }
865
866 spin_unlock_irqrestore(&priv->lock, flags);
867}
868
James Ketrenosc848d0a2005-08-24 21:56:24 -0500869static void ipw_bg_led_link_on(void *data)
870{
871 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800872 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500873 ipw_led_link_on(data);
Zhu Yi46441512006-01-24 16:37:59 +0800874 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500875}
876
Adrian Bunka73e22b2006-01-21 01:39:42 +0100877static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500878{
879 unsigned long flags;
880 u32 led;
881
882 /* If configured not to use LEDs, or nic type is 1,
883 * then we don't goggle the LINK led. */
884 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
885 return;
886
887 spin_lock_irqsave(&priv->lock, flags);
888
889 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500890 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500891 led &= priv->led_association_off;
892 led = ipw_register_toggle(led);
893
894 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500895 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500896
897 IPW_DEBUG_LED("Link LED Off\n");
898
899 priv->status &= ~STATUS_LED_LINK_ON;
900
901 /* If we aren't associated and the radio is on, schedule
902 * turning the LED on (blink while unassociated) */
903 if (!(priv->status & STATUS_RF_KILL_MASK) &&
904 !(priv->status & STATUS_ASSOCIATED))
905 queue_delayed_work(priv->workqueue, &priv->led_link_on,
906 LD_TIME_LINK_OFF);
907
908 }
909
910 spin_unlock_irqrestore(&priv->lock, flags);
911}
912
James Ketrenosc848d0a2005-08-24 21:56:24 -0500913static void ipw_bg_led_link_off(void *data)
914{
915 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800916 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500917 ipw_led_link_off(data);
Zhu Yi46441512006-01-24 16:37:59 +0800918 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500919}
920
Arjan van de Ven858119e2006-01-14 13:20:43 -0800921static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500922{
James Ketrenosa613bff2005-08-24 21:43:11 -0500923 u32 led;
924
925 if (priv->config & CFG_NO_LED)
926 return;
927
James Ketrenosb095c382005-08-24 22:04:42 -0500928 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500929 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500930
931 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500932 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500933 led |= priv->led_activity_on;
934
935 led = ipw_register_toggle(led);
936
937 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500938 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500939
940 IPW_DEBUG_LED("Activity LED On\n");
941
942 priv->status |= STATUS_LED_ACT_ON;
943
James Ketrenosc848d0a2005-08-24 21:56:24 -0500944 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500945 queue_delayed_work(priv->workqueue, &priv->led_act_off,
946 LD_TIME_ACT_ON);
947 } else {
948 /* Reschedule LED off for full time period */
949 cancel_delayed_work(&priv->led_act_off);
950 queue_delayed_work(priv->workqueue, &priv->led_act_off,
951 LD_TIME_ACT_ON);
952 }
James Ketrenosb095c382005-08-24 22:04:42 -0500953}
James Ketrenosa613bff2005-08-24 21:43:11 -0500954
Adrian Bunka73e22b2006-01-21 01:39:42 +0100955#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500956void ipw_led_activity_on(struct ipw_priv *priv)
957{
958 unsigned long flags;
959 spin_lock_irqsave(&priv->lock, flags);
960 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500961 spin_unlock_irqrestore(&priv->lock, flags);
962}
Adrian Bunka73e22b2006-01-21 01:39:42 +0100963#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -0500964
Adrian Bunka73e22b2006-01-21 01:39:42 +0100965static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500966{
967 unsigned long flags;
968 u32 led;
969
970 if (priv->config & CFG_NO_LED)
971 return;
972
973 spin_lock_irqsave(&priv->lock, flags);
974
975 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500976 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500977 led &= priv->led_activity_off;
978
979 led = ipw_register_toggle(led);
980
981 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500982 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500983
984 IPW_DEBUG_LED("Activity LED Off\n");
985
986 priv->status &= ~STATUS_LED_ACT_ON;
987 }
988
989 spin_unlock_irqrestore(&priv->lock, flags);
990}
991
James Ketrenosc848d0a2005-08-24 21:56:24 -0500992static void ipw_bg_led_activity_off(void *data)
993{
994 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800995 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500996 ipw_led_activity_off(data);
Zhu Yi46441512006-01-24 16:37:59 +0800997 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500998}
999
Adrian Bunka73e22b2006-01-21 01:39:42 +01001000static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001001{
1002 unsigned long flags;
1003 u32 led;
1004
1005 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -05001006 if (priv->config & CFG_NO_LED ||
1007 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -05001008 return;
1009
1010 spin_lock_irqsave(&priv->lock, flags);
1011
James Ketrenosb095c382005-08-24 22:04:42 -05001012 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001013 if (priv->assoc_network->mode == IEEE_A) {
1014 led |= priv->led_ofdm_on;
1015 led &= priv->led_association_off;
1016 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
1017 } else if (priv->assoc_network->mode == IEEE_G) {
1018 led |= priv->led_ofdm_on;
1019 led |= priv->led_association_on;
1020 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
1021 } else {
1022 led &= priv->led_ofdm_off;
1023 led |= priv->led_association_on;
1024 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
1025 }
1026
1027 led = ipw_register_toggle(led);
1028
1029 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001030 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001031
1032 spin_unlock_irqrestore(&priv->lock, flags);
1033}
1034
Adrian Bunka73e22b2006-01-21 01:39:42 +01001035static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001036{
1037 unsigned long flags;
1038 u32 led;
1039
1040 /* Only nic type 1 supports mode LEDs */
1041 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
1042 return;
1043
1044 spin_lock_irqsave(&priv->lock, flags);
1045
James Ketrenosb095c382005-08-24 22:04:42 -05001046 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001047 led &= priv->led_ofdm_off;
1048 led &= priv->led_association_off;
1049
1050 led = ipw_register_toggle(led);
1051
1052 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001053 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001054
1055 spin_unlock_irqrestore(&priv->lock, flags);
1056}
1057
Adrian Bunka73e22b2006-01-21 01:39:42 +01001058static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001059{
1060 ipw_led_link_on(priv);
1061}
1062
Adrian Bunka73e22b2006-01-21 01:39:42 +01001063static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001064{
1065 ipw_led_activity_off(priv);
1066 ipw_led_link_off(priv);
1067}
1068
Adrian Bunka73e22b2006-01-21 01:39:42 +01001069static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001070{
1071 /* Set the Link Led on for all nic types */
1072 ipw_led_link_on(priv);
1073}
1074
Adrian Bunka73e22b2006-01-21 01:39:42 +01001075static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001076{
1077 ipw_led_activity_off(priv);
1078 ipw_led_link_off(priv);
1079
1080 if (priv->status & STATUS_RF_KILL_MASK)
1081 ipw_led_radio_off(priv);
1082}
1083
Adrian Bunka73e22b2006-01-21 01:39:42 +01001084static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001085{
1086 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1087
1088 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001089 priv->led_activity_on = IPW_ACTIVITY_LED;
1090 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001091
James Ketrenosb095c382005-08-24 22:04:42 -05001092 priv->led_association_on = IPW_ASSOCIATED_LED;
1093 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001094
1095 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001096 priv->led_ofdm_on = IPW_OFDM_LED;
1097 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001098
1099 switch (priv->nic_type) {
1100 case EEPROM_NIC_TYPE_1:
1101 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001102 priv->led_activity_on = IPW_ASSOCIATED_LED;
1103 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1104 priv->led_association_on = IPW_ACTIVITY_LED;
1105 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001106
1107 if (!(priv->config & CFG_NO_LED))
1108 ipw_led_band_on(priv);
1109
1110 /* And we don't blink link LEDs for this nic, so
1111 * just return here */
1112 return;
1113
1114 case EEPROM_NIC_TYPE_3:
1115 case EEPROM_NIC_TYPE_2:
1116 case EEPROM_NIC_TYPE_4:
1117 case EEPROM_NIC_TYPE_0:
1118 break;
1119
1120 default:
1121 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1122 priv->nic_type);
1123 priv->nic_type = EEPROM_NIC_TYPE_0;
1124 break;
1125 }
1126
1127 if (!(priv->config & CFG_NO_LED)) {
1128 if (priv->status & STATUS_ASSOCIATED)
1129 ipw_led_link_on(priv);
1130 else
1131 ipw_led_link_off(priv);
1132 }
1133}
1134
Adrian Bunka73e22b2006-01-21 01:39:42 +01001135static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001136{
James Ketrenosa613bff2005-08-24 21:43:11 -05001137 ipw_led_activity_off(priv);
1138 ipw_led_link_off(priv);
1139 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001140 cancel_delayed_work(&priv->led_link_on);
1141 cancel_delayed_work(&priv->led_link_off);
1142 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001143}
1144
James Ketrenos43f66a62005-03-25 12:31:53 -06001145/*
1146 * The following adds a new attribute to the sysfs representation
1147 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1148 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001149 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001150 * See the level definitions in ipw for details.
1151 */
1152static ssize_t show_debug_level(struct device_driver *d, char *buf)
1153{
1154 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1155}
James Ketrenosa613bff2005-08-24 21:43:11 -05001156
1157static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1158 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001159{
1160 char *p = (char *)buf;
1161 u32 val;
1162
1163 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1164 p++;
1165 if (p[0] == 'x' || p[0] == 'X')
1166 p++;
1167 val = simple_strtoul(p, &p, 16);
1168 } else
1169 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001170 if (p == buf)
1171 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001172 ": %s is not in hex or decimal form.\n", buf);
1173 else
1174 ipw_debug_level = val;
1175
1176 return strnlen(buf, count);
1177}
1178
Jeff Garzikbf794512005-07-31 13:07:26 -04001179static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001180 show_debug_level, store_debug_level);
1181
James Ketrenosb39860c2005-08-12 09:36:32 -05001182static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1183{
Zhu Yic8fe6672006-01-24 16:36:36 +08001184 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001185 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1186}
1187
1188static void ipw_capture_event_log(struct ipw_priv *priv,
1189 u32 log_len, struct ipw_event *log)
1190{
1191 u32 base;
1192
1193 if (log_len) {
1194 base = ipw_read32(priv, IPW_EVENT_LOG);
1195 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1196 (u8 *) log, sizeof(*log) * log_len);
1197 }
1198}
1199
1200static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1201{
1202 struct ipw_fw_error *error;
1203 u32 log_len = ipw_get_event_log_len(priv);
1204 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1205 u32 elem_len = ipw_read_reg32(priv, base);
1206
1207 error = kmalloc(sizeof(*error) +
1208 sizeof(*error->elem) * elem_len +
1209 sizeof(*error->log) * log_len, GFP_ATOMIC);
1210 if (!error) {
1211 IPW_ERROR("Memory allocation for firmware error log "
1212 "failed.\n");
1213 return NULL;
1214 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001215 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001216 error->status = priv->status;
1217 error->config = priv->config;
1218 error->elem_len = elem_len;
1219 error->log_len = log_len;
1220 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001221 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001222
1223 ipw_capture_event_log(priv, log_len, error->log);
1224
1225 if (elem_len)
1226 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1227 sizeof(*error->elem) * elem_len);
1228
1229 return error;
1230}
1231
James Ketrenosb39860c2005-08-12 09:36:32 -05001232static ssize_t show_event_log(struct device *d,
1233 struct device_attribute *attr, char *buf)
1234{
1235 struct ipw_priv *priv = dev_get_drvdata(d);
1236 u32 log_len = ipw_get_event_log_len(priv);
1237 struct ipw_event log[log_len];
1238 u32 len = 0, i;
1239
1240 ipw_capture_event_log(priv, log_len, log);
1241
1242 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1243 for (i = 0; i < log_len; i++)
1244 len += snprintf(buf + len, PAGE_SIZE - len,
1245 "\n%08X%08X%08X",
1246 log[i].time, log[i].event, log[i].data);
1247 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1248 return len;
1249}
1250
1251static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1252
1253static ssize_t show_error(struct device *d,
1254 struct device_attribute *attr, char *buf)
1255{
1256 struct ipw_priv *priv = dev_get_drvdata(d);
1257 u32 len = 0, i;
1258 if (!priv->error)
1259 return 0;
1260 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001261 "%08lX%08X%08X%08X",
1262 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001263 priv->error->status,
1264 priv->error->config, priv->error->elem_len);
1265 for (i = 0; i < priv->error->elem_len; i++)
1266 len += snprintf(buf + len, PAGE_SIZE - len,
1267 "\n%08X%08X%08X%08X%08X%08X%08X",
1268 priv->error->elem[i].time,
1269 priv->error->elem[i].desc,
1270 priv->error->elem[i].blink1,
1271 priv->error->elem[i].blink2,
1272 priv->error->elem[i].link1,
1273 priv->error->elem[i].link2,
1274 priv->error->elem[i].data);
1275
1276 len += snprintf(buf + len, PAGE_SIZE - len,
1277 "\n%08X", priv->error->log_len);
1278 for (i = 0; i < priv->error->log_len; i++)
1279 len += snprintf(buf + len, PAGE_SIZE - len,
1280 "\n%08X%08X%08X",
1281 priv->error->log[i].time,
1282 priv->error->log[i].event,
1283 priv->error->log[i].data);
1284 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1285 return len;
1286}
1287
1288static ssize_t clear_error(struct device *d,
1289 struct device_attribute *attr,
1290 const char *buf, size_t count)
1291{
1292 struct ipw_priv *priv = dev_get_drvdata(d);
Jesper Juhl8f760782006-06-27 02:55:06 -07001293
1294 kfree(priv->error);
1295 priv->error = NULL;
James Ketrenosb39860c2005-08-12 09:36:32 -05001296 return count;
1297}
1298
1299static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1300
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001301static ssize_t show_cmd_log(struct device *d,
1302 struct device_attribute *attr, char *buf)
1303{
1304 struct ipw_priv *priv = dev_get_drvdata(d);
1305 u32 len = 0, i;
1306 if (!priv->cmdlog)
1307 return 0;
1308 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1309 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1310 i = (i + 1) % priv->cmdlog_len) {
1311 len +=
1312 snprintf(buf + len, PAGE_SIZE - len,
1313 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1314 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1315 priv->cmdlog[i].cmd.len);
1316 len +=
1317 snprintk_buf(buf + len, PAGE_SIZE - len,
1318 (u8 *) priv->cmdlog[i].cmd.param,
1319 priv->cmdlog[i].cmd.len);
1320 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1321 }
1322 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1323 return len;
1324}
1325
1326static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1327
Zhu Yid685b8c2006-04-13 17:20:27 +08001328#ifdef CONFIG_IPW2200_PROMISCUOUS
1329static void ipw_prom_free(struct ipw_priv *priv);
1330static int ipw_prom_alloc(struct ipw_priv *priv);
1331static ssize_t store_rtap_iface(struct device *d,
1332 struct device_attribute *attr,
1333 const char *buf, size_t count)
1334{
1335 struct ipw_priv *priv = dev_get_drvdata(d);
1336 int rc = 0;
1337
1338 if (count < 1)
1339 return -EINVAL;
1340
1341 switch (buf[0]) {
1342 case '0':
1343 if (!rtap_iface)
1344 return count;
1345
1346 if (netif_running(priv->prom_net_dev)) {
1347 IPW_WARNING("Interface is up. Cannot unregister.\n");
1348 return count;
1349 }
1350
1351 ipw_prom_free(priv);
1352 rtap_iface = 0;
1353 break;
1354
1355 case '1':
1356 if (rtap_iface)
1357 return count;
1358
1359 rc = ipw_prom_alloc(priv);
1360 if (!rc)
1361 rtap_iface = 1;
1362 break;
1363
1364 default:
1365 return -EINVAL;
1366 }
1367
1368 if (rc) {
1369 IPW_ERROR("Failed to register promiscuous network "
1370 "device (error %d).\n", rc);
1371 }
1372
1373 return count;
1374}
1375
1376static ssize_t show_rtap_iface(struct device *d,
1377 struct device_attribute *attr,
1378 char *buf)
1379{
1380 struct ipw_priv *priv = dev_get_drvdata(d);
1381 if (rtap_iface)
1382 return sprintf(buf, "%s", priv->prom_net_dev->name);
1383 else {
1384 buf[0] = '-';
1385 buf[1] = '1';
1386 buf[2] = '\0';
1387 return 3;
1388 }
1389}
1390
1391static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1392 store_rtap_iface);
1393
1394static ssize_t store_rtap_filter(struct device *d,
1395 struct device_attribute *attr,
1396 const char *buf, size_t count)
1397{
1398 struct ipw_priv *priv = dev_get_drvdata(d);
1399
1400 if (!priv->prom_priv) {
1401 IPW_ERROR("Attempting to set filter without "
1402 "rtap_iface enabled.\n");
1403 return -EPERM;
1404 }
1405
1406 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1407
1408 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1409 BIT_ARG16(priv->prom_priv->filter));
1410
1411 return count;
1412}
1413
1414static ssize_t show_rtap_filter(struct device *d,
1415 struct device_attribute *attr,
1416 char *buf)
1417{
1418 struct ipw_priv *priv = dev_get_drvdata(d);
1419 return sprintf(buf, "0x%04X",
1420 priv->prom_priv ? priv->prom_priv->filter : 0);
1421}
1422
1423static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1424 store_rtap_filter);
1425#endif
1426
James Ketrenosa613bff2005-08-24 21:43:11 -05001427static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1428 char *buf)
1429{
1430 struct ipw_priv *priv = dev_get_drvdata(d);
1431 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1432}
1433
1434static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1435 const char *buf, size_t count)
1436{
1437 struct ipw_priv *priv = dev_get_drvdata(d);
Brice Goglin0f52bf92005-12-01 01:41:46 -08001438#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosa613bff2005-08-24 21:43:11 -05001439 struct net_device *dev = priv->net_dev;
James Ketrenosc848d0a2005-08-24 21:56:24 -05001440#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05001441 char buffer[] = "00000000";
1442 unsigned long len =
1443 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1444 unsigned long val;
1445 char *p = buffer;
1446
1447 IPW_DEBUG_INFO("enter\n");
1448
1449 strncpy(buffer, buf, len);
1450 buffer[len] = 0;
1451
1452 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1453 p++;
1454 if (p[0] == 'x' || p[0] == 'X')
1455 p++;
1456 val = simple_strtoul(p, &p, 16);
1457 } else
1458 val = simple_strtoul(p, &p, 10);
1459 if (p == buffer) {
1460 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1461 } else {
1462 priv->ieee->scan_age = val;
1463 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1464 }
1465
1466 IPW_DEBUG_INFO("exit\n");
1467 return len;
1468}
1469
1470static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1471
1472static ssize_t show_led(struct device *d, struct device_attribute *attr,
1473 char *buf)
1474{
1475 struct ipw_priv *priv = dev_get_drvdata(d);
1476 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1477}
1478
1479static ssize_t store_led(struct device *d, struct device_attribute *attr,
1480 const char *buf, size_t count)
1481{
1482 struct ipw_priv *priv = dev_get_drvdata(d);
1483
1484 IPW_DEBUG_INFO("enter\n");
1485
1486 if (count == 0)
1487 return 0;
1488
1489 if (*buf == 0) {
1490 IPW_DEBUG_LED("Disabling LED control.\n");
1491 priv->config |= CFG_NO_LED;
1492 ipw_led_shutdown(priv);
1493 } else {
1494 IPW_DEBUG_LED("Enabling LED control.\n");
1495 priv->config &= ~CFG_NO_LED;
1496 ipw_led_init(priv);
1497 }
1498
1499 IPW_DEBUG_INFO("exit\n");
1500 return count;
1501}
1502
1503static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1504
Andrew Mortonad3fee52005-06-20 14:30:36 -07001505static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001506 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001507{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001508 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001509 return sprintf(buf, "0x%08x\n", (int)p->status);
1510}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001511
James Ketrenos43f66a62005-03-25 12:31:53 -06001512static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1513
Andrew Mortonad3fee52005-06-20 14:30:36 -07001514static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1515 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001516{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001517 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001518 return sprintf(buf, "0x%08x\n", (int)p->config);
1519}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001520
James Ketrenos43f66a62005-03-25 12:31:53 -06001521static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1522
Andrew Mortonad3fee52005-06-20 14:30:36 -07001523static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001524 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001525{
James Ketrenosa613bff2005-08-24 21:43:11 -05001526 struct ipw_priv *priv = d->driver_data;
1527 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001528}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001529
James Ketrenos43f66a62005-03-25 12:31:53 -06001530static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1531
Andrew Mortonad3fee52005-06-20 14:30:36 -07001532static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001533 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001534{
1535 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001536 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001537
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001538 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001539 return 0;
1540
1541 return sprintf(buf, "0x%08x\n", tmp);
1542}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001543
1544static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001545
Andrew Mortonad3fee52005-06-20 14:30:36 -07001546static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1547 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001548{
1549 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001550 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001551
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001552 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001553 return 0;
1554
1555 return sprintf(buf, "0x%08x\n", tmp);
1556}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001557
1558static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001559
1560/*
1561 * Add a device attribute to view/control the delay between eeprom
1562 * operations.
1563 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001564static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001565 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001566{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001567 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001568 return sprintf(buf, "%i\n", n);
1569}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001570static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001571 struct device_attribute *attr,
1572 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001573{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001574 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001575 sscanf(buf, "%i", &p->eeprom_delay);
1576 return strnlen(buf, count);
1577}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001578
1579static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1580 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001581
Andrew Mortonad3fee52005-06-20 14:30:36 -07001582static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001583 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001584{
1585 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001586 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001587
James Ketrenosb095c382005-08-24 22:04:42 -05001588 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001589 return sprintf(buf, "0x%08x\n", reg);
1590}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001591static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001592 struct device_attribute *attr,
1593 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001594{
1595 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001596 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001597
1598 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001599 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001600 return strnlen(buf, count);
1601}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001602
1603static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1604 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001605
Andrew Mortonad3fee52005-06-20 14:30:36 -07001606static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001607 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001608{
1609 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001610 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001611
1612 reg = ipw_read_reg32(p, 0x301100);
1613 return sprintf(buf, "0x%08x\n", reg);
1614}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001615static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001616 struct device_attribute *attr,
1617 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001618{
1619 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001620 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001621
1622 sscanf(buf, "%x", &reg);
1623 ipw_write_reg32(p, 0x301100, reg);
1624 return strnlen(buf, count);
1625}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001626
1627static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1628 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001629
Andrew Mortonad3fee52005-06-20 14:30:36 -07001630static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001631 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001632{
1633 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001634 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001635
Jeff Garzikbf794512005-07-31 13:07:26 -04001636 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001637 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001638 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001639 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001640
James Ketrenos43f66a62005-03-25 12:31:53 -06001641 return sprintf(buf, "0x%08x\n", reg);
1642}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001643static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001644 struct device_attribute *attr,
1645 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001646{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001647 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001648
1649 sscanf(buf, "%x", &priv->indirect_dword);
1650 priv->status |= STATUS_INDIRECT_DWORD;
1651 return strnlen(buf, count);
1652}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001653
1654static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1655 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001656
Andrew Mortonad3fee52005-06-20 14:30:36 -07001657static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001658 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001659{
1660 u8 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001661 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001662
Jeff Garzikbf794512005-07-31 13:07:26 -04001663 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001664 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001665 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001666 reg = 0;
1667
1668 return sprintf(buf, "0x%02x\n", reg);
1669}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001670static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001671 struct device_attribute *attr,
1672 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001673{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001674 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001675
1676 sscanf(buf, "%x", &priv->indirect_byte);
1677 priv->status |= STATUS_INDIRECT_BYTE;
1678 return strnlen(buf, count);
1679}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001680
1681static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001682 show_indirect_byte, store_indirect_byte);
1683
Andrew Mortonad3fee52005-06-20 14:30:36 -07001684static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001685 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001686{
1687 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001688 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001689
Jeff Garzikbf794512005-07-31 13:07:26 -04001690 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001691 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001692 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001693 reg = 0;
1694
1695 return sprintf(buf, "0x%08x\n", reg);
1696}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001697static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001698 struct device_attribute *attr,
1699 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001700{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001701 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001702
1703 sscanf(buf, "%x", &priv->direct_dword);
1704 priv->status |= STATUS_DIRECT_DWORD;
1705 return strnlen(buf, count);
1706}
James Ketrenos43f66a62005-03-25 12:31:53 -06001707
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001708static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1709 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001710
Arjan van de Ven858119e2006-01-14 13:20:43 -08001711static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001712{
1713 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1714 priv->status |= STATUS_RF_KILL_HW;
1715 else
1716 priv->status &= ~STATUS_RF_KILL_HW;
1717
1718 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1719}
1720
Andrew Mortonad3fee52005-06-20 14:30:36 -07001721static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001722 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001723{
1724 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001725 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001726 2 - HW based RF kill active
1727 3 - Both HW and SW baed RF kill active */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001728 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001729 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001730 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001731 return sprintf(buf, "%i\n", val);
1732}
1733
1734static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1735{
Jeff Garzikbf794512005-07-31 13:07:26 -04001736 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001737 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001738 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001739
1740 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1741 disable_radio ? "OFF" : "ON");
1742
1743 if (disable_radio) {
1744 priv->status |= STATUS_RF_KILL_SW;
1745
James Ketrenosa613bff2005-08-24 21:43:11 -05001746 if (priv->workqueue)
James Ketrenos43f66a62005-03-25 12:31:53 -06001747 cancel_delayed_work(&priv->request_scan);
James Ketrenos43f66a62005-03-25 12:31:53 -06001748 queue_work(priv->workqueue, &priv->down);
1749 } else {
1750 priv->status &= ~STATUS_RF_KILL_SW;
1751 if (rf_kill_active(priv)) {
1752 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1753 "disabled by HW switch\n");
1754 /* Make sure the RF_KILL check timer is running */
1755 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001756 queue_delayed_work(priv->workqueue, &priv->rf_kill,
James Ketrenos43f66a62005-03-25 12:31:53 -06001757 2 * HZ);
Jeff Garzikbf794512005-07-31 13:07:26 -04001758 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001759 queue_work(priv->workqueue, &priv->up);
1760 }
1761
1762 return 1;
1763}
1764
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001765static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1766 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001767{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001768 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -04001769
James Ketrenos43f66a62005-03-25 12:31:53 -06001770 ipw_radio_kill_sw(priv, buf[0] == '1');
1771
1772 return count;
1773}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001774
1775static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001776
James Ketrenosb095c382005-08-24 22:04:42 -05001777static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1778 char *buf)
1779{
1780 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1781 int pos = 0, len = 0;
1782 if (priv->config & CFG_SPEED_SCAN) {
1783 while (priv->speed_scan[pos] != 0)
1784 len += sprintf(&buf[len], "%d ",
1785 priv->speed_scan[pos++]);
1786 return len + sprintf(&buf[len], "\n");
1787 }
1788
1789 return sprintf(buf, "0\n");
1790}
1791
1792static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1793 const char *buf, size_t count)
1794{
1795 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1796 int channel, pos = 0;
1797 const char *p = buf;
1798
1799 /* list of space separated channels to scan, optionally ending with 0 */
1800 while ((channel = simple_strtol(p, NULL, 0))) {
1801 if (pos == MAX_SPEED_SCAN - 1) {
1802 priv->speed_scan[pos] = 0;
1803 break;
1804 }
1805
Larry Finger1867b112006-02-28 09:48:28 -06001806 if (ieee80211_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001807 priv->speed_scan[pos++] = channel;
1808 else
1809 IPW_WARNING("Skipping invalid channel request: %d\n",
1810 channel);
1811 p = strchr(p, ' ');
1812 if (!p)
1813 break;
1814 while (*p == ' ' || *p == '\t')
1815 p++;
1816 }
1817
1818 if (pos == 0)
1819 priv->config &= ~CFG_SPEED_SCAN;
1820 else {
1821 priv->speed_scan_pos = 0;
1822 priv->config |= CFG_SPEED_SCAN;
1823 }
1824
1825 return count;
1826}
1827
1828static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1829 store_speed_scan);
1830
1831static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1832 char *buf)
1833{
1834 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1835 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1836}
1837
1838static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1839 const char *buf, size_t count)
1840{
1841 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1842 if (buf[0] == '1')
1843 priv->config |= CFG_NET_STATS;
1844 else
1845 priv->config &= ~CFG_NET_STATS;
1846
1847 return count;
1848}
1849
James Ketrenosafbf30a2005-08-25 00:05:33 -05001850static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1851 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001852
James Ketrenosea2b26e2005-08-24 21:25:16 -05001853static void notify_wx_assoc_event(struct ipw_priv *priv)
1854{
1855 union iwreq_data wrqu;
1856 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1857 if (priv->status & STATUS_ASSOCIATED)
1858 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1859 else
1860 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1861 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1862}
1863
James Ketrenos43f66a62005-03-25 12:31:53 -06001864static void ipw_irq_tasklet(struct ipw_priv *priv)
1865{
1866 u32 inta, inta_mask, handled = 0;
1867 unsigned long flags;
1868 int rc = 0;
1869
Zhu Yi89c318e2006-06-08 22:19:49 -07001870 spin_lock_irqsave(&priv->irq_lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001871
James Ketrenosb095c382005-08-24 22:04:42 -05001872 inta = ipw_read32(priv, IPW_INTA_RW);
1873 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1874 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001875
1876 /* Add any cached INTA values that need to be handled */
1877 inta |= priv->isr_inta;
1878
Zhu Yi89c318e2006-06-08 22:19:49 -07001879 spin_unlock_irqrestore(&priv->irq_lock, flags);
1880
1881 spin_lock_irqsave(&priv->lock, flags);
1882
James Ketrenos43f66a62005-03-25 12:31:53 -06001883 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001884 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001885 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001886 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001887 }
1888
James Ketrenosb095c382005-08-24 22:04:42 -05001889 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001890 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001891 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001892 priv->status &= ~STATUS_HCMD_ACTIVE;
1893 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001894 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001895 }
1896
James Ketrenosb095c382005-08-24 22:04:42 -05001897 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001898 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001899 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05001900 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06001901 }
1902
James Ketrenosb095c382005-08-24 22:04:42 -05001903 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001904 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001905 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05001906 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06001907 }
1908
James Ketrenosb095c382005-08-24 22:04:42 -05001909 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001910 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001911 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05001912 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06001913 }
1914
James Ketrenosb095c382005-08-24 22:04:42 -05001915 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001916 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001917 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05001918 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06001919 }
1920
James Ketrenosb095c382005-08-24 22:04:42 -05001921 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001922 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001923 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001924 }
1925
James Ketrenosb095c382005-08-24 22:04:42 -05001926 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001927 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001928 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06001929 }
1930
James Ketrenosb095c382005-08-24 22:04:42 -05001931 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001932 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001933 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001934 }
1935
James Ketrenosb095c382005-08-24 22:04:42 -05001936 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001937 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001938 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001939 }
1940
James Ketrenosb095c382005-08-24 22:04:42 -05001941 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001942 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001943 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001944 }
1945
James Ketrenosb095c382005-08-24 22:04:42 -05001946 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001947 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1948 priv->status |= STATUS_RF_KILL_HW;
1949 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05001950 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06001951 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05001952 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001953 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05001954 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001955 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001956
James Ketrenosb095c382005-08-24 22:04:42 -05001957 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001958 IPW_WARNING("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001959 if (priv->error) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001960 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001961#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001962 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1963 struct ipw_fw_error *error =
1964 ipw_alloc_error_log(priv);
1965 ipw_dump_error_log(priv, error);
Jesper Juhl8f760782006-06-27 02:55:06 -07001966 kfree(error);
James Ketrenosb39860c2005-08-12 09:36:32 -05001967 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001968#endif
James Ketrenosb39860c2005-08-12 09:36:32 -05001969 } else {
1970 priv->error = ipw_alloc_error_log(priv);
1971 if (priv->error)
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001972 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001973 else
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001974 IPW_DEBUG_FW("Error allocating sysfs 'error' "
1975 "log.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001976#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001977 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1978 ipw_dump_error_log(priv, priv->error);
1979#endif
1980 }
1981
James Ketrenosb095c382005-08-24 22:04:42 -05001982 /* XXX: If hardware encryption is for WPA/WPA2,
1983 * we have to notify the supplicant. */
1984 if (priv->ieee->sec.encrypt) {
1985 priv->status &= ~STATUS_ASSOCIATED;
1986 notify_wx_assoc_event(priv);
1987 }
1988
1989 /* Keep the restart process from trying to send host
1990 * commands by clearing the INIT status bit */
1991 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001992
1993 /* Cancel currently queued command. */
1994 priv->status &= ~STATUS_HCMD_ACTIVE;
1995 wake_up_interruptible(&priv->wait_command_queue);
1996
James Ketrenos43f66a62005-03-25 12:31:53 -06001997 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05001998 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001999 }
2000
James Ketrenosb095c382005-08-24 22:04:42 -05002001 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002002 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002003 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002004 }
2005
2006 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002007 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06002008 }
2009
Zhu Yi89c318e2006-06-08 22:19:49 -07002010 spin_unlock_irqrestore(&priv->lock, flags);
2011
James Ketrenos43f66a62005-03-25 12:31:53 -06002012 /* enable all interrupts */
2013 ipw_enable_interrupts(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06002014}
Jeff Garzikbf794512005-07-31 13:07:26 -04002015
James Ketrenos43f66a62005-03-25 12:31:53 -06002016#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2017static char *get_cmd_string(u8 cmd)
2018{
2019 switch (cmd) {
2020 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04002021 IPW_CMD(POWER_DOWN);
2022 IPW_CMD(SYSTEM_CONFIG);
2023 IPW_CMD(MULTICAST_ADDRESS);
2024 IPW_CMD(SSID);
2025 IPW_CMD(ADAPTER_ADDRESS);
2026 IPW_CMD(PORT_TYPE);
2027 IPW_CMD(RTS_THRESHOLD);
2028 IPW_CMD(FRAG_THRESHOLD);
2029 IPW_CMD(POWER_MODE);
2030 IPW_CMD(WEP_KEY);
2031 IPW_CMD(TGI_TX_KEY);
2032 IPW_CMD(SCAN_REQUEST);
2033 IPW_CMD(SCAN_REQUEST_EXT);
2034 IPW_CMD(ASSOCIATE);
2035 IPW_CMD(SUPPORTED_RATES);
2036 IPW_CMD(SCAN_ABORT);
2037 IPW_CMD(TX_FLUSH);
2038 IPW_CMD(QOS_PARAMETERS);
2039 IPW_CMD(DINO_CONFIG);
2040 IPW_CMD(RSN_CAPABILITIES);
2041 IPW_CMD(RX_KEY);
2042 IPW_CMD(CARD_DISABLE);
2043 IPW_CMD(SEED_NUMBER);
2044 IPW_CMD(TX_POWER);
2045 IPW_CMD(COUNTRY_INFO);
2046 IPW_CMD(AIRONET_INFO);
2047 IPW_CMD(AP_TX_POWER);
2048 IPW_CMD(CCKM_INFO);
2049 IPW_CMD(CCX_VER_INFO);
2050 IPW_CMD(SET_CALIBRATION);
2051 IPW_CMD(SENSITIVITY_CALIB);
2052 IPW_CMD(RETRY_LIMIT);
2053 IPW_CMD(IPW_PRE_POWER_DOWN);
2054 IPW_CMD(VAP_BEACON_TEMPLATE);
2055 IPW_CMD(VAP_DTIM_PERIOD);
2056 IPW_CMD(EXT_SUPPORTED_RATES);
2057 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2058 IPW_CMD(VAP_QUIET_INTERVALS);
2059 IPW_CMD(VAP_CHANNEL_SWITCH);
2060 IPW_CMD(VAP_MANDATORY_CHANNELS);
2061 IPW_CMD(VAP_CELL_PWR_LIMIT);
2062 IPW_CMD(VAP_CF_PARAM_SET);
2063 IPW_CMD(VAP_SET_BEACONING_STATE);
2064 IPW_CMD(MEASUREMENT);
2065 IPW_CMD(POWER_CAPABILITY);
2066 IPW_CMD(SUPPORTED_CHANNELS);
2067 IPW_CMD(TPC_REPORT);
2068 IPW_CMD(WME_INFO);
2069 IPW_CMD(PRODUCTION_COMMAND);
2070 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06002071 return "UNKNOWN";
2072 }
2073}
James Ketrenos43f66a62005-03-25 12:31:53 -06002074
2075#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002076
2077static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06002078{
2079 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002080 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06002081
James Ketrenosa613bff2005-08-24 21:43:11 -05002082 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002083 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002084 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2085 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002086 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002087 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06002088 }
2089
2090 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04002091
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002092 if (priv->cmdlog) {
2093 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2094 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2095 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2096 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2097 cmd->len);
2098 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2099 }
2100
James Ketrenosb095c382005-08-24 22:04:42 -05002101 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2102 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2103 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08002104
2105#ifndef DEBUG_CMD_WEP_KEY
2106 if (cmd->cmd == IPW_CMD_WEP_KEY)
2107 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2108 else
2109#endif
2110 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2111
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002112 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05002113 if (rc) {
2114 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002115 IPW_ERROR("Failed to send %s: Reason %d\n",
2116 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05002117 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002118 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002119 }
2120 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002121
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002122 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2123 !(priv->
2124 status & STATUS_HCMD_ACTIVE),
2125 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002126 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05002127 spin_lock_irqsave(&priv->lock, flags);
2128 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002129 IPW_ERROR("Failed to send %s: Command timed out.\n",
2130 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002131 priv->status &= ~STATUS_HCMD_ACTIVE;
2132 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002133 rc = -EIO;
2134 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002135 }
2136 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05002137 } else
2138 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002139
James Ketrenosb095c382005-08-24 22:04:42 -05002140 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002141 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2142 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002143 rc = -EIO;
2144 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06002145 }
2146
Zhu Yi2638bc32006-01-24 16:37:52 +08002147 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002148 if (priv->cmdlog) {
2149 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2150 priv->cmdlog_pos %= priv->cmdlog_len;
2151 }
2152 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002153}
2154
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002155static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002156{
2157 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002158 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002159 };
2160
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002161 return __ipw_send_cmd(priv, &cmd);
2162}
2163
2164static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2165 void *data)
2166{
2167 struct host_cmd cmd = {
2168 .cmd = command,
2169 .len = len,
2170 .param = data,
2171 };
2172
2173 return __ipw_send_cmd(priv, &cmd);
2174}
2175
2176static int ipw_send_host_complete(struct ipw_priv *priv)
2177{
James Ketrenos43f66a62005-03-25 12:31:53 -06002178 if (!priv) {
2179 IPW_ERROR("Invalid args\n");
2180 return -1;
2181 }
2182
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002183 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002184}
2185
Zhu Yid685b8c2006-04-13 17:20:27 +08002186static int ipw_send_system_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002187{
Zhu Yid685b8c2006-04-13 17:20:27 +08002188 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2189 sizeof(priv->sys_config),
2190 &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002191}
2192
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002193static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002194{
James Ketrenos43f66a62005-03-25 12:31:53 -06002195 if (!priv || !ssid) {
2196 IPW_ERROR("Invalid args\n");
2197 return -1;
2198 }
2199
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002200 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002201 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002202}
2203
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002204static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002205{
James Ketrenos43f66a62005-03-25 12:31:53 -06002206 if (!priv || !mac) {
2207 IPW_ERROR("Invalid args\n");
2208 return -1;
2209 }
2210
2211 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2212 priv->net_dev->name, MAC_ARG(mac));
2213
Zhu Yi2638bc32006-01-24 16:37:52 +08002214 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002215}
2216
James Ketrenosa613bff2005-08-24 21:43:11 -05002217/*
2218 * NOTE: This must be executed from our workqueue as it results in udelay
2219 * being called which may corrupt the keyboard if executed on default
2220 * workqueue
2221 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002222static void ipw_adapter_restart(void *adapter)
2223{
2224 struct ipw_priv *priv = adapter;
2225
2226 if (priv->status & STATUS_RF_KILL_MASK)
2227 return;
2228
2229 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002230
2231 if (priv->assoc_network &&
2232 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2233 ipw_remove_current_network(priv);
2234
James Ketrenos43f66a62005-03-25 12:31:53 -06002235 if (ipw_up(priv)) {
2236 IPW_ERROR("Failed to up device\n");
2237 return;
2238 }
2239}
2240
James Ketrenosc848d0a2005-08-24 21:56:24 -05002241static void ipw_bg_adapter_restart(void *data)
2242{
2243 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08002244 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002245 ipw_adapter_restart(data);
Zhu Yi46441512006-01-24 16:37:59 +08002246 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002247}
2248
James Ketrenos43f66a62005-03-25 12:31:53 -06002249#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2250
2251static void ipw_scan_check(void *data)
2252{
2253 struct ipw_priv *priv = data;
2254 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2255 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002256 "adapter after (%dms).\n",
2257 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
James Ketrenosa613bff2005-08-24 21:43:11 -05002258 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06002259 }
2260}
2261
James Ketrenosc848d0a2005-08-24 21:56:24 -05002262static void ipw_bg_scan_check(void *data)
2263{
2264 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08002265 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002266 ipw_scan_check(data);
Zhu Yi46441512006-01-24 16:37:59 +08002267 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002268}
2269
James Ketrenos43f66a62005-03-25 12:31:53 -06002270static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2271 struct ipw_scan_request_ext *request)
2272{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002273 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002274 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002275}
2276
2277static int ipw_send_scan_abort(struct ipw_priv *priv)
2278{
James Ketrenos43f66a62005-03-25 12:31:53 -06002279 if (!priv) {
2280 IPW_ERROR("Invalid args\n");
2281 return -1;
2282 }
2283
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002284 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002285}
2286
2287static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2288{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002289 struct ipw_sensitivity_calib calib = {
2290 .beacon_rssi_raw = sens,
James Ketrenos43f66a62005-03-25 12:31:53 -06002291 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002292
2293 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002294 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002295}
2296
2297static int ipw_send_associate(struct ipw_priv *priv,
2298 struct ipw_associate *associate)
2299{
James Ketrenosa613bff2005-08-24 21:43:11 -05002300 struct ipw_associate tmp_associate;
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002301
2302 if (!priv || !associate) {
2303 IPW_ERROR("Invalid args\n");
2304 return -1;
2305 }
2306
James Ketrenosa613bff2005-08-24 21:43:11 -05002307 memcpy(&tmp_associate, associate, sizeof(*associate));
2308 tmp_associate.policy_support =
2309 cpu_to_le16(tmp_associate.policy_support);
2310 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2311 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2312 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2313 tmp_associate.listen_interval =
2314 cpu_to_le16(tmp_associate.listen_interval);
2315 tmp_associate.beacon_interval =
2316 cpu_to_le16(tmp_associate.beacon_interval);
2317 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2318
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002319 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
Zhu Yi2638bc32006-01-24 16:37:52 +08002320 &tmp_associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002321}
2322
2323static int ipw_send_supported_rates(struct ipw_priv *priv,
2324 struct ipw_supported_rates *rates)
2325{
James Ketrenos43f66a62005-03-25 12:31:53 -06002326 if (!priv || !rates) {
2327 IPW_ERROR("Invalid args\n");
2328 return -1;
2329 }
2330
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002331 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002332 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002333}
2334
2335static int ipw_set_random_seed(struct ipw_priv *priv)
2336{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002337 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002338
2339 if (!priv) {
2340 IPW_ERROR("Invalid args\n");
2341 return -1;
2342 }
2343
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002344 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002345
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002346 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002347}
2348
James Ketrenos43f66a62005-03-25 12:31:53 -06002349static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2350{
James Ketrenos43f66a62005-03-25 12:31:53 -06002351 if (!priv) {
2352 IPW_ERROR("Invalid args\n");
2353 return -1;
2354 }
2355
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002356 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off),
Zhu Yi2638bc32006-01-24 16:37:52 +08002357 &phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002358}
James Ketrenos43f66a62005-03-25 12:31:53 -06002359
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002360static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002361{
James Ketrenos43f66a62005-03-25 12:31:53 -06002362 if (!priv || !power) {
2363 IPW_ERROR("Invalid args\n");
2364 return -1;
2365 }
2366
Zhu Yi2638bc32006-01-24 16:37:52 +08002367 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002368}
James Ketrenos43f66a62005-03-25 12:31:53 -06002369
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002370static int ipw_set_tx_power(struct ipw_priv *priv)
2371{
Larry Finger1867b112006-02-28 09:48:28 -06002372 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002373 struct ipw_tx_power tx_power;
2374 s8 max_power;
2375 int i;
2376
2377 memset(&tx_power, 0, sizeof(tx_power));
2378
2379 /* configure device for 'G' band */
2380 tx_power.ieee_mode = IPW_G_MODE;
2381 tx_power.num_channels = geo->bg_channels;
2382 for (i = 0; i < geo->bg_channels; i++) {
2383 max_power = geo->bg[i].max_power;
2384 tx_power.channels_tx_power[i].channel_number =
2385 geo->bg[i].channel;
2386 tx_power.channels_tx_power[i].tx_power = max_power ?
2387 min(max_power, priv->tx_power) : priv->tx_power;
2388 }
2389 if (ipw_send_tx_power(priv, &tx_power))
2390 return -EIO;
2391
2392 /* configure device to also handle 'B' band */
2393 tx_power.ieee_mode = IPW_B_MODE;
2394 if (ipw_send_tx_power(priv, &tx_power))
2395 return -EIO;
2396
2397 /* configure device to also handle 'A' band */
2398 if (priv->ieee->abg_true) {
2399 tx_power.ieee_mode = IPW_A_MODE;
2400 tx_power.num_channels = geo->a_channels;
2401 for (i = 0; i < tx_power.num_channels; i++) {
2402 max_power = geo->a[i].max_power;
2403 tx_power.channels_tx_power[i].channel_number =
2404 geo->a[i].channel;
2405 tx_power.channels_tx_power[i].tx_power = max_power ?
2406 min(max_power, priv->tx_power) : priv->tx_power;
2407 }
2408 if (ipw_send_tx_power(priv, &tx_power))
2409 return -EIO;
2410 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002411 return 0;
2412}
2413
2414static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2415{
2416 struct ipw_rts_threshold rts_threshold = {
2417 .rts_threshold = rts,
2418 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002419
2420 if (!priv) {
2421 IPW_ERROR("Invalid args\n");
2422 return -1;
2423 }
2424
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002425 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2426 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002427}
2428
2429static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2430{
2431 struct ipw_frag_threshold frag_threshold = {
2432 .frag_threshold = frag,
2433 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002434
2435 if (!priv) {
2436 IPW_ERROR("Invalid args\n");
2437 return -1;
2438 }
2439
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002440 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2441 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002442}
2443
2444static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2445{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002446 u32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002447
2448 if (!priv) {
2449 IPW_ERROR("Invalid args\n");
2450 return -1;
2451 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002452
James Ketrenos43f66a62005-03-25 12:31:53 -06002453 /* If on battery, set to 3, if AC set to CAM, else user
2454 * level */
2455 switch (mode) {
2456 case IPW_POWER_BATTERY:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002457 param = IPW_POWER_INDEX_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06002458 break;
2459 case IPW_POWER_AC:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002460 param = IPW_POWER_MODE_CAM;
James Ketrenos43f66a62005-03-25 12:31:53 -06002461 break;
2462 default:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002463 param = mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06002464 break;
2465 }
2466
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002467 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002468 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002469}
2470
James Ketrenosafbf30a2005-08-25 00:05:33 -05002471static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2472{
2473 struct ipw_retry_limit retry_limit = {
2474 .short_retry_limit = slimit,
2475 .long_retry_limit = llimit
2476 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002477
2478 if (!priv) {
2479 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002480 return -1;
2481 }
2482
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002483 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002484 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002485}
2486
2487/*
2488 * The IPW device contains a Microwire compatible EEPROM that stores
2489 * various data like the MAC address. Usually the firmware has exclusive
2490 * access to the eeprom, but during device initialization (before the
2491 * device driver has sent the HostComplete command to the firmware) the
2492 * device driver has read access to the EEPROM by way of indirect addressing
2493 * through a couple of memory mapped registers.
2494 *
2495 * The following is a simplified implementation for pulling data out of the
2496 * the eeprom, along with some helper functions to find information in
2497 * the per device private data's copy of the eeprom.
2498 *
2499 * NOTE: To better understand how these functions work (i.e what is a chip
2500 * select and why do have to keep driving the eeprom clock?), read
2501 * just about any data sheet for a Microwire compatible EEPROM.
2502 */
2503
2504/* write a 32 bit value into the indirect accessor register */
2505static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2506{
2507 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002508
James Ketrenos43f66a62005-03-25 12:31:53 -06002509 /* the eeprom requires some time to complete the operation */
2510 udelay(p->eeprom_delay);
2511
2512 return;
2513}
2514
2515/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002516static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002517{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002518 eeprom_write_reg(priv, 0);
2519 eeprom_write_reg(priv, EEPROM_BIT_CS);
2520 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2521 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002522}
2523
2524/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002525static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002526{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002527 eeprom_write_reg(priv, EEPROM_BIT_CS);
2528 eeprom_write_reg(priv, 0);
2529 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002530}
2531
2532/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002533static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002534{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002535 int d = (bit ? EEPROM_BIT_DI : 0);
2536 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2537 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002538}
2539
2540/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002541static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002542{
2543 int i;
2544
2545 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002546 eeprom_write_bit(priv, 1);
2547 eeprom_write_bit(priv, op & 2);
2548 eeprom_write_bit(priv, op & 1);
2549 for (i = 7; i >= 0; i--) {
2550 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002551 }
2552}
2553
2554/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002555static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002556{
2557 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002558 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002559
James Ketrenos43f66a62005-03-25 12:31:53 -06002560 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002561 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002562
2563 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002564 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002565
2566 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002567 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002568 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002569 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2570 eeprom_write_reg(priv, EEPROM_BIT_CS);
2571 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2572 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002573 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002574
James Ketrenos43f66a62005-03-25 12:31:53 -06002575 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002576 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002577 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002578
James Ketrenos43f66a62005-03-25 12:31:53 -06002579 return r;
2580}
2581
2582/* helper function for pulling the mac address out of the private */
2583/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002584static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002585{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002586 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002587}
2588
2589/*
2590 * Either the device driver (i.e. the host) or the firmware can
2591 * load eeprom data into the designated region in SRAM. If neither
2592 * happens then the FW will shutdown with a fatal error.
2593 *
2594 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2595 * bit needs region of shared SRAM needs to be non-zero.
2596 */
2597static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2598{
2599 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002600 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002601
James Ketrenos43f66a62005-03-25 12:31:53 -06002602 IPW_DEBUG_TRACE(">>\n");
2603
2604 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002605 for (i = 0; i < 128; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002606 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002607
Jeff Garzikbf794512005-07-31 13:07:26 -04002608 /*
2609 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002610 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002611 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002612 */
Alexey Dobriyan386093e2006-02-01 03:04:57 -08002613 if (priv->eeprom[EEPROM_VERSION] != 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002614 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2615
2616 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002617 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002618 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002619
2620 /* Do not load eeprom data on fatal error or suspend */
2621 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2622 } else {
2623 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2624
2625 /* Load eeprom data on fatal error or suspend */
2626 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2627 }
2628
2629 IPW_DEBUG_TRACE("<<\n");
2630}
2631
Arjan van de Ven858119e2006-01-14 13:20:43 -08002632static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002633{
2634 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002635 if (!count)
2636 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002637 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002638 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002639 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002640}
2641
2642static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2643{
James Ketrenosb095c382005-08-24 22:04:42 -05002644 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002645 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002646 sizeof(struct command_block));
2647}
2648
2649static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002650{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002651
2652 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002653
James Ketrenos43f66a62005-03-25 12:31:53 -06002654 /* Start the dma */
2655 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002656
James Ketrenos43f66a62005-03-25 12:31:53 -06002657 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002658 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002659
2660 IPW_DEBUG_FW("<< : \n");
2661 return 0;
2662}
2663
2664static void ipw_fw_dma_abort(struct ipw_priv *priv)
2665{
2666 u32 control = 0;
2667
2668 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002669
Pavel Machek67fd6b42006-07-11 15:34:05 +02002670 /* set the Stop and Abort bit */
James Ketrenos43f66a62005-03-25 12:31:53 -06002671 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002672 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002673 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002674
James Ketrenos43f66a62005-03-25 12:31:53 -06002675 IPW_DEBUG_FW("<< \n");
2676}
2677
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002678static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2679 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002680{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002681 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002682 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002683 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002684 IPW_DEBUG_FW(">> :\n");
2685
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002686 ipw_write_indirect(priv, address, (u8 *) cb,
2687 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002688
2689 IPW_DEBUG_FW("<< :\n");
2690 return 0;
2691
2692}
2693
2694static int ipw_fw_dma_kick(struct ipw_priv *priv)
2695{
2696 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002697 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002698
2699 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002700
James Ketrenos43f66a62005-03-25 12:31:53 -06002701 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002702 ipw_fw_dma_write_command_block(priv, index,
2703 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002704
2705 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002706 ipw_clear_bit(priv, IPW_RESET_REG,
2707 IPW_RESET_REG_MASTER_DISABLED |
2708 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002709
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002710 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002711 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002712 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002713
2714 IPW_DEBUG_FW("<< :\n");
2715 return 0;
2716}
2717
2718static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2719{
2720 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002721 u32 register_value = 0;
2722 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002723
2724 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002725 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002726 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002727
2728 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002729 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2730 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002731
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002732 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002733 cb_fields_address = address;
2734 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002735 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002736
2737 cb_fields_address += sizeof(u32);
2738 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002739 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002740
2741 cb_fields_address += sizeof(u32);
2742 register_value = ipw_read_reg32(priv, cb_fields_address);
2743 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2744 register_value);
2745
2746 cb_fields_address += sizeof(u32);
2747 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002748 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002749
2750 IPW_DEBUG_FW(">> :\n");
2751}
2752
2753static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2754{
2755 u32 current_cb_address = 0;
2756 u32 current_cb_index = 0;
2757
2758 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002759 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002760
James Ketrenosb095c382005-08-24 22:04:42 -05002761 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002762 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002763
James Ketrenos43f66a62005-03-25 12:31:53 -06002764 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002765 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002766
2767 IPW_DEBUG_FW(">> :\n");
2768 return current_cb_index;
2769
2770}
2771
2772static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2773 u32 src_address,
2774 u32 dest_address,
2775 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002776 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002777{
2778
Jeff Garzikbf794512005-07-31 13:07:26 -04002779 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002780 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2781 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002782 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002783 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002784
2785 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2786 src_address, dest_address, length);
2787
2788 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2789 return -1;
2790
2791 last_cb_element = priv->sram_desc.last_cb_index;
2792 cb = &priv->sram_desc.cb_list[last_cb_element];
2793 priv->sram_desc.last_cb_index++;
2794
2795 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002796 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002797 control |= CB_INT_ENABLED;
2798
2799 if (is_last)
2800 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002801
James Ketrenos43f66a62005-03-25 12:31:53 -06002802 control |= length;
2803
2804 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002805 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002806
2807 /* Copy the Source and Destination addresses */
2808 cb->dest_addr = dest_address;
2809 cb->source_addr = src_address;
2810
2811 /* Copy the Control Word last */
2812 cb->control = control;
2813
2814 return 0;
2815}
2816
2817static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002818 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06002819{
2820 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002821 u32 src_offset = 0;
2822 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002823 int status = 0;
2824 IPW_DEBUG_FW(">> \n");
2825 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2826 src_phys, dest_address, length);
2827 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002828 status = ipw_fw_dma_add_command_block(priv,
2829 src_phys + src_offset,
2830 dest_address +
2831 dest_offset,
2832 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002833 if (status) {
2834 IPW_DEBUG_FW_INFO(": Failed\n");
2835 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002836 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002837 IPW_DEBUG_FW_INFO(": Added new cb\n");
2838
2839 src_offset += CB_MAX_LENGTH;
2840 dest_offset += CB_MAX_LENGTH;
2841 bytes_left -= CB_MAX_LENGTH;
2842 }
2843
2844 /* add the buffer tail */
2845 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002846 status =
2847 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2848 dest_address + dest_offset,
2849 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002850 if (status) {
2851 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2852 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002853 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002854 IPW_DEBUG_FW_INFO
2855 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002856 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002857
James Ketrenos43f66a62005-03-25 12:31:53 -06002858 IPW_DEBUG_FW("<< \n");
2859 return 0;
2860}
2861
2862static int ipw_fw_dma_wait(struct ipw_priv *priv)
2863{
Zhu Yi397ae122006-01-24 16:37:22 +08002864 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002865 u32 watchdog = 0;
2866
2867 IPW_DEBUG_FW(">> : \n");
2868
2869 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002870 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002871 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002872
2873 while (current_index < priv->sram_desc.last_cb_index) {
2874 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002875 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002876 current_index = ipw_fw_dma_command_block_index(priv);
2877
Zhu Yi397ae122006-01-24 16:37:22 +08002878 if (previous_index < current_index) {
2879 watchdog = 0;
2880 continue;
2881 }
2882 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002883 IPW_DEBUG_FW_INFO("Timeout\n");
2884 ipw_fw_dma_dump_command_block(priv);
2885 ipw_fw_dma_abort(priv);
2886 return -1;
2887 }
2888 }
2889
2890 ipw_fw_dma_abort(priv);
2891
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002892 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002893 ipw_set_bit(priv, IPW_RESET_REG,
2894 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002895
2896 IPW_DEBUG_FW("<< dmaWaitSync \n");
2897 return 0;
2898}
2899
Jeff Garzikbf794512005-07-31 13:07:26 -04002900static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002901{
2902 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002903 struct ieee80211_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002904 unsigned long flags;
2905
2906 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002907 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2908 network = list_entry(element, struct ieee80211_network, list);
2909 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2910 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002911 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002912 &priv->ieee->network_free_list);
2913 }
2914 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002915 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002916}
2917
2918/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002919 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002920 * Reads debug register from domain0.
2921 * If card is present, pre-defined value should
2922 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002923 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002924 * @param priv
2925 * @return 1 if card is present, 0 otherwise
2926 */
2927static inline int ipw_alive(struct ipw_priv *priv)
2928{
2929 return ipw_read32(priv, 0x90) == 0xd55555d5;
2930}
2931
Zhu Yic7b6a672006-01-24 16:37:05 +08002932/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002933static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06002934 int timeout)
2935{
2936 int i = 0;
2937
2938 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002939 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002940 return i;
2941 mdelay(10);
2942 i += 10;
2943 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002944
James Ketrenos43f66a62005-03-25 12:31:53 -06002945 return -ETIME;
2946}
2947
Jeff Garzikbf794512005-07-31 13:07:26 -04002948/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002949 * the ipw hardware. It assumes the buffer has all the bits for the
2950 * image and the caller is handling the memory allocation and clean up.
2951 */
2952
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002953static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002954{
2955 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002956
James Ketrenos43f66a62005-03-25 12:31:53 -06002957 IPW_DEBUG_TRACE(">> \n");
2958 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05002959 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002960
Zhu Yic7b6a672006-01-24 16:37:05 +08002961 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05002962 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2963 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06002964 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08002965 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002966 return -1;
2967 }
2968
2969 IPW_DEBUG_INFO("stop master %dms\n", rc);
2970
2971 return rc;
2972}
2973
2974static void ipw_arc_release(struct ipw_priv *priv)
2975{
2976 IPW_DEBUG_TRACE(">> \n");
2977 mdelay(5);
2978
James Ketrenosb095c382005-08-24 22:04:42 -05002979 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002980
2981 /* no one knows timing, for safety add some delay */
2982 mdelay(5);
2983}
2984
James Ketrenos43f66a62005-03-25 12:31:53 -06002985struct fw_chunk {
2986 u32 address;
2987 u32 length;
2988};
2989
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002990static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002991{
2992 int rc = 0, i, addr;
2993 u8 cr = 0;
2994 u16 *image;
2995
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002996 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002997
James Ketrenos43f66a62005-03-25 12:31:53 -06002998 IPW_DEBUG_TRACE(">> \n");
2999
3000 rc = ipw_stop_master(priv);
3001
3002 if (rc < 0)
3003 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003004
James Ketrenosb095c382005-08-24 22:04:42 -05003005 for (addr = IPW_SHARED_LOWER_BOUND;
3006 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003007 ipw_write32(priv, addr, 0);
3008 }
3009
3010 /* no ucode (yet) */
3011 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3012 /* destroy DMA queues */
3013 /* reset sequence */
3014
James Ketrenosb095c382005-08-24 22:04:42 -05003015 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06003016 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05003017 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06003018 mdelay(1);
3019
3020 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05003021 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06003022 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003023
James Ketrenosb095c382005-08-24 22:04:42 -05003024 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003025 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003026
James Ketrenos43f66a62005-03-25 12:31:53 -06003027 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08003028 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3029 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003030 mdelay(1);
3031
3032 /* write ucode */
3033 /**
3034 * @bug
3035 * Do NOT set indirect address register once and then
3036 * store data to indirect data register in the loop.
3037 * It seems very reasonable, but in this case DINO do not
3038 * accept ucode. It is essential to set address each time.
3039 */
3040 /* load new ipw uCode */
3041 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05003042 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
James Ketrenosa613bff2005-08-24 21:43:11 -05003043 cpu_to_le16(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06003044
James Ketrenos43f66a62005-03-25 12:31:53 -06003045 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05003046 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3047 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06003048
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003049 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06003050
3051 /* wait for alive response */
3052 for (i = 0; i < 100; i++) {
3053 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05003054 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003055 if (cr & DINO_RXFIFO_DATA)
3056 break;
3057 mdelay(1);
3058 }
3059
3060 if (cr & DINO_RXFIFO_DATA) {
3061 /* alive_command_responce size is NOT multiple of 4 */
3062 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04003063
3064 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06003065 response_buffer[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05003066 le32_to_cpu(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05003067 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06003068 memcpy(&priv->dino_alive, response_buffer,
3069 sizeof(priv->dino_alive));
3070 if (priv->dino_alive.alive_command == 1
3071 && priv->dino_alive.ucode_valid == 1) {
3072 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003073 IPW_DEBUG_INFO
3074 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3075 "of %02d/%02d/%02d %02d:%02d\n",
3076 priv->dino_alive.software_revision,
3077 priv->dino_alive.software_revision,
3078 priv->dino_alive.device_identifier,
3079 priv->dino_alive.device_identifier,
3080 priv->dino_alive.time_stamp[0],
3081 priv->dino_alive.time_stamp[1],
3082 priv->dino_alive.time_stamp[2],
3083 priv->dino_alive.time_stamp[3],
3084 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003085 } else {
3086 IPW_DEBUG_INFO("Microcode is not alive\n");
3087 rc = -EINVAL;
3088 }
3089 } else {
3090 IPW_DEBUG_INFO("No alive response from DINO\n");
3091 rc = -ETIME;
3092 }
3093
3094 /* disable DINO, otherwise for some reason
3095 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05003096 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003097
James Ketrenos43f66a62005-03-25 12:31:53 -06003098 return rc;
3099}
3100
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003101static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003102{
3103 int rc = -1;
3104 int offset = 0;
3105 struct fw_chunk *chunk;
3106 dma_addr_t shared_phys;
3107 u8 *shared_virt;
3108
3109 IPW_DEBUG_TRACE("<< : \n");
3110 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
3111
3112 if (!shared_virt)
3113 return -ENOMEM;
3114
3115 memmove(shared_virt, data, len);
3116
3117 /* Start the Dma */
3118 rc = ipw_fw_dma_enable(priv);
3119
3120 if (priv->sram_desc.last_cb_index > 0) {
3121 /* the DMA is already ready this would be a bug. */
3122 BUG();
3123 goto out;
3124 }
3125
3126 do {
3127 chunk = (struct fw_chunk *)(data + offset);
3128 offset += sizeof(struct fw_chunk);
3129 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003130 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003131 * offeset*/
3132 /* Dma loading */
3133 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
James Ketrenosa613bff2005-08-24 21:43:11 -05003134 le32_to_cpu(chunk->address),
3135 le32_to_cpu(chunk->length));
James Ketrenos43f66a62005-03-25 12:31:53 -06003136 if (rc) {
3137 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3138 goto out;
3139 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003140
James Ketrenosa613bff2005-08-24 21:43:11 -05003141 offset += le32_to_cpu(chunk->length);
James Ketrenos43f66a62005-03-25 12:31:53 -06003142 } while (offset < len);
3143
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003144 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06003145 rc = ipw_fw_dma_kick(priv);
3146 if (rc) {
3147 IPW_ERROR("dmaKick Failed\n");
3148 goto out;
3149 }
3150
3151 rc = ipw_fw_dma_wait(priv);
3152 if (rc) {
3153 IPW_ERROR("dmaWaitSync Failed\n");
3154 goto out;
3155 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003156 out:
3157 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06003158 return rc;
3159}
3160
3161/* stop nic */
3162static int ipw_stop_nic(struct ipw_priv *priv)
3163{
3164 int rc = 0;
3165
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003166 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003167 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003168
James Ketrenosb095c382005-08-24 22:04:42 -05003169 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3170 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003171 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003172 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003173 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003174 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003175
James Ketrenosb095c382005-08-24 22:04:42 -05003176 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003177
James Ketrenos43f66a62005-03-25 12:31:53 -06003178 return rc;
3179}
3180
3181static void ipw_start_nic(struct ipw_priv *priv)
3182{
3183 IPW_DEBUG_TRACE(">>\n");
3184
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003185 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003186 ipw_clear_bit(priv, IPW_RESET_REG,
3187 IPW_RESET_REG_MASTER_DISABLED |
3188 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003189 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003190
James Ketrenos43f66a62005-03-25 12:31:53 -06003191 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003192 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3193 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003194
3195 IPW_DEBUG_TRACE("<<\n");
3196}
Jeff Garzikbf794512005-07-31 13:07:26 -04003197
James Ketrenos43f66a62005-03-25 12:31:53 -06003198static int ipw_init_nic(struct ipw_priv *priv)
3199{
3200 int rc;
3201
3202 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003203 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003204 /*prvHwInitNic */
3205 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003206 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003207
3208 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003209 ipw_write32(priv, IPW_READ_INT_REGISTER,
3210 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003211
3212 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003213 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3214 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003215 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003216 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3217
3218 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003219 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003220
3221 udelay(10);
3222
3223 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003224 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003225
3226 IPW_DEBUG_TRACE(">>\n");
3227 return 0;
3228}
3229
Jeff Garzikbf794512005-07-31 13:07:26 -04003230/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003231 * Probe is an ok place to call this from.
3232 */
3233static int ipw_reset_nic(struct ipw_priv *priv)
3234{
3235 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003236 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003237
3238 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003239
James Ketrenos43f66a62005-03-25 12:31:53 -06003240 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003241
James Ketrenosa613bff2005-08-24 21:43:11 -05003242 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003243 /* Clear the 'host command active' bit... */
3244 priv->status &= ~STATUS_HCMD_ACTIVE;
3245 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003246 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3247 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003248 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003249
3250 IPW_DEBUG_TRACE("<<\n");
3251 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003252}
James Ketrenos43f66a62005-03-25 12:31:53 -06003253
James Ketrenos9006ea72006-03-08 03:22:28 +08003254
3255struct ipw_fw {
Zhu Yi0070f8c2006-04-13 17:20:12 +08003256 __le32 ver;
3257 __le32 boot_size;
3258 __le32 ucode_size;
3259 __le32 fw_size;
James Ketrenos9006ea72006-03-08 03:22:28 +08003260 u8 data[0];
3261};
3262
Jeff Garzikbf794512005-07-31 13:07:26 -04003263static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos9006ea72006-03-08 03:22:28 +08003264 const struct firmware **raw, const char *name)
James Ketrenos43f66a62005-03-25 12:31:53 -06003265{
James Ketrenos9006ea72006-03-08 03:22:28 +08003266 struct ipw_fw *fw;
James Ketrenos43f66a62005-03-25 12:31:53 -06003267 int rc;
3268
3269 /* ask firmware_class module to get the boot firmware off disk */
James Ketrenos9006ea72006-03-08 03:22:28 +08003270 rc = request_firmware(raw, name, &priv->pci_dev->dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06003271 if (rc < 0) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003272 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003273 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003274 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003275
James Ketrenos9006ea72006-03-08 03:22:28 +08003276 if ((*raw)->size < sizeof(*fw)) {
3277 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003278 return -EINVAL;
3279 }
3280
James Ketrenos9006ea72006-03-08 03:22:28 +08003281 fw = (void *)(*raw)->data;
3282
Zhu Yi0070f8c2006-04-13 17:20:12 +08003283 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3284 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003285 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3286 name, (*raw)->size);
3287 return -EINVAL;
3288 }
3289
3290 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003291 name,
James Ketrenos9006ea72006-03-08 03:22:28 +08003292 le32_to_cpu(fw->ver) >> 16,
3293 le32_to_cpu(fw->ver) & 0xff,
3294 (*raw)->size - sizeof(*fw));
James Ketrenos43f66a62005-03-25 12:31:53 -06003295 return 0;
3296}
3297
James Ketrenosb095c382005-08-24 22:04:42 -05003298#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003299
Arjan van de Ven858119e2006-01-14 13:20:43 -08003300static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003301 struct ipw_rx_queue *rxq)
3302{
3303 unsigned long flags;
3304 int i;
3305
3306 spin_lock_irqsave(&rxq->lock, flags);
3307
3308 INIT_LIST_HEAD(&rxq->rx_free);
3309 INIT_LIST_HEAD(&rxq->rx_used);
3310
3311 /* Fill the rx_used queue with _all_ of the Rx buffers */
3312 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3313 /* In the reset function, these buffers may have been allocated
3314 * to an SKB, so we need to unmap and free potential storage */
3315 if (rxq->pool[i].skb != NULL) {
3316 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003317 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003318 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003319 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003320 }
3321 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3322 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003323
James Ketrenos43f66a62005-03-25 12:31:53 -06003324 /* Set us so that we have processed and used all buffers, but have
3325 * not restocked the Rx queue with fresh buffers */
3326 rxq->read = rxq->write = 0;
3327 rxq->processed = RX_QUEUE_SIZE - 1;
3328 rxq->free_count = 0;
3329 spin_unlock_irqrestore(&rxq->lock, flags);
3330}
3331
3332#ifdef CONFIG_PM
3333static int fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003334static const struct firmware *raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003335
3336static void free_firmware(void)
3337{
3338 if (fw_loaded) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003339 release_firmware(raw);
3340 raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003341 fw_loaded = 0;
3342 }
3343}
3344#else
3345#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003346#endif
3347
3348static int ipw_load(struct ipw_priv *priv)
3349{
3350#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003351 const struct firmware *raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003352#endif
James Ketrenos9006ea72006-03-08 03:22:28 +08003353 struct ipw_fw *fw;
3354 u8 *boot_img, *ucode_img, *fw_img;
3355 u8 *name = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003356 int rc = 0, retries = 3;
3357
Zhu Yi397ae122006-01-24 16:37:22 +08003358 switch (priv->ieee->iw_mode) {
3359 case IW_MODE_ADHOC:
James Ketrenos9006ea72006-03-08 03:22:28 +08003360 name = "ipw2200-ibss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003361 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003362#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003363 case IW_MODE_MONITOR:
James Ketrenos9006ea72006-03-08 03:22:28 +08003364 name = "ipw2200-sniffer.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003365 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003366#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003367 case IW_MODE_INFRA:
James Ketrenos9006ea72006-03-08 03:22:28 +08003368 name = "ipw2200-bss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003369 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003370 }
Zhu Yi397ae122006-01-24 16:37:22 +08003371
James Ketrenos9006ea72006-03-08 03:22:28 +08003372 if (!name) {
3373 rc = -EINVAL;
3374 goto error;
3375 }
3376
3377#ifdef CONFIG_PM
3378 if (!fw_loaded) {
3379#endif
3380 rc = ipw_get_fw(priv, &raw, name);
3381 if (rc < 0)
3382 goto error;
3383#ifdef CONFIG_PM
3384 }
3385#endif
3386
3387 fw = (void *)raw->data;
3388 boot_img = &fw->data[0];
Zhu Yi0070f8c2006-04-13 17:20:12 +08003389 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3390 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3391 le32_to_cpu(fw->ucode_size)];
James Ketrenos9006ea72006-03-08 03:22:28 +08003392
Zhu Yi397ae122006-01-24 16:37:22 +08003393 if (rc < 0)
3394 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003395
3396 if (!priv->rxq)
3397 priv->rxq = ipw_rx_queue_alloc(priv);
3398 else
3399 ipw_rx_queue_reset(priv, priv->rxq);
3400 if (!priv->rxq) {
3401 IPW_ERROR("Unable to initialize Rx queue\n");
3402 goto error;
3403 }
3404
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003405 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003406 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003407 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003408 priv->status &= ~STATUS_INT_ENABLED;
3409
3410 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003411 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003412
James Ketrenos43f66a62005-03-25 12:31:53 -06003413 ipw_stop_nic(priv);
3414
3415 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003416 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003417 IPW_ERROR("Unable to reset NIC\n");
3418 goto error;
3419 }
3420
James Ketrenosb095c382005-08-24 22:04:42 -05003421 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3422 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003423
3424 /* DMA the initial boot firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003425 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003426 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003427 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003428 goto error;
3429 }
3430
3431 /* kick start the device */
3432 ipw_start_nic(priv);
3433
Zhu Yic7b6a672006-01-24 16:37:05 +08003434 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003435 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3436 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003437 if (rc < 0) {
3438 IPW_ERROR("device failed to boot initial fw image\n");
3439 goto error;
3440 }
3441 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3442
Jeff Garzikbf794512005-07-31 13:07:26 -04003443 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003444 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003445
3446 /* DMA the ucode into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003447 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003448 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003449 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003450 goto error;
3451 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003452
James Ketrenos43f66a62005-03-25 12:31:53 -06003453 /* stop nic */
3454 ipw_stop_nic(priv);
3455
3456 /* DMA bss firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003457 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003458 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003459 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003460 goto error;
3461 }
Zhu Yi397ae122006-01-24 16:37:22 +08003462#ifdef CONFIG_PM
3463 fw_loaded = 1;
3464#endif
3465
James Ketrenos43f66a62005-03-25 12:31:53 -06003466 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3467
3468 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003469 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003470 IPW_ERROR("Unable to initialize queues\n");
3471 goto error;
3472 }
3473
3474 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003475 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003476 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003477 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003478
James Ketrenos43f66a62005-03-25 12:31:53 -06003479 /* kick start the device */
3480 ipw_start_nic(priv);
3481
James Ketrenosb095c382005-08-24 22:04:42 -05003482 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003483 if (retries > 0) {
3484 IPW_WARNING("Parity error. Retrying init.\n");
3485 retries--;
3486 goto retry;
3487 }
3488
3489 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3490 rc = -EIO;
3491 goto error;
3492 }
3493
3494 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003495 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3496 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003497 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003498 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003499 goto error;
3500 }
3501 IPW_DEBUG_INFO("device response after %dms\n", rc);
3502
3503 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003504 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003505
3506 /* read eeprom data and initialize the eeprom region of sram */
3507 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003508 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003509
3510 /* enable interrupts */
3511 ipw_enable_interrupts(priv);
3512
3513 /* Ensure our queue has valid packets */
3514 ipw_rx_queue_replenish(priv);
3515
James Ketrenosb095c382005-08-24 22:04:42 -05003516 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003517
3518 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003519 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003520
3521#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003522 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003523#endif
3524 return 0;
3525
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003526 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003527 if (priv->rxq) {
3528 ipw_rx_queue_free(priv, priv->rxq);
3529 priv->rxq = NULL;
3530 }
3531 ipw_tx_queue_free(priv);
James Ketrenos9006ea72006-03-08 03:22:28 +08003532 if (raw)
3533 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003534#ifdef CONFIG_PM
3535 fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003536 raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003537#endif
3538
3539 return rc;
3540}
3541
Jeff Garzikbf794512005-07-31 13:07:26 -04003542/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003543 * DMA services
3544 *
3545 * Theory of operation
3546 *
3547 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3548 * 2 empty entries always kept in the buffer to protect from overflow.
3549 *
3550 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003551 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3552 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003553 * Tx queue resumed.
3554 *
3555 * The IPW operates with six queues, one receive queue in the device's
3556 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003557 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003558 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003559 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003560 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003561 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003562 * we only utilize the first data transmit queue (queue1).
3563 */
3564
3565/**
3566 * Driver allocates buffers of this size for Rx
3567 */
3568
3569static inline int ipw_queue_space(const struct clx2_queue *q)
3570{
3571 int s = q->last_used - q->first_empty;
3572 if (s <= 0)
3573 s += q->n_bd;
3574 s -= 2; /* keep some reserve to not confuse empty and full situations */
3575 if (s < 0)
3576 s = 0;
3577 return s;
3578}
3579
3580static inline int ipw_queue_inc_wrap(int index, int n_bd)
3581{
3582 return (++index == n_bd) ? 0 : index;
3583}
3584
3585/**
3586 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003587 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003588 * @param q queue to init
3589 * @param count Number of BD's to allocate. Should be power of 2
3590 * @param read_register Address for 'read' register
3591 * (not offset within BAR, full address)
3592 * @param write_register Address for 'write' register
3593 * (not offset within BAR, full address)
3594 * @param base_register Address for 'base' register
3595 * (not offset within BAR, full address)
3596 * @param size Address for 'size' register
3597 * (not offset within BAR, full address)
3598 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003599static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003600 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003601{
3602 q->n_bd = count;
3603
3604 q->low_mark = q->n_bd / 4;
3605 if (q->low_mark < 4)
3606 q->low_mark = 4;
3607
3608 q->high_mark = q->n_bd / 8;
3609 if (q->high_mark < 2)
3610 q->high_mark = 2;
3611
3612 q->first_empty = q->last_used = 0;
3613 q->reg_r = read;
3614 q->reg_w = write;
3615
3616 ipw_write32(priv, base, q->dma_addr);
3617 ipw_write32(priv, size, count);
3618 ipw_write32(priv, read, 0);
3619 ipw_write32(priv, write, 0);
3620
3621 _ipw_read32(priv, 0x90);
3622}
3623
Jeff Garzikbf794512005-07-31 13:07:26 -04003624static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003625 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003626 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003627{
3628 struct pci_dev *dev = priv->pci_dev;
3629
3630 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3631 if (!q->txb) {
3632 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3633 return -ENOMEM;
3634 }
3635
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003636 q->bd =
3637 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003638 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003639 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003640 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003641 kfree(q->txb);
3642 q->txb = NULL;
3643 return -ENOMEM;
3644 }
3645
3646 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3647 return 0;
3648}
3649
3650/**
3651 * Free one TFD, those at index [txq->q.last_used].
3652 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003653 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003654 * @param dev
3655 * @param txq
3656 */
3657static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3658 struct clx2_tx_queue *txq)
3659{
3660 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3661 struct pci_dev *dev = priv->pci_dev;
3662 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003663
James Ketrenos43f66a62005-03-25 12:31:53 -06003664 /* classify bd */
3665 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3666 /* nothing to cleanup after for host commands */
3667 return;
3668
3669 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003670 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3671 IPW_ERROR("Too many chunks: %i\n",
3672 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003673 /** @todo issue fatal error, it is quite serious situation */
3674 return;
3675 }
3676
3677 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003678 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3679 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3680 le16_to_cpu(bd->u.data.chunk_len[i]),
3681 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003682 if (txq->txb[txq->q.last_used]) {
3683 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3684 txq->txb[txq->q.last_used] = NULL;
3685 }
3686 }
3687}
3688
3689/**
3690 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003691 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003692 * Empty queue by removing and destroying all BD's.
3693 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003694 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003695 * @param dev
3696 * @param q
3697 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003698static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003699{
3700 struct clx2_queue *q = &txq->q;
3701 struct pci_dev *dev = priv->pci_dev;
3702
Jeff Garzikbf794512005-07-31 13:07:26 -04003703 if (q->n_bd == 0)
3704 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003705
3706 /* first, empty all BD's */
3707 for (; q->first_empty != q->last_used;
3708 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3709 ipw_queue_tx_free_tfd(priv, txq);
3710 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003711
James Ketrenos43f66a62005-03-25 12:31:53 -06003712 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003713 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003714 q->dma_addr);
3715 kfree(txq->txb);
3716
3717 /* 0 fill whole structure */
3718 memset(txq, 0, sizeof(*txq));
3719}
3720
James Ketrenos43f66a62005-03-25 12:31:53 -06003721/**
3722 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003723 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003724 * @param priv
3725 */
3726static void ipw_tx_queue_free(struct ipw_priv *priv)
3727{
3728 /* Tx CMD queue */
3729 ipw_queue_tx_free(priv, &priv->txq_cmd);
3730
3731 /* Tx queues */
3732 ipw_queue_tx_free(priv, &priv->txq[0]);
3733 ipw_queue_tx_free(priv, &priv->txq[1]);
3734 ipw_queue_tx_free(priv, &priv->txq[2]);
3735 ipw_queue_tx_free(priv, &priv->txq[3]);
3736}
3737
Arjan van de Ven858119e2006-01-14 13:20:43 -08003738static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003739{
3740 /* First 3 bytes are manufacturer */
3741 bssid[0] = priv->mac_addr[0];
3742 bssid[1] = priv->mac_addr[1];
3743 bssid[2] = priv->mac_addr[2];
3744
3745 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003746 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003747
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003748 bssid[0] &= 0xfe; /* clear multicast bit */
3749 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003750}
3751
Arjan van de Ven858119e2006-01-14 13:20:43 -08003752static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003753{
3754 struct ipw_station_entry entry;
3755 int i;
3756
3757 for (i = 0; i < priv->num_stations; i++) {
3758 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3759 /* Another node is active in network */
3760 priv->missed_adhoc_beacons = 0;
3761 if (!(priv->config & CFG_STATIC_CHANNEL))
3762 /* when other nodes drop out, we drop out */
3763 priv->config &= ~CFG_ADHOC_PERSIST;
3764
3765 return i;
3766 }
3767 }
3768
3769 if (i == MAX_STATIONS)
3770 return IPW_INVALID_STATION;
3771
3772 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3773
3774 entry.reserved = 0;
3775 entry.support_mode = 0;
3776 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3777 memcpy(priv->stations[i], bssid, ETH_ALEN);
3778 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003779 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003780 priv->num_stations++;
3781
3782 return i;
3783}
3784
Arjan van de Ven858119e2006-01-14 13:20:43 -08003785static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003786{
3787 int i;
3788
Jeff Garzikbf794512005-07-31 13:07:26 -04003789 for (i = 0; i < priv->num_stations; i++)
3790 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003791 return i;
3792
3793 return IPW_INVALID_STATION;
3794}
3795
3796static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3797{
3798 int err;
3799
Hong Liu7b996592005-08-25 17:36:13 +08003800 if (priv->status & STATUS_ASSOCIATING) {
3801 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3802 queue_work(priv->workqueue, &priv->disassociate);
3803 return;
3804 }
3805
3806 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003807 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3808 return;
3809 }
3810
3811 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3812 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04003813 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06003814 priv->assoc_request.channel);
3815
3816 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3817 priv->status |= STATUS_DISASSOCIATING;
3818
3819 if (quiet)
3820 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3821 else
3822 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003823
James Ketrenos43f66a62005-03-25 12:31:53 -06003824 err = ipw_send_associate(priv, &priv->assoc_request);
3825 if (err) {
3826 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3827 "failed.\n");
3828 return;
3829 }
3830
3831}
3832
James Ketrenosc848d0a2005-08-24 21:56:24 -05003833static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003834{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003835 struct ipw_priv *priv = data;
3836 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3837 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003838 ipw_send_disassociate(data, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003839 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003840}
3841
James Ketrenosc848d0a2005-08-24 21:56:24 -05003842static void ipw_bg_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003843{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003844 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08003845 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003846 ipw_disassociate(data);
Zhu Yi46441512006-01-24 16:37:59 +08003847 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003848}
3849
Zhu Yid8bad6d2005-07-13 12:25:38 -05003850static void ipw_system_config(void *data)
3851{
3852 struct ipw_priv *priv = data;
Zhu Yid685b8c2006-04-13 17:20:27 +08003853
3854#ifdef CONFIG_IPW2200_PROMISCUOUS
3855 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
3856 priv->sys_config.accept_all_data_frames = 1;
3857 priv->sys_config.accept_non_directed_frames = 1;
3858 priv->sys_config.accept_all_mgmt_bcpr = 1;
3859 priv->sys_config.accept_all_mgmt_frames = 1;
3860 }
3861#endif
3862
3863 ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003864}
3865
3866struct ipw_status_code {
3867 u16 status;
3868 const char *reason;
3869};
3870
3871static const struct ipw_status_code ipw_status_codes[] = {
3872 {0x00, "Successful"},
3873 {0x01, "Unspecified failure"},
3874 {0x0A, "Cannot support all requested capabilities in the "
3875 "Capability information field"},
3876 {0x0B, "Reassociation denied due to inability to confirm that "
3877 "association exists"},
3878 {0x0C, "Association denied due to reason outside the scope of this "
3879 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003880 {0x0D,
3881 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003882 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003883 {0x0E,
3884 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003885 "transaction sequence number out of expected sequence"},
3886 {0x0F, "Authentication rejected because of challenge failure"},
3887 {0x10, "Authentication rejected due to timeout waiting for next "
3888 "frame in sequence"},
3889 {0x11, "Association denied because AP is unable to handle additional "
3890 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003891 {0x12,
3892 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003893 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003894 {0x13,
3895 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003896 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003897 {0x14,
3898 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003899 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003900 {0x15,
3901 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003902 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003903 {0x19,
3904 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003905 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003906 {0x1A,
3907 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003908 "DSSS-OFDM operation"},
3909 {0x28, "Invalid Information Element"},
3910 {0x29, "Group Cipher is not valid"},
3911 {0x2A, "Pairwise Cipher is not valid"},
3912 {0x2B, "AKMP is not valid"},
3913 {0x2C, "Unsupported RSN IE version"},
3914 {0x2D, "Invalid RSN IE Capabilities"},
3915 {0x2E, "Cipher suite is rejected per security policy"},
3916};
3917
Brice Goglin0f52bf92005-12-01 01:41:46 -08003918#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04003919static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003920{
3921 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003922 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003923 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003924 return ipw_status_codes[i].reason;
3925 return "Unknown status value.";
3926}
3927#endif
3928
3929static void inline average_init(struct average *avg)
3930{
3931 memset(avg, 0, sizeof(*avg));
3932}
3933
Zhu Yi00d21de2006-04-13 17:19:02 +08003934#define DEPTH_RSSI 8
3935#define DEPTH_NOISE 16
3936static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
3937{
3938 return ((depth-1)*prev_avg + val)/depth;
3939}
3940
Arjan van de Ven858119e2006-01-14 13:20:43 -08003941static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06003942{
3943 avg->sum -= avg->entries[avg->pos];
3944 avg->sum += val;
3945 avg->entries[avg->pos++] = val;
3946 if (unlikely(avg->pos == AVG_ENTRIES)) {
3947 avg->init = 1;
3948 avg->pos = 0;
3949 }
3950}
3951
Arjan van de Ven858119e2006-01-14 13:20:43 -08003952static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06003953{
3954 if (!unlikely(avg->init)) {
3955 if (avg->pos)
3956 return avg->sum / avg->pos;
3957 return 0;
3958 }
3959
3960 return avg->sum / AVG_ENTRIES;
3961}
3962
3963static void ipw_reset_stats(struct ipw_priv *priv)
3964{
3965 u32 len = sizeof(u32);
3966
3967 priv->quality = 0;
3968
3969 average_init(&priv->average_missed_beacons);
Zhu Yi00d21de2006-04-13 17:19:02 +08003970 priv->exp_avg_rssi = -60;
3971 priv->exp_avg_noise = -85 + 0x100;
James Ketrenos43f66a62005-03-25 12:31:53 -06003972
3973 priv->last_rate = 0;
3974 priv->last_missed_beacons = 0;
3975 priv->last_rx_packets = 0;
3976 priv->last_tx_packets = 0;
3977 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003978
James Ketrenos43f66a62005-03-25 12:31:53 -06003979 /* Firmware managed, reset only when NIC is restarted, so we have to
3980 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003981 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003982 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003983 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003984 &priv->last_tx_failures, &len);
3985
3986 /* Driver managed, reset with each association */
3987 priv->missed_adhoc_beacons = 0;
3988 priv->missed_beacons = 0;
3989 priv->tx_packets = 0;
3990 priv->rx_packets = 0;
3991
3992}
3993
Arjan van de Ven858119e2006-01-14 13:20:43 -08003994static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003995{
3996 u32 i = 0x80000000;
3997 u32 mask = priv->rates_mask;
3998 /* If currently associated in B mode, restrict the maximum
3999 * rate match to B rates */
4000 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
4001 mask &= IEEE80211_CCK_RATES_MASK;
4002
4003 /* TODO: Verify that the rate is supported by the current rates
4004 * list. */
4005
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004006 while (i && !(mask & i))
4007 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004008 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004009 case IEEE80211_CCK_RATE_1MB_MASK:
4010 return 1000000;
4011 case IEEE80211_CCK_RATE_2MB_MASK:
4012 return 2000000;
4013 case IEEE80211_CCK_RATE_5MB_MASK:
4014 return 5500000;
4015 case IEEE80211_OFDM_RATE_6MB_MASK:
4016 return 6000000;
4017 case IEEE80211_OFDM_RATE_9MB_MASK:
4018 return 9000000;
4019 case IEEE80211_CCK_RATE_11MB_MASK:
4020 return 11000000;
4021 case IEEE80211_OFDM_RATE_12MB_MASK:
4022 return 12000000;
4023 case IEEE80211_OFDM_RATE_18MB_MASK:
4024 return 18000000;
4025 case IEEE80211_OFDM_RATE_24MB_MASK:
4026 return 24000000;
4027 case IEEE80211_OFDM_RATE_36MB_MASK:
4028 return 36000000;
4029 case IEEE80211_OFDM_RATE_48MB_MASK:
4030 return 48000000;
4031 case IEEE80211_OFDM_RATE_54MB_MASK:
4032 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004033 }
4034
Jeff Garzikbf794512005-07-31 13:07:26 -04004035 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06004036 return 11000000;
4037 else
4038 return 54000000;
4039}
4040
4041static u32 ipw_get_current_rate(struct ipw_priv *priv)
4042{
4043 u32 rate, len = sizeof(rate);
4044 int err;
4045
Jeff Garzikbf794512005-07-31 13:07:26 -04004046 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06004047 return 0;
4048
4049 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004050 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06004051 &len);
4052 if (err) {
4053 IPW_DEBUG_INFO("failed querying ordinals.\n");
4054 return 0;
4055 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004056 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06004057 return ipw_get_max_rate(priv);
4058
4059 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004060 case IPW_TX_RATE_1MB:
4061 return 1000000;
4062 case IPW_TX_RATE_2MB:
4063 return 2000000;
4064 case IPW_TX_RATE_5MB:
4065 return 5500000;
4066 case IPW_TX_RATE_6MB:
4067 return 6000000;
4068 case IPW_TX_RATE_9MB:
4069 return 9000000;
4070 case IPW_TX_RATE_11MB:
4071 return 11000000;
4072 case IPW_TX_RATE_12MB:
4073 return 12000000;
4074 case IPW_TX_RATE_18MB:
4075 return 18000000;
4076 case IPW_TX_RATE_24MB:
4077 return 24000000;
4078 case IPW_TX_RATE_36MB:
4079 return 36000000;
4080 case IPW_TX_RATE_48MB:
4081 return 48000000;
4082 case IPW_TX_RATE_54MB:
4083 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004084 }
4085
4086 return 0;
4087}
4088
James Ketrenos43f66a62005-03-25 12:31:53 -06004089#define IPW_STATS_INTERVAL (2 * HZ)
4090static void ipw_gather_stats(struct ipw_priv *priv)
4091{
4092 u32 rx_err, rx_err_delta, rx_packets_delta;
4093 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4094 u32 missed_beacons_percent, missed_beacons_delta;
4095 u32 quality = 0;
4096 u32 len = sizeof(u32);
4097 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004098 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004099 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004100 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06004101
4102 if (!(priv->status & STATUS_ASSOCIATED)) {
4103 priv->quality = 0;
4104 return;
4105 }
4106
4107 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04004108 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06004109 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004110 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06004111 priv->last_missed_beacons = priv->missed_beacons;
4112 if (priv->assoc_request.beacon_interval) {
4113 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004114 (HZ * priv->assoc_request.beacon_interval) /
4115 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004116 } else {
4117 missed_beacons_percent = 0;
4118 }
4119 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4120
4121 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4122 rx_err_delta = rx_err - priv->last_rx_err;
4123 priv->last_rx_err = rx_err;
4124
4125 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4126 tx_failures_delta = tx_failures - priv->last_tx_failures;
4127 priv->last_tx_failures = tx_failures;
4128
4129 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4130 priv->last_rx_packets = priv->rx_packets;
4131
4132 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4133 priv->last_tx_packets = priv->tx_packets;
4134
4135 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004136 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004137 * Missed beacon: 100% = 0, 0% = 70% missed
4138 * Rate: 60% = 1Mbs, 100% = Max
4139 * Rx and Tx errors represent a straight % of total Rx/Tx
4140 * RSSI: 100% = > -50, 0% = < -80
4141 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004142 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004143 * The lowest computed quality is used.
4144 *
4145 */
4146#define BEACON_THRESHOLD 5
4147 beacon_quality = 100 - missed_beacons_percent;
4148 if (beacon_quality < BEACON_THRESHOLD)
4149 beacon_quality = 0;
4150 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004151 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004152 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004153 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004154 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004155
James Ketrenos43f66a62005-03-25 12:31:53 -06004156 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004157 max_rate = ipw_get_max_rate(priv);
4158 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004159 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4160 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004161
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004162 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004163 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004164 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004165 else
4166 rx_quality = 100;
4167 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4168 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004169
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004170 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004171 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004172 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004173 else
4174 tx_quality = 100;
4175 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4176 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004177
Zhu Yi00d21de2006-04-13 17:19:02 +08004178 rssi = priv->exp_avg_rssi;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004179 signal_quality =
4180 (100 *
4181 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4182 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4183 (priv->ieee->perfect_rssi - rssi) *
4184 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4185 62 * (priv->ieee->perfect_rssi - rssi))) /
4186 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4187 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4188 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004189 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004190 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004191 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004192
Zhu Yi61fb9ed2006-04-13 17:19:55 +08004193 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004194 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004195
4196 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06004197 min(rate_quality,
4198 min(tx_quality, min(rx_quality, signal_quality))));
4199 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004200 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4201 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004202 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004203 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4204 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004205 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004206 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4207 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004208 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004209 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4210 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004211 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004212 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4213 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004214
4215 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004216
4217 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004218 IPW_STATS_INTERVAL);
4219}
4220
James Ketrenosc848d0a2005-08-24 21:56:24 -05004221static void ipw_bg_gather_stats(void *data)
4222{
4223 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08004224 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004225 ipw_gather_stats(data);
Zhu Yi46441512006-01-24 16:37:59 +08004226 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004227}
4228
Ben Cahille7582562005-10-06 15:34:41 -05004229/* Missed beacon behavior:
4230 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4231 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4232 * Above disassociate threshold, give up and stop scanning.
4233 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004234static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004235 int missed_count)
4236{
4237 priv->notif_missed_beacons = missed_count;
4238
James Ketrenosafbf30a2005-08-25 00:05:33 -05004239 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004240 priv->status & STATUS_ASSOCIATED) {
4241 /* If associated and we've hit the missed
4242 * beacon threshold, disassociate, turn
4243 * off roaming, and abort any active scans */
4244 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004245 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004246 "Missed beacon: %d - disassociate\n", missed_count);
4247 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004248 if (priv->status & STATUS_SCANNING) {
4249 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4250 IPW_DL_STATE,
4251 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004252 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004253 }
4254
James Ketrenosea2b26e2005-08-24 21:25:16 -05004255 queue_work(priv->workqueue, &priv->disassociate);
4256 return;
4257 }
4258
4259 if (priv->status & STATUS_ROAMING) {
4260 /* If we are currently roaming, then just
4261 * print a debug statement... */
4262 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4263 "Missed beacon: %d - roam in progress\n",
4264 missed_count);
4265 return;
4266 }
4267
Zhu Yi4bfdb912006-01-24 16:37:16 +08004268 if (roaming &&
4269 (missed_count > priv->roaming_threshold &&
4270 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004271 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004272 * bit in the status and kick off a scan.
4273 * This can happen several times before we reach
4274 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004275 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4276 "Missed beacon: %d - initiate "
4277 "roaming\n", missed_count);
4278 if (!(priv->status & STATUS_ROAMING)) {
4279 priv->status |= STATUS_ROAMING;
4280 if (!(priv->status & STATUS_SCANNING))
4281 queue_work(priv->workqueue,
4282 &priv->request_scan);
4283 }
4284 return;
4285 }
4286
4287 if (priv->status & STATUS_SCANNING) {
4288 /* Stop scan to keep fw from getting
4289 * stuck (only if we aren't roaming --
4290 * otherwise we'll never scan more than 2 or 3
4291 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004292 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4293 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004294 queue_work(priv->workqueue, &priv->abort_scan);
4295 }
4296
4297 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004298}
4299
James Ketrenos43f66a62005-03-25 12:31:53 -06004300/**
4301 * Handle host notification packet.
4302 * Called from interrupt routine
4303 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004304static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004305 struct ipw_rx_notification *notif)
4306{
James Ketrenosa613bff2005-08-24 21:43:11 -05004307 notif->size = le16_to_cpu(notif->size);
4308
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004309 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004310
James Ketrenos43f66a62005-03-25 12:31:53 -06004311 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004312 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4313 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004314
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004315 switch (assoc->state) {
4316 case CMAS_ASSOCIATED:{
4317 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4318 IPW_DL_ASSOC,
4319 "associated: '%s' " MAC_FMT
4320 " \n",
4321 escape_essid(priv->essid,
4322 priv->essid_len),
4323 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04004324
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004325 switch (priv->ieee->iw_mode) {
4326 case IW_MODE_INFRA:
4327 memcpy(priv->ieee->bssid,
4328 priv->bssid, ETH_ALEN);
4329 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004330
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004331 case IW_MODE_ADHOC:
4332 memcpy(priv->ieee->bssid,
4333 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004334
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004335 /* clear out the station table */
4336 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004337
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004338 IPW_DEBUG_ASSOC
4339 ("queueing adhoc check\n");
4340 queue_delayed_work(priv->
4341 workqueue,
4342 &priv->
4343 adhoc_check,
4344 priv->
4345 assoc_request.
4346 beacon_interval);
4347 break;
4348 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004349
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004350 priv->status &= ~STATUS_ASSOCIATING;
4351 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004352 queue_work(priv->workqueue,
4353 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004354
Zhu Yie43e3c12006-04-13 17:20:45 +08004355#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004356#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4357 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4358 if ((priv->status & STATUS_AUTH) &&
4359 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4360 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004361 if ((sizeof
4362 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004363 ieee80211_assoc_response)
James Ketrenosb095c382005-08-24 22:04:42 -05004364 <= notif->size)
4365 && (notif->size <= 2314)) {
4366 struct
4367 ieee80211_rx_stats
4368 stats = {
4369 .len =
4370 notif->
4371 size - 1,
4372 };
4373
4374 IPW_DEBUG_QOS
4375 ("QoS Associate "
4376 "size %d\n",
4377 notif->size);
4378 ieee80211_rx_mgt(priv->
4379 ieee,
4380 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004381 ieee80211_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004382 *)
4383 &notif->u.raw, &stats);
4384 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004385 }
James Ketrenosb095c382005-08-24 22:04:42 -05004386#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004387
James Ketrenosa613bff2005-08-24 21:43:11 -05004388 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004389
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004390 break;
4391 }
4392
4393 case CMAS_AUTHENTICATED:{
4394 if (priv->
4395 status & (STATUS_ASSOCIATED |
4396 STATUS_AUTH)) {
Brice Goglin0f52bf92005-12-01 01:41:46 -08004397#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004398 struct notif_authenticate *auth
4399 = &notif->u.auth;
4400 IPW_DEBUG(IPW_DL_NOTIF |
4401 IPW_DL_STATE |
4402 IPW_DL_ASSOC,
4403 "deauthenticated: '%s' "
4404 MAC_FMT
4405 ": (0x%04X) - %s \n",
4406 escape_essid(priv->
4407 essid,
4408 priv->
4409 essid_len),
4410 MAC_ARG(priv->bssid),
4411 ntohs(auth->status),
4412 ipw_get_status_code
4413 (ntohs
4414 (auth->status)));
4415#endif
4416
4417 priv->status &=
4418 ~(STATUS_ASSOCIATING |
4419 STATUS_AUTH |
4420 STATUS_ASSOCIATED);
4421
James Ketrenosa613bff2005-08-24 21:43:11 -05004422 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004423 break;
4424 }
4425
4426 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4427 IPW_DL_ASSOC,
4428 "authenticated: '%s' " MAC_FMT
4429 "\n",
4430 escape_essid(priv->essid,
4431 priv->essid_len),
4432 MAC_ARG(priv->bssid));
4433 break;
4434 }
4435
4436 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004437 if (priv->status & STATUS_AUTH) {
4438 struct
4439 ieee80211_assoc_response
4440 *resp;
4441 resp =
4442 (struct
4443 ieee80211_assoc_response
4444 *)&notif->u.raw;
4445 IPW_DEBUG(IPW_DL_NOTIF |
4446 IPW_DL_STATE |
4447 IPW_DL_ASSOC,
4448 "association failed (0x%04X): %s\n",
4449 ntohs(resp->status),
4450 ipw_get_status_code
4451 (ntohs
4452 (resp->status)));
4453 }
4454
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004455 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4456 IPW_DL_ASSOC,
4457 "disassociated: '%s' " MAC_FMT
4458 " \n",
4459 escape_essid(priv->essid,
4460 priv->essid_len),
4461 MAC_ARG(priv->bssid));
4462
4463 priv->status &=
4464 ~(STATUS_DISASSOCIATING |
4465 STATUS_ASSOCIATING |
4466 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004467 if (priv->assoc_network
4468 && (priv->assoc_network->
4469 capability &
4470 WLAN_CAPABILITY_IBSS))
4471 ipw_remove_current_network
4472 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004473
James Ketrenosa613bff2005-08-24 21:43:11 -05004474 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004475
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004476 break;
4477 }
4478
James Ketrenosb095c382005-08-24 22:04:42 -05004479 case CMAS_RX_ASSOC_RESP:
4480 break;
4481
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004482 default:
4483 IPW_ERROR("assoc: unknown (%d)\n",
4484 assoc->state);
4485 break;
4486 }
4487
James Ketrenos43f66a62005-03-25 12:31:53 -06004488 break;
4489 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004490
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004491 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4492 struct notif_authenticate *auth = &notif->u.auth;
4493 switch (auth->state) {
4494 case CMAS_AUTHENTICATED:
4495 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4496 "authenticated: '%s' " MAC_FMT " \n",
4497 escape_essid(priv->essid,
4498 priv->essid_len),
4499 MAC_ARG(priv->bssid));
4500 priv->status |= STATUS_AUTH;
4501 break;
4502
4503 case CMAS_INIT:
4504 if (priv->status & STATUS_AUTH) {
4505 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4506 IPW_DL_ASSOC,
4507 "authentication failed (0x%04X): %s\n",
4508 ntohs(auth->status),
4509 ipw_get_status_code(ntohs
4510 (auth->
4511 status)));
4512 }
4513 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4514 IPW_DL_ASSOC,
4515 "deauthenticated: '%s' " MAC_FMT "\n",
4516 escape_essid(priv->essid,
4517 priv->essid_len),
4518 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004519
4520 priv->status &= ~(STATUS_ASSOCIATING |
4521 STATUS_AUTH |
4522 STATUS_ASSOCIATED);
4523
James Ketrenosa613bff2005-08-24 21:43:11 -05004524 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004525 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004526
4527 case CMAS_TX_AUTH_SEQ_1:
4528 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4529 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4530 break;
4531 case CMAS_RX_AUTH_SEQ_2:
4532 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4533 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4534 break;
4535 case CMAS_AUTH_SEQ_1_PASS:
4536 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4537 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4538 break;
4539 case CMAS_AUTH_SEQ_1_FAIL:
4540 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4541 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4542 break;
4543 case CMAS_TX_AUTH_SEQ_3:
4544 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4545 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4546 break;
4547 case CMAS_RX_AUTH_SEQ_4:
4548 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4549 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4550 break;
4551 case CMAS_AUTH_SEQ_2_PASS:
4552 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4553 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4554 break;
4555 case CMAS_AUTH_SEQ_2_FAIL:
4556 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4557 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4558 break;
4559 case CMAS_TX_ASSOC:
4560 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4561 IPW_DL_ASSOC, "TX_ASSOC\n");
4562 break;
4563 case CMAS_RX_ASSOC_RESP:
4564 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4565 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004566
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004567 break;
4568 case CMAS_ASSOCIATED:
4569 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4570 IPW_DL_ASSOC, "ASSOCIATED\n");
4571 break;
4572 default:
4573 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4574 auth->state);
4575 break;
4576 }
4577 break;
4578 }
4579
4580 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4581 struct notif_channel_result *x =
4582 &notif->u.channel_result;
4583
4584 if (notif->size == sizeof(*x)) {
4585 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4586 x->channel_num);
4587 } else {
4588 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4589 "(should be %zd)\n",
4590 notif->size, sizeof(*x));
4591 }
4592 break;
4593 }
4594
4595 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4596 struct notif_scan_complete *x = &notif->u.scan_complete;
4597 if (notif->size == sizeof(*x)) {
4598 IPW_DEBUG_SCAN
4599 ("Scan completed: type %d, %d channels, "
4600 "%d status\n", x->scan_type,
4601 x->num_channels, x->status);
4602 } else {
4603 IPW_ERROR("Scan completed of wrong size %d "
4604 "(should be %zd)\n",
4605 notif->size, sizeof(*x));
4606 }
4607
4608 priv->status &=
4609 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4610
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004611 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004612 cancel_delayed_work(&priv->scan_check);
4613
James Ketrenosb095c382005-08-24 22:04:42 -05004614 if (priv->status & STATUS_EXIT_PENDING)
4615 break;
4616
4617 priv->ieee->scans++;
4618
4619#ifdef CONFIG_IPW2200_MONITOR
4620 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004621 priv->status |= STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004622 queue_work(priv->workqueue,
4623 &priv->request_scan);
4624 break;
4625 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004626 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004627#endif /* CONFIG_IPW2200_MONITOR */
4628
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004629 if (!(priv->status & (STATUS_ASSOCIATED |
4630 STATUS_ASSOCIATING |
4631 STATUS_ROAMING |
4632 STATUS_DISASSOCIATING)))
4633 queue_work(priv->workqueue, &priv->associate);
4634 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004635 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4636 /* If a scan completed and we are in roam mode, then
4637 * the scan that completed was the one requested as a
4638 * result of entering roam... so, schedule the
4639 * roam work */
4640 queue_work(priv->workqueue,
4641 &priv->roam);
4642 else
4643 /* Don't schedule if we aborted the scan */
4644 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004645 } else if (priv->status & STATUS_SCAN_PENDING)
4646 queue_work(priv->workqueue,
4647 &priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004648 else if (priv->config & CFG_BACKGROUND_SCAN
4649 && priv->status & STATUS_ASSOCIATED)
4650 queue_delayed_work(priv->workqueue,
4651 &priv->request_scan, HZ);
Zhu Yi07f02e42006-04-13 17:19:25 +08004652
4653 /* Send an empty event to user space.
4654 * We don't send the received data on the event because
4655 * it would require us to do complex transcoding, and
4656 * we want to minimise the work done in the irq handler
4657 * Use a request to extract the data.
4658 * Also, we generate this even for any scan, regardless
4659 * on how the scan was initiated. User space can just
4660 * sync on periodic scan to get fresh data...
4661 * Jean II */
4662 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) {
4663 union iwreq_data wrqu;
4664
4665 wrqu.data.length = 0;
4666 wrqu.data.flags = 0;
4667 wireless_send_event(priv->net_dev, SIOCGIWSCAN,
4668 &wrqu, NULL);
4669 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004670 break;
4671 }
4672
4673 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4674 struct notif_frag_length *x = &notif->u.frag_len;
4675
James Ketrenosa613bff2005-08-24 21:43:11 -05004676 if (notif->size == sizeof(*x))
4677 IPW_ERROR("Frag length: %d\n",
4678 le16_to_cpu(x->frag_length));
4679 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004680 IPW_ERROR("Frag length of wrong size %d "
4681 "(should be %zd)\n",
4682 notif->size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004683 break;
4684 }
4685
4686 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4687 struct notif_link_deterioration *x =
4688 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004689
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004690 if (notif->size == sizeof(*x)) {
4691 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Cahill, Ben M12977152006-03-08 02:58:02 +08004692 "link deterioration: type %d, cnt %d\n",
4693 x->silence_notification_type,
4694 x->silence_count);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004695 memcpy(&priv->last_link_deterioration, x,
4696 sizeof(*x));
4697 } else {
4698 IPW_ERROR("Link Deterioration of wrong size %d "
4699 "(should be %zd)\n",
4700 notif->size, sizeof(*x));
4701 }
4702 break;
4703 }
4704
4705 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4706 IPW_ERROR("Dino config\n");
4707 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004708 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004709 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004710
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004711 break;
4712 }
4713
4714 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4715 struct notif_beacon_state *x = &notif->u.beacon_state;
4716 if (notif->size != sizeof(*x)) {
4717 IPW_ERROR
4718 ("Beacon state of wrong size %d (should "
4719 "be %zd)\n", notif->size, sizeof(*x));
4720 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004721 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004722
James Ketrenosa613bff2005-08-24 21:43:11 -05004723 if (le32_to_cpu(x->state) ==
4724 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4725 ipw_handle_missed_beacon(priv,
4726 le32_to_cpu(x->
4727 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004728
James Ketrenos43f66a62005-03-25 12:31:53 -06004729 break;
4730 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004731
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004732 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4733 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
4734 if (notif->size == sizeof(*x)) {
4735 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4736 "0x%02x station %d\n",
4737 x->key_state, x->security_type,
4738 x->station_index);
4739 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004740 }
4741
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004742 IPW_ERROR
4743 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4744 notif->size, sizeof(*x));
4745 break;
4746 }
4747
4748 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4749 struct notif_calibration *x = &notif->u.calibration;
4750
4751 if (notif->size == sizeof(*x)) {
4752 memcpy(&priv->calib, x, sizeof(*x));
4753 IPW_DEBUG_INFO("TODO: Calibration\n");
4754 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004755 }
4756
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004757 IPW_ERROR
4758 ("Calibration of wrong size %d (should be %zd)\n",
4759 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004760 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004761 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004762
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004763 case HOST_NOTIFICATION_NOISE_STATS:{
4764 if (notif->size == sizeof(u32)) {
Zhu Yi00d21de2006-04-13 17:19:02 +08004765 priv->exp_avg_noise =
4766 exponential_average(priv->exp_avg_noise,
4767 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4768 DEPTH_NOISE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004769 break;
4770 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004771
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004772 IPW_ERROR
4773 ("Noise stat is wrong size %d (should be %zd)\n",
4774 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004775 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004776 }
4777
James Ketrenos43f66a62005-03-25 12:31:53 -06004778 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004779 IPW_DEBUG_NOTIF("Unknown notification: "
4780 "subtype=%d,flags=0x%2x,size=%d\n",
4781 notif->subtype, notif->flags, notif->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004782 }
4783}
4784
4785/**
4786 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004787 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004788 * @param priv
4789 * @return error code
4790 */
4791static int ipw_queue_reset(struct ipw_priv *priv)
4792{
4793 int rc = 0;
4794 /** @todo customize queue sizes */
4795 int nTx = 64, nTxCmd = 8;
4796 ipw_tx_queue_free(priv);
4797 /* Tx CMD queue */
4798 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004799 IPW_TX_CMD_QUEUE_READ_INDEX,
4800 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4801 IPW_TX_CMD_QUEUE_BD_BASE,
4802 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004803 if (rc) {
4804 IPW_ERROR("Tx Cmd queue init failed\n");
4805 goto error;
4806 }
4807 /* Tx queue(s) */
4808 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004809 IPW_TX_QUEUE_0_READ_INDEX,
4810 IPW_TX_QUEUE_0_WRITE_INDEX,
4811 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004812 if (rc) {
4813 IPW_ERROR("Tx 0 queue init failed\n");
4814 goto error;
4815 }
4816 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004817 IPW_TX_QUEUE_1_READ_INDEX,
4818 IPW_TX_QUEUE_1_WRITE_INDEX,
4819 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004820 if (rc) {
4821 IPW_ERROR("Tx 1 queue init failed\n");
4822 goto error;
4823 }
4824 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004825 IPW_TX_QUEUE_2_READ_INDEX,
4826 IPW_TX_QUEUE_2_WRITE_INDEX,
4827 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004828 if (rc) {
4829 IPW_ERROR("Tx 2 queue init failed\n");
4830 goto error;
4831 }
4832 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004833 IPW_TX_QUEUE_3_READ_INDEX,
4834 IPW_TX_QUEUE_3_WRITE_INDEX,
4835 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004836 if (rc) {
4837 IPW_ERROR("Tx 3 queue init failed\n");
4838 goto error;
4839 }
4840 /* statistics */
4841 priv->rx_bufs_min = 0;
4842 priv->rx_pend_max = 0;
4843 return rc;
4844
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004845 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004846 ipw_tx_queue_free(priv);
4847 return rc;
4848}
4849
4850/**
4851 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004852 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004853 * When FW adwances 'R' index, all entries between old and
4854 * new 'R' index need to be reclaimed. As result, some free space
4855 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004856 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004857 * @note Need to protect against garbage in 'R' index
4858 * @param priv
4859 * @param txq
4860 * @param qindex
4861 * @return Number of used entries remains in the queue
4862 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004863static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004864 struct clx2_tx_queue *txq, int qindex)
4865{
4866 u32 hw_tail;
4867 int used;
4868 struct clx2_queue *q = &txq->q;
4869
4870 hw_tail = ipw_read32(priv, q->reg_r);
4871 if (hw_tail >= q->n_bd) {
4872 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004873 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4874 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004875 goto done;
4876 }
4877 for (; q->last_used != hw_tail;
4878 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4879 ipw_queue_tx_free_tfd(priv, txq);
4880 priv->tx_packets++;
4881 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004882 done:
James Ketrenos9ddf84f2005-08-16 17:07:11 -05004883 if ((ipw_queue_space(q) > q->low_mark) &&
4884 (qindex >= 0) &&
4885 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4886 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06004887 used = q->first_empty - q->last_used;
4888 if (used < 0)
4889 used += q->n_bd;
4890
4891 return used;
4892}
4893
4894static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4895 int len, int sync)
4896{
4897 struct clx2_tx_queue *txq = &priv->txq_cmd;
4898 struct clx2_queue *q = &txq->q;
4899 struct tfd_frame *tfd;
4900
4901 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4902 IPW_ERROR("No space for Tx\n");
4903 return -EBUSY;
4904 }
4905
4906 tfd = &txq->bd[q->first_empty];
4907 txq->txb[q->first_empty] = NULL;
4908
4909 memset(tfd, 0, sizeof(*tfd));
4910 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4911 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4912 priv->hcmd_seq++;
4913 tfd->u.cmd.index = hcmd;
4914 tfd->u.cmd.length = len;
4915 memcpy(tfd->u.cmd.payload, buf, len);
4916 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4917 ipw_write32(priv, q->reg_w, q->first_empty);
4918 _ipw_read32(priv, 0x90);
4919
4920 return 0;
4921}
4922
Jeff Garzikbf794512005-07-31 13:07:26 -04004923/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004924 * Rx theory of operation
4925 *
4926 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05004927 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06004928 * 0 to 31
4929 *
4930 * Rx Queue Indexes
4931 * The host/firmware share two index registers for managing the Rx buffers.
4932 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004933 * The READ index maps to the first position that the firmware may be writing
4934 * to -- the driver can read up to (but not including) this position and get
4935 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06004936 * The READ index is managed by the firmware once the card is enabled.
4937 *
4938 * The WRITE index maps to the last position the driver has read from -- the
4939 * position preceding WRITE is the last slot the firmware can place a packet.
4940 *
4941 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04004942 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06004943 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004944 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06004945 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4946 *
4947 * When the firmware places a packet in a buffer it will advance the READ index
4948 * and fire the RX interrupt. The driver can then query the READ index and
4949 * process as many packets as possible, moving the WRITE index forward as it
4950 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04004951 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004952 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004953 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06004954 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04004955 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06004956 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4957 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4958 * 'processed' and 'read' driver indexes as well)
4959 * + A received packet is processed and handed to the kernel network stack,
4960 * detached from the ipw->rxq. The driver 'processed' index is updated.
4961 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04004962 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4963 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06004964 * were enough free buffers and RX_STALLED is set it is cleared.
4965 *
4966 *
4967 * Driver sequence:
4968 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004969 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06004970 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4971 * ipw_rx_queue_restock
4972 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4973 * queue, updates firmware pointers, and updates
4974 * the WRITE index. If insufficient rx_free buffers
4975 * are available, schedules ipw_rx_queue_replenish
4976 *
4977 * -- enable interrupts --
4978 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04004979 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06004980 * Moves the packet buffer from queue to rx_used.
4981 * Calls ipw_rx_queue_restock to refill any empty
4982 * slots.
4983 * ...
4984 *
4985 */
4986
Jeff Garzikbf794512005-07-31 13:07:26 -04004987/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004988 * If there are slots in the RX queue that need to be restocked,
4989 * and we have free pre-allocated buffers, fill the ranks as much
4990 * as we can pulling from rx_free.
4991 *
4992 * This moves the 'write' index forward to catch up with 'processed', and
4993 * also updates the memory address in the firmware to reference the new
4994 * target buffer.
4995 */
4996static void ipw_rx_queue_restock(struct ipw_priv *priv)
4997{
4998 struct ipw_rx_queue *rxq = priv->rxq;
4999 struct list_head *element;
5000 struct ipw_rx_mem_buffer *rxb;
5001 unsigned long flags;
5002 int write;
5003
5004 spin_lock_irqsave(&rxq->lock, flags);
5005 write = rxq->write;
5006 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
5007 element = rxq->rx_free.next;
5008 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5009 list_del(element);
5010
James Ketrenosb095c382005-08-24 22:04:42 -05005011 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06005012 rxb->dma_addr);
5013 rxq->queue[rxq->write] = rxb;
5014 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5015 rxq->free_count--;
5016 }
5017 spin_unlock_irqrestore(&rxq->lock, flags);
5018
Jeff Garzikbf794512005-07-31 13:07:26 -04005019 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06005020 * refill it */
5021 if (rxq->free_count <= RX_LOW_WATERMARK)
5022 queue_work(priv->workqueue, &priv->rx_replenish);
5023
5024 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04005025 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05005026 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06005027}
5028
5029/*
5030 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04005031 * Also restock the Rx queue via ipw_rx_queue_restock.
5032 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005033 * This is called as a scheduled work item (except for during intialization)
5034 */
5035static void ipw_rx_queue_replenish(void *data)
5036{
5037 struct ipw_priv *priv = data;
5038 struct ipw_rx_queue *rxq = priv->rxq;
5039 struct list_head *element;
5040 struct ipw_rx_mem_buffer *rxb;
5041 unsigned long flags;
5042
5043 spin_lock_irqsave(&rxq->lock, flags);
5044 while (!list_empty(&rxq->rx_used)) {
5045 element = rxq->rx_used.next;
5046 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05005047 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06005048 if (!rxb->skb) {
5049 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5050 priv->net_dev->name);
5051 /* We don't reschedule replenish work here -- we will
5052 * call the restock method and if it still needs
5053 * more buffers it will schedule replenish */
5054 break;
5055 }
5056 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04005057
James Ketrenos43f66a62005-03-25 12:31:53 -06005058 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005059 rxb->dma_addr =
5060 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05005061 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04005062
James Ketrenos43f66a62005-03-25 12:31:53 -06005063 list_add_tail(&rxb->list, &rxq->rx_free);
5064 rxq->free_count++;
5065 }
5066 spin_unlock_irqrestore(&rxq->lock, flags);
5067
5068 ipw_rx_queue_restock(priv);
5069}
5070
James Ketrenosc848d0a2005-08-24 21:56:24 -05005071static void ipw_bg_rx_queue_replenish(void *data)
5072{
5073 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08005074 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005075 ipw_rx_queue_replenish(data);
Zhu Yi46441512006-01-24 16:37:59 +08005076 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005077}
5078
James Ketrenos43f66a62005-03-25 12:31:53 -06005079/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08005080 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04005081 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06005082 * non NULL it is unmapped and freed
5083 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005084static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06005085{
5086 int i;
5087
5088 if (!rxq)
5089 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005090
James Ketrenos43f66a62005-03-25 12:31:53 -06005091 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5092 if (rxq->pool[i].skb != NULL) {
5093 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05005094 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005095 dev_kfree_skb(rxq->pool[i].skb);
5096 }
5097 }
5098
5099 kfree(rxq);
5100}
5101
5102static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5103{
5104 struct ipw_rx_queue *rxq;
5105 int i;
5106
Takisc75f4742005-12-01 01:41:45 -08005107 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02005108 if (unlikely(!rxq)) {
5109 IPW_ERROR("memory allocation failed\n");
5110 return NULL;
5111 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005112 spin_lock_init(&rxq->lock);
5113 INIT_LIST_HEAD(&rxq->rx_free);
5114 INIT_LIST_HEAD(&rxq->rx_used);
5115
5116 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04005117 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06005118 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5119
5120 /* Set us so that we have processed and used all buffers, but have
5121 * not restocked the Rx queue with fresh buffers */
5122 rxq->read = rxq->write = 0;
5123 rxq->processed = RX_QUEUE_SIZE - 1;
5124 rxq->free_count = 0;
5125
5126 return rxq;
5127}
5128
5129static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5130{
5131 rate &= ~IEEE80211_BASIC_RATE_MASK;
5132 if (ieee_mode == IEEE_A) {
5133 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005134 case IEEE80211_OFDM_RATE_6MB:
5135 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005136 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005137 case IEEE80211_OFDM_RATE_9MB:
5138 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005139 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005140 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005141 return priv->
5142 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005143 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005144 return priv->
5145 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005146 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005147 return priv->
5148 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005149 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005150 return priv->
5151 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005152 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005153 return priv->
5154 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005155 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005156 return priv->
5157 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005158 default:
5159 return 0;
5160 }
5161 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005162
James Ketrenos43f66a62005-03-25 12:31:53 -06005163 /* B and G mixed */
5164 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005165 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005166 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005167 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005168 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005169 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005170 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005171 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005172 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
5173 }
5174
5175 /* If we are limited to B modulations, bail at this point */
5176 if (ieee_mode == IEEE_B)
5177 return 0;
5178
5179 /* G */
5180 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005181 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005182 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005183 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005184 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005185 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005186 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005187 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005188 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005189 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005190 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005191 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005192 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005193 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005194 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005195 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005196 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5197 }
5198
5199 return 0;
5200}
5201
Jeff Garzikbf794512005-07-31 13:07:26 -04005202static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005203 const struct ieee80211_network *network,
5204 struct ipw_supported_rates *rates)
5205{
5206 int num_rates, i;
5207
5208 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005209 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005210 rates->num_rates = 0;
5211 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005212 if (!ipw_is_rate_in_mask(priv, network->mode,
5213 network->rates[i])) {
5214
James Ketrenosea2b26e2005-08-24 21:25:16 -05005215 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005216 IPW_DEBUG_SCAN("Adding masked mandatory "
5217 "rate %02X\n",
5218 network->rates[i]);
5219 rates->supported_rates[rates->num_rates++] =
5220 network->rates[i];
5221 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005222 }
5223
James Ketrenos43f66a62005-03-25 12:31:53 -06005224 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5225 network->rates[i], priv->rates_mask);
5226 continue;
5227 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005228
James Ketrenos43f66a62005-03-25 12:31:53 -06005229 rates->supported_rates[rates->num_rates++] = network->rates[i];
5230 }
5231
James Ketrenosa613bff2005-08-24 21:43:11 -05005232 num_rates = min(network->rates_ex_len,
5233 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005234 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005235 if (!ipw_is_rate_in_mask(priv, network->mode,
5236 network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005237 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005238 IPW_DEBUG_SCAN("Adding masked mandatory "
5239 "rate %02X\n",
5240 network->rates_ex[i]);
5241 rates->supported_rates[rates->num_rates++] =
5242 network->rates[i];
5243 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005244 }
5245
James Ketrenos43f66a62005-03-25 12:31:53 -06005246 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5247 network->rates_ex[i], priv->rates_mask);
5248 continue;
5249 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005250
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005251 rates->supported_rates[rates->num_rates++] =
5252 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005253 }
5254
James Ketrenosea2b26e2005-08-24 21:25:16 -05005255 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005256}
5257
Arjan van de Ven858119e2006-01-14 13:20:43 -08005258static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005259 const struct ipw_supported_rates *src)
5260{
5261 u8 i;
5262 for (i = 0; i < src->num_rates; i++)
5263 dest->supported_rates[i] = src->supported_rates[i];
5264 dest->num_rates = src->num_rates;
5265}
5266
5267/* TODO: Look at sniffed packets in the air to determine if the basic rate
5268 * mask should ever be used -- right now all callers to add the scan rates are
5269 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5270static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005271 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005272{
Jeff Garzikbf794512005-07-31 13:07:26 -04005273 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005274 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005275
James Ketrenos43f66a62005-03-25 12:31:53 -06005276 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005277 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005278 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005279
5280 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005281 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005282 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005283
5284 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005285 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005286 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005287
5288 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005289 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005290 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005291}
5292
5293static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005294 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005295{
Jeff Garzikbf794512005-07-31 13:07:26 -04005296 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005297 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005298
5299 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005300 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005301 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005302
5303 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005304 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005305 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005306
5307 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005308 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005309 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005310
5311 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005312 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005313 IEEE80211_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005314
5315 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005316 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005317 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005318
5319 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005320 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005321 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005322
5323 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005324 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005325 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005326
5327 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005328 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005329 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005330}
5331
5332struct ipw_network_match {
5333 struct ieee80211_network *network;
5334 struct ipw_supported_rates rates;
5335};
5336
James Ketrenosc848d0a2005-08-24 21:56:24 -05005337static int ipw_find_adhoc_network(struct ipw_priv *priv,
5338 struct ipw_network_match *match,
5339 struct ieee80211_network *network,
5340 int roaming)
5341{
5342 struct ipw_supported_rates rates;
5343
5344 /* Verify that this network's capability is compatible with the
5345 * current mode (AdHoc or Infrastructure) */
5346 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5347 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5348 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5349 "capability mismatch.\n",
5350 escape_essid(network->ssid, network->ssid_len),
5351 MAC_ARG(network->bssid));
5352 return 0;
5353 }
5354
5355 /* If we do not have an ESSID for this AP, we can not associate with
5356 * it */
5357 if (network->flags & NETWORK_EMPTY_ESSID) {
5358 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5359 "because of hidden ESSID.\n",
5360 escape_essid(network->ssid, network->ssid_len),
5361 MAC_ARG(network->bssid));
5362 return 0;
5363 }
5364
5365 if (unlikely(roaming)) {
5366 /* If we are roaming, then ensure check if this is a valid
5367 * network to try and roam to */
5368 if ((network->ssid_len != match->network->ssid_len) ||
5369 memcmp(network->ssid, match->network->ssid,
5370 network->ssid_len)) {
5371 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5372 "because of non-network ESSID.\n",
5373 escape_essid(network->ssid,
5374 network->ssid_len),
5375 MAC_ARG(network->bssid));
5376 return 0;
5377 }
5378 } else {
5379 /* If an ESSID has been configured then compare the broadcast
5380 * ESSID to ours */
5381 if ((priv->config & CFG_STATIC_ESSID) &&
5382 ((network->ssid_len != priv->essid_len) ||
5383 memcmp(network->ssid, priv->essid,
5384 min(network->ssid_len, priv->essid_len)))) {
5385 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005386
James Ketrenosc848d0a2005-08-24 21:56:24 -05005387 strncpy(escaped,
5388 escape_essid(network->ssid, network->ssid_len),
5389 sizeof(escaped));
5390 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5391 "because of ESSID mismatch: '%s'.\n",
5392 escaped, MAC_ARG(network->bssid),
5393 escape_essid(priv->essid,
5394 priv->essid_len));
5395 return 0;
5396 }
5397 }
5398
5399 /* If the old network rate is better than this one, don't bother
5400 * testing everything else. */
5401
5402 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005403 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5404 "current network.\n",
5405 escape_essid(match->network->ssid,
5406 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005407 return 0;
5408 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005409 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5410 "current network.\n",
5411 escape_essid(match->network->ssid,
5412 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005413 return 0;
5414 }
5415
5416 /* Now go through and see if the requested network is valid... */
5417 if (priv->ieee->scan_age != 0 &&
5418 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5419 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005420 "because of age: %ums.\n",
James Ketrenosc848d0a2005-08-24 21:56:24 -05005421 escape_essid(network->ssid, network->ssid_len),
5422 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005423 jiffies_to_msecs(jiffies -
5424 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005425 return 0;
5426 }
5427
5428 if ((priv->config & CFG_STATIC_CHANNEL) &&
5429 (network->channel != priv->channel)) {
5430 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5431 "because of channel mismatch: %d != %d.\n",
5432 escape_essid(network->ssid, network->ssid_len),
5433 MAC_ARG(network->bssid),
5434 network->channel, priv->channel);
5435 return 0;
5436 }
5437
5438 /* Verify privacy compatability */
5439 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5440 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5441 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5442 "because of privacy mismatch: %s != %s.\n",
5443 escape_essid(network->ssid, network->ssid_len),
5444 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005445 priv->
5446 capability & CAP_PRIVACY_ON ? "on" : "off",
5447 network->
5448 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5449 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005450 return 0;
5451 }
5452
5453 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5454 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5455 "because of the same BSSID match: " MAC_FMT
5456 ".\n", escape_essid(network->ssid,
5457 network->ssid_len),
5458 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5459 return 0;
5460 }
5461
5462 /* Filter out any incompatible freq / mode combinations */
5463 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5464 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5465 "because of invalid frequency/mode "
5466 "combination.\n",
5467 escape_essid(network->ssid, network->ssid_len),
5468 MAC_ARG(network->bssid));
5469 return 0;
5470 }
5471
5472 /* Ensure that the rates supported by the driver are compatible with
5473 * this AP, including verification of basic rates (mandatory) */
5474 if (!ipw_compatible_rates(priv, network, &rates)) {
5475 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5476 "because configured rate mask excludes "
5477 "AP mandatory rate.\n",
5478 escape_essid(network->ssid, network->ssid_len),
5479 MAC_ARG(network->bssid));
5480 return 0;
5481 }
5482
5483 if (rates.num_rates == 0) {
5484 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5485 "because of no compatible rates.\n",
5486 escape_essid(network->ssid, network->ssid_len),
5487 MAC_ARG(network->bssid));
5488 return 0;
5489 }
5490
5491 /* TODO: Perform any further minimal comparititive tests. We do not
5492 * want to put too much policy logic here; intelligent scan selection
5493 * should occur within a generic IEEE 802.11 user space tool. */
5494
5495 /* Set up 'new' AP to this network */
5496 ipw_copy_rates(&match->rates, &rates);
5497 match->network = network;
5498 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5499 escape_essid(network->ssid, network->ssid_len),
5500 MAC_ARG(network->bssid));
5501
5502 return 1;
5503}
5504
5505static void ipw_merge_adhoc_network(void *data)
5506{
5507 struct ipw_priv *priv = data;
5508 struct ieee80211_network *network = NULL;
5509 struct ipw_network_match match = {
5510 .network = priv->assoc_network
5511 };
5512
James Ketrenosafbf30a2005-08-25 00:05:33 -05005513 if ((priv->status & STATUS_ASSOCIATED) &&
5514 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005515 /* First pass through ROAM process -- look for a better
5516 * network */
5517 unsigned long flags;
5518
5519 spin_lock_irqsave(&priv->ieee->lock, flags);
5520 list_for_each_entry(network, &priv->ieee->network_list, list) {
5521 if (network != priv->assoc_network)
5522 ipw_find_adhoc_network(priv, &match, network,
5523 1);
5524 }
5525 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5526
5527 if (match.network == priv->assoc_network) {
5528 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5529 "merge to.\n");
5530 return;
5531 }
5532
Zhu Yi46441512006-01-24 16:37:59 +08005533 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005534 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5535 IPW_DEBUG_MERGE("remove network %s\n",
5536 escape_essid(priv->essid,
5537 priv->essid_len));
5538 ipw_remove_current_network(priv);
5539 }
5540
5541 ipw_disassociate(priv);
5542 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005543 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005544 return;
5545 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005546}
5547
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005548static int ipw_best_network(struct ipw_priv *priv,
5549 struct ipw_network_match *match,
5550 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005551{
5552 struct ipw_supported_rates rates;
5553
5554 /* Verify that this network's capability is compatible with the
5555 * current mode (AdHoc or Infrastructure) */
5556 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005557 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005558 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5559 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5560 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005561 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005562 escape_essid(network->ssid, network->ssid_len),
5563 MAC_ARG(network->bssid));
5564 return 0;
5565 }
5566
5567 /* If we do not have an ESSID for this AP, we can not associate with
5568 * it */
5569 if (network->flags & NETWORK_EMPTY_ESSID) {
5570 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5571 "because of hidden ESSID.\n",
5572 escape_essid(network->ssid, network->ssid_len),
5573 MAC_ARG(network->bssid));
5574 return 0;
5575 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005576
James Ketrenos43f66a62005-03-25 12:31:53 -06005577 if (unlikely(roaming)) {
5578 /* If we are roaming, then ensure check if this is a valid
5579 * network to try and roam to */
5580 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005581 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005582 network->ssid_len)) {
5583 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5584 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04005585 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005586 network->ssid_len),
5587 MAC_ARG(network->bssid));
5588 return 0;
5589 }
5590 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005591 /* If an ESSID has been configured then compare the broadcast
5592 * ESSID to ours */
5593 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005594 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005595 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005596 min(network->ssid_len, priv->essid_len)))) {
5597 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005598 strncpy(escaped,
5599 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005600 sizeof(escaped));
5601 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005602 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005603 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005604 escape_essid(priv->essid,
5605 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005606 return 0;
5607 }
5608 }
5609
5610 /* If the old network rate is better than this one, don't bother
5611 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005612 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005613 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005614 strncpy(escaped,
5615 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005616 sizeof(escaped));
5617 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5618 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5619 escaped, MAC_ARG(network->bssid),
5620 escape_essid(match->network->ssid,
5621 match->network->ssid_len),
5622 MAC_ARG(match->network->bssid));
5623 return 0;
5624 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005625
James Ketrenos43f66a62005-03-25 12:31:53 -06005626 /* If this network has already had an association attempt within the
5627 * last 3 seconds, do not try and associate again... */
5628 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005629 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005630 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005631 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005632 "assoc attempt).\n",
5633 escape_essid(network->ssid, network->ssid_len),
5634 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005635 jiffies_to_msecs(jiffies -
5636 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005637 return 0;
5638 }
5639
5640 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005641 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005642 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005643 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005644 "because of age: %ums.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005645 escape_essid(network->ssid, network->ssid_len),
5646 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005647 jiffies_to_msecs(jiffies -
5648 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005649 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005650 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005651
Jeff Garzikbf794512005-07-31 13:07:26 -04005652 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005653 (network->channel != priv->channel)) {
5654 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5655 "because of channel mismatch: %d != %d.\n",
5656 escape_essid(network->ssid, network->ssid_len),
5657 MAC_ARG(network->bssid),
5658 network->channel, priv->channel);
5659 return 0;
5660 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005661
James Ketrenos43f66a62005-03-25 12:31:53 -06005662 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005663 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005664 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5665 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5666 "because of privacy mismatch: %s != %s.\n",
5667 escape_essid(network->ssid, network->ssid_len),
5668 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04005669 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005670 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005671 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005672 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005673 return 0;
5674 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005675
5676 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005677 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5678 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5679 "because of BSSID mismatch: " MAC_FMT ".\n",
5680 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005681 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005682 return 0;
5683 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005684
James Ketrenos43f66a62005-03-25 12:31:53 -06005685 /* Filter out any incompatible freq / mode combinations */
5686 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5687 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5688 "because of invalid frequency/mode "
5689 "combination.\n",
5690 escape_essid(network->ssid, network->ssid_len),
5691 MAC_ARG(network->bssid));
5692 return 0;
5693 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005694
Liu Hong1fe0adb2005-08-19 09:33:10 -05005695 /* Filter out invalid channel in current GEO */
Larry Finger1867b112006-02-28 09:48:28 -06005696 if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005697 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5698 "because of invalid channel in current GEO\n",
5699 escape_essid(network->ssid, network->ssid_len),
5700 MAC_ARG(network->bssid));
5701 return 0;
5702 }
5703
James Ketrenosea2b26e2005-08-24 21:25:16 -05005704 /* Ensure that the rates supported by the driver are compatible with
5705 * this AP, including verification of basic rates (mandatory) */
5706 if (!ipw_compatible_rates(priv, network, &rates)) {
5707 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5708 "because configured rate mask excludes "
5709 "AP mandatory rate.\n",
5710 escape_essid(network->ssid, network->ssid_len),
5711 MAC_ARG(network->bssid));
5712 return 0;
5713 }
5714
James Ketrenos43f66a62005-03-25 12:31:53 -06005715 if (rates.num_rates == 0) {
5716 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5717 "because of no compatible rates.\n",
5718 escape_essid(network->ssid, network->ssid_len),
5719 MAC_ARG(network->bssid));
5720 return 0;
5721 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005722
James Ketrenos43f66a62005-03-25 12:31:53 -06005723 /* TODO: Perform any further minimal comparititive tests. We do not
5724 * want to put too much policy logic here; intelligent scan selection
5725 * should occur within a generic IEEE 802.11 user space tool. */
5726
5727 /* Set up 'new' AP to this network */
5728 ipw_copy_rates(&match->rates, &rates);
5729 match->network = network;
5730
5731 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5732 escape_essid(network->ssid, network->ssid_len),
5733 MAC_ARG(network->bssid));
5734
5735 return 1;
5736}
5737
Jeff Garzikbf794512005-07-31 13:07:26 -04005738static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005739 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005740{
Larry Finger1867b112006-02-28 09:48:28 -06005741 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005742 int i;
5743
James Ketrenos43f66a62005-03-25 12:31:53 -06005744 /*
5745 * For the purposes of scanning, we can set our wireless mode
5746 * to trigger scans across combinations of bands, but when it
5747 * comes to creating a new ad-hoc network, we have tell the FW
5748 * exactly which band to use.
5749 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005750 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005751 * chossen band. Attempting to create a new ad-hoc network
5752 * with an invalid channel for wireless mode will trigger a
5753 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005754 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005755 */
Larry Finger1867b112006-02-28 09:48:28 -06005756 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005757 case IEEE80211_52GHZ_BAND:
5758 network->mode = IEEE_A;
Larry Finger1867b112006-02-28 09:48:28 -06005759 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005760 BUG_ON(i == -1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005761 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5762 IPW_WARNING("Overriding invalid channel\n");
5763 priv->channel = geo->a[0].channel;
5764 }
5765 break;
5766
5767 case IEEE80211_24GHZ_BAND:
5768 if (priv->ieee->mode & IEEE_G)
5769 network->mode = IEEE_G;
5770 else
5771 network->mode = IEEE_B;
Larry Finger1867b112006-02-28 09:48:28 -06005772 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005773 BUG_ON(i == -1);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005774 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5775 IPW_WARNING("Overriding invalid channel\n");
5776 priv->channel = geo->bg[0].channel;
5777 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005778 break;
5779
5780 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005781 IPW_WARNING("Overriding invalid channel\n");
5782 if (priv->ieee->mode & IEEE_A) {
5783 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005784 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005785 } else if (priv->ieee->mode & IEEE_G) {
5786 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005787 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005788 } else {
5789 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005790 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005791 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005792 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005793 }
5794
5795 network->channel = priv->channel;
5796 priv->config |= CFG_ADHOC_PERSIST;
5797 ipw_create_bssid(priv, network->bssid);
5798 network->ssid_len = priv->essid_len;
5799 memcpy(network->ssid, priv->essid, priv->essid_len);
5800 memset(&network->stats, 0, sizeof(network->stats));
5801 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005802 if (!(priv->config & CFG_PREAMBLE_LONG))
5803 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005804 if (priv->capability & CAP_PRIVACY_ON)
5805 network->capability |= WLAN_CAPABILITY_PRIVACY;
5806 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005807 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005808 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005809 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005810 &priv->rates.supported_rates[network->rates_len],
5811 network->rates_ex_len);
5812 network->last_scanned = 0;
5813 network->flags = 0;
5814 network->last_associate = 0;
5815 network->time_stamp[0] = 0;
5816 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005817 network->beacon_interval = 100; /* Default */
5818 network->listen_interval = 10; /* Default */
5819 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005820 network->wpa_ie_len = 0;
5821 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005822}
5823
James Ketrenosb095c382005-08-24 22:04:42 -05005824static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5825{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005826 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005827
5828 if (!(priv->ieee->sec.flags & (1 << index)))
5829 return;
5830
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005831 key.key_id = index;
5832 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5833 key.security_type = type;
5834 key.station_index = 0; /* always 0 for BSS */
5835 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005836 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005837 key.tx_counter[0] = 0;
5838 key.tx_counter[1] = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005839
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005840 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05005841}
5842
5843static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005844{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005845 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06005846 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06005847
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005848 key.cmd_id = DINO_CMD_WEP_KEY;
5849 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005850
James Ketrenosb095c382005-08-24 22:04:42 -05005851 /* Note: AES keys cannot be set for multiple times.
5852 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005853 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005854 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05005855 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005856 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005857 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005858 }
5859
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005860 key.key_size = priv->ieee->sec.key_sizes[i];
5861 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05005862
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005863 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04005864 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005865}
5866
Zhu Yi1fbfea52005-08-05 17:22:56 +08005867static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5868{
5869 if (priv->ieee->host_encrypt)
5870 return;
5871
5872 switch (level) {
5873 case SEC_LEVEL_3:
5874 priv->sys_config.disable_unicast_decryption = 0;
5875 priv->ieee->host_decrypt = 0;
5876 break;
5877 case SEC_LEVEL_2:
5878 priv->sys_config.disable_unicast_decryption = 1;
5879 priv->ieee->host_decrypt = 1;
5880 break;
5881 case SEC_LEVEL_1:
5882 priv->sys_config.disable_unicast_decryption = 0;
5883 priv->ieee->host_decrypt = 0;
5884 break;
5885 case SEC_LEVEL_0:
5886 priv->sys_config.disable_unicast_decryption = 1;
5887 break;
5888 default:
5889 break;
5890 }
5891}
5892
5893static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5894{
5895 if (priv->ieee->host_encrypt)
5896 return;
5897
5898 switch (level) {
5899 case SEC_LEVEL_3:
5900 priv->sys_config.disable_multicast_decryption = 0;
5901 break;
5902 case SEC_LEVEL_2:
5903 priv->sys_config.disable_multicast_decryption = 1;
5904 break;
5905 case SEC_LEVEL_1:
5906 priv->sys_config.disable_multicast_decryption = 0;
5907 break;
5908 case SEC_LEVEL_0:
5909 priv->sys_config.disable_multicast_decryption = 1;
5910 break;
5911 default:
5912 break;
5913 }
5914}
5915
James Ketrenosb095c382005-08-24 22:04:42 -05005916static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5917{
5918 switch (priv->ieee->sec.level) {
5919 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005920 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5921 ipw_send_tgi_tx_key(priv,
5922 DCT_FLAG_EXT_SECURITY_CCM,
5923 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005924
Hong Liu567deaf2005-08-31 18:07:22 +08005925 if (!priv->ieee->host_mc_decrypt)
5926 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05005927 break;
5928 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005929 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5930 ipw_send_tgi_tx_key(priv,
5931 DCT_FLAG_EXT_SECURITY_TKIP,
5932 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05005933 break;
5934 case SEC_LEVEL_1:
5935 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05005936 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5937 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05005938 break;
5939 case SEC_LEVEL_0:
5940 default:
5941 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005942 }
5943}
5944
5945static void ipw_adhoc_check(void *data)
5946{
5947 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04005948
James Ketrenosafbf30a2005-08-25 00:05:33 -05005949 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005950 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005951 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5952 IPW_DL_STATE | IPW_DL_ASSOC,
5953 "Missed beacon: %d - disassociate\n",
5954 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06005955 ipw_remove_current_network(priv);
5956 ipw_disassociate(priv);
5957 return;
5958 }
5959
Jeff Garzikbf794512005-07-31 13:07:26 -04005960 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06005961 priv->assoc_request.beacon_interval);
5962}
5963
James Ketrenosc848d0a2005-08-24 21:56:24 -05005964static void ipw_bg_adhoc_check(void *data)
5965{
5966 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08005967 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005968 ipw_adhoc_check(data);
Zhu Yi46441512006-01-24 16:37:59 +08005969 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005970}
5971
Brice Goglin0f52bf92005-12-01 01:41:46 -08005972#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -06005973static void ipw_debug_config(struct ipw_priv *priv)
5974{
5975 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5976 "[CFG 0x%08X]\n", priv->config);
5977 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005978 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005979 else
5980 IPW_DEBUG_INFO("Channel unlocked.\n");
5981 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04005982 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005983 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005984 else
5985 IPW_DEBUG_INFO("ESSID unlocked.\n");
5986 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05005987 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5988 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005989 else
5990 IPW_DEBUG_INFO("BSSID unlocked.\n");
5991 if (priv->capability & CAP_PRIVACY_ON)
5992 IPW_DEBUG_INFO("PRIVACY on\n");
5993 else
5994 IPW_DEBUG_INFO("PRIVACY off\n");
5995 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5996}
5997#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04005998#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06005999#endif
6000
Arjan van de Ven858119e2006-01-14 13:20:43 -08006001static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06006002{
6003 /* TODO: Verify that this works... */
6004 struct ipw_fixed_rate fr = {
6005 .tx_rates = priv->rates_mask
6006 };
6007 u32 reg;
6008 u16 mask = 0;
6009
Jeff Garzikbf794512005-07-31 13:07:26 -04006010 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06006011 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04006012
James Ketrenos43f66a62005-03-25 12:31:53 -06006013 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006014 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06006015 /* IEEE_A */
6016 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
6017 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006018 IPW_DEBUG_WX
6019 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06006020 fr.tx_rates = 0;
6021 break;
6022 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006023
James Ketrenos43f66a62005-03-25 12:31:53 -06006024 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
6025 break;
6026
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006027 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06006028 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05006029 if (mode == IEEE_B) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006030 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
6031 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006032 IPW_DEBUG_WX
6033 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06006034 fr.tx_rates = 0;
6035 }
6036 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006037 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006038
6039 /* IEEE_G */
6040 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
6041 IEEE80211_OFDM_RATES_MASK)) {
6042 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006043 IPW_DEBUG_WX
6044 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06006045 fr.tx_rates = 0;
6046 break;
6047 }
6048
6049 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
6050 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
6051 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
6052 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006053
James Ketrenos43f66a62005-03-25 12:31:53 -06006054 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
6055 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
6056 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
6057 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006058
James Ketrenos43f66a62005-03-25 12:31:53 -06006059 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
6060 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
6061 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
6062 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006063
James Ketrenos43f66a62005-03-25 12:31:53 -06006064 fr.tx_rates |= mask;
6065 break;
6066 }
6067
6068 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006069 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06006070}
6071
James Ketrenosea2b26e2005-08-24 21:25:16 -05006072static void ipw_abort_scan(struct ipw_priv *priv)
6073{
6074 int err;
6075
6076 if (priv->status & STATUS_SCAN_ABORTING) {
6077 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6078 return;
6079 }
6080 priv->status |= STATUS_SCAN_ABORTING;
6081
6082 err = ipw_send_scan_abort(priv);
6083 if (err)
6084 IPW_DEBUG_HC("Request to abort scan failed.\n");
6085}
6086
James Ketrenosafbf30a2005-08-25 00:05:33 -05006087static void ipw_add_scan_channels(struct ipw_priv *priv,
6088 struct ipw_scan_request_ext *scan,
6089 int scan_type)
6090{
6091 int channel_index = 0;
6092 const struct ieee80211_geo *geo;
6093 int i;
6094
Larry Finger1867b112006-02-28 09:48:28 -06006095 geo = ieee80211_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006096
6097 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
6098 int start = channel_index;
6099 for (i = 0; i < geo->a_channels; i++) {
6100 if ((priv->status & STATUS_ASSOCIATED) &&
6101 geo->a[i].channel == priv->channel)
6102 continue;
6103 channel_index++;
6104 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006105 ipw_set_scan_type(scan, channel_index,
6106 geo->a[i].
6107 flags & IEEE80211_CH_PASSIVE_ONLY ?
6108 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6109 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006110 }
6111
6112 if (start != channel_index) {
6113 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6114 (channel_index - start);
6115 channel_index++;
6116 }
6117 }
6118
6119 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
6120 int start = channel_index;
6121 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006122 int index;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006123 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
6124 /* nop out the list */
6125 [0] = 0
6126 };
6127
6128 u8 channel;
6129 while (channel_index < IPW_SCAN_CHANNELS) {
6130 channel =
6131 priv->speed_scan[priv->speed_scan_pos];
6132 if (channel == 0) {
6133 priv->speed_scan_pos = 0;
6134 channel = priv->speed_scan[0];
6135 }
6136 if ((priv->status & STATUS_ASSOCIATED) &&
6137 channel == priv->channel) {
6138 priv->speed_scan_pos++;
6139 continue;
6140 }
6141
6142 /* If this channel has already been
6143 * added in scan, break from loop
6144 * and this will be the first channel
6145 * in the next scan.
6146 */
6147 if (channels[channel - 1] != 0)
6148 break;
6149
6150 channels[channel - 1] = 1;
6151 priv->speed_scan_pos++;
6152 channel_index++;
6153 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006154 index =
Larry Finger1867b112006-02-28 09:48:28 -06006155 ieee80211_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006156 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006157 geo->bg[index].
6158 flags &
6159 IEEE80211_CH_PASSIVE_ONLY ?
6160 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6161 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006162 }
6163 } else {
6164 for (i = 0; i < geo->bg_channels; i++) {
6165 if ((priv->status & STATUS_ASSOCIATED) &&
6166 geo->bg[i].channel == priv->channel)
6167 continue;
6168 channel_index++;
6169 scan->channels_list[channel_index] =
6170 geo->bg[i].channel;
6171 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006172 geo->bg[i].
6173 flags &
6174 IEEE80211_CH_PASSIVE_ONLY ?
6175 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6176 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006177 }
6178 }
6179
6180 if (start != channel_index) {
6181 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6182 (channel_index - start);
6183 }
6184 }
6185}
6186
James Ketrenosea2b26e2005-08-24 21:25:16 -05006187static int ipw_request_scan(struct ipw_priv *priv)
6188{
6189 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006190 int err = 0, scan_type;
6191
6192 if (!(priv->status & STATUS_INIT) ||
6193 (priv->status & STATUS_EXIT_PENDING))
6194 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006195
Zhu Yi46441512006-01-24 16:37:59 +08006196 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006197
James Ketrenosea2b26e2005-08-24 21:25:16 -05006198 if (priv->status & STATUS_SCANNING) {
James Ketrenosa613bff2005-08-24 21:43:11 -05006199 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05006200 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006201 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006202 }
6203
James Ketrenosafbf30a2005-08-25 00:05:33 -05006204 if (!(priv->status & STATUS_SCAN_FORCED) &&
6205 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006206 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6207 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006208 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006209 }
6210
6211 if (priv->status & STATUS_RF_KILL_MASK) {
6212 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6213 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006214 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006215 }
6216
6217 memset(&scan, 0, sizeof(scan));
6218
James Ketrenosb095c382005-08-24 22:04:42 -05006219 if (priv->config & CFG_SPEED_SCAN)
6220 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6221 cpu_to_le16(30);
6222 else
6223 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6224 cpu_to_le16(20);
6225
James Ketrenosa613bff2005-08-24 21:43:11 -05006226 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6227 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05006228 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006229
James Ketrenosa613bff2005-08-24 21:43:11 -05006230 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006231
James Ketrenosb095c382005-08-24 22:04:42 -05006232#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006233 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006234 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006235 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006236
Larry Finger1867b112006-02-28 09:48:28 -06006237 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006238 case IEEE80211_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006239 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006240 channel = priv->channel;
6241 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006242
James Ketrenosb095c382005-08-24 22:04:42 -05006243 case IEEE80211_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006244 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006245 channel = priv->channel;
6246 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006247
James Ketrenosb095c382005-08-24 22:04:42 -05006248 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006249 band = (u8) (IPW_B_MODE << 6) | 1;
6250 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006251 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006252 }
6253
James Ketrenosb095c382005-08-24 22:04:42 -05006254 scan.channels_list[0] = band;
6255 scan.channels_list[1] = channel;
6256 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006257
James Ketrenosb095c382005-08-24 22:04:42 -05006258 /* NOTE: The card will sit on this channel for this time
6259 * period. Scan aborts are timing sensitive and frequently
6260 * result in firmware restarts. As such, it is best to
6261 * set a small dwell_time here and just keep re-issuing
6262 * scans. Otherwise fast channel hopping will not actually
6263 * hop channels.
6264 *
6265 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006266 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6267 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006268 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006269#endif /* CONFIG_IPW2200_MONITOR */
6270 /* If we are roaming, then make this a directed scan for the
6271 * current network. Otherwise, ensure that every other scan
6272 * is a fast channel hop scan */
6273 if ((priv->status & STATUS_ROAMING)
6274 || (!(priv->status & STATUS_ASSOCIATED)
6275 && (priv->config & CFG_STATIC_ESSID)
6276 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006277 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6278 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006279 IPW_DEBUG_HC("Attempt to send SSID command "
6280 "failed.\n");
6281 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006282 }
6283
6284 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006285 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006286 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006287
James Ketrenosafbf30a2005-08-25 00:05:33 -05006288 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006289#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006290 }
6291#endif
6292
6293 err = ipw_send_scan_request_ext(priv, &scan);
6294 if (err) {
6295 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006296 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006297 }
6298
6299 priv->status |= STATUS_SCANNING;
6300 priv->status &= ~STATUS_SCAN_PENDING;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006301 queue_delayed_work(priv->workqueue, &priv->scan_check,
6302 IPW_SCAN_CHECK_WATCHDOG);
James Ketrenosb095c382005-08-24 22:04:42 -05006303 done:
Zhu Yi46441512006-01-24 16:37:59 +08006304 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006305 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006306}
6307
6308static void ipw_bg_abort_scan(void *data)
6309{
6310 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08006311 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006312 ipw_abort_scan(data);
Zhu Yi46441512006-01-24 16:37:59 +08006313 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006314}
6315
James Ketrenosea2b26e2005-08-24 21:25:16 -05006316static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6317{
James Ketrenosb095c382005-08-24 22:04:42 -05006318 /* This is called when wpa_supplicant loads and closes the driver
6319 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006320 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006321 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006322}
6323
James Ketrenosea2b26e2005-08-24 21:25:16 -05006324static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6325{
6326 struct ieee80211_device *ieee = priv->ieee;
6327 struct ieee80211_security sec = {
6328 .flags = SEC_AUTH_MODE,
6329 };
6330 int ret = 0;
6331
James Ketrenosafbf30a2005-08-25 00:05:33 -05006332 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006333 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6334 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006335 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006336 sec.auth_mode = WLAN_AUTH_OPEN;
6337 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006338 } else if (value & IW_AUTH_ALG_LEAP) {
6339 sec.auth_mode = WLAN_AUTH_LEAP;
6340 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006341 } else
6342 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006343
6344 if (ieee->set_security)
6345 ieee->set_security(ieee->dev, &sec);
6346 else
6347 ret = -EOPNOTSUPP;
6348
6349 return ret;
6350}
6351
Adrian Bunka73e22b2006-01-21 01:39:42 +01006352static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6353 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006354{
6355 /* make sure WPA is enabled */
6356 ipw_wpa_enable(priv, 1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006357}
6358
6359static int ipw_set_rsn_capa(struct ipw_priv *priv,
6360 char *capabilities, int length)
6361{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006362 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6363
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006364 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006365 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006366}
6367
James Ketrenosafbf30a2005-08-25 00:05:33 -05006368/*
6369 * WE-18 support
6370 */
6371
6372/* SIOCSIWGENIE */
6373static int ipw_wx_set_genie(struct net_device *dev,
6374 struct iw_request_info *info,
6375 union iwreq_data *wrqu, char *extra)
6376{
6377 struct ipw_priv *priv = ieee80211_priv(dev);
6378 struct ieee80211_device *ieee = priv->ieee;
6379 u8 *buf;
6380 int err = 0;
6381
6382 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6383 (wrqu->data.length && extra == NULL))
6384 return -EINVAL;
6385
James Ketrenosafbf30a2005-08-25 00:05:33 -05006386 if (wrqu->data.length) {
6387 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6388 if (buf == NULL) {
6389 err = -ENOMEM;
6390 goto out;
6391 }
6392
6393 memcpy(buf, extra, wrqu->data.length);
6394 kfree(ieee->wpa_ie);
6395 ieee->wpa_ie = buf;
6396 ieee->wpa_ie_len = wrqu->data.length;
6397 } else {
6398 kfree(ieee->wpa_ie);
6399 ieee->wpa_ie = NULL;
6400 ieee->wpa_ie_len = 0;
6401 }
6402
6403 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6404 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006405 return err;
6406}
6407
6408/* SIOCGIWGENIE */
6409static int ipw_wx_get_genie(struct net_device *dev,
6410 struct iw_request_info *info,
6411 union iwreq_data *wrqu, char *extra)
6412{
6413 struct ipw_priv *priv = ieee80211_priv(dev);
6414 struct ieee80211_device *ieee = priv->ieee;
6415 int err = 0;
6416
James Ketrenosafbf30a2005-08-25 00:05:33 -05006417 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6418 wrqu->data.length = 0;
6419 goto out;
6420 }
6421
6422 if (wrqu->data.length < ieee->wpa_ie_len) {
6423 err = -E2BIG;
6424 goto out;
6425 }
6426
6427 wrqu->data.length = ieee->wpa_ie_len;
6428 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6429
6430 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006431 return err;
6432}
6433
Zhu Yi1fbfea52005-08-05 17:22:56 +08006434static int wext_cipher2level(int cipher)
6435{
6436 switch (cipher) {
6437 case IW_AUTH_CIPHER_NONE:
6438 return SEC_LEVEL_0;
6439 case IW_AUTH_CIPHER_WEP40:
6440 case IW_AUTH_CIPHER_WEP104:
6441 return SEC_LEVEL_1;
6442 case IW_AUTH_CIPHER_TKIP:
6443 return SEC_LEVEL_2;
6444 case IW_AUTH_CIPHER_CCMP:
6445 return SEC_LEVEL_3;
6446 default:
6447 return -1;
6448 }
6449}
6450
James Ketrenosafbf30a2005-08-25 00:05:33 -05006451/* SIOCSIWAUTH */
6452static int ipw_wx_set_auth(struct net_device *dev,
6453 struct iw_request_info *info,
6454 union iwreq_data *wrqu, char *extra)
6455{
6456 struct ipw_priv *priv = ieee80211_priv(dev);
6457 struct ieee80211_device *ieee = priv->ieee;
6458 struct iw_param *param = &wrqu->param;
6459 struct ieee80211_crypt_data *crypt;
6460 unsigned long flags;
6461 int ret = 0;
6462
6463 switch (param->flags & IW_AUTH_INDEX) {
6464 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006465 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006466 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006467 ipw_set_hw_decrypt_unicast(priv,
6468 wext_cipher2level(param->value));
6469 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006470 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006471 ipw_set_hw_decrypt_multicast(priv,
6472 wext_cipher2level(param->value));
6473 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006474 case IW_AUTH_KEY_MGMT:
6475 /*
6476 * ipw2200 does not use these parameters
6477 */
6478 break;
6479
6480 case IW_AUTH_TKIP_COUNTERMEASURES:
6481 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006482 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006483 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006484
6485 flags = crypt->ops->get_flags(crypt->priv);
6486
6487 if (param->value)
6488 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6489 else
6490 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6491
6492 crypt->ops->set_flags(flags, crypt->priv);
6493
6494 break;
6495
6496 case IW_AUTH_DROP_UNENCRYPTED:{
6497 /* HACK:
6498 *
6499 * wpa_supplicant calls set_wpa_enabled when the driver
6500 * is loaded and unloaded, regardless of if WPA is being
6501 * used. No other calls are made which can be used to
6502 * determine if encryption will be used or not prior to
6503 * association being expected. If encryption is not being
6504 * used, drop_unencrypted is set to false, else true -- we
6505 * can use this to determine if the CAP_PRIVACY_ON bit should
6506 * be set.
6507 */
6508 struct ieee80211_security sec = {
6509 .flags = SEC_ENABLED,
6510 .enabled = param->value,
6511 };
6512 priv->ieee->drop_unencrypted = param->value;
6513 /* We only change SEC_LEVEL for open mode. Others
6514 * are set by ipw_wpa_set_encryption.
6515 */
6516 if (!param->value) {
6517 sec.flags |= SEC_LEVEL;
6518 sec.level = SEC_LEVEL_0;
6519 } else {
6520 sec.flags |= SEC_LEVEL;
6521 sec.level = SEC_LEVEL_1;
6522 }
6523 if (priv->ieee->set_security)
6524 priv->ieee->set_security(priv->ieee->dev, &sec);
6525 break;
6526 }
6527
6528 case IW_AUTH_80211_AUTH_ALG:
6529 ret = ipw_wpa_set_auth_algs(priv, param->value);
6530 break;
6531
6532 case IW_AUTH_WPA_ENABLED:
6533 ret = ipw_wpa_enable(priv, param->value);
Zhu Yie3c5a642006-04-13 17:21:13 +08006534 ipw_disassociate(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006535 break;
6536
6537 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6538 ieee->ieee802_1x = param->value;
6539 break;
6540
James Ketrenosafbf30a2005-08-25 00:05:33 -05006541 case IW_AUTH_PRIVACY_INVOKED:
6542 ieee->privacy_invoked = param->value;
6543 break;
6544
6545 default:
6546 return -EOPNOTSUPP;
6547 }
6548 return ret;
6549}
6550
6551/* SIOCGIWAUTH */
6552static int ipw_wx_get_auth(struct net_device *dev,
6553 struct iw_request_info *info,
6554 union iwreq_data *wrqu, char *extra)
6555{
6556 struct ipw_priv *priv = ieee80211_priv(dev);
6557 struct ieee80211_device *ieee = priv->ieee;
6558 struct ieee80211_crypt_data *crypt;
6559 struct iw_param *param = &wrqu->param;
6560 int ret = 0;
6561
6562 switch (param->flags & IW_AUTH_INDEX) {
6563 case IW_AUTH_WPA_VERSION:
6564 case IW_AUTH_CIPHER_PAIRWISE:
6565 case IW_AUTH_CIPHER_GROUP:
6566 case IW_AUTH_KEY_MGMT:
6567 /*
6568 * wpa_supplicant will control these internally
6569 */
6570 ret = -EOPNOTSUPP;
6571 break;
6572
6573 case IW_AUTH_TKIP_COUNTERMEASURES:
6574 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006575 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006576 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006577
6578 param->value = (crypt->ops->get_flags(crypt->priv) &
6579 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6580
6581 break;
6582
6583 case IW_AUTH_DROP_UNENCRYPTED:
6584 param->value = ieee->drop_unencrypted;
6585 break;
6586
6587 case IW_AUTH_80211_AUTH_ALG:
6588 param->value = ieee->sec.auth_mode;
6589 break;
6590
6591 case IW_AUTH_WPA_ENABLED:
6592 param->value = ieee->wpa_enabled;
6593 break;
6594
6595 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6596 param->value = ieee->ieee802_1x;
6597 break;
6598
6599 case IW_AUTH_ROAMING_CONTROL:
6600 case IW_AUTH_PRIVACY_INVOKED:
6601 param->value = ieee->privacy_invoked;
6602 break;
6603
6604 default:
6605 return -EOPNOTSUPP;
6606 }
6607 return 0;
6608}
6609
6610/* SIOCSIWENCODEEXT */
6611static int ipw_wx_set_encodeext(struct net_device *dev,
6612 struct iw_request_info *info,
6613 union iwreq_data *wrqu, char *extra)
6614{
6615 struct ipw_priv *priv = ieee80211_priv(dev);
6616 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6617
6618 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006619 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006620 /* IPW HW can't build TKIP MIC,
6621 host decryption still needed */
6622 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6623 priv->ieee->host_mc_decrypt = 1;
6624 else {
6625 priv->ieee->host_encrypt = 0;
6626 priv->ieee->host_encrypt_msdu = 1;
6627 priv->ieee->host_decrypt = 1;
6628 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006629 } else {
6630 priv->ieee->host_encrypt = 0;
6631 priv->ieee->host_encrypt_msdu = 0;
6632 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006633 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006634 }
6635 }
6636
6637 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6638}
6639
6640/* SIOCGIWENCODEEXT */
6641static int ipw_wx_get_encodeext(struct net_device *dev,
6642 struct iw_request_info *info,
6643 union iwreq_data *wrqu, char *extra)
6644{
6645 struct ipw_priv *priv = ieee80211_priv(dev);
6646 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6647}
6648
6649/* SIOCSIWMLME */
6650static int ipw_wx_set_mlme(struct net_device *dev,
6651 struct iw_request_info *info,
6652 union iwreq_data *wrqu, char *extra)
6653{
6654 struct ipw_priv *priv = ieee80211_priv(dev);
6655 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6656 u16 reason;
6657
6658 reason = cpu_to_le16(mlme->reason_code);
6659
6660 switch (mlme->cmd) {
6661 case IW_MLME_DEAUTH:
Pavel Machek67fd6b42006-07-11 15:34:05 +02006662 /* silently ignore */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006663 break;
6664
6665 case IW_MLME_DISASSOC:
6666 ipw_disassociate(priv);
6667 break;
6668
6669 default:
6670 return -EOPNOTSUPP;
6671 }
6672 return 0;
6673}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006674
Zhu Yie43e3c12006-04-13 17:20:45 +08006675#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05006676
6677/* QoS */
6678/*
6679* get the modulation type of the current network or
6680* the card current mode
6681*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006682static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006683{
6684 u8 mode = 0;
6685
6686 if (priv->status & STATUS_ASSOCIATED) {
6687 unsigned long flags;
6688
6689 spin_lock_irqsave(&priv->ieee->lock, flags);
6690 mode = priv->assoc_network->mode;
6691 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6692 } else {
6693 mode = priv->ieee->mode;
6694 }
6695 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6696 return mode;
6697}
6698
6699/*
6700* Handle management frame beacon and probe response
6701*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006702static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6703 int active_network,
6704 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006705{
6706 u32 size = sizeof(struct ieee80211_qos_parameters);
6707
James Ketrenosafbf30a2005-08-25 00:05:33 -05006708 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006709 network->qos_data.active = network->qos_data.supported;
6710
6711 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006712 if (active_network &&
6713 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006714 network->qos_data.active = network->qos_data.supported;
6715
6716 if ((network->qos_data.active == 1) && (active_network == 1) &&
6717 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6718 (network->qos_data.old_param_count !=
6719 network->qos_data.param_count)) {
6720 network->qos_data.old_param_count =
6721 network->qos_data.param_count;
6722 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006723 IPW_DEBUG_QOS("QoS parameters change call "
6724 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006725 }
6726 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006727 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6728 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006729 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006730 else
6731 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006732 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006733
James Ketrenosb095c382005-08-24 22:04:42 -05006734 if ((network->qos_data.active == 1) && (active_network == 1)) {
6735 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6736 schedule_work(&priv->qos_activate);
6737 }
6738
6739 network->qos_data.active = 0;
6740 network->qos_data.supported = 0;
6741 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006742 if ((priv->status & STATUS_ASSOCIATED) &&
6743 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6744 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6745 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6746 !(network->flags & NETWORK_EMPTY_ESSID))
James Ketrenosb095c382005-08-24 22:04:42 -05006747 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006748 priv->assoc_network->ssid_len) &&
6749 !memcmp(network->ssid,
6750 priv->assoc_network->ssid,
6751 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006752 queue_work(priv->workqueue,
6753 &priv->merge_networks);
6754 }
James Ketrenosb095c382005-08-24 22:04:42 -05006755 }
6756
6757 return 0;
6758}
6759
6760/*
6761* This function set up the firmware to support QoS. It sends
6762* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6763*/
6764static int ipw_qos_activate(struct ipw_priv *priv,
6765 struct ieee80211_qos_data *qos_network_data)
6766{
6767 int err;
6768 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6769 struct ieee80211_qos_parameters *active_one = NULL;
6770 u32 size = sizeof(struct ieee80211_qos_parameters);
6771 u32 burst_duration;
6772 int i;
6773 u8 type;
6774
6775 type = ipw_qos_current_mode(priv);
6776
6777 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6778 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6779 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6780 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6781
6782 if (qos_network_data == NULL) {
6783 if (type == IEEE_B) {
6784 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6785 active_one = &def_parameters_CCK;
6786 } else
6787 active_one = &def_parameters_OFDM;
6788
James Ketrenosafbf30a2005-08-25 00:05:33 -05006789 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006790 burst_duration = ipw_qos_get_burst_duration(priv);
6791 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006792 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6793 (u16) burst_duration;
6794 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05006795 if (type == IEEE_B) {
6796 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6797 type);
6798 if (priv->qos_data.qos_enable == 0)
6799 active_one = &def_parameters_CCK;
6800 else
6801 active_one = priv->qos_data.def_qos_parm_CCK;
6802 } else {
6803 if (priv->qos_data.qos_enable == 0)
6804 active_one = &def_parameters_OFDM;
6805 else
6806 active_one = priv->qos_data.def_qos_parm_OFDM;
6807 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006808 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006809 } else {
6810 unsigned long flags;
6811 int active;
6812
6813 spin_lock_irqsave(&priv->ieee->lock, flags);
6814 active_one = &(qos_network_data->parameters);
6815 qos_network_data->old_param_count =
6816 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006817 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006818 active = qos_network_data->supported;
6819 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6820
6821 if (active == 0) {
6822 burst_duration = ipw_qos_get_burst_duration(priv);
6823 for (i = 0; i < QOS_QUEUE_NUM; i++)
6824 qos_parameters[QOS_PARAM_SET_ACTIVE].
6825 tx_op_limit[i] = (u16) burst_duration;
6826 }
6827 }
6828
6829 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05006830 err = ipw_send_qos_params_command(priv,
6831 (struct ieee80211_qos_parameters *)
6832 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05006833 if (err)
6834 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6835
6836 return err;
6837}
6838
6839/*
6840* send IPW_CMD_WME_INFO to the firmware
6841*/
6842static int ipw_qos_set_info_element(struct ipw_priv *priv)
6843{
6844 int ret = 0;
6845 struct ieee80211_qos_information_element qos_info;
6846
6847 if (priv == NULL)
6848 return -1;
6849
6850 qos_info.elementID = QOS_ELEMENT_ID;
6851 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6852
6853 qos_info.version = QOS_VERSION_1;
6854 qos_info.ac_info = 0;
6855
6856 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6857 qos_info.qui_type = QOS_OUI_TYPE;
6858 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6859
6860 ret = ipw_send_qos_info_command(priv, &qos_info);
6861 if (ret != 0) {
6862 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6863 }
6864 return ret;
6865}
6866
6867/*
6868* Set the QoS parameter with the association request structure
6869*/
6870static int ipw_qos_association(struct ipw_priv *priv,
6871 struct ieee80211_network *network)
6872{
6873 int err = 0;
6874 struct ieee80211_qos_data *qos_data = NULL;
6875 struct ieee80211_qos_data ibss_data = {
6876 .supported = 1,
6877 .active = 1,
6878 };
6879
6880 switch (priv->ieee->iw_mode) {
6881 case IW_MODE_ADHOC:
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02006882 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
James Ketrenosb095c382005-08-24 22:04:42 -05006883
6884 qos_data = &ibss_data;
6885 break;
6886
6887 case IW_MODE_INFRA:
6888 qos_data = &network->qos_data;
6889 break;
6890
6891 default:
6892 BUG();
6893 break;
6894 }
6895
6896 err = ipw_qos_activate(priv, qos_data);
6897 if (err) {
6898 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6899 return err;
6900 }
6901
6902 if (priv->qos_data.qos_enable && qos_data->supported) {
6903 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6904 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6905 return ipw_qos_set_info_element(priv);
6906 }
6907
6908 return 0;
6909}
6910
6911/*
6912* handling the beaconing responces. if we get different QoS setting
6913* of the network from the the associated setting adjust the QoS
6914* setting
6915*/
6916static int ipw_qos_association_resp(struct ipw_priv *priv,
6917 struct ieee80211_network *network)
6918{
6919 int ret = 0;
6920 unsigned long flags;
6921 u32 size = sizeof(struct ieee80211_qos_parameters);
6922 int set_qos_param = 0;
6923
James Ketrenosafbf30a2005-08-25 00:05:33 -05006924 if ((priv == NULL) || (network == NULL) ||
6925 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05006926 return ret;
6927
6928 if (!(priv->status & STATUS_ASSOCIATED))
6929 return ret;
6930
James Ketrenosafbf30a2005-08-25 00:05:33 -05006931 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05006932 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05006933
6934 spin_lock_irqsave(&priv->ieee->lock, flags);
6935 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006936 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
James Ketrenosb095c382005-08-24 22:04:42 -05006937 sizeof(struct ieee80211_qos_data));
6938 priv->assoc_network->qos_data.active = 1;
6939 if ((network->qos_data.old_param_count !=
6940 network->qos_data.param_count)) {
6941 set_qos_param = 1;
6942 network->qos_data.old_param_count =
6943 network->qos_data.param_count;
6944 }
6945
6946 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006947 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
6948 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006949 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006950 else
6951 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006952 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006953 priv->assoc_network->qos_data.active = 0;
6954 priv->assoc_network->qos_data.supported = 0;
6955 set_qos_param = 1;
6956 }
6957
6958 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6959
6960 if (set_qos_param == 1)
6961 schedule_work(&priv->qos_activate);
6962
6963 return ret;
6964}
6965
6966static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
6967{
6968 u32 ret = 0;
6969
6970 if ((priv == NULL))
6971 return 0;
6972
James Ketrenosafbf30a2005-08-25 00:05:33 -05006973 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05006974 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006975 else
James Ketrenosb095c382005-08-24 22:04:42 -05006976 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006977
James Ketrenosb095c382005-08-24 22:04:42 -05006978 return ret;
6979}
6980
6981/*
6982* Initialize the setting of QoS global
6983*/
6984static void ipw_qos_init(struct ipw_priv *priv, int enable,
6985 int burst_enable, u32 burst_duration_CCK,
6986 u32 burst_duration_OFDM)
6987{
6988 priv->qos_data.qos_enable = enable;
6989
6990 if (priv->qos_data.qos_enable) {
6991 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
6992 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
6993 IPW_DEBUG_QOS("QoS is enabled\n");
6994 } else {
6995 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
6996 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
6997 IPW_DEBUG_QOS("QoS is not enabled\n");
6998 }
6999
7000 priv->qos_data.burst_enable = burst_enable;
7001
7002 if (burst_enable) {
7003 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7004 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7005 } else {
7006 priv->qos_data.burst_duration_CCK = 0;
7007 priv->qos_data.burst_duration_OFDM = 0;
7008 }
7009}
7010
7011/*
7012* map the packet priority to the right TX Queue
7013*/
7014static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7015{
7016 if (priority > 7 || !priv->qos_data.qos_enable)
7017 priority = 0;
7018
7019 return from_priority_to_tx_queue[priority] - 1;
7020}
7021
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007022static int ipw_is_qos_active(struct net_device *dev,
7023 struct sk_buff *skb)
James Ketrenosb095c382005-08-24 22:04:42 -05007024{
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007025 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosb095c382005-08-24 22:04:42 -05007026 struct ieee80211_qos_data *qos_data = NULL;
7027 int active, supported;
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007028 u8 *daddr = skb->data + ETH_ALEN;
7029 int unicast = !is_multicast_ether_addr(daddr);
James Ketrenosb095c382005-08-24 22:04:42 -05007030
7031 if (!(priv->status & STATUS_ASSOCIATED))
7032 return 0;
7033
7034 qos_data = &priv->assoc_network->qos_data;
7035
James Ketrenosb095c382005-08-24 22:04:42 -05007036 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7037 if (unicast == 0)
7038 qos_data->active = 0;
7039 else
7040 qos_data->active = qos_data->supported;
7041 }
James Ketrenosb095c382005-08-24 22:04:42 -05007042 active = qos_data->active;
7043 supported = qos_data->supported;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007044 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7045 "unicast %d\n",
7046 priv->qos_data.qos_enable, active, supported, unicast);
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007047 if (active && priv->qos_data.qos_enable)
7048 return 1;
James Ketrenosb095c382005-08-24 22:04:42 -05007049
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007050 return 0;
7051
7052}
7053/*
7054* add QoS parameter to the TX command
7055*/
7056static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7057 u16 priority,
7058 struct tfd_data *tfd)
7059{
7060 int tx_queue_id = 0;
7061
7062
7063 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7064 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7065
7066 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7067 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
7068 tfd->tfd.tfd_26.mchdr.qos_ctrl |= CTRL_QOS_NO_ACK;
James Ketrenosb095c382005-08-24 22:04:42 -05007069 }
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007070 return 0;
James Ketrenosb095c382005-08-24 22:04:42 -05007071}
7072
7073/*
7074* background support to run QoS activate functionality
7075*/
7076static void ipw_bg_qos_activate(void *data)
7077{
7078 struct ipw_priv *priv = data;
7079
7080 if (priv == NULL)
7081 return;
7082
Zhu Yi46441512006-01-24 16:37:59 +08007083 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007084
7085 if (priv->status & STATUS_ASSOCIATED)
7086 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7087
Zhu Yi46441512006-01-24 16:37:59 +08007088 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007089}
7090
James Ketrenos3b9990c2005-08-19 13:18:55 -05007091static int ipw_handle_probe_response(struct net_device *dev,
7092 struct ieee80211_probe_response *resp,
7093 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007094{
7095 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007096 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7097 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007098
James Ketrenos3b9990c2005-08-19 13:18:55 -05007099 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007100
James Ketrenos3b9990c2005-08-19 13:18:55 -05007101 return 0;
7102}
James Ketrenosb095c382005-08-24 22:04:42 -05007103
James Ketrenos3b9990c2005-08-19 13:18:55 -05007104static int ipw_handle_beacon(struct net_device *dev,
7105 struct ieee80211_beacon *resp,
7106 struct ieee80211_network *network)
7107{
7108 struct ipw_priv *priv = ieee80211_priv(dev);
7109 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7110 (network == priv->assoc_network));
7111
7112 ipw_qos_handle_probe_response(priv, active_network, network);
7113
7114 return 0;
7115}
7116
7117static int ipw_handle_assoc_response(struct net_device *dev,
7118 struct ieee80211_assoc_response *resp,
7119 struct ieee80211_network *network)
7120{
7121 struct ipw_priv *priv = ieee80211_priv(dev);
7122 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007123 return 0;
7124}
7125
7126static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7127 *qos_param)
7128{
Zhu Yi4e226992006-01-24 16:37:36 +08007129 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7130 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007131}
7132
7133static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7134 *qos_param)
7135{
Zhu Yi4e226992006-01-24 16:37:36 +08007136 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7137 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007138}
7139
Zhu Yie43e3c12006-04-13 17:20:45 +08007140#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -05007141
James Ketrenos43f66a62005-03-25 12:31:53 -06007142static int ipw_associate_network(struct ipw_priv *priv,
7143 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007144 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007145{
7146 int err;
7147
7148 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007149 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007150
7151 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007152 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007153 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007154 memcpy(priv->essid, network->ssid, priv->essid_len);
7155 }
7156
7157 network->last_associate = jiffies;
7158
7159 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7160 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007161 priv->assoc_request.auth_key = 0;
7162
James Ketrenos43f66a62005-03-25 12:31:53 -06007163 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007164 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007165 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007166 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7167
Zhu Yi1ba61e02006-02-15 13:00:55 +08007168 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007169 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007170
7171 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7172 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7173 priv->assoc_request.auth_type = AUTH_LEAP;
7174 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007175 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007176
James Ketrenosa613bff2005-08-24 21:43:11 -05007177 if (priv->ieee->wpa_ie_len) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007178 priv->assoc_request.policy_support = 0x02; /* RSN active */
7179 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7180 priv->ieee->wpa_ie_len);
7181 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007182
Jeff Garzikbf794512005-07-31 13:07:26 -04007183 /*
7184 * It is valid for our ieee device to support multiple modes, but
7185 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007186 * just one mode.
7187 */
7188 if (network->mode & priv->ieee->mode & IEEE_A)
7189 priv->assoc_request.ieee_mode = IPW_A_MODE;
7190 else if (network->mode & priv->ieee->mode & IEEE_G)
7191 priv->assoc_request.ieee_mode = IPW_G_MODE;
7192 else if (network->mode & priv->ieee->mode & IEEE_B)
7193 priv->assoc_request.ieee_mode = IPW_B_MODE;
7194
James Ketrenosea2b26e2005-08-24 21:25:16 -05007195 priv->assoc_request.capability = network->capability;
7196 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7197 && !(priv->config & CFG_PREAMBLE_LONG)) {
7198 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7199 } else {
7200 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7201
7202 /* Clear the short preamble if we won't be supporting it */
7203 priv->assoc_request.capability &=
7204 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7205 }
7206
James Ketrenosafbf30a2005-08-25 00:05:33 -05007207 /* Clear capability bits that aren't used in Ad Hoc */
7208 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7209 priv->assoc_request.capability &=
7210 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7211
James Ketrenos43f66a62005-03-25 12:31:53 -06007212 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007213 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007214 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04007215 escape_essid(priv->essid, priv->essid_len),
7216 network->channel,
7217 ipw_modes[priv->assoc_request.ieee_mode],
7218 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007219 (priv->assoc_request.preamble_length ==
7220 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7221 network->capability &
7222 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007223 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007224 priv->capability & CAP_PRIVACY_ON ?
7225 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007226 "(open)") : "",
7227 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007228 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007229 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007230 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007231
7232 priv->assoc_request.beacon_interval = network->beacon_interval;
7233 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007234 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007235 priv->assoc_request.assoc_type = HC_IBSS_START;
7236 priv->assoc_request.assoc_tsf_msw = 0;
7237 priv->assoc_request.assoc_tsf_lsw = 0;
7238 } else {
7239 if (unlikely(roaming))
7240 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7241 else
7242 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7243 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7244 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7245 }
7246
James Ketrenosafbf30a2005-08-25 00:05:33 -05007247 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007248
7249 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7250 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7251 priv->assoc_request.atim_window = network->atim_window;
7252 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007253 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007254 priv->assoc_request.atim_window = 0;
7255 }
7256
James Ketrenos43f66a62005-03-25 12:31:53 -06007257 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04007258
James Ketrenos43f66a62005-03-25 12:31:53 -06007259 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7260 if (err) {
7261 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7262 return err;
7263 }
7264
7265 rates->ieee_mode = priv->assoc_request.ieee_mode;
7266 rates->purpose = IPW_RATE_CONNECT;
7267 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007268
James Ketrenos43f66a62005-03-25 12:31:53 -06007269 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7270 priv->sys_config.dot11g_auto_detection = 1;
7271 else
7272 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007273
7274 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7275 priv->sys_config.answer_broadcast_ssid_probe = 1;
7276 else
7277 priv->sys_config.answer_broadcast_ssid_probe = 0;
7278
Zhu Yid685b8c2006-04-13 17:20:27 +08007279 err = ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007280 if (err) {
7281 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7282 return err;
7283 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007284
James Ketrenos43f66a62005-03-25 12:31:53 -06007285 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007286 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007287 if (err) {
7288 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7289 return err;
7290 }
7291
7292 /*
7293 * If preemption is enabled, it is possible for the association
7294 * to complete before we return from ipw_send_associate. Therefore
7295 * we have to be sure and update our priviate data first.
7296 */
7297 priv->channel = network->channel;
7298 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007299 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007300 priv->status &= ~STATUS_SECURITY_UPDATED;
7301
7302 priv->assoc_network = network;
7303
Zhu Yie43e3c12006-04-13 17:20:45 +08007304#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05007305 ipw_qos_association(priv, network);
7306#endif
7307
James Ketrenos43f66a62005-03-25 12:31:53 -06007308 err = ipw_send_associate(priv, &priv->assoc_request);
7309 if (err) {
7310 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7311 return err;
7312 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007313
7314 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007315 escape_essid(priv->essid, priv->essid_len),
7316 MAC_ARG(priv->bssid));
7317
7318 return 0;
7319}
7320
7321static void ipw_roam(void *data)
7322{
7323 struct ipw_priv *priv = data;
7324 struct ieee80211_network *network = NULL;
7325 struct ipw_network_match match = {
7326 .network = priv->assoc_network
7327 };
7328
7329 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007330 *
7331 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007332 * setting the status ROAM bit and requesting a scan.
7333 * 2. When the scan completes, it schedules the ROAM work
7334 * 3. The ROAM work looks at all of the known networks for one that
7335 * is a better network than the currently associated. If none
7336 * found, the ROAM process is over (ROAM bit cleared)
7337 * 4. If a better network is found, a disassociation request is
7338 * sent.
7339 * 5. When the disassociation completes, the roam work is again
7340 * scheduled. The second time through, the driver is no longer
7341 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007342 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007343 * 6. At this point ,the roaming process is complete and the ROAM
7344 * status bit is cleared.
7345 */
7346
7347 /* If we are no longer associated, and the roaming bit is no longer
7348 * set, then we are not actively roaming, so just return */
7349 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7350 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007351
James Ketrenos43f66a62005-03-25 12:31:53 -06007352 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007353 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007354 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007355 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007356 u8 rssi = priv->assoc_network->stats.rssi;
7357 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007358 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007359 list_for_each_entry(network, &priv->ieee->network_list, list) {
7360 if (network != priv->assoc_network)
7361 ipw_best_network(priv, &match, network, 1);
7362 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007363 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007364 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007365
James Ketrenos43f66a62005-03-25 12:31:53 -06007366 if (match.network == priv->assoc_network) {
7367 IPW_DEBUG_ASSOC("No better APs in this network to "
7368 "roam to.\n");
7369 priv->status &= ~STATUS_ROAMING;
7370 ipw_debug_config(priv);
7371 return;
7372 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007373
James Ketrenos43f66a62005-03-25 12:31:53 -06007374 ipw_send_disassociate(priv, 1);
7375 priv->assoc_network = match.network;
7376
7377 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007378 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007379
7380 /* Second pass through ROAM process -- request association */
7381 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7382 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7383 priv->status &= ~STATUS_ROAMING;
7384}
7385
James Ketrenosc848d0a2005-08-24 21:56:24 -05007386static void ipw_bg_roam(void *data)
7387{
7388 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08007389 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007390 ipw_roam(data);
Zhu Yi46441512006-01-24 16:37:59 +08007391 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007392}
7393
7394static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007395{
7396 struct ipw_priv *priv = data;
7397
7398 struct ieee80211_network *network = NULL;
7399 struct ipw_network_match match = {
7400 .network = NULL
7401 };
7402 struct ipw_supported_rates *rates;
7403 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007404 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007405
James Ketrenosb095c382005-08-24 22:04:42 -05007406 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7407 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7408 return 0;
7409 }
7410
James Ketrenosc848d0a2005-08-24 21:56:24 -05007411 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007412 IPW_DEBUG_ASSOC("Not attempting association (already in "
7413 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007414 return 0;
7415 }
7416
Hong Liue6324722005-09-14 21:04:15 -05007417 if (priv->status & STATUS_DISASSOCIATING) {
7418 IPW_DEBUG_ASSOC("Not attempting association (in "
7419 "disassociating)\n ");
7420 queue_work(priv->workqueue, &priv->associate);
7421 return 0;
7422 }
7423
James Ketrenosc848d0a2005-08-24 21:56:24 -05007424 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007425 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7426 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007427 return 0;
7428 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007429
7430 if (!(priv->config & CFG_ASSOCIATE) &&
7431 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007432 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007433 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007434 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007435 }
7436
James Ketrenosa613bff2005-08-24 21:43:11 -05007437 /* Protect our use of the network_list */
7438 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007439 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007440 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007441
7442 network = match.network;
7443 rates = &match.rates;
7444
7445 if (network == NULL &&
7446 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7447 priv->config & CFG_ADHOC_CREATE &&
7448 priv->config & CFG_STATIC_ESSID &&
James Ketrenosa613bff2005-08-24 21:43:11 -05007449 priv->config & CFG_STATIC_CHANNEL &&
James Ketrenos43f66a62005-03-25 12:31:53 -06007450 !list_empty(&priv->ieee->network_free_list)) {
7451 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007452 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007453 ipw_adhoc_create(priv, network);
7454 rates = &priv->rates;
7455 list_del(element);
7456 list_add_tail(&network->list, &priv->ieee->network_list);
7457 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007458 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007459
James Ketrenos43f66a62005-03-25 12:31:53 -06007460 /* If we reached the end of the list, then we don't have any valid
7461 * matching APs */
7462 if (!network) {
7463 ipw_debug_config(priv);
7464
James Ketrenosb095c382005-08-24 22:04:42 -05007465 if (!(priv->status & STATUS_SCANNING)) {
7466 if (!(priv->config & CFG_SPEED_SCAN))
7467 queue_delayed_work(priv->workqueue,
7468 &priv->request_scan,
7469 SCAN_INTERVAL);
7470 else
7471 queue_work(priv->workqueue,
7472 &priv->request_scan);
7473 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007474
James Ketrenosc848d0a2005-08-24 21:56:24 -05007475 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007476 }
7477
7478 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007479
7480 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007481}
Jeff Garzikbf794512005-07-31 13:07:26 -04007482
James Ketrenosc848d0a2005-08-24 21:56:24 -05007483static void ipw_bg_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007484{
James Ketrenosc848d0a2005-08-24 21:56:24 -05007485 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08007486 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007487 ipw_associate(data);
Zhu Yi46441512006-01-24 16:37:59 +08007488 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007489}
7490
James Ketrenosb095c382005-08-24 22:04:42 -05007491static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7492 struct sk_buff *skb)
7493{
7494 struct ieee80211_hdr *hdr;
7495 u16 fc;
7496
7497 hdr = (struct ieee80211_hdr *)skb->data;
7498 fc = le16_to_cpu(hdr->frame_ctl);
7499 if (!(fc & IEEE80211_FCTL_PROTECTED))
7500 return;
7501
7502 fc &= ~IEEE80211_FCTL_PROTECTED;
7503 hdr->frame_ctl = cpu_to_le16(fc);
7504 switch (priv->ieee->sec.level) {
7505 case SEC_LEVEL_3:
7506 /* Remove CCMP HDR */
7507 memmove(skb->data + IEEE80211_3ADDR_LEN,
7508 skb->data + IEEE80211_3ADDR_LEN + 8,
7509 skb->len - IEEE80211_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007510 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007511 break;
7512 case SEC_LEVEL_2:
7513 break;
7514 case SEC_LEVEL_1:
7515 /* Remove IV */
7516 memmove(skb->data + IEEE80211_3ADDR_LEN,
7517 skb->data + IEEE80211_3ADDR_LEN + 4,
7518 skb->len - IEEE80211_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007519 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007520 break;
7521 case SEC_LEVEL_0:
7522 break;
7523 default:
7524 printk(KERN_ERR "Unknow security level %d\n",
7525 priv->ieee->sec.level);
7526 break;
7527 }
7528}
7529
7530static void ipw_handle_data_packet(struct ipw_priv *priv,
7531 struct ipw_rx_mem_buffer *rxb,
7532 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007533{
Hong Liu567deaf2005-08-31 18:07:22 +08007534 struct ieee80211_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007535 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7536
7537 /* We received data from the HW, so stop the watchdog */
7538 priv->net_dev->trans_start = jiffies;
7539
Jeff Garzikbf794512005-07-31 13:07:26 -04007540 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007541 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007542 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007543 skb_tailroom(rxb->skb))) {
7544 priv->ieee->stats.rx_errors++;
7545 priv->wstats.discard.misc++;
7546 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7547 return;
7548 } else if (unlikely(!netif_running(priv->net_dev))) {
7549 priv->ieee->stats.rx_dropped++;
7550 priv->wstats.discard.misc++;
7551 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7552 return;
7553 }
7554
7555 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007556 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007557
7558 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007559 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007560
7561 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7562
James Ketrenosb095c382005-08-24 22:04:42 -05007563 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
Hong Liu567deaf2005-08-31 18:07:22 +08007564 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7565 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007566 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007567 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007568 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7569
Jeff Garzikbf794512005-07-31 13:07:26 -04007570 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06007571 priv->ieee->stats.rx_errors++;
James Ketrenosa613bff2005-08-24 21:43:11 -05007572 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007573 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007574 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007575 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007576}
7577
Zhu Yi459d4082006-04-13 17:21:00 +08007578#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05007579static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7580 struct ipw_rx_mem_buffer *rxb,
7581 struct ieee80211_rx_stats *stats)
7582{
7583 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7584 struct ipw_rx_frame *frame = &pkt->u.frame;
7585
7586 /* initial pull of some data */
7587 u16 received_channel = frame->received_channel;
7588 u8 antennaAndPhy = frame->antennaAndPhy;
7589 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7590 u16 pktrate = frame->rate;
7591
7592 /* Magic struct that slots into the radiotap header -- no reason
7593 * to build this manually element by element, we can write it much
7594 * more efficiently than we can parse it. ORDER MATTERS HERE */
Zhu Yid685b8c2006-04-13 17:20:27 +08007595 struct ipw_rt_hdr *ipw_rt;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007596
7597 short len = le16_to_cpu(pkt->u.frame.length);
7598
7599 /* We received data from the HW, so stop the watchdog */
7600 priv->net_dev->trans_start = jiffies;
7601
7602 /* We only process data packets if the
7603 * interface is open */
7604 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7605 skb_tailroom(rxb->skb))) {
7606 priv->ieee->stats.rx_errors++;
7607 priv->wstats.discard.misc++;
7608 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7609 return;
7610 } else if (unlikely(!netif_running(priv->net_dev))) {
7611 priv->ieee->stats.rx_dropped++;
7612 priv->wstats.discard.misc++;
7613 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7614 return;
7615 }
7616
7617 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7618 * that now */
7619 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7620 /* FIXME: Should alloc bigger skb instead */
7621 priv->ieee->stats.rx_dropped++;
7622 priv->wstats.discard.misc++;
7623 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7624 return;
7625 }
7626
7627 /* copy the frame itself */
7628 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7629 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7630
7631 /* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7632 * part of our real header, saves a little time.
7633 *
7634 * No longer necessary since we fill in all our data. Purge before merging
7635 * patch officially.
7636 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7637 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7638 */
7639
7640 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7641
7642 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7643 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7644 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7645
7646 /* Big bitfield of all the fields we provide in radiotap */
7647 ipw_rt->rt_hdr.it_present =
7648 ((1 << IEEE80211_RADIOTAP_FLAGS) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007649 (1 << IEEE80211_RADIOTAP_TSFT) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007650 (1 << IEEE80211_RADIOTAP_RATE) |
7651 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7652 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007653 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007654 (1 << IEEE80211_RADIOTAP_ANTENNA));
7655
7656 /* Zero the flags, we'll add to them as we go */
7657 ipw_rt->rt_flags = 0;
7658
7659 /* Convert signal to DBM */
7660 ipw_rt->rt_dbmsignal = antsignal;
7661
7662 /* Convert the channel data and set the flags */
7663 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7664 if (received_channel > 14) { /* 802.11a */
7665 ipw_rt->rt_chbitmask =
7666 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7667 } else if (antennaAndPhy & 32) { /* 802.11b */
7668 ipw_rt->rt_chbitmask =
7669 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7670 } else { /* 802.11g */
7671 ipw_rt->rt_chbitmask =
7672 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7673 }
7674
7675 /* set the rate in multiples of 500k/s */
7676 switch (pktrate) {
7677 case IPW_TX_RATE_1MB:
7678 ipw_rt->rt_rate = 2;
7679 break;
7680 case IPW_TX_RATE_2MB:
7681 ipw_rt->rt_rate = 4;
7682 break;
7683 case IPW_TX_RATE_5MB:
7684 ipw_rt->rt_rate = 10;
7685 break;
7686 case IPW_TX_RATE_6MB:
7687 ipw_rt->rt_rate = 12;
7688 break;
7689 case IPW_TX_RATE_9MB:
7690 ipw_rt->rt_rate = 18;
7691 break;
7692 case IPW_TX_RATE_11MB:
7693 ipw_rt->rt_rate = 22;
7694 break;
7695 case IPW_TX_RATE_12MB:
7696 ipw_rt->rt_rate = 24;
7697 break;
7698 case IPW_TX_RATE_18MB:
7699 ipw_rt->rt_rate = 36;
7700 break;
7701 case IPW_TX_RATE_24MB:
7702 ipw_rt->rt_rate = 48;
7703 break;
7704 case IPW_TX_RATE_36MB:
7705 ipw_rt->rt_rate = 72;
7706 break;
7707 case IPW_TX_RATE_48MB:
7708 ipw_rt->rt_rate = 96;
7709 break;
7710 case IPW_TX_RATE_54MB:
7711 ipw_rt->rt_rate = 108;
7712 break;
7713 default:
7714 ipw_rt->rt_rate = 0;
7715 break;
7716 }
7717
7718 /* antenna number */
7719 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7720
7721 /* set the preamble flag if we have it */
7722 if ((antennaAndPhy & 64))
7723 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7724
7725 /* Set the size of the skb to the size of the frame */
7726 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007727
7728 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7729
7730 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7731 priv->ieee->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007732 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007733 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007734 /* no LED during capture */
7735 }
7736}
7737#endif
7738
Zhu Yid685b8c2006-04-13 17:20:27 +08007739#ifdef CONFIG_IPW2200_PROMISCUOUS
7740#define ieee80211_is_probe_response(fc) \
7741 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7742 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7743
7744#define ieee80211_is_management(fc) \
7745 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7746
7747#define ieee80211_is_control(fc) \
7748 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7749
7750#define ieee80211_is_data(fc) \
7751 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
7752
7753#define ieee80211_is_assoc_request(fc) \
7754 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
7755
7756#define ieee80211_is_reassoc_request(fc) \
7757 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
7758
7759static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
7760 struct ipw_rx_mem_buffer *rxb,
7761 struct ieee80211_rx_stats *stats)
7762{
7763 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7764 struct ipw_rx_frame *frame = &pkt->u.frame;
7765 struct ipw_rt_hdr *ipw_rt;
7766
7767 /* First cache any information we need before we overwrite
7768 * the information provided in the skb from the hardware */
7769 struct ieee80211_hdr *hdr;
7770 u16 channel = frame->received_channel;
7771 u8 phy_flags = frame->antennaAndPhy;
7772 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
7773 s8 noise = frame->noise;
7774 u8 rate = frame->rate;
7775 short len = le16_to_cpu(pkt->u.frame.length);
7776 u64 tsf = 0;
7777 struct sk_buff *skb;
7778 int hdr_only = 0;
7779 u16 filter = priv->prom_priv->filter;
7780
7781 /* If the filter is set to not include Rx frames then return */
7782 if (filter & IPW_PROM_NO_RX)
7783 return;
7784
Zhu Yid685b8c2006-04-13 17:20:27 +08007785 /* We received data from the HW, so stop the watchdog */
7786 priv->prom_net_dev->trans_start = jiffies;
7787
7788 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
7789 priv->prom_priv->ieee->stats.rx_errors++;
7790 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7791 return;
7792 }
7793
7794 /* We only process data packets if the interface is open */
7795 if (unlikely(!netif_running(priv->prom_net_dev))) {
7796 priv->prom_priv->ieee->stats.rx_dropped++;
7797 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7798 return;
7799 }
7800
7801 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7802 * that now */
7803 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7804 /* FIXME: Should alloc bigger skb instead */
7805 priv->prom_priv->ieee->stats.rx_dropped++;
7806 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7807 return;
7808 }
7809
7810 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
7811 if (ieee80211_is_management(hdr->frame_ctl)) {
7812 if (filter & IPW_PROM_NO_MGMT)
7813 return;
7814 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
7815 hdr_only = 1;
7816 } else if (ieee80211_is_control(hdr->frame_ctl)) {
7817 if (filter & IPW_PROM_NO_CTL)
7818 return;
7819 if (filter & IPW_PROM_CTL_HEADER_ONLY)
7820 hdr_only = 1;
7821 } else if (ieee80211_is_data(hdr->frame_ctl)) {
7822 if (filter & IPW_PROM_NO_DATA)
7823 return;
7824 if (filter & IPW_PROM_DATA_HEADER_ONLY)
7825 hdr_only = 1;
7826 }
7827
7828 /* Copy the SKB since this is for the promiscuous side */
7829 skb = skb_copy(rxb->skb, GFP_ATOMIC);
7830 if (skb == NULL) {
7831 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
7832 return;
7833 }
7834
7835 /* copy the frame data to write after where the radiotap header goes */
7836 ipw_rt = (void *)skb->data;
7837
7838 if (hdr_only)
7839 len = ieee80211_get_hdrlen(hdr->frame_ctl);
7840
7841 memcpy(ipw_rt->payload, hdr, len);
7842
7843 /* Zero the radiotap static buffer ... We only need to zero the bytes
7844 * NOT part of our real header, saves a little time.
7845 *
7846 * No longer necessary since we fill in all our data. Purge before
7847 * merging patch officially.
7848 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7849 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7850 */
7851
7852 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7853 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7854 ipw_rt->rt_hdr.it_len = sizeof(*ipw_rt); /* total header+data */
7855
7856 /* Set the size of the skb to the size of the frame */
7857 skb_put(skb, ipw_rt->rt_hdr.it_len + len);
7858
7859 /* Big bitfield of all the fields we provide in radiotap */
7860 ipw_rt->rt_hdr.it_present =
7861 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7862 (1 << IEEE80211_RADIOTAP_TSFT) |
7863 (1 << IEEE80211_RADIOTAP_RATE) |
7864 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7865 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7866 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
7867 (1 << IEEE80211_RADIOTAP_ANTENNA));
7868
7869 /* Zero the flags, we'll add to them as we go */
7870 ipw_rt->rt_flags = 0;
7871
7872 ipw_rt->rt_tsf = tsf;
7873
7874 /* Convert to DBM */
7875 ipw_rt->rt_dbmsignal = signal;
7876 ipw_rt->rt_dbmnoise = noise;
7877
7878 /* Convert the channel data and set the flags */
7879 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
7880 if (channel > 14) { /* 802.11a */
7881 ipw_rt->rt_chbitmask =
7882 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7883 } else if (phy_flags & (1 << 5)) { /* 802.11b */
7884 ipw_rt->rt_chbitmask =
7885 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7886 } else { /* 802.11g */
7887 ipw_rt->rt_chbitmask =
7888 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7889 }
7890
7891 /* set the rate in multiples of 500k/s */
7892 switch (rate) {
7893 case IPW_TX_RATE_1MB:
7894 ipw_rt->rt_rate = 2;
7895 break;
7896 case IPW_TX_RATE_2MB:
7897 ipw_rt->rt_rate = 4;
7898 break;
7899 case IPW_TX_RATE_5MB:
7900 ipw_rt->rt_rate = 10;
7901 break;
7902 case IPW_TX_RATE_6MB:
7903 ipw_rt->rt_rate = 12;
7904 break;
7905 case IPW_TX_RATE_9MB:
7906 ipw_rt->rt_rate = 18;
7907 break;
7908 case IPW_TX_RATE_11MB:
7909 ipw_rt->rt_rate = 22;
7910 break;
7911 case IPW_TX_RATE_12MB:
7912 ipw_rt->rt_rate = 24;
7913 break;
7914 case IPW_TX_RATE_18MB:
7915 ipw_rt->rt_rate = 36;
7916 break;
7917 case IPW_TX_RATE_24MB:
7918 ipw_rt->rt_rate = 48;
7919 break;
7920 case IPW_TX_RATE_36MB:
7921 ipw_rt->rt_rate = 72;
7922 break;
7923 case IPW_TX_RATE_48MB:
7924 ipw_rt->rt_rate = 96;
7925 break;
7926 case IPW_TX_RATE_54MB:
7927 ipw_rt->rt_rate = 108;
7928 break;
7929 default:
7930 ipw_rt->rt_rate = 0;
7931 break;
7932 }
7933
7934 /* antenna number */
7935 ipw_rt->rt_antenna = (phy_flags & 3);
7936
7937 /* set the preamble flag if we have it */
7938 if (phy_flags & (1 << 6))
7939 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7940
7941 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
7942
7943 if (!ieee80211_rx(priv->prom_priv->ieee, skb, stats)) {
7944 priv->prom_priv->ieee->stats.rx_errors++;
7945 dev_kfree_skb_any(skb);
7946 }
7947}
7948#endif
7949
Arjan van de Ven858119e2006-01-14 13:20:43 -08007950static int is_network_packet(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007951 struct ieee80211_hdr_4addr *header)
7952{
7953 /* Filter incoming packets to determine if they are targetted toward
7954 * this network, discarding packets coming from ourselves */
7955 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05007956 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007957 /* packets from our adapter are dropped (echo) */
7958 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7959 return 0;
7960
Peter Jones90700fd2005-08-26 16:51:06 -05007961 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007962 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05007963 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007964
7965 /* packets to our adapter go through */
7966 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7967 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007968
Peter Jones90700fd2005-08-26 16:51:06 -05007969 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007970 /* packets from our adapter are dropped (echo) */
7971 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7972 return 0;
7973
Peter Jones90700fd2005-08-26 16:51:06 -05007974 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007975 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05007976 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7977
7978 /* packets to our adapter go through */
7979 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7980 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007981 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007982
James Ketrenosea2b26e2005-08-24 21:25:16 -05007983 return 1;
7984}
7985
James Ketrenosafbf30a2005-08-25 00:05:33 -05007986#define IPW_PACKET_RETRY_TIME HZ
7987
Arjan van de Ven858119e2006-01-14 13:20:43 -08007988static int is_duplicate_packet(struct ipw_priv *priv,
James Ketrenosafbf30a2005-08-25 00:05:33 -05007989 struct ieee80211_hdr_4addr *header)
7990{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007991 u16 sc = le16_to_cpu(header->seq_ctl);
7992 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7993 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7994 u16 *last_seq, *last_frag;
7995 unsigned long *last_time;
7996
7997 switch (priv->ieee->iw_mode) {
7998 case IW_MODE_ADHOC:
7999 {
8000 struct list_head *p;
8001 struct ipw_ibss_seq *entry = NULL;
8002 u8 *mac = header->addr2;
8003 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8004
8005 __list_for_each(p, &priv->ibss_mac_hash[index]) {
8006 entry =
8007 list_entry(p, struct ipw_ibss_seq, list);
8008 if (!memcmp(entry->mac, mac, ETH_ALEN))
8009 break;
8010 }
8011 if (p == &priv->ibss_mac_hash[index]) {
8012 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
8013 if (!entry) {
8014 IPW_ERROR
8015 ("Cannot malloc new mac entry\n");
8016 return 0;
8017 }
8018 memcpy(entry->mac, mac, ETH_ALEN);
8019 entry->seq_num = seq;
8020 entry->frag_num = frag;
8021 entry->packet_time = jiffies;
8022 list_add(&entry->list,
8023 &priv->ibss_mac_hash[index]);
8024 return 0;
8025 }
8026 last_seq = &entry->seq_num;
8027 last_frag = &entry->frag_num;
8028 last_time = &entry->packet_time;
8029 break;
8030 }
8031 case IW_MODE_INFRA:
8032 last_seq = &priv->last_seq_num;
8033 last_frag = &priv->last_frag_num;
8034 last_time = &priv->last_packet_time;
8035 break;
8036 default:
8037 return 0;
8038 }
8039 if ((*last_seq == seq) &&
8040 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8041 if (*last_frag == frag)
8042 goto drop;
8043 if (*last_frag + 1 != frag)
8044 /* out-of-order fragment */
8045 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008046 } else
8047 *last_seq = seq;
8048
Zhu Yif57ce7c2005-07-13 12:22:15 -05008049 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008050 *last_time = jiffies;
8051 return 0;
8052
8053 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08008054 /* Comment this line now since we observed the card receives
8055 * duplicate packets but the FCTL_RETRY bit is not set in the
8056 * IBSS mode with fragmentation enabled.
8057 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008058 return 1;
8059}
8060
James Ketrenosb095c382005-08-24 22:04:42 -05008061static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8062 struct ipw_rx_mem_buffer *rxb,
8063 struct ieee80211_rx_stats *stats)
8064{
8065 struct sk_buff *skb = rxb->skb;
8066 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
8067 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
8068 (skb->data + IPW_RX_FRAME_SIZE);
8069
8070 ieee80211_rx_mgt(priv->ieee, header, stats);
8071
8072 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8073 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8074 IEEE80211_STYPE_PROBE_RESP) ||
8075 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8076 IEEE80211_STYPE_BEACON))) {
8077 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8078 ipw_add_station(priv, header->addr2);
8079 }
8080
8081 if (priv->config & CFG_NET_STATS) {
8082 IPW_DEBUG_HC("sending stat packet\n");
8083
8084 /* Set the size of the skb to the size of the full
8085 * ipw header and 802.11 frame */
8086 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8087 IPW_RX_FRAME_SIZE);
8088
8089 /* Advance past the ipw packet header to the 802.11 frame */
8090 skb_pull(skb, IPW_RX_FRAME_SIZE);
8091
8092 /* Push the ieee80211_rx_stats before the 802.11 frame */
8093 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8094
8095 skb->dev = priv->ieee->dev;
8096
8097 /* Point raw at the ieee80211_stats */
8098 skb->mac.raw = skb->data;
8099
8100 skb->pkt_type = PACKET_OTHERHOST;
8101 skb->protocol = __constant_htons(ETH_P_80211_STATS);
8102 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8103 netif_rx(skb);
8104 rxb->skb = NULL;
8105 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008106}
8107
James Ketrenos43f66a62005-03-25 12:31:53 -06008108/*
8109 * Main entry function for recieving a packet with 80211 headers. This
8110 * should be called when ever the FW has notified us that there is a new
8111 * skb in the recieve queue.
8112 */
8113static void ipw_rx(struct ipw_priv *priv)
8114{
8115 struct ipw_rx_mem_buffer *rxb;
8116 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05008117 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06008118 u32 r, w, i;
8119 u8 network_packet;
8120
James Ketrenosb095c382005-08-24 22:04:42 -05008121 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8122 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
James Ketrenos43f66a62005-03-25 12:31:53 -06008123 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
8124
8125 while (i != r) {
8126 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06008127 if (unlikely(rxb == NULL)) {
8128 printk(KERN_CRIT "Queue not allocated!\n");
8129 break;
8130 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008131 priv->rxq->queue[i] = NULL;
8132
8133 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008134 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06008135 PCI_DMA_FROMDEVICE);
8136
8137 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8138 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8139 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008140 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008141
8142 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008143 case RX_FRAME_TYPE: /* 802.11 frame */ {
8144 struct ieee80211_rx_stats stats = {
James Ketrenosc848d0a2005-08-24 21:56:24 -05008145 .rssi =
8146 le16_to_cpu(pkt->u.frame.rssi_dbm) -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008147 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008148 .signal =
Bill Mossb1916082006-02-15 08:50:18 +08008149 le16_to_cpu(pkt->u.frame.rssi_dbm) -
8150 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008151 .noise =
8152 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008153 .rate = pkt->u.frame.rate,
8154 .mac_time = jiffies,
8155 .received_channel =
8156 pkt->u.frame.received_channel,
8157 .freq =
8158 (pkt->u.frame.
8159 control & (1 << 0)) ?
8160 IEEE80211_24GHZ_BAND :
8161 IEEE80211_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008162 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008163 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008164
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008165 if (stats.rssi != 0)
8166 stats.mask |= IEEE80211_STATMASK_RSSI;
8167 if (stats.signal != 0)
8168 stats.mask |= IEEE80211_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008169 if (stats.noise != 0)
8170 stats.mask |= IEEE80211_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008171 if (stats.rate != 0)
8172 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008173
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008174 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008175
Zhu Yid685b8c2006-04-13 17:20:27 +08008176#ifdef CONFIG_IPW2200_PROMISCUOUS
8177 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8178 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8179#endif
8180
James Ketrenosb095c382005-08-24 22:04:42 -05008181#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008182 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08008183#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yid685b8c2006-04-13 17:20:27 +08008184
8185 ipw_handle_data_packet_monitor(priv,
8186 rxb,
8187 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008188#else
Zhu Yid685b8c2006-04-13 17:20:27 +08008189 ipw_handle_data_packet(priv, rxb,
8190 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008191#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008192 break;
8193 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008194#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008195
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008196 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05008197 (struct ieee80211_hdr_4addr *)(rxb->skb->
8198 data +
8199 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008200 /* TODO: Check Ad-Hoc dest/source and make sure
8201 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008202 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008203 * frame control of the packet and disregard
8204 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008205
James Ketrenosea2b26e2005-08-24 21:25:16 -05008206 network_packet =
8207 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008208 if (network_packet && priv->assoc_network) {
8209 priv->assoc_network->stats.rssi =
8210 stats.rssi;
Zhu Yi00d21de2006-04-13 17:19:02 +08008211 priv->exp_avg_rssi =
8212 exponential_average(priv->exp_avg_rssi,
8213 stats.rssi, DEPTH_RSSI);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008214 }
8215
8216 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008217 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008218
James Ketrenosa613bff2005-08-24 21:43:11 -05008219 if (le16_to_cpu(pkt->u.frame.length) <
Zhu Yi9d0be032006-02-15 06:18:19 +08008220 ieee80211_get_hdrlen(le16_to_cpu(
8221 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008222 IPW_DEBUG_DROP
8223 ("Received packet is too small. "
8224 "Dropping.\n");
8225 priv->ieee->stats.rx_errors++;
8226 priv->wstats.discard.misc++;
8227 break;
8228 }
8229
James Ketrenosa613bff2005-08-24 21:43:11 -05008230 switch (WLAN_FC_GET_TYPE
8231 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008232
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008233 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008234 ipw_handle_mgmt_packet(priv, rxb,
8235 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008236 break;
8237
8238 case IEEE80211_FTYPE_CTL:
8239 break;
8240
8241 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008242 if (unlikely(!network_packet ||
8243 is_duplicate_packet(priv,
8244 header)))
8245 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008246 IPW_DEBUG_DROP("Dropping: "
8247 MAC_FMT ", "
8248 MAC_FMT ", "
8249 MAC_FMT "\n",
8250 MAC_ARG(header->
8251 addr1),
8252 MAC_ARG(header->
8253 addr2),
8254 MAC_ARG(header->
8255 addr3));
James Ketrenosb095c382005-08-24 22:04:42 -05008256 break;
8257 }
8258
8259 ipw_handle_data_packet(priv, rxb,
8260 &stats);
8261
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008262 break;
8263 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008264 break;
8265 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008266
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008267 case RX_HOST_NOTIFICATION_TYPE:{
8268 IPW_DEBUG_RX
8269 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008270 pkt->u.notification.subtype,
8271 pkt->u.notification.flags,
8272 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008273 ipw_rx_notification(priv, &pkt->u.notification);
8274 break;
8275 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008276
8277 default:
8278 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8279 pkt->header.message_type);
8280 break;
8281 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008282
8283 /* For now we just don't re-use anything. We can tweak this
8284 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008285 * fail to Rx correctly */
8286 if (rxb->skb != NULL) {
8287 dev_kfree_skb_any(rxb->skb);
8288 rxb->skb = NULL;
8289 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008290
James Ketrenos43f66a62005-03-25 12:31:53 -06008291 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008292 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008293 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008294
James Ketrenos43f66a62005-03-25 12:31:53 -06008295 i = (i + 1) % RX_QUEUE_SIZE;
8296 }
8297
8298 /* Backtrack one entry */
8299 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
8300
8301 ipw_rx_queue_restock(priv);
8302}
8303
James Ketrenosafbf30a2005-08-25 00:05:33 -05008304#define DEFAULT_RTS_THRESHOLD 2304U
8305#define MIN_RTS_THRESHOLD 1U
8306#define MAX_RTS_THRESHOLD 2304U
8307#define DEFAULT_BEACON_INTERVAL 100U
8308#define DEFAULT_SHORT_RETRY_LIMIT 7U
8309#define DEFAULT_LONG_RETRY_LIMIT 4U
8310
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008311/**
8312 * ipw_sw_reset
8313 * @option: options to control different reset behaviour
8314 * 0 = reset everything except the 'disable' module_param
8315 * 1 = reset everything and print out driver info (for probe only)
8316 * 2 = reset everything
8317 */
8318static int ipw_sw_reset(struct ipw_priv *priv, int option)
James Ketrenos43f66a62005-03-25 12:31:53 -06008319{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008320 int band, modulation;
8321 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008322
James Ketrenosafbf30a2005-08-25 00:05:33 -05008323 /* Initialize module parameter values here */
8324 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008325
James Ketrenosafbf30a2005-08-25 00:05:33 -05008326 /* 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;
James Ketrenos43f66a62005-03-25 12:31:53 -06008330
James Ketrenosafbf30a2005-08-25 00:05:33 -05008331 if (associate)
8332 priv->config |= CFG_ASSOCIATE;
8333 else
8334 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008335
James Ketrenosafbf30a2005-08-25 00:05:33 -05008336 if (auto_create)
8337 priv->config |= CFG_ADHOC_CREATE;
8338 else
8339 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8340
Zhu Yi17ed0812006-01-24 16:36:31 +08008341 priv->config &= ~CFG_STATIC_ESSID;
8342 priv->essid_len = 0;
8343 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8344
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008345 if (disable && option) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008346 priv->status |= STATUS_RF_KILL_SW;
8347 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008348 }
8349
James Ketrenosafbf30a2005-08-25 00:05:33 -05008350 if (channel != 0) {
8351 priv->config |= CFG_STATIC_CHANNEL;
8352 priv->channel = channel;
8353 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8354 /* TODO: Validate that provided channel is in range */
8355 }
Zhu Yie43e3c12006-04-13 17:20:45 +08008356#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05008357 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8358 burst_duration_CCK, burst_duration_OFDM);
Zhu Yie43e3c12006-04-13 17:20:45 +08008359#endif /* CONFIG_IPW2200_QOS */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008360
8361 switch (mode) {
8362 case 1:
8363 priv->ieee->iw_mode = IW_MODE_ADHOC;
8364 priv->net_dev->type = ARPHRD_ETHER;
8365
8366 break;
8367#ifdef CONFIG_IPW2200_MONITOR
8368 case 2:
8369 priv->ieee->iw_mode = IW_MODE_MONITOR;
Zhu Yi459d4082006-04-13 17:21:00 +08008370#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008371 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8372#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008373 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008374#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008375 break;
8376#endif
8377 default:
8378 case 0:
8379 priv->net_dev->type = ARPHRD_ETHER;
8380 priv->ieee->iw_mode = IW_MODE_INFRA;
8381 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008382 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008383
James Ketrenosafbf30a2005-08-25 00:05:33 -05008384 if (hwcrypto) {
8385 priv->ieee->host_encrypt = 0;
8386 priv->ieee->host_encrypt_msdu = 0;
8387 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008388 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008389 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008390 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008391
Zhu Yie402c932005-08-05 17:20:40 +08008392 /* IPW2200/2915 is abled to do hardware fragmentation. */
8393 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008394
James Ketrenosafbf30a2005-08-25 00:05:33 -05008395 if ((priv->pci_dev->device == 0x4223) ||
8396 (priv->pci_dev->device == 0x4224)) {
Zhu Yie8c69e22006-02-17 08:25:12 +08008397 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008398 printk(KERN_INFO DRV_NAME
8399 ": Detected Intel PRO/Wireless 2915ABG Network "
8400 "Connection\n");
8401 priv->ieee->abg_true = 1;
8402 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8403 modulation = IEEE80211_OFDM_MODULATION |
8404 IEEE80211_CCK_MODULATION;
8405 priv->adapter = IPW_2915ABG;
8406 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008407 } else {
Zhu Yie8c69e22006-02-17 08:25:12 +08008408 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008409 printk(KERN_INFO DRV_NAME
8410 ": Detected Intel PRO/Wireless 2200BG Network "
8411 "Connection\n");
8412
8413 priv->ieee->abg_true = 0;
8414 band = IEEE80211_24GHZ_BAND;
8415 modulation = IEEE80211_OFDM_MODULATION |
8416 IEEE80211_CCK_MODULATION;
8417 priv->adapter = IPW_2200BG;
8418 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008419 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008420
James Ketrenosafbf30a2005-08-25 00:05:33 -05008421 priv->ieee->freq_band = band;
8422 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008423
James Ketrenosafbf30a2005-08-25 00:05:33 -05008424 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008425
James Ketrenosafbf30a2005-08-25 00:05:33 -05008426 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8427 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008428
James Ketrenosafbf30a2005-08-25 00:05:33 -05008429 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8430 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8431 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008432
James Ketrenosafbf30a2005-08-25 00:05:33 -05008433 /* If power management is turned on, default to AC mode */
8434 priv->power_mode = IPW_POWER_AC;
8435 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008436
Zhu Yi0ece35b2005-08-05 17:26:51 +08008437 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008438}
8439
8440/*
8441 * This file defines the Wireless Extension handlers. It does not
8442 * define any methods of hardware manipulation and relies on the
8443 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008444 *
8445 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008446 * function used to poll the hardware vs. making unecessary calls.
8447 *
8448 */
8449
Jeff Garzikbf794512005-07-31 13:07:26 -04008450static int ipw_wx_get_name(struct net_device *dev,
8451 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008452 union iwreq_data *wrqu, char *extra)
8453{
8454 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008455 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008456 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -05008457 strcpy(wrqu->name, "radio off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008458 else if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06008459 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04008460 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008461 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8462 ipw_modes[priv->assoc_request.ieee_mode]);
8463 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
Zhu Yi46441512006-01-24 16:37:59 +08008464 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008465 return 0;
8466}
8467
8468static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8469{
8470 if (channel == 0) {
8471 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8472 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008473 IPW_DEBUG_ASSOC("Attempting to associate with new "
8474 "parameters.\n");
8475 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008476 return 0;
8477 }
8478
8479 priv->config |= CFG_STATIC_CHANNEL;
8480
8481 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008482 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8483 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008484 return 0;
8485 }
8486
8487 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8488 priv->channel = channel;
8489
James Ketrenosb095c382005-08-24 22:04:42 -05008490#ifdef CONFIG_IPW2200_MONITOR
8491 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008492 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008493 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008494 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008495 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008496 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008497 }
8498
8499 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8500 udelay(10);
8501
8502 if (priv->status & STATUS_SCANNING)
8503 IPW_DEBUG_SCAN("Still scanning...\n");
8504 else
8505 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8506 1000 - i);
8507
8508 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008509 }
James Ketrenosb095c382005-08-24 22:04:42 -05008510#endif /* CONFIG_IPW2200_MONITOR */
8511
James Ketrenosc848d0a2005-08-24 21:56:24 -05008512 /* Network configuration changed -- force [re]association */
8513 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8514 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008515 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008516
8517 return 0;
8518}
8519
Jeff Garzikbf794512005-07-31 13:07:26 -04008520static int ipw_wx_set_freq(struct net_device *dev,
8521 struct iw_request_info *info,
8522 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008523{
8524 struct ipw_priv *priv = ieee80211_priv(dev);
Larry Finger1867b112006-02-28 09:48:28 -06008525 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008526 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008527 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008528 u8 channel, flags;
8529 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008530
James Ketrenosb095c382005-08-24 22:04:42 -05008531 if (fwrq->m == 0) {
8532 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008533 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008534 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008535 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008536 return ret;
8537 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008538 /* if setting by freq convert to channel */
8539 if (fwrq->e == 1) {
Larry Finger1867b112006-02-28 09:48:28 -06008540 channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008541 if (channel == 0)
8542 return -EINVAL;
8543 } else
8544 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008545
Larry Finger1867b112006-02-28 09:48:28 -06008546 if (!(band = ieee80211_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008547 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008548
Liu Hong1fe0adb2005-08-19 09:33:10 -05008549 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
Larry Finger1867b112006-02-28 09:48:28 -06008550 i = ieee80211_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008551 if (i == -1)
8552 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008553
8554 flags = (band == IEEE80211_24GHZ_BAND) ?
8555 geo->bg[i].flags : geo->a[i].flags;
8556 if (flags & IEEE80211_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008557 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8558 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008559 }
8560 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008561
James Ketrenos43f66a62005-03-25 12:31:53 -06008562 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008563 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008564 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008565 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008566 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008567}
8568
Jeff Garzikbf794512005-07-31 13:07:26 -04008569static int ipw_wx_get_freq(struct net_device *dev,
8570 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008571 union iwreq_data *wrqu, char *extra)
8572{
8573 struct ipw_priv *priv = ieee80211_priv(dev);
8574
8575 wrqu->freq.e = 0;
8576
8577 /* If we are associated, trying to associate, or have a statically
8578 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008579 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008580 if (priv->config & CFG_STATIC_CHANNEL ||
8581 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8582 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04008583 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008584 wrqu->freq.m = 0;
8585
Zhu Yi46441512006-01-24 16:37:59 +08008586 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008587 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8588 return 0;
8589}
8590
Jeff Garzikbf794512005-07-31 13:07:26 -04008591static int ipw_wx_set_mode(struct net_device *dev,
8592 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008593 union iwreq_data *wrqu, char *extra)
8594{
8595 struct ipw_priv *priv = ieee80211_priv(dev);
8596 int err = 0;
8597
8598 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8599
James Ketrenos43f66a62005-03-25 12:31:53 -06008600 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008601#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008602 case IW_MODE_MONITOR:
8603#endif
8604 case IW_MODE_ADHOC:
8605 case IW_MODE_INFRA:
8606 break;
8607 case IW_MODE_AUTO:
8608 wrqu->mode = IW_MODE_INFRA;
8609 break;
8610 default:
8611 return -EINVAL;
8612 }
James Ketrenosb095c382005-08-24 22:04:42 -05008613 if (wrqu->mode == priv->ieee->iw_mode)
8614 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008615
Zhu Yi46441512006-01-24 16:37:59 +08008616 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008617
8618 ipw_sw_reset(priv, 0);
8619
James Ketrenosb095c382005-08-24 22:04:42 -05008620#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008621 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008622 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008623
8624 if (wrqu->mode == IW_MODE_MONITOR)
Zhu Yi459d4082006-04-13 17:21:00 +08008625#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008626 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8627#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008628 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008629#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008630#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008631
Jeff Garzikbf794512005-07-31 13:07:26 -04008632 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06008633 * flag so ipw_load() will bring in the new firmawre */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008634 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008635
8636 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008637
James Ketrenosc848d0a2005-08-24 21:56:24 -05008638 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008639 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008640 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008641}
8642
Jeff Garzikbf794512005-07-31 13:07:26 -04008643static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008644 struct iw_request_info *info,
8645 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008646{
8647 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008648 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008649 wrqu->mode = priv->ieee->iw_mode;
8650 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008651 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008652 return 0;
8653}
8654
James Ketrenos43f66a62005-03-25 12:31:53 -06008655/* Values are in microsecond */
8656static const s32 timeout_duration[] = {
8657 350000,
8658 250000,
8659 75000,
8660 37000,
8661 25000,
8662};
8663
8664static const s32 period_duration[] = {
8665 400000,
8666 700000,
8667 1000000,
8668 1000000,
8669 1000000
8670};
8671
Jeff Garzikbf794512005-07-31 13:07:26 -04008672static int ipw_wx_get_range(struct net_device *dev,
8673 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008674 union iwreq_data *wrqu, char *extra)
8675{
8676 struct ipw_priv *priv = ieee80211_priv(dev);
8677 struct iw_range *range = (struct iw_range *)extra;
Larry Finger1867b112006-02-28 09:48:28 -06008678 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008679 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008680
8681 wrqu->data.length = sizeof(*range);
8682 memset(range, 0, sizeof(*range));
8683
8684 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008685 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008686
8687 range->max_qual.qual = 100;
8688 /* TODO: Find real max RSSI and stick here */
8689 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008690 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008691 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008692
8693 range->avg_qual.qual = 70;
8694 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008695 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008696 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008697 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008698 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008699 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008700
Jeff Garzikbf794512005-07-31 13:07:26 -04008701 for (i = 0; i < range->num_bitrates; i++)
8702 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008703 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008704
James Ketrenos43f66a62005-03-25 12:31:53 -06008705 range->max_rts = DEFAULT_RTS_THRESHOLD;
8706 range->min_frag = MIN_FRAG_THRESHOLD;
8707 range->max_frag = MAX_FRAG_THRESHOLD;
8708
8709 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008710 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008711 range->num_encoding_sizes = 2;
8712 range->max_encoding_tokens = WEP_KEYS;
8713
8714 /* Set the Wireless Extension versions */
8715 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008716 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008717
James Ketrenosb095c382005-08-24 22:04:42 -05008718 i = 0;
8719 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
Zhu Yie815de42006-03-02 05:55:51 +08008720 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8721 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8722 (geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8723 continue;
8724
James Ketrenosb095c382005-08-24 22:04:42 -05008725 range->freq[i].i = geo->bg[j].channel;
8726 range->freq[i].m = geo->bg[j].freq * 100000;
8727 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008728 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008729 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008730 }
James Ketrenosb095c382005-08-24 22:04:42 -05008731
8732 if (priv->ieee->mode & IEEE_A) {
Zhu Yie815de42006-03-02 05:55:51 +08008733 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8734 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8735 (geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8736 continue;
8737
James Ketrenosb095c382005-08-24 22:04:42 -05008738 range->freq[i].i = geo->a[j].channel;
8739 range->freq[i].m = geo->a[j].freq * 100000;
8740 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008741 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008742 }
8743 }
8744
8745 range->num_channels = i;
8746 range->num_frequency = i;
8747
Zhu Yi46441512006-01-24 16:37:59 +08008748 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008749
8750 /* Event capability (kernel + driver) */
8751 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8752 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
Zhu Yi07f02e42006-04-13 17:19:25 +08008753 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
8754 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008755 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008756
Dan Williamsf1b50862006-01-30 13:58:56 -05008757 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8758 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8759
James Ketrenos43f66a62005-03-25 12:31:53 -06008760 IPW_DEBUG_WX("GET Range\n");
8761 return 0;
8762}
8763
Jeff Garzikbf794512005-07-31 13:07:26 -04008764static int ipw_wx_set_wap(struct net_device *dev,
8765 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008766 union iwreq_data *wrqu, char *extra)
8767{
8768 struct ipw_priv *priv = ieee80211_priv(dev);
8769
8770 static const unsigned char any[] = {
8771 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8772 };
8773 static const unsigned char off[] = {
8774 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8775 };
8776
Jeff Garzikbf794512005-07-31 13:07:26 -04008777 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06008778 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08008779 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008780 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8781 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8782 /* we disable mandatory BSSID association */
8783 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8784 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008785 IPW_DEBUG_ASSOC("Attempting to associate with new "
8786 "parameters.\n");
8787 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08008788 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008789 return 0;
8790 }
8791
8792 priv->config |= CFG_STATIC_BSSID;
8793 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8794 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008795 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008796 return 0;
8797 }
8798
8799 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8800 MAC_ARG(wrqu->ap_addr.sa_data));
8801
8802 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8803
James Ketrenosc848d0a2005-08-24 21:56:24 -05008804 /* Network configuration changed -- force [re]association */
8805 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8806 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008807 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008808
Zhu Yi46441512006-01-24 16:37:59 +08008809 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008810 return 0;
8811}
8812
Jeff Garzikbf794512005-07-31 13:07:26 -04008813static int ipw_wx_get_wap(struct net_device *dev,
8814 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008815 union iwreq_data *wrqu, char *extra)
8816{
8817 struct ipw_priv *priv = ieee80211_priv(dev);
8818 /* If we are associated, trying to associate, or have a statically
8819 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008820 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04008821 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06008822 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8823 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008824 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06008825 } else
8826 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8827
8828 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8829 MAC_ARG(wrqu->ap_addr.sa_data));
Zhu Yi46441512006-01-24 16:37:59 +08008830 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008831 return 0;
8832}
8833
Jeff Garzikbf794512005-07-31 13:07:26 -04008834static int ipw_wx_set_essid(struct net_device *dev,
8835 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008836 union iwreq_data *wrqu, char *extra)
8837{
8838 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008839 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06008840 int length = 0;
Zhu Yi46441512006-01-24 16:37:59 +08008841 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008842 if (wrqu->essid.flags && wrqu->essid.length) {
8843 length = wrqu->essid.length - 1;
8844 essid = extra;
8845 }
8846 if (length == 0) {
8847 IPW_DEBUG_WX("Setting ESSID to ANY\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008848 if ((priv->config & CFG_STATIC_ESSID) &&
8849 !(priv->status & (STATUS_ASSOCIATED |
James Ketrenos43f66a62005-03-25 12:31:53 -06008850 STATUS_ASSOCIATING))) {
8851 IPW_DEBUG_ASSOC("Attempting to associate with new "
8852 "parameters.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008853 priv->config &= ~CFG_STATIC_ESSID;
James Ketrenos43f66a62005-03-25 12:31:53 -06008854 ipw_associate(priv);
8855 }
Zhu Yi46441512006-01-24 16:37:59 +08008856 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008857 return 0;
8858 }
8859
8860 length = min(length, IW_ESSID_MAX_SIZE);
8861
8862 priv->config |= CFG_STATIC_ESSID;
8863
8864 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8865 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008866 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008867 return 0;
8868 }
8869
8870 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8871 length);
8872
8873 priv->essid_len = length;
8874 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04008875
James Ketrenosc848d0a2005-08-24 21:56:24 -05008876 /* Network configuration changed -- force [re]association */
8877 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8878 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008879 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008880
Zhu Yi46441512006-01-24 16:37:59 +08008881 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008882 return 0;
8883}
8884
Jeff Garzikbf794512005-07-31 13:07:26 -04008885static int ipw_wx_get_essid(struct net_device *dev,
8886 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008887 union iwreq_data *wrqu, char *extra)
8888{
8889 struct ipw_priv *priv = ieee80211_priv(dev);
8890
8891 /* If we are associated, trying to associate, or have a statically
8892 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008893 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008894 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04008895 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8896 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008897 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04008898 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06008899 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008900 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008901 } else {
8902 IPW_DEBUG_WX("Getting essid: ANY\n");
8903 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008904 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008905 }
Zhu Yi46441512006-01-24 16:37:59 +08008906 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008907 return 0;
8908}
8909
Jeff Garzikbf794512005-07-31 13:07:26 -04008910static int ipw_wx_set_nick(struct net_device *dev,
8911 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008912 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008913{
James Ketrenos43f66a62005-03-25 12:31:53 -06008914 struct ipw_priv *priv = ieee80211_priv(dev);
8915
8916 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8917 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8918 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08008919 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008920 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06008921 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008922 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06008923 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08008924 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008925 return 0;
8926
8927}
8928
Jeff Garzikbf794512005-07-31 13:07:26 -04008929static int ipw_wx_get_nick(struct net_device *dev,
8930 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008931 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008932{
James Ketrenos43f66a62005-03-25 12:31:53 -06008933 struct ipw_priv *priv = ieee80211_priv(dev);
8934 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08008935 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008936 wrqu->data.length = strlen(priv->nick) + 1;
8937 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008938 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08008939 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008940 return 0;
8941}
8942
Olivier Hochreutiner651be262006-03-08 03:13:55 +08008943static int ipw_wx_set_sens(struct net_device *dev,
8944 struct iw_request_info *info,
8945 union iwreq_data *wrqu, char *extra)
8946{
8947 struct ipw_priv *priv = ieee80211_priv(dev);
8948 int err = 0;
8949
8950 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
8951 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
8952 mutex_lock(&priv->mutex);
8953
8954 if (wrqu->sens.fixed == 0)
8955 {
8956 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8957 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8958 goto out;
8959 }
8960 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
8961 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
8962 err = -EINVAL;
8963 goto out;
8964 }
8965
8966 priv->roaming_threshold = wrqu->sens.value;
8967 priv->disassociate_threshold = 3*wrqu->sens.value;
8968 out:
8969 mutex_unlock(&priv->mutex);
8970 return err;
8971}
8972
8973static int ipw_wx_get_sens(struct net_device *dev,
8974 struct iw_request_info *info,
8975 union iwreq_data *wrqu, char *extra)
8976{
8977 struct ipw_priv *priv = ieee80211_priv(dev);
8978 mutex_lock(&priv->mutex);
8979 wrqu->sens.fixed = 1;
8980 wrqu->sens.value = priv->roaming_threshold;
8981 mutex_unlock(&priv->mutex);
8982
8983 IPW_DEBUG_WX("GET roaming threshold -> %s %d \n",
8984 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
8985
8986 return 0;
8987}
8988
James Ketrenos43f66a62005-03-25 12:31:53 -06008989static int ipw_wx_set_rate(struct net_device *dev,
8990 struct iw_request_info *info,
8991 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008992{
James Ketrenosea2b26e2005-08-24 21:25:16 -05008993 /* TODO: We should use semaphores or locks for access to priv */
8994 struct ipw_priv *priv = ieee80211_priv(dev);
8995 u32 target_rate = wrqu->bitrate.value;
8996 u32 fixed, mask;
8997
8998 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8999 /* value = X, fixed = 1 means only rate X */
9000 /* value = X, fixed = 0 means all rates lower equal X */
9001
9002 if (target_rate == -1) {
9003 fixed = 0;
9004 mask = IEEE80211_DEFAULT_RATES_MASK;
9005 /* Now we should reassociate */
9006 goto apply;
9007 }
9008
9009 mask = 0;
9010 fixed = wrqu->bitrate.fixed;
9011
9012 if (target_rate == 1000000 || !fixed)
9013 mask |= IEEE80211_CCK_RATE_1MB_MASK;
9014 if (target_rate == 1000000)
9015 goto apply;
9016
9017 if (target_rate == 2000000 || !fixed)
9018 mask |= IEEE80211_CCK_RATE_2MB_MASK;
9019 if (target_rate == 2000000)
9020 goto apply;
9021
9022 if (target_rate == 5500000 || !fixed)
9023 mask |= IEEE80211_CCK_RATE_5MB_MASK;
9024 if (target_rate == 5500000)
9025 goto apply;
9026
9027 if (target_rate == 6000000 || !fixed)
9028 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
9029 if (target_rate == 6000000)
9030 goto apply;
9031
9032 if (target_rate == 9000000 || !fixed)
9033 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
9034 if (target_rate == 9000000)
9035 goto apply;
9036
9037 if (target_rate == 11000000 || !fixed)
9038 mask |= IEEE80211_CCK_RATE_11MB_MASK;
9039 if (target_rate == 11000000)
9040 goto apply;
9041
9042 if (target_rate == 12000000 || !fixed)
9043 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
9044 if (target_rate == 12000000)
9045 goto apply;
9046
9047 if (target_rate == 18000000 || !fixed)
9048 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
9049 if (target_rate == 18000000)
9050 goto apply;
9051
9052 if (target_rate == 24000000 || !fixed)
9053 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
9054 if (target_rate == 24000000)
9055 goto apply;
9056
9057 if (target_rate == 36000000 || !fixed)
9058 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
9059 if (target_rate == 36000000)
9060 goto apply;
9061
9062 if (target_rate == 48000000 || !fixed)
9063 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
9064 if (target_rate == 48000000)
9065 goto apply;
9066
9067 if (target_rate == 54000000 || !fixed)
9068 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
9069 if (target_rate == 54000000)
9070 goto apply;
9071
9072 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9073 return -EINVAL;
9074
9075 apply:
9076 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9077 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08009078 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009079 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009080 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05009081 ipw_set_fixed_rate(priv, priv->ieee->mode);
9082 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05009083 priv->config |= CFG_FIXED_RATE;
9084
James Ketrenosc848d0a2005-08-24 21:56:24 -05009085 if (priv->rates_mask == mask) {
9086 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009087 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009088 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009089 }
9090
James Ketrenosc848d0a2005-08-24 21:56:24 -05009091 priv->rates_mask = mask;
9092
9093 /* Network configuration changed -- force [re]association */
9094 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9095 if (!ipw_disassociate(priv))
9096 ipw_associate(priv);
9097
Zhu Yi46441512006-01-24 16:37:59 +08009098 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009099 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009100}
9101
Jeff Garzikbf794512005-07-31 13:07:26 -04009102static int ipw_wx_get_rate(struct net_device *dev,
9103 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009104 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009105{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009106 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009107 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009108 wrqu->bitrate.value = priv->last_rate;
Zhu Yi455936c2006-04-13 17:20:05 +08009109 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009110 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009111 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
9112 return 0;
9113}
9114
Jeff Garzikbf794512005-07-31 13:07:26 -04009115static int ipw_wx_set_rts(struct net_device *dev,
9116 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009117 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009118{
James Ketrenos43f66a62005-03-25 12:31:53 -06009119 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009120 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009121 if (wrqu->rts.disabled)
9122 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9123 else {
9124 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05009125 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009126 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009127 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009128 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009129 priv->rts_threshold = wrqu->rts.value;
9130 }
9131
9132 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08009133 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009134 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
9135 return 0;
9136}
9137
Jeff Garzikbf794512005-07-31 13:07:26 -04009138static int ipw_wx_get_rts(struct net_device *dev,
9139 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009140 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009141{
James Ketrenos43f66a62005-03-25 12:31:53 -06009142 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009143 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009144 wrqu->rts.value = priv->rts_threshold;
9145 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009146 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08009147 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009148 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
9149 return 0;
9150}
9151
Jeff Garzikbf794512005-07-31 13:07:26 -04009152static int ipw_wx_set_txpow(struct net_device *dev,
9153 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009154 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009155{
James Ketrenos43f66a62005-03-25 12:31:53 -06009156 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009157 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009158
Zhu Yi46441512006-01-24 16:37:59 +08009159 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009160 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009161 err = -EINPROGRESS;
9162 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009163 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009164
James Ketrenosb095c382005-08-24 22:04:42 -05009165 if (!wrqu->power.fixed)
9166 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06009167
James Ketrenosc848d0a2005-08-24 21:56:24 -05009168 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009169 err = -EINVAL;
9170 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009171 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009172
James Ketrenosb095c382005-08-24 22:04:42 -05009173 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05009174 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009175 err = -EINVAL;
9176 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009177 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009178
9179 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009180 err = ipw_set_tx_power(priv);
9181 out:
Zhu Yi46441512006-01-24 16:37:59 +08009182 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009183 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009184}
9185
Jeff Garzikbf794512005-07-31 13:07:26 -04009186static int ipw_wx_get_txpow(struct net_device *dev,
9187 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009188 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009189{
James Ketrenos43f66a62005-03-25 12:31:53 -06009190 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009191 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009192 wrqu->power.value = priv->tx_power;
9193 wrqu->power.fixed = 1;
9194 wrqu->power.flags = IW_TXPOW_DBM;
9195 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009196 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009197
Jeff Garzikbf794512005-07-31 13:07:26 -04009198 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08009199 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009200
9201 return 0;
9202}
9203
Jeff Garzikbf794512005-07-31 13:07:26 -04009204static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009205 struct iw_request_info *info,
9206 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009207{
9208 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009209 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009210 if (wrqu->frag.disabled)
9211 priv->ieee->fts = DEFAULT_FTS;
9212 else {
9213 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05009214 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009215 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009216 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05009217 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009218
James Ketrenos43f66a62005-03-25 12:31:53 -06009219 priv->ieee->fts = wrqu->frag.value & ~0x1;
9220 }
9221
9222 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08009223 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009224 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
9225 return 0;
9226}
9227
Jeff Garzikbf794512005-07-31 13:07:26 -04009228static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009229 struct iw_request_info *info,
9230 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009231{
9232 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009233 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009234 wrqu->frag.value = priv->ieee->fts;
9235 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009236 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08009237 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009238 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
9239
9240 return 0;
9241}
9242
Jeff Garzikbf794512005-07-31 13:07:26 -04009243static int ipw_wx_set_retry(struct net_device *dev,
9244 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009245 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009246{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009247 struct ipw_priv *priv = ieee80211_priv(dev);
9248
9249 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9250 return -EINVAL;
9251
9252 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9253 return 0;
9254
9255 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
9256 return -EINVAL;
9257
Zhu Yi46441512006-01-24 16:37:59 +08009258 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009259 if (wrqu->retry.flags & IW_RETRY_MIN)
9260 priv->short_retry_limit = (u8) wrqu->retry.value;
9261 else if (wrqu->retry.flags & IW_RETRY_MAX)
9262 priv->long_retry_limit = (u8) wrqu->retry.value;
9263 else {
9264 priv->short_retry_limit = (u8) wrqu->retry.value;
9265 priv->long_retry_limit = (u8) wrqu->retry.value;
9266 }
9267
9268 ipw_send_retry_limit(priv, priv->short_retry_limit,
9269 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08009270 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009271 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9272 priv->short_retry_limit, priv->long_retry_limit);
9273 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009274}
9275
Jeff Garzikbf794512005-07-31 13:07:26 -04009276static int ipw_wx_get_retry(struct net_device *dev,
9277 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009278 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009279{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009280 struct ipw_priv *priv = ieee80211_priv(dev);
9281
Zhu Yi46441512006-01-24 16:37:59 +08009282 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009283 wrqu->retry.disabled = 0;
9284
9285 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08009286 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009287 return -EINVAL;
9288 }
9289
9290 if (wrqu->retry.flags & IW_RETRY_MAX) {
9291 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
9292 wrqu->retry.value = priv->long_retry_limit;
9293 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
9294 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
9295 wrqu->retry.value = priv->short_retry_limit;
9296 } else {
9297 wrqu->retry.flags = IW_RETRY_LIMIT;
9298 wrqu->retry.value = priv->short_retry_limit;
9299 }
Zhu Yi46441512006-01-24 16:37:59 +08009300 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009301
9302 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9303
9304 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009305}
9306
James Ketrenosafbf30a2005-08-25 00:05:33 -05009307static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
9308 int essid_len)
9309{
9310 struct ipw_scan_request_ext scan;
9311 int err = 0, scan_type;
9312
Pekka Enbergefb34422005-11-16 21:55:05 +02009313 if (!(priv->status & STATUS_INIT) ||
9314 (priv->status & STATUS_EXIT_PENDING))
9315 return 0;
9316
Zhu Yi46441512006-01-24 16:37:59 +08009317 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009318
9319 if (priv->status & STATUS_RF_KILL_MASK) {
9320 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
9321 priv->status |= STATUS_SCAN_PENDING;
9322 goto done;
9323 }
9324
9325 IPW_DEBUG_HC("starting request direct scan!\n");
9326
9327 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
Olaf Kirchd834a412006-01-09 17:00:37 +01009328 /* We should not sleep here; otherwise we will block most
9329 * of the system (for instance, we hold rtnl_lock when we
9330 * get here).
9331 */
9332 err = -EAGAIN;
9333 goto done;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009334 }
9335 memset(&scan, 0, sizeof(scan));
9336
9337 if (priv->config & CFG_SPEED_SCAN)
9338 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9339 cpu_to_le16(30);
9340 else
9341 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9342 cpu_to_le16(20);
9343
9344 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
9345 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05009346 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009347 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
9348
9349 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
9350
9351 err = ipw_send_ssid(priv, essid, essid_len);
9352 if (err) {
9353 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
9354 goto done;
9355 }
9356 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
9357
9358 ipw_add_scan_channels(priv, &scan, scan_type);
9359
9360 err = ipw_send_scan_request_ext(priv, &scan);
9361 if (err) {
9362 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
9363 goto done;
9364 }
9365
9366 priv->status |= STATUS_SCANNING;
9367
9368 done:
Zhu Yi46441512006-01-24 16:37:59 +08009369 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009370 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009371}
9372
Jeff Garzikbf794512005-07-31 13:07:26 -04009373static int ipw_wx_set_scan(struct net_device *dev,
9374 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009375 union iwreq_data *wrqu, char *extra)
9376{
9377 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009378 struct iw_scan_req *req = NULL;
9379 if (wrqu->data.length
9380 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9381 req = (struct iw_scan_req *)extra;
9382 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9383 ipw_request_direct_scan(priv, req->essid,
9384 req->essid_len);
9385 return 0;
9386 }
9387 }
James Ketrenos8935f392005-10-05 15:59:08 -05009388
James Ketrenos43f66a62005-03-25 12:31:53 -06009389 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009390
9391 queue_work(priv->workqueue, &priv->request_scan);
9392
James Ketrenos43f66a62005-03-25 12:31:53 -06009393 return 0;
9394}
9395
Jeff Garzikbf794512005-07-31 13:07:26 -04009396static int ipw_wx_get_scan(struct net_device *dev,
9397 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009398 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009399{
James Ketrenos43f66a62005-03-25 12:31:53 -06009400 struct ipw_priv *priv = ieee80211_priv(dev);
9401 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9402}
9403
Jeff Garzikbf794512005-07-31 13:07:26 -04009404static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009405 struct iw_request_info *info,
9406 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009407{
9408 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009409 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009410 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009411
Zhu Yi46441512006-01-24 16:37:59 +08009412 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009413 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009414
Hong Liucaeff812005-08-05 17:25:50 +08009415 /* In IBSS mode, we need to notify the firmware to update
9416 * the beacon info after we changed the capability. */
9417 if (cap != priv->capability &&
9418 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9419 priv->status & STATUS_ASSOCIATED)
9420 ipw_disassociate(priv);
9421
Zhu Yi46441512006-01-24 16:37:59 +08009422 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009423 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009424}
9425
Jeff Garzikbf794512005-07-31 13:07:26 -04009426static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009427 struct iw_request_info *info,
9428 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009429{
9430 struct ipw_priv *priv = ieee80211_priv(dev);
9431 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9432}
9433
Jeff Garzikbf794512005-07-31 13:07:26 -04009434static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009435 struct iw_request_info *info,
9436 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009437{
9438 struct ipw_priv *priv = ieee80211_priv(dev);
9439 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009440 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009441 if (wrqu->power.disabled) {
9442 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9443 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9444 if (err) {
9445 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009446 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009447 return err;
9448 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009449 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009450 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009451 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009452 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009453
9454 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009455 case IW_POWER_ON: /* If not specified */
9456 case IW_POWER_MODE: /* If set all mask */
9457 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009458 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009459 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009460 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9461 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009462 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009463 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009464 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009465
James Ketrenos43f66a62005-03-25 12:31:53 -06009466 /* If the user hasn't specified a power management mode yet, default
9467 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009468 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009469 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009470 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009471 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9472 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9473 if (err) {
9474 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009475 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009476 return err;
9477 }
9478
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009479 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009480 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009481 return 0;
9482}
9483
Jeff Garzikbf794512005-07-31 13:07:26 -04009484static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009485 struct iw_request_info *info,
9486 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009487{
9488 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009489 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009490 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009491 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009492 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009493 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009494
Zhu Yi46441512006-01-24 16:37:59 +08009495 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009496 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009497
James Ketrenos43f66a62005-03-25 12:31:53 -06009498 return 0;
9499}
9500
Jeff Garzikbf794512005-07-31 13:07:26 -04009501static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009502 struct iw_request_info *info,
9503 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009504{
9505 struct ipw_priv *priv = ieee80211_priv(dev);
9506 int mode = *(int *)extra;
9507 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009508 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009509 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9510 mode = IPW_POWER_AC;
9511 priv->power_mode = mode;
9512 } else {
9513 priv->power_mode = IPW_POWER_ENABLED | mode;
9514 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009515
James Ketrenos43f66a62005-03-25 12:31:53 -06009516 if (priv->power_mode != mode) {
9517 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009518
James Ketrenos43f66a62005-03-25 12:31:53 -06009519 if (err) {
9520 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009521 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009522 return err;
9523 }
9524 }
Zhu Yi46441512006-01-24 16:37:59 +08009525 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009526 return 0;
9527}
9528
9529#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009530static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009531 struct iw_request_info *info,
9532 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009533{
9534 struct ipw_priv *priv = ieee80211_priv(dev);
9535 int level = IPW_POWER_LEVEL(priv->power_mode);
9536 char *p = extra;
9537
9538 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9539
9540 switch (level) {
9541 case IPW_POWER_AC:
9542 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9543 break;
9544 case IPW_POWER_BATTERY:
9545 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9546 break;
9547 default:
9548 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009549 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009550 timeout_duration[level - 1] / 1000,
9551 period_duration[level - 1] / 1000);
9552 }
9553
9554 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009555 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009556
9557 wrqu->data.length = p - extra + 1;
9558
9559 return 0;
9560}
9561
9562static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009563 struct iw_request_info *info,
9564 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009565{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009566 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009567 int mode = *(int *)extra;
9568 u8 band = 0, modulation = 0;
9569
9570 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009571 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009572 return -EINVAL;
9573 }
Zhu Yi46441512006-01-24 16:37:59 +08009574 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009575 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009576 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009577 if (mode & IEEE_A) {
9578 band |= IEEE80211_52GHZ_BAND;
9579 modulation |= IEEE80211_OFDM_MODULATION;
9580 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009581 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009582 } else {
9583 if (mode & IEEE_A) {
9584 IPW_WARNING("Attempt to set 2200BG into "
9585 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009586 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009587 return -EINVAL;
9588 }
9589
James Ketrenosa33a1982005-09-14 14:28:59 -05009590 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009591 }
9592
9593 if (mode & IEEE_B) {
9594 band |= IEEE80211_24GHZ_BAND;
9595 modulation |= IEEE80211_CCK_MODULATION;
9596 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009597 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009598
James Ketrenos43f66a62005-03-25 12:31:53 -06009599 if (mode & IEEE_G) {
9600 band |= IEEE80211_24GHZ_BAND;
9601 modulation |= IEEE80211_OFDM_MODULATION;
9602 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009603 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009604
9605 priv->ieee->mode = mode;
9606 priv->ieee->freq_band = band;
9607 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009608 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009609
James Ketrenosc848d0a2005-08-24 21:56:24 -05009610 /* Network configuration changed -- force [re]association */
9611 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9612 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009613 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009614 ipw_associate(priv);
9615 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009616
James Ketrenosa613bff2005-08-24 21:43:11 -05009617 /* Update the band LEDs */
9618 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009619
Jeff Garzikbf794512005-07-31 13:07:26 -04009620 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009621 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009622 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009623 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009624 return 0;
9625}
9626
9627static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009628 struct iw_request_info *info,
9629 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009630{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009631 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009632 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009633 switch (priv->ieee->mode) {
9634 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009635 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9636 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009637 case IEEE_B:
9638 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9639 break;
9640 case IEEE_A | IEEE_B:
9641 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9642 break;
9643 case IEEE_G:
9644 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9645 break;
9646 case IEEE_A | IEEE_G:
9647 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9648 break;
9649 case IEEE_B | IEEE_G:
9650 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9651 break;
9652 case IEEE_A | IEEE_B | IEEE_G:
9653 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9654 break;
9655 default:
9656 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009657 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009658 }
9659
James Ketrenos43f66a62005-03-25 12:31:53 -06009660 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9661
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009662 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009663 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009664
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009665 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009666}
9667
James Ketrenosea2b26e2005-08-24 21:25:16 -05009668static int ipw_wx_set_preamble(struct net_device *dev,
9669 struct iw_request_info *info,
9670 union iwreq_data *wrqu, char *extra)
9671{
9672 struct ipw_priv *priv = ieee80211_priv(dev);
9673 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009674 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009675 /* Switching from SHORT -> LONG requires a disassociation */
9676 if (mode == 1) {
9677 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9678 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009679
9680 /* Network configuration changed -- force [re]association */
9681 IPW_DEBUG_ASSOC
9682 ("[re]association triggered due to preamble change.\n");
9683 if (!ipw_disassociate(priv))
9684 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009685 }
9686 goto done;
9687 }
9688
9689 if (mode == 0) {
9690 priv->config &= ~CFG_PREAMBLE_LONG;
9691 goto done;
9692 }
Zhu Yi46441512006-01-24 16:37:59 +08009693 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009694 return -EINVAL;
9695
9696 done:
Zhu Yi46441512006-01-24 16:37:59 +08009697 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009698 return 0;
9699}
9700
9701static int ipw_wx_get_preamble(struct net_device *dev,
9702 struct iw_request_info *info,
9703 union iwreq_data *wrqu, char *extra)
9704{
9705 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009706 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009707 if (priv->config & CFG_PREAMBLE_LONG)
9708 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9709 else
9710 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009711 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009712 return 0;
9713}
9714
James Ketrenosb095c382005-08-24 22:04:42 -05009715#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009716static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009717 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009718 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009719{
James Ketrenos43f66a62005-03-25 12:31:53 -06009720 struct ipw_priv *priv = ieee80211_priv(dev);
9721 int *parms = (int *)extra;
9722 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009723 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009724 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009725 if (enable) {
9726 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08009727#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05009728 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9729#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009730 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009731#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009732 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009733 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009734
James Ketrenos43f66a62005-03-25 12:31:53 -06009735 ipw_set_channel(priv, parms[1]);
9736 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009737 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009738 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009739 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009740 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009741 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009742 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009743 }
Zhu Yi46441512006-01-24 16:37:59 +08009744 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009745 return 0;
9746}
9747
Pavel Machek67fd6b42006-07-11 15:34:05 +02009748#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenosb095c382005-08-24 22:04:42 -05009749
Jeff Garzikbf794512005-07-31 13:07:26 -04009750static int ipw_wx_reset(struct net_device *dev,
9751 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009752 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009753{
James Ketrenos43f66a62005-03-25 12:31:53 -06009754 struct ipw_priv *priv = ieee80211_priv(dev);
9755 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009756 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009757 return 0;
9758}
James Ketrenosb095c382005-08-24 22:04:42 -05009759
James Ketrenosb095c382005-08-24 22:04:42 -05009760static int ipw_wx_sw_reset(struct net_device *dev,
9761 struct iw_request_info *info,
9762 union iwreq_data *wrqu, char *extra)
9763{
9764 struct ipw_priv *priv = ieee80211_priv(dev);
9765 union iwreq_data wrqu_sec = {
9766 .encoding = {
9767 .flags = IW_ENCODE_DISABLED,
9768 },
9769 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009770 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009771
9772 IPW_DEBUG_WX("SW_RESET\n");
9773
Zhu Yi46441512006-01-24 16:37:59 +08009774 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009775
Zhu Yid6d5b5c2006-02-16 16:21:09 +08009776 ret = ipw_sw_reset(priv, 2);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009777 if (!ret) {
9778 free_firmware();
9779 ipw_adapter_restart(priv);
9780 }
James Ketrenosb095c382005-08-24 22:04:42 -05009781
9782 /* The SW reset bit might have been toggled on by the 'disable'
9783 * module parameter, so take appropriate action */
9784 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9785
Zhu Yi46441512006-01-24 16:37:59 +08009786 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009787 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009788 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009789
9790 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9791 /* Configuration likely changed -- force [re]association */
9792 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9793 "reset.\n");
9794 if (!ipw_disassociate(priv))
9795 ipw_associate(priv);
9796 }
9797
Zhu Yi46441512006-01-24 16:37:59 +08009798 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009799
9800 return 0;
9801}
James Ketrenos43f66a62005-03-25 12:31:53 -06009802
9803/* Rebase the WE IOCTLs to zero for the handler array */
9804#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009805static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009806 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9807 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9808 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9809 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9810 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009811 IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens,
9812 IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009813 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9814 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9815 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9816 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9817 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9818 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9819 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9820 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9821 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9822 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9823 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9824 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9825 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9826 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9827 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9828 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9829 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9830 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9831 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9832 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9833 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9834 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9835 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -05009836 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9837 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9838 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9839 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -05009840 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9841 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9842 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9843 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9844 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9845 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9846 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
James Ketrenos43f66a62005-03-25 12:31:53 -06009847};
9848
James Ketrenosb095c382005-08-24 22:04:42 -05009849enum {
9850 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9851 IPW_PRIV_GET_POWER,
9852 IPW_PRIV_SET_MODE,
9853 IPW_PRIV_GET_MODE,
9854 IPW_PRIV_SET_PREAMBLE,
9855 IPW_PRIV_GET_PREAMBLE,
9856 IPW_PRIV_RESET,
9857 IPW_PRIV_SW_RESET,
9858#ifdef CONFIG_IPW2200_MONITOR
9859 IPW_PRIV_SET_MONITOR,
9860#endif
9861};
James Ketrenos43f66a62005-03-25 12:31:53 -06009862
Jeff Garzikbf794512005-07-31 13:07:26 -04009863static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06009864 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009865 .cmd = IPW_PRIV_SET_POWER,
9866 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9867 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009868 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009869 .cmd = IPW_PRIV_GET_POWER,
9870 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9871 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009872 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009873 .cmd = IPW_PRIV_SET_MODE,
9874 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9875 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009876 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009877 .cmd = IPW_PRIV_GET_MODE,
9878 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9879 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009880 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009881 .cmd = IPW_PRIV_SET_PREAMBLE,
9882 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9883 .name = "set_preamble"},
9884 {
9885 .cmd = IPW_PRIV_GET_PREAMBLE,
9886 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9887 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009888 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009889 IPW_PRIV_RESET,
9890 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -05009891 {
9892 IPW_PRIV_SW_RESET,
9893 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9894#ifdef CONFIG_IPW2200_MONITOR
9895 {
9896 IPW_PRIV_SET_MONITOR,
9897 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9898#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06009899};
9900
9901static iw_handler ipw_priv_handler[] = {
9902 ipw_wx_set_powermode,
9903 ipw_wx_get_powermode,
9904 ipw_wx_set_wireless_mode,
9905 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009906 ipw_wx_set_preamble,
9907 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -04009908 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -05009909 ipw_wx_sw_reset,
9910#ifdef CONFIG_IPW2200_MONITOR
9911 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -06009912#endif
9913};
9914
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009915static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009916 .standard = ipw_wx_handlers,
9917 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9918 .num_private = ARRAY_SIZE(ipw_priv_handler),
9919 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9920 .private = ipw_priv_handler,
9921 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009922 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06009923};
9924
James Ketrenos43f66a62005-03-25 12:31:53 -06009925/*
9926 * Get wireless statistics.
9927 * Called by /proc/net/wireless
9928 * Also called by SIOCGIWSTATS
9929 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009930static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06009931{
9932 struct ipw_priv *priv = ieee80211_priv(dev);
9933 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009934
James Ketrenos43f66a62005-03-25 12:31:53 -06009935 wstats = &priv->wstats;
9936
James Ketrenosea2b26e2005-08-24 21:25:16 -05009937 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -05009938 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06009939 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9940 * and associated; if not associcated, the values are all meaningless
9941 * anyway, so set them all to NULL and INVALID */
9942 if (!(priv->status & STATUS_ASSOCIATED)) {
9943 wstats->miss.beacon = 0;
9944 wstats->discard.retries = 0;
9945 wstats->qual.qual = 0;
9946 wstats->qual.level = 0;
9947 wstats->qual.noise = 0;
9948 wstats->qual.updated = 7;
9949 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009950 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06009951 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009952 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009953
9954 wstats->qual.qual = priv->quality;
Zhu Yi00d21de2006-04-13 17:19:02 +08009955 wstats->qual.level = priv->exp_avg_rssi;
9956 wstats->qual.noise = priv->exp_avg_noise;
James Ketrenos43f66a62005-03-25 12:31:53 -06009957 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +08009958 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009959
9960 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9961 wstats->discard.retries = priv->last_tx_failures;
9962 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04009963
James Ketrenos43f66a62005-03-25 12:31:53 -06009964/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9965 goto fail_get_ordinal;
9966 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04009967
James Ketrenos43f66a62005-03-25 12:31:53 -06009968 return wstats;
9969}
9970
James Ketrenos43f66a62005-03-25 12:31:53 -06009971/* net device stuff */
9972
Arjan van de Ven858119e2006-01-14 13:20:43 -08009973static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -06009974{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009975 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +08009976 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009977 sys_config->answer_broadcast_ssid_probe = 0;
9978 sys_config->accept_all_data_frames = 0;
9979 sys_config->accept_non_directed_frames = 1;
9980 sys_config->exclude_unicast_unencrypted = 0;
9981 sys_config->disable_unicast_decryption = 1;
9982 sys_config->exclude_multicast_unencrypted = 0;
9983 sys_config->disable_multicast_decryption = 1;
Zhu Yid2b83e12006-04-13 17:19:36 +08009984 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
9985 antenna = CFG_SYS_ANTENNA_BOTH;
9986 sys_config->antenna_diversity = antenna;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009987 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -06009988 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009989 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009990 sys_config->bt_coexist_collision_thr = 0;
Pavel Machek67fd6b42006-07-11 15:34:05 +02009991 sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */
Cahill, Ben M12977152006-03-08 02:58:02 +08009992 sys_config->silence_threshold = 0x1e;
James Ketrenos43f66a62005-03-25 12:31:53 -06009993}
9994
9995static int ipw_net_open(struct net_device *dev)
9996{
9997 struct ipw_priv *priv = ieee80211_priv(dev);
9998 IPW_DEBUG_INFO("dev->open\n");
9999 /* we should be verifying the device is ready to be opened */
Zhu Yi46441512006-01-24 16:37:59 +080010000 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -040010001 if (!(priv->status & STATUS_RF_KILL_MASK) &&
10002 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -060010003 netif_start_queue(dev);
Zhu Yi46441512006-01-24 16:37:59 +080010004 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010005 return 0;
10006}
10007
10008static int ipw_net_stop(struct net_device *dev)
10009{
10010 IPW_DEBUG_INFO("dev->close\n");
10011 netif_stop_queue(dev);
10012 return 0;
10013}
10014
10015/*
10016todo:
10017
10018modify to send one tfd per fragment instead of using chunking. otherwise
10019we need to heavily modify the ieee80211_skb_to_txb.
10020*/
10021
Arjan van de Ven858119e2006-01-14 13:20:43 -080010022static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -050010023 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010024{
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010025 struct ieee80211_hdr_3addrqos *hdr = (struct ieee80211_hdr_3addrqos *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010026 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -060010027 int i = 0;
10028 struct tfd_frame *tfd;
Zhu Yie43e3c12006-04-13 17:20:45 +080010029#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010030 int tx_id = ipw_get_tx_queue_number(priv, pri);
10031 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10032#else
James Ketrenos43f66a62005-03-25 12:31:53 -060010033 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -050010034#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060010035 struct clx2_queue *q = &txq->q;
10036 u8 id, hdr_len, unicast;
10037 u16 remaining_bytes;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010038 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -060010039
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010040 hdr_len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
James Ketrenos43f66a62005-03-25 12:31:53 -060010041 switch (priv->ieee->iw_mode) {
10042 case IW_MODE_ADHOC:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010043 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010044 id = ipw_find_station(priv, hdr->addr1);
10045 if (id == IPW_INVALID_STATION) {
10046 id = ipw_add_station(priv, hdr->addr1);
10047 if (id == IPW_INVALID_STATION) {
10048 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -040010049 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010050 MAC_ARG(hdr->addr1));
10051 goto drop;
10052 }
10053 }
10054 break;
10055
10056 case IW_MODE_INFRA:
10057 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010058 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -060010059 id = 0;
10060 break;
10061 }
10062
10063 tfd = &txq->bd[q->first_empty];
10064 txq->txb[q->first_empty] = txb;
10065 memset(tfd, 0, sizeof(*tfd));
10066 tfd->u.data.station_number = id;
10067
10068 tfd->control_flags.message_type = TX_FRAME_TYPE;
10069 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10070
10071 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -050010072 tfd->u.data.len = cpu_to_le16(txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010073 remaining_bytes = txb->payload_size;
Jeff Garzikbf794512005-07-31 13:07:26 -040010074
James Ketrenos43f66a62005-03-25 12:31:53 -060010075 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -050010076 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010077 else
James Ketrenosb095c382005-08-24 22:04:42 -050010078 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010079
James Ketrenosea2b26e2005-08-24 21:25:16 -050010080 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10081 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010082
James Ketrenosc848d0a2005-08-24 21:56:24 -050010083 fc = le16_to_cpu(hdr->frame_ctl);
10084 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -060010085
10086 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10087
James Ketrenosb095c382005-08-24 22:04:42 -050010088 if (likely(unicast))
10089 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10090
10091 if (txb->encrypted && !priv->ieee->host_encrypt) {
10092 switch (priv->ieee->sec.level) {
10093 case SEC_LEVEL_3:
10094 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10095 IEEE80211_FCTL_PROTECTED;
10096 /* XXX: ACK flag must be set for CCMP even if it
10097 * is a multicast/broadcast packet, because CCMP
10098 * group communication encrypted by GTK is
10099 * actually done by the AP. */
10100 if (!unicast)
10101 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10102
10103 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10104 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10105 tfd->u.data.key_index = 0;
10106 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10107 break;
10108 case SEC_LEVEL_2:
10109 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10110 IEEE80211_FCTL_PROTECTED;
10111 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10112 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10113 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10114 break;
10115 case SEC_LEVEL_1:
10116 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10117 IEEE80211_FCTL_PROTECTED;
10118 tfd->u.data.key_index = priv->ieee->tx_keyidx;
10119 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
10120 40)
10121 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10122 else
10123 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10124 break;
10125 case SEC_LEVEL_0:
10126 break;
10127 default:
10128 printk(KERN_ERR "Unknow security level %d\n",
10129 priv->ieee->sec.level);
10130 break;
10131 }
10132 } else
10133 /* No hardware encryption */
10134 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10135
Zhu Yie43e3c12006-04-13 17:20:45 +080010136#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010137 if (fc & IEEE80211_STYPE_QOS_DATA)
10138 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
Zhu Yie43e3c12006-04-13 17:20:45 +080010139#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050010140
James Ketrenos43f66a62005-03-25 12:31:53 -060010141 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -050010142 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10143 txb->nr_frags));
10144 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10145 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10146 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10147 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10148 i, le32_to_cpu(tfd->u.data.num_chunks),
10149 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010150 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010151 i, tfd->u.data.num_chunks,
10152 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010153 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -060010154 txb->fragments[i]->len - hdr_len);
10155
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010156 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010157 cpu_to_le32(pci_map_single
10158 (priv->pci_dev,
10159 txb->fragments[i]->data + hdr_len,
10160 txb->fragments[i]->len - hdr_len,
10161 PCI_DMA_TODEVICE));
10162 tfd->u.data.chunk_len[i] =
10163 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -060010164 }
10165
10166 if (i != txb->nr_frags) {
10167 struct sk_buff *skb;
10168 u16 remaining_bytes = 0;
10169 int j;
10170
10171 for (j = i; j < txb->nr_frags; j++)
10172 remaining_bytes += txb->fragments[j]->len - hdr_len;
10173
10174 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10175 remaining_bytes);
10176 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10177 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -050010178 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -060010179 for (j = i; j < txb->nr_frags; j++) {
10180 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010181
James Ketrenos43f66a62005-03-25 12:31:53 -060010182 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010183 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010184 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010185 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010186 }
10187 dev_kfree_skb_any(txb->fragments[i]);
10188 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010189 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010190 cpu_to_le32(pci_map_single
10191 (priv->pci_dev, skb->data,
10192 tfd->u.data.chunk_len[i],
10193 PCI_DMA_TODEVICE));
10194
10195 tfd->u.data.num_chunks =
10196 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
10197 1);
Jeff Garzikbf794512005-07-31 13:07:26 -040010198 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010199 }
10200
10201 /* kick DMA */
10202 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10203 ipw_write32(priv, q->reg_w, q->first_empty);
10204
James Ketrenosf6970142006-02-14 09:10:51 +080010205 if (ipw_queue_space(q) < q->high_mark)
10206 netif_stop_queue(priv->net_dev);
10207
James Ketrenos227d2dc2005-07-28 16:25:55 -050010208 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010209
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010210 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -060010211 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
10212 ieee80211_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -050010213 return NETDEV_TX_OK;
10214}
10215
10216static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10217{
10218 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yie43e3c12006-04-13 17:20:45 +080010219#ifdef CONFIG_IPW2200_QOS
James Ketrenos227d2dc2005-07-28 16:25:55 -050010220 int tx_id = ipw_get_tx_queue_number(priv, pri);
10221 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10222#else
10223 struct clx2_tx_queue *txq = &priv->txq[0];
Zhu Yie43e3c12006-04-13 17:20:45 +080010224#endif /* CONFIG_IPW2200_QOS */
James Ketrenos227d2dc2005-07-28 16:25:55 -050010225
10226 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
10227 return 1;
10228
10229 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010230}
10231
Zhu Yid685b8c2006-04-13 17:20:27 +080010232#ifdef CONFIG_IPW2200_PROMISCUOUS
10233static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
10234 struct ieee80211_txb *txb)
10235{
10236 struct ieee80211_rx_stats dummystats;
10237 struct ieee80211_hdr *hdr;
10238 u8 n;
10239 u16 filter = priv->prom_priv->filter;
10240 int hdr_only = 0;
10241
10242 if (filter & IPW_PROM_NO_TX)
10243 return;
10244
10245 memset(&dummystats, 0, sizeof(dummystats));
10246
10247 /* Filtering of fragment chains is done agains the first fragment */
10248 hdr = (void *)txb->fragments[0]->data;
10249 if (ieee80211_is_management(hdr->frame_ctl)) {
10250 if (filter & IPW_PROM_NO_MGMT)
10251 return;
10252 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10253 hdr_only = 1;
10254 } else if (ieee80211_is_control(hdr->frame_ctl)) {
10255 if (filter & IPW_PROM_NO_CTL)
10256 return;
10257 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10258 hdr_only = 1;
10259 } else if (ieee80211_is_data(hdr->frame_ctl)) {
10260 if (filter & IPW_PROM_NO_DATA)
10261 return;
10262 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10263 hdr_only = 1;
10264 }
10265
10266 for(n=0; n<txb->nr_frags; ++n) {
10267 struct sk_buff *src = txb->fragments[n];
10268 struct sk_buff *dst;
10269 struct ieee80211_radiotap_header *rt_hdr;
10270 int len;
10271
10272 if (hdr_only) {
10273 hdr = (void *)src->data;
10274 len = ieee80211_get_hdrlen(hdr->frame_ctl);
10275 } else
10276 len = src->len;
10277
10278 dst = alloc_skb(
10279 len + IEEE80211_RADIOTAP_HDRLEN, GFP_ATOMIC);
10280 if (!dst) continue;
10281
10282 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10283
10284 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10285 rt_hdr->it_pad = 0;
10286 rt_hdr->it_present = 0; /* after all, it's just an idea */
10287 rt_hdr->it_present |= (1 << IEEE80211_RADIOTAP_CHANNEL);
10288
10289 *(u16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
10290 ieee80211chan2mhz(priv->channel));
10291 if (priv->channel > 14) /* 802.11a */
10292 *(u16*)skb_put(dst, sizeof(u16)) =
10293 cpu_to_le16(IEEE80211_CHAN_OFDM |
10294 IEEE80211_CHAN_5GHZ);
10295 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
10296 *(u16*)skb_put(dst, sizeof(u16)) =
10297 cpu_to_le16(IEEE80211_CHAN_CCK |
10298 IEEE80211_CHAN_2GHZ);
10299 else /* 802.11g */
10300 *(u16*)skb_put(dst, sizeof(u16)) =
10301 cpu_to_le16(IEEE80211_CHAN_OFDM |
10302 IEEE80211_CHAN_2GHZ);
10303
10304 rt_hdr->it_len = dst->len;
10305
10306 memcpy(skb_put(dst, len), src->data, len);
10307
10308 if (!ieee80211_rx(priv->prom_priv->ieee, dst, &dummystats))
10309 dev_kfree_skb_any(dst);
10310 }
10311}
10312#endif
10313
James Ketrenos43f66a62005-03-25 12:31:53 -060010314static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -050010315 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010316{
10317 struct ipw_priv *priv = ieee80211_priv(dev);
10318 unsigned long flags;
James Ketrenos227d2dc2005-07-28 16:25:55 -050010319 int ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010320
10321 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010322 spin_lock_irqsave(&priv->lock, flags);
10323
10324 if (!(priv->status & STATUS_ASSOCIATED)) {
10325 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
10326 priv->ieee->stats.tx_carrier_errors++;
10327 netif_stop_queue(dev);
10328 goto fail_unlock;
10329 }
10330
Zhu Yid685b8c2006-04-13 17:20:27 +080010331#ifdef CONFIG_IPW2200_PROMISCUOUS
10332 if (rtap_iface && netif_running(priv->prom_net_dev))
10333 ipw_handle_promiscuous_tx(priv, txb);
10334#endif
10335
James Ketrenos227d2dc2005-07-28 16:25:55 -050010336 ret = ipw_tx_skb(priv, txb, pri);
10337 if (ret == NETDEV_TX_OK)
10338 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010339 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010340
James Ketrenos227d2dc2005-07-28 16:25:55 -050010341 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010342
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010343 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010344 spin_unlock_irqrestore(&priv->lock, flags);
10345 return 1;
10346}
10347
10348static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
10349{
10350 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -040010351
James Ketrenos43f66a62005-03-25 12:31:53 -060010352 priv->ieee->stats.tx_packets = priv->tx_packets;
10353 priv->ieee->stats.rx_packets = priv->rx_packets;
10354 return &priv->ieee->stats;
10355}
10356
10357static void ipw_net_set_multicast_list(struct net_device *dev)
10358{
10359
10360}
10361
10362static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10363{
10364 struct ipw_priv *priv = ieee80211_priv(dev);
10365 struct sockaddr *addr = p;
10366 if (!is_valid_ether_addr(addr->sa_data))
10367 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +080010368 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010369 priv->config |= CFG_CUSTOM_MAC;
10370 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
10371 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
10372 priv->net_dev->name, MAC_ARG(priv->mac_addr));
James Ketrenosa613bff2005-08-24 21:43:11 -050010373 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +080010374 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010375 return 0;
10376}
10377
Jeff Garzikbf794512005-07-31 13:07:26 -040010378static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010379 struct ethtool_drvinfo *info)
10380{
10381 struct ipw_priv *p = ieee80211_priv(dev);
10382 char vers[64];
10383 char date[32];
10384 u32 len;
10385
10386 strcpy(info->driver, DRV_NAME);
10387 strcpy(info->version, DRV_VERSION);
10388
10389 len = sizeof(vers);
10390 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10391 len = sizeof(date);
10392 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10393
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010394 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010395 vers, date);
10396 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010397 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010398}
10399
10400static u32 ipw_ethtool_get_link(struct net_device *dev)
10401{
10402 struct ipw_priv *priv = ieee80211_priv(dev);
10403 return (priv->status & STATUS_ASSOCIATED) != 0;
10404}
10405
10406static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10407{
James Ketrenosb095c382005-08-24 22:04:42 -050010408 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010409}
10410
10411static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010412 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010413{
10414 struct ipw_priv *p = ieee80211_priv(dev);
10415
James Ketrenosb095c382005-08-24 22:04:42 -050010416 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010417 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010418 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010419 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +080010420 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010421 return 0;
10422}
10423
10424static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010425 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010426{
10427 struct ipw_priv *p = ieee80211_priv(dev);
10428 int i;
10429
James Ketrenosb095c382005-08-24 22:04:42 -050010430 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010431 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010432 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010433 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Adrian Bunk71e585f2006-03-11 04:42:58 +010010434 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10435 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +080010436 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010437 return 0;
10438}
10439
10440static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010441 .get_link = ipw_ethtool_get_link,
10442 .get_drvinfo = ipw_ethtool_get_drvinfo,
10443 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10444 .get_eeprom = ipw_ethtool_get_eeprom,
10445 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010446};
10447
10448static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
10449{
10450 struct ipw_priv *priv = data;
10451 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010452
James Ketrenos43f66a62005-03-25 12:31:53 -060010453 if (!priv)
10454 return IRQ_NONE;
10455
Zhu Yi89c318e2006-06-08 22:19:49 -070010456 spin_lock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010457
10458 if (!(priv->status & STATUS_INT_ENABLED)) {
10459 /* Shared IRQ */
10460 goto none;
10461 }
10462
James Ketrenosb095c382005-08-24 22:04:42 -050010463 inta = ipw_read32(priv, IPW_INTA_RW);
10464 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010465
James Ketrenos43f66a62005-03-25 12:31:53 -060010466 if (inta == 0xFFFFFFFF) {
10467 /* Hardware disappeared */
10468 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10469 goto none;
10470 }
10471
James Ketrenosb095c382005-08-24 22:04:42 -050010472 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010473 /* Shared interrupt */
10474 goto none;
10475 }
10476
10477 /* tell the device to stop sending interrupts */
Zhu Yi89c318e2006-06-08 22:19:49 -070010478 __ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010479
James Ketrenos43f66a62005-03-25 12:31:53 -060010480 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010481 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10482 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010483
James Ketrenos43f66a62005-03-25 12:31:53 -060010484 /* Cache INTA value for our tasklet */
10485 priv->isr_inta = inta;
10486
10487 tasklet_schedule(&priv->irq_tasklet);
10488
Zhu Yi89c318e2006-06-08 22:19:49 -070010489 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010490
10491 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010492 none:
Zhu Yi89c318e2006-06-08 22:19:49 -070010493 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010494 return IRQ_NONE;
10495}
10496
10497static void ipw_rf_kill(void *adapter)
10498{
10499 struct ipw_priv *priv = adapter;
10500 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010501
James Ketrenos43f66a62005-03-25 12:31:53 -060010502 spin_lock_irqsave(&priv->lock, flags);
10503
10504 if (rf_kill_active(priv)) {
10505 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10506 if (priv->workqueue)
10507 queue_delayed_work(priv->workqueue,
10508 &priv->rf_kill, 2 * HZ);
10509 goto exit_unlock;
10510 }
10511
10512 /* RF Kill is now disabled, so bring the device back up */
10513
10514 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10515 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10516 "device\n");
10517
10518 /* we can not do an adapter restart while inside an irq lock */
10519 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010520 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010521 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10522 "enabled\n");
10523
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010524 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010525 spin_unlock_irqrestore(&priv->lock, flags);
10526}
10527
James Ketrenosc848d0a2005-08-24 21:56:24 -050010528static void ipw_bg_rf_kill(void *data)
10529{
10530 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010531 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010532 ipw_rf_kill(data);
Zhu Yi46441512006-01-24 16:37:59 +080010533 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010534}
10535
Adrian Bunka73e22b2006-01-21 01:39:42 +010010536static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010537{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010538 priv->last_seq_num = -1;
10539 priv->last_frag_num = -1;
10540 priv->last_packet_time = 0;
10541
James Ketrenosa613bff2005-08-24 21:43:11 -050010542 netif_carrier_on(priv->net_dev);
10543 if (netif_queue_stopped(priv->net_dev)) {
10544 IPW_DEBUG_NOTIF("waking queue\n");
10545 netif_wake_queue(priv->net_dev);
10546 } else {
10547 IPW_DEBUG_NOTIF("starting queue\n");
10548 netif_start_queue(priv->net_dev);
10549 }
10550
James Ketrenosc848d0a2005-08-24 21:56:24 -050010551 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010552 ipw_reset_stats(priv);
10553 /* Ensure the rate is updated immediately */
10554 priv->last_rate = ipw_get_current_rate(priv);
10555 ipw_gather_stats(priv);
10556 ipw_led_link_up(priv);
10557 notify_wx_assoc_event(priv);
10558
10559 if (priv->config & CFG_BACKGROUND_SCAN)
10560 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10561}
10562
James Ketrenosc848d0a2005-08-24 21:56:24 -050010563static void ipw_bg_link_up(void *data)
10564{
10565 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010566 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010567 ipw_link_up(data);
Zhu Yi46441512006-01-24 16:37:59 +080010568 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010569}
10570
Adrian Bunka73e22b2006-01-21 01:39:42 +010010571static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010572{
10573 ipw_led_link_down(priv);
10574 netif_carrier_off(priv->net_dev);
10575 netif_stop_queue(priv->net_dev);
10576 notify_wx_assoc_event(priv);
10577
10578 /* Cancel any queued work ... */
10579 cancel_delayed_work(&priv->request_scan);
10580 cancel_delayed_work(&priv->adhoc_check);
10581 cancel_delayed_work(&priv->gather_stats);
10582
10583 ipw_reset_stats(priv);
10584
James Ketrenosafbf30a2005-08-25 00:05:33 -050010585 if (!(priv->status & STATUS_EXIT_PENDING)) {
10586 /* Queue up another scan... */
10587 queue_work(priv->workqueue, &priv->request_scan);
10588 }
James Ketrenosa613bff2005-08-24 21:43:11 -050010589}
10590
James Ketrenosc848d0a2005-08-24 21:56:24 -050010591static void ipw_bg_link_down(void *data)
10592{
10593 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010594 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010595 ipw_link_down(data);
Zhu Yi46441512006-01-24 16:37:59 +080010596 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010597}
10598
James Ketrenos43f66a62005-03-25 12:31:53 -060010599static int ipw_setup_deferred_work(struct ipw_priv *priv)
10600{
10601 int ret = 0;
10602
James Ketrenos43f66a62005-03-25 12:31:53 -060010603 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010604 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010605 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010606
James Ketrenosc848d0a2005-08-24 21:56:24 -050010607 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10608 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10609 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
Zhu Yid8bad6d2005-07-13 12:25:38 -050010610 INIT_WORK(&priv->system_config, ipw_system_config, priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010611 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10612 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10613 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10614 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10615 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010616 INIT_WORK(&priv->request_scan,
James Ketrenos43f66a62005-03-25 12:31:53 -060010617 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010618 INIT_WORK(&priv->gather_stats,
James Ketrenosc848d0a2005-08-24 21:56:24 -050010619 (void (*)(void *))ipw_bg_gather_stats, priv);
10620 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10621 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10622 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10623 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10624 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10625 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
James Ketrenosa613bff2005-08-24 21:43:11 -050010626 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010627 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
James Ketrenosa613bff2005-08-24 21:43:11 -050010628 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010629 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10630 priv);
10631 INIT_WORK(&priv->merge_networks,
10632 (void (*)(void *))ipw_merge_adhoc_network, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010633
Zhu Yie43e3c12006-04-13 17:20:45 +080010634#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010635 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10636 priv);
Zhu Yie43e3c12006-04-13 17:20:45 +080010637#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010638
10639 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10640 ipw_irq_tasklet, (unsigned long)priv);
10641
10642 return ret;
10643}
10644
James Ketrenos43f66a62005-03-25 12:31:53 -060010645static void shim__set_security(struct net_device *dev,
10646 struct ieee80211_security *sec)
10647{
10648 struct ipw_priv *priv = ieee80211_priv(dev);
10649 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010650 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010651 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010652 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010653 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010654 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010655 priv->ieee->sec.flags &= ~(1 << i);
10656 else {
10657 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010658 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010659 priv->ieee->sec.flags |= (1 << i);
10660 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010661 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010662 } else if (sec->level != SEC_LEVEL_1)
10663 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010664 }
10665
James Ketrenosb095c382005-08-24 22:04:42 -050010666 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010667 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010668 priv->ieee->sec.active_key = sec->active_key;
10669 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010670 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010671 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010672 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010673 } else
10674 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010675
10676 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010677 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10678 priv->ieee->sec.auth_mode = sec->auth_mode;
10679 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010680 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10681 priv->capability |= CAP_SHARED_KEY;
10682 else
10683 priv->capability &= ~CAP_SHARED_KEY;
10684 priv->status |= STATUS_SECURITY_UPDATED;
10685 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010686
James Ketrenosb095c382005-08-24 22:04:42 -050010687 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10688 priv->ieee->sec.flags |= SEC_ENABLED;
10689 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010690 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010691 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010692 priv->capability |= CAP_PRIVACY_ON;
10693 else
10694 priv->capability &= ~CAP_PRIVACY_ON;
10695 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010696
James Ketrenosafbf30a2005-08-25 00:05:33 -050010697 if (sec->flags & SEC_ENCRYPT)
10698 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010699
James Ketrenosb095c382005-08-24 22:04:42 -050010700 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10701 priv->ieee->sec.level = sec->level;
10702 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010703 priv->status |= STATUS_SECURITY_UPDATED;
10704 }
10705
Zhu Yi1fbfea52005-08-05 17:22:56 +080010706 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10707 ipw_set_hwcrypto_keys(priv);
10708
Jeff Garzikbf794512005-07-31 13:07:26 -040010709 /* To match current functionality of ipw2100 (which works well w/
10710 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010711 * privacy capability changes ... */
10712#if 0
10713 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010714 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -060010715 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010716 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010717 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010718 IPW_DEBUG_ASSOC("Disassociating due to capability "
10719 "change.\n");
10720 ipw_disassociate(priv);
10721 }
10722#endif
10723}
10724
Jeff Garzikbf794512005-07-31 13:07:26 -040010725static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010726 struct ipw_supported_rates *rates)
10727{
10728 /* TODO: Mask out rates based on priv->rates_mask */
10729
10730 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010731 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010732 switch (priv->ieee->freq_band) {
10733 case IEEE80211_52GHZ_BAND:
10734 rates->ieee_mode = IPW_A_MODE;
10735 rates->purpose = IPW_RATE_CAPABILITIES;
10736 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10737 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10738 break;
10739
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010740 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010741 rates->ieee_mode = IPW_G_MODE;
10742 rates->purpose = IPW_RATE_CAPABILITIES;
10743 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10744 IEEE80211_CCK_DEFAULT_RATES_MASK);
10745 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10746 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10747 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10748 }
10749 break;
10750 }
10751
10752 return 0;
10753}
10754
Jeff Garzikbf794512005-07-31 13:07:26 -040010755static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010756{
James Ketrenos43f66a62005-03-25 12:31:53 -060010757 /* This is only called from ipw_up, which resets/reloads the firmware
10758 so, we don't need to first disable the card before we configure
10759 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010760 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010761 goto error;
10762
10763 /* initialize adapter address */
10764 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10765 goto error;
10766
10767 /* set basic system config settings */
10768 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010769
10770 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10771 * Does not support BT priority yet (don't abort or defer our Tx) */
10772 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010773 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010774
10775 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10776 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010777 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010778 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10779 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010780 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010781 }
10782
Zhu Yid685b8c2006-04-13 17:20:27 +080010783#ifdef CONFIG_IPW2200_PROMISCUOUS
10784 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10785 priv->sys_config.accept_all_data_frames = 1;
10786 priv->sys_config.accept_non_directed_frames = 1;
10787 priv->sys_config.accept_all_mgmt_bcpr = 1;
10788 priv->sys_config.accept_all_mgmt_frames = 1;
10789 }
10790#endif
10791
James Ketrenosc848d0a2005-08-24 21:56:24 -050010792 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10793 priv->sys_config.answer_broadcast_ssid_probe = 1;
10794 else
10795 priv->sys_config.answer_broadcast_ssid_probe = 0;
10796
Zhu Yid685b8c2006-04-13 17:20:27 +080010797 if (ipw_send_system_config(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010798 goto error;
10799
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010800 init_supported_rates(priv, &priv->rates);
10801 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010802 goto error;
10803
10804 /* Set request-to-send threshold */
10805 if (priv->rts_threshold) {
10806 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10807 goto error;
10808 }
Zhu Yie43e3c12006-04-13 17:20:45 +080010809#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010810 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10811 ipw_qos_activate(priv, NULL);
Zhu Yie43e3c12006-04-13 17:20:45 +080010812#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010813
10814 if (ipw_set_random_seed(priv))
10815 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010816
James Ketrenos43f66a62005-03-25 12:31:53 -060010817 /* final state transition to the RUN state */
10818 if (ipw_send_host_complete(priv))
10819 goto error;
10820
James Ketrenose6666192005-08-12 09:17:04 -050010821 priv->status |= STATUS_INIT;
10822
10823 ipw_led_init(priv);
10824 ipw_led_radio_on(priv);
10825 priv->notif_missed_beacons = 0;
10826
10827 /* Set hardware WEP key if it is configured. */
10828 if ((priv->capability & CAP_PRIVACY_ON) &&
10829 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10830 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10831 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010832
10833 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010834
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010835 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010836 return -EIO;
10837}
10838
James Ketrenos4f36f802005-08-03 20:36:56 -050010839/*
10840 * NOTE:
10841 *
10842 * These tables have been tested in conjunction with the
10843 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10844 *
10845 * Altering this values, using it on other hardware, or in geographies
10846 * not intended for resale of the above mentioned Intel adapters has
10847 * not been tested.
10848 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080010849 * Remember to update the table in README.ipw2200 when changing this
10850 * table.
10851 *
James Ketrenos4f36f802005-08-03 20:36:56 -050010852 */
10853static const struct ieee80211_geo ipw_geos[] = {
10854 { /* Restricted */
10855 "---",
10856 .bg_channels = 11,
10857 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10858 {2427, 4}, {2432, 5}, {2437, 6},
10859 {2442, 7}, {2447, 8}, {2452, 9},
10860 {2457, 10}, {2462, 11}},
10861 },
10862
10863 { /* Custom US/Canada */
10864 "ZZF",
10865 .bg_channels = 11,
10866 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10867 {2427, 4}, {2432, 5}, {2437, 6},
10868 {2442, 7}, {2447, 8}, {2452, 9},
10869 {2457, 10}, {2462, 11}},
10870 .a_channels = 8,
10871 .a = {{5180, 36},
10872 {5200, 40},
10873 {5220, 44},
10874 {5240, 48},
10875 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10876 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10877 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10878 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10879 },
10880
10881 { /* Rest of World */
10882 "ZZD",
10883 .bg_channels = 13,
10884 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10885 {2427, 4}, {2432, 5}, {2437, 6},
10886 {2442, 7}, {2447, 8}, {2452, 9},
10887 {2457, 10}, {2462, 11}, {2467, 12},
10888 {2472, 13}},
10889 },
10890
10891 { /* Custom USA & Europe & High */
10892 "ZZA",
10893 .bg_channels = 11,
10894 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10895 {2427, 4}, {2432, 5}, {2437, 6},
10896 {2442, 7}, {2447, 8}, {2452, 9},
10897 {2457, 10}, {2462, 11}},
10898 .a_channels = 13,
10899 .a = {{5180, 36},
10900 {5200, 40},
10901 {5220, 44},
10902 {5240, 48},
10903 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10904 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10905 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10906 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10907 {5745, 149},
10908 {5765, 153},
10909 {5785, 157},
10910 {5805, 161},
10911 {5825, 165}},
10912 },
10913
10914 { /* Custom NA & Europe */
10915 "ZZB",
10916 .bg_channels = 11,
10917 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10918 {2427, 4}, {2432, 5}, {2437, 6},
10919 {2442, 7}, {2447, 8}, {2452, 9},
10920 {2457, 10}, {2462, 11}},
10921 .a_channels = 13,
10922 .a = {{5180, 36},
10923 {5200, 40},
10924 {5220, 44},
10925 {5240, 48},
10926 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10927 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10928 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10929 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10930 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10931 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10932 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10933 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10934 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10935 },
10936
10937 { /* Custom Japan */
10938 "ZZC",
10939 .bg_channels = 11,
10940 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10941 {2427, 4}, {2432, 5}, {2437, 6},
10942 {2442, 7}, {2447, 8}, {2452, 9},
10943 {2457, 10}, {2462, 11}},
10944 .a_channels = 4,
10945 .a = {{5170, 34}, {5190, 38},
10946 {5210, 42}, {5230, 46}},
10947 },
10948
10949 { /* Custom */
10950 "ZZM",
10951 .bg_channels = 11,
10952 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10953 {2427, 4}, {2432, 5}, {2437, 6},
10954 {2442, 7}, {2447, 8}, {2452, 9},
10955 {2457, 10}, {2462, 11}},
10956 },
10957
10958 { /* Europe */
10959 "ZZE",
10960 .bg_channels = 13,
10961 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10962 {2427, 4}, {2432, 5}, {2437, 6},
10963 {2442, 7}, {2447, 8}, {2452, 9},
10964 {2457, 10}, {2462, 11}, {2467, 12},
10965 {2472, 13}},
10966 .a_channels = 19,
10967 .a = {{5180, 36},
10968 {5200, 40},
10969 {5220, 44},
10970 {5240, 48},
10971 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10972 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10973 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10974 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10975 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10976 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10977 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10978 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10979 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10980 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10981 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10982 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10983 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10984 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10985 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10986 },
10987
10988 { /* Custom Japan */
10989 "ZZJ",
10990 .bg_channels = 14,
10991 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10992 {2427, 4}, {2432, 5}, {2437, 6},
10993 {2442, 7}, {2447, 8}, {2452, 9},
10994 {2457, 10}, {2462, 11}, {2467, 12},
10995 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10996 .a_channels = 4,
10997 .a = {{5170, 34}, {5190, 38},
10998 {5210, 42}, {5230, 46}},
10999 },
11000
James Ketrenos03520572005-10-19 16:12:31 -050011001 { /* Rest of World */
11002 "ZZR",
11003 .bg_channels = 14,
11004 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11005 {2427, 4}, {2432, 5}, {2437, 6},
11006 {2442, 7}, {2447, 8}, {2452, 9},
11007 {2457, 10}, {2462, 11}, {2467, 12},
11008 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
11009 IEEE80211_CH_PASSIVE_ONLY}},
11010 },
11011
James Ketrenos4f36f802005-08-03 20:36:56 -050011012 { /* High Band */
11013 "ZZH",
11014 .bg_channels = 13,
11015 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11016 {2427, 4}, {2432, 5}, {2437, 6},
11017 {2442, 7}, {2447, 8}, {2452, 9},
11018 {2457, 10}, {2462, 11},
11019 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
11020 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
11021 .a_channels = 4,
11022 .a = {{5745, 149}, {5765, 153},
11023 {5785, 157}, {5805, 161}},
11024 },
11025
11026 { /* Custom Europe */
11027 "ZZG",
11028 .bg_channels = 13,
11029 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11030 {2427, 4}, {2432, 5}, {2437, 6},
11031 {2442, 7}, {2447, 8}, {2452, 9},
11032 {2457, 10}, {2462, 11},
11033 {2467, 12}, {2472, 13}},
11034 .a_channels = 4,
11035 .a = {{5180, 36}, {5200, 40},
11036 {5220, 44}, {5240, 48}},
11037 },
11038
11039 { /* Europe */
11040 "ZZK",
11041 .bg_channels = 13,
11042 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11043 {2427, 4}, {2432, 5}, {2437, 6},
11044 {2442, 7}, {2447, 8}, {2452, 9},
11045 {2457, 10}, {2462, 11},
11046 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
11047 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
11048 .a_channels = 24,
11049 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
11050 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
11051 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
11052 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
11053 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11054 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11055 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11056 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11057 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
11058 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
11059 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
11060 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
11061 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
11062 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
11063 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
11064 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
11065 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
11066 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
11067 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
11068 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11069 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11070 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11071 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11072 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11073 },
11074
11075 { /* Europe */
11076 "ZZL",
11077 .bg_channels = 11,
11078 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11079 {2427, 4}, {2432, 5}, {2437, 6},
11080 {2442, 7}, {2447, 8}, {2452, 9},
11081 {2457, 10}, {2462, 11}},
11082 .a_channels = 13,
11083 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
11084 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
11085 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
11086 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
11087 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11088 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11089 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11090 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11091 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11092 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11093 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11094 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11095 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11096 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050011097};
11098
James Ketrenos43f66a62005-03-25 12:31:53 -060011099#define MAX_HW_RESTARTS 5
11100static int ipw_up(struct ipw_priv *priv)
11101{
James Ketrenos4f36f802005-08-03 20:36:56 -050011102 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060011103
11104 if (priv->status & STATUS_EXIT_PENDING)
11105 return -EIO;
11106
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011107 if (cmdlog && !priv->cmdlog) {
11108 priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
11109 GFP_KERNEL);
11110 if (priv->cmdlog == NULL) {
11111 IPW_ERROR("Error allocating %d command log entries.\n",
11112 cmdlog);
Zhu Yid0b526b2006-04-13 17:19:50 +080011113 return -ENOMEM;
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011114 } else {
11115 memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
11116 priv->cmdlog_len = cmdlog;
11117 }
11118 }
11119
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011120 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040011121 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060011122 * Also start the clocks. */
11123 rc = ipw_load(priv);
11124 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050011125 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011126 return rc;
11127 }
11128
11129 ipw_init_ordinals(priv);
11130 if (!(priv->config & CFG_CUSTOM_MAC))
11131 eeprom_parse_mac(priv, priv->mac_addr);
11132 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
11133
James Ketrenos4f36f802005-08-03 20:36:56 -050011134 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11135 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11136 ipw_geos[j].name, 3))
11137 break;
11138 }
James Ketrenos03520572005-10-19 16:12:31 -050011139 if (j == ARRAY_SIZE(ipw_geos)) {
11140 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11141 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11142 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11143 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050011144 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050011145 }
Larry Finger1867b112006-02-28 09:48:28 -060011146 if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050011147 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060011148 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050011149 }
11150
James Ketrenosb095c382005-08-24 22:04:42 -050011151 if (priv->status & STATUS_RF_KILL_SW) {
11152 IPW_WARNING("Radio disabled by module parameter.\n");
11153 return 0;
11154 } else if (rf_kill_active(priv)) {
11155 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11156 "Kill switch must be turned off for "
11157 "wireless networking to work.\n");
11158 queue_delayed_work(priv->workqueue, &priv->rf_kill,
11159 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060011160 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050011161 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011162
11163 rc = ipw_config(priv);
11164 if (!rc) {
11165 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011166
James Ketrenose6666192005-08-12 09:17:04 -050011167 /* If configure to try and auto-associate, kick
11168 * off a scan. */
11169 queue_work(priv->workqueue, &priv->request_scan);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011170
James Ketrenos43f66a62005-03-25 12:31:53 -060011171 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011172 }
Jeff Garzikbf794512005-07-31 13:07:26 -040011173
James Ketrenosc848d0a2005-08-24 21:56:24 -050011174 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011175 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11176 i, MAX_HW_RESTARTS);
11177
11178 /* We had an error bringing up the hardware, so take it
11179 * all the way back down so we can try again */
11180 ipw_down(priv);
11181 }
11182
Jeff Garzikbf794512005-07-31 13:07:26 -040011183 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060011184 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011185 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011186
James Ketrenos43f66a62005-03-25 12:31:53 -060011187 return -EIO;
11188}
11189
James Ketrenosc848d0a2005-08-24 21:56:24 -050011190static void ipw_bg_up(void *data)
11191{
11192 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080011193 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011194 ipw_up(data);
Zhu Yi46441512006-01-24 16:37:59 +080011195 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011196}
11197
James Ketrenosb095c382005-08-24 22:04:42 -050011198static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060011199{
James Ketrenosb095c382005-08-24 22:04:42 -050011200 int i;
11201
11202 if (priv->status & STATUS_SCANNING) {
11203 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11204 ipw_abort_scan(priv);
11205 }
11206
11207 if (priv->status & STATUS_ASSOCIATED) {
11208 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11209 ipw_disassociate(priv);
11210 }
11211
11212 ipw_led_shutdown(priv);
11213
11214 /* Wait up to 1s for status to change to not scanning and not
11215 * associated (disassociation can take a while for a ful 802.11
11216 * exchange */
11217 for (i = 1000; i && (priv->status &
11218 (STATUS_DISASSOCIATING |
11219 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11220 udelay(10);
11221
11222 if (priv->status & (STATUS_DISASSOCIATING |
11223 STATUS_ASSOCIATED | STATUS_SCANNING))
11224 IPW_DEBUG_INFO("Still associated or scanning...\n");
11225 else
11226 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11227
James Ketrenosc848d0a2005-08-24 21:56:24 -050011228 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060011229 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050011230
11231 priv->status &= ~STATUS_INIT;
11232}
11233
James Ketrenos43f66a62005-03-25 12:31:53 -060011234static void ipw_down(struct ipw_priv *priv)
11235{
James Ketrenosb095c382005-08-24 22:04:42 -050011236 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11237
11238 priv->status |= STATUS_EXIT_PENDING;
11239
11240 if (ipw_is_init(priv))
11241 ipw_deinit(priv);
11242
11243 /* Wipe out the EXIT_PENDING status bit if we are not actually
11244 * exiting the module */
11245 if (!exit_pending)
11246 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011247
11248 /* tell the device to stop sending interrupts */
11249 ipw_disable_interrupts(priv);
11250
11251 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050011252 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011253 netif_carrier_off(priv->net_dev);
11254 netif_stop_queue(priv->net_dev);
11255
11256 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050011257
11258 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011259}
11260
James Ketrenosc848d0a2005-08-24 21:56:24 -050011261static void ipw_bg_down(void *data)
11262{
11263 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080011264 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011265 ipw_down(data);
Zhu Yi46441512006-01-24 16:37:59 +080011266 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011267}
11268
11269/* Called by register_netdev() */
11270static int ipw_net_init(struct net_device *dev)
11271{
11272 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +080011273 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011274
James Ketrenosc848d0a2005-08-24 21:56:24 -050011275 if (ipw_up(priv)) {
Zhu Yi46441512006-01-24 16:37:59 +080011276 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011277 return -EIO;
James Ketrenos43f66a62005-03-25 12:31:53 -060011278 }
11279
Zhu Yi46441512006-01-24 16:37:59 +080011280 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011281 return 0;
11282}
11283
11284/* PCI driver stuff */
11285static struct pci_device_id card_ids[] = {
11286 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11287 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11288 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11289 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11290 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11291 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11292 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11293 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11294 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11295 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11296 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11297 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11298 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11299 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11300 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11301 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11302 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
11303 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011304 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
James Ketrenosa613bff2005-08-24 21:43:11 -050011305 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011306 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
11307 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040011308
James Ketrenos43f66a62005-03-25 12:31:53 -060011309 /* required last entry */
11310 {0,}
11311};
11312
11313MODULE_DEVICE_TABLE(pci, card_ids);
11314
11315static struct attribute *ipw_sysfs_entries[] = {
11316 &dev_attr_rf_kill.attr,
11317 &dev_attr_direct_dword.attr,
11318 &dev_attr_indirect_byte.attr,
11319 &dev_attr_indirect_dword.attr,
11320 &dev_attr_mem_gpio_reg.attr,
11321 &dev_attr_command_event_reg.attr,
11322 &dev_attr_nic_type.attr,
11323 &dev_attr_status.attr,
11324 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011325 &dev_attr_error.attr,
11326 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011327 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011328 &dev_attr_eeprom_delay.attr,
11329 &dev_attr_ucode_version.attr,
11330 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011331 &dev_attr_scan_age.attr,
11332 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011333 &dev_attr_speed_scan.attr,
11334 &dev_attr_net_stats.attr,
Zhu Yid685b8c2006-04-13 17:20:27 +080011335#ifdef CONFIG_IPW2200_PROMISCUOUS
11336 &dev_attr_rtap_iface.attr,
11337 &dev_attr_rtap_filter.attr,
11338#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011339 NULL
11340};
11341
11342static struct attribute_group ipw_attribute_group = {
11343 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011344 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011345};
11346
Zhu Yid685b8c2006-04-13 17:20:27 +080011347#ifdef CONFIG_IPW2200_PROMISCUOUS
11348static int ipw_prom_open(struct net_device *dev)
11349{
11350 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11351 struct ipw_priv *priv = prom_priv->priv;
11352
11353 IPW_DEBUG_INFO("prom dev->open\n");
11354 netif_carrier_off(dev);
11355 netif_stop_queue(dev);
11356
11357 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11358 priv->sys_config.accept_all_data_frames = 1;
11359 priv->sys_config.accept_non_directed_frames = 1;
11360 priv->sys_config.accept_all_mgmt_bcpr = 1;
11361 priv->sys_config.accept_all_mgmt_frames = 1;
11362
11363 ipw_send_system_config(priv);
11364 }
11365
11366 return 0;
11367}
11368
11369static int ipw_prom_stop(struct net_device *dev)
11370{
11371 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11372 struct ipw_priv *priv = prom_priv->priv;
11373
11374 IPW_DEBUG_INFO("prom dev->stop\n");
11375
11376 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11377 priv->sys_config.accept_all_data_frames = 0;
11378 priv->sys_config.accept_non_directed_frames = 0;
11379 priv->sys_config.accept_all_mgmt_bcpr = 0;
11380 priv->sys_config.accept_all_mgmt_frames = 0;
11381
11382 ipw_send_system_config(priv);
11383 }
11384
11385 return 0;
11386}
11387
11388static int ipw_prom_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
11389{
11390 IPW_DEBUG_INFO("prom dev->xmit\n");
11391 netif_stop_queue(dev);
11392 return -EOPNOTSUPP;
11393}
11394
11395static struct net_device_stats *ipw_prom_get_stats(struct net_device *dev)
11396{
11397 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11398 return &prom_priv->ieee->stats;
11399}
11400
11401static int ipw_prom_alloc(struct ipw_priv *priv)
11402{
11403 int rc = 0;
11404
11405 if (priv->prom_net_dev)
11406 return -EPERM;
11407
11408 priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv));
11409 if (priv->prom_net_dev == NULL)
11410 return -ENOMEM;
11411
11412 priv->prom_priv = ieee80211_priv(priv->prom_net_dev);
11413 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11414 priv->prom_priv->priv = priv;
11415
11416 strcpy(priv->prom_net_dev->name, "rtap%d");
11417
11418 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
11419 priv->prom_net_dev->open = ipw_prom_open;
11420 priv->prom_net_dev->stop = ipw_prom_stop;
11421 priv->prom_net_dev->get_stats = ipw_prom_get_stats;
11422 priv->prom_net_dev->hard_start_xmit = ipw_prom_hard_start_xmit;
11423
11424 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
11425
11426 rc = register_netdev(priv->prom_net_dev);
11427 if (rc) {
11428 free_ieee80211(priv->prom_net_dev);
11429 priv->prom_net_dev = NULL;
11430 return rc;
11431 }
11432
11433 return 0;
11434}
11435
11436static void ipw_prom_free(struct ipw_priv *priv)
11437{
11438 if (!priv->prom_net_dev)
11439 return;
11440
11441 unregister_netdev(priv->prom_net_dev);
11442 free_ieee80211(priv->prom_net_dev);
11443
11444 priv->prom_net_dev = NULL;
11445}
11446
11447#endif
11448
11449
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011450static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011451{
11452 int err = 0;
11453 struct net_device *net_dev;
11454 void __iomem *base;
11455 u32 length, val;
11456 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011457 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011458
11459 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
11460 if (net_dev == NULL) {
11461 err = -ENOMEM;
11462 goto out;
11463 }
11464
11465 priv = ieee80211_priv(net_dev);
11466 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011467
James Ketrenos43f66a62005-03-25 12:31:53 -060011468 priv->net_dev = net_dev;
11469 priv->pci_dev = pdev;
Brice Goglin0f52bf92005-12-01 01:41:46 -080011470#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060011471 ipw_debug_level = debug;
11472#endif
Zhu Yi89c318e2006-06-08 22:19:49 -070011473 spin_lock_init(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060011474 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011475 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11476 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011477
Zhu Yi46441512006-01-24 16:37:59 +080011478 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011479 if (pci_enable_device(pdev)) {
11480 err = -ENODEV;
11481 goto out_free_ieee80211;
11482 }
11483
11484 pci_set_master(pdev);
11485
Tobias Klauser0e08b442005-06-20 14:28:41 -070011486 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -040011487 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -070011488 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060011489 if (err) {
11490 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11491 goto out_pci_disable_device;
11492 }
11493
11494 pci_set_drvdata(pdev, priv);
11495
11496 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011497 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011498 goto out_pci_disable_device;
11499
Jeff Garzikbf794512005-07-31 13:07:26 -040011500 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011501 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011502 pci_read_config_dword(pdev, 0x40, &val);
11503 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011504 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011505
James Ketrenos43f66a62005-03-25 12:31:53 -060011506 length = pci_resource_len(pdev, 0);
11507 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011508
James Ketrenos43f66a62005-03-25 12:31:53 -060011509 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
11510 if (!base) {
11511 err = -ENODEV;
11512 goto out_pci_release_regions;
11513 }
11514
11515 priv->hw_base = base;
11516 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11517 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11518
11519 err = ipw_setup_deferred_work(priv);
11520 if (err) {
11521 IPW_ERROR("Unable to setup deferred work\n");
11522 goto out_iounmap;
11523 }
11524
James Ketrenosb095c382005-08-24 22:04:42 -050011525 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011526
Thomas Gleixner1fb9df52006-07-01 19:29:39 -070011527 err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011528 if (err) {
11529 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11530 goto out_destroy_workqueue;
11531 }
11532
11533 SET_MODULE_OWNER(net_dev);
11534 SET_NETDEV_DEV(net_dev, &pdev->dev);
11535
Zhu Yi46441512006-01-24 16:37:59 +080011536 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011537
James Ketrenos43f66a62005-03-25 12:31:53 -060011538 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11539 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011540 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011541
Zhu Yie43e3c12006-04-13 17:20:45 +080011542#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080011543 priv->ieee->is_qos_active = ipw_is_qos_active;
James Ketrenos3b9990c2005-08-19 13:18:55 -050011544 priv->ieee->handle_probe_response = ipw_handle_beacon;
11545 priv->ieee->handle_beacon = ipw_handle_probe_response;
11546 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
Zhu Yie43e3c12006-04-13 17:20:45 +080011547#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011548
James Ketrenosc848d0a2005-08-24 21:56:24 -050011549 priv->ieee->perfect_rssi = -20;
11550 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011551
11552 net_dev->open = ipw_net_open;
11553 net_dev->stop = ipw_net_stop;
11554 net_dev->init = ipw_net_init;
11555 net_dev->get_stats = ipw_net_get_stats;
11556 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11557 net_dev->set_mac_address = ipw_net_set_mac_address;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011558 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011559 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011560 net_dev->wireless_handlers = &ipw_wx_handler_def;
11561 net_dev->ethtool_ops = &ipw_ethtool_ops;
11562 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011563 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011564 net_dev->mem_start = pci_resource_start(pdev, 0);
11565 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11566
11567 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11568 if (err) {
11569 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011570 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011571 goto out_release_irq;
11572 }
11573
Zhu Yi46441512006-01-24 16:37:59 +080011574 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011575 err = register_netdev(net_dev);
11576 if (err) {
11577 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011578 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011579 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011580
Zhu Yid685b8c2006-04-13 17:20:27 +080011581#ifdef CONFIG_IPW2200_PROMISCUOUS
11582 if (rtap_iface) {
11583 err = ipw_prom_alloc(priv);
11584 if (err) {
11585 IPW_ERROR("Failed to register promiscuous network "
11586 "device (error %d).\n", err);
11587 unregister_netdev(priv->net_dev);
11588 goto out_remove_sysfs;
11589 }
11590 }
11591#endif
11592
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011593 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11594 "channels, %d 802.11a channels)\n",
11595 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11596 priv->ieee->geo.a_channels);
11597
James Ketrenos43f66a62005-03-25 12:31:53 -060011598 return 0;
11599
James Ketrenosa613bff2005-08-24 21:43:11 -050011600 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011601 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011602 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011603 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011604 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011605 destroy_workqueue(priv->workqueue);
11606 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011607 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011608 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011609 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011610 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011611 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011612 pci_disable_device(pdev);
11613 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011614 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -060011615 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011616 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011617 return err;
11618}
11619
11620static void ipw_pci_remove(struct pci_dev *pdev)
11621{
11622 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011623 struct list_head *p, *q;
11624 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011625
James Ketrenos43f66a62005-03-25 12:31:53 -060011626 if (!priv)
11627 return;
11628
Zhu Yi46441512006-01-24 16:37:59 +080011629 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011630
James Ketrenosafbf30a2005-08-25 00:05:33 -050011631 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011632 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011633 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11634
Zhu Yi46441512006-01-24 16:37:59 +080011635 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011636
11637 unregister_netdev(priv->net_dev);
11638
11639 if (priv->rxq) {
11640 ipw_rx_queue_free(priv, priv->rxq);
11641 priv->rxq = NULL;
11642 }
11643 ipw_tx_queue_free(priv);
11644
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011645 if (priv->cmdlog) {
11646 kfree(priv->cmdlog);
11647 priv->cmdlog = NULL;
11648 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011649 /* ipw_down will ensure that there is no more pending work
11650 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011651 cancel_delayed_work(&priv->adhoc_check);
11652 cancel_delayed_work(&priv->gather_stats);
11653 cancel_delayed_work(&priv->request_scan);
11654 cancel_delayed_work(&priv->rf_kill);
11655 cancel_delayed_work(&priv->scan_check);
11656 destroy_workqueue(priv->workqueue);
11657 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011658
James Ketrenosafbf30a2005-08-25 00:05:33 -050011659 /* Free MAC hash list for ADHOC */
11660 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11661 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011662 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011663 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011664 }
11665 }
11666
Jesper Juhl8f760782006-06-27 02:55:06 -070011667 kfree(priv->error);
11668 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011669
Zhu Yid685b8c2006-04-13 17:20:27 +080011670#ifdef CONFIG_IPW2200_PROMISCUOUS
11671 ipw_prom_free(priv);
11672#endif
11673
James Ketrenos43f66a62005-03-25 12:31:53 -060011674 free_irq(pdev->irq, priv);
11675 iounmap(priv->hw_base);
11676 pci_release_regions(pdev);
11677 pci_disable_device(pdev);
11678 pci_set_drvdata(pdev, NULL);
11679 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011680 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011681}
11682
James Ketrenos43f66a62005-03-25 12:31:53 -060011683#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011684static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011685{
11686 struct ipw_priv *priv = pci_get_drvdata(pdev);
11687 struct net_device *dev = priv->net_dev;
11688
11689 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11690
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011691 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011692 ipw_down(priv);
11693
11694 /* Remove the PRESENT state of the device */
11695 netif_device_detach(dev);
11696
James Ketrenos43f66a62005-03-25 12:31:53 -060011697 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011698 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011699 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011700
James Ketrenos43f66a62005-03-25 12:31:53 -060011701 return 0;
11702}
11703
11704static int ipw_pci_resume(struct pci_dev *pdev)
11705{
11706 struct ipw_priv *priv = pci_get_drvdata(pdev);
11707 struct net_device *dev = priv->net_dev;
11708 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011709
James Ketrenos43f66a62005-03-25 12:31:53 -060011710 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11711
James Ketrenosea2b26e2005-08-24 21:25:16 -050011712 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011713 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011714 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011715
James Ketrenos43f66a62005-03-25 12:31:53 -060011716 /*
11717 * Suspend/Resume resets the PCI configuration space, so we have to
11718 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11719 * from interfering with C3 CPU state. pci_restore_state won't help
11720 * here since it only restores the first 64 bytes pci config header.
11721 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011722 pci_read_config_dword(pdev, 0x40, &val);
11723 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011724 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11725
11726 /* Set the device back into the PRESENT state; this will also wake
11727 * the queue of needed */
11728 netif_device_attach(dev);
11729
11730 /* Bring the device back up */
11731 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011732
James Ketrenos43f66a62005-03-25 12:31:53 -060011733 return 0;
11734}
11735#endif
11736
11737/* driver initialization stuff */
11738static struct pci_driver ipw_driver = {
11739 .name = DRV_NAME,
11740 .id_table = card_ids,
11741 .probe = ipw_pci_probe,
11742 .remove = __devexit_p(ipw_pci_remove),
11743#ifdef CONFIG_PM
11744 .suspend = ipw_pci_suspend,
11745 .resume = ipw_pci_resume,
11746#endif
11747};
11748
11749static int __init ipw_init(void)
11750{
11751 int ret;
11752
11753 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11754 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11755
Jeff Garzik29917622006-08-19 17:48:59 -040011756 ret = pci_register_driver(&ipw_driver);
James Ketrenos43f66a62005-03-25 12:31:53 -060011757 if (ret) {
11758 IPW_ERROR("Unable to initialize PCI module\n");
11759 return ret;
11760 }
11761
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011762 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011763 if (ret) {
11764 IPW_ERROR("Unable to create driver sysfs file\n");
11765 pci_unregister_driver(&ipw_driver);
11766 return ret;
11767 }
11768
11769 return ret;
11770}
11771
11772static void __exit ipw_exit(void)
11773{
11774 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11775 pci_unregister_driver(&ipw_driver);
11776}
11777
11778module_param(disable, int, 0444);
11779MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11780
11781module_param(associate, int, 0444);
11782MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11783
11784module_param(auto_create, int, 0444);
11785MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11786
James Ketrenosa613bff2005-08-24 21:43:11 -050011787module_param(led, int, 0444);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011788MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011789
Zhu Yi3e1555b2006-03-06 05:48:37 +080011790#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060011791module_param(debug, int, 0444);
11792MODULE_PARM_DESC(debug, "debug output mask");
Zhu Yi3e1555b2006-03-06 05:48:37 +080011793#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011794
11795module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011796MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011797
Zhu Yid685b8c2006-04-13 17:20:27 +080011798#ifdef CONFIG_IPW2200_PROMISCUOUS
11799module_param(rtap_iface, int, 0444);
11800MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
11801#endif
11802
Zhu Yie43e3c12006-04-13 17:20:45 +080011803#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050011804module_param(qos_enable, int, 0444);
11805MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060011806
James Ketrenosb095c382005-08-24 22:04:42 -050011807module_param(qos_burst_enable, int, 0444);
11808MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11809
11810module_param(qos_no_ack_mask, int, 0444);
11811MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11812
11813module_param(burst_duration_CCK, int, 0444);
11814MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11815
11816module_param(burst_duration_OFDM, int, 0444);
11817MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
Zhu Yie43e3c12006-04-13 17:20:45 +080011818#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011819
11820#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -060011821module_param(mode, int, 0444);
11822MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11823#else
11824module_param(mode, int, 0444);
11825MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11826#endif
11827
Zhu Yi810dabd2006-01-24 16:36:59 +080011828module_param(bt_coexist, int, 0444);
11829MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
11830
James Ketrenosb095c382005-08-24 22:04:42 -050011831module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080011832MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050011833
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011834module_param(cmdlog, int, 0444);
11835MODULE_PARM_DESC(cmdlog,
11836 "allocate a ring buffer for logging firmware commands");
11837
Zhu Yi4bfdb912006-01-24 16:37:16 +080011838module_param(roaming, int, 0444);
11839MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
11840
Zhu Yid2b83e12006-04-13 17:19:36 +080011841module_param(antenna, int, 0444);
11842MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
11843
James Ketrenos43f66a62005-03-25 12:31:53 -060011844module_exit(ipw_exit);
11845module_init(ipw_init);