blob: 081a8999666e7e168404141073c687d0af2dfe0b [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
1232static void ipw_free_error_log(struct ipw_fw_error *error)
1233{
1234 if (error)
1235 kfree(error);
1236}
1237
1238static ssize_t show_event_log(struct device *d,
1239 struct device_attribute *attr, char *buf)
1240{
1241 struct ipw_priv *priv = dev_get_drvdata(d);
1242 u32 log_len = ipw_get_event_log_len(priv);
1243 struct ipw_event log[log_len];
1244 u32 len = 0, i;
1245
1246 ipw_capture_event_log(priv, log_len, log);
1247
1248 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1249 for (i = 0; i < log_len; i++)
1250 len += snprintf(buf + len, PAGE_SIZE - len,
1251 "\n%08X%08X%08X",
1252 log[i].time, log[i].event, log[i].data);
1253 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1254 return len;
1255}
1256
1257static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1258
1259static ssize_t show_error(struct device *d,
1260 struct device_attribute *attr, char *buf)
1261{
1262 struct ipw_priv *priv = dev_get_drvdata(d);
1263 u32 len = 0, i;
1264 if (!priv->error)
1265 return 0;
1266 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001267 "%08lX%08X%08X%08X",
1268 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001269 priv->error->status,
1270 priv->error->config, priv->error->elem_len);
1271 for (i = 0; i < priv->error->elem_len; i++)
1272 len += snprintf(buf + len, PAGE_SIZE - len,
1273 "\n%08X%08X%08X%08X%08X%08X%08X",
1274 priv->error->elem[i].time,
1275 priv->error->elem[i].desc,
1276 priv->error->elem[i].blink1,
1277 priv->error->elem[i].blink2,
1278 priv->error->elem[i].link1,
1279 priv->error->elem[i].link2,
1280 priv->error->elem[i].data);
1281
1282 len += snprintf(buf + len, PAGE_SIZE - len,
1283 "\n%08X", priv->error->log_len);
1284 for (i = 0; i < priv->error->log_len; i++)
1285 len += snprintf(buf + len, PAGE_SIZE - len,
1286 "\n%08X%08X%08X",
1287 priv->error->log[i].time,
1288 priv->error->log[i].event,
1289 priv->error->log[i].data);
1290 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1291 return len;
1292}
1293
1294static ssize_t clear_error(struct device *d,
1295 struct device_attribute *attr,
1296 const char *buf, size_t count)
1297{
1298 struct ipw_priv *priv = dev_get_drvdata(d);
1299 if (priv->error) {
1300 ipw_free_error_log(priv->error);
1301 priv->error = NULL;
1302 }
1303 return count;
1304}
1305
1306static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1307
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001308static ssize_t show_cmd_log(struct device *d,
1309 struct device_attribute *attr, char *buf)
1310{
1311 struct ipw_priv *priv = dev_get_drvdata(d);
1312 u32 len = 0, i;
1313 if (!priv->cmdlog)
1314 return 0;
1315 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1316 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1317 i = (i + 1) % priv->cmdlog_len) {
1318 len +=
1319 snprintf(buf + len, PAGE_SIZE - len,
1320 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1321 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1322 priv->cmdlog[i].cmd.len);
1323 len +=
1324 snprintk_buf(buf + len, PAGE_SIZE - len,
1325 (u8 *) priv->cmdlog[i].cmd.param,
1326 priv->cmdlog[i].cmd.len);
1327 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1328 }
1329 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1330 return len;
1331}
1332
1333static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1334
Zhu Yid685b8c2006-04-13 17:20:27 +08001335#ifdef CONFIG_IPW2200_PROMISCUOUS
1336static void ipw_prom_free(struct ipw_priv *priv);
1337static int ipw_prom_alloc(struct ipw_priv *priv);
1338static ssize_t store_rtap_iface(struct device *d,
1339 struct device_attribute *attr,
1340 const char *buf, size_t count)
1341{
1342 struct ipw_priv *priv = dev_get_drvdata(d);
1343 int rc = 0;
1344
1345 if (count < 1)
1346 return -EINVAL;
1347
1348 switch (buf[0]) {
1349 case '0':
1350 if (!rtap_iface)
1351 return count;
1352
1353 if (netif_running(priv->prom_net_dev)) {
1354 IPW_WARNING("Interface is up. Cannot unregister.\n");
1355 return count;
1356 }
1357
1358 ipw_prom_free(priv);
1359 rtap_iface = 0;
1360 break;
1361
1362 case '1':
1363 if (rtap_iface)
1364 return count;
1365
1366 rc = ipw_prom_alloc(priv);
1367 if (!rc)
1368 rtap_iface = 1;
1369 break;
1370
1371 default:
1372 return -EINVAL;
1373 }
1374
1375 if (rc) {
1376 IPW_ERROR("Failed to register promiscuous network "
1377 "device (error %d).\n", rc);
1378 }
1379
1380 return count;
1381}
1382
1383static ssize_t show_rtap_iface(struct device *d,
1384 struct device_attribute *attr,
1385 char *buf)
1386{
1387 struct ipw_priv *priv = dev_get_drvdata(d);
1388 if (rtap_iface)
1389 return sprintf(buf, "%s", priv->prom_net_dev->name);
1390 else {
1391 buf[0] = '-';
1392 buf[1] = '1';
1393 buf[2] = '\0';
1394 return 3;
1395 }
1396}
1397
1398static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1399 store_rtap_iface);
1400
1401static ssize_t store_rtap_filter(struct device *d,
1402 struct device_attribute *attr,
1403 const char *buf, size_t count)
1404{
1405 struct ipw_priv *priv = dev_get_drvdata(d);
1406
1407 if (!priv->prom_priv) {
1408 IPW_ERROR("Attempting to set filter without "
1409 "rtap_iface enabled.\n");
1410 return -EPERM;
1411 }
1412
1413 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1414
1415 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1416 BIT_ARG16(priv->prom_priv->filter));
1417
1418 return count;
1419}
1420
1421static ssize_t show_rtap_filter(struct device *d,
1422 struct device_attribute *attr,
1423 char *buf)
1424{
1425 struct ipw_priv *priv = dev_get_drvdata(d);
1426 return sprintf(buf, "0x%04X",
1427 priv->prom_priv ? priv->prom_priv->filter : 0);
1428}
1429
1430static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1431 store_rtap_filter);
1432#endif
1433
James Ketrenosa613bff2005-08-24 21:43:11 -05001434static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1435 char *buf)
1436{
1437 struct ipw_priv *priv = dev_get_drvdata(d);
1438 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1439}
1440
1441static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1442 const char *buf, size_t count)
1443{
1444 struct ipw_priv *priv = dev_get_drvdata(d);
Brice Goglin0f52bf92005-12-01 01:41:46 -08001445#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosa613bff2005-08-24 21:43:11 -05001446 struct net_device *dev = priv->net_dev;
James Ketrenosc848d0a2005-08-24 21:56:24 -05001447#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05001448 char buffer[] = "00000000";
1449 unsigned long len =
1450 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1451 unsigned long val;
1452 char *p = buffer;
1453
1454 IPW_DEBUG_INFO("enter\n");
1455
1456 strncpy(buffer, buf, len);
1457 buffer[len] = 0;
1458
1459 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1460 p++;
1461 if (p[0] == 'x' || p[0] == 'X')
1462 p++;
1463 val = simple_strtoul(p, &p, 16);
1464 } else
1465 val = simple_strtoul(p, &p, 10);
1466 if (p == buffer) {
1467 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1468 } else {
1469 priv->ieee->scan_age = val;
1470 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1471 }
1472
1473 IPW_DEBUG_INFO("exit\n");
1474 return len;
1475}
1476
1477static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1478
1479static ssize_t show_led(struct device *d, struct device_attribute *attr,
1480 char *buf)
1481{
1482 struct ipw_priv *priv = dev_get_drvdata(d);
1483 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1484}
1485
1486static ssize_t store_led(struct device *d, struct device_attribute *attr,
1487 const char *buf, size_t count)
1488{
1489 struct ipw_priv *priv = dev_get_drvdata(d);
1490
1491 IPW_DEBUG_INFO("enter\n");
1492
1493 if (count == 0)
1494 return 0;
1495
1496 if (*buf == 0) {
1497 IPW_DEBUG_LED("Disabling LED control.\n");
1498 priv->config |= CFG_NO_LED;
1499 ipw_led_shutdown(priv);
1500 } else {
1501 IPW_DEBUG_LED("Enabling LED control.\n");
1502 priv->config &= ~CFG_NO_LED;
1503 ipw_led_init(priv);
1504 }
1505
1506 IPW_DEBUG_INFO("exit\n");
1507 return count;
1508}
1509
1510static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1511
Andrew Mortonad3fee52005-06-20 14:30:36 -07001512static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001513 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001514{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001515 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001516 return sprintf(buf, "0x%08x\n", (int)p->status);
1517}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001518
James Ketrenos43f66a62005-03-25 12:31:53 -06001519static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1520
Andrew Mortonad3fee52005-06-20 14:30:36 -07001521static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1522 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001523{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001524 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001525 return sprintf(buf, "0x%08x\n", (int)p->config);
1526}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001527
James Ketrenos43f66a62005-03-25 12:31:53 -06001528static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1529
Andrew Mortonad3fee52005-06-20 14:30:36 -07001530static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001531 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001532{
James Ketrenosa613bff2005-08-24 21:43:11 -05001533 struct ipw_priv *priv = d->driver_data;
1534 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001535}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001536
James Ketrenos43f66a62005-03-25 12:31:53 -06001537static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1538
Andrew Mortonad3fee52005-06-20 14:30:36 -07001539static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001540 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001541{
1542 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001543 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001544
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001545 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001546 return 0;
1547
1548 return sprintf(buf, "0x%08x\n", tmp);
1549}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001550
1551static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001552
Andrew Mortonad3fee52005-06-20 14:30:36 -07001553static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1554 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001555{
1556 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001557 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001558
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001559 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001560 return 0;
1561
1562 return sprintf(buf, "0x%08x\n", tmp);
1563}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001564
1565static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001566
1567/*
1568 * Add a device attribute to view/control the delay between eeprom
1569 * operations.
1570 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001571static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001572 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001573{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001574 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001575 return sprintf(buf, "%i\n", n);
1576}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001577static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001578 struct device_attribute *attr,
1579 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001580{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001581 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001582 sscanf(buf, "%i", &p->eeprom_delay);
1583 return strnlen(buf, count);
1584}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001585
1586static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1587 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001588
Andrew Mortonad3fee52005-06-20 14:30:36 -07001589static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001590 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001591{
1592 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001593 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001594
James Ketrenosb095c382005-08-24 22:04:42 -05001595 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001596 return sprintf(buf, "0x%08x\n", reg);
1597}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001598static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001599 struct device_attribute *attr,
1600 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001601{
1602 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001603 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001604
1605 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001606 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001607 return strnlen(buf, count);
1608}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001609
1610static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1611 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001612
Andrew Mortonad3fee52005-06-20 14:30:36 -07001613static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001614 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001615{
1616 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001617 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001618
1619 reg = ipw_read_reg32(p, 0x301100);
1620 return sprintf(buf, "0x%08x\n", reg);
1621}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001622static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001623 struct device_attribute *attr,
1624 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001625{
1626 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001627 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001628
1629 sscanf(buf, "%x", &reg);
1630 ipw_write_reg32(p, 0x301100, reg);
1631 return strnlen(buf, count);
1632}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001633
1634static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1635 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001636
Andrew Mortonad3fee52005-06-20 14:30:36 -07001637static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001638 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001639{
1640 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001641 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001642
Jeff Garzikbf794512005-07-31 13:07:26 -04001643 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001644 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001645 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001646 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001647
James Ketrenos43f66a62005-03-25 12:31:53 -06001648 return sprintf(buf, "0x%08x\n", reg);
1649}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001650static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001651 struct device_attribute *attr,
1652 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001653{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001654 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001655
1656 sscanf(buf, "%x", &priv->indirect_dword);
1657 priv->status |= STATUS_INDIRECT_DWORD;
1658 return strnlen(buf, count);
1659}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001660
1661static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1662 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001663
Andrew Mortonad3fee52005-06-20 14:30:36 -07001664static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001665 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001666{
1667 u8 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001668 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001669
Jeff Garzikbf794512005-07-31 13:07:26 -04001670 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001671 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001672 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001673 reg = 0;
1674
1675 return sprintf(buf, "0x%02x\n", reg);
1676}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001677static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001678 struct device_attribute *attr,
1679 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001680{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001681 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001682
1683 sscanf(buf, "%x", &priv->indirect_byte);
1684 priv->status |= STATUS_INDIRECT_BYTE;
1685 return strnlen(buf, count);
1686}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001687
1688static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001689 show_indirect_byte, store_indirect_byte);
1690
Andrew Mortonad3fee52005-06-20 14:30:36 -07001691static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001692 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001693{
1694 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001695 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001696
Jeff Garzikbf794512005-07-31 13:07:26 -04001697 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001698 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001699 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001700 reg = 0;
1701
1702 return sprintf(buf, "0x%08x\n", reg);
1703}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001704static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001705 struct device_attribute *attr,
1706 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001707{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001708 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001709
1710 sscanf(buf, "%x", &priv->direct_dword);
1711 priv->status |= STATUS_DIRECT_DWORD;
1712 return strnlen(buf, count);
1713}
James Ketrenos43f66a62005-03-25 12:31:53 -06001714
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001715static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1716 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001717
Arjan van de Ven858119e2006-01-14 13:20:43 -08001718static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001719{
1720 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1721 priv->status |= STATUS_RF_KILL_HW;
1722 else
1723 priv->status &= ~STATUS_RF_KILL_HW;
1724
1725 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1726}
1727
Andrew Mortonad3fee52005-06-20 14:30:36 -07001728static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001729 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001730{
1731 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001732 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001733 2 - HW based RF kill active
1734 3 - Both HW and SW baed RF kill active */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001735 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001736 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001737 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001738 return sprintf(buf, "%i\n", val);
1739}
1740
1741static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1742{
Jeff Garzikbf794512005-07-31 13:07:26 -04001743 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001744 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001745 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001746
1747 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1748 disable_radio ? "OFF" : "ON");
1749
1750 if (disable_radio) {
1751 priv->status |= STATUS_RF_KILL_SW;
1752
James Ketrenosa613bff2005-08-24 21:43:11 -05001753 if (priv->workqueue)
James Ketrenos43f66a62005-03-25 12:31:53 -06001754 cancel_delayed_work(&priv->request_scan);
James Ketrenos43f66a62005-03-25 12:31:53 -06001755 queue_work(priv->workqueue, &priv->down);
1756 } else {
1757 priv->status &= ~STATUS_RF_KILL_SW;
1758 if (rf_kill_active(priv)) {
1759 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1760 "disabled by HW switch\n");
1761 /* Make sure the RF_KILL check timer is running */
1762 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001763 queue_delayed_work(priv->workqueue, &priv->rf_kill,
James Ketrenos43f66a62005-03-25 12:31:53 -06001764 2 * HZ);
Jeff Garzikbf794512005-07-31 13:07:26 -04001765 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001766 queue_work(priv->workqueue, &priv->up);
1767 }
1768
1769 return 1;
1770}
1771
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001772static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1773 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001774{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001775 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -04001776
James Ketrenos43f66a62005-03-25 12:31:53 -06001777 ipw_radio_kill_sw(priv, buf[0] == '1');
1778
1779 return count;
1780}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001781
1782static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001783
James Ketrenosb095c382005-08-24 22:04:42 -05001784static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1785 char *buf)
1786{
1787 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1788 int pos = 0, len = 0;
1789 if (priv->config & CFG_SPEED_SCAN) {
1790 while (priv->speed_scan[pos] != 0)
1791 len += sprintf(&buf[len], "%d ",
1792 priv->speed_scan[pos++]);
1793 return len + sprintf(&buf[len], "\n");
1794 }
1795
1796 return sprintf(buf, "0\n");
1797}
1798
1799static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1800 const char *buf, size_t count)
1801{
1802 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1803 int channel, pos = 0;
1804 const char *p = buf;
1805
1806 /* list of space separated channels to scan, optionally ending with 0 */
1807 while ((channel = simple_strtol(p, NULL, 0))) {
1808 if (pos == MAX_SPEED_SCAN - 1) {
1809 priv->speed_scan[pos] = 0;
1810 break;
1811 }
1812
Larry Finger1867b112006-02-28 09:48:28 -06001813 if (ieee80211_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001814 priv->speed_scan[pos++] = channel;
1815 else
1816 IPW_WARNING("Skipping invalid channel request: %d\n",
1817 channel);
1818 p = strchr(p, ' ');
1819 if (!p)
1820 break;
1821 while (*p == ' ' || *p == '\t')
1822 p++;
1823 }
1824
1825 if (pos == 0)
1826 priv->config &= ~CFG_SPEED_SCAN;
1827 else {
1828 priv->speed_scan_pos = 0;
1829 priv->config |= CFG_SPEED_SCAN;
1830 }
1831
1832 return count;
1833}
1834
1835static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1836 store_speed_scan);
1837
1838static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1839 char *buf)
1840{
1841 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1842 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1843}
1844
1845static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1846 const char *buf, size_t count)
1847{
1848 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1849 if (buf[0] == '1')
1850 priv->config |= CFG_NET_STATS;
1851 else
1852 priv->config &= ~CFG_NET_STATS;
1853
1854 return count;
1855}
1856
James Ketrenosafbf30a2005-08-25 00:05:33 -05001857static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1858 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001859
James Ketrenosea2b26e2005-08-24 21:25:16 -05001860static void notify_wx_assoc_event(struct ipw_priv *priv)
1861{
1862 union iwreq_data wrqu;
1863 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1864 if (priv->status & STATUS_ASSOCIATED)
1865 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1866 else
1867 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1868 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1869}
1870
James Ketrenos43f66a62005-03-25 12:31:53 -06001871static void ipw_irq_tasklet(struct ipw_priv *priv)
1872{
1873 u32 inta, inta_mask, handled = 0;
1874 unsigned long flags;
1875 int rc = 0;
1876
Zhu Yi89c318e2006-06-08 22:19:49 -07001877 spin_lock_irqsave(&priv->irq_lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001878
James Ketrenosb095c382005-08-24 22:04:42 -05001879 inta = ipw_read32(priv, IPW_INTA_RW);
1880 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1881 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001882
1883 /* Add any cached INTA values that need to be handled */
1884 inta |= priv->isr_inta;
1885
Zhu Yi89c318e2006-06-08 22:19:49 -07001886 spin_unlock_irqrestore(&priv->irq_lock, flags);
1887
1888 spin_lock_irqsave(&priv->lock, flags);
1889
James Ketrenos43f66a62005-03-25 12:31:53 -06001890 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001891 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001892 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001893 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001894 }
1895
James Ketrenosb095c382005-08-24 22:04:42 -05001896 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001897 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001898 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001899 priv->status &= ~STATUS_HCMD_ACTIVE;
1900 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001901 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001902 }
1903
James Ketrenosb095c382005-08-24 22:04:42 -05001904 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001905 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001906 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05001907 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06001908 }
1909
James Ketrenosb095c382005-08-24 22:04:42 -05001910 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001911 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001912 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05001913 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06001914 }
1915
James Ketrenosb095c382005-08-24 22:04:42 -05001916 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001917 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001918 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05001919 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06001920 }
1921
James Ketrenosb095c382005-08-24 22:04:42 -05001922 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001923 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001924 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05001925 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06001926 }
1927
James Ketrenosb095c382005-08-24 22:04:42 -05001928 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001929 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001930 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001931 }
1932
James Ketrenosb095c382005-08-24 22:04:42 -05001933 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001934 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001935 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06001936 }
1937
James Ketrenosb095c382005-08-24 22:04:42 -05001938 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001939 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001940 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001941 }
1942
James Ketrenosb095c382005-08-24 22:04:42 -05001943 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001944 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001945 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001946 }
1947
James Ketrenosb095c382005-08-24 22:04:42 -05001948 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001949 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001950 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001951 }
1952
James Ketrenosb095c382005-08-24 22:04:42 -05001953 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001954 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1955 priv->status |= STATUS_RF_KILL_HW;
1956 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05001957 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06001958 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05001959 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001960 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05001961 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001962 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001963
James Ketrenosb095c382005-08-24 22:04:42 -05001964 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001965 IPW_WARNING("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001966 if (priv->error) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001967 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001968#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001969 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1970 struct ipw_fw_error *error =
1971 ipw_alloc_error_log(priv);
1972 ipw_dump_error_log(priv, error);
1973 if (error)
1974 ipw_free_error_log(error);
1975 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001976#endif
James Ketrenosb39860c2005-08-12 09:36:32 -05001977 } else {
1978 priv->error = ipw_alloc_error_log(priv);
1979 if (priv->error)
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001980 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001981 else
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001982 IPW_DEBUG_FW("Error allocating sysfs 'error' "
1983 "log.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001984#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001985 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1986 ipw_dump_error_log(priv, priv->error);
1987#endif
1988 }
1989
James Ketrenosb095c382005-08-24 22:04:42 -05001990 /* XXX: If hardware encryption is for WPA/WPA2,
1991 * we have to notify the supplicant. */
1992 if (priv->ieee->sec.encrypt) {
1993 priv->status &= ~STATUS_ASSOCIATED;
1994 notify_wx_assoc_event(priv);
1995 }
1996
1997 /* Keep the restart process from trying to send host
1998 * commands by clearing the INIT status bit */
1999 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05002000
2001 /* Cancel currently queued command. */
2002 priv->status &= ~STATUS_HCMD_ACTIVE;
2003 wake_up_interruptible(&priv->wait_command_queue);
2004
James Ketrenos43f66a62005-03-25 12:31:53 -06002005 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05002006 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002007 }
2008
James Ketrenosb095c382005-08-24 22:04:42 -05002009 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002010 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002011 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002012 }
2013
2014 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002015 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06002016 }
2017
Zhu Yi89c318e2006-06-08 22:19:49 -07002018 spin_unlock_irqrestore(&priv->lock, flags);
2019
James Ketrenos43f66a62005-03-25 12:31:53 -06002020 /* enable all interrupts */
2021 ipw_enable_interrupts(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06002022}
Jeff Garzikbf794512005-07-31 13:07:26 -04002023
James Ketrenos43f66a62005-03-25 12:31:53 -06002024#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2025static char *get_cmd_string(u8 cmd)
2026{
2027 switch (cmd) {
2028 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04002029 IPW_CMD(POWER_DOWN);
2030 IPW_CMD(SYSTEM_CONFIG);
2031 IPW_CMD(MULTICAST_ADDRESS);
2032 IPW_CMD(SSID);
2033 IPW_CMD(ADAPTER_ADDRESS);
2034 IPW_CMD(PORT_TYPE);
2035 IPW_CMD(RTS_THRESHOLD);
2036 IPW_CMD(FRAG_THRESHOLD);
2037 IPW_CMD(POWER_MODE);
2038 IPW_CMD(WEP_KEY);
2039 IPW_CMD(TGI_TX_KEY);
2040 IPW_CMD(SCAN_REQUEST);
2041 IPW_CMD(SCAN_REQUEST_EXT);
2042 IPW_CMD(ASSOCIATE);
2043 IPW_CMD(SUPPORTED_RATES);
2044 IPW_CMD(SCAN_ABORT);
2045 IPW_CMD(TX_FLUSH);
2046 IPW_CMD(QOS_PARAMETERS);
2047 IPW_CMD(DINO_CONFIG);
2048 IPW_CMD(RSN_CAPABILITIES);
2049 IPW_CMD(RX_KEY);
2050 IPW_CMD(CARD_DISABLE);
2051 IPW_CMD(SEED_NUMBER);
2052 IPW_CMD(TX_POWER);
2053 IPW_CMD(COUNTRY_INFO);
2054 IPW_CMD(AIRONET_INFO);
2055 IPW_CMD(AP_TX_POWER);
2056 IPW_CMD(CCKM_INFO);
2057 IPW_CMD(CCX_VER_INFO);
2058 IPW_CMD(SET_CALIBRATION);
2059 IPW_CMD(SENSITIVITY_CALIB);
2060 IPW_CMD(RETRY_LIMIT);
2061 IPW_CMD(IPW_PRE_POWER_DOWN);
2062 IPW_CMD(VAP_BEACON_TEMPLATE);
2063 IPW_CMD(VAP_DTIM_PERIOD);
2064 IPW_CMD(EXT_SUPPORTED_RATES);
2065 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2066 IPW_CMD(VAP_QUIET_INTERVALS);
2067 IPW_CMD(VAP_CHANNEL_SWITCH);
2068 IPW_CMD(VAP_MANDATORY_CHANNELS);
2069 IPW_CMD(VAP_CELL_PWR_LIMIT);
2070 IPW_CMD(VAP_CF_PARAM_SET);
2071 IPW_CMD(VAP_SET_BEACONING_STATE);
2072 IPW_CMD(MEASUREMENT);
2073 IPW_CMD(POWER_CAPABILITY);
2074 IPW_CMD(SUPPORTED_CHANNELS);
2075 IPW_CMD(TPC_REPORT);
2076 IPW_CMD(WME_INFO);
2077 IPW_CMD(PRODUCTION_COMMAND);
2078 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06002079 return "UNKNOWN";
2080 }
2081}
James Ketrenos43f66a62005-03-25 12:31:53 -06002082
2083#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002084
2085static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06002086{
2087 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002088 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06002089
James Ketrenosa613bff2005-08-24 21:43:11 -05002090 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002091 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002092 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2093 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002094 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002095 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06002096 }
2097
2098 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04002099
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002100 if (priv->cmdlog) {
2101 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2102 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2103 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2104 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2105 cmd->len);
2106 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2107 }
2108
James Ketrenosb095c382005-08-24 22:04:42 -05002109 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2110 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2111 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08002112
2113#ifndef DEBUG_CMD_WEP_KEY
2114 if (cmd->cmd == IPW_CMD_WEP_KEY)
2115 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2116 else
2117#endif
2118 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2119
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002120 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05002121 if (rc) {
2122 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002123 IPW_ERROR("Failed to send %s: Reason %d\n",
2124 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05002125 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002126 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002127 }
2128 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002129
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002130 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2131 !(priv->
2132 status & STATUS_HCMD_ACTIVE),
2133 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002134 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05002135 spin_lock_irqsave(&priv->lock, flags);
2136 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002137 IPW_ERROR("Failed to send %s: Command timed out.\n",
2138 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002139 priv->status &= ~STATUS_HCMD_ACTIVE;
2140 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002141 rc = -EIO;
2142 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002143 }
2144 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05002145 } else
2146 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002147
James Ketrenosb095c382005-08-24 22:04:42 -05002148 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002149 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2150 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002151 rc = -EIO;
2152 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06002153 }
2154
Zhu Yi2638bc32006-01-24 16:37:52 +08002155 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002156 if (priv->cmdlog) {
2157 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2158 priv->cmdlog_pos %= priv->cmdlog_len;
2159 }
2160 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002161}
2162
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002163static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002164{
2165 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002166 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002167 };
2168
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002169 return __ipw_send_cmd(priv, &cmd);
2170}
2171
2172static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2173 void *data)
2174{
2175 struct host_cmd cmd = {
2176 .cmd = command,
2177 .len = len,
2178 .param = data,
2179 };
2180
2181 return __ipw_send_cmd(priv, &cmd);
2182}
2183
2184static int ipw_send_host_complete(struct ipw_priv *priv)
2185{
James Ketrenos43f66a62005-03-25 12:31:53 -06002186 if (!priv) {
2187 IPW_ERROR("Invalid args\n");
2188 return -1;
2189 }
2190
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002191 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002192}
2193
Zhu Yid685b8c2006-04-13 17:20:27 +08002194static int ipw_send_system_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002195{
Zhu Yid685b8c2006-04-13 17:20:27 +08002196 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2197 sizeof(priv->sys_config),
2198 &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002199}
2200
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002201static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002202{
James Ketrenos43f66a62005-03-25 12:31:53 -06002203 if (!priv || !ssid) {
2204 IPW_ERROR("Invalid args\n");
2205 return -1;
2206 }
2207
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002208 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002209 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002210}
2211
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002212static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002213{
James Ketrenos43f66a62005-03-25 12:31:53 -06002214 if (!priv || !mac) {
2215 IPW_ERROR("Invalid args\n");
2216 return -1;
2217 }
2218
2219 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2220 priv->net_dev->name, MAC_ARG(mac));
2221
Zhu Yi2638bc32006-01-24 16:37:52 +08002222 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002223}
2224
James Ketrenosa613bff2005-08-24 21:43:11 -05002225/*
2226 * NOTE: This must be executed from our workqueue as it results in udelay
2227 * being called which may corrupt the keyboard if executed on default
2228 * workqueue
2229 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002230static void ipw_adapter_restart(void *adapter)
2231{
2232 struct ipw_priv *priv = adapter;
2233
2234 if (priv->status & STATUS_RF_KILL_MASK)
2235 return;
2236
2237 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002238
2239 if (priv->assoc_network &&
2240 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2241 ipw_remove_current_network(priv);
2242
James Ketrenos43f66a62005-03-25 12:31:53 -06002243 if (ipw_up(priv)) {
2244 IPW_ERROR("Failed to up device\n");
2245 return;
2246 }
2247}
2248
James Ketrenosc848d0a2005-08-24 21:56:24 -05002249static void ipw_bg_adapter_restart(void *data)
2250{
2251 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08002252 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002253 ipw_adapter_restart(data);
Zhu Yi46441512006-01-24 16:37:59 +08002254 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002255}
2256
James Ketrenos43f66a62005-03-25 12:31:53 -06002257#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2258
2259static void ipw_scan_check(void *data)
2260{
2261 struct ipw_priv *priv = data;
2262 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2263 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002264 "adapter after (%dms).\n",
2265 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
James Ketrenosa613bff2005-08-24 21:43:11 -05002266 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06002267 }
2268}
2269
James Ketrenosc848d0a2005-08-24 21:56:24 -05002270static void ipw_bg_scan_check(void *data)
2271{
2272 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08002273 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002274 ipw_scan_check(data);
Zhu Yi46441512006-01-24 16:37:59 +08002275 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002276}
2277
James Ketrenos43f66a62005-03-25 12:31:53 -06002278static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2279 struct ipw_scan_request_ext *request)
2280{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002281 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002282 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002283}
2284
2285static int ipw_send_scan_abort(struct ipw_priv *priv)
2286{
James Ketrenos43f66a62005-03-25 12:31:53 -06002287 if (!priv) {
2288 IPW_ERROR("Invalid args\n");
2289 return -1;
2290 }
2291
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002292 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002293}
2294
2295static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2296{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002297 struct ipw_sensitivity_calib calib = {
2298 .beacon_rssi_raw = sens,
James Ketrenos43f66a62005-03-25 12:31:53 -06002299 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002300
2301 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002302 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002303}
2304
2305static int ipw_send_associate(struct ipw_priv *priv,
2306 struct ipw_associate *associate)
2307{
James Ketrenosa613bff2005-08-24 21:43:11 -05002308 struct ipw_associate tmp_associate;
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002309
2310 if (!priv || !associate) {
2311 IPW_ERROR("Invalid args\n");
2312 return -1;
2313 }
2314
James Ketrenosa613bff2005-08-24 21:43:11 -05002315 memcpy(&tmp_associate, associate, sizeof(*associate));
2316 tmp_associate.policy_support =
2317 cpu_to_le16(tmp_associate.policy_support);
2318 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2319 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2320 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2321 tmp_associate.listen_interval =
2322 cpu_to_le16(tmp_associate.listen_interval);
2323 tmp_associate.beacon_interval =
2324 cpu_to_le16(tmp_associate.beacon_interval);
2325 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2326
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002327 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
Zhu Yi2638bc32006-01-24 16:37:52 +08002328 &tmp_associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002329}
2330
2331static int ipw_send_supported_rates(struct ipw_priv *priv,
2332 struct ipw_supported_rates *rates)
2333{
James Ketrenos43f66a62005-03-25 12:31:53 -06002334 if (!priv || !rates) {
2335 IPW_ERROR("Invalid args\n");
2336 return -1;
2337 }
2338
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002339 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002340 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002341}
2342
2343static int ipw_set_random_seed(struct ipw_priv *priv)
2344{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002345 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002346
2347 if (!priv) {
2348 IPW_ERROR("Invalid args\n");
2349 return -1;
2350 }
2351
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002352 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002353
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002354 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002355}
2356
James Ketrenos43f66a62005-03-25 12:31:53 -06002357static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2358{
James Ketrenos43f66a62005-03-25 12:31:53 -06002359 if (!priv) {
2360 IPW_ERROR("Invalid args\n");
2361 return -1;
2362 }
2363
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002364 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off),
Zhu Yi2638bc32006-01-24 16:37:52 +08002365 &phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002366}
James Ketrenos43f66a62005-03-25 12:31:53 -06002367
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002368static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002369{
James Ketrenos43f66a62005-03-25 12:31:53 -06002370 if (!priv || !power) {
2371 IPW_ERROR("Invalid args\n");
2372 return -1;
2373 }
2374
Zhu Yi2638bc32006-01-24 16:37:52 +08002375 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002376}
James Ketrenos43f66a62005-03-25 12:31:53 -06002377
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002378static int ipw_set_tx_power(struct ipw_priv *priv)
2379{
Larry Finger1867b112006-02-28 09:48:28 -06002380 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002381 struct ipw_tx_power tx_power;
2382 s8 max_power;
2383 int i;
2384
2385 memset(&tx_power, 0, sizeof(tx_power));
2386
2387 /* configure device for 'G' band */
2388 tx_power.ieee_mode = IPW_G_MODE;
2389 tx_power.num_channels = geo->bg_channels;
2390 for (i = 0; i < geo->bg_channels; i++) {
2391 max_power = geo->bg[i].max_power;
2392 tx_power.channels_tx_power[i].channel_number =
2393 geo->bg[i].channel;
2394 tx_power.channels_tx_power[i].tx_power = max_power ?
2395 min(max_power, priv->tx_power) : priv->tx_power;
2396 }
2397 if (ipw_send_tx_power(priv, &tx_power))
2398 return -EIO;
2399
2400 /* configure device to also handle 'B' band */
2401 tx_power.ieee_mode = IPW_B_MODE;
2402 if (ipw_send_tx_power(priv, &tx_power))
2403 return -EIO;
2404
2405 /* configure device to also handle 'A' band */
2406 if (priv->ieee->abg_true) {
2407 tx_power.ieee_mode = IPW_A_MODE;
2408 tx_power.num_channels = geo->a_channels;
2409 for (i = 0; i < tx_power.num_channels; i++) {
2410 max_power = geo->a[i].max_power;
2411 tx_power.channels_tx_power[i].channel_number =
2412 geo->a[i].channel;
2413 tx_power.channels_tx_power[i].tx_power = max_power ?
2414 min(max_power, priv->tx_power) : priv->tx_power;
2415 }
2416 if (ipw_send_tx_power(priv, &tx_power))
2417 return -EIO;
2418 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002419 return 0;
2420}
2421
2422static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2423{
2424 struct ipw_rts_threshold rts_threshold = {
2425 .rts_threshold = rts,
2426 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002427
2428 if (!priv) {
2429 IPW_ERROR("Invalid args\n");
2430 return -1;
2431 }
2432
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002433 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2434 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002435}
2436
2437static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2438{
2439 struct ipw_frag_threshold frag_threshold = {
2440 .frag_threshold = frag,
2441 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002442
2443 if (!priv) {
2444 IPW_ERROR("Invalid args\n");
2445 return -1;
2446 }
2447
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002448 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2449 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002450}
2451
2452static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2453{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002454 u32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002455
2456 if (!priv) {
2457 IPW_ERROR("Invalid args\n");
2458 return -1;
2459 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002460
James Ketrenos43f66a62005-03-25 12:31:53 -06002461 /* If on battery, set to 3, if AC set to CAM, else user
2462 * level */
2463 switch (mode) {
2464 case IPW_POWER_BATTERY:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002465 param = IPW_POWER_INDEX_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06002466 break;
2467 case IPW_POWER_AC:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002468 param = IPW_POWER_MODE_CAM;
James Ketrenos43f66a62005-03-25 12:31:53 -06002469 break;
2470 default:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002471 param = mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06002472 break;
2473 }
2474
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002475 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002476 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002477}
2478
James Ketrenosafbf30a2005-08-25 00:05:33 -05002479static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2480{
2481 struct ipw_retry_limit retry_limit = {
2482 .short_retry_limit = slimit,
2483 .long_retry_limit = llimit
2484 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002485
2486 if (!priv) {
2487 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002488 return -1;
2489 }
2490
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002491 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002492 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002493}
2494
2495/*
2496 * The IPW device contains a Microwire compatible EEPROM that stores
2497 * various data like the MAC address. Usually the firmware has exclusive
2498 * access to the eeprom, but during device initialization (before the
2499 * device driver has sent the HostComplete command to the firmware) the
2500 * device driver has read access to the EEPROM by way of indirect addressing
2501 * through a couple of memory mapped registers.
2502 *
2503 * The following is a simplified implementation for pulling data out of the
2504 * the eeprom, along with some helper functions to find information in
2505 * the per device private data's copy of the eeprom.
2506 *
2507 * NOTE: To better understand how these functions work (i.e what is a chip
2508 * select and why do have to keep driving the eeprom clock?), read
2509 * just about any data sheet for a Microwire compatible EEPROM.
2510 */
2511
2512/* write a 32 bit value into the indirect accessor register */
2513static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2514{
2515 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002516
James Ketrenos43f66a62005-03-25 12:31:53 -06002517 /* the eeprom requires some time to complete the operation */
2518 udelay(p->eeprom_delay);
2519
2520 return;
2521}
2522
2523/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002524static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002525{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002526 eeprom_write_reg(priv, 0);
2527 eeprom_write_reg(priv, EEPROM_BIT_CS);
2528 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2529 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002530}
2531
2532/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002533static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002534{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002535 eeprom_write_reg(priv, EEPROM_BIT_CS);
2536 eeprom_write_reg(priv, 0);
2537 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002538}
2539
2540/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002541static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002542{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002543 int d = (bit ? EEPROM_BIT_DI : 0);
2544 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2545 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002546}
2547
2548/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002549static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002550{
2551 int i;
2552
2553 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002554 eeprom_write_bit(priv, 1);
2555 eeprom_write_bit(priv, op & 2);
2556 eeprom_write_bit(priv, op & 1);
2557 for (i = 7; i >= 0; i--) {
2558 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002559 }
2560}
2561
2562/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002563static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002564{
2565 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002566 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002567
James Ketrenos43f66a62005-03-25 12:31:53 -06002568 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002569 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002570
2571 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002572 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002573
2574 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002575 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002576 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002577 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2578 eeprom_write_reg(priv, EEPROM_BIT_CS);
2579 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2580 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002581 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002582
James Ketrenos43f66a62005-03-25 12:31:53 -06002583 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002584 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002585 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002586
James Ketrenos43f66a62005-03-25 12:31:53 -06002587 return r;
2588}
2589
2590/* helper function for pulling the mac address out of the private */
2591/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002592static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002593{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002594 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002595}
2596
2597/*
2598 * Either the device driver (i.e. the host) or the firmware can
2599 * load eeprom data into the designated region in SRAM. If neither
2600 * happens then the FW will shutdown with a fatal error.
2601 *
2602 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2603 * bit needs region of shared SRAM needs to be non-zero.
2604 */
2605static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2606{
2607 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002608 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002609
James Ketrenos43f66a62005-03-25 12:31:53 -06002610 IPW_DEBUG_TRACE(">>\n");
2611
2612 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002613 for (i = 0; i < 128; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002614 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002615
Jeff Garzikbf794512005-07-31 13:07:26 -04002616 /*
2617 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002618 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002619 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002620 */
Alexey Dobriyan386093e2006-02-01 03:04:57 -08002621 if (priv->eeprom[EEPROM_VERSION] != 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002622 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2623
2624 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002625 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002626 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002627
2628 /* Do not load eeprom data on fatal error or suspend */
2629 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2630 } else {
2631 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2632
2633 /* Load eeprom data on fatal error or suspend */
2634 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2635 }
2636
2637 IPW_DEBUG_TRACE("<<\n");
2638}
2639
Arjan van de Ven858119e2006-01-14 13:20:43 -08002640static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002641{
2642 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002643 if (!count)
2644 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002645 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002646 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002647 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002648}
2649
2650static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2651{
James Ketrenosb095c382005-08-24 22:04:42 -05002652 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002653 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002654 sizeof(struct command_block));
2655}
2656
2657static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002658{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002659
2660 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002661
James Ketrenos43f66a62005-03-25 12:31:53 -06002662 /* Start the dma */
2663 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002664
James Ketrenos43f66a62005-03-25 12:31:53 -06002665 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002666 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002667
2668 IPW_DEBUG_FW("<< : \n");
2669 return 0;
2670}
2671
2672static void ipw_fw_dma_abort(struct ipw_priv *priv)
2673{
2674 u32 control = 0;
2675
2676 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002677
2678 //set the Stop and Abort bit
James Ketrenos43f66a62005-03-25 12:31:53 -06002679 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002680 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002681 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002682
James Ketrenos43f66a62005-03-25 12:31:53 -06002683 IPW_DEBUG_FW("<< \n");
2684}
2685
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002686static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2687 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002688{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002689 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002690 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002691 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002692 IPW_DEBUG_FW(">> :\n");
2693
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002694 ipw_write_indirect(priv, address, (u8 *) cb,
2695 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002696
2697 IPW_DEBUG_FW("<< :\n");
2698 return 0;
2699
2700}
2701
2702static int ipw_fw_dma_kick(struct ipw_priv *priv)
2703{
2704 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002705 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002706
2707 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002708
James Ketrenos43f66a62005-03-25 12:31:53 -06002709 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002710 ipw_fw_dma_write_command_block(priv, index,
2711 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002712
2713 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002714 ipw_clear_bit(priv, IPW_RESET_REG,
2715 IPW_RESET_REG_MASTER_DISABLED |
2716 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002717
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002718 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002719 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002720 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002721
2722 IPW_DEBUG_FW("<< :\n");
2723 return 0;
2724}
2725
2726static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2727{
2728 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002729 u32 register_value = 0;
2730 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002731
2732 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002733 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002734 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002735
2736 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002737 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2738 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002739
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002740 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002741 cb_fields_address = address;
2742 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002743 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002744
2745 cb_fields_address += sizeof(u32);
2746 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002747 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002748
2749 cb_fields_address += sizeof(u32);
2750 register_value = ipw_read_reg32(priv, cb_fields_address);
2751 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2752 register_value);
2753
2754 cb_fields_address += sizeof(u32);
2755 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002756 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002757
2758 IPW_DEBUG_FW(">> :\n");
2759}
2760
2761static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2762{
2763 u32 current_cb_address = 0;
2764 u32 current_cb_index = 0;
2765
2766 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002767 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002768
James Ketrenosb095c382005-08-24 22:04:42 -05002769 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002770 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002771
James Ketrenos43f66a62005-03-25 12:31:53 -06002772 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002773 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002774
2775 IPW_DEBUG_FW(">> :\n");
2776 return current_cb_index;
2777
2778}
2779
2780static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2781 u32 src_address,
2782 u32 dest_address,
2783 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002784 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002785{
2786
Jeff Garzikbf794512005-07-31 13:07:26 -04002787 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002788 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2789 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002790 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002791 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002792
2793 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2794 src_address, dest_address, length);
2795
2796 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2797 return -1;
2798
2799 last_cb_element = priv->sram_desc.last_cb_index;
2800 cb = &priv->sram_desc.cb_list[last_cb_element];
2801 priv->sram_desc.last_cb_index++;
2802
2803 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002804 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002805 control |= CB_INT_ENABLED;
2806
2807 if (is_last)
2808 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002809
James Ketrenos43f66a62005-03-25 12:31:53 -06002810 control |= length;
2811
2812 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002813 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002814
2815 /* Copy the Source and Destination addresses */
2816 cb->dest_addr = dest_address;
2817 cb->source_addr = src_address;
2818
2819 /* Copy the Control Word last */
2820 cb->control = control;
2821
2822 return 0;
2823}
2824
2825static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002826 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06002827{
2828 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002829 u32 src_offset = 0;
2830 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002831 int status = 0;
2832 IPW_DEBUG_FW(">> \n");
2833 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2834 src_phys, dest_address, length);
2835 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002836 status = ipw_fw_dma_add_command_block(priv,
2837 src_phys + src_offset,
2838 dest_address +
2839 dest_offset,
2840 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002841 if (status) {
2842 IPW_DEBUG_FW_INFO(": Failed\n");
2843 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002844 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002845 IPW_DEBUG_FW_INFO(": Added new cb\n");
2846
2847 src_offset += CB_MAX_LENGTH;
2848 dest_offset += CB_MAX_LENGTH;
2849 bytes_left -= CB_MAX_LENGTH;
2850 }
2851
2852 /* add the buffer tail */
2853 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002854 status =
2855 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2856 dest_address + dest_offset,
2857 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002858 if (status) {
2859 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2860 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002861 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002862 IPW_DEBUG_FW_INFO
2863 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002864 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002865
James Ketrenos43f66a62005-03-25 12:31:53 -06002866 IPW_DEBUG_FW("<< \n");
2867 return 0;
2868}
2869
2870static int ipw_fw_dma_wait(struct ipw_priv *priv)
2871{
Zhu Yi397ae122006-01-24 16:37:22 +08002872 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002873 u32 watchdog = 0;
2874
2875 IPW_DEBUG_FW(">> : \n");
2876
2877 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002878 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002879 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002880
2881 while (current_index < priv->sram_desc.last_cb_index) {
2882 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002883 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002884 current_index = ipw_fw_dma_command_block_index(priv);
2885
Zhu Yi397ae122006-01-24 16:37:22 +08002886 if (previous_index < current_index) {
2887 watchdog = 0;
2888 continue;
2889 }
2890 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002891 IPW_DEBUG_FW_INFO("Timeout\n");
2892 ipw_fw_dma_dump_command_block(priv);
2893 ipw_fw_dma_abort(priv);
2894 return -1;
2895 }
2896 }
2897
2898 ipw_fw_dma_abort(priv);
2899
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002900 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002901 ipw_set_bit(priv, IPW_RESET_REG,
2902 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002903
2904 IPW_DEBUG_FW("<< dmaWaitSync \n");
2905 return 0;
2906}
2907
Jeff Garzikbf794512005-07-31 13:07:26 -04002908static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002909{
2910 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002911 struct ieee80211_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002912 unsigned long flags;
2913
2914 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002915 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2916 network = list_entry(element, struct ieee80211_network, list);
2917 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2918 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002919 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002920 &priv->ieee->network_free_list);
2921 }
2922 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002923 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002924}
2925
2926/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002927 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002928 * Reads debug register from domain0.
2929 * If card is present, pre-defined value should
2930 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002931 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002932 * @param priv
2933 * @return 1 if card is present, 0 otherwise
2934 */
2935static inline int ipw_alive(struct ipw_priv *priv)
2936{
2937 return ipw_read32(priv, 0x90) == 0xd55555d5;
2938}
2939
Zhu Yic7b6a672006-01-24 16:37:05 +08002940/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002941static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06002942 int timeout)
2943{
2944 int i = 0;
2945
2946 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002947 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002948 return i;
2949 mdelay(10);
2950 i += 10;
2951 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002952
James Ketrenos43f66a62005-03-25 12:31:53 -06002953 return -ETIME;
2954}
2955
Jeff Garzikbf794512005-07-31 13:07:26 -04002956/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002957 * the ipw hardware. It assumes the buffer has all the bits for the
2958 * image and the caller is handling the memory allocation and clean up.
2959 */
2960
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002961static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002962{
2963 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002964
James Ketrenos43f66a62005-03-25 12:31:53 -06002965 IPW_DEBUG_TRACE(">> \n");
2966 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05002967 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002968
Zhu Yic7b6a672006-01-24 16:37:05 +08002969 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05002970 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2971 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06002972 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08002973 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002974 return -1;
2975 }
2976
2977 IPW_DEBUG_INFO("stop master %dms\n", rc);
2978
2979 return rc;
2980}
2981
2982static void ipw_arc_release(struct ipw_priv *priv)
2983{
2984 IPW_DEBUG_TRACE(">> \n");
2985 mdelay(5);
2986
James Ketrenosb095c382005-08-24 22:04:42 -05002987 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002988
2989 /* no one knows timing, for safety add some delay */
2990 mdelay(5);
2991}
2992
James Ketrenos43f66a62005-03-25 12:31:53 -06002993struct fw_chunk {
2994 u32 address;
2995 u32 length;
2996};
2997
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002998static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002999{
3000 int rc = 0, i, addr;
3001 u8 cr = 0;
3002 u16 *image;
3003
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003004 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04003005
James Ketrenos43f66a62005-03-25 12:31:53 -06003006 IPW_DEBUG_TRACE(">> \n");
3007
3008 rc = ipw_stop_master(priv);
3009
3010 if (rc < 0)
3011 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003012
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003013// spin_lock_irqsave(&priv->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04003014
James Ketrenosb095c382005-08-24 22:04:42 -05003015 for (addr = IPW_SHARED_LOWER_BOUND;
3016 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003017 ipw_write32(priv, addr, 0);
3018 }
3019
3020 /* no ucode (yet) */
3021 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3022 /* destroy DMA queues */
3023 /* reset sequence */
3024
James Ketrenosb095c382005-08-24 22:04:42 -05003025 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06003026 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05003027 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06003028 mdelay(1);
3029
3030 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05003031 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06003032 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003033
James Ketrenosb095c382005-08-24 22:04:42 -05003034 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003035 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003036
James Ketrenos43f66a62005-03-25 12:31:53 -06003037 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08003038 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3039 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003040 mdelay(1);
3041
3042 /* write ucode */
3043 /**
3044 * @bug
3045 * Do NOT set indirect address register once and then
3046 * store data to indirect data register in the loop.
3047 * It seems very reasonable, but in this case DINO do not
3048 * accept ucode. It is essential to set address each time.
3049 */
3050 /* load new ipw uCode */
3051 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05003052 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
James Ketrenosa613bff2005-08-24 21:43:11 -05003053 cpu_to_le16(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06003054
James Ketrenos43f66a62005-03-25 12:31:53 -06003055 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05003056 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3057 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06003058
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003059 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06003060
3061 /* wait for alive response */
3062 for (i = 0; i < 100; i++) {
3063 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05003064 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003065 if (cr & DINO_RXFIFO_DATA)
3066 break;
3067 mdelay(1);
3068 }
3069
3070 if (cr & DINO_RXFIFO_DATA) {
3071 /* alive_command_responce size is NOT multiple of 4 */
3072 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04003073
3074 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06003075 response_buffer[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05003076 le32_to_cpu(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05003077 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06003078 memcpy(&priv->dino_alive, response_buffer,
3079 sizeof(priv->dino_alive));
3080 if (priv->dino_alive.alive_command == 1
3081 && priv->dino_alive.ucode_valid == 1) {
3082 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003083 IPW_DEBUG_INFO
3084 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3085 "of %02d/%02d/%02d %02d:%02d\n",
3086 priv->dino_alive.software_revision,
3087 priv->dino_alive.software_revision,
3088 priv->dino_alive.device_identifier,
3089 priv->dino_alive.device_identifier,
3090 priv->dino_alive.time_stamp[0],
3091 priv->dino_alive.time_stamp[1],
3092 priv->dino_alive.time_stamp[2],
3093 priv->dino_alive.time_stamp[3],
3094 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003095 } else {
3096 IPW_DEBUG_INFO("Microcode is not alive\n");
3097 rc = -EINVAL;
3098 }
3099 } else {
3100 IPW_DEBUG_INFO("No alive response from DINO\n");
3101 rc = -ETIME;
3102 }
3103
3104 /* disable DINO, otherwise for some reason
3105 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05003106 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003107
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003108// spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003109
3110 return rc;
3111}
3112
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003113static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003114{
3115 int rc = -1;
3116 int offset = 0;
3117 struct fw_chunk *chunk;
3118 dma_addr_t shared_phys;
3119 u8 *shared_virt;
3120
3121 IPW_DEBUG_TRACE("<< : \n");
3122 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
3123
3124 if (!shared_virt)
3125 return -ENOMEM;
3126
3127 memmove(shared_virt, data, len);
3128
3129 /* Start the Dma */
3130 rc = ipw_fw_dma_enable(priv);
3131
3132 if (priv->sram_desc.last_cb_index > 0) {
3133 /* the DMA is already ready this would be a bug. */
3134 BUG();
3135 goto out;
3136 }
3137
3138 do {
3139 chunk = (struct fw_chunk *)(data + offset);
3140 offset += sizeof(struct fw_chunk);
3141 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003142 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003143 * offeset*/
3144 /* Dma loading */
3145 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
James Ketrenosa613bff2005-08-24 21:43:11 -05003146 le32_to_cpu(chunk->address),
3147 le32_to_cpu(chunk->length));
James Ketrenos43f66a62005-03-25 12:31:53 -06003148 if (rc) {
3149 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3150 goto out;
3151 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003152
James Ketrenosa613bff2005-08-24 21:43:11 -05003153 offset += le32_to_cpu(chunk->length);
James Ketrenos43f66a62005-03-25 12:31:53 -06003154 } while (offset < len);
3155
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003156 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06003157 rc = ipw_fw_dma_kick(priv);
3158 if (rc) {
3159 IPW_ERROR("dmaKick Failed\n");
3160 goto out;
3161 }
3162
3163 rc = ipw_fw_dma_wait(priv);
3164 if (rc) {
3165 IPW_ERROR("dmaWaitSync Failed\n");
3166 goto out;
3167 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003168 out:
3169 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06003170 return rc;
3171}
3172
3173/* stop nic */
3174static int ipw_stop_nic(struct ipw_priv *priv)
3175{
3176 int rc = 0;
3177
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003178 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003179 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003180
James Ketrenosb095c382005-08-24 22:04:42 -05003181 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3182 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003183 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003184 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003185 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003186 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003187
James Ketrenosb095c382005-08-24 22:04:42 -05003188 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003189
James Ketrenos43f66a62005-03-25 12:31:53 -06003190 return rc;
3191}
3192
3193static void ipw_start_nic(struct ipw_priv *priv)
3194{
3195 IPW_DEBUG_TRACE(">>\n");
3196
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003197 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003198 ipw_clear_bit(priv, IPW_RESET_REG,
3199 IPW_RESET_REG_MASTER_DISABLED |
3200 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003201 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003202
James Ketrenos43f66a62005-03-25 12:31:53 -06003203 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003204 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3205 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003206
3207 IPW_DEBUG_TRACE("<<\n");
3208}
Jeff Garzikbf794512005-07-31 13:07:26 -04003209
James Ketrenos43f66a62005-03-25 12:31:53 -06003210static int ipw_init_nic(struct ipw_priv *priv)
3211{
3212 int rc;
3213
3214 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003215 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003216 /*prvHwInitNic */
3217 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003218 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003219
3220 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003221 ipw_write32(priv, IPW_READ_INT_REGISTER,
3222 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003223
3224 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003225 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3226 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003227 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003228 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3229
3230 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003231 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003232
3233 udelay(10);
3234
3235 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003236 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003237
3238 IPW_DEBUG_TRACE(">>\n");
3239 return 0;
3240}
3241
Jeff Garzikbf794512005-07-31 13:07:26 -04003242/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003243 * Probe is an ok place to call this from.
3244 */
3245static int ipw_reset_nic(struct ipw_priv *priv)
3246{
3247 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003248 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003249
3250 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003251
James Ketrenos43f66a62005-03-25 12:31:53 -06003252 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003253
James Ketrenosa613bff2005-08-24 21:43:11 -05003254 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003255 /* Clear the 'host command active' bit... */
3256 priv->status &= ~STATUS_HCMD_ACTIVE;
3257 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003258 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3259 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003260 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003261
3262 IPW_DEBUG_TRACE("<<\n");
3263 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003264}
James Ketrenos43f66a62005-03-25 12:31:53 -06003265
James Ketrenos9006ea72006-03-08 03:22:28 +08003266
3267struct ipw_fw {
Zhu Yi0070f8c2006-04-13 17:20:12 +08003268 __le32 ver;
3269 __le32 boot_size;
3270 __le32 ucode_size;
3271 __le32 fw_size;
James Ketrenos9006ea72006-03-08 03:22:28 +08003272 u8 data[0];
3273};
3274
Jeff Garzikbf794512005-07-31 13:07:26 -04003275static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos9006ea72006-03-08 03:22:28 +08003276 const struct firmware **raw, const char *name)
James Ketrenos43f66a62005-03-25 12:31:53 -06003277{
James Ketrenos9006ea72006-03-08 03:22:28 +08003278 struct ipw_fw *fw;
James Ketrenos43f66a62005-03-25 12:31:53 -06003279 int rc;
3280
3281 /* ask firmware_class module to get the boot firmware off disk */
James Ketrenos9006ea72006-03-08 03:22:28 +08003282 rc = request_firmware(raw, name, &priv->pci_dev->dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06003283 if (rc < 0) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003284 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003285 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003286 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003287
James Ketrenos9006ea72006-03-08 03:22:28 +08003288 if ((*raw)->size < sizeof(*fw)) {
3289 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003290 return -EINVAL;
3291 }
3292
James Ketrenos9006ea72006-03-08 03:22:28 +08003293 fw = (void *)(*raw)->data;
3294
Zhu Yi0070f8c2006-04-13 17:20:12 +08003295 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3296 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003297 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3298 name, (*raw)->size);
3299 return -EINVAL;
3300 }
3301
3302 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003303 name,
James Ketrenos9006ea72006-03-08 03:22:28 +08003304 le32_to_cpu(fw->ver) >> 16,
3305 le32_to_cpu(fw->ver) & 0xff,
3306 (*raw)->size - sizeof(*fw));
James Ketrenos43f66a62005-03-25 12:31:53 -06003307 return 0;
3308}
3309
James Ketrenosb095c382005-08-24 22:04:42 -05003310#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003311
Arjan van de Ven858119e2006-01-14 13:20:43 -08003312static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003313 struct ipw_rx_queue *rxq)
3314{
3315 unsigned long flags;
3316 int i;
3317
3318 spin_lock_irqsave(&rxq->lock, flags);
3319
3320 INIT_LIST_HEAD(&rxq->rx_free);
3321 INIT_LIST_HEAD(&rxq->rx_used);
3322
3323 /* Fill the rx_used queue with _all_ of the Rx buffers */
3324 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3325 /* In the reset function, these buffers may have been allocated
3326 * to an SKB, so we need to unmap and free potential storage */
3327 if (rxq->pool[i].skb != NULL) {
3328 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003329 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003330 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003331 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003332 }
3333 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3334 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003335
James Ketrenos43f66a62005-03-25 12:31:53 -06003336 /* Set us so that we have processed and used all buffers, but have
3337 * not restocked the Rx queue with fresh buffers */
3338 rxq->read = rxq->write = 0;
3339 rxq->processed = RX_QUEUE_SIZE - 1;
3340 rxq->free_count = 0;
3341 spin_unlock_irqrestore(&rxq->lock, flags);
3342}
3343
3344#ifdef CONFIG_PM
3345static int fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003346static const struct firmware *raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003347
3348static void free_firmware(void)
3349{
3350 if (fw_loaded) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003351 release_firmware(raw);
3352 raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003353 fw_loaded = 0;
3354 }
3355}
3356#else
3357#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003358#endif
3359
3360static int ipw_load(struct ipw_priv *priv)
3361{
3362#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003363 const struct firmware *raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003364#endif
James Ketrenos9006ea72006-03-08 03:22:28 +08003365 struct ipw_fw *fw;
3366 u8 *boot_img, *ucode_img, *fw_img;
3367 u8 *name = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003368 int rc = 0, retries = 3;
3369
Zhu Yi397ae122006-01-24 16:37:22 +08003370 switch (priv->ieee->iw_mode) {
3371 case IW_MODE_ADHOC:
James Ketrenos9006ea72006-03-08 03:22:28 +08003372 name = "ipw2200-ibss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003373 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003374#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003375 case IW_MODE_MONITOR:
James Ketrenos9006ea72006-03-08 03:22:28 +08003376 name = "ipw2200-sniffer.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003377 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003378#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003379 case IW_MODE_INFRA:
James Ketrenos9006ea72006-03-08 03:22:28 +08003380 name = "ipw2200-bss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003381 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003382 }
Zhu Yi397ae122006-01-24 16:37:22 +08003383
James Ketrenos9006ea72006-03-08 03:22:28 +08003384 if (!name) {
3385 rc = -EINVAL;
3386 goto error;
3387 }
3388
3389#ifdef CONFIG_PM
3390 if (!fw_loaded) {
3391#endif
3392 rc = ipw_get_fw(priv, &raw, name);
3393 if (rc < 0)
3394 goto error;
3395#ifdef CONFIG_PM
3396 }
3397#endif
3398
3399 fw = (void *)raw->data;
3400 boot_img = &fw->data[0];
Zhu Yi0070f8c2006-04-13 17:20:12 +08003401 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3402 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3403 le32_to_cpu(fw->ucode_size)];
James Ketrenos9006ea72006-03-08 03:22:28 +08003404
Zhu Yi397ae122006-01-24 16:37:22 +08003405 if (rc < 0)
3406 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003407
3408 if (!priv->rxq)
3409 priv->rxq = ipw_rx_queue_alloc(priv);
3410 else
3411 ipw_rx_queue_reset(priv, priv->rxq);
3412 if (!priv->rxq) {
3413 IPW_ERROR("Unable to initialize Rx queue\n");
3414 goto error;
3415 }
3416
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003417 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003418 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003419 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003420 priv->status &= ~STATUS_INT_ENABLED;
3421
3422 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003423 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003424
James Ketrenos43f66a62005-03-25 12:31:53 -06003425 ipw_stop_nic(priv);
3426
3427 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003428 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003429 IPW_ERROR("Unable to reset NIC\n");
3430 goto error;
3431 }
3432
James Ketrenosb095c382005-08-24 22:04:42 -05003433 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3434 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003435
3436 /* DMA the initial boot firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003437 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003438 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003439 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003440 goto error;
3441 }
3442
3443 /* kick start the device */
3444 ipw_start_nic(priv);
3445
Zhu Yic7b6a672006-01-24 16:37:05 +08003446 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003447 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3448 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003449 if (rc < 0) {
3450 IPW_ERROR("device failed to boot initial fw image\n");
3451 goto error;
3452 }
3453 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3454
Jeff Garzikbf794512005-07-31 13:07:26 -04003455 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003456 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003457
3458 /* DMA the ucode into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003459 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003460 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003461 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003462 goto error;
3463 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003464
James Ketrenos43f66a62005-03-25 12:31:53 -06003465 /* stop nic */
3466 ipw_stop_nic(priv);
3467
3468 /* DMA bss firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003469 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003470 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003471 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003472 goto error;
3473 }
Zhu Yi397ae122006-01-24 16:37:22 +08003474#ifdef CONFIG_PM
3475 fw_loaded = 1;
3476#endif
3477
James Ketrenos43f66a62005-03-25 12:31:53 -06003478 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3479
3480 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003481 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003482 IPW_ERROR("Unable to initialize queues\n");
3483 goto error;
3484 }
3485
3486 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003487 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003488 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003489 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003490
James Ketrenos43f66a62005-03-25 12:31:53 -06003491 /* kick start the device */
3492 ipw_start_nic(priv);
3493
James Ketrenosb095c382005-08-24 22:04:42 -05003494 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003495 if (retries > 0) {
3496 IPW_WARNING("Parity error. Retrying init.\n");
3497 retries--;
3498 goto retry;
3499 }
3500
3501 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3502 rc = -EIO;
3503 goto error;
3504 }
3505
3506 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003507 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3508 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003509 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003510 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003511 goto error;
3512 }
3513 IPW_DEBUG_INFO("device response after %dms\n", rc);
3514
3515 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003516 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003517
3518 /* read eeprom data and initialize the eeprom region of sram */
3519 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003520 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003521
3522 /* enable interrupts */
3523 ipw_enable_interrupts(priv);
3524
3525 /* Ensure our queue has valid packets */
3526 ipw_rx_queue_replenish(priv);
3527
James Ketrenosb095c382005-08-24 22:04:42 -05003528 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003529
3530 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003531 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003532
3533#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003534 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003535#endif
3536 return 0;
3537
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003538 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003539 if (priv->rxq) {
3540 ipw_rx_queue_free(priv, priv->rxq);
3541 priv->rxq = NULL;
3542 }
3543 ipw_tx_queue_free(priv);
James Ketrenos9006ea72006-03-08 03:22:28 +08003544 if (raw)
3545 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003546#ifdef CONFIG_PM
3547 fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003548 raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003549#endif
3550
3551 return rc;
3552}
3553
Jeff Garzikbf794512005-07-31 13:07:26 -04003554/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003555 * DMA services
3556 *
3557 * Theory of operation
3558 *
3559 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3560 * 2 empty entries always kept in the buffer to protect from overflow.
3561 *
3562 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003563 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3564 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003565 * Tx queue resumed.
3566 *
3567 * The IPW operates with six queues, one receive queue in the device's
3568 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003569 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003570 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003571 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003572 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003573 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003574 * we only utilize the first data transmit queue (queue1).
3575 */
3576
3577/**
3578 * Driver allocates buffers of this size for Rx
3579 */
3580
3581static inline int ipw_queue_space(const struct clx2_queue *q)
3582{
3583 int s = q->last_used - q->first_empty;
3584 if (s <= 0)
3585 s += q->n_bd;
3586 s -= 2; /* keep some reserve to not confuse empty and full situations */
3587 if (s < 0)
3588 s = 0;
3589 return s;
3590}
3591
3592static inline int ipw_queue_inc_wrap(int index, int n_bd)
3593{
3594 return (++index == n_bd) ? 0 : index;
3595}
3596
3597/**
3598 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003599 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003600 * @param q queue to init
3601 * @param count Number of BD's to allocate. Should be power of 2
3602 * @param read_register Address for 'read' register
3603 * (not offset within BAR, full address)
3604 * @param write_register Address for 'write' register
3605 * (not offset within BAR, full address)
3606 * @param base_register Address for 'base' register
3607 * (not offset within BAR, full address)
3608 * @param size Address for 'size' register
3609 * (not offset within BAR, full address)
3610 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003611static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003612 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003613{
3614 q->n_bd = count;
3615
3616 q->low_mark = q->n_bd / 4;
3617 if (q->low_mark < 4)
3618 q->low_mark = 4;
3619
3620 q->high_mark = q->n_bd / 8;
3621 if (q->high_mark < 2)
3622 q->high_mark = 2;
3623
3624 q->first_empty = q->last_used = 0;
3625 q->reg_r = read;
3626 q->reg_w = write;
3627
3628 ipw_write32(priv, base, q->dma_addr);
3629 ipw_write32(priv, size, count);
3630 ipw_write32(priv, read, 0);
3631 ipw_write32(priv, write, 0);
3632
3633 _ipw_read32(priv, 0x90);
3634}
3635
Jeff Garzikbf794512005-07-31 13:07:26 -04003636static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003637 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003638 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003639{
3640 struct pci_dev *dev = priv->pci_dev;
3641
3642 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3643 if (!q->txb) {
3644 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3645 return -ENOMEM;
3646 }
3647
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003648 q->bd =
3649 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003650 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003651 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003652 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003653 kfree(q->txb);
3654 q->txb = NULL;
3655 return -ENOMEM;
3656 }
3657
3658 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3659 return 0;
3660}
3661
3662/**
3663 * Free one TFD, those at index [txq->q.last_used].
3664 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003665 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003666 * @param dev
3667 * @param txq
3668 */
3669static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3670 struct clx2_tx_queue *txq)
3671{
3672 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3673 struct pci_dev *dev = priv->pci_dev;
3674 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003675
James Ketrenos43f66a62005-03-25 12:31:53 -06003676 /* classify bd */
3677 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3678 /* nothing to cleanup after for host commands */
3679 return;
3680
3681 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003682 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3683 IPW_ERROR("Too many chunks: %i\n",
3684 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003685 /** @todo issue fatal error, it is quite serious situation */
3686 return;
3687 }
3688
3689 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003690 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3691 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3692 le16_to_cpu(bd->u.data.chunk_len[i]),
3693 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003694 if (txq->txb[txq->q.last_used]) {
3695 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3696 txq->txb[txq->q.last_used] = NULL;
3697 }
3698 }
3699}
3700
3701/**
3702 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003703 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003704 * Empty queue by removing and destroying all BD's.
3705 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003706 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003707 * @param dev
3708 * @param q
3709 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003710static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003711{
3712 struct clx2_queue *q = &txq->q;
3713 struct pci_dev *dev = priv->pci_dev;
3714
Jeff Garzikbf794512005-07-31 13:07:26 -04003715 if (q->n_bd == 0)
3716 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003717
3718 /* first, empty all BD's */
3719 for (; q->first_empty != q->last_used;
3720 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3721 ipw_queue_tx_free_tfd(priv, txq);
3722 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003723
James Ketrenos43f66a62005-03-25 12:31:53 -06003724 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003725 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003726 q->dma_addr);
3727 kfree(txq->txb);
3728
3729 /* 0 fill whole structure */
3730 memset(txq, 0, sizeof(*txq));
3731}
3732
James Ketrenos43f66a62005-03-25 12:31:53 -06003733/**
3734 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003735 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003736 * @param priv
3737 */
3738static void ipw_tx_queue_free(struct ipw_priv *priv)
3739{
3740 /* Tx CMD queue */
3741 ipw_queue_tx_free(priv, &priv->txq_cmd);
3742
3743 /* Tx queues */
3744 ipw_queue_tx_free(priv, &priv->txq[0]);
3745 ipw_queue_tx_free(priv, &priv->txq[1]);
3746 ipw_queue_tx_free(priv, &priv->txq[2]);
3747 ipw_queue_tx_free(priv, &priv->txq[3]);
3748}
3749
Arjan van de Ven858119e2006-01-14 13:20:43 -08003750static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003751{
3752 /* First 3 bytes are manufacturer */
3753 bssid[0] = priv->mac_addr[0];
3754 bssid[1] = priv->mac_addr[1];
3755 bssid[2] = priv->mac_addr[2];
3756
3757 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003758 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003759
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003760 bssid[0] &= 0xfe; /* clear multicast bit */
3761 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003762}
3763
Arjan van de Ven858119e2006-01-14 13:20:43 -08003764static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003765{
3766 struct ipw_station_entry entry;
3767 int i;
3768
3769 for (i = 0; i < priv->num_stations; i++) {
3770 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3771 /* Another node is active in network */
3772 priv->missed_adhoc_beacons = 0;
3773 if (!(priv->config & CFG_STATIC_CHANNEL))
3774 /* when other nodes drop out, we drop out */
3775 priv->config &= ~CFG_ADHOC_PERSIST;
3776
3777 return i;
3778 }
3779 }
3780
3781 if (i == MAX_STATIONS)
3782 return IPW_INVALID_STATION;
3783
3784 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3785
3786 entry.reserved = 0;
3787 entry.support_mode = 0;
3788 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3789 memcpy(priv->stations[i], bssid, ETH_ALEN);
3790 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003791 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003792 priv->num_stations++;
3793
3794 return i;
3795}
3796
Arjan van de Ven858119e2006-01-14 13:20:43 -08003797static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003798{
3799 int i;
3800
Jeff Garzikbf794512005-07-31 13:07:26 -04003801 for (i = 0; i < priv->num_stations; i++)
3802 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003803 return i;
3804
3805 return IPW_INVALID_STATION;
3806}
3807
3808static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3809{
3810 int err;
3811
Hong Liu7b996592005-08-25 17:36:13 +08003812 if (priv->status & STATUS_ASSOCIATING) {
3813 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3814 queue_work(priv->workqueue, &priv->disassociate);
3815 return;
3816 }
3817
3818 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003819 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3820 return;
3821 }
3822
3823 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3824 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04003825 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06003826 priv->assoc_request.channel);
3827
3828 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3829 priv->status |= STATUS_DISASSOCIATING;
3830
3831 if (quiet)
3832 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3833 else
3834 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003835
James Ketrenos43f66a62005-03-25 12:31:53 -06003836 err = ipw_send_associate(priv, &priv->assoc_request);
3837 if (err) {
3838 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3839 "failed.\n");
3840 return;
3841 }
3842
3843}
3844
James Ketrenosc848d0a2005-08-24 21:56:24 -05003845static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003846{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003847 struct ipw_priv *priv = data;
3848 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3849 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003850 ipw_send_disassociate(data, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003851 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003852}
3853
James Ketrenosc848d0a2005-08-24 21:56:24 -05003854static void ipw_bg_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003855{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003856 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08003857 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003858 ipw_disassociate(data);
Zhu Yi46441512006-01-24 16:37:59 +08003859 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003860}
3861
Zhu Yid8bad6d2005-07-13 12:25:38 -05003862static void ipw_system_config(void *data)
3863{
3864 struct ipw_priv *priv = data;
Zhu Yid685b8c2006-04-13 17:20:27 +08003865
3866#ifdef CONFIG_IPW2200_PROMISCUOUS
3867 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
3868 priv->sys_config.accept_all_data_frames = 1;
3869 priv->sys_config.accept_non_directed_frames = 1;
3870 priv->sys_config.accept_all_mgmt_bcpr = 1;
3871 priv->sys_config.accept_all_mgmt_frames = 1;
3872 }
3873#endif
3874
3875 ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003876}
3877
3878struct ipw_status_code {
3879 u16 status;
3880 const char *reason;
3881};
3882
3883static const struct ipw_status_code ipw_status_codes[] = {
3884 {0x00, "Successful"},
3885 {0x01, "Unspecified failure"},
3886 {0x0A, "Cannot support all requested capabilities in the "
3887 "Capability information field"},
3888 {0x0B, "Reassociation denied due to inability to confirm that "
3889 "association exists"},
3890 {0x0C, "Association denied due to reason outside the scope of this "
3891 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003892 {0x0D,
3893 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003894 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003895 {0x0E,
3896 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003897 "transaction sequence number out of expected sequence"},
3898 {0x0F, "Authentication rejected because of challenge failure"},
3899 {0x10, "Authentication rejected due to timeout waiting for next "
3900 "frame in sequence"},
3901 {0x11, "Association denied because AP is unable to handle additional "
3902 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003903 {0x12,
3904 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003905 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003906 {0x13,
3907 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003908 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003909 {0x14,
3910 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003911 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003912 {0x15,
3913 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003914 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003915 {0x19,
3916 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003917 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003918 {0x1A,
3919 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003920 "DSSS-OFDM operation"},
3921 {0x28, "Invalid Information Element"},
3922 {0x29, "Group Cipher is not valid"},
3923 {0x2A, "Pairwise Cipher is not valid"},
3924 {0x2B, "AKMP is not valid"},
3925 {0x2C, "Unsupported RSN IE version"},
3926 {0x2D, "Invalid RSN IE Capabilities"},
3927 {0x2E, "Cipher suite is rejected per security policy"},
3928};
3929
Brice Goglin0f52bf92005-12-01 01:41:46 -08003930#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04003931static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003932{
3933 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003934 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003935 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003936 return ipw_status_codes[i].reason;
3937 return "Unknown status value.";
3938}
3939#endif
3940
3941static void inline average_init(struct average *avg)
3942{
3943 memset(avg, 0, sizeof(*avg));
3944}
3945
Zhu Yi00d21de2006-04-13 17:19:02 +08003946#define DEPTH_RSSI 8
3947#define DEPTH_NOISE 16
3948static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
3949{
3950 return ((depth-1)*prev_avg + val)/depth;
3951}
3952
Arjan van de Ven858119e2006-01-14 13:20:43 -08003953static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06003954{
3955 avg->sum -= avg->entries[avg->pos];
3956 avg->sum += val;
3957 avg->entries[avg->pos++] = val;
3958 if (unlikely(avg->pos == AVG_ENTRIES)) {
3959 avg->init = 1;
3960 avg->pos = 0;
3961 }
3962}
3963
Arjan van de Ven858119e2006-01-14 13:20:43 -08003964static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06003965{
3966 if (!unlikely(avg->init)) {
3967 if (avg->pos)
3968 return avg->sum / avg->pos;
3969 return 0;
3970 }
3971
3972 return avg->sum / AVG_ENTRIES;
3973}
3974
3975static void ipw_reset_stats(struct ipw_priv *priv)
3976{
3977 u32 len = sizeof(u32);
3978
3979 priv->quality = 0;
3980
3981 average_init(&priv->average_missed_beacons);
Zhu Yi00d21de2006-04-13 17:19:02 +08003982 priv->exp_avg_rssi = -60;
3983 priv->exp_avg_noise = -85 + 0x100;
James Ketrenos43f66a62005-03-25 12:31:53 -06003984
3985 priv->last_rate = 0;
3986 priv->last_missed_beacons = 0;
3987 priv->last_rx_packets = 0;
3988 priv->last_tx_packets = 0;
3989 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003990
James Ketrenos43f66a62005-03-25 12:31:53 -06003991 /* Firmware managed, reset only when NIC is restarted, so we have to
3992 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003993 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003994 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003995 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003996 &priv->last_tx_failures, &len);
3997
3998 /* Driver managed, reset with each association */
3999 priv->missed_adhoc_beacons = 0;
4000 priv->missed_beacons = 0;
4001 priv->tx_packets = 0;
4002 priv->rx_packets = 0;
4003
4004}
4005
Arjan van de Ven858119e2006-01-14 13:20:43 -08004006static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06004007{
4008 u32 i = 0x80000000;
4009 u32 mask = priv->rates_mask;
4010 /* If currently associated in B mode, restrict the maximum
4011 * rate match to B rates */
4012 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
4013 mask &= IEEE80211_CCK_RATES_MASK;
4014
4015 /* TODO: Verify that the rate is supported by the current rates
4016 * list. */
4017
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004018 while (i && !(mask & i))
4019 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004020 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004021 case IEEE80211_CCK_RATE_1MB_MASK:
4022 return 1000000;
4023 case IEEE80211_CCK_RATE_2MB_MASK:
4024 return 2000000;
4025 case IEEE80211_CCK_RATE_5MB_MASK:
4026 return 5500000;
4027 case IEEE80211_OFDM_RATE_6MB_MASK:
4028 return 6000000;
4029 case IEEE80211_OFDM_RATE_9MB_MASK:
4030 return 9000000;
4031 case IEEE80211_CCK_RATE_11MB_MASK:
4032 return 11000000;
4033 case IEEE80211_OFDM_RATE_12MB_MASK:
4034 return 12000000;
4035 case IEEE80211_OFDM_RATE_18MB_MASK:
4036 return 18000000;
4037 case IEEE80211_OFDM_RATE_24MB_MASK:
4038 return 24000000;
4039 case IEEE80211_OFDM_RATE_36MB_MASK:
4040 return 36000000;
4041 case IEEE80211_OFDM_RATE_48MB_MASK:
4042 return 48000000;
4043 case IEEE80211_OFDM_RATE_54MB_MASK:
4044 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004045 }
4046
Jeff Garzikbf794512005-07-31 13:07:26 -04004047 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06004048 return 11000000;
4049 else
4050 return 54000000;
4051}
4052
4053static u32 ipw_get_current_rate(struct ipw_priv *priv)
4054{
4055 u32 rate, len = sizeof(rate);
4056 int err;
4057
Jeff Garzikbf794512005-07-31 13:07:26 -04004058 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06004059 return 0;
4060
4061 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004062 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06004063 &len);
4064 if (err) {
4065 IPW_DEBUG_INFO("failed querying ordinals.\n");
4066 return 0;
4067 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004068 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06004069 return ipw_get_max_rate(priv);
4070
4071 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004072 case IPW_TX_RATE_1MB:
4073 return 1000000;
4074 case IPW_TX_RATE_2MB:
4075 return 2000000;
4076 case IPW_TX_RATE_5MB:
4077 return 5500000;
4078 case IPW_TX_RATE_6MB:
4079 return 6000000;
4080 case IPW_TX_RATE_9MB:
4081 return 9000000;
4082 case IPW_TX_RATE_11MB:
4083 return 11000000;
4084 case IPW_TX_RATE_12MB:
4085 return 12000000;
4086 case IPW_TX_RATE_18MB:
4087 return 18000000;
4088 case IPW_TX_RATE_24MB:
4089 return 24000000;
4090 case IPW_TX_RATE_36MB:
4091 return 36000000;
4092 case IPW_TX_RATE_48MB:
4093 return 48000000;
4094 case IPW_TX_RATE_54MB:
4095 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004096 }
4097
4098 return 0;
4099}
4100
James Ketrenos43f66a62005-03-25 12:31:53 -06004101#define IPW_STATS_INTERVAL (2 * HZ)
4102static void ipw_gather_stats(struct ipw_priv *priv)
4103{
4104 u32 rx_err, rx_err_delta, rx_packets_delta;
4105 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4106 u32 missed_beacons_percent, missed_beacons_delta;
4107 u32 quality = 0;
4108 u32 len = sizeof(u32);
4109 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004110 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004111 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004112 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06004113
4114 if (!(priv->status & STATUS_ASSOCIATED)) {
4115 priv->quality = 0;
4116 return;
4117 }
4118
4119 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04004120 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06004121 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004122 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06004123 priv->last_missed_beacons = priv->missed_beacons;
4124 if (priv->assoc_request.beacon_interval) {
4125 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004126 (HZ * priv->assoc_request.beacon_interval) /
4127 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004128 } else {
4129 missed_beacons_percent = 0;
4130 }
4131 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4132
4133 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4134 rx_err_delta = rx_err - priv->last_rx_err;
4135 priv->last_rx_err = rx_err;
4136
4137 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4138 tx_failures_delta = tx_failures - priv->last_tx_failures;
4139 priv->last_tx_failures = tx_failures;
4140
4141 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4142 priv->last_rx_packets = priv->rx_packets;
4143
4144 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4145 priv->last_tx_packets = priv->tx_packets;
4146
4147 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004148 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004149 * Missed beacon: 100% = 0, 0% = 70% missed
4150 * Rate: 60% = 1Mbs, 100% = Max
4151 * Rx and Tx errors represent a straight % of total Rx/Tx
4152 * RSSI: 100% = > -50, 0% = < -80
4153 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004154 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004155 * The lowest computed quality is used.
4156 *
4157 */
4158#define BEACON_THRESHOLD 5
4159 beacon_quality = 100 - missed_beacons_percent;
4160 if (beacon_quality < BEACON_THRESHOLD)
4161 beacon_quality = 0;
4162 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004163 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004164 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004165 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004166 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004167
James Ketrenos43f66a62005-03-25 12:31:53 -06004168 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004169 max_rate = ipw_get_max_rate(priv);
4170 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004171 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4172 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004173
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004174 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004175 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004176 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004177 else
4178 rx_quality = 100;
4179 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4180 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004181
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004182 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004183 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004184 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004185 else
4186 tx_quality = 100;
4187 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4188 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004189
Zhu Yi00d21de2006-04-13 17:19:02 +08004190 rssi = priv->exp_avg_rssi;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004191 signal_quality =
4192 (100 *
4193 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4194 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4195 (priv->ieee->perfect_rssi - rssi) *
4196 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4197 62 * (priv->ieee->perfect_rssi - rssi))) /
4198 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4199 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4200 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004201 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004202 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004203 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004204
Zhu Yi61fb9ed2006-04-13 17:19:55 +08004205 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004206 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004207
4208 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06004209 min(rate_quality,
4210 min(tx_quality, min(rx_quality, signal_quality))));
4211 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004212 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4213 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004214 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004215 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4216 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004217 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004218 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4219 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004220 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004221 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4222 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004223 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004224 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4225 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004226
4227 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004228
4229 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004230 IPW_STATS_INTERVAL);
4231}
4232
James Ketrenosc848d0a2005-08-24 21:56:24 -05004233static void ipw_bg_gather_stats(void *data)
4234{
4235 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08004236 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004237 ipw_gather_stats(data);
Zhu Yi46441512006-01-24 16:37:59 +08004238 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004239}
4240
Ben Cahille7582562005-10-06 15:34:41 -05004241/* Missed beacon behavior:
4242 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4243 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4244 * Above disassociate threshold, give up and stop scanning.
4245 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004246static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004247 int missed_count)
4248{
4249 priv->notif_missed_beacons = missed_count;
4250
James Ketrenosafbf30a2005-08-25 00:05:33 -05004251 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004252 priv->status & STATUS_ASSOCIATED) {
4253 /* If associated and we've hit the missed
4254 * beacon threshold, disassociate, turn
4255 * off roaming, and abort any active scans */
4256 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004257 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004258 "Missed beacon: %d - disassociate\n", missed_count);
4259 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004260 if (priv->status & STATUS_SCANNING) {
4261 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4262 IPW_DL_STATE,
4263 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004264 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004265 }
4266
James Ketrenosea2b26e2005-08-24 21:25:16 -05004267 queue_work(priv->workqueue, &priv->disassociate);
4268 return;
4269 }
4270
4271 if (priv->status & STATUS_ROAMING) {
4272 /* If we are currently roaming, then just
4273 * print a debug statement... */
4274 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4275 "Missed beacon: %d - roam in progress\n",
4276 missed_count);
4277 return;
4278 }
4279
Zhu Yi4bfdb912006-01-24 16:37:16 +08004280 if (roaming &&
4281 (missed_count > priv->roaming_threshold &&
4282 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004283 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004284 * bit in the status and kick off a scan.
4285 * This can happen several times before we reach
4286 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004287 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4288 "Missed beacon: %d - initiate "
4289 "roaming\n", missed_count);
4290 if (!(priv->status & STATUS_ROAMING)) {
4291 priv->status |= STATUS_ROAMING;
4292 if (!(priv->status & STATUS_SCANNING))
4293 queue_work(priv->workqueue,
4294 &priv->request_scan);
4295 }
4296 return;
4297 }
4298
4299 if (priv->status & STATUS_SCANNING) {
4300 /* Stop scan to keep fw from getting
4301 * stuck (only if we aren't roaming --
4302 * otherwise we'll never scan more than 2 or 3
4303 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004304 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4305 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004306 queue_work(priv->workqueue, &priv->abort_scan);
4307 }
4308
4309 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004310}
4311
James Ketrenos43f66a62005-03-25 12:31:53 -06004312/**
4313 * Handle host notification packet.
4314 * Called from interrupt routine
4315 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004316static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004317 struct ipw_rx_notification *notif)
4318{
James Ketrenosa613bff2005-08-24 21:43:11 -05004319 notif->size = le16_to_cpu(notif->size);
4320
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004321 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004322
James Ketrenos43f66a62005-03-25 12:31:53 -06004323 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004324 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4325 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004326
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004327 switch (assoc->state) {
4328 case CMAS_ASSOCIATED:{
4329 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4330 IPW_DL_ASSOC,
4331 "associated: '%s' " MAC_FMT
4332 " \n",
4333 escape_essid(priv->essid,
4334 priv->essid_len),
4335 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04004336
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004337 switch (priv->ieee->iw_mode) {
4338 case IW_MODE_INFRA:
4339 memcpy(priv->ieee->bssid,
4340 priv->bssid, ETH_ALEN);
4341 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004342
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004343 case IW_MODE_ADHOC:
4344 memcpy(priv->ieee->bssid,
4345 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004346
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004347 /* clear out the station table */
4348 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004349
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004350 IPW_DEBUG_ASSOC
4351 ("queueing adhoc check\n");
4352 queue_delayed_work(priv->
4353 workqueue,
4354 &priv->
4355 adhoc_check,
4356 priv->
4357 assoc_request.
4358 beacon_interval);
4359 break;
4360 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004361
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004362 priv->status &= ~STATUS_ASSOCIATING;
4363 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004364 queue_work(priv->workqueue,
4365 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004366
Zhu Yie43e3c12006-04-13 17:20:45 +08004367#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004368#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4369 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4370 if ((priv->status & STATUS_AUTH) &&
4371 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4372 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004373 if ((sizeof
4374 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004375 ieee80211_assoc_response)
James Ketrenosb095c382005-08-24 22:04:42 -05004376 <= notif->size)
4377 && (notif->size <= 2314)) {
4378 struct
4379 ieee80211_rx_stats
4380 stats = {
4381 .len =
4382 notif->
4383 size - 1,
4384 };
4385
4386 IPW_DEBUG_QOS
4387 ("QoS Associate "
4388 "size %d\n",
4389 notif->size);
4390 ieee80211_rx_mgt(priv->
4391 ieee,
4392 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004393 ieee80211_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004394 *)
4395 &notif->u.raw, &stats);
4396 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004397 }
James Ketrenosb095c382005-08-24 22:04:42 -05004398#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004399
James Ketrenosa613bff2005-08-24 21:43:11 -05004400 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004401
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004402 break;
4403 }
4404
4405 case CMAS_AUTHENTICATED:{
4406 if (priv->
4407 status & (STATUS_ASSOCIATED |
4408 STATUS_AUTH)) {
Brice Goglin0f52bf92005-12-01 01:41:46 -08004409#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004410 struct notif_authenticate *auth
4411 = &notif->u.auth;
4412 IPW_DEBUG(IPW_DL_NOTIF |
4413 IPW_DL_STATE |
4414 IPW_DL_ASSOC,
4415 "deauthenticated: '%s' "
4416 MAC_FMT
4417 ": (0x%04X) - %s \n",
4418 escape_essid(priv->
4419 essid,
4420 priv->
4421 essid_len),
4422 MAC_ARG(priv->bssid),
4423 ntohs(auth->status),
4424 ipw_get_status_code
4425 (ntohs
4426 (auth->status)));
4427#endif
4428
4429 priv->status &=
4430 ~(STATUS_ASSOCIATING |
4431 STATUS_AUTH |
4432 STATUS_ASSOCIATED);
4433
James Ketrenosa613bff2005-08-24 21:43:11 -05004434 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004435 break;
4436 }
4437
4438 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4439 IPW_DL_ASSOC,
4440 "authenticated: '%s' " MAC_FMT
4441 "\n",
4442 escape_essid(priv->essid,
4443 priv->essid_len),
4444 MAC_ARG(priv->bssid));
4445 break;
4446 }
4447
4448 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004449 if (priv->status & STATUS_AUTH) {
4450 struct
4451 ieee80211_assoc_response
4452 *resp;
4453 resp =
4454 (struct
4455 ieee80211_assoc_response
4456 *)&notif->u.raw;
4457 IPW_DEBUG(IPW_DL_NOTIF |
4458 IPW_DL_STATE |
4459 IPW_DL_ASSOC,
4460 "association failed (0x%04X): %s\n",
4461 ntohs(resp->status),
4462 ipw_get_status_code
4463 (ntohs
4464 (resp->status)));
4465 }
4466
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004467 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4468 IPW_DL_ASSOC,
4469 "disassociated: '%s' " MAC_FMT
4470 " \n",
4471 escape_essid(priv->essid,
4472 priv->essid_len),
4473 MAC_ARG(priv->bssid));
4474
4475 priv->status &=
4476 ~(STATUS_DISASSOCIATING |
4477 STATUS_ASSOCIATING |
4478 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004479 if (priv->assoc_network
4480 && (priv->assoc_network->
4481 capability &
4482 WLAN_CAPABILITY_IBSS))
4483 ipw_remove_current_network
4484 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004485
James Ketrenosa613bff2005-08-24 21:43:11 -05004486 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004487
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004488 break;
4489 }
4490
James Ketrenosb095c382005-08-24 22:04:42 -05004491 case CMAS_RX_ASSOC_RESP:
4492 break;
4493
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004494 default:
4495 IPW_ERROR("assoc: unknown (%d)\n",
4496 assoc->state);
4497 break;
4498 }
4499
James Ketrenos43f66a62005-03-25 12:31:53 -06004500 break;
4501 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004502
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004503 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4504 struct notif_authenticate *auth = &notif->u.auth;
4505 switch (auth->state) {
4506 case CMAS_AUTHENTICATED:
4507 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4508 "authenticated: '%s' " MAC_FMT " \n",
4509 escape_essid(priv->essid,
4510 priv->essid_len),
4511 MAC_ARG(priv->bssid));
4512 priv->status |= STATUS_AUTH;
4513 break;
4514
4515 case CMAS_INIT:
4516 if (priv->status & STATUS_AUTH) {
4517 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4518 IPW_DL_ASSOC,
4519 "authentication failed (0x%04X): %s\n",
4520 ntohs(auth->status),
4521 ipw_get_status_code(ntohs
4522 (auth->
4523 status)));
4524 }
4525 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4526 IPW_DL_ASSOC,
4527 "deauthenticated: '%s' " MAC_FMT "\n",
4528 escape_essid(priv->essid,
4529 priv->essid_len),
4530 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004531
4532 priv->status &= ~(STATUS_ASSOCIATING |
4533 STATUS_AUTH |
4534 STATUS_ASSOCIATED);
4535
James Ketrenosa613bff2005-08-24 21:43:11 -05004536 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004537 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004538
4539 case CMAS_TX_AUTH_SEQ_1:
4540 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4541 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4542 break;
4543 case CMAS_RX_AUTH_SEQ_2:
4544 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4545 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4546 break;
4547 case CMAS_AUTH_SEQ_1_PASS:
4548 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4549 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4550 break;
4551 case CMAS_AUTH_SEQ_1_FAIL:
4552 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4553 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4554 break;
4555 case CMAS_TX_AUTH_SEQ_3:
4556 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4557 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4558 break;
4559 case CMAS_RX_AUTH_SEQ_4:
4560 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4561 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4562 break;
4563 case CMAS_AUTH_SEQ_2_PASS:
4564 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4565 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4566 break;
4567 case CMAS_AUTH_SEQ_2_FAIL:
4568 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4569 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4570 break;
4571 case CMAS_TX_ASSOC:
4572 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4573 IPW_DL_ASSOC, "TX_ASSOC\n");
4574 break;
4575 case CMAS_RX_ASSOC_RESP:
4576 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4577 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004578
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004579 break;
4580 case CMAS_ASSOCIATED:
4581 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4582 IPW_DL_ASSOC, "ASSOCIATED\n");
4583 break;
4584 default:
4585 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4586 auth->state);
4587 break;
4588 }
4589 break;
4590 }
4591
4592 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4593 struct notif_channel_result *x =
4594 &notif->u.channel_result;
4595
4596 if (notif->size == sizeof(*x)) {
4597 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4598 x->channel_num);
4599 } else {
4600 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4601 "(should be %zd)\n",
4602 notif->size, sizeof(*x));
4603 }
4604 break;
4605 }
4606
4607 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4608 struct notif_scan_complete *x = &notif->u.scan_complete;
4609 if (notif->size == sizeof(*x)) {
4610 IPW_DEBUG_SCAN
4611 ("Scan completed: type %d, %d channels, "
4612 "%d status\n", x->scan_type,
4613 x->num_channels, x->status);
4614 } else {
4615 IPW_ERROR("Scan completed of wrong size %d "
4616 "(should be %zd)\n",
4617 notif->size, sizeof(*x));
4618 }
4619
4620 priv->status &=
4621 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4622
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004623 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004624 cancel_delayed_work(&priv->scan_check);
4625
James Ketrenosb095c382005-08-24 22:04:42 -05004626 if (priv->status & STATUS_EXIT_PENDING)
4627 break;
4628
4629 priv->ieee->scans++;
4630
4631#ifdef CONFIG_IPW2200_MONITOR
4632 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004633 priv->status |= STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004634 queue_work(priv->workqueue,
4635 &priv->request_scan);
4636 break;
4637 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004638 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004639#endif /* CONFIG_IPW2200_MONITOR */
4640
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004641 if (!(priv->status & (STATUS_ASSOCIATED |
4642 STATUS_ASSOCIATING |
4643 STATUS_ROAMING |
4644 STATUS_DISASSOCIATING)))
4645 queue_work(priv->workqueue, &priv->associate);
4646 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004647 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4648 /* If a scan completed and we are in roam mode, then
4649 * the scan that completed was the one requested as a
4650 * result of entering roam... so, schedule the
4651 * roam work */
4652 queue_work(priv->workqueue,
4653 &priv->roam);
4654 else
4655 /* Don't schedule if we aborted the scan */
4656 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004657 } else if (priv->status & STATUS_SCAN_PENDING)
4658 queue_work(priv->workqueue,
4659 &priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004660 else if (priv->config & CFG_BACKGROUND_SCAN
4661 && priv->status & STATUS_ASSOCIATED)
4662 queue_delayed_work(priv->workqueue,
4663 &priv->request_scan, HZ);
Zhu Yi07f02e42006-04-13 17:19:25 +08004664
4665 /* Send an empty event to user space.
4666 * We don't send the received data on the event because
4667 * it would require us to do complex transcoding, and
4668 * we want to minimise the work done in the irq handler
4669 * Use a request to extract the data.
4670 * Also, we generate this even for any scan, regardless
4671 * on how the scan was initiated. User space can just
4672 * sync on periodic scan to get fresh data...
4673 * Jean II */
4674 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) {
4675 union iwreq_data wrqu;
4676
4677 wrqu.data.length = 0;
4678 wrqu.data.flags = 0;
4679 wireless_send_event(priv->net_dev, SIOCGIWSCAN,
4680 &wrqu, NULL);
4681 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004682 break;
4683 }
4684
4685 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4686 struct notif_frag_length *x = &notif->u.frag_len;
4687
James Ketrenosa613bff2005-08-24 21:43:11 -05004688 if (notif->size == sizeof(*x))
4689 IPW_ERROR("Frag length: %d\n",
4690 le16_to_cpu(x->frag_length));
4691 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004692 IPW_ERROR("Frag length of wrong size %d "
4693 "(should be %zd)\n",
4694 notif->size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004695 break;
4696 }
4697
4698 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4699 struct notif_link_deterioration *x =
4700 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004701
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004702 if (notif->size == sizeof(*x)) {
4703 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Cahill, Ben M12977152006-03-08 02:58:02 +08004704 "link deterioration: type %d, cnt %d\n",
4705 x->silence_notification_type,
4706 x->silence_count);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004707 memcpy(&priv->last_link_deterioration, x,
4708 sizeof(*x));
4709 } else {
4710 IPW_ERROR("Link Deterioration of wrong size %d "
4711 "(should be %zd)\n",
4712 notif->size, sizeof(*x));
4713 }
4714 break;
4715 }
4716
4717 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4718 IPW_ERROR("Dino config\n");
4719 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004720 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004721 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004722
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004723 break;
4724 }
4725
4726 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4727 struct notif_beacon_state *x = &notif->u.beacon_state;
4728 if (notif->size != sizeof(*x)) {
4729 IPW_ERROR
4730 ("Beacon state of wrong size %d (should "
4731 "be %zd)\n", notif->size, sizeof(*x));
4732 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004733 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004734
James Ketrenosa613bff2005-08-24 21:43:11 -05004735 if (le32_to_cpu(x->state) ==
4736 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4737 ipw_handle_missed_beacon(priv,
4738 le32_to_cpu(x->
4739 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004740
James Ketrenos43f66a62005-03-25 12:31:53 -06004741 break;
4742 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004743
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004744 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4745 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
4746 if (notif->size == sizeof(*x)) {
4747 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4748 "0x%02x station %d\n",
4749 x->key_state, x->security_type,
4750 x->station_index);
4751 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004752 }
4753
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004754 IPW_ERROR
4755 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4756 notif->size, sizeof(*x));
4757 break;
4758 }
4759
4760 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4761 struct notif_calibration *x = &notif->u.calibration;
4762
4763 if (notif->size == sizeof(*x)) {
4764 memcpy(&priv->calib, x, sizeof(*x));
4765 IPW_DEBUG_INFO("TODO: Calibration\n");
4766 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004767 }
4768
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004769 IPW_ERROR
4770 ("Calibration of wrong size %d (should be %zd)\n",
4771 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004772 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004773 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004774
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004775 case HOST_NOTIFICATION_NOISE_STATS:{
4776 if (notif->size == sizeof(u32)) {
Zhu Yi00d21de2006-04-13 17:19:02 +08004777 priv->exp_avg_noise =
4778 exponential_average(priv->exp_avg_noise,
4779 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4780 DEPTH_NOISE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004781 break;
4782 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004783
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004784 IPW_ERROR
4785 ("Noise stat is wrong size %d (should be %zd)\n",
4786 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004787 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004788 }
4789
James Ketrenos43f66a62005-03-25 12:31:53 -06004790 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004791 IPW_DEBUG_NOTIF("Unknown notification: "
4792 "subtype=%d,flags=0x%2x,size=%d\n",
4793 notif->subtype, notif->flags, notif->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004794 }
4795}
4796
4797/**
4798 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004799 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004800 * @param priv
4801 * @return error code
4802 */
4803static int ipw_queue_reset(struct ipw_priv *priv)
4804{
4805 int rc = 0;
4806 /** @todo customize queue sizes */
4807 int nTx = 64, nTxCmd = 8;
4808 ipw_tx_queue_free(priv);
4809 /* Tx CMD queue */
4810 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004811 IPW_TX_CMD_QUEUE_READ_INDEX,
4812 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4813 IPW_TX_CMD_QUEUE_BD_BASE,
4814 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004815 if (rc) {
4816 IPW_ERROR("Tx Cmd queue init failed\n");
4817 goto error;
4818 }
4819 /* Tx queue(s) */
4820 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004821 IPW_TX_QUEUE_0_READ_INDEX,
4822 IPW_TX_QUEUE_0_WRITE_INDEX,
4823 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004824 if (rc) {
4825 IPW_ERROR("Tx 0 queue init failed\n");
4826 goto error;
4827 }
4828 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004829 IPW_TX_QUEUE_1_READ_INDEX,
4830 IPW_TX_QUEUE_1_WRITE_INDEX,
4831 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004832 if (rc) {
4833 IPW_ERROR("Tx 1 queue init failed\n");
4834 goto error;
4835 }
4836 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004837 IPW_TX_QUEUE_2_READ_INDEX,
4838 IPW_TX_QUEUE_2_WRITE_INDEX,
4839 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004840 if (rc) {
4841 IPW_ERROR("Tx 2 queue init failed\n");
4842 goto error;
4843 }
4844 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004845 IPW_TX_QUEUE_3_READ_INDEX,
4846 IPW_TX_QUEUE_3_WRITE_INDEX,
4847 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004848 if (rc) {
4849 IPW_ERROR("Tx 3 queue init failed\n");
4850 goto error;
4851 }
4852 /* statistics */
4853 priv->rx_bufs_min = 0;
4854 priv->rx_pend_max = 0;
4855 return rc;
4856
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004857 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004858 ipw_tx_queue_free(priv);
4859 return rc;
4860}
4861
4862/**
4863 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004864 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004865 * When FW adwances 'R' index, all entries between old and
4866 * new 'R' index need to be reclaimed. As result, some free space
4867 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004868 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004869 * @note Need to protect against garbage in 'R' index
4870 * @param priv
4871 * @param txq
4872 * @param qindex
4873 * @return Number of used entries remains in the queue
4874 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004875static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004876 struct clx2_tx_queue *txq, int qindex)
4877{
4878 u32 hw_tail;
4879 int used;
4880 struct clx2_queue *q = &txq->q;
4881
4882 hw_tail = ipw_read32(priv, q->reg_r);
4883 if (hw_tail >= q->n_bd) {
4884 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004885 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4886 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004887 goto done;
4888 }
4889 for (; q->last_used != hw_tail;
4890 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4891 ipw_queue_tx_free_tfd(priv, txq);
4892 priv->tx_packets++;
4893 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004894 done:
James Ketrenos9ddf84f2005-08-16 17:07:11 -05004895 if ((ipw_queue_space(q) > q->low_mark) &&
4896 (qindex >= 0) &&
4897 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4898 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06004899 used = q->first_empty - q->last_used;
4900 if (used < 0)
4901 used += q->n_bd;
4902
4903 return used;
4904}
4905
4906static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4907 int len, int sync)
4908{
4909 struct clx2_tx_queue *txq = &priv->txq_cmd;
4910 struct clx2_queue *q = &txq->q;
4911 struct tfd_frame *tfd;
4912
4913 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4914 IPW_ERROR("No space for Tx\n");
4915 return -EBUSY;
4916 }
4917
4918 tfd = &txq->bd[q->first_empty];
4919 txq->txb[q->first_empty] = NULL;
4920
4921 memset(tfd, 0, sizeof(*tfd));
4922 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4923 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4924 priv->hcmd_seq++;
4925 tfd->u.cmd.index = hcmd;
4926 tfd->u.cmd.length = len;
4927 memcpy(tfd->u.cmd.payload, buf, len);
4928 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4929 ipw_write32(priv, q->reg_w, q->first_empty);
4930 _ipw_read32(priv, 0x90);
4931
4932 return 0;
4933}
4934
Jeff Garzikbf794512005-07-31 13:07:26 -04004935/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004936 * Rx theory of operation
4937 *
4938 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05004939 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06004940 * 0 to 31
4941 *
4942 * Rx Queue Indexes
4943 * The host/firmware share two index registers for managing the Rx buffers.
4944 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004945 * The READ index maps to the first position that the firmware may be writing
4946 * to -- the driver can read up to (but not including) this position and get
4947 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06004948 * The READ index is managed by the firmware once the card is enabled.
4949 *
4950 * The WRITE index maps to the last position the driver has read from -- the
4951 * position preceding WRITE is the last slot the firmware can place a packet.
4952 *
4953 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04004954 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06004955 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004956 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06004957 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4958 *
4959 * When the firmware places a packet in a buffer it will advance the READ index
4960 * and fire the RX interrupt. The driver can then query the READ index and
4961 * process as many packets as possible, moving the WRITE index forward as it
4962 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04004963 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004964 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004965 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06004966 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04004967 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06004968 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4969 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4970 * 'processed' and 'read' driver indexes as well)
4971 * + A received packet is processed and handed to the kernel network stack,
4972 * detached from the ipw->rxq. The driver 'processed' index is updated.
4973 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04004974 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4975 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06004976 * were enough free buffers and RX_STALLED is set it is cleared.
4977 *
4978 *
4979 * Driver sequence:
4980 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004981 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06004982 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4983 * ipw_rx_queue_restock
4984 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4985 * queue, updates firmware pointers, and updates
4986 * the WRITE index. If insufficient rx_free buffers
4987 * are available, schedules ipw_rx_queue_replenish
4988 *
4989 * -- enable interrupts --
4990 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04004991 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06004992 * Moves the packet buffer from queue to rx_used.
4993 * Calls ipw_rx_queue_restock to refill any empty
4994 * slots.
4995 * ...
4996 *
4997 */
4998
Jeff Garzikbf794512005-07-31 13:07:26 -04004999/*
James Ketrenos43f66a62005-03-25 12:31:53 -06005000 * If there are slots in the RX queue that need to be restocked,
5001 * and we have free pre-allocated buffers, fill the ranks as much
5002 * as we can pulling from rx_free.
5003 *
5004 * This moves the 'write' index forward to catch up with 'processed', and
5005 * also updates the memory address in the firmware to reference the new
5006 * target buffer.
5007 */
5008static void ipw_rx_queue_restock(struct ipw_priv *priv)
5009{
5010 struct ipw_rx_queue *rxq = priv->rxq;
5011 struct list_head *element;
5012 struct ipw_rx_mem_buffer *rxb;
5013 unsigned long flags;
5014 int write;
5015
5016 spin_lock_irqsave(&rxq->lock, flags);
5017 write = rxq->write;
5018 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
5019 element = rxq->rx_free.next;
5020 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5021 list_del(element);
5022
James Ketrenosb095c382005-08-24 22:04:42 -05005023 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06005024 rxb->dma_addr);
5025 rxq->queue[rxq->write] = rxb;
5026 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5027 rxq->free_count--;
5028 }
5029 spin_unlock_irqrestore(&rxq->lock, flags);
5030
Jeff Garzikbf794512005-07-31 13:07:26 -04005031 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06005032 * refill it */
5033 if (rxq->free_count <= RX_LOW_WATERMARK)
5034 queue_work(priv->workqueue, &priv->rx_replenish);
5035
5036 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04005037 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05005038 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06005039}
5040
5041/*
5042 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04005043 * Also restock the Rx queue via ipw_rx_queue_restock.
5044 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005045 * This is called as a scheduled work item (except for during intialization)
5046 */
5047static void ipw_rx_queue_replenish(void *data)
5048{
5049 struct ipw_priv *priv = data;
5050 struct ipw_rx_queue *rxq = priv->rxq;
5051 struct list_head *element;
5052 struct ipw_rx_mem_buffer *rxb;
5053 unsigned long flags;
5054
5055 spin_lock_irqsave(&rxq->lock, flags);
5056 while (!list_empty(&rxq->rx_used)) {
5057 element = rxq->rx_used.next;
5058 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05005059 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06005060 if (!rxb->skb) {
5061 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5062 priv->net_dev->name);
5063 /* We don't reschedule replenish work here -- we will
5064 * call the restock method and if it still needs
5065 * more buffers it will schedule replenish */
5066 break;
5067 }
5068 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04005069
James Ketrenos43f66a62005-03-25 12:31:53 -06005070 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005071 rxb->dma_addr =
5072 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05005073 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04005074
James Ketrenos43f66a62005-03-25 12:31:53 -06005075 list_add_tail(&rxb->list, &rxq->rx_free);
5076 rxq->free_count++;
5077 }
5078 spin_unlock_irqrestore(&rxq->lock, flags);
5079
5080 ipw_rx_queue_restock(priv);
5081}
5082
James Ketrenosc848d0a2005-08-24 21:56:24 -05005083static void ipw_bg_rx_queue_replenish(void *data)
5084{
5085 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08005086 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005087 ipw_rx_queue_replenish(data);
Zhu Yi46441512006-01-24 16:37:59 +08005088 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005089}
5090
James Ketrenos43f66a62005-03-25 12:31:53 -06005091/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08005092 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04005093 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06005094 * non NULL it is unmapped and freed
5095 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005096static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06005097{
5098 int i;
5099
5100 if (!rxq)
5101 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005102
James Ketrenos43f66a62005-03-25 12:31:53 -06005103 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5104 if (rxq->pool[i].skb != NULL) {
5105 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05005106 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005107 dev_kfree_skb(rxq->pool[i].skb);
5108 }
5109 }
5110
5111 kfree(rxq);
5112}
5113
5114static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5115{
5116 struct ipw_rx_queue *rxq;
5117 int i;
5118
Takisc75f4742005-12-01 01:41:45 -08005119 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02005120 if (unlikely(!rxq)) {
5121 IPW_ERROR("memory allocation failed\n");
5122 return NULL;
5123 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005124 spin_lock_init(&rxq->lock);
5125 INIT_LIST_HEAD(&rxq->rx_free);
5126 INIT_LIST_HEAD(&rxq->rx_used);
5127
5128 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04005129 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06005130 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5131
5132 /* Set us so that we have processed and used all buffers, but have
5133 * not restocked the Rx queue with fresh buffers */
5134 rxq->read = rxq->write = 0;
5135 rxq->processed = RX_QUEUE_SIZE - 1;
5136 rxq->free_count = 0;
5137
5138 return rxq;
5139}
5140
5141static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5142{
5143 rate &= ~IEEE80211_BASIC_RATE_MASK;
5144 if (ieee_mode == IEEE_A) {
5145 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005146 case IEEE80211_OFDM_RATE_6MB:
5147 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005148 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005149 case IEEE80211_OFDM_RATE_9MB:
5150 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005151 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005152 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005153 return priv->
5154 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005155 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005156 return priv->
5157 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005158 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005159 return priv->
5160 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005161 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005162 return priv->
5163 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005164 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005165 return priv->
5166 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005167 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005168 return priv->
5169 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005170 default:
5171 return 0;
5172 }
5173 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005174
James Ketrenos43f66a62005-03-25 12:31:53 -06005175 /* B and G mixed */
5176 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005177 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005178 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005179 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005180 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005181 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005182 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005183 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005184 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
5185 }
5186
5187 /* If we are limited to B modulations, bail at this point */
5188 if (ieee_mode == IEEE_B)
5189 return 0;
5190
5191 /* G */
5192 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005193 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005194 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005195 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005196 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005197 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005198 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005199 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005200 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005201 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005202 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005203 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005204 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005205 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005206 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005207 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005208 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5209 }
5210
5211 return 0;
5212}
5213
Jeff Garzikbf794512005-07-31 13:07:26 -04005214static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005215 const struct ieee80211_network *network,
5216 struct ipw_supported_rates *rates)
5217{
5218 int num_rates, i;
5219
5220 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005221 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005222 rates->num_rates = 0;
5223 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005224 if (!ipw_is_rate_in_mask(priv, network->mode,
5225 network->rates[i])) {
5226
James Ketrenosea2b26e2005-08-24 21:25:16 -05005227 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005228 IPW_DEBUG_SCAN("Adding masked mandatory "
5229 "rate %02X\n",
5230 network->rates[i]);
5231 rates->supported_rates[rates->num_rates++] =
5232 network->rates[i];
5233 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005234 }
5235
James Ketrenos43f66a62005-03-25 12:31:53 -06005236 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5237 network->rates[i], priv->rates_mask);
5238 continue;
5239 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005240
James Ketrenos43f66a62005-03-25 12:31:53 -06005241 rates->supported_rates[rates->num_rates++] = network->rates[i];
5242 }
5243
James Ketrenosa613bff2005-08-24 21:43:11 -05005244 num_rates = min(network->rates_ex_len,
5245 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005246 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005247 if (!ipw_is_rate_in_mask(priv, network->mode,
5248 network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005249 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005250 IPW_DEBUG_SCAN("Adding masked mandatory "
5251 "rate %02X\n",
5252 network->rates_ex[i]);
5253 rates->supported_rates[rates->num_rates++] =
5254 network->rates[i];
5255 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005256 }
5257
James Ketrenos43f66a62005-03-25 12:31:53 -06005258 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5259 network->rates_ex[i], priv->rates_mask);
5260 continue;
5261 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005262
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005263 rates->supported_rates[rates->num_rates++] =
5264 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005265 }
5266
James Ketrenosea2b26e2005-08-24 21:25:16 -05005267 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005268}
5269
Arjan van de Ven858119e2006-01-14 13:20:43 -08005270static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005271 const struct ipw_supported_rates *src)
5272{
5273 u8 i;
5274 for (i = 0; i < src->num_rates; i++)
5275 dest->supported_rates[i] = src->supported_rates[i];
5276 dest->num_rates = src->num_rates;
5277}
5278
5279/* TODO: Look at sniffed packets in the air to determine if the basic rate
5280 * mask should ever be used -- right now all callers to add the scan rates are
5281 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5282static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005283 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005284{
Jeff Garzikbf794512005-07-31 13:07:26 -04005285 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005286 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005287
James Ketrenos43f66a62005-03-25 12:31:53 -06005288 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005289 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005290 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005291
5292 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005293 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005294 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005295
5296 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005297 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005298 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005299
5300 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005301 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005302 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005303}
5304
5305static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005306 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005307{
Jeff Garzikbf794512005-07-31 13:07:26 -04005308 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005309 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005310
5311 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005312 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005313 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005314
5315 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005316 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005317 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005318
5319 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005320 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005321 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005322
5323 if (rate_mask & IEEE80211_OFDM_RATE_18MB_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_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005326
5327 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005328 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005329 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005330
5331 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005332 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005333 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005334
5335 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005336 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005337 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005338
5339 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005340 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005341 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005342}
5343
5344struct ipw_network_match {
5345 struct ieee80211_network *network;
5346 struct ipw_supported_rates rates;
5347};
5348
James Ketrenosc848d0a2005-08-24 21:56:24 -05005349static int ipw_find_adhoc_network(struct ipw_priv *priv,
5350 struct ipw_network_match *match,
5351 struct ieee80211_network *network,
5352 int roaming)
5353{
5354 struct ipw_supported_rates rates;
5355
5356 /* Verify that this network's capability is compatible with the
5357 * current mode (AdHoc or Infrastructure) */
5358 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5359 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5360 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5361 "capability mismatch.\n",
5362 escape_essid(network->ssid, network->ssid_len),
5363 MAC_ARG(network->bssid));
5364 return 0;
5365 }
5366
5367 /* If we do not have an ESSID for this AP, we can not associate with
5368 * it */
5369 if (network->flags & NETWORK_EMPTY_ESSID) {
5370 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5371 "because of hidden ESSID.\n",
5372 escape_essid(network->ssid, network->ssid_len),
5373 MAC_ARG(network->bssid));
5374 return 0;
5375 }
5376
5377 if (unlikely(roaming)) {
5378 /* If we are roaming, then ensure check if this is a valid
5379 * network to try and roam to */
5380 if ((network->ssid_len != match->network->ssid_len) ||
5381 memcmp(network->ssid, match->network->ssid,
5382 network->ssid_len)) {
5383 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5384 "because of non-network ESSID.\n",
5385 escape_essid(network->ssid,
5386 network->ssid_len),
5387 MAC_ARG(network->bssid));
5388 return 0;
5389 }
5390 } else {
5391 /* If an ESSID has been configured then compare the broadcast
5392 * ESSID to ours */
5393 if ((priv->config & CFG_STATIC_ESSID) &&
5394 ((network->ssid_len != priv->essid_len) ||
5395 memcmp(network->ssid, priv->essid,
5396 min(network->ssid_len, priv->essid_len)))) {
5397 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005398
James Ketrenosc848d0a2005-08-24 21:56:24 -05005399 strncpy(escaped,
5400 escape_essid(network->ssid, network->ssid_len),
5401 sizeof(escaped));
5402 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5403 "because of ESSID mismatch: '%s'.\n",
5404 escaped, MAC_ARG(network->bssid),
5405 escape_essid(priv->essid,
5406 priv->essid_len));
5407 return 0;
5408 }
5409 }
5410
5411 /* If the old network rate is better than this one, don't bother
5412 * testing everything else. */
5413
5414 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005415 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5416 "current network.\n",
5417 escape_essid(match->network->ssid,
5418 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005419 return 0;
5420 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005421 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5422 "current network.\n",
5423 escape_essid(match->network->ssid,
5424 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005425 return 0;
5426 }
5427
5428 /* Now go through and see if the requested network is valid... */
5429 if (priv->ieee->scan_age != 0 &&
5430 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5431 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005432 "because of age: %ums.\n",
James Ketrenosc848d0a2005-08-24 21:56:24 -05005433 escape_essid(network->ssid, network->ssid_len),
5434 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005435 jiffies_to_msecs(jiffies -
5436 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005437 return 0;
5438 }
5439
5440 if ((priv->config & CFG_STATIC_CHANNEL) &&
5441 (network->channel != priv->channel)) {
5442 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5443 "because of channel mismatch: %d != %d.\n",
5444 escape_essid(network->ssid, network->ssid_len),
5445 MAC_ARG(network->bssid),
5446 network->channel, priv->channel);
5447 return 0;
5448 }
5449
5450 /* Verify privacy compatability */
5451 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5452 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5453 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5454 "because of privacy mismatch: %s != %s.\n",
5455 escape_essid(network->ssid, network->ssid_len),
5456 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005457 priv->
5458 capability & CAP_PRIVACY_ON ? "on" : "off",
5459 network->
5460 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5461 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005462 return 0;
5463 }
5464
5465 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5466 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5467 "because of the same BSSID match: " MAC_FMT
5468 ".\n", escape_essid(network->ssid,
5469 network->ssid_len),
5470 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5471 return 0;
5472 }
5473
5474 /* Filter out any incompatible freq / mode combinations */
5475 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5476 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5477 "because of invalid frequency/mode "
5478 "combination.\n",
5479 escape_essid(network->ssid, network->ssid_len),
5480 MAC_ARG(network->bssid));
5481 return 0;
5482 }
5483
5484 /* Ensure that the rates supported by the driver are compatible with
5485 * this AP, including verification of basic rates (mandatory) */
5486 if (!ipw_compatible_rates(priv, network, &rates)) {
5487 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5488 "because configured rate mask excludes "
5489 "AP mandatory rate.\n",
5490 escape_essid(network->ssid, network->ssid_len),
5491 MAC_ARG(network->bssid));
5492 return 0;
5493 }
5494
5495 if (rates.num_rates == 0) {
5496 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5497 "because of no compatible rates.\n",
5498 escape_essid(network->ssid, network->ssid_len),
5499 MAC_ARG(network->bssid));
5500 return 0;
5501 }
5502
5503 /* TODO: Perform any further minimal comparititive tests. We do not
5504 * want to put too much policy logic here; intelligent scan selection
5505 * should occur within a generic IEEE 802.11 user space tool. */
5506
5507 /* Set up 'new' AP to this network */
5508 ipw_copy_rates(&match->rates, &rates);
5509 match->network = network;
5510 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5511 escape_essid(network->ssid, network->ssid_len),
5512 MAC_ARG(network->bssid));
5513
5514 return 1;
5515}
5516
5517static void ipw_merge_adhoc_network(void *data)
5518{
5519 struct ipw_priv *priv = data;
5520 struct ieee80211_network *network = NULL;
5521 struct ipw_network_match match = {
5522 .network = priv->assoc_network
5523 };
5524
James Ketrenosafbf30a2005-08-25 00:05:33 -05005525 if ((priv->status & STATUS_ASSOCIATED) &&
5526 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005527 /* First pass through ROAM process -- look for a better
5528 * network */
5529 unsigned long flags;
5530
5531 spin_lock_irqsave(&priv->ieee->lock, flags);
5532 list_for_each_entry(network, &priv->ieee->network_list, list) {
5533 if (network != priv->assoc_network)
5534 ipw_find_adhoc_network(priv, &match, network,
5535 1);
5536 }
5537 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5538
5539 if (match.network == priv->assoc_network) {
5540 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5541 "merge to.\n");
5542 return;
5543 }
5544
Zhu Yi46441512006-01-24 16:37:59 +08005545 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005546 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5547 IPW_DEBUG_MERGE("remove network %s\n",
5548 escape_essid(priv->essid,
5549 priv->essid_len));
5550 ipw_remove_current_network(priv);
5551 }
5552
5553 ipw_disassociate(priv);
5554 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005555 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005556 return;
5557 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005558}
5559
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005560static int ipw_best_network(struct ipw_priv *priv,
5561 struct ipw_network_match *match,
5562 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005563{
5564 struct ipw_supported_rates rates;
5565
5566 /* Verify that this network's capability is compatible with the
5567 * current mode (AdHoc or Infrastructure) */
5568 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005569 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005570 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5571 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5572 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005573 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005574 escape_essid(network->ssid, network->ssid_len),
5575 MAC_ARG(network->bssid));
5576 return 0;
5577 }
5578
5579 /* If we do not have an ESSID for this AP, we can not associate with
5580 * it */
5581 if (network->flags & NETWORK_EMPTY_ESSID) {
5582 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5583 "because of hidden ESSID.\n",
5584 escape_essid(network->ssid, network->ssid_len),
5585 MAC_ARG(network->bssid));
5586 return 0;
5587 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005588
James Ketrenos43f66a62005-03-25 12:31:53 -06005589 if (unlikely(roaming)) {
5590 /* If we are roaming, then ensure check if this is a valid
5591 * network to try and roam to */
5592 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005593 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005594 network->ssid_len)) {
5595 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5596 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04005597 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005598 network->ssid_len),
5599 MAC_ARG(network->bssid));
5600 return 0;
5601 }
5602 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005603 /* If an ESSID has been configured then compare the broadcast
5604 * ESSID to ours */
5605 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005606 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005607 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005608 min(network->ssid_len, priv->essid_len)))) {
5609 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005610 strncpy(escaped,
5611 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005612 sizeof(escaped));
5613 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005614 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005615 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005616 escape_essid(priv->essid,
5617 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005618 return 0;
5619 }
5620 }
5621
5622 /* If the old network rate is better than this one, don't bother
5623 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005624 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005625 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005626 strncpy(escaped,
5627 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005628 sizeof(escaped));
5629 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5630 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5631 escaped, MAC_ARG(network->bssid),
5632 escape_essid(match->network->ssid,
5633 match->network->ssid_len),
5634 MAC_ARG(match->network->bssid));
5635 return 0;
5636 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005637
James Ketrenos43f66a62005-03-25 12:31:53 -06005638 /* If this network has already had an association attempt within the
5639 * last 3 seconds, do not try and associate again... */
5640 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005641 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005642 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005643 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005644 "assoc attempt).\n",
5645 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_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005649 return 0;
5650 }
5651
5652 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005653 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005654 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005655 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005656 "because of age: %ums.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005657 escape_essid(network->ssid, network->ssid_len),
5658 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005659 jiffies_to_msecs(jiffies -
5660 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005661 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005662 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005663
Jeff Garzikbf794512005-07-31 13:07:26 -04005664 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005665 (network->channel != priv->channel)) {
5666 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5667 "because of channel mismatch: %d != %d.\n",
5668 escape_essid(network->ssid, network->ssid_len),
5669 MAC_ARG(network->bssid),
5670 network->channel, priv->channel);
5671 return 0;
5672 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005673
James Ketrenos43f66a62005-03-25 12:31:53 -06005674 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005675 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005676 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5677 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5678 "because of privacy mismatch: %s != %s.\n",
5679 escape_essid(network->ssid, network->ssid_len),
5680 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04005681 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005682 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005683 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005684 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005685 return 0;
5686 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005687
5688 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005689 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5690 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5691 "because of BSSID mismatch: " MAC_FMT ".\n",
5692 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005693 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005694 return 0;
5695 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005696
James Ketrenos43f66a62005-03-25 12:31:53 -06005697 /* Filter out any incompatible freq / mode combinations */
5698 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5699 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5700 "because of invalid frequency/mode "
5701 "combination.\n",
5702 escape_essid(network->ssid, network->ssid_len),
5703 MAC_ARG(network->bssid));
5704 return 0;
5705 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005706
Liu Hong1fe0adb2005-08-19 09:33:10 -05005707 /* Filter out invalid channel in current GEO */
Larry Finger1867b112006-02-28 09:48:28 -06005708 if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005709 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5710 "because of invalid channel in current GEO\n",
5711 escape_essid(network->ssid, network->ssid_len),
5712 MAC_ARG(network->bssid));
5713 return 0;
5714 }
5715
James Ketrenosea2b26e2005-08-24 21:25:16 -05005716 /* Ensure that the rates supported by the driver are compatible with
5717 * this AP, including verification of basic rates (mandatory) */
5718 if (!ipw_compatible_rates(priv, network, &rates)) {
5719 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5720 "because configured rate mask excludes "
5721 "AP mandatory rate.\n",
5722 escape_essid(network->ssid, network->ssid_len),
5723 MAC_ARG(network->bssid));
5724 return 0;
5725 }
5726
James Ketrenos43f66a62005-03-25 12:31:53 -06005727 if (rates.num_rates == 0) {
5728 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5729 "because of no compatible rates.\n",
5730 escape_essid(network->ssid, network->ssid_len),
5731 MAC_ARG(network->bssid));
5732 return 0;
5733 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005734
James Ketrenos43f66a62005-03-25 12:31:53 -06005735 /* TODO: Perform any further minimal comparititive tests. We do not
5736 * want to put too much policy logic here; intelligent scan selection
5737 * should occur within a generic IEEE 802.11 user space tool. */
5738
5739 /* Set up 'new' AP to this network */
5740 ipw_copy_rates(&match->rates, &rates);
5741 match->network = network;
5742
5743 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5744 escape_essid(network->ssid, network->ssid_len),
5745 MAC_ARG(network->bssid));
5746
5747 return 1;
5748}
5749
Jeff Garzikbf794512005-07-31 13:07:26 -04005750static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005751 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005752{
Larry Finger1867b112006-02-28 09:48:28 -06005753 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005754 int i;
5755
James Ketrenos43f66a62005-03-25 12:31:53 -06005756 /*
5757 * For the purposes of scanning, we can set our wireless mode
5758 * to trigger scans across combinations of bands, but when it
5759 * comes to creating a new ad-hoc network, we have tell the FW
5760 * exactly which band to use.
5761 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005762 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005763 * chossen band. Attempting to create a new ad-hoc network
5764 * with an invalid channel for wireless mode will trigger a
5765 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005766 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005767 */
Larry Finger1867b112006-02-28 09:48:28 -06005768 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005769 case IEEE80211_52GHZ_BAND:
5770 network->mode = IEEE_A;
Larry Finger1867b112006-02-28 09:48:28 -06005771 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005772 BUG_ON(i == -1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005773 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5774 IPW_WARNING("Overriding invalid channel\n");
5775 priv->channel = geo->a[0].channel;
5776 }
5777 break;
5778
5779 case IEEE80211_24GHZ_BAND:
5780 if (priv->ieee->mode & IEEE_G)
5781 network->mode = IEEE_G;
5782 else
5783 network->mode = IEEE_B;
Larry Finger1867b112006-02-28 09:48:28 -06005784 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005785 BUG_ON(i == -1);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005786 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5787 IPW_WARNING("Overriding invalid channel\n");
5788 priv->channel = geo->bg[0].channel;
5789 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005790 break;
5791
5792 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005793 IPW_WARNING("Overriding invalid channel\n");
5794 if (priv->ieee->mode & IEEE_A) {
5795 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005796 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005797 } else if (priv->ieee->mode & IEEE_G) {
5798 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005799 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005800 } else {
5801 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005802 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005803 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005804 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005805 }
5806
5807 network->channel = priv->channel;
5808 priv->config |= CFG_ADHOC_PERSIST;
5809 ipw_create_bssid(priv, network->bssid);
5810 network->ssid_len = priv->essid_len;
5811 memcpy(network->ssid, priv->essid, priv->essid_len);
5812 memset(&network->stats, 0, sizeof(network->stats));
5813 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005814 if (!(priv->config & CFG_PREAMBLE_LONG))
5815 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005816 if (priv->capability & CAP_PRIVACY_ON)
5817 network->capability |= WLAN_CAPABILITY_PRIVACY;
5818 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005819 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005820 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005821 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005822 &priv->rates.supported_rates[network->rates_len],
5823 network->rates_ex_len);
5824 network->last_scanned = 0;
5825 network->flags = 0;
5826 network->last_associate = 0;
5827 network->time_stamp[0] = 0;
5828 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005829 network->beacon_interval = 100; /* Default */
5830 network->listen_interval = 10; /* Default */
5831 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005832 network->wpa_ie_len = 0;
5833 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005834}
5835
James Ketrenosb095c382005-08-24 22:04:42 -05005836static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5837{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005838 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005839
5840 if (!(priv->ieee->sec.flags & (1 << index)))
5841 return;
5842
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005843 key.key_id = index;
5844 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5845 key.security_type = type;
5846 key.station_index = 0; /* always 0 for BSS */
5847 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005848 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005849 key.tx_counter[0] = 0;
5850 key.tx_counter[1] = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005851
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005852 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05005853}
5854
5855static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005856{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005857 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06005858 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06005859
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005860 key.cmd_id = DINO_CMD_WEP_KEY;
5861 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005862
James Ketrenosb095c382005-08-24 22:04:42 -05005863 /* Note: AES keys cannot be set for multiple times.
5864 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005865 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005866 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05005867 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005868 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005869 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005870 }
5871
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005872 key.key_size = priv->ieee->sec.key_sizes[i];
5873 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05005874
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005875 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04005876 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005877}
5878
Zhu Yi1fbfea52005-08-05 17:22:56 +08005879static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5880{
5881 if (priv->ieee->host_encrypt)
5882 return;
5883
5884 switch (level) {
5885 case SEC_LEVEL_3:
5886 priv->sys_config.disable_unicast_decryption = 0;
5887 priv->ieee->host_decrypt = 0;
5888 break;
5889 case SEC_LEVEL_2:
5890 priv->sys_config.disable_unicast_decryption = 1;
5891 priv->ieee->host_decrypt = 1;
5892 break;
5893 case SEC_LEVEL_1:
5894 priv->sys_config.disable_unicast_decryption = 0;
5895 priv->ieee->host_decrypt = 0;
5896 break;
5897 case SEC_LEVEL_0:
5898 priv->sys_config.disable_unicast_decryption = 1;
5899 break;
5900 default:
5901 break;
5902 }
5903}
5904
5905static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5906{
5907 if (priv->ieee->host_encrypt)
5908 return;
5909
5910 switch (level) {
5911 case SEC_LEVEL_3:
5912 priv->sys_config.disable_multicast_decryption = 0;
5913 break;
5914 case SEC_LEVEL_2:
5915 priv->sys_config.disable_multicast_decryption = 1;
5916 break;
5917 case SEC_LEVEL_1:
5918 priv->sys_config.disable_multicast_decryption = 0;
5919 break;
5920 case SEC_LEVEL_0:
5921 priv->sys_config.disable_multicast_decryption = 1;
5922 break;
5923 default:
5924 break;
5925 }
5926}
5927
James Ketrenosb095c382005-08-24 22:04:42 -05005928static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5929{
5930 switch (priv->ieee->sec.level) {
5931 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005932 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5933 ipw_send_tgi_tx_key(priv,
5934 DCT_FLAG_EXT_SECURITY_CCM,
5935 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005936
Hong Liu567deaf2005-08-31 18:07:22 +08005937 if (!priv->ieee->host_mc_decrypt)
5938 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05005939 break;
5940 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005941 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5942 ipw_send_tgi_tx_key(priv,
5943 DCT_FLAG_EXT_SECURITY_TKIP,
5944 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05005945 break;
5946 case SEC_LEVEL_1:
5947 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05005948 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5949 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05005950 break;
5951 case SEC_LEVEL_0:
5952 default:
5953 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005954 }
5955}
5956
5957static void ipw_adhoc_check(void *data)
5958{
5959 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04005960
James Ketrenosafbf30a2005-08-25 00:05:33 -05005961 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005962 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005963 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5964 IPW_DL_STATE | IPW_DL_ASSOC,
5965 "Missed beacon: %d - disassociate\n",
5966 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06005967 ipw_remove_current_network(priv);
5968 ipw_disassociate(priv);
5969 return;
5970 }
5971
Jeff Garzikbf794512005-07-31 13:07:26 -04005972 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06005973 priv->assoc_request.beacon_interval);
5974}
5975
James Ketrenosc848d0a2005-08-24 21:56:24 -05005976static void ipw_bg_adhoc_check(void *data)
5977{
5978 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08005979 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005980 ipw_adhoc_check(data);
Zhu Yi46441512006-01-24 16:37:59 +08005981 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005982}
5983
Brice Goglin0f52bf92005-12-01 01:41:46 -08005984#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -06005985static void ipw_debug_config(struct ipw_priv *priv)
5986{
5987 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5988 "[CFG 0x%08X]\n", priv->config);
5989 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005990 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005991 else
5992 IPW_DEBUG_INFO("Channel unlocked.\n");
5993 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04005994 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005995 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005996 else
5997 IPW_DEBUG_INFO("ESSID unlocked.\n");
5998 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05005999 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
6000 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06006001 else
6002 IPW_DEBUG_INFO("BSSID unlocked.\n");
6003 if (priv->capability & CAP_PRIVACY_ON)
6004 IPW_DEBUG_INFO("PRIVACY on\n");
6005 else
6006 IPW_DEBUG_INFO("PRIVACY off\n");
6007 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
6008}
6009#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04006010#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06006011#endif
6012
Arjan van de Ven858119e2006-01-14 13:20:43 -08006013static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06006014{
6015 /* TODO: Verify that this works... */
6016 struct ipw_fixed_rate fr = {
6017 .tx_rates = priv->rates_mask
6018 };
6019 u32 reg;
6020 u16 mask = 0;
6021
Jeff Garzikbf794512005-07-31 13:07:26 -04006022 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06006023 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04006024
James Ketrenos43f66a62005-03-25 12:31:53 -06006025 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006026 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06006027 /* IEEE_A */
6028 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
6029 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006030 IPW_DEBUG_WX
6031 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06006032 fr.tx_rates = 0;
6033 break;
6034 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006035
James Ketrenos43f66a62005-03-25 12:31:53 -06006036 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
6037 break;
6038
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006039 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06006040 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05006041 if (mode == IEEE_B) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006042 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
6043 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006044 IPW_DEBUG_WX
6045 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06006046 fr.tx_rates = 0;
6047 }
6048 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006049 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006050
6051 /* IEEE_G */
6052 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
6053 IEEE80211_OFDM_RATES_MASK)) {
6054 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006055 IPW_DEBUG_WX
6056 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06006057 fr.tx_rates = 0;
6058 break;
6059 }
6060
6061 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
6062 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
6063 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
6064 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006065
James Ketrenos43f66a62005-03-25 12:31:53 -06006066 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
6067 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
6068 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
6069 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006070
James Ketrenos43f66a62005-03-25 12:31:53 -06006071 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
6072 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
6073 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
6074 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006075
James Ketrenos43f66a62005-03-25 12:31:53 -06006076 fr.tx_rates |= mask;
6077 break;
6078 }
6079
6080 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006081 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06006082}
6083
James Ketrenosea2b26e2005-08-24 21:25:16 -05006084static void ipw_abort_scan(struct ipw_priv *priv)
6085{
6086 int err;
6087
6088 if (priv->status & STATUS_SCAN_ABORTING) {
6089 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6090 return;
6091 }
6092 priv->status |= STATUS_SCAN_ABORTING;
6093
6094 err = ipw_send_scan_abort(priv);
6095 if (err)
6096 IPW_DEBUG_HC("Request to abort scan failed.\n");
6097}
6098
James Ketrenosafbf30a2005-08-25 00:05:33 -05006099static void ipw_add_scan_channels(struct ipw_priv *priv,
6100 struct ipw_scan_request_ext *scan,
6101 int scan_type)
6102{
6103 int channel_index = 0;
6104 const struct ieee80211_geo *geo;
6105 int i;
6106
Larry Finger1867b112006-02-28 09:48:28 -06006107 geo = ieee80211_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006108
6109 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
6110 int start = channel_index;
6111 for (i = 0; i < geo->a_channels; i++) {
6112 if ((priv->status & STATUS_ASSOCIATED) &&
6113 geo->a[i].channel == priv->channel)
6114 continue;
6115 channel_index++;
6116 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006117 ipw_set_scan_type(scan, channel_index,
6118 geo->a[i].
6119 flags & IEEE80211_CH_PASSIVE_ONLY ?
6120 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6121 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006122 }
6123
6124 if (start != channel_index) {
6125 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6126 (channel_index - start);
6127 channel_index++;
6128 }
6129 }
6130
6131 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
6132 int start = channel_index;
6133 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006134 int index;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006135 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
6136 /* nop out the list */
6137 [0] = 0
6138 };
6139
6140 u8 channel;
6141 while (channel_index < IPW_SCAN_CHANNELS) {
6142 channel =
6143 priv->speed_scan[priv->speed_scan_pos];
6144 if (channel == 0) {
6145 priv->speed_scan_pos = 0;
6146 channel = priv->speed_scan[0];
6147 }
6148 if ((priv->status & STATUS_ASSOCIATED) &&
6149 channel == priv->channel) {
6150 priv->speed_scan_pos++;
6151 continue;
6152 }
6153
6154 /* If this channel has already been
6155 * added in scan, break from loop
6156 * and this will be the first channel
6157 * in the next scan.
6158 */
6159 if (channels[channel - 1] != 0)
6160 break;
6161
6162 channels[channel - 1] = 1;
6163 priv->speed_scan_pos++;
6164 channel_index++;
6165 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006166 index =
Larry Finger1867b112006-02-28 09:48:28 -06006167 ieee80211_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006168 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006169 geo->bg[index].
6170 flags &
6171 IEEE80211_CH_PASSIVE_ONLY ?
6172 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6173 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006174 }
6175 } else {
6176 for (i = 0; i < geo->bg_channels; i++) {
6177 if ((priv->status & STATUS_ASSOCIATED) &&
6178 geo->bg[i].channel == priv->channel)
6179 continue;
6180 channel_index++;
6181 scan->channels_list[channel_index] =
6182 geo->bg[i].channel;
6183 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006184 geo->bg[i].
6185 flags &
6186 IEEE80211_CH_PASSIVE_ONLY ?
6187 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6188 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006189 }
6190 }
6191
6192 if (start != channel_index) {
6193 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6194 (channel_index - start);
6195 }
6196 }
6197}
6198
James Ketrenosea2b26e2005-08-24 21:25:16 -05006199static int ipw_request_scan(struct ipw_priv *priv)
6200{
6201 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006202 int err = 0, scan_type;
6203
6204 if (!(priv->status & STATUS_INIT) ||
6205 (priv->status & STATUS_EXIT_PENDING))
6206 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006207
Zhu Yi46441512006-01-24 16:37:59 +08006208 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006209
James Ketrenosea2b26e2005-08-24 21:25:16 -05006210 if (priv->status & STATUS_SCANNING) {
James Ketrenosa613bff2005-08-24 21:43:11 -05006211 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05006212 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006213 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006214 }
6215
James Ketrenosafbf30a2005-08-25 00:05:33 -05006216 if (!(priv->status & STATUS_SCAN_FORCED) &&
6217 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006218 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6219 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006220 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006221 }
6222
6223 if (priv->status & STATUS_RF_KILL_MASK) {
6224 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6225 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006226 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006227 }
6228
6229 memset(&scan, 0, sizeof(scan));
6230
James Ketrenosb095c382005-08-24 22:04:42 -05006231 if (priv->config & CFG_SPEED_SCAN)
6232 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6233 cpu_to_le16(30);
6234 else
6235 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6236 cpu_to_le16(20);
6237
James Ketrenosa613bff2005-08-24 21:43:11 -05006238 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6239 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05006240 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006241
James Ketrenosa613bff2005-08-24 21:43:11 -05006242 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006243
James Ketrenosb095c382005-08-24 22:04:42 -05006244#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006245 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006246 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006247 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006248
Larry Finger1867b112006-02-28 09:48:28 -06006249 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006250 case IEEE80211_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006251 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006252 channel = priv->channel;
6253 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006254
James Ketrenosb095c382005-08-24 22:04:42 -05006255 case IEEE80211_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006256 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006257 channel = priv->channel;
6258 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006259
James Ketrenosb095c382005-08-24 22:04:42 -05006260 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006261 band = (u8) (IPW_B_MODE << 6) | 1;
6262 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006263 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006264 }
6265
James Ketrenosb095c382005-08-24 22:04:42 -05006266 scan.channels_list[0] = band;
6267 scan.channels_list[1] = channel;
6268 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006269
James Ketrenosb095c382005-08-24 22:04:42 -05006270 /* NOTE: The card will sit on this channel for this time
6271 * period. Scan aborts are timing sensitive and frequently
6272 * result in firmware restarts. As such, it is best to
6273 * set a small dwell_time here and just keep re-issuing
6274 * scans. Otherwise fast channel hopping will not actually
6275 * hop channels.
6276 *
6277 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006278 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6279 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006280 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006281#endif /* CONFIG_IPW2200_MONITOR */
6282 /* If we are roaming, then make this a directed scan for the
6283 * current network. Otherwise, ensure that every other scan
6284 * is a fast channel hop scan */
6285 if ((priv->status & STATUS_ROAMING)
6286 || (!(priv->status & STATUS_ASSOCIATED)
6287 && (priv->config & CFG_STATIC_ESSID)
6288 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006289 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6290 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006291 IPW_DEBUG_HC("Attempt to send SSID command "
6292 "failed.\n");
6293 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006294 }
6295
6296 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006297 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006298 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006299
James Ketrenosafbf30a2005-08-25 00:05:33 -05006300 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006301#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006302 }
6303#endif
6304
6305 err = ipw_send_scan_request_ext(priv, &scan);
6306 if (err) {
6307 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006308 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006309 }
6310
6311 priv->status |= STATUS_SCANNING;
6312 priv->status &= ~STATUS_SCAN_PENDING;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006313 queue_delayed_work(priv->workqueue, &priv->scan_check,
6314 IPW_SCAN_CHECK_WATCHDOG);
James Ketrenosb095c382005-08-24 22:04:42 -05006315 done:
Zhu Yi46441512006-01-24 16:37:59 +08006316 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006317 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006318}
6319
6320static void ipw_bg_abort_scan(void *data)
6321{
6322 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08006323 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006324 ipw_abort_scan(data);
Zhu Yi46441512006-01-24 16:37:59 +08006325 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006326}
6327
James Ketrenosea2b26e2005-08-24 21:25:16 -05006328static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6329{
James Ketrenosb095c382005-08-24 22:04:42 -05006330 /* This is called when wpa_supplicant loads and closes the driver
6331 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006332 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006333 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006334}
6335
James Ketrenosea2b26e2005-08-24 21:25:16 -05006336static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6337{
6338 struct ieee80211_device *ieee = priv->ieee;
6339 struct ieee80211_security sec = {
6340 .flags = SEC_AUTH_MODE,
6341 };
6342 int ret = 0;
6343
James Ketrenosafbf30a2005-08-25 00:05:33 -05006344 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006345 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6346 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006347 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006348 sec.auth_mode = WLAN_AUTH_OPEN;
6349 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006350 } else if (value & IW_AUTH_ALG_LEAP) {
6351 sec.auth_mode = WLAN_AUTH_LEAP;
6352 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006353 } else
6354 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006355
6356 if (ieee->set_security)
6357 ieee->set_security(ieee->dev, &sec);
6358 else
6359 ret = -EOPNOTSUPP;
6360
6361 return ret;
6362}
6363
Adrian Bunka73e22b2006-01-21 01:39:42 +01006364static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6365 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006366{
6367 /* make sure WPA is enabled */
6368 ipw_wpa_enable(priv, 1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006369}
6370
6371static int ipw_set_rsn_capa(struct ipw_priv *priv,
6372 char *capabilities, int length)
6373{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006374 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6375
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006376 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006377 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006378}
6379
James Ketrenosafbf30a2005-08-25 00:05:33 -05006380/*
6381 * WE-18 support
6382 */
6383
6384/* SIOCSIWGENIE */
6385static int ipw_wx_set_genie(struct net_device *dev,
6386 struct iw_request_info *info,
6387 union iwreq_data *wrqu, char *extra)
6388{
6389 struct ipw_priv *priv = ieee80211_priv(dev);
6390 struct ieee80211_device *ieee = priv->ieee;
6391 u8 *buf;
6392 int err = 0;
6393
6394 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6395 (wrqu->data.length && extra == NULL))
6396 return -EINVAL;
6397
Zhu Yi46441512006-01-24 16:37:59 +08006398 //mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006399
6400 //if (!ieee->wpa_enabled) {
6401 // err = -EOPNOTSUPP;
6402 // goto out;
6403 //}
6404
6405 if (wrqu->data.length) {
6406 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6407 if (buf == NULL) {
6408 err = -ENOMEM;
6409 goto out;
6410 }
6411
6412 memcpy(buf, extra, wrqu->data.length);
6413 kfree(ieee->wpa_ie);
6414 ieee->wpa_ie = buf;
6415 ieee->wpa_ie_len = wrqu->data.length;
6416 } else {
6417 kfree(ieee->wpa_ie);
6418 ieee->wpa_ie = NULL;
6419 ieee->wpa_ie_len = 0;
6420 }
6421
6422 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6423 out:
Zhu Yi46441512006-01-24 16:37:59 +08006424 //mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006425 return err;
6426}
6427
6428/* SIOCGIWGENIE */
6429static int ipw_wx_get_genie(struct net_device *dev,
6430 struct iw_request_info *info,
6431 union iwreq_data *wrqu, char *extra)
6432{
6433 struct ipw_priv *priv = ieee80211_priv(dev);
6434 struct ieee80211_device *ieee = priv->ieee;
6435 int err = 0;
6436
Zhu Yi46441512006-01-24 16:37:59 +08006437 //mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006438
6439 //if (!ieee->wpa_enabled) {
6440 // err = -EOPNOTSUPP;
6441 // goto out;
6442 //}
6443
6444 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6445 wrqu->data.length = 0;
6446 goto out;
6447 }
6448
6449 if (wrqu->data.length < ieee->wpa_ie_len) {
6450 err = -E2BIG;
6451 goto out;
6452 }
6453
6454 wrqu->data.length = ieee->wpa_ie_len;
6455 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6456
6457 out:
Zhu Yi46441512006-01-24 16:37:59 +08006458 //mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006459 return err;
6460}
6461
Zhu Yi1fbfea52005-08-05 17:22:56 +08006462static int wext_cipher2level(int cipher)
6463{
6464 switch (cipher) {
6465 case IW_AUTH_CIPHER_NONE:
6466 return SEC_LEVEL_0;
6467 case IW_AUTH_CIPHER_WEP40:
6468 case IW_AUTH_CIPHER_WEP104:
6469 return SEC_LEVEL_1;
6470 case IW_AUTH_CIPHER_TKIP:
6471 return SEC_LEVEL_2;
6472 case IW_AUTH_CIPHER_CCMP:
6473 return SEC_LEVEL_3;
6474 default:
6475 return -1;
6476 }
6477}
6478
James Ketrenosafbf30a2005-08-25 00:05:33 -05006479/* SIOCSIWAUTH */
6480static int ipw_wx_set_auth(struct net_device *dev,
6481 struct iw_request_info *info,
6482 union iwreq_data *wrqu, char *extra)
6483{
6484 struct ipw_priv *priv = ieee80211_priv(dev);
6485 struct ieee80211_device *ieee = priv->ieee;
6486 struct iw_param *param = &wrqu->param;
6487 struct ieee80211_crypt_data *crypt;
6488 unsigned long flags;
6489 int ret = 0;
6490
6491 switch (param->flags & IW_AUTH_INDEX) {
6492 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006493 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006494 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006495 ipw_set_hw_decrypt_unicast(priv,
6496 wext_cipher2level(param->value));
6497 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006498 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006499 ipw_set_hw_decrypt_multicast(priv,
6500 wext_cipher2level(param->value));
6501 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006502 case IW_AUTH_KEY_MGMT:
6503 /*
6504 * ipw2200 does not use these parameters
6505 */
6506 break;
6507
6508 case IW_AUTH_TKIP_COUNTERMEASURES:
6509 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006510 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006511 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006512
6513 flags = crypt->ops->get_flags(crypt->priv);
6514
6515 if (param->value)
6516 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6517 else
6518 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6519
6520 crypt->ops->set_flags(flags, crypt->priv);
6521
6522 break;
6523
6524 case IW_AUTH_DROP_UNENCRYPTED:{
6525 /* HACK:
6526 *
6527 * wpa_supplicant calls set_wpa_enabled when the driver
6528 * is loaded and unloaded, regardless of if WPA is being
6529 * used. No other calls are made which can be used to
6530 * determine if encryption will be used or not prior to
6531 * association being expected. If encryption is not being
6532 * used, drop_unencrypted is set to false, else true -- we
6533 * can use this to determine if the CAP_PRIVACY_ON bit should
6534 * be set.
6535 */
6536 struct ieee80211_security sec = {
6537 .flags = SEC_ENABLED,
6538 .enabled = param->value,
6539 };
6540 priv->ieee->drop_unencrypted = param->value;
6541 /* We only change SEC_LEVEL for open mode. Others
6542 * are set by ipw_wpa_set_encryption.
6543 */
6544 if (!param->value) {
6545 sec.flags |= SEC_LEVEL;
6546 sec.level = SEC_LEVEL_0;
6547 } else {
6548 sec.flags |= SEC_LEVEL;
6549 sec.level = SEC_LEVEL_1;
6550 }
6551 if (priv->ieee->set_security)
6552 priv->ieee->set_security(priv->ieee->dev, &sec);
6553 break;
6554 }
6555
6556 case IW_AUTH_80211_AUTH_ALG:
6557 ret = ipw_wpa_set_auth_algs(priv, param->value);
6558 break;
6559
6560 case IW_AUTH_WPA_ENABLED:
6561 ret = ipw_wpa_enable(priv, param->value);
Zhu Yie3c5a642006-04-13 17:21:13 +08006562 ipw_disassociate(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006563 break;
6564
6565 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6566 ieee->ieee802_1x = param->value;
6567 break;
6568
6569 //case IW_AUTH_ROAMING_CONTROL:
6570 case IW_AUTH_PRIVACY_INVOKED:
6571 ieee->privacy_invoked = param->value;
6572 break;
6573
6574 default:
6575 return -EOPNOTSUPP;
6576 }
6577 return ret;
6578}
6579
6580/* SIOCGIWAUTH */
6581static int ipw_wx_get_auth(struct net_device *dev,
6582 struct iw_request_info *info,
6583 union iwreq_data *wrqu, char *extra)
6584{
6585 struct ipw_priv *priv = ieee80211_priv(dev);
6586 struct ieee80211_device *ieee = priv->ieee;
6587 struct ieee80211_crypt_data *crypt;
6588 struct iw_param *param = &wrqu->param;
6589 int ret = 0;
6590
6591 switch (param->flags & IW_AUTH_INDEX) {
6592 case IW_AUTH_WPA_VERSION:
6593 case IW_AUTH_CIPHER_PAIRWISE:
6594 case IW_AUTH_CIPHER_GROUP:
6595 case IW_AUTH_KEY_MGMT:
6596 /*
6597 * wpa_supplicant will control these internally
6598 */
6599 ret = -EOPNOTSUPP;
6600 break;
6601
6602 case IW_AUTH_TKIP_COUNTERMEASURES:
6603 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006604 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006605 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006606
6607 param->value = (crypt->ops->get_flags(crypt->priv) &
6608 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6609
6610 break;
6611
6612 case IW_AUTH_DROP_UNENCRYPTED:
6613 param->value = ieee->drop_unencrypted;
6614 break;
6615
6616 case IW_AUTH_80211_AUTH_ALG:
6617 param->value = ieee->sec.auth_mode;
6618 break;
6619
6620 case IW_AUTH_WPA_ENABLED:
6621 param->value = ieee->wpa_enabled;
6622 break;
6623
6624 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6625 param->value = ieee->ieee802_1x;
6626 break;
6627
6628 case IW_AUTH_ROAMING_CONTROL:
6629 case IW_AUTH_PRIVACY_INVOKED:
6630 param->value = ieee->privacy_invoked;
6631 break;
6632
6633 default:
6634 return -EOPNOTSUPP;
6635 }
6636 return 0;
6637}
6638
6639/* SIOCSIWENCODEEXT */
6640static int ipw_wx_set_encodeext(struct net_device *dev,
6641 struct iw_request_info *info,
6642 union iwreq_data *wrqu, char *extra)
6643{
6644 struct ipw_priv *priv = ieee80211_priv(dev);
6645 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6646
6647 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006648 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006649 /* IPW HW can't build TKIP MIC,
6650 host decryption still needed */
6651 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6652 priv->ieee->host_mc_decrypt = 1;
6653 else {
6654 priv->ieee->host_encrypt = 0;
6655 priv->ieee->host_encrypt_msdu = 1;
6656 priv->ieee->host_decrypt = 1;
6657 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006658 } else {
6659 priv->ieee->host_encrypt = 0;
6660 priv->ieee->host_encrypt_msdu = 0;
6661 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006662 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006663 }
6664 }
6665
6666 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6667}
6668
6669/* SIOCGIWENCODEEXT */
6670static int ipw_wx_get_encodeext(struct net_device *dev,
6671 struct iw_request_info *info,
6672 union iwreq_data *wrqu, char *extra)
6673{
6674 struct ipw_priv *priv = ieee80211_priv(dev);
6675 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6676}
6677
6678/* SIOCSIWMLME */
6679static int ipw_wx_set_mlme(struct net_device *dev,
6680 struct iw_request_info *info,
6681 union iwreq_data *wrqu, char *extra)
6682{
6683 struct ipw_priv *priv = ieee80211_priv(dev);
6684 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6685 u16 reason;
6686
6687 reason = cpu_to_le16(mlme->reason_code);
6688
6689 switch (mlme->cmd) {
6690 case IW_MLME_DEAUTH:
6691 // silently ignore
6692 break;
6693
6694 case IW_MLME_DISASSOC:
6695 ipw_disassociate(priv);
6696 break;
6697
6698 default:
6699 return -EOPNOTSUPP;
6700 }
6701 return 0;
6702}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006703
Zhu Yie43e3c12006-04-13 17:20:45 +08006704#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05006705
6706/* QoS */
6707/*
6708* get the modulation type of the current network or
6709* the card current mode
6710*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006711static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006712{
6713 u8 mode = 0;
6714
6715 if (priv->status & STATUS_ASSOCIATED) {
6716 unsigned long flags;
6717
6718 spin_lock_irqsave(&priv->ieee->lock, flags);
6719 mode = priv->assoc_network->mode;
6720 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6721 } else {
6722 mode = priv->ieee->mode;
6723 }
6724 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6725 return mode;
6726}
6727
6728/*
6729* Handle management frame beacon and probe response
6730*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006731static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6732 int active_network,
6733 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006734{
6735 u32 size = sizeof(struct ieee80211_qos_parameters);
6736
James Ketrenosafbf30a2005-08-25 00:05:33 -05006737 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006738 network->qos_data.active = network->qos_data.supported;
6739
6740 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006741 if (active_network &&
6742 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006743 network->qos_data.active = network->qos_data.supported;
6744
6745 if ((network->qos_data.active == 1) && (active_network == 1) &&
6746 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6747 (network->qos_data.old_param_count !=
6748 network->qos_data.param_count)) {
6749 network->qos_data.old_param_count =
6750 network->qos_data.param_count;
6751 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006752 IPW_DEBUG_QOS("QoS parameters change call "
6753 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006754 }
6755 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006756 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6757 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006758 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006759 else
6760 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006761 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006762
James Ketrenosb095c382005-08-24 22:04:42 -05006763 if ((network->qos_data.active == 1) && (active_network == 1)) {
6764 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6765 schedule_work(&priv->qos_activate);
6766 }
6767
6768 network->qos_data.active = 0;
6769 network->qos_data.supported = 0;
6770 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006771 if ((priv->status & STATUS_ASSOCIATED) &&
6772 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6773 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6774 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6775 !(network->flags & NETWORK_EMPTY_ESSID))
James Ketrenosb095c382005-08-24 22:04:42 -05006776 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006777 priv->assoc_network->ssid_len) &&
6778 !memcmp(network->ssid,
6779 priv->assoc_network->ssid,
6780 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006781 queue_work(priv->workqueue,
6782 &priv->merge_networks);
6783 }
James Ketrenosb095c382005-08-24 22:04:42 -05006784 }
6785
6786 return 0;
6787}
6788
6789/*
6790* This function set up the firmware to support QoS. It sends
6791* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6792*/
6793static int ipw_qos_activate(struct ipw_priv *priv,
6794 struct ieee80211_qos_data *qos_network_data)
6795{
6796 int err;
6797 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6798 struct ieee80211_qos_parameters *active_one = NULL;
6799 u32 size = sizeof(struct ieee80211_qos_parameters);
6800 u32 burst_duration;
6801 int i;
6802 u8 type;
6803
6804 type = ipw_qos_current_mode(priv);
6805
6806 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6807 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6808 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6809 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6810
6811 if (qos_network_data == NULL) {
6812 if (type == IEEE_B) {
6813 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6814 active_one = &def_parameters_CCK;
6815 } else
6816 active_one = &def_parameters_OFDM;
6817
James Ketrenosafbf30a2005-08-25 00:05:33 -05006818 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006819 burst_duration = ipw_qos_get_burst_duration(priv);
6820 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006821 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6822 (u16) burst_duration;
6823 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05006824 if (type == IEEE_B) {
6825 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6826 type);
6827 if (priv->qos_data.qos_enable == 0)
6828 active_one = &def_parameters_CCK;
6829 else
6830 active_one = priv->qos_data.def_qos_parm_CCK;
6831 } else {
6832 if (priv->qos_data.qos_enable == 0)
6833 active_one = &def_parameters_OFDM;
6834 else
6835 active_one = priv->qos_data.def_qos_parm_OFDM;
6836 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006837 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006838 } else {
6839 unsigned long flags;
6840 int active;
6841
6842 spin_lock_irqsave(&priv->ieee->lock, flags);
6843 active_one = &(qos_network_data->parameters);
6844 qos_network_data->old_param_count =
6845 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006846 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006847 active = qos_network_data->supported;
6848 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6849
6850 if (active == 0) {
6851 burst_duration = ipw_qos_get_burst_duration(priv);
6852 for (i = 0; i < QOS_QUEUE_NUM; i++)
6853 qos_parameters[QOS_PARAM_SET_ACTIVE].
6854 tx_op_limit[i] = (u16) burst_duration;
6855 }
6856 }
6857
6858 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05006859 err = ipw_send_qos_params_command(priv,
6860 (struct ieee80211_qos_parameters *)
6861 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05006862 if (err)
6863 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6864
6865 return err;
6866}
6867
6868/*
6869* send IPW_CMD_WME_INFO to the firmware
6870*/
6871static int ipw_qos_set_info_element(struct ipw_priv *priv)
6872{
6873 int ret = 0;
6874 struct ieee80211_qos_information_element qos_info;
6875
6876 if (priv == NULL)
6877 return -1;
6878
6879 qos_info.elementID = QOS_ELEMENT_ID;
6880 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6881
6882 qos_info.version = QOS_VERSION_1;
6883 qos_info.ac_info = 0;
6884
6885 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6886 qos_info.qui_type = QOS_OUI_TYPE;
6887 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6888
6889 ret = ipw_send_qos_info_command(priv, &qos_info);
6890 if (ret != 0) {
6891 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6892 }
6893 return ret;
6894}
6895
6896/*
6897* Set the QoS parameter with the association request structure
6898*/
6899static int ipw_qos_association(struct ipw_priv *priv,
6900 struct ieee80211_network *network)
6901{
6902 int err = 0;
6903 struct ieee80211_qos_data *qos_data = NULL;
6904 struct ieee80211_qos_data ibss_data = {
6905 .supported = 1,
6906 .active = 1,
6907 };
6908
6909 switch (priv->ieee->iw_mode) {
6910 case IW_MODE_ADHOC:
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02006911 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
James Ketrenosb095c382005-08-24 22:04:42 -05006912
6913 qos_data = &ibss_data;
6914 break;
6915
6916 case IW_MODE_INFRA:
6917 qos_data = &network->qos_data;
6918 break;
6919
6920 default:
6921 BUG();
6922 break;
6923 }
6924
6925 err = ipw_qos_activate(priv, qos_data);
6926 if (err) {
6927 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6928 return err;
6929 }
6930
6931 if (priv->qos_data.qos_enable && qos_data->supported) {
6932 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6933 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6934 return ipw_qos_set_info_element(priv);
6935 }
6936
6937 return 0;
6938}
6939
6940/*
6941* handling the beaconing responces. if we get different QoS setting
6942* of the network from the the associated setting adjust the QoS
6943* setting
6944*/
6945static int ipw_qos_association_resp(struct ipw_priv *priv,
6946 struct ieee80211_network *network)
6947{
6948 int ret = 0;
6949 unsigned long flags;
6950 u32 size = sizeof(struct ieee80211_qos_parameters);
6951 int set_qos_param = 0;
6952
James Ketrenosafbf30a2005-08-25 00:05:33 -05006953 if ((priv == NULL) || (network == NULL) ||
6954 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05006955 return ret;
6956
6957 if (!(priv->status & STATUS_ASSOCIATED))
6958 return ret;
6959
James Ketrenosafbf30a2005-08-25 00:05:33 -05006960 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05006961 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05006962
6963 spin_lock_irqsave(&priv->ieee->lock, flags);
6964 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006965 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
James Ketrenosb095c382005-08-24 22:04:42 -05006966 sizeof(struct ieee80211_qos_data));
6967 priv->assoc_network->qos_data.active = 1;
6968 if ((network->qos_data.old_param_count !=
6969 network->qos_data.param_count)) {
6970 set_qos_param = 1;
6971 network->qos_data.old_param_count =
6972 network->qos_data.param_count;
6973 }
6974
6975 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006976 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
6977 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006978 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006979 else
6980 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006981 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006982 priv->assoc_network->qos_data.active = 0;
6983 priv->assoc_network->qos_data.supported = 0;
6984 set_qos_param = 1;
6985 }
6986
6987 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6988
6989 if (set_qos_param == 1)
6990 schedule_work(&priv->qos_activate);
6991
6992 return ret;
6993}
6994
6995static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
6996{
6997 u32 ret = 0;
6998
6999 if ((priv == NULL))
7000 return 0;
7001
James Ketrenosafbf30a2005-08-25 00:05:33 -05007002 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05007003 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007004 else
James Ketrenosb095c382005-08-24 22:04:42 -05007005 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007006
James Ketrenosb095c382005-08-24 22:04:42 -05007007 return ret;
7008}
7009
7010/*
7011* Initialize the setting of QoS global
7012*/
7013static void ipw_qos_init(struct ipw_priv *priv, int enable,
7014 int burst_enable, u32 burst_duration_CCK,
7015 u32 burst_duration_OFDM)
7016{
7017 priv->qos_data.qos_enable = enable;
7018
7019 if (priv->qos_data.qos_enable) {
7020 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7021 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7022 IPW_DEBUG_QOS("QoS is enabled\n");
7023 } else {
7024 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7025 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7026 IPW_DEBUG_QOS("QoS is not enabled\n");
7027 }
7028
7029 priv->qos_data.burst_enable = burst_enable;
7030
7031 if (burst_enable) {
7032 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7033 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7034 } else {
7035 priv->qos_data.burst_duration_CCK = 0;
7036 priv->qos_data.burst_duration_OFDM = 0;
7037 }
7038}
7039
7040/*
7041* map the packet priority to the right TX Queue
7042*/
7043static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7044{
7045 if (priority > 7 || !priv->qos_data.qos_enable)
7046 priority = 0;
7047
7048 return from_priority_to_tx_queue[priority] - 1;
7049}
7050
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007051static int ipw_is_qos_active(struct net_device *dev,
7052 struct sk_buff *skb)
James Ketrenosb095c382005-08-24 22:04:42 -05007053{
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007054 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosb095c382005-08-24 22:04:42 -05007055 struct ieee80211_qos_data *qos_data = NULL;
7056 int active, supported;
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007057 u8 *daddr = skb->data + ETH_ALEN;
7058 int unicast = !is_multicast_ether_addr(daddr);
James Ketrenosb095c382005-08-24 22:04:42 -05007059
7060 if (!(priv->status & STATUS_ASSOCIATED))
7061 return 0;
7062
7063 qos_data = &priv->assoc_network->qos_data;
7064
James Ketrenosb095c382005-08-24 22:04:42 -05007065 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7066 if (unicast == 0)
7067 qos_data->active = 0;
7068 else
7069 qos_data->active = qos_data->supported;
7070 }
James Ketrenosb095c382005-08-24 22:04:42 -05007071 active = qos_data->active;
7072 supported = qos_data->supported;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007073 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7074 "unicast %d\n",
7075 priv->qos_data.qos_enable, active, supported, unicast);
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007076 if (active && priv->qos_data.qos_enable)
7077 return 1;
James Ketrenosb095c382005-08-24 22:04:42 -05007078
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007079 return 0;
7080
7081}
7082/*
7083* add QoS parameter to the TX command
7084*/
7085static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7086 u16 priority,
7087 struct tfd_data *tfd)
7088{
7089 int tx_queue_id = 0;
7090
7091
7092 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7093 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7094
7095 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7096 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
7097 tfd->tfd.tfd_26.mchdr.qos_ctrl |= CTRL_QOS_NO_ACK;
James Ketrenosb095c382005-08-24 22:04:42 -05007098 }
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007099 return 0;
James Ketrenosb095c382005-08-24 22:04:42 -05007100}
7101
7102/*
7103* background support to run QoS activate functionality
7104*/
7105static void ipw_bg_qos_activate(void *data)
7106{
7107 struct ipw_priv *priv = data;
7108
7109 if (priv == NULL)
7110 return;
7111
Zhu Yi46441512006-01-24 16:37:59 +08007112 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007113
7114 if (priv->status & STATUS_ASSOCIATED)
7115 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7116
Zhu Yi46441512006-01-24 16:37:59 +08007117 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007118}
7119
James Ketrenos3b9990c2005-08-19 13:18:55 -05007120static int ipw_handle_probe_response(struct net_device *dev,
7121 struct ieee80211_probe_response *resp,
7122 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007123{
7124 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007125 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7126 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007127
James Ketrenos3b9990c2005-08-19 13:18:55 -05007128 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007129
James Ketrenos3b9990c2005-08-19 13:18:55 -05007130 return 0;
7131}
James Ketrenosb095c382005-08-24 22:04:42 -05007132
James Ketrenos3b9990c2005-08-19 13:18:55 -05007133static int ipw_handle_beacon(struct net_device *dev,
7134 struct ieee80211_beacon *resp,
7135 struct ieee80211_network *network)
7136{
7137 struct ipw_priv *priv = ieee80211_priv(dev);
7138 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7139 (network == priv->assoc_network));
7140
7141 ipw_qos_handle_probe_response(priv, active_network, network);
7142
7143 return 0;
7144}
7145
7146static int ipw_handle_assoc_response(struct net_device *dev,
7147 struct ieee80211_assoc_response *resp,
7148 struct ieee80211_network *network)
7149{
7150 struct ipw_priv *priv = ieee80211_priv(dev);
7151 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007152 return 0;
7153}
7154
7155static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7156 *qos_param)
7157{
Zhu Yi4e226992006-01-24 16:37:36 +08007158 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7159 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007160}
7161
7162static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7163 *qos_param)
7164{
Zhu Yi4e226992006-01-24 16:37:36 +08007165 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7166 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007167}
7168
Zhu Yie43e3c12006-04-13 17:20:45 +08007169#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -05007170
James Ketrenos43f66a62005-03-25 12:31:53 -06007171static int ipw_associate_network(struct ipw_priv *priv,
7172 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007173 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007174{
7175 int err;
7176
7177 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007178 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007179
7180 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007181 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007182 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007183 memcpy(priv->essid, network->ssid, priv->essid_len);
7184 }
7185
7186 network->last_associate = jiffies;
7187
7188 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7189 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007190 priv->assoc_request.auth_key = 0;
7191
James Ketrenos43f66a62005-03-25 12:31:53 -06007192 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007193 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007194 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007195 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7196
Zhu Yi1ba61e02006-02-15 13:00:55 +08007197 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007198 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007199
7200 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7201 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7202 priv->assoc_request.auth_type = AUTH_LEAP;
7203 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007204 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007205
James Ketrenosa613bff2005-08-24 21:43:11 -05007206 if (priv->ieee->wpa_ie_len) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007207 priv->assoc_request.policy_support = 0x02; /* RSN active */
7208 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7209 priv->ieee->wpa_ie_len);
7210 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007211
Jeff Garzikbf794512005-07-31 13:07:26 -04007212 /*
7213 * It is valid for our ieee device to support multiple modes, but
7214 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007215 * just one mode.
7216 */
7217 if (network->mode & priv->ieee->mode & IEEE_A)
7218 priv->assoc_request.ieee_mode = IPW_A_MODE;
7219 else if (network->mode & priv->ieee->mode & IEEE_G)
7220 priv->assoc_request.ieee_mode = IPW_G_MODE;
7221 else if (network->mode & priv->ieee->mode & IEEE_B)
7222 priv->assoc_request.ieee_mode = IPW_B_MODE;
7223
James Ketrenosea2b26e2005-08-24 21:25:16 -05007224 priv->assoc_request.capability = network->capability;
7225 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7226 && !(priv->config & CFG_PREAMBLE_LONG)) {
7227 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7228 } else {
7229 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7230
7231 /* Clear the short preamble if we won't be supporting it */
7232 priv->assoc_request.capability &=
7233 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7234 }
7235
James Ketrenosafbf30a2005-08-25 00:05:33 -05007236 /* Clear capability bits that aren't used in Ad Hoc */
7237 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7238 priv->assoc_request.capability &=
7239 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7240
James Ketrenos43f66a62005-03-25 12:31:53 -06007241 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007242 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007243 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04007244 escape_essid(priv->essid, priv->essid_len),
7245 network->channel,
7246 ipw_modes[priv->assoc_request.ieee_mode],
7247 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007248 (priv->assoc_request.preamble_length ==
7249 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7250 network->capability &
7251 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007252 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007253 priv->capability & CAP_PRIVACY_ON ?
7254 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007255 "(open)") : "",
7256 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007257 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007258 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007259 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007260
7261 priv->assoc_request.beacon_interval = network->beacon_interval;
7262 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007263 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007264 priv->assoc_request.assoc_type = HC_IBSS_START;
7265 priv->assoc_request.assoc_tsf_msw = 0;
7266 priv->assoc_request.assoc_tsf_lsw = 0;
7267 } else {
7268 if (unlikely(roaming))
7269 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7270 else
7271 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7272 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7273 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7274 }
7275
James Ketrenosafbf30a2005-08-25 00:05:33 -05007276 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007277
7278 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7279 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7280 priv->assoc_request.atim_window = network->atim_window;
7281 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007282 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007283 priv->assoc_request.atim_window = 0;
7284 }
7285
James Ketrenos43f66a62005-03-25 12:31:53 -06007286 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04007287
James Ketrenos43f66a62005-03-25 12:31:53 -06007288 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7289 if (err) {
7290 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7291 return err;
7292 }
7293
7294 rates->ieee_mode = priv->assoc_request.ieee_mode;
7295 rates->purpose = IPW_RATE_CONNECT;
7296 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007297
James Ketrenos43f66a62005-03-25 12:31:53 -06007298 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7299 priv->sys_config.dot11g_auto_detection = 1;
7300 else
7301 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007302
7303 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7304 priv->sys_config.answer_broadcast_ssid_probe = 1;
7305 else
7306 priv->sys_config.answer_broadcast_ssid_probe = 0;
7307
Zhu Yid685b8c2006-04-13 17:20:27 +08007308 err = ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007309 if (err) {
7310 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7311 return err;
7312 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007313
James Ketrenos43f66a62005-03-25 12:31:53 -06007314 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007315 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007316 if (err) {
7317 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7318 return err;
7319 }
7320
7321 /*
7322 * If preemption is enabled, it is possible for the association
7323 * to complete before we return from ipw_send_associate. Therefore
7324 * we have to be sure and update our priviate data first.
7325 */
7326 priv->channel = network->channel;
7327 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007328 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007329 priv->status &= ~STATUS_SECURITY_UPDATED;
7330
7331 priv->assoc_network = network;
7332
Zhu Yie43e3c12006-04-13 17:20:45 +08007333#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05007334 ipw_qos_association(priv, network);
7335#endif
7336
James Ketrenos43f66a62005-03-25 12:31:53 -06007337 err = ipw_send_associate(priv, &priv->assoc_request);
7338 if (err) {
7339 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7340 return err;
7341 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007342
7343 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007344 escape_essid(priv->essid, priv->essid_len),
7345 MAC_ARG(priv->bssid));
7346
7347 return 0;
7348}
7349
7350static void ipw_roam(void *data)
7351{
7352 struct ipw_priv *priv = data;
7353 struct ieee80211_network *network = NULL;
7354 struct ipw_network_match match = {
7355 .network = priv->assoc_network
7356 };
7357
7358 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007359 *
7360 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007361 * setting the status ROAM bit and requesting a scan.
7362 * 2. When the scan completes, it schedules the ROAM work
7363 * 3. The ROAM work looks at all of the known networks for one that
7364 * is a better network than the currently associated. If none
7365 * found, the ROAM process is over (ROAM bit cleared)
7366 * 4. If a better network is found, a disassociation request is
7367 * sent.
7368 * 5. When the disassociation completes, the roam work is again
7369 * scheduled. The second time through, the driver is no longer
7370 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007371 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007372 * 6. At this point ,the roaming process is complete and the ROAM
7373 * status bit is cleared.
7374 */
7375
7376 /* If we are no longer associated, and the roaming bit is no longer
7377 * set, then we are not actively roaming, so just return */
7378 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7379 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007380
James Ketrenos43f66a62005-03-25 12:31:53 -06007381 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007382 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007383 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007384 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007385 u8 rssi = priv->assoc_network->stats.rssi;
7386 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007387 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007388 list_for_each_entry(network, &priv->ieee->network_list, list) {
7389 if (network != priv->assoc_network)
7390 ipw_best_network(priv, &match, network, 1);
7391 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007392 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007393 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007394
James Ketrenos43f66a62005-03-25 12:31:53 -06007395 if (match.network == priv->assoc_network) {
7396 IPW_DEBUG_ASSOC("No better APs in this network to "
7397 "roam to.\n");
7398 priv->status &= ~STATUS_ROAMING;
7399 ipw_debug_config(priv);
7400 return;
7401 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007402
James Ketrenos43f66a62005-03-25 12:31:53 -06007403 ipw_send_disassociate(priv, 1);
7404 priv->assoc_network = match.network;
7405
7406 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007407 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007408
7409 /* Second pass through ROAM process -- request association */
7410 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7411 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7412 priv->status &= ~STATUS_ROAMING;
7413}
7414
James Ketrenosc848d0a2005-08-24 21:56:24 -05007415static void ipw_bg_roam(void *data)
7416{
7417 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08007418 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007419 ipw_roam(data);
Zhu Yi46441512006-01-24 16:37:59 +08007420 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007421}
7422
7423static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007424{
7425 struct ipw_priv *priv = data;
7426
7427 struct ieee80211_network *network = NULL;
7428 struct ipw_network_match match = {
7429 .network = NULL
7430 };
7431 struct ipw_supported_rates *rates;
7432 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007433 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007434
James Ketrenosb095c382005-08-24 22:04:42 -05007435 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7436 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7437 return 0;
7438 }
7439
James Ketrenosc848d0a2005-08-24 21:56:24 -05007440 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007441 IPW_DEBUG_ASSOC("Not attempting association (already in "
7442 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007443 return 0;
7444 }
7445
Hong Liue6324722005-09-14 21:04:15 -05007446 if (priv->status & STATUS_DISASSOCIATING) {
7447 IPW_DEBUG_ASSOC("Not attempting association (in "
7448 "disassociating)\n ");
7449 queue_work(priv->workqueue, &priv->associate);
7450 return 0;
7451 }
7452
James Ketrenosc848d0a2005-08-24 21:56:24 -05007453 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007454 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7455 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007456 return 0;
7457 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007458
7459 if (!(priv->config & CFG_ASSOCIATE) &&
7460 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007461 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007462 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007463 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007464 }
7465
James Ketrenosa613bff2005-08-24 21:43:11 -05007466 /* Protect our use of the network_list */
7467 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007468 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007469 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007470
7471 network = match.network;
7472 rates = &match.rates;
7473
7474 if (network == NULL &&
7475 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7476 priv->config & CFG_ADHOC_CREATE &&
7477 priv->config & CFG_STATIC_ESSID &&
James Ketrenosa613bff2005-08-24 21:43:11 -05007478 priv->config & CFG_STATIC_CHANNEL &&
James Ketrenos43f66a62005-03-25 12:31:53 -06007479 !list_empty(&priv->ieee->network_free_list)) {
7480 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007481 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007482 ipw_adhoc_create(priv, network);
7483 rates = &priv->rates;
7484 list_del(element);
7485 list_add_tail(&network->list, &priv->ieee->network_list);
7486 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007487 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007488
James Ketrenos43f66a62005-03-25 12:31:53 -06007489 /* If we reached the end of the list, then we don't have any valid
7490 * matching APs */
7491 if (!network) {
7492 ipw_debug_config(priv);
7493
James Ketrenosb095c382005-08-24 22:04:42 -05007494 if (!(priv->status & STATUS_SCANNING)) {
7495 if (!(priv->config & CFG_SPEED_SCAN))
7496 queue_delayed_work(priv->workqueue,
7497 &priv->request_scan,
7498 SCAN_INTERVAL);
7499 else
7500 queue_work(priv->workqueue,
7501 &priv->request_scan);
7502 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007503
James Ketrenosc848d0a2005-08-24 21:56:24 -05007504 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007505 }
7506
7507 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007508
7509 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007510}
Jeff Garzikbf794512005-07-31 13:07:26 -04007511
James Ketrenosc848d0a2005-08-24 21:56:24 -05007512static void ipw_bg_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007513{
James Ketrenosc848d0a2005-08-24 21:56:24 -05007514 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08007515 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007516 ipw_associate(data);
Zhu Yi46441512006-01-24 16:37:59 +08007517 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007518}
7519
James Ketrenosb095c382005-08-24 22:04:42 -05007520static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7521 struct sk_buff *skb)
7522{
7523 struct ieee80211_hdr *hdr;
7524 u16 fc;
7525
7526 hdr = (struct ieee80211_hdr *)skb->data;
7527 fc = le16_to_cpu(hdr->frame_ctl);
7528 if (!(fc & IEEE80211_FCTL_PROTECTED))
7529 return;
7530
7531 fc &= ~IEEE80211_FCTL_PROTECTED;
7532 hdr->frame_ctl = cpu_to_le16(fc);
7533 switch (priv->ieee->sec.level) {
7534 case SEC_LEVEL_3:
7535 /* Remove CCMP HDR */
7536 memmove(skb->data + IEEE80211_3ADDR_LEN,
7537 skb->data + IEEE80211_3ADDR_LEN + 8,
7538 skb->len - IEEE80211_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007539 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007540 break;
7541 case SEC_LEVEL_2:
7542 break;
7543 case SEC_LEVEL_1:
7544 /* Remove IV */
7545 memmove(skb->data + IEEE80211_3ADDR_LEN,
7546 skb->data + IEEE80211_3ADDR_LEN + 4,
7547 skb->len - IEEE80211_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007548 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007549 break;
7550 case SEC_LEVEL_0:
7551 break;
7552 default:
7553 printk(KERN_ERR "Unknow security level %d\n",
7554 priv->ieee->sec.level);
7555 break;
7556 }
7557}
7558
7559static void ipw_handle_data_packet(struct ipw_priv *priv,
7560 struct ipw_rx_mem_buffer *rxb,
7561 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007562{
Hong Liu567deaf2005-08-31 18:07:22 +08007563 struct ieee80211_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007564 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7565
7566 /* We received data from the HW, so stop the watchdog */
7567 priv->net_dev->trans_start = jiffies;
7568
Jeff Garzikbf794512005-07-31 13:07:26 -04007569 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007570 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007571 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007572 skb_tailroom(rxb->skb))) {
7573 priv->ieee->stats.rx_errors++;
7574 priv->wstats.discard.misc++;
7575 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7576 return;
7577 } else if (unlikely(!netif_running(priv->net_dev))) {
7578 priv->ieee->stats.rx_dropped++;
7579 priv->wstats.discard.misc++;
7580 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7581 return;
7582 }
7583
7584 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007585 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007586
7587 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007588 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007589
7590 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7591
James Ketrenosb095c382005-08-24 22:04:42 -05007592 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
Hong Liu567deaf2005-08-31 18:07:22 +08007593 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7594 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007595 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007596 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007597 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7598
Jeff Garzikbf794512005-07-31 13:07:26 -04007599 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06007600 priv->ieee->stats.rx_errors++;
James Ketrenosa613bff2005-08-24 21:43:11 -05007601 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007602 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007603 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007604 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007605}
7606
Zhu Yi459d4082006-04-13 17:21:00 +08007607#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05007608static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7609 struct ipw_rx_mem_buffer *rxb,
7610 struct ieee80211_rx_stats *stats)
7611{
7612 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7613 struct ipw_rx_frame *frame = &pkt->u.frame;
7614
7615 /* initial pull of some data */
7616 u16 received_channel = frame->received_channel;
7617 u8 antennaAndPhy = frame->antennaAndPhy;
7618 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7619 u16 pktrate = frame->rate;
7620
7621 /* Magic struct that slots into the radiotap header -- no reason
7622 * to build this manually element by element, we can write it much
7623 * more efficiently than we can parse it. ORDER MATTERS HERE */
Zhu Yid685b8c2006-04-13 17:20:27 +08007624 struct ipw_rt_hdr *ipw_rt;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007625
7626 short len = le16_to_cpu(pkt->u.frame.length);
7627
7628 /* We received data from the HW, so stop the watchdog */
7629 priv->net_dev->trans_start = jiffies;
7630
7631 /* We only process data packets if the
7632 * interface is open */
7633 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7634 skb_tailroom(rxb->skb))) {
7635 priv->ieee->stats.rx_errors++;
7636 priv->wstats.discard.misc++;
7637 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7638 return;
7639 } else if (unlikely(!netif_running(priv->net_dev))) {
7640 priv->ieee->stats.rx_dropped++;
7641 priv->wstats.discard.misc++;
7642 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7643 return;
7644 }
7645
7646 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7647 * that now */
7648 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7649 /* FIXME: Should alloc bigger skb instead */
7650 priv->ieee->stats.rx_dropped++;
7651 priv->wstats.discard.misc++;
7652 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7653 return;
7654 }
7655
7656 /* copy the frame itself */
7657 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7658 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7659
7660 /* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7661 * part of our real header, saves a little time.
7662 *
7663 * No longer necessary since we fill in all our data. Purge before merging
7664 * patch officially.
7665 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7666 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7667 */
7668
7669 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7670
7671 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7672 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7673 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7674
7675 /* Big bitfield of all the fields we provide in radiotap */
7676 ipw_rt->rt_hdr.it_present =
7677 ((1 << IEEE80211_RADIOTAP_FLAGS) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007678 (1 << IEEE80211_RADIOTAP_TSFT) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007679 (1 << IEEE80211_RADIOTAP_RATE) |
7680 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7681 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007682 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007683 (1 << IEEE80211_RADIOTAP_ANTENNA));
7684
7685 /* Zero the flags, we'll add to them as we go */
7686 ipw_rt->rt_flags = 0;
7687
7688 /* Convert signal to DBM */
7689 ipw_rt->rt_dbmsignal = antsignal;
7690
7691 /* Convert the channel data and set the flags */
7692 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7693 if (received_channel > 14) { /* 802.11a */
7694 ipw_rt->rt_chbitmask =
7695 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7696 } else if (antennaAndPhy & 32) { /* 802.11b */
7697 ipw_rt->rt_chbitmask =
7698 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7699 } else { /* 802.11g */
7700 ipw_rt->rt_chbitmask =
7701 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7702 }
7703
7704 /* set the rate in multiples of 500k/s */
7705 switch (pktrate) {
7706 case IPW_TX_RATE_1MB:
7707 ipw_rt->rt_rate = 2;
7708 break;
7709 case IPW_TX_RATE_2MB:
7710 ipw_rt->rt_rate = 4;
7711 break;
7712 case IPW_TX_RATE_5MB:
7713 ipw_rt->rt_rate = 10;
7714 break;
7715 case IPW_TX_RATE_6MB:
7716 ipw_rt->rt_rate = 12;
7717 break;
7718 case IPW_TX_RATE_9MB:
7719 ipw_rt->rt_rate = 18;
7720 break;
7721 case IPW_TX_RATE_11MB:
7722 ipw_rt->rt_rate = 22;
7723 break;
7724 case IPW_TX_RATE_12MB:
7725 ipw_rt->rt_rate = 24;
7726 break;
7727 case IPW_TX_RATE_18MB:
7728 ipw_rt->rt_rate = 36;
7729 break;
7730 case IPW_TX_RATE_24MB:
7731 ipw_rt->rt_rate = 48;
7732 break;
7733 case IPW_TX_RATE_36MB:
7734 ipw_rt->rt_rate = 72;
7735 break;
7736 case IPW_TX_RATE_48MB:
7737 ipw_rt->rt_rate = 96;
7738 break;
7739 case IPW_TX_RATE_54MB:
7740 ipw_rt->rt_rate = 108;
7741 break;
7742 default:
7743 ipw_rt->rt_rate = 0;
7744 break;
7745 }
7746
7747 /* antenna number */
7748 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7749
7750 /* set the preamble flag if we have it */
7751 if ((antennaAndPhy & 64))
7752 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7753
7754 /* Set the size of the skb to the size of the frame */
7755 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007756
7757 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7758
7759 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7760 priv->ieee->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007761 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007762 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007763 /* no LED during capture */
7764 }
7765}
7766#endif
7767
Zhu Yid685b8c2006-04-13 17:20:27 +08007768#ifdef CONFIG_IPW2200_PROMISCUOUS
7769#define ieee80211_is_probe_response(fc) \
7770 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7771 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7772
7773#define ieee80211_is_management(fc) \
7774 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7775
7776#define ieee80211_is_control(fc) \
7777 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7778
7779#define ieee80211_is_data(fc) \
7780 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
7781
7782#define ieee80211_is_assoc_request(fc) \
7783 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
7784
7785#define ieee80211_is_reassoc_request(fc) \
7786 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
7787
7788static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
7789 struct ipw_rx_mem_buffer *rxb,
7790 struct ieee80211_rx_stats *stats)
7791{
7792 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7793 struct ipw_rx_frame *frame = &pkt->u.frame;
7794 struct ipw_rt_hdr *ipw_rt;
7795
7796 /* First cache any information we need before we overwrite
7797 * the information provided in the skb from the hardware */
7798 struct ieee80211_hdr *hdr;
7799 u16 channel = frame->received_channel;
7800 u8 phy_flags = frame->antennaAndPhy;
7801 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
7802 s8 noise = frame->noise;
7803 u8 rate = frame->rate;
7804 short len = le16_to_cpu(pkt->u.frame.length);
7805 u64 tsf = 0;
7806 struct sk_buff *skb;
7807 int hdr_only = 0;
7808 u16 filter = priv->prom_priv->filter;
7809
7810 /* If the filter is set to not include Rx frames then return */
7811 if (filter & IPW_PROM_NO_RX)
7812 return;
7813
Zhu Yid685b8c2006-04-13 17:20:27 +08007814 /* We received data from the HW, so stop the watchdog */
7815 priv->prom_net_dev->trans_start = jiffies;
7816
7817 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
7818 priv->prom_priv->ieee->stats.rx_errors++;
7819 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7820 return;
7821 }
7822
7823 /* We only process data packets if the interface is open */
7824 if (unlikely(!netif_running(priv->prom_net_dev))) {
7825 priv->prom_priv->ieee->stats.rx_dropped++;
7826 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7827 return;
7828 }
7829
7830 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7831 * that now */
7832 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7833 /* FIXME: Should alloc bigger skb instead */
7834 priv->prom_priv->ieee->stats.rx_dropped++;
7835 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7836 return;
7837 }
7838
7839 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
7840 if (ieee80211_is_management(hdr->frame_ctl)) {
7841 if (filter & IPW_PROM_NO_MGMT)
7842 return;
7843 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
7844 hdr_only = 1;
7845 } else if (ieee80211_is_control(hdr->frame_ctl)) {
7846 if (filter & IPW_PROM_NO_CTL)
7847 return;
7848 if (filter & IPW_PROM_CTL_HEADER_ONLY)
7849 hdr_only = 1;
7850 } else if (ieee80211_is_data(hdr->frame_ctl)) {
7851 if (filter & IPW_PROM_NO_DATA)
7852 return;
7853 if (filter & IPW_PROM_DATA_HEADER_ONLY)
7854 hdr_only = 1;
7855 }
7856
7857 /* Copy the SKB since this is for the promiscuous side */
7858 skb = skb_copy(rxb->skb, GFP_ATOMIC);
7859 if (skb == NULL) {
7860 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
7861 return;
7862 }
7863
7864 /* copy the frame data to write after where the radiotap header goes */
7865 ipw_rt = (void *)skb->data;
7866
7867 if (hdr_only)
7868 len = ieee80211_get_hdrlen(hdr->frame_ctl);
7869
7870 memcpy(ipw_rt->payload, hdr, len);
7871
7872 /* Zero the radiotap static buffer ... We only need to zero the bytes
7873 * NOT part of our real header, saves a little time.
7874 *
7875 * No longer necessary since we fill in all our data. Purge before
7876 * merging patch officially.
7877 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7878 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7879 */
7880
7881 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7882 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7883 ipw_rt->rt_hdr.it_len = sizeof(*ipw_rt); /* total header+data */
7884
7885 /* Set the size of the skb to the size of the frame */
7886 skb_put(skb, ipw_rt->rt_hdr.it_len + len);
7887
7888 /* Big bitfield of all the fields we provide in radiotap */
7889 ipw_rt->rt_hdr.it_present =
7890 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7891 (1 << IEEE80211_RADIOTAP_TSFT) |
7892 (1 << IEEE80211_RADIOTAP_RATE) |
7893 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7894 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7895 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
7896 (1 << IEEE80211_RADIOTAP_ANTENNA));
7897
7898 /* Zero the flags, we'll add to them as we go */
7899 ipw_rt->rt_flags = 0;
7900
7901 ipw_rt->rt_tsf = tsf;
7902
7903 /* Convert to DBM */
7904 ipw_rt->rt_dbmsignal = signal;
7905 ipw_rt->rt_dbmnoise = noise;
7906
7907 /* Convert the channel data and set the flags */
7908 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
7909 if (channel > 14) { /* 802.11a */
7910 ipw_rt->rt_chbitmask =
7911 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7912 } else if (phy_flags & (1 << 5)) { /* 802.11b */
7913 ipw_rt->rt_chbitmask =
7914 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7915 } else { /* 802.11g */
7916 ipw_rt->rt_chbitmask =
7917 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7918 }
7919
7920 /* set the rate in multiples of 500k/s */
7921 switch (rate) {
7922 case IPW_TX_RATE_1MB:
7923 ipw_rt->rt_rate = 2;
7924 break;
7925 case IPW_TX_RATE_2MB:
7926 ipw_rt->rt_rate = 4;
7927 break;
7928 case IPW_TX_RATE_5MB:
7929 ipw_rt->rt_rate = 10;
7930 break;
7931 case IPW_TX_RATE_6MB:
7932 ipw_rt->rt_rate = 12;
7933 break;
7934 case IPW_TX_RATE_9MB:
7935 ipw_rt->rt_rate = 18;
7936 break;
7937 case IPW_TX_RATE_11MB:
7938 ipw_rt->rt_rate = 22;
7939 break;
7940 case IPW_TX_RATE_12MB:
7941 ipw_rt->rt_rate = 24;
7942 break;
7943 case IPW_TX_RATE_18MB:
7944 ipw_rt->rt_rate = 36;
7945 break;
7946 case IPW_TX_RATE_24MB:
7947 ipw_rt->rt_rate = 48;
7948 break;
7949 case IPW_TX_RATE_36MB:
7950 ipw_rt->rt_rate = 72;
7951 break;
7952 case IPW_TX_RATE_48MB:
7953 ipw_rt->rt_rate = 96;
7954 break;
7955 case IPW_TX_RATE_54MB:
7956 ipw_rt->rt_rate = 108;
7957 break;
7958 default:
7959 ipw_rt->rt_rate = 0;
7960 break;
7961 }
7962
7963 /* antenna number */
7964 ipw_rt->rt_antenna = (phy_flags & 3);
7965
7966 /* set the preamble flag if we have it */
7967 if (phy_flags & (1 << 6))
7968 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7969
7970 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
7971
7972 if (!ieee80211_rx(priv->prom_priv->ieee, skb, stats)) {
7973 priv->prom_priv->ieee->stats.rx_errors++;
7974 dev_kfree_skb_any(skb);
7975 }
7976}
7977#endif
7978
Arjan van de Ven858119e2006-01-14 13:20:43 -08007979static int is_network_packet(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007980 struct ieee80211_hdr_4addr *header)
7981{
7982 /* Filter incoming packets to determine if they are targetted toward
7983 * this network, discarding packets coming from ourselves */
7984 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05007985 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007986 /* packets from our adapter are dropped (echo) */
7987 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7988 return 0;
7989
Peter Jones90700fd2005-08-26 16:51:06 -05007990 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007991 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05007992 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007993
7994 /* packets to our adapter go through */
7995 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7996 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007997
Peter Jones90700fd2005-08-26 16:51:06 -05007998 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007999 /* packets from our adapter are dropped (echo) */
8000 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
8001 return 0;
8002
Peter Jones90700fd2005-08-26 16:51:06 -05008003 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08008004 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05008005 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
8006
8007 /* packets to our adapter go through */
8008 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8009 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008010 }
James Ketrenosa613bff2005-08-24 21:43:11 -05008011
James Ketrenosea2b26e2005-08-24 21:25:16 -05008012 return 1;
8013}
8014
James Ketrenosafbf30a2005-08-25 00:05:33 -05008015#define IPW_PACKET_RETRY_TIME HZ
8016
Arjan van de Ven858119e2006-01-14 13:20:43 -08008017static int is_duplicate_packet(struct ipw_priv *priv,
James Ketrenosafbf30a2005-08-25 00:05:33 -05008018 struct ieee80211_hdr_4addr *header)
8019{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008020 u16 sc = le16_to_cpu(header->seq_ctl);
8021 u16 seq = WLAN_GET_SEQ_SEQ(sc);
8022 u16 frag = WLAN_GET_SEQ_FRAG(sc);
8023 u16 *last_seq, *last_frag;
8024 unsigned long *last_time;
8025
8026 switch (priv->ieee->iw_mode) {
8027 case IW_MODE_ADHOC:
8028 {
8029 struct list_head *p;
8030 struct ipw_ibss_seq *entry = NULL;
8031 u8 *mac = header->addr2;
8032 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8033
8034 __list_for_each(p, &priv->ibss_mac_hash[index]) {
8035 entry =
8036 list_entry(p, struct ipw_ibss_seq, list);
8037 if (!memcmp(entry->mac, mac, ETH_ALEN))
8038 break;
8039 }
8040 if (p == &priv->ibss_mac_hash[index]) {
8041 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
8042 if (!entry) {
8043 IPW_ERROR
8044 ("Cannot malloc new mac entry\n");
8045 return 0;
8046 }
8047 memcpy(entry->mac, mac, ETH_ALEN);
8048 entry->seq_num = seq;
8049 entry->frag_num = frag;
8050 entry->packet_time = jiffies;
8051 list_add(&entry->list,
8052 &priv->ibss_mac_hash[index]);
8053 return 0;
8054 }
8055 last_seq = &entry->seq_num;
8056 last_frag = &entry->frag_num;
8057 last_time = &entry->packet_time;
8058 break;
8059 }
8060 case IW_MODE_INFRA:
8061 last_seq = &priv->last_seq_num;
8062 last_frag = &priv->last_frag_num;
8063 last_time = &priv->last_packet_time;
8064 break;
8065 default:
8066 return 0;
8067 }
8068 if ((*last_seq == seq) &&
8069 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8070 if (*last_frag == frag)
8071 goto drop;
8072 if (*last_frag + 1 != frag)
8073 /* out-of-order fragment */
8074 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008075 } else
8076 *last_seq = seq;
8077
Zhu Yif57ce7c2005-07-13 12:22:15 -05008078 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008079 *last_time = jiffies;
8080 return 0;
8081
8082 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08008083 /* Comment this line now since we observed the card receives
8084 * duplicate packets but the FCTL_RETRY bit is not set in the
8085 * IBSS mode with fragmentation enabled.
8086 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008087 return 1;
8088}
8089
James Ketrenosb095c382005-08-24 22:04:42 -05008090static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8091 struct ipw_rx_mem_buffer *rxb,
8092 struct ieee80211_rx_stats *stats)
8093{
8094 struct sk_buff *skb = rxb->skb;
8095 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
8096 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
8097 (skb->data + IPW_RX_FRAME_SIZE);
8098
8099 ieee80211_rx_mgt(priv->ieee, header, stats);
8100
8101 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8102 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8103 IEEE80211_STYPE_PROBE_RESP) ||
8104 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8105 IEEE80211_STYPE_BEACON))) {
8106 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8107 ipw_add_station(priv, header->addr2);
8108 }
8109
8110 if (priv->config & CFG_NET_STATS) {
8111 IPW_DEBUG_HC("sending stat packet\n");
8112
8113 /* Set the size of the skb to the size of the full
8114 * ipw header and 802.11 frame */
8115 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8116 IPW_RX_FRAME_SIZE);
8117
8118 /* Advance past the ipw packet header to the 802.11 frame */
8119 skb_pull(skb, IPW_RX_FRAME_SIZE);
8120
8121 /* Push the ieee80211_rx_stats before the 802.11 frame */
8122 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8123
8124 skb->dev = priv->ieee->dev;
8125
8126 /* Point raw at the ieee80211_stats */
8127 skb->mac.raw = skb->data;
8128
8129 skb->pkt_type = PACKET_OTHERHOST;
8130 skb->protocol = __constant_htons(ETH_P_80211_STATS);
8131 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8132 netif_rx(skb);
8133 rxb->skb = NULL;
8134 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008135}
8136
James Ketrenos43f66a62005-03-25 12:31:53 -06008137/*
8138 * Main entry function for recieving a packet with 80211 headers. This
8139 * should be called when ever the FW has notified us that there is a new
8140 * skb in the recieve queue.
8141 */
8142static void ipw_rx(struct ipw_priv *priv)
8143{
8144 struct ipw_rx_mem_buffer *rxb;
8145 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05008146 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06008147 u32 r, w, i;
8148 u8 network_packet;
8149
James Ketrenosb095c382005-08-24 22:04:42 -05008150 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8151 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
James Ketrenos43f66a62005-03-25 12:31:53 -06008152 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
8153
8154 while (i != r) {
8155 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06008156 if (unlikely(rxb == NULL)) {
8157 printk(KERN_CRIT "Queue not allocated!\n");
8158 break;
8159 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008160 priv->rxq->queue[i] = NULL;
8161
8162 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008163 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06008164 PCI_DMA_FROMDEVICE);
8165
8166 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8167 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8168 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008169 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008170
8171 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008172 case RX_FRAME_TYPE: /* 802.11 frame */ {
8173 struct ieee80211_rx_stats stats = {
James Ketrenosc848d0a2005-08-24 21:56:24 -05008174 .rssi =
8175 le16_to_cpu(pkt->u.frame.rssi_dbm) -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008176 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008177 .signal =
Bill Mossb1916082006-02-15 08:50:18 +08008178 le16_to_cpu(pkt->u.frame.rssi_dbm) -
8179 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008180 .noise =
8181 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008182 .rate = pkt->u.frame.rate,
8183 .mac_time = jiffies,
8184 .received_channel =
8185 pkt->u.frame.received_channel,
8186 .freq =
8187 (pkt->u.frame.
8188 control & (1 << 0)) ?
8189 IEEE80211_24GHZ_BAND :
8190 IEEE80211_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008191 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008192 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008193
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008194 if (stats.rssi != 0)
8195 stats.mask |= IEEE80211_STATMASK_RSSI;
8196 if (stats.signal != 0)
8197 stats.mask |= IEEE80211_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008198 if (stats.noise != 0)
8199 stats.mask |= IEEE80211_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008200 if (stats.rate != 0)
8201 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008202
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008203 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008204
Zhu Yid685b8c2006-04-13 17:20:27 +08008205#ifdef CONFIG_IPW2200_PROMISCUOUS
8206 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8207 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8208#endif
8209
James Ketrenosb095c382005-08-24 22:04:42 -05008210#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008211 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08008212#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yid685b8c2006-04-13 17:20:27 +08008213
8214 ipw_handle_data_packet_monitor(priv,
8215 rxb,
8216 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008217#else
Zhu Yid685b8c2006-04-13 17:20:27 +08008218 ipw_handle_data_packet(priv, rxb,
8219 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008220#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008221 break;
8222 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008223#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008224
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008225 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05008226 (struct ieee80211_hdr_4addr *)(rxb->skb->
8227 data +
8228 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008229 /* TODO: Check Ad-Hoc dest/source and make sure
8230 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008231 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008232 * frame control of the packet and disregard
8233 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008234
James Ketrenosea2b26e2005-08-24 21:25:16 -05008235 network_packet =
8236 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008237 if (network_packet && priv->assoc_network) {
8238 priv->assoc_network->stats.rssi =
8239 stats.rssi;
Zhu Yi00d21de2006-04-13 17:19:02 +08008240 priv->exp_avg_rssi =
8241 exponential_average(priv->exp_avg_rssi,
8242 stats.rssi, DEPTH_RSSI);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008243 }
8244
8245 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008246 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008247
James Ketrenosa613bff2005-08-24 21:43:11 -05008248 if (le16_to_cpu(pkt->u.frame.length) <
Zhu Yi9d0be032006-02-15 06:18:19 +08008249 ieee80211_get_hdrlen(le16_to_cpu(
8250 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008251 IPW_DEBUG_DROP
8252 ("Received packet is too small. "
8253 "Dropping.\n");
8254 priv->ieee->stats.rx_errors++;
8255 priv->wstats.discard.misc++;
8256 break;
8257 }
8258
James Ketrenosa613bff2005-08-24 21:43:11 -05008259 switch (WLAN_FC_GET_TYPE
8260 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008261
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008262 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008263 ipw_handle_mgmt_packet(priv, rxb,
8264 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008265 break;
8266
8267 case IEEE80211_FTYPE_CTL:
8268 break;
8269
8270 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008271 if (unlikely(!network_packet ||
8272 is_duplicate_packet(priv,
8273 header)))
8274 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008275 IPW_DEBUG_DROP("Dropping: "
8276 MAC_FMT ", "
8277 MAC_FMT ", "
8278 MAC_FMT "\n",
8279 MAC_ARG(header->
8280 addr1),
8281 MAC_ARG(header->
8282 addr2),
8283 MAC_ARG(header->
8284 addr3));
James Ketrenosb095c382005-08-24 22:04:42 -05008285 break;
8286 }
8287
8288 ipw_handle_data_packet(priv, rxb,
8289 &stats);
8290
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008291 break;
8292 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008293 break;
8294 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008295
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008296 case RX_HOST_NOTIFICATION_TYPE:{
8297 IPW_DEBUG_RX
8298 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008299 pkt->u.notification.subtype,
8300 pkt->u.notification.flags,
8301 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008302 ipw_rx_notification(priv, &pkt->u.notification);
8303 break;
8304 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008305
8306 default:
8307 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8308 pkt->header.message_type);
8309 break;
8310 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008311
8312 /* For now we just don't re-use anything. We can tweak this
8313 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008314 * fail to Rx correctly */
8315 if (rxb->skb != NULL) {
8316 dev_kfree_skb_any(rxb->skb);
8317 rxb->skb = NULL;
8318 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008319
James Ketrenos43f66a62005-03-25 12:31:53 -06008320 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008321 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008322 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008323
James Ketrenos43f66a62005-03-25 12:31:53 -06008324 i = (i + 1) % RX_QUEUE_SIZE;
8325 }
8326
8327 /* Backtrack one entry */
8328 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
8329
8330 ipw_rx_queue_restock(priv);
8331}
8332
James Ketrenosafbf30a2005-08-25 00:05:33 -05008333#define DEFAULT_RTS_THRESHOLD 2304U
8334#define MIN_RTS_THRESHOLD 1U
8335#define MAX_RTS_THRESHOLD 2304U
8336#define DEFAULT_BEACON_INTERVAL 100U
8337#define DEFAULT_SHORT_RETRY_LIMIT 7U
8338#define DEFAULT_LONG_RETRY_LIMIT 4U
8339
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008340/**
8341 * ipw_sw_reset
8342 * @option: options to control different reset behaviour
8343 * 0 = reset everything except the 'disable' module_param
8344 * 1 = reset everything and print out driver info (for probe only)
8345 * 2 = reset everything
8346 */
8347static int ipw_sw_reset(struct ipw_priv *priv, int option)
James Ketrenos43f66a62005-03-25 12:31:53 -06008348{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008349 int band, modulation;
8350 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008351
James Ketrenosafbf30a2005-08-25 00:05:33 -05008352 /* Initialize module parameter values here */
8353 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008354
James Ketrenosafbf30a2005-08-25 00:05:33 -05008355 /* We default to disabling the LED code as right now it causes
8356 * too many systems to lock up... */
8357 if (!led)
8358 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008359
James Ketrenosafbf30a2005-08-25 00:05:33 -05008360 if (associate)
8361 priv->config |= CFG_ASSOCIATE;
8362 else
8363 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008364
James Ketrenosafbf30a2005-08-25 00:05:33 -05008365 if (auto_create)
8366 priv->config |= CFG_ADHOC_CREATE;
8367 else
8368 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8369
Zhu Yi17ed0812006-01-24 16:36:31 +08008370 priv->config &= ~CFG_STATIC_ESSID;
8371 priv->essid_len = 0;
8372 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8373
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008374 if (disable && option) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008375 priv->status |= STATUS_RF_KILL_SW;
8376 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008377 }
8378
James Ketrenosafbf30a2005-08-25 00:05:33 -05008379 if (channel != 0) {
8380 priv->config |= CFG_STATIC_CHANNEL;
8381 priv->channel = channel;
8382 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8383 /* TODO: Validate that provided channel is in range */
8384 }
Zhu Yie43e3c12006-04-13 17:20:45 +08008385#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05008386 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8387 burst_duration_CCK, burst_duration_OFDM);
Zhu Yie43e3c12006-04-13 17:20:45 +08008388#endif /* CONFIG_IPW2200_QOS */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008389
8390 switch (mode) {
8391 case 1:
8392 priv->ieee->iw_mode = IW_MODE_ADHOC;
8393 priv->net_dev->type = ARPHRD_ETHER;
8394
8395 break;
8396#ifdef CONFIG_IPW2200_MONITOR
8397 case 2:
8398 priv->ieee->iw_mode = IW_MODE_MONITOR;
Zhu Yi459d4082006-04-13 17:21:00 +08008399#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008400 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8401#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008402 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008403#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008404 break;
8405#endif
8406 default:
8407 case 0:
8408 priv->net_dev->type = ARPHRD_ETHER;
8409 priv->ieee->iw_mode = IW_MODE_INFRA;
8410 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008411 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008412
James Ketrenosafbf30a2005-08-25 00:05:33 -05008413 if (hwcrypto) {
8414 priv->ieee->host_encrypt = 0;
8415 priv->ieee->host_encrypt_msdu = 0;
8416 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008417 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008418 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008419 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008420
Zhu Yie402c932005-08-05 17:20:40 +08008421 /* IPW2200/2915 is abled to do hardware fragmentation. */
8422 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008423
James Ketrenosafbf30a2005-08-25 00:05:33 -05008424 if ((priv->pci_dev->device == 0x4223) ||
8425 (priv->pci_dev->device == 0x4224)) {
Zhu Yie8c69e22006-02-17 08:25:12 +08008426 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008427 printk(KERN_INFO DRV_NAME
8428 ": Detected Intel PRO/Wireless 2915ABG Network "
8429 "Connection\n");
8430 priv->ieee->abg_true = 1;
8431 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8432 modulation = IEEE80211_OFDM_MODULATION |
8433 IEEE80211_CCK_MODULATION;
8434 priv->adapter = IPW_2915ABG;
8435 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008436 } else {
Zhu Yie8c69e22006-02-17 08:25:12 +08008437 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008438 printk(KERN_INFO DRV_NAME
8439 ": Detected Intel PRO/Wireless 2200BG Network "
8440 "Connection\n");
8441
8442 priv->ieee->abg_true = 0;
8443 band = IEEE80211_24GHZ_BAND;
8444 modulation = IEEE80211_OFDM_MODULATION |
8445 IEEE80211_CCK_MODULATION;
8446 priv->adapter = IPW_2200BG;
8447 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008448 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008449
James Ketrenosafbf30a2005-08-25 00:05:33 -05008450 priv->ieee->freq_band = band;
8451 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008452
James Ketrenosafbf30a2005-08-25 00:05:33 -05008453 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008454
James Ketrenosafbf30a2005-08-25 00:05:33 -05008455 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8456 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008457
James Ketrenosafbf30a2005-08-25 00:05:33 -05008458 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8459 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8460 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008461
James Ketrenosafbf30a2005-08-25 00:05:33 -05008462 /* If power management is turned on, default to AC mode */
8463 priv->power_mode = IPW_POWER_AC;
8464 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008465
Zhu Yi0ece35b2005-08-05 17:26:51 +08008466 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008467}
8468
8469/*
8470 * This file defines the Wireless Extension handlers. It does not
8471 * define any methods of hardware manipulation and relies on the
8472 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008473 *
8474 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008475 * function used to poll the hardware vs. making unecessary calls.
8476 *
8477 */
8478
Jeff Garzikbf794512005-07-31 13:07:26 -04008479static int ipw_wx_get_name(struct net_device *dev,
8480 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008481 union iwreq_data *wrqu, char *extra)
8482{
8483 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008484 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008485 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -05008486 strcpy(wrqu->name, "radio off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008487 else if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06008488 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04008489 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008490 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8491 ipw_modes[priv->assoc_request.ieee_mode]);
8492 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
Zhu Yi46441512006-01-24 16:37:59 +08008493 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008494 return 0;
8495}
8496
8497static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8498{
8499 if (channel == 0) {
8500 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8501 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008502 IPW_DEBUG_ASSOC("Attempting to associate with new "
8503 "parameters.\n");
8504 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008505 return 0;
8506 }
8507
8508 priv->config |= CFG_STATIC_CHANNEL;
8509
8510 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008511 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8512 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008513 return 0;
8514 }
8515
8516 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8517 priv->channel = channel;
8518
James Ketrenosb095c382005-08-24 22:04:42 -05008519#ifdef CONFIG_IPW2200_MONITOR
8520 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008521 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008522 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008523 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008524 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008525 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008526 }
8527
8528 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8529 udelay(10);
8530
8531 if (priv->status & STATUS_SCANNING)
8532 IPW_DEBUG_SCAN("Still scanning...\n");
8533 else
8534 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8535 1000 - i);
8536
8537 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008538 }
James Ketrenosb095c382005-08-24 22:04:42 -05008539#endif /* CONFIG_IPW2200_MONITOR */
8540
James Ketrenosc848d0a2005-08-24 21:56:24 -05008541 /* Network configuration changed -- force [re]association */
8542 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8543 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008544 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008545
8546 return 0;
8547}
8548
Jeff Garzikbf794512005-07-31 13:07:26 -04008549static int ipw_wx_set_freq(struct net_device *dev,
8550 struct iw_request_info *info,
8551 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008552{
8553 struct ipw_priv *priv = ieee80211_priv(dev);
Larry Finger1867b112006-02-28 09:48:28 -06008554 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008555 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008556 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008557 u8 channel, flags;
8558 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008559
James Ketrenosb095c382005-08-24 22:04:42 -05008560 if (fwrq->m == 0) {
8561 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008562 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008563 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008564 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008565 return ret;
8566 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008567 /* if setting by freq convert to channel */
8568 if (fwrq->e == 1) {
Larry Finger1867b112006-02-28 09:48:28 -06008569 channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008570 if (channel == 0)
8571 return -EINVAL;
8572 } else
8573 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008574
Larry Finger1867b112006-02-28 09:48:28 -06008575 if (!(band = ieee80211_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008576 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008577
Liu Hong1fe0adb2005-08-19 09:33:10 -05008578 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
Larry Finger1867b112006-02-28 09:48:28 -06008579 i = ieee80211_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008580 if (i == -1)
8581 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008582
8583 flags = (band == IEEE80211_24GHZ_BAND) ?
8584 geo->bg[i].flags : geo->a[i].flags;
8585 if (flags & IEEE80211_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008586 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8587 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008588 }
8589 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008590
James Ketrenos43f66a62005-03-25 12:31:53 -06008591 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008592 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008593 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008594 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008595 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008596}
8597
Jeff Garzikbf794512005-07-31 13:07:26 -04008598static int ipw_wx_get_freq(struct net_device *dev,
8599 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008600 union iwreq_data *wrqu, char *extra)
8601{
8602 struct ipw_priv *priv = ieee80211_priv(dev);
8603
8604 wrqu->freq.e = 0;
8605
8606 /* If we are associated, trying to associate, or have a statically
8607 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008608 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008609 if (priv->config & CFG_STATIC_CHANNEL ||
8610 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8611 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04008612 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008613 wrqu->freq.m = 0;
8614
Zhu Yi46441512006-01-24 16:37:59 +08008615 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008616 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8617 return 0;
8618}
8619
Jeff Garzikbf794512005-07-31 13:07:26 -04008620static int ipw_wx_set_mode(struct net_device *dev,
8621 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008622 union iwreq_data *wrqu, char *extra)
8623{
8624 struct ipw_priv *priv = ieee80211_priv(dev);
8625 int err = 0;
8626
8627 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8628
James Ketrenos43f66a62005-03-25 12:31:53 -06008629 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008630#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008631 case IW_MODE_MONITOR:
8632#endif
8633 case IW_MODE_ADHOC:
8634 case IW_MODE_INFRA:
8635 break;
8636 case IW_MODE_AUTO:
8637 wrqu->mode = IW_MODE_INFRA;
8638 break;
8639 default:
8640 return -EINVAL;
8641 }
James Ketrenosb095c382005-08-24 22:04:42 -05008642 if (wrqu->mode == priv->ieee->iw_mode)
8643 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008644
Zhu Yi46441512006-01-24 16:37:59 +08008645 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008646
8647 ipw_sw_reset(priv, 0);
8648
James Ketrenosb095c382005-08-24 22:04:42 -05008649#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008650 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008651 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008652
8653 if (wrqu->mode == IW_MODE_MONITOR)
Zhu Yi459d4082006-04-13 17:21:00 +08008654#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008655 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8656#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008657 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008658#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008659#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008660
Jeff Garzikbf794512005-07-31 13:07:26 -04008661 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06008662 * flag so ipw_load() will bring in the new firmawre */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008663 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008664
8665 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008666
James Ketrenosc848d0a2005-08-24 21:56:24 -05008667 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008668 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008669 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008670}
8671
Jeff Garzikbf794512005-07-31 13:07:26 -04008672static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008673 struct iw_request_info *info,
8674 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008675{
8676 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008677 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008678 wrqu->mode = priv->ieee->iw_mode;
8679 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008680 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008681 return 0;
8682}
8683
James Ketrenos43f66a62005-03-25 12:31:53 -06008684/* Values are in microsecond */
8685static const s32 timeout_duration[] = {
8686 350000,
8687 250000,
8688 75000,
8689 37000,
8690 25000,
8691};
8692
8693static const s32 period_duration[] = {
8694 400000,
8695 700000,
8696 1000000,
8697 1000000,
8698 1000000
8699};
8700
Jeff Garzikbf794512005-07-31 13:07:26 -04008701static int ipw_wx_get_range(struct net_device *dev,
8702 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008703 union iwreq_data *wrqu, char *extra)
8704{
8705 struct ipw_priv *priv = ieee80211_priv(dev);
8706 struct iw_range *range = (struct iw_range *)extra;
Larry Finger1867b112006-02-28 09:48:28 -06008707 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008708 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008709
8710 wrqu->data.length = sizeof(*range);
8711 memset(range, 0, sizeof(*range));
8712
8713 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008714 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008715
8716 range->max_qual.qual = 100;
8717 /* TODO: Find real max RSSI and stick here */
8718 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008719 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008720 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008721
8722 range->avg_qual.qual = 70;
8723 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008724 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008725 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008726 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008727 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008728 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008729
Jeff Garzikbf794512005-07-31 13:07:26 -04008730 for (i = 0; i < range->num_bitrates; i++)
8731 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008732 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008733
James Ketrenos43f66a62005-03-25 12:31:53 -06008734 range->max_rts = DEFAULT_RTS_THRESHOLD;
8735 range->min_frag = MIN_FRAG_THRESHOLD;
8736 range->max_frag = MAX_FRAG_THRESHOLD;
8737
8738 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008739 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008740 range->num_encoding_sizes = 2;
8741 range->max_encoding_tokens = WEP_KEYS;
8742
8743 /* Set the Wireless Extension versions */
8744 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008745 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008746
James Ketrenosb095c382005-08-24 22:04:42 -05008747 i = 0;
8748 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
Zhu Yie815de42006-03-02 05:55:51 +08008749 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8750 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8751 (geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8752 continue;
8753
James Ketrenosb095c382005-08-24 22:04:42 -05008754 range->freq[i].i = geo->bg[j].channel;
8755 range->freq[i].m = geo->bg[j].freq * 100000;
8756 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008757 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008758 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008759 }
James Ketrenosb095c382005-08-24 22:04:42 -05008760
8761 if (priv->ieee->mode & IEEE_A) {
Zhu Yie815de42006-03-02 05:55:51 +08008762 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8763 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8764 (geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8765 continue;
8766
James Ketrenosb095c382005-08-24 22:04:42 -05008767 range->freq[i].i = geo->a[j].channel;
8768 range->freq[i].m = geo->a[j].freq * 100000;
8769 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008770 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008771 }
8772 }
8773
8774 range->num_channels = i;
8775 range->num_frequency = i;
8776
Zhu Yi46441512006-01-24 16:37:59 +08008777 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008778
8779 /* Event capability (kernel + driver) */
8780 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8781 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
Zhu Yi07f02e42006-04-13 17:19:25 +08008782 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
8783 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008784 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008785
Dan Williamsf1b50862006-01-30 13:58:56 -05008786 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8787 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8788
James Ketrenos43f66a62005-03-25 12:31:53 -06008789 IPW_DEBUG_WX("GET Range\n");
8790 return 0;
8791}
8792
Jeff Garzikbf794512005-07-31 13:07:26 -04008793static int ipw_wx_set_wap(struct net_device *dev,
8794 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008795 union iwreq_data *wrqu, char *extra)
8796{
8797 struct ipw_priv *priv = ieee80211_priv(dev);
8798
8799 static const unsigned char any[] = {
8800 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8801 };
8802 static const unsigned char off[] = {
8803 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8804 };
8805
Jeff Garzikbf794512005-07-31 13:07:26 -04008806 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06008807 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08008808 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008809 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8810 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8811 /* we disable mandatory BSSID association */
8812 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8813 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008814 IPW_DEBUG_ASSOC("Attempting to associate with new "
8815 "parameters.\n");
8816 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08008817 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008818 return 0;
8819 }
8820
8821 priv->config |= CFG_STATIC_BSSID;
8822 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8823 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008824 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008825 return 0;
8826 }
8827
8828 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8829 MAC_ARG(wrqu->ap_addr.sa_data));
8830
8831 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8832
James Ketrenosc848d0a2005-08-24 21:56:24 -05008833 /* Network configuration changed -- force [re]association */
8834 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8835 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008836 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008837
Zhu Yi46441512006-01-24 16:37:59 +08008838 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008839 return 0;
8840}
8841
Jeff Garzikbf794512005-07-31 13:07:26 -04008842static int ipw_wx_get_wap(struct net_device *dev,
8843 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008844 union iwreq_data *wrqu, char *extra)
8845{
8846 struct ipw_priv *priv = ieee80211_priv(dev);
8847 /* If we are associated, trying to associate, or have a statically
8848 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008849 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04008850 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06008851 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8852 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008853 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06008854 } else
8855 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8856
8857 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8858 MAC_ARG(wrqu->ap_addr.sa_data));
Zhu Yi46441512006-01-24 16:37:59 +08008859 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008860 return 0;
8861}
8862
Jeff Garzikbf794512005-07-31 13:07:26 -04008863static int ipw_wx_set_essid(struct net_device *dev,
8864 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008865 union iwreq_data *wrqu, char *extra)
8866{
8867 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008868 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06008869 int length = 0;
Zhu Yi46441512006-01-24 16:37:59 +08008870 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008871 if (wrqu->essid.flags && wrqu->essid.length) {
8872 length = wrqu->essid.length - 1;
8873 essid = extra;
8874 }
8875 if (length == 0) {
8876 IPW_DEBUG_WX("Setting ESSID to ANY\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008877 if ((priv->config & CFG_STATIC_ESSID) &&
8878 !(priv->status & (STATUS_ASSOCIATED |
James Ketrenos43f66a62005-03-25 12:31:53 -06008879 STATUS_ASSOCIATING))) {
8880 IPW_DEBUG_ASSOC("Attempting to associate with new "
8881 "parameters.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008882 priv->config &= ~CFG_STATIC_ESSID;
James Ketrenos43f66a62005-03-25 12:31:53 -06008883 ipw_associate(priv);
8884 }
Zhu Yi46441512006-01-24 16:37:59 +08008885 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008886 return 0;
8887 }
8888
8889 length = min(length, IW_ESSID_MAX_SIZE);
8890
8891 priv->config |= CFG_STATIC_ESSID;
8892
8893 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8894 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008895 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008896 return 0;
8897 }
8898
8899 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8900 length);
8901
8902 priv->essid_len = length;
8903 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04008904
James Ketrenosc848d0a2005-08-24 21:56:24 -05008905 /* Network configuration changed -- force [re]association */
8906 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8907 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008908 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008909
Zhu Yi46441512006-01-24 16:37:59 +08008910 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008911 return 0;
8912}
8913
Jeff Garzikbf794512005-07-31 13:07:26 -04008914static int ipw_wx_get_essid(struct net_device *dev,
8915 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008916 union iwreq_data *wrqu, char *extra)
8917{
8918 struct ipw_priv *priv = ieee80211_priv(dev);
8919
8920 /* If we are associated, trying to associate, or have a statically
8921 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008922 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008923 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04008924 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8925 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008926 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04008927 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06008928 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008929 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008930 } else {
8931 IPW_DEBUG_WX("Getting essid: ANY\n");
8932 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008933 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008934 }
Zhu Yi46441512006-01-24 16:37:59 +08008935 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008936 return 0;
8937}
8938
Jeff Garzikbf794512005-07-31 13:07:26 -04008939static int ipw_wx_set_nick(struct net_device *dev,
8940 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008941 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008942{
James Ketrenos43f66a62005-03-25 12:31:53 -06008943 struct ipw_priv *priv = ieee80211_priv(dev);
8944
8945 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8946 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8947 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08008948 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008949 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06008950 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008951 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06008952 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08008953 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008954 return 0;
8955
8956}
8957
Jeff Garzikbf794512005-07-31 13:07:26 -04008958static int ipw_wx_get_nick(struct net_device *dev,
8959 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008960 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008961{
James Ketrenos43f66a62005-03-25 12:31:53 -06008962 struct ipw_priv *priv = ieee80211_priv(dev);
8963 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08008964 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008965 wrqu->data.length = strlen(priv->nick) + 1;
8966 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008967 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08008968 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008969 return 0;
8970}
8971
Olivier Hochreutiner651be262006-03-08 03:13:55 +08008972static int ipw_wx_set_sens(struct net_device *dev,
8973 struct iw_request_info *info,
8974 union iwreq_data *wrqu, char *extra)
8975{
8976 struct ipw_priv *priv = ieee80211_priv(dev);
8977 int err = 0;
8978
8979 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
8980 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
8981 mutex_lock(&priv->mutex);
8982
8983 if (wrqu->sens.fixed == 0)
8984 {
8985 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8986 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8987 goto out;
8988 }
8989 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
8990 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
8991 err = -EINVAL;
8992 goto out;
8993 }
8994
8995 priv->roaming_threshold = wrqu->sens.value;
8996 priv->disassociate_threshold = 3*wrqu->sens.value;
8997 out:
8998 mutex_unlock(&priv->mutex);
8999 return err;
9000}
9001
9002static int ipw_wx_get_sens(struct net_device *dev,
9003 struct iw_request_info *info,
9004 union iwreq_data *wrqu, char *extra)
9005{
9006 struct ipw_priv *priv = ieee80211_priv(dev);
9007 mutex_lock(&priv->mutex);
9008 wrqu->sens.fixed = 1;
9009 wrqu->sens.value = priv->roaming_threshold;
9010 mutex_unlock(&priv->mutex);
9011
9012 IPW_DEBUG_WX("GET roaming threshold -> %s %d \n",
9013 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9014
9015 return 0;
9016}
9017
James Ketrenos43f66a62005-03-25 12:31:53 -06009018static int ipw_wx_set_rate(struct net_device *dev,
9019 struct iw_request_info *info,
9020 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009021{
James Ketrenosea2b26e2005-08-24 21:25:16 -05009022 /* TODO: We should use semaphores or locks for access to priv */
9023 struct ipw_priv *priv = ieee80211_priv(dev);
9024 u32 target_rate = wrqu->bitrate.value;
9025 u32 fixed, mask;
9026
9027 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
9028 /* value = X, fixed = 1 means only rate X */
9029 /* value = X, fixed = 0 means all rates lower equal X */
9030
9031 if (target_rate == -1) {
9032 fixed = 0;
9033 mask = IEEE80211_DEFAULT_RATES_MASK;
9034 /* Now we should reassociate */
9035 goto apply;
9036 }
9037
9038 mask = 0;
9039 fixed = wrqu->bitrate.fixed;
9040
9041 if (target_rate == 1000000 || !fixed)
9042 mask |= IEEE80211_CCK_RATE_1MB_MASK;
9043 if (target_rate == 1000000)
9044 goto apply;
9045
9046 if (target_rate == 2000000 || !fixed)
9047 mask |= IEEE80211_CCK_RATE_2MB_MASK;
9048 if (target_rate == 2000000)
9049 goto apply;
9050
9051 if (target_rate == 5500000 || !fixed)
9052 mask |= IEEE80211_CCK_RATE_5MB_MASK;
9053 if (target_rate == 5500000)
9054 goto apply;
9055
9056 if (target_rate == 6000000 || !fixed)
9057 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
9058 if (target_rate == 6000000)
9059 goto apply;
9060
9061 if (target_rate == 9000000 || !fixed)
9062 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
9063 if (target_rate == 9000000)
9064 goto apply;
9065
9066 if (target_rate == 11000000 || !fixed)
9067 mask |= IEEE80211_CCK_RATE_11MB_MASK;
9068 if (target_rate == 11000000)
9069 goto apply;
9070
9071 if (target_rate == 12000000 || !fixed)
9072 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
9073 if (target_rate == 12000000)
9074 goto apply;
9075
9076 if (target_rate == 18000000 || !fixed)
9077 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
9078 if (target_rate == 18000000)
9079 goto apply;
9080
9081 if (target_rate == 24000000 || !fixed)
9082 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
9083 if (target_rate == 24000000)
9084 goto apply;
9085
9086 if (target_rate == 36000000 || !fixed)
9087 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
9088 if (target_rate == 36000000)
9089 goto apply;
9090
9091 if (target_rate == 48000000 || !fixed)
9092 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
9093 if (target_rate == 48000000)
9094 goto apply;
9095
9096 if (target_rate == 54000000 || !fixed)
9097 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
9098 if (target_rate == 54000000)
9099 goto apply;
9100
9101 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9102 return -EINVAL;
9103
9104 apply:
9105 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9106 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08009107 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009108 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009109 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05009110 ipw_set_fixed_rate(priv, priv->ieee->mode);
9111 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05009112 priv->config |= CFG_FIXED_RATE;
9113
James Ketrenosc848d0a2005-08-24 21:56:24 -05009114 if (priv->rates_mask == mask) {
9115 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009116 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009117 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009118 }
9119
James Ketrenosc848d0a2005-08-24 21:56:24 -05009120 priv->rates_mask = mask;
9121
9122 /* Network configuration changed -- force [re]association */
9123 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9124 if (!ipw_disassociate(priv))
9125 ipw_associate(priv);
9126
Zhu Yi46441512006-01-24 16:37:59 +08009127 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009128 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009129}
9130
Jeff Garzikbf794512005-07-31 13:07:26 -04009131static int ipw_wx_get_rate(struct net_device *dev,
9132 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009133 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009134{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009135 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009136 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009137 wrqu->bitrate.value = priv->last_rate;
Zhu Yi455936c2006-04-13 17:20:05 +08009138 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009139 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009140 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
9141 return 0;
9142}
9143
Jeff Garzikbf794512005-07-31 13:07:26 -04009144static int ipw_wx_set_rts(struct net_device *dev,
9145 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009146 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009147{
James Ketrenos43f66a62005-03-25 12:31:53 -06009148 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009149 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009150 if (wrqu->rts.disabled)
9151 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9152 else {
9153 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05009154 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009155 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009156 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009157 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009158 priv->rts_threshold = wrqu->rts.value;
9159 }
9160
9161 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08009162 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009163 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
9164 return 0;
9165}
9166
Jeff Garzikbf794512005-07-31 13:07:26 -04009167static int ipw_wx_get_rts(struct net_device *dev,
9168 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009169 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009170{
James Ketrenos43f66a62005-03-25 12:31:53 -06009171 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009172 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009173 wrqu->rts.value = priv->rts_threshold;
9174 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009175 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08009176 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009177 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
9178 return 0;
9179}
9180
Jeff Garzikbf794512005-07-31 13:07:26 -04009181static int ipw_wx_set_txpow(struct net_device *dev,
9182 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009183 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009184{
James Ketrenos43f66a62005-03-25 12:31:53 -06009185 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009186 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009187
Zhu Yi46441512006-01-24 16:37:59 +08009188 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009189 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009190 err = -EINPROGRESS;
9191 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009192 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009193
James Ketrenosb095c382005-08-24 22:04:42 -05009194 if (!wrqu->power.fixed)
9195 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06009196
James Ketrenosc848d0a2005-08-24 21:56:24 -05009197 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009198 err = -EINVAL;
9199 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009200 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009201
James Ketrenosb095c382005-08-24 22:04:42 -05009202 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05009203 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009204 err = -EINVAL;
9205 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009206 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009207
9208 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009209 err = ipw_set_tx_power(priv);
9210 out:
Zhu Yi46441512006-01-24 16:37:59 +08009211 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009212 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009213}
9214
Jeff Garzikbf794512005-07-31 13:07:26 -04009215static int ipw_wx_get_txpow(struct net_device *dev,
9216 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009217 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009218{
James Ketrenos43f66a62005-03-25 12:31:53 -06009219 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009220 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009221 wrqu->power.value = priv->tx_power;
9222 wrqu->power.fixed = 1;
9223 wrqu->power.flags = IW_TXPOW_DBM;
9224 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009225 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009226
Jeff Garzikbf794512005-07-31 13:07:26 -04009227 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08009228 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009229
9230 return 0;
9231}
9232
Jeff Garzikbf794512005-07-31 13:07:26 -04009233static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009234 struct iw_request_info *info,
9235 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009236{
9237 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009238 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009239 if (wrqu->frag.disabled)
9240 priv->ieee->fts = DEFAULT_FTS;
9241 else {
9242 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05009243 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009244 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009245 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05009246 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009247
James Ketrenos43f66a62005-03-25 12:31:53 -06009248 priv->ieee->fts = wrqu->frag.value & ~0x1;
9249 }
9250
9251 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08009252 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009253 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
9254 return 0;
9255}
9256
Jeff Garzikbf794512005-07-31 13:07:26 -04009257static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009258 struct iw_request_info *info,
9259 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009260{
9261 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009262 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009263 wrqu->frag.value = priv->ieee->fts;
9264 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009265 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08009266 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009267 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
9268
9269 return 0;
9270}
9271
Jeff Garzikbf794512005-07-31 13:07:26 -04009272static int ipw_wx_set_retry(struct net_device *dev,
9273 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009274 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009275{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009276 struct ipw_priv *priv = ieee80211_priv(dev);
9277
9278 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9279 return -EINVAL;
9280
9281 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9282 return 0;
9283
9284 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
9285 return -EINVAL;
9286
Zhu Yi46441512006-01-24 16:37:59 +08009287 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009288 if (wrqu->retry.flags & IW_RETRY_MIN)
9289 priv->short_retry_limit = (u8) wrqu->retry.value;
9290 else if (wrqu->retry.flags & IW_RETRY_MAX)
9291 priv->long_retry_limit = (u8) wrqu->retry.value;
9292 else {
9293 priv->short_retry_limit = (u8) wrqu->retry.value;
9294 priv->long_retry_limit = (u8) wrqu->retry.value;
9295 }
9296
9297 ipw_send_retry_limit(priv, priv->short_retry_limit,
9298 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08009299 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009300 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9301 priv->short_retry_limit, priv->long_retry_limit);
9302 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009303}
9304
Jeff Garzikbf794512005-07-31 13:07:26 -04009305static int ipw_wx_get_retry(struct net_device *dev,
9306 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009307 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009308{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009309 struct ipw_priv *priv = ieee80211_priv(dev);
9310
Zhu Yi46441512006-01-24 16:37:59 +08009311 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009312 wrqu->retry.disabled = 0;
9313
9314 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08009315 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009316 return -EINVAL;
9317 }
9318
9319 if (wrqu->retry.flags & IW_RETRY_MAX) {
9320 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
9321 wrqu->retry.value = priv->long_retry_limit;
9322 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
9323 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
9324 wrqu->retry.value = priv->short_retry_limit;
9325 } else {
9326 wrqu->retry.flags = IW_RETRY_LIMIT;
9327 wrqu->retry.value = priv->short_retry_limit;
9328 }
Zhu Yi46441512006-01-24 16:37:59 +08009329 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009330
9331 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9332
9333 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009334}
9335
James Ketrenosafbf30a2005-08-25 00:05:33 -05009336static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
9337 int essid_len)
9338{
9339 struct ipw_scan_request_ext scan;
9340 int err = 0, scan_type;
9341
Pekka Enbergefb34422005-11-16 21:55:05 +02009342 if (!(priv->status & STATUS_INIT) ||
9343 (priv->status & STATUS_EXIT_PENDING))
9344 return 0;
9345
Zhu Yi46441512006-01-24 16:37:59 +08009346 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009347
9348 if (priv->status & STATUS_RF_KILL_MASK) {
9349 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
9350 priv->status |= STATUS_SCAN_PENDING;
9351 goto done;
9352 }
9353
9354 IPW_DEBUG_HC("starting request direct scan!\n");
9355
9356 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
Olaf Kirchd834a412006-01-09 17:00:37 +01009357 /* We should not sleep here; otherwise we will block most
9358 * of the system (for instance, we hold rtnl_lock when we
9359 * get here).
9360 */
9361 err = -EAGAIN;
9362 goto done;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009363 }
9364 memset(&scan, 0, sizeof(scan));
9365
9366 if (priv->config & CFG_SPEED_SCAN)
9367 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9368 cpu_to_le16(30);
9369 else
9370 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9371 cpu_to_le16(20);
9372
9373 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
9374 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05009375 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009376 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
9377
9378 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
9379
9380 err = ipw_send_ssid(priv, essid, essid_len);
9381 if (err) {
9382 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
9383 goto done;
9384 }
9385 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
9386
9387 ipw_add_scan_channels(priv, &scan, scan_type);
9388
9389 err = ipw_send_scan_request_ext(priv, &scan);
9390 if (err) {
9391 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
9392 goto done;
9393 }
9394
9395 priv->status |= STATUS_SCANNING;
9396
9397 done:
Zhu Yi46441512006-01-24 16:37:59 +08009398 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009399 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009400}
9401
Jeff Garzikbf794512005-07-31 13:07:26 -04009402static int ipw_wx_set_scan(struct net_device *dev,
9403 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009404 union iwreq_data *wrqu, char *extra)
9405{
9406 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009407 struct iw_scan_req *req = NULL;
9408 if (wrqu->data.length
9409 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9410 req = (struct iw_scan_req *)extra;
9411 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9412 ipw_request_direct_scan(priv, req->essid,
9413 req->essid_len);
9414 return 0;
9415 }
9416 }
James Ketrenos8935f392005-10-05 15:59:08 -05009417
James Ketrenos43f66a62005-03-25 12:31:53 -06009418 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009419
9420 queue_work(priv->workqueue, &priv->request_scan);
9421
James Ketrenos43f66a62005-03-25 12:31:53 -06009422 return 0;
9423}
9424
Jeff Garzikbf794512005-07-31 13:07:26 -04009425static int ipw_wx_get_scan(struct net_device *dev,
9426 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009427 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009428{
James Ketrenos43f66a62005-03-25 12:31:53 -06009429 struct ipw_priv *priv = ieee80211_priv(dev);
9430 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9431}
9432
Jeff Garzikbf794512005-07-31 13:07:26 -04009433static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009434 struct iw_request_info *info,
9435 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009436{
9437 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009438 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009439 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009440
Zhu Yi46441512006-01-24 16:37:59 +08009441 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009442 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009443
Hong Liucaeff812005-08-05 17:25:50 +08009444 /* In IBSS mode, we need to notify the firmware to update
9445 * the beacon info after we changed the capability. */
9446 if (cap != priv->capability &&
9447 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9448 priv->status & STATUS_ASSOCIATED)
9449 ipw_disassociate(priv);
9450
Zhu Yi46441512006-01-24 16:37:59 +08009451 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009452 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009453}
9454
Jeff Garzikbf794512005-07-31 13:07:26 -04009455static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009456 struct iw_request_info *info,
9457 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009458{
9459 struct ipw_priv *priv = ieee80211_priv(dev);
9460 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9461}
9462
Jeff Garzikbf794512005-07-31 13:07:26 -04009463static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009464 struct iw_request_info *info,
9465 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009466{
9467 struct ipw_priv *priv = ieee80211_priv(dev);
9468 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009469 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009470 if (wrqu->power.disabled) {
9471 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9472 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
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 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009478 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009479 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009480 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009481 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009482
9483 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009484 case IW_POWER_ON: /* If not specified */
9485 case IW_POWER_MODE: /* If set all mask */
9486 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009487 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009488 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009489 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9490 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009491 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009492 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009493 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009494
James Ketrenos43f66a62005-03-25 12:31:53 -06009495 /* If the user hasn't specified a power management mode yet, default
9496 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009497 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009498 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009499 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009500 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9501 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9502 if (err) {
9503 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009504 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009505 return err;
9506 }
9507
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009508 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009509 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009510 return 0;
9511}
9512
Jeff Garzikbf794512005-07-31 13:07:26 -04009513static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009514 struct iw_request_info *info,
9515 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009516{
9517 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009518 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009519 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009520 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009521 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009522 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009523
Zhu Yi46441512006-01-24 16:37:59 +08009524 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009525 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009526
James Ketrenos43f66a62005-03-25 12:31:53 -06009527 return 0;
9528}
9529
Jeff Garzikbf794512005-07-31 13:07:26 -04009530static int ipw_wx_set_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 mode = *(int *)extra;
9536 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009537 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009538 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9539 mode = IPW_POWER_AC;
9540 priv->power_mode = mode;
9541 } else {
9542 priv->power_mode = IPW_POWER_ENABLED | mode;
9543 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009544
James Ketrenos43f66a62005-03-25 12:31:53 -06009545 if (priv->power_mode != mode) {
9546 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009547
James Ketrenos43f66a62005-03-25 12:31:53 -06009548 if (err) {
9549 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009550 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009551 return err;
9552 }
9553 }
Zhu Yi46441512006-01-24 16:37:59 +08009554 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009555 return 0;
9556}
9557
9558#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009559static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009560 struct iw_request_info *info,
9561 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009562{
9563 struct ipw_priv *priv = ieee80211_priv(dev);
9564 int level = IPW_POWER_LEVEL(priv->power_mode);
9565 char *p = extra;
9566
9567 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9568
9569 switch (level) {
9570 case IPW_POWER_AC:
9571 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9572 break;
9573 case IPW_POWER_BATTERY:
9574 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9575 break;
9576 default:
9577 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009578 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009579 timeout_duration[level - 1] / 1000,
9580 period_duration[level - 1] / 1000);
9581 }
9582
9583 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009584 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009585
9586 wrqu->data.length = p - extra + 1;
9587
9588 return 0;
9589}
9590
9591static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009592 struct iw_request_info *info,
9593 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009594{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009595 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009596 int mode = *(int *)extra;
9597 u8 band = 0, modulation = 0;
9598
9599 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009600 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009601 return -EINVAL;
9602 }
Zhu Yi46441512006-01-24 16:37:59 +08009603 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009604 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009605 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009606 if (mode & IEEE_A) {
9607 band |= IEEE80211_52GHZ_BAND;
9608 modulation |= IEEE80211_OFDM_MODULATION;
9609 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009610 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009611 } else {
9612 if (mode & IEEE_A) {
9613 IPW_WARNING("Attempt to set 2200BG into "
9614 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009615 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009616 return -EINVAL;
9617 }
9618
James Ketrenosa33a1982005-09-14 14:28:59 -05009619 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009620 }
9621
9622 if (mode & IEEE_B) {
9623 band |= IEEE80211_24GHZ_BAND;
9624 modulation |= IEEE80211_CCK_MODULATION;
9625 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009626 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009627
James Ketrenos43f66a62005-03-25 12:31:53 -06009628 if (mode & IEEE_G) {
9629 band |= IEEE80211_24GHZ_BAND;
9630 modulation |= IEEE80211_OFDM_MODULATION;
9631 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009632 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009633
9634 priv->ieee->mode = mode;
9635 priv->ieee->freq_band = band;
9636 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009637 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009638
James Ketrenosc848d0a2005-08-24 21:56:24 -05009639 /* Network configuration changed -- force [re]association */
9640 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9641 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009642 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009643 ipw_associate(priv);
9644 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009645
James Ketrenosa613bff2005-08-24 21:43:11 -05009646 /* Update the band LEDs */
9647 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009648
Jeff Garzikbf794512005-07-31 13:07:26 -04009649 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009650 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009651 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009652 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009653 return 0;
9654}
9655
9656static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009657 struct iw_request_info *info,
9658 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009659{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009660 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009661 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009662 switch (priv->ieee->mode) {
9663 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009664 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9665 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009666 case IEEE_B:
9667 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9668 break;
9669 case IEEE_A | IEEE_B:
9670 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9671 break;
9672 case IEEE_G:
9673 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9674 break;
9675 case IEEE_A | IEEE_G:
9676 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9677 break;
9678 case IEEE_B | IEEE_G:
9679 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9680 break;
9681 case IEEE_A | IEEE_B | IEEE_G:
9682 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9683 break;
9684 default:
9685 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009686 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009687 }
9688
James Ketrenos43f66a62005-03-25 12:31:53 -06009689 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9690
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009691 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009692 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009693
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009694 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009695}
9696
James Ketrenosea2b26e2005-08-24 21:25:16 -05009697static int ipw_wx_set_preamble(struct net_device *dev,
9698 struct iw_request_info *info,
9699 union iwreq_data *wrqu, char *extra)
9700{
9701 struct ipw_priv *priv = ieee80211_priv(dev);
9702 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009703 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009704 /* Switching from SHORT -> LONG requires a disassociation */
9705 if (mode == 1) {
9706 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9707 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009708
9709 /* Network configuration changed -- force [re]association */
9710 IPW_DEBUG_ASSOC
9711 ("[re]association triggered due to preamble change.\n");
9712 if (!ipw_disassociate(priv))
9713 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009714 }
9715 goto done;
9716 }
9717
9718 if (mode == 0) {
9719 priv->config &= ~CFG_PREAMBLE_LONG;
9720 goto done;
9721 }
Zhu Yi46441512006-01-24 16:37:59 +08009722 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009723 return -EINVAL;
9724
9725 done:
Zhu Yi46441512006-01-24 16:37:59 +08009726 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009727 return 0;
9728}
9729
9730static int ipw_wx_get_preamble(struct net_device *dev,
9731 struct iw_request_info *info,
9732 union iwreq_data *wrqu, char *extra)
9733{
9734 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009735 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009736 if (priv->config & CFG_PREAMBLE_LONG)
9737 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9738 else
9739 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009740 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009741 return 0;
9742}
9743
James Ketrenosb095c382005-08-24 22:04:42 -05009744#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009745static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009746 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009747 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009748{
James Ketrenos43f66a62005-03-25 12:31:53 -06009749 struct ipw_priv *priv = ieee80211_priv(dev);
9750 int *parms = (int *)extra;
9751 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009752 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009753 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009754 if (enable) {
9755 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08009756#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05009757 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9758#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009759 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009760#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009761 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009762 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009763
James Ketrenos43f66a62005-03-25 12:31:53 -06009764 ipw_set_channel(priv, parms[1]);
9765 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009766 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009767 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009768 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009769 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009770 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009771 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009772 }
Zhu Yi46441512006-01-24 16:37:59 +08009773 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009774 return 0;
9775}
9776
James Ketrenosb095c382005-08-24 22:04:42 -05009777#endif // CONFIG_IPW2200_MONITOR
9778
Jeff Garzikbf794512005-07-31 13:07:26 -04009779static int ipw_wx_reset(struct net_device *dev,
9780 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009781 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009782{
James Ketrenos43f66a62005-03-25 12:31:53 -06009783 struct ipw_priv *priv = ieee80211_priv(dev);
9784 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009785 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009786 return 0;
9787}
James Ketrenosb095c382005-08-24 22:04:42 -05009788
James Ketrenosb095c382005-08-24 22:04:42 -05009789static int ipw_wx_sw_reset(struct net_device *dev,
9790 struct iw_request_info *info,
9791 union iwreq_data *wrqu, char *extra)
9792{
9793 struct ipw_priv *priv = ieee80211_priv(dev);
9794 union iwreq_data wrqu_sec = {
9795 .encoding = {
9796 .flags = IW_ENCODE_DISABLED,
9797 },
9798 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009799 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009800
9801 IPW_DEBUG_WX("SW_RESET\n");
9802
Zhu Yi46441512006-01-24 16:37:59 +08009803 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009804
Zhu Yid6d5b5c2006-02-16 16:21:09 +08009805 ret = ipw_sw_reset(priv, 2);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009806 if (!ret) {
9807 free_firmware();
9808 ipw_adapter_restart(priv);
9809 }
James Ketrenosb095c382005-08-24 22:04:42 -05009810
9811 /* The SW reset bit might have been toggled on by the 'disable'
9812 * module parameter, so take appropriate action */
9813 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9814
Zhu Yi46441512006-01-24 16:37:59 +08009815 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009816 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009817 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009818
9819 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9820 /* Configuration likely changed -- force [re]association */
9821 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9822 "reset.\n");
9823 if (!ipw_disassociate(priv))
9824 ipw_associate(priv);
9825 }
9826
Zhu Yi46441512006-01-24 16:37:59 +08009827 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009828
9829 return 0;
9830}
James Ketrenos43f66a62005-03-25 12:31:53 -06009831
9832/* Rebase the WE IOCTLs to zero for the handler array */
9833#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009834static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009835 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9836 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9837 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9838 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9839 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009840 IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens,
9841 IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009842 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9843 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9844 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9845 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9846 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9847 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9848 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9849 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9850 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9851 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9852 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9853 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9854 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9855 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9856 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9857 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9858 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9859 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9860 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9861 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9862 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9863 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9864 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -05009865 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9866 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9867 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9868 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -05009869 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9870 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9871 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9872 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9873 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9874 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9875 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
James Ketrenos43f66a62005-03-25 12:31:53 -06009876};
9877
James Ketrenosb095c382005-08-24 22:04:42 -05009878enum {
9879 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9880 IPW_PRIV_GET_POWER,
9881 IPW_PRIV_SET_MODE,
9882 IPW_PRIV_GET_MODE,
9883 IPW_PRIV_SET_PREAMBLE,
9884 IPW_PRIV_GET_PREAMBLE,
9885 IPW_PRIV_RESET,
9886 IPW_PRIV_SW_RESET,
9887#ifdef CONFIG_IPW2200_MONITOR
9888 IPW_PRIV_SET_MONITOR,
9889#endif
9890};
James Ketrenos43f66a62005-03-25 12:31:53 -06009891
Jeff Garzikbf794512005-07-31 13:07:26 -04009892static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06009893 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009894 .cmd = IPW_PRIV_SET_POWER,
9895 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9896 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009897 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009898 .cmd = IPW_PRIV_GET_POWER,
9899 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9900 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009901 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009902 .cmd = IPW_PRIV_SET_MODE,
9903 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9904 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009905 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009906 .cmd = IPW_PRIV_GET_MODE,
9907 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9908 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009909 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009910 .cmd = IPW_PRIV_SET_PREAMBLE,
9911 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9912 .name = "set_preamble"},
9913 {
9914 .cmd = IPW_PRIV_GET_PREAMBLE,
9915 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9916 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009917 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009918 IPW_PRIV_RESET,
9919 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -05009920 {
9921 IPW_PRIV_SW_RESET,
9922 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9923#ifdef CONFIG_IPW2200_MONITOR
9924 {
9925 IPW_PRIV_SET_MONITOR,
9926 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9927#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06009928};
9929
9930static iw_handler ipw_priv_handler[] = {
9931 ipw_wx_set_powermode,
9932 ipw_wx_get_powermode,
9933 ipw_wx_set_wireless_mode,
9934 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009935 ipw_wx_set_preamble,
9936 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -04009937 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -05009938 ipw_wx_sw_reset,
9939#ifdef CONFIG_IPW2200_MONITOR
9940 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -06009941#endif
9942};
9943
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009944static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009945 .standard = ipw_wx_handlers,
9946 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9947 .num_private = ARRAY_SIZE(ipw_priv_handler),
9948 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9949 .private = ipw_priv_handler,
9950 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009951 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06009952};
9953
James Ketrenos43f66a62005-03-25 12:31:53 -06009954/*
9955 * Get wireless statistics.
9956 * Called by /proc/net/wireless
9957 * Also called by SIOCGIWSTATS
9958 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009959static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06009960{
9961 struct ipw_priv *priv = ieee80211_priv(dev);
9962 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009963
James Ketrenos43f66a62005-03-25 12:31:53 -06009964 wstats = &priv->wstats;
9965
James Ketrenosea2b26e2005-08-24 21:25:16 -05009966 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -05009967 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06009968 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9969 * and associated; if not associcated, the values are all meaningless
9970 * anyway, so set them all to NULL and INVALID */
9971 if (!(priv->status & STATUS_ASSOCIATED)) {
9972 wstats->miss.beacon = 0;
9973 wstats->discard.retries = 0;
9974 wstats->qual.qual = 0;
9975 wstats->qual.level = 0;
9976 wstats->qual.noise = 0;
9977 wstats->qual.updated = 7;
9978 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009979 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06009980 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009981 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009982
9983 wstats->qual.qual = priv->quality;
Zhu Yi00d21de2006-04-13 17:19:02 +08009984 wstats->qual.level = priv->exp_avg_rssi;
9985 wstats->qual.noise = priv->exp_avg_noise;
James Ketrenos43f66a62005-03-25 12:31:53 -06009986 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +08009987 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009988
9989 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9990 wstats->discard.retries = priv->last_tx_failures;
9991 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04009992
James Ketrenos43f66a62005-03-25 12:31:53 -06009993/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9994 goto fail_get_ordinal;
9995 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04009996
James Ketrenos43f66a62005-03-25 12:31:53 -06009997 return wstats;
9998}
9999
James Ketrenos43f66a62005-03-25 12:31:53 -060010000/* net device stuff */
10001
Arjan van de Ven858119e2006-01-14 13:20:43 -080010002static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -060010003{
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010004 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +080010005 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010006 sys_config->answer_broadcast_ssid_probe = 0;
10007 sys_config->accept_all_data_frames = 0;
10008 sys_config->accept_non_directed_frames = 1;
10009 sys_config->exclude_unicast_unencrypted = 0;
10010 sys_config->disable_unicast_decryption = 1;
10011 sys_config->exclude_multicast_unencrypted = 0;
10012 sys_config->disable_multicast_decryption = 1;
Zhu Yid2b83e12006-04-13 17:19:36 +080010013 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
10014 antenna = CFG_SYS_ANTENNA_BOTH;
10015 sys_config->antenna_diversity = antenna;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010016 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010017 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010018 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010019 sys_config->bt_coexist_collision_thr = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010020 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
Cahill, Ben M12977152006-03-08 02:58:02 +080010021 sys_config->silence_threshold = 0x1e;
James Ketrenos43f66a62005-03-25 12:31:53 -060010022}
10023
10024static int ipw_net_open(struct net_device *dev)
10025{
10026 struct ipw_priv *priv = ieee80211_priv(dev);
10027 IPW_DEBUG_INFO("dev->open\n");
10028 /* we should be verifying the device is ready to be opened */
Zhu Yi46441512006-01-24 16:37:59 +080010029 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -040010030 if (!(priv->status & STATUS_RF_KILL_MASK) &&
10031 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -060010032 netif_start_queue(dev);
Zhu Yi46441512006-01-24 16:37:59 +080010033 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010034 return 0;
10035}
10036
10037static int ipw_net_stop(struct net_device *dev)
10038{
10039 IPW_DEBUG_INFO("dev->close\n");
10040 netif_stop_queue(dev);
10041 return 0;
10042}
10043
10044/*
10045todo:
10046
10047modify to send one tfd per fragment instead of using chunking. otherwise
10048we need to heavily modify the ieee80211_skb_to_txb.
10049*/
10050
Arjan van de Ven858119e2006-01-14 13:20:43 -080010051static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -050010052 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010053{
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010054 struct ieee80211_hdr_3addrqos *hdr = (struct ieee80211_hdr_3addrqos *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010055 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -060010056 int i = 0;
10057 struct tfd_frame *tfd;
Zhu Yie43e3c12006-04-13 17:20:45 +080010058#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010059 int tx_id = ipw_get_tx_queue_number(priv, pri);
10060 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10061#else
James Ketrenos43f66a62005-03-25 12:31:53 -060010062 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -050010063#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060010064 struct clx2_queue *q = &txq->q;
10065 u8 id, hdr_len, unicast;
10066 u16 remaining_bytes;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010067 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -060010068
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010069 hdr_len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
James Ketrenos43f66a62005-03-25 12:31:53 -060010070 switch (priv->ieee->iw_mode) {
10071 case IW_MODE_ADHOC:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010072 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010073 id = ipw_find_station(priv, hdr->addr1);
10074 if (id == IPW_INVALID_STATION) {
10075 id = ipw_add_station(priv, hdr->addr1);
10076 if (id == IPW_INVALID_STATION) {
10077 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -040010078 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010079 MAC_ARG(hdr->addr1));
10080 goto drop;
10081 }
10082 }
10083 break;
10084
10085 case IW_MODE_INFRA:
10086 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010087 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -060010088 id = 0;
10089 break;
10090 }
10091
10092 tfd = &txq->bd[q->first_empty];
10093 txq->txb[q->first_empty] = txb;
10094 memset(tfd, 0, sizeof(*tfd));
10095 tfd->u.data.station_number = id;
10096
10097 tfd->control_flags.message_type = TX_FRAME_TYPE;
10098 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10099
10100 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -050010101 tfd->u.data.len = cpu_to_le16(txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010102 remaining_bytes = txb->payload_size;
Jeff Garzikbf794512005-07-31 13:07:26 -040010103
James Ketrenos43f66a62005-03-25 12:31:53 -060010104 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -050010105 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010106 else
James Ketrenosb095c382005-08-24 22:04:42 -050010107 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010108
James Ketrenosea2b26e2005-08-24 21:25:16 -050010109 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10110 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010111
James Ketrenosc848d0a2005-08-24 21:56:24 -050010112 fc = le16_to_cpu(hdr->frame_ctl);
10113 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -060010114
10115 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10116
James Ketrenosb095c382005-08-24 22:04:42 -050010117 if (likely(unicast))
10118 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10119
10120 if (txb->encrypted && !priv->ieee->host_encrypt) {
10121 switch (priv->ieee->sec.level) {
10122 case SEC_LEVEL_3:
10123 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10124 IEEE80211_FCTL_PROTECTED;
10125 /* XXX: ACK flag must be set for CCMP even if it
10126 * is a multicast/broadcast packet, because CCMP
10127 * group communication encrypted by GTK is
10128 * actually done by the AP. */
10129 if (!unicast)
10130 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10131
10132 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10133 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10134 tfd->u.data.key_index = 0;
10135 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10136 break;
10137 case SEC_LEVEL_2:
10138 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10139 IEEE80211_FCTL_PROTECTED;
10140 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10141 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10142 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10143 break;
10144 case SEC_LEVEL_1:
10145 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10146 IEEE80211_FCTL_PROTECTED;
10147 tfd->u.data.key_index = priv->ieee->tx_keyidx;
10148 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
10149 40)
10150 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10151 else
10152 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10153 break;
10154 case SEC_LEVEL_0:
10155 break;
10156 default:
10157 printk(KERN_ERR "Unknow security level %d\n",
10158 priv->ieee->sec.level);
10159 break;
10160 }
10161 } else
10162 /* No hardware encryption */
10163 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10164
Zhu Yie43e3c12006-04-13 17:20:45 +080010165#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010166 if (fc & IEEE80211_STYPE_QOS_DATA)
10167 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
Zhu Yie43e3c12006-04-13 17:20:45 +080010168#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050010169
James Ketrenos43f66a62005-03-25 12:31:53 -060010170 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -050010171 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10172 txb->nr_frags));
10173 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10174 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10175 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10176 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10177 i, le32_to_cpu(tfd->u.data.num_chunks),
10178 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010179 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010180 i, tfd->u.data.num_chunks,
10181 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010182 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -060010183 txb->fragments[i]->len - hdr_len);
10184
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010185 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010186 cpu_to_le32(pci_map_single
10187 (priv->pci_dev,
10188 txb->fragments[i]->data + hdr_len,
10189 txb->fragments[i]->len - hdr_len,
10190 PCI_DMA_TODEVICE));
10191 tfd->u.data.chunk_len[i] =
10192 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -060010193 }
10194
10195 if (i != txb->nr_frags) {
10196 struct sk_buff *skb;
10197 u16 remaining_bytes = 0;
10198 int j;
10199
10200 for (j = i; j < txb->nr_frags; j++)
10201 remaining_bytes += txb->fragments[j]->len - hdr_len;
10202
10203 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10204 remaining_bytes);
10205 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10206 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -050010207 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -060010208 for (j = i; j < txb->nr_frags; j++) {
10209 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010210
James Ketrenos43f66a62005-03-25 12:31:53 -060010211 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010212 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010213 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010214 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010215 }
10216 dev_kfree_skb_any(txb->fragments[i]);
10217 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010218 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010219 cpu_to_le32(pci_map_single
10220 (priv->pci_dev, skb->data,
10221 tfd->u.data.chunk_len[i],
10222 PCI_DMA_TODEVICE));
10223
10224 tfd->u.data.num_chunks =
10225 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
10226 1);
Jeff Garzikbf794512005-07-31 13:07:26 -040010227 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010228 }
10229
10230 /* kick DMA */
10231 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10232 ipw_write32(priv, q->reg_w, q->first_empty);
10233
James Ketrenosf6970142006-02-14 09:10:51 +080010234 if (ipw_queue_space(q) < q->high_mark)
10235 netif_stop_queue(priv->net_dev);
10236
James Ketrenos227d2dc2005-07-28 16:25:55 -050010237 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010238
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010239 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -060010240 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
10241 ieee80211_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -050010242 return NETDEV_TX_OK;
10243}
10244
10245static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10246{
10247 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yie43e3c12006-04-13 17:20:45 +080010248#ifdef CONFIG_IPW2200_QOS
James Ketrenos227d2dc2005-07-28 16:25:55 -050010249 int tx_id = ipw_get_tx_queue_number(priv, pri);
10250 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10251#else
10252 struct clx2_tx_queue *txq = &priv->txq[0];
Zhu Yie43e3c12006-04-13 17:20:45 +080010253#endif /* CONFIG_IPW2200_QOS */
James Ketrenos227d2dc2005-07-28 16:25:55 -050010254
10255 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
10256 return 1;
10257
10258 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010259}
10260
Zhu Yid685b8c2006-04-13 17:20:27 +080010261#ifdef CONFIG_IPW2200_PROMISCUOUS
10262static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
10263 struct ieee80211_txb *txb)
10264{
10265 struct ieee80211_rx_stats dummystats;
10266 struct ieee80211_hdr *hdr;
10267 u8 n;
10268 u16 filter = priv->prom_priv->filter;
10269 int hdr_only = 0;
10270
10271 if (filter & IPW_PROM_NO_TX)
10272 return;
10273
10274 memset(&dummystats, 0, sizeof(dummystats));
10275
10276 /* Filtering of fragment chains is done agains the first fragment */
10277 hdr = (void *)txb->fragments[0]->data;
10278 if (ieee80211_is_management(hdr->frame_ctl)) {
10279 if (filter & IPW_PROM_NO_MGMT)
10280 return;
10281 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10282 hdr_only = 1;
10283 } else if (ieee80211_is_control(hdr->frame_ctl)) {
10284 if (filter & IPW_PROM_NO_CTL)
10285 return;
10286 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10287 hdr_only = 1;
10288 } else if (ieee80211_is_data(hdr->frame_ctl)) {
10289 if (filter & IPW_PROM_NO_DATA)
10290 return;
10291 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10292 hdr_only = 1;
10293 }
10294
10295 for(n=0; n<txb->nr_frags; ++n) {
10296 struct sk_buff *src = txb->fragments[n];
10297 struct sk_buff *dst;
10298 struct ieee80211_radiotap_header *rt_hdr;
10299 int len;
10300
10301 if (hdr_only) {
10302 hdr = (void *)src->data;
10303 len = ieee80211_get_hdrlen(hdr->frame_ctl);
10304 } else
10305 len = src->len;
10306
10307 dst = alloc_skb(
10308 len + IEEE80211_RADIOTAP_HDRLEN, GFP_ATOMIC);
10309 if (!dst) continue;
10310
10311 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10312
10313 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10314 rt_hdr->it_pad = 0;
10315 rt_hdr->it_present = 0; /* after all, it's just an idea */
10316 rt_hdr->it_present |= (1 << IEEE80211_RADIOTAP_CHANNEL);
10317
10318 *(u16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
10319 ieee80211chan2mhz(priv->channel));
10320 if (priv->channel > 14) /* 802.11a */
10321 *(u16*)skb_put(dst, sizeof(u16)) =
10322 cpu_to_le16(IEEE80211_CHAN_OFDM |
10323 IEEE80211_CHAN_5GHZ);
10324 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
10325 *(u16*)skb_put(dst, sizeof(u16)) =
10326 cpu_to_le16(IEEE80211_CHAN_CCK |
10327 IEEE80211_CHAN_2GHZ);
10328 else /* 802.11g */
10329 *(u16*)skb_put(dst, sizeof(u16)) =
10330 cpu_to_le16(IEEE80211_CHAN_OFDM |
10331 IEEE80211_CHAN_2GHZ);
10332
10333 rt_hdr->it_len = dst->len;
10334
10335 memcpy(skb_put(dst, len), src->data, len);
10336
10337 if (!ieee80211_rx(priv->prom_priv->ieee, dst, &dummystats))
10338 dev_kfree_skb_any(dst);
10339 }
10340}
10341#endif
10342
James Ketrenos43f66a62005-03-25 12:31:53 -060010343static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -050010344 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010345{
10346 struct ipw_priv *priv = ieee80211_priv(dev);
10347 unsigned long flags;
James Ketrenos227d2dc2005-07-28 16:25:55 -050010348 int ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010349
10350 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010351 spin_lock_irqsave(&priv->lock, flags);
10352
10353 if (!(priv->status & STATUS_ASSOCIATED)) {
10354 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
10355 priv->ieee->stats.tx_carrier_errors++;
10356 netif_stop_queue(dev);
10357 goto fail_unlock;
10358 }
10359
Zhu Yid685b8c2006-04-13 17:20:27 +080010360#ifdef CONFIG_IPW2200_PROMISCUOUS
10361 if (rtap_iface && netif_running(priv->prom_net_dev))
10362 ipw_handle_promiscuous_tx(priv, txb);
10363#endif
10364
James Ketrenos227d2dc2005-07-28 16:25:55 -050010365 ret = ipw_tx_skb(priv, txb, pri);
10366 if (ret == NETDEV_TX_OK)
10367 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010368 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010369
James Ketrenos227d2dc2005-07-28 16:25:55 -050010370 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010371
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010372 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010373 spin_unlock_irqrestore(&priv->lock, flags);
10374 return 1;
10375}
10376
10377static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
10378{
10379 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -040010380
James Ketrenos43f66a62005-03-25 12:31:53 -060010381 priv->ieee->stats.tx_packets = priv->tx_packets;
10382 priv->ieee->stats.rx_packets = priv->rx_packets;
10383 return &priv->ieee->stats;
10384}
10385
10386static void ipw_net_set_multicast_list(struct net_device *dev)
10387{
10388
10389}
10390
10391static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10392{
10393 struct ipw_priv *priv = ieee80211_priv(dev);
10394 struct sockaddr *addr = p;
10395 if (!is_valid_ether_addr(addr->sa_data))
10396 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +080010397 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010398 priv->config |= CFG_CUSTOM_MAC;
10399 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
10400 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
10401 priv->net_dev->name, MAC_ARG(priv->mac_addr));
James Ketrenosa613bff2005-08-24 21:43:11 -050010402 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +080010403 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010404 return 0;
10405}
10406
Jeff Garzikbf794512005-07-31 13:07:26 -040010407static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010408 struct ethtool_drvinfo *info)
10409{
10410 struct ipw_priv *p = ieee80211_priv(dev);
10411 char vers[64];
10412 char date[32];
10413 u32 len;
10414
10415 strcpy(info->driver, DRV_NAME);
10416 strcpy(info->version, DRV_VERSION);
10417
10418 len = sizeof(vers);
10419 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10420 len = sizeof(date);
10421 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10422
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010423 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010424 vers, date);
10425 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010426 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010427}
10428
10429static u32 ipw_ethtool_get_link(struct net_device *dev)
10430{
10431 struct ipw_priv *priv = ieee80211_priv(dev);
10432 return (priv->status & STATUS_ASSOCIATED) != 0;
10433}
10434
10435static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10436{
James Ketrenosb095c382005-08-24 22:04:42 -050010437 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010438}
10439
10440static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010441 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010442{
10443 struct ipw_priv *p = ieee80211_priv(dev);
10444
James Ketrenosb095c382005-08-24 22:04:42 -050010445 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010446 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010447 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010448 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +080010449 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010450 return 0;
10451}
10452
10453static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010454 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010455{
10456 struct ipw_priv *p = ieee80211_priv(dev);
10457 int i;
10458
James Ketrenosb095c382005-08-24 22:04:42 -050010459 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010460 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010461 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010462 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Adrian Bunk71e585f2006-03-11 04:42:58 +010010463 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10464 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +080010465 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010466 return 0;
10467}
10468
10469static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010470 .get_link = ipw_ethtool_get_link,
10471 .get_drvinfo = ipw_ethtool_get_drvinfo,
10472 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10473 .get_eeprom = ipw_ethtool_get_eeprom,
10474 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010475};
10476
10477static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
10478{
10479 struct ipw_priv *priv = data;
10480 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010481
James Ketrenos43f66a62005-03-25 12:31:53 -060010482 if (!priv)
10483 return IRQ_NONE;
10484
Zhu Yi89c318e2006-06-08 22:19:49 -070010485 spin_lock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010486
10487 if (!(priv->status & STATUS_INT_ENABLED)) {
10488 /* Shared IRQ */
10489 goto none;
10490 }
10491
James Ketrenosb095c382005-08-24 22:04:42 -050010492 inta = ipw_read32(priv, IPW_INTA_RW);
10493 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010494
James Ketrenos43f66a62005-03-25 12:31:53 -060010495 if (inta == 0xFFFFFFFF) {
10496 /* Hardware disappeared */
10497 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10498 goto none;
10499 }
10500
James Ketrenosb095c382005-08-24 22:04:42 -050010501 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010502 /* Shared interrupt */
10503 goto none;
10504 }
10505
10506 /* tell the device to stop sending interrupts */
Zhu Yi89c318e2006-06-08 22:19:49 -070010507 __ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010508
James Ketrenos43f66a62005-03-25 12:31:53 -060010509 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010510 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10511 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010512
James Ketrenos43f66a62005-03-25 12:31:53 -060010513 /* Cache INTA value for our tasklet */
10514 priv->isr_inta = inta;
10515
10516 tasklet_schedule(&priv->irq_tasklet);
10517
Zhu Yi89c318e2006-06-08 22:19:49 -070010518 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010519
10520 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010521 none:
Zhu Yi89c318e2006-06-08 22:19:49 -070010522 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010523 return IRQ_NONE;
10524}
10525
10526static void ipw_rf_kill(void *adapter)
10527{
10528 struct ipw_priv *priv = adapter;
10529 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010530
James Ketrenos43f66a62005-03-25 12:31:53 -060010531 spin_lock_irqsave(&priv->lock, flags);
10532
10533 if (rf_kill_active(priv)) {
10534 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10535 if (priv->workqueue)
10536 queue_delayed_work(priv->workqueue,
10537 &priv->rf_kill, 2 * HZ);
10538 goto exit_unlock;
10539 }
10540
10541 /* RF Kill is now disabled, so bring the device back up */
10542
10543 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10544 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10545 "device\n");
10546
10547 /* we can not do an adapter restart while inside an irq lock */
10548 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010549 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010550 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10551 "enabled\n");
10552
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010553 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010554 spin_unlock_irqrestore(&priv->lock, flags);
10555}
10556
James Ketrenosc848d0a2005-08-24 21:56:24 -050010557static void ipw_bg_rf_kill(void *data)
10558{
10559 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010560 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010561 ipw_rf_kill(data);
Zhu Yi46441512006-01-24 16:37:59 +080010562 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010563}
10564
Adrian Bunka73e22b2006-01-21 01:39:42 +010010565static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010566{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010567 priv->last_seq_num = -1;
10568 priv->last_frag_num = -1;
10569 priv->last_packet_time = 0;
10570
James Ketrenosa613bff2005-08-24 21:43:11 -050010571 netif_carrier_on(priv->net_dev);
10572 if (netif_queue_stopped(priv->net_dev)) {
10573 IPW_DEBUG_NOTIF("waking queue\n");
10574 netif_wake_queue(priv->net_dev);
10575 } else {
10576 IPW_DEBUG_NOTIF("starting queue\n");
10577 netif_start_queue(priv->net_dev);
10578 }
10579
James Ketrenosc848d0a2005-08-24 21:56:24 -050010580 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010581 ipw_reset_stats(priv);
10582 /* Ensure the rate is updated immediately */
10583 priv->last_rate = ipw_get_current_rate(priv);
10584 ipw_gather_stats(priv);
10585 ipw_led_link_up(priv);
10586 notify_wx_assoc_event(priv);
10587
10588 if (priv->config & CFG_BACKGROUND_SCAN)
10589 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10590}
10591
James Ketrenosc848d0a2005-08-24 21:56:24 -050010592static void ipw_bg_link_up(void *data)
10593{
10594 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010595 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010596 ipw_link_up(data);
Zhu Yi46441512006-01-24 16:37:59 +080010597 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010598}
10599
Adrian Bunka73e22b2006-01-21 01:39:42 +010010600static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010601{
10602 ipw_led_link_down(priv);
10603 netif_carrier_off(priv->net_dev);
10604 netif_stop_queue(priv->net_dev);
10605 notify_wx_assoc_event(priv);
10606
10607 /* Cancel any queued work ... */
10608 cancel_delayed_work(&priv->request_scan);
10609 cancel_delayed_work(&priv->adhoc_check);
10610 cancel_delayed_work(&priv->gather_stats);
10611
10612 ipw_reset_stats(priv);
10613
James Ketrenosafbf30a2005-08-25 00:05:33 -050010614 if (!(priv->status & STATUS_EXIT_PENDING)) {
10615 /* Queue up another scan... */
10616 queue_work(priv->workqueue, &priv->request_scan);
10617 }
James Ketrenosa613bff2005-08-24 21:43:11 -050010618}
10619
James Ketrenosc848d0a2005-08-24 21:56:24 -050010620static void ipw_bg_link_down(void *data)
10621{
10622 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010623 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010624 ipw_link_down(data);
Zhu Yi46441512006-01-24 16:37:59 +080010625 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010626}
10627
James Ketrenos43f66a62005-03-25 12:31:53 -060010628static int ipw_setup_deferred_work(struct ipw_priv *priv)
10629{
10630 int ret = 0;
10631
James Ketrenos43f66a62005-03-25 12:31:53 -060010632 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010633 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010634 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010635
James Ketrenosc848d0a2005-08-24 21:56:24 -050010636 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10637 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10638 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
Zhu Yid8bad6d2005-07-13 12:25:38 -050010639 INIT_WORK(&priv->system_config, ipw_system_config, priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010640 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10641 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10642 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10643 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10644 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010645 INIT_WORK(&priv->request_scan,
James Ketrenos43f66a62005-03-25 12:31:53 -060010646 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010647 INIT_WORK(&priv->gather_stats,
James Ketrenosc848d0a2005-08-24 21:56:24 -050010648 (void (*)(void *))ipw_bg_gather_stats, priv);
10649 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10650 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10651 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10652 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10653 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10654 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
James Ketrenosa613bff2005-08-24 21:43:11 -050010655 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010656 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
James Ketrenosa613bff2005-08-24 21:43:11 -050010657 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010658 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10659 priv);
10660 INIT_WORK(&priv->merge_networks,
10661 (void (*)(void *))ipw_merge_adhoc_network, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010662
Zhu Yie43e3c12006-04-13 17:20:45 +080010663#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010664 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10665 priv);
Zhu Yie43e3c12006-04-13 17:20:45 +080010666#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010667
10668 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10669 ipw_irq_tasklet, (unsigned long)priv);
10670
10671 return ret;
10672}
10673
James Ketrenos43f66a62005-03-25 12:31:53 -060010674static void shim__set_security(struct net_device *dev,
10675 struct ieee80211_security *sec)
10676{
10677 struct ipw_priv *priv = ieee80211_priv(dev);
10678 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010679 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010680 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010681 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010682 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010683 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010684 priv->ieee->sec.flags &= ~(1 << i);
10685 else {
10686 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010687 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010688 priv->ieee->sec.flags |= (1 << i);
10689 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010690 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010691 } else if (sec->level != SEC_LEVEL_1)
10692 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010693 }
10694
James Ketrenosb095c382005-08-24 22:04:42 -050010695 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010696 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010697 priv->ieee->sec.active_key = sec->active_key;
10698 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010699 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010700 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010701 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010702 } else
10703 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010704
10705 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010706 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10707 priv->ieee->sec.auth_mode = sec->auth_mode;
10708 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010709 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10710 priv->capability |= CAP_SHARED_KEY;
10711 else
10712 priv->capability &= ~CAP_SHARED_KEY;
10713 priv->status |= STATUS_SECURITY_UPDATED;
10714 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010715
James Ketrenosb095c382005-08-24 22:04:42 -050010716 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10717 priv->ieee->sec.flags |= SEC_ENABLED;
10718 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010719 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010720 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010721 priv->capability |= CAP_PRIVACY_ON;
10722 else
10723 priv->capability &= ~CAP_PRIVACY_ON;
10724 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010725
James Ketrenosafbf30a2005-08-25 00:05:33 -050010726 if (sec->flags & SEC_ENCRYPT)
10727 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010728
James Ketrenosb095c382005-08-24 22:04:42 -050010729 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10730 priv->ieee->sec.level = sec->level;
10731 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010732 priv->status |= STATUS_SECURITY_UPDATED;
10733 }
10734
Zhu Yi1fbfea52005-08-05 17:22:56 +080010735 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10736 ipw_set_hwcrypto_keys(priv);
10737
Jeff Garzikbf794512005-07-31 13:07:26 -040010738 /* To match current functionality of ipw2100 (which works well w/
10739 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010740 * privacy capability changes ... */
10741#if 0
10742 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010743 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -060010744 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010745 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010746 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010747 IPW_DEBUG_ASSOC("Disassociating due to capability "
10748 "change.\n");
10749 ipw_disassociate(priv);
10750 }
10751#endif
10752}
10753
Jeff Garzikbf794512005-07-31 13:07:26 -040010754static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010755 struct ipw_supported_rates *rates)
10756{
10757 /* TODO: Mask out rates based on priv->rates_mask */
10758
10759 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010760 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010761 switch (priv->ieee->freq_band) {
10762 case IEEE80211_52GHZ_BAND:
10763 rates->ieee_mode = IPW_A_MODE;
10764 rates->purpose = IPW_RATE_CAPABILITIES;
10765 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10766 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10767 break;
10768
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010769 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010770 rates->ieee_mode = IPW_G_MODE;
10771 rates->purpose = IPW_RATE_CAPABILITIES;
10772 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10773 IEEE80211_CCK_DEFAULT_RATES_MASK);
10774 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10775 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10776 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10777 }
10778 break;
10779 }
10780
10781 return 0;
10782}
10783
Jeff Garzikbf794512005-07-31 13:07:26 -040010784static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010785{
James Ketrenos43f66a62005-03-25 12:31:53 -060010786 /* This is only called from ipw_up, which resets/reloads the firmware
10787 so, we don't need to first disable the card before we configure
10788 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010789 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010790 goto error;
10791
10792 /* initialize adapter address */
10793 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10794 goto error;
10795
10796 /* set basic system config settings */
10797 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010798
10799 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10800 * Does not support BT priority yet (don't abort or defer our Tx) */
10801 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010802 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010803
10804 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10805 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010806 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010807 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10808 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010809 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010810 }
10811
Zhu Yid685b8c2006-04-13 17:20:27 +080010812#ifdef CONFIG_IPW2200_PROMISCUOUS
10813 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10814 priv->sys_config.accept_all_data_frames = 1;
10815 priv->sys_config.accept_non_directed_frames = 1;
10816 priv->sys_config.accept_all_mgmt_bcpr = 1;
10817 priv->sys_config.accept_all_mgmt_frames = 1;
10818 }
10819#endif
10820
James Ketrenosc848d0a2005-08-24 21:56:24 -050010821 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10822 priv->sys_config.answer_broadcast_ssid_probe = 1;
10823 else
10824 priv->sys_config.answer_broadcast_ssid_probe = 0;
10825
Zhu Yid685b8c2006-04-13 17:20:27 +080010826 if (ipw_send_system_config(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010827 goto error;
10828
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010829 init_supported_rates(priv, &priv->rates);
10830 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010831 goto error;
10832
10833 /* Set request-to-send threshold */
10834 if (priv->rts_threshold) {
10835 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10836 goto error;
10837 }
Zhu Yie43e3c12006-04-13 17:20:45 +080010838#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010839 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10840 ipw_qos_activate(priv, NULL);
Zhu Yie43e3c12006-04-13 17:20:45 +080010841#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010842
10843 if (ipw_set_random_seed(priv))
10844 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010845
James Ketrenos43f66a62005-03-25 12:31:53 -060010846 /* final state transition to the RUN state */
10847 if (ipw_send_host_complete(priv))
10848 goto error;
10849
James Ketrenose6666192005-08-12 09:17:04 -050010850 priv->status |= STATUS_INIT;
10851
10852 ipw_led_init(priv);
10853 ipw_led_radio_on(priv);
10854 priv->notif_missed_beacons = 0;
10855
10856 /* Set hardware WEP key if it is configured. */
10857 if ((priv->capability & CAP_PRIVACY_ON) &&
10858 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10859 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10860 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010861
10862 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010863
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010864 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010865 return -EIO;
10866}
10867
James Ketrenos4f36f802005-08-03 20:36:56 -050010868/*
10869 * NOTE:
10870 *
10871 * These tables have been tested in conjunction with the
10872 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10873 *
10874 * Altering this values, using it on other hardware, or in geographies
10875 * not intended for resale of the above mentioned Intel adapters has
10876 * not been tested.
10877 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080010878 * Remember to update the table in README.ipw2200 when changing this
10879 * table.
10880 *
James Ketrenos4f36f802005-08-03 20:36:56 -050010881 */
10882static const struct ieee80211_geo ipw_geos[] = {
10883 { /* Restricted */
10884 "---",
10885 .bg_channels = 11,
10886 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10887 {2427, 4}, {2432, 5}, {2437, 6},
10888 {2442, 7}, {2447, 8}, {2452, 9},
10889 {2457, 10}, {2462, 11}},
10890 },
10891
10892 { /* Custom US/Canada */
10893 "ZZF",
10894 .bg_channels = 11,
10895 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10896 {2427, 4}, {2432, 5}, {2437, 6},
10897 {2442, 7}, {2447, 8}, {2452, 9},
10898 {2457, 10}, {2462, 11}},
10899 .a_channels = 8,
10900 .a = {{5180, 36},
10901 {5200, 40},
10902 {5220, 44},
10903 {5240, 48},
10904 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10905 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10906 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10907 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10908 },
10909
10910 { /* Rest of World */
10911 "ZZD",
10912 .bg_channels = 13,
10913 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10914 {2427, 4}, {2432, 5}, {2437, 6},
10915 {2442, 7}, {2447, 8}, {2452, 9},
10916 {2457, 10}, {2462, 11}, {2467, 12},
10917 {2472, 13}},
10918 },
10919
10920 { /* Custom USA & Europe & High */
10921 "ZZA",
10922 .bg_channels = 11,
10923 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10924 {2427, 4}, {2432, 5}, {2437, 6},
10925 {2442, 7}, {2447, 8}, {2452, 9},
10926 {2457, 10}, {2462, 11}},
10927 .a_channels = 13,
10928 .a = {{5180, 36},
10929 {5200, 40},
10930 {5220, 44},
10931 {5240, 48},
10932 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10933 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10934 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10935 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10936 {5745, 149},
10937 {5765, 153},
10938 {5785, 157},
10939 {5805, 161},
10940 {5825, 165}},
10941 },
10942
10943 { /* Custom NA & Europe */
10944 "ZZB",
10945 .bg_channels = 11,
10946 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10947 {2427, 4}, {2432, 5}, {2437, 6},
10948 {2442, 7}, {2447, 8}, {2452, 9},
10949 {2457, 10}, {2462, 11}},
10950 .a_channels = 13,
10951 .a = {{5180, 36},
10952 {5200, 40},
10953 {5220, 44},
10954 {5240, 48},
10955 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10956 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10957 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10958 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10959 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10960 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10961 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10962 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10963 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10964 },
10965
10966 { /* Custom Japan */
10967 "ZZC",
10968 .bg_channels = 11,
10969 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10970 {2427, 4}, {2432, 5}, {2437, 6},
10971 {2442, 7}, {2447, 8}, {2452, 9},
10972 {2457, 10}, {2462, 11}},
10973 .a_channels = 4,
10974 .a = {{5170, 34}, {5190, 38},
10975 {5210, 42}, {5230, 46}},
10976 },
10977
10978 { /* Custom */
10979 "ZZM",
10980 .bg_channels = 11,
10981 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10982 {2427, 4}, {2432, 5}, {2437, 6},
10983 {2442, 7}, {2447, 8}, {2452, 9},
10984 {2457, 10}, {2462, 11}},
10985 },
10986
10987 { /* Europe */
10988 "ZZE",
10989 .bg_channels = 13,
10990 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10991 {2427, 4}, {2432, 5}, {2437, 6},
10992 {2442, 7}, {2447, 8}, {2452, 9},
10993 {2457, 10}, {2462, 11}, {2467, 12},
10994 {2472, 13}},
10995 .a_channels = 19,
10996 .a = {{5180, 36},
10997 {5200, 40},
10998 {5220, 44},
10999 {5240, 48},
11000 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11001 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11002 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11003 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11004 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
11005 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
11006 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
11007 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
11008 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
11009 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
11010 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
11011 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
11012 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
11013 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
11014 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
11015 },
11016
11017 { /* Custom Japan */
11018 "ZZJ",
11019 .bg_channels = 14,
11020 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11021 {2427, 4}, {2432, 5}, {2437, 6},
11022 {2442, 7}, {2447, 8}, {2452, 9},
11023 {2457, 10}, {2462, 11}, {2467, 12},
11024 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
11025 .a_channels = 4,
11026 .a = {{5170, 34}, {5190, 38},
11027 {5210, 42}, {5230, 46}},
11028 },
11029
James Ketrenos03520572005-10-19 16:12:31 -050011030 { /* Rest of World */
11031 "ZZR",
11032 .bg_channels = 14,
11033 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11034 {2427, 4}, {2432, 5}, {2437, 6},
11035 {2442, 7}, {2447, 8}, {2452, 9},
11036 {2457, 10}, {2462, 11}, {2467, 12},
11037 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
11038 IEEE80211_CH_PASSIVE_ONLY}},
11039 },
11040
James Ketrenos4f36f802005-08-03 20:36:56 -050011041 { /* High Band */
11042 "ZZH",
11043 .bg_channels = 13,
11044 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11045 {2427, 4}, {2432, 5}, {2437, 6},
11046 {2442, 7}, {2447, 8}, {2452, 9},
11047 {2457, 10}, {2462, 11},
11048 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
11049 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
11050 .a_channels = 4,
11051 .a = {{5745, 149}, {5765, 153},
11052 {5785, 157}, {5805, 161}},
11053 },
11054
11055 { /* Custom Europe */
11056 "ZZG",
11057 .bg_channels = 13,
11058 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11059 {2427, 4}, {2432, 5}, {2437, 6},
11060 {2442, 7}, {2447, 8}, {2452, 9},
11061 {2457, 10}, {2462, 11},
11062 {2467, 12}, {2472, 13}},
11063 .a_channels = 4,
11064 .a = {{5180, 36}, {5200, 40},
11065 {5220, 44}, {5240, 48}},
11066 },
11067
11068 { /* Europe */
11069 "ZZK",
11070 .bg_channels = 13,
11071 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11072 {2427, 4}, {2432, 5}, {2437, 6},
11073 {2442, 7}, {2447, 8}, {2452, 9},
11074 {2457, 10}, {2462, 11},
11075 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
11076 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
11077 .a_channels = 24,
11078 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
11079 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
11080 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
11081 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
11082 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11083 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11084 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11085 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11086 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
11087 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
11088 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
11089 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
11090 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
11091 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
11092 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
11093 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
11094 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
11095 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
11096 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
11097 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11098 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11099 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11100 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11101 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11102 },
11103
11104 { /* Europe */
11105 "ZZL",
11106 .bg_channels = 11,
11107 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11108 {2427, 4}, {2432, 5}, {2437, 6},
11109 {2442, 7}, {2447, 8}, {2452, 9},
11110 {2457, 10}, {2462, 11}},
11111 .a_channels = 13,
11112 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
11113 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
11114 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
11115 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
11116 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11117 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11118 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11119 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11120 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11121 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11122 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11123 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11124 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11125 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050011126};
11127
James Ketrenos43f66a62005-03-25 12:31:53 -060011128#define MAX_HW_RESTARTS 5
11129static int ipw_up(struct ipw_priv *priv)
11130{
James Ketrenos4f36f802005-08-03 20:36:56 -050011131 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060011132
11133 if (priv->status & STATUS_EXIT_PENDING)
11134 return -EIO;
11135
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011136 if (cmdlog && !priv->cmdlog) {
11137 priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
11138 GFP_KERNEL);
11139 if (priv->cmdlog == NULL) {
11140 IPW_ERROR("Error allocating %d command log entries.\n",
11141 cmdlog);
Zhu Yid0b526b2006-04-13 17:19:50 +080011142 return -ENOMEM;
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011143 } else {
11144 memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
11145 priv->cmdlog_len = cmdlog;
11146 }
11147 }
11148
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011149 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040011150 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060011151 * Also start the clocks. */
11152 rc = ipw_load(priv);
11153 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050011154 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011155 return rc;
11156 }
11157
11158 ipw_init_ordinals(priv);
11159 if (!(priv->config & CFG_CUSTOM_MAC))
11160 eeprom_parse_mac(priv, priv->mac_addr);
11161 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
11162
James Ketrenos4f36f802005-08-03 20:36:56 -050011163 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11164 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11165 ipw_geos[j].name, 3))
11166 break;
11167 }
James Ketrenos03520572005-10-19 16:12:31 -050011168 if (j == ARRAY_SIZE(ipw_geos)) {
11169 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11170 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11171 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11172 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050011173 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050011174 }
Larry Finger1867b112006-02-28 09:48:28 -060011175 if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050011176 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060011177 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050011178 }
11179
James Ketrenosb095c382005-08-24 22:04:42 -050011180 if (priv->status & STATUS_RF_KILL_SW) {
11181 IPW_WARNING("Radio disabled by module parameter.\n");
11182 return 0;
11183 } else if (rf_kill_active(priv)) {
11184 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11185 "Kill switch must be turned off for "
11186 "wireless networking to work.\n");
11187 queue_delayed_work(priv->workqueue, &priv->rf_kill,
11188 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060011189 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050011190 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011191
11192 rc = ipw_config(priv);
11193 if (!rc) {
11194 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011195
James Ketrenose6666192005-08-12 09:17:04 -050011196 /* If configure to try and auto-associate, kick
11197 * off a scan. */
11198 queue_work(priv->workqueue, &priv->request_scan);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011199
James Ketrenos43f66a62005-03-25 12:31:53 -060011200 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011201 }
Jeff Garzikbf794512005-07-31 13:07:26 -040011202
James Ketrenosc848d0a2005-08-24 21:56:24 -050011203 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011204 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11205 i, MAX_HW_RESTARTS);
11206
11207 /* We had an error bringing up the hardware, so take it
11208 * all the way back down so we can try again */
11209 ipw_down(priv);
11210 }
11211
Jeff Garzikbf794512005-07-31 13:07:26 -040011212 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060011213 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011214 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011215
James Ketrenos43f66a62005-03-25 12:31:53 -060011216 return -EIO;
11217}
11218
James Ketrenosc848d0a2005-08-24 21:56:24 -050011219static void ipw_bg_up(void *data)
11220{
11221 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080011222 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011223 ipw_up(data);
Zhu Yi46441512006-01-24 16:37:59 +080011224 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011225}
11226
James Ketrenosb095c382005-08-24 22:04:42 -050011227static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060011228{
James Ketrenosb095c382005-08-24 22:04:42 -050011229 int i;
11230
11231 if (priv->status & STATUS_SCANNING) {
11232 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11233 ipw_abort_scan(priv);
11234 }
11235
11236 if (priv->status & STATUS_ASSOCIATED) {
11237 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11238 ipw_disassociate(priv);
11239 }
11240
11241 ipw_led_shutdown(priv);
11242
11243 /* Wait up to 1s for status to change to not scanning and not
11244 * associated (disassociation can take a while for a ful 802.11
11245 * exchange */
11246 for (i = 1000; i && (priv->status &
11247 (STATUS_DISASSOCIATING |
11248 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11249 udelay(10);
11250
11251 if (priv->status & (STATUS_DISASSOCIATING |
11252 STATUS_ASSOCIATED | STATUS_SCANNING))
11253 IPW_DEBUG_INFO("Still associated or scanning...\n");
11254 else
11255 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11256
James Ketrenosc848d0a2005-08-24 21:56:24 -050011257 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060011258 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050011259
11260 priv->status &= ~STATUS_INIT;
11261}
11262
James Ketrenos43f66a62005-03-25 12:31:53 -060011263static void ipw_down(struct ipw_priv *priv)
11264{
James Ketrenosb095c382005-08-24 22:04:42 -050011265 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11266
11267 priv->status |= STATUS_EXIT_PENDING;
11268
11269 if (ipw_is_init(priv))
11270 ipw_deinit(priv);
11271
11272 /* Wipe out the EXIT_PENDING status bit if we are not actually
11273 * exiting the module */
11274 if (!exit_pending)
11275 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011276
11277 /* tell the device to stop sending interrupts */
11278 ipw_disable_interrupts(priv);
11279
11280 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050011281 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011282 netif_carrier_off(priv->net_dev);
11283 netif_stop_queue(priv->net_dev);
11284
11285 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050011286
11287 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011288}
11289
James Ketrenosc848d0a2005-08-24 21:56:24 -050011290static void ipw_bg_down(void *data)
11291{
11292 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080011293 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011294 ipw_down(data);
Zhu Yi46441512006-01-24 16:37:59 +080011295 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011296}
11297
11298/* Called by register_netdev() */
11299static int ipw_net_init(struct net_device *dev)
11300{
11301 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +080011302 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011303
James Ketrenosc848d0a2005-08-24 21:56:24 -050011304 if (ipw_up(priv)) {
Zhu Yi46441512006-01-24 16:37:59 +080011305 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011306 return -EIO;
James Ketrenos43f66a62005-03-25 12:31:53 -060011307 }
11308
Zhu Yi46441512006-01-24 16:37:59 +080011309 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011310 return 0;
11311}
11312
11313/* PCI driver stuff */
11314static struct pci_device_id card_ids[] = {
11315 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11316 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11317 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11318 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11319 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11320 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11321 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11322 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11323 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11324 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11325 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11326 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11327 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11328 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11329 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11330 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11331 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
11332 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011333 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
James Ketrenosa613bff2005-08-24 21:43:11 -050011334 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011335 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
11336 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040011337
James Ketrenos43f66a62005-03-25 12:31:53 -060011338 /* required last entry */
11339 {0,}
11340};
11341
11342MODULE_DEVICE_TABLE(pci, card_ids);
11343
11344static struct attribute *ipw_sysfs_entries[] = {
11345 &dev_attr_rf_kill.attr,
11346 &dev_attr_direct_dword.attr,
11347 &dev_attr_indirect_byte.attr,
11348 &dev_attr_indirect_dword.attr,
11349 &dev_attr_mem_gpio_reg.attr,
11350 &dev_attr_command_event_reg.attr,
11351 &dev_attr_nic_type.attr,
11352 &dev_attr_status.attr,
11353 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011354 &dev_attr_error.attr,
11355 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011356 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011357 &dev_attr_eeprom_delay.attr,
11358 &dev_attr_ucode_version.attr,
11359 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011360 &dev_attr_scan_age.attr,
11361 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011362 &dev_attr_speed_scan.attr,
11363 &dev_attr_net_stats.attr,
Zhu Yid685b8c2006-04-13 17:20:27 +080011364#ifdef CONFIG_IPW2200_PROMISCUOUS
11365 &dev_attr_rtap_iface.attr,
11366 &dev_attr_rtap_filter.attr,
11367#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011368 NULL
11369};
11370
11371static struct attribute_group ipw_attribute_group = {
11372 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011373 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011374};
11375
Zhu Yid685b8c2006-04-13 17:20:27 +080011376#ifdef CONFIG_IPW2200_PROMISCUOUS
11377static int ipw_prom_open(struct net_device *dev)
11378{
11379 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11380 struct ipw_priv *priv = prom_priv->priv;
11381
11382 IPW_DEBUG_INFO("prom dev->open\n");
11383 netif_carrier_off(dev);
11384 netif_stop_queue(dev);
11385
11386 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11387 priv->sys_config.accept_all_data_frames = 1;
11388 priv->sys_config.accept_non_directed_frames = 1;
11389 priv->sys_config.accept_all_mgmt_bcpr = 1;
11390 priv->sys_config.accept_all_mgmt_frames = 1;
11391
11392 ipw_send_system_config(priv);
11393 }
11394
11395 return 0;
11396}
11397
11398static int ipw_prom_stop(struct net_device *dev)
11399{
11400 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11401 struct ipw_priv *priv = prom_priv->priv;
11402
11403 IPW_DEBUG_INFO("prom dev->stop\n");
11404
11405 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11406 priv->sys_config.accept_all_data_frames = 0;
11407 priv->sys_config.accept_non_directed_frames = 0;
11408 priv->sys_config.accept_all_mgmt_bcpr = 0;
11409 priv->sys_config.accept_all_mgmt_frames = 0;
11410
11411 ipw_send_system_config(priv);
11412 }
11413
11414 return 0;
11415}
11416
11417static int ipw_prom_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
11418{
11419 IPW_DEBUG_INFO("prom dev->xmit\n");
11420 netif_stop_queue(dev);
11421 return -EOPNOTSUPP;
11422}
11423
11424static struct net_device_stats *ipw_prom_get_stats(struct net_device *dev)
11425{
11426 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11427 return &prom_priv->ieee->stats;
11428}
11429
11430static int ipw_prom_alloc(struct ipw_priv *priv)
11431{
11432 int rc = 0;
11433
11434 if (priv->prom_net_dev)
11435 return -EPERM;
11436
11437 priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv));
11438 if (priv->prom_net_dev == NULL)
11439 return -ENOMEM;
11440
11441 priv->prom_priv = ieee80211_priv(priv->prom_net_dev);
11442 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11443 priv->prom_priv->priv = priv;
11444
11445 strcpy(priv->prom_net_dev->name, "rtap%d");
11446
11447 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
11448 priv->prom_net_dev->open = ipw_prom_open;
11449 priv->prom_net_dev->stop = ipw_prom_stop;
11450 priv->prom_net_dev->get_stats = ipw_prom_get_stats;
11451 priv->prom_net_dev->hard_start_xmit = ipw_prom_hard_start_xmit;
11452
11453 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
11454
11455 rc = register_netdev(priv->prom_net_dev);
11456 if (rc) {
11457 free_ieee80211(priv->prom_net_dev);
11458 priv->prom_net_dev = NULL;
11459 return rc;
11460 }
11461
11462 return 0;
11463}
11464
11465static void ipw_prom_free(struct ipw_priv *priv)
11466{
11467 if (!priv->prom_net_dev)
11468 return;
11469
11470 unregister_netdev(priv->prom_net_dev);
11471 free_ieee80211(priv->prom_net_dev);
11472
11473 priv->prom_net_dev = NULL;
11474}
11475
11476#endif
11477
11478
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011479static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011480{
11481 int err = 0;
11482 struct net_device *net_dev;
11483 void __iomem *base;
11484 u32 length, val;
11485 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011486 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011487
11488 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
11489 if (net_dev == NULL) {
11490 err = -ENOMEM;
11491 goto out;
11492 }
11493
11494 priv = ieee80211_priv(net_dev);
11495 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011496
James Ketrenos43f66a62005-03-25 12:31:53 -060011497 priv->net_dev = net_dev;
11498 priv->pci_dev = pdev;
Brice Goglin0f52bf92005-12-01 01:41:46 -080011499#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060011500 ipw_debug_level = debug;
11501#endif
Zhu Yi89c318e2006-06-08 22:19:49 -070011502 spin_lock_init(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060011503 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011504 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11505 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011506
Zhu Yi46441512006-01-24 16:37:59 +080011507 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011508 if (pci_enable_device(pdev)) {
11509 err = -ENODEV;
11510 goto out_free_ieee80211;
11511 }
11512
11513 pci_set_master(pdev);
11514
Tobias Klauser0e08b442005-06-20 14:28:41 -070011515 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -040011516 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -070011517 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060011518 if (err) {
11519 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11520 goto out_pci_disable_device;
11521 }
11522
11523 pci_set_drvdata(pdev, priv);
11524
11525 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011526 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011527 goto out_pci_disable_device;
11528
Jeff Garzikbf794512005-07-31 13:07:26 -040011529 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011530 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011531 pci_read_config_dword(pdev, 0x40, &val);
11532 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011533 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011534
James Ketrenos43f66a62005-03-25 12:31:53 -060011535 length = pci_resource_len(pdev, 0);
11536 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011537
James Ketrenos43f66a62005-03-25 12:31:53 -060011538 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
11539 if (!base) {
11540 err = -ENODEV;
11541 goto out_pci_release_regions;
11542 }
11543
11544 priv->hw_base = base;
11545 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11546 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11547
11548 err = ipw_setup_deferred_work(priv);
11549 if (err) {
11550 IPW_ERROR("Unable to setup deferred work\n");
11551 goto out_iounmap;
11552 }
11553
James Ketrenosb095c382005-08-24 22:04:42 -050011554 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011555
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011556 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011557 if (err) {
11558 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11559 goto out_destroy_workqueue;
11560 }
11561
11562 SET_MODULE_OWNER(net_dev);
11563 SET_NETDEV_DEV(net_dev, &pdev->dev);
11564
Zhu Yi46441512006-01-24 16:37:59 +080011565 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011566
James Ketrenos43f66a62005-03-25 12:31:53 -060011567 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11568 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011569 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011570
Zhu Yie43e3c12006-04-13 17:20:45 +080011571#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080011572 priv->ieee->is_qos_active = ipw_is_qos_active;
James Ketrenos3b9990c2005-08-19 13:18:55 -050011573 priv->ieee->handle_probe_response = ipw_handle_beacon;
11574 priv->ieee->handle_beacon = ipw_handle_probe_response;
11575 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
Zhu Yie43e3c12006-04-13 17:20:45 +080011576#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011577
James Ketrenosc848d0a2005-08-24 21:56:24 -050011578 priv->ieee->perfect_rssi = -20;
11579 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011580
11581 net_dev->open = ipw_net_open;
11582 net_dev->stop = ipw_net_stop;
11583 net_dev->init = ipw_net_init;
11584 net_dev->get_stats = ipw_net_get_stats;
11585 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11586 net_dev->set_mac_address = ipw_net_set_mac_address;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011587 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011588 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011589 net_dev->wireless_handlers = &ipw_wx_handler_def;
11590 net_dev->ethtool_ops = &ipw_ethtool_ops;
11591 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011592 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011593 net_dev->mem_start = pci_resource_start(pdev, 0);
11594 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11595
11596 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11597 if (err) {
11598 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011599 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011600 goto out_release_irq;
11601 }
11602
Zhu Yi46441512006-01-24 16:37:59 +080011603 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011604 err = register_netdev(net_dev);
11605 if (err) {
11606 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011607 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011608 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011609
Zhu Yid685b8c2006-04-13 17:20:27 +080011610#ifdef CONFIG_IPW2200_PROMISCUOUS
11611 if (rtap_iface) {
11612 err = ipw_prom_alloc(priv);
11613 if (err) {
11614 IPW_ERROR("Failed to register promiscuous network "
11615 "device (error %d).\n", err);
11616 unregister_netdev(priv->net_dev);
11617 goto out_remove_sysfs;
11618 }
11619 }
11620#endif
11621
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011622 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11623 "channels, %d 802.11a channels)\n",
11624 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11625 priv->ieee->geo.a_channels);
11626
James Ketrenos43f66a62005-03-25 12:31:53 -060011627 return 0;
11628
James Ketrenosa613bff2005-08-24 21:43:11 -050011629 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011630 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011631 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011632 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011633 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011634 destroy_workqueue(priv->workqueue);
11635 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011636 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011637 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011638 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011639 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011640 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011641 pci_disable_device(pdev);
11642 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011643 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -060011644 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011645 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011646 return err;
11647}
11648
11649static void ipw_pci_remove(struct pci_dev *pdev)
11650{
11651 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011652 struct list_head *p, *q;
11653 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011654
James Ketrenos43f66a62005-03-25 12:31:53 -060011655 if (!priv)
11656 return;
11657
Zhu Yi46441512006-01-24 16:37:59 +080011658 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011659
James Ketrenosafbf30a2005-08-25 00:05:33 -050011660 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011661 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011662 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11663
Zhu Yi46441512006-01-24 16:37:59 +080011664 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011665
11666 unregister_netdev(priv->net_dev);
11667
11668 if (priv->rxq) {
11669 ipw_rx_queue_free(priv, priv->rxq);
11670 priv->rxq = NULL;
11671 }
11672 ipw_tx_queue_free(priv);
11673
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011674 if (priv->cmdlog) {
11675 kfree(priv->cmdlog);
11676 priv->cmdlog = NULL;
11677 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011678 /* ipw_down will ensure that there is no more pending work
11679 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011680 cancel_delayed_work(&priv->adhoc_check);
11681 cancel_delayed_work(&priv->gather_stats);
11682 cancel_delayed_work(&priv->request_scan);
11683 cancel_delayed_work(&priv->rf_kill);
11684 cancel_delayed_work(&priv->scan_check);
11685 destroy_workqueue(priv->workqueue);
11686 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011687
James Ketrenosafbf30a2005-08-25 00:05:33 -050011688 /* Free MAC hash list for ADHOC */
11689 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11690 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011691 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011692 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011693 }
11694 }
11695
James Ketrenosb39860c2005-08-12 09:36:32 -050011696 if (priv->error) {
11697 ipw_free_error_log(priv->error);
11698 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011699 }
11700
Zhu Yid685b8c2006-04-13 17:20:27 +080011701#ifdef CONFIG_IPW2200_PROMISCUOUS
11702 ipw_prom_free(priv);
11703#endif
11704
James Ketrenos43f66a62005-03-25 12:31:53 -060011705 free_irq(pdev->irq, priv);
11706 iounmap(priv->hw_base);
11707 pci_release_regions(pdev);
11708 pci_disable_device(pdev);
11709 pci_set_drvdata(pdev, NULL);
11710 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011711 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011712}
11713
James Ketrenos43f66a62005-03-25 12:31:53 -060011714#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011715static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011716{
11717 struct ipw_priv *priv = pci_get_drvdata(pdev);
11718 struct net_device *dev = priv->net_dev;
11719
11720 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11721
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011722 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011723 ipw_down(priv);
11724
11725 /* Remove the PRESENT state of the device */
11726 netif_device_detach(dev);
11727
James Ketrenos43f66a62005-03-25 12:31:53 -060011728 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011729 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011730 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011731
James Ketrenos43f66a62005-03-25 12:31:53 -060011732 return 0;
11733}
11734
11735static int ipw_pci_resume(struct pci_dev *pdev)
11736{
11737 struct ipw_priv *priv = pci_get_drvdata(pdev);
11738 struct net_device *dev = priv->net_dev;
11739 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011740
James Ketrenos43f66a62005-03-25 12:31:53 -060011741 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11742
James Ketrenosea2b26e2005-08-24 21:25:16 -050011743 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011744 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011745 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011746
James Ketrenos43f66a62005-03-25 12:31:53 -060011747 /*
11748 * Suspend/Resume resets the PCI configuration space, so we have to
11749 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11750 * from interfering with C3 CPU state. pci_restore_state won't help
11751 * here since it only restores the first 64 bytes pci config header.
11752 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011753 pci_read_config_dword(pdev, 0x40, &val);
11754 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011755 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11756
11757 /* Set the device back into the PRESENT state; this will also wake
11758 * the queue of needed */
11759 netif_device_attach(dev);
11760
11761 /* Bring the device back up */
11762 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011763
James Ketrenos43f66a62005-03-25 12:31:53 -060011764 return 0;
11765}
11766#endif
11767
11768/* driver initialization stuff */
11769static struct pci_driver ipw_driver = {
11770 .name = DRV_NAME,
11771 .id_table = card_ids,
11772 .probe = ipw_pci_probe,
11773 .remove = __devexit_p(ipw_pci_remove),
11774#ifdef CONFIG_PM
11775 .suspend = ipw_pci_suspend,
11776 .resume = ipw_pci_resume,
11777#endif
11778};
11779
11780static int __init ipw_init(void)
11781{
11782 int ret;
11783
11784 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11785 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11786
11787 ret = pci_module_init(&ipw_driver);
11788 if (ret) {
11789 IPW_ERROR("Unable to initialize PCI module\n");
11790 return ret;
11791 }
11792
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011793 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011794 if (ret) {
11795 IPW_ERROR("Unable to create driver sysfs file\n");
11796 pci_unregister_driver(&ipw_driver);
11797 return ret;
11798 }
11799
11800 return ret;
11801}
11802
11803static void __exit ipw_exit(void)
11804{
11805 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11806 pci_unregister_driver(&ipw_driver);
11807}
11808
11809module_param(disable, int, 0444);
11810MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11811
11812module_param(associate, int, 0444);
11813MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11814
11815module_param(auto_create, int, 0444);
11816MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11817
James Ketrenosa613bff2005-08-24 21:43:11 -050011818module_param(led, int, 0444);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011819MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011820
Zhu Yi3e1555b2006-03-06 05:48:37 +080011821#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060011822module_param(debug, int, 0444);
11823MODULE_PARM_DESC(debug, "debug output mask");
Zhu Yi3e1555b2006-03-06 05:48:37 +080011824#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011825
11826module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011827MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011828
Zhu Yid685b8c2006-04-13 17:20:27 +080011829#ifdef CONFIG_IPW2200_PROMISCUOUS
11830module_param(rtap_iface, int, 0444);
11831MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
11832#endif
11833
Zhu Yie43e3c12006-04-13 17:20:45 +080011834#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050011835module_param(qos_enable, int, 0444);
11836MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060011837
James Ketrenosb095c382005-08-24 22:04:42 -050011838module_param(qos_burst_enable, int, 0444);
11839MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11840
11841module_param(qos_no_ack_mask, int, 0444);
11842MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11843
11844module_param(burst_duration_CCK, int, 0444);
11845MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11846
11847module_param(burst_duration_OFDM, int, 0444);
11848MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
Zhu Yie43e3c12006-04-13 17:20:45 +080011849#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011850
11851#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -060011852module_param(mode, int, 0444);
11853MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11854#else
11855module_param(mode, int, 0444);
11856MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11857#endif
11858
Zhu Yi810dabd2006-01-24 16:36:59 +080011859module_param(bt_coexist, int, 0444);
11860MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
11861
James Ketrenosb095c382005-08-24 22:04:42 -050011862module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080011863MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050011864
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011865module_param(cmdlog, int, 0444);
11866MODULE_PARM_DESC(cmdlog,
11867 "allocate a ring buffer for logging firmware commands");
11868
Zhu Yi4bfdb912006-01-24 16:37:16 +080011869module_param(roaming, int, 0444);
11870MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
11871
Zhu Yid2b83e12006-04-13 17:19:36 +080011872module_param(antenna, int, 0444);
11873MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
11874
James Ketrenos43f66a62005-03-25 12:31:53 -060011875module_exit(ipw_exit);
11876module_init(ipw_init);