blob: a8a8f975432fe1e32a3fb04aa0a4bc2d59d94e24 [file] [log] [blame]
James Ketrenos43f66a62005-03-25 12:31:53 -06001/******************************************************************************
Jeff Garzikbf794512005-07-31 13:07:26 -04002
Zhu Yi171e7b22006-02-15 07:17:56 +08003 Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved.
James Ketrenos43f66a62005-03-25 12:31:53 -06004
5 802.11 status code portion of this file from ethereal-0.10.6:
6 Copyright 2000, Axis Communications AB
7 Ethereal - Network traffic analyzer
8 By Gerald Combs <gerald@ethereal.com>
9 Copyright 1998 Gerald Combs
10
Jeff Garzikbf794512005-07-31 13:07:26 -040011 This program is free software; you can redistribute it and/or modify it
12 under the terms of version 2 of the GNU General Public License as
James Ketrenos43f66a62005-03-25 12:31:53 -060013 published by the Free Software Foundation.
Jeff Garzikbf794512005-07-31 13:07:26 -040014
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
James Ketrenos43f66a62005-03-25 12:31:53 -060018 more details.
Jeff Garzikbf794512005-07-31 13:07:26 -040019
James Ketrenos43f66a62005-03-25 12:31:53 -060020 You should have received a copy of the GNU General Public License along with
Jeff Garzikbf794512005-07-31 13:07:26 -040021 this program; if not, write to the Free Software Foundation, Inc., 59
James Ketrenos43f66a62005-03-25 12:31:53 -060022 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Jeff Garzikbf794512005-07-31 13:07:26 -040023
James Ketrenos43f66a62005-03-25 12:31:53 -060024 The full GNU General Public License is included in this distribution in the
25 file called LICENSE.
Jeff Garzikbf794512005-07-31 13:07:26 -040026
James Ketrenos43f66a62005-03-25 12:31:53 -060027 Contact Information:
28 James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30
31******************************************************************************/
32
33#include "ipw2200.h"
Olaf Hering733482e2005-11-08 21:34:55 -080034#include <linux/version.h>
James Ketrenos43f66a62005-03-25 12:31:53 -060035
Zhu Yiae4af612006-04-13 17:20:34 +080036
37#ifndef KBUILD_EXTMOD
38#define VK "k"
39#else
40#define VK
41#endif
42
43#ifdef CONFIG_IPW2200_DEBUG
44#define VD "d"
45#else
46#define VD
47#endif
48
49#ifdef CONFIG_IPW2200_MONITOR
50#define VM "m"
51#else
52#define VM
53#endif
54
55#ifdef CONFIG_IPW2200_PROMISCUOUS
56#define VP "p"
57#else
58#define VP
59#endif
60
Zhu Yi459d4082006-04-13 17:21:00 +080061#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yiae4af612006-04-13 17:20:34 +080062#define VR "r"
63#else
64#define VR
65#endif
66
67#ifdef CONFIG_IPW2200_QOS
68#define VQ "q"
69#else
70#define VQ
71#endif
72
Zhu Yi555fd912006-04-13 17:20:40 +080073#define IPW2200_VERSION "1.1.2" VK VD VM VP VR VQ
James Ketrenos43f66a62005-03-25 12:31:53 -060074#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
Zhu Yi171e7b22006-02-15 07:17:56 +080075#define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
James Ketrenos43f66a62005-03-25 12:31:53 -060076#define DRV_VERSION IPW2200_VERSION
77
James Ketrenosb095c382005-08-24 22:04:42 -050078#define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
79
James Ketrenos43f66a62005-03-25 12:31:53 -060080MODULE_DESCRIPTION(DRV_DESCRIPTION);
81MODULE_VERSION(DRV_VERSION);
82MODULE_AUTHOR(DRV_COPYRIGHT);
83MODULE_LICENSE("GPL");
84
James Ketrenosf6c5cb72005-08-25 00:39:09 -050085static int cmdlog = 0;
Zhu Yi5dc81c32006-04-13 17:19:44 +080086#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060087static int debug = 0;
Zhu Yi5dc81c32006-04-13 17:19:44 +080088#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060089static int channel = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060090static int mode = 0;
91
92static u32 ipw_debug_level;
93static int associate = 1;
94static int auto_create = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -050095static int led = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060096static int disable = 0;
Zhu Yi810dabd2006-01-24 16:36:59 +080097static int bt_coexist = 0;
Zhu Yibde37d02006-01-24 16:38:08 +080098static int hwcrypto = 0;
Zhu Yi4bfdb912006-01-24 16:37:16 +080099static int roaming = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -0600100static const char ipw_modes[] = {
101 'a', 'b', 'g', '?'
102};
Zhu Yid2b83e12006-04-13 17:19:36 +0800103static int antenna = CFG_SYS_ANTENNA_BOTH;
James Ketrenos43f66a62005-03-25 12:31:53 -0600104
Zhu Yid685b8c2006-04-13 17:20:27 +0800105#ifdef CONFIG_IPW2200_PROMISCUOUS
106static int rtap_iface = 0; /* def: 0 -- do not create rtap interface */
107#endif
108
109
Zhu Yie43e3c12006-04-13 17:20:45 +0800110#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -0500111static int qos_enable = 0;
112static int qos_burst_enable = 0;
113static int qos_no_ack_mask = 0;
114static int burst_duration_CCK = 0;
115static int burst_duration_OFDM = 0;
116
117static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
118 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
119 QOS_TX3_CW_MIN_OFDM},
120 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
121 QOS_TX3_CW_MAX_OFDM},
122 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
123 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
124 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
125 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
126};
127
128static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
129 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
130 QOS_TX3_CW_MIN_CCK},
131 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
132 QOS_TX3_CW_MAX_CCK},
133 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
134 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
135 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
136 QOS_TX3_TXOP_LIMIT_CCK}
137};
138
139static struct ieee80211_qos_parameters def_parameters_OFDM = {
140 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
141 DEF_TX3_CW_MIN_OFDM},
142 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
143 DEF_TX3_CW_MAX_OFDM},
144 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
145 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
146 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
147 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
148};
149
150static struct ieee80211_qos_parameters def_parameters_CCK = {
151 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
152 DEF_TX3_CW_MIN_CCK},
153 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
154 DEF_TX3_CW_MAX_CCK},
155 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
156 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
157 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
158 DEF_TX3_TXOP_LIMIT_CCK}
159};
160
161static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
162
163static int from_priority_to_tx_queue[] = {
164 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
165 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
166};
167
168static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
169
170static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
171 *qos_param);
172static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
173 *qos_param);
Zhu Yie43e3c12006-04-13 17:20:45 +0800174#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -0500175
Benoit Boissinot97a78ca2005-09-15 17:30:28 +0000176static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
James Ketrenosb095c382005-08-24 22:04:42 -0500177static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600178static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400179static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600180 struct clx2_tx_queue *txq, int qindex);
181static int ipw_queue_reset(struct ipw_priv *priv);
182
183static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
184 int len, int sync);
185
186static void ipw_tx_queue_free(struct ipw_priv *);
187
188static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
189static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
190static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600191static int ipw_up(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500192static void ipw_bg_up(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600193static void ipw_down(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500194static void ipw_bg_down(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600195static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400196static int init_supported_rates(struct ipw_priv *priv,
197 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500198static void ipw_set_hwcrypto_keys(struct ipw_priv *);
199static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600200
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500201static int snprint_line(char *buf, size_t count,
202 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600203{
204 int out, i, j, l;
205 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400206
James Ketrenos43f66a62005-03-25 12:31:53 -0600207 out = snprintf(buf, count, "%08X", ofs);
208
209 for (l = 0, i = 0; i < 2; i++) {
210 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400211 for (j = 0; j < 8 && l < len; j++, l++)
212 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600213 data[(i * 8 + j)]);
214 for (; j < 8; j++)
215 out += snprintf(buf + out, count - out, " ");
216 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400217
James Ketrenos43f66a62005-03-25 12:31:53 -0600218 out += snprintf(buf + out, count - out, " ");
219 for (l = 0, i = 0; i < 2; i++) {
220 out += snprintf(buf + out, count - out, " ");
221 for (j = 0; j < 8 && l < len; j++, l++) {
222 c = data[(i * 8 + j)];
223 if (!isascii(c) || !isprint(c))
224 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400225
James Ketrenos43f66a62005-03-25 12:31:53 -0600226 out += snprintf(buf + out, count - out, "%c", c);
227 }
228
229 for (; j < 8; j++)
230 out += snprintf(buf + out, count - out, " ");
231 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400232
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500233 return out;
James Ketrenos43f66a62005-03-25 12:31:53 -0600234}
235
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400236static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600237{
238 char line[81];
239 u32 ofs = 0;
240 if (!(ipw_debug_level & level))
241 return;
242
243 while (len) {
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500244 snprint_line(line, sizeof(line), &data[ofs],
245 min(len, 16U), ofs);
246 printk(KERN_DEBUG "%s\n", line);
James Ketrenos43f66a62005-03-25 12:31:53 -0600247 ofs += 16;
248 len -= min(len, 16U);
249 }
250}
251
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500252static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
253{
254 size_t out = size;
255 u32 ofs = 0;
256 int total = 0;
257
258 while (size && len) {
259 out = snprint_line(output, size, &data[ofs],
260 min_t(size_t, len, 16U), ofs);
261
262 ofs += 16;
263 output += out;
264 size -= out;
265 len -= min_t(size_t, len, 16U);
266 total += out;
267 }
268 return total;
269}
270
Zhu Yic8fe6672006-01-24 16:36:36 +0800271/* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600272static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
273#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
274
Zhu Yic8fe6672006-01-24 16:36:36 +0800275/* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600276static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
277#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
278
Zhu Yic8fe6672006-01-24 16:36:36 +0800279/* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600280static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
281static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
282{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400283 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
284 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600285 _ipw_write_reg8(a, b, c);
286}
287
Zhu Yic8fe6672006-01-24 16:36:36 +0800288/* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600289static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
290static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
291{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400292 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
293 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600294 _ipw_write_reg16(a, b, c);
295}
296
Zhu Yic8fe6672006-01-24 16:36:36 +0800297/* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600298static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
299static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
300{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400301 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
302 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600303 _ipw_write_reg32(a, b, c);
304}
305
Zhu Yic8fe6672006-01-24 16:36:36 +0800306/* 8-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600307#define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800308
309/* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600310#define ipw_write8(ipw, ofs, val) \
311 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
312 _ipw_write8(ipw, ofs, val)
313
Zhu Yic8fe6672006-01-24 16:36:36 +0800314/* 16-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600315#define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800316
317/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600318#define ipw_write16(ipw, ofs, val) \
319 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
320 _ipw_write16(ipw, ofs, val)
321
Zhu Yic8fe6672006-01-24 16:36:36 +0800322/* 32-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600323#define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800324
325/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600326#define ipw_write32(ipw, ofs, val) \
327 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
328 _ipw_write32(ipw, ofs, val)
329
Zhu Yic8fe6672006-01-24 16:36:36 +0800330/* 8-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600331#define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800332
333/* 8-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400334static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
335{
336 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600337 return _ipw_read8(ipw, ofs);
338}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400339
Zhu Yic8fe6672006-01-24 16:36:36 +0800340/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600341#define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
342
Zhu Yic8fe6672006-01-24 16:36:36 +0800343/* 16-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600344#define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800345
346/* 16-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400347static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
348{
349 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600350 return _ipw_read16(ipw, ofs);
351}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400352
Zhu Yic8fe6672006-01-24 16:36:36 +0800353/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600354#define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
355
Zhu Yic8fe6672006-01-24 16:36:36 +0800356/* 32-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600357#define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800358
359/* 32-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400360static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
361{
362 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600363 return _ipw_read32(ipw, ofs);
364}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400365
Zhu Yic8fe6672006-01-24 16:36:36 +0800366/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600367#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
368
Zhu Yic8fe6672006-01-24 16:36:36 +0800369/* multi-byte read (above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600370static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500371static inline void __ipw_read_indirect(const char *f, int l,
372 struct ipw_priv *a, u32 b, u8 * c, int d)
373{
374 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
375 d);
376 _ipw_read_indirect(a, b, c, d);
377}
378
Zhu Yic8fe6672006-01-24 16:36:36 +0800379/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500380#define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600381
Zhu Yic8fe6672006-01-24 16:36:36 +0800382/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400383static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
384 int num);
James Ketrenos43f66a62005-03-25 12:31:53 -0600385#define ipw_write_indirect(a, b, c, d) \
386 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
James Ketrenosafbf30a2005-08-25 00:05:33 -0500387 _ipw_write_indirect(a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600388
Zhu Yic8fe6672006-01-24 16:36:36 +0800389/* 32-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400390static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600391{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400392 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500393 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
394 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600395}
396
Zhu Yic8fe6672006-01-24 16:36:36 +0800397/* 8-bit indirect write (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600398static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
399{
Zhu Yi2638bc32006-01-24 16:37:52 +0800400 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800401 u32 dif_len = reg - aligned_addr;
402
James Ketrenos43f66a62005-03-25 12:31:53 -0600403 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800404 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
405 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600406}
407
Zhu Yic8fe6672006-01-24 16:36:36 +0800408/* 16-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400409static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600410{
Zhu Yi2638bc32006-01-24 16:37:52 +0800411 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800412 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
413
James Ketrenos43f66a62005-03-25 12:31:53 -0600414 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800415 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
416 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600417}
418
Zhu Yic8fe6672006-01-24 16:36:36 +0800419/* 8-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600420static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
421{
422 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500423 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -0600424 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500425 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400426 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600427}
428
Zhu Yic8fe6672006-01-24 16:36:36 +0800429/* 32-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600430static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
431{
432 u32 value;
433
434 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
435
James Ketrenosb095c382005-08-24 22:04:42 -0500436 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
437 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
James Ketrenos43f66a62005-03-25 12:31:53 -0600438 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
439 return value;
440}
441
Zhu Yic8fe6672006-01-24 16:36:36 +0800442/* General purpose, no alignment requirement, iterative (multi-byte) read, */
443/* for area above 1st 4K of SRAM/reg space */
James Ketrenos43f66a62005-03-25 12:31:53 -0600444static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
445 int num)
446{
Zhu Yi2638bc32006-01-24 16:37:52 +0800447 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600448 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600449 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400450
James Ketrenos43f66a62005-03-25 12:31:53 -0600451 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
452
James Ketrenosea2b26e2005-08-24 21:25:16 -0500453 if (num <= 0) {
454 return;
455 }
456
Zhu Yic8fe6672006-01-24 16:36:36 +0800457 /* Read the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600458 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500459 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600460 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500461 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500462 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600463 aligned_addr += 4;
464 }
465
Zhu Yic8fe6672006-01-24 16:36:36 +0800466 /* Read all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500467 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500468 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500469 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400470
Zhu Yic8fe6672006-01-24 16:36:36 +0800471 /* Read the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500472 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500473 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500474 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500475 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500476 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600477}
478
Zhu Yic8fe6672006-01-24 16:36:36 +0800479/* General purpose, no alignment requirement, iterative (multi-byte) write, */
480/* for area above 1st 4K of SRAM/reg space */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400481static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600482 int num)
483{
Zhu Yi2638bc32006-01-24 16:37:52 +0800484 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600485 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600486 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400487
James Ketrenos43f66a62005-03-25 12:31:53 -0600488 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400489
James Ketrenosea2b26e2005-08-24 21:25:16 -0500490 if (num <= 0) {
491 return;
492 }
493
Zhu Yic8fe6672006-01-24 16:36:36 +0800494 /* Write the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600495 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500496 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
Zhu Yic8fe6672006-01-24 16:36:36 +0800497 /* Start writing at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500498 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500499 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600500 aligned_addr += 4;
501 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400502
Zhu Yic8fe6672006-01-24 16:36:36 +0800503 /* Write all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500504 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500505 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500506 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400507
Zhu Yic8fe6672006-01-24 16:36:36 +0800508 /* Write the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500509 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500510 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500511 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500512 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500513 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600514}
515
Zhu Yic8fe6672006-01-24 16:36:36 +0800516/* General purpose, no alignment requirement, iterative (multi-byte) write, */
517/* for 1st 4K of SRAM/regs space */
Jeff Garzikbf794512005-07-31 13:07:26 -0400518static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600519 int num)
520{
521 memcpy_toio((priv->hw_base + addr), buf, num);
522}
523
Zhu Yic8fe6672006-01-24 16:36:36 +0800524/* Set bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600525static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
526{
527 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
528}
529
Zhu Yic8fe6672006-01-24 16:36:36 +0800530/* Clear bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600531static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
532{
533 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
534}
535
Zhu Yi89c318e2006-06-08 22:19:49 -0700536static inline void __ipw_enable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600537{
538 if (priv->status & STATUS_INT_ENABLED)
539 return;
540 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500541 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600542}
543
Zhu Yi89c318e2006-06-08 22:19:49 -0700544static inline void __ipw_disable_interrupts(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -0600545{
546 if (!(priv->status & STATUS_INT_ENABLED))
547 return;
548 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500549 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600550}
551
Zhu Yi89c318e2006-06-08 22:19:49 -0700552static inline void ipw_enable_interrupts(struct ipw_priv *priv)
553{
554 unsigned long flags;
555
556 spin_lock_irqsave(&priv->irq_lock, flags);
557 __ipw_enable_interrupts(priv);
558 spin_unlock_irqrestore(&priv->irq_lock, flags);
559}
560
561static inline void ipw_disable_interrupts(struct ipw_priv *priv)
562{
563 unsigned long flags;
564
565 spin_lock_irqsave(&priv->irq_lock, flags);
566 __ipw_disable_interrupts(priv);
567 spin_unlock_irqrestore(&priv->irq_lock, flags);
568}
569
Brice Goglin0f52bf92005-12-01 01:41:46 -0800570#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -0600571static char *ipw_error_desc(u32 val)
572{
573 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400574 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600575 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400576 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600577 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400578 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600579 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400580 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600581 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400582 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500583 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400584 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500585 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400586 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500587 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400588 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500589 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400590 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500591 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400592 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500593 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400594 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500595 return "DMA_STATUS";
596 case IPW_FW_ERROR_DINO_ERROR:
597 return "DINO_ERROR";
598 case IPW_FW_ERROR_EEPROM_ERROR:
599 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400600 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500601 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400602 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500603 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400604 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500605 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600606 }
607}
608
James Ketrenosb39860c2005-08-12 09:36:32 -0500609static void ipw_dump_error_log(struct ipw_priv *priv,
610 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600611{
James Ketrenosb39860c2005-08-12 09:36:32 -0500612 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600613
James Ketrenosb39860c2005-08-12 09:36:32 -0500614 if (!error) {
615 IPW_ERROR("Error allocating and capturing error log. "
616 "Nothing to dump.\n");
617 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600618 }
619
James Ketrenosb39860c2005-08-12 09:36:32 -0500620 IPW_ERROR("Start IPW Error Log Dump:\n");
621 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
622 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600623
James Ketrenosb39860c2005-08-12 09:36:32 -0500624 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400625 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500626 ipw_error_desc(error->elem[i].desc),
627 error->elem[i].time,
628 error->elem[i].blink1,
629 error->elem[i].blink2,
630 error->elem[i].link1,
631 error->elem[i].link2, error->elem[i].data);
632 for (i = 0; i < error->log_len; i++)
633 IPW_ERROR("%i\t0x%08x\t%i\n",
634 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500635 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600636}
James Ketrenos43f66a62005-03-25 12:31:53 -0600637#endif
James Ketrenos43f66a62005-03-25 12:31:53 -0600638
James Ketrenosc848d0a2005-08-24 21:56:24 -0500639static inline int ipw_is_init(struct ipw_priv *priv)
640{
641 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600642}
643
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400644static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600645{
646 u32 addr, field_info, field_len, field_count, total_len;
647
648 IPW_DEBUG_ORD("ordinal = %i\n", ord);
649
650 if (!priv || !val || !len) {
651 IPW_DEBUG_ORD("Invalid argument\n");
652 return -EINVAL;
653 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400654
James Ketrenos43f66a62005-03-25 12:31:53 -0600655 /* verify device ordinal tables have been initialized */
656 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
657 IPW_DEBUG_ORD("Access ordinals before initialization\n");
658 return -EINVAL;
659 }
660
661 switch (IPW_ORD_TABLE_ID_MASK & ord) {
662 case IPW_ORD_TABLE_0_MASK:
663 /*
664 * TABLE 0: Direct access to a table of 32 bit values
665 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400666 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600667 * read from the table
668 */
669
670 /* remove the table id from the ordinal */
671 ord &= IPW_ORD_TABLE_VALUE_MASK;
672
673 /* boundary check */
674 if (ord > priv->table0_len) {
675 IPW_DEBUG_ORD("ordinal value (%i) longer then "
676 "max (%i)\n", ord, priv->table0_len);
677 return -EINVAL;
678 }
679
680 /* verify we have enough room to store the value */
681 if (*len < sizeof(u32)) {
682 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200683 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600684 return -EINVAL;
685 }
686
687 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400688 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600689
690 *len = sizeof(u32);
691 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400692 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600693 break;
694
695 case IPW_ORD_TABLE_1_MASK:
696 /*
697 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400698 *
699 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600700 * representing starting addr for the data (which is
701 * also a u32)
702 */
703
704 /* remove the table id from the ordinal */
705 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400706
James Ketrenos43f66a62005-03-25 12:31:53 -0600707 /* boundary check */
708 if (ord > priv->table1_len) {
709 IPW_DEBUG_ORD("ordinal value too long\n");
710 return -EINVAL;
711 }
712
713 /* verify we have enough room to store the value */
714 if (*len < sizeof(u32)) {
715 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200716 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600717 return -EINVAL;
718 }
719
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400720 *((u32 *) val) =
721 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600722 *len = sizeof(u32);
723 break;
724
725 case IPW_ORD_TABLE_2_MASK:
726 /*
727 * TABLE 2: Indirect access to a table of variable sized values
728 *
729 * This table consist of six values, each containing
730 * - dword containing the starting offset of the data
731 * - dword containing the lengh in the first 16bits
732 * and the count in the second 16bits
733 */
734
735 /* remove the table id from the ordinal */
736 ord &= IPW_ORD_TABLE_VALUE_MASK;
737
738 /* boundary check */
739 if (ord > priv->table2_len) {
740 IPW_DEBUG_ORD("ordinal value too long\n");
741 return -EINVAL;
742 }
743
744 /* get the address of statistic */
745 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400746
747 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600748 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400749 field_info =
750 ipw_read_reg32(priv,
751 priv->table2_addr + (ord << 3) +
752 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400753
James Ketrenos43f66a62005-03-25 12:31:53 -0600754 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400755 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400756
James Ketrenos43f66a62005-03-25 12:31:53 -0600757 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400758 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400759
James Ketrenos43f66a62005-03-25 12:31:53 -0600760 /* abort if not enought memory */
761 total_len = field_len * field_count;
762 if (total_len > *len) {
763 *len = total_len;
764 return -EINVAL;
765 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400766
James Ketrenos43f66a62005-03-25 12:31:53 -0600767 *len = total_len;
768 if (!total_len)
769 return 0;
770
771 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400772 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600773 addr, total_len, field_info);
774 ipw_read_indirect(priv, addr, val, total_len);
775 break;
776
777 default:
778 IPW_DEBUG_ORD("Invalid ordinal!\n");
779 return -EINVAL;
780
781 }
782
James Ketrenos43f66a62005-03-25 12:31:53 -0600783 return 0;
784}
785
786static void ipw_init_ordinals(struct ipw_priv *priv)
787{
788 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400789 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600790
791 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
792 priv->table0_addr, priv->table0_len);
793
794 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
795 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
796
797 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
798 priv->table1_addr, priv->table1_len);
799
800 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
801 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400802 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600803
804 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
805 priv->table2_addr, priv->table2_len);
806
807}
808
Adrian Bunka73e22b2006-01-21 01:39:42 +0100809static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500810{
James Ketrenosb095c382005-08-24 22:04:42 -0500811 reg &= ~IPW_START_STANDBY;
812 if (reg & IPW_GATE_ODMA)
813 reg &= ~IPW_GATE_ODMA;
814 if (reg & IPW_GATE_IDMA)
815 reg &= ~IPW_GATE_IDMA;
816 if (reg & IPW_GATE_ADMA)
817 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500818 return reg;
819}
820
821/*
822 * LED behavior:
823 * - On radio ON, turn on any LEDs that require to be on during start
824 * - On initialization, start unassociated blink
825 * - On association, disable unassociated blink
826 * - On disassociation, start unassociated blink
827 * - On radio OFF, turn off any LEDs started during radio on
828 *
829 */
Zhu Yiede61112006-01-24 16:37:10 +0800830#define LD_TIME_LINK_ON msecs_to_jiffies(300)
831#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
832#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500833
Adrian Bunka73e22b2006-01-21 01:39:42 +0100834static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500835{
836 unsigned long flags;
837 u32 led;
838
839 /* If configured to not use LEDs, or nic_type is 1,
840 * then we don't toggle a LINK led */
841 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
842 return;
843
844 spin_lock_irqsave(&priv->lock, flags);
845
846 if (!(priv->status & STATUS_RF_KILL_MASK) &&
847 !(priv->status & STATUS_LED_LINK_ON)) {
848 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500849 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500850 led |= priv->led_association_on;
851
852 led = ipw_register_toggle(led);
853
854 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500855 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500856
857 priv->status |= STATUS_LED_LINK_ON;
858
859 /* If we aren't associated, schedule turning the LED off */
860 if (!(priv->status & STATUS_ASSOCIATED))
861 queue_delayed_work(priv->workqueue,
862 &priv->led_link_off,
863 LD_TIME_LINK_ON);
864 }
865
866 spin_unlock_irqrestore(&priv->lock, flags);
867}
868
James Ketrenosc848d0a2005-08-24 21:56:24 -0500869static void ipw_bg_led_link_on(void *data)
870{
871 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800872 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500873 ipw_led_link_on(data);
Zhu Yi46441512006-01-24 16:37:59 +0800874 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500875}
876
Adrian Bunka73e22b2006-01-21 01:39:42 +0100877static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500878{
879 unsigned long flags;
880 u32 led;
881
882 /* If configured not to use LEDs, or nic type is 1,
883 * then we don't goggle the LINK led. */
884 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
885 return;
886
887 spin_lock_irqsave(&priv->lock, flags);
888
889 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500890 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500891 led &= priv->led_association_off;
892 led = ipw_register_toggle(led);
893
894 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500895 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500896
897 IPW_DEBUG_LED("Link LED Off\n");
898
899 priv->status &= ~STATUS_LED_LINK_ON;
900
901 /* If we aren't associated and the radio is on, schedule
902 * turning the LED on (blink while unassociated) */
903 if (!(priv->status & STATUS_RF_KILL_MASK) &&
904 !(priv->status & STATUS_ASSOCIATED))
905 queue_delayed_work(priv->workqueue, &priv->led_link_on,
906 LD_TIME_LINK_OFF);
907
908 }
909
910 spin_unlock_irqrestore(&priv->lock, flags);
911}
912
James Ketrenosc848d0a2005-08-24 21:56:24 -0500913static void ipw_bg_led_link_off(void *data)
914{
915 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800916 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500917 ipw_led_link_off(data);
Zhu Yi46441512006-01-24 16:37:59 +0800918 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500919}
920
Arjan van de Ven858119e2006-01-14 13:20:43 -0800921static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500922{
James Ketrenosa613bff2005-08-24 21:43:11 -0500923 u32 led;
924
925 if (priv->config & CFG_NO_LED)
926 return;
927
James Ketrenosb095c382005-08-24 22:04:42 -0500928 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500929 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500930
931 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500932 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500933 led |= priv->led_activity_on;
934
935 led = ipw_register_toggle(led);
936
937 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500938 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500939
940 IPW_DEBUG_LED("Activity LED On\n");
941
942 priv->status |= STATUS_LED_ACT_ON;
943
James Ketrenosc848d0a2005-08-24 21:56:24 -0500944 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500945 queue_delayed_work(priv->workqueue, &priv->led_act_off,
946 LD_TIME_ACT_ON);
947 } else {
948 /* Reschedule LED off for full time period */
949 cancel_delayed_work(&priv->led_act_off);
950 queue_delayed_work(priv->workqueue, &priv->led_act_off,
951 LD_TIME_ACT_ON);
952 }
James Ketrenosb095c382005-08-24 22:04:42 -0500953}
James Ketrenosa613bff2005-08-24 21:43:11 -0500954
Adrian Bunka73e22b2006-01-21 01:39:42 +0100955#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500956void ipw_led_activity_on(struct ipw_priv *priv)
957{
958 unsigned long flags;
959 spin_lock_irqsave(&priv->lock, flags);
960 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500961 spin_unlock_irqrestore(&priv->lock, flags);
962}
Adrian Bunka73e22b2006-01-21 01:39:42 +0100963#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -0500964
Adrian Bunka73e22b2006-01-21 01:39:42 +0100965static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500966{
967 unsigned long flags;
968 u32 led;
969
970 if (priv->config & CFG_NO_LED)
971 return;
972
973 spin_lock_irqsave(&priv->lock, flags);
974
975 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500976 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500977 led &= priv->led_activity_off;
978
979 led = ipw_register_toggle(led);
980
981 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500982 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500983
984 IPW_DEBUG_LED("Activity LED Off\n");
985
986 priv->status &= ~STATUS_LED_ACT_ON;
987 }
988
989 spin_unlock_irqrestore(&priv->lock, flags);
990}
991
James Ketrenosc848d0a2005-08-24 21:56:24 -0500992static void ipw_bg_led_activity_off(void *data)
993{
994 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800995 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500996 ipw_led_activity_off(data);
Zhu Yi46441512006-01-24 16:37:59 +0800997 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500998}
999
Adrian Bunka73e22b2006-01-21 01:39:42 +01001000static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001001{
1002 unsigned long flags;
1003 u32 led;
1004
1005 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -05001006 if (priv->config & CFG_NO_LED ||
1007 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -05001008 return;
1009
1010 spin_lock_irqsave(&priv->lock, flags);
1011
James Ketrenosb095c382005-08-24 22:04:42 -05001012 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001013 if (priv->assoc_network->mode == IEEE_A) {
1014 led |= priv->led_ofdm_on;
1015 led &= priv->led_association_off;
1016 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
1017 } else if (priv->assoc_network->mode == IEEE_G) {
1018 led |= priv->led_ofdm_on;
1019 led |= priv->led_association_on;
1020 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
1021 } else {
1022 led &= priv->led_ofdm_off;
1023 led |= priv->led_association_on;
1024 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
1025 }
1026
1027 led = ipw_register_toggle(led);
1028
1029 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001030 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001031
1032 spin_unlock_irqrestore(&priv->lock, flags);
1033}
1034
Adrian Bunka73e22b2006-01-21 01:39:42 +01001035static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001036{
1037 unsigned long flags;
1038 u32 led;
1039
1040 /* Only nic type 1 supports mode LEDs */
1041 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
1042 return;
1043
1044 spin_lock_irqsave(&priv->lock, flags);
1045
James Ketrenosb095c382005-08-24 22:04:42 -05001046 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001047 led &= priv->led_ofdm_off;
1048 led &= priv->led_association_off;
1049
1050 led = ipw_register_toggle(led);
1051
1052 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001053 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001054
1055 spin_unlock_irqrestore(&priv->lock, flags);
1056}
1057
Adrian Bunka73e22b2006-01-21 01:39:42 +01001058static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001059{
1060 ipw_led_link_on(priv);
1061}
1062
Adrian Bunka73e22b2006-01-21 01:39:42 +01001063static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001064{
1065 ipw_led_activity_off(priv);
1066 ipw_led_link_off(priv);
1067}
1068
Adrian Bunka73e22b2006-01-21 01:39:42 +01001069static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001070{
1071 /* Set the Link Led on for all nic types */
1072 ipw_led_link_on(priv);
1073}
1074
Adrian Bunka73e22b2006-01-21 01:39:42 +01001075static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001076{
1077 ipw_led_activity_off(priv);
1078 ipw_led_link_off(priv);
1079
1080 if (priv->status & STATUS_RF_KILL_MASK)
1081 ipw_led_radio_off(priv);
1082}
1083
Adrian Bunka73e22b2006-01-21 01:39:42 +01001084static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001085{
1086 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1087
1088 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001089 priv->led_activity_on = IPW_ACTIVITY_LED;
1090 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001091
James Ketrenosb095c382005-08-24 22:04:42 -05001092 priv->led_association_on = IPW_ASSOCIATED_LED;
1093 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001094
1095 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001096 priv->led_ofdm_on = IPW_OFDM_LED;
1097 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001098
1099 switch (priv->nic_type) {
1100 case EEPROM_NIC_TYPE_1:
1101 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001102 priv->led_activity_on = IPW_ASSOCIATED_LED;
1103 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1104 priv->led_association_on = IPW_ACTIVITY_LED;
1105 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001106
1107 if (!(priv->config & CFG_NO_LED))
1108 ipw_led_band_on(priv);
1109
1110 /* And we don't blink link LEDs for this nic, so
1111 * just return here */
1112 return;
1113
1114 case EEPROM_NIC_TYPE_3:
1115 case EEPROM_NIC_TYPE_2:
1116 case EEPROM_NIC_TYPE_4:
1117 case EEPROM_NIC_TYPE_0:
1118 break;
1119
1120 default:
1121 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1122 priv->nic_type);
1123 priv->nic_type = EEPROM_NIC_TYPE_0;
1124 break;
1125 }
1126
1127 if (!(priv->config & CFG_NO_LED)) {
1128 if (priv->status & STATUS_ASSOCIATED)
1129 ipw_led_link_on(priv);
1130 else
1131 ipw_led_link_off(priv);
1132 }
1133}
1134
Adrian Bunka73e22b2006-01-21 01:39:42 +01001135static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001136{
James Ketrenosa613bff2005-08-24 21:43:11 -05001137 ipw_led_activity_off(priv);
1138 ipw_led_link_off(priv);
1139 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001140 cancel_delayed_work(&priv->led_link_on);
1141 cancel_delayed_work(&priv->led_link_off);
1142 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001143}
1144
James Ketrenos43f66a62005-03-25 12:31:53 -06001145/*
1146 * The following adds a new attribute to the sysfs representation
1147 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1148 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001149 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001150 * See the level definitions in ipw for details.
1151 */
1152static ssize_t show_debug_level(struct device_driver *d, char *buf)
1153{
1154 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1155}
James Ketrenosa613bff2005-08-24 21:43:11 -05001156
1157static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1158 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001159{
1160 char *p = (char *)buf;
1161 u32 val;
1162
1163 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1164 p++;
1165 if (p[0] == 'x' || p[0] == 'X')
1166 p++;
1167 val = simple_strtoul(p, &p, 16);
1168 } else
1169 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001170 if (p == buf)
1171 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001172 ": %s is not in hex or decimal form.\n", buf);
1173 else
1174 ipw_debug_level = val;
1175
1176 return strnlen(buf, count);
1177}
1178
Jeff Garzikbf794512005-07-31 13:07:26 -04001179static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001180 show_debug_level, store_debug_level);
1181
James Ketrenosb39860c2005-08-12 09:36:32 -05001182static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1183{
Zhu Yic8fe6672006-01-24 16:36:36 +08001184 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001185 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1186}
1187
1188static void ipw_capture_event_log(struct ipw_priv *priv,
1189 u32 log_len, struct ipw_event *log)
1190{
1191 u32 base;
1192
1193 if (log_len) {
1194 base = ipw_read32(priv, IPW_EVENT_LOG);
1195 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1196 (u8 *) log, sizeof(*log) * log_len);
1197 }
1198}
1199
1200static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1201{
1202 struct ipw_fw_error *error;
1203 u32 log_len = ipw_get_event_log_len(priv);
1204 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1205 u32 elem_len = ipw_read_reg32(priv, base);
1206
1207 error = kmalloc(sizeof(*error) +
1208 sizeof(*error->elem) * elem_len +
1209 sizeof(*error->log) * log_len, GFP_ATOMIC);
1210 if (!error) {
1211 IPW_ERROR("Memory allocation for firmware error log "
1212 "failed.\n");
1213 return NULL;
1214 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001215 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001216 error->status = priv->status;
1217 error->config = priv->config;
1218 error->elem_len = elem_len;
1219 error->log_len = log_len;
1220 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001221 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001222
1223 ipw_capture_event_log(priv, log_len, error->log);
1224
1225 if (elem_len)
1226 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1227 sizeof(*error->elem) * elem_len);
1228
1229 return error;
1230}
1231
James Ketrenosb39860c2005-08-12 09:36:32 -05001232static ssize_t show_event_log(struct device *d,
1233 struct device_attribute *attr, char *buf)
1234{
1235 struct ipw_priv *priv = dev_get_drvdata(d);
1236 u32 log_len = ipw_get_event_log_len(priv);
1237 struct ipw_event log[log_len];
1238 u32 len = 0, i;
1239
1240 ipw_capture_event_log(priv, log_len, log);
1241
1242 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1243 for (i = 0; i < log_len; i++)
1244 len += snprintf(buf + len, PAGE_SIZE - len,
1245 "\n%08X%08X%08X",
1246 log[i].time, log[i].event, log[i].data);
1247 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1248 return len;
1249}
1250
1251static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1252
1253static ssize_t show_error(struct device *d,
1254 struct device_attribute *attr, char *buf)
1255{
1256 struct ipw_priv *priv = dev_get_drvdata(d);
1257 u32 len = 0, i;
1258 if (!priv->error)
1259 return 0;
1260 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001261 "%08lX%08X%08X%08X",
1262 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001263 priv->error->status,
1264 priv->error->config, priv->error->elem_len);
1265 for (i = 0; i < priv->error->elem_len; i++)
1266 len += snprintf(buf + len, PAGE_SIZE - len,
1267 "\n%08X%08X%08X%08X%08X%08X%08X",
1268 priv->error->elem[i].time,
1269 priv->error->elem[i].desc,
1270 priv->error->elem[i].blink1,
1271 priv->error->elem[i].blink2,
1272 priv->error->elem[i].link1,
1273 priv->error->elem[i].link2,
1274 priv->error->elem[i].data);
1275
1276 len += snprintf(buf + len, PAGE_SIZE - len,
1277 "\n%08X", priv->error->log_len);
1278 for (i = 0; i < priv->error->log_len; i++)
1279 len += snprintf(buf + len, PAGE_SIZE - len,
1280 "\n%08X%08X%08X",
1281 priv->error->log[i].time,
1282 priv->error->log[i].event,
1283 priv->error->log[i].data);
1284 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1285 return len;
1286}
1287
1288static ssize_t clear_error(struct device *d,
1289 struct device_attribute *attr,
1290 const char *buf, size_t count)
1291{
1292 struct ipw_priv *priv = dev_get_drvdata(d);
Jesper Juhl8f760782006-06-27 02:55:06 -07001293
1294 kfree(priv->error);
1295 priv->error = NULL;
James Ketrenosb39860c2005-08-12 09:36:32 -05001296 return count;
1297}
1298
1299static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1300
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001301static ssize_t show_cmd_log(struct device *d,
1302 struct device_attribute *attr, char *buf)
1303{
1304 struct ipw_priv *priv = dev_get_drvdata(d);
1305 u32 len = 0, i;
1306 if (!priv->cmdlog)
1307 return 0;
1308 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1309 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1310 i = (i + 1) % priv->cmdlog_len) {
1311 len +=
1312 snprintf(buf + len, PAGE_SIZE - len,
1313 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1314 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1315 priv->cmdlog[i].cmd.len);
1316 len +=
1317 snprintk_buf(buf + len, PAGE_SIZE - len,
1318 (u8 *) priv->cmdlog[i].cmd.param,
1319 priv->cmdlog[i].cmd.len);
1320 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1321 }
1322 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1323 return len;
1324}
1325
1326static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1327
Zhu Yid685b8c2006-04-13 17:20:27 +08001328#ifdef CONFIG_IPW2200_PROMISCUOUS
1329static void ipw_prom_free(struct ipw_priv *priv);
1330static int ipw_prom_alloc(struct ipw_priv *priv);
1331static ssize_t store_rtap_iface(struct device *d,
1332 struct device_attribute *attr,
1333 const char *buf, size_t count)
1334{
1335 struct ipw_priv *priv = dev_get_drvdata(d);
1336 int rc = 0;
1337
1338 if (count < 1)
1339 return -EINVAL;
1340
1341 switch (buf[0]) {
1342 case '0':
1343 if (!rtap_iface)
1344 return count;
1345
1346 if (netif_running(priv->prom_net_dev)) {
1347 IPW_WARNING("Interface is up. Cannot unregister.\n");
1348 return count;
1349 }
1350
1351 ipw_prom_free(priv);
1352 rtap_iface = 0;
1353 break;
1354
1355 case '1':
1356 if (rtap_iface)
1357 return count;
1358
1359 rc = ipw_prom_alloc(priv);
1360 if (!rc)
1361 rtap_iface = 1;
1362 break;
1363
1364 default:
1365 return -EINVAL;
1366 }
1367
1368 if (rc) {
1369 IPW_ERROR("Failed to register promiscuous network "
1370 "device (error %d).\n", rc);
1371 }
1372
1373 return count;
1374}
1375
1376static ssize_t show_rtap_iface(struct device *d,
1377 struct device_attribute *attr,
1378 char *buf)
1379{
1380 struct ipw_priv *priv = dev_get_drvdata(d);
1381 if (rtap_iface)
1382 return sprintf(buf, "%s", priv->prom_net_dev->name);
1383 else {
1384 buf[0] = '-';
1385 buf[1] = '1';
1386 buf[2] = '\0';
1387 return 3;
1388 }
1389}
1390
1391static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1392 store_rtap_iface);
1393
1394static ssize_t store_rtap_filter(struct device *d,
1395 struct device_attribute *attr,
1396 const char *buf, size_t count)
1397{
1398 struct ipw_priv *priv = dev_get_drvdata(d);
1399
1400 if (!priv->prom_priv) {
1401 IPW_ERROR("Attempting to set filter without "
1402 "rtap_iface enabled.\n");
1403 return -EPERM;
1404 }
1405
1406 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1407
1408 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1409 BIT_ARG16(priv->prom_priv->filter));
1410
1411 return count;
1412}
1413
1414static ssize_t show_rtap_filter(struct device *d,
1415 struct device_attribute *attr,
1416 char *buf)
1417{
1418 struct ipw_priv *priv = dev_get_drvdata(d);
1419 return sprintf(buf, "0x%04X",
1420 priv->prom_priv ? priv->prom_priv->filter : 0);
1421}
1422
1423static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1424 store_rtap_filter);
1425#endif
1426
James Ketrenosa613bff2005-08-24 21:43:11 -05001427static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1428 char *buf)
1429{
1430 struct ipw_priv *priv = dev_get_drvdata(d);
1431 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1432}
1433
1434static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1435 const char *buf, size_t count)
1436{
1437 struct ipw_priv *priv = dev_get_drvdata(d);
Brice Goglin0f52bf92005-12-01 01:41:46 -08001438#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosa613bff2005-08-24 21:43:11 -05001439 struct net_device *dev = priv->net_dev;
James Ketrenosc848d0a2005-08-24 21:56:24 -05001440#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05001441 char buffer[] = "00000000";
1442 unsigned long len =
1443 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1444 unsigned long val;
1445 char *p = buffer;
1446
1447 IPW_DEBUG_INFO("enter\n");
1448
1449 strncpy(buffer, buf, len);
1450 buffer[len] = 0;
1451
1452 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1453 p++;
1454 if (p[0] == 'x' || p[0] == 'X')
1455 p++;
1456 val = simple_strtoul(p, &p, 16);
1457 } else
1458 val = simple_strtoul(p, &p, 10);
1459 if (p == buffer) {
1460 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1461 } else {
1462 priv->ieee->scan_age = val;
1463 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1464 }
1465
1466 IPW_DEBUG_INFO("exit\n");
1467 return len;
1468}
1469
1470static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1471
1472static ssize_t show_led(struct device *d, struct device_attribute *attr,
1473 char *buf)
1474{
1475 struct ipw_priv *priv = dev_get_drvdata(d);
1476 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1477}
1478
1479static ssize_t store_led(struct device *d, struct device_attribute *attr,
1480 const char *buf, size_t count)
1481{
1482 struct ipw_priv *priv = dev_get_drvdata(d);
1483
1484 IPW_DEBUG_INFO("enter\n");
1485
1486 if (count == 0)
1487 return 0;
1488
1489 if (*buf == 0) {
1490 IPW_DEBUG_LED("Disabling LED control.\n");
1491 priv->config |= CFG_NO_LED;
1492 ipw_led_shutdown(priv);
1493 } else {
1494 IPW_DEBUG_LED("Enabling LED control.\n");
1495 priv->config &= ~CFG_NO_LED;
1496 ipw_led_init(priv);
1497 }
1498
1499 IPW_DEBUG_INFO("exit\n");
1500 return count;
1501}
1502
1503static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1504
Andrew Mortonad3fee52005-06-20 14:30:36 -07001505static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001506 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001507{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001508 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001509 return sprintf(buf, "0x%08x\n", (int)p->status);
1510}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001511
James Ketrenos43f66a62005-03-25 12:31:53 -06001512static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1513
Andrew Mortonad3fee52005-06-20 14:30:36 -07001514static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1515 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001516{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001517 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001518 return sprintf(buf, "0x%08x\n", (int)p->config);
1519}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001520
James Ketrenos43f66a62005-03-25 12:31:53 -06001521static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1522
Andrew Mortonad3fee52005-06-20 14:30:36 -07001523static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001524 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001525{
James Ketrenosa613bff2005-08-24 21:43:11 -05001526 struct ipw_priv *priv = d->driver_data;
1527 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001528}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001529
James Ketrenos43f66a62005-03-25 12:31:53 -06001530static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1531
Andrew Mortonad3fee52005-06-20 14:30:36 -07001532static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001533 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001534{
1535 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001536 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001537
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001538 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001539 return 0;
1540
1541 return sprintf(buf, "0x%08x\n", tmp);
1542}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001543
1544static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001545
Andrew Mortonad3fee52005-06-20 14:30:36 -07001546static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1547 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001548{
1549 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001550 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001551
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001552 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001553 return 0;
1554
1555 return sprintf(buf, "0x%08x\n", tmp);
1556}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001557
1558static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001559
1560/*
1561 * Add a device attribute to view/control the delay between eeprom
1562 * operations.
1563 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001564static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001565 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001566{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001567 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001568 return sprintf(buf, "%i\n", n);
1569}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001570static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001571 struct device_attribute *attr,
1572 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001573{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001574 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001575 sscanf(buf, "%i", &p->eeprom_delay);
1576 return strnlen(buf, count);
1577}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001578
1579static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1580 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001581
Andrew Mortonad3fee52005-06-20 14:30:36 -07001582static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001583 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001584{
1585 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001586 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001587
James Ketrenosb095c382005-08-24 22:04:42 -05001588 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001589 return sprintf(buf, "0x%08x\n", reg);
1590}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001591static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001592 struct device_attribute *attr,
1593 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001594{
1595 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001596 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001597
1598 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001599 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001600 return strnlen(buf, count);
1601}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001602
1603static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1604 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001605
Andrew Mortonad3fee52005-06-20 14:30:36 -07001606static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001607 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001608{
1609 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001610 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001611
1612 reg = ipw_read_reg32(p, 0x301100);
1613 return sprintf(buf, "0x%08x\n", reg);
1614}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001615static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001616 struct device_attribute *attr,
1617 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001618{
1619 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001620 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001621
1622 sscanf(buf, "%x", &reg);
1623 ipw_write_reg32(p, 0x301100, reg);
1624 return strnlen(buf, count);
1625}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001626
1627static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1628 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001629
Andrew Mortonad3fee52005-06-20 14:30:36 -07001630static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001631 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001632{
1633 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001634 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001635
Jeff Garzikbf794512005-07-31 13:07:26 -04001636 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001637 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001638 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001639 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001640
James Ketrenos43f66a62005-03-25 12:31:53 -06001641 return sprintf(buf, "0x%08x\n", reg);
1642}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001643static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001644 struct device_attribute *attr,
1645 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001646{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001647 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001648
1649 sscanf(buf, "%x", &priv->indirect_dword);
1650 priv->status |= STATUS_INDIRECT_DWORD;
1651 return strnlen(buf, count);
1652}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001653
1654static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1655 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001656
Andrew Mortonad3fee52005-06-20 14:30:36 -07001657static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001658 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001659{
1660 u8 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001661 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001662
Jeff Garzikbf794512005-07-31 13:07:26 -04001663 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001664 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001665 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001666 reg = 0;
1667
1668 return sprintf(buf, "0x%02x\n", reg);
1669}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001670static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001671 struct device_attribute *attr,
1672 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001673{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001674 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001675
1676 sscanf(buf, "%x", &priv->indirect_byte);
1677 priv->status |= STATUS_INDIRECT_BYTE;
1678 return strnlen(buf, count);
1679}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001680
1681static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001682 show_indirect_byte, store_indirect_byte);
1683
Andrew Mortonad3fee52005-06-20 14:30:36 -07001684static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001685 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001686{
1687 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001688 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001689
Jeff Garzikbf794512005-07-31 13:07:26 -04001690 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001691 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001692 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001693 reg = 0;
1694
1695 return sprintf(buf, "0x%08x\n", reg);
1696}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001697static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001698 struct device_attribute *attr,
1699 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001700{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001701 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001702
1703 sscanf(buf, "%x", &priv->direct_dword);
1704 priv->status |= STATUS_DIRECT_DWORD;
1705 return strnlen(buf, count);
1706}
James Ketrenos43f66a62005-03-25 12:31:53 -06001707
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001708static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1709 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001710
Arjan van de Ven858119e2006-01-14 13:20:43 -08001711static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001712{
1713 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1714 priv->status |= STATUS_RF_KILL_HW;
1715 else
1716 priv->status &= ~STATUS_RF_KILL_HW;
1717
1718 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1719}
1720
Andrew Mortonad3fee52005-06-20 14:30:36 -07001721static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001722 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001723{
1724 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001725 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001726 2 - HW based RF kill active
1727 3 - Both HW and SW baed RF kill active */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001728 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001729 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001730 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001731 return sprintf(buf, "%i\n", val);
1732}
1733
1734static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1735{
Jeff Garzikbf794512005-07-31 13:07:26 -04001736 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001737 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001738 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001739
1740 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1741 disable_radio ? "OFF" : "ON");
1742
1743 if (disable_radio) {
1744 priv->status |= STATUS_RF_KILL_SW;
1745
James Ketrenosa613bff2005-08-24 21:43:11 -05001746 if (priv->workqueue)
James Ketrenos43f66a62005-03-25 12:31:53 -06001747 cancel_delayed_work(&priv->request_scan);
James Ketrenos43f66a62005-03-25 12:31:53 -06001748 queue_work(priv->workqueue, &priv->down);
1749 } else {
1750 priv->status &= ~STATUS_RF_KILL_SW;
1751 if (rf_kill_active(priv)) {
1752 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1753 "disabled by HW switch\n");
1754 /* Make sure the RF_KILL check timer is running */
1755 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001756 queue_delayed_work(priv->workqueue, &priv->rf_kill,
James Ketrenos43f66a62005-03-25 12:31:53 -06001757 2 * HZ);
Jeff Garzikbf794512005-07-31 13:07:26 -04001758 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001759 queue_work(priv->workqueue, &priv->up);
1760 }
1761
1762 return 1;
1763}
1764
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001765static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1766 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001767{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001768 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -04001769
James Ketrenos43f66a62005-03-25 12:31:53 -06001770 ipw_radio_kill_sw(priv, buf[0] == '1');
1771
1772 return count;
1773}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001774
1775static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001776
James Ketrenosb095c382005-08-24 22:04:42 -05001777static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1778 char *buf)
1779{
1780 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1781 int pos = 0, len = 0;
1782 if (priv->config & CFG_SPEED_SCAN) {
1783 while (priv->speed_scan[pos] != 0)
1784 len += sprintf(&buf[len], "%d ",
1785 priv->speed_scan[pos++]);
1786 return len + sprintf(&buf[len], "\n");
1787 }
1788
1789 return sprintf(buf, "0\n");
1790}
1791
1792static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1793 const char *buf, size_t count)
1794{
1795 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1796 int channel, pos = 0;
1797 const char *p = buf;
1798
1799 /* list of space separated channels to scan, optionally ending with 0 */
1800 while ((channel = simple_strtol(p, NULL, 0))) {
1801 if (pos == MAX_SPEED_SCAN - 1) {
1802 priv->speed_scan[pos] = 0;
1803 break;
1804 }
1805
Larry Finger1867b112006-02-28 09:48:28 -06001806 if (ieee80211_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001807 priv->speed_scan[pos++] = channel;
1808 else
1809 IPW_WARNING("Skipping invalid channel request: %d\n",
1810 channel);
1811 p = strchr(p, ' ');
1812 if (!p)
1813 break;
1814 while (*p == ' ' || *p == '\t')
1815 p++;
1816 }
1817
1818 if (pos == 0)
1819 priv->config &= ~CFG_SPEED_SCAN;
1820 else {
1821 priv->speed_scan_pos = 0;
1822 priv->config |= CFG_SPEED_SCAN;
1823 }
1824
1825 return count;
1826}
1827
1828static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1829 store_speed_scan);
1830
1831static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1832 char *buf)
1833{
1834 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1835 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1836}
1837
1838static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1839 const char *buf, size_t count)
1840{
1841 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1842 if (buf[0] == '1')
1843 priv->config |= CFG_NET_STATS;
1844 else
1845 priv->config &= ~CFG_NET_STATS;
1846
1847 return count;
1848}
1849
James Ketrenosafbf30a2005-08-25 00:05:33 -05001850static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1851 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001852
James Ketrenosea2b26e2005-08-24 21:25:16 -05001853static void notify_wx_assoc_event(struct ipw_priv *priv)
1854{
1855 union iwreq_data wrqu;
1856 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1857 if (priv->status & STATUS_ASSOCIATED)
1858 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1859 else
1860 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1861 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1862}
1863
James Ketrenos43f66a62005-03-25 12:31:53 -06001864static void ipw_irq_tasklet(struct ipw_priv *priv)
1865{
1866 u32 inta, inta_mask, handled = 0;
1867 unsigned long flags;
1868 int rc = 0;
1869
Zhu Yi89c318e2006-06-08 22:19:49 -07001870 spin_lock_irqsave(&priv->irq_lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001871
James Ketrenosb095c382005-08-24 22:04:42 -05001872 inta = ipw_read32(priv, IPW_INTA_RW);
1873 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1874 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001875
1876 /* Add any cached INTA values that need to be handled */
1877 inta |= priv->isr_inta;
1878
Zhu Yi89c318e2006-06-08 22:19:49 -07001879 spin_unlock_irqrestore(&priv->irq_lock, flags);
1880
1881 spin_lock_irqsave(&priv->lock, flags);
1882
James Ketrenos43f66a62005-03-25 12:31:53 -06001883 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001884 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001885 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001886 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001887 }
1888
James Ketrenosb095c382005-08-24 22:04:42 -05001889 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001890 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001891 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001892 priv->status &= ~STATUS_HCMD_ACTIVE;
1893 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001894 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001895 }
1896
James Ketrenosb095c382005-08-24 22:04:42 -05001897 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001898 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001899 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05001900 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06001901 }
1902
James Ketrenosb095c382005-08-24 22:04:42 -05001903 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001904 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001905 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05001906 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06001907 }
1908
James Ketrenosb095c382005-08-24 22:04:42 -05001909 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001910 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001911 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05001912 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06001913 }
1914
James Ketrenosb095c382005-08-24 22:04:42 -05001915 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001916 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001917 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05001918 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06001919 }
1920
James Ketrenosb095c382005-08-24 22:04:42 -05001921 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001922 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001923 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001924 }
1925
James Ketrenosb095c382005-08-24 22:04:42 -05001926 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001927 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001928 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06001929 }
1930
James Ketrenosb095c382005-08-24 22:04:42 -05001931 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001932 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001933 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001934 }
1935
James Ketrenosb095c382005-08-24 22:04:42 -05001936 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001937 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001938 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001939 }
1940
James Ketrenosb095c382005-08-24 22:04:42 -05001941 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001942 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001943 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001944 }
1945
James Ketrenosb095c382005-08-24 22:04:42 -05001946 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001947 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1948 priv->status |= STATUS_RF_KILL_HW;
1949 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05001950 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06001951 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05001952 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001953 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05001954 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001955 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001956
James Ketrenosb095c382005-08-24 22:04:42 -05001957 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001958 IPW_WARNING("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001959 if (priv->error) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001960 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001961#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001962 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1963 struct ipw_fw_error *error =
1964 ipw_alloc_error_log(priv);
1965 ipw_dump_error_log(priv, error);
Jesper Juhl8f760782006-06-27 02:55:06 -07001966 kfree(error);
James Ketrenosb39860c2005-08-12 09:36:32 -05001967 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001968#endif
James Ketrenosb39860c2005-08-12 09:36:32 -05001969 } else {
1970 priv->error = ipw_alloc_error_log(priv);
1971 if (priv->error)
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001972 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001973 else
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001974 IPW_DEBUG_FW("Error allocating sysfs 'error' "
1975 "log.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001976#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001977 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1978 ipw_dump_error_log(priv, priv->error);
1979#endif
1980 }
1981
James Ketrenosb095c382005-08-24 22:04:42 -05001982 /* XXX: If hardware encryption is for WPA/WPA2,
1983 * we have to notify the supplicant. */
1984 if (priv->ieee->sec.encrypt) {
1985 priv->status &= ~STATUS_ASSOCIATED;
1986 notify_wx_assoc_event(priv);
1987 }
1988
1989 /* Keep the restart process from trying to send host
1990 * commands by clearing the INIT status bit */
1991 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001992
1993 /* Cancel currently queued command. */
1994 priv->status &= ~STATUS_HCMD_ACTIVE;
1995 wake_up_interruptible(&priv->wait_command_queue);
1996
James Ketrenos43f66a62005-03-25 12:31:53 -06001997 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05001998 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001999 }
2000
James Ketrenosb095c382005-08-24 22:04:42 -05002001 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002002 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002003 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06002004 }
2005
2006 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002007 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06002008 }
2009
Zhu Yi89c318e2006-06-08 22:19:49 -07002010 spin_unlock_irqrestore(&priv->lock, flags);
2011
James Ketrenos43f66a62005-03-25 12:31:53 -06002012 /* enable all interrupts */
2013 ipw_enable_interrupts(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06002014}
Jeff Garzikbf794512005-07-31 13:07:26 -04002015
James Ketrenos43f66a62005-03-25 12:31:53 -06002016#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2017static char *get_cmd_string(u8 cmd)
2018{
2019 switch (cmd) {
2020 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04002021 IPW_CMD(POWER_DOWN);
2022 IPW_CMD(SYSTEM_CONFIG);
2023 IPW_CMD(MULTICAST_ADDRESS);
2024 IPW_CMD(SSID);
2025 IPW_CMD(ADAPTER_ADDRESS);
2026 IPW_CMD(PORT_TYPE);
2027 IPW_CMD(RTS_THRESHOLD);
2028 IPW_CMD(FRAG_THRESHOLD);
2029 IPW_CMD(POWER_MODE);
2030 IPW_CMD(WEP_KEY);
2031 IPW_CMD(TGI_TX_KEY);
2032 IPW_CMD(SCAN_REQUEST);
2033 IPW_CMD(SCAN_REQUEST_EXT);
2034 IPW_CMD(ASSOCIATE);
2035 IPW_CMD(SUPPORTED_RATES);
2036 IPW_CMD(SCAN_ABORT);
2037 IPW_CMD(TX_FLUSH);
2038 IPW_CMD(QOS_PARAMETERS);
2039 IPW_CMD(DINO_CONFIG);
2040 IPW_CMD(RSN_CAPABILITIES);
2041 IPW_CMD(RX_KEY);
2042 IPW_CMD(CARD_DISABLE);
2043 IPW_CMD(SEED_NUMBER);
2044 IPW_CMD(TX_POWER);
2045 IPW_CMD(COUNTRY_INFO);
2046 IPW_CMD(AIRONET_INFO);
2047 IPW_CMD(AP_TX_POWER);
2048 IPW_CMD(CCKM_INFO);
2049 IPW_CMD(CCX_VER_INFO);
2050 IPW_CMD(SET_CALIBRATION);
2051 IPW_CMD(SENSITIVITY_CALIB);
2052 IPW_CMD(RETRY_LIMIT);
2053 IPW_CMD(IPW_PRE_POWER_DOWN);
2054 IPW_CMD(VAP_BEACON_TEMPLATE);
2055 IPW_CMD(VAP_DTIM_PERIOD);
2056 IPW_CMD(EXT_SUPPORTED_RATES);
2057 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2058 IPW_CMD(VAP_QUIET_INTERVALS);
2059 IPW_CMD(VAP_CHANNEL_SWITCH);
2060 IPW_CMD(VAP_MANDATORY_CHANNELS);
2061 IPW_CMD(VAP_CELL_PWR_LIMIT);
2062 IPW_CMD(VAP_CF_PARAM_SET);
2063 IPW_CMD(VAP_SET_BEACONING_STATE);
2064 IPW_CMD(MEASUREMENT);
2065 IPW_CMD(POWER_CAPABILITY);
2066 IPW_CMD(SUPPORTED_CHANNELS);
2067 IPW_CMD(TPC_REPORT);
2068 IPW_CMD(WME_INFO);
2069 IPW_CMD(PRODUCTION_COMMAND);
2070 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06002071 return "UNKNOWN";
2072 }
2073}
James Ketrenos43f66a62005-03-25 12:31:53 -06002074
2075#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002076
2077static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06002078{
2079 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002080 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06002081
James Ketrenosa613bff2005-08-24 21:43:11 -05002082 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002083 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002084 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2085 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002086 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002087 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06002088 }
2089
2090 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04002091
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002092 if (priv->cmdlog) {
2093 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2094 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2095 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2096 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2097 cmd->len);
2098 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2099 }
2100
James Ketrenosb095c382005-08-24 22:04:42 -05002101 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2102 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2103 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08002104
2105#ifndef DEBUG_CMD_WEP_KEY
2106 if (cmd->cmd == IPW_CMD_WEP_KEY)
2107 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2108 else
2109#endif
2110 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2111
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002112 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05002113 if (rc) {
2114 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002115 IPW_ERROR("Failed to send %s: Reason %d\n",
2116 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05002117 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002118 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002119 }
2120 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002121
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002122 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2123 !(priv->
2124 status & STATUS_HCMD_ACTIVE),
2125 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002126 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05002127 spin_lock_irqsave(&priv->lock, flags);
2128 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002129 IPW_ERROR("Failed to send %s: Command timed out.\n",
2130 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002131 priv->status &= ~STATUS_HCMD_ACTIVE;
2132 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002133 rc = -EIO;
2134 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002135 }
2136 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05002137 } else
2138 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002139
James Ketrenosb095c382005-08-24 22:04:42 -05002140 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002141 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2142 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002143 rc = -EIO;
2144 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06002145 }
2146
Zhu Yi2638bc32006-01-24 16:37:52 +08002147 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002148 if (priv->cmdlog) {
2149 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2150 priv->cmdlog_pos %= priv->cmdlog_len;
2151 }
2152 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002153}
2154
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002155static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002156{
2157 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002158 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002159 };
2160
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002161 return __ipw_send_cmd(priv, &cmd);
2162}
2163
2164static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2165 void *data)
2166{
2167 struct host_cmd cmd = {
2168 .cmd = command,
2169 .len = len,
2170 .param = data,
2171 };
2172
2173 return __ipw_send_cmd(priv, &cmd);
2174}
2175
2176static int ipw_send_host_complete(struct ipw_priv *priv)
2177{
James Ketrenos43f66a62005-03-25 12:31:53 -06002178 if (!priv) {
2179 IPW_ERROR("Invalid args\n");
2180 return -1;
2181 }
2182
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002183 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002184}
2185
Zhu Yid685b8c2006-04-13 17:20:27 +08002186static int ipw_send_system_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002187{
Zhu Yid685b8c2006-04-13 17:20:27 +08002188 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2189 sizeof(priv->sys_config),
2190 &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002191}
2192
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002193static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002194{
James Ketrenos43f66a62005-03-25 12:31:53 -06002195 if (!priv || !ssid) {
2196 IPW_ERROR("Invalid args\n");
2197 return -1;
2198 }
2199
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002200 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002201 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002202}
2203
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002204static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002205{
James Ketrenos43f66a62005-03-25 12:31:53 -06002206 if (!priv || !mac) {
2207 IPW_ERROR("Invalid args\n");
2208 return -1;
2209 }
2210
2211 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2212 priv->net_dev->name, MAC_ARG(mac));
2213
Zhu Yi2638bc32006-01-24 16:37:52 +08002214 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002215}
2216
James Ketrenosa613bff2005-08-24 21:43:11 -05002217/*
2218 * NOTE: This must be executed from our workqueue as it results in udelay
2219 * being called which may corrupt the keyboard if executed on default
2220 * workqueue
2221 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002222static void ipw_adapter_restart(void *adapter)
2223{
2224 struct ipw_priv *priv = adapter;
2225
2226 if (priv->status & STATUS_RF_KILL_MASK)
2227 return;
2228
2229 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002230
2231 if (priv->assoc_network &&
2232 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2233 ipw_remove_current_network(priv);
2234
James Ketrenos43f66a62005-03-25 12:31:53 -06002235 if (ipw_up(priv)) {
2236 IPW_ERROR("Failed to up device\n");
2237 return;
2238 }
2239}
2240
James Ketrenosc848d0a2005-08-24 21:56:24 -05002241static void ipw_bg_adapter_restart(void *data)
2242{
2243 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08002244 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002245 ipw_adapter_restart(data);
Zhu Yi46441512006-01-24 16:37:59 +08002246 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002247}
2248
James Ketrenos43f66a62005-03-25 12:31:53 -06002249#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2250
2251static void ipw_scan_check(void *data)
2252{
2253 struct ipw_priv *priv = data;
2254 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2255 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002256 "adapter after (%dms).\n",
2257 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
James Ketrenosa613bff2005-08-24 21:43:11 -05002258 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06002259 }
2260}
2261
James Ketrenosc848d0a2005-08-24 21:56:24 -05002262static void ipw_bg_scan_check(void *data)
2263{
2264 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08002265 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002266 ipw_scan_check(data);
Zhu Yi46441512006-01-24 16:37:59 +08002267 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002268}
2269
James Ketrenos43f66a62005-03-25 12:31:53 -06002270static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2271 struct ipw_scan_request_ext *request)
2272{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002273 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002274 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002275}
2276
2277static int ipw_send_scan_abort(struct ipw_priv *priv)
2278{
James Ketrenos43f66a62005-03-25 12:31:53 -06002279 if (!priv) {
2280 IPW_ERROR("Invalid args\n");
2281 return -1;
2282 }
2283
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002284 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002285}
2286
2287static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2288{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002289 struct ipw_sensitivity_calib calib = {
2290 .beacon_rssi_raw = sens,
James Ketrenos43f66a62005-03-25 12:31:53 -06002291 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002292
2293 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002294 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002295}
2296
2297static int ipw_send_associate(struct ipw_priv *priv,
2298 struct ipw_associate *associate)
2299{
James Ketrenosa613bff2005-08-24 21:43:11 -05002300 struct ipw_associate tmp_associate;
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002301
2302 if (!priv || !associate) {
2303 IPW_ERROR("Invalid args\n");
2304 return -1;
2305 }
2306
James Ketrenosa613bff2005-08-24 21:43:11 -05002307 memcpy(&tmp_associate, associate, sizeof(*associate));
2308 tmp_associate.policy_support =
2309 cpu_to_le16(tmp_associate.policy_support);
2310 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2311 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2312 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2313 tmp_associate.listen_interval =
2314 cpu_to_le16(tmp_associate.listen_interval);
2315 tmp_associate.beacon_interval =
2316 cpu_to_le16(tmp_associate.beacon_interval);
2317 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2318
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002319 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
Zhu Yi2638bc32006-01-24 16:37:52 +08002320 &tmp_associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002321}
2322
2323static int ipw_send_supported_rates(struct ipw_priv *priv,
2324 struct ipw_supported_rates *rates)
2325{
James Ketrenos43f66a62005-03-25 12:31:53 -06002326 if (!priv || !rates) {
2327 IPW_ERROR("Invalid args\n");
2328 return -1;
2329 }
2330
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002331 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002332 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002333}
2334
2335static int ipw_set_random_seed(struct ipw_priv *priv)
2336{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002337 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002338
2339 if (!priv) {
2340 IPW_ERROR("Invalid args\n");
2341 return -1;
2342 }
2343
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002344 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002345
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002346 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002347}
2348
James Ketrenos43f66a62005-03-25 12:31:53 -06002349static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2350{
James Ketrenos43f66a62005-03-25 12:31:53 -06002351 if (!priv) {
2352 IPW_ERROR("Invalid args\n");
2353 return -1;
2354 }
2355
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002356 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off),
Zhu Yi2638bc32006-01-24 16:37:52 +08002357 &phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002358}
James Ketrenos43f66a62005-03-25 12:31:53 -06002359
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002360static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002361{
James Ketrenos43f66a62005-03-25 12:31:53 -06002362 if (!priv || !power) {
2363 IPW_ERROR("Invalid args\n");
2364 return -1;
2365 }
2366
Zhu Yi2638bc32006-01-24 16:37:52 +08002367 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002368}
James Ketrenos43f66a62005-03-25 12:31:53 -06002369
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002370static int ipw_set_tx_power(struct ipw_priv *priv)
2371{
Larry Finger1867b112006-02-28 09:48:28 -06002372 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002373 struct ipw_tx_power tx_power;
2374 s8 max_power;
2375 int i;
2376
2377 memset(&tx_power, 0, sizeof(tx_power));
2378
2379 /* configure device for 'G' band */
2380 tx_power.ieee_mode = IPW_G_MODE;
2381 tx_power.num_channels = geo->bg_channels;
2382 for (i = 0; i < geo->bg_channels; i++) {
2383 max_power = geo->bg[i].max_power;
2384 tx_power.channels_tx_power[i].channel_number =
2385 geo->bg[i].channel;
2386 tx_power.channels_tx_power[i].tx_power = max_power ?
2387 min(max_power, priv->tx_power) : priv->tx_power;
2388 }
2389 if (ipw_send_tx_power(priv, &tx_power))
2390 return -EIO;
2391
2392 /* configure device to also handle 'B' band */
2393 tx_power.ieee_mode = IPW_B_MODE;
2394 if (ipw_send_tx_power(priv, &tx_power))
2395 return -EIO;
2396
2397 /* configure device to also handle 'A' band */
2398 if (priv->ieee->abg_true) {
2399 tx_power.ieee_mode = IPW_A_MODE;
2400 tx_power.num_channels = geo->a_channels;
2401 for (i = 0; i < tx_power.num_channels; i++) {
2402 max_power = geo->a[i].max_power;
2403 tx_power.channels_tx_power[i].channel_number =
2404 geo->a[i].channel;
2405 tx_power.channels_tx_power[i].tx_power = max_power ?
2406 min(max_power, priv->tx_power) : priv->tx_power;
2407 }
2408 if (ipw_send_tx_power(priv, &tx_power))
2409 return -EIO;
2410 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002411 return 0;
2412}
2413
2414static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2415{
2416 struct ipw_rts_threshold rts_threshold = {
2417 .rts_threshold = rts,
2418 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002419
2420 if (!priv) {
2421 IPW_ERROR("Invalid args\n");
2422 return -1;
2423 }
2424
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002425 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2426 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002427}
2428
2429static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2430{
2431 struct ipw_frag_threshold frag_threshold = {
2432 .frag_threshold = frag,
2433 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002434
2435 if (!priv) {
2436 IPW_ERROR("Invalid args\n");
2437 return -1;
2438 }
2439
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002440 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2441 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002442}
2443
2444static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2445{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002446 u32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002447
2448 if (!priv) {
2449 IPW_ERROR("Invalid args\n");
2450 return -1;
2451 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002452
James Ketrenos43f66a62005-03-25 12:31:53 -06002453 /* If on battery, set to 3, if AC set to CAM, else user
2454 * level */
2455 switch (mode) {
2456 case IPW_POWER_BATTERY:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002457 param = IPW_POWER_INDEX_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06002458 break;
2459 case IPW_POWER_AC:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002460 param = IPW_POWER_MODE_CAM;
James Ketrenos43f66a62005-03-25 12:31:53 -06002461 break;
2462 default:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002463 param = mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06002464 break;
2465 }
2466
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002467 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002468 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002469}
2470
James Ketrenosafbf30a2005-08-25 00:05:33 -05002471static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2472{
2473 struct ipw_retry_limit retry_limit = {
2474 .short_retry_limit = slimit,
2475 .long_retry_limit = llimit
2476 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002477
2478 if (!priv) {
2479 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002480 return -1;
2481 }
2482
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002483 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002484 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002485}
2486
2487/*
2488 * The IPW device contains a Microwire compatible EEPROM that stores
2489 * various data like the MAC address. Usually the firmware has exclusive
2490 * access to the eeprom, but during device initialization (before the
2491 * device driver has sent the HostComplete command to the firmware) the
2492 * device driver has read access to the EEPROM by way of indirect addressing
2493 * through a couple of memory mapped registers.
2494 *
2495 * The following is a simplified implementation for pulling data out of the
2496 * the eeprom, along with some helper functions to find information in
2497 * the per device private data's copy of the eeprom.
2498 *
2499 * NOTE: To better understand how these functions work (i.e what is a chip
2500 * select and why do have to keep driving the eeprom clock?), read
2501 * just about any data sheet for a Microwire compatible EEPROM.
2502 */
2503
2504/* write a 32 bit value into the indirect accessor register */
2505static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2506{
2507 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002508
James Ketrenos43f66a62005-03-25 12:31:53 -06002509 /* the eeprom requires some time to complete the operation */
2510 udelay(p->eeprom_delay);
2511
2512 return;
2513}
2514
2515/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002516static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002517{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002518 eeprom_write_reg(priv, 0);
2519 eeprom_write_reg(priv, EEPROM_BIT_CS);
2520 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2521 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002522}
2523
2524/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002525static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002526{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002527 eeprom_write_reg(priv, EEPROM_BIT_CS);
2528 eeprom_write_reg(priv, 0);
2529 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002530}
2531
2532/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002533static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002534{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002535 int d = (bit ? EEPROM_BIT_DI : 0);
2536 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2537 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002538}
2539
2540/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002541static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002542{
2543 int i;
2544
2545 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002546 eeprom_write_bit(priv, 1);
2547 eeprom_write_bit(priv, op & 2);
2548 eeprom_write_bit(priv, op & 1);
2549 for (i = 7; i >= 0; i--) {
2550 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002551 }
2552}
2553
2554/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002555static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002556{
2557 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002558 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002559
James Ketrenos43f66a62005-03-25 12:31:53 -06002560 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002561 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002562
2563 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002564 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002565
2566 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002567 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002568 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002569 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2570 eeprom_write_reg(priv, EEPROM_BIT_CS);
2571 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2572 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002573 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002574
James Ketrenos43f66a62005-03-25 12:31:53 -06002575 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002576 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002577 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002578
James Ketrenos43f66a62005-03-25 12:31:53 -06002579 return r;
2580}
2581
2582/* helper function for pulling the mac address out of the private */
2583/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002584static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002585{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002586 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002587}
2588
2589/*
2590 * Either the device driver (i.e. the host) or the firmware can
2591 * load eeprom data into the designated region in SRAM. If neither
2592 * happens then the FW will shutdown with a fatal error.
2593 *
2594 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2595 * bit needs region of shared SRAM needs to be non-zero.
2596 */
2597static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2598{
2599 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002600 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002601
James Ketrenos43f66a62005-03-25 12:31:53 -06002602 IPW_DEBUG_TRACE(">>\n");
2603
2604 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002605 for (i = 0; i < 128; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002606 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002607
Jeff Garzikbf794512005-07-31 13:07:26 -04002608 /*
2609 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002610 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002611 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002612 */
Alexey Dobriyan386093e2006-02-01 03:04:57 -08002613 if (priv->eeprom[EEPROM_VERSION] != 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002614 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2615
2616 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002617 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002618 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002619
2620 /* Do not load eeprom data on fatal error or suspend */
2621 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2622 } else {
2623 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2624
2625 /* Load eeprom data on fatal error or suspend */
2626 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2627 }
2628
2629 IPW_DEBUG_TRACE("<<\n");
2630}
2631
Arjan van de Ven858119e2006-01-14 13:20:43 -08002632static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002633{
2634 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002635 if (!count)
2636 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002637 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002638 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002639 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002640}
2641
2642static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2643{
James Ketrenosb095c382005-08-24 22:04:42 -05002644 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002645 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002646 sizeof(struct command_block));
2647}
2648
2649static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002650{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002651
2652 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002653
James Ketrenos43f66a62005-03-25 12:31:53 -06002654 /* Start the dma */
2655 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002656
James Ketrenos43f66a62005-03-25 12:31:53 -06002657 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002658 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002659
2660 IPW_DEBUG_FW("<< : \n");
2661 return 0;
2662}
2663
2664static void ipw_fw_dma_abort(struct ipw_priv *priv)
2665{
2666 u32 control = 0;
2667
2668 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002669
2670 //set the Stop and Abort bit
James Ketrenos43f66a62005-03-25 12:31:53 -06002671 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002672 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002673 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002674
James Ketrenos43f66a62005-03-25 12:31:53 -06002675 IPW_DEBUG_FW("<< \n");
2676}
2677
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002678static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2679 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002680{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002681 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002682 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002683 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002684 IPW_DEBUG_FW(">> :\n");
2685
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002686 ipw_write_indirect(priv, address, (u8 *) cb,
2687 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002688
2689 IPW_DEBUG_FW("<< :\n");
2690 return 0;
2691
2692}
2693
2694static int ipw_fw_dma_kick(struct ipw_priv *priv)
2695{
2696 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002697 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002698
2699 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002700
James Ketrenos43f66a62005-03-25 12:31:53 -06002701 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002702 ipw_fw_dma_write_command_block(priv, index,
2703 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002704
2705 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002706 ipw_clear_bit(priv, IPW_RESET_REG,
2707 IPW_RESET_REG_MASTER_DISABLED |
2708 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002709
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002710 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002711 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002712 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002713
2714 IPW_DEBUG_FW("<< :\n");
2715 return 0;
2716}
2717
2718static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2719{
2720 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002721 u32 register_value = 0;
2722 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002723
2724 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002725 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002726 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002727
2728 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002729 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2730 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002731
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002732 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002733 cb_fields_address = address;
2734 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002735 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002736
2737 cb_fields_address += sizeof(u32);
2738 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002739 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002740
2741 cb_fields_address += sizeof(u32);
2742 register_value = ipw_read_reg32(priv, cb_fields_address);
2743 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2744 register_value);
2745
2746 cb_fields_address += sizeof(u32);
2747 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002748 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002749
2750 IPW_DEBUG_FW(">> :\n");
2751}
2752
2753static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2754{
2755 u32 current_cb_address = 0;
2756 u32 current_cb_index = 0;
2757
2758 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002759 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002760
James Ketrenosb095c382005-08-24 22:04:42 -05002761 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002762 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002763
James Ketrenos43f66a62005-03-25 12:31:53 -06002764 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002765 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002766
2767 IPW_DEBUG_FW(">> :\n");
2768 return current_cb_index;
2769
2770}
2771
2772static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2773 u32 src_address,
2774 u32 dest_address,
2775 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002776 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002777{
2778
Jeff Garzikbf794512005-07-31 13:07:26 -04002779 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002780 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2781 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002782 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002783 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002784
2785 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2786 src_address, dest_address, length);
2787
2788 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2789 return -1;
2790
2791 last_cb_element = priv->sram_desc.last_cb_index;
2792 cb = &priv->sram_desc.cb_list[last_cb_element];
2793 priv->sram_desc.last_cb_index++;
2794
2795 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002796 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002797 control |= CB_INT_ENABLED;
2798
2799 if (is_last)
2800 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002801
James Ketrenos43f66a62005-03-25 12:31:53 -06002802 control |= length;
2803
2804 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002805 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002806
2807 /* Copy the Source and Destination addresses */
2808 cb->dest_addr = dest_address;
2809 cb->source_addr = src_address;
2810
2811 /* Copy the Control Word last */
2812 cb->control = control;
2813
2814 return 0;
2815}
2816
2817static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002818 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06002819{
2820 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002821 u32 src_offset = 0;
2822 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002823 int status = 0;
2824 IPW_DEBUG_FW(">> \n");
2825 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2826 src_phys, dest_address, length);
2827 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002828 status = ipw_fw_dma_add_command_block(priv,
2829 src_phys + src_offset,
2830 dest_address +
2831 dest_offset,
2832 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002833 if (status) {
2834 IPW_DEBUG_FW_INFO(": Failed\n");
2835 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002836 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002837 IPW_DEBUG_FW_INFO(": Added new cb\n");
2838
2839 src_offset += CB_MAX_LENGTH;
2840 dest_offset += CB_MAX_LENGTH;
2841 bytes_left -= CB_MAX_LENGTH;
2842 }
2843
2844 /* add the buffer tail */
2845 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002846 status =
2847 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2848 dest_address + dest_offset,
2849 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002850 if (status) {
2851 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2852 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002853 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002854 IPW_DEBUG_FW_INFO
2855 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002856 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002857
James Ketrenos43f66a62005-03-25 12:31:53 -06002858 IPW_DEBUG_FW("<< \n");
2859 return 0;
2860}
2861
2862static int ipw_fw_dma_wait(struct ipw_priv *priv)
2863{
Zhu Yi397ae122006-01-24 16:37:22 +08002864 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002865 u32 watchdog = 0;
2866
2867 IPW_DEBUG_FW(">> : \n");
2868
2869 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002870 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002871 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002872
2873 while (current_index < priv->sram_desc.last_cb_index) {
2874 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002875 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002876 current_index = ipw_fw_dma_command_block_index(priv);
2877
Zhu Yi397ae122006-01-24 16:37:22 +08002878 if (previous_index < current_index) {
2879 watchdog = 0;
2880 continue;
2881 }
2882 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002883 IPW_DEBUG_FW_INFO("Timeout\n");
2884 ipw_fw_dma_dump_command_block(priv);
2885 ipw_fw_dma_abort(priv);
2886 return -1;
2887 }
2888 }
2889
2890 ipw_fw_dma_abort(priv);
2891
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002892 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002893 ipw_set_bit(priv, IPW_RESET_REG,
2894 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002895
2896 IPW_DEBUG_FW("<< dmaWaitSync \n");
2897 return 0;
2898}
2899
Jeff Garzikbf794512005-07-31 13:07:26 -04002900static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002901{
2902 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002903 struct ieee80211_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002904 unsigned long flags;
2905
2906 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002907 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2908 network = list_entry(element, struct ieee80211_network, list);
2909 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2910 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002911 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002912 &priv->ieee->network_free_list);
2913 }
2914 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002915 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002916}
2917
2918/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002919 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002920 * Reads debug register from domain0.
2921 * If card is present, pre-defined value should
2922 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002923 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002924 * @param priv
2925 * @return 1 if card is present, 0 otherwise
2926 */
2927static inline int ipw_alive(struct ipw_priv *priv)
2928{
2929 return ipw_read32(priv, 0x90) == 0xd55555d5;
2930}
2931
Zhu Yic7b6a672006-01-24 16:37:05 +08002932/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002933static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06002934 int timeout)
2935{
2936 int i = 0;
2937
2938 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002939 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002940 return i;
2941 mdelay(10);
2942 i += 10;
2943 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002944
James Ketrenos43f66a62005-03-25 12:31:53 -06002945 return -ETIME;
2946}
2947
Jeff Garzikbf794512005-07-31 13:07:26 -04002948/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002949 * the ipw hardware. It assumes the buffer has all the bits for the
2950 * image and the caller is handling the memory allocation and clean up.
2951 */
2952
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002953static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002954{
2955 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002956
James Ketrenos43f66a62005-03-25 12:31:53 -06002957 IPW_DEBUG_TRACE(">> \n");
2958 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05002959 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002960
Zhu Yic7b6a672006-01-24 16:37:05 +08002961 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05002962 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2963 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06002964 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08002965 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002966 return -1;
2967 }
2968
2969 IPW_DEBUG_INFO("stop master %dms\n", rc);
2970
2971 return rc;
2972}
2973
2974static void ipw_arc_release(struct ipw_priv *priv)
2975{
2976 IPW_DEBUG_TRACE(">> \n");
2977 mdelay(5);
2978
James Ketrenosb095c382005-08-24 22:04:42 -05002979 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002980
2981 /* no one knows timing, for safety add some delay */
2982 mdelay(5);
2983}
2984
James Ketrenos43f66a62005-03-25 12:31:53 -06002985struct fw_chunk {
2986 u32 address;
2987 u32 length;
2988};
2989
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002990static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002991{
2992 int rc = 0, i, addr;
2993 u8 cr = 0;
2994 u16 *image;
2995
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002996 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002997
James Ketrenos43f66a62005-03-25 12:31:53 -06002998 IPW_DEBUG_TRACE(">> \n");
2999
3000 rc = ipw_stop_master(priv);
3001
3002 if (rc < 0)
3003 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003004
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003005// spin_lock_irqsave(&priv->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04003006
James Ketrenosb095c382005-08-24 22:04:42 -05003007 for (addr = IPW_SHARED_LOWER_BOUND;
3008 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003009 ipw_write32(priv, addr, 0);
3010 }
3011
3012 /* no ucode (yet) */
3013 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3014 /* destroy DMA queues */
3015 /* reset sequence */
3016
James Ketrenosb095c382005-08-24 22:04:42 -05003017 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06003018 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05003019 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06003020 mdelay(1);
3021
3022 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05003023 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06003024 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003025
James Ketrenosb095c382005-08-24 22:04:42 -05003026 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003027 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003028
James Ketrenos43f66a62005-03-25 12:31:53 -06003029 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08003030 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3031 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003032 mdelay(1);
3033
3034 /* write ucode */
3035 /**
3036 * @bug
3037 * Do NOT set indirect address register once and then
3038 * store data to indirect data register in the loop.
3039 * It seems very reasonable, but in this case DINO do not
3040 * accept ucode. It is essential to set address each time.
3041 */
3042 /* load new ipw uCode */
3043 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05003044 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
James Ketrenosa613bff2005-08-24 21:43:11 -05003045 cpu_to_le16(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06003046
James Ketrenos43f66a62005-03-25 12:31:53 -06003047 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05003048 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3049 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06003050
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003051 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06003052
3053 /* wait for alive response */
3054 for (i = 0; i < 100; i++) {
3055 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05003056 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003057 if (cr & DINO_RXFIFO_DATA)
3058 break;
3059 mdelay(1);
3060 }
3061
3062 if (cr & DINO_RXFIFO_DATA) {
3063 /* alive_command_responce size is NOT multiple of 4 */
3064 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04003065
3066 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06003067 response_buffer[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05003068 le32_to_cpu(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05003069 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06003070 memcpy(&priv->dino_alive, response_buffer,
3071 sizeof(priv->dino_alive));
3072 if (priv->dino_alive.alive_command == 1
3073 && priv->dino_alive.ucode_valid == 1) {
3074 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003075 IPW_DEBUG_INFO
3076 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3077 "of %02d/%02d/%02d %02d:%02d\n",
3078 priv->dino_alive.software_revision,
3079 priv->dino_alive.software_revision,
3080 priv->dino_alive.device_identifier,
3081 priv->dino_alive.device_identifier,
3082 priv->dino_alive.time_stamp[0],
3083 priv->dino_alive.time_stamp[1],
3084 priv->dino_alive.time_stamp[2],
3085 priv->dino_alive.time_stamp[3],
3086 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003087 } else {
3088 IPW_DEBUG_INFO("Microcode is not alive\n");
3089 rc = -EINVAL;
3090 }
3091 } else {
3092 IPW_DEBUG_INFO("No alive response from DINO\n");
3093 rc = -ETIME;
3094 }
3095
3096 /* disable DINO, otherwise for some reason
3097 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05003098 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003099
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003100// spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003101
3102 return rc;
3103}
3104
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003105static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003106{
3107 int rc = -1;
3108 int offset = 0;
3109 struct fw_chunk *chunk;
3110 dma_addr_t shared_phys;
3111 u8 *shared_virt;
3112
3113 IPW_DEBUG_TRACE("<< : \n");
3114 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
3115
3116 if (!shared_virt)
3117 return -ENOMEM;
3118
3119 memmove(shared_virt, data, len);
3120
3121 /* Start the Dma */
3122 rc = ipw_fw_dma_enable(priv);
3123
3124 if (priv->sram_desc.last_cb_index > 0) {
3125 /* the DMA is already ready this would be a bug. */
3126 BUG();
3127 goto out;
3128 }
3129
3130 do {
3131 chunk = (struct fw_chunk *)(data + offset);
3132 offset += sizeof(struct fw_chunk);
3133 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003134 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003135 * offeset*/
3136 /* Dma loading */
3137 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
James Ketrenosa613bff2005-08-24 21:43:11 -05003138 le32_to_cpu(chunk->address),
3139 le32_to_cpu(chunk->length));
James Ketrenos43f66a62005-03-25 12:31:53 -06003140 if (rc) {
3141 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3142 goto out;
3143 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003144
James Ketrenosa613bff2005-08-24 21:43:11 -05003145 offset += le32_to_cpu(chunk->length);
James Ketrenos43f66a62005-03-25 12:31:53 -06003146 } while (offset < len);
3147
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003148 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06003149 rc = ipw_fw_dma_kick(priv);
3150 if (rc) {
3151 IPW_ERROR("dmaKick Failed\n");
3152 goto out;
3153 }
3154
3155 rc = ipw_fw_dma_wait(priv);
3156 if (rc) {
3157 IPW_ERROR("dmaWaitSync Failed\n");
3158 goto out;
3159 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003160 out:
3161 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06003162 return rc;
3163}
3164
3165/* stop nic */
3166static int ipw_stop_nic(struct ipw_priv *priv)
3167{
3168 int rc = 0;
3169
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003170 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003171 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003172
James Ketrenosb095c382005-08-24 22:04:42 -05003173 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3174 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003175 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003176 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003177 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003178 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003179
James Ketrenosb095c382005-08-24 22:04:42 -05003180 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003181
James Ketrenos43f66a62005-03-25 12:31:53 -06003182 return rc;
3183}
3184
3185static void ipw_start_nic(struct ipw_priv *priv)
3186{
3187 IPW_DEBUG_TRACE(">>\n");
3188
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003189 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003190 ipw_clear_bit(priv, IPW_RESET_REG,
3191 IPW_RESET_REG_MASTER_DISABLED |
3192 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003193 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003194
James Ketrenos43f66a62005-03-25 12:31:53 -06003195 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003196 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3197 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003198
3199 IPW_DEBUG_TRACE("<<\n");
3200}
Jeff Garzikbf794512005-07-31 13:07:26 -04003201
James Ketrenos43f66a62005-03-25 12:31:53 -06003202static int ipw_init_nic(struct ipw_priv *priv)
3203{
3204 int rc;
3205
3206 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003207 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003208 /*prvHwInitNic */
3209 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003210 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003211
3212 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003213 ipw_write32(priv, IPW_READ_INT_REGISTER,
3214 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003215
3216 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003217 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3218 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003219 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003220 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3221
3222 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003223 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003224
3225 udelay(10);
3226
3227 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003228 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003229
3230 IPW_DEBUG_TRACE(">>\n");
3231 return 0;
3232}
3233
Jeff Garzikbf794512005-07-31 13:07:26 -04003234/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003235 * Probe is an ok place to call this from.
3236 */
3237static int ipw_reset_nic(struct ipw_priv *priv)
3238{
3239 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003240 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003241
3242 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003243
James Ketrenos43f66a62005-03-25 12:31:53 -06003244 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003245
James Ketrenosa613bff2005-08-24 21:43:11 -05003246 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003247 /* Clear the 'host command active' bit... */
3248 priv->status &= ~STATUS_HCMD_ACTIVE;
3249 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003250 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3251 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003252 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003253
3254 IPW_DEBUG_TRACE("<<\n");
3255 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003256}
James Ketrenos43f66a62005-03-25 12:31:53 -06003257
James Ketrenos9006ea72006-03-08 03:22:28 +08003258
3259struct ipw_fw {
Zhu Yi0070f8c2006-04-13 17:20:12 +08003260 __le32 ver;
3261 __le32 boot_size;
3262 __le32 ucode_size;
3263 __le32 fw_size;
James Ketrenos9006ea72006-03-08 03:22:28 +08003264 u8 data[0];
3265};
3266
Jeff Garzikbf794512005-07-31 13:07:26 -04003267static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos9006ea72006-03-08 03:22:28 +08003268 const struct firmware **raw, const char *name)
James Ketrenos43f66a62005-03-25 12:31:53 -06003269{
James Ketrenos9006ea72006-03-08 03:22:28 +08003270 struct ipw_fw *fw;
James Ketrenos43f66a62005-03-25 12:31:53 -06003271 int rc;
3272
3273 /* ask firmware_class module to get the boot firmware off disk */
James Ketrenos9006ea72006-03-08 03:22:28 +08003274 rc = request_firmware(raw, name, &priv->pci_dev->dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06003275 if (rc < 0) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003276 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003277 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003278 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003279
James Ketrenos9006ea72006-03-08 03:22:28 +08003280 if ((*raw)->size < sizeof(*fw)) {
3281 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003282 return -EINVAL;
3283 }
3284
James Ketrenos9006ea72006-03-08 03:22:28 +08003285 fw = (void *)(*raw)->data;
3286
Zhu Yi0070f8c2006-04-13 17:20:12 +08003287 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3288 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003289 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3290 name, (*raw)->size);
3291 return -EINVAL;
3292 }
3293
3294 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003295 name,
James Ketrenos9006ea72006-03-08 03:22:28 +08003296 le32_to_cpu(fw->ver) >> 16,
3297 le32_to_cpu(fw->ver) & 0xff,
3298 (*raw)->size - sizeof(*fw));
James Ketrenos43f66a62005-03-25 12:31:53 -06003299 return 0;
3300}
3301
James Ketrenosb095c382005-08-24 22:04:42 -05003302#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003303
Arjan van de Ven858119e2006-01-14 13:20:43 -08003304static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003305 struct ipw_rx_queue *rxq)
3306{
3307 unsigned long flags;
3308 int i;
3309
3310 spin_lock_irqsave(&rxq->lock, flags);
3311
3312 INIT_LIST_HEAD(&rxq->rx_free);
3313 INIT_LIST_HEAD(&rxq->rx_used);
3314
3315 /* Fill the rx_used queue with _all_ of the Rx buffers */
3316 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3317 /* In the reset function, these buffers may have been allocated
3318 * to an SKB, so we need to unmap and free potential storage */
3319 if (rxq->pool[i].skb != NULL) {
3320 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003321 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003322 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003323 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003324 }
3325 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3326 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003327
James Ketrenos43f66a62005-03-25 12:31:53 -06003328 /* Set us so that we have processed and used all buffers, but have
3329 * not restocked the Rx queue with fresh buffers */
3330 rxq->read = rxq->write = 0;
3331 rxq->processed = RX_QUEUE_SIZE - 1;
3332 rxq->free_count = 0;
3333 spin_unlock_irqrestore(&rxq->lock, flags);
3334}
3335
3336#ifdef CONFIG_PM
3337static int fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003338static const struct firmware *raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003339
3340static void free_firmware(void)
3341{
3342 if (fw_loaded) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003343 release_firmware(raw);
3344 raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003345 fw_loaded = 0;
3346 }
3347}
3348#else
3349#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003350#endif
3351
3352static int ipw_load(struct ipw_priv *priv)
3353{
3354#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003355 const struct firmware *raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003356#endif
James Ketrenos9006ea72006-03-08 03:22:28 +08003357 struct ipw_fw *fw;
3358 u8 *boot_img, *ucode_img, *fw_img;
3359 u8 *name = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003360 int rc = 0, retries = 3;
3361
Zhu Yi397ae122006-01-24 16:37:22 +08003362 switch (priv->ieee->iw_mode) {
3363 case IW_MODE_ADHOC:
James Ketrenos9006ea72006-03-08 03:22:28 +08003364 name = "ipw2200-ibss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003365 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003366#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003367 case IW_MODE_MONITOR:
James Ketrenos9006ea72006-03-08 03:22:28 +08003368 name = "ipw2200-sniffer.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003369 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003370#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003371 case IW_MODE_INFRA:
James Ketrenos9006ea72006-03-08 03:22:28 +08003372 name = "ipw2200-bss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003373 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003374 }
Zhu Yi397ae122006-01-24 16:37:22 +08003375
James Ketrenos9006ea72006-03-08 03:22:28 +08003376 if (!name) {
3377 rc = -EINVAL;
3378 goto error;
3379 }
3380
3381#ifdef CONFIG_PM
3382 if (!fw_loaded) {
3383#endif
3384 rc = ipw_get_fw(priv, &raw, name);
3385 if (rc < 0)
3386 goto error;
3387#ifdef CONFIG_PM
3388 }
3389#endif
3390
3391 fw = (void *)raw->data;
3392 boot_img = &fw->data[0];
Zhu Yi0070f8c2006-04-13 17:20:12 +08003393 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3394 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3395 le32_to_cpu(fw->ucode_size)];
James Ketrenos9006ea72006-03-08 03:22:28 +08003396
Zhu Yi397ae122006-01-24 16:37:22 +08003397 if (rc < 0)
3398 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003399
3400 if (!priv->rxq)
3401 priv->rxq = ipw_rx_queue_alloc(priv);
3402 else
3403 ipw_rx_queue_reset(priv, priv->rxq);
3404 if (!priv->rxq) {
3405 IPW_ERROR("Unable to initialize Rx queue\n");
3406 goto error;
3407 }
3408
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003409 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003410 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003411 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003412 priv->status &= ~STATUS_INT_ENABLED;
3413
3414 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003415 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003416
James Ketrenos43f66a62005-03-25 12:31:53 -06003417 ipw_stop_nic(priv);
3418
3419 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003420 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003421 IPW_ERROR("Unable to reset NIC\n");
3422 goto error;
3423 }
3424
James Ketrenosb095c382005-08-24 22:04:42 -05003425 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3426 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003427
3428 /* DMA the initial boot firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003429 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003430 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003431 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003432 goto error;
3433 }
3434
3435 /* kick start the device */
3436 ipw_start_nic(priv);
3437
Zhu Yic7b6a672006-01-24 16:37:05 +08003438 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003439 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3440 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003441 if (rc < 0) {
3442 IPW_ERROR("device failed to boot initial fw image\n");
3443 goto error;
3444 }
3445 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3446
Jeff Garzikbf794512005-07-31 13:07:26 -04003447 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003448 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003449
3450 /* DMA the ucode into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003451 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003452 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003453 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003454 goto error;
3455 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003456
James Ketrenos43f66a62005-03-25 12:31:53 -06003457 /* stop nic */
3458 ipw_stop_nic(priv);
3459
3460 /* DMA bss firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003461 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003462 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003463 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003464 goto error;
3465 }
Zhu Yi397ae122006-01-24 16:37:22 +08003466#ifdef CONFIG_PM
3467 fw_loaded = 1;
3468#endif
3469
James Ketrenos43f66a62005-03-25 12:31:53 -06003470 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3471
3472 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003473 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003474 IPW_ERROR("Unable to initialize queues\n");
3475 goto error;
3476 }
3477
3478 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003479 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003480 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003481 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003482
James Ketrenos43f66a62005-03-25 12:31:53 -06003483 /* kick start the device */
3484 ipw_start_nic(priv);
3485
James Ketrenosb095c382005-08-24 22:04:42 -05003486 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003487 if (retries > 0) {
3488 IPW_WARNING("Parity error. Retrying init.\n");
3489 retries--;
3490 goto retry;
3491 }
3492
3493 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3494 rc = -EIO;
3495 goto error;
3496 }
3497
3498 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003499 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3500 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003501 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003502 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003503 goto error;
3504 }
3505 IPW_DEBUG_INFO("device response after %dms\n", rc);
3506
3507 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003508 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003509
3510 /* read eeprom data and initialize the eeprom region of sram */
3511 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003512 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003513
3514 /* enable interrupts */
3515 ipw_enable_interrupts(priv);
3516
3517 /* Ensure our queue has valid packets */
3518 ipw_rx_queue_replenish(priv);
3519
James Ketrenosb095c382005-08-24 22:04:42 -05003520 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003521
3522 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003523 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003524
3525#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003526 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003527#endif
3528 return 0;
3529
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003530 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003531 if (priv->rxq) {
3532 ipw_rx_queue_free(priv, priv->rxq);
3533 priv->rxq = NULL;
3534 }
3535 ipw_tx_queue_free(priv);
James Ketrenos9006ea72006-03-08 03:22:28 +08003536 if (raw)
3537 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003538#ifdef CONFIG_PM
3539 fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003540 raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003541#endif
3542
3543 return rc;
3544}
3545
Jeff Garzikbf794512005-07-31 13:07:26 -04003546/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003547 * DMA services
3548 *
3549 * Theory of operation
3550 *
3551 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3552 * 2 empty entries always kept in the buffer to protect from overflow.
3553 *
3554 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003555 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3556 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003557 * Tx queue resumed.
3558 *
3559 * The IPW operates with six queues, one receive queue in the device's
3560 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003561 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003562 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003563 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003564 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003565 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003566 * we only utilize the first data transmit queue (queue1).
3567 */
3568
3569/**
3570 * Driver allocates buffers of this size for Rx
3571 */
3572
3573static inline int ipw_queue_space(const struct clx2_queue *q)
3574{
3575 int s = q->last_used - q->first_empty;
3576 if (s <= 0)
3577 s += q->n_bd;
3578 s -= 2; /* keep some reserve to not confuse empty and full situations */
3579 if (s < 0)
3580 s = 0;
3581 return s;
3582}
3583
3584static inline int ipw_queue_inc_wrap(int index, int n_bd)
3585{
3586 return (++index == n_bd) ? 0 : index;
3587}
3588
3589/**
3590 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003591 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003592 * @param q queue to init
3593 * @param count Number of BD's to allocate. Should be power of 2
3594 * @param read_register Address for 'read' register
3595 * (not offset within BAR, full address)
3596 * @param write_register Address for 'write' register
3597 * (not offset within BAR, full address)
3598 * @param base_register Address for 'base' register
3599 * (not offset within BAR, full address)
3600 * @param size Address for 'size' register
3601 * (not offset within BAR, full address)
3602 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003603static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003604 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003605{
3606 q->n_bd = count;
3607
3608 q->low_mark = q->n_bd / 4;
3609 if (q->low_mark < 4)
3610 q->low_mark = 4;
3611
3612 q->high_mark = q->n_bd / 8;
3613 if (q->high_mark < 2)
3614 q->high_mark = 2;
3615
3616 q->first_empty = q->last_used = 0;
3617 q->reg_r = read;
3618 q->reg_w = write;
3619
3620 ipw_write32(priv, base, q->dma_addr);
3621 ipw_write32(priv, size, count);
3622 ipw_write32(priv, read, 0);
3623 ipw_write32(priv, write, 0);
3624
3625 _ipw_read32(priv, 0x90);
3626}
3627
Jeff Garzikbf794512005-07-31 13:07:26 -04003628static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003629 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003630 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003631{
3632 struct pci_dev *dev = priv->pci_dev;
3633
3634 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3635 if (!q->txb) {
3636 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3637 return -ENOMEM;
3638 }
3639
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003640 q->bd =
3641 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003642 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003643 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003644 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003645 kfree(q->txb);
3646 q->txb = NULL;
3647 return -ENOMEM;
3648 }
3649
3650 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3651 return 0;
3652}
3653
3654/**
3655 * Free one TFD, those at index [txq->q.last_used].
3656 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003657 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003658 * @param dev
3659 * @param txq
3660 */
3661static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3662 struct clx2_tx_queue *txq)
3663{
3664 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3665 struct pci_dev *dev = priv->pci_dev;
3666 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003667
James Ketrenos43f66a62005-03-25 12:31:53 -06003668 /* classify bd */
3669 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3670 /* nothing to cleanup after for host commands */
3671 return;
3672
3673 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003674 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3675 IPW_ERROR("Too many chunks: %i\n",
3676 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003677 /** @todo issue fatal error, it is quite serious situation */
3678 return;
3679 }
3680
3681 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003682 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3683 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3684 le16_to_cpu(bd->u.data.chunk_len[i]),
3685 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003686 if (txq->txb[txq->q.last_used]) {
3687 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3688 txq->txb[txq->q.last_used] = NULL;
3689 }
3690 }
3691}
3692
3693/**
3694 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003695 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003696 * Empty queue by removing and destroying all BD's.
3697 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003698 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003699 * @param dev
3700 * @param q
3701 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003702static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003703{
3704 struct clx2_queue *q = &txq->q;
3705 struct pci_dev *dev = priv->pci_dev;
3706
Jeff Garzikbf794512005-07-31 13:07:26 -04003707 if (q->n_bd == 0)
3708 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003709
3710 /* first, empty all BD's */
3711 for (; q->first_empty != q->last_used;
3712 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3713 ipw_queue_tx_free_tfd(priv, txq);
3714 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003715
James Ketrenos43f66a62005-03-25 12:31:53 -06003716 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003717 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003718 q->dma_addr);
3719 kfree(txq->txb);
3720
3721 /* 0 fill whole structure */
3722 memset(txq, 0, sizeof(*txq));
3723}
3724
James Ketrenos43f66a62005-03-25 12:31:53 -06003725/**
3726 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003727 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003728 * @param priv
3729 */
3730static void ipw_tx_queue_free(struct ipw_priv *priv)
3731{
3732 /* Tx CMD queue */
3733 ipw_queue_tx_free(priv, &priv->txq_cmd);
3734
3735 /* Tx queues */
3736 ipw_queue_tx_free(priv, &priv->txq[0]);
3737 ipw_queue_tx_free(priv, &priv->txq[1]);
3738 ipw_queue_tx_free(priv, &priv->txq[2]);
3739 ipw_queue_tx_free(priv, &priv->txq[3]);
3740}
3741
Arjan van de Ven858119e2006-01-14 13:20:43 -08003742static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003743{
3744 /* First 3 bytes are manufacturer */
3745 bssid[0] = priv->mac_addr[0];
3746 bssid[1] = priv->mac_addr[1];
3747 bssid[2] = priv->mac_addr[2];
3748
3749 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003750 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003751
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003752 bssid[0] &= 0xfe; /* clear multicast bit */
3753 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003754}
3755
Arjan van de Ven858119e2006-01-14 13:20:43 -08003756static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003757{
3758 struct ipw_station_entry entry;
3759 int i;
3760
3761 for (i = 0; i < priv->num_stations; i++) {
3762 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3763 /* Another node is active in network */
3764 priv->missed_adhoc_beacons = 0;
3765 if (!(priv->config & CFG_STATIC_CHANNEL))
3766 /* when other nodes drop out, we drop out */
3767 priv->config &= ~CFG_ADHOC_PERSIST;
3768
3769 return i;
3770 }
3771 }
3772
3773 if (i == MAX_STATIONS)
3774 return IPW_INVALID_STATION;
3775
3776 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3777
3778 entry.reserved = 0;
3779 entry.support_mode = 0;
3780 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3781 memcpy(priv->stations[i], bssid, ETH_ALEN);
3782 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003783 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003784 priv->num_stations++;
3785
3786 return i;
3787}
3788
Arjan van de Ven858119e2006-01-14 13:20:43 -08003789static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003790{
3791 int i;
3792
Jeff Garzikbf794512005-07-31 13:07:26 -04003793 for (i = 0; i < priv->num_stations; i++)
3794 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003795 return i;
3796
3797 return IPW_INVALID_STATION;
3798}
3799
3800static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3801{
3802 int err;
3803
Hong Liu7b996592005-08-25 17:36:13 +08003804 if (priv->status & STATUS_ASSOCIATING) {
3805 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3806 queue_work(priv->workqueue, &priv->disassociate);
3807 return;
3808 }
3809
3810 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003811 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3812 return;
3813 }
3814
3815 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3816 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04003817 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06003818 priv->assoc_request.channel);
3819
3820 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3821 priv->status |= STATUS_DISASSOCIATING;
3822
3823 if (quiet)
3824 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3825 else
3826 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003827
James Ketrenos43f66a62005-03-25 12:31:53 -06003828 err = ipw_send_associate(priv, &priv->assoc_request);
3829 if (err) {
3830 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3831 "failed.\n");
3832 return;
3833 }
3834
3835}
3836
James Ketrenosc848d0a2005-08-24 21:56:24 -05003837static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003838{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003839 struct ipw_priv *priv = data;
3840 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3841 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003842 ipw_send_disassociate(data, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003843 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003844}
3845
James Ketrenosc848d0a2005-08-24 21:56:24 -05003846static void ipw_bg_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003847{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003848 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08003849 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003850 ipw_disassociate(data);
Zhu Yi46441512006-01-24 16:37:59 +08003851 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003852}
3853
Zhu Yid8bad6d2005-07-13 12:25:38 -05003854static void ipw_system_config(void *data)
3855{
3856 struct ipw_priv *priv = data;
Zhu Yid685b8c2006-04-13 17:20:27 +08003857
3858#ifdef CONFIG_IPW2200_PROMISCUOUS
3859 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
3860 priv->sys_config.accept_all_data_frames = 1;
3861 priv->sys_config.accept_non_directed_frames = 1;
3862 priv->sys_config.accept_all_mgmt_bcpr = 1;
3863 priv->sys_config.accept_all_mgmt_frames = 1;
3864 }
3865#endif
3866
3867 ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003868}
3869
3870struct ipw_status_code {
3871 u16 status;
3872 const char *reason;
3873};
3874
3875static const struct ipw_status_code ipw_status_codes[] = {
3876 {0x00, "Successful"},
3877 {0x01, "Unspecified failure"},
3878 {0x0A, "Cannot support all requested capabilities in the "
3879 "Capability information field"},
3880 {0x0B, "Reassociation denied due to inability to confirm that "
3881 "association exists"},
3882 {0x0C, "Association denied due to reason outside the scope of this "
3883 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003884 {0x0D,
3885 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003886 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003887 {0x0E,
3888 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003889 "transaction sequence number out of expected sequence"},
3890 {0x0F, "Authentication rejected because of challenge failure"},
3891 {0x10, "Authentication rejected due to timeout waiting for next "
3892 "frame in sequence"},
3893 {0x11, "Association denied because AP is unable to handle additional "
3894 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003895 {0x12,
3896 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003897 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003898 {0x13,
3899 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003900 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003901 {0x14,
3902 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003903 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003904 {0x15,
3905 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003906 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003907 {0x19,
3908 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003909 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003910 {0x1A,
3911 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003912 "DSSS-OFDM operation"},
3913 {0x28, "Invalid Information Element"},
3914 {0x29, "Group Cipher is not valid"},
3915 {0x2A, "Pairwise Cipher is not valid"},
3916 {0x2B, "AKMP is not valid"},
3917 {0x2C, "Unsupported RSN IE version"},
3918 {0x2D, "Invalid RSN IE Capabilities"},
3919 {0x2E, "Cipher suite is rejected per security policy"},
3920};
3921
Brice Goglin0f52bf92005-12-01 01:41:46 -08003922#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04003923static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003924{
3925 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003926 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003927 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003928 return ipw_status_codes[i].reason;
3929 return "Unknown status value.";
3930}
3931#endif
3932
3933static void inline average_init(struct average *avg)
3934{
3935 memset(avg, 0, sizeof(*avg));
3936}
3937
Zhu Yi00d21de2006-04-13 17:19:02 +08003938#define DEPTH_RSSI 8
3939#define DEPTH_NOISE 16
3940static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
3941{
3942 return ((depth-1)*prev_avg + val)/depth;
3943}
3944
Arjan van de Ven858119e2006-01-14 13:20:43 -08003945static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06003946{
3947 avg->sum -= avg->entries[avg->pos];
3948 avg->sum += val;
3949 avg->entries[avg->pos++] = val;
3950 if (unlikely(avg->pos == AVG_ENTRIES)) {
3951 avg->init = 1;
3952 avg->pos = 0;
3953 }
3954}
3955
Arjan van de Ven858119e2006-01-14 13:20:43 -08003956static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06003957{
3958 if (!unlikely(avg->init)) {
3959 if (avg->pos)
3960 return avg->sum / avg->pos;
3961 return 0;
3962 }
3963
3964 return avg->sum / AVG_ENTRIES;
3965}
3966
3967static void ipw_reset_stats(struct ipw_priv *priv)
3968{
3969 u32 len = sizeof(u32);
3970
3971 priv->quality = 0;
3972
3973 average_init(&priv->average_missed_beacons);
Zhu Yi00d21de2006-04-13 17:19:02 +08003974 priv->exp_avg_rssi = -60;
3975 priv->exp_avg_noise = -85 + 0x100;
James Ketrenos43f66a62005-03-25 12:31:53 -06003976
3977 priv->last_rate = 0;
3978 priv->last_missed_beacons = 0;
3979 priv->last_rx_packets = 0;
3980 priv->last_tx_packets = 0;
3981 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003982
James Ketrenos43f66a62005-03-25 12:31:53 -06003983 /* Firmware managed, reset only when NIC is restarted, so we have to
3984 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003985 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003986 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003987 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003988 &priv->last_tx_failures, &len);
3989
3990 /* Driver managed, reset with each association */
3991 priv->missed_adhoc_beacons = 0;
3992 priv->missed_beacons = 0;
3993 priv->tx_packets = 0;
3994 priv->rx_packets = 0;
3995
3996}
3997
Arjan van de Ven858119e2006-01-14 13:20:43 -08003998static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003999{
4000 u32 i = 0x80000000;
4001 u32 mask = priv->rates_mask;
4002 /* If currently associated in B mode, restrict the maximum
4003 * rate match to B rates */
4004 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
4005 mask &= IEEE80211_CCK_RATES_MASK;
4006
4007 /* TODO: Verify that the rate is supported by the current rates
4008 * list. */
4009
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004010 while (i && !(mask & i))
4011 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06004012 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004013 case IEEE80211_CCK_RATE_1MB_MASK:
4014 return 1000000;
4015 case IEEE80211_CCK_RATE_2MB_MASK:
4016 return 2000000;
4017 case IEEE80211_CCK_RATE_5MB_MASK:
4018 return 5500000;
4019 case IEEE80211_OFDM_RATE_6MB_MASK:
4020 return 6000000;
4021 case IEEE80211_OFDM_RATE_9MB_MASK:
4022 return 9000000;
4023 case IEEE80211_CCK_RATE_11MB_MASK:
4024 return 11000000;
4025 case IEEE80211_OFDM_RATE_12MB_MASK:
4026 return 12000000;
4027 case IEEE80211_OFDM_RATE_18MB_MASK:
4028 return 18000000;
4029 case IEEE80211_OFDM_RATE_24MB_MASK:
4030 return 24000000;
4031 case IEEE80211_OFDM_RATE_36MB_MASK:
4032 return 36000000;
4033 case IEEE80211_OFDM_RATE_48MB_MASK:
4034 return 48000000;
4035 case IEEE80211_OFDM_RATE_54MB_MASK:
4036 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004037 }
4038
Jeff Garzikbf794512005-07-31 13:07:26 -04004039 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06004040 return 11000000;
4041 else
4042 return 54000000;
4043}
4044
4045static u32 ipw_get_current_rate(struct ipw_priv *priv)
4046{
4047 u32 rate, len = sizeof(rate);
4048 int err;
4049
Jeff Garzikbf794512005-07-31 13:07:26 -04004050 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06004051 return 0;
4052
4053 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004054 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06004055 &len);
4056 if (err) {
4057 IPW_DEBUG_INFO("failed querying ordinals.\n");
4058 return 0;
4059 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004060 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06004061 return ipw_get_max_rate(priv);
4062
4063 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004064 case IPW_TX_RATE_1MB:
4065 return 1000000;
4066 case IPW_TX_RATE_2MB:
4067 return 2000000;
4068 case IPW_TX_RATE_5MB:
4069 return 5500000;
4070 case IPW_TX_RATE_6MB:
4071 return 6000000;
4072 case IPW_TX_RATE_9MB:
4073 return 9000000;
4074 case IPW_TX_RATE_11MB:
4075 return 11000000;
4076 case IPW_TX_RATE_12MB:
4077 return 12000000;
4078 case IPW_TX_RATE_18MB:
4079 return 18000000;
4080 case IPW_TX_RATE_24MB:
4081 return 24000000;
4082 case IPW_TX_RATE_36MB:
4083 return 36000000;
4084 case IPW_TX_RATE_48MB:
4085 return 48000000;
4086 case IPW_TX_RATE_54MB:
4087 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004088 }
4089
4090 return 0;
4091}
4092
James Ketrenos43f66a62005-03-25 12:31:53 -06004093#define IPW_STATS_INTERVAL (2 * HZ)
4094static void ipw_gather_stats(struct ipw_priv *priv)
4095{
4096 u32 rx_err, rx_err_delta, rx_packets_delta;
4097 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4098 u32 missed_beacons_percent, missed_beacons_delta;
4099 u32 quality = 0;
4100 u32 len = sizeof(u32);
4101 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004102 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004103 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004104 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06004105
4106 if (!(priv->status & STATUS_ASSOCIATED)) {
4107 priv->quality = 0;
4108 return;
4109 }
4110
4111 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04004112 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06004113 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004114 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06004115 priv->last_missed_beacons = priv->missed_beacons;
4116 if (priv->assoc_request.beacon_interval) {
4117 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004118 (HZ * priv->assoc_request.beacon_interval) /
4119 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004120 } else {
4121 missed_beacons_percent = 0;
4122 }
4123 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4124
4125 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4126 rx_err_delta = rx_err - priv->last_rx_err;
4127 priv->last_rx_err = rx_err;
4128
4129 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4130 tx_failures_delta = tx_failures - priv->last_tx_failures;
4131 priv->last_tx_failures = tx_failures;
4132
4133 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4134 priv->last_rx_packets = priv->rx_packets;
4135
4136 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4137 priv->last_tx_packets = priv->tx_packets;
4138
4139 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004140 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004141 * Missed beacon: 100% = 0, 0% = 70% missed
4142 * Rate: 60% = 1Mbs, 100% = Max
4143 * Rx and Tx errors represent a straight % of total Rx/Tx
4144 * RSSI: 100% = > -50, 0% = < -80
4145 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004146 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004147 * The lowest computed quality is used.
4148 *
4149 */
4150#define BEACON_THRESHOLD 5
4151 beacon_quality = 100 - missed_beacons_percent;
4152 if (beacon_quality < BEACON_THRESHOLD)
4153 beacon_quality = 0;
4154 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004155 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004156 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004157 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004158 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004159
James Ketrenos43f66a62005-03-25 12:31:53 -06004160 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004161 max_rate = ipw_get_max_rate(priv);
4162 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004163 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4164 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004165
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004166 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004167 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004168 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004169 else
4170 rx_quality = 100;
4171 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4172 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004173
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004174 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004175 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004176 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004177 else
4178 tx_quality = 100;
4179 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4180 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004181
Zhu Yi00d21de2006-04-13 17:19:02 +08004182 rssi = priv->exp_avg_rssi;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004183 signal_quality =
4184 (100 *
4185 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4186 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4187 (priv->ieee->perfect_rssi - rssi) *
4188 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4189 62 * (priv->ieee->perfect_rssi - rssi))) /
4190 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4191 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4192 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004193 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004194 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004195 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004196
Zhu Yi61fb9ed2006-04-13 17:19:55 +08004197 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004198 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004199
4200 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06004201 min(rate_quality,
4202 min(tx_quality, min(rx_quality, signal_quality))));
4203 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004204 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4205 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004206 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004207 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4208 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004209 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004210 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4211 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004212 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004213 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4214 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004215 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004216 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4217 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004218
4219 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004220
4221 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004222 IPW_STATS_INTERVAL);
4223}
4224
James Ketrenosc848d0a2005-08-24 21:56:24 -05004225static void ipw_bg_gather_stats(void *data)
4226{
4227 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08004228 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004229 ipw_gather_stats(data);
Zhu Yi46441512006-01-24 16:37:59 +08004230 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004231}
4232
Ben Cahille7582562005-10-06 15:34:41 -05004233/* Missed beacon behavior:
4234 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4235 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4236 * Above disassociate threshold, give up and stop scanning.
4237 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004238static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004239 int missed_count)
4240{
4241 priv->notif_missed_beacons = missed_count;
4242
James Ketrenosafbf30a2005-08-25 00:05:33 -05004243 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004244 priv->status & STATUS_ASSOCIATED) {
4245 /* If associated and we've hit the missed
4246 * beacon threshold, disassociate, turn
4247 * off roaming, and abort any active scans */
4248 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004249 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004250 "Missed beacon: %d - disassociate\n", missed_count);
4251 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004252 if (priv->status & STATUS_SCANNING) {
4253 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4254 IPW_DL_STATE,
4255 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004256 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004257 }
4258
James Ketrenosea2b26e2005-08-24 21:25:16 -05004259 queue_work(priv->workqueue, &priv->disassociate);
4260 return;
4261 }
4262
4263 if (priv->status & STATUS_ROAMING) {
4264 /* If we are currently roaming, then just
4265 * print a debug statement... */
4266 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4267 "Missed beacon: %d - roam in progress\n",
4268 missed_count);
4269 return;
4270 }
4271
Zhu Yi4bfdb912006-01-24 16:37:16 +08004272 if (roaming &&
4273 (missed_count > priv->roaming_threshold &&
4274 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004275 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004276 * bit in the status and kick off a scan.
4277 * This can happen several times before we reach
4278 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004279 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4280 "Missed beacon: %d - initiate "
4281 "roaming\n", missed_count);
4282 if (!(priv->status & STATUS_ROAMING)) {
4283 priv->status |= STATUS_ROAMING;
4284 if (!(priv->status & STATUS_SCANNING))
4285 queue_work(priv->workqueue,
4286 &priv->request_scan);
4287 }
4288 return;
4289 }
4290
4291 if (priv->status & STATUS_SCANNING) {
4292 /* Stop scan to keep fw from getting
4293 * stuck (only if we aren't roaming --
4294 * otherwise we'll never scan more than 2 or 3
4295 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004296 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4297 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004298 queue_work(priv->workqueue, &priv->abort_scan);
4299 }
4300
4301 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004302}
4303
James Ketrenos43f66a62005-03-25 12:31:53 -06004304/**
4305 * Handle host notification packet.
4306 * Called from interrupt routine
4307 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004308static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004309 struct ipw_rx_notification *notif)
4310{
James Ketrenosa613bff2005-08-24 21:43:11 -05004311 notif->size = le16_to_cpu(notif->size);
4312
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004313 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004314
James Ketrenos43f66a62005-03-25 12:31:53 -06004315 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004316 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4317 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004318
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004319 switch (assoc->state) {
4320 case CMAS_ASSOCIATED:{
4321 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4322 IPW_DL_ASSOC,
4323 "associated: '%s' " MAC_FMT
4324 " \n",
4325 escape_essid(priv->essid,
4326 priv->essid_len),
4327 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04004328
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004329 switch (priv->ieee->iw_mode) {
4330 case IW_MODE_INFRA:
4331 memcpy(priv->ieee->bssid,
4332 priv->bssid, ETH_ALEN);
4333 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004334
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004335 case IW_MODE_ADHOC:
4336 memcpy(priv->ieee->bssid,
4337 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004338
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004339 /* clear out the station table */
4340 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004341
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004342 IPW_DEBUG_ASSOC
4343 ("queueing adhoc check\n");
4344 queue_delayed_work(priv->
4345 workqueue,
4346 &priv->
4347 adhoc_check,
4348 priv->
4349 assoc_request.
4350 beacon_interval);
4351 break;
4352 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004353
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004354 priv->status &= ~STATUS_ASSOCIATING;
4355 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004356 queue_work(priv->workqueue,
4357 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004358
Zhu Yie43e3c12006-04-13 17:20:45 +08004359#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004360#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4361 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4362 if ((priv->status & STATUS_AUTH) &&
4363 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4364 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004365 if ((sizeof
4366 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004367 ieee80211_assoc_response)
James Ketrenosb095c382005-08-24 22:04:42 -05004368 <= notif->size)
4369 && (notif->size <= 2314)) {
4370 struct
4371 ieee80211_rx_stats
4372 stats = {
4373 .len =
4374 notif->
4375 size - 1,
4376 };
4377
4378 IPW_DEBUG_QOS
4379 ("QoS Associate "
4380 "size %d\n",
4381 notif->size);
4382 ieee80211_rx_mgt(priv->
4383 ieee,
4384 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004385 ieee80211_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004386 *)
4387 &notif->u.raw, &stats);
4388 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004389 }
James Ketrenosb095c382005-08-24 22:04:42 -05004390#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004391
James Ketrenosa613bff2005-08-24 21:43:11 -05004392 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004393
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004394 break;
4395 }
4396
4397 case CMAS_AUTHENTICATED:{
4398 if (priv->
4399 status & (STATUS_ASSOCIATED |
4400 STATUS_AUTH)) {
Brice Goglin0f52bf92005-12-01 01:41:46 -08004401#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004402 struct notif_authenticate *auth
4403 = &notif->u.auth;
4404 IPW_DEBUG(IPW_DL_NOTIF |
4405 IPW_DL_STATE |
4406 IPW_DL_ASSOC,
4407 "deauthenticated: '%s' "
4408 MAC_FMT
4409 ": (0x%04X) - %s \n",
4410 escape_essid(priv->
4411 essid,
4412 priv->
4413 essid_len),
4414 MAC_ARG(priv->bssid),
4415 ntohs(auth->status),
4416 ipw_get_status_code
4417 (ntohs
4418 (auth->status)));
4419#endif
4420
4421 priv->status &=
4422 ~(STATUS_ASSOCIATING |
4423 STATUS_AUTH |
4424 STATUS_ASSOCIATED);
4425
James Ketrenosa613bff2005-08-24 21:43:11 -05004426 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004427 break;
4428 }
4429
4430 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4431 IPW_DL_ASSOC,
4432 "authenticated: '%s' " MAC_FMT
4433 "\n",
4434 escape_essid(priv->essid,
4435 priv->essid_len),
4436 MAC_ARG(priv->bssid));
4437 break;
4438 }
4439
4440 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004441 if (priv->status & STATUS_AUTH) {
4442 struct
4443 ieee80211_assoc_response
4444 *resp;
4445 resp =
4446 (struct
4447 ieee80211_assoc_response
4448 *)&notif->u.raw;
4449 IPW_DEBUG(IPW_DL_NOTIF |
4450 IPW_DL_STATE |
4451 IPW_DL_ASSOC,
4452 "association failed (0x%04X): %s\n",
4453 ntohs(resp->status),
4454 ipw_get_status_code
4455 (ntohs
4456 (resp->status)));
4457 }
4458
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004459 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4460 IPW_DL_ASSOC,
4461 "disassociated: '%s' " MAC_FMT
4462 " \n",
4463 escape_essid(priv->essid,
4464 priv->essid_len),
4465 MAC_ARG(priv->bssid));
4466
4467 priv->status &=
4468 ~(STATUS_DISASSOCIATING |
4469 STATUS_ASSOCIATING |
4470 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004471 if (priv->assoc_network
4472 && (priv->assoc_network->
4473 capability &
4474 WLAN_CAPABILITY_IBSS))
4475 ipw_remove_current_network
4476 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004477
James Ketrenosa613bff2005-08-24 21:43:11 -05004478 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004479
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004480 break;
4481 }
4482
James Ketrenosb095c382005-08-24 22:04:42 -05004483 case CMAS_RX_ASSOC_RESP:
4484 break;
4485
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004486 default:
4487 IPW_ERROR("assoc: unknown (%d)\n",
4488 assoc->state);
4489 break;
4490 }
4491
James Ketrenos43f66a62005-03-25 12:31:53 -06004492 break;
4493 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004494
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004495 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4496 struct notif_authenticate *auth = &notif->u.auth;
4497 switch (auth->state) {
4498 case CMAS_AUTHENTICATED:
4499 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4500 "authenticated: '%s' " MAC_FMT " \n",
4501 escape_essid(priv->essid,
4502 priv->essid_len),
4503 MAC_ARG(priv->bssid));
4504 priv->status |= STATUS_AUTH;
4505 break;
4506
4507 case CMAS_INIT:
4508 if (priv->status & STATUS_AUTH) {
4509 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4510 IPW_DL_ASSOC,
4511 "authentication failed (0x%04X): %s\n",
4512 ntohs(auth->status),
4513 ipw_get_status_code(ntohs
4514 (auth->
4515 status)));
4516 }
4517 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4518 IPW_DL_ASSOC,
4519 "deauthenticated: '%s' " MAC_FMT "\n",
4520 escape_essid(priv->essid,
4521 priv->essid_len),
4522 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004523
4524 priv->status &= ~(STATUS_ASSOCIATING |
4525 STATUS_AUTH |
4526 STATUS_ASSOCIATED);
4527
James Ketrenosa613bff2005-08-24 21:43:11 -05004528 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004529 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004530
4531 case CMAS_TX_AUTH_SEQ_1:
4532 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4533 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4534 break;
4535 case CMAS_RX_AUTH_SEQ_2:
4536 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4537 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4538 break;
4539 case CMAS_AUTH_SEQ_1_PASS:
4540 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4541 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4542 break;
4543 case CMAS_AUTH_SEQ_1_FAIL:
4544 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4545 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4546 break;
4547 case CMAS_TX_AUTH_SEQ_3:
4548 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4549 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4550 break;
4551 case CMAS_RX_AUTH_SEQ_4:
4552 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4553 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4554 break;
4555 case CMAS_AUTH_SEQ_2_PASS:
4556 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4557 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4558 break;
4559 case CMAS_AUTH_SEQ_2_FAIL:
4560 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4561 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4562 break;
4563 case CMAS_TX_ASSOC:
4564 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4565 IPW_DL_ASSOC, "TX_ASSOC\n");
4566 break;
4567 case CMAS_RX_ASSOC_RESP:
4568 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4569 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004570
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004571 break;
4572 case CMAS_ASSOCIATED:
4573 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4574 IPW_DL_ASSOC, "ASSOCIATED\n");
4575 break;
4576 default:
4577 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4578 auth->state);
4579 break;
4580 }
4581 break;
4582 }
4583
4584 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4585 struct notif_channel_result *x =
4586 &notif->u.channel_result;
4587
4588 if (notif->size == sizeof(*x)) {
4589 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4590 x->channel_num);
4591 } else {
4592 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4593 "(should be %zd)\n",
4594 notif->size, sizeof(*x));
4595 }
4596 break;
4597 }
4598
4599 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4600 struct notif_scan_complete *x = &notif->u.scan_complete;
4601 if (notif->size == sizeof(*x)) {
4602 IPW_DEBUG_SCAN
4603 ("Scan completed: type %d, %d channels, "
4604 "%d status\n", x->scan_type,
4605 x->num_channels, x->status);
4606 } else {
4607 IPW_ERROR("Scan completed of wrong size %d "
4608 "(should be %zd)\n",
4609 notif->size, sizeof(*x));
4610 }
4611
4612 priv->status &=
4613 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4614
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004615 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004616 cancel_delayed_work(&priv->scan_check);
4617
James Ketrenosb095c382005-08-24 22:04:42 -05004618 if (priv->status & STATUS_EXIT_PENDING)
4619 break;
4620
4621 priv->ieee->scans++;
4622
4623#ifdef CONFIG_IPW2200_MONITOR
4624 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004625 priv->status |= STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004626 queue_work(priv->workqueue,
4627 &priv->request_scan);
4628 break;
4629 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004630 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004631#endif /* CONFIG_IPW2200_MONITOR */
4632
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004633 if (!(priv->status & (STATUS_ASSOCIATED |
4634 STATUS_ASSOCIATING |
4635 STATUS_ROAMING |
4636 STATUS_DISASSOCIATING)))
4637 queue_work(priv->workqueue, &priv->associate);
4638 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004639 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4640 /* If a scan completed and we are in roam mode, then
4641 * the scan that completed was the one requested as a
4642 * result of entering roam... so, schedule the
4643 * roam work */
4644 queue_work(priv->workqueue,
4645 &priv->roam);
4646 else
4647 /* Don't schedule if we aborted the scan */
4648 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004649 } else if (priv->status & STATUS_SCAN_PENDING)
4650 queue_work(priv->workqueue,
4651 &priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004652 else if (priv->config & CFG_BACKGROUND_SCAN
4653 && priv->status & STATUS_ASSOCIATED)
4654 queue_delayed_work(priv->workqueue,
4655 &priv->request_scan, HZ);
Zhu Yi07f02e42006-04-13 17:19:25 +08004656
4657 /* Send an empty event to user space.
4658 * We don't send the received data on the event because
4659 * it would require us to do complex transcoding, and
4660 * we want to minimise the work done in the irq handler
4661 * Use a request to extract the data.
4662 * Also, we generate this even for any scan, regardless
4663 * on how the scan was initiated. User space can just
4664 * sync on periodic scan to get fresh data...
4665 * Jean II */
4666 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) {
4667 union iwreq_data wrqu;
4668
4669 wrqu.data.length = 0;
4670 wrqu.data.flags = 0;
4671 wireless_send_event(priv->net_dev, SIOCGIWSCAN,
4672 &wrqu, NULL);
4673 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004674 break;
4675 }
4676
4677 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4678 struct notif_frag_length *x = &notif->u.frag_len;
4679
James Ketrenosa613bff2005-08-24 21:43:11 -05004680 if (notif->size == sizeof(*x))
4681 IPW_ERROR("Frag length: %d\n",
4682 le16_to_cpu(x->frag_length));
4683 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004684 IPW_ERROR("Frag length of wrong size %d "
4685 "(should be %zd)\n",
4686 notif->size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004687 break;
4688 }
4689
4690 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4691 struct notif_link_deterioration *x =
4692 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004693
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004694 if (notif->size == sizeof(*x)) {
4695 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Cahill, Ben M12977152006-03-08 02:58:02 +08004696 "link deterioration: type %d, cnt %d\n",
4697 x->silence_notification_type,
4698 x->silence_count);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004699 memcpy(&priv->last_link_deterioration, x,
4700 sizeof(*x));
4701 } else {
4702 IPW_ERROR("Link Deterioration of wrong size %d "
4703 "(should be %zd)\n",
4704 notif->size, sizeof(*x));
4705 }
4706 break;
4707 }
4708
4709 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4710 IPW_ERROR("Dino config\n");
4711 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004712 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004713 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004714
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004715 break;
4716 }
4717
4718 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4719 struct notif_beacon_state *x = &notif->u.beacon_state;
4720 if (notif->size != sizeof(*x)) {
4721 IPW_ERROR
4722 ("Beacon state of wrong size %d (should "
4723 "be %zd)\n", notif->size, sizeof(*x));
4724 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004725 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004726
James Ketrenosa613bff2005-08-24 21:43:11 -05004727 if (le32_to_cpu(x->state) ==
4728 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4729 ipw_handle_missed_beacon(priv,
4730 le32_to_cpu(x->
4731 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004732
James Ketrenos43f66a62005-03-25 12:31:53 -06004733 break;
4734 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004735
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004736 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4737 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
4738 if (notif->size == sizeof(*x)) {
4739 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4740 "0x%02x station %d\n",
4741 x->key_state, x->security_type,
4742 x->station_index);
4743 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004744 }
4745
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004746 IPW_ERROR
4747 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4748 notif->size, sizeof(*x));
4749 break;
4750 }
4751
4752 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4753 struct notif_calibration *x = &notif->u.calibration;
4754
4755 if (notif->size == sizeof(*x)) {
4756 memcpy(&priv->calib, x, sizeof(*x));
4757 IPW_DEBUG_INFO("TODO: Calibration\n");
4758 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004759 }
4760
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004761 IPW_ERROR
4762 ("Calibration of wrong size %d (should be %zd)\n",
4763 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004764 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004765 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004766
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004767 case HOST_NOTIFICATION_NOISE_STATS:{
4768 if (notif->size == sizeof(u32)) {
Zhu Yi00d21de2006-04-13 17:19:02 +08004769 priv->exp_avg_noise =
4770 exponential_average(priv->exp_avg_noise,
4771 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4772 DEPTH_NOISE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004773 break;
4774 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004775
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004776 IPW_ERROR
4777 ("Noise stat is wrong size %d (should be %zd)\n",
4778 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004779 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004780 }
4781
James Ketrenos43f66a62005-03-25 12:31:53 -06004782 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004783 IPW_DEBUG_NOTIF("Unknown notification: "
4784 "subtype=%d,flags=0x%2x,size=%d\n",
4785 notif->subtype, notif->flags, notif->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004786 }
4787}
4788
4789/**
4790 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004791 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004792 * @param priv
4793 * @return error code
4794 */
4795static int ipw_queue_reset(struct ipw_priv *priv)
4796{
4797 int rc = 0;
4798 /** @todo customize queue sizes */
4799 int nTx = 64, nTxCmd = 8;
4800 ipw_tx_queue_free(priv);
4801 /* Tx CMD queue */
4802 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004803 IPW_TX_CMD_QUEUE_READ_INDEX,
4804 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4805 IPW_TX_CMD_QUEUE_BD_BASE,
4806 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004807 if (rc) {
4808 IPW_ERROR("Tx Cmd queue init failed\n");
4809 goto error;
4810 }
4811 /* Tx queue(s) */
4812 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004813 IPW_TX_QUEUE_0_READ_INDEX,
4814 IPW_TX_QUEUE_0_WRITE_INDEX,
4815 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004816 if (rc) {
4817 IPW_ERROR("Tx 0 queue init failed\n");
4818 goto error;
4819 }
4820 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004821 IPW_TX_QUEUE_1_READ_INDEX,
4822 IPW_TX_QUEUE_1_WRITE_INDEX,
4823 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004824 if (rc) {
4825 IPW_ERROR("Tx 1 queue init failed\n");
4826 goto error;
4827 }
4828 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004829 IPW_TX_QUEUE_2_READ_INDEX,
4830 IPW_TX_QUEUE_2_WRITE_INDEX,
4831 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004832 if (rc) {
4833 IPW_ERROR("Tx 2 queue init failed\n");
4834 goto error;
4835 }
4836 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004837 IPW_TX_QUEUE_3_READ_INDEX,
4838 IPW_TX_QUEUE_3_WRITE_INDEX,
4839 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004840 if (rc) {
4841 IPW_ERROR("Tx 3 queue init failed\n");
4842 goto error;
4843 }
4844 /* statistics */
4845 priv->rx_bufs_min = 0;
4846 priv->rx_pend_max = 0;
4847 return rc;
4848
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004849 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004850 ipw_tx_queue_free(priv);
4851 return rc;
4852}
4853
4854/**
4855 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004856 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004857 * When FW adwances 'R' index, all entries between old and
4858 * new 'R' index need to be reclaimed. As result, some free space
4859 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004860 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004861 * @note Need to protect against garbage in 'R' index
4862 * @param priv
4863 * @param txq
4864 * @param qindex
4865 * @return Number of used entries remains in the queue
4866 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004867static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004868 struct clx2_tx_queue *txq, int qindex)
4869{
4870 u32 hw_tail;
4871 int used;
4872 struct clx2_queue *q = &txq->q;
4873
4874 hw_tail = ipw_read32(priv, q->reg_r);
4875 if (hw_tail >= q->n_bd) {
4876 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004877 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4878 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004879 goto done;
4880 }
4881 for (; q->last_used != hw_tail;
4882 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4883 ipw_queue_tx_free_tfd(priv, txq);
4884 priv->tx_packets++;
4885 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004886 done:
James Ketrenos9ddf84f2005-08-16 17:07:11 -05004887 if ((ipw_queue_space(q) > q->low_mark) &&
4888 (qindex >= 0) &&
4889 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4890 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06004891 used = q->first_empty - q->last_used;
4892 if (used < 0)
4893 used += q->n_bd;
4894
4895 return used;
4896}
4897
4898static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4899 int len, int sync)
4900{
4901 struct clx2_tx_queue *txq = &priv->txq_cmd;
4902 struct clx2_queue *q = &txq->q;
4903 struct tfd_frame *tfd;
4904
4905 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4906 IPW_ERROR("No space for Tx\n");
4907 return -EBUSY;
4908 }
4909
4910 tfd = &txq->bd[q->first_empty];
4911 txq->txb[q->first_empty] = NULL;
4912
4913 memset(tfd, 0, sizeof(*tfd));
4914 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4915 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4916 priv->hcmd_seq++;
4917 tfd->u.cmd.index = hcmd;
4918 tfd->u.cmd.length = len;
4919 memcpy(tfd->u.cmd.payload, buf, len);
4920 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4921 ipw_write32(priv, q->reg_w, q->first_empty);
4922 _ipw_read32(priv, 0x90);
4923
4924 return 0;
4925}
4926
Jeff Garzikbf794512005-07-31 13:07:26 -04004927/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004928 * Rx theory of operation
4929 *
4930 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05004931 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06004932 * 0 to 31
4933 *
4934 * Rx Queue Indexes
4935 * The host/firmware share two index registers for managing the Rx buffers.
4936 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004937 * The READ index maps to the first position that the firmware may be writing
4938 * to -- the driver can read up to (but not including) this position and get
4939 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06004940 * The READ index is managed by the firmware once the card is enabled.
4941 *
4942 * The WRITE index maps to the last position the driver has read from -- the
4943 * position preceding WRITE is the last slot the firmware can place a packet.
4944 *
4945 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04004946 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06004947 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004948 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06004949 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4950 *
4951 * When the firmware places a packet in a buffer it will advance the READ index
4952 * and fire the RX interrupt. The driver can then query the READ index and
4953 * process as many packets as possible, moving the WRITE index forward as it
4954 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04004955 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004956 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004957 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06004958 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04004959 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06004960 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4961 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4962 * 'processed' and 'read' driver indexes as well)
4963 * + A received packet is processed and handed to the kernel network stack,
4964 * detached from the ipw->rxq. The driver 'processed' index is updated.
4965 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04004966 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4967 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06004968 * were enough free buffers and RX_STALLED is set it is cleared.
4969 *
4970 *
4971 * Driver sequence:
4972 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004973 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06004974 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4975 * ipw_rx_queue_restock
4976 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4977 * queue, updates firmware pointers, and updates
4978 * the WRITE index. If insufficient rx_free buffers
4979 * are available, schedules ipw_rx_queue_replenish
4980 *
4981 * -- enable interrupts --
4982 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04004983 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06004984 * Moves the packet buffer from queue to rx_used.
4985 * Calls ipw_rx_queue_restock to refill any empty
4986 * slots.
4987 * ...
4988 *
4989 */
4990
Jeff Garzikbf794512005-07-31 13:07:26 -04004991/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004992 * If there are slots in the RX queue that need to be restocked,
4993 * and we have free pre-allocated buffers, fill the ranks as much
4994 * as we can pulling from rx_free.
4995 *
4996 * This moves the 'write' index forward to catch up with 'processed', and
4997 * also updates the memory address in the firmware to reference the new
4998 * target buffer.
4999 */
5000static void ipw_rx_queue_restock(struct ipw_priv *priv)
5001{
5002 struct ipw_rx_queue *rxq = priv->rxq;
5003 struct list_head *element;
5004 struct ipw_rx_mem_buffer *rxb;
5005 unsigned long flags;
5006 int write;
5007
5008 spin_lock_irqsave(&rxq->lock, flags);
5009 write = rxq->write;
5010 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
5011 element = rxq->rx_free.next;
5012 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
5013 list_del(element);
5014
James Ketrenosb095c382005-08-24 22:04:42 -05005015 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06005016 rxb->dma_addr);
5017 rxq->queue[rxq->write] = rxb;
5018 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5019 rxq->free_count--;
5020 }
5021 spin_unlock_irqrestore(&rxq->lock, flags);
5022
Jeff Garzikbf794512005-07-31 13:07:26 -04005023 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06005024 * refill it */
5025 if (rxq->free_count <= RX_LOW_WATERMARK)
5026 queue_work(priv->workqueue, &priv->rx_replenish);
5027
5028 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04005029 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05005030 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06005031}
5032
5033/*
5034 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04005035 * Also restock the Rx queue via ipw_rx_queue_restock.
5036 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005037 * This is called as a scheduled work item (except for during intialization)
5038 */
5039static void ipw_rx_queue_replenish(void *data)
5040{
5041 struct ipw_priv *priv = data;
5042 struct ipw_rx_queue *rxq = priv->rxq;
5043 struct list_head *element;
5044 struct ipw_rx_mem_buffer *rxb;
5045 unsigned long flags;
5046
5047 spin_lock_irqsave(&rxq->lock, flags);
5048 while (!list_empty(&rxq->rx_used)) {
5049 element = rxq->rx_used.next;
5050 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05005051 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06005052 if (!rxb->skb) {
5053 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5054 priv->net_dev->name);
5055 /* We don't reschedule replenish work here -- we will
5056 * call the restock method and if it still needs
5057 * more buffers it will schedule replenish */
5058 break;
5059 }
5060 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04005061
James Ketrenos43f66a62005-03-25 12:31:53 -06005062 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005063 rxb->dma_addr =
5064 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05005065 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04005066
James Ketrenos43f66a62005-03-25 12:31:53 -06005067 list_add_tail(&rxb->list, &rxq->rx_free);
5068 rxq->free_count++;
5069 }
5070 spin_unlock_irqrestore(&rxq->lock, flags);
5071
5072 ipw_rx_queue_restock(priv);
5073}
5074
James Ketrenosc848d0a2005-08-24 21:56:24 -05005075static void ipw_bg_rx_queue_replenish(void *data)
5076{
5077 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08005078 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005079 ipw_rx_queue_replenish(data);
Zhu Yi46441512006-01-24 16:37:59 +08005080 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005081}
5082
James Ketrenos43f66a62005-03-25 12:31:53 -06005083/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08005084 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04005085 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06005086 * non NULL it is unmapped and freed
5087 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005088static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06005089{
5090 int i;
5091
5092 if (!rxq)
5093 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005094
James Ketrenos43f66a62005-03-25 12:31:53 -06005095 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5096 if (rxq->pool[i].skb != NULL) {
5097 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05005098 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005099 dev_kfree_skb(rxq->pool[i].skb);
5100 }
5101 }
5102
5103 kfree(rxq);
5104}
5105
5106static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5107{
5108 struct ipw_rx_queue *rxq;
5109 int i;
5110
Takisc75f4742005-12-01 01:41:45 -08005111 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02005112 if (unlikely(!rxq)) {
5113 IPW_ERROR("memory allocation failed\n");
5114 return NULL;
5115 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005116 spin_lock_init(&rxq->lock);
5117 INIT_LIST_HEAD(&rxq->rx_free);
5118 INIT_LIST_HEAD(&rxq->rx_used);
5119
5120 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04005121 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06005122 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5123
5124 /* Set us so that we have processed and used all buffers, but have
5125 * not restocked the Rx queue with fresh buffers */
5126 rxq->read = rxq->write = 0;
5127 rxq->processed = RX_QUEUE_SIZE - 1;
5128 rxq->free_count = 0;
5129
5130 return rxq;
5131}
5132
5133static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5134{
5135 rate &= ~IEEE80211_BASIC_RATE_MASK;
5136 if (ieee_mode == IEEE_A) {
5137 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005138 case IEEE80211_OFDM_RATE_6MB:
5139 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005140 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005141 case IEEE80211_OFDM_RATE_9MB:
5142 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005143 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005144 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005145 return priv->
5146 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005147 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005148 return priv->
5149 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005150 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005151 return priv->
5152 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005153 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005154 return priv->
5155 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005156 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005157 return priv->
5158 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005159 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005160 return priv->
5161 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005162 default:
5163 return 0;
5164 }
5165 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005166
James Ketrenos43f66a62005-03-25 12:31:53 -06005167 /* B and G mixed */
5168 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005169 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005170 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005171 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005172 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005173 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005174 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005175 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005176 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
5177 }
5178
5179 /* If we are limited to B modulations, bail at this point */
5180 if (ieee_mode == IEEE_B)
5181 return 0;
5182
5183 /* G */
5184 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005185 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005186 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005187 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005188 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005189 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005190 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005191 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005192 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005193 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005194 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005195 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005196 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005197 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005198 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005199 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005200 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5201 }
5202
5203 return 0;
5204}
5205
Jeff Garzikbf794512005-07-31 13:07:26 -04005206static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005207 const struct ieee80211_network *network,
5208 struct ipw_supported_rates *rates)
5209{
5210 int num_rates, i;
5211
5212 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005213 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005214 rates->num_rates = 0;
5215 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005216 if (!ipw_is_rate_in_mask(priv, network->mode,
5217 network->rates[i])) {
5218
James Ketrenosea2b26e2005-08-24 21:25:16 -05005219 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005220 IPW_DEBUG_SCAN("Adding masked mandatory "
5221 "rate %02X\n",
5222 network->rates[i]);
5223 rates->supported_rates[rates->num_rates++] =
5224 network->rates[i];
5225 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005226 }
5227
James Ketrenos43f66a62005-03-25 12:31:53 -06005228 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5229 network->rates[i], priv->rates_mask);
5230 continue;
5231 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005232
James Ketrenos43f66a62005-03-25 12:31:53 -06005233 rates->supported_rates[rates->num_rates++] = network->rates[i];
5234 }
5235
James Ketrenosa613bff2005-08-24 21:43:11 -05005236 num_rates = min(network->rates_ex_len,
5237 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005238 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005239 if (!ipw_is_rate_in_mask(priv, network->mode,
5240 network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005241 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005242 IPW_DEBUG_SCAN("Adding masked mandatory "
5243 "rate %02X\n",
5244 network->rates_ex[i]);
5245 rates->supported_rates[rates->num_rates++] =
5246 network->rates[i];
5247 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005248 }
5249
James Ketrenos43f66a62005-03-25 12:31:53 -06005250 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5251 network->rates_ex[i], priv->rates_mask);
5252 continue;
5253 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005254
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005255 rates->supported_rates[rates->num_rates++] =
5256 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005257 }
5258
James Ketrenosea2b26e2005-08-24 21:25:16 -05005259 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005260}
5261
Arjan van de Ven858119e2006-01-14 13:20:43 -08005262static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005263 const struct ipw_supported_rates *src)
5264{
5265 u8 i;
5266 for (i = 0; i < src->num_rates; i++)
5267 dest->supported_rates[i] = src->supported_rates[i];
5268 dest->num_rates = src->num_rates;
5269}
5270
5271/* TODO: Look at sniffed packets in the air to determine if the basic rate
5272 * mask should ever be used -- right now all callers to add the scan rates are
5273 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5274static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005275 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005276{
Jeff Garzikbf794512005-07-31 13:07:26 -04005277 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005278 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005279
James Ketrenos43f66a62005-03-25 12:31:53 -06005280 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005281 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005282 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005283
5284 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005285 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005286 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005287
5288 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005289 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005290 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005291
5292 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005293 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005294 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005295}
5296
5297static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005298 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005299{
Jeff Garzikbf794512005-07-31 13:07:26 -04005300 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005301 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005302
5303 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005304 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005305 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005306
5307 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005308 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005309 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005310
5311 if (rate_mask & IEEE80211_OFDM_RATE_12MB_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_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005314
5315 if (rate_mask & IEEE80211_OFDM_RATE_18MB_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_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005318
5319 if (rate_mask & IEEE80211_OFDM_RATE_24MB_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_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005322
5323 if (rate_mask & IEEE80211_OFDM_RATE_36MB_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_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005326
5327 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005328 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005329 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005330
5331 if (rate_mask & IEEE80211_OFDM_RATE_54MB_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_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005334}
5335
5336struct ipw_network_match {
5337 struct ieee80211_network *network;
5338 struct ipw_supported_rates rates;
5339};
5340
James Ketrenosc848d0a2005-08-24 21:56:24 -05005341static int ipw_find_adhoc_network(struct ipw_priv *priv,
5342 struct ipw_network_match *match,
5343 struct ieee80211_network *network,
5344 int roaming)
5345{
5346 struct ipw_supported_rates rates;
5347
5348 /* Verify that this network's capability is compatible with the
5349 * current mode (AdHoc or Infrastructure) */
5350 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5351 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5352 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5353 "capability mismatch.\n",
5354 escape_essid(network->ssid, network->ssid_len),
5355 MAC_ARG(network->bssid));
5356 return 0;
5357 }
5358
5359 /* If we do not have an ESSID for this AP, we can not associate with
5360 * it */
5361 if (network->flags & NETWORK_EMPTY_ESSID) {
5362 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5363 "because of hidden ESSID.\n",
5364 escape_essid(network->ssid, network->ssid_len),
5365 MAC_ARG(network->bssid));
5366 return 0;
5367 }
5368
5369 if (unlikely(roaming)) {
5370 /* If we are roaming, then ensure check if this is a valid
5371 * network to try and roam to */
5372 if ((network->ssid_len != match->network->ssid_len) ||
5373 memcmp(network->ssid, match->network->ssid,
5374 network->ssid_len)) {
5375 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5376 "because of non-network ESSID.\n",
5377 escape_essid(network->ssid,
5378 network->ssid_len),
5379 MAC_ARG(network->bssid));
5380 return 0;
5381 }
5382 } else {
5383 /* If an ESSID has been configured then compare the broadcast
5384 * ESSID to ours */
5385 if ((priv->config & CFG_STATIC_ESSID) &&
5386 ((network->ssid_len != priv->essid_len) ||
5387 memcmp(network->ssid, priv->essid,
5388 min(network->ssid_len, priv->essid_len)))) {
5389 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005390
James Ketrenosc848d0a2005-08-24 21:56:24 -05005391 strncpy(escaped,
5392 escape_essid(network->ssid, network->ssid_len),
5393 sizeof(escaped));
5394 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5395 "because of ESSID mismatch: '%s'.\n",
5396 escaped, MAC_ARG(network->bssid),
5397 escape_essid(priv->essid,
5398 priv->essid_len));
5399 return 0;
5400 }
5401 }
5402
5403 /* If the old network rate is better than this one, don't bother
5404 * testing everything else. */
5405
5406 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005407 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5408 "current network.\n",
5409 escape_essid(match->network->ssid,
5410 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005411 return 0;
5412 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005413 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5414 "current network.\n",
5415 escape_essid(match->network->ssid,
5416 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005417 return 0;
5418 }
5419
5420 /* Now go through and see if the requested network is valid... */
5421 if (priv->ieee->scan_age != 0 &&
5422 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5423 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005424 "because of age: %ums.\n",
James Ketrenosc848d0a2005-08-24 21:56:24 -05005425 escape_essid(network->ssid, network->ssid_len),
5426 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005427 jiffies_to_msecs(jiffies -
5428 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005429 return 0;
5430 }
5431
5432 if ((priv->config & CFG_STATIC_CHANNEL) &&
5433 (network->channel != priv->channel)) {
5434 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5435 "because of channel mismatch: %d != %d.\n",
5436 escape_essid(network->ssid, network->ssid_len),
5437 MAC_ARG(network->bssid),
5438 network->channel, priv->channel);
5439 return 0;
5440 }
5441
5442 /* Verify privacy compatability */
5443 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5444 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5445 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5446 "because of privacy mismatch: %s != %s.\n",
5447 escape_essid(network->ssid, network->ssid_len),
5448 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005449 priv->
5450 capability & CAP_PRIVACY_ON ? "on" : "off",
5451 network->
5452 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5453 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005454 return 0;
5455 }
5456
5457 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5458 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5459 "because of the same BSSID match: " MAC_FMT
5460 ".\n", escape_essid(network->ssid,
5461 network->ssid_len),
5462 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5463 return 0;
5464 }
5465
5466 /* Filter out any incompatible freq / mode combinations */
5467 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5468 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5469 "because of invalid frequency/mode "
5470 "combination.\n",
5471 escape_essid(network->ssid, network->ssid_len),
5472 MAC_ARG(network->bssid));
5473 return 0;
5474 }
5475
5476 /* Ensure that the rates supported by the driver are compatible with
5477 * this AP, including verification of basic rates (mandatory) */
5478 if (!ipw_compatible_rates(priv, network, &rates)) {
5479 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5480 "because configured rate mask excludes "
5481 "AP mandatory rate.\n",
5482 escape_essid(network->ssid, network->ssid_len),
5483 MAC_ARG(network->bssid));
5484 return 0;
5485 }
5486
5487 if (rates.num_rates == 0) {
5488 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5489 "because of no compatible rates.\n",
5490 escape_essid(network->ssid, network->ssid_len),
5491 MAC_ARG(network->bssid));
5492 return 0;
5493 }
5494
5495 /* TODO: Perform any further minimal comparititive tests. We do not
5496 * want to put too much policy logic here; intelligent scan selection
5497 * should occur within a generic IEEE 802.11 user space tool. */
5498
5499 /* Set up 'new' AP to this network */
5500 ipw_copy_rates(&match->rates, &rates);
5501 match->network = network;
5502 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5503 escape_essid(network->ssid, network->ssid_len),
5504 MAC_ARG(network->bssid));
5505
5506 return 1;
5507}
5508
5509static void ipw_merge_adhoc_network(void *data)
5510{
5511 struct ipw_priv *priv = data;
5512 struct ieee80211_network *network = NULL;
5513 struct ipw_network_match match = {
5514 .network = priv->assoc_network
5515 };
5516
James Ketrenosafbf30a2005-08-25 00:05:33 -05005517 if ((priv->status & STATUS_ASSOCIATED) &&
5518 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005519 /* First pass through ROAM process -- look for a better
5520 * network */
5521 unsigned long flags;
5522
5523 spin_lock_irqsave(&priv->ieee->lock, flags);
5524 list_for_each_entry(network, &priv->ieee->network_list, list) {
5525 if (network != priv->assoc_network)
5526 ipw_find_adhoc_network(priv, &match, network,
5527 1);
5528 }
5529 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5530
5531 if (match.network == priv->assoc_network) {
5532 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5533 "merge to.\n");
5534 return;
5535 }
5536
Zhu Yi46441512006-01-24 16:37:59 +08005537 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005538 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5539 IPW_DEBUG_MERGE("remove network %s\n",
5540 escape_essid(priv->essid,
5541 priv->essid_len));
5542 ipw_remove_current_network(priv);
5543 }
5544
5545 ipw_disassociate(priv);
5546 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005547 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005548 return;
5549 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005550}
5551
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005552static int ipw_best_network(struct ipw_priv *priv,
5553 struct ipw_network_match *match,
5554 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005555{
5556 struct ipw_supported_rates rates;
5557
5558 /* Verify that this network's capability is compatible with the
5559 * current mode (AdHoc or Infrastructure) */
5560 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005561 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005562 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5563 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5564 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005565 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005566 escape_essid(network->ssid, network->ssid_len),
5567 MAC_ARG(network->bssid));
5568 return 0;
5569 }
5570
5571 /* If we do not have an ESSID for this AP, we can not associate with
5572 * it */
5573 if (network->flags & NETWORK_EMPTY_ESSID) {
5574 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5575 "because of hidden ESSID.\n",
5576 escape_essid(network->ssid, network->ssid_len),
5577 MAC_ARG(network->bssid));
5578 return 0;
5579 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005580
James Ketrenos43f66a62005-03-25 12:31:53 -06005581 if (unlikely(roaming)) {
5582 /* If we are roaming, then ensure check if this is a valid
5583 * network to try and roam to */
5584 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005585 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005586 network->ssid_len)) {
5587 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5588 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04005589 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005590 network->ssid_len),
5591 MAC_ARG(network->bssid));
5592 return 0;
5593 }
5594 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005595 /* If an ESSID has been configured then compare the broadcast
5596 * ESSID to ours */
5597 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005598 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005599 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005600 min(network->ssid_len, priv->essid_len)))) {
5601 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005602 strncpy(escaped,
5603 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005604 sizeof(escaped));
5605 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005606 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005607 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005608 escape_essid(priv->essid,
5609 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005610 return 0;
5611 }
5612 }
5613
5614 /* If the old network rate is better than this one, don't bother
5615 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005616 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005617 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005618 strncpy(escaped,
5619 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005620 sizeof(escaped));
5621 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5622 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5623 escaped, MAC_ARG(network->bssid),
5624 escape_essid(match->network->ssid,
5625 match->network->ssid_len),
5626 MAC_ARG(match->network->bssid));
5627 return 0;
5628 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005629
James Ketrenos43f66a62005-03-25 12:31:53 -06005630 /* If this network has already had an association attempt within the
5631 * last 3 seconds, do not try and associate again... */
5632 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005633 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005634 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005635 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005636 "assoc attempt).\n",
5637 escape_essid(network->ssid, network->ssid_len),
5638 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005639 jiffies_to_msecs(jiffies -
5640 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005641 return 0;
5642 }
5643
5644 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005645 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005646 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005647 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005648 "because of age: %ums.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005649 escape_essid(network->ssid, network->ssid_len),
5650 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005651 jiffies_to_msecs(jiffies -
5652 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005653 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005654 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005655
Jeff Garzikbf794512005-07-31 13:07:26 -04005656 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005657 (network->channel != priv->channel)) {
5658 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5659 "because of channel mismatch: %d != %d.\n",
5660 escape_essid(network->ssid, network->ssid_len),
5661 MAC_ARG(network->bssid),
5662 network->channel, priv->channel);
5663 return 0;
5664 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005665
James Ketrenos43f66a62005-03-25 12:31:53 -06005666 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005667 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005668 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5669 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5670 "because of privacy mismatch: %s != %s.\n",
5671 escape_essid(network->ssid, network->ssid_len),
5672 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04005673 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005674 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005675 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005676 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005677 return 0;
5678 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005679
5680 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005681 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5682 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5683 "because of BSSID mismatch: " MAC_FMT ".\n",
5684 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005685 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005686 return 0;
5687 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005688
James Ketrenos43f66a62005-03-25 12:31:53 -06005689 /* Filter out any incompatible freq / mode combinations */
5690 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5691 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5692 "because of invalid frequency/mode "
5693 "combination.\n",
5694 escape_essid(network->ssid, network->ssid_len),
5695 MAC_ARG(network->bssid));
5696 return 0;
5697 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005698
Liu Hong1fe0adb2005-08-19 09:33:10 -05005699 /* Filter out invalid channel in current GEO */
Larry Finger1867b112006-02-28 09:48:28 -06005700 if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005701 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5702 "because of invalid channel in current GEO\n",
5703 escape_essid(network->ssid, network->ssid_len),
5704 MAC_ARG(network->bssid));
5705 return 0;
5706 }
5707
James Ketrenosea2b26e2005-08-24 21:25:16 -05005708 /* Ensure that the rates supported by the driver are compatible with
5709 * this AP, including verification of basic rates (mandatory) */
5710 if (!ipw_compatible_rates(priv, network, &rates)) {
5711 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5712 "because configured rate mask excludes "
5713 "AP mandatory rate.\n",
5714 escape_essid(network->ssid, network->ssid_len),
5715 MAC_ARG(network->bssid));
5716 return 0;
5717 }
5718
James Ketrenos43f66a62005-03-25 12:31:53 -06005719 if (rates.num_rates == 0) {
5720 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5721 "because of no compatible rates.\n",
5722 escape_essid(network->ssid, network->ssid_len),
5723 MAC_ARG(network->bssid));
5724 return 0;
5725 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005726
James Ketrenos43f66a62005-03-25 12:31:53 -06005727 /* TODO: Perform any further minimal comparititive tests. We do not
5728 * want to put too much policy logic here; intelligent scan selection
5729 * should occur within a generic IEEE 802.11 user space tool. */
5730
5731 /* Set up 'new' AP to this network */
5732 ipw_copy_rates(&match->rates, &rates);
5733 match->network = network;
5734
5735 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5736 escape_essid(network->ssid, network->ssid_len),
5737 MAC_ARG(network->bssid));
5738
5739 return 1;
5740}
5741
Jeff Garzikbf794512005-07-31 13:07:26 -04005742static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005743 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005744{
Larry Finger1867b112006-02-28 09:48:28 -06005745 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005746 int i;
5747
James Ketrenos43f66a62005-03-25 12:31:53 -06005748 /*
5749 * For the purposes of scanning, we can set our wireless mode
5750 * to trigger scans across combinations of bands, but when it
5751 * comes to creating a new ad-hoc network, we have tell the FW
5752 * exactly which band to use.
5753 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005754 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005755 * chossen band. Attempting to create a new ad-hoc network
5756 * with an invalid channel for wireless mode will trigger a
5757 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005758 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005759 */
Larry Finger1867b112006-02-28 09:48:28 -06005760 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005761 case IEEE80211_52GHZ_BAND:
5762 network->mode = IEEE_A;
Larry Finger1867b112006-02-28 09:48:28 -06005763 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005764 BUG_ON(i == -1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005765 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5766 IPW_WARNING("Overriding invalid channel\n");
5767 priv->channel = geo->a[0].channel;
5768 }
5769 break;
5770
5771 case IEEE80211_24GHZ_BAND:
5772 if (priv->ieee->mode & IEEE_G)
5773 network->mode = IEEE_G;
5774 else
5775 network->mode = IEEE_B;
Larry Finger1867b112006-02-28 09:48:28 -06005776 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005777 BUG_ON(i == -1);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005778 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5779 IPW_WARNING("Overriding invalid channel\n");
5780 priv->channel = geo->bg[0].channel;
5781 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005782 break;
5783
5784 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005785 IPW_WARNING("Overriding invalid channel\n");
5786 if (priv->ieee->mode & IEEE_A) {
5787 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005788 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005789 } else if (priv->ieee->mode & IEEE_G) {
5790 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005791 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005792 } else {
5793 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005794 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005795 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005796 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005797 }
5798
5799 network->channel = priv->channel;
5800 priv->config |= CFG_ADHOC_PERSIST;
5801 ipw_create_bssid(priv, network->bssid);
5802 network->ssid_len = priv->essid_len;
5803 memcpy(network->ssid, priv->essid, priv->essid_len);
5804 memset(&network->stats, 0, sizeof(network->stats));
5805 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005806 if (!(priv->config & CFG_PREAMBLE_LONG))
5807 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005808 if (priv->capability & CAP_PRIVACY_ON)
5809 network->capability |= WLAN_CAPABILITY_PRIVACY;
5810 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005811 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005812 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005813 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005814 &priv->rates.supported_rates[network->rates_len],
5815 network->rates_ex_len);
5816 network->last_scanned = 0;
5817 network->flags = 0;
5818 network->last_associate = 0;
5819 network->time_stamp[0] = 0;
5820 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005821 network->beacon_interval = 100; /* Default */
5822 network->listen_interval = 10; /* Default */
5823 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005824 network->wpa_ie_len = 0;
5825 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005826}
5827
James Ketrenosb095c382005-08-24 22:04:42 -05005828static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5829{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005830 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005831
5832 if (!(priv->ieee->sec.flags & (1 << index)))
5833 return;
5834
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005835 key.key_id = index;
5836 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5837 key.security_type = type;
5838 key.station_index = 0; /* always 0 for BSS */
5839 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005840 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005841 key.tx_counter[0] = 0;
5842 key.tx_counter[1] = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005843
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005844 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05005845}
5846
5847static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005848{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005849 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06005850 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06005851
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005852 key.cmd_id = DINO_CMD_WEP_KEY;
5853 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005854
James Ketrenosb095c382005-08-24 22:04:42 -05005855 /* Note: AES keys cannot be set for multiple times.
5856 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005857 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005858 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05005859 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005860 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005861 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005862 }
5863
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005864 key.key_size = priv->ieee->sec.key_sizes[i];
5865 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05005866
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005867 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04005868 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005869}
5870
Zhu Yi1fbfea52005-08-05 17:22:56 +08005871static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5872{
5873 if (priv->ieee->host_encrypt)
5874 return;
5875
5876 switch (level) {
5877 case SEC_LEVEL_3:
5878 priv->sys_config.disable_unicast_decryption = 0;
5879 priv->ieee->host_decrypt = 0;
5880 break;
5881 case SEC_LEVEL_2:
5882 priv->sys_config.disable_unicast_decryption = 1;
5883 priv->ieee->host_decrypt = 1;
5884 break;
5885 case SEC_LEVEL_1:
5886 priv->sys_config.disable_unicast_decryption = 0;
5887 priv->ieee->host_decrypt = 0;
5888 break;
5889 case SEC_LEVEL_0:
5890 priv->sys_config.disable_unicast_decryption = 1;
5891 break;
5892 default:
5893 break;
5894 }
5895}
5896
5897static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5898{
5899 if (priv->ieee->host_encrypt)
5900 return;
5901
5902 switch (level) {
5903 case SEC_LEVEL_3:
5904 priv->sys_config.disable_multicast_decryption = 0;
5905 break;
5906 case SEC_LEVEL_2:
5907 priv->sys_config.disable_multicast_decryption = 1;
5908 break;
5909 case SEC_LEVEL_1:
5910 priv->sys_config.disable_multicast_decryption = 0;
5911 break;
5912 case SEC_LEVEL_0:
5913 priv->sys_config.disable_multicast_decryption = 1;
5914 break;
5915 default:
5916 break;
5917 }
5918}
5919
James Ketrenosb095c382005-08-24 22:04:42 -05005920static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5921{
5922 switch (priv->ieee->sec.level) {
5923 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005924 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5925 ipw_send_tgi_tx_key(priv,
5926 DCT_FLAG_EXT_SECURITY_CCM,
5927 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005928
Hong Liu567deaf2005-08-31 18:07:22 +08005929 if (!priv->ieee->host_mc_decrypt)
5930 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05005931 break;
5932 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005933 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5934 ipw_send_tgi_tx_key(priv,
5935 DCT_FLAG_EXT_SECURITY_TKIP,
5936 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05005937 break;
5938 case SEC_LEVEL_1:
5939 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05005940 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5941 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05005942 break;
5943 case SEC_LEVEL_0:
5944 default:
5945 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005946 }
5947}
5948
5949static void ipw_adhoc_check(void *data)
5950{
5951 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04005952
James Ketrenosafbf30a2005-08-25 00:05:33 -05005953 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005954 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005955 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5956 IPW_DL_STATE | IPW_DL_ASSOC,
5957 "Missed beacon: %d - disassociate\n",
5958 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06005959 ipw_remove_current_network(priv);
5960 ipw_disassociate(priv);
5961 return;
5962 }
5963
Jeff Garzikbf794512005-07-31 13:07:26 -04005964 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06005965 priv->assoc_request.beacon_interval);
5966}
5967
James Ketrenosc848d0a2005-08-24 21:56:24 -05005968static void ipw_bg_adhoc_check(void *data)
5969{
5970 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08005971 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005972 ipw_adhoc_check(data);
Zhu Yi46441512006-01-24 16:37:59 +08005973 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005974}
5975
Brice Goglin0f52bf92005-12-01 01:41:46 -08005976#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -06005977static void ipw_debug_config(struct ipw_priv *priv)
5978{
5979 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5980 "[CFG 0x%08X]\n", priv->config);
5981 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005982 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005983 else
5984 IPW_DEBUG_INFO("Channel unlocked.\n");
5985 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04005986 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005987 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005988 else
5989 IPW_DEBUG_INFO("ESSID unlocked.\n");
5990 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05005991 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5992 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005993 else
5994 IPW_DEBUG_INFO("BSSID unlocked.\n");
5995 if (priv->capability & CAP_PRIVACY_ON)
5996 IPW_DEBUG_INFO("PRIVACY on\n");
5997 else
5998 IPW_DEBUG_INFO("PRIVACY off\n");
5999 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
6000}
6001#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04006002#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06006003#endif
6004
Arjan van de Ven858119e2006-01-14 13:20:43 -08006005static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06006006{
6007 /* TODO: Verify that this works... */
6008 struct ipw_fixed_rate fr = {
6009 .tx_rates = priv->rates_mask
6010 };
6011 u32 reg;
6012 u16 mask = 0;
6013
Jeff Garzikbf794512005-07-31 13:07:26 -04006014 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06006015 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04006016
James Ketrenos43f66a62005-03-25 12:31:53 -06006017 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006018 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06006019 /* IEEE_A */
6020 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
6021 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006022 IPW_DEBUG_WX
6023 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06006024 fr.tx_rates = 0;
6025 break;
6026 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006027
James Ketrenos43f66a62005-03-25 12:31:53 -06006028 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
6029 break;
6030
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006031 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06006032 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05006033 if (mode == IEEE_B) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006034 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
6035 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006036 IPW_DEBUG_WX
6037 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06006038 fr.tx_rates = 0;
6039 }
6040 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006041 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006042
6043 /* IEEE_G */
6044 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
6045 IEEE80211_OFDM_RATES_MASK)) {
6046 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006047 IPW_DEBUG_WX
6048 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06006049 fr.tx_rates = 0;
6050 break;
6051 }
6052
6053 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
6054 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
6055 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
6056 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006057
James Ketrenos43f66a62005-03-25 12:31:53 -06006058 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
6059 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
6060 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
6061 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006062
James Ketrenos43f66a62005-03-25 12:31:53 -06006063 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
6064 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
6065 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
6066 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006067
James Ketrenos43f66a62005-03-25 12:31:53 -06006068 fr.tx_rates |= mask;
6069 break;
6070 }
6071
6072 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006073 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06006074}
6075
James Ketrenosea2b26e2005-08-24 21:25:16 -05006076static void ipw_abort_scan(struct ipw_priv *priv)
6077{
6078 int err;
6079
6080 if (priv->status & STATUS_SCAN_ABORTING) {
6081 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6082 return;
6083 }
6084 priv->status |= STATUS_SCAN_ABORTING;
6085
6086 err = ipw_send_scan_abort(priv);
6087 if (err)
6088 IPW_DEBUG_HC("Request to abort scan failed.\n");
6089}
6090
James Ketrenosafbf30a2005-08-25 00:05:33 -05006091static void ipw_add_scan_channels(struct ipw_priv *priv,
6092 struct ipw_scan_request_ext *scan,
6093 int scan_type)
6094{
6095 int channel_index = 0;
6096 const struct ieee80211_geo *geo;
6097 int i;
6098
Larry Finger1867b112006-02-28 09:48:28 -06006099 geo = ieee80211_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006100
6101 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
6102 int start = channel_index;
6103 for (i = 0; i < geo->a_channels; i++) {
6104 if ((priv->status & STATUS_ASSOCIATED) &&
6105 geo->a[i].channel == priv->channel)
6106 continue;
6107 channel_index++;
6108 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006109 ipw_set_scan_type(scan, channel_index,
6110 geo->a[i].
6111 flags & IEEE80211_CH_PASSIVE_ONLY ?
6112 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6113 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006114 }
6115
6116 if (start != channel_index) {
6117 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6118 (channel_index - start);
6119 channel_index++;
6120 }
6121 }
6122
6123 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
6124 int start = channel_index;
6125 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006126 int index;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006127 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
6128 /* nop out the list */
6129 [0] = 0
6130 };
6131
6132 u8 channel;
6133 while (channel_index < IPW_SCAN_CHANNELS) {
6134 channel =
6135 priv->speed_scan[priv->speed_scan_pos];
6136 if (channel == 0) {
6137 priv->speed_scan_pos = 0;
6138 channel = priv->speed_scan[0];
6139 }
6140 if ((priv->status & STATUS_ASSOCIATED) &&
6141 channel == priv->channel) {
6142 priv->speed_scan_pos++;
6143 continue;
6144 }
6145
6146 /* If this channel has already been
6147 * added in scan, break from loop
6148 * and this will be the first channel
6149 * in the next scan.
6150 */
6151 if (channels[channel - 1] != 0)
6152 break;
6153
6154 channels[channel - 1] = 1;
6155 priv->speed_scan_pos++;
6156 channel_index++;
6157 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006158 index =
Larry Finger1867b112006-02-28 09:48:28 -06006159 ieee80211_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006160 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006161 geo->bg[index].
6162 flags &
6163 IEEE80211_CH_PASSIVE_ONLY ?
6164 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6165 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006166 }
6167 } else {
6168 for (i = 0; i < geo->bg_channels; i++) {
6169 if ((priv->status & STATUS_ASSOCIATED) &&
6170 geo->bg[i].channel == priv->channel)
6171 continue;
6172 channel_index++;
6173 scan->channels_list[channel_index] =
6174 geo->bg[i].channel;
6175 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006176 geo->bg[i].
6177 flags &
6178 IEEE80211_CH_PASSIVE_ONLY ?
6179 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6180 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006181 }
6182 }
6183
6184 if (start != channel_index) {
6185 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6186 (channel_index - start);
6187 }
6188 }
6189}
6190
James Ketrenosea2b26e2005-08-24 21:25:16 -05006191static int ipw_request_scan(struct ipw_priv *priv)
6192{
6193 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006194 int err = 0, scan_type;
6195
6196 if (!(priv->status & STATUS_INIT) ||
6197 (priv->status & STATUS_EXIT_PENDING))
6198 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006199
Zhu Yi46441512006-01-24 16:37:59 +08006200 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006201
James Ketrenosea2b26e2005-08-24 21:25:16 -05006202 if (priv->status & STATUS_SCANNING) {
James Ketrenosa613bff2005-08-24 21:43:11 -05006203 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05006204 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006205 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006206 }
6207
James Ketrenosafbf30a2005-08-25 00:05:33 -05006208 if (!(priv->status & STATUS_SCAN_FORCED) &&
6209 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006210 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6211 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006212 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006213 }
6214
6215 if (priv->status & STATUS_RF_KILL_MASK) {
6216 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6217 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006218 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006219 }
6220
6221 memset(&scan, 0, sizeof(scan));
6222
James Ketrenosb095c382005-08-24 22:04:42 -05006223 if (priv->config & CFG_SPEED_SCAN)
6224 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6225 cpu_to_le16(30);
6226 else
6227 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6228 cpu_to_le16(20);
6229
James Ketrenosa613bff2005-08-24 21:43:11 -05006230 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6231 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05006232 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006233
James Ketrenosa613bff2005-08-24 21:43:11 -05006234 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006235
James Ketrenosb095c382005-08-24 22:04:42 -05006236#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006237 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006238 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006239 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006240
Larry Finger1867b112006-02-28 09:48:28 -06006241 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006242 case IEEE80211_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006243 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006244 channel = priv->channel;
6245 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006246
James Ketrenosb095c382005-08-24 22:04:42 -05006247 case IEEE80211_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006248 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006249 channel = priv->channel;
6250 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006251
James Ketrenosb095c382005-08-24 22:04:42 -05006252 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006253 band = (u8) (IPW_B_MODE << 6) | 1;
6254 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006255 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006256 }
6257
James Ketrenosb095c382005-08-24 22:04:42 -05006258 scan.channels_list[0] = band;
6259 scan.channels_list[1] = channel;
6260 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006261
James Ketrenosb095c382005-08-24 22:04:42 -05006262 /* NOTE: The card will sit on this channel for this time
6263 * period. Scan aborts are timing sensitive and frequently
6264 * result in firmware restarts. As such, it is best to
6265 * set a small dwell_time here and just keep re-issuing
6266 * scans. Otherwise fast channel hopping will not actually
6267 * hop channels.
6268 *
6269 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006270 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6271 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006272 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006273#endif /* CONFIG_IPW2200_MONITOR */
6274 /* If we are roaming, then make this a directed scan for the
6275 * current network. Otherwise, ensure that every other scan
6276 * is a fast channel hop scan */
6277 if ((priv->status & STATUS_ROAMING)
6278 || (!(priv->status & STATUS_ASSOCIATED)
6279 && (priv->config & CFG_STATIC_ESSID)
6280 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006281 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6282 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006283 IPW_DEBUG_HC("Attempt to send SSID command "
6284 "failed.\n");
6285 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006286 }
6287
6288 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006289 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006290 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006291
James Ketrenosafbf30a2005-08-25 00:05:33 -05006292 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006293#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006294 }
6295#endif
6296
6297 err = ipw_send_scan_request_ext(priv, &scan);
6298 if (err) {
6299 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006300 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006301 }
6302
6303 priv->status |= STATUS_SCANNING;
6304 priv->status &= ~STATUS_SCAN_PENDING;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006305 queue_delayed_work(priv->workqueue, &priv->scan_check,
6306 IPW_SCAN_CHECK_WATCHDOG);
James Ketrenosb095c382005-08-24 22:04:42 -05006307 done:
Zhu Yi46441512006-01-24 16:37:59 +08006308 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006309 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006310}
6311
6312static void ipw_bg_abort_scan(void *data)
6313{
6314 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08006315 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006316 ipw_abort_scan(data);
Zhu Yi46441512006-01-24 16:37:59 +08006317 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006318}
6319
James Ketrenosea2b26e2005-08-24 21:25:16 -05006320static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6321{
James Ketrenosb095c382005-08-24 22:04:42 -05006322 /* This is called when wpa_supplicant loads and closes the driver
6323 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006324 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006325 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006326}
6327
James Ketrenosea2b26e2005-08-24 21:25:16 -05006328static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6329{
6330 struct ieee80211_device *ieee = priv->ieee;
6331 struct ieee80211_security sec = {
6332 .flags = SEC_AUTH_MODE,
6333 };
6334 int ret = 0;
6335
James Ketrenosafbf30a2005-08-25 00:05:33 -05006336 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006337 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6338 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006339 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006340 sec.auth_mode = WLAN_AUTH_OPEN;
6341 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006342 } else if (value & IW_AUTH_ALG_LEAP) {
6343 sec.auth_mode = WLAN_AUTH_LEAP;
6344 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006345 } else
6346 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006347
6348 if (ieee->set_security)
6349 ieee->set_security(ieee->dev, &sec);
6350 else
6351 ret = -EOPNOTSUPP;
6352
6353 return ret;
6354}
6355
Adrian Bunka73e22b2006-01-21 01:39:42 +01006356static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6357 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006358{
6359 /* make sure WPA is enabled */
6360 ipw_wpa_enable(priv, 1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006361}
6362
6363static int ipw_set_rsn_capa(struct ipw_priv *priv,
6364 char *capabilities, int length)
6365{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006366 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6367
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006368 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006369 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006370}
6371
James Ketrenosafbf30a2005-08-25 00:05:33 -05006372/*
6373 * WE-18 support
6374 */
6375
6376/* SIOCSIWGENIE */
6377static int ipw_wx_set_genie(struct net_device *dev,
6378 struct iw_request_info *info,
6379 union iwreq_data *wrqu, char *extra)
6380{
6381 struct ipw_priv *priv = ieee80211_priv(dev);
6382 struct ieee80211_device *ieee = priv->ieee;
6383 u8 *buf;
6384 int err = 0;
6385
6386 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6387 (wrqu->data.length && extra == NULL))
6388 return -EINVAL;
6389
Zhu Yi46441512006-01-24 16:37:59 +08006390 //mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006391
6392 //if (!ieee->wpa_enabled) {
6393 // err = -EOPNOTSUPP;
6394 // goto out;
6395 //}
6396
6397 if (wrqu->data.length) {
6398 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6399 if (buf == NULL) {
6400 err = -ENOMEM;
6401 goto out;
6402 }
6403
6404 memcpy(buf, extra, wrqu->data.length);
6405 kfree(ieee->wpa_ie);
6406 ieee->wpa_ie = buf;
6407 ieee->wpa_ie_len = wrqu->data.length;
6408 } else {
6409 kfree(ieee->wpa_ie);
6410 ieee->wpa_ie = NULL;
6411 ieee->wpa_ie_len = 0;
6412 }
6413
6414 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6415 out:
Zhu Yi46441512006-01-24 16:37:59 +08006416 //mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006417 return err;
6418}
6419
6420/* SIOCGIWGENIE */
6421static int ipw_wx_get_genie(struct net_device *dev,
6422 struct iw_request_info *info,
6423 union iwreq_data *wrqu, char *extra)
6424{
6425 struct ipw_priv *priv = ieee80211_priv(dev);
6426 struct ieee80211_device *ieee = priv->ieee;
6427 int err = 0;
6428
Zhu Yi46441512006-01-24 16:37:59 +08006429 //mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006430
6431 //if (!ieee->wpa_enabled) {
6432 // err = -EOPNOTSUPP;
6433 // goto out;
6434 //}
6435
6436 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6437 wrqu->data.length = 0;
6438 goto out;
6439 }
6440
6441 if (wrqu->data.length < ieee->wpa_ie_len) {
6442 err = -E2BIG;
6443 goto out;
6444 }
6445
6446 wrqu->data.length = ieee->wpa_ie_len;
6447 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6448
6449 out:
Zhu Yi46441512006-01-24 16:37:59 +08006450 //mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006451 return err;
6452}
6453
Zhu Yi1fbfea52005-08-05 17:22:56 +08006454static int wext_cipher2level(int cipher)
6455{
6456 switch (cipher) {
6457 case IW_AUTH_CIPHER_NONE:
6458 return SEC_LEVEL_0;
6459 case IW_AUTH_CIPHER_WEP40:
6460 case IW_AUTH_CIPHER_WEP104:
6461 return SEC_LEVEL_1;
6462 case IW_AUTH_CIPHER_TKIP:
6463 return SEC_LEVEL_2;
6464 case IW_AUTH_CIPHER_CCMP:
6465 return SEC_LEVEL_3;
6466 default:
6467 return -1;
6468 }
6469}
6470
James Ketrenosafbf30a2005-08-25 00:05:33 -05006471/* SIOCSIWAUTH */
6472static int ipw_wx_set_auth(struct net_device *dev,
6473 struct iw_request_info *info,
6474 union iwreq_data *wrqu, char *extra)
6475{
6476 struct ipw_priv *priv = ieee80211_priv(dev);
6477 struct ieee80211_device *ieee = priv->ieee;
6478 struct iw_param *param = &wrqu->param;
6479 struct ieee80211_crypt_data *crypt;
6480 unsigned long flags;
6481 int ret = 0;
6482
6483 switch (param->flags & IW_AUTH_INDEX) {
6484 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006485 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006486 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006487 ipw_set_hw_decrypt_unicast(priv,
6488 wext_cipher2level(param->value));
6489 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006490 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006491 ipw_set_hw_decrypt_multicast(priv,
6492 wext_cipher2level(param->value));
6493 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006494 case IW_AUTH_KEY_MGMT:
6495 /*
6496 * ipw2200 does not use these parameters
6497 */
6498 break;
6499
6500 case IW_AUTH_TKIP_COUNTERMEASURES:
6501 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006502 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006503 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006504
6505 flags = crypt->ops->get_flags(crypt->priv);
6506
6507 if (param->value)
6508 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6509 else
6510 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6511
6512 crypt->ops->set_flags(flags, crypt->priv);
6513
6514 break;
6515
6516 case IW_AUTH_DROP_UNENCRYPTED:{
6517 /* HACK:
6518 *
6519 * wpa_supplicant calls set_wpa_enabled when the driver
6520 * is loaded and unloaded, regardless of if WPA is being
6521 * used. No other calls are made which can be used to
6522 * determine if encryption will be used or not prior to
6523 * association being expected. If encryption is not being
6524 * used, drop_unencrypted is set to false, else true -- we
6525 * can use this to determine if the CAP_PRIVACY_ON bit should
6526 * be set.
6527 */
6528 struct ieee80211_security sec = {
6529 .flags = SEC_ENABLED,
6530 .enabled = param->value,
6531 };
6532 priv->ieee->drop_unencrypted = param->value;
6533 /* We only change SEC_LEVEL for open mode. Others
6534 * are set by ipw_wpa_set_encryption.
6535 */
6536 if (!param->value) {
6537 sec.flags |= SEC_LEVEL;
6538 sec.level = SEC_LEVEL_0;
6539 } else {
6540 sec.flags |= SEC_LEVEL;
6541 sec.level = SEC_LEVEL_1;
6542 }
6543 if (priv->ieee->set_security)
6544 priv->ieee->set_security(priv->ieee->dev, &sec);
6545 break;
6546 }
6547
6548 case IW_AUTH_80211_AUTH_ALG:
6549 ret = ipw_wpa_set_auth_algs(priv, param->value);
6550 break;
6551
6552 case IW_AUTH_WPA_ENABLED:
6553 ret = ipw_wpa_enable(priv, param->value);
Zhu Yie3c5a642006-04-13 17:21:13 +08006554 ipw_disassociate(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006555 break;
6556
6557 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6558 ieee->ieee802_1x = param->value;
6559 break;
6560
6561 //case IW_AUTH_ROAMING_CONTROL:
6562 case IW_AUTH_PRIVACY_INVOKED:
6563 ieee->privacy_invoked = param->value;
6564 break;
6565
6566 default:
6567 return -EOPNOTSUPP;
6568 }
6569 return ret;
6570}
6571
6572/* SIOCGIWAUTH */
6573static int ipw_wx_get_auth(struct net_device *dev,
6574 struct iw_request_info *info,
6575 union iwreq_data *wrqu, char *extra)
6576{
6577 struct ipw_priv *priv = ieee80211_priv(dev);
6578 struct ieee80211_device *ieee = priv->ieee;
6579 struct ieee80211_crypt_data *crypt;
6580 struct iw_param *param = &wrqu->param;
6581 int ret = 0;
6582
6583 switch (param->flags & IW_AUTH_INDEX) {
6584 case IW_AUTH_WPA_VERSION:
6585 case IW_AUTH_CIPHER_PAIRWISE:
6586 case IW_AUTH_CIPHER_GROUP:
6587 case IW_AUTH_KEY_MGMT:
6588 /*
6589 * wpa_supplicant will control these internally
6590 */
6591 ret = -EOPNOTSUPP;
6592 break;
6593
6594 case IW_AUTH_TKIP_COUNTERMEASURES:
6595 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006596 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006597 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006598
6599 param->value = (crypt->ops->get_flags(crypt->priv) &
6600 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6601
6602 break;
6603
6604 case IW_AUTH_DROP_UNENCRYPTED:
6605 param->value = ieee->drop_unencrypted;
6606 break;
6607
6608 case IW_AUTH_80211_AUTH_ALG:
6609 param->value = ieee->sec.auth_mode;
6610 break;
6611
6612 case IW_AUTH_WPA_ENABLED:
6613 param->value = ieee->wpa_enabled;
6614 break;
6615
6616 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6617 param->value = ieee->ieee802_1x;
6618 break;
6619
6620 case IW_AUTH_ROAMING_CONTROL:
6621 case IW_AUTH_PRIVACY_INVOKED:
6622 param->value = ieee->privacy_invoked;
6623 break;
6624
6625 default:
6626 return -EOPNOTSUPP;
6627 }
6628 return 0;
6629}
6630
6631/* SIOCSIWENCODEEXT */
6632static int ipw_wx_set_encodeext(struct net_device *dev,
6633 struct iw_request_info *info,
6634 union iwreq_data *wrqu, char *extra)
6635{
6636 struct ipw_priv *priv = ieee80211_priv(dev);
6637 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6638
6639 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006640 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006641 /* IPW HW can't build TKIP MIC,
6642 host decryption still needed */
6643 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6644 priv->ieee->host_mc_decrypt = 1;
6645 else {
6646 priv->ieee->host_encrypt = 0;
6647 priv->ieee->host_encrypt_msdu = 1;
6648 priv->ieee->host_decrypt = 1;
6649 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006650 } else {
6651 priv->ieee->host_encrypt = 0;
6652 priv->ieee->host_encrypt_msdu = 0;
6653 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006654 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006655 }
6656 }
6657
6658 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6659}
6660
6661/* SIOCGIWENCODEEXT */
6662static int ipw_wx_get_encodeext(struct net_device *dev,
6663 struct iw_request_info *info,
6664 union iwreq_data *wrqu, char *extra)
6665{
6666 struct ipw_priv *priv = ieee80211_priv(dev);
6667 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6668}
6669
6670/* SIOCSIWMLME */
6671static int ipw_wx_set_mlme(struct net_device *dev,
6672 struct iw_request_info *info,
6673 union iwreq_data *wrqu, char *extra)
6674{
6675 struct ipw_priv *priv = ieee80211_priv(dev);
6676 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6677 u16 reason;
6678
6679 reason = cpu_to_le16(mlme->reason_code);
6680
6681 switch (mlme->cmd) {
6682 case IW_MLME_DEAUTH:
6683 // silently ignore
6684 break;
6685
6686 case IW_MLME_DISASSOC:
6687 ipw_disassociate(priv);
6688 break;
6689
6690 default:
6691 return -EOPNOTSUPP;
6692 }
6693 return 0;
6694}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006695
Zhu Yie43e3c12006-04-13 17:20:45 +08006696#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05006697
6698/* QoS */
6699/*
6700* get the modulation type of the current network or
6701* the card current mode
6702*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006703static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006704{
6705 u8 mode = 0;
6706
6707 if (priv->status & STATUS_ASSOCIATED) {
6708 unsigned long flags;
6709
6710 spin_lock_irqsave(&priv->ieee->lock, flags);
6711 mode = priv->assoc_network->mode;
6712 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6713 } else {
6714 mode = priv->ieee->mode;
6715 }
6716 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6717 return mode;
6718}
6719
6720/*
6721* Handle management frame beacon and probe response
6722*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006723static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6724 int active_network,
6725 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006726{
6727 u32 size = sizeof(struct ieee80211_qos_parameters);
6728
James Ketrenosafbf30a2005-08-25 00:05:33 -05006729 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006730 network->qos_data.active = network->qos_data.supported;
6731
6732 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006733 if (active_network &&
6734 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006735 network->qos_data.active = network->qos_data.supported;
6736
6737 if ((network->qos_data.active == 1) && (active_network == 1) &&
6738 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6739 (network->qos_data.old_param_count !=
6740 network->qos_data.param_count)) {
6741 network->qos_data.old_param_count =
6742 network->qos_data.param_count;
6743 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006744 IPW_DEBUG_QOS("QoS parameters change call "
6745 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006746 }
6747 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006748 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6749 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006750 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006751 else
6752 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006753 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006754
James Ketrenosb095c382005-08-24 22:04:42 -05006755 if ((network->qos_data.active == 1) && (active_network == 1)) {
6756 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6757 schedule_work(&priv->qos_activate);
6758 }
6759
6760 network->qos_data.active = 0;
6761 network->qos_data.supported = 0;
6762 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006763 if ((priv->status & STATUS_ASSOCIATED) &&
6764 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6765 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6766 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6767 !(network->flags & NETWORK_EMPTY_ESSID))
James Ketrenosb095c382005-08-24 22:04:42 -05006768 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006769 priv->assoc_network->ssid_len) &&
6770 !memcmp(network->ssid,
6771 priv->assoc_network->ssid,
6772 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006773 queue_work(priv->workqueue,
6774 &priv->merge_networks);
6775 }
James Ketrenosb095c382005-08-24 22:04:42 -05006776 }
6777
6778 return 0;
6779}
6780
6781/*
6782* This function set up the firmware to support QoS. It sends
6783* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6784*/
6785static int ipw_qos_activate(struct ipw_priv *priv,
6786 struct ieee80211_qos_data *qos_network_data)
6787{
6788 int err;
6789 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6790 struct ieee80211_qos_parameters *active_one = NULL;
6791 u32 size = sizeof(struct ieee80211_qos_parameters);
6792 u32 burst_duration;
6793 int i;
6794 u8 type;
6795
6796 type = ipw_qos_current_mode(priv);
6797
6798 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6799 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6800 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6801 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6802
6803 if (qos_network_data == NULL) {
6804 if (type == IEEE_B) {
6805 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6806 active_one = &def_parameters_CCK;
6807 } else
6808 active_one = &def_parameters_OFDM;
6809
James Ketrenosafbf30a2005-08-25 00:05:33 -05006810 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006811 burst_duration = ipw_qos_get_burst_duration(priv);
6812 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006813 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6814 (u16) burst_duration;
6815 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05006816 if (type == IEEE_B) {
6817 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6818 type);
6819 if (priv->qos_data.qos_enable == 0)
6820 active_one = &def_parameters_CCK;
6821 else
6822 active_one = priv->qos_data.def_qos_parm_CCK;
6823 } else {
6824 if (priv->qos_data.qos_enable == 0)
6825 active_one = &def_parameters_OFDM;
6826 else
6827 active_one = priv->qos_data.def_qos_parm_OFDM;
6828 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006829 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006830 } else {
6831 unsigned long flags;
6832 int active;
6833
6834 spin_lock_irqsave(&priv->ieee->lock, flags);
6835 active_one = &(qos_network_data->parameters);
6836 qos_network_data->old_param_count =
6837 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006838 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006839 active = qos_network_data->supported;
6840 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6841
6842 if (active == 0) {
6843 burst_duration = ipw_qos_get_burst_duration(priv);
6844 for (i = 0; i < QOS_QUEUE_NUM; i++)
6845 qos_parameters[QOS_PARAM_SET_ACTIVE].
6846 tx_op_limit[i] = (u16) burst_duration;
6847 }
6848 }
6849
6850 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05006851 err = ipw_send_qos_params_command(priv,
6852 (struct ieee80211_qos_parameters *)
6853 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05006854 if (err)
6855 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6856
6857 return err;
6858}
6859
6860/*
6861* send IPW_CMD_WME_INFO to the firmware
6862*/
6863static int ipw_qos_set_info_element(struct ipw_priv *priv)
6864{
6865 int ret = 0;
6866 struct ieee80211_qos_information_element qos_info;
6867
6868 if (priv == NULL)
6869 return -1;
6870
6871 qos_info.elementID = QOS_ELEMENT_ID;
6872 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6873
6874 qos_info.version = QOS_VERSION_1;
6875 qos_info.ac_info = 0;
6876
6877 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6878 qos_info.qui_type = QOS_OUI_TYPE;
6879 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6880
6881 ret = ipw_send_qos_info_command(priv, &qos_info);
6882 if (ret != 0) {
6883 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6884 }
6885 return ret;
6886}
6887
6888/*
6889* Set the QoS parameter with the association request structure
6890*/
6891static int ipw_qos_association(struct ipw_priv *priv,
6892 struct ieee80211_network *network)
6893{
6894 int err = 0;
6895 struct ieee80211_qos_data *qos_data = NULL;
6896 struct ieee80211_qos_data ibss_data = {
6897 .supported = 1,
6898 .active = 1,
6899 };
6900
6901 switch (priv->ieee->iw_mode) {
6902 case IW_MODE_ADHOC:
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02006903 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
James Ketrenosb095c382005-08-24 22:04:42 -05006904
6905 qos_data = &ibss_data;
6906 break;
6907
6908 case IW_MODE_INFRA:
6909 qos_data = &network->qos_data;
6910 break;
6911
6912 default:
6913 BUG();
6914 break;
6915 }
6916
6917 err = ipw_qos_activate(priv, qos_data);
6918 if (err) {
6919 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6920 return err;
6921 }
6922
6923 if (priv->qos_data.qos_enable && qos_data->supported) {
6924 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6925 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6926 return ipw_qos_set_info_element(priv);
6927 }
6928
6929 return 0;
6930}
6931
6932/*
6933* handling the beaconing responces. if we get different QoS setting
6934* of the network from the the associated setting adjust the QoS
6935* setting
6936*/
6937static int ipw_qos_association_resp(struct ipw_priv *priv,
6938 struct ieee80211_network *network)
6939{
6940 int ret = 0;
6941 unsigned long flags;
6942 u32 size = sizeof(struct ieee80211_qos_parameters);
6943 int set_qos_param = 0;
6944
James Ketrenosafbf30a2005-08-25 00:05:33 -05006945 if ((priv == NULL) || (network == NULL) ||
6946 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05006947 return ret;
6948
6949 if (!(priv->status & STATUS_ASSOCIATED))
6950 return ret;
6951
James Ketrenosafbf30a2005-08-25 00:05:33 -05006952 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05006953 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05006954
6955 spin_lock_irqsave(&priv->ieee->lock, flags);
6956 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006957 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
James Ketrenosb095c382005-08-24 22:04:42 -05006958 sizeof(struct ieee80211_qos_data));
6959 priv->assoc_network->qos_data.active = 1;
6960 if ((network->qos_data.old_param_count !=
6961 network->qos_data.param_count)) {
6962 set_qos_param = 1;
6963 network->qos_data.old_param_count =
6964 network->qos_data.param_count;
6965 }
6966
6967 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006968 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
6969 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006970 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006971 else
6972 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006973 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006974 priv->assoc_network->qos_data.active = 0;
6975 priv->assoc_network->qos_data.supported = 0;
6976 set_qos_param = 1;
6977 }
6978
6979 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6980
6981 if (set_qos_param == 1)
6982 schedule_work(&priv->qos_activate);
6983
6984 return ret;
6985}
6986
6987static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
6988{
6989 u32 ret = 0;
6990
6991 if ((priv == NULL))
6992 return 0;
6993
James Ketrenosafbf30a2005-08-25 00:05:33 -05006994 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05006995 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006996 else
James Ketrenosb095c382005-08-24 22:04:42 -05006997 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006998
James Ketrenosb095c382005-08-24 22:04:42 -05006999 return ret;
7000}
7001
7002/*
7003* Initialize the setting of QoS global
7004*/
7005static void ipw_qos_init(struct ipw_priv *priv, int enable,
7006 int burst_enable, u32 burst_duration_CCK,
7007 u32 burst_duration_OFDM)
7008{
7009 priv->qos_data.qos_enable = enable;
7010
7011 if (priv->qos_data.qos_enable) {
7012 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
7013 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
7014 IPW_DEBUG_QOS("QoS is enabled\n");
7015 } else {
7016 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
7017 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
7018 IPW_DEBUG_QOS("QoS is not enabled\n");
7019 }
7020
7021 priv->qos_data.burst_enable = burst_enable;
7022
7023 if (burst_enable) {
7024 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
7025 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
7026 } else {
7027 priv->qos_data.burst_duration_CCK = 0;
7028 priv->qos_data.burst_duration_OFDM = 0;
7029 }
7030}
7031
7032/*
7033* map the packet priority to the right TX Queue
7034*/
7035static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
7036{
7037 if (priority > 7 || !priv->qos_data.qos_enable)
7038 priority = 0;
7039
7040 return from_priority_to_tx_queue[priority] - 1;
7041}
7042
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007043static int ipw_is_qos_active(struct net_device *dev,
7044 struct sk_buff *skb)
James Ketrenosb095c382005-08-24 22:04:42 -05007045{
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007046 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosb095c382005-08-24 22:04:42 -05007047 struct ieee80211_qos_data *qos_data = NULL;
7048 int active, supported;
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007049 u8 *daddr = skb->data + ETH_ALEN;
7050 int unicast = !is_multicast_ether_addr(daddr);
James Ketrenosb095c382005-08-24 22:04:42 -05007051
7052 if (!(priv->status & STATUS_ASSOCIATED))
7053 return 0;
7054
7055 qos_data = &priv->assoc_network->qos_data;
7056
James Ketrenosb095c382005-08-24 22:04:42 -05007057 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7058 if (unicast == 0)
7059 qos_data->active = 0;
7060 else
7061 qos_data->active = qos_data->supported;
7062 }
James Ketrenosb095c382005-08-24 22:04:42 -05007063 active = qos_data->active;
7064 supported = qos_data->supported;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007065 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7066 "unicast %d\n",
7067 priv->qos_data.qos_enable, active, supported, unicast);
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007068 if (active && priv->qos_data.qos_enable)
7069 return 1;
James Ketrenosb095c382005-08-24 22:04:42 -05007070
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007071 return 0;
7072
7073}
7074/*
7075* add QoS parameter to the TX command
7076*/
7077static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7078 u16 priority,
7079 struct tfd_data *tfd)
7080{
7081 int tx_queue_id = 0;
7082
7083
7084 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7085 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7086
7087 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7088 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
7089 tfd->tfd.tfd_26.mchdr.qos_ctrl |= CTRL_QOS_NO_ACK;
James Ketrenosb095c382005-08-24 22:04:42 -05007090 }
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007091 return 0;
James Ketrenosb095c382005-08-24 22:04:42 -05007092}
7093
7094/*
7095* background support to run QoS activate functionality
7096*/
7097static void ipw_bg_qos_activate(void *data)
7098{
7099 struct ipw_priv *priv = data;
7100
7101 if (priv == NULL)
7102 return;
7103
Zhu Yi46441512006-01-24 16:37:59 +08007104 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007105
7106 if (priv->status & STATUS_ASSOCIATED)
7107 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7108
Zhu Yi46441512006-01-24 16:37:59 +08007109 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007110}
7111
James Ketrenos3b9990c2005-08-19 13:18:55 -05007112static int ipw_handle_probe_response(struct net_device *dev,
7113 struct ieee80211_probe_response *resp,
7114 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007115{
7116 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007117 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7118 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007119
James Ketrenos3b9990c2005-08-19 13:18:55 -05007120 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007121
James Ketrenos3b9990c2005-08-19 13:18:55 -05007122 return 0;
7123}
James Ketrenosb095c382005-08-24 22:04:42 -05007124
James Ketrenos3b9990c2005-08-19 13:18:55 -05007125static int ipw_handle_beacon(struct net_device *dev,
7126 struct ieee80211_beacon *resp,
7127 struct ieee80211_network *network)
7128{
7129 struct ipw_priv *priv = ieee80211_priv(dev);
7130 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7131 (network == priv->assoc_network));
7132
7133 ipw_qos_handle_probe_response(priv, active_network, network);
7134
7135 return 0;
7136}
7137
7138static int ipw_handle_assoc_response(struct net_device *dev,
7139 struct ieee80211_assoc_response *resp,
7140 struct ieee80211_network *network)
7141{
7142 struct ipw_priv *priv = ieee80211_priv(dev);
7143 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007144 return 0;
7145}
7146
7147static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7148 *qos_param)
7149{
Zhu Yi4e226992006-01-24 16:37:36 +08007150 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7151 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007152}
7153
7154static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7155 *qos_param)
7156{
Zhu Yi4e226992006-01-24 16:37:36 +08007157 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7158 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007159}
7160
Zhu Yie43e3c12006-04-13 17:20:45 +08007161#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -05007162
James Ketrenos43f66a62005-03-25 12:31:53 -06007163static int ipw_associate_network(struct ipw_priv *priv,
7164 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007165 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007166{
7167 int err;
7168
7169 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007170 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007171
7172 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007173 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007174 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007175 memcpy(priv->essid, network->ssid, priv->essid_len);
7176 }
7177
7178 network->last_associate = jiffies;
7179
7180 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7181 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007182 priv->assoc_request.auth_key = 0;
7183
James Ketrenos43f66a62005-03-25 12:31:53 -06007184 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007185 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007186 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007187 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7188
Zhu Yi1ba61e02006-02-15 13:00:55 +08007189 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007190 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007191
7192 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7193 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7194 priv->assoc_request.auth_type = AUTH_LEAP;
7195 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007196 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007197
James Ketrenosa613bff2005-08-24 21:43:11 -05007198 if (priv->ieee->wpa_ie_len) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007199 priv->assoc_request.policy_support = 0x02; /* RSN active */
7200 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7201 priv->ieee->wpa_ie_len);
7202 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007203
Jeff Garzikbf794512005-07-31 13:07:26 -04007204 /*
7205 * It is valid for our ieee device to support multiple modes, but
7206 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007207 * just one mode.
7208 */
7209 if (network->mode & priv->ieee->mode & IEEE_A)
7210 priv->assoc_request.ieee_mode = IPW_A_MODE;
7211 else if (network->mode & priv->ieee->mode & IEEE_G)
7212 priv->assoc_request.ieee_mode = IPW_G_MODE;
7213 else if (network->mode & priv->ieee->mode & IEEE_B)
7214 priv->assoc_request.ieee_mode = IPW_B_MODE;
7215
James Ketrenosea2b26e2005-08-24 21:25:16 -05007216 priv->assoc_request.capability = network->capability;
7217 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7218 && !(priv->config & CFG_PREAMBLE_LONG)) {
7219 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7220 } else {
7221 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7222
7223 /* Clear the short preamble if we won't be supporting it */
7224 priv->assoc_request.capability &=
7225 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7226 }
7227
James Ketrenosafbf30a2005-08-25 00:05:33 -05007228 /* Clear capability bits that aren't used in Ad Hoc */
7229 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7230 priv->assoc_request.capability &=
7231 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7232
James Ketrenos43f66a62005-03-25 12:31:53 -06007233 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007234 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007235 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04007236 escape_essid(priv->essid, priv->essid_len),
7237 network->channel,
7238 ipw_modes[priv->assoc_request.ieee_mode],
7239 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007240 (priv->assoc_request.preamble_length ==
7241 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7242 network->capability &
7243 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007244 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007245 priv->capability & CAP_PRIVACY_ON ?
7246 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007247 "(open)") : "",
7248 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007249 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007250 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007251 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007252
7253 priv->assoc_request.beacon_interval = network->beacon_interval;
7254 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007255 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007256 priv->assoc_request.assoc_type = HC_IBSS_START;
7257 priv->assoc_request.assoc_tsf_msw = 0;
7258 priv->assoc_request.assoc_tsf_lsw = 0;
7259 } else {
7260 if (unlikely(roaming))
7261 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7262 else
7263 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7264 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7265 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7266 }
7267
James Ketrenosafbf30a2005-08-25 00:05:33 -05007268 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007269
7270 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7271 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7272 priv->assoc_request.atim_window = network->atim_window;
7273 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007274 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007275 priv->assoc_request.atim_window = 0;
7276 }
7277
James Ketrenos43f66a62005-03-25 12:31:53 -06007278 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04007279
James Ketrenos43f66a62005-03-25 12:31:53 -06007280 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7281 if (err) {
7282 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7283 return err;
7284 }
7285
7286 rates->ieee_mode = priv->assoc_request.ieee_mode;
7287 rates->purpose = IPW_RATE_CONNECT;
7288 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007289
James Ketrenos43f66a62005-03-25 12:31:53 -06007290 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7291 priv->sys_config.dot11g_auto_detection = 1;
7292 else
7293 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007294
7295 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7296 priv->sys_config.answer_broadcast_ssid_probe = 1;
7297 else
7298 priv->sys_config.answer_broadcast_ssid_probe = 0;
7299
Zhu Yid685b8c2006-04-13 17:20:27 +08007300 err = ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007301 if (err) {
7302 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7303 return err;
7304 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007305
James Ketrenos43f66a62005-03-25 12:31:53 -06007306 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007307 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007308 if (err) {
7309 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7310 return err;
7311 }
7312
7313 /*
7314 * If preemption is enabled, it is possible for the association
7315 * to complete before we return from ipw_send_associate. Therefore
7316 * we have to be sure and update our priviate data first.
7317 */
7318 priv->channel = network->channel;
7319 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007320 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007321 priv->status &= ~STATUS_SECURITY_UPDATED;
7322
7323 priv->assoc_network = network;
7324
Zhu Yie43e3c12006-04-13 17:20:45 +08007325#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05007326 ipw_qos_association(priv, network);
7327#endif
7328
James Ketrenos43f66a62005-03-25 12:31:53 -06007329 err = ipw_send_associate(priv, &priv->assoc_request);
7330 if (err) {
7331 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7332 return err;
7333 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007334
7335 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007336 escape_essid(priv->essid, priv->essid_len),
7337 MAC_ARG(priv->bssid));
7338
7339 return 0;
7340}
7341
7342static void ipw_roam(void *data)
7343{
7344 struct ipw_priv *priv = data;
7345 struct ieee80211_network *network = NULL;
7346 struct ipw_network_match match = {
7347 .network = priv->assoc_network
7348 };
7349
7350 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007351 *
7352 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007353 * setting the status ROAM bit and requesting a scan.
7354 * 2. When the scan completes, it schedules the ROAM work
7355 * 3. The ROAM work looks at all of the known networks for one that
7356 * is a better network than the currently associated. If none
7357 * found, the ROAM process is over (ROAM bit cleared)
7358 * 4. If a better network is found, a disassociation request is
7359 * sent.
7360 * 5. When the disassociation completes, the roam work is again
7361 * scheduled. The second time through, the driver is no longer
7362 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007363 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007364 * 6. At this point ,the roaming process is complete and the ROAM
7365 * status bit is cleared.
7366 */
7367
7368 /* If we are no longer associated, and the roaming bit is no longer
7369 * set, then we are not actively roaming, so just return */
7370 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7371 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007372
James Ketrenos43f66a62005-03-25 12:31:53 -06007373 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007374 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007375 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007376 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007377 u8 rssi = priv->assoc_network->stats.rssi;
7378 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007379 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007380 list_for_each_entry(network, &priv->ieee->network_list, list) {
7381 if (network != priv->assoc_network)
7382 ipw_best_network(priv, &match, network, 1);
7383 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007384 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007385 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007386
James Ketrenos43f66a62005-03-25 12:31:53 -06007387 if (match.network == priv->assoc_network) {
7388 IPW_DEBUG_ASSOC("No better APs in this network to "
7389 "roam to.\n");
7390 priv->status &= ~STATUS_ROAMING;
7391 ipw_debug_config(priv);
7392 return;
7393 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007394
James Ketrenos43f66a62005-03-25 12:31:53 -06007395 ipw_send_disassociate(priv, 1);
7396 priv->assoc_network = match.network;
7397
7398 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007399 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007400
7401 /* Second pass through ROAM process -- request association */
7402 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7403 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7404 priv->status &= ~STATUS_ROAMING;
7405}
7406
James Ketrenosc848d0a2005-08-24 21:56:24 -05007407static void ipw_bg_roam(void *data)
7408{
7409 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08007410 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007411 ipw_roam(data);
Zhu Yi46441512006-01-24 16:37:59 +08007412 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007413}
7414
7415static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007416{
7417 struct ipw_priv *priv = data;
7418
7419 struct ieee80211_network *network = NULL;
7420 struct ipw_network_match match = {
7421 .network = NULL
7422 };
7423 struct ipw_supported_rates *rates;
7424 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007425 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007426
James Ketrenosb095c382005-08-24 22:04:42 -05007427 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7428 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7429 return 0;
7430 }
7431
James Ketrenosc848d0a2005-08-24 21:56:24 -05007432 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007433 IPW_DEBUG_ASSOC("Not attempting association (already in "
7434 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007435 return 0;
7436 }
7437
Hong Liue6324722005-09-14 21:04:15 -05007438 if (priv->status & STATUS_DISASSOCIATING) {
7439 IPW_DEBUG_ASSOC("Not attempting association (in "
7440 "disassociating)\n ");
7441 queue_work(priv->workqueue, &priv->associate);
7442 return 0;
7443 }
7444
James Ketrenosc848d0a2005-08-24 21:56:24 -05007445 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007446 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7447 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007448 return 0;
7449 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007450
7451 if (!(priv->config & CFG_ASSOCIATE) &&
7452 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007453 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007454 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007455 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007456 }
7457
James Ketrenosa613bff2005-08-24 21:43:11 -05007458 /* Protect our use of the network_list */
7459 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007460 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007461 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007462
7463 network = match.network;
7464 rates = &match.rates;
7465
7466 if (network == NULL &&
7467 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7468 priv->config & CFG_ADHOC_CREATE &&
7469 priv->config & CFG_STATIC_ESSID &&
James Ketrenosa613bff2005-08-24 21:43:11 -05007470 priv->config & CFG_STATIC_CHANNEL &&
James Ketrenos43f66a62005-03-25 12:31:53 -06007471 !list_empty(&priv->ieee->network_free_list)) {
7472 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007473 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007474 ipw_adhoc_create(priv, network);
7475 rates = &priv->rates;
7476 list_del(element);
7477 list_add_tail(&network->list, &priv->ieee->network_list);
7478 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007479 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007480
James Ketrenos43f66a62005-03-25 12:31:53 -06007481 /* If we reached the end of the list, then we don't have any valid
7482 * matching APs */
7483 if (!network) {
7484 ipw_debug_config(priv);
7485
James Ketrenosb095c382005-08-24 22:04:42 -05007486 if (!(priv->status & STATUS_SCANNING)) {
7487 if (!(priv->config & CFG_SPEED_SCAN))
7488 queue_delayed_work(priv->workqueue,
7489 &priv->request_scan,
7490 SCAN_INTERVAL);
7491 else
7492 queue_work(priv->workqueue,
7493 &priv->request_scan);
7494 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007495
James Ketrenosc848d0a2005-08-24 21:56:24 -05007496 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007497 }
7498
7499 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007500
7501 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007502}
Jeff Garzikbf794512005-07-31 13:07:26 -04007503
James Ketrenosc848d0a2005-08-24 21:56:24 -05007504static void ipw_bg_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007505{
James Ketrenosc848d0a2005-08-24 21:56:24 -05007506 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08007507 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007508 ipw_associate(data);
Zhu Yi46441512006-01-24 16:37:59 +08007509 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007510}
7511
James Ketrenosb095c382005-08-24 22:04:42 -05007512static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7513 struct sk_buff *skb)
7514{
7515 struct ieee80211_hdr *hdr;
7516 u16 fc;
7517
7518 hdr = (struct ieee80211_hdr *)skb->data;
7519 fc = le16_to_cpu(hdr->frame_ctl);
7520 if (!(fc & IEEE80211_FCTL_PROTECTED))
7521 return;
7522
7523 fc &= ~IEEE80211_FCTL_PROTECTED;
7524 hdr->frame_ctl = cpu_to_le16(fc);
7525 switch (priv->ieee->sec.level) {
7526 case SEC_LEVEL_3:
7527 /* Remove CCMP HDR */
7528 memmove(skb->data + IEEE80211_3ADDR_LEN,
7529 skb->data + IEEE80211_3ADDR_LEN + 8,
7530 skb->len - IEEE80211_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007531 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007532 break;
7533 case SEC_LEVEL_2:
7534 break;
7535 case SEC_LEVEL_1:
7536 /* Remove IV */
7537 memmove(skb->data + IEEE80211_3ADDR_LEN,
7538 skb->data + IEEE80211_3ADDR_LEN + 4,
7539 skb->len - IEEE80211_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007540 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007541 break;
7542 case SEC_LEVEL_0:
7543 break;
7544 default:
7545 printk(KERN_ERR "Unknow security level %d\n",
7546 priv->ieee->sec.level);
7547 break;
7548 }
7549}
7550
7551static void ipw_handle_data_packet(struct ipw_priv *priv,
7552 struct ipw_rx_mem_buffer *rxb,
7553 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007554{
Hong Liu567deaf2005-08-31 18:07:22 +08007555 struct ieee80211_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007556 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7557
7558 /* We received data from the HW, so stop the watchdog */
7559 priv->net_dev->trans_start = jiffies;
7560
Jeff Garzikbf794512005-07-31 13:07:26 -04007561 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007562 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007563 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007564 skb_tailroom(rxb->skb))) {
7565 priv->ieee->stats.rx_errors++;
7566 priv->wstats.discard.misc++;
7567 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7568 return;
7569 } else if (unlikely(!netif_running(priv->net_dev))) {
7570 priv->ieee->stats.rx_dropped++;
7571 priv->wstats.discard.misc++;
7572 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7573 return;
7574 }
7575
7576 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007577 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007578
7579 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007580 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007581
7582 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7583
James Ketrenosb095c382005-08-24 22:04:42 -05007584 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
Hong Liu567deaf2005-08-31 18:07:22 +08007585 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7586 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007587 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007588 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007589 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7590
Jeff Garzikbf794512005-07-31 13:07:26 -04007591 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06007592 priv->ieee->stats.rx_errors++;
James Ketrenosa613bff2005-08-24 21:43:11 -05007593 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007594 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007595 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007596 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007597}
7598
Zhu Yi459d4082006-04-13 17:21:00 +08007599#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05007600static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7601 struct ipw_rx_mem_buffer *rxb,
7602 struct ieee80211_rx_stats *stats)
7603{
7604 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7605 struct ipw_rx_frame *frame = &pkt->u.frame;
7606
7607 /* initial pull of some data */
7608 u16 received_channel = frame->received_channel;
7609 u8 antennaAndPhy = frame->antennaAndPhy;
7610 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7611 u16 pktrate = frame->rate;
7612
7613 /* Magic struct that slots into the radiotap header -- no reason
7614 * to build this manually element by element, we can write it much
7615 * more efficiently than we can parse it. ORDER MATTERS HERE */
Zhu Yid685b8c2006-04-13 17:20:27 +08007616 struct ipw_rt_hdr *ipw_rt;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007617
7618 short len = le16_to_cpu(pkt->u.frame.length);
7619
7620 /* We received data from the HW, so stop the watchdog */
7621 priv->net_dev->trans_start = jiffies;
7622
7623 /* We only process data packets if the
7624 * interface is open */
7625 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7626 skb_tailroom(rxb->skb))) {
7627 priv->ieee->stats.rx_errors++;
7628 priv->wstats.discard.misc++;
7629 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7630 return;
7631 } else if (unlikely(!netif_running(priv->net_dev))) {
7632 priv->ieee->stats.rx_dropped++;
7633 priv->wstats.discard.misc++;
7634 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7635 return;
7636 }
7637
7638 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7639 * that now */
7640 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7641 /* FIXME: Should alloc bigger skb instead */
7642 priv->ieee->stats.rx_dropped++;
7643 priv->wstats.discard.misc++;
7644 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7645 return;
7646 }
7647
7648 /* copy the frame itself */
7649 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7650 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7651
7652 /* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7653 * part of our real header, saves a little time.
7654 *
7655 * No longer necessary since we fill in all our data. Purge before merging
7656 * patch officially.
7657 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7658 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7659 */
7660
7661 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7662
7663 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7664 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7665 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7666
7667 /* Big bitfield of all the fields we provide in radiotap */
7668 ipw_rt->rt_hdr.it_present =
7669 ((1 << IEEE80211_RADIOTAP_FLAGS) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007670 (1 << IEEE80211_RADIOTAP_TSFT) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007671 (1 << IEEE80211_RADIOTAP_RATE) |
7672 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7673 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007674 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007675 (1 << IEEE80211_RADIOTAP_ANTENNA));
7676
7677 /* Zero the flags, we'll add to them as we go */
7678 ipw_rt->rt_flags = 0;
7679
7680 /* Convert signal to DBM */
7681 ipw_rt->rt_dbmsignal = antsignal;
7682
7683 /* Convert the channel data and set the flags */
7684 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7685 if (received_channel > 14) { /* 802.11a */
7686 ipw_rt->rt_chbitmask =
7687 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7688 } else if (antennaAndPhy & 32) { /* 802.11b */
7689 ipw_rt->rt_chbitmask =
7690 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7691 } else { /* 802.11g */
7692 ipw_rt->rt_chbitmask =
7693 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7694 }
7695
7696 /* set the rate in multiples of 500k/s */
7697 switch (pktrate) {
7698 case IPW_TX_RATE_1MB:
7699 ipw_rt->rt_rate = 2;
7700 break;
7701 case IPW_TX_RATE_2MB:
7702 ipw_rt->rt_rate = 4;
7703 break;
7704 case IPW_TX_RATE_5MB:
7705 ipw_rt->rt_rate = 10;
7706 break;
7707 case IPW_TX_RATE_6MB:
7708 ipw_rt->rt_rate = 12;
7709 break;
7710 case IPW_TX_RATE_9MB:
7711 ipw_rt->rt_rate = 18;
7712 break;
7713 case IPW_TX_RATE_11MB:
7714 ipw_rt->rt_rate = 22;
7715 break;
7716 case IPW_TX_RATE_12MB:
7717 ipw_rt->rt_rate = 24;
7718 break;
7719 case IPW_TX_RATE_18MB:
7720 ipw_rt->rt_rate = 36;
7721 break;
7722 case IPW_TX_RATE_24MB:
7723 ipw_rt->rt_rate = 48;
7724 break;
7725 case IPW_TX_RATE_36MB:
7726 ipw_rt->rt_rate = 72;
7727 break;
7728 case IPW_TX_RATE_48MB:
7729 ipw_rt->rt_rate = 96;
7730 break;
7731 case IPW_TX_RATE_54MB:
7732 ipw_rt->rt_rate = 108;
7733 break;
7734 default:
7735 ipw_rt->rt_rate = 0;
7736 break;
7737 }
7738
7739 /* antenna number */
7740 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7741
7742 /* set the preamble flag if we have it */
7743 if ((antennaAndPhy & 64))
7744 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7745
7746 /* Set the size of the skb to the size of the frame */
7747 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007748
7749 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7750
7751 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7752 priv->ieee->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007753 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007754 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007755 /* no LED during capture */
7756 }
7757}
7758#endif
7759
Zhu Yid685b8c2006-04-13 17:20:27 +08007760#ifdef CONFIG_IPW2200_PROMISCUOUS
7761#define ieee80211_is_probe_response(fc) \
7762 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7763 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7764
7765#define ieee80211_is_management(fc) \
7766 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7767
7768#define ieee80211_is_control(fc) \
7769 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7770
7771#define ieee80211_is_data(fc) \
7772 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
7773
7774#define ieee80211_is_assoc_request(fc) \
7775 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
7776
7777#define ieee80211_is_reassoc_request(fc) \
7778 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
7779
7780static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
7781 struct ipw_rx_mem_buffer *rxb,
7782 struct ieee80211_rx_stats *stats)
7783{
7784 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7785 struct ipw_rx_frame *frame = &pkt->u.frame;
7786 struct ipw_rt_hdr *ipw_rt;
7787
7788 /* First cache any information we need before we overwrite
7789 * the information provided in the skb from the hardware */
7790 struct ieee80211_hdr *hdr;
7791 u16 channel = frame->received_channel;
7792 u8 phy_flags = frame->antennaAndPhy;
7793 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
7794 s8 noise = frame->noise;
7795 u8 rate = frame->rate;
7796 short len = le16_to_cpu(pkt->u.frame.length);
7797 u64 tsf = 0;
7798 struct sk_buff *skb;
7799 int hdr_only = 0;
7800 u16 filter = priv->prom_priv->filter;
7801
7802 /* If the filter is set to not include Rx frames then return */
7803 if (filter & IPW_PROM_NO_RX)
7804 return;
7805
Zhu Yid685b8c2006-04-13 17:20:27 +08007806 /* We received data from the HW, so stop the watchdog */
7807 priv->prom_net_dev->trans_start = jiffies;
7808
7809 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
7810 priv->prom_priv->ieee->stats.rx_errors++;
7811 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7812 return;
7813 }
7814
7815 /* We only process data packets if the interface is open */
7816 if (unlikely(!netif_running(priv->prom_net_dev))) {
7817 priv->prom_priv->ieee->stats.rx_dropped++;
7818 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7819 return;
7820 }
7821
7822 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7823 * that now */
7824 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7825 /* FIXME: Should alloc bigger skb instead */
7826 priv->prom_priv->ieee->stats.rx_dropped++;
7827 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7828 return;
7829 }
7830
7831 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
7832 if (ieee80211_is_management(hdr->frame_ctl)) {
7833 if (filter & IPW_PROM_NO_MGMT)
7834 return;
7835 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
7836 hdr_only = 1;
7837 } else if (ieee80211_is_control(hdr->frame_ctl)) {
7838 if (filter & IPW_PROM_NO_CTL)
7839 return;
7840 if (filter & IPW_PROM_CTL_HEADER_ONLY)
7841 hdr_only = 1;
7842 } else if (ieee80211_is_data(hdr->frame_ctl)) {
7843 if (filter & IPW_PROM_NO_DATA)
7844 return;
7845 if (filter & IPW_PROM_DATA_HEADER_ONLY)
7846 hdr_only = 1;
7847 }
7848
7849 /* Copy the SKB since this is for the promiscuous side */
7850 skb = skb_copy(rxb->skb, GFP_ATOMIC);
7851 if (skb == NULL) {
7852 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
7853 return;
7854 }
7855
7856 /* copy the frame data to write after where the radiotap header goes */
7857 ipw_rt = (void *)skb->data;
7858
7859 if (hdr_only)
7860 len = ieee80211_get_hdrlen(hdr->frame_ctl);
7861
7862 memcpy(ipw_rt->payload, hdr, len);
7863
7864 /* Zero the radiotap static buffer ... We only need to zero the bytes
7865 * NOT part of our real header, saves a little time.
7866 *
7867 * No longer necessary since we fill in all our data. Purge before
7868 * merging patch officially.
7869 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7870 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7871 */
7872
7873 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7874 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7875 ipw_rt->rt_hdr.it_len = sizeof(*ipw_rt); /* total header+data */
7876
7877 /* Set the size of the skb to the size of the frame */
7878 skb_put(skb, ipw_rt->rt_hdr.it_len + len);
7879
7880 /* Big bitfield of all the fields we provide in radiotap */
7881 ipw_rt->rt_hdr.it_present =
7882 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7883 (1 << IEEE80211_RADIOTAP_TSFT) |
7884 (1 << IEEE80211_RADIOTAP_RATE) |
7885 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7886 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7887 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
7888 (1 << IEEE80211_RADIOTAP_ANTENNA));
7889
7890 /* Zero the flags, we'll add to them as we go */
7891 ipw_rt->rt_flags = 0;
7892
7893 ipw_rt->rt_tsf = tsf;
7894
7895 /* Convert to DBM */
7896 ipw_rt->rt_dbmsignal = signal;
7897 ipw_rt->rt_dbmnoise = noise;
7898
7899 /* Convert the channel data and set the flags */
7900 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
7901 if (channel > 14) { /* 802.11a */
7902 ipw_rt->rt_chbitmask =
7903 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7904 } else if (phy_flags & (1 << 5)) { /* 802.11b */
7905 ipw_rt->rt_chbitmask =
7906 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7907 } else { /* 802.11g */
7908 ipw_rt->rt_chbitmask =
7909 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7910 }
7911
7912 /* set the rate in multiples of 500k/s */
7913 switch (rate) {
7914 case IPW_TX_RATE_1MB:
7915 ipw_rt->rt_rate = 2;
7916 break;
7917 case IPW_TX_RATE_2MB:
7918 ipw_rt->rt_rate = 4;
7919 break;
7920 case IPW_TX_RATE_5MB:
7921 ipw_rt->rt_rate = 10;
7922 break;
7923 case IPW_TX_RATE_6MB:
7924 ipw_rt->rt_rate = 12;
7925 break;
7926 case IPW_TX_RATE_9MB:
7927 ipw_rt->rt_rate = 18;
7928 break;
7929 case IPW_TX_RATE_11MB:
7930 ipw_rt->rt_rate = 22;
7931 break;
7932 case IPW_TX_RATE_12MB:
7933 ipw_rt->rt_rate = 24;
7934 break;
7935 case IPW_TX_RATE_18MB:
7936 ipw_rt->rt_rate = 36;
7937 break;
7938 case IPW_TX_RATE_24MB:
7939 ipw_rt->rt_rate = 48;
7940 break;
7941 case IPW_TX_RATE_36MB:
7942 ipw_rt->rt_rate = 72;
7943 break;
7944 case IPW_TX_RATE_48MB:
7945 ipw_rt->rt_rate = 96;
7946 break;
7947 case IPW_TX_RATE_54MB:
7948 ipw_rt->rt_rate = 108;
7949 break;
7950 default:
7951 ipw_rt->rt_rate = 0;
7952 break;
7953 }
7954
7955 /* antenna number */
7956 ipw_rt->rt_antenna = (phy_flags & 3);
7957
7958 /* set the preamble flag if we have it */
7959 if (phy_flags & (1 << 6))
7960 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7961
7962 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
7963
7964 if (!ieee80211_rx(priv->prom_priv->ieee, skb, stats)) {
7965 priv->prom_priv->ieee->stats.rx_errors++;
7966 dev_kfree_skb_any(skb);
7967 }
7968}
7969#endif
7970
Arjan van de Ven858119e2006-01-14 13:20:43 -08007971static int is_network_packet(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007972 struct ieee80211_hdr_4addr *header)
7973{
7974 /* Filter incoming packets to determine if they are targetted toward
7975 * this network, discarding packets coming from ourselves */
7976 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05007977 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007978 /* packets from our adapter are dropped (echo) */
7979 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7980 return 0;
7981
Peter Jones90700fd2005-08-26 16:51:06 -05007982 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007983 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05007984 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007985
7986 /* packets to our adapter go through */
7987 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7988 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007989
Peter Jones90700fd2005-08-26 16:51:06 -05007990 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007991 /* packets from our adapter are dropped (echo) */
7992 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7993 return 0;
7994
Peter Jones90700fd2005-08-26 16:51:06 -05007995 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007996 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05007997 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7998
7999 /* packets to our adapter go through */
8000 return !memcmp(header->addr1, priv->net_dev->dev_addr,
8001 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008002 }
James Ketrenosa613bff2005-08-24 21:43:11 -05008003
James Ketrenosea2b26e2005-08-24 21:25:16 -05008004 return 1;
8005}
8006
James Ketrenosafbf30a2005-08-25 00:05:33 -05008007#define IPW_PACKET_RETRY_TIME HZ
8008
Arjan van de Ven858119e2006-01-14 13:20:43 -08008009static int is_duplicate_packet(struct ipw_priv *priv,
James Ketrenosafbf30a2005-08-25 00:05:33 -05008010 struct ieee80211_hdr_4addr *header)
8011{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008012 u16 sc = le16_to_cpu(header->seq_ctl);
8013 u16 seq = WLAN_GET_SEQ_SEQ(sc);
8014 u16 frag = WLAN_GET_SEQ_FRAG(sc);
8015 u16 *last_seq, *last_frag;
8016 unsigned long *last_time;
8017
8018 switch (priv->ieee->iw_mode) {
8019 case IW_MODE_ADHOC:
8020 {
8021 struct list_head *p;
8022 struct ipw_ibss_seq *entry = NULL;
8023 u8 *mac = header->addr2;
8024 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8025
8026 __list_for_each(p, &priv->ibss_mac_hash[index]) {
8027 entry =
8028 list_entry(p, struct ipw_ibss_seq, list);
8029 if (!memcmp(entry->mac, mac, ETH_ALEN))
8030 break;
8031 }
8032 if (p == &priv->ibss_mac_hash[index]) {
8033 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
8034 if (!entry) {
8035 IPW_ERROR
8036 ("Cannot malloc new mac entry\n");
8037 return 0;
8038 }
8039 memcpy(entry->mac, mac, ETH_ALEN);
8040 entry->seq_num = seq;
8041 entry->frag_num = frag;
8042 entry->packet_time = jiffies;
8043 list_add(&entry->list,
8044 &priv->ibss_mac_hash[index]);
8045 return 0;
8046 }
8047 last_seq = &entry->seq_num;
8048 last_frag = &entry->frag_num;
8049 last_time = &entry->packet_time;
8050 break;
8051 }
8052 case IW_MODE_INFRA:
8053 last_seq = &priv->last_seq_num;
8054 last_frag = &priv->last_frag_num;
8055 last_time = &priv->last_packet_time;
8056 break;
8057 default:
8058 return 0;
8059 }
8060 if ((*last_seq == seq) &&
8061 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8062 if (*last_frag == frag)
8063 goto drop;
8064 if (*last_frag + 1 != frag)
8065 /* out-of-order fragment */
8066 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008067 } else
8068 *last_seq = seq;
8069
Zhu Yif57ce7c2005-07-13 12:22:15 -05008070 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008071 *last_time = jiffies;
8072 return 0;
8073
8074 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08008075 /* Comment this line now since we observed the card receives
8076 * duplicate packets but the FCTL_RETRY bit is not set in the
8077 * IBSS mode with fragmentation enabled.
8078 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008079 return 1;
8080}
8081
James Ketrenosb095c382005-08-24 22:04:42 -05008082static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8083 struct ipw_rx_mem_buffer *rxb,
8084 struct ieee80211_rx_stats *stats)
8085{
8086 struct sk_buff *skb = rxb->skb;
8087 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
8088 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
8089 (skb->data + IPW_RX_FRAME_SIZE);
8090
8091 ieee80211_rx_mgt(priv->ieee, header, stats);
8092
8093 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8094 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8095 IEEE80211_STYPE_PROBE_RESP) ||
8096 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8097 IEEE80211_STYPE_BEACON))) {
8098 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8099 ipw_add_station(priv, header->addr2);
8100 }
8101
8102 if (priv->config & CFG_NET_STATS) {
8103 IPW_DEBUG_HC("sending stat packet\n");
8104
8105 /* Set the size of the skb to the size of the full
8106 * ipw header and 802.11 frame */
8107 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8108 IPW_RX_FRAME_SIZE);
8109
8110 /* Advance past the ipw packet header to the 802.11 frame */
8111 skb_pull(skb, IPW_RX_FRAME_SIZE);
8112
8113 /* Push the ieee80211_rx_stats before the 802.11 frame */
8114 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8115
8116 skb->dev = priv->ieee->dev;
8117
8118 /* Point raw at the ieee80211_stats */
8119 skb->mac.raw = skb->data;
8120
8121 skb->pkt_type = PACKET_OTHERHOST;
8122 skb->protocol = __constant_htons(ETH_P_80211_STATS);
8123 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8124 netif_rx(skb);
8125 rxb->skb = NULL;
8126 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008127}
8128
James Ketrenos43f66a62005-03-25 12:31:53 -06008129/*
8130 * Main entry function for recieving a packet with 80211 headers. This
8131 * should be called when ever the FW has notified us that there is a new
8132 * skb in the recieve queue.
8133 */
8134static void ipw_rx(struct ipw_priv *priv)
8135{
8136 struct ipw_rx_mem_buffer *rxb;
8137 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05008138 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06008139 u32 r, w, i;
8140 u8 network_packet;
8141
James Ketrenosb095c382005-08-24 22:04:42 -05008142 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8143 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
James Ketrenos43f66a62005-03-25 12:31:53 -06008144 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
8145
8146 while (i != r) {
8147 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06008148 if (unlikely(rxb == NULL)) {
8149 printk(KERN_CRIT "Queue not allocated!\n");
8150 break;
8151 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008152 priv->rxq->queue[i] = NULL;
8153
8154 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008155 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06008156 PCI_DMA_FROMDEVICE);
8157
8158 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8159 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8160 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008161 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008162
8163 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008164 case RX_FRAME_TYPE: /* 802.11 frame */ {
8165 struct ieee80211_rx_stats stats = {
James Ketrenosc848d0a2005-08-24 21:56:24 -05008166 .rssi =
8167 le16_to_cpu(pkt->u.frame.rssi_dbm) -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008168 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008169 .signal =
Bill Mossb1916082006-02-15 08:50:18 +08008170 le16_to_cpu(pkt->u.frame.rssi_dbm) -
8171 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008172 .noise =
8173 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008174 .rate = pkt->u.frame.rate,
8175 .mac_time = jiffies,
8176 .received_channel =
8177 pkt->u.frame.received_channel,
8178 .freq =
8179 (pkt->u.frame.
8180 control & (1 << 0)) ?
8181 IEEE80211_24GHZ_BAND :
8182 IEEE80211_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008183 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008184 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008185
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008186 if (stats.rssi != 0)
8187 stats.mask |= IEEE80211_STATMASK_RSSI;
8188 if (stats.signal != 0)
8189 stats.mask |= IEEE80211_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008190 if (stats.noise != 0)
8191 stats.mask |= IEEE80211_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008192 if (stats.rate != 0)
8193 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008194
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008195 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008196
Zhu Yid685b8c2006-04-13 17:20:27 +08008197#ifdef CONFIG_IPW2200_PROMISCUOUS
8198 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8199 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8200#endif
8201
James Ketrenosb095c382005-08-24 22:04:42 -05008202#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008203 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08008204#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yid685b8c2006-04-13 17:20:27 +08008205
8206 ipw_handle_data_packet_monitor(priv,
8207 rxb,
8208 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008209#else
Zhu Yid685b8c2006-04-13 17:20:27 +08008210 ipw_handle_data_packet(priv, rxb,
8211 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008212#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008213 break;
8214 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008215#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008216
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008217 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05008218 (struct ieee80211_hdr_4addr *)(rxb->skb->
8219 data +
8220 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008221 /* TODO: Check Ad-Hoc dest/source and make sure
8222 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008223 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008224 * frame control of the packet and disregard
8225 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008226
James Ketrenosea2b26e2005-08-24 21:25:16 -05008227 network_packet =
8228 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008229 if (network_packet && priv->assoc_network) {
8230 priv->assoc_network->stats.rssi =
8231 stats.rssi;
Zhu Yi00d21de2006-04-13 17:19:02 +08008232 priv->exp_avg_rssi =
8233 exponential_average(priv->exp_avg_rssi,
8234 stats.rssi, DEPTH_RSSI);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008235 }
8236
8237 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008238 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008239
James Ketrenosa613bff2005-08-24 21:43:11 -05008240 if (le16_to_cpu(pkt->u.frame.length) <
Zhu Yi9d0be032006-02-15 06:18:19 +08008241 ieee80211_get_hdrlen(le16_to_cpu(
8242 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008243 IPW_DEBUG_DROP
8244 ("Received packet is too small. "
8245 "Dropping.\n");
8246 priv->ieee->stats.rx_errors++;
8247 priv->wstats.discard.misc++;
8248 break;
8249 }
8250
James Ketrenosa613bff2005-08-24 21:43:11 -05008251 switch (WLAN_FC_GET_TYPE
8252 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008253
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008254 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008255 ipw_handle_mgmt_packet(priv, rxb,
8256 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008257 break;
8258
8259 case IEEE80211_FTYPE_CTL:
8260 break;
8261
8262 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008263 if (unlikely(!network_packet ||
8264 is_duplicate_packet(priv,
8265 header)))
8266 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008267 IPW_DEBUG_DROP("Dropping: "
8268 MAC_FMT ", "
8269 MAC_FMT ", "
8270 MAC_FMT "\n",
8271 MAC_ARG(header->
8272 addr1),
8273 MAC_ARG(header->
8274 addr2),
8275 MAC_ARG(header->
8276 addr3));
James Ketrenosb095c382005-08-24 22:04:42 -05008277 break;
8278 }
8279
8280 ipw_handle_data_packet(priv, rxb,
8281 &stats);
8282
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008283 break;
8284 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008285 break;
8286 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008287
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008288 case RX_HOST_NOTIFICATION_TYPE:{
8289 IPW_DEBUG_RX
8290 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008291 pkt->u.notification.subtype,
8292 pkt->u.notification.flags,
8293 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008294 ipw_rx_notification(priv, &pkt->u.notification);
8295 break;
8296 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008297
8298 default:
8299 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8300 pkt->header.message_type);
8301 break;
8302 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008303
8304 /* For now we just don't re-use anything. We can tweak this
8305 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008306 * fail to Rx correctly */
8307 if (rxb->skb != NULL) {
8308 dev_kfree_skb_any(rxb->skb);
8309 rxb->skb = NULL;
8310 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008311
James Ketrenos43f66a62005-03-25 12:31:53 -06008312 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008313 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008314 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008315
James Ketrenos43f66a62005-03-25 12:31:53 -06008316 i = (i + 1) % RX_QUEUE_SIZE;
8317 }
8318
8319 /* Backtrack one entry */
8320 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
8321
8322 ipw_rx_queue_restock(priv);
8323}
8324
James Ketrenosafbf30a2005-08-25 00:05:33 -05008325#define DEFAULT_RTS_THRESHOLD 2304U
8326#define MIN_RTS_THRESHOLD 1U
8327#define MAX_RTS_THRESHOLD 2304U
8328#define DEFAULT_BEACON_INTERVAL 100U
8329#define DEFAULT_SHORT_RETRY_LIMIT 7U
8330#define DEFAULT_LONG_RETRY_LIMIT 4U
8331
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008332/**
8333 * ipw_sw_reset
8334 * @option: options to control different reset behaviour
8335 * 0 = reset everything except the 'disable' module_param
8336 * 1 = reset everything and print out driver info (for probe only)
8337 * 2 = reset everything
8338 */
8339static int ipw_sw_reset(struct ipw_priv *priv, int option)
James Ketrenos43f66a62005-03-25 12:31:53 -06008340{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008341 int band, modulation;
8342 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008343
James Ketrenosafbf30a2005-08-25 00:05:33 -05008344 /* Initialize module parameter values here */
8345 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008346
James Ketrenosafbf30a2005-08-25 00:05:33 -05008347 /* We default to disabling the LED code as right now it causes
8348 * too many systems to lock up... */
8349 if (!led)
8350 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008351
James Ketrenosafbf30a2005-08-25 00:05:33 -05008352 if (associate)
8353 priv->config |= CFG_ASSOCIATE;
8354 else
8355 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008356
James Ketrenosafbf30a2005-08-25 00:05:33 -05008357 if (auto_create)
8358 priv->config |= CFG_ADHOC_CREATE;
8359 else
8360 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8361
Zhu Yi17ed0812006-01-24 16:36:31 +08008362 priv->config &= ~CFG_STATIC_ESSID;
8363 priv->essid_len = 0;
8364 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8365
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008366 if (disable && option) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008367 priv->status |= STATUS_RF_KILL_SW;
8368 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008369 }
8370
James Ketrenosafbf30a2005-08-25 00:05:33 -05008371 if (channel != 0) {
8372 priv->config |= CFG_STATIC_CHANNEL;
8373 priv->channel = channel;
8374 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8375 /* TODO: Validate that provided channel is in range */
8376 }
Zhu Yie43e3c12006-04-13 17:20:45 +08008377#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05008378 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8379 burst_duration_CCK, burst_duration_OFDM);
Zhu Yie43e3c12006-04-13 17:20:45 +08008380#endif /* CONFIG_IPW2200_QOS */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008381
8382 switch (mode) {
8383 case 1:
8384 priv->ieee->iw_mode = IW_MODE_ADHOC;
8385 priv->net_dev->type = ARPHRD_ETHER;
8386
8387 break;
8388#ifdef CONFIG_IPW2200_MONITOR
8389 case 2:
8390 priv->ieee->iw_mode = IW_MODE_MONITOR;
Zhu Yi459d4082006-04-13 17:21:00 +08008391#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008392 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8393#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008394 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008395#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008396 break;
8397#endif
8398 default:
8399 case 0:
8400 priv->net_dev->type = ARPHRD_ETHER;
8401 priv->ieee->iw_mode = IW_MODE_INFRA;
8402 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008403 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008404
James Ketrenosafbf30a2005-08-25 00:05:33 -05008405 if (hwcrypto) {
8406 priv->ieee->host_encrypt = 0;
8407 priv->ieee->host_encrypt_msdu = 0;
8408 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008409 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008410 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008411 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008412
Zhu Yie402c932005-08-05 17:20:40 +08008413 /* IPW2200/2915 is abled to do hardware fragmentation. */
8414 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008415
James Ketrenosafbf30a2005-08-25 00:05:33 -05008416 if ((priv->pci_dev->device == 0x4223) ||
8417 (priv->pci_dev->device == 0x4224)) {
Zhu Yie8c69e22006-02-17 08:25:12 +08008418 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008419 printk(KERN_INFO DRV_NAME
8420 ": Detected Intel PRO/Wireless 2915ABG Network "
8421 "Connection\n");
8422 priv->ieee->abg_true = 1;
8423 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8424 modulation = IEEE80211_OFDM_MODULATION |
8425 IEEE80211_CCK_MODULATION;
8426 priv->adapter = IPW_2915ABG;
8427 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008428 } else {
Zhu Yie8c69e22006-02-17 08:25:12 +08008429 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008430 printk(KERN_INFO DRV_NAME
8431 ": Detected Intel PRO/Wireless 2200BG Network "
8432 "Connection\n");
8433
8434 priv->ieee->abg_true = 0;
8435 band = IEEE80211_24GHZ_BAND;
8436 modulation = IEEE80211_OFDM_MODULATION |
8437 IEEE80211_CCK_MODULATION;
8438 priv->adapter = IPW_2200BG;
8439 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008440 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008441
James Ketrenosafbf30a2005-08-25 00:05:33 -05008442 priv->ieee->freq_band = band;
8443 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008444
James Ketrenosafbf30a2005-08-25 00:05:33 -05008445 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008446
James Ketrenosafbf30a2005-08-25 00:05:33 -05008447 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8448 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008449
James Ketrenosafbf30a2005-08-25 00:05:33 -05008450 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8451 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8452 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008453
James Ketrenosafbf30a2005-08-25 00:05:33 -05008454 /* If power management is turned on, default to AC mode */
8455 priv->power_mode = IPW_POWER_AC;
8456 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008457
Zhu Yi0ece35b2005-08-05 17:26:51 +08008458 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008459}
8460
8461/*
8462 * This file defines the Wireless Extension handlers. It does not
8463 * define any methods of hardware manipulation and relies on the
8464 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008465 *
8466 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008467 * function used to poll the hardware vs. making unecessary calls.
8468 *
8469 */
8470
Jeff Garzikbf794512005-07-31 13:07:26 -04008471static int ipw_wx_get_name(struct net_device *dev,
8472 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008473 union iwreq_data *wrqu, char *extra)
8474{
8475 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008476 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008477 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -05008478 strcpy(wrqu->name, "radio off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008479 else if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06008480 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04008481 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008482 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8483 ipw_modes[priv->assoc_request.ieee_mode]);
8484 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
Zhu Yi46441512006-01-24 16:37:59 +08008485 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008486 return 0;
8487}
8488
8489static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8490{
8491 if (channel == 0) {
8492 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8493 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008494 IPW_DEBUG_ASSOC("Attempting to associate with new "
8495 "parameters.\n");
8496 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008497 return 0;
8498 }
8499
8500 priv->config |= CFG_STATIC_CHANNEL;
8501
8502 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008503 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8504 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008505 return 0;
8506 }
8507
8508 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8509 priv->channel = channel;
8510
James Ketrenosb095c382005-08-24 22:04:42 -05008511#ifdef CONFIG_IPW2200_MONITOR
8512 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008513 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008514 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008515 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008516 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008517 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008518 }
8519
8520 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8521 udelay(10);
8522
8523 if (priv->status & STATUS_SCANNING)
8524 IPW_DEBUG_SCAN("Still scanning...\n");
8525 else
8526 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8527 1000 - i);
8528
8529 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008530 }
James Ketrenosb095c382005-08-24 22:04:42 -05008531#endif /* CONFIG_IPW2200_MONITOR */
8532
James Ketrenosc848d0a2005-08-24 21:56:24 -05008533 /* Network configuration changed -- force [re]association */
8534 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8535 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008536 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008537
8538 return 0;
8539}
8540
Jeff Garzikbf794512005-07-31 13:07:26 -04008541static int ipw_wx_set_freq(struct net_device *dev,
8542 struct iw_request_info *info,
8543 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008544{
8545 struct ipw_priv *priv = ieee80211_priv(dev);
Larry Finger1867b112006-02-28 09:48:28 -06008546 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008547 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008548 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008549 u8 channel, flags;
8550 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008551
James Ketrenosb095c382005-08-24 22:04:42 -05008552 if (fwrq->m == 0) {
8553 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008554 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008555 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008556 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008557 return ret;
8558 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008559 /* if setting by freq convert to channel */
8560 if (fwrq->e == 1) {
Larry Finger1867b112006-02-28 09:48:28 -06008561 channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008562 if (channel == 0)
8563 return -EINVAL;
8564 } else
8565 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008566
Larry Finger1867b112006-02-28 09:48:28 -06008567 if (!(band = ieee80211_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008568 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008569
Liu Hong1fe0adb2005-08-19 09:33:10 -05008570 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
Larry Finger1867b112006-02-28 09:48:28 -06008571 i = ieee80211_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008572 if (i == -1)
8573 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008574
8575 flags = (band == IEEE80211_24GHZ_BAND) ?
8576 geo->bg[i].flags : geo->a[i].flags;
8577 if (flags & IEEE80211_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008578 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8579 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008580 }
8581 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008582
James Ketrenos43f66a62005-03-25 12:31:53 -06008583 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008584 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008585 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008586 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008587 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008588}
8589
Jeff Garzikbf794512005-07-31 13:07:26 -04008590static int ipw_wx_get_freq(struct net_device *dev,
8591 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008592 union iwreq_data *wrqu, char *extra)
8593{
8594 struct ipw_priv *priv = ieee80211_priv(dev);
8595
8596 wrqu->freq.e = 0;
8597
8598 /* If we are associated, trying to associate, or have a statically
8599 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008600 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008601 if (priv->config & CFG_STATIC_CHANNEL ||
8602 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8603 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04008604 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008605 wrqu->freq.m = 0;
8606
Zhu Yi46441512006-01-24 16:37:59 +08008607 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008608 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8609 return 0;
8610}
8611
Jeff Garzikbf794512005-07-31 13:07:26 -04008612static int ipw_wx_set_mode(struct net_device *dev,
8613 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008614 union iwreq_data *wrqu, char *extra)
8615{
8616 struct ipw_priv *priv = ieee80211_priv(dev);
8617 int err = 0;
8618
8619 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8620
James Ketrenos43f66a62005-03-25 12:31:53 -06008621 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008622#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008623 case IW_MODE_MONITOR:
8624#endif
8625 case IW_MODE_ADHOC:
8626 case IW_MODE_INFRA:
8627 break;
8628 case IW_MODE_AUTO:
8629 wrqu->mode = IW_MODE_INFRA;
8630 break;
8631 default:
8632 return -EINVAL;
8633 }
James Ketrenosb095c382005-08-24 22:04:42 -05008634 if (wrqu->mode == priv->ieee->iw_mode)
8635 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008636
Zhu Yi46441512006-01-24 16:37:59 +08008637 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008638
8639 ipw_sw_reset(priv, 0);
8640
James Ketrenosb095c382005-08-24 22:04:42 -05008641#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008642 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008643 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008644
8645 if (wrqu->mode == IW_MODE_MONITOR)
Zhu Yi459d4082006-04-13 17:21:00 +08008646#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008647 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8648#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008649 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008650#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008651#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008652
Jeff Garzikbf794512005-07-31 13:07:26 -04008653 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06008654 * flag so ipw_load() will bring in the new firmawre */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008655 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008656
8657 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008658
James Ketrenosc848d0a2005-08-24 21:56:24 -05008659 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008660 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008661 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008662}
8663
Jeff Garzikbf794512005-07-31 13:07:26 -04008664static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008665 struct iw_request_info *info,
8666 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008667{
8668 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008669 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008670 wrqu->mode = priv->ieee->iw_mode;
8671 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008672 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008673 return 0;
8674}
8675
James Ketrenos43f66a62005-03-25 12:31:53 -06008676/* Values are in microsecond */
8677static const s32 timeout_duration[] = {
8678 350000,
8679 250000,
8680 75000,
8681 37000,
8682 25000,
8683};
8684
8685static const s32 period_duration[] = {
8686 400000,
8687 700000,
8688 1000000,
8689 1000000,
8690 1000000
8691};
8692
Jeff Garzikbf794512005-07-31 13:07:26 -04008693static int ipw_wx_get_range(struct net_device *dev,
8694 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008695 union iwreq_data *wrqu, char *extra)
8696{
8697 struct ipw_priv *priv = ieee80211_priv(dev);
8698 struct iw_range *range = (struct iw_range *)extra;
Larry Finger1867b112006-02-28 09:48:28 -06008699 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008700 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008701
8702 wrqu->data.length = sizeof(*range);
8703 memset(range, 0, sizeof(*range));
8704
8705 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008706 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008707
8708 range->max_qual.qual = 100;
8709 /* TODO: Find real max RSSI and stick here */
8710 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008711 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008712 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008713
8714 range->avg_qual.qual = 70;
8715 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008716 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008717 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008718 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008719 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008720 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008721
Jeff Garzikbf794512005-07-31 13:07:26 -04008722 for (i = 0; i < range->num_bitrates; i++)
8723 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008724 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008725
James Ketrenos43f66a62005-03-25 12:31:53 -06008726 range->max_rts = DEFAULT_RTS_THRESHOLD;
8727 range->min_frag = MIN_FRAG_THRESHOLD;
8728 range->max_frag = MAX_FRAG_THRESHOLD;
8729
8730 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008731 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008732 range->num_encoding_sizes = 2;
8733 range->max_encoding_tokens = WEP_KEYS;
8734
8735 /* Set the Wireless Extension versions */
8736 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008737 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008738
James Ketrenosb095c382005-08-24 22:04:42 -05008739 i = 0;
8740 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
Zhu Yie815de42006-03-02 05:55:51 +08008741 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8742 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8743 (geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8744 continue;
8745
James Ketrenosb095c382005-08-24 22:04:42 -05008746 range->freq[i].i = geo->bg[j].channel;
8747 range->freq[i].m = geo->bg[j].freq * 100000;
8748 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008749 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008750 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008751 }
James Ketrenosb095c382005-08-24 22:04:42 -05008752
8753 if (priv->ieee->mode & IEEE_A) {
Zhu Yie815de42006-03-02 05:55:51 +08008754 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8755 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8756 (geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8757 continue;
8758
James Ketrenosb095c382005-08-24 22:04:42 -05008759 range->freq[i].i = geo->a[j].channel;
8760 range->freq[i].m = geo->a[j].freq * 100000;
8761 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008762 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008763 }
8764 }
8765
8766 range->num_channels = i;
8767 range->num_frequency = i;
8768
Zhu Yi46441512006-01-24 16:37:59 +08008769 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008770
8771 /* Event capability (kernel + driver) */
8772 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8773 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
Zhu Yi07f02e42006-04-13 17:19:25 +08008774 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
8775 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008776 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008777
Dan Williamsf1b50862006-01-30 13:58:56 -05008778 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8779 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8780
James Ketrenos43f66a62005-03-25 12:31:53 -06008781 IPW_DEBUG_WX("GET Range\n");
8782 return 0;
8783}
8784
Jeff Garzikbf794512005-07-31 13:07:26 -04008785static int ipw_wx_set_wap(struct net_device *dev,
8786 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008787 union iwreq_data *wrqu, char *extra)
8788{
8789 struct ipw_priv *priv = ieee80211_priv(dev);
8790
8791 static const unsigned char any[] = {
8792 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8793 };
8794 static const unsigned char off[] = {
8795 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8796 };
8797
Jeff Garzikbf794512005-07-31 13:07:26 -04008798 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06008799 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08008800 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008801 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8802 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8803 /* we disable mandatory BSSID association */
8804 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8805 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008806 IPW_DEBUG_ASSOC("Attempting to associate with new "
8807 "parameters.\n");
8808 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08008809 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008810 return 0;
8811 }
8812
8813 priv->config |= CFG_STATIC_BSSID;
8814 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8815 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008816 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008817 return 0;
8818 }
8819
8820 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8821 MAC_ARG(wrqu->ap_addr.sa_data));
8822
8823 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8824
James Ketrenosc848d0a2005-08-24 21:56:24 -05008825 /* Network configuration changed -- force [re]association */
8826 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8827 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008828 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008829
Zhu Yi46441512006-01-24 16:37:59 +08008830 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008831 return 0;
8832}
8833
Jeff Garzikbf794512005-07-31 13:07:26 -04008834static int ipw_wx_get_wap(struct net_device *dev,
8835 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008836 union iwreq_data *wrqu, char *extra)
8837{
8838 struct ipw_priv *priv = ieee80211_priv(dev);
8839 /* If we are associated, trying to associate, or have a statically
8840 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008841 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04008842 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06008843 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8844 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008845 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06008846 } else
8847 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8848
8849 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8850 MAC_ARG(wrqu->ap_addr.sa_data));
Zhu Yi46441512006-01-24 16:37:59 +08008851 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008852 return 0;
8853}
8854
Jeff Garzikbf794512005-07-31 13:07:26 -04008855static int ipw_wx_set_essid(struct net_device *dev,
8856 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008857 union iwreq_data *wrqu, char *extra)
8858{
8859 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008860 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06008861 int length = 0;
Zhu Yi46441512006-01-24 16:37:59 +08008862 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008863 if (wrqu->essid.flags && wrqu->essid.length) {
8864 length = wrqu->essid.length - 1;
8865 essid = extra;
8866 }
8867 if (length == 0) {
8868 IPW_DEBUG_WX("Setting ESSID to ANY\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008869 if ((priv->config & CFG_STATIC_ESSID) &&
8870 !(priv->status & (STATUS_ASSOCIATED |
James Ketrenos43f66a62005-03-25 12:31:53 -06008871 STATUS_ASSOCIATING))) {
8872 IPW_DEBUG_ASSOC("Attempting to associate with new "
8873 "parameters.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008874 priv->config &= ~CFG_STATIC_ESSID;
James Ketrenos43f66a62005-03-25 12:31:53 -06008875 ipw_associate(priv);
8876 }
Zhu Yi46441512006-01-24 16:37:59 +08008877 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008878 return 0;
8879 }
8880
8881 length = min(length, IW_ESSID_MAX_SIZE);
8882
8883 priv->config |= CFG_STATIC_ESSID;
8884
8885 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8886 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008887 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008888 return 0;
8889 }
8890
8891 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8892 length);
8893
8894 priv->essid_len = length;
8895 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04008896
James Ketrenosc848d0a2005-08-24 21:56:24 -05008897 /* Network configuration changed -- force [re]association */
8898 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8899 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008900 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008901
Zhu Yi46441512006-01-24 16:37:59 +08008902 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008903 return 0;
8904}
8905
Jeff Garzikbf794512005-07-31 13:07:26 -04008906static int ipw_wx_get_essid(struct net_device *dev,
8907 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008908 union iwreq_data *wrqu, char *extra)
8909{
8910 struct ipw_priv *priv = ieee80211_priv(dev);
8911
8912 /* If we are associated, trying to associate, or have a statically
8913 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008914 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008915 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04008916 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8917 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008918 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04008919 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06008920 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008921 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008922 } else {
8923 IPW_DEBUG_WX("Getting essid: ANY\n");
8924 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008925 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008926 }
Zhu Yi46441512006-01-24 16:37:59 +08008927 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008928 return 0;
8929}
8930
Jeff Garzikbf794512005-07-31 13:07:26 -04008931static int ipw_wx_set_nick(struct net_device *dev,
8932 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008933 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008934{
James Ketrenos43f66a62005-03-25 12:31:53 -06008935 struct ipw_priv *priv = ieee80211_priv(dev);
8936
8937 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8938 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8939 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08008940 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008941 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06008942 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008943 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06008944 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08008945 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008946 return 0;
8947
8948}
8949
Jeff Garzikbf794512005-07-31 13:07:26 -04008950static int ipw_wx_get_nick(struct net_device *dev,
8951 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008952 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008953{
James Ketrenos43f66a62005-03-25 12:31:53 -06008954 struct ipw_priv *priv = ieee80211_priv(dev);
8955 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08008956 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008957 wrqu->data.length = strlen(priv->nick) + 1;
8958 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008959 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08008960 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008961 return 0;
8962}
8963
Olivier Hochreutiner651be262006-03-08 03:13:55 +08008964static int ipw_wx_set_sens(struct net_device *dev,
8965 struct iw_request_info *info,
8966 union iwreq_data *wrqu, char *extra)
8967{
8968 struct ipw_priv *priv = ieee80211_priv(dev);
8969 int err = 0;
8970
8971 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
8972 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
8973 mutex_lock(&priv->mutex);
8974
8975 if (wrqu->sens.fixed == 0)
8976 {
8977 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8978 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8979 goto out;
8980 }
8981 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
8982 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
8983 err = -EINVAL;
8984 goto out;
8985 }
8986
8987 priv->roaming_threshold = wrqu->sens.value;
8988 priv->disassociate_threshold = 3*wrqu->sens.value;
8989 out:
8990 mutex_unlock(&priv->mutex);
8991 return err;
8992}
8993
8994static int ipw_wx_get_sens(struct net_device *dev,
8995 struct iw_request_info *info,
8996 union iwreq_data *wrqu, char *extra)
8997{
8998 struct ipw_priv *priv = ieee80211_priv(dev);
8999 mutex_lock(&priv->mutex);
9000 wrqu->sens.fixed = 1;
9001 wrqu->sens.value = priv->roaming_threshold;
9002 mutex_unlock(&priv->mutex);
9003
9004 IPW_DEBUG_WX("GET roaming threshold -> %s %d \n",
9005 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
9006
9007 return 0;
9008}
9009
James Ketrenos43f66a62005-03-25 12:31:53 -06009010static int ipw_wx_set_rate(struct net_device *dev,
9011 struct iw_request_info *info,
9012 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009013{
James Ketrenosea2b26e2005-08-24 21:25:16 -05009014 /* TODO: We should use semaphores or locks for access to priv */
9015 struct ipw_priv *priv = ieee80211_priv(dev);
9016 u32 target_rate = wrqu->bitrate.value;
9017 u32 fixed, mask;
9018
9019 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
9020 /* value = X, fixed = 1 means only rate X */
9021 /* value = X, fixed = 0 means all rates lower equal X */
9022
9023 if (target_rate == -1) {
9024 fixed = 0;
9025 mask = IEEE80211_DEFAULT_RATES_MASK;
9026 /* Now we should reassociate */
9027 goto apply;
9028 }
9029
9030 mask = 0;
9031 fixed = wrqu->bitrate.fixed;
9032
9033 if (target_rate == 1000000 || !fixed)
9034 mask |= IEEE80211_CCK_RATE_1MB_MASK;
9035 if (target_rate == 1000000)
9036 goto apply;
9037
9038 if (target_rate == 2000000 || !fixed)
9039 mask |= IEEE80211_CCK_RATE_2MB_MASK;
9040 if (target_rate == 2000000)
9041 goto apply;
9042
9043 if (target_rate == 5500000 || !fixed)
9044 mask |= IEEE80211_CCK_RATE_5MB_MASK;
9045 if (target_rate == 5500000)
9046 goto apply;
9047
9048 if (target_rate == 6000000 || !fixed)
9049 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
9050 if (target_rate == 6000000)
9051 goto apply;
9052
9053 if (target_rate == 9000000 || !fixed)
9054 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
9055 if (target_rate == 9000000)
9056 goto apply;
9057
9058 if (target_rate == 11000000 || !fixed)
9059 mask |= IEEE80211_CCK_RATE_11MB_MASK;
9060 if (target_rate == 11000000)
9061 goto apply;
9062
9063 if (target_rate == 12000000 || !fixed)
9064 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
9065 if (target_rate == 12000000)
9066 goto apply;
9067
9068 if (target_rate == 18000000 || !fixed)
9069 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
9070 if (target_rate == 18000000)
9071 goto apply;
9072
9073 if (target_rate == 24000000 || !fixed)
9074 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
9075 if (target_rate == 24000000)
9076 goto apply;
9077
9078 if (target_rate == 36000000 || !fixed)
9079 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
9080 if (target_rate == 36000000)
9081 goto apply;
9082
9083 if (target_rate == 48000000 || !fixed)
9084 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
9085 if (target_rate == 48000000)
9086 goto apply;
9087
9088 if (target_rate == 54000000 || !fixed)
9089 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
9090 if (target_rate == 54000000)
9091 goto apply;
9092
9093 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9094 return -EINVAL;
9095
9096 apply:
9097 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9098 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08009099 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009100 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009101 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05009102 ipw_set_fixed_rate(priv, priv->ieee->mode);
9103 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05009104 priv->config |= CFG_FIXED_RATE;
9105
James Ketrenosc848d0a2005-08-24 21:56:24 -05009106 if (priv->rates_mask == mask) {
9107 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009108 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009109 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009110 }
9111
James Ketrenosc848d0a2005-08-24 21:56:24 -05009112 priv->rates_mask = mask;
9113
9114 /* Network configuration changed -- force [re]association */
9115 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9116 if (!ipw_disassociate(priv))
9117 ipw_associate(priv);
9118
Zhu Yi46441512006-01-24 16:37:59 +08009119 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009120 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009121}
9122
Jeff Garzikbf794512005-07-31 13:07:26 -04009123static int ipw_wx_get_rate(struct net_device *dev,
9124 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009125 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009126{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009127 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009128 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009129 wrqu->bitrate.value = priv->last_rate;
Zhu Yi455936c2006-04-13 17:20:05 +08009130 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009131 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009132 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
9133 return 0;
9134}
9135
Jeff Garzikbf794512005-07-31 13:07:26 -04009136static int ipw_wx_set_rts(struct net_device *dev,
9137 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009138 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009139{
James Ketrenos43f66a62005-03-25 12:31:53 -06009140 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009141 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009142 if (wrqu->rts.disabled)
9143 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9144 else {
9145 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05009146 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009147 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009148 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009149 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009150 priv->rts_threshold = wrqu->rts.value;
9151 }
9152
9153 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08009154 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009155 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
9156 return 0;
9157}
9158
Jeff Garzikbf794512005-07-31 13:07:26 -04009159static int ipw_wx_get_rts(struct net_device *dev,
9160 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009161 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009162{
James Ketrenos43f66a62005-03-25 12:31:53 -06009163 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009164 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009165 wrqu->rts.value = priv->rts_threshold;
9166 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009167 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08009168 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009169 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
9170 return 0;
9171}
9172
Jeff Garzikbf794512005-07-31 13:07:26 -04009173static int ipw_wx_set_txpow(struct net_device *dev,
9174 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009175 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009176{
James Ketrenos43f66a62005-03-25 12:31:53 -06009177 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009178 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009179
Zhu Yi46441512006-01-24 16:37:59 +08009180 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009181 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009182 err = -EINPROGRESS;
9183 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009184 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009185
James Ketrenosb095c382005-08-24 22:04:42 -05009186 if (!wrqu->power.fixed)
9187 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06009188
James Ketrenosc848d0a2005-08-24 21:56:24 -05009189 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009190 err = -EINVAL;
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.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05009195 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009196 err = -EINVAL;
9197 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009198 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009199
9200 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009201 err = ipw_set_tx_power(priv);
9202 out:
Zhu Yi46441512006-01-24 16:37:59 +08009203 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009204 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009205}
9206
Jeff Garzikbf794512005-07-31 13:07:26 -04009207static int ipw_wx_get_txpow(struct net_device *dev,
9208 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009209 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009210{
James Ketrenos43f66a62005-03-25 12:31:53 -06009211 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009212 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009213 wrqu->power.value = priv->tx_power;
9214 wrqu->power.fixed = 1;
9215 wrqu->power.flags = IW_TXPOW_DBM;
9216 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009217 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009218
Jeff Garzikbf794512005-07-31 13:07:26 -04009219 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08009220 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009221
9222 return 0;
9223}
9224
Jeff Garzikbf794512005-07-31 13:07:26 -04009225static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009226 struct iw_request_info *info,
9227 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009228{
9229 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009230 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009231 if (wrqu->frag.disabled)
9232 priv->ieee->fts = DEFAULT_FTS;
9233 else {
9234 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05009235 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009236 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009237 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05009238 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009239
James Ketrenos43f66a62005-03-25 12:31:53 -06009240 priv->ieee->fts = wrqu->frag.value & ~0x1;
9241 }
9242
9243 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08009244 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009245 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
9246 return 0;
9247}
9248
Jeff Garzikbf794512005-07-31 13:07:26 -04009249static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009250 struct iw_request_info *info,
9251 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009252{
9253 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009254 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009255 wrqu->frag.value = priv->ieee->fts;
9256 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009257 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08009258 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009259 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
9260
9261 return 0;
9262}
9263
Jeff Garzikbf794512005-07-31 13:07:26 -04009264static int ipw_wx_set_retry(struct net_device *dev,
9265 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009266 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009267{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009268 struct ipw_priv *priv = ieee80211_priv(dev);
9269
9270 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9271 return -EINVAL;
9272
9273 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9274 return 0;
9275
9276 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
9277 return -EINVAL;
9278
Zhu Yi46441512006-01-24 16:37:59 +08009279 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009280 if (wrqu->retry.flags & IW_RETRY_MIN)
9281 priv->short_retry_limit = (u8) wrqu->retry.value;
9282 else if (wrqu->retry.flags & IW_RETRY_MAX)
9283 priv->long_retry_limit = (u8) wrqu->retry.value;
9284 else {
9285 priv->short_retry_limit = (u8) wrqu->retry.value;
9286 priv->long_retry_limit = (u8) wrqu->retry.value;
9287 }
9288
9289 ipw_send_retry_limit(priv, priv->short_retry_limit,
9290 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08009291 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009292 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9293 priv->short_retry_limit, priv->long_retry_limit);
9294 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009295}
9296
Jeff Garzikbf794512005-07-31 13:07:26 -04009297static int ipw_wx_get_retry(struct net_device *dev,
9298 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009299 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009300{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009301 struct ipw_priv *priv = ieee80211_priv(dev);
9302
Zhu Yi46441512006-01-24 16:37:59 +08009303 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009304 wrqu->retry.disabled = 0;
9305
9306 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08009307 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009308 return -EINVAL;
9309 }
9310
9311 if (wrqu->retry.flags & IW_RETRY_MAX) {
9312 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
9313 wrqu->retry.value = priv->long_retry_limit;
9314 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
9315 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
9316 wrqu->retry.value = priv->short_retry_limit;
9317 } else {
9318 wrqu->retry.flags = IW_RETRY_LIMIT;
9319 wrqu->retry.value = priv->short_retry_limit;
9320 }
Zhu Yi46441512006-01-24 16:37:59 +08009321 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009322
9323 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9324
9325 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009326}
9327
James Ketrenosafbf30a2005-08-25 00:05:33 -05009328static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
9329 int essid_len)
9330{
9331 struct ipw_scan_request_ext scan;
9332 int err = 0, scan_type;
9333
Pekka Enbergefb34422005-11-16 21:55:05 +02009334 if (!(priv->status & STATUS_INIT) ||
9335 (priv->status & STATUS_EXIT_PENDING))
9336 return 0;
9337
Zhu Yi46441512006-01-24 16:37:59 +08009338 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009339
9340 if (priv->status & STATUS_RF_KILL_MASK) {
9341 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
9342 priv->status |= STATUS_SCAN_PENDING;
9343 goto done;
9344 }
9345
9346 IPW_DEBUG_HC("starting request direct scan!\n");
9347
9348 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
Olaf Kirchd834a412006-01-09 17:00:37 +01009349 /* We should not sleep here; otherwise we will block most
9350 * of the system (for instance, we hold rtnl_lock when we
9351 * get here).
9352 */
9353 err = -EAGAIN;
9354 goto done;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009355 }
9356 memset(&scan, 0, sizeof(scan));
9357
9358 if (priv->config & CFG_SPEED_SCAN)
9359 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9360 cpu_to_le16(30);
9361 else
9362 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9363 cpu_to_le16(20);
9364
9365 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
9366 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05009367 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009368 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
9369
9370 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
9371
9372 err = ipw_send_ssid(priv, essid, essid_len);
9373 if (err) {
9374 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
9375 goto done;
9376 }
9377 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
9378
9379 ipw_add_scan_channels(priv, &scan, scan_type);
9380
9381 err = ipw_send_scan_request_ext(priv, &scan);
9382 if (err) {
9383 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
9384 goto done;
9385 }
9386
9387 priv->status |= STATUS_SCANNING;
9388
9389 done:
Zhu Yi46441512006-01-24 16:37:59 +08009390 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009391 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009392}
9393
Jeff Garzikbf794512005-07-31 13:07:26 -04009394static int ipw_wx_set_scan(struct net_device *dev,
9395 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009396 union iwreq_data *wrqu, char *extra)
9397{
9398 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009399 struct iw_scan_req *req = NULL;
9400 if (wrqu->data.length
9401 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9402 req = (struct iw_scan_req *)extra;
9403 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9404 ipw_request_direct_scan(priv, req->essid,
9405 req->essid_len);
9406 return 0;
9407 }
9408 }
James Ketrenos8935f392005-10-05 15:59:08 -05009409
James Ketrenos43f66a62005-03-25 12:31:53 -06009410 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009411
9412 queue_work(priv->workqueue, &priv->request_scan);
9413
James Ketrenos43f66a62005-03-25 12:31:53 -06009414 return 0;
9415}
9416
Jeff Garzikbf794512005-07-31 13:07:26 -04009417static int ipw_wx_get_scan(struct net_device *dev,
9418 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009419 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009420{
James Ketrenos43f66a62005-03-25 12:31:53 -06009421 struct ipw_priv *priv = ieee80211_priv(dev);
9422 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9423}
9424
Jeff Garzikbf794512005-07-31 13:07:26 -04009425static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009426 struct iw_request_info *info,
9427 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009428{
9429 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009430 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009431 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009432
Zhu Yi46441512006-01-24 16:37:59 +08009433 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009434 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009435
Hong Liucaeff812005-08-05 17:25:50 +08009436 /* In IBSS mode, we need to notify the firmware to update
9437 * the beacon info after we changed the capability. */
9438 if (cap != priv->capability &&
9439 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9440 priv->status & STATUS_ASSOCIATED)
9441 ipw_disassociate(priv);
9442
Zhu Yi46441512006-01-24 16:37:59 +08009443 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009444 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009445}
9446
Jeff Garzikbf794512005-07-31 13:07:26 -04009447static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009448 struct iw_request_info *info,
9449 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009450{
9451 struct ipw_priv *priv = ieee80211_priv(dev);
9452 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9453}
9454
Jeff Garzikbf794512005-07-31 13:07:26 -04009455static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009456 struct iw_request_info *info,
9457 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009458{
9459 struct ipw_priv *priv = ieee80211_priv(dev);
9460 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009461 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009462 if (wrqu->power.disabled) {
9463 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9464 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9465 if (err) {
9466 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009467 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009468 return err;
9469 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009470 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009471 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009472 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009473 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009474
9475 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009476 case IW_POWER_ON: /* If not specified */
9477 case IW_POWER_MODE: /* If set all mask */
9478 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009479 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009480 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009481 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9482 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009483 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009484 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009485 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009486
James Ketrenos43f66a62005-03-25 12:31:53 -06009487 /* If the user hasn't specified a power management mode yet, default
9488 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009489 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009490 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009491 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009492 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9493 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9494 if (err) {
9495 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009496 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009497 return err;
9498 }
9499
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009500 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009501 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009502 return 0;
9503}
9504
Jeff Garzikbf794512005-07-31 13:07:26 -04009505static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009506 struct iw_request_info *info,
9507 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009508{
9509 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009510 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009511 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009512 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009513 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009514 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009515
Zhu Yi46441512006-01-24 16:37:59 +08009516 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009517 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009518
James Ketrenos43f66a62005-03-25 12:31:53 -06009519 return 0;
9520}
9521
Jeff Garzikbf794512005-07-31 13:07:26 -04009522static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009523 struct iw_request_info *info,
9524 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009525{
9526 struct ipw_priv *priv = ieee80211_priv(dev);
9527 int mode = *(int *)extra;
9528 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009529 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009530 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9531 mode = IPW_POWER_AC;
9532 priv->power_mode = mode;
9533 } else {
9534 priv->power_mode = IPW_POWER_ENABLED | mode;
9535 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009536
James Ketrenos43f66a62005-03-25 12:31:53 -06009537 if (priv->power_mode != mode) {
9538 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009539
James Ketrenos43f66a62005-03-25 12:31:53 -06009540 if (err) {
9541 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009542 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009543 return err;
9544 }
9545 }
Zhu Yi46441512006-01-24 16:37:59 +08009546 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009547 return 0;
9548}
9549
9550#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009551static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009552 struct iw_request_info *info,
9553 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009554{
9555 struct ipw_priv *priv = ieee80211_priv(dev);
9556 int level = IPW_POWER_LEVEL(priv->power_mode);
9557 char *p = extra;
9558
9559 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9560
9561 switch (level) {
9562 case IPW_POWER_AC:
9563 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9564 break;
9565 case IPW_POWER_BATTERY:
9566 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9567 break;
9568 default:
9569 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009570 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009571 timeout_duration[level - 1] / 1000,
9572 period_duration[level - 1] / 1000);
9573 }
9574
9575 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009576 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009577
9578 wrqu->data.length = p - extra + 1;
9579
9580 return 0;
9581}
9582
9583static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009584 struct iw_request_info *info,
9585 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009586{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009587 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009588 int mode = *(int *)extra;
9589 u8 band = 0, modulation = 0;
9590
9591 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009592 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009593 return -EINVAL;
9594 }
Zhu Yi46441512006-01-24 16:37:59 +08009595 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009596 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009597 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009598 if (mode & IEEE_A) {
9599 band |= IEEE80211_52GHZ_BAND;
9600 modulation |= IEEE80211_OFDM_MODULATION;
9601 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009602 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009603 } else {
9604 if (mode & IEEE_A) {
9605 IPW_WARNING("Attempt to set 2200BG into "
9606 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009607 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009608 return -EINVAL;
9609 }
9610
James Ketrenosa33a1982005-09-14 14:28:59 -05009611 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009612 }
9613
9614 if (mode & IEEE_B) {
9615 band |= IEEE80211_24GHZ_BAND;
9616 modulation |= IEEE80211_CCK_MODULATION;
9617 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009618 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009619
James Ketrenos43f66a62005-03-25 12:31:53 -06009620 if (mode & IEEE_G) {
9621 band |= IEEE80211_24GHZ_BAND;
9622 modulation |= IEEE80211_OFDM_MODULATION;
9623 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009624 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009625
9626 priv->ieee->mode = mode;
9627 priv->ieee->freq_band = band;
9628 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009629 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009630
James Ketrenosc848d0a2005-08-24 21:56:24 -05009631 /* Network configuration changed -- force [re]association */
9632 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9633 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009634 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009635 ipw_associate(priv);
9636 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009637
James Ketrenosa613bff2005-08-24 21:43:11 -05009638 /* Update the band LEDs */
9639 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009640
Jeff Garzikbf794512005-07-31 13:07:26 -04009641 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009642 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009643 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009644 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009645 return 0;
9646}
9647
9648static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009649 struct iw_request_info *info,
9650 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009651{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009652 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009653 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009654 switch (priv->ieee->mode) {
9655 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009656 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9657 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009658 case IEEE_B:
9659 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9660 break;
9661 case IEEE_A | IEEE_B:
9662 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9663 break;
9664 case IEEE_G:
9665 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9666 break;
9667 case IEEE_A | IEEE_G:
9668 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9669 break;
9670 case IEEE_B | IEEE_G:
9671 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9672 break;
9673 case IEEE_A | IEEE_B | IEEE_G:
9674 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9675 break;
9676 default:
9677 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009678 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009679 }
9680
James Ketrenos43f66a62005-03-25 12:31:53 -06009681 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9682
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009683 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009684 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009685
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009686 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009687}
9688
James Ketrenosea2b26e2005-08-24 21:25:16 -05009689static int ipw_wx_set_preamble(struct net_device *dev,
9690 struct iw_request_info *info,
9691 union iwreq_data *wrqu, char *extra)
9692{
9693 struct ipw_priv *priv = ieee80211_priv(dev);
9694 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009695 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009696 /* Switching from SHORT -> LONG requires a disassociation */
9697 if (mode == 1) {
9698 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9699 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009700
9701 /* Network configuration changed -- force [re]association */
9702 IPW_DEBUG_ASSOC
9703 ("[re]association triggered due to preamble change.\n");
9704 if (!ipw_disassociate(priv))
9705 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009706 }
9707 goto done;
9708 }
9709
9710 if (mode == 0) {
9711 priv->config &= ~CFG_PREAMBLE_LONG;
9712 goto done;
9713 }
Zhu Yi46441512006-01-24 16:37:59 +08009714 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009715 return -EINVAL;
9716
9717 done:
Zhu Yi46441512006-01-24 16:37:59 +08009718 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009719 return 0;
9720}
9721
9722static int ipw_wx_get_preamble(struct net_device *dev,
9723 struct iw_request_info *info,
9724 union iwreq_data *wrqu, char *extra)
9725{
9726 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009727 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009728 if (priv->config & CFG_PREAMBLE_LONG)
9729 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9730 else
9731 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009732 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009733 return 0;
9734}
9735
James Ketrenosb095c382005-08-24 22:04:42 -05009736#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009737static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009738 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009739 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009740{
James Ketrenos43f66a62005-03-25 12:31:53 -06009741 struct ipw_priv *priv = ieee80211_priv(dev);
9742 int *parms = (int *)extra;
9743 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009744 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009745 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009746 if (enable) {
9747 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08009748#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05009749 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9750#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009751 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009752#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009753 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009754 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009755
James Ketrenos43f66a62005-03-25 12:31:53 -06009756 ipw_set_channel(priv, parms[1]);
9757 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009758 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009759 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009760 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009761 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009762 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009763 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009764 }
Zhu Yi46441512006-01-24 16:37:59 +08009765 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009766 return 0;
9767}
9768
James Ketrenosb095c382005-08-24 22:04:42 -05009769#endif // CONFIG_IPW2200_MONITOR
9770
Jeff Garzikbf794512005-07-31 13:07:26 -04009771static int ipw_wx_reset(struct net_device *dev,
9772 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009773 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009774{
James Ketrenos43f66a62005-03-25 12:31:53 -06009775 struct ipw_priv *priv = ieee80211_priv(dev);
9776 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009777 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009778 return 0;
9779}
James Ketrenosb095c382005-08-24 22:04:42 -05009780
James Ketrenosb095c382005-08-24 22:04:42 -05009781static int ipw_wx_sw_reset(struct net_device *dev,
9782 struct iw_request_info *info,
9783 union iwreq_data *wrqu, char *extra)
9784{
9785 struct ipw_priv *priv = ieee80211_priv(dev);
9786 union iwreq_data wrqu_sec = {
9787 .encoding = {
9788 .flags = IW_ENCODE_DISABLED,
9789 },
9790 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009791 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009792
9793 IPW_DEBUG_WX("SW_RESET\n");
9794
Zhu Yi46441512006-01-24 16:37:59 +08009795 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009796
Zhu Yid6d5b5c2006-02-16 16:21:09 +08009797 ret = ipw_sw_reset(priv, 2);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009798 if (!ret) {
9799 free_firmware();
9800 ipw_adapter_restart(priv);
9801 }
James Ketrenosb095c382005-08-24 22:04:42 -05009802
9803 /* The SW reset bit might have been toggled on by the 'disable'
9804 * module parameter, so take appropriate action */
9805 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9806
Zhu Yi46441512006-01-24 16:37:59 +08009807 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009808 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009809 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009810
9811 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9812 /* Configuration likely changed -- force [re]association */
9813 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9814 "reset.\n");
9815 if (!ipw_disassociate(priv))
9816 ipw_associate(priv);
9817 }
9818
Zhu Yi46441512006-01-24 16:37:59 +08009819 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009820
9821 return 0;
9822}
James Ketrenos43f66a62005-03-25 12:31:53 -06009823
9824/* Rebase the WE IOCTLs to zero for the handler array */
9825#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009826static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009827 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9828 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9829 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9830 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9831 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009832 IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens,
9833 IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009834 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9835 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9836 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9837 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9838 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9839 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9840 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9841 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9842 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9843 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9844 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9845 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9846 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9847 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9848 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9849 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9850 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9851 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9852 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9853 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9854 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9855 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9856 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -05009857 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9858 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9859 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9860 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -05009861 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9862 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9863 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9864 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9865 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9866 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9867 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
James Ketrenos43f66a62005-03-25 12:31:53 -06009868};
9869
James Ketrenosb095c382005-08-24 22:04:42 -05009870enum {
9871 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9872 IPW_PRIV_GET_POWER,
9873 IPW_PRIV_SET_MODE,
9874 IPW_PRIV_GET_MODE,
9875 IPW_PRIV_SET_PREAMBLE,
9876 IPW_PRIV_GET_PREAMBLE,
9877 IPW_PRIV_RESET,
9878 IPW_PRIV_SW_RESET,
9879#ifdef CONFIG_IPW2200_MONITOR
9880 IPW_PRIV_SET_MONITOR,
9881#endif
9882};
James Ketrenos43f66a62005-03-25 12:31:53 -06009883
Jeff Garzikbf794512005-07-31 13:07:26 -04009884static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06009885 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009886 .cmd = IPW_PRIV_SET_POWER,
9887 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9888 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009889 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009890 .cmd = IPW_PRIV_GET_POWER,
9891 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9892 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009893 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009894 .cmd = IPW_PRIV_SET_MODE,
9895 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9896 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009897 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009898 .cmd = IPW_PRIV_GET_MODE,
9899 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9900 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009901 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009902 .cmd = IPW_PRIV_SET_PREAMBLE,
9903 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9904 .name = "set_preamble"},
9905 {
9906 .cmd = IPW_PRIV_GET_PREAMBLE,
9907 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9908 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009909 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009910 IPW_PRIV_RESET,
9911 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -05009912 {
9913 IPW_PRIV_SW_RESET,
9914 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9915#ifdef CONFIG_IPW2200_MONITOR
9916 {
9917 IPW_PRIV_SET_MONITOR,
9918 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9919#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06009920};
9921
9922static iw_handler ipw_priv_handler[] = {
9923 ipw_wx_set_powermode,
9924 ipw_wx_get_powermode,
9925 ipw_wx_set_wireless_mode,
9926 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009927 ipw_wx_set_preamble,
9928 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -04009929 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -05009930 ipw_wx_sw_reset,
9931#ifdef CONFIG_IPW2200_MONITOR
9932 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -06009933#endif
9934};
9935
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009936static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009937 .standard = ipw_wx_handlers,
9938 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9939 .num_private = ARRAY_SIZE(ipw_priv_handler),
9940 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9941 .private = ipw_priv_handler,
9942 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009943 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06009944};
9945
James Ketrenos43f66a62005-03-25 12:31:53 -06009946/*
9947 * Get wireless statistics.
9948 * Called by /proc/net/wireless
9949 * Also called by SIOCGIWSTATS
9950 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009951static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06009952{
9953 struct ipw_priv *priv = ieee80211_priv(dev);
9954 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009955
James Ketrenos43f66a62005-03-25 12:31:53 -06009956 wstats = &priv->wstats;
9957
James Ketrenosea2b26e2005-08-24 21:25:16 -05009958 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -05009959 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06009960 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9961 * and associated; if not associcated, the values are all meaningless
9962 * anyway, so set them all to NULL and INVALID */
9963 if (!(priv->status & STATUS_ASSOCIATED)) {
9964 wstats->miss.beacon = 0;
9965 wstats->discard.retries = 0;
9966 wstats->qual.qual = 0;
9967 wstats->qual.level = 0;
9968 wstats->qual.noise = 0;
9969 wstats->qual.updated = 7;
9970 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009971 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06009972 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009973 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009974
9975 wstats->qual.qual = priv->quality;
Zhu Yi00d21de2006-04-13 17:19:02 +08009976 wstats->qual.level = priv->exp_avg_rssi;
9977 wstats->qual.noise = priv->exp_avg_noise;
James Ketrenos43f66a62005-03-25 12:31:53 -06009978 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +08009979 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009980
9981 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9982 wstats->discard.retries = priv->last_tx_failures;
9983 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04009984
James Ketrenos43f66a62005-03-25 12:31:53 -06009985/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9986 goto fail_get_ordinal;
9987 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04009988
James Ketrenos43f66a62005-03-25 12:31:53 -06009989 return wstats;
9990}
9991
James Ketrenos43f66a62005-03-25 12:31:53 -06009992/* net device stuff */
9993
Arjan van de Ven858119e2006-01-14 13:20:43 -08009994static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -06009995{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009996 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +08009997 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009998 sys_config->answer_broadcast_ssid_probe = 0;
9999 sys_config->accept_all_data_frames = 0;
10000 sys_config->accept_non_directed_frames = 1;
10001 sys_config->exclude_unicast_unencrypted = 0;
10002 sys_config->disable_unicast_decryption = 1;
10003 sys_config->exclude_multicast_unencrypted = 0;
10004 sys_config->disable_multicast_decryption = 1;
Zhu Yid2b83e12006-04-13 17:19:36 +080010005 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
10006 antenna = CFG_SYS_ANTENNA_BOTH;
10007 sys_config->antenna_diversity = antenna;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010008 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010009 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010010 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010011 sys_config->bt_coexist_collision_thr = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010012 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
Cahill, Ben M12977152006-03-08 02:58:02 +080010013 sys_config->silence_threshold = 0x1e;
James Ketrenos43f66a62005-03-25 12:31:53 -060010014}
10015
10016static int ipw_net_open(struct net_device *dev)
10017{
10018 struct ipw_priv *priv = ieee80211_priv(dev);
10019 IPW_DEBUG_INFO("dev->open\n");
10020 /* we should be verifying the device is ready to be opened */
Zhu Yi46441512006-01-24 16:37:59 +080010021 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -040010022 if (!(priv->status & STATUS_RF_KILL_MASK) &&
10023 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -060010024 netif_start_queue(dev);
Zhu Yi46441512006-01-24 16:37:59 +080010025 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010026 return 0;
10027}
10028
10029static int ipw_net_stop(struct net_device *dev)
10030{
10031 IPW_DEBUG_INFO("dev->close\n");
10032 netif_stop_queue(dev);
10033 return 0;
10034}
10035
10036/*
10037todo:
10038
10039modify to send one tfd per fragment instead of using chunking. otherwise
10040we need to heavily modify the ieee80211_skb_to_txb.
10041*/
10042
Arjan van de Ven858119e2006-01-14 13:20:43 -080010043static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -050010044 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010045{
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010046 struct ieee80211_hdr_3addrqos *hdr = (struct ieee80211_hdr_3addrqos *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010047 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -060010048 int i = 0;
10049 struct tfd_frame *tfd;
Zhu Yie43e3c12006-04-13 17:20:45 +080010050#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010051 int tx_id = ipw_get_tx_queue_number(priv, pri);
10052 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10053#else
James Ketrenos43f66a62005-03-25 12:31:53 -060010054 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -050010055#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060010056 struct clx2_queue *q = &txq->q;
10057 u8 id, hdr_len, unicast;
10058 u16 remaining_bytes;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010059 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -060010060
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010061 hdr_len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
James Ketrenos43f66a62005-03-25 12:31:53 -060010062 switch (priv->ieee->iw_mode) {
10063 case IW_MODE_ADHOC:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010064 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010065 id = ipw_find_station(priv, hdr->addr1);
10066 if (id == IPW_INVALID_STATION) {
10067 id = ipw_add_station(priv, hdr->addr1);
10068 if (id == IPW_INVALID_STATION) {
10069 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -040010070 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010071 MAC_ARG(hdr->addr1));
10072 goto drop;
10073 }
10074 }
10075 break;
10076
10077 case IW_MODE_INFRA:
10078 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010079 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -060010080 id = 0;
10081 break;
10082 }
10083
10084 tfd = &txq->bd[q->first_empty];
10085 txq->txb[q->first_empty] = txb;
10086 memset(tfd, 0, sizeof(*tfd));
10087 tfd->u.data.station_number = id;
10088
10089 tfd->control_flags.message_type = TX_FRAME_TYPE;
10090 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10091
10092 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -050010093 tfd->u.data.len = cpu_to_le16(txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010094 remaining_bytes = txb->payload_size;
Jeff Garzikbf794512005-07-31 13:07:26 -040010095
James Ketrenos43f66a62005-03-25 12:31:53 -060010096 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -050010097 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010098 else
James Ketrenosb095c382005-08-24 22:04:42 -050010099 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010100
James Ketrenosea2b26e2005-08-24 21:25:16 -050010101 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10102 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010103
James Ketrenosc848d0a2005-08-24 21:56:24 -050010104 fc = le16_to_cpu(hdr->frame_ctl);
10105 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -060010106
10107 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10108
James Ketrenosb095c382005-08-24 22:04:42 -050010109 if (likely(unicast))
10110 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10111
10112 if (txb->encrypted && !priv->ieee->host_encrypt) {
10113 switch (priv->ieee->sec.level) {
10114 case SEC_LEVEL_3:
10115 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10116 IEEE80211_FCTL_PROTECTED;
10117 /* XXX: ACK flag must be set for CCMP even if it
10118 * is a multicast/broadcast packet, because CCMP
10119 * group communication encrypted by GTK is
10120 * actually done by the AP. */
10121 if (!unicast)
10122 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10123
10124 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10125 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10126 tfd->u.data.key_index = 0;
10127 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10128 break;
10129 case SEC_LEVEL_2:
10130 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10131 IEEE80211_FCTL_PROTECTED;
10132 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10133 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10134 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10135 break;
10136 case SEC_LEVEL_1:
10137 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10138 IEEE80211_FCTL_PROTECTED;
10139 tfd->u.data.key_index = priv->ieee->tx_keyidx;
10140 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
10141 40)
10142 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10143 else
10144 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10145 break;
10146 case SEC_LEVEL_0:
10147 break;
10148 default:
10149 printk(KERN_ERR "Unknow security level %d\n",
10150 priv->ieee->sec.level);
10151 break;
10152 }
10153 } else
10154 /* No hardware encryption */
10155 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10156
Zhu Yie43e3c12006-04-13 17:20:45 +080010157#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010158 if (fc & IEEE80211_STYPE_QOS_DATA)
10159 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
Zhu Yie43e3c12006-04-13 17:20:45 +080010160#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050010161
James Ketrenos43f66a62005-03-25 12:31:53 -060010162 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -050010163 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10164 txb->nr_frags));
10165 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10166 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10167 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10168 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10169 i, le32_to_cpu(tfd->u.data.num_chunks),
10170 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010171 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010172 i, tfd->u.data.num_chunks,
10173 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010174 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -060010175 txb->fragments[i]->len - hdr_len);
10176
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010177 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010178 cpu_to_le32(pci_map_single
10179 (priv->pci_dev,
10180 txb->fragments[i]->data + hdr_len,
10181 txb->fragments[i]->len - hdr_len,
10182 PCI_DMA_TODEVICE));
10183 tfd->u.data.chunk_len[i] =
10184 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -060010185 }
10186
10187 if (i != txb->nr_frags) {
10188 struct sk_buff *skb;
10189 u16 remaining_bytes = 0;
10190 int j;
10191
10192 for (j = i; j < txb->nr_frags; j++)
10193 remaining_bytes += txb->fragments[j]->len - hdr_len;
10194
10195 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10196 remaining_bytes);
10197 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10198 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -050010199 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -060010200 for (j = i; j < txb->nr_frags; j++) {
10201 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010202
James Ketrenos43f66a62005-03-25 12:31:53 -060010203 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010204 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010205 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010206 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010207 }
10208 dev_kfree_skb_any(txb->fragments[i]);
10209 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010210 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010211 cpu_to_le32(pci_map_single
10212 (priv->pci_dev, skb->data,
10213 tfd->u.data.chunk_len[i],
10214 PCI_DMA_TODEVICE));
10215
10216 tfd->u.data.num_chunks =
10217 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
10218 1);
Jeff Garzikbf794512005-07-31 13:07:26 -040010219 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010220 }
10221
10222 /* kick DMA */
10223 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10224 ipw_write32(priv, q->reg_w, q->first_empty);
10225
James Ketrenosf6970142006-02-14 09:10:51 +080010226 if (ipw_queue_space(q) < q->high_mark)
10227 netif_stop_queue(priv->net_dev);
10228
James Ketrenos227d2dc2005-07-28 16:25:55 -050010229 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010230
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010231 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -060010232 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
10233 ieee80211_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -050010234 return NETDEV_TX_OK;
10235}
10236
10237static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10238{
10239 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yie43e3c12006-04-13 17:20:45 +080010240#ifdef CONFIG_IPW2200_QOS
James Ketrenos227d2dc2005-07-28 16:25:55 -050010241 int tx_id = ipw_get_tx_queue_number(priv, pri);
10242 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10243#else
10244 struct clx2_tx_queue *txq = &priv->txq[0];
Zhu Yie43e3c12006-04-13 17:20:45 +080010245#endif /* CONFIG_IPW2200_QOS */
James Ketrenos227d2dc2005-07-28 16:25:55 -050010246
10247 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
10248 return 1;
10249
10250 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010251}
10252
Zhu Yid685b8c2006-04-13 17:20:27 +080010253#ifdef CONFIG_IPW2200_PROMISCUOUS
10254static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
10255 struct ieee80211_txb *txb)
10256{
10257 struct ieee80211_rx_stats dummystats;
10258 struct ieee80211_hdr *hdr;
10259 u8 n;
10260 u16 filter = priv->prom_priv->filter;
10261 int hdr_only = 0;
10262
10263 if (filter & IPW_PROM_NO_TX)
10264 return;
10265
10266 memset(&dummystats, 0, sizeof(dummystats));
10267
10268 /* Filtering of fragment chains is done agains the first fragment */
10269 hdr = (void *)txb->fragments[0]->data;
10270 if (ieee80211_is_management(hdr->frame_ctl)) {
10271 if (filter & IPW_PROM_NO_MGMT)
10272 return;
10273 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10274 hdr_only = 1;
10275 } else if (ieee80211_is_control(hdr->frame_ctl)) {
10276 if (filter & IPW_PROM_NO_CTL)
10277 return;
10278 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10279 hdr_only = 1;
10280 } else if (ieee80211_is_data(hdr->frame_ctl)) {
10281 if (filter & IPW_PROM_NO_DATA)
10282 return;
10283 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10284 hdr_only = 1;
10285 }
10286
10287 for(n=0; n<txb->nr_frags; ++n) {
10288 struct sk_buff *src = txb->fragments[n];
10289 struct sk_buff *dst;
10290 struct ieee80211_radiotap_header *rt_hdr;
10291 int len;
10292
10293 if (hdr_only) {
10294 hdr = (void *)src->data;
10295 len = ieee80211_get_hdrlen(hdr->frame_ctl);
10296 } else
10297 len = src->len;
10298
10299 dst = alloc_skb(
10300 len + IEEE80211_RADIOTAP_HDRLEN, GFP_ATOMIC);
10301 if (!dst) continue;
10302
10303 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10304
10305 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10306 rt_hdr->it_pad = 0;
10307 rt_hdr->it_present = 0; /* after all, it's just an idea */
10308 rt_hdr->it_present |= (1 << IEEE80211_RADIOTAP_CHANNEL);
10309
10310 *(u16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
10311 ieee80211chan2mhz(priv->channel));
10312 if (priv->channel > 14) /* 802.11a */
10313 *(u16*)skb_put(dst, sizeof(u16)) =
10314 cpu_to_le16(IEEE80211_CHAN_OFDM |
10315 IEEE80211_CHAN_5GHZ);
10316 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
10317 *(u16*)skb_put(dst, sizeof(u16)) =
10318 cpu_to_le16(IEEE80211_CHAN_CCK |
10319 IEEE80211_CHAN_2GHZ);
10320 else /* 802.11g */
10321 *(u16*)skb_put(dst, sizeof(u16)) =
10322 cpu_to_le16(IEEE80211_CHAN_OFDM |
10323 IEEE80211_CHAN_2GHZ);
10324
10325 rt_hdr->it_len = dst->len;
10326
10327 memcpy(skb_put(dst, len), src->data, len);
10328
10329 if (!ieee80211_rx(priv->prom_priv->ieee, dst, &dummystats))
10330 dev_kfree_skb_any(dst);
10331 }
10332}
10333#endif
10334
James Ketrenos43f66a62005-03-25 12:31:53 -060010335static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -050010336 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010337{
10338 struct ipw_priv *priv = ieee80211_priv(dev);
10339 unsigned long flags;
James Ketrenos227d2dc2005-07-28 16:25:55 -050010340 int ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010341
10342 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010343 spin_lock_irqsave(&priv->lock, flags);
10344
10345 if (!(priv->status & STATUS_ASSOCIATED)) {
10346 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
10347 priv->ieee->stats.tx_carrier_errors++;
10348 netif_stop_queue(dev);
10349 goto fail_unlock;
10350 }
10351
Zhu Yid685b8c2006-04-13 17:20:27 +080010352#ifdef CONFIG_IPW2200_PROMISCUOUS
10353 if (rtap_iface && netif_running(priv->prom_net_dev))
10354 ipw_handle_promiscuous_tx(priv, txb);
10355#endif
10356
James Ketrenos227d2dc2005-07-28 16:25:55 -050010357 ret = ipw_tx_skb(priv, txb, pri);
10358 if (ret == NETDEV_TX_OK)
10359 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010360 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010361
James Ketrenos227d2dc2005-07-28 16:25:55 -050010362 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010363
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010364 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010365 spin_unlock_irqrestore(&priv->lock, flags);
10366 return 1;
10367}
10368
10369static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
10370{
10371 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -040010372
James Ketrenos43f66a62005-03-25 12:31:53 -060010373 priv->ieee->stats.tx_packets = priv->tx_packets;
10374 priv->ieee->stats.rx_packets = priv->rx_packets;
10375 return &priv->ieee->stats;
10376}
10377
10378static void ipw_net_set_multicast_list(struct net_device *dev)
10379{
10380
10381}
10382
10383static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10384{
10385 struct ipw_priv *priv = ieee80211_priv(dev);
10386 struct sockaddr *addr = p;
10387 if (!is_valid_ether_addr(addr->sa_data))
10388 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +080010389 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010390 priv->config |= CFG_CUSTOM_MAC;
10391 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
10392 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
10393 priv->net_dev->name, MAC_ARG(priv->mac_addr));
James Ketrenosa613bff2005-08-24 21:43:11 -050010394 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +080010395 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010396 return 0;
10397}
10398
Jeff Garzikbf794512005-07-31 13:07:26 -040010399static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010400 struct ethtool_drvinfo *info)
10401{
10402 struct ipw_priv *p = ieee80211_priv(dev);
10403 char vers[64];
10404 char date[32];
10405 u32 len;
10406
10407 strcpy(info->driver, DRV_NAME);
10408 strcpy(info->version, DRV_VERSION);
10409
10410 len = sizeof(vers);
10411 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10412 len = sizeof(date);
10413 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10414
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010415 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010416 vers, date);
10417 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010418 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010419}
10420
10421static u32 ipw_ethtool_get_link(struct net_device *dev)
10422{
10423 struct ipw_priv *priv = ieee80211_priv(dev);
10424 return (priv->status & STATUS_ASSOCIATED) != 0;
10425}
10426
10427static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10428{
James Ketrenosb095c382005-08-24 22:04:42 -050010429 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010430}
10431
10432static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010433 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010434{
10435 struct ipw_priv *p = ieee80211_priv(dev);
10436
James Ketrenosb095c382005-08-24 22:04:42 -050010437 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010438 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010439 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010440 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +080010441 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010442 return 0;
10443}
10444
10445static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010446 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010447{
10448 struct ipw_priv *p = ieee80211_priv(dev);
10449 int i;
10450
James Ketrenosb095c382005-08-24 22:04:42 -050010451 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010452 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010453 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010454 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Adrian Bunk71e585f2006-03-11 04:42:58 +010010455 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10456 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +080010457 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010458 return 0;
10459}
10460
10461static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010462 .get_link = ipw_ethtool_get_link,
10463 .get_drvinfo = ipw_ethtool_get_drvinfo,
10464 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10465 .get_eeprom = ipw_ethtool_get_eeprom,
10466 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010467};
10468
10469static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
10470{
10471 struct ipw_priv *priv = data;
10472 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010473
James Ketrenos43f66a62005-03-25 12:31:53 -060010474 if (!priv)
10475 return IRQ_NONE;
10476
Zhu Yi89c318e2006-06-08 22:19:49 -070010477 spin_lock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010478
10479 if (!(priv->status & STATUS_INT_ENABLED)) {
10480 /* Shared IRQ */
10481 goto none;
10482 }
10483
James Ketrenosb095c382005-08-24 22:04:42 -050010484 inta = ipw_read32(priv, IPW_INTA_RW);
10485 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010486
James Ketrenos43f66a62005-03-25 12:31:53 -060010487 if (inta == 0xFFFFFFFF) {
10488 /* Hardware disappeared */
10489 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10490 goto none;
10491 }
10492
James Ketrenosb095c382005-08-24 22:04:42 -050010493 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010494 /* Shared interrupt */
10495 goto none;
10496 }
10497
10498 /* tell the device to stop sending interrupts */
Zhu Yi89c318e2006-06-08 22:19:49 -070010499 __ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010500
James Ketrenos43f66a62005-03-25 12:31:53 -060010501 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010502 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10503 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010504
James Ketrenos43f66a62005-03-25 12:31:53 -060010505 /* Cache INTA value for our tasklet */
10506 priv->isr_inta = inta;
10507
10508 tasklet_schedule(&priv->irq_tasklet);
10509
Zhu Yi89c318e2006-06-08 22:19:49 -070010510 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010511
10512 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010513 none:
Zhu Yi89c318e2006-06-08 22:19:49 -070010514 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010515 return IRQ_NONE;
10516}
10517
10518static void ipw_rf_kill(void *adapter)
10519{
10520 struct ipw_priv *priv = adapter;
10521 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010522
James Ketrenos43f66a62005-03-25 12:31:53 -060010523 spin_lock_irqsave(&priv->lock, flags);
10524
10525 if (rf_kill_active(priv)) {
10526 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10527 if (priv->workqueue)
10528 queue_delayed_work(priv->workqueue,
10529 &priv->rf_kill, 2 * HZ);
10530 goto exit_unlock;
10531 }
10532
10533 /* RF Kill is now disabled, so bring the device back up */
10534
10535 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10536 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10537 "device\n");
10538
10539 /* we can not do an adapter restart while inside an irq lock */
10540 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010541 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010542 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10543 "enabled\n");
10544
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010545 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010546 spin_unlock_irqrestore(&priv->lock, flags);
10547}
10548
James Ketrenosc848d0a2005-08-24 21:56:24 -050010549static void ipw_bg_rf_kill(void *data)
10550{
10551 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010552 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010553 ipw_rf_kill(data);
Zhu Yi46441512006-01-24 16:37:59 +080010554 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010555}
10556
Adrian Bunka73e22b2006-01-21 01:39:42 +010010557static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010558{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010559 priv->last_seq_num = -1;
10560 priv->last_frag_num = -1;
10561 priv->last_packet_time = 0;
10562
James Ketrenosa613bff2005-08-24 21:43:11 -050010563 netif_carrier_on(priv->net_dev);
10564 if (netif_queue_stopped(priv->net_dev)) {
10565 IPW_DEBUG_NOTIF("waking queue\n");
10566 netif_wake_queue(priv->net_dev);
10567 } else {
10568 IPW_DEBUG_NOTIF("starting queue\n");
10569 netif_start_queue(priv->net_dev);
10570 }
10571
James Ketrenosc848d0a2005-08-24 21:56:24 -050010572 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010573 ipw_reset_stats(priv);
10574 /* Ensure the rate is updated immediately */
10575 priv->last_rate = ipw_get_current_rate(priv);
10576 ipw_gather_stats(priv);
10577 ipw_led_link_up(priv);
10578 notify_wx_assoc_event(priv);
10579
10580 if (priv->config & CFG_BACKGROUND_SCAN)
10581 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10582}
10583
James Ketrenosc848d0a2005-08-24 21:56:24 -050010584static void ipw_bg_link_up(void *data)
10585{
10586 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010587 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010588 ipw_link_up(data);
Zhu Yi46441512006-01-24 16:37:59 +080010589 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010590}
10591
Adrian Bunka73e22b2006-01-21 01:39:42 +010010592static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010593{
10594 ipw_led_link_down(priv);
10595 netif_carrier_off(priv->net_dev);
10596 netif_stop_queue(priv->net_dev);
10597 notify_wx_assoc_event(priv);
10598
10599 /* Cancel any queued work ... */
10600 cancel_delayed_work(&priv->request_scan);
10601 cancel_delayed_work(&priv->adhoc_check);
10602 cancel_delayed_work(&priv->gather_stats);
10603
10604 ipw_reset_stats(priv);
10605
James Ketrenosafbf30a2005-08-25 00:05:33 -050010606 if (!(priv->status & STATUS_EXIT_PENDING)) {
10607 /* Queue up another scan... */
10608 queue_work(priv->workqueue, &priv->request_scan);
10609 }
James Ketrenosa613bff2005-08-24 21:43:11 -050010610}
10611
James Ketrenosc848d0a2005-08-24 21:56:24 -050010612static void ipw_bg_link_down(void *data)
10613{
10614 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010615 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010616 ipw_link_down(data);
Zhu Yi46441512006-01-24 16:37:59 +080010617 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010618}
10619
James Ketrenos43f66a62005-03-25 12:31:53 -060010620static int ipw_setup_deferred_work(struct ipw_priv *priv)
10621{
10622 int ret = 0;
10623
James Ketrenos43f66a62005-03-25 12:31:53 -060010624 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010625 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010626 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010627
James Ketrenosc848d0a2005-08-24 21:56:24 -050010628 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10629 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10630 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
Zhu Yid8bad6d2005-07-13 12:25:38 -050010631 INIT_WORK(&priv->system_config, ipw_system_config, priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010632 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10633 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10634 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10635 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10636 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010637 INIT_WORK(&priv->request_scan,
James Ketrenos43f66a62005-03-25 12:31:53 -060010638 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010639 INIT_WORK(&priv->gather_stats,
James Ketrenosc848d0a2005-08-24 21:56:24 -050010640 (void (*)(void *))ipw_bg_gather_stats, priv);
10641 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10642 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10643 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10644 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10645 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10646 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
James Ketrenosa613bff2005-08-24 21:43:11 -050010647 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010648 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
James Ketrenosa613bff2005-08-24 21:43:11 -050010649 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010650 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10651 priv);
10652 INIT_WORK(&priv->merge_networks,
10653 (void (*)(void *))ipw_merge_adhoc_network, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010654
Zhu Yie43e3c12006-04-13 17:20:45 +080010655#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010656 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10657 priv);
Zhu Yie43e3c12006-04-13 17:20:45 +080010658#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010659
10660 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10661 ipw_irq_tasklet, (unsigned long)priv);
10662
10663 return ret;
10664}
10665
James Ketrenos43f66a62005-03-25 12:31:53 -060010666static void shim__set_security(struct net_device *dev,
10667 struct ieee80211_security *sec)
10668{
10669 struct ipw_priv *priv = ieee80211_priv(dev);
10670 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010671 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010672 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010673 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010674 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010675 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010676 priv->ieee->sec.flags &= ~(1 << i);
10677 else {
10678 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010679 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010680 priv->ieee->sec.flags |= (1 << i);
10681 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010682 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010683 } else if (sec->level != SEC_LEVEL_1)
10684 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010685 }
10686
James Ketrenosb095c382005-08-24 22:04:42 -050010687 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010688 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010689 priv->ieee->sec.active_key = sec->active_key;
10690 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010691 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010692 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010693 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010694 } else
10695 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010696
10697 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010698 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10699 priv->ieee->sec.auth_mode = sec->auth_mode;
10700 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010701 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10702 priv->capability |= CAP_SHARED_KEY;
10703 else
10704 priv->capability &= ~CAP_SHARED_KEY;
10705 priv->status |= STATUS_SECURITY_UPDATED;
10706 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010707
James Ketrenosb095c382005-08-24 22:04:42 -050010708 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10709 priv->ieee->sec.flags |= SEC_ENABLED;
10710 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010711 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010712 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010713 priv->capability |= CAP_PRIVACY_ON;
10714 else
10715 priv->capability &= ~CAP_PRIVACY_ON;
10716 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010717
James Ketrenosafbf30a2005-08-25 00:05:33 -050010718 if (sec->flags & SEC_ENCRYPT)
10719 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010720
James Ketrenosb095c382005-08-24 22:04:42 -050010721 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10722 priv->ieee->sec.level = sec->level;
10723 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010724 priv->status |= STATUS_SECURITY_UPDATED;
10725 }
10726
Zhu Yi1fbfea52005-08-05 17:22:56 +080010727 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10728 ipw_set_hwcrypto_keys(priv);
10729
Jeff Garzikbf794512005-07-31 13:07:26 -040010730 /* To match current functionality of ipw2100 (which works well w/
10731 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010732 * privacy capability changes ... */
10733#if 0
10734 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010735 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -060010736 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010737 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010738 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010739 IPW_DEBUG_ASSOC("Disassociating due to capability "
10740 "change.\n");
10741 ipw_disassociate(priv);
10742 }
10743#endif
10744}
10745
Jeff Garzikbf794512005-07-31 13:07:26 -040010746static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010747 struct ipw_supported_rates *rates)
10748{
10749 /* TODO: Mask out rates based on priv->rates_mask */
10750
10751 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010752 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010753 switch (priv->ieee->freq_band) {
10754 case IEEE80211_52GHZ_BAND:
10755 rates->ieee_mode = IPW_A_MODE;
10756 rates->purpose = IPW_RATE_CAPABILITIES;
10757 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10758 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10759 break;
10760
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010761 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010762 rates->ieee_mode = IPW_G_MODE;
10763 rates->purpose = IPW_RATE_CAPABILITIES;
10764 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10765 IEEE80211_CCK_DEFAULT_RATES_MASK);
10766 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10767 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10768 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10769 }
10770 break;
10771 }
10772
10773 return 0;
10774}
10775
Jeff Garzikbf794512005-07-31 13:07:26 -040010776static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010777{
James Ketrenos43f66a62005-03-25 12:31:53 -060010778 /* This is only called from ipw_up, which resets/reloads the firmware
10779 so, we don't need to first disable the card before we configure
10780 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010781 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010782 goto error;
10783
10784 /* initialize adapter address */
10785 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10786 goto error;
10787
10788 /* set basic system config settings */
10789 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010790
10791 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10792 * Does not support BT priority yet (don't abort or defer our Tx) */
10793 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010794 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010795
10796 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10797 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010798 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010799 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10800 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010801 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010802 }
10803
Zhu Yid685b8c2006-04-13 17:20:27 +080010804#ifdef CONFIG_IPW2200_PROMISCUOUS
10805 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10806 priv->sys_config.accept_all_data_frames = 1;
10807 priv->sys_config.accept_non_directed_frames = 1;
10808 priv->sys_config.accept_all_mgmt_bcpr = 1;
10809 priv->sys_config.accept_all_mgmt_frames = 1;
10810 }
10811#endif
10812
James Ketrenosc848d0a2005-08-24 21:56:24 -050010813 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10814 priv->sys_config.answer_broadcast_ssid_probe = 1;
10815 else
10816 priv->sys_config.answer_broadcast_ssid_probe = 0;
10817
Zhu Yid685b8c2006-04-13 17:20:27 +080010818 if (ipw_send_system_config(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010819 goto error;
10820
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010821 init_supported_rates(priv, &priv->rates);
10822 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010823 goto error;
10824
10825 /* Set request-to-send threshold */
10826 if (priv->rts_threshold) {
10827 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10828 goto error;
10829 }
Zhu Yie43e3c12006-04-13 17:20:45 +080010830#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010831 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10832 ipw_qos_activate(priv, NULL);
Zhu Yie43e3c12006-04-13 17:20:45 +080010833#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010834
10835 if (ipw_set_random_seed(priv))
10836 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010837
James Ketrenos43f66a62005-03-25 12:31:53 -060010838 /* final state transition to the RUN state */
10839 if (ipw_send_host_complete(priv))
10840 goto error;
10841
James Ketrenose6666192005-08-12 09:17:04 -050010842 priv->status |= STATUS_INIT;
10843
10844 ipw_led_init(priv);
10845 ipw_led_radio_on(priv);
10846 priv->notif_missed_beacons = 0;
10847
10848 /* Set hardware WEP key if it is configured. */
10849 if ((priv->capability & CAP_PRIVACY_ON) &&
10850 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10851 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10852 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010853
10854 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010855
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010856 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010857 return -EIO;
10858}
10859
James Ketrenos4f36f802005-08-03 20:36:56 -050010860/*
10861 * NOTE:
10862 *
10863 * These tables have been tested in conjunction with the
10864 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10865 *
10866 * Altering this values, using it on other hardware, or in geographies
10867 * not intended for resale of the above mentioned Intel adapters has
10868 * not been tested.
10869 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080010870 * Remember to update the table in README.ipw2200 when changing this
10871 * table.
10872 *
James Ketrenos4f36f802005-08-03 20:36:56 -050010873 */
10874static const struct ieee80211_geo ipw_geos[] = {
10875 { /* Restricted */
10876 "---",
10877 .bg_channels = 11,
10878 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10879 {2427, 4}, {2432, 5}, {2437, 6},
10880 {2442, 7}, {2447, 8}, {2452, 9},
10881 {2457, 10}, {2462, 11}},
10882 },
10883
10884 { /* Custom US/Canada */
10885 "ZZF",
10886 .bg_channels = 11,
10887 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10888 {2427, 4}, {2432, 5}, {2437, 6},
10889 {2442, 7}, {2447, 8}, {2452, 9},
10890 {2457, 10}, {2462, 11}},
10891 .a_channels = 8,
10892 .a = {{5180, 36},
10893 {5200, 40},
10894 {5220, 44},
10895 {5240, 48},
10896 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10897 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10898 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10899 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10900 },
10901
10902 { /* Rest of World */
10903 "ZZD",
10904 .bg_channels = 13,
10905 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10906 {2427, 4}, {2432, 5}, {2437, 6},
10907 {2442, 7}, {2447, 8}, {2452, 9},
10908 {2457, 10}, {2462, 11}, {2467, 12},
10909 {2472, 13}},
10910 },
10911
10912 { /* Custom USA & Europe & High */
10913 "ZZA",
10914 .bg_channels = 11,
10915 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10916 {2427, 4}, {2432, 5}, {2437, 6},
10917 {2442, 7}, {2447, 8}, {2452, 9},
10918 {2457, 10}, {2462, 11}},
10919 .a_channels = 13,
10920 .a = {{5180, 36},
10921 {5200, 40},
10922 {5220, 44},
10923 {5240, 48},
10924 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10925 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10926 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10927 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10928 {5745, 149},
10929 {5765, 153},
10930 {5785, 157},
10931 {5805, 161},
10932 {5825, 165}},
10933 },
10934
10935 { /* Custom NA & Europe */
10936 "ZZB",
10937 .bg_channels = 11,
10938 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10939 {2427, 4}, {2432, 5}, {2437, 6},
10940 {2442, 7}, {2447, 8}, {2452, 9},
10941 {2457, 10}, {2462, 11}},
10942 .a_channels = 13,
10943 .a = {{5180, 36},
10944 {5200, 40},
10945 {5220, 44},
10946 {5240, 48},
10947 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10948 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10949 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10950 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10951 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10952 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10953 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10954 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10955 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10956 },
10957
10958 { /* Custom Japan */
10959 "ZZC",
10960 .bg_channels = 11,
10961 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10962 {2427, 4}, {2432, 5}, {2437, 6},
10963 {2442, 7}, {2447, 8}, {2452, 9},
10964 {2457, 10}, {2462, 11}},
10965 .a_channels = 4,
10966 .a = {{5170, 34}, {5190, 38},
10967 {5210, 42}, {5230, 46}},
10968 },
10969
10970 { /* Custom */
10971 "ZZM",
10972 .bg_channels = 11,
10973 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10974 {2427, 4}, {2432, 5}, {2437, 6},
10975 {2442, 7}, {2447, 8}, {2452, 9},
10976 {2457, 10}, {2462, 11}},
10977 },
10978
10979 { /* Europe */
10980 "ZZE",
10981 .bg_channels = 13,
10982 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10983 {2427, 4}, {2432, 5}, {2437, 6},
10984 {2442, 7}, {2447, 8}, {2452, 9},
10985 {2457, 10}, {2462, 11}, {2467, 12},
10986 {2472, 13}},
10987 .a_channels = 19,
10988 .a = {{5180, 36},
10989 {5200, 40},
10990 {5220, 44},
10991 {5240, 48},
10992 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10993 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10994 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10995 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10996 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10997 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10998 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10999 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
11000 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
11001 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
11002 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
11003 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
11004 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
11005 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
11006 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
11007 },
11008
11009 { /* Custom Japan */
11010 "ZZJ",
11011 .bg_channels = 14,
11012 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11013 {2427, 4}, {2432, 5}, {2437, 6},
11014 {2442, 7}, {2447, 8}, {2452, 9},
11015 {2457, 10}, {2462, 11}, {2467, 12},
11016 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
11017 .a_channels = 4,
11018 .a = {{5170, 34}, {5190, 38},
11019 {5210, 42}, {5230, 46}},
11020 },
11021
James Ketrenos03520572005-10-19 16:12:31 -050011022 { /* Rest of World */
11023 "ZZR",
11024 .bg_channels = 14,
11025 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11026 {2427, 4}, {2432, 5}, {2437, 6},
11027 {2442, 7}, {2447, 8}, {2452, 9},
11028 {2457, 10}, {2462, 11}, {2467, 12},
11029 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
11030 IEEE80211_CH_PASSIVE_ONLY}},
11031 },
11032
James Ketrenos4f36f802005-08-03 20:36:56 -050011033 { /* High Band */
11034 "ZZH",
11035 .bg_channels = 13,
11036 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11037 {2427, 4}, {2432, 5}, {2437, 6},
11038 {2442, 7}, {2447, 8}, {2452, 9},
11039 {2457, 10}, {2462, 11},
11040 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
11041 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
11042 .a_channels = 4,
11043 .a = {{5745, 149}, {5765, 153},
11044 {5785, 157}, {5805, 161}},
11045 },
11046
11047 { /* Custom Europe */
11048 "ZZG",
11049 .bg_channels = 13,
11050 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11051 {2427, 4}, {2432, 5}, {2437, 6},
11052 {2442, 7}, {2447, 8}, {2452, 9},
11053 {2457, 10}, {2462, 11},
11054 {2467, 12}, {2472, 13}},
11055 .a_channels = 4,
11056 .a = {{5180, 36}, {5200, 40},
11057 {5220, 44}, {5240, 48}},
11058 },
11059
11060 { /* Europe */
11061 "ZZK",
11062 .bg_channels = 13,
11063 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11064 {2427, 4}, {2432, 5}, {2437, 6},
11065 {2442, 7}, {2447, 8}, {2452, 9},
11066 {2457, 10}, {2462, 11},
11067 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
11068 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
11069 .a_channels = 24,
11070 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
11071 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
11072 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
11073 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
11074 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11075 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11076 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11077 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11078 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
11079 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
11080 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
11081 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
11082 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
11083 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
11084 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
11085 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
11086 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
11087 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
11088 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
11089 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11090 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11091 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11092 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11093 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11094 },
11095
11096 { /* Europe */
11097 "ZZL",
11098 .bg_channels = 11,
11099 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11100 {2427, 4}, {2432, 5}, {2437, 6},
11101 {2442, 7}, {2447, 8}, {2452, 9},
11102 {2457, 10}, {2462, 11}},
11103 .a_channels = 13,
11104 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
11105 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
11106 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
11107 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
11108 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11109 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11110 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11111 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11112 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11113 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11114 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11115 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11116 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11117 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050011118};
11119
James Ketrenos43f66a62005-03-25 12:31:53 -060011120#define MAX_HW_RESTARTS 5
11121static int ipw_up(struct ipw_priv *priv)
11122{
James Ketrenos4f36f802005-08-03 20:36:56 -050011123 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060011124
11125 if (priv->status & STATUS_EXIT_PENDING)
11126 return -EIO;
11127
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011128 if (cmdlog && !priv->cmdlog) {
11129 priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
11130 GFP_KERNEL);
11131 if (priv->cmdlog == NULL) {
11132 IPW_ERROR("Error allocating %d command log entries.\n",
11133 cmdlog);
Zhu Yid0b526b2006-04-13 17:19:50 +080011134 return -ENOMEM;
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011135 } else {
11136 memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
11137 priv->cmdlog_len = cmdlog;
11138 }
11139 }
11140
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011141 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040011142 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060011143 * Also start the clocks. */
11144 rc = ipw_load(priv);
11145 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050011146 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011147 return rc;
11148 }
11149
11150 ipw_init_ordinals(priv);
11151 if (!(priv->config & CFG_CUSTOM_MAC))
11152 eeprom_parse_mac(priv, priv->mac_addr);
11153 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
11154
James Ketrenos4f36f802005-08-03 20:36:56 -050011155 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11156 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11157 ipw_geos[j].name, 3))
11158 break;
11159 }
James Ketrenos03520572005-10-19 16:12:31 -050011160 if (j == ARRAY_SIZE(ipw_geos)) {
11161 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11162 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11163 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11164 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050011165 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050011166 }
Larry Finger1867b112006-02-28 09:48:28 -060011167 if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050011168 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060011169 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050011170 }
11171
James Ketrenosb095c382005-08-24 22:04:42 -050011172 if (priv->status & STATUS_RF_KILL_SW) {
11173 IPW_WARNING("Radio disabled by module parameter.\n");
11174 return 0;
11175 } else if (rf_kill_active(priv)) {
11176 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11177 "Kill switch must be turned off for "
11178 "wireless networking to work.\n");
11179 queue_delayed_work(priv->workqueue, &priv->rf_kill,
11180 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060011181 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050011182 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011183
11184 rc = ipw_config(priv);
11185 if (!rc) {
11186 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011187
James Ketrenose6666192005-08-12 09:17:04 -050011188 /* If configure to try and auto-associate, kick
11189 * off a scan. */
11190 queue_work(priv->workqueue, &priv->request_scan);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011191
James Ketrenos43f66a62005-03-25 12:31:53 -060011192 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011193 }
Jeff Garzikbf794512005-07-31 13:07:26 -040011194
James Ketrenosc848d0a2005-08-24 21:56:24 -050011195 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011196 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11197 i, MAX_HW_RESTARTS);
11198
11199 /* We had an error bringing up the hardware, so take it
11200 * all the way back down so we can try again */
11201 ipw_down(priv);
11202 }
11203
Jeff Garzikbf794512005-07-31 13:07:26 -040011204 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060011205 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011206 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011207
James Ketrenos43f66a62005-03-25 12:31:53 -060011208 return -EIO;
11209}
11210
James Ketrenosc848d0a2005-08-24 21:56:24 -050011211static void ipw_bg_up(void *data)
11212{
11213 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080011214 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011215 ipw_up(data);
Zhu Yi46441512006-01-24 16:37:59 +080011216 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011217}
11218
James Ketrenosb095c382005-08-24 22:04:42 -050011219static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060011220{
James Ketrenosb095c382005-08-24 22:04:42 -050011221 int i;
11222
11223 if (priv->status & STATUS_SCANNING) {
11224 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11225 ipw_abort_scan(priv);
11226 }
11227
11228 if (priv->status & STATUS_ASSOCIATED) {
11229 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11230 ipw_disassociate(priv);
11231 }
11232
11233 ipw_led_shutdown(priv);
11234
11235 /* Wait up to 1s for status to change to not scanning and not
11236 * associated (disassociation can take a while for a ful 802.11
11237 * exchange */
11238 for (i = 1000; i && (priv->status &
11239 (STATUS_DISASSOCIATING |
11240 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11241 udelay(10);
11242
11243 if (priv->status & (STATUS_DISASSOCIATING |
11244 STATUS_ASSOCIATED | STATUS_SCANNING))
11245 IPW_DEBUG_INFO("Still associated or scanning...\n");
11246 else
11247 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11248
James Ketrenosc848d0a2005-08-24 21:56:24 -050011249 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060011250 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050011251
11252 priv->status &= ~STATUS_INIT;
11253}
11254
James Ketrenos43f66a62005-03-25 12:31:53 -060011255static void ipw_down(struct ipw_priv *priv)
11256{
James Ketrenosb095c382005-08-24 22:04:42 -050011257 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11258
11259 priv->status |= STATUS_EXIT_PENDING;
11260
11261 if (ipw_is_init(priv))
11262 ipw_deinit(priv);
11263
11264 /* Wipe out the EXIT_PENDING status bit if we are not actually
11265 * exiting the module */
11266 if (!exit_pending)
11267 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011268
11269 /* tell the device to stop sending interrupts */
11270 ipw_disable_interrupts(priv);
11271
11272 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050011273 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011274 netif_carrier_off(priv->net_dev);
11275 netif_stop_queue(priv->net_dev);
11276
11277 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050011278
11279 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011280}
11281
James Ketrenosc848d0a2005-08-24 21:56:24 -050011282static void ipw_bg_down(void *data)
11283{
11284 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080011285 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011286 ipw_down(data);
Zhu Yi46441512006-01-24 16:37:59 +080011287 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011288}
11289
11290/* Called by register_netdev() */
11291static int ipw_net_init(struct net_device *dev)
11292{
11293 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +080011294 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011295
James Ketrenosc848d0a2005-08-24 21:56:24 -050011296 if (ipw_up(priv)) {
Zhu Yi46441512006-01-24 16:37:59 +080011297 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011298 return -EIO;
James Ketrenos43f66a62005-03-25 12:31:53 -060011299 }
11300
Zhu Yi46441512006-01-24 16:37:59 +080011301 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011302 return 0;
11303}
11304
11305/* PCI driver stuff */
11306static struct pci_device_id card_ids[] = {
11307 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11308 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11309 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11310 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11311 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11312 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11313 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11314 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11315 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11316 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11317 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11318 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11319 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11320 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11321 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11322 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11323 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
11324 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011325 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
James Ketrenosa613bff2005-08-24 21:43:11 -050011326 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011327 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
11328 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040011329
James Ketrenos43f66a62005-03-25 12:31:53 -060011330 /* required last entry */
11331 {0,}
11332};
11333
11334MODULE_DEVICE_TABLE(pci, card_ids);
11335
11336static struct attribute *ipw_sysfs_entries[] = {
11337 &dev_attr_rf_kill.attr,
11338 &dev_attr_direct_dword.attr,
11339 &dev_attr_indirect_byte.attr,
11340 &dev_attr_indirect_dword.attr,
11341 &dev_attr_mem_gpio_reg.attr,
11342 &dev_attr_command_event_reg.attr,
11343 &dev_attr_nic_type.attr,
11344 &dev_attr_status.attr,
11345 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011346 &dev_attr_error.attr,
11347 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011348 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011349 &dev_attr_eeprom_delay.attr,
11350 &dev_attr_ucode_version.attr,
11351 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011352 &dev_attr_scan_age.attr,
11353 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011354 &dev_attr_speed_scan.attr,
11355 &dev_attr_net_stats.attr,
Zhu Yid685b8c2006-04-13 17:20:27 +080011356#ifdef CONFIG_IPW2200_PROMISCUOUS
11357 &dev_attr_rtap_iface.attr,
11358 &dev_attr_rtap_filter.attr,
11359#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011360 NULL
11361};
11362
11363static struct attribute_group ipw_attribute_group = {
11364 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011365 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011366};
11367
Zhu Yid685b8c2006-04-13 17:20:27 +080011368#ifdef CONFIG_IPW2200_PROMISCUOUS
11369static int ipw_prom_open(struct net_device *dev)
11370{
11371 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11372 struct ipw_priv *priv = prom_priv->priv;
11373
11374 IPW_DEBUG_INFO("prom dev->open\n");
11375 netif_carrier_off(dev);
11376 netif_stop_queue(dev);
11377
11378 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11379 priv->sys_config.accept_all_data_frames = 1;
11380 priv->sys_config.accept_non_directed_frames = 1;
11381 priv->sys_config.accept_all_mgmt_bcpr = 1;
11382 priv->sys_config.accept_all_mgmt_frames = 1;
11383
11384 ipw_send_system_config(priv);
11385 }
11386
11387 return 0;
11388}
11389
11390static int ipw_prom_stop(struct net_device *dev)
11391{
11392 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11393 struct ipw_priv *priv = prom_priv->priv;
11394
11395 IPW_DEBUG_INFO("prom dev->stop\n");
11396
11397 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11398 priv->sys_config.accept_all_data_frames = 0;
11399 priv->sys_config.accept_non_directed_frames = 0;
11400 priv->sys_config.accept_all_mgmt_bcpr = 0;
11401 priv->sys_config.accept_all_mgmt_frames = 0;
11402
11403 ipw_send_system_config(priv);
11404 }
11405
11406 return 0;
11407}
11408
11409static int ipw_prom_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
11410{
11411 IPW_DEBUG_INFO("prom dev->xmit\n");
11412 netif_stop_queue(dev);
11413 return -EOPNOTSUPP;
11414}
11415
11416static struct net_device_stats *ipw_prom_get_stats(struct net_device *dev)
11417{
11418 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11419 return &prom_priv->ieee->stats;
11420}
11421
11422static int ipw_prom_alloc(struct ipw_priv *priv)
11423{
11424 int rc = 0;
11425
11426 if (priv->prom_net_dev)
11427 return -EPERM;
11428
11429 priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv));
11430 if (priv->prom_net_dev == NULL)
11431 return -ENOMEM;
11432
11433 priv->prom_priv = ieee80211_priv(priv->prom_net_dev);
11434 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11435 priv->prom_priv->priv = priv;
11436
11437 strcpy(priv->prom_net_dev->name, "rtap%d");
11438
11439 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
11440 priv->prom_net_dev->open = ipw_prom_open;
11441 priv->prom_net_dev->stop = ipw_prom_stop;
11442 priv->prom_net_dev->get_stats = ipw_prom_get_stats;
11443 priv->prom_net_dev->hard_start_xmit = ipw_prom_hard_start_xmit;
11444
11445 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
11446
11447 rc = register_netdev(priv->prom_net_dev);
11448 if (rc) {
11449 free_ieee80211(priv->prom_net_dev);
11450 priv->prom_net_dev = NULL;
11451 return rc;
11452 }
11453
11454 return 0;
11455}
11456
11457static void ipw_prom_free(struct ipw_priv *priv)
11458{
11459 if (!priv->prom_net_dev)
11460 return;
11461
11462 unregister_netdev(priv->prom_net_dev);
11463 free_ieee80211(priv->prom_net_dev);
11464
11465 priv->prom_net_dev = NULL;
11466}
11467
11468#endif
11469
11470
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011471static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011472{
11473 int err = 0;
11474 struct net_device *net_dev;
11475 void __iomem *base;
11476 u32 length, val;
11477 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011478 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011479
11480 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
11481 if (net_dev == NULL) {
11482 err = -ENOMEM;
11483 goto out;
11484 }
11485
11486 priv = ieee80211_priv(net_dev);
11487 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011488
James Ketrenos43f66a62005-03-25 12:31:53 -060011489 priv->net_dev = net_dev;
11490 priv->pci_dev = pdev;
Brice Goglin0f52bf92005-12-01 01:41:46 -080011491#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060011492 ipw_debug_level = debug;
11493#endif
Zhu Yi89c318e2006-06-08 22:19:49 -070011494 spin_lock_init(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060011495 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011496 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11497 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011498
Zhu Yi46441512006-01-24 16:37:59 +080011499 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011500 if (pci_enable_device(pdev)) {
11501 err = -ENODEV;
11502 goto out_free_ieee80211;
11503 }
11504
11505 pci_set_master(pdev);
11506
Tobias Klauser0e08b442005-06-20 14:28:41 -070011507 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -040011508 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -070011509 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060011510 if (err) {
11511 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11512 goto out_pci_disable_device;
11513 }
11514
11515 pci_set_drvdata(pdev, priv);
11516
11517 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011518 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011519 goto out_pci_disable_device;
11520
Jeff Garzikbf794512005-07-31 13:07:26 -040011521 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011522 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011523 pci_read_config_dword(pdev, 0x40, &val);
11524 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011525 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011526
James Ketrenos43f66a62005-03-25 12:31:53 -060011527 length = pci_resource_len(pdev, 0);
11528 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011529
James Ketrenos43f66a62005-03-25 12:31:53 -060011530 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
11531 if (!base) {
11532 err = -ENODEV;
11533 goto out_pci_release_regions;
11534 }
11535
11536 priv->hw_base = base;
11537 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11538 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11539
11540 err = ipw_setup_deferred_work(priv);
11541 if (err) {
11542 IPW_ERROR("Unable to setup deferred work\n");
11543 goto out_iounmap;
11544 }
11545
James Ketrenosb095c382005-08-24 22:04:42 -050011546 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011547
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011548 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011549 if (err) {
11550 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11551 goto out_destroy_workqueue;
11552 }
11553
11554 SET_MODULE_OWNER(net_dev);
11555 SET_NETDEV_DEV(net_dev, &pdev->dev);
11556
Zhu Yi46441512006-01-24 16:37:59 +080011557 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011558
James Ketrenos43f66a62005-03-25 12:31:53 -060011559 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11560 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011561 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011562
Zhu Yie43e3c12006-04-13 17:20:45 +080011563#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080011564 priv->ieee->is_qos_active = ipw_is_qos_active;
James Ketrenos3b9990c2005-08-19 13:18:55 -050011565 priv->ieee->handle_probe_response = ipw_handle_beacon;
11566 priv->ieee->handle_beacon = ipw_handle_probe_response;
11567 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
Zhu Yie43e3c12006-04-13 17:20:45 +080011568#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011569
James Ketrenosc848d0a2005-08-24 21:56:24 -050011570 priv->ieee->perfect_rssi = -20;
11571 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011572
11573 net_dev->open = ipw_net_open;
11574 net_dev->stop = ipw_net_stop;
11575 net_dev->init = ipw_net_init;
11576 net_dev->get_stats = ipw_net_get_stats;
11577 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11578 net_dev->set_mac_address = ipw_net_set_mac_address;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011579 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011580 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011581 net_dev->wireless_handlers = &ipw_wx_handler_def;
11582 net_dev->ethtool_ops = &ipw_ethtool_ops;
11583 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011584 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011585 net_dev->mem_start = pci_resource_start(pdev, 0);
11586 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11587
11588 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11589 if (err) {
11590 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011591 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011592 goto out_release_irq;
11593 }
11594
Zhu Yi46441512006-01-24 16:37:59 +080011595 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011596 err = register_netdev(net_dev);
11597 if (err) {
11598 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011599 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011600 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011601
Zhu Yid685b8c2006-04-13 17:20:27 +080011602#ifdef CONFIG_IPW2200_PROMISCUOUS
11603 if (rtap_iface) {
11604 err = ipw_prom_alloc(priv);
11605 if (err) {
11606 IPW_ERROR("Failed to register promiscuous network "
11607 "device (error %d).\n", err);
11608 unregister_netdev(priv->net_dev);
11609 goto out_remove_sysfs;
11610 }
11611 }
11612#endif
11613
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011614 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11615 "channels, %d 802.11a channels)\n",
11616 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11617 priv->ieee->geo.a_channels);
11618
James Ketrenos43f66a62005-03-25 12:31:53 -060011619 return 0;
11620
James Ketrenosa613bff2005-08-24 21:43:11 -050011621 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011622 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011623 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011624 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011625 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011626 destroy_workqueue(priv->workqueue);
11627 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011628 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011629 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011630 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011631 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011632 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011633 pci_disable_device(pdev);
11634 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011635 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -060011636 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011637 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011638 return err;
11639}
11640
11641static void ipw_pci_remove(struct pci_dev *pdev)
11642{
11643 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011644 struct list_head *p, *q;
11645 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011646
James Ketrenos43f66a62005-03-25 12:31:53 -060011647 if (!priv)
11648 return;
11649
Zhu Yi46441512006-01-24 16:37:59 +080011650 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011651
James Ketrenosafbf30a2005-08-25 00:05:33 -050011652 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011653 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011654 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11655
Zhu Yi46441512006-01-24 16:37:59 +080011656 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011657
11658 unregister_netdev(priv->net_dev);
11659
11660 if (priv->rxq) {
11661 ipw_rx_queue_free(priv, priv->rxq);
11662 priv->rxq = NULL;
11663 }
11664 ipw_tx_queue_free(priv);
11665
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011666 if (priv->cmdlog) {
11667 kfree(priv->cmdlog);
11668 priv->cmdlog = NULL;
11669 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011670 /* ipw_down will ensure that there is no more pending work
11671 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011672 cancel_delayed_work(&priv->adhoc_check);
11673 cancel_delayed_work(&priv->gather_stats);
11674 cancel_delayed_work(&priv->request_scan);
11675 cancel_delayed_work(&priv->rf_kill);
11676 cancel_delayed_work(&priv->scan_check);
11677 destroy_workqueue(priv->workqueue);
11678 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011679
James Ketrenosafbf30a2005-08-25 00:05:33 -050011680 /* Free MAC hash list for ADHOC */
11681 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11682 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011683 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011684 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011685 }
11686 }
11687
Jesper Juhl8f760782006-06-27 02:55:06 -070011688 kfree(priv->error);
11689 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011690
Zhu Yid685b8c2006-04-13 17:20:27 +080011691#ifdef CONFIG_IPW2200_PROMISCUOUS
11692 ipw_prom_free(priv);
11693#endif
11694
James Ketrenos43f66a62005-03-25 12:31:53 -060011695 free_irq(pdev->irq, priv);
11696 iounmap(priv->hw_base);
11697 pci_release_regions(pdev);
11698 pci_disable_device(pdev);
11699 pci_set_drvdata(pdev, NULL);
11700 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011701 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011702}
11703
James Ketrenos43f66a62005-03-25 12:31:53 -060011704#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011705static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011706{
11707 struct ipw_priv *priv = pci_get_drvdata(pdev);
11708 struct net_device *dev = priv->net_dev;
11709
11710 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11711
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011712 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011713 ipw_down(priv);
11714
11715 /* Remove the PRESENT state of the device */
11716 netif_device_detach(dev);
11717
James Ketrenos43f66a62005-03-25 12:31:53 -060011718 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011719 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011720 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011721
James Ketrenos43f66a62005-03-25 12:31:53 -060011722 return 0;
11723}
11724
11725static int ipw_pci_resume(struct pci_dev *pdev)
11726{
11727 struct ipw_priv *priv = pci_get_drvdata(pdev);
11728 struct net_device *dev = priv->net_dev;
11729 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011730
James Ketrenos43f66a62005-03-25 12:31:53 -060011731 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11732
James Ketrenosea2b26e2005-08-24 21:25:16 -050011733 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011734 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011735 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011736
James Ketrenos43f66a62005-03-25 12:31:53 -060011737 /*
11738 * Suspend/Resume resets the PCI configuration space, so we have to
11739 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11740 * from interfering with C3 CPU state. pci_restore_state won't help
11741 * here since it only restores the first 64 bytes pci config header.
11742 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011743 pci_read_config_dword(pdev, 0x40, &val);
11744 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011745 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11746
11747 /* Set the device back into the PRESENT state; this will also wake
11748 * the queue of needed */
11749 netif_device_attach(dev);
11750
11751 /* Bring the device back up */
11752 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011753
James Ketrenos43f66a62005-03-25 12:31:53 -060011754 return 0;
11755}
11756#endif
11757
11758/* driver initialization stuff */
11759static struct pci_driver ipw_driver = {
11760 .name = DRV_NAME,
11761 .id_table = card_ids,
11762 .probe = ipw_pci_probe,
11763 .remove = __devexit_p(ipw_pci_remove),
11764#ifdef CONFIG_PM
11765 .suspend = ipw_pci_suspend,
11766 .resume = ipw_pci_resume,
11767#endif
11768};
11769
11770static int __init ipw_init(void)
11771{
11772 int ret;
11773
11774 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11775 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11776
11777 ret = pci_module_init(&ipw_driver);
11778 if (ret) {
11779 IPW_ERROR("Unable to initialize PCI module\n");
11780 return ret;
11781 }
11782
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011783 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011784 if (ret) {
11785 IPW_ERROR("Unable to create driver sysfs file\n");
11786 pci_unregister_driver(&ipw_driver);
11787 return ret;
11788 }
11789
11790 return ret;
11791}
11792
11793static void __exit ipw_exit(void)
11794{
11795 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11796 pci_unregister_driver(&ipw_driver);
11797}
11798
11799module_param(disable, int, 0444);
11800MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11801
11802module_param(associate, int, 0444);
11803MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11804
11805module_param(auto_create, int, 0444);
11806MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11807
James Ketrenosa613bff2005-08-24 21:43:11 -050011808module_param(led, int, 0444);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011809MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011810
Zhu Yi3e1555b2006-03-06 05:48:37 +080011811#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060011812module_param(debug, int, 0444);
11813MODULE_PARM_DESC(debug, "debug output mask");
Zhu Yi3e1555b2006-03-06 05:48:37 +080011814#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011815
11816module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011817MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011818
Zhu Yid685b8c2006-04-13 17:20:27 +080011819#ifdef CONFIG_IPW2200_PROMISCUOUS
11820module_param(rtap_iface, int, 0444);
11821MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
11822#endif
11823
Zhu Yie43e3c12006-04-13 17:20:45 +080011824#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050011825module_param(qos_enable, int, 0444);
11826MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060011827
James Ketrenosb095c382005-08-24 22:04:42 -050011828module_param(qos_burst_enable, int, 0444);
11829MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11830
11831module_param(qos_no_ack_mask, int, 0444);
11832MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11833
11834module_param(burst_duration_CCK, int, 0444);
11835MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11836
11837module_param(burst_duration_OFDM, int, 0444);
11838MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
Zhu Yie43e3c12006-04-13 17:20:45 +080011839#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011840
11841#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -060011842module_param(mode, int, 0444);
11843MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11844#else
11845module_param(mode, int, 0444);
11846MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11847#endif
11848
Zhu Yi810dabd2006-01-24 16:36:59 +080011849module_param(bt_coexist, int, 0444);
11850MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
11851
James Ketrenosb095c382005-08-24 22:04:42 -050011852module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080011853MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050011854
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011855module_param(cmdlog, int, 0444);
11856MODULE_PARM_DESC(cmdlog,
11857 "allocate a ring buffer for logging firmware commands");
11858
Zhu Yi4bfdb912006-01-24 16:37:16 +080011859module_param(roaming, int, 0444);
11860MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
11861
Zhu Yid2b83e12006-04-13 17:19:36 +080011862module_param(antenna, int, 0444);
11863MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
11864
James Ketrenos43f66a62005-03-25 12:31:53 -060011865module_exit(ipw_exit);
11866module_init(ipw_init);