blob: 946d5b4c8f757b289d79d83151d2bd8d75687846 [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
James Ketrenos43f66a62005-03-25 12:31:53 -0600570static char *ipw_error_desc(u32 val)
571{
572 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400573 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600574 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400575 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600576 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400577 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600578 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400579 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600580 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400581 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500582 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400583 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500584 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400585 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500586 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400587 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500588 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400589 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500590 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400591 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500592 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400593 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500594 return "DMA_STATUS";
595 case IPW_FW_ERROR_DINO_ERROR:
596 return "DINO_ERROR";
597 case IPW_FW_ERROR_EEPROM_ERROR:
598 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400599 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500600 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400601 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500602 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400603 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500604 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600605 }
606}
607
James Ketrenosb39860c2005-08-12 09:36:32 -0500608static void ipw_dump_error_log(struct ipw_priv *priv,
609 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600610{
James Ketrenosb39860c2005-08-12 09:36:32 -0500611 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600612
James Ketrenosb39860c2005-08-12 09:36:32 -0500613 if (!error) {
614 IPW_ERROR("Error allocating and capturing error log. "
615 "Nothing to dump.\n");
616 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600617 }
618
James Ketrenosb39860c2005-08-12 09:36:32 -0500619 IPW_ERROR("Start IPW Error Log Dump:\n");
620 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
621 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600622
James Ketrenosb39860c2005-08-12 09:36:32 -0500623 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400624 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500625 ipw_error_desc(error->elem[i].desc),
626 error->elem[i].time,
627 error->elem[i].blink1,
628 error->elem[i].blink2,
629 error->elem[i].link1,
630 error->elem[i].link2, error->elem[i].data);
631 for (i = 0; i < error->log_len; i++)
632 IPW_ERROR("%i\t0x%08x\t%i\n",
633 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500634 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600635}
James Ketrenos43f66a62005-03-25 12:31:53 -0600636
James Ketrenosc848d0a2005-08-24 21:56:24 -0500637static inline int ipw_is_init(struct ipw_priv *priv)
638{
639 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600640}
641
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400642static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600643{
644 u32 addr, field_info, field_len, field_count, total_len;
645
646 IPW_DEBUG_ORD("ordinal = %i\n", ord);
647
648 if (!priv || !val || !len) {
649 IPW_DEBUG_ORD("Invalid argument\n");
650 return -EINVAL;
651 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400652
James Ketrenos43f66a62005-03-25 12:31:53 -0600653 /* verify device ordinal tables have been initialized */
654 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
655 IPW_DEBUG_ORD("Access ordinals before initialization\n");
656 return -EINVAL;
657 }
658
659 switch (IPW_ORD_TABLE_ID_MASK & ord) {
660 case IPW_ORD_TABLE_0_MASK:
661 /*
662 * TABLE 0: Direct access to a table of 32 bit values
663 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400664 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600665 * read from the table
666 */
667
668 /* remove the table id from the ordinal */
669 ord &= IPW_ORD_TABLE_VALUE_MASK;
670
671 /* boundary check */
672 if (ord > priv->table0_len) {
673 IPW_DEBUG_ORD("ordinal value (%i) longer then "
674 "max (%i)\n", ord, priv->table0_len);
675 return -EINVAL;
676 }
677
678 /* verify we have enough room to store the value */
679 if (*len < sizeof(u32)) {
680 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200681 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600682 return -EINVAL;
683 }
684
685 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400686 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600687
688 *len = sizeof(u32);
689 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400690 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600691 break;
692
693 case IPW_ORD_TABLE_1_MASK:
694 /*
695 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400696 *
697 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600698 * representing starting addr for the data (which is
699 * also a u32)
700 */
701
702 /* remove the table id from the ordinal */
703 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400704
James Ketrenos43f66a62005-03-25 12:31:53 -0600705 /* boundary check */
706 if (ord > priv->table1_len) {
707 IPW_DEBUG_ORD("ordinal value too long\n");
708 return -EINVAL;
709 }
710
711 /* verify we have enough room to store the value */
712 if (*len < sizeof(u32)) {
713 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200714 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600715 return -EINVAL;
716 }
717
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400718 *((u32 *) val) =
719 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600720 *len = sizeof(u32);
721 break;
722
723 case IPW_ORD_TABLE_2_MASK:
724 /*
725 * TABLE 2: Indirect access to a table of variable sized values
726 *
727 * This table consist of six values, each containing
728 * - dword containing the starting offset of the data
729 * - dword containing the lengh in the first 16bits
730 * and the count in the second 16bits
731 */
732
733 /* remove the table id from the ordinal */
734 ord &= IPW_ORD_TABLE_VALUE_MASK;
735
736 /* boundary check */
737 if (ord > priv->table2_len) {
738 IPW_DEBUG_ORD("ordinal value too long\n");
739 return -EINVAL;
740 }
741
742 /* get the address of statistic */
743 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400744
745 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600746 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400747 field_info =
748 ipw_read_reg32(priv,
749 priv->table2_addr + (ord << 3) +
750 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400751
James Ketrenos43f66a62005-03-25 12:31:53 -0600752 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400753 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400754
James Ketrenos43f66a62005-03-25 12:31:53 -0600755 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400756 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400757
James Ketrenos43f66a62005-03-25 12:31:53 -0600758 /* abort if not enought memory */
759 total_len = field_len * field_count;
760 if (total_len > *len) {
761 *len = total_len;
762 return -EINVAL;
763 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400764
James Ketrenos43f66a62005-03-25 12:31:53 -0600765 *len = total_len;
766 if (!total_len)
767 return 0;
768
769 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400770 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600771 addr, total_len, field_info);
772 ipw_read_indirect(priv, addr, val, total_len);
773 break;
774
775 default:
776 IPW_DEBUG_ORD("Invalid ordinal!\n");
777 return -EINVAL;
778
779 }
780
James Ketrenos43f66a62005-03-25 12:31:53 -0600781 return 0;
782}
783
784static void ipw_init_ordinals(struct ipw_priv *priv)
785{
786 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400787 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600788
789 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
790 priv->table0_addr, priv->table0_len);
791
792 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
793 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
794
795 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
796 priv->table1_addr, priv->table1_len);
797
798 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
799 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400800 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600801
802 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
803 priv->table2_addr, priv->table2_len);
804
805}
806
Adrian Bunka73e22b2006-01-21 01:39:42 +0100807static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500808{
James Ketrenosb095c382005-08-24 22:04:42 -0500809 reg &= ~IPW_START_STANDBY;
810 if (reg & IPW_GATE_ODMA)
811 reg &= ~IPW_GATE_ODMA;
812 if (reg & IPW_GATE_IDMA)
813 reg &= ~IPW_GATE_IDMA;
814 if (reg & IPW_GATE_ADMA)
815 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500816 return reg;
817}
818
819/*
820 * LED behavior:
821 * - On radio ON, turn on any LEDs that require to be on during start
822 * - On initialization, start unassociated blink
823 * - On association, disable unassociated blink
824 * - On disassociation, start unassociated blink
825 * - On radio OFF, turn off any LEDs started during radio on
826 *
827 */
Zhu Yiede61112006-01-24 16:37:10 +0800828#define LD_TIME_LINK_ON msecs_to_jiffies(300)
829#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
830#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500831
Adrian Bunka73e22b2006-01-21 01:39:42 +0100832static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500833{
834 unsigned long flags;
835 u32 led;
836
837 /* If configured to not use LEDs, or nic_type is 1,
838 * then we don't toggle a LINK led */
839 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
840 return;
841
842 spin_lock_irqsave(&priv->lock, flags);
843
844 if (!(priv->status & STATUS_RF_KILL_MASK) &&
845 !(priv->status & STATUS_LED_LINK_ON)) {
846 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500847 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500848 led |= priv->led_association_on;
849
850 led = ipw_register_toggle(led);
851
852 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500853 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500854
855 priv->status |= STATUS_LED_LINK_ON;
856
857 /* If we aren't associated, schedule turning the LED off */
858 if (!(priv->status & STATUS_ASSOCIATED))
859 queue_delayed_work(priv->workqueue,
860 &priv->led_link_off,
861 LD_TIME_LINK_ON);
862 }
863
864 spin_unlock_irqrestore(&priv->lock, flags);
865}
866
James Ketrenosc848d0a2005-08-24 21:56:24 -0500867static void ipw_bg_led_link_on(void *data)
868{
869 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800870 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500871 ipw_led_link_on(data);
Zhu Yi46441512006-01-24 16:37:59 +0800872 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500873}
874
Adrian Bunka73e22b2006-01-21 01:39:42 +0100875static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500876{
877 unsigned long flags;
878 u32 led;
879
880 /* If configured not to use LEDs, or nic type is 1,
881 * then we don't goggle the LINK led. */
882 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
883 return;
884
885 spin_lock_irqsave(&priv->lock, flags);
886
887 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500888 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500889 led &= priv->led_association_off;
890 led = ipw_register_toggle(led);
891
892 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500893 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500894
895 IPW_DEBUG_LED("Link LED Off\n");
896
897 priv->status &= ~STATUS_LED_LINK_ON;
898
899 /* If we aren't associated and the radio is on, schedule
900 * turning the LED on (blink while unassociated) */
901 if (!(priv->status & STATUS_RF_KILL_MASK) &&
902 !(priv->status & STATUS_ASSOCIATED))
903 queue_delayed_work(priv->workqueue, &priv->led_link_on,
904 LD_TIME_LINK_OFF);
905
906 }
907
908 spin_unlock_irqrestore(&priv->lock, flags);
909}
910
James Ketrenosc848d0a2005-08-24 21:56:24 -0500911static void ipw_bg_led_link_off(void *data)
912{
913 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800914 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500915 ipw_led_link_off(data);
Zhu Yi46441512006-01-24 16:37:59 +0800916 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500917}
918
Arjan van de Ven858119e2006-01-14 13:20:43 -0800919static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500920{
James Ketrenosa613bff2005-08-24 21:43:11 -0500921 u32 led;
922
923 if (priv->config & CFG_NO_LED)
924 return;
925
James Ketrenosb095c382005-08-24 22:04:42 -0500926 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500927 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500928
929 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500930 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500931 led |= priv->led_activity_on;
932
933 led = ipw_register_toggle(led);
934
935 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500936 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500937
938 IPW_DEBUG_LED("Activity LED On\n");
939
940 priv->status |= STATUS_LED_ACT_ON;
941
James Ketrenosc848d0a2005-08-24 21:56:24 -0500942 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500943 queue_delayed_work(priv->workqueue, &priv->led_act_off,
944 LD_TIME_ACT_ON);
945 } else {
946 /* Reschedule LED off for full time period */
947 cancel_delayed_work(&priv->led_act_off);
948 queue_delayed_work(priv->workqueue, &priv->led_act_off,
949 LD_TIME_ACT_ON);
950 }
James Ketrenosb095c382005-08-24 22:04:42 -0500951}
James Ketrenosa613bff2005-08-24 21:43:11 -0500952
Adrian Bunka73e22b2006-01-21 01:39:42 +0100953#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500954void ipw_led_activity_on(struct ipw_priv *priv)
955{
956 unsigned long flags;
957 spin_lock_irqsave(&priv->lock, flags);
958 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500959 spin_unlock_irqrestore(&priv->lock, flags);
960}
Adrian Bunka73e22b2006-01-21 01:39:42 +0100961#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -0500962
Adrian Bunka73e22b2006-01-21 01:39:42 +0100963static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500964{
965 unsigned long flags;
966 u32 led;
967
968 if (priv->config & CFG_NO_LED)
969 return;
970
971 spin_lock_irqsave(&priv->lock, flags);
972
973 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500974 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500975 led &= priv->led_activity_off;
976
977 led = ipw_register_toggle(led);
978
979 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500980 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500981
982 IPW_DEBUG_LED("Activity LED Off\n");
983
984 priv->status &= ~STATUS_LED_ACT_ON;
985 }
986
987 spin_unlock_irqrestore(&priv->lock, flags);
988}
989
James Ketrenosc848d0a2005-08-24 21:56:24 -0500990static void ipw_bg_led_activity_off(void *data)
991{
992 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800993 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500994 ipw_led_activity_off(data);
Zhu Yi46441512006-01-24 16:37:59 +0800995 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500996}
997
Adrian Bunka73e22b2006-01-21 01:39:42 +0100998static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500999{
1000 unsigned long flags;
1001 u32 led;
1002
1003 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -05001004 if (priv->config & CFG_NO_LED ||
1005 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -05001006 return;
1007
1008 spin_lock_irqsave(&priv->lock, flags);
1009
James Ketrenosb095c382005-08-24 22:04:42 -05001010 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001011 if (priv->assoc_network->mode == IEEE_A) {
1012 led |= priv->led_ofdm_on;
1013 led &= priv->led_association_off;
1014 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
1015 } else if (priv->assoc_network->mode == IEEE_G) {
1016 led |= priv->led_ofdm_on;
1017 led |= priv->led_association_on;
1018 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
1019 } else {
1020 led &= priv->led_ofdm_off;
1021 led |= priv->led_association_on;
1022 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
1023 }
1024
1025 led = ipw_register_toggle(led);
1026
1027 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001028 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001029
1030 spin_unlock_irqrestore(&priv->lock, flags);
1031}
1032
Adrian Bunka73e22b2006-01-21 01:39:42 +01001033static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001034{
1035 unsigned long flags;
1036 u32 led;
1037
1038 /* Only nic type 1 supports mode LEDs */
1039 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
1040 return;
1041
1042 spin_lock_irqsave(&priv->lock, flags);
1043
James Ketrenosb095c382005-08-24 22:04:42 -05001044 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -05001045 led &= priv->led_ofdm_off;
1046 led &= priv->led_association_off;
1047
1048 led = ipw_register_toggle(led);
1049
1050 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -05001051 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -05001052
1053 spin_unlock_irqrestore(&priv->lock, flags);
1054}
1055
Adrian Bunka73e22b2006-01-21 01:39:42 +01001056static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001057{
1058 ipw_led_link_on(priv);
1059}
1060
Adrian Bunka73e22b2006-01-21 01:39:42 +01001061static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001062{
1063 ipw_led_activity_off(priv);
1064 ipw_led_link_off(priv);
1065}
1066
Adrian Bunka73e22b2006-01-21 01:39:42 +01001067static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001068{
1069 /* Set the Link Led on for all nic types */
1070 ipw_led_link_on(priv);
1071}
1072
Adrian Bunka73e22b2006-01-21 01:39:42 +01001073static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001074{
1075 ipw_led_activity_off(priv);
1076 ipw_led_link_off(priv);
1077
1078 if (priv->status & STATUS_RF_KILL_MASK)
1079 ipw_led_radio_off(priv);
1080}
1081
Adrian Bunka73e22b2006-01-21 01:39:42 +01001082static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001083{
1084 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1085
1086 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001087 priv->led_activity_on = IPW_ACTIVITY_LED;
1088 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001089
James Ketrenosb095c382005-08-24 22:04:42 -05001090 priv->led_association_on = IPW_ASSOCIATED_LED;
1091 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001092
1093 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001094 priv->led_ofdm_on = IPW_OFDM_LED;
1095 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001096
1097 switch (priv->nic_type) {
1098 case EEPROM_NIC_TYPE_1:
1099 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001100 priv->led_activity_on = IPW_ASSOCIATED_LED;
1101 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1102 priv->led_association_on = IPW_ACTIVITY_LED;
1103 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001104
1105 if (!(priv->config & CFG_NO_LED))
1106 ipw_led_band_on(priv);
1107
1108 /* And we don't blink link LEDs for this nic, so
1109 * just return here */
1110 return;
1111
1112 case EEPROM_NIC_TYPE_3:
1113 case EEPROM_NIC_TYPE_2:
1114 case EEPROM_NIC_TYPE_4:
1115 case EEPROM_NIC_TYPE_0:
1116 break;
1117
1118 default:
1119 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1120 priv->nic_type);
1121 priv->nic_type = EEPROM_NIC_TYPE_0;
1122 break;
1123 }
1124
1125 if (!(priv->config & CFG_NO_LED)) {
1126 if (priv->status & STATUS_ASSOCIATED)
1127 ipw_led_link_on(priv);
1128 else
1129 ipw_led_link_off(priv);
1130 }
1131}
1132
Adrian Bunka73e22b2006-01-21 01:39:42 +01001133static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001134{
James Ketrenosa613bff2005-08-24 21:43:11 -05001135 ipw_led_activity_off(priv);
1136 ipw_led_link_off(priv);
1137 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001138 cancel_delayed_work(&priv->led_link_on);
1139 cancel_delayed_work(&priv->led_link_off);
1140 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001141}
1142
James Ketrenos43f66a62005-03-25 12:31:53 -06001143/*
1144 * The following adds a new attribute to the sysfs representation
1145 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1146 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001147 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001148 * See the level definitions in ipw for details.
1149 */
1150static ssize_t show_debug_level(struct device_driver *d, char *buf)
1151{
1152 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1153}
James Ketrenosa613bff2005-08-24 21:43:11 -05001154
1155static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1156 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001157{
1158 char *p = (char *)buf;
1159 u32 val;
1160
1161 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1162 p++;
1163 if (p[0] == 'x' || p[0] == 'X')
1164 p++;
1165 val = simple_strtoul(p, &p, 16);
1166 } else
1167 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001168 if (p == buf)
1169 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001170 ": %s is not in hex or decimal form.\n", buf);
1171 else
1172 ipw_debug_level = val;
1173
1174 return strnlen(buf, count);
1175}
1176
Jeff Garzikbf794512005-07-31 13:07:26 -04001177static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001178 show_debug_level, store_debug_level);
1179
James Ketrenosb39860c2005-08-12 09:36:32 -05001180static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1181{
Zhu Yic8fe6672006-01-24 16:36:36 +08001182 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001183 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1184}
1185
1186static void ipw_capture_event_log(struct ipw_priv *priv,
1187 u32 log_len, struct ipw_event *log)
1188{
1189 u32 base;
1190
1191 if (log_len) {
1192 base = ipw_read32(priv, IPW_EVENT_LOG);
1193 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1194 (u8 *) log, sizeof(*log) * log_len);
1195 }
1196}
1197
1198static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1199{
1200 struct ipw_fw_error *error;
1201 u32 log_len = ipw_get_event_log_len(priv);
1202 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1203 u32 elem_len = ipw_read_reg32(priv, base);
1204
1205 error = kmalloc(sizeof(*error) +
1206 sizeof(*error->elem) * elem_len +
1207 sizeof(*error->log) * log_len, GFP_ATOMIC);
1208 if (!error) {
1209 IPW_ERROR("Memory allocation for firmware error log "
1210 "failed.\n");
1211 return NULL;
1212 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001213 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001214 error->status = priv->status;
1215 error->config = priv->config;
1216 error->elem_len = elem_len;
1217 error->log_len = log_len;
1218 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001219 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001220
1221 ipw_capture_event_log(priv, log_len, error->log);
1222
1223 if (elem_len)
1224 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1225 sizeof(*error->elem) * elem_len);
1226
1227 return error;
1228}
1229
James Ketrenosb39860c2005-08-12 09:36:32 -05001230static ssize_t show_event_log(struct device *d,
1231 struct device_attribute *attr, char *buf)
1232{
1233 struct ipw_priv *priv = dev_get_drvdata(d);
1234 u32 log_len = ipw_get_event_log_len(priv);
1235 struct ipw_event log[log_len];
1236 u32 len = 0, i;
1237
1238 ipw_capture_event_log(priv, log_len, log);
1239
1240 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1241 for (i = 0; i < log_len; i++)
1242 len += snprintf(buf + len, PAGE_SIZE - len,
1243 "\n%08X%08X%08X",
1244 log[i].time, log[i].event, log[i].data);
1245 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1246 return len;
1247}
1248
1249static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1250
1251static ssize_t show_error(struct device *d,
1252 struct device_attribute *attr, char *buf)
1253{
1254 struct ipw_priv *priv = dev_get_drvdata(d);
1255 u32 len = 0, i;
1256 if (!priv->error)
1257 return 0;
1258 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001259 "%08lX%08X%08X%08X",
1260 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001261 priv->error->status,
1262 priv->error->config, priv->error->elem_len);
1263 for (i = 0; i < priv->error->elem_len; i++)
1264 len += snprintf(buf + len, PAGE_SIZE - len,
1265 "\n%08X%08X%08X%08X%08X%08X%08X",
1266 priv->error->elem[i].time,
1267 priv->error->elem[i].desc,
1268 priv->error->elem[i].blink1,
1269 priv->error->elem[i].blink2,
1270 priv->error->elem[i].link1,
1271 priv->error->elem[i].link2,
1272 priv->error->elem[i].data);
1273
1274 len += snprintf(buf + len, PAGE_SIZE - len,
1275 "\n%08X", priv->error->log_len);
1276 for (i = 0; i < priv->error->log_len; i++)
1277 len += snprintf(buf + len, PAGE_SIZE - len,
1278 "\n%08X%08X%08X",
1279 priv->error->log[i].time,
1280 priv->error->log[i].event,
1281 priv->error->log[i].data);
1282 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1283 return len;
1284}
1285
1286static ssize_t clear_error(struct device *d,
1287 struct device_attribute *attr,
1288 const char *buf, size_t count)
1289{
1290 struct ipw_priv *priv = dev_get_drvdata(d);
Jesper Juhl8f760782006-06-27 02:55:06 -07001291
1292 kfree(priv->error);
1293 priv->error = NULL;
James Ketrenosb39860c2005-08-12 09:36:32 -05001294 return count;
1295}
1296
1297static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1298
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001299static ssize_t show_cmd_log(struct device *d,
1300 struct device_attribute *attr, char *buf)
1301{
1302 struct ipw_priv *priv = dev_get_drvdata(d);
1303 u32 len = 0, i;
1304 if (!priv->cmdlog)
1305 return 0;
1306 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1307 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1308 i = (i + 1) % priv->cmdlog_len) {
1309 len +=
1310 snprintf(buf + len, PAGE_SIZE - len,
1311 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1312 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1313 priv->cmdlog[i].cmd.len);
1314 len +=
1315 snprintk_buf(buf + len, PAGE_SIZE - len,
1316 (u8 *) priv->cmdlog[i].cmd.param,
1317 priv->cmdlog[i].cmd.len);
1318 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1319 }
1320 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1321 return len;
1322}
1323
1324static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1325
Zhu Yid685b8c2006-04-13 17:20:27 +08001326#ifdef CONFIG_IPW2200_PROMISCUOUS
1327static void ipw_prom_free(struct ipw_priv *priv);
1328static int ipw_prom_alloc(struct ipw_priv *priv);
1329static ssize_t store_rtap_iface(struct device *d,
1330 struct device_attribute *attr,
1331 const char *buf, size_t count)
1332{
1333 struct ipw_priv *priv = dev_get_drvdata(d);
1334 int rc = 0;
1335
1336 if (count < 1)
1337 return -EINVAL;
1338
1339 switch (buf[0]) {
1340 case '0':
1341 if (!rtap_iface)
1342 return count;
1343
1344 if (netif_running(priv->prom_net_dev)) {
1345 IPW_WARNING("Interface is up. Cannot unregister.\n");
1346 return count;
1347 }
1348
1349 ipw_prom_free(priv);
1350 rtap_iface = 0;
1351 break;
1352
1353 case '1':
1354 if (rtap_iface)
1355 return count;
1356
1357 rc = ipw_prom_alloc(priv);
1358 if (!rc)
1359 rtap_iface = 1;
1360 break;
1361
1362 default:
1363 return -EINVAL;
1364 }
1365
1366 if (rc) {
1367 IPW_ERROR("Failed to register promiscuous network "
1368 "device (error %d).\n", rc);
1369 }
1370
1371 return count;
1372}
1373
1374static ssize_t show_rtap_iface(struct device *d,
1375 struct device_attribute *attr,
1376 char *buf)
1377{
1378 struct ipw_priv *priv = dev_get_drvdata(d);
1379 if (rtap_iface)
1380 return sprintf(buf, "%s", priv->prom_net_dev->name);
1381 else {
1382 buf[0] = '-';
1383 buf[1] = '1';
1384 buf[2] = '\0';
1385 return 3;
1386 }
1387}
1388
1389static DEVICE_ATTR(rtap_iface, S_IWUSR | S_IRUSR, show_rtap_iface,
1390 store_rtap_iface);
1391
1392static ssize_t store_rtap_filter(struct device *d,
1393 struct device_attribute *attr,
1394 const char *buf, size_t count)
1395{
1396 struct ipw_priv *priv = dev_get_drvdata(d);
1397
1398 if (!priv->prom_priv) {
1399 IPW_ERROR("Attempting to set filter without "
1400 "rtap_iface enabled.\n");
1401 return -EPERM;
1402 }
1403
1404 priv->prom_priv->filter = simple_strtol(buf, NULL, 0);
1405
1406 IPW_DEBUG_INFO("Setting rtap filter to " BIT_FMT16 "\n",
1407 BIT_ARG16(priv->prom_priv->filter));
1408
1409 return count;
1410}
1411
1412static ssize_t show_rtap_filter(struct device *d,
1413 struct device_attribute *attr,
1414 char *buf)
1415{
1416 struct ipw_priv *priv = dev_get_drvdata(d);
1417 return sprintf(buf, "0x%04X",
1418 priv->prom_priv ? priv->prom_priv->filter : 0);
1419}
1420
1421static DEVICE_ATTR(rtap_filter, S_IWUSR | S_IRUSR, show_rtap_filter,
1422 store_rtap_filter);
1423#endif
1424
James Ketrenosa613bff2005-08-24 21:43:11 -05001425static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1426 char *buf)
1427{
1428 struct ipw_priv *priv = dev_get_drvdata(d);
1429 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1430}
1431
1432static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1433 const char *buf, size_t count)
1434{
1435 struct ipw_priv *priv = dev_get_drvdata(d);
1436 struct net_device *dev = priv->net_dev;
1437 char buffer[] = "00000000";
1438 unsigned long len =
1439 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1440 unsigned long val;
1441 char *p = buffer;
1442
1443 IPW_DEBUG_INFO("enter\n");
1444
1445 strncpy(buffer, buf, len);
1446 buffer[len] = 0;
1447
1448 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1449 p++;
1450 if (p[0] == 'x' || p[0] == 'X')
1451 p++;
1452 val = simple_strtoul(p, &p, 16);
1453 } else
1454 val = simple_strtoul(p, &p, 10);
1455 if (p == buffer) {
1456 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1457 } else {
1458 priv->ieee->scan_age = val;
1459 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1460 }
1461
1462 IPW_DEBUG_INFO("exit\n");
1463 return len;
1464}
1465
1466static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1467
1468static ssize_t show_led(struct device *d, struct device_attribute *attr,
1469 char *buf)
1470{
1471 struct ipw_priv *priv = dev_get_drvdata(d);
1472 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1473}
1474
1475static ssize_t store_led(struct device *d, struct device_attribute *attr,
1476 const char *buf, size_t count)
1477{
1478 struct ipw_priv *priv = dev_get_drvdata(d);
1479
1480 IPW_DEBUG_INFO("enter\n");
1481
1482 if (count == 0)
1483 return 0;
1484
1485 if (*buf == 0) {
1486 IPW_DEBUG_LED("Disabling LED control.\n");
1487 priv->config |= CFG_NO_LED;
1488 ipw_led_shutdown(priv);
1489 } else {
1490 IPW_DEBUG_LED("Enabling LED control.\n");
1491 priv->config &= ~CFG_NO_LED;
1492 ipw_led_init(priv);
1493 }
1494
1495 IPW_DEBUG_INFO("exit\n");
1496 return count;
1497}
1498
1499static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1500
Andrew Mortonad3fee52005-06-20 14:30:36 -07001501static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001502 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001503{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001504 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001505 return sprintf(buf, "0x%08x\n", (int)p->status);
1506}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001507
James Ketrenos43f66a62005-03-25 12:31:53 -06001508static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1509
Andrew Mortonad3fee52005-06-20 14:30:36 -07001510static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1511 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001512{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001513 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001514 return sprintf(buf, "0x%08x\n", (int)p->config);
1515}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001516
James Ketrenos43f66a62005-03-25 12:31:53 -06001517static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1518
Andrew Mortonad3fee52005-06-20 14:30:36 -07001519static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001520 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001521{
James Ketrenosa613bff2005-08-24 21:43:11 -05001522 struct ipw_priv *priv = d->driver_data;
1523 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001524}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001525
James Ketrenos43f66a62005-03-25 12:31:53 -06001526static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1527
Andrew Mortonad3fee52005-06-20 14:30:36 -07001528static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001529 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001530{
1531 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001532 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001533
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001534 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001535 return 0;
1536
1537 return sprintf(buf, "0x%08x\n", tmp);
1538}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001539
1540static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001541
Andrew Mortonad3fee52005-06-20 14:30:36 -07001542static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1543 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001544{
1545 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001546 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001547
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001548 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001549 return 0;
1550
1551 return sprintf(buf, "0x%08x\n", tmp);
1552}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001553
1554static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001555
1556/*
1557 * Add a device attribute to view/control the delay between eeprom
1558 * operations.
1559 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001560static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001561 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001562{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001563 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001564 return sprintf(buf, "%i\n", n);
1565}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001566static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001567 struct device_attribute *attr,
1568 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001569{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001570 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001571 sscanf(buf, "%i", &p->eeprom_delay);
1572 return strnlen(buf, count);
1573}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001574
1575static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1576 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001577
Andrew Mortonad3fee52005-06-20 14:30:36 -07001578static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001579 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001580{
1581 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001582 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001583
James Ketrenosb095c382005-08-24 22:04:42 -05001584 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001585 return sprintf(buf, "0x%08x\n", reg);
1586}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001587static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001588 struct device_attribute *attr,
1589 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001590{
1591 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001592 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001593
1594 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001595 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001596 return strnlen(buf, count);
1597}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001598
1599static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1600 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001601
Andrew Mortonad3fee52005-06-20 14:30:36 -07001602static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001603 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001604{
1605 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001606 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001607
1608 reg = ipw_read_reg32(p, 0x301100);
1609 return sprintf(buf, "0x%08x\n", reg);
1610}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001611static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001612 struct device_attribute *attr,
1613 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001614{
1615 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001616 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001617
1618 sscanf(buf, "%x", &reg);
1619 ipw_write_reg32(p, 0x301100, reg);
1620 return strnlen(buf, count);
1621}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001622
1623static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1624 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001625
Andrew Mortonad3fee52005-06-20 14:30:36 -07001626static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001627 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001628{
1629 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001630 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001631
Jeff Garzikbf794512005-07-31 13:07:26 -04001632 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001633 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001634 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001635 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001636
James Ketrenos43f66a62005-03-25 12:31:53 -06001637 return sprintf(buf, "0x%08x\n", reg);
1638}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001639static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001640 struct device_attribute *attr,
1641 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001642{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001643 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001644
1645 sscanf(buf, "%x", &priv->indirect_dword);
1646 priv->status |= STATUS_INDIRECT_DWORD;
1647 return strnlen(buf, count);
1648}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001649
1650static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1651 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001652
Andrew Mortonad3fee52005-06-20 14:30:36 -07001653static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001654 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001655{
1656 u8 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001657 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001658
Jeff Garzikbf794512005-07-31 13:07:26 -04001659 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001660 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001661 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001662 reg = 0;
1663
1664 return sprintf(buf, "0x%02x\n", reg);
1665}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001666static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001667 struct device_attribute *attr,
1668 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001669{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001670 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001671
1672 sscanf(buf, "%x", &priv->indirect_byte);
1673 priv->status |= STATUS_INDIRECT_BYTE;
1674 return strnlen(buf, count);
1675}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001676
1677static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001678 show_indirect_byte, store_indirect_byte);
1679
Andrew Mortonad3fee52005-06-20 14:30:36 -07001680static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001681 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001682{
1683 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001684 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001685
Jeff Garzikbf794512005-07-31 13:07:26 -04001686 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001687 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001688 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001689 reg = 0;
1690
1691 return sprintf(buf, "0x%08x\n", reg);
1692}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001693static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001694 struct device_attribute *attr,
1695 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001696{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001697 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001698
1699 sscanf(buf, "%x", &priv->direct_dword);
1700 priv->status |= STATUS_DIRECT_DWORD;
1701 return strnlen(buf, count);
1702}
James Ketrenos43f66a62005-03-25 12:31:53 -06001703
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001704static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1705 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001706
Arjan van de Ven858119e2006-01-14 13:20:43 -08001707static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001708{
1709 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1710 priv->status |= STATUS_RF_KILL_HW;
1711 else
1712 priv->status &= ~STATUS_RF_KILL_HW;
1713
1714 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1715}
1716
Andrew Mortonad3fee52005-06-20 14:30:36 -07001717static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001718 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001719{
1720 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001721 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001722 2 - HW based RF kill active
1723 3 - Both HW and SW baed RF kill active */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001724 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001725 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001726 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001727 return sprintf(buf, "%i\n", val);
1728}
1729
1730static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1731{
Jeff Garzikbf794512005-07-31 13:07:26 -04001732 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001733 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001734 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001735
1736 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1737 disable_radio ? "OFF" : "ON");
1738
1739 if (disable_radio) {
1740 priv->status |= STATUS_RF_KILL_SW;
1741
James Ketrenosa613bff2005-08-24 21:43:11 -05001742 if (priv->workqueue)
James Ketrenos43f66a62005-03-25 12:31:53 -06001743 cancel_delayed_work(&priv->request_scan);
James Ketrenos43f66a62005-03-25 12:31:53 -06001744 queue_work(priv->workqueue, &priv->down);
1745 } else {
1746 priv->status &= ~STATUS_RF_KILL_SW;
1747 if (rf_kill_active(priv)) {
1748 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1749 "disabled by HW switch\n");
1750 /* Make sure the RF_KILL check timer is running */
1751 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001752 queue_delayed_work(priv->workqueue, &priv->rf_kill,
James Ketrenos43f66a62005-03-25 12:31:53 -06001753 2 * HZ);
Jeff Garzikbf794512005-07-31 13:07:26 -04001754 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001755 queue_work(priv->workqueue, &priv->up);
1756 }
1757
1758 return 1;
1759}
1760
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001761static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1762 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001763{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001764 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -04001765
James Ketrenos43f66a62005-03-25 12:31:53 -06001766 ipw_radio_kill_sw(priv, buf[0] == '1');
1767
1768 return count;
1769}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001770
1771static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001772
James Ketrenosb095c382005-08-24 22:04:42 -05001773static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1774 char *buf)
1775{
1776 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1777 int pos = 0, len = 0;
1778 if (priv->config & CFG_SPEED_SCAN) {
1779 while (priv->speed_scan[pos] != 0)
1780 len += sprintf(&buf[len], "%d ",
1781 priv->speed_scan[pos++]);
1782 return len + sprintf(&buf[len], "\n");
1783 }
1784
1785 return sprintf(buf, "0\n");
1786}
1787
1788static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1789 const char *buf, size_t count)
1790{
1791 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1792 int channel, pos = 0;
1793 const char *p = buf;
1794
1795 /* list of space separated channels to scan, optionally ending with 0 */
1796 while ((channel = simple_strtol(p, NULL, 0))) {
1797 if (pos == MAX_SPEED_SCAN - 1) {
1798 priv->speed_scan[pos] = 0;
1799 break;
1800 }
1801
Larry Finger1867b112006-02-28 09:48:28 -06001802 if (ieee80211_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001803 priv->speed_scan[pos++] = channel;
1804 else
1805 IPW_WARNING("Skipping invalid channel request: %d\n",
1806 channel);
1807 p = strchr(p, ' ');
1808 if (!p)
1809 break;
1810 while (*p == ' ' || *p == '\t')
1811 p++;
1812 }
1813
1814 if (pos == 0)
1815 priv->config &= ~CFG_SPEED_SCAN;
1816 else {
1817 priv->speed_scan_pos = 0;
1818 priv->config |= CFG_SPEED_SCAN;
1819 }
1820
1821 return count;
1822}
1823
1824static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1825 store_speed_scan);
1826
1827static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1828 char *buf)
1829{
1830 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1831 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1832}
1833
1834static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1835 const char *buf, size_t count)
1836{
1837 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1838 if (buf[0] == '1')
1839 priv->config |= CFG_NET_STATS;
1840 else
1841 priv->config &= ~CFG_NET_STATS;
1842
1843 return count;
1844}
1845
James Ketrenosafbf30a2005-08-25 00:05:33 -05001846static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1847 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001848
James Ketrenosea2b26e2005-08-24 21:25:16 -05001849static void notify_wx_assoc_event(struct ipw_priv *priv)
1850{
1851 union iwreq_data wrqu;
1852 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1853 if (priv->status & STATUS_ASSOCIATED)
1854 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1855 else
1856 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1857 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1858}
1859
James Ketrenos43f66a62005-03-25 12:31:53 -06001860static void ipw_irq_tasklet(struct ipw_priv *priv)
1861{
1862 u32 inta, inta_mask, handled = 0;
1863 unsigned long flags;
1864 int rc = 0;
1865
Zhu Yi89c318e2006-06-08 22:19:49 -07001866 spin_lock_irqsave(&priv->irq_lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001867
James Ketrenosb095c382005-08-24 22:04:42 -05001868 inta = ipw_read32(priv, IPW_INTA_RW);
1869 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1870 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001871
1872 /* Add any cached INTA values that need to be handled */
1873 inta |= priv->isr_inta;
1874
Zhu Yi89c318e2006-06-08 22:19:49 -07001875 spin_unlock_irqrestore(&priv->irq_lock, flags);
1876
1877 spin_lock_irqsave(&priv->lock, flags);
1878
James Ketrenos43f66a62005-03-25 12:31:53 -06001879 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001880 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001881 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001882 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001883 }
1884
James Ketrenosb095c382005-08-24 22:04:42 -05001885 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001886 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001887 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001888 priv->status &= ~STATUS_HCMD_ACTIVE;
1889 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001890 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001891 }
1892
James Ketrenosb095c382005-08-24 22:04:42 -05001893 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001894 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001895 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05001896 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06001897 }
1898
James Ketrenosb095c382005-08-24 22:04:42 -05001899 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001900 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001901 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05001902 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06001903 }
1904
James Ketrenosb095c382005-08-24 22:04:42 -05001905 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001906 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001907 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05001908 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06001909 }
1910
James Ketrenosb095c382005-08-24 22:04:42 -05001911 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001912 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001913 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05001914 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06001915 }
1916
James Ketrenosb095c382005-08-24 22:04:42 -05001917 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001918 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001919 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001920 }
1921
James Ketrenosb095c382005-08-24 22:04:42 -05001922 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001923 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001924 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06001925 }
1926
James Ketrenosb095c382005-08-24 22:04:42 -05001927 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001928 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001929 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001930 }
1931
James Ketrenosb095c382005-08-24 22:04:42 -05001932 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001933 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001934 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001935 }
1936
James Ketrenosb095c382005-08-24 22:04:42 -05001937 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001938 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001939 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001940 }
1941
James Ketrenosb095c382005-08-24 22:04:42 -05001942 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001943 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1944 priv->status |= STATUS_RF_KILL_HW;
1945 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05001946 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06001947 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05001948 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001949 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05001950 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001951 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001952
James Ketrenosb095c382005-08-24 22:04:42 -05001953 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001954 IPW_WARNING("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001955 if (priv->error) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001956 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001957 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1958 struct ipw_fw_error *error =
1959 ipw_alloc_error_log(priv);
1960 ipw_dump_error_log(priv, error);
Jesper Juhl8f760782006-06-27 02:55:06 -07001961 kfree(error);
James Ketrenosb39860c2005-08-12 09:36:32 -05001962 }
James Ketrenosb39860c2005-08-12 09:36:32 -05001963 } else {
1964 priv->error = ipw_alloc_error_log(priv);
1965 if (priv->error)
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001966 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001967 else
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001968 IPW_DEBUG_FW("Error allocating sysfs 'error' "
1969 "log.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001970 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1971 ipw_dump_error_log(priv, priv->error);
James Ketrenosb39860c2005-08-12 09:36:32 -05001972 }
1973
James Ketrenosb095c382005-08-24 22:04:42 -05001974 /* XXX: If hardware encryption is for WPA/WPA2,
1975 * we have to notify the supplicant. */
1976 if (priv->ieee->sec.encrypt) {
1977 priv->status &= ~STATUS_ASSOCIATED;
1978 notify_wx_assoc_event(priv);
1979 }
1980
1981 /* Keep the restart process from trying to send host
1982 * commands by clearing the INIT status bit */
1983 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001984
1985 /* Cancel currently queued command. */
1986 priv->status &= ~STATUS_HCMD_ACTIVE;
1987 wake_up_interruptible(&priv->wait_command_queue);
1988
James Ketrenos43f66a62005-03-25 12:31:53 -06001989 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05001990 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001991 }
1992
James Ketrenosb095c382005-08-24 22:04:42 -05001993 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001994 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001995 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001996 }
1997
1998 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001999 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06002000 }
2001
Zhu Yi89c318e2006-06-08 22:19:49 -07002002 spin_unlock_irqrestore(&priv->lock, flags);
2003
James Ketrenos43f66a62005-03-25 12:31:53 -06002004 /* enable all interrupts */
2005 ipw_enable_interrupts(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06002006}
Jeff Garzikbf794512005-07-31 13:07:26 -04002007
James Ketrenos43f66a62005-03-25 12:31:53 -06002008#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
2009static char *get_cmd_string(u8 cmd)
2010{
2011 switch (cmd) {
2012 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04002013 IPW_CMD(POWER_DOWN);
2014 IPW_CMD(SYSTEM_CONFIG);
2015 IPW_CMD(MULTICAST_ADDRESS);
2016 IPW_CMD(SSID);
2017 IPW_CMD(ADAPTER_ADDRESS);
2018 IPW_CMD(PORT_TYPE);
2019 IPW_CMD(RTS_THRESHOLD);
2020 IPW_CMD(FRAG_THRESHOLD);
2021 IPW_CMD(POWER_MODE);
2022 IPW_CMD(WEP_KEY);
2023 IPW_CMD(TGI_TX_KEY);
2024 IPW_CMD(SCAN_REQUEST);
2025 IPW_CMD(SCAN_REQUEST_EXT);
2026 IPW_CMD(ASSOCIATE);
2027 IPW_CMD(SUPPORTED_RATES);
2028 IPW_CMD(SCAN_ABORT);
2029 IPW_CMD(TX_FLUSH);
2030 IPW_CMD(QOS_PARAMETERS);
2031 IPW_CMD(DINO_CONFIG);
2032 IPW_CMD(RSN_CAPABILITIES);
2033 IPW_CMD(RX_KEY);
2034 IPW_CMD(CARD_DISABLE);
2035 IPW_CMD(SEED_NUMBER);
2036 IPW_CMD(TX_POWER);
2037 IPW_CMD(COUNTRY_INFO);
2038 IPW_CMD(AIRONET_INFO);
2039 IPW_CMD(AP_TX_POWER);
2040 IPW_CMD(CCKM_INFO);
2041 IPW_CMD(CCX_VER_INFO);
2042 IPW_CMD(SET_CALIBRATION);
2043 IPW_CMD(SENSITIVITY_CALIB);
2044 IPW_CMD(RETRY_LIMIT);
2045 IPW_CMD(IPW_PRE_POWER_DOWN);
2046 IPW_CMD(VAP_BEACON_TEMPLATE);
2047 IPW_CMD(VAP_DTIM_PERIOD);
2048 IPW_CMD(EXT_SUPPORTED_RATES);
2049 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
2050 IPW_CMD(VAP_QUIET_INTERVALS);
2051 IPW_CMD(VAP_CHANNEL_SWITCH);
2052 IPW_CMD(VAP_MANDATORY_CHANNELS);
2053 IPW_CMD(VAP_CELL_PWR_LIMIT);
2054 IPW_CMD(VAP_CF_PARAM_SET);
2055 IPW_CMD(VAP_SET_BEACONING_STATE);
2056 IPW_CMD(MEASUREMENT);
2057 IPW_CMD(POWER_CAPABILITY);
2058 IPW_CMD(SUPPORTED_CHANNELS);
2059 IPW_CMD(TPC_REPORT);
2060 IPW_CMD(WME_INFO);
2061 IPW_CMD(PRODUCTION_COMMAND);
2062 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06002063 return "UNKNOWN";
2064 }
2065}
James Ketrenos43f66a62005-03-25 12:31:53 -06002066
2067#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002068
2069static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06002070{
2071 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002072 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06002073
James Ketrenosa613bff2005-08-24 21:43:11 -05002074 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002075 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002076 IPW_ERROR("Failed to send %s: Already sending a command.\n",
2077 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002078 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002079 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06002080 }
2081
2082 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04002083
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002084 if (priv->cmdlog) {
2085 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
2086 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
2087 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
2088 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
2089 cmd->len);
2090 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
2091 }
2092
James Ketrenosb095c382005-08-24 22:04:42 -05002093 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
2094 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
2095 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08002096
2097#ifndef DEBUG_CMD_WEP_KEY
2098 if (cmd->cmd == IPW_CMD_WEP_KEY)
2099 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
2100 else
2101#endif
2102 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
2103
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002104 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05002105 if (rc) {
2106 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002107 IPW_ERROR("Failed to send %s: Reason %d\n",
2108 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05002109 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002110 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002111 }
2112 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002113
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002114 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
2115 !(priv->
2116 status & STATUS_HCMD_ACTIVE),
2117 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002118 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05002119 spin_lock_irqsave(&priv->lock, flags);
2120 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002121 IPW_ERROR("Failed to send %s: Command timed out.\n",
2122 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05002123 priv->status &= ~STATUS_HCMD_ACTIVE;
2124 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002125 rc = -EIO;
2126 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05002127 }
2128 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05002129 } else
2130 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05002131
James Ketrenosb095c382005-08-24 22:04:42 -05002132 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05002133 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
2134 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002135 rc = -EIO;
2136 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06002137 }
2138
Zhu Yi2638bc32006-01-24 16:37:52 +08002139 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05002140 if (priv->cmdlog) {
2141 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
2142 priv->cmdlog_pos %= priv->cmdlog_len;
2143 }
2144 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06002145}
2146
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002147static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002148{
2149 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002150 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002151 };
2152
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002153 return __ipw_send_cmd(priv, &cmd);
2154}
2155
2156static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2157 void *data)
2158{
2159 struct host_cmd cmd = {
2160 .cmd = command,
2161 .len = len,
2162 .param = data,
2163 };
2164
2165 return __ipw_send_cmd(priv, &cmd);
2166}
2167
2168static int ipw_send_host_complete(struct ipw_priv *priv)
2169{
James Ketrenos43f66a62005-03-25 12:31:53 -06002170 if (!priv) {
2171 IPW_ERROR("Invalid args\n");
2172 return -1;
2173 }
2174
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002175 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002176}
2177
Zhu Yid685b8c2006-04-13 17:20:27 +08002178static int ipw_send_system_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002179{
Zhu Yid685b8c2006-04-13 17:20:27 +08002180 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG,
2181 sizeof(priv->sys_config),
2182 &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002183}
2184
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002185static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002186{
James Ketrenos43f66a62005-03-25 12:31:53 -06002187 if (!priv || !ssid) {
2188 IPW_ERROR("Invalid args\n");
2189 return -1;
2190 }
2191
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002192 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002193 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002194}
2195
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002196static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002197{
James Ketrenos43f66a62005-03-25 12:31:53 -06002198 if (!priv || !mac) {
2199 IPW_ERROR("Invalid args\n");
2200 return -1;
2201 }
2202
2203 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2204 priv->net_dev->name, MAC_ARG(mac));
2205
Zhu Yi2638bc32006-01-24 16:37:52 +08002206 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002207}
2208
James Ketrenosa613bff2005-08-24 21:43:11 -05002209/*
2210 * NOTE: This must be executed from our workqueue as it results in udelay
2211 * being called which may corrupt the keyboard if executed on default
2212 * workqueue
2213 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002214static void ipw_adapter_restart(void *adapter)
2215{
2216 struct ipw_priv *priv = adapter;
2217
2218 if (priv->status & STATUS_RF_KILL_MASK)
2219 return;
2220
2221 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002222
2223 if (priv->assoc_network &&
2224 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2225 ipw_remove_current_network(priv);
2226
James Ketrenos43f66a62005-03-25 12:31:53 -06002227 if (ipw_up(priv)) {
2228 IPW_ERROR("Failed to up device\n");
2229 return;
2230 }
2231}
2232
James Ketrenosc848d0a2005-08-24 21:56:24 -05002233static void ipw_bg_adapter_restart(void *data)
2234{
2235 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08002236 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002237 ipw_adapter_restart(data);
Zhu Yi46441512006-01-24 16:37:59 +08002238 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002239}
2240
James Ketrenos43f66a62005-03-25 12:31:53 -06002241#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2242
2243static void ipw_scan_check(void *data)
2244{
2245 struct ipw_priv *priv = data;
2246 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2247 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002248 "adapter after (%dms).\n",
2249 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
James Ketrenosa613bff2005-08-24 21:43:11 -05002250 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06002251 }
2252}
2253
James Ketrenosc848d0a2005-08-24 21:56:24 -05002254static void ipw_bg_scan_check(void *data)
2255{
2256 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08002257 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002258 ipw_scan_check(data);
Zhu Yi46441512006-01-24 16:37:59 +08002259 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002260}
2261
James Ketrenos43f66a62005-03-25 12:31:53 -06002262static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2263 struct ipw_scan_request_ext *request)
2264{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002265 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002266 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002267}
2268
2269static int ipw_send_scan_abort(struct ipw_priv *priv)
2270{
James Ketrenos43f66a62005-03-25 12:31:53 -06002271 if (!priv) {
2272 IPW_ERROR("Invalid args\n");
2273 return -1;
2274 }
2275
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002276 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002277}
2278
2279static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2280{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002281 struct ipw_sensitivity_calib calib = {
2282 .beacon_rssi_raw = sens,
James Ketrenos43f66a62005-03-25 12:31:53 -06002283 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002284
2285 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002286 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002287}
2288
2289static int ipw_send_associate(struct ipw_priv *priv,
2290 struct ipw_associate *associate)
2291{
James Ketrenosa613bff2005-08-24 21:43:11 -05002292 struct ipw_associate tmp_associate;
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002293
2294 if (!priv || !associate) {
2295 IPW_ERROR("Invalid args\n");
2296 return -1;
2297 }
2298
James Ketrenosa613bff2005-08-24 21:43:11 -05002299 memcpy(&tmp_associate, associate, sizeof(*associate));
2300 tmp_associate.policy_support =
2301 cpu_to_le16(tmp_associate.policy_support);
2302 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2303 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2304 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2305 tmp_associate.listen_interval =
2306 cpu_to_le16(tmp_associate.listen_interval);
2307 tmp_associate.beacon_interval =
2308 cpu_to_le16(tmp_associate.beacon_interval);
2309 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2310
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002311 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
Zhu Yi2638bc32006-01-24 16:37:52 +08002312 &tmp_associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002313}
2314
2315static int ipw_send_supported_rates(struct ipw_priv *priv,
2316 struct ipw_supported_rates *rates)
2317{
James Ketrenos43f66a62005-03-25 12:31:53 -06002318 if (!priv || !rates) {
2319 IPW_ERROR("Invalid args\n");
2320 return -1;
2321 }
2322
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002323 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002324 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002325}
2326
2327static int ipw_set_random_seed(struct ipw_priv *priv)
2328{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002329 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002330
2331 if (!priv) {
2332 IPW_ERROR("Invalid args\n");
2333 return -1;
2334 }
2335
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002336 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002337
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002338 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002339}
2340
James Ketrenos43f66a62005-03-25 12:31:53 -06002341static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2342{
James Ketrenos43f66a62005-03-25 12:31:53 -06002343 if (!priv) {
2344 IPW_ERROR("Invalid args\n");
2345 return -1;
2346 }
2347
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002348 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off),
Zhu Yi2638bc32006-01-24 16:37:52 +08002349 &phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002350}
James Ketrenos43f66a62005-03-25 12:31:53 -06002351
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002352static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002353{
James Ketrenos43f66a62005-03-25 12:31:53 -06002354 if (!priv || !power) {
2355 IPW_ERROR("Invalid args\n");
2356 return -1;
2357 }
2358
Zhu Yi2638bc32006-01-24 16:37:52 +08002359 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002360}
James Ketrenos43f66a62005-03-25 12:31:53 -06002361
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002362static int ipw_set_tx_power(struct ipw_priv *priv)
2363{
Larry Finger1867b112006-02-28 09:48:28 -06002364 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002365 struct ipw_tx_power tx_power;
2366 s8 max_power;
2367 int i;
2368
2369 memset(&tx_power, 0, sizeof(tx_power));
2370
2371 /* configure device for 'G' band */
2372 tx_power.ieee_mode = IPW_G_MODE;
2373 tx_power.num_channels = geo->bg_channels;
2374 for (i = 0; i < geo->bg_channels; i++) {
2375 max_power = geo->bg[i].max_power;
2376 tx_power.channels_tx_power[i].channel_number =
2377 geo->bg[i].channel;
2378 tx_power.channels_tx_power[i].tx_power = max_power ?
2379 min(max_power, priv->tx_power) : priv->tx_power;
2380 }
2381 if (ipw_send_tx_power(priv, &tx_power))
2382 return -EIO;
2383
2384 /* configure device to also handle 'B' band */
2385 tx_power.ieee_mode = IPW_B_MODE;
2386 if (ipw_send_tx_power(priv, &tx_power))
2387 return -EIO;
2388
2389 /* configure device to also handle 'A' band */
2390 if (priv->ieee->abg_true) {
2391 tx_power.ieee_mode = IPW_A_MODE;
2392 tx_power.num_channels = geo->a_channels;
2393 for (i = 0; i < tx_power.num_channels; i++) {
2394 max_power = geo->a[i].max_power;
2395 tx_power.channels_tx_power[i].channel_number =
2396 geo->a[i].channel;
2397 tx_power.channels_tx_power[i].tx_power = max_power ?
2398 min(max_power, priv->tx_power) : priv->tx_power;
2399 }
2400 if (ipw_send_tx_power(priv, &tx_power))
2401 return -EIO;
2402 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002403 return 0;
2404}
2405
2406static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2407{
2408 struct ipw_rts_threshold rts_threshold = {
2409 .rts_threshold = rts,
2410 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002411
2412 if (!priv) {
2413 IPW_ERROR("Invalid args\n");
2414 return -1;
2415 }
2416
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002417 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2418 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002419}
2420
2421static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2422{
2423 struct ipw_frag_threshold frag_threshold = {
2424 .frag_threshold = frag,
2425 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002426
2427 if (!priv) {
2428 IPW_ERROR("Invalid args\n");
2429 return -1;
2430 }
2431
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002432 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2433 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002434}
2435
2436static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2437{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002438 u32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002439
2440 if (!priv) {
2441 IPW_ERROR("Invalid args\n");
2442 return -1;
2443 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002444
James Ketrenos43f66a62005-03-25 12:31:53 -06002445 /* If on battery, set to 3, if AC set to CAM, else user
2446 * level */
2447 switch (mode) {
2448 case IPW_POWER_BATTERY:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002449 param = IPW_POWER_INDEX_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06002450 break;
2451 case IPW_POWER_AC:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002452 param = IPW_POWER_MODE_CAM;
James Ketrenos43f66a62005-03-25 12:31:53 -06002453 break;
2454 default:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002455 param = mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06002456 break;
2457 }
2458
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002459 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002460 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002461}
2462
James Ketrenosafbf30a2005-08-25 00:05:33 -05002463static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2464{
2465 struct ipw_retry_limit retry_limit = {
2466 .short_retry_limit = slimit,
2467 .long_retry_limit = llimit
2468 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002469
2470 if (!priv) {
2471 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002472 return -1;
2473 }
2474
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002475 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002476 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002477}
2478
2479/*
2480 * The IPW device contains a Microwire compatible EEPROM that stores
2481 * various data like the MAC address. Usually the firmware has exclusive
2482 * access to the eeprom, but during device initialization (before the
2483 * device driver has sent the HostComplete command to the firmware) the
2484 * device driver has read access to the EEPROM by way of indirect addressing
2485 * through a couple of memory mapped registers.
2486 *
2487 * The following is a simplified implementation for pulling data out of the
2488 * the eeprom, along with some helper functions to find information in
2489 * the per device private data's copy of the eeprom.
2490 *
2491 * NOTE: To better understand how these functions work (i.e what is a chip
2492 * select and why do have to keep driving the eeprom clock?), read
2493 * just about any data sheet for a Microwire compatible EEPROM.
2494 */
2495
2496/* write a 32 bit value into the indirect accessor register */
2497static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2498{
2499 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002500
James Ketrenos43f66a62005-03-25 12:31:53 -06002501 /* the eeprom requires some time to complete the operation */
2502 udelay(p->eeprom_delay);
2503
2504 return;
2505}
2506
2507/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002508static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002509{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002510 eeprom_write_reg(priv, 0);
2511 eeprom_write_reg(priv, EEPROM_BIT_CS);
2512 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2513 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002514}
2515
2516/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002517static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002518{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002519 eeprom_write_reg(priv, EEPROM_BIT_CS);
2520 eeprom_write_reg(priv, 0);
2521 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002522}
2523
2524/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002525static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002526{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002527 int d = (bit ? EEPROM_BIT_DI : 0);
2528 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2529 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002530}
2531
2532/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002533static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002534{
2535 int i;
2536
2537 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002538 eeprom_write_bit(priv, 1);
2539 eeprom_write_bit(priv, op & 2);
2540 eeprom_write_bit(priv, op & 1);
2541 for (i = 7; i >= 0; i--) {
2542 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002543 }
2544}
2545
2546/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002547static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002548{
2549 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002550 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002551
James Ketrenos43f66a62005-03-25 12:31:53 -06002552 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002553 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002554
2555 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002556 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002557
2558 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002559 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002560 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002561 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2562 eeprom_write_reg(priv, EEPROM_BIT_CS);
2563 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2564 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002565 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002566
James Ketrenos43f66a62005-03-25 12:31:53 -06002567 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002568 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002569 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002570
James Ketrenos43f66a62005-03-25 12:31:53 -06002571 return r;
2572}
2573
2574/* helper function for pulling the mac address out of the private */
2575/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002576static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002577{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002578 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002579}
2580
2581/*
2582 * Either the device driver (i.e. the host) or the firmware can
2583 * load eeprom data into the designated region in SRAM. If neither
2584 * happens then the FW will shutdown with a fatal error.
2585 *
2586 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2587 * bit needs region of shared SRAM needs to be non-zero.
2588 */
2589static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2590{
2591 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002592 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002593
James Ketrenos43f66a62005-03-25 12:31:53 -06002594 IPW_DEBUG_TRACE(">>\n");
2595
2596 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002597 for (i = 0; i < 128; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002598 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002599
Jeff Garzikbf794512005-07-31 13:07:26 -04002600 /*
2601 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002602 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002603 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002604 */
Alexey Dobriyan386093e2006-02-01 03:04:57 -08002605 if (priv->eeprom[EEPROM_VERSION] != 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002606 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2607
2608 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002609 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002610 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002611
2612 /* Do not load eeprom data on fatal error or suspend */
2613 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2614 } else {
2615 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2616
2617 /* Load eeprom data on fatal error or suspend */
2618 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2619 }
2620
2621 IPW_DEBUG_TRACE("<<\n");
2622}
2623
Arjan van de Ven858119e2006-01-14 13:20:43 -08002624static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002625{
2626 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002627 if (!count)
2628 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002629 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002630 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002631 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002632}
2633
2634static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2635{
James Ketrenosb095c382005-08-24 22:04:42 -05002636 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002637 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002638 sizeof(struct command_block));
2639}
2640
2641static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002642{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002643
2644 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002645
James Ketrenos43f66a62005-03-25 12:31:53 -06002646 /* Start the dma */
2647 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002648
James Ketrenos43f66a62005-03-25 12:31:53 -06002649 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002650 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002651
2652 IPW_DEBUG_FW("<< : \n");
2653 return 0;
2654}
2655
2656static void ipw_fw_dma_abort(struct ipw_priv *priv)
2657{
2658 u32 control = 0;
2659
2660 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002661
Pavel Machek67fd6b42006-07-11 15:34:05 +02002662 /* set the Stop and Abort bit */
James Ketrenos43f66a62005-03-25 12:31:53 -06002663 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002664 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002665 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002666
James Ketrenos43f66a62005-03-25 12:31:53 -06002667 IPW_DEBUG_FW("<< \n");
2668}
2669
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002670static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2671 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002672{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002673 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002674 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002675 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002676 IPW_DEBUG_FW(">> :\n");
2677
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002678 ipw_write_indirect(priv, address, (u8 *) cb,
2679 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002680
2681 IPW_DEBUG_FW("<< :\n");
2682 return 0;
2683
2684}
2685
2686static int ipw_fw_dma_kick(struct ipw_priv *priv)
2687{
2688 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002689 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002690
2691 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002692
James Ketrenos43f66a62005-03-25 12:31:53 -06002693 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002694 ipw_fw_dma_write_command_block(priv, index,
2695 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002696
2697 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002698 ipw_clear_bit(priv, IPW_RESET_REG,
2699 IPW_RESET_REG_MASTER_DISABLED |
2700 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002701
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002702 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002703 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002704 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002705
2706 IPW_DEBUG_FW("<< :\n");
2707 return 0;
2708}
2709
2710static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2711{
2712 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002713 u32 register_value = 0;
2714 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002715
2716 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002717 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002718 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002719
2720 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002721 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2722 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002723
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002724 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002725 cb_fields_address = address;
2726 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002727 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002728
2729 cb_fields_address += sizeof(u32);
2730 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002731 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002732
2733 cb_fields_address += sizeof(u32);
2734 register_value = ipw_read_reg32(priv, cb_fields_address);
2735 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2736 register_value);
2737
2738 cb_fields_address += sizeof(u32);
2739 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002740 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002741
2742 IPW_DEBUG_FW(">> :\n");
2743}
2744
2745static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2746{
2747 u32 current_cb_address = 0;
2748 u32 current_cb_index = 0;
2749
2750 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002751 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002752
James Ketrenosb095c382005-08-24 22:04:42 -05002753 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002754 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002755
James Ketrenos43f66a62005-03-25 12:31:53 -06002756 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002757 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002758
2759 IPW_DEBUG_FW(">> :\n");
2760 return current_cb_index;
2761
2762}
2763
2764static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2765 u32 src_address,
2766 u32 dest_address,
2767 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002768 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002769{
2770
Jeff Garzikbf794512005-07-31 13:07:26 -04002771 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002772 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2773 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002774 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002775 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002776
2777 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2778 src_address, dest_address, length);
2779
2780 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2781 return -1;
2782
2783 last_cb_element = priv->sram_desc.last_cb_index;
2784 cb = &priv->sram_desc.cb_list[last_cb_element];
2785 priv->sram_desc.last_cb_index++;
2786
2787 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002788 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002789 control |= CB_INT_ENABLED;
2790
2791 if (is_last)
2792 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002793
James Ketrenos43f66a62005-03-25 12:31:53 -06002794 control |= length;
2795
2796 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002797 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002798
2799 /* Copy the Source and Destination addresses */
2800 cb->dest_addr = dest_address;
2801 cb->source_addr = src_address;
2802
2803 /* Copy the Control Word last */
2804 cb->control = control;
2805
2806 return 0;
2807}
2808
2809static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002810 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06002811{
2812 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002813 u32 src_offset = 0;
2814 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002815 int status = 0;
2816 IPW_DEBUG_FW(">> \n");
2817 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2818 src_phys, dest_address, length);
2819 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002820 status = ipw_fw_dma_add_command_block(priv,
2821 src_phys + src_offset,
2822 dest_address +
2823 dest_offset,
2824 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002825 if (status) {
2826 IPW_DEBUG_FW_INFO(": Failed\n");
2827 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002828 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002829 IPW_DEBUG_FW_INFO(": Added new cb\n");
2830
2831 src_offset += CB_MAX_LENGTH;
2832 dest_offset += CB_MAX_LENGTH;
2833 bytes_left -= CB_MAX_LENGTH;
2834 }
2835
2836 /* add the buffer tail */
2837 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002838 status =
2839 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2840 dest_address + dest_offset,
2841 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002842 if (status) {
2843 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2844 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002845 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002846 IPW_DEBUG_FW_INFO
2847 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002848 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002849
James Ketrenos43f66a62005-03-25 12:31:53 -06002850 IPW_DEBUG_FW("<< \n");
2851 return 0;
2852}
2853
2854static int ipw_fw_dma_wait(struct ipw_priv *priv)
2855{
Zhu Yi397ae122006-01-24 16:37:22 +08002856 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002857 u32 watchdog = 0;
2858
2859 IPW_DEBUG_FW(">> : \n");
2860
2861 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002862 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002863 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002864
2865 while (current_index < priv->sram_desc.last_cb_index) {
2866 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002867 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002868 current_index = ipw_fw_dma_command_block_index(priv);
2869
Zhu Yi397ae122006-01-24 16:37:22 +08002870 if (previous_index < current_index) {
2871 watchdog = 0;
2872 continue;
2873 }
2874 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002875 IPW_DEBUG_FW_INFO("Timeout\n");
2876 ipw_fw_dma_dump_command_block(priv);
2877 ipw_fw_dma_abort(priv);
2878 return -1;
2879 }
2880 }
2881
2882 ipw_fw_dma_abort(priv);
2883
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002884 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002885 ipw_set_bit(priv, IPW_RESET_REG,
2886 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002887
2888 IPW_DEBUG_FW("<< dmaWaitSync \n");
2889 return 0;
2890}
2891
Jeff Garzikbf794512005-07-31 13:07:26 -04002892static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002893{
2894 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002895 struct ieee80211_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002896 unsigned long flags;
2897
2898 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002899 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2900 network = list_entry(element, struct ieee80211_network, list);
2901 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2902 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002903 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002904 &priv->ieee->network_free_list);
2905 }
2906 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002907 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002908}
2909
2910/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002911 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002912 * Reads debug register from domain0.
2913 * If card is present, pre-defined value should
2914 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002915 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002916 * @param priv
2917 * @return 1 if card is present, 0 otherwise
2918 */
2919static inline int ipw_alive(struct ipw_priv *priv)
2920{
2921 return ipw_read32(priv, 0x90) == 0xd55555d5;
2922}
2923
Zhu Yic7b6a672006-01-24 16:37:05 +08002924/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002925static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06002926 int timeout)
2927{
2928 int i = 0;
2929
2930 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002931 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002932 return i;
2933 mdelay(10);
2934 i += 10;
2935 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002936
James Ketrenos43f66a62005-03-25 12:31:53 -06002937 return -ETIME;
2938}
2939
Jeff Garzikbf794512005-07-31 13:07:26 -04002940/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002941 * the ipw hardware. It assumes the buffer has all the bits for the
2942 * image and the caller is handling the memory allocation and clean up.
2943 */
2944
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002945static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002946{
2947 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002948
James Ketrenos43f66a62005-03-25 12:31:53 -06002949 IPW_DEBUG_TRACE(">> \n");
2950 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05002951 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002952
Zhu Yic7b6a672006-01-24 16:37:05 +08002953 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05002954 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2955 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06002956 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08002957 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002958 return -1;
2959 }
2960
2961 IPW_DEBUG_INFO("stop master %dms\n", rc);
2962
2963 return rc;
2964}
2965
2966static void ipw_arc_release(struct ipw_priv *priv)
2967{
2968 IPW_DEBUG_TRACE(">> \n");
2969 mdelay(5);
2970
James Ketrenosb095c382005-08-24 22:04:42 -05002971 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002972
2973 /* no one knows timing, for safety add some delay */
2974 mdelay(5);
2975}
2976
James Ketrenos43f66a62005-03-25 12:31:53 -06002977struct fw_chunk {
2978 u32 address;
2979 u32 length;
2980};
2981
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002982static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002983{
2984 int rc = 0, i, addr;
2985 u8 cr = 0;
2986 u16 *image;
2987
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002988 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002989
James Ketrenos43f66a62005-03-25 12:31:53 -06002990 IPW_DEBUG_TRACE(">> \n");
2991
2992 rc = ipw_stop_master(priv);
2993
2994 if (rc < 0)
2995 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002996
James Ketrenosb095c382005-08-24 22:04:42 -05002997 for (addr = IPW_SHARED_LOWER_BOUND;
2998 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002999 ipw_write32(priv, addr, 0);
3000 }
3001
3002 /* no ucode (yet) */
3003 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
3004 /* destroy DMA queues */
3005 /* reset sequence */
3006
James Ketrenosb095c382005-08-24 22:04:42 -05003007 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06003008 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05003009 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06003010 mdelay(1);
3011
3012 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05003013 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06003014 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003015
James Ketrenosb095c382005-08-24 22:04:42 -05003016 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003017 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04003018
James Ketrenos43f66a62005-03-25 12:31:53 -06003019 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08003020 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
3021 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003022 mdelay(1);
3023
3024 /* write ucode */
3025 /**
3026 * @bug
3027 * Do NOT set indirect address register once and then
3028 * store data to indirect data register in the loop.
3029 * It seems very reasonable, but in this case DINO do not
3030 * accept ucode. It is essential to set address each time.
3031 */
3032 /* load new ipw uCode */
3033 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05003034 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
James Ketrenosa613bff2005-08-24 21:43:11 -05003035 cpu_to_le16(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06003036
James Ketrenos43f66a62005-03-25 12:31:53 -06003037 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05003038 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
3039 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06003040
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003041 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06003042
3043 /* wait for alive response */
3044 for (i = 0; i < 100; i++) {
3045 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05003046 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06003047 if (cr & DINO_RXFIFO_DATA)
3048 break;
3049 mdelay(1);
3050 }
3051
3052 if (cr & DINO_RXFIFO_DATA) {
3053 /* alive_command_responce size is NOT multiple of 4 */
3054 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04003055
3056 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06003057 response_buffer[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05003058 le32_to_cpu(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05003059 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06003060 memcpy(&priv->dino_alive, response_buffer,
3061 sizeof(priv->dino_alive));
3062 if (priv->dino_alive.alive_command == 1
3063 && priv->dino_alive.ucode_valid == 1) {
3064 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003065 IPW_DEBUG_INFO
3066 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
3067 "of %02d/%02d/%02d %02d:%02d\n",
3068 priv->dino_alive.software_revision,
3069 priv->dino_alive.software_revision,
3070 priv->dino_alive.device_identifier,
3071 priv->dino_alive.device_identifier,
3072 priv->dino_alive.time_stamp[0],
3073 priv->dino_alive.time_stamp[1],
3074 priv->dino_alive.time_stamp[2],
3075 priv->dino_alive.time_stamp[3],
3076 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06003077 } else {
3078 IPW_DEBUG_INFO("Microcode is not alive\n");
3079 rc = -EINVAL;
3080 }
3081 } else {
3082 IPW_DEBUG_INFO("No alive response from DINO\n");
3083 rc = -ETIME;
3084 }
3085
3086 /* disable DINO, otherwise for some reason
3087 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05003088 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06003089
James Ketrenos43f66a62005-03-25 12:31:53 -06003090 return rc;
3091}
3092
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003093static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06003094{
3095 int rc = -1;
3096 int offset = 0;
3097 struct fw_chunk *chunk;
3098 dma_addr_t shared_phys;
3099 u8 *shared_virt;
3100
3101 IPW_DEBUG_TRACE("<< : \n");
3102 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
3103
3104 if (!shared_virt)
3105 return -ENOMEM;
3106
3107 memmove(shared_virt, data, len);
3108
3109 /* Start the Dma */
3110 rc = ipw_fw_dma_enable(priv);
3111
3112 if (priv->sram_desc.last_cb_index > 0) {
3113 /* the DMA is already ready this would be a bug. */
3114 BUG();
3115 goto out;
3116 }
3117
3118 do {
3119 chunk = (struct fw_chunk *)(data + offset);
3120 offset += sizeof(struct fw_chunk);
3121 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003122 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003123 * offeset*/
3124 /* Dma loading */
3125 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
James Ketrenosa613bff2005-08-24 21:43:11 -05003126 le32_to_cpu(chunk->address),
3127 le32_to_cpu(chunk->length));
James Ketrenos43f66a62005-03-25 12:31:53 -06003128 if (rc) {
3129 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3130 goto out;
3131 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003132
James Ketrenosa613bff2005-08-24 21:43:11 -05003133 offset += le32_to_cpu(chunk->length);
James Ketrenos43f66a62005-03-25 12:31:53 -06003134 } while (offset < len);
3135
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003136 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06003137 rc = ipw_fw_dma_kick(priv);
3138 if (rc) {
3139 IPW_ERROR("dmaKick Failed\n");
3140 goto out;
3141 }
3142
3143 rc = ipw_fw_dma_wait(priv);
3144 if (rc) {
3145 IPW_ERROR("dmaWaitSync Failed\n");
3146 goto out;
3147 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003148 out:
3149 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06003150 return rc;
3151}
3152
3153/* stop nic */
3154static int ipw_stop_nic(struct ipw_priv *priv)
3155{
3156 int rc = 0;
3157
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003158 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003159 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003160
James Ketrenosb095c382005-08-24 22:04:42 -05003161 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3162 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003163 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003164 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003165 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003166 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003167
James Ketrenosb095c382005-08-24 22:04:42 -05003168 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003169
James Ketrenos43f66a62005-03-25 12:31:53 -06003170 return rc;
3171}
3172
3173static void ipw_start_nic(struct ipw_priv *priv)
3174{
3175 IPW_DEBUG_TRACE(">>\n");
3176
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003177 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003178 ipw_clear_bit(priv, IPW_RESET_REG,
3179 IPW_RESET_REG_MASTER_DISABLED |
3180 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003181 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003182
James Ketrenos43f66a62005-03-25 12:31:53 -06003183 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003184 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3185 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003186
3187 IPW_DEBUG_TRACE("<<\n");
3188}
Jeff Garzikbf794512005-07-31 13:07:26 -04003189
James Ketrenos43f66a62005-03-25 12:31:53 -06003190static int ipw_init_nic(struct ipw_priv *priv)
3191{
3192 int rc;
3193
3194 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003195 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003196 /*prvHwInitNic */
3197 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003198 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003199
3200 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003201 ipw_write32(priv, IPW_READ_INT_REGISTER,
3202 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003203
3204 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003205 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3206 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003207 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003208 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3209
3210 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003211 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003212
3213 udelay(10);
3214
3215 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003216 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003217
3218 IPW_DEBUG_TRACE(">>\n");
3219 return 0;
3220}
3221
Jeff Garzikbf794512005-07-31 13:07:26 -04003222/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003223 * Probe is an ok place to call this from.
3224 */
3225static int ipw_reset_nic(struct ipw_priv *priv)
3226{
3227 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003228 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003229
3230 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003231
James Ketrenos43f66a62005-03-25 12:31:53 -06003232 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003233
James Ketrenosa613bff2005-08-24 21:43:11 -05003234 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003235 /* Clear the 'host command active' bit... */
3236 priv->status &= ~STATUS_HCMD_ACTIVE;
3237 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003238 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3239 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003240 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003241
3242 IPW_DEBUG_TRACE("<<\n");
3243 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003244}
James Ketrenos43f66a62005-03-25 12:31:53 -06003245
James Ketrenos9006ea72006-03-08 03:22:28 +08003246
3247struct ipw_fw {
Zhu Yi0070f8c2006-04-13 17:20:12 +08003248 __le32 ver;
3249 __le32 boot_size;
3250 __le32 ucode_size;
3251 __le32 fw_size;
James Ketrenos9006ea72006-03-08 03:22:28 +08003252 u8 data[0];
3253};
3254
Jeff Garzikbf794512005-07-31 13:07:26 -04003255static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos9006ea72006-03-08 03:22:28 +08003256 const struct firmware **raw, const char *name)
James Ketrenos43f66a62005-03-25 12:31:53 -06003257{
James Ketrenos9006ea72006-03-08 03:22:28 +08003258 struct ipw_fw *fw;
James Ketrenos43f66a62005-03-25 12:31:53 -06003259 int rc;
3260
3261 /* ask firmware_class module to get the boot firmware off disk */
James Ketrenos9006ea72006-03-08 03:22:28 +08003262 rc = request_firmware(raw, name, &priv->pci_dev->dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06003263 if (rc < 0) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003264 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003265 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003266 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003267
James Ketrenos9006ea72006-03-08 03:22:28 +08003268 if ((*raw)->size < sizeof(*fw)) {
3269 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003270 return -EINVAL;
3271 }
3272
James Ketrenos9006ea72006-03-08 03:22:28 +08003273 fw = (void *)(*raw)->data;
3274
Zhu Yi0070f8c2006-04-13 17:20:12 +08003275 if ((*raw)->size < sizeof(*fw) + le32_to_cpu(fw->boot_size) +
3276 le32_to_cpu(fw->ucode_size) + le32_to_cpu(fw->fw_size)) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003277 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3278 name, (*raw)->size);
3279 return -EINVAL;
3280 }
3281
3282 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003283 name,
James Ketrenos9006ea72006-03-08 03:22:28 +08003284 le32_to_cpu(fw->ver) >> 16,
3285 le32_to_cpu(fw->ver) & 0xff,
3286 (*raw)->size - sizeof(*fw));
James Ketrenos43f66a62005-03-25 12:31:53 -06003287 return 0;
3288}
3289
James Ketrenosb095c382005-08-24 22:04:42 -05003290#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003291
Arjan van de Ven858119e2006-01-14 13:20:43 -08003292static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003293 struct ipw_rx_queue *rxq)
3294{
3295 unsigned long flags;
3296 int i;
3297
3298 spin_lock_irqsave(&rxq->lock, flags);
3299
3300 INIT_LIST_HEAD(&rxq->rx_free);
3301 INIT_LIST_HEAD(&rxq->rx_used);
3302
3303 /* Fill the rx_used queue with _all_ of the Rx buffers */
3304 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3305 /* In the reset function, these buffers may have been allocated
3306 * to an SKB, so we need to unmap and free potential storage */
3307 if (rxq->pool[i].skb != NULL) {
3308 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003309 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003310 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003311 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003312 }
3313 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3314 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003315
James Ketrenos43f66a62005-03-25 12:31:53 -06003316 /* Set us so that we have processed and used all buffers, but have
3317 * not restocked the Rx queue with fresh buffers */
3318 rxq->read = rxq->write = 0;
3319 rxq->processed = RX_QUEUE_SIZE - 1;
3320 rxq->free_count = 0;
3321 spin_unlock_irqrestore(&rxq->lock, flags);
3322}
3323
3324#ifdef CONFIG_PM
3325static int fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003326static const struct firmware *raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003327
3328static void free_firmware(void)
3329{
3330 if (fw_loaded) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003331 release_firmware(raw);
3332 raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003333 fw_loaded = 0;
3334 }
3335}
3336#else
3337#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003338#endif
3339
3340static int ipw_load(struct ipw_priv *priv)
3341{
3342#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003343 const struct firmware *raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003344#endif
James Ketrenos9006ea72006-03-08 03:22:28 +08003345 struct ipw_fw *fw;
3346 u8 *boot_img, *ucode_img, *fw_img;
3347 u8 *name = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003348 int rc = 0, retries = 3;
3349
Zhu Yi397ae122006-01-24 16:37:22 +08003350 switch (priv->ieee->iw_mode) {
3351 case IW_MODE_ADHOC:
James Ketrenos9006ea72006-03-08 03:22:28 +08003352 name = "ipw2200-ibss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003353 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003354#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003355 case IW_MODE_MONITOR:
James Ketrenos9006ea72006-03-08 03:22:28 +08003356 name = "ipw2200-sniffer.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003357 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003358#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003359 case IW_MODE_INFRA:
James Ketrenos9006ea72006-03-08 03:22:28 +08003360 name = "ipw2200-bss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003361 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003362 }
Zhu Yi397ae122006-01-24 16:37:22 +08003363
James Ketrenos9006ea72006-03-08 03:22:28 +08003364 if (!name) {
3365 rc = -EINVAL;
3366 goto error;
3367 }
3368
3369#ifdef CONFIG_PM
3370 if (!fw_loaded) {
3371#endif
3372 rc = ipw_get_fw(priv, &raw, name);
3373 if (rc < 0)
3374 goto error;
3375#ifdef CONFIG_PM
3376 }
3377#endif
3378
3379 fw = (void *)raw->data;
3380 boot_img = &fw->data[0];
Zhu Yi0070f8c2006-04-13 17:20:12 +08003381 ucode_img = &fw->data[le32_to_cpu(fw->boot_size)];
3382 fw_img = &fw->data[le32_to_cpu(fw->boot_size) +
3383 le32_to_cpu(fw->ucode_size)];
James Ketrenos9006ea72006-03-08 03:22:28 +08003384
Zhu Yi397ae122006-01-24 16:37:22 +08003385 if (rc < 0)
3386 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003387
3388 if (!priv->rxq)
3389 priv->rxq = ipw_rx_queue_alloc(priv);
3390 else
3391 ipw_rx_queue_reset(priv, priv->rxq);
3392 if (!priv->rxq) {
3393 IPW_ERROR("Unable to initialize Rx queue\n");
3394 goto error;
3395 }
3396
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003397 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003398 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003399 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003400 priv->status &= ~STATUS_INT_ENABLED;
3401
3402 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003403 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003404
James Ketrenos43f66a62005-03-25 12:31:53 -06003405 ipw_stop_nic(priv);
3406
3407 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003408 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003409 IPW_ERROR("Unable to reset NIC\n");
3410 goto error;
3411 }
3412
James Ketrenosb095c382005-08-24 22:04:42 -05003413 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3414 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003415
3416 /* DMA the initial boot firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003417 rc = ipw_load_firmware(priv, boot_img, le32_to_cpu(fw->boot_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003418 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003419 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003420 goto error;
3421 }
3422
3423 /* kick start the device */
3424 ipw_start_nic(priv);
3425
Zhu Yic7b6a672006-01-24 16:37:05 +08003426 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003427 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3428 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003429 if (rc < 0) {
3430 IPW_ERROR("device failed to boot initial fw image\n");
3431 goto error;
3432 }
3433 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3434
Jeff Garzikbf794512005-07-31 13:07:26 -04003435 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003436 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003437
3438 /* DMA the ucode into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003439 rc = ipw_load_ucode(priv, ucode_img, le32_to_cpu(fw->ucode_size));
James Ketrenos43f66a62005-03-25 12:31:53 -06003440 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003441 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003442 goto error;
3443 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003444
James Ketrenos43f66a62005-03-25 12:31:53 -06003445 /* stop nic */
3446 ipw_stop_nic(priv);
3447
3448 /* DMA bss firmware into the device */
Zhu Yi0070f8c2006-04-13 17:20:12 +08003449 rc = ipw_load_firmware(priv, fw_img, le32_to_cpu(fw->fw_size));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003450 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003451 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003452 goto error;
3453 }
Zhu Yi397ae122006-01-24 16:37:22 +08003454#ifdef CONFIG_PM
3455 fw_loaded = 1;
3456#endif
3457
James Ketrenos43f66a62005-03-25 12:31:53 -06003458 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3459
3460 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003461 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003462 IPW_ERROR("Unable to initialize queues\n");
3463 goto error;
3464 }
3465
3466 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003467 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003468 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003469 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003470
James Ketrenos43f66a62005-03-25 12:31:53 -06003471 /* kick start the device */
3472 ipw_start_nic(priv);
3473
James Ketrenosb095c382005-08-24 22:04:42 -05003474 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003475 if (retries > 0) {
3476 IPW_WARNING("Parity error. Retrying init.\n");
3477 retries--;
3478 goto retry;
3479 }
3480
3481 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3482 rc = -EIO;
3483 goto error;
3484 }
3485
3486 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003487 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3488 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003489 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003490 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003491 goto error;
3492 }
3493 IPW_DEBUG_INFO("device response after %dms\n", rc);
3494
3495 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003496 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003497
3498 /* read eeprom data and initialize the eeprom region of sram */
3499 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003500 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003501
3502 /* enable interrupts */
3503 ipw_enable_interrupts(priv);
3504
3505 /* Ensure our queue has valid packets */
3506 ipw_rx_queue_replenish(priv);
3507
James Ketrenosb095c382005-08-24 22:04:42 -05003508 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003509
3510 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003511 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003512
3513#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003514 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003515#endif
3516 return 0;
3517
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003518 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003519 if (priv->rxq) {
3520 ipw_rx_queue_free(priv, priv->rxq);
3521 priv->rxq = NULL;
3522 }
3523 ipw_tx_queue_free(priv);
James Ketrenos9006ea72006-03-08 03:22:28 +08003524 if (raw)
3525 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003526#ifdef CONFIG_PM
3527 fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003528 raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003529#endif
3530
3531 return rc;
3532}
3533
Jeff Garzikbf794512005-07-31 13:07:26 -04003534/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003535 * DMA services
3536 *
3537 * Theory of operation
3538 *
3539 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3540 * 2 empty entries always kept in the buffer to protect from overflow.
3541 *
3542 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003543 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3544 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003545 * Tx queue resumed.
3546 *
3547 * The IPW operates with six queues, one receive queue in the device's
3548 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003549 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003550 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003551 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003552 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003553 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003554 * we only utilize the first data transmit queue (queue1).
3555 */
3556
3557/**
3558 * Driver allocates buffers of this size for Rx
3559 */
3560
3561static inline int ipw_queue_space(const struct clx2_queue *q)
3562{
3563 int s = q->last_used - q->first_empty;
3564 if (s <= 0)
3565 s += q->n_bd;
3566 s -= 2; /* keep some reserve to not confuse empty and full situations */
3567 if (s < 0)
3568 s = 0;
3569 return s;
3570}
3571
3572static inline int ipw_queue_inc_wrap(int index, int n_bd)
3573{
3574 return (++index == n_bd) ? 0 : index;
3575}
3576
3577/**
3578 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003579 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003580 * @param q queue to init
3581 * @param count Number of BD's to allocate. Should be power of 2
3582 * @param read_register Address for 'read' register
3583 * (not offset within BAR, full address)
3584 * @param write_register Address for 'write' register
3585 * (not offset within BAR, full address)
3586 * @param base_register Address for 'base' register
3587 * (not offset within BAR, full address)
3588 * @param size Address for 'size' register
3589 * (not offset within BAR, full address)
3590 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003591static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003592 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003593{
3594 q->n_bd = count;
3595
3596 q->low_mark = q->n_bd / 4;
3597 if (q->low_mark < 4)
3598 q->low_mark = 4;
3599
3600 q->high_mark = q->n_bd / 8;
3601 if (q->high_mark < 2)
3602 q->high_mark = 2;
3603
3604 q->first_empty = q->last_used = 0;
3605 q->reg_r = read;
3606 q->reg_w = write;
3607
3608 ipw_write32(priv, base, q->dma_addr);
3609 ipw_write32(priv, size, count);
3610 ipw_write32(priv, read, 0);
3611 ipw_write32(priv, write, 0);
3612
3613 _ipw_read32(priv, 0x90);
3614}
3615
Jeff Garzikbf794512005-07-31 13:07:26 -04003616static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003617 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003618 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003619{
3620 struct pci_dev *dev = priv->pci_dev;
3621
3622 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3623 if (!q->txb) {
3624 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3625 return -ENOMEM;
3626 }
3627
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003628 q->bd =
3629 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003630 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003631 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003632 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003633 kfree(q->txb);
3634 q->txb = NULL;
3635 return -ENOMEM;
3636 }
3637
3638 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3639 return 0;
3640}
3641
3642/**
3643 * Free one TFD, those at index [txq->q.last_used].
3644 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003645 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003646 * @param dev
3647 * @param txq
3648 */
3649static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3650 struct clx2_tx_queue *txq)
3651{
3652 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3653 struct pci_dev *dev = priv->pci_dev;
3654 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003655
James Ketrenos43f66a62005-03-25 12:31:53 -06003656 /* classify bd */
3657 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3658 /* nothing to cleanup after for host commands */
3659 return;
3660
3661 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003662 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3663 IPW_ERROR("Too many chunks: %i\n",
3664 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003665 /** @todo issue fatal error, it is quite serious situation */
3666 return;
3667 }
3668
3669 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003670 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3671 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3672 le16_to_cpu(bd->u.data.chunk_len[i]),
3673 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003674 if (txq->txb[txq->q.last_used]) {
3675 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3676 txq->txb[txq->q.last_used] = NULL;
3677 }
3678 }
3679}
3680
3681/**
3682 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003683 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003684 * Empty queue by removing and destroying all BD's.
3685 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003686 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003687 * @param dev
3688 * @param q
3689 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003690static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003691{
3692 struct clx2_queue *q = &txq->q;
3693 struct pci_dev *dev = priv->pci_dev;
3694
Jeff Garzikbf794512005-07-31 13:07:26 -04003695 if (q->n_bd == 0)
3696 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003697
3698 /* first, empty all BD's */
3699 for (; q->first_empty != q->last_used;
3700 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3701 ipw_queue_tx_free_tfd(priv, txq);
3702 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003703
James Ketrenos43f66a62005-03-25 12:31:53 -06003704 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003705 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003706 q->dma_addr);
3707 kfree(txq->txb);
3708
3709 /* 0 fill whole structure */
3710 memset(txq, 0, sizeof(*txq));
3711}
3712
James Ketrenos43f66a62005-03-25 12:31:53 -06003713/**
3714 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003715 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003716 * @param priv
3717 */
3718static void ipw_tx_queue_free(struct ipw_priv *priv)
3719{
3720 /* Tx CMD queue */
3721 ipw_queue_tx_free(priv, &priv->txq_cmd);
3722
3723 /* Tx queues */
3724 ipw_queue_tx_free(priv, &priv->txq[0]);
3725 ipw_queue_tx_free(priv, &priv->txq[1]);
3726 ipw_queue_tx_free(priv, &priv->txq[2]);
3727 ipw_queue_tx_free(priv, &priv->txq[3]);
3728}
3729
Arjan van de Ven858119e2006-01-14 13:20:43 -08003730static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003731{
3732 /* First 3 bytes are manufacturer */
3733 bssid[0] = priv->mac_addr[0];
3734 bssid[1] = priv->mac_addr[1];
3735 bssid[2] = priv->mac_addr[2];
3736
3737 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003738 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003739
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003740 bssid[0] &= 0xfe; /* clear multicast bit */
3741 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003742}
3743
Arjan van de Ven858119e2006-01-14 13:20:43 -08003744static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003745{
3746 struct ipw_station_entry entry;
3747 int i;
3748
3749 for (i = 0; i < priv->num_stations; i++) {
3750 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3751 /* Another node is active in network */
3752 priv->missed_adhoc_beacons = 0;
3753 if (!(priv->config & CFG_STATIC_CHANNEL))
3754 /* when other nodes drop out, we drop out */
3755 priv->config &= ~CFG_ADHOC_PERSIST;
3756
3757 return i;
3758 }
3759 }
3760
3761 if (i == MAX_STATIONS)
3762 return IPW_INVALID_STATION;
3763
3764 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3765
3766 entry.reserved = 0;
3767 entry.support_mode = 0;
3768 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3769 memcpy(priv->stations[i], bssid, ETH_ALEN);
3770 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003771 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003772 priv->num_stations++;
3773
3774 return i;
3775}
3776
Arjan van de Ven858119e2006-01-14 13:20:43 -08003777static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003778{
3779 int i;
3780
Jeff Garzikbf794512005-07-31 13:07:26 -04003781 for (i = 0; i < priv->num_stations; i++)
3782 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003783 return i;
3784
3785 return IPW_INVALID_STATION;
3786}
3787
3788static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3789{
3790 int err;
3791
Hong Liu7b996592005-08-25 17:36:13 +08003792 if (priv->status & STATUS_ASSOCIATING) {
3793 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3794 queue_work(priv->workqueue, &priv->disassociate);
3795 return;
3796 }
3797
3798 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003799 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3800 return;
3801 }
3802
3803 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3804 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04003805 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06003806 priv->assoc_request.channel);
3807
3808 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3809 priv->status |= STATUS_DISASSOCIATING;
3810
3811 if (quiet)
3812 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3813 else
3814 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003815
James Ketrenos43f66a62005-03-25 12:31:53 -06003816 err = ipw_send_associate(priv, &priv->assoc_request);
3817 if (err) {
3818 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3819 "failed.\n");
3820 return;
3821 }
3822
3823}
3824
James Ketrenosc848d0a2005-08-24 21:56:24 -05003825static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003826{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003827 struct ipw_priv *priv = data;
3828 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3829 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003830 ipw_send_disassociate(data, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003831 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003832}
3833
James Ketrenosc848d0a2005-08-24 21:56:24 -05003834static void ipw_bg_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003835{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003836 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08003837 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003838 ipw_disassociate(data);
Zhu Yi46441512006-01-24 16:37:59 +08003839 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003840}
3841
Zhu Yid8bad6d2005-07-13 12:25:38 -05003842static void ipw_system_config(void *data)
3843{
3844 struct ipw_priv *priv = data;
Zhu Yid685b8c2006-04-13 17:20:27 +08003845
3846#ifdef CONFIG_IPW2200_PROMISCUOUS
3847 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
3848 priv->sys_config.accept_all_data_frames = 1;
3849 priv->sys_config.accept_non_directed_frames = 1;
3850 priv->sys_config.accept_all_mgmt_bcpr = 1;
3851 priv->sys_config.accept_all_mgmt_frames = 1;
3852 }
3853#endif
3854
3855 ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003856}
3857
3858struct ipw_status_code {
3859 u16 status;
3860 const char *reason;
3861};
3862
3863static const struct ipw_status_code ipw_status_codes[] = {
3864 {0x00, "Successful"},
3865 {0x01, "Unspecified failure"},
3866 {0x0A, "Cannot support all requested capabilities in the "
3867 "Capability information field"},
3868 {0x0B, "Reassociation denied due to inability to confirm that "
3869 "association exists"},
3870 {0x0C, "Association denied due to reason outside the scope of this "
3871 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003872 {0x0D,
3873 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003874 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003875 {0x0E,
3876 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003877 "transaction sequence number out of expected sequence"},
3878 {0x0F, "Authentication rejected because of challenge failure"},
3879 {0x10, "Authentication rejected due to timeout waiting for next "
3880 "frame in sequence"},
3881 {0x11, "Association denied because AP is unable to handle additional "
3882 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003883 {0x12,
3884 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003885 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003886 {0x13,
3887 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003888 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003889 {0x14,
3890 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003891 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003892 {0x15,
3893 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003894 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003895 {0x19,
3896 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003897 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003898 {0x1A,
3899 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003900 "DSSS-OFDM operation"},
3901 {0x28, "Invalid Information Element"},
3902 {0x29, "Group Cipher is not valid"},
3903 {0x2A, "Pairwise Cipher is not valid"},
3904 {0x2B, "AKMP is not valid"},
3905 {0x2C, "Unsupported RSN IE version"},
3906 {0x2D, "Invalid RSN IE Capabilities"},
3907 {0x2E, "Cipher suite is rejected per security policy"},
3908};
3909
Jeff Garzikbf794512005-07-31 13:07:26 -04003910static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003911{
3912 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003913 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003914 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003915 return ipw_status_codes[i].reason;
3916 return "Unknown status value.";
3917}
James Ketrenos43f66a62005-03-25 12:31:53 -06003918
3919static void inline average_init(struct average *avg)
3920{
3921 memset(avg, 0, sizeof(*avg));
3922}
3923
Zhu Yi00d21de2006-04-13 17:19:02 +08003924#define DEPTH_RSSI 8
3925#define DEPTH_NOISE 16
3926static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
3927{
3928 return ((depth-1)*prev_avg + val)/depth;
3929}
3930
Arjan van de Ven858119e2006-01-14 13:20:43 -08003931static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06003932{
3933 avg->sum -= avg->entries[avg->pos];
3934 avg->sum += val;
3935 avg->entries[avg->pos++] = val;
3936 if (unlikely(avg->pos == AVG_ENTRIES)) {
3937 avg->init = 1;
3938 avg->pos = 0;
3939 }
3940}
3941
Arjan van de Ven858119e2006-01-14 13:20:43 -08003942static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06003943{
3944 if (!unlikely(avg->init)) {
3945 if (avg->pos)
3946 return avg->sum / avg->pos;
3947 return 0;
3948 }
3949
3950 return avg->sum / AVG_ENTRIES;
3951}
3952
3953static void ipw_reset_stats(struct ipw_priv *priv)
3954{
3955 u32 len = sizeof(u32);
3956
3957 priv->quality = 0;
3958
3959 average_init(&priv->average_missed_beacons);
Zhu Yi00d21de2006-04-13 17:19:02 +08003960 priv->exp_avg_rssi = -60;
3961 priv->exp_avg_noise = -85 + 0x100;
James Ketrenos43f66a62005-03-25 12:31:53 -06003962
3963 priv->last_rate = 0;
3964 priv->last_missed_beacons = 0;
3965 priv->last_rx_packets = 0;
3966 priv->last_tx_packets = 0;
3967 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003968
James Ketrenos43f66a62005-03-25 12:31:53 -06003969 /* Firmware managed, reset only when NIC is restarted, so we have to
3970 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003971 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003972 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003973 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003974 &priv->last_tx_failures, &len);
3975
3976 /* Driver managed, reset with each association */
3977 priv->missed_adhoc_beacons = 0;
3978 priv->missed_beacons = 0;
3979 priv->tx_packets = 0;
3980 priv->rx_packets = 0;
3981
3982}
3983
Arjan van de Ven858119e2006-01-14 13:20:43 -08003984static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003985{
3986 u32 i = 0x80000000;
3987 u32 mask = priv->rates_mask;
3988 /* If currently associated in B mode, restrict the maximum
3989 * rate match to B rates */
3990 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3991 mask &= IEEE80211_CCK_RATES_MASK;
3992
3993 /* TODO: Verify that the rate is supported by the current rates
3994 * list. */
3995
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003996 while (i && !(mask & i))
3997 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003998 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003999 case IEEE80211_CCK_RATE_1MB_MASK:
4000 return 1000000;
4001 case IEEE80211_CCK_RATE_2MB_MASK:
4002 return 2000000;
4003 case IEEE80211_CCK_RATE_5MB_MASK:
4004 return 5500000;
4005 case IEEE80211_OFDM_RATE_6MB_MASK:
4006 return 6000000;
4007 case IEEE80211_OFDM_RATE_9MB_MASK:
4008 return 9000000;
4009 case IEEE80211_CCK_RATE_11MB_MASK:
4010 return 11000000;
4011 case IEEE80211_OFDM_RATE_12MB_MASK:
4012 return 12000000;
4013 case IEEE80211_OFDM_RATE_18MB_MASK:
4014 return 18000000;
4015 case IEEE80211_OFDM_RATE_24MB_MASK:
4016 return 24000000;
4017 case IEEE80211_OFDM_RATE_36MB_MASK:
4018 return 36000000;
4019 case IEEE80211_OFDM_RATE_48MB_MASK:
4020 return 48000000;
4021 case IEEE80211_OFDM_RATE_54MB_MASK:
4022 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004023 }
4024
Jeff Garzikbf794512005-07-31 13:07:26 -04004025 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06004026 return 11000000;
4027 else
4028 return 54000000;
4029}
4030
4031static u32 ipw_get_current_rate(struct ipw_priv *priv)
4032{
4033 u32 rate, len = sizeof(rate);
4034 int err;
4035
Jeff Garzikbf794512005-07-31 13:07:26 -04004036 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06004037 return 0;
4038
4039 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004040 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06004041 &len);
4042 if (err) {
4043 IPW_DEBUG_INFO("failed querying ordinals.\n");
4044 return 0;
4045 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004046 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06004047 return ipw_get_max_rate(priv);
4048
4049 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004050 case IPW_TX_RATE_1MB:
4051 return 1000000;
4052 case IPW_TX_RATE_2MB:
4053 return 2000000;
4054 case IPW_TX_RATE_5MB:
4055 return 5500000;
4056 case IPW_TX_RATE_6MB:
4057 return 6000000;
4058 case IPW_TX_RATE_9MB:
4059 return 9000000;
4060 case IPW_TX_RATE_11MB:
4061 return 11000000;
4062 case IPW_TX_RATE_12MB:
4063 return 12000000;
4064 case IPW_TX_RATE_18MB:
4065 return 18000000;
4066 case IPW_TX_RATE_24MB:
4067 return 24000000;
4068 case IPW_TX_RATE_36MB:
4069 return 36000000;
4070 case IPW_TX_RATE_48MB:
4071 return 48000000;
4072 case IPW_TX_RATE_54MB:
4073 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06004074 }
4075
4076 return 0;
4077}
4078
James Ketrenos43f66a62005-03-25 12:31:53 -06004079#define IPW_STATS_INTERVAL (2 * HZ)
4080static void ipw_gather_stats(struct ipw_priv *priv)
4081{
4082 u32 rx_err, rx_err_delta, rx_packets_delta;
4083 u32 tx_failures, tx_failures_delta, tx_packets_delta;
4084 u32 missed_beacons_percent, missed_beacons_delta;
4085 u32 quality = 0;
4086 u32 len = sizeof(u32);
4087 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04004088 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004089 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004090 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06004091
4092 if (!(priv->status & STATUS_ASSOCIATED)) {
4093 priv->quality = 0;
4094 return;
4095 }
4096
4097 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04004098 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06004099 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004100 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06004101 priv->last_missed_beacons = priv->missed_beacons;
4102 if (priv->assoc_request.beacon_interval) {
4103 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004104 (HZ * priv->assoc_request.beacon_interval) /
4105 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06004106 } else {
4107 missed_beacons_percent = 0;
4108 }
4109 average_add(&priv->average_missed_beacons, missed_beacons_percent);
4110
4111 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
4112 rx_err_delta = rx_err - priv->last_rx_err;
4113 priv->last_rx_err = rx_err;
4114
4115 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
4116 tx_failures_delta = tx_failures - priv->last_tx_failures;
4117 priv->last_tx_failures = tx_failures;
4118
4119 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4120 priv->last_rx_packets = priv->rx_packets;
4121
4122 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4123 priv->last_tx_packets = priv->tx_packets;
4124
4125 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004126 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004127 * Missed beacon: 100% = 0, 0% = 70% missed
4128 * Rate: 60% = 1Mbs, 100% = Max
4129 * Rx and Tx errors represent a straight % of total Rx/Tx
4130 * RSSI: 100% = > -50, 0% = < -80
4131 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004132 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004133 * The lowest computed quality is used.
4134 *
4135 */
4136#define BEACON_THRESHOLD 5
4137 beacon_quality = 100 - missed_beacons_percent;
4138 if (beacon_quality < BEACON_THRESHOLD)
4139 beacon_quality = 0;
4140 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004141 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004142 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004143 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004144 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004145
James Ketrenos43f66a62005-03-25 12:31:53 -06004146 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004147 max_rate = ipw_get_max_rate(priv);
4148 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004149 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4150 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004151
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004152 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004153 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004154 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004155 else
4156 rx_quality = 100;
4157 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4158 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004159
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004160 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004161 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004162 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004163 else
4164 tx_quality = 100;
4165 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4166 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004167
Zhu Yi00d21de2006-04-13 17:19:02 +08004168 rssi = priv->exp_avg_rssi;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004169 signal_quality =
4170 (100 *
4171 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4172 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4173 (priv->ieee->perfect_rssi - rssi) *
4174 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4175 62 * (priv->ieee->perfect_rssi - rssi))) /
4176 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4177 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4178 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004179 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004180 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004181 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004182
Zhu Yi61fb9ed2006-04-13 17:19:55 +08004183 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004184 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004185
4186 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06004187 min(rate_quality,
4188 min(tx_quality, min(rx_quality, signal_quality))));
4189 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004190 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4191 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004192 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004193 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4194 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004195 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004196 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4197 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004198 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004199 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4200 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004201 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004202 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4203 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004204
4205 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004206
4207 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004208 IPW_STATS_INTERVAL);
4209}
4210
James Ketrenosc848d0a2005-08-24 21:56:24 -05004211static void ipw_bg_gather_stats(void *data)
4212{
4213 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08004214 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004215 ipw_gather_stats(data);
Zhu Yi46441512006-01-24 16:37:59 +08004216 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004217}
4218
Ben Cahille7582562005-10-06 15:34:41 -05004219/* Missed beacon behavior:
4220 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4221 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4222 * Above disassociate threshold, give up and stop scanning.
4223 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004224static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004225 int missed_count)
4226{
4227 priv->notif_missed_beacons = missed_count;
4228
James Ketrenosafbf30a2005-08-25 00:05:33 -05004229 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004230 priv->status & STATUS_ASSOCIATED) {
4231 /* If associated and we've hit the missed
4232 * beacon threshold, disassociate, turn
4233 * off roaming, and abort any active scans */
4234 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004235 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004236 "Missed beacon: %d - disassociate\n", missed_count);
4237 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004238 if (priv->status & STATUS_SCANNING) {
4239 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4240 IPW_DL_STATE,
4241 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004242 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004243 }
4244
James Ketrenosea2b26e2005-08-24 21:25:16 -05004245 queue_work(priv->workqueue, &priv->disassociate);
4246 return;
4247 }
4248
4249 if (priv->status & STATUS_ROAMING) {
4250 /* If we are currently roaming, then just
4251 * print a debug statement... */
4252 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4253 "Missed beacon: %d - roam in progress\n",
4254 missed_count);
4255 return;
4256 }
4257
Zhu Yi4bfdb912006-01-24 16:37:16 +08004258 if (roaming &&
4259 (missed_count > priv->roaming_threshold &&
4260 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004261 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004262 * bit in the status and kick off a scan.
4263 * This can happen several times before we reach
4264 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004265 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4266 "Missed beacon: %d - initiate "
4267 "roaming\n", missed_count);
4268 if (!(priv->status & STATUS_ROAMING)) {
4269 priv->status |= STATUS_ROAMING;
4270 if (!(priv->status & STATUS_SCANNING))
4271 queue_work(priv->workqueue,
4272 &priv->request_scan);
4273 }
4274 return;
4275 }
4276
4277 if (priv->status & STATUS_SCANNING) {
4278 /* Stop scan to keep fw from getting
4279 * stuck (only if we aren't roaming --
4280 * otherwise we'll never scan more than 2 or 3
4281 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004282 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4283 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004284 queue_work(priv->workqueue, &priv->abort_scan);
4285 }
4286
4287 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004288}
4289
James Ketrenos43f66a62005-03-25 12:31:53 -06004290/**
4291 * Handle host notification packet.
4292 * Called from interrupt routine
4293 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004294static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004295 struct ipw_rx_notification *notif)
4296{
James Ketrenosa613bff2005-08-24 21:43:11 -05004297 notif->size = le16_to_cpu(notif->size);
4298
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004299 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004300
James Ketrenos43f66a62005-03-25 12:31:53 -06004301 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004302 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4303 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004304
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004305 switch (assoc->state) {
4306 case CMAS_ASSOCIATED:{
4307 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4308 IPW_DL_ASSOC,
4309 "associated: '%s' " MAC_FMT
4310 " \n",
4311 escape_essid(priv->essid,
4312 priv->essid_len),
4313 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04004314
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004315 switch (priv->ieee->iw_mode) {
4316 case IW_MODE_INFRA:
4317 memcpy(priv->ieee->bssid,
4318 priv->bssid, ETH_ALEN);
4319 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004320
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004321 case IW_MODE_ADHOC:
4322 memcpy(priv->ieee->bssid,
4323 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004324
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004325 /* clear out the station table */
4326 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004327
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004328 IPW_DEBUG_ASSOC
4329 ("queueing adhoc check\n");
4330 queue_delayed_work(priv->
4331 workqueue,
4332 &priv->
4333 adhoc_check,
4334 priv->
4335 assoc_request.
4336 beacon_interval);
4337 break;
4338 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004339
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004340 priv->status &= ~STATUS_ASSOCIATING;
4341 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004342 queue_work(priv->workqueue,
4343 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004344
Zhu Yie43e3c12006-04-13 17:20:45 +08004345#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004346#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4347 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4348 if ((priv->status & STATUS_AUTH) &&
4349 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4350 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004351 if ((sizeof
4352 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004353 ieee80211_assoc_response)
James Ketrenosb095c382005-08-24 22:04:42 -05004354 <= notif->size)
4355 && (notif->size <= 2314)) {
4356 struct
4357 ieee80211_rx_stats
4358 stats = {
4359 .len =
4360 notif->
4361 size - 1,
4362 };
4363
4364 IPW_DEBUG_QOS
4365 ("QoS Associate "
4366 "size %d\n",
4367 notif->size);
4368 ieee80211_rx_mgt(priv->
4369 ieee,
4370 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004371 ieee80211_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004372 *)
4373 &notif->u.raw, &stats);
4374 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004375 }
James Ketrenosb095c382005-08-24 22:04:42 -05004376#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004377
James Ketrenosa613bff2005-08-24 21:43:11 -05004378 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004379
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004380 break;
4381 }
4382
4383 case CMAS_AUTHENTICATED:{
4384 if (priv->
4385 status & (STATUS_ASSOCIATED |
4386 STATUS_AUTH)) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004387 struct notif_authenticate *auth
4388 = &notif->u.auth;
4389 IPW_DEBUG(IPW_DL_NOTIF |
4390 IPW_DL_STATE |
4391 IPW_DL_ASSOC,
4392 "deauthenticated: '%s' "
4393 MAC_FMT
4394 ": (0x%04X) - %s \n",
4395 escape_essid(priv->
4396 essid,
4397 priv->
4398 essid_len),
4399 MAC_ARG(priv->bssid),
4400 ntohs(auth->status),
4401 ipw_get_status_code
4402 (ntohs
4403 (auth->status)));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004404
4405 priv->status &=
4406 ~(STATUS_ASSOCIATING |
4407 STATUS_AUTH |
4408 STATUS_ASSOCIATED);
4409
James Ketrenosa613bff2005-08-24 21:43:11 -05004410 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004411 break;
4412 }
4413
4414 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4415 IPW_DL_ASSOC,
4416 "authenticated: '%s' " MAC_FMT
4417 "\n",
4418 escape_essid(priv->essid,
4419 priv->essid_len),
4420 MAC_ARG(priv->bssid));
4421 break;
4422 }
4423
4424 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004425 if (priv->status & STATUS_AUTH) {
4426 struct
4427 ieee80211_assoc_response
4428 *resp;
4429 resp =
4430 (struct
4431 ieee80211_assoc_response
4432 *)&notif->u.raw;
4433 IPW_DEBUG(IPW_DL_NOTIF |
4434 IPW_DL_STATE |
4435 IPW_DL_ASSOC,
4436 "association failed (0x%04X): %s\n",
4437 ntohs(resp->status),
4438 ipw_get_status_code
4439 (ntohs
4440 (resp->status)));
4441 }
4442
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004443 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4444 IPW_DL_ASSOC,
4445 "disassociated: '%s' " MAC_FMT
4446 " \n",
4447 escape_essid(priv->essid,
4448 priv->essid_len),
4449 MAC_ARG(priv->bssid));
4450
4451 priv->status &=
4452 ~(STATUS_DISASSOCIATING |
4453 STATUS_ASSOCIATING |
4454 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004455 if (priv->assoc_network
4456 && (priv->assoc_network->
4457 capability &
4458 WLAN_CAPABILITY_IBSS))
4459 ipw_remove_current_network
4460 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004461
James Ketrenosa613bff2005-08-24 21:43:11 -05004462 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004463
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004464 break;
4465 }
4466
James Ketrenosb095c382005-08-24 22:04:42 -05004467 case CMAS_RX_ASSOC_RESP:
4468 break;
4469
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004470 default:
4471 IPW_ERROR("assoc: unknown (%d)\n",
4472 assoc->state);
4473 break;
4474 }
4475
James Ketrenos43f66a62005-03-25 12:31:53 -06004476 break;
4477 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004478
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004479 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4480 struct notif_authenticate *auth = &notif->u.auth;
4481 switch (auth->state) {
4482 case CMAS_AUTHENTICATED:
4483 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4484 "authenticated: '%s' " MAC_FMT " \n",
4485 escape_essid(priv->essid,
4486 priv->essid_len),
4487 MAC_ARG(priv->bssid));
4488 priv->status |= STATUS_AUTH;
4489 break;
4490
4491 case CMAS_INIT:
4492 if (priv->status & STATUS_AUTH) {
4493 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4494 IPW_DL_ASSOC,
4495 "authentication failed (0x%04X): %s\n",
4496 ntohs(auth->status),
4497 ipw_get_status_code(ntohs
4498 (auth->
4499 status)));
4500 }
4501 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4502 IPW_DL_ASSOC,
4503 "deauthenticated: '%s' " MAC_FMT "\n",
4504 escape_essid(priv->essid,
4505 priv->essid_len),
4506 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004507
4508 priv->status &= ~(STATUS_ASSOCIATING |
4509 STATUS_AUTH |
4510 STATUS_ASSOCIATED);
4511
James Ketrenosa613bff2005-08-24 21:43:11 -05004512 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004513 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004514
4515 case CMAS_TX_AUTH_SEQ_1:
4516 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4517 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4518 break;
4519 case CMAS_RX_AUTH_SEQ_2:
4520 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4521 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4522 break;
4523 case CMAS_AUTH_SEQ_1_PASS:
4524 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4525 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4526 break;
4527 case CMAS_AUTH_SEQ_1_FAIL:
4528 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4529 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4530 break;
4531 case CMAS_TX_AUTH_SEQ_3:
4532 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4533 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4534 break;
4535 case CMAS_RX_AUTH_SEQ_4:
4536 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4537 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4538 break;
4539 case CMAS_AUTH_SEQ_2_PASS:
4540 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4541 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4542 break;
4543 case CMAS_AUTH_SEQ_2_FAIL:
4544 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4545 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4546 break;
4547 case CMAS_TX_ASSOC:
4548 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4549 IPW_DL_ASSOC, "TX_ASSOC\n");
4550 break;
4551 case CMAS_RX_ASSOC_RESP:
4552 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4553 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004554
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004555 break;
4556 case CMAS_ASSOCIATED:
4557 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4558 IPW_DL_ASSOC, "ASSOCIATED\n");
4559 break;
4560 default:
4561 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4562 auth->state);
4563 break;
4564 }
4565 break;
4566 }
4567
4568 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4569 struct notif_channel_result *x =
4570 &notif->u.channel_result;
4571
4572 if (notif->size == sizeof(*x)) {
4573 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4574 x->channel_num);
4575 } else {
4576 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4577 "(should be %zd)\n",
4578 notif->size, sizeof(*x));
4579 }
4580 break;
4581 }
4582
4583 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4584 struct notif_scan_complete *x = &notif->u.scan_complete;
4585 if (notif->size == sizeof(*x)) {
4586 IPW_DEBUG_SCAN
4587 ("Scan completed: type %d, %d channels, "
4588 "%d status\n", x->scan_type,
4589 x->num_channels, x->status);
4590 } else {
4591 IPW_ERROR("Scan completed of wrong size %d "
4592 "(should be %zd)\n",
4593 notif->size, sizeof(*x));
4594 }
4595
4596 priv->status &=
4597 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4598
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004599 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004600 cancel_delayed_work(&priv->scan_check);
4601
James Ketrenosb095c382005-08-24 22:04:42 -05004602 if (priv->status & STATUS_EXIT_PENDING)
4603 break;
4604
4605 priv->ieee->scans++;
4606
4607#ifdef CONFIG_IPW2200_MONITOR
4608 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004609 priv->status |= STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004610 queue_work(priv->workqueue,
4611 &priv->request_scan);
4612 break;
4613 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004614 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004615#endif /* CONFIG_IPW2200_MONITOR */
4616
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004617 if (!(priv->status & (STATUS_ASSOCIATED |
4618 STATUS_ASSOCIATING |
4619 STATUS_ROAMING |
4620 STATUS_DISASSOCIATING)))
4621 queue_work(priv->workqueue, &priv->associate);
4622 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004623 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4624 /* If a scan completed and we are in roam mode, then
4625 * the scan that completed was the one requested as a
4626 * result of entering roam... so, schedule the
4627 * roam work */
4628 queue_work(priv->workqueue,
4629 &priv->roam);
4630 else
4631 /* Don't schedule if we aborted the scan */
4632 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004633 } else if (priv->status & STATUS_SCAN_PENDING)
4634 queue_work(priv->workqueue,
4635 &priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004636 else if (priv->config & CFG_BACKGROUND_SCAN
4637 && priv->status & STATUS_ASSOCIATED)
4638 queue_delayed_work(priv->workqueue,
4639 &priv->request_scan, HZ);
Zhu Yi07f02e42006-04-13 17:19:25 +08004640
4641 /* Send an empty event to user space.
4642 * We don't send the received data on the event because
4643 * it would require us to do complex transcoding, and
4644 * we want to minimise the work done in the irq handler
4645 * Use a request to extract the data.
4646 * Also, we generate this even for any scan, regardless
4647 * on how the scan was initiated. User space can just
4648 * sync on periodic scan to get fresh data...
4649 * Jean II */
4650 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) {
4651 union iwreq_data wrqu;
4652
4653 wrqu.data.length = 0;
4654 wrqu.data.flags = 0;
4655 wireless_send_event(priv->net_dev, SIOCGIWSCAN,
4656 &wrqu, NULL);
4657 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004658 break;
4659 }
4660
4661 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4662 struct notif_frag_length *x = &notif->u.frag_len;
4663
James Ketrenosa613bff2005-08-24 21:43:11 -05004664 if (notif->size == sizeof(*x))
4665 IPW_ERROR("Frag length: %d\n",
4666 le16_to_cpu(x->frag_length));
4667 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004668 IPW_ERROR("Frag length of wrong size %d "
4669 "(should be %zd)\n",
4670 notif->size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004671 break;
4672 }
4673
4674 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4675 struct notif_link_deterioration *x =
4676 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004677
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004678 if (notif->size == sizeof(*x)) {
4679 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Cahill, Ben M12977152006-03-08 02:58:02 +08004680 "link deterioration: type %d, cnt %d\n",
4681 x->silence_notification_type,
4682 x->silence_count);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004683 memcpy(&priv->last_link_deterioration, x,
4684 sizeof(*x));
4685 } else {
4686 IPW_ERROR("Link Deterioration of wrong size %d "
4687 "(should be %zd)\n",
4688 notif->size, sizeof(*x));
4689 }
4690 break;
4691 }
4692
4693 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4694 IPW_ERROR("Dino config\n");
4695 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004696 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004697 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004698
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004699 break;
4700 }
4701
4702 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4703 struct notif_beacon_state *x = &notif->u.beacon_state;
4704 if (notif->size != sizeof(*x)) {
4705 IPW_ERROR
4706 ("Beacon state of wrong size %d (should "
4707 "be %zd)\n", notif->size, sizeof(*x));
4708 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004709 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004710
James Ketrenosa613bff2005-08-24 21:43:11 -05004711 if (le32_to_cpu(x->state) ==
4712 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4713 ipw_handle_missed_beacon(priv,
4714 le32_to_cpu(x->
4715 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004716
James Ketrenos43f66a62005-03-25 12:31:53 -06004717 break;
4718 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004719
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004720 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4721 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
4722 if (notif->size == sizeof(*x)) {
4723 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4724 "0x%02x station %d\n",
4725 x->key_state, x->security_type,
4726 x->station_index);
4727 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004728 }
4729
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004730 IPW_ERROR
4731 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4732 notif->size, sizeof(*x));
4733 break;
4734 }
4735
4736 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4737 struct notif_calibration *x = &notif->u.calibration;
4738
4739 if (notif->size == sizeof(*x)) {
4740 memcpy(&priv->calib, x, sizeof(*x));
4741 IPW_DEBUG_INFO("TODO: Calibration\n");
4742 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004743 }
4744
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004745 IPW_ERROR
4746 ("Calibration of wrong size %d (should be %zd)\n",
4747 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004748 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004749 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004750
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004751 case HOST_NOTIFICATION_NOISE_STATS:{
4752 if (notif->size == sizeof(u32)) {
Zhu Yi00d21de2006-04-13 17:19:02 +08004753 priv->exp_avg_noise =
4754 exponential_average(priv->exp_avg_noise,
4755 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4756 DEPTH_NOISE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004757 break;
4758 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004759
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004760 IPW_ERROR
4761 ("Noise stat is wrong size %d (should be %zd)\n",
4762 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004763 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004764 }
4765
James Ketrenos43f66a62005-03-25 12:31:53 -06004766 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004767 IPW_DEBUG_NOTIF("Unknown notification: "
4768 "subtype=%d,flags=0x%2x,size=%d\n",
4769 notif->subtype, notif->flags, notif->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004770 }
4771}
4772
4773/**
4774 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004775 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004776 * @param priv
4777 * @return error code
4778 */
4779static int ipw_queue_reset(struct ipw_priv *priv)
4780{
4781 int rc = 0;
4782 /** @todo customize queue sizes */
4783 int nTx = 64, nTxCmd = 8;
4784 ipw_tx_queue_free(priv);
4785 /* Tx CMD queue */
4786 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004787 IPW_TX_CMD_QUEUE_READ_INDEX,
4788 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4789 IPW_TX_CMD_QUEUE_BD_BASE,
4790 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004791 if (rc) {
4792 IPW_ERROR("Tx Cmd queue init failed\n");
4793 goto error;
4794 }
4795 /* Tx queue(s) */
4796 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004797 IPW_TX_QUEUE_0_READ_INDEX,
4798 IPW_TX_QUEUE_0_WRITE_INDEX,
4799 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004800 if (rc) {
4801 IPW_ERROR("Tx 0 queue init failed\n");
4802 goto error;
4803 }
4804 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004805 IPW_TX_QUEUE_1_READ_INDEX,
4806 IPW_TX_QUEUE_1_WRITE_INDEX,
4807 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004808 if (rc) {
4809 IPW_ERROR("Tx 1 queue init failed\n");
4810 goto error;
4811 }
4812 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004813 IPW_TX_QUEUE_2_READ_INDEX,
4814 IPW_TX_QUEUE_2_WRITE_INDEX,
4815 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004816 if (rc) {
4817 IPW_ERROR("Tx 2 queue init failed\n");
4818 goto error;
4819 }
4820 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004821 IPW_TX_QUEUE_3_READ_INDEX,
4822 IPW_TX_QUEUE_3_WRITE_INDEX,
4823 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004824 if (rc) {
4825 IPW_ERROR("Tx 3 queue init failed\n");
4826 goto error;
4827 }
4828 /* statistics */
4829 priv->rx_bufs_min = 0;
4830 priv->rx_pend_max = 0;
4831 return rc;
4832
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004833 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004834 ipw_tx_queue_free(priv);
4835 return rc;
4836}
4837
4838/**
4839 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004840 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004841 * When FW adwances 'R' index, all entries between old and
4842 * new 'R' index need to be reclaimed. As result, some free space
4843 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004844 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004845 * @note Need to protect against garbage in 'R' index
4846 * @param priv
4847 * @param txq
4848 * @param qindex
4849 * @return Number of used entries remains in the queue
4850 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004851static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004852 struct clx2_tx_queue *txq, int qindex)
4853{
4854 u32 hw_tail;
4855 int used;
4856 struct clx2_queue *q = &txq->q;
4857
4858 hw_tail = ipw_read32(priv, q->reg_r);
4859 if (hw_tail >= q->n_bd) {
4860 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004861 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4862 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004863 goto done;
4864 }
4865 for (; q->last_used != hw_tail;
4866 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4867 ipw_queue_tx_free_tfd(priv, txq);
4868 priv->tx_packets++;
4869 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004870 done:
James Ketrenos9ddf84f2005-08-16 17:07:11 -05004871 if ((ipw_queue_space(q) > q->low_mark) &&
4872 (qindex >= 0) &&
4873 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4874 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06004875 used = q->first_empty - q->last_used;
4876 if (used < 0)
4877 used += q->n_bd;
4878
4879 return used;
4880}
4881
4882static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4883 int len, int sync)
4884{
4885 struct clx2_tx_queue *txq = &priv->txq_cmd;
4886 struct clx2_queue *q = &txq->q;
4887 struct tfd_frame *tfd;
4888
4889 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4890 IPW_ERROR("No space for Tx\n");
4891 return -EBUSY;
4892 }
4893
4894 tfd = &txq->bd[q->first_empty];
4895 txq->txb[q->first_empty] = NULL;
4896
4897 memset(tfd, 0, sizeof(*tfd));
4898 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4899 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4900 priv->hcmd_seq++;
4901 tfd->u.cmd.index = hcmd;
4902 tfd->u.cmd.length = len;
4903 memcpy(tfd->u.cmd.payload, buf, len);
4904 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4905 ipw_write32(priv, q->reg_w, q->first_empty);
4906 _ipw_read32(priv, 0x90);
4907
4908 return 0;
4909}
4910
Jeff Garzikbf794512005-07-31 13:07:26 -04004911/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004912 * Rx theory of operation
4913 *
4914 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05004915 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06004916 * 0 to 31
4917 *
4918 * Rx Queue Indexes
4919 * The host/firmware share two index registers for managing the Rx buffers.
4920 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004921 * The READ index maps to the first position that the firmware may be writing
4922 * to -- the driver can read up to (but not including) this position and get
4923 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06004924 * The READ index is managed by the firmware once the card is enabled.
4925 *
4926 * The WRITE index maps to the last position the driver has read from -- the
4927 * position preceding WRITE is the last slot the firmware can place a packet.
4928 *
4929 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04004930 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06004931 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004932 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06004933 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4934 *
4935 * When the firmware places a packet in a buffer it will advance the READ index
4936 * and fire the RX interrupt. The driver can then query the READ index and
4937 * process as many packets as possible, moving the WRITE index forward as it
4938 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04004939 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004940 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004941 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06004942 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04004943 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06004944 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4945 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4946 * 'processed' and 'read' driver indexes as well)
4947 * + A received packet is processed and handed to the kernel network stack,
4948 * detached from the ipw->rxq. The driver 'processed' index is updated.
4949 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04004950 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4951 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06004952 * were enough free buffers and RX_STALLED is set it is cleared.
4953 *
4954 *
4955 * Driver sequence:
4956 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004957 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06004958 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4959 * ipw_rx_queue_restock
4960 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4961 * queue, updates firmware pointers, and updates
4962 * the WRITE index. If insufficient rx_free buffers
4963 * are available, schedules ipw_rx_queue_replenish
4964 *
4965 * -- enable interrupts --
4966 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04004967 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06004968 * Moves the packet buffer from queue to rx_used.
4969 * Calls ipw_rx_queue_restock to refill any empty
4970 * slots.
4971 * ...
4972 *
4973 */
4974
Jeff Garzikbf794512005-07-31 13:07:26 -04004975/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004976 * If there are slots in the RX queue that need to be restocked,
4977 * and we have free pre-allocated buffers, fill the ranks as much
4978 * as we can pulling from rx_free.
4979 *
4980 * This moves the 'write' index forward to catch up with 'processed', and
4981 * also updates the memory address in the firmware to reference the new
4982 * target buffer.
4983 */
4984static void ipw_rx_queue_restock(struct ipw_priv *priv)
4985{
4986 struct ipw_rx_queue *rxq = priv->rxq;
4987 struct list_head *element;
4988 struct ipw_rx_mem_buffer *rxb;
4989 unsigned long flags;
4990 int write;
4991
4992 spin_lock_irqsave(&rxq->lock, flags);
4993 write = rxq->write;
4994 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4995 element = rxq->rx_free.next;
4996 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4997 list_del(element);
4998
James Ketrenosb095c382005-08-24 22:04:42 -05004999 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06005000 rxb->dma_addr);
5001 rxq->queue[rxq->write] = rxb;
5002 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
5003 rxq->free_count--;
5004 }
5005 spin_unlock_irqrestore(&rxq->lock, flags);
5006
Jeff Garzikbf794512005-07-31 13:07:26 -04005007 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06005008 * refill it */
5009 if (rxq->free_count <= RX_LOW_WATERMARK)
5010 queue_work(priv->workqueue, &priv->rx_replenish);
5011
5012 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04005013 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05005014 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06005015}
5016
5017/*
5018 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04005019 * Also restock the Rx queue via ipw_rx_queue_restock.
5020 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005021 * This is called as a scheduled work item (except for during intialization)
5022 */
5023static void ipw_rx_queue_replenish(void *data)
5024{
5025 struct ipw_priv *priv = data;
5026 struct ipw_rx_queue *rxq = priv->rxq;
5027 struct list_head *element;
5028 struct ipw_rx_mem_buffer *rxb;
5029 unsigned long flags;
5030
5031 spin_lock_irqsave(&rxq->lock, flags);
5032 while (!list_empty(&rxq->rx_used)) {
5033 element = rxq->rx_used.next;
5034 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05005035 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06005036 if (!rxb->skb) {
5037 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
5038 priv->net_dev->name);
5039 /* We don't reschedule replenish work here -- we will
5040 * call the restock method and if it still needs
5041 * more buffers it will schedule replenish */
5042 break;
5043 }
5044 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04005045
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005046 rxb->dma_addr =
5047 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05005048 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04005049
James Ketrenos43f66a62005-03-25 12:31:53 -06005050 list_add_tail(&rxb->list, &rxq->rx_free);
5051 rxq->free_count++;
5052 }
5053 spin_unlock_irqrestore(&rxq->lock, flags);
5054
5055 ipw_rx_queue_restock(priv);
5056}
5057
James Ketrenosc848d0a2005-08-24 21:56:24 -05005058static void ipw_bg_rx_queue_replenish(void *data)
5059{
5060 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08005061 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005062 ipw_rx_queue_replenish(data);
Zhu Yi46441512006-01-24 16:37:59 +08005063 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005064}
5065
James Ketrenos43f66a62005-03-25 12:31:53 -06005066/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08005067 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04005068 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06005069 * non NULL it is unmapped and freed
5070 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005071static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06005072{
5073 int i;
5074
5075 if (!rxq)
5076 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04005077
James Ketrenos43f66a62005-03-25 12:31:53 -06005078 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
5079 if (rxq->pool[i].skb != NULL) {
5080 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05005081 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06005082 dev_kfree_skb(rxq->pool[i].skb);
5083 }
5084 }
5085
5086 kfree(rxq);
5087}
5088
5089static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
5090{
5091 struct ipw_rx_queue *rxq;
5092 int i;
5093
Takisc75f4742005-12-01 01:41:45 -08005094 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02005095 if (unlikely(!rxq)) {
5096 IPW_ERROR("memory allocation failed\n");
5097 return NULL;
5098 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005099 spin_lock_init(&rxq->lock);
5100 INIT_LIST_HEAD(&rxq->rx_free);
5101 INIT_LIST_HEAD(&rxq->rx_used);
5102
5103 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04005104 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06005105 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
5106
5107 /* Set us so that we have processed and used all buffers, but have
5108 * not restocked the Rx queue with fresh buffers */
5109 rxq->read = rxq->write = 0;
5110 rxq->processed = RX_QUEUE_SIZE - 1;
5111 rxq->free_count = 0;
5112
5113 return rxq;
5114}
5115
5116static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
5117{
5118 rate &= ~IEEE80211_BASIC_RATE_MASK;
5119 if (ieee_mode == IEEE_A) {
5120 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005121 case IEEE80211_OFDM_RATE_6MB:
5122 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005123 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005124 case IEEE80211_OFDM_RATE_9MB:
5125 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005126 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005127 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005128 return priv->
5129 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005130 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005131 return priv->
5132 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005133 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005134 return priv->
5135 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005136 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005137 return priv->
5138 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005139 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005140 return priv->
5141 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005142 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005143 return priv->
5144 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005145 default:
5146 return 0;
5147 }
5148 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005149
James Ketrenos43f66a62005-03-25 12:31:53 -06005150 /* B and G mixed */
5151 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005152 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005153 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005154 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005155 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005156 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005157 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005158 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005159 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
5160 }
5161
5162 /* If we are limited to B modulations, bail at this point */
5163 if (ieee_mode == IEEE_B)
5164 return 0;
5165
5166 /* G */
5167 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005168 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005169 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005170 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005171 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005172 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005173 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005174 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005175 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005176 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005177 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005178 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005179 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005180 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005181 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005182 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005183 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5184 }
5185
5186 return 0;
5187}
5188
Jeff Garzikbf794512005-07-31 13:07:26 -04005189static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005190 const struct ieee80211_network *network,
5191 struct ipw_supported_rates *rates)
5192{
5193 int num_rates, i;
5194
5195 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005196 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005197 rates->num_rates = 0;
5198 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005199 if (!ipw_is_rate_in_mask(priv, network->mode,
5200 network->rates[i])) {
5201
James Ketrenosea2b26e2005-08-24 21:25:16 -05005202 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005203 IPW_DEBUG_SCAN("Adding masked mandatory "
5204 "rate %02X\n",
5205 network->rates[i]);
5206 rates->supported_rates[rates->num_rates++] =
5207 network->rates[i];
5208 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005209 }
5210
James Ketrenos43f66a62005-03-25 12:31:53 -06005211 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5212 network->rates[i], priv->rates_mask);
5213 continue;
5214 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005215
James Ketrenos43f66a62005-03-25 12:31:53 -06005216 rates->supported_rates[rates->num_rates++] = network->rates[i];
5217 }
5218
James Ketrenosa613bff2005-08-24 21:43:11 -05005219 num_rates = min(network->rates_ex_len,
5220 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005221 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005222 if (!ipw_is_rate_in_mask(priv, network->mode,
5223 network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005224 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005225 IPW_DEBUG_SCAN("Adding masked mandatory "
5226 "rate %02X\n",
5227 network->rates_ex[i]);
5228 rates->supported_rates[rates->num_rates++] =
5229 network->rates[i];
5230 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005231 }
5232
James Ketrenos43f66a62005-03-25 12:31:53 -06005233 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5234 network->rates_ex[i], priv->rates_mask);
5235 continue;
5236 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005237
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005238 rates->supported_rates[rates->num_rates++] =
5239 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005240 }
5241
James Ketrenosea2b26e2005-08-24 21:25:16 -05005242 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005243}
5244
Arjan van de Ven858119e2006-01-14 13:20:43 -08005245static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005246 const struct ipw_supported_rates *src)
5247{
5248 u8 i;
5249 for (i = 0; i < src->num_rates; i++)
5250 dest->supported_rates[i] = src->supported_rates[i];
5251 dest->num_rates = src->num_rates;
5252}
5253
5254/* TODO: Look at sniffed packets in the air to determine if the basic rate
5255 * mask should ever be used -- right now all callers to add the scan rates are
5256 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5257static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005258 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005259{
Jeff Garzikbf794512005-07-31 13:07:26 -04005260 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005261 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005262
James Ketrenos43f66a62005-03-25 12:31:53 -06005263 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005264 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005265 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005266
5267 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005268 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005269 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005270
5271 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005272 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005273 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005274
5275 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005276 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005277 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005278}
5279
5280static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005281 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005282{
Jeff Garzikbf794512005-07-31 13:07:26 -04005283 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005284 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005285
5286 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005287 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005288 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005289
5290 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005291 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005292 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005293
5294 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005295 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005296 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005297
5298 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005299 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005300 IEEE80211_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005301
5302 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005303 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005304 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005305
5306 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005307 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005308 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005309
5310 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005311 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005312 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005313
5314 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005315 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005316 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005317}
5318
5319struct ipw_network_match {
5320 struct ieee80211_network *network;
5321 struct ipw_supported_rates rates;
5322};
5323
James Ketrenosc848d0a2005-08-24 21:56:24 -05005324static int ipw_find_adhoc_network(struct ipw_priv *priv,
5325 struct ipw_network_match *match,
5326 struct ieee80211_network *network,
5327 int roaming)
5328{
5329 struct ipw_supported_rates rates;
5330
5331 /* Verify that this network's capability is compatible with the
5332 * current mode (AdHoc or Infrastructure) */
5333 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5334 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5335 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5336 "capability mismatch.\n",
5337 escape_essid(network->ssid, network->ssid_len),
5338 MAC_ARG(network->bssid));
5339 return 0;
5340 }
5341
5342 /* If we do not have an ESSID for this AP, we can not associate with
5343 * it */
5344 if (network->flags & NETWORK_EMPTY_ESSID) {
5345 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5346 "because of hidden ESSID.\n",
5347 escape_essid(network->ssid, network->ssid_len),
5348 MAC_ARG(network->bssid));
5349 return 0;
5350 }
5351
5352 if (unlikely(roaming)) {
5353 /* If we are roaming, then ensure check if this is a valid
5354 * network to try and roam to */
5355 if ((network->ssid_len != match->network->ssid_len) ||
5356 memcmp(network->ssid, match->network->ssid,
5357 network->ssid_len)) {
5358 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5359 "because of non-network ESSID.\n",
5360 escape_essid(network->ssid,
5361 network->ssid_len),
5362 MAC_ARG(network->bssid));
5363 return 0;
5364 }
5365 } else {
5366 /* If an ESSID has been configured then compare the broadcast
5367 * ESSID to ours */
5368 if ((priv->config & CFG_STATIC_ESSID) &&
5369 ((network->ssid_len != priv->essid_len) ||
5370 memcmp(network->ssid, priv->essid,
5371 min(network->ssid_len, priv->essid_len)))) {
5372 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005373
James Ketrenosc848d0a2005-08-24 21:56:24 -05005374 strncpy(escaped,
5375 escape_essid(network->ssid, network->ssid_len),
5376 sizeof(escaped));
5377 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5378 "because of ESSID mismatch: '%s'.\n",
5379 escaped, MAC_ARG(network->bssid),
5380 escape_essid(priv->essid,
5381 priv->essid_len));
5382 return 0;
5383 }
5384 }
5385
5386 /* If the old network rate is better than this one, don't bother
5387 * testing everything else. */
5388
5389 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005390 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5391 "current network.\n",
5392 escape_essid(match->network->ssid,
5393 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005394 return 0;
5395 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005396 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5397 "current network.\n",
5398 escape_essid(match->network->ssid,
5399 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005400 return 0;
5401 }
5402
5403 /* Now go through and see if the requested network is valid... */
5404 if (priv->ieee->scan_age != 0 &&
5405 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5406 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005407 "because of age: %ums.\n",
James Ketrenosc848d0a2005-08-24 21:56:24 -05005408 escape_essid(network->ssid, network->ssid_len),
5409 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005410 jiffies_to_msecs(jiffies -
5411 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005412 return 0;
5413 }
5414
5415 if ((priv->config & CFG_STATIC_CHANNEL) &&
5416 (network->channel != priv->channel)) {
5417 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5418 "because of channel mismatch: %d != %d.\n",
5419 escape_essid(network->ssid, network->ssid_len),
5420 MAC_ARG(network->bssid),
5421 network->channel, priv->channel);
5422 return 0;
5423 }
5424
5425 /* Verify privacy compatability */
5426 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5427 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5428 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5429 "because of privacy mismatch: %s != %s.\n",
5430 escape_essid(network->ssid, network->ssid_len),
5431 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005432 priv->
5433 capability & CAP_PRIVACY_ON ? "on" : "off",
5434 network->
5435 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5436 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005437 return 0;
5438 }
5439
5440 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5441 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5442 "because of the same BSSID match: " MAC_FMT
5443 ".\n", escape_essid(network->ssid,
5444 network->ssid_len),
5445 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5446 return 0;
5447 }
5448
5449 /* Filter out any incompatible freq / mode combinations */
5450 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5451 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5452 "because of invalid frequency/mode "
5453 "combination.\n",
5454 escape_essid(network->ssid, network->ssid_len),
5455 MAC_ARG(network->bssid));
5456 return 0;
5457 }
5458
5459 /* Ensure that the rates supported by the driver are compatible with
5460 * this AP, including verification of basic rates (mandatory) */
5461 if (!ipw_compatible_rates(priv, network, &rates)) {
5462 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5463 "because configured rate mask excludes "
5464 "AP mandatory rate.\n",
5465 escape_essid(network->ssid, network->ssid_len),
5466 MAC_ARG(network->bssid));
5467 return 0;
5468 }
5469
5470 if (rates.num_rates == 0) {
5471 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5472 "because of no compatible rates.\n",
5473 escape_essid(network->ssid, network->ssid_len),
5474 MAC_ARG(network->bssid));
5475 return 0;
5476 }
5477
5478 /* TODO: Perform any further minimal comparititive tests. We do not
5479 * want to put too much policy logic here; intelligent scan selection
5480 * should occur within a generic IEEE 802.11 user space tool. */
5481
5482 /* Set up 'new' AP to this network */
5483 ipw_copy_rates(&match->rates, &rates);
5484 match->network = network;
5485 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5486 escape_essid(network->ssid, network->ssid_len),
5487 MAC_ARG(network->bssid));
5488
5489 return 1;
5490}
5491
5492static void ipw_merge_adhoc_network(void *data)
5493{
5494 struct ipw_priv *priv = data;
5495 struct ieee80211_network *network = NULL;
5496 struct ipw_network_match match = {
5497 .network = priv->assoc_network
5498 };
5499
James Ketrenosafbf30a2005-08-25 00:05:33 -05005500 if ((priv->status & STATUS_ASSOCIATED) &&
5501 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005502 /* First pass through ROAM process -- look for a better
5503 * network */
5504 unsigned long flags;
5505
5506 spin_lock_irqsave(&priv->ieee->lock, flags);
5507 list_for_each_entry(network, &priv->ieee->network_list, list) {
5508 if (network != priv->assoc_network)
5509 ipw_find_adhoc_network(priv, &match, network,
5510 1);
5511 }
5512 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5513
5514 if (match.network == priv->assoc_network) {
5515 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5516 "merge to.\n");
5517 return;
5518 }
5519
Zhu Yi46441512006-01-24 16:37:59 +08005520 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005521 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5522 IPW_DEBUG_MERGE("remove network %s\n",
5523 escape_essid(priv->essid,
5524 priv->essid_len));
5525 ipw_remove_current_network(priv);
5526 }
5527
5528 ipw_disassociate(priv);
5529 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005530 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005531 return;
5532 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005533}
5534
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005535static int ipw_best_network(struct ipw_priv *priv,
5536 struct ipw_network_match *match,
5537 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005538{
5539 struct ipw_supported_rates rates;
5540
5541 /* Verify that this network's capability is compatible with the
5542 * current mode (AdHoc or Infrastructure) */
5543 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005544 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005545 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5546 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5547 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005548 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005549 escape_essid(network->ssid, network->ssid_len),
5550 MAC_ARG(network->bssid));
5551 return 0;
5552 }
5553
5554 /* If we do not have an ESSID for this AP, we can not associate with
5555 * it */
5556 if (network->flags & NETWORK_EMPTY_ESSID) {
5557 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5558 "because of hidden ESSID.\n",
5559 escape_essid(network->ssid, network->ssid_len),
5560 MAC_ARG(network->bssid));
5561 return 0;
5562 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005563
James Ketrenos43f66a62005-03-25 12:31:53 -06005564 if (unlikely(roaming)) {
5565 /* If we are roaming, then ensure check if this is a valid
5566 * network to try and roam to */
5567 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005568 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005569 network->ssid_len)) {
5570 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5571 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04005572 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005573 network->ssid_len),
5574 MAC_ARG(network->bssid));
5575 return 0;
5576 }
5577 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005578 /* If an ESSID has been configured then compare the broadcast
5579 * ESSID to ours */
5580 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005581 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005582 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005583 min(network->ssid_len, priv->essid_len)))) {
5584 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005585 strncpy(escaped,
5586 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005587 sizeof(escaped));
5588 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005589 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005590 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005591 escape_essid(priv->essid,
5592 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005593 return 0;
5594 }
5595 }
5596
5597 /* If the old network rate is better than this one, don't bother
5598 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005599 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005600 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005601 strncpy(escaped,
5602 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005603 sizeof(escaped));
5604 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5605 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5606 escaped, MAC_ARG(network->bssid),
5607 escape_essid(match->network->ssid,
5608 match->network->ssid_len),
5609 MAC_ARG(match->network->bssid));
5610 return 0;
5611 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005612
James Ketrenos43f66a62005-03-25 12:31:53 -06005613 /* If this network has already had an association attempt within the
5614 * last 3 seconds, do not try and associate again... */
5615 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005616 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005617 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005618 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005619 "assoc attempt).\n",
5620 escape_essid(network->ssid, network->ssid_len),
5621 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005622 jiffies_to_msecs(jiffies -
5623 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005624 return 0;
5625 }
5626
5627 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005628 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005629 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005630 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005631 "because of age: %ums.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005632 escape_essid(network->ssid, network->ssid_len),
5633 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005634 jiffies_to_msecs(jiffies -
5635 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005636 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005637 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005638
Jeff Garzikbf794512005-07-31 13:07:26 -04005639 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005640 (network->channel != priv->channel)) {
5641 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5642 "because of channel mismatch: %d != %d.\n",
5643 escape_essid(network->ssid, network->ssid_len),
5644 MAC_ARG(network->bssid),
5645 network->channel, priv->channel);
5646 return 0;
5647 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005648
James Ketrenos43f66a62005-03-25 12:31:53 -06005649 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005650 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005651 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5652 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5653 "because of privacy mismatch: %s != %s.\n",
5654 escape_essid(network->ssid, network->ssid_len),
5655 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04005656 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005657 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005658 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005659 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005660 return 0;
5661 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005662
5663 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005664 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5665 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5666 "because of BSSID mismatch: " MAC_FMT ".\n",
5667 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005668 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005669 return 0;
5670 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005671
James Ketrenos43f66a62005-03-25 12:31:53 -06005672 /* Filter out any incompatible freq / mode combinations */
5673 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5674 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5675 "because of invalid frequency/mode "
5676 "combination.\n",
5677 escape_essid(network->ssid, network->ssid_len),
5678 MAC_ARG(network->bssid));
5679 return 0;
5680 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005681
Liu Hong1fe0adb2005-08-19 09:33:10 -05005682 /* Filter out invalid channel in current GEO */
Larry Finger1867b112006-02-28 09:48:28 -06005683 if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005684 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5685 "because of invalid channel in current GEO\n",
5686 escape_essid(network->ssid, network->ssid_len),
5687 MAC_ARG(network->bssid));
5688 return 0;
5689 }
5690
James Ketrenosea2b26e2005-08-24 21:25:16 -05005691 /* Ensure that the rates supported by the driver are compatible with
5692 * this AP, including verification of basic rates (mandatory) */
5693 if (!ipw_compatible_rates(priv, network, &rates)) {
5694 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5695 "because configured rate mask excludes "
5696 "AP mandatory rate.\n",
5697 escape_essid(network->ssid, network->ssid_len),
5698 MAC_ARG(network->bssid));
5699 return 0;
5700 }
5701
James Ketrenos43f66a62005-03-25 12:31:53 -06005702 if (rates.num_rates == 0) {
5703 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5704 "because of no compatible rates.\n",
5705 escape_essid(network->ssid, network->ssid_len),
5706 MAC_ARG(network->bssid));
5707 return 0;
5708 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005709
James Ketrenos43f66a62005-03-25 12:31:53 -06005710 /* TODO: Perform any further minimal comparititive tests. We do not
5711 * want to put too much policy logic here; intelligent scan selection
5712 * should occur within a generic IEEE 802.11 user space tool. */
5713
5714 /* Set up 'new' AP to this network */
5715 ipw_copy_rates(&match->rates, &rates);
5716 match->network = network;
5717
5718 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5719 escape_essid(network->ssid, network->ssid_len),
5720 MAC_ARG(network->bssid));
5721
5722 return 1;
5723}
5724
Jeff Garzikbf794512005-07-31 13:07:26 -04005725static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005726 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005727{
Larry Finger1867b112006-02-28 09:48:28 -06005728 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005729 int i;
5730
James Ketrenos43f66a62005-03-25 12:31:53 -06005731 /*
5732 * For the purposes of scanning, we can set our wireless mode
5733 * to trigger scans across combinations of bands, but when it
5734 * comes to creating a new ad-hoc network, we have tell the FW
5735 * exactly which band to use.
5736 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005737 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005738 * chossen band. Attempting to create a new ad-hoc network
5739 * with an invalid channel for wireless mode will trigger a
5740 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005741 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005742 */
Larry Finger1867b112006-02-28 09:48:28 -06005743 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005744 case IEEE80211_52GHZ_BAND:
5745 network->mode = IEEE_A;
Larry Finger1867b112006-02-28 09:48:28 -06005746 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005747 BUG_ON(i == -1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005748 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5749 IPW_WARNING("Overriding invalid channel\n");
5750 priv->channel = geo->a[0].channel;
5751 }
5752 break;
5753
5754 case IEEE80211_24GHZ_BAND:
5755 if (priv->ieee->mode & IEEE_G)
5756 network->mode = IEEE_G;
5757 else
5758 network->mode = IEEE_B;
Larry Finger1867b112006-02-28 09:48:28 -06005759 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005760 BUG_ON(i == -1);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005761 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5762 IPW_WARNING("Overriding invalid channel\n");
5763 priv->channel = geo->bg[0].channel;
5764 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005765 break;
5766
5767 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005768 IPW_WARNING("Overriding invalid channel\n");
5769 if (priv->ieee->mode & IEEE_A) {
5770 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005771 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005772 } else if (priv->ieee->mode & IEEE_G) {
5773 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005774 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005775 } else {
5776 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005777 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005778 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005779 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005780 }
5781
5782 network->channel = priv->channel;
5783 priv->config |= CFG_ADHOC_PERSIST;
5784 ipw_create_bssid(priv, network->bssid);
5785 network->ssid_len = priv->essid_len;
5786 memcpy(network->ssid, priv->essid, priv->essid_len);
5787 memset(&network->stats, 0, sizeof(network->stats));
5788 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005789 if (!(priv->config & CFG_PREAMBLE_LONG))
5790 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005791 if (priv->capability & CAP_PRIVACY_ON)
5792 network->capability |= WLAN_CAPABILITY_PRIVACY;
5793 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005794 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005795 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005796 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005797 &priv->rates.supported_rates[network->rates_len],
5798 network->rates_ex_len);
5799 network->last_scanned = 0;
5800 network->flags = 0;
5801 network->last_associate = 0;
5802 network->time_stamp[0] = 0;
5803 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005804 network->beacon_interval = 100; /* Default */
5805 network->listen_interval = 10; /* Default */
5806 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005807 network->wpa_ie_len = 0;
5808 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005809}
5810
James Ketrenosb095c382005-08-24 22:04:42 -05005811static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5812{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005813 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005814
5815 if (!(priv->ieee->sec.flags & (1 << index)))
5816 return;
5817
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005818 key.key_id = index;
5819 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5820 key.security_type = type;
5821 key.station_index = 0; /* always 0 for BSS */
5822 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005823 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005824 key.tx_counter[0] = 0;
5825 key.tx_counter[1] = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005826
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005827 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05005828}
5829
5830static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005831{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005832 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06005833 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06005834
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005835 key.cmd_id = DINO_CMD_WEP_KEY;
5836 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005837
James Ketrenosb095c382005-08-24 22:04:42 -05005838 /* Note: AES keys cannot be set for multiple times.
5839 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005840 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005841 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05005842 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005843 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005844 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005845 }
5846
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005847 key.key_size = priv->ieee->sec.key_sizes[i];
5848 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05005849
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005850 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04005851 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005852}
5853
Zhu Yi1fbfea52005-08-05 17:22:56 +08005854static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5855{
5856 if (priv->ieee->host_encrypt)
5857 return;
5858
5859 switch (level) {
5860 case SEC_LEVEL_3:
5861 priv->sys_config.disable_unicast_decryption = 0;
5862 priv->ieee->host_decrypt = 0;
5863 break;
5864 case SEC_LEVEL_2:
5865 priv->sys_config.disable_unicast_decryption = 1;
5866 priv->ieee->host_decrypt = 1;
5867 break;
5868 case SEC_LEVEL_1:
5869 priv->sys_config.disable_unicast_decryption = 0;
5870 priv->ieee->host_decrypt = 0;
5871 break;
5872 case SEC_LEVEL_0:
5873 priv->sys_config.disable_unicast_decryption = 1;
5874 break;
5875 default:
5876 break;
5877 }
5878}
5879
5880static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5881{
5882 if (priv->ieee->host_encrypt)
5883 return;
5884
5885 switch (level) {
5886 case SEC_LEVEL_3:
5887 priv->sys_config.disable_multicast_decryption = 0;
5888 break;
5889 case SEC_LEVEL_2:
5890 priv->sys_config.disable_multicast_decryption = 1;
5891 break;
5892 case SEC_LEVEL_1:
5893 priv->sys_config.disable_multicast_decryption = 0;
5894 break;
5895 case SEC_LEVEL_0:
5896 priv->sys_config.disable_multicast_decryption = 1;
5897 break;
5898 default:
5899 break;
5900 }
5901}
5902
James Ketrenosb095c382005-08-24 22:04:42 -05005903static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5904{
5905 switch (priv->ieee->sec.level) {
5906 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005907 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5908 ipw_send_tgi_tx_key(priv,
5909 DCT_FLAG_EXT_SECURITY_CCM,
5910 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005911
Hong Liu567deaf2005-08-31 18:07:22 +08005912 if (!priv->ieee->host_mc_decrypt)
5913 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05005914 break;
5915 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005916 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5917 ipw_send_tgi_tx_key(priv,
5918 DCT_FLAG_EXT_SECURITY_TKIP,
5919 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05005920 break;
5921 case SEC_LEVEL_1:
5922 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05005923 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5924 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05005925 break;
5926 case SEC_LEVEL_0:
5927 default:
5928 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005929 }
5930}
5931
5932static void ipw_adhoc_check(void *data)
5933{
5934 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04005935
James Ketrenosafbf30a2005-08-25 00:05:33 -05005936 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005937 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005938 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5939 IPW_DL_STATE | IPW_DL_ASSOC,
5940 "Missed beacon: %d - disassociate\n",
5941 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06005942 ipw_remove_current_network(priv);
5943 ipw_disassociate(priv);
5944 return;
5945 }
5946
Jeff Garzikbf794512005-07-31 13:07:26 -04005947 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06005948 priv->assoc_request.beacon_interval);
5949}
5950
James Ketrenosc848d0a2005-08-24 21:56:24 -05005951static void ipw_bg_adhoc_check(void *data)
5952{
5953 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08005954 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005955 ipw_adhoc_check(data);
Zhu Yi46441512006-01-24 16:37:59 +08005956 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005957}
5958
James Ketrenos43f66a62005-03-25 12:31:53 -06005959static void ipw_debug_config(struct ipw_priv *priv)
5960{
5961 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5962 "[CFG 0x%08X]\n", priv->config);
5963 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005964 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005965 else
5966 IPW_DEBUG_INFO("Channel unlocked.\n");
5967 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04005968 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005969 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005970 else
5971 IPW_DEBUG_INFO("ESSID unlocked.\n");
5972 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05005973 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5974 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005975 else
5976 IPW_DEBUG_INFO("BSSID unlocked.\n");
5977 if (priv->capability & CAP_PRIVACY_ON)
5978 IPW_DEBUG_INFO("PRIVACY on\n");
5979 else
5980 IPW_DEBUG_INFO("PRIVACY off\n");
5981 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5982}
James Ketrenos43f66a62005-03-25 12:31:53 -06005983
Arjan van de Ven858119e2006-01-14 13:20:43 -08005984static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06005985{
5986 /* TODO: Verify that this works... */
5987 struct ipw_fixed_rate fr = {
5988 .tx_rates = priv->rates_mask
5989 };
5990 u32 reg;
5991 u16 mask = 0;
5992
Jeff Garzikbf794512005-07-31 13:07:26 -04005993 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06005994 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04005995
James Ketrenos43f66a62005-03-25 12:31:53 -06005996 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005997 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06005998 /* IEEE_A */
5999 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
6000 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006001 IPW_DEBUG_WX
6002 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06006003 fr.tx_rates = 0;
6004 break;
6005 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006006
James Ketrenos43f66a62005-03-25 12:31:53 -06006007 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
6008 break;
6009
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006010 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06006011 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05006012 if (mode == IEEE_B) {
James Ketrenos43f66a62005-03-25 12:31:53 -06006013 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
6014 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006015 IPW_DEBUG_WX
6016 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06006017 fr.tx_rates = 0;
6018 }
6019 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04006020 }
James Ketrenos43f66a62005-03-25 12:31:53 -06006021
6022 /* IEEE_G */
6023 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
6024 IEEE80211_OFDM_RATES_MASK)) {
6025 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05006026 IPW_DEBUG_WX
6027 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06006028 fr.tx_rates = 0;
6029 break;
6030 }
6031
6032 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
6033 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
6034 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
6035 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006036
James Ketrenos43f66a62005-03-25 12:31:53 -06006037 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
6038 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
6039 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
6040 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006041
James Ketrenos43f66a62005-03-25 12:31:53 -06006042 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
6043 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
6044 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
6045 }
Jeff Garzikbf794512005-07-31 13:07:26 -04006046
James Ketrenos43f66a62005-03-25 12:31:53 -06006047 fr.tx_rates |= mask;
6048 break;
6049 }
6050
6051 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04006052 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06006053}
6054
James Ketrenosea2b26e2005-08-24 21:25:16 -05006055static void ipw_abort_scan(struct ipw_priv *priv)
6056{
6057 int err;
6058
6059 if (priv->status & STATUS_SCAN_ABORTING) {
6060 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
6061 return;
6062 }
6063 priv->status |= STATUS_SCAN_ABORTING;
6064
6065 err = ipw_send_scan_abort(priv);
6066 if (err)
6067 IPW_DEBUG_HC("Request to abort scan failed.\n");
6068}
6069
James Ketrenosafbf30a2005-08-25 00:05:33 -05006070static void ipw_add_scan_channels(struct ipw_priv *priv,
6071 struct ipw_scan_request_ext *scan,
6072 int scan_type)
6073{
6074 int channel_index = 0;
6075 const struct ieee80211_geo *geo;
6076 int i;
6077
Larry Finger1867b112006-02-28 09:48:28 -06006078 geo = ieee80211_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006079
6080 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
6081 int start = channel_index;
6082 for (i = 0; i < geo->a_channels; i++) {
6083 if ((priv->status & STATUS_ASSOCIATED) &&
6084 geo->a[i].channel == priv->channel)
6085 continue;
6086 channel_index++;
6087 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006088 ipw_set_scan_type(scan, channel_index,
6089 geo->a[i].
6090 flags & IEEE80211_CH_PASSIVE_ONLY ?
6091 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
6092 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006093 }
6094
6095 if (start != channel_index) {
6096 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
6097 (channel_index - start);
6098 channel_index++;
6099 }
6100 }
6101
6102 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
6103 int start = channel_index;
6104 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05006105 int index;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006106 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
6107 /* nop out the list */
6108 [0] = 0
6109 };
6110
6111 u8 channel;
6112 while (channel_index < IPW_SCAN_CHANNELS) {
6113 channel =
6114 priv->speed_scan[priv->speed_scan_pos];
6115 if (channel == 0) {
6116 priv->speed_scan_pos = 0;
6117 channel = priv->speed_scan[0];
6118 }
6119 if ((priv->status & STATUS_ASSOCIATED) &&
6120 channel == priv->channel) {
6121 priv->speed_scan_pos++;
6122 continue;
6123 }
6124
6125 /* If this channel has already been
6126 * added in scan, break from loop
6127 * and this will be the first channel
6128 * in the next scan.
6129 */
6130 if (channels[channel - 1] != 0)
6131 break;
6132
6133 channels[channel - 1] = 1;
6134 priv->speed_scan_pos++;
6135 channel_index++;
6136 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006137 index =
Larry Finger1867b112006-02-28 09:48:28 -06006138 ieee80211_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006139 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006140 geo->bg[index].
6141 flags &
6142 IEEE80211_CH_PASSIVE_ONLY ?
6143 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6144 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006145 }
6146 } else {
6147 for (i = 0; i < geo->bg_channels; i++) {
6148 if ((priv->status & STATUS_ASSOCIATED) &&
6149 geo->bg[i].channel == priv->channel)
6150 continue;
6151 channel_index++;
6152 scan->channels_list[channel_index] =
6153 geo->bg[i].channel;
6154 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006155 geo->bg[i].
6156 flags &
6157 IEEE80211_CH_PASSIVE_ONLY ?
6158 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6159 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006160 }
6161 }
6162
6163 if (start != channel_index) {
6164 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6165 (channel_index - start);
6166 }
6167 }
6168}
6169
James Ketrenosea2b26e2005-08-24 21:25:16 -05006170static int ipw_request_scan(struct ipw_priv *priv)
6171{
6172 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006173 int err = 0, scan_type;
6174
6175 if (!(priv->status & STATUS_INIT) ||
6176 (priv->status & STATUS_EXIT_PENDING))
6177 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006178
Zhu Yi46441512006-01-24 16:37:59 +08006179 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006180
James Ketrenosea2b26e2005-08-24 21:25:16 -05006181 if (priv->status & STATUS_SCANNING) {
James Ketrenosa613bff2005-08-24 21:43:11 -05006182 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05006183 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006184 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006185 }
6186
James Ketrenosafbf30a2005-08-25 00:05:33 -05006187 if (!(priv->status & STATUS_SCAN_FORCED) &&
6188 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006189 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6190 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006191 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006192 }
6193
6194 if (priv->status & STATUS_RF_KILL_MASK) {
6195 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6196 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006197 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006198 }
6199
6200 memset(&scan, 0, sizeof(scan));
6201
James Ketrenosb095c382005-08-24 22:04:42 -05006202 if (priv->config & CFG_SPEED_SCAN)
6203 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6204 cpu_to_le16(30);
6205 else
6206 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6207 cpu_to_le16(20);
6208
James Ketrenosa613bff2005-08-24 21:43:11 -05006209 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6210 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05006211 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006212
James Ketrenosa613bff2005-08-24 21:43:11 -05006213 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006214
James Ketrenosb095c382005-08-24 22:04:42 -05006215#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006216 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006217 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006218 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006219
Larry Finger1867b112006-02-28 09:48:28 -06006220 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006221 case IEEE80211_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006222 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006223 channel = priv->channel;
6224 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006225
James Ketrenosb095c382005-08-24 22:04:42 -05006226 case IEEE80211_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006227 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006228 channel = priv->channel;
6229 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006230
James Ketrenosb095c382005-08-24 22:04:42 -05006231 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006232 band = (u8) (IPW_B_MODE << 6) | 1;
6233 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006234 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006235 }
6236
James Ketrenosb095c382005-08-24 22:04:42 -05006237 scan.channels_list[0] = band;
6238 scan.channels_list[1] = channel;
6239 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006240
James Ketrenosb095c382005-08-24 22:04:42 -05006241 /* NOTE: The card will sit on this channel for this time
6242 * period. Scan aborts are timing sensitive and frequently
6243 * result in firmware restarts. As such, it is best to
6244 * set a small dwell_time here and just keep re-issuing
6245 * scans. Otherwise fast channel hopping will not actually
6246 * hop channels.
6247 *
6248 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006249 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6250 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006251 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006252#endif /* CONFIG_IPW2200_MONITOR */
6253 /* If we are roaming, then make this a directed scan for the
6254 * current network. Otherwise, ensure that every other scan
6255 * is a fast channel hop scan */
6256 if ((priv->status & STATUS_ROAMING)
6257 || (!(priv->status & STATUS_ASSOCIATED)
6258 && (priv->config & CFG_STATIC_ESSID)
6259 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006260 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6261 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006262 IPW_DEBUG_HC("Attempt to send SSID command "
6263 "failed.\n");
6264 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006265 }
6266
6267 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006268 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006269 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006270
James Ketrenosafbf30a2005-08-25 00:05:33 -05006271 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006272#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006273 }
6274#endif
6275
6276 err = ipw_send_scan_request_ext(priv, &scan);
6277 if (err) {
6278 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006279 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006280 }
6281
6282 priv->status |= STATUS_SCANNING;
6283 priv->status &= ~STATUS_SCAN_PENDING;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006284 queue_delayed_work(priv->workqueue, &priv->scan_check,
6285 IPW_SCAN_CHECK_WATCHDOG);
James Ketrenosb095c382005-08-24 22:04:42 -05006286 done:
Zhu Yi46441512006-01-24 16:37:59 +08006287 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006288 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006289}
6290
6291static void ipw_bg_abort_scan(void *data)
6292{
6293 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08006294 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006295 ipw_abort_scan(data);
Zhu Yi46441512006-01-24 16:37:59 +08006296 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006297}
6298
James Ketrenosea2b26e2005-08-24 21:25:16 -05006299static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6300{
James Ketrenosb095c382005-08-24 22:04:42 -05006301 /* This is called when wpa_supplicant loads and closes the driver
6302 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006303 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006304 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006305}
6306
James Ketrenosea2b26e2005-08-24 21:25:16 -05006307static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6308{
6309 struct ieee80211_device *ieee = priv->ieee;
6310 struct ieee80211_security sec = {
6311 .flags = SEC_AUTH_MODE,
6312 };
6313 int ret = 0;
6314
James Ketrenosafbf30a2005-08-25 00:05:33 -05006315 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006316 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6317 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006318 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006319 sec.auth_mode = WLAN_AUTH_OPEN;
6320 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006321 } else if (value & IW_AUTH_ALG_LEAP) {
6322 sec.auth_mode = WLAN_AUTH_LEAP;
6323 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006324 } else
6325 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006326
6327 if (ieee->set_security)
6328 ieee->set_security(ieee->dev, &sec);
6329 else
6330 ret = -EOPNOTSUPP;
6331
6332 return ret;
6333}
6334
Adrian Bunka73e22b2006-01-21 01:39:42 +01006335static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6336 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006337{
6338 /* make sure WPA is enabled */
6339 ipw_wpa_enable(priv, 1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006340}
6341
6342static int ipw_set_rsn_capa(struct ipw_priv *priv,
6343 char *capabilities, int length)
6344{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006345 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6346
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006347 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006348 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006349}
6350
James Ketrenosafbf30a2005-08-25 00:05:33 -05006351/*
6352 * WE-18 support
6353 */
6354
6355/* SIOCSIWGENIE */
6356static int ipw_wx_set_genie(struct net_device *dev,
6357 struct iw_request_info *info,
6358 union iwreq_data *wrqu, char *extra)
6359{
6360 struct ipw_priv *priv = ieee80211_priv(dev);
6361 struct ieee80211_device *ieee = priv->ieee;
6362 u8 *buf;
6363 int err = 0;
6364
6365 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6366 (wrqu->data.length && extra == NULL))
6367 return -EINVAL;
6368
James Ketrenosafbf30a2005-08-25 00:05:33 -05006369 if (wrqu->data.length) {
6370 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6371 if (buf == NULL) {
6372 err = -ENOMEM;
6373 goto out;
6374 }
6375
6376 memcpy(buf, extra, wrqu->data.length);
6377 kfree(ieee->wpa_ie);
6378 ieee->wpa_ie = buf;
6379 ieee->wpa_ie_len = wrqu->data.length;
6380 } else {
6381 kfree(ieee->wpa_ie);
6382 ieee->wpa_ie = NULL;
6383 ieee->wpa_ie_len = 0;
6384 }
6385
6386 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6387 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006388 return err;
6389}
6390
6391/* SIOCGIWGENIE */
6392static int ipw_wx_get_genie(struct net_device *dev,
6393 struct iw_request_info *info,
6394 union iwreq_data *wrqu, char *extra)
6395{
6396 struct ipw_priv *priv = ieee80211_priv(dev);
6397 struct ieee80211_device *ieee = priv->ieee;
6398 int err = 0;
6399
James Ketrenosafbf30a2005-08-25 00:05:33 -05006400 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6401 wrqu->data.length = 0;
6402 goto out;
6403 }
6404
6405 if (wrqu->data.length < ieee->wpa_ie_len) {
6406 err = -E2BIG;
6407 goto out;
6408 }
6409
6410 wrqu->data.length = ieee->wpa_ie_len;
6411 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6412
6413 out:
James Ketrenosafbf30a2005-08-25 00:05:33 -05006414 return err;
6415}
6416
Zhu Yi1fbfea52005-08-05 17:22:56 +08006417static int wext_cipher2level(int cipher)
6418{
6419 switch (cipher) {
6420 case IW_AUTH_CIPHER_NONE:
6421 return SEC_LEVEL_0;
6422 case IW_AUTH_CIPHER_WEP40:
6423 case IW_AUTH_CIPHER_WEP104:
6424 return SEC_LEVEL_1;
6425 case IW_AUTH_CIPHER_TKIP:
6426 return SEC_LEVEL_2;
6427 case IW_AUTH_CIPHER_CCMP:
6428 return SEC_LEVEL_3;
6429 default:
6430 return -1;
6431 }
6432}
6433
James Ketrenosafbf30a2005-08-25 00:05:33 -05006434/* SIOCSIWAUTH */
6435static int ipw_wx_set_auth(struct net_device *dev,
6436 struct iw_request_info *info,
6437 union iwreq_data *wrqu, char *extra)
6438{
6439 struct ipw_priv *priv = ieee80211_priv(dev);
6440 struct ieee80211_device *ieee = priv->ieee;
6441 struct iw_param *param = &wrqu->param;
6442 struct ieee80211_crypt_data *crypt;
6443 unsigned long flags;
6444 int ret = 0;
6445
6446 switch (param->flags & IW_AUTH_INDEX) {
6447 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006448 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006449 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006450 ipw_set_hw_decrypt_unicast(priv,
6451 wext_cipher2level(param->value));
6452 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006453 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006454 ipw_set_hw_decrypt_multicast(priv,
6455 wext_cipher2level(param->value));
6456 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006457 case IW_AUTH_KEY_MGMT:
6458 /*
6459 * ipw2200 does not use these parameters
6460 */
6461 break;
6462
6463 case IW_AUTH_TKIP_COUNTERMEASURES:
6464 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006465 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006466 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006467
6468 flags = crypt->ops->get_flags(crypt->priv);
6469
6470 if (param->value)
6471 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6472 else
6473 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6474
6475 crypt->ops->set_flags(flags, crypt->priv);
6476
6477 break;
6478
6479 case IW_AUTH_DROP_UNENCRYPTED:{
6480 /* HACK:
6481 *
6482 * wpa_supplicant calls set_wpa_enabled when the driver
6483 * is loaded and unloaded, regardless of if WPA is being
6484 * used. No other calls are made which can be used to
6485 * determine if encryption will be used or not prior to
6486 * association being expected. If encryption is not being
6487 * used, drop_unencrypted is set to false, else true -- we
6488 * can use this to determine if the CAP_PRIVACY_ON bit should
6489 * be set.
6490 */
6491 struct ieee80211_security sec = {
6492 .flags = SEC_ENABLED,
6493 .enabled = param->value,
6494 };
6495 priv->ieee->drop_unencrypted = param->value;
6496 /* We only change SEC_LEVEL for open mode. Others
6497 * are set by ipw_wpa_set_encryption.
6498 */
6499 if (!param->value) {
6500 sec.flags |= SEC_LEVEL;
6501 sec.level = SEC_LEVEL_0;
6502 } else {
6503 sec.flags |= SEC_LEVEL;
6504 sec.level = SEC_LEVEL_1;
6505 }
6506 if (priv->ieee->set_security)
6507 priv->ieee->set_security(priv->ieee->dev, &sec);
6508 break;
6509 }
6510
6511 case IW_AUTH_80211_AUTH_ALG:
6512 ret = ipw_wpa_set_auth_algs(priv, param->value);
6513 break;
6514
6515 case IW_AUTH_WPA_ENABLED:
6516 ret = ipw_wpa_enable(priv, param->value);
Zhu Yie3c5a642006-04-13 17:21:13 +08006517 ipw_disassociate(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006518 break;
6519
6520 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6521 ieee->ieee802_1x = param->value;
6522 break;
6523
James Ketrenosafbf30a2005-08-25 00:05:33 -05006524 case IW_AUTH_PRIVACY_INVOKED:
6525 ieee->privacy_invoked = param->value;
6526 break;
6527
6528 default:
6529 return -EOPNOTSUPP;
6530 }
6531 return ret;
6532}
6533
6534/* SIOCGIWAUTH */
6535static int ipw_wx_get_auth(struct net_device *dev,
6536 struct iw_request_info *info,
6537 union iwreq_data *wrqu, char *extra)
6538{
6539 struct ipw_priv *priv = ieee80211_priv(dev);
6540 struct ieee80211_device *ieee = priv->ieee;
6541 struct ieee80211_crypt_data *crypt;
6542 struct iw_param *param = &wrqu->param;
6543 int ret = 0;
6544
6545 switch (param->flags & IW_AUTH_INDEX) {
6546 case IW_AUTH_WPA_VERSION:
6547 case IW_AUTH_CIPHER_PAIRWISE:
6548 case IW_AUTH_CIPHER_GROUP:
6549 case IW_AUTH_KEY_MGMT:
6550 /*
6551 * wpa_supplicant will control these internally
6552 */
6553 ret = -EOPNOTSUPP;
6554 break;
6555
6556 case IW_AUTH_TKIP_COUNTERMEASURES:
6557 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006558 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006559 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006560
6561 param->value = (crypt->ops->get_flags(crypt->priv) &
6562 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6563
6564 break;
6565
6566 case IW_AUTH_DROP_UNENCRYPTED:
6567 param->value = ieee->drop_unencrypted;
6568 break;
6569
6570 case IW_AUTH_80211_AUTH_ALG:
6571 param->value = ieee->sec.auth_mode;
6572 break;
6573
6574 case IW_AUTH_WPA_ENABLED:
6575 param->value = ieee->wpa_enabled;
6576 break;
6577
6578 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6579 param->value = ieee->ieee802_1x;
6580 break;
6581
6582 case IW_AUTH_ROAMING_CONTROL:
6583 case IW_AUTH_PRIVACY_INVOKED:
6584 param->value = ieee->privacy_invoked;
6585 break;
6586
6587 default:
6588 return -EOPNOTSUPP;
6589 }
6590 return 0;
6591}
6592
6593/* SIOCSIWENCODEEXT */
6594static int ipw_wx_set_encodeext(struct net_device *dev,
6595 struct iw_request_info *info,
6596 union iwreq_data *wrqu, char *extra)
6597{
6598 struct ipw_priv *priv = ieee80211_priv(dev);
6599 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6600
6601 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006602 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006603 /* IPW HW can't build TKIP MIC,
6604 host decryption still needed */
6605 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6606 priv->ieee->host_mc_decrypt = 1;
6607 else {
6608 priv->ieee->host_encrypt = 0;
6609 priv->ieee->host_encrypt_msdu = 1;
6610 priv->ieee->host_decrypt = 1;
6611 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006612 } else {
6613 priv->ieee->host_encrypt = 0;
6614 priv->ieee->host_encrypt_msdu = 0;
6615 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006616 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006617 }
6618 }
6619
6620 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6621}
6622
6623/* SIOCGIWENCODEEXT */
6624static int ipw_wx_get_encodeext(struct net_device *dev,
6625 struct iw_request_info *info,
6626 union iwreq_data *wrqu, char *extra)
6627{
6628 struct ipw_priv *priv = ieee80211_priv(dev);
6629 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6630}
6631
6632/* SIOCSIWMLME */
6633static int ipw_wx_set_mlme(struct net_device *dev,
6634 struct iw_request_info *info,
6635 union iwreq_data *wrqu, char *extra)
6636{
6637 struct ipw_priv *priv = ieee80211_priv(dev);
6638 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6639 u16 reason;
6640
6641 reason = cpu_to_le16(mlme->reason_code);
6642
6643 switch (mlme->cmd) {
6644 case IW_MLME_DEAUTH:
Pavel Machek67fd6b42006-07-11 15:34:05 +02006645 /* silently ignore */
James Ketrenosafbf30a2005-08-25 00:05:33 -05006646 break;
6647
6648 case IW_MLME_DISASSOC:
6649 ipw_disassociate(priv);
6650 break;
6651
6652 default:
6653 return -EOPNOTSUPP;
6654 }
6655 return 0;
6656}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006657
Zhu Yie43e3c12006-04-13 17:20:45 +08006658#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05006659
6660/* QoS */
6661/*
6662* get the modulation type of the current network or
6663* the card current mode
6664*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006665static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006666{
6667 u8 mode = 0;
6668
6669 if (priv->status & STATUS_ASSOCIATED) {
6670 unsigned long flags;
6671
6672 spin_lock_irqsave(&priv->ieee->lock, flags);
6673 mode = priv->assoc_network->mode;
6674 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6675 } else {
6676 mode = priv->ieee->mode;
6677 }
6678 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6679 return mode;
6680}
6681
6682/*
6683* Handle management frame beacon and probe response
6684*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006685static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6686 int active_network,
6687 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006688{
6689 u32 size = sizeof(struct ieee80211_qos_parameters);
6690
James Ketrenosafbf30a2005-08-25 00:05:33 -05006691 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006692 network->qos_data.active = network->qos_data.supported;
6693
6694 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006695 if (active_network &&
6696 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006697 network->qos_data.active = network->qos_data.supported;
6698
6699 if ((network->qos_data.active == 1) && (active_network == 1) &&
6700 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6701 (network->qos_data.old_param_count !=
6702 network->qos_data.param_count)) {
6703 network->qos_data.old_param_count =
6704 network->qos_data.param_count;
6705 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006706 IPW_DEBUG_QOS("QoS parameters change call "
6707 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006708 }
6709 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006710 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6711 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006712 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006713 else
6714 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006715 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006716
James Ketrenosb095c382005-08-24 22:04:42 -05006717 if ((network->qos_data.active == 1) && (active_network == 1)) {
6718 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6719 schedule_work(&priv->qos_activate);
6720 }
6721
6722 network->qos_data.active = 0;
6723 network->qos_data.supported = 0;
6724 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006725 if ((priv->status & STATUS_ASSOCIATED) &&
6726 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6727 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6728 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6729 !(network->flags & NETWORK_EMPTY_ESSID))
James Ketrenosb095c382005-08-24 22:04:42 -05006730 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006731 priv->assoc_network->ssid_len) &&
6732 !memcmp(network->ssid,
6733 priv->assoc_network->ssid,
6734 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006735 queue_work(priv->workqueue,
6736 &priv->merge_networks);
6737 }
James Ketrenosb095c382005-08-24 22:04:42 -05006738 }
6739
6740 return 0;
6741}
6742
6743/*
6744* This function set up the firmware to support QoS. It sends
6745* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6746*/
6747static int ipw_qos_activate(struct ipw_priv *priv,
6748 struct ieee80211_qos_data *qos_network_data)
6749{
6750 int err;
6751 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6752 struct ieee80211_qos_parameters *active_one = NULL;
6753 u32 size = sizeof(struct ieee80211_qos_parameters);
6754 u32 burst_duration;
6755 int i;
6756 u8 type;
6757
6758 type = ipw_qos_current_mode(priv);
6759
6760 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6761 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6762 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6763 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6764
6765 if (qos_network_data == NULL) {
6766 if (type == IEEE_B) {
6767 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6768 active_one = &def_parameters_CCK;
6769 } else
6770 active_one = &def_parameters_OFDM;
6771
James Ketrenosafbf30a2005-08-25 00:05:33 -05006772 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006773 burst_duration = ipw_qos_get_burst_duration(priv);
6774 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006775 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6776 (u16) burst_duration;
6777 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05006778 if (type == IEEE_B) {
6779 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6780 type);
6781 if (priv->qos_data.qos_enable == 0)
6782 active_one = &def_parameters_CCK;
6783 else
6784 active_one = priv->qos_data.def_qos_parm_CCK;
6785 } else {
6786 if (priv->qos_data.qos_enable == 0)
6787 active_one = &def_parameters_OFDM;
6788 else
6789 active_one = priv->qos_data.def_qos_parm_OFDM;
6790 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006791 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006792 } else {
6793 unsigned long flags;
6794 int active;
6795
6796 spin_lock_irqsave(&priv->ieee->lock, flags);
6797 active_one = &(qos_network_data->parameters);
6798 qos_network_data->old_param_count =
6799 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006800 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006801 active = qos_network_data->supported;
6802 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6803
6804 if (active == 0) {
6805 burst_duration = ipw_qos_get_burst_duration(priv);
6806 for (i = 0; i < QOS_QUEUE_NUM; i++)
6807 qos_parameters[QOS_PARAM_SET_ACTIVE].
6808 tx_op_limit[i] = (u16) burst_duration;
6809 }
6810 }
6811
6812 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05006813 err = ipw_send_qos_params_command(priv,
6814 (struct ieee80211_qos_parameters *)
6815 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05006816 if (err)
6817 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6818
6819 return err;
6820}
6821
6822/*
6823* send IPW_CMD_WME_INFO to the firmware
6824*/
6825static int ipw_qos_set_info_element(struct ipw_priv *priv)
6826{
6827 int ret = 0;
6828 struct ieee80211_qos_information_element qos_info;
6829
6830 if (priv == NULL)
6831 return -1;
6832
6833 qos_info.elementID = QOS_ELEMENT_ID;
6834 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6835
6836 qos_info.version = QOS_VERSION_1;
6837 qos_info.ac_info = 0;
6838
6839 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6840 qos_info.qui_type = QOS_OUI_TYPE;
6841 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6842
6843 ret = ipw_send_qos_info_command(priv, &qos_info);
6844 if (ret != 0) {
6845 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6846 }
6847 return ret;
6848}
6849
6850/*
6851* Set the QoS parameter with the association request structure
6852*/
6853static int ipw_qos_association(struct ipw_priv *priv,
6854 struct ieee80211_network *network)
6855{
6856 int err = 0;
6857 struct ieee80211_qos_data *qos_data = NULL;
6858 struct ieee80211_qos_data ibss_data = {
6859 .supported = 1,
6860 .active = 1,
6861 };
6862
6863 switch (priv->ieee->iw_mode) {
6864 case IW_MODE_ADHOC:
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02006865 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
James Ketrenosb095c382005-08-24 22:04:42 -05006866
6867 qos_data = &ibss_data;
6868 break;
6869
6870 case IW_MODE_INFRA:
6871 qos_data = &network->qos_data;
6872 break;
6873
6874 default:
6875 BUG();
6876 break;
6877 }
6878
6879 err = ipw_qos_activate(priv, qos_data);
6880 if (err) {
6881 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6882 return err;
6883 }
6884
6885 if (priv->qos_data.qos_enable && qos_data->supported) {
6886 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6887 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6888 return ipw_qos_set_info_element(priv);
6889 }
6890
6891 return 0;
6892}
6893
6894/*
6895* handling the beaconing responces. if we get different QoS setting
6896* of the network from the the associated setting adjust the QoS
6897* setting
6898*/
6899static int ipw_qos_association_resp(struct ipw_priv *priv,
6900 struct ieee80211_network *network)
6901{
6902 int ret = 0;
6903 unsigned long flags;
6904 u32 size = sizeof(struct ieee80211_qos_parameters);
6905 int set_qos_param = 0;
6906
James Ketrenosafbf30a2005-08-25 00:05:33 -05006907 if ((priv == NULL) || (network == NULL) ||
6908 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05006909 return ret;
6910
6911 if (!(priv->status & STATUS_ASSOCIATED))
6912 return ret;
6913
James Ketrenosafbf30a2005-08-25 00:05:33 -05006914 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05006915 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05006916
6917 spin_lock_irqsave(&priv->ieee->lock, flags);
6918 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006919 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
James Ketrenosb095c382005-08-24 22:04:42 -05006920 sizeof(struct ieee80211_qos_data));
6921 priv->assoc_network->qos_data.active = 1;
6922 if ((network->qos_data.old_param_count !=
6923 network->qos_data.param_count)) {
6924 set_qos_param = 1;
6925 network->qos_data.old_param_count =
6926 network->qos_data.param_count;
6927 }
6928
6929 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006930 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
6931 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006932 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006933 else
6934 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006935 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006936 priv->assoc_network->qos_data.active = 0;
6937 priv->assoc_network->qos_data.supported = 0;
6938 set_qos_param = 1;
6939 }
6940
6941 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6942
6943 if (set_qos_param == 1)
6944 schedule_work(&priv->qos_activate);
6945
6946 return ret;
6947}
6948
6949static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
6950{
6951 u32 ret = 0;
6952
6953 if ((priv == NULL))
6954 return 0;
6955
James Ketrenosafbf30a2005-08-25 00:05:33 -05006956 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05006957 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006958 else
James Ketrenosb095c382005-08-24 22:04:42 -05006959 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006960
James Ketrenosb095c382005-08-24 22:04:42 -05006961 return ret;
6962}
6963
6964/*
6965* Initialize the setting of QoS global
6966*/
6967static void ipw_qos_init(struct ipw_priv *priv, int enable,
6968 int burst_enable, u32 burst_duration_CCK,
6969 u32 burst_duration_OFDM)
6970{
6971 priv->qos_data.qos_enable = enable;
6972
6973 if (priv->qos_data.qos_enable) {
6974 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
6975 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
6976 IPW_DEBUG_QOS("QoS is enabled\n");
6977 } else {
6978 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
6979 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
6980 IPW_DEBUG_QOS("QoS is not enabled\n");
6981 }
6982
6983 priv->qos_data.burst_enable = burst_enable;
6984
6985 if (burst_enable) {
6986 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
6987 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
6988 } else {
6989 priv->qos_data.burst_duration_CCK = 0;
6990 priv->qos_data.burst_duration_OFDM = 0;
6991 }
6992}
6993
6994/*
6995* map the packet priority to the right TX Queue
6996*/
6997static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
6998{
6999 if (priority > 7 || !priv->qos_data.qos_enable)
7000 priority = 0;
7001
7002 return from_priority_to_tx_queue[priority] - 1;
7003}
7004
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007005static int ipw_is_qos_active(struct net_device *dev,
7006 struct sk_buff *skb)
James Ketrenosb095c382005-08-24 22:04:42 -05007007{
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007008 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosb095c382005-08-24 22:04:42 -05007009 struct ieee80211_qos_data *qos_data = NULL;
7010 int active, supported;
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007011 u8 *daddr = skb->data + ETH_ALEN;
7012 int unicast = !is_multicast_ether_addr(daddr);
James Ketrenosb095c382005-08-24 22:04:42 -05007013
7014 if (!(priv->status & STATUS_ASSOCIATED))
7015 return 0;
7016
7017 qos_data = &priv->assoc_network->qos_data;
7018
James Ketrenosb095c382005-08-24 22:04:42 -05007019 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7020 if (unicast == 0)
7021 qos_data->active = 0;
7022 else
7023 qos_data->active = qos_data->supported;
7024 }
James Ketrenosb095c382005-08-24 22:04:42 -05007025 active = qos_data->active;
7026 supported = qos_data->supported;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007027 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
7028 "unicast %d\n",
7029 priv->qos_data.qos_enable, active, supported, unicast);
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007030 if (active && priv->qos_data.qos_enable)
7031 return 1;
James Ketrenosb095c382005-08-24 22:04:42 -05007032
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007033 return 0;
7034
7035}
7036/*
7037* add QoS parameter to the TX command
7038*/
7039static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
7040 u16 priority,
7041 struct tfd_data *tfd)
7042{
7043 int tx_queue_id = 0;
7044
7045
7046 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
7047 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
7048
7049 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
7050 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
7051 tfd->tfd.tfd_26.mchdr.qos_ctrl |= CTRL_QOS_NO_ACK;
James Ketrenosb095c382005-08-24 22:04:42 -05007052 }
Zhu Yia5cf4fe2006-04-13 17:19:11 +08007053 return 0;
James Ketrenosb095c382005-08-24 22:04:42 -05007054}
7055
7056/*
7057* background support to run QoS activate functionality
7058*/
7059static void ipw_bg_qos_activate(void *data)
7060{
7061 struct ipw_priv *priv = data;
7062
7063 if (priv == NULL)
7064 return;
7065
Zhu Yi46441512006-01-24 16:37:59 +08007066 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007067
7068 if (priv->status & STATUS_ASSOCIATED)
7069 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
7070
Zhu Yi46441512006-01-24 16:37:59 +08007071 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05007072}
7073
James Ketrenos3b9990c2005-08-19 13:18:55 -05007074static int ipw_handle_probe_response(struct net_device *dev,
7075 struct ieee80211_probe_response *resp,
7076 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05007077{
7078 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05007079 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7080 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05007081
James Ketrenos3b9990c2005-08-19 13:18:55 -05007082 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007083
James Ketrenos3b9990c2005-08-19 13:18:55 -05007084 return 0;
7085}
James Ketrenosb095c382005-08-24 22:04:42 -05007086
James Ketrenos3b9990c2005-08-19 13:18:55 -05007087static int ipw_handle_beacon(struct net_device *dev,
7088 struct ieee80211_beacon *resp,
7089 struct ieee80211_network *network)
7090{
7091 struct ipw_priv *priv = ieee80211_priv(dev);
7092 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7093 (network == priv->assoc_network));
7094
7095 ipw_qos_handle_probe_response(priv, active_network, network);
7096
7097 return 0;
7098}
7099
7100static int ipw_handle_assoc_response(struct net_device *dev,
7101 struct ieee80211_assoc_response *resp,
7102 struct ieee80211_network *network)
7103{
7104 struct ipw_priv *priv = ieee80211_priv(dev);
7105 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007106 return 0;
7107}
7108
7109static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7110 *qos_param)
7111{
Zhu Yi4e226992006-01-24 16:37:36 +08007112 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7113 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007114}
7115
7116static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7117 *qos_param)
7118{
Zhu Yi4e226992006-01-24 16:37:36 +08007119 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7120 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007121}
7122
Zhu Yie43e3c12006-04-13 17:20:45 +08007123#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -05007124
James Ketrenos43f66a62005-03-25 12:31:53 -06007125static int ipw_associate_network(struct ipw_priv *priv,
7126 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007127 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007128{
7129 int err;
7130
7131 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007132 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007133
7134 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007135 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007136 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007137 memcpy(priv->essid, network->ssid, priv->essid_len);
7138 }
7139
7140 network->last_associate = jiffies;
7141
7142 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7143 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007144 priv->assoc_request.auth_key = 0;
7145
James Ketrenos43f66a62005-03-25 12:31:53 -06007146 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007147 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007148 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007149 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7150
Zhu Yi1ba61e02006-02-15 13:00:55 +08007151 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007152 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007153
7154 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7155 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7156 priv->assoc_request.auth_type = AUTH_LEAP;
7157 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007158 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007159
James Ketrenosa613bff2005-08-24 21:43:11 -05007160 if (priv->ieee->wpa_ie_len) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007161 priv->assoc_request.policy_support = 0x02; /* RSN active */
7162 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7163 priv->ieee->wpa_ie_len);
7164 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007165
Jeff Garzikbf794512005-07-31 13:07:26 -04007166 /*
7167 * It is valid for our ieee device to support multiple modes, but
7168 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007169 * just one mode.
7170 */
7171 if (network->mode & priv->ieee->mode & IEEE_A)
7172 priv->assoc_request.ieee_mode = IPW_A_MODE;
7173 else if (network->mode & priv->ieee->mode & IEEE_G)
7174 priv->assoc_request.ieee_mode = IPW_G_MODE;
7175 else if (network->mode & priv->ieee->mode & IEEE_B)
7176 priv->assoc_request.ieee_mode = IPW_B_MODE;
7177
James Ketrenosea2b26e2005-08-24 21:25:16 -05007178 priv->assoc_request.capability = network->capability;
7179 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7180 && !(priv->config & CFG_PREAMBLE_LONG)) {
7181 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7182 } else {
7183 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7184
7185 /* Clear the short preamble if we won't be supporting it */
7186 priv->assoc_request.capability &=
7187 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7188 }
7189
James Ketrenosafbf30a2005-08-25 00:05:33 -05007190 /* Clear capability bits that aren't used in Ad Hoc */
7191 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7192 priv->assoc_request.capability &=
7193 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7194
James Ketrenos43f66a62005-03-25 12:31:53 -06007195 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007196 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007197 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04007198 escape_essid(priv->essid, priv->essid_len),
7199 network->channel,
7200 ipw_modes[priv->assoc_request.ieee_mode],
7201 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007202 (priv->assoc_request.preamble_length ==
7203 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7204 network->capability &
7205 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007206 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007207 priv->capability & CAP_PRIVACY_ON ?
7208 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007209 "(open)") : "",
7210 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007211 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007212 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007213 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007214
7215 priv->assoc_request.beacon_interval = network->beacon_interval;
7216 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007217 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007218 priv->assoc_request.assoc_type = HC_IBSS_START;
7219 priv->assoc_request.assoc_tsf_msw = 0;
7220 priv->assoc_request.assoc_tsf_lsw = 0;
7221 } else {
7222 if (unlikely(roaming))
7223 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7224 else
7225 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7226 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7227 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7228 }
7229
James Ketrenosafbf30a2005-08-25 00:05:33 -05007230 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007231
7232 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7233 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7234 priv->assoc_request.atim_window = network->atim_window;
7235 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007236 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007237 priv->assoc_request.atim_window = 0;
7238 }
7239
James Ketrenos43f66a62005-03-25 12:31:53 -06007240 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04007241
James Ketrenos43f66a62005-03-25 12:31:53 -06007242 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7243 if (err) {
7244 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7245 return err;
7246 }
7247
7248 rates->ieee_mode = priv->assoc_request.ieee_mode;
7249 rates->purpose = IPW_RATE_CONNECT;
7250 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007251
James Ketrenos43f66a62005-03-25 12:31:53 -06007252 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7253 priv->sys_config.dot11g_auto_detection = 1;
7254 else
7255 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007256
7257 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7258 priv->sys_config.answer_broadcast_ssid_probe = 1;
7259 else
7260 priv->sys_config.answer_broadcast_ssid_probe = 0;
7261
Zhu Yid685b8c2006-04-13 17:20:27 +08007262 err = ipw_send_system_config(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06007263 if (err) {
7264 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7265 return err;
7266 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007267
James Ketrenos43f66a62005-03-25 12:31:53 -06007268 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007269 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007270 if (err) {
7271 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7272 return err;
7273 }
7274
7275 /*
7276 * If preemption is enabled, it is possible for the association
7277 * to complete before we return from ipw_send_associate. Therefore
7278 * we have to be sure and update our priviate data first.
7279 */
7280 priv->channel = network->channel;
7281 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007282 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007283 priv->status &= ~STATUS_SECURITY_UPDATED;
7284
7285 priv->assoc_network = network;
7286
Zhu Yie43e3c12006-04-13 17:20:45 +08007287#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -05007288 ipw_qos_association(priv, network);
7289#endif
7290
James Ketrenos43f66a62005-03-25 12:31:53 -06007291 err = ipw_send_associate(priv, &priv->assoc_request);
7292 if (err) {
7293 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7294 return err;
7295 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007296
7297 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007298 escape_essid(priv->essid, priv->essid_len),
7299 MAC_ARG(priv->bssid));
7300
7301 return 0;
7302}
7303
7304static void ipw_roam(void *data)
7305{
7306 struct ipw_priv *priv = data;
7307 struct ieee80211_network *network = NULL;
7308 struct ipw_network_match match = {
7309 .network = priv->assoc_network
7310 };
7311
7312 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007313 *
7314 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007315 * setting the status ROAM bit and requesting a scan.
7316 * 2. When the scan completes, it schedules the ROAM work
7317 * 3. The ROAM work looks at all of the known networks for one that
7318 * is a better network than the currently associated. If none
7319 * found, the ROAM process is over (ROAM bit cleared)
7320 * 4. If a better network is found, a disassociation request is
7321 * sent.
7322 * 5. When the disassociation completes, the roam work is again
7323 * scheduled. The second time through, the driver is no longer
7324 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007325 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007326 * 6. At this point ,the roaming process is complete and the ROAM
7327 * status bit is cleared.
7328 */
7329
7330 /* If we are no longer associated, and the roaming bit is no longer
7331 * set, then we are not actively roaming, so just return */
7332 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7333 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007334
James Ketrenos43f66a62005-03-25 12:31:53 -06007335 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007336 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007337 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007338 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007339 u8 rssi = priv->assoc_network->stats.rssi;
7340 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007341 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007342 list_for_each_entry(network, &priv->ieee->network_list, list) {
7343 if (network != priv->assoc_network)
7344 ipw_best_network(priv, &match, network, 1);
7345 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007346 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007347 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007348
James Ketrenos43f66a62005-03-25 12:31:53 -06007349 if (match.network == priv->assoc_network) {
7350 IPW_DEBUG_ASSOC("No better APs in this network to "
7351 "roam to.\n");
7352 priv->status &= ~STATUS_ROAMING;
7353 ipw_debug_config(priv);
7354 return;
7355 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007356
James Ketrenos43f66a62005-03-25 12:31:53 -06007357 ipw_send_disassociate(priv, 1);
7358 priv->assoc_network = match.network;
7359
7360 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007361 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007362
7363 /* Second pass through ROAM process -- request association */
7364 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7365 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7366 priv->status &= ~STATUS_ROAMING;
7367}
7368
James Ketrenosc848d0a2005-08-24 21:56:24 -05007369static void ipw_bg_roam(void *data)
7370{
7371 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08007372 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007373 ipw_roam(data);
Zhu Yi46441512006-01-24 16:37:59 +08007374 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007375}
7376
7377static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007378{
7379 struct ipw_priv *priv = data;
7380
7381 struct ieee80211_network *network = NULL;
7382 struct ipw_network_match match = {
7383 .network = NULL
7384 };
7385 struct ipw_supported_rates *rates;
7386 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007387 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007388
James Ketrenosb095c382005-08-24 22:04:42 -05007389 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7390 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7391 return 0;
7392 }
7393
James Ketrenosc848d0a2005-08-24 21:56:24 -05007394 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007395 IPW_DEBUG_ASSOC("Not attempting association (already in "
7396 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007397 return 0;
7398 }
7399
Hong Liue6324722005-09-14 21:04:15 -05007400 if (priv->status & STATUS_DISASSOCIATING) {
7401 IPW_DEBUG_ASSOC("Not attempting association (in "
7402 "disassociating)\n ");
7403 queue_work(priv->workqueue, &priv->associate);
7404 return 0;
7405 }
7406
James Ketrenosc848d0a2005-08-24 21:56:24 -05007407 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007408 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7409 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007410 return 0;
7411 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007412
7413 if (!(priv->config & CFG_ASSOCIATE) &&
7414 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007415 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007416 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007417 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007418 }
7419
James Ketrenosa613bff2005-08-24 21:43:11 -05007420 /* Protect our use of the network_list */
7421 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007422 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007423 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007424
7425 network = match.network;
7426 rates = &match.rates;
7427
7428 if (network == NULL &&
7429 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7430 priv->config & CFG_ADHOC_CREATE &&
7431 priv->config & CFG_STATIC_ESSID &&
James Ketrenosa613bff2005-08-24 21:43:11 -05007432 priv->config & CFG_STATIC_CHANNEL &&
James Ketrenos43f66a62005-03-25 12:31:53 -06007433 !list_empty(&priv->ieee->network_free_list)) {
7434 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007435 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007436 ipw_adhoc_create(priv, network);
7437 rates = &priv->rates;
7438 list_del(element);
7439 list_add_tail(&network->list, &priv->ieee->network_list);
7440 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007441 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007442
James Ketrenos43f66a62005-03-25 12:31:53 -06007443 /* If we reached the end of the list, then we don't have any valid
7444 * matching APs */
7445 if (!network) {
7446 ipw_debug_config(priv);
7447
James Ketrenosb095c382005-08-24 22:04:42 -05007448 if (!(priv->status & STATUS_SCANNING)) {
7449 if (!(priv->config & CFG_SPEED_SCAN))
7450 queue_delayed_work(priv->workqueue,
7451 &priv->request_scan,
7452 SCAN_INTERVAL);
7453 else
7454 queue_work(priv->workqueue,
7455 &priv->request_scan);
7456 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007457
James Ketrenosc848d0a2005-08-24 21:56:24 -05007458 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007459 }
7460
7461 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007462
7463 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007464}
Jeff Garzikbf794512005-07-31 13:07:26 -04007465
James Ketrenosc848d0a2005-08-24 21:56:24 -05007466static void ipw_bg_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007467{
James Ketrenosc848d0a2005-08-24 21:56:24 -05007468 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08007469 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007470 ipw_associate(data);
Zhu Yi46441512006-01-24 16:37:59 +08007471 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007472}
7473
James Ketrenosb095c382005-08-24 22:04:42 -05007474static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7475 struct sk_buff *skb)
7476{
7477 struct ieee80211_hdr *hdr;
7478 u16 fc;
7479
7480 hdr = (struct ieee80211_hdr *)skb->data;
7481 fc = le16_to_cpu(hdr->frame_ctl);
7482 if (!(fc & IEEE80211_FCTL_PROTECTED))
7483 return;
7484
7485 fc &= ~IEEE80211_FCTL_PROTECTED;
7486 hdr->frame_ctl = cpu_to_le16(fc);
7487 switch (priv->ieee->sec.level) {
7488 case SEC_LEVEL_3:
7489 /* Remove CCMP HDR */
7490 memmove(skb->data + IEEE80211_3ADDR_LEN,
7491 skb->data + IEEE80211_3ADDR_LEN + 8,
7492 skb->len - IEEE80211_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007493 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007494 break;
7495 case SEC_LEVEL_2:
7496 break;
7497 case SEC_LEVEL_1:
7498 /* Remove IV */
7499 memmove(skb->data + IEEE80211_3ADDR_LEN,
7500 skb->data + IEEE80211_3ADDR_LEN + 4,
7501 skb->len - IEEE80211_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007502 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007503 break;
7504 case SEC_LEVEL_0:
7505 break;
7506 default:
7507 printk(KERN_ERR "Unknow security level %d\n",
7508 priv->ieee->sec.level);
7509 break;
7510 }
7511}
7512
7513static void ipw_handle_data_packet(struct ipw_priv *priv,
7514 struct ipw_rx_mem_buffer *rxb,
7515 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007516{
Hong Liu567deaf2005-08-31 18:07:22 +08007517 struct ieee80211_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007518 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7519
7520 /* We received data from the HW, so stop the watchdog */
7521 priv->net_dev->trans_start = jiffies;
7522
Jeff Garzikbf794512005-07-31 13:07:26 -04007523 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007524 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007525 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007526 skb_tailroom(rxb->skb))) {
7527 priv->ieee->stats.rx_errors++;
7528 priv->wstats.discard.misc++;
7529 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7530 return;
7531 } else if (unlikely(!netif_running(priv->net_dev))) {
7532 priv->ieee->stats.rx_dropped++;
7533 priv->wstats.discard.misc++;
7534 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7535 return;
7536 }
7537
7538 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007539 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007540
7541 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007542 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007543
7544 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7545
James Ketrenosb095c382005-08-24 22:04:42 -05007546 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
Hong Liu567deaf2005-08-31 18:07:22 +08007547 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7548 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007549 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007550 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007551 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7552
Jeff Garzikbf794512005-07-31 13:07:26 -04007553 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06007554 priv->ieee->stats.rx_errors++;
James Ketrenosa613bff2005-08-24 21:43:11 -05007555 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007556 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007557 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007558 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007559}
7560
Zhu Yi459d4082006-04-13 17:21:00 +08007561#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05007562static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7563 struct ipw_rx_mem_buffer *rxb,
7564 struct ieee80211_rx_stats *stats)
7565{
7566 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7567 struct ipw_rx_frame *frame = &pkt->u.frame;
7568
7569 /* initial pull of some data */
7570 u16 received_channel = frame->received_channel;
7571 u8 antennaAndPhy = frame->antennaAndPhy;
7572 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7573 u16 pktrate = frame->rate;
7574
7575 /* Magic struct that slots into the radiotap header -- no reason
7576 * to build this manually element by element, we can write it much
7577 * more efficiently than we can parse it. ORDER MATTERS HERE */
Zhu Yid685b8c2006-04-13 17:20:27 +08007578 struct ipw_rt_hdr *ipw_rt;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007579
7580 short len = le16_to_cpu(pkt->u.frame.length);
7581
7582 /* We received data from the HW, so stop the watchdog */
7583 priv->net_dev->trans_start = jiffies;
7584
7585 /* We only process data packets if the
7586 * interface is open */
7587 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7588 skb_tailroom(rxb->skb))) {
7589 priv->ieee->stats.rx_errors++;
7590 priv->wstats.discard.misc++;
7591 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7592 return;
7593 } else if (unlikely(!netif_running(priv->net_dev))) {
7594 priv->ieee->stats.rx_dropped++;
7595 priv->wstats.discard.misc++;
7596 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7597 return;
7598 }
7599
7600 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7601 * that now */
7602 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7603 /* FIXME: Should alloc bigger skb instead */
7604 priv->ieee->stats.rx_dropped++;
7605 priv->wstats.discard.misc++;
7606 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7607 return;
7608 }
7609
7610 /* copy the frame itself */
7611 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7612 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7613
7614 /* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7615 * part of our real header, saves a little time.
7616 *
7617 * No longer necessary since we fill in all our data. Purge before merging
7618 * patch officially.
7619 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7620 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7621 */
7622
7623 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7624
7625 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7626 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7627 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7628
7629 /* Big bitfield of all the fields we provide in radiotap */
7630 ipw_rt->rt_hdr.it_present =
7631 ((1 << IEEE80211_RADIOTAP_FLAGS) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007632 (1 << IEEE80211_RADIOTAP_TSFT) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007633 (1 << IEEE80211_RADIOTAP_RATE) |
7634 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7635 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
Zhu Yid685b8c2006-04-13 17:20:27 +08007636 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
Mike Kershaw24a47db2005-08-26 00:41:54 -05007637 (1 << IEEE80211_RADIOTAP_ANTENNA));
7638
7639 /* Zero the flags, we'll add to them as we go */
7640 ipw_rt->rt_flags = 0;
7641
7642 /* Convert signal to DBM */
7643 ipw_rt->rt_dbmsignal = antsignal;
7644
7645 /* Convert the channel data and set the flags */
7646 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7647 if (received_channel > 14) { /* 802.11a */
7648 ipw_rt->rt_chbitmask =
7649 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7650 } else if (antennaAndPhy & 32) { /* 802.11b */
7651 ipw_rt->rt_chbitmask =
7652 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7653 } else { /* 802.11g */
7654 ipw_rt->rt_chbitmask =
7655 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7656 }
7657
7658 /* set the rate in multiples of 500k/s */
7659 switch (pktrate) {
7660 case IPW_TX_RATE_1MB:
7661 ipw_rt->rt_rate = 2;
7662 break;
7663 case IPW_TX_RATE_2MB:
7664 ipw_rt->rt_rate = 4;
7665 break;
7666 case IPW_TX_RATE_5MB:
7667 ipw_rt->rt_rate = 10;
7668 break;
7669 case IPW_TX_RATE_6MB:
7670 ipw_rt->rt_rate = 12;
7671 break;
7672 case IPW_TX_RATE_9MB:
7673 ipw_rt->rt_rate = 18;
7674 break;
7675 case IPW_TX_RATE_11MB:
7676 ipw_rt->rt_rate = 22;
7677 break;
7678 case IPW_TX_RATE_12MB:
7679 ipw_rt->rt_rate = 24;
7680 break;
7681 case IPW_TX_RATE_18MB:
7682 ipw_rt->rt_rate = 36;
7683 break;
7684 case IPW_TX_RATE_24MB:
7685 ipw_rt->rt_rate = 48;
7686 break;
7687 case IPW_TX_RATE_36MB:
7688 ipw_rt->rt_rate = 72;
7689 break;
7690 case IPW_TX_RATE_48MB:
7691 ipw_rt->rt_rate = 96;
7692 break;
7693 case IPW_TX_RATE_54MB:
7694 ipw_rt->rt_rate = 108;
7695 break;
7696 default:
7697 ipw_rt->rt_rate = 0;
7698 break;
7699 }
7700
7701 /* antenna number */
7702 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7703
7704 /* set the preamble flag if we have it */
7705 if ((antennaAndPhy & 64))
7706 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7707
7708 /* Set the size of the skb to the size of the frame */
7709 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007710
7711 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7712
7713 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7714 priv->ieee->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007715 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007716 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007717 /* no LED during capture */
7718 }
7719}
7720#endif
7721
Zhu Yid685b8c2006-04-13 17:20:27 +08007722#ifdef CONFIG_IPW2200_PROMISCUOUS
7723#define ieee80211_is_probe_response(fc) \
7724 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && \
7725 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP )
7726
7727#define ieee80211_is_management(fc) \
7728 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
7729
7730#define ieee80211_is_control(fc) \
7731 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
7732
7733#define ieee80211_is_data(fc) \
7734 ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
7735
7736#define ieee80211_is_assoc_request(fc) \
7737 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ)
7738
7739#define ieee80211_is_reassoc_request(fc) \
7740 ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
7741
7742static void ipw_handle_promiscuous_rx(struct ipw_priv *priv,
7743 struct ipw_rx_mem_buffer *rxb,
7744 struct ieee80211_rx_stats *stats)
7745{
7746 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7747 struct ipw_rx_frame *frame = &pkt->u.frame;
7748 struct ipw_rt_hdr *ipw_rt;
7749
7750 /* First cache any information we need before we overwrite
7751 * the information provided in the skb from the hardware */
7752 struct ieee80211_hdr *hdr;
7753 u16 channel = frame->received_channel;
7754 u8 phy_flags = frame->antennaAndPhy;
7755 s8 signal = frame->rssi_dbm - IPW_RSSI_TO_DBM;
7756 s8 noise = frame->noise;
7757 u8 rate = frame->rate;
7758 short len = le16_to_cpu(pkt->u.frame.length);
7759 u64 tsf = 0;
7760 struct sk_buff *skb;
7761 int hdr_only = 0;
7762 u16 filter = priv->prom_priv->filter;
7763
7764 /* If the filter is set to not include Rx frames then return */
7765 if (filter & IPW_PROM_NO_RX)
7766 return;
7767
Zhu Yid685b8c2006-04-13 17:20:27 +08007768 /* We received data from the HW, so stop the watchdog */
7769 priv->prom_net_dev->trans_start = jiffies;
7770
7771 if (unlikely((len + IPW_RX_FRAME_SIZE) > skb_tailroom(rxb->skb))) {
7772 priv->prom_priv->ieee->stats.rx_errors++;
7773 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7774 return;
7775 }
7776
7777 /* We only process data packets if the interface is open */
7778 if (unlikely(!netif_running(priv->prom_net_dev))) {
7779 priv->prom_priv->ieee->stats.rx_dropped++;
7780 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7781 return;
7782 }
7783
7784 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7785 * that now */
7786 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7787 /* FIXME: Should alloc bigger skb instead */
7788 priv->prom_priv->ieee->stats.rx_dropped++;
7789 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7790 return;
7791 }
7792
7793 hdr = (void *)rxb->skb->data + IPW_RX_FRAME_SIZE;
7794 if (ieee80211_is_management(hdr->frame_ctl)) {
7795 if (filter & IPW_PROM_NO_MGMT)
7796 return;
7797 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
7798 hdr_only = 1;
7799 } else if (ieee80211_is_control(hdr->frame_ctl)) {
7800 if (filter & IPW_PROM_NO_CTL)
7801 return;
7802 if (filter & IPW_PROM_CTL_HEADER_ONLY)
7803 hdr_only = 1;
7804 } else if (ieee80211_is_data(hdr->frame_ctl)) {
7805 if (filter & IPW_PROM_NO_DATA)
7806 return;
7807 if (filter & IPW_PROM_DATA_HEADER_ONLY)
7808 hdr_only = 1;
7809 }
7810
7811 /* Copy the SKB since this is for the promiscuous side */
7812 skb = skb_copy(rxb->skb, GFP_ATOMIC);
7813 if (skb == NULL) {
7814 IPW_ERROR("skb_clone failed for promiscuous copy.\n");
7815 return;
7816 }
7817
7818 /* copy the frame data to write after where the radiotap header goes */
7819 ipw_rt = (void *)skb->data;
7820
7821 if (hdr_only)
7822 len = ieee80211_get_hdrlen(hdr->frame_ctl);
7823
7824 memcpy(ipw_rt->payload, hdr, len);
7825
7826 /* Zero the radiotap static buffer ... We only need to zero the bytes
7827 * NOT part of our real header, saves a little time.
7828 *
7829 * No longer necessary since we fill in all our data. Purge before
7830 * merging patch officially.
7831 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7832 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7833 */
7834
7835 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7836 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7837 ipw_rt->rt_hdr.it_len = sizeof(*ipw_rt); /* total header+data */
7838
7839 /* Set the size of the skb to the size of the frame */
7840 skb_put(skb, ipw_rt->rt_hdr.it_len + len);
7841
7842 /* Big bitfield of all the fields we provide in radiotap */
7843 ipw_rt->rt_hdr.it_present =
7844 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7845 (1 << IEEE80211_RADIOTAP_TSFT) |
7846 (1 << IEEE80211_RADIOTAP_RATE) |
7847 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7848 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7849 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
7850 (1 << IEEE80211_RADIOTAP_ANTENNA));
7851
7852 /* Zero the flags, we'll add to them as we go */
7853 ipw_rt->rt_flags = 0;
7854
7855 ipw_rt->rt_tsf = tsf;
7856
7857 /* Convert to DBM */
7858 ipw_rt->rt_dbmsignal = signal;
7859 ipw_rt->rt_dbmnoise = noise;
7860
7861 /* Convert the channel data and set the flags */
7862 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(channel));
7863 if (channel > 14) { /* 802.11a */
7864 ipw_rt->rt_chbitmask =
7865 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7866 } else if (phy_flags & (1 << 5)) { /* 802.11b */
7867 ipw_rt->rt_chbitmask =
7868 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7869 } else { /* 802.11g */
7870 ipw_rt->rt_chbitmask =
7871 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7872 }
7873
7874 /* set the rate in multiples of 500k/s */
7875 switch (rate) {
7876 case IPW_TX_RATE_1MB:
7877 ipw_rt->rt_rate = 2;
7878 break;
7879 case IPW_TX_RATE_2MB:
7880 ipw_rt->rt_rate = 4;
7881 break;
7882 case IPW_TX_RATE_5MB:
7883 ipw_rt->rt_rate = 10;
7884 break;
7885 case IPW_TX_RATE_6MB:
7886 ipw_rt->rt_rate = 12;
7887 break;
7888 case IPW_TX_RATE_9MB:
7889 ipw_rt->rt_rate = 18;
7890 break;
7891 case IPW_TX_RATE_11MB:
7892 ipw_rt->rt_rate = 22;
7893 break;
7894 case IPW_TX_RATE_12MB:
7895 ipw_rt->rt_rate = 24;
7896 break;
7897 case IPW_TX_RATE_18MB:
7898 ipw_rt->rt_rate = 36;
7899 break;
7900 case IPW_TX_RATE_24MB:
7901 ipw_rt->rt_rate = 48;
7902 break;
7903 case IPW_TX_RATE_36MB:
7904 ipw_rt->rt_rate = 72;
7905 break;
7906 case IPW_TX_RATE_48MB:
7907 ipw_rt->rt_rate = 96;
7908 break;
7909 case IPW_TX_RATE_54MB:
7910 ipw_rt->rt_rate = 108;
7911 break;
7912 default:
7913 ipw_rt->rt_rate = 0;
7914 break;
7915 }
7916
7917 /* antenna number */
7918 ipw_rt->rt_antenna = (phy_flags & 3);
7919
7920 /* set the preamble flag if we have it */
7921 if (phy_flags & (1 << 6))
7922 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7923
7924 IPW_DEBUG_RX("Rx packet of %d bytes.\n", skb->len);
7925
7926 if (!ieee80211_rx(priv->prom_priv->ieee, skb, stats)) {
7927 priv->prom_priv->ieee->stats.rx_errors++;
7928 dev_kfree_skb_any(skb);
7929 }
7930}
7931#endif
7932
Arjan van de Ven858119e2006-01-14 13:20:43 -08007933static int is_network_packet(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007934 struct ieee80211_hdr_4addr *header)
7935{
7936 /* Filter incoming packets to determine if they are targetted toward
7937 * this network, discarding packets coming from ourselves */
7938 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05007939 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007940 /* packets from our adapter are dropped (echo) */
7941 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7942 return 0;
7943
Peter Jones90700fd2005-08-26 16:51:06 -05007944 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007945 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05007946 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007947
7948 /* packets to our adapter go through */
7949 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7950 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007951
Peter Jones90700fd2005-08-26 16:51:06 -05007952 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007953 /* packets from our adapter are dropped (echo) */
7954 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7955 return 0;
7956
Peter Jones90700fd2005-08-26 16:51:06 -05007957 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007958 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05007959 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7960
7961 /* packets to our adapter go through */
7962 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7963 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007964 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007965
James Ketrenosea2b26e2005-08-24 21:25:16 -05007966 return 1;
7967}
7968
James Ketrenosafbf30a2005-08-25 00:05:33 -05007969#define IPW_PACKET_RETRY_TIME HZ
7970
Arjan van de Ven858119e2006-01-14 13:20:43 -08007971static int is_duplicate_packet(struct ipw_priv *priv,
James Ketrenosafbf30a2005-08-25 00:05:33 -05007972 struct ieee80211_hdr_4addr *header)
7973{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007974 u16 sc = le16_to_cpu(header->seq_ctl);
7975 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7976 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7977 u16 *last_seq, *last_frag;
7978 unsigned long *last_time;
7979
7980 switch (priv->ieee->iw_mode) {
7981 case IW_MODE_ADHOC:
7982 {
7983 struct list_head *p;
7984 struct ipw_ibss_seq *entry = NULL;
7985 u8 *mac = header->addr2;
7986 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
7987
7988 __list_for_each(p, &priv->ibss_mac_hash[index]) {
7989 entry =
7990 list_entry(p, struct ipw_ibss_seq, list);
7991 if (!memcmp(entry->mac, mac, ETH_ALEN))
7992 break;
7993 }
7994 if (p == &priv->ibss_mac_hash[index]) {
7995 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
7996 if (!entry) {
7997 IPW_ERROR
7998 ("Cannot malloc new mac entry\n");
7999 return 0;
8000 }
8001 memcpy(entry->mac, mac, ETH_ALEN);
8002 entry->seq_num = seq;
8003 entry->frag_num = frag;
8004 entry->packet_time = jiffies;
8005 list_add(&entry->list,
8006 &priv->ibss_mac_hash[index]);
8007 return 0;
8008 }
8009 last_seq = &entry->seq_num;
8010 last_frag = &entry->frag_num;
8011 last_time = &entry->packet_time;
8012 break;
8013 }
8014 case IW_MODE_INFRA:
8015 last_seq = &priv->last_seq_num;
8016 last_frag = &priv->last_frag_num;
8017 last_time = &priv->last_packet_time;
8018 break;
8019 default:
8020 return 0;
8021 }
8022 if ((*last_seq == seq) &&
8023 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
8024 if (*last_frag == frag)
8025 goto drop;
8026 if (*last_frag + 1 != frag)
8027 /* out-of-order fragment */
8028 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008029 } else
8030 *last_seq = seq;
8031
Zhu Yif57ce7c2005-07-13 12:22:15 -05008032 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008033 *last_time = jiffies;
8034 return 0;
8035
8036 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08008037 /* Comment this line now since we observed the card receives
8038 * duplicate packets but the FCTL_RETRY bit is not set in the
8039 * IBSS mode with fragmentation enabled.
8040 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008041 return 1;
8042}
8043
James Ketrenosb095c382005-08-24 22:04:42 -05008044static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
8045 struct ipw_rx_mem_buffer *rxb,
8046 struct ieee80211_rx_stats *stats)
8047{
8048 struct sk_buff *skb = rxb->skb;
8049 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
8050 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
8051 (skb->data + IPW_RX_FRAME_SIZE);
8052
8053 ieee80211_rx_mgt(priv->ieee, header, stats);
8054
8055 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
8056 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8057 IEEE80211_STYPE_PROBE_RESP) ||
8058 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
8059 IEEE80211_STYPE_BEACON))) {
8060 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
8061 ipw_add_station(priv, header->addr2);
8062 }
8063
8064 if (priv->config & CFG_NET_STATS) {
8065 IPW_DEBUG_HC("sending stat packet\n");
8066
8067 /* Set the size of the skb to the size of the full
8068 * ipw header and 802.11 frame */
8069 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
8070 IPW_RX_FRAME_SIZE);
8071
8072 /* Advance past the ipw packet header to the 802.11 frame */
8073 skb_pull(skb, IPW_RX_FRAME_SIZE);
8074
8075 /* Push the ieee80211_rx_stats before the 802.11 frame */
8076 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
8077
8078 skb->dev = priv->ieee->dev;
8079
8080 /* Point raw at the ieee80211_stats */
8081 skb->mac.raw = skb->data;
8082
8083 skb->pkt_type = PACKET_OTHERHOST;
8084 skb->protocol = __constant_htons(ETH_P_80211_STATS);
8085 memset(skb->cb, 0, sizeof(rxb->skb->cb));
8086 netif_rx(skb);
8087 rxb->skb = NULL;
8088 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008089}
8090
James Ketrenos43f66a62005-03-25 12:31:53 -06008091/*
8092 * Main entry function for recieving a packet with 80211 headers. This
8093 * should be called when ever the FW has notified us that there is a new
8094 * skb in the recieve queue.
8095 */
8096static void ipw_rx(struct ipw_priv *priv)
8097{
8098 struct ipw_rx_mem_buffer *rxb;
8099 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05008100 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06008101 u32 r, w, i;
8102 u8 network_packet;
8103
James Ketrenosb095c382005-08-24 22:04:42 -05008104 r = ipw_read32(priv, IPW_RX_READ_INDEX);
8105 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
James Ketrenos43f66a62005-03-25 12:31:53 -06008106 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
8107
8108 while (i != r) {
8109 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06008110 if (unlikely(rxb == NULL)) {
8111 printk(KERN_CRIT "Queue not allocated!\n");
8112 break;
8113 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008114 priv->rxq->queue[i] = NULL;
8115
8116 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008117 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06008118 PCI_DMA_FROMDEVICE);
8119
8120 pkt = (struct ipw_rx_packet *)rxb->skb->data;
8121 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
8122 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008123 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06008124
8125 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008126 case RX_FRAME_TYPE: /* 802.11 frame */ {
8127 struct ieee80211_rx_stats stats = {
James Ketrenosc848d0a2005-08-24 21:56:24 -05008128 .rssi =
8129 le16_to_cpu(pkt->u.frame.rssi_dbm) -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008130 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008131 .signal =
Bill Mossb1916082006-02-15 08:50:18 +08008132 le16_to_cpu(pkt->u.frame.rssi_dbm) -
8133 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05008134 .noise =
8135 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008136 .rate = pkt->u.frame.rate,
8137 .mac_time = jiffies,
8138 .received_channel =
8139 pkt->u.frame.received_channel,
8140 .freq =
8141 (pkt->u.frame.
8142 control & (1 << 0)) ?
8143 IEEE80211_24GHZ_BAND :
8144 IEEE80211_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05008145 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008146 };
James Ketrenos43f66a62005-03-25 12:31:53 -06008147
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008148 if (stats.rssi != 0)
8149 stats.mask |= IEEE80211_STATMASK_RSSI;
8150 if (stats.signal != 0)
8151 stats.mask |= IEEE80211_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008152 if (stats.noise != 0)
8153 stats.mask |= IEEE80211_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008154 if (stats.rate != 0)
8155 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06008156
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008157 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06008158
Zhu Yid685b8c2006-04-13 17:20:27 +08008159#ifdef CONFIG_IPW2200_PROMISCUOUS
8160 if (priv->prom_net_dev && netif_running(priv->prom_net_dev))
8161 ipw_handle_promiscuous_rx(priv, rxb, &stats);
8162#endif
8163
James Ketrenosb095c382005-08-24 22:04:42 -05008164#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008165 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08008166#ifdef CONFIG_IPW2200_RADIOTAP
Zhu Yid685b8c2006-04-13 17:20:27 +08008167
8168 ipw_handle_data_packet_monitor(priv,
8169 rxb,
8170 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008171#else
Zhu Yid685b8c2006-04-13 17:20:27 +08008172 ipw_handle_data_packet(priv, rxb,
8173 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05008174#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008175 break;
8176 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008177#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04008178
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008179 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05008180 (struct ieee80211_hdr_4addr *)(rxb->skb->
8181 data +
8182 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008183 /* TODO: Check Ad-Hoc dest/source and make sure
8184 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04008185 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06008186 * frame control of the packet and disregard
8187 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06008188
James Ketrenosea2b26e2005-08-24 21:25:16 -05008189 network_packet =
8190 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008191 if (network_packet && priv->assoc_network) {
8192 priv->assoc_network->stats.rssi =
8193 stats.rssi;
Zhu Yi00d21de2006-04-13 17:19:02 +08008194 priv->exp_avg_rssi =
8195 exponential_average(priv->exp_avg_rssi,
8196 stats.rssi, DEPTH_RSSI);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008197 }
8198
8199 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05008200 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008201
James Ketrenosa613bff2005-08-24 21:43:11 -05008202 if (le16_to_cpu(pkt->u.frame.length) <
Zhu Yi9d0be032006-02-15 06:18:19 +08008203 ieee80211_get_hdrlen(le16_to_cpu(
8204 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008205 IPW_DEBUG_DROP
8206 ("Received packet is too small. "
8207 "Dropping.\n");
8208 priv->ieee->stats.rx_errors++;
8209 priv->wstats.discard.misc++;
8210 break;
8211 }
8212
James Ketrenosa613bff2005-08-24 21:43:11 -05008213 switch (WLAN_FC_GET_TYPE
8214 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05008215
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008216 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05008217 ipw_handle_mgmt_packet(priv, rxb,
8218 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008219 break;
8220
8221 case IEEE80211_FTYPE_CTL:
8222 break;
8223
8224 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05008225 if (unlikely(!network_packet ||
8226 is_duplicate_packet(priv,
8227 header)))
8228 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008229 IPW_DEBUG_DROP("Dropping: "
8230 MAC_FMT ", "
8231 MAC_FMT ", "
8232 MAC_FMT "\n",
8233 MAC_ARG(header->
8234 addr1),
8235 MAC_ARG(header->
8236 addr2),
8237 MAC_ARG(header->
8238 addr3));
James Ketrenosb095c382005-08-24 22:04:42 -05008239 break;
8240 }
8241
8242 ipw_handle_data_packet(priv, rxb,
8243 &stats);
8244
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008245 break;
8246 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008247 break;
8248 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008249
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008250 case RX_HOST_NOTIFICATION_TYPE:{
8251 IPW_DEBUG_RX
8252 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008253 pkt->u.notification.subtype,
8254 pkt->u.notification.flags,
8255 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008256 ipw_rx_notification(priv, &pkt->u.notification);
8257 break;
8258 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008259
8260 default:
8261 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
8262 pkt->header.message_type);
8263 break;
8264 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008265
8266 /* For now we just don't re-use anything. We can tweak this
8267 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06008268 * fail to Rx correctly */
8269 if (rxb->skb != NULL) {
8270 dev_kfree_skb_any(rxb->skb);
8271 rxb->skb = NULL;
8272 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008273
James Ketrenos43f66a62005-03-25 12:31:53 -06008274 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05008275 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06008276 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04008277
James Ketrenos43f66a62005-03-25 12:31:53 -06008278 i = (i + 1) % RX_QUEUE_SIZE;
8279 }
8280
8281 /* Backtrack one entry */
8282 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
8283
8284 ipw_rx_queue_restock(priv);
8285}
8286
James Ketrenosafbf30a2005-08-25 00:05:33 -05008287#define DEFAULT_RTS_THRESHOLD 2304U
8288#define MIN_RTS_THRESHOLD 1U
8289#define MAX_RTS_THRESHOLD 2304U
8290#define DEFAULT_BEACON_INTERVAL 100U
8291#define DEFAULT_SHORT_RETRY_LIMIT 7U
8292#define DEFAULT_LONG_RETRY_LIMIT 4U
8293
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008294/**
8295 * ipw_sw_reset
8296 * @option: options to control different reset behaviour
8297 * 0 = reset everything except the 'disable' module_param
8298 * 1 = reset everything and print out driver info (for probe only)
8299 * 2 = reset everything
8300 */
8301static int ipw_sw_reset(struct ipw_priv *priv, int option)
James Ketrenos43f66a62005-03-25 12:31:53 -06008302{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008303 int band, modulation;
8304 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008305
James Ketrenosafbf30a2005-08-25 00:05:33 -05008306 /* Initialize module parameter values here */
8307 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008308
James Ketrenosafbf30a2005-08-25 00:05:33 -05008309 /* We default to disabling the LED code as right now it causes
8310 * too many systems to lock up... */
8311 if (!led)
8312 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008313
James Ketrenosafbf30a2005-08-25 00:05:33 -05008314 if (associate)
8315 priv->config |= CFG_ASSOCIATE;
8316 else
8317 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008318
James Ketrenosafbf30a2005-08-25 00:05:33 -05008319 if (auto_create)
8320 priv->config |= CFG_ADHOC_CREATE;
8321 else
8322 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8323
Zhu Yi17ed0812006-01-24 16:36:31 +08008324 priv->config &= ~CFG_STATIC_ESSID;
8325 priv->essid_len = 0;
8326 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8327
Zhu Yid6d5b5c2006-02-16 16:21:09 +08008328 if (disable && option) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008329 priv->status |= STATUS_RF_KILL_SW;
8330 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008331 }
8332
James Ketrenosafbf30a2005-08-25 00:05:33 -05008333 if (channel != 0) {
8334 priv->config |= CFG_STATIC_CHANNEL;
8335 priv->channel = channel;
8336 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8337 /* TODO: Validate that provided channel is in range */
8338 }
Zhu Yie43e3c12006-04-13 17:20:45 +08008339#ifdef CONFIG_IPW2200_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05008340 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8341 burst_duration_CCK, burst_duration_OFDM);
Zhu Yie43e3c12006-04-13 17:20:45 +08008342#endif /* CONFIG_IPW2200_QOS */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008343
8344 switch (mode) {
8345 case 1:
8346 priv->ieee->iw_mode = IW_MODE_ADHOC;
8347 priv->net_dev->type = ARPHRD_ETHER;
8348
8349 break;
8350#ifdef CONFIG_IPW2200_MONITOR
8351 case 2:
8352 priv->ieee->iw_mode = IW_MODE_MONITOR;
Zhu Yi459d4082006-04-13 17:21:00 +08008353#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008354 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8355#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008356 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008357#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008358 break;
8359#endif
8360 default:
8361 case 0:
8362 priv->net_dev->type = ARPHRD_ETHER;
8363 priv->ieee->iw_mode = IW_MODE_INFRA;
8364 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008365 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008366
James Ketrenosafbf30a2005-08-25 00:05:33 -05008367 if (hwcrypto) {
8368 priv->ieee->host_encrypt = 0;
8369 priv->ieee->host_encrypt_msdu = 0;
8370 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008371 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008372 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008373 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008374
Zhu Yie402c932005-08-05 17:20:40 +08008375 /* IPW2200/2915 is abled to do hardware fragmentation. */
8376 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008377
James Ketrenosafbf30a2005-08-25 00:05:33 -05008378 if ((priv->pci_dev->device == 0x4223) ||
8379 (priv->pci_dev->device == 0x4224)) {
Zhu Yie8c69e22006-02-17 08:25:12 +08008380 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008381 printk(KERN_INFO DRV_NAME
8382 ": Detected Intel PRO/Wireless 2915ABG Network "
8383 "Connection\n");
8384 priv->ieee->abg_true = 1;
8385 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8386 modulation = IEEE80211_OFDM_MODULATION |
8387 IEEE80211_CCK_MODULATION;
8388 priv->adapter = IPW_2915ABG;
8389 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008390 } else {
Zhu Yie8c69e22006-02-17 08:25:12 +08008391 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008392 printk(KERN_INFO DRV_NAME
8393 ": Detected Intel PRO/Wireless 2200BG Network "
8394 "Connection\n");
8395
8396 priv->ieee->abg_true = 0;
8397 band = IEEE80211_24GHZ_BAND;
8398 modulation = IEEE80211_OFDM_MODULATION |
8399 IEEE80211_CCK_MODULATION;
8400 priv->adapter = IPW_2200BG;
8401 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008402 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008403
James Ketrenosafbf30a2005-08-25 00:05:33 -05008404 priv->ieee->freq_band = band;
8405 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008406
James Ketrenosafbf30a2005-08-25 00:05:33 -05008407 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008408
James Ketrenosafbf30a2005-08-25 00:05:33 -05008409 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8410 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008411
James Ketrenosafbf30a2005-08-25 00:05:33 -05008412 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8413 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8414 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008415
James Ketrenosafbf30a2005-08-25 00:05:33 -05008416 /* If power management is turned on, default to AC mode */
8417 priv->power_mode = IPW_POWER_AC;
8418 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008419
Zhu Yi0ece35b2005-08-05 17:26:51 +08008420 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008421}
8422
8423/*
8424 * This file defines the Wireless Extension handlers. It does not
8425 * define any methods of hardware manipulation and relies on the
8426 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008427 *
8428 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008429 * function used to poll the hardware vs. making unecessary calls.
8430 *
8431 */
8432
Jeff Garzikbf794512005-07-31 13:07:26 -04008433static int ipw_wx_get_name(struct net_device *dev,
8434 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008435 union iwreq_data *wrqu, char *extra)
8436{
8437 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008438 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008439 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -05008440 strcpy(wrqu->name, "radio off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008441 else if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06008442 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04008443 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008444 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8445 ipw_modes[priv->assoc_request.ieee_mode]);
8446 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
Zhu Yi46441512006-01-24 16:37:59 +08008447 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008448 return 0;
8449}
8450
8451static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8452{
8453 if (channel == 0) {
8454 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8455 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008456 IPW_DEBUG_ASSOC("Attempting to associate with new "
8457 "parameters.\n");
8458 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008459 return 0;
8460 }
8461
8462 priv->config |= CFG_STATIC_CHANNEL;
8463
8464 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008465 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8466 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008467 return 0;
8468 }
8469
8470 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8471 priv->channel = channel;
8472
James Ketrenosb095c382005-08-24 22:04:42 -05008473#ifdef CONFIG_IPW2200_MONITOR
8474 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008475 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008476 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008477 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008478 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008479 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008480 }
8481
8482 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8483 udelay(10);
8484
8485 if (priv->status & STATUS_SCANNING)
8486 IPW_DEBUG_SCAN("Still scanning...\n");
8487 else
8488 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8489 1000 - i);
8490
8491 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008492 }
James Ketrenosb095c382005-08-24 22:04:42 -05008493#endif /* CONFIG_IPW2200_MONITOR */
8494
James Ketrenosc848d0a2005-08-24 21:56:24 -05008495 /* Network configuration changed -- force [re]association */
8496 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8497 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008498 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008499
8500 return 0;
8501}
8502
Jeff Garzikbf794512005-07-31 13:07:26 -04008503static int ipw_wx_set_freq(struct net_device *dev,
8504 struct iw_request_info *info,
8505 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008506{
8507 struct ipw_priv *priv = ieee80211_priv(dev);
Larry Finger1867b112006-02-28 09:48:28 -06008508 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008509 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008510 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008511 u8 channel, flags;
8512 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008513
James Ketrenosb095c382005-08-24 22:04:42 -05008514 if (fwrq->m == 0) {
8515 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008516 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008517 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008518 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008519 return ret;
8520 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008521 /* if setting by freq convert to channel */
8522 if (fwrq->e == 1) {
Larry Finger1867b112006-02-28 09:48:28 -06008523 channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008524 if (channel == 0)
8525 return -EINVAL;
8526 } else
8527 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008528
Larry Finger1867b112006-02-28 09:48:28 -06008529 if (!(band = ieee80211_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008530 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008531
Liu Hong1fe0adb2005-08-19 09:33:10 -05008532 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
Larry Finger1867b112006-02-28 09:48:28 -06008533 i = ieee80211_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008534 if (i == -1)
8535 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008536
8537 flags = (band == IEEE80211_24GHZ_BAND) ?
8538 geo->bg[i].flags : geo->a[i].flags;
8539 if (flags & IEEE80211_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008540 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8541 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008542 }
8543 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008544
James Ketrenos43f66a62005-03-25 12:31:53 -06008545 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008546 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008547 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008548 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008549 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008550}
8551
Jeff Garzikbf794512005-07-31 13:07:26 -04008552static int ipw_wx_get_freq(struct net_device *dev,
8553 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008554 union iwreq_data *wrqu, char *extra)
8555{
8556 struct ipw_priv *priv = ieee80211_priv(dev);
8557
8558 wrqu->freq.e = 0;
8559
8560 /* If we are associated, trying to associate, or have a statically
8561 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008562 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008563 if (priv->config & CFG_STATIC_CHANNEL ||
Zhu Yic580f672006-08-21 11:37:01 +08008564 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) {
8565 int i;
8566
8567 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
8568 BUG_ON(i == -1);
8569 wrqu->freq.e = 1;
8570
8571 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
8572 case IEEE80211_52GHZ_BAND:
8573 wrqu->freq.m = priv->ieee->geo.a[i].freq * 100000;
8574 break;
8575
8576 case IEEE80211_24GHZ_BAND:
8577 wrqu->freq.m = priv->ieee->geo.bg[i].freq * 100000;
8578 break;
8579
8580 default:
8581 BUG();
8582 }
8583 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06008584 wrqu->freq.m = 0;
8585
Zhu Yi46441512006-01-24 16:37:59 +08008586 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008587 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8588 return 0;
8589}
8590
Jeff Garzikbf794512005-07-31 13:07:26 -04008591static int ipw_wx_set_mode(struct net_device *dev,
8592 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008593 union iwreq_data *wrqu, char *extra)
8594{
8595 struct ipw_priv *priv = ieee80211_priv(dev);
8596 int err = 0;
8597
8598 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8599
James Ketrenos43f66a62005-03-25 12:31:53 -06008600 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008601#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008602 case IW_MODE_MONITOR:
8603#endif
8604 case IW_MODE_ADHOC:
8605 case IW_MODE_INFRA:
8606 break;
8607 case IW_MODE_AUTO:
8608 wrqu->mode = IW_MODE_INFRA;
8609 break;
8610 default:
8611 return -EINVAL;
8612 }
James Ketrenosb095c382005-08-24 22:04:42 -05008613 if (wrqu->mode == priv->ieee->iw_mode)
8614 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008615
Zhu Yi46441512006-01-24 16:37:59 +08008616 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008617
8618 ipw_sw_reset(priv, 0);
8619
James Ketrenosb095c382005-08-24 22:04:42 -05008620#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008621 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008622 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008623
8624 if (wrqu->mode == IW_MODE_MONITOR)
Zhu Yi459d4082006-04-13 17:21:00 +08008625#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05008626 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8627#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008628 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008629#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008630#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008631
Jeff Garzikbf794512005-07-31 13:07:26 -04008632 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06008633 * flag so ipw_load() will bring in the new firmawre */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008634 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008635
8636 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008637
James Ketrenosc848d0a2005-08-24 21:56:24 -05008638 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008639 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008640 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008641}
8642
Jeff Garzikbf794512005-07-31 13:07:26 -04008643static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008644 struct iw_request_info *info,
8645 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008646{
8647 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008648 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008649 wrqu->mode = priv->ieee->iw_mode;
8650 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008651 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008652 return 0;
8653}
8654
James Ketrenos43f66a62005-03-25 12:31:53 -06008655/* Values are in microsecond */
8656static const s32 timeout_duration[] = {
8657 350000,
8658 250000,
8659 75000,
8660 37000,
8661 25000,
8662};
8663
8664static const s32 period_duration[] = {
8665 400000,
8666 700000,
8667 1000000,
8668 1000000,
8669 1000000
8670};
8671
Jeff Garzikbf794512005-07-31 13:07:26 -04008672static int ipw_wx_get_range(struct net_device *dev,
8673 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008674 union iwreq_data *wrqu, char *extra)
8675{
8676 struct ipw_priv *priv = ieee80211_priv(dev);
8677 struct iw_range *range = (struct iw_range *)extra;
Larry Finger1867b112006-02-28 09:48:28 -06008678 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008679 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008680
8681 wrqu->data.length = sizeof(*range);
8682 memset(range, 0, sizeof(*range));
8683
8684 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008685 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008686
8687 range->max_qual.qual = 100;
8688 /* TODO: Find real max RSSI and stick here */
8689 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008690 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008691 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008692
8693 range->avg_qual.qual = 70;
8694 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008695 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008696 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008697 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008698 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008699 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008700
Jeff Garzikbf794512005-07-31 13:07:26 -04008701 for (i = 0; i < range->num_bitrates; i++)
8702 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008703 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008704
James Ketrenos43f66a62005-03-25 12:31:53 -06008705 range->max_rts = DEFAULT_RTS_THRESHOLD;
8706 range->min_frag = MIN_FRAG_THRESHOLD;
8707 range->max_frag = MAX_FRAG_THRESHOLD;
8708
8709 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008710 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008711 range->num_encoding_sizes = 2;
8712 range->max_encoding_tokens = WEP_KEYS;
8713
8714 /* Set the Wireless Extension versions */
8715 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008716 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008717
James Ketrenosb095c382005-08-24 22:04:42 -05008718 i = 0;
8719 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
Zhu Yie815de42006-03-02 05:55:51 +08008720 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8721 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8722 (geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8723 continue;
8724
James Ketrenosb095c382005-08-24 22:04:42 -05008725 range->freq[i].i = geo->bg[j].channel;
8726 range->freq[i].m = geo->bg[j].freq * 100000;
8727 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008728 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008729 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008730 }
James Ketrenosb095c382005-08-24 22:04:42 -05008731
8732 if (priv->ieee->mode & IEEE_A) {
Zhu Yie815de42006-03-02 05:55:51 +08008733 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8734 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8735 (geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8736 continue;
8737
James Ketrenosb095c382005-08-24 22:04:42 -05008738 range->freq[i].i = geo->a[j].channel;
8739 range->freq[i].m = geo->a[j].freq * 100000;
8740 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008741 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008742 }
8743 }
8744
8745 range->num_channels = i;
8746 range->num_frequency = i;
8747
Zhu Yi46441512006-01-24 16:37:59 +08008748 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008749
8750 /* Event capability (kernel + driver) */
8751 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8752 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
Zhu Yi07f02e42006-04-13 17:19:25 +08008753 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
8754 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008755 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008756
Dan Williamsf1b50862006-01-30 13:58:56 -05008757 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8758 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8759
James Ketrenos43f66a62005-03-25 12:31:53 -06008760 IPW_DEBUG_WX("GET Range\n");
8761 return 0;
8762}
8763
Jeff Garzikbf794512005-07-31 13:07:26 -04008764static int ipw_wx_set_wap(struct net_device *dev,
8765 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008766 union iwreq_data *wrqu, char *extra)
8767{
8768 struct ipw_priv *priv = ieee80211_priv(dev);
8769
8770 static const unsigned char any[] = {
8771 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8772 };
8773 static const unsigned char off[] = {
8774 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8775 };
8776
Jeff Garzikbf794512005-07-31 13:07:26 -04008777 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06008778 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08008779 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008780 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8781 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8782 /* we disable mandatory BSSID association */
8783 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8784 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008785 IPW_DEBUG_ASSOC("Attempting to associate with new "
8786 "parameters.\n");
8787 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08008788 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008789 return 0;
8790 }
8791
8792 priv->config |= CFG_STATIC_BSSID;
8793 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8794 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008795 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008796 return 0;
8797 }
8798
8799 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8800 MAC_ARG(wrqu->ap_addr.sa_data));
8801
8802 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8803
James Ketrenosc848d0a2005-08-24 21:56:24 -05008804 /* Network configuration changed -- force [re]association */
8805 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8806 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008807 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008808
Zhu Yi46441512006-01-24 16:37:59 +08008809 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008810 return 0;
8811}
8812
Jeff Garzikbf794512005-07-31 13:07:26 -04008813static int ipw_wx_get_wap(struct net_device *dev,
8814 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008815 union iwreq_data *wrqu, char *extra)
8816{
8817 struct ipw_priv *priv = ieee80211_priv(dev);
8818 /* If we are associated, trying to associate, or have a statically
8819 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008820 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04008821 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06008822 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8823 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008824 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06008825 } else
8826 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8827
8828 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8829 MAC_ARG(wrqu->ap_addr.sa_data));
Zhu Yi46441512006-01-24 16:37:59 +08008830 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008831 return 0;
8832}
8833
Jeff Garzikbf794512005-07-31 13:07:26 -04008834static int ipw_wx_set_essid(struct net_device *dev,
8835 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008836 union iwreq_data *wrqu, char *extra)
8837{
8838 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yiab644b02006-08-21 11:37:13 +08008839 int length;
James Ketrenos43f66a62005-03-25 12:31:53 -06008840
Zhu Yiab644b02006-08-21 11:37:13 +08008841 mutex_lock(&priv->mutex);
8842
8843 if (!wrqu->essid.flags)
8844 {
8845 IPW_DEBUG_WX("Setting ESSID to ANY\n");
8846 ipw_disassociate(priv);
8847 priv->config &= ~CFG_STATIC_ESSID;
8848 ipw_associate(priv);
8849 mutex_unlock(&priv->mutex);
8850 return 0;
8851 }
8852
Zhu Yia9f0d422006-08-21 11:37:26 +08008853 length = min((int)wrqu->essid.length, IW_ESSID_MAX_SIZE);
8854 if (!extra[length - 1])
8855 length--;
James Ketrenos43f66a62005-03-25 12:31:53 -06008856
8857 priv->config |= CFG_STATIC_ESSID;
8858
Zhu Yia9f0d422006-08-21 11:37:26 +08008859 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)
8860 && (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06008861 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008862 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008863 return 0;
8864 }
8865
Zhu Yiab644b02006-08-21 11:37:13 +08008866 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(extra, length),
James Ketrenos43f66a62005-03-25 12:31:53 -06008867 length);
8868
8869 priv->essid_len = length;
Zhu Yia9f0d422006-08-21 11:37:26 +08008870 memcpy(priv->essid, extra, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04008871
James Ketrenosc848d0a2005-08-24 21:56:24 -05008872 /* Network configuration changed -- force [re]association */
8873 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8874 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008875 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008876
Zhu Yi46441512006-01-24 16:37:59 +08008877 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008878 return 0;
8879}
8880
Jeff Garzikbf794512005-07-31 13:07:26 -04008881static int ipw_wx_get_essid(struct net_device *dev,
8882 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008883 union iwreq_data *wrqu, char *extra)
8884{
8885 struct ipw_priv *priv = ieee80211_priv(dev);
8886
8887 /* If we are associated, trying to associate, or have a statically
8888 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008889 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008890 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04008891 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8892 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008893 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04008894 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06008895 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008896 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008897 } else {
8898 IPW_DEBUG_WX("Getting essid: ANY\n");
8899 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008900 wrqu->essid.flags = 0; /* active */
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_set_nick(struct net_device *dev,
8907 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008908 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008909{
James Ketrenos43f66a62005-03-25 12:31:53 -06008910 struct ipw_priv *priv = ieee80211_priv(dev);
8911
8912 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8913 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8914 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08008915 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008916 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06008917 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008918 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06008919 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08008920 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008921 return 0;
8922
8923}
8924
Jeff Garzikbf794512005-07-31 13:07:26 -04008925static int ipw_wx_get_nick(struct net_device *dev,
8926 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008927 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008928{
James Ketrenos43f66a62005-03-25 12:31:53 -06008929 struct ipw_priv *priv = ieee80211_priv(dev);
8930 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08008931 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008932 wrqu->data.length = strlen(priv->nick) + 1;
8933 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008934 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08008935 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008936 return 0;
8937}
8938
Olivier Hochreutiner651be262006-03-08 03:13:55 +08008939static int ipw_wx_set_sens(struct net_device *dev,
8940 struct iw_request_info *info,
8941 union iwreq_data *wrqu, char *extra)
8942{
8943 struct ipw_priv *priv = ieee80211_priv(dev);
8944 int err = 0;
8945
8946 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
8947 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
8948 mutex_lock(&priv->mutex);
8949
8950 if (wrqu->sens.fixed == 0)
8951 {
8952 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8953 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8954 goto out;
8955 }
8956 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
8957 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
8958 err = -EINVAL;
8959 goto out;
8960 }
8961
8962 priv->roaming_threshold = wrqu->sens.value;
8963 priv->disassociate_threshold = 3*wrqu->sens.value;
8964 out:
8965 mutex_unlock(&priv->mutex);
8966 return err;
8967}
8968
8969static int ipw_wx_get_sens(struct net_device *dev,
8970 struct iw_request_info *info,
8971 union iwreq_data *wrqu, char *extra)
8972{
8973 struct ipw_priv *priv = ieee80211_priv(dev);
8974 mutex_lock(&priv->mutex);
8975 wrqu->sens.fixed = 1;
8976 wrqu->sens.value = priv->roaming_threshold;
8977 mutex_unlock(&priv->mutex);
8978
8979 IPW_DEBUG_WX("GET roaming threshold -> %s %d \n",
8980 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
8981
8982 return 0;
8983}
8984
James Ketrenos43f66a62005-03-25 12:31:53 -06008985static int ipw_wx_set_rate(struct net_device *dev,
8986 struct iw_request_info *info,
8987 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008988{
James Ketrenosea2b26e2005-08-24 21:25:16 -05008989 /* TODO: We should use semaphores or locks for access to priv */
8990 struct ipw_priv *priv = ieee80211_priv(dev);
8991 u32 target_rate = wrqu->bitrate.value;
8992 u32 fixed, mask;
8993
8994 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8995 /* value = X, fixed = 1 means only rate X */
8996 /* value = X, fixed = 0 means all rates lower equal X */
8997
8998 if (target_rate == -1) {
8999 fixed = 0;
9000 mask = IEEE80211_DEFAULT_RATES_MASK;
9001 /* Now we should reassociate */
9002 goto apply;
9003 }
9004
9005 mask = 0;
9006 fixed = wrqu->bitrate.fixed;
9007
9008 if (target_rate == 1000000 || !fixed)
9009 mask |= IEEE80211_CCK_RATE_1MB_MASK;
9010 if (target_rate == 1000000)
9011 goto apply;
9012
9013 if (target_rate == 2000000 || !fixed)
9014 mask |= IEEE80211_CCK_RATE_2MB_MASK;
9015 if (target_rate == 2000000)
9016 goto apply;
9017
9018 if (target_rate == 5500000 || !fixed)
9019 mask |= IEEE80211_CCK_RATE_5MB_MASK;
9020 if (target_rate == 5500000)
9021 goto apply;
9022
9023 if (target_rate == 6000000 || !fixed)
9024 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
9025 if (target_rate == 6000000)
9026 goto apply;
9027
9028 if (target_rate == 9000000 || !fixed)
9029 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
9030 if (target_rate == 9000000)
9031 goto apply;
9032
9033 if (target_rate == 11000000 || !fixed)
9034 mask |= IEEE80211_CCK_RATE_11MB_MASK;
9035 if (target_rate == 11000000)
9036 goto apply;
9037
9038 if (target_rate == 12000000 || !fixed)
9039 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
9040 if (target_rate == 12000000)
9041 goto apply;
9042
9043 if (target_rate == 18000000 || !fixed)
9044 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
9045 if (target_rate == 18000000)
9046 goto apply;
9047
9048 if (target_rate == 24000000 || !fixed)
9049 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
9050 if (target_rate == 24000000)
9051 goto apply;
9052
9053 if (target_rate == 36000000 || !fixed)
9054 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
9055 if (target_rate == 36000000)
9056 goto apply;
9057
9058 if (target_rate == 48000000 || !fixed)
9059 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
9060 if (target_rate == 48000000)
9061 goto apply;
9062
9063 if (target_rate == 54000000 || !fixed)
9064 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
9065 if (target_rate == 54000000)
9066 goto apply;
9067
9068 IPW_DEBUG_WX("invalid rate specified, returning error\n");
9069 return -EINVAL;
9070
9071 apply:
9072 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
9073 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08009074 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009075 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009076 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05009077 ipw_set_fixed_rate(priv, priv->ieee->mode);
9078 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05009079 priv->config |= CFG_FIXED_RATE;
9080
James Ketrenosc848d0a2005-08-24 21:56:24 -05009081 if (priv->rates_mask == mask) {
9082 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009083 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009084 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009085 }
9086
James Ketrenosc848d0a2005-08-24 21:56:24 -05009087 priv->rates_mask = mask;
9088
9089 /* Network configuration changed -- force [re]association */
9090 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
9091 if (!ipw_disassociate(priv))
9092 ipw_associate(priv);
9093
Zhu Yi46441512006-01-24 16:37:59 +08009094 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009095 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009096}
9097
Jeff Garzikbf794512005-07-31 13:07:26 -04009098static int ipw_wx_get_rate(struct net_device *dev,
9099 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009100 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009101{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009102 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009103 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009104 wrqu->bitrate.value = priv->last_rate;
Zhu Yi455936c2006-04-13 17:20:05 +08009105 wrqu->bitrate.fixed = (priv->config & CFG_FIXED_RATE) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009106 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009107 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
9108 return 0;
9109}
9110
Jeff Garzikbf794512005-07-31 13:07:26 -04009111static int ipw_wx_set_rts(struct net_device *dev,
9112 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009113 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009114{
James Ketrenos43f66a62005-03-25 12:31:53 -06009115 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009116 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009117 if (wrqu->rts.disabled)
9118 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
9119 else {
9120 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05009121 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009122 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009123 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009124 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009125 priv->rts_threshold = wrqu->rts.value;
9126 }
9127
9128 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08009129 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009130 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
9131 return 0;
9132}
9133
Jeff Garzikbf794512005-07-31 13:07:26 -04009134static int ipw_wx_get_rts(struct net_device *dev,
9135 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009136 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009137{
James Ketrenos43f66a62005-03-25 12:31:53 -06009138 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009139 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009140 wrqu->rts.value = priv->rts_threshold;
9141 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009142 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08009143 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009144 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
9145 return 0;
9146}
9147
Jeff Garzikbf794512005-07-31 13:07:26 -04009148static int ipw_wx_set_txpow(struct net_device *dev,
9149 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009150 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009151{
James Ketrenos43f66a62005-03-25 12:31:53 -06009152 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009153 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009154
Zhu Yi46441512006-01-24 16:37:59 +08009155 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009156 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009157 err = -EINPROGRESS;
9158 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009159 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009160
James Ketrenosb095c382005-08-24 22:04:42 -05009161 if (!wrqu->power.fixed)
9162 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06009163
James Ketrenosc848d0a2005-08-24 21:56:24 -05009164 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009165 err = -EINVAL;
9166 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009167 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009168
James Ketrenosb095c382005-08-24 22:04:42 -05009169 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05009170 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009171 err = -EINVAL;
9172 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009173 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009174
9175 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009176 err = ipw_set_tx_power(priv);
9177 out:
Zhu Yi46441512006-01-24 16:37:59 +08009178 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08009179 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009180}
9181
Jeff Garzikbf794512005-07-31 13:07:26 -04009182static int ipw_wx_get_txpow(struct net_device *dev,
9183 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009184 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009185{
James Ketrenos43f66a62005-03-25 12:31:53 -06009186 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009187 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009188 wrqu->power.value = priv->tx_power;
9189 wrqu->power.fixed = 1;
9190 wrqu->power.flags = IW_TXPOW_DBM;
9191 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08009192 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009193
Jeff Garzikbf794512005-07-31 13:07:26 -04009194 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08009195 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06009196
9197 return 0;
9198}
9199
Jeff Garzikbf794512005-07-31 13:07:26 -04009200static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009201 struct iw_request_info *info,
9202 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009203{
9204 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009205 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009206 if (wrqu->frag.disabled)
9207 priv->ieee->fts = DEFAULT_FTS;
9208 else {
9209 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05009210 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08009211 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009212 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05009213 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009214
James Ketrenos43f66a62005-03-25 12:31:53 -06009215 priv->ieee->fts = wrqu->frag.value & ~0x1;
9216 }
9217
9218 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08009219 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009220 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
9221 return 0;
9222}
9223
Jeff Garzikbf794512005-07-31 13:07:26 -04009224static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009225 struct iw_request_info *info,
9226 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009227{
9228 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009229 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009230 wrqu->frag.value = priv->ieee->fts;
9231 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009232 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08009233 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009234 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
9235
9236 return 0;
9237}
9238
Jeff Garzikbf794512005-07-31 13:07:26 -04009239static int ipw_wx_set_retry(struct net_device *dev,
9240 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009241 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009242{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009243 struct ipw_priv *priv = ieee80211_priv(dev);
9244
9245 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
9246 return -EINVAL;
9247
9248 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
9249 return 0;
9250
9251 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
9252 return -EINVAL;
9253
Zhu Yi46441512006-01-24 16:37:59 +08009254 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009255 if (wrqu->retry.flags & IW_RETRY_MIN)
9256 priv->short_retry_limit = (u8) wrqu->retry.value;
9257 else if (wrqu->retry.flags & IW_RETRY_MAX)
9258 priv->long_retry_limit = (u8) wrqu->retry.value;
9259 else {
9260 priv->short_retry_limit = (u8) wrqu->retry.value;
9261 priv->long_retry_limit = (u8) wrqu->retry.value;
9262 }
9263
9264 ipw_send_retry_limit(priv, priv->short_retry_limit,
9265 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08009266 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009267 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
9268 priv->short_retry_limit, priv->long_retry_limit);
9269 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009270}
9271
Jeff Garzikbf794512005-07-31 13:07:26 -04009272static int ipw_wx_get_retry(struct net_device *dev,
9273 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009274 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009275{
James Ketrenosafbf30a2005-08-25 00:05:33 -05009276 struct ipw_priv *priv = ieee80211_priv(dev);
9277
Zhu Yi46441512006-01-24 16:37:59 +08009278 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009279 wrqu->retry.disabled = 0;
9280
9281 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08009282 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009283 return -EINVAL;
9284 }
9285
9286 if (wrqu->retry.flags & IW_RETRY_MAX) {
9287 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
9288 wrqu->retry.value = priv->long_retry_limit;
9289 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
9290 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
9291 wrqu->retry.value = priv->short_retry_limit;
9292 } else {
9293 wrqu->retry.flags = IW_RETRY_LIMIT;
9294 wrqu->retry.value = priv->short_retry_limit;
9295 }
Zhu Yi46441512006-01-24 16:37:59 +08009296 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009297
9298 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
9299
9300 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009301}
9302
James Ketrenosafbf30a2005-08-25 00:05:33 -05009303static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
9304 int essid_len)
9305{
9306 struct ipw_scan_request_ext scan;
9307 int err = 0, scan_type;
9308
Pekka Enbergefb34422005-11-16 21:55:05 +02009309 if (!(priv->status & STATUS_INIT) ||
9310 (priv->status & STATUS_EXIT_PENDING))
9311 return 0;
9312
Zhu Yi46441512006-01-24 16:37:59 +08009313 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009314
9315 if (priv->status & STATUS_RF_KILL_MASK) {
9316 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
9317 priv->status |= STATUS_SCAN_PENDING;
9318 goto done;
9319 }
9320
9321 IPW_DEBUG_HC("starting request direct scan!\n");
9322
9323 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
Olaf Kirchd834a412006-01-09 17:00:37 +01009324 /* We should not sleep here; otherwise we will block most
9325 * of the system (for instance, we hold rtnl_lock when we
9326 * get here).
9327 */
9328 err = -EAGAIN;
9329 goto done;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009330 }
9331 memset(&scan, 0, sizeof(scan));
9332
9333 if (priv->config & CFG_SPEED_SCAN)
9334 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9335 cpu_to_le16(30);
9336 else
9337 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
9338 cpu_to_le16(20);
9339
9340 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
9341 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05009342 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009343 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
9344
9345 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
9346
9347 err = ipw_send_ssid(priv, essid, essid_len);
9348 if (err) {
9349 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
9350 goto done;
9351 }
9352 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
9353
9354 ipw_add_scan_channels(priv, &scan, scan_type);
9355
9356 err = ipw_send_scan_request_ext(priv, &scan);
9357 if (err) {
9358 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
9359 goto done;
9360 }
9361
9362 priv->status |= STATUS_SCANNING;
9363
9364 done:
Zhu Yi46441512006-01-24 16:37:59 +08009365 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009366 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009367}
9368
Jeff Garzikbf794512005-07-31 13:07:26 -04009369static int ipw_wx_set_scan(struct net_device *dev,
9370 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009371 union iwreq_data *wrqu, char *extra)
9372{
9373 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009374 struct iw_scan_req *req = NULL;
9375 if (wrqu->data.length
9376 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9377 req = (struct iw_scan_req *)extra;
9378 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9379 ipw_request_direct_scan(priv, req->essid,
9380 req->essid_len);
9381 return 0;
9382 }
9383 }
James Ketrenos8935f392005-10-05 15:59:08 -05009384
James Ketrenos43f66a62005-03-25 12:31:53 -06009385 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009386
9387 queue_work(priv->workqueue, &priv->request_scan);
9388
James Ketrenos43f66a62005-03-25 12:31:53 -06009389 return 0;
9390}
9391
Jeff Garzikbf794512005-07-31 13:07:26 -04009392static int ipw_wx_get_scan(struct net_device *dev,
9393 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009394 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009395{
James Ketrenos43f66a62005-03-25 12:31:53 -06009396 struct ipw_priv *priv = ieee80211_priv(dev);
9397 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9398}
9399
Jeff Garzikbf794512005-07-31 13:07:26 -04009400static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009401 struct iw_request_info *info,
9402 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009403{
9404 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009405 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009406 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009407
Zhu Yi46441512006-01-24 16:37:59 +08009408 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009409 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009410
Hong Liucaeff812005-08-05 17:25:50 +08009411 /* In IBSS mode, we need to notify the firmware to update
9412 * the beacon info after we changed the capability. */
9413 if (cap != priv->capability &&
9414 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9415 priv->status & STATUS_ASSOCIATED)
9416 ipw_disassociate(priv);
9417
Zhu Yi46441512006-01-24 16:37:59 +08009418 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009419 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009420}
9421
Jeff Garzikbf794512005-07-31 13:07:26 -04009422static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009423 struct iw_request_info *info,
9424 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009425{
9426 struct ipw_priv *priv = ieee80211_priv(dev);
9427 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9428}
9429
Jeff Garzikbf794512005-07-31 13:07:26 -04009430static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009431 struct iw_request_info *info,
9432 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009433{
9434 struct ipw_priv *priv = ieee80211_priv(dev);
9435 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009436 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009437 if (wrqu->power.disabled) {
9438 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9439 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9440 if (err) {
9441 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009442 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009443 return err;
9444 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009445 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009446 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009447 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009448 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009449
9450 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009451 case IW_POWER_ON: /* If not specified */
9452 case IW_POWER_MODE: /* If set all mask */
9453 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009454 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009455 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009456 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9457 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009458 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009459 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009460 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009461
James Ketrenos43f66a62005-03-25 12:31:53 -06009462 /* If the user hasn't specified a power management mode yet, default
9463 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009464 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009465 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009466 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009467 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9468 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9469 if (err) {
9470 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009471 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009472 return err;
9473 }
9474
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009475 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009476 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009477 return 0;
9478}
9479
Jeff Garzikbf794512005-07-31 13:07:26 -04009480static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009481 struct iw_request_info *info,
9482 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009483{
9484 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009485 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009486 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009487 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009488 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009489 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009490
Zhu Yi46441512006-01-24 16:37:59 +08009491 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009492 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009493
James Ketrenos43f66a62005-03-25 12:31:53 -06009494 return 0;
9495}
9496
Jeff Garzikbf794512005-07-31 13:07:26 -04009497static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009498 struct iw_request_info *info,
9499 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009500{
9501 struct ipw_priv *priv = ieee80211_priv(dev);
9502 int mode = *(int *)extra;
9503 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009504 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009505 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9506 mode = IPW_POWER_AC;
9507 priv->power_mode = mode;
9508 } else {
9509 priv->power_mode = IPW_POWER_ENABLED | mode;
9510 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009511
James Ketrenos43f66a62005-03-25 12:31:53 -06009512 if (priv->power_mode != mode) {
9513 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009514
James Ketrenos43f66a62005-03-25 12:31:53 -06009515 if (err) {
9516 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009517 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009518 return err;
9519 }
9520 }
Zhu Yi46441512006-01-24 16:37:59 +08009521 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009522 return 0;
9523}
9524
9525#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009526static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009527 struct iw_request_info *info,
9528 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009529{
9530 struct ipw_priv *priv = ieee80211_priv(dev);
9531 int level = IPW_POWER_LEVEL(priv->power_mode);
9532 char *p = extra;
9533
9534 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9535
9536 switch (level) {
9537 case IPW_POWER_AC:
9538 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9539 break;
9540 case IPW_POWER_BATTERY:
9541 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9542 break;
9543 default:
9544 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009545 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009546 timeout_duration[level - 1] / 1000,
9547 period_duration[level - 1] / 1000);
9548 }
9549
9550 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009551 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009552
9553 wrqu->data.length = p - extra + 1;
9554
9555 return 0;
9556}
9557
9558static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009559 struct iw_request_info *info,
9560 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009561{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009562 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009563 int mode = *(int *)extra;
9564 u8 band = 0, modulation = 0;
9565
9566 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009567 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009568 return -EINVAL;
9569 }
Zhu Yi46441512006-01-24 16:37:59 +08009570 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009571 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009572 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009573 if (mode & IEEE_A) {
9574 band |= IEEE80211_52GHZ_BAND;
9575 modulation |= IEEE80211_OFDM_MODULATION;
9576 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009577 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009578 } else {
9579 if (mode & IEEE_A) {
9580 IPW_WARNING("Attempt to set 2200BG into "
9581 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009582 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009583 return -EINVAL;
9584 }
9585
James Ketrenosa33a1982005-09-14 14:28:59 -05009586 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009587 }
9588
9589 if (mode & IEEE_B) {
9590 band |= IEEE80211_24GHZ_BAND;
9591 modulation |= IEEE80211_CCK_MODULATION;
9592 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009593 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009594
James Ketrenos43f66a62005-03-25 12:31:53 -06009595 if (mode & IEEE_G) {
9596 band |= IEEE80211_24GHZ_BAND;
9597 modulation |= IEEE80211_OFDM_MODULATION;
9598 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009599 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009600
9601 priv->ieee->mode = mode;
9602 priv->ieee->freq_band = band;
9603 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009604 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009605
James Ketrenosc848d0a2005-08-24 21:56:24 -05009606 /* Network configuration changed -- force [re]association */
9607 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9608 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009609 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009610 ipw_associate(priv);
9611 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009612
James Ketrenosa613bff2005-08-24 21:43:11 -05009613 /* Update the band LEDs */
9614 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009615
Jeff Garzikbf794512005-07-31 13:07:26 -04009616 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009617 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009618 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009619 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009620 return 0;
9621}
9622
9623static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009624 struct iw_request_info *info,
9625 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009626{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009627 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009628 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009629 switch (priv->ieee->mode) {
9630 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009631 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9632 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009633 case IEEE_B:
9634 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9635 break;
9636 case IEEE_A | IEEE_B:
9637 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9638 break;
9639 case IEEE_G:
9640 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9641 break;
9642 case IEEE_A | IEEE_G:
9643 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9644 break;
9645 case IEEE_B | IEEE_G:
9646 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9647 break;
9648 case IEEE_A | IEEE_B | IEEE_G:
9649 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9650 break;
9651 default:
9652 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009653 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009654 }
9655
James Ketrenos43f66a62005-03-25 12:31:53 -06009656 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9657
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009658 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009659 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009660
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009661 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009662}
9663
James Ketrenosea2b26e2005-08-24 21:25:16 -05009664static int ipw_wx_set_preamble(struct net_device *dev,
9665 struct iw_request_info *info,
9666 union iwreq_data *wrqu, char *extra)
9667{
9668 struct ipw_priv *priv = ieee80211_priv(dev);
9669 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009670 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009671 /* Switching from SHORT -> LONG requires a disassociation */
9672 if (mode == 1) {
9673 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9674 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009675
9676 /* Network configuration changed -- force [re]association */
9677 IPW_DEBUG_ASSOC
9678 ("[re]association triggered due to preamble change.\n");
9679 if (!ipw_disassociate(priv))
9680 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009681 }
9682 goto done;
9683 }
9684
9685 if (mode == 0) {
9686 priv->config &= ~CFG_PREAMBLE_LONG;
9687 goto done;
9688 }
Zhu Yi46441512006-01-24 16:37:59 +08009689 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009690 return -EINVAL;
9691
9692 done:
Zhu Yi46441512006-01-24 16:37:59 +08009693 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009694 return 0;
9695}
9696
9697static int ipw_wx_get_preamble(struct net_device *dev,
9698 struct iw_request_info *info,
9699 union iwreq_data *wrqu, char *extra)
9700{
9701 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009702 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009703 if (priv->config & CFG_PREAMBLE_LONG)
9704 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9705 else
9706 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009707 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009708 return 0;
9709}
9710
James Ketrenosb095c382005-08-24 22:04:42 -05009711#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009712static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009713 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009714 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009715{
James Ketrenos43f66a62005-03-25 12:31:53 -06009716 struct ipw_priv *priv = ieee80211_priv(dev);
9717 int *parms = (int *)extra;
9718 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009719 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009720 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009721 if (enable) {
9722 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi459d4082006-04-13 17:21:00 +08009723#ifdef CONFIG_IPW2200_RADIOTAP
Mike Kershaw24a47db2005-08-26 00:41:54 -05009724 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9725#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009726 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009727#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009728 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009729 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009730
James Ketrenos43f66a62005-03-25 12:31:53 -06009731 ipw_set_channel(priv, parms[1]);
9732 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009733 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009734 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009735 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009736 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009737 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009738 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009739 }
Zhu Yi46441512006-01-24 16:37:59 +08009740 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009741 return 0;
9742}
9743
Pavel Machek67fd6b42006-07-11 15:34:05 +02009744#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenosb095c382005-08-24 22:04:42 -05009745
Jeff Garzikbf794512005-07-31 13:07:26 -04009746static int ipw_wx_reset(struct net_device *dev,
9747 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009748 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009749{
James Ketrenos43f66a62005-03-25 12:31:53 -06009750 struct ipw_priv *priv = ieee80211_priv(dev);
9751 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009752 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009753 return 0;
9754}
James Ketrenosb095c382005-08-24 22:04:42 -05009755
James Ketrenosb095c382005-08-24 22:04:42 -05009756static int ipw_wx_sw_reset(struct net_device *dev,
9757 struct iw_request_info *info,
9758 union iwreq_data *wrqu, char *extra)
9759{
9760 struct ipw_priv *priv = ieee80211_priv(dev);
9761 union iwreq_data wrqu_sec = {
9762 .encoding = {
9763 .flags = IW_ENCODE_DISABLED,
9764 },
9765 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009766 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009767
9768 IPW_DEBUG_WX("SW_RESET\n");
9769
Zhu Yi46441512006-01-24 16:37:59 +08009770 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009771
Zhu Yid6d5b5c2006-02-16 16:21:09 +08009772 ret = ipw_sw_reset(priv, 2);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009773 if (!ret) {
9774 free_firmware();
9775 ipw_adapter_restart(priv);
9776 }
James Ketrenosb095c382005-08-24 22:04:42 -05009777
9778 /* The SW reset bit might have been toggled on by the 'disable'
9779 * module parameter, so take appropriate action */
9780 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9781
Zhu Yi46441512006-01-24 16:37:59 +08009782 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009783 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009784 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009785
9786 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9787 /* Configuration likely changed -- force [re]association */
9788 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9789 "reset.\n");
9790 if (!ipw_disassociate(priv))
9791 ipw_associate(priv);
9792 }
9793
Zhu Yi46441512006-01-24 16:37:59 +08009794 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009795
9796 return 0;
9797}
James Ketrenos43f66a62005-03-25 12:31:53 -06009798
9799/* Rebase the WE IOCTLs to zero for the handler array */
9800#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009801static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009802 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9803 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9804 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9805 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9806 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009807 IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens,
9808 IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009809 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9810 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9811 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9812 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9813 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9814 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9815 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9816 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9817 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9818 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9819 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9820 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9821 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9822 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9823 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9824 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9825 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9826 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9827 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9828 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9829 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9830 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9831 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -05009832 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9833 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9834 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9835 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -05009836 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9837 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9838 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9839 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9840 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9841 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9842 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
James Ketrenos43f66a62005-03-25 12:31:53 -06009843};
9844
James Ketrenosb095c382005-08-24 22:04:42 -05009845enum {
9846 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9847 IPW_PRIV_GET_POWER,
9848 IPW_PRIV_SET_MODE,
9849 IPW_PRIV_GET_MODE,
9850 IPW_PRIV_SET_PREAMBLE,
9851 IPW_PRIV_GET_PREAMBLE,
9852 IPW_PRIV_RESET,
9853 IPW_PRIV_SW_RESET,
9854#ifdef CONFIG_IPW2200_MONITOR
9855 IPW_PRIV_SET_MONITOR,
9856#endif
9857};
James Ketrenos43f66a62005-03-25 12:31:53 -06009858
Jeff Garzikbf794512005-07-31 13:07:26 -04009859static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06009860 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009861 .cmd = IPW_PRIV_SET_POWER,
9862 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9863 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009864 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009865 .cmd = IPW_PRIV_GET_POWER,
9866 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9867 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009868 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009869 .cmd = IPW_PRIV_SET_MODE,
9870 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9871 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009872 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009873 .cmd = IPW_PRIV_GET_MODE,
9874 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9875 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009876 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009877 .cmd = IPW_PRIV_SET_PREAMBLE,
9878 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9879 .name = "set_preamble"},
9880 {
9881 .cmd = IPW_PRIV_GET_PREAMBLE,
9882 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9883 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009884 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009885 IPW_PRIV_RESET,
9886 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -05009887 {
9888 IPW_PRIV_SW_RESET,
9889 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9890#ifdef CONFIG_IPW2200_MONITOR
9891 {
9892 IPW_PRIV_SET_MONITOR,
9893 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9894#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06009895};
9896
9897static iw_handler ipw_priv_handler[] = {
9898 ipw_wx_set_powermode,
9899 ipw_wx_get_powermode,
9900 ipw_wx_set_wireless_mode,
9901 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009902 ipw_wx_set_preamble,
9903 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -04009904 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -05009905 ipw_wx_sw_reset,
9906#ifdef CONFIG_IPW2200_MONITOR
9907 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -06009908#endif
9909};
9910
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009911static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009912 .standard = ipw_wx_handlers,
9913 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9914 .num_private = ARRAY_SIZE(ipw_priv_handler),
9915 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9916 .private = ipw_priv_handler,
9917 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009918 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06009919};
9920
James Ketrenos43f66a62005-03-25 12:31:53 -06009921/*
9922 * Get wireless statistics.
9923 * Called by /proc/net/wireless
9924 * Also called by SIOCGIWSTATS
9925 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009926static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06009927{
9928 struct ipw_priv *priv = ieee80211_priv(dev);
9929 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009930
James Ketrenos43f66a62005-03-25 12:31:53 -06009931 wstats = &priv->wstats;
9932
James Ketrenosea2b26e2005-08-24 21:25:16 -05009933 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -05009934 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06009935 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9936 * and associated; if not associcated, the values are all meaningless
9937 * anyway, so set them all to NULL and INVALID */
9938 if (!(priv->status & STATUS_ASSOCIATED)) {
9939 wstats->miss.beacon = 0;
9940 wstats->discard.retries = 0;
9941 wstats->qual.qual = 0;
9942 wstats->qual.level = 0;
9943 wstats->qual.noise = 0;
9944 wstats->qual.updated = 7;
9945 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009946 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06009947 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009948 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009949
9950 wstats->qual.qual = priv->quality;
Zhu Yi00d21de2006-04-13 17:19:02 +08009951 wstats->qual.level = priv->exp_avg_rssi;
9952 wstats->qual.noise = priv->exp_avg_noise;
James Ketrenos43f66a62005-03-25 12:31:53 -06009953 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +08009954 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009955
9956 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9957 wstats->discard.retries = priv->last_tx_failures;
9958 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04009959
James Ketrenos43f66a62005-03-25 12:31:53 -06009960/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9961 goto fail_get_ordinal;
9962 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04009963
James Ketrenos43f66a62005-03-25 12:31:53 -06009964 return wstats;
9965}
9966
James Ketrenos43f66a62005-03-25 12:31:53 -06009967/* net device stuff */
9968
Arjan van de Ven858119e2006-01-14 13:20:43 -08009969static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -06009970{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009971 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +08009972 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009973 sys_config->answer_broadcast_ssid_probe = 0;
9974 sys_config->accept_all_data_frames = 0;
9975 sys_config->accept_non_directed_frames = 1;
9976 sys_config->exclude_unicast_unencrypted = 0;
9977 sys_config->disable_unicast_decryption = 1;
9978 sys_config->exclude_multicast_unencrypted = 0;
9979 sys_config->disable_multicast_decryption = 1;
Zhu Yid2b83e12006-04-13 17:19:36 +08009980 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
9981 antenna = CFG_SYS_ANTENNA_BOTH;
9982 sys_config->antenna_diversity = antenna;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009983 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -06009984 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009985 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009986 sys_config->bt_coexist_collision_thr = 0;
Pavel Machek67fd6b42006-07-11 15:34:05 +02009987 sys_config->pass_noise_stats_to_host = 1; /* 1 -- fix for 256 */
Cahill, Ben M12977152006-03-08 02:58:02 +08009988 sys_config->silence_threshold = 0x1e;
James Ketrenos43f66a62005-03-25 12:31:53 -06009989}
9990
9991static int ipw_net_open(struct net_device *dev)
9992{
9993 struct ipw_priv *priv = ieee80211_priv(dev);
9994 IPW_DEBUG_INFO("dev->open\n");
9995 /* we should be verifying the device is ready to be opened */
Zhu Yi46441512006-01-24 16:37:59 +08009996 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009997 if (!(priv->status & STATUS_RF_KILL_MASK) &&
9998 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009999 netif_start_queue(dev);
Zhu Yi46441512006-01-24 16:37:59 +080010000 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010001 return 0;
10002}
10003
10004static int ipw_net_stop(struct net_device *dev)
10005{
10006 IPW_DEBUG_INFO("dev->close\n");
10007 netif_stop_queue(dev);
10008 return 0;
10009}
10010
10011/*
10012todo:
10013
10014modify to send one tfd per fragment instead of using chunking. otherwise
10015we need to heavily modify the ieee80211_skb_to_txb.
10016*/
10017
Arjan van de Ven858119e2006-01-14 13:20:43 -080010018static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -050010019 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010020{
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010021 struct ieee80211_hdr_3addrqos *hdr = (struct ieee80211_hdr_3addrqos *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010022 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -060010023 int i = 0;
10024 struct tfd_frame *tfd;
Zhu Yie43e3c12006-04-13 17:20:45 +080010025#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010026 int tx_id = ipw_get_tx_queue_number(priv, pri);
10027 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10028#else
James Ketrenos43f66a62005-03-25 12:31:53 -060010029 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -050010030#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060010031 struct clx2_queue *q = &txq->q;
10032 u8 id, hdr_len, unicast;
10033 u16 remaining_bytes;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010034 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -060010035
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010036 hdr_len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
James Ketrenos43f66a62005-03-25 12:31:53 -060010037 switch (priv->ieee->iw_mode) {
10038 case IW_MODE_ADHOC:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010039 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010040 id = ipw_find_station(priv, hdr->addr1);
10041 if (id == IPW_INVALID_STATION) {
10042 id = ipw_add_station(priv, hdr->addr1);
10043 if (id == IPW_INVALID_STATION) {
10044 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -040010045 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010046 MAC_ARG(hdr->addr1));
10047 goto drop;
10048 }
10049 }
10050 break;
10051
10052 case IW_MODE_INFRA:
10053 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -080010054 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -060010055 id = 0;
10056 break;
10057 }
10058
10059 tfd = &txq->bd[q->first_empty];
10060 txq->txb[q->first_empty] = txb;
10061 memset(tfd, 0, sizeof(*tfd));
10062 tfd->u.data.station_number = id;
10063
10064 tfd->control_flags.message_type = TX_FRAME_TYPE;
10065 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
10066
10067 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -050010068 tfd->u.data.len = cpu_to_le16(txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010069 remaining_bytes = txb->payload_size;
Jeff Garzikbf794512005-07-31 13:07:26 -040010070
James Ketrenos43f66a62005-03-25 12:31:53 -060010071 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -050010072 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010073 else
James Ketrenosb095c382005-08-24 22:04:42 -050010074 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -060010075
James Ketrenosea2b26e2005-08-24 21:25:16 -050010076 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
10077 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010078
James Ketrenosc848d0a2005-08-24 21:56:24 -050010079 fc = le16_to_cpu(hdr->frame_ctl);
10080 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -060010081
10082 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
10083
James Ketrenosb095c382005-08-24 22:04:42 -050010084 if (likely(unicast))
10085 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10086
10087 if (txb->encrypted && !priv->ieee->host_encrypt) {
10088 switch (priv->ieee->sec.level) {
10089 case SEC_LEVEL_3:
10090 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10091 IEEE80211_FCTL_PROTECTED;
10092 /* XXX: ACK flag must be set for CCMP even if it
10093 * is a multicast/broadcast packet, because CCMP
10094 * group communication encrypted by GTK is
10095 * actually done by the AP. */
10096 if (!unicast)
10097 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
10098
10099 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10100 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
10101 tfd->u.data.key_index = 0;
10102 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
10103 break;
10104 case SEC_LEVEL_2:
10105 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10106 IEEE80211_FCTL_PROTECTED;
10107 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
10108 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
10109 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
10110 break;
10111 case SEC_LEVEL_1:
10112 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
10113 IEEE80211_FCTL_PROTECTED;
10114 tfd->u.data.key_index = priv->ieee->tx_keyidx;
10115 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
10116 40)
10117 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
10118 else
10119 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
10120 break;
10121 case SEC_LEVEL_0:
10122 break;
10123 default:
10124 printk(KERN_ERR "Unknow security level %d\n",
10125 priv->ieee->sec.level);
10126 break;
10127 }
10128 } else
10129 /* No hardware encryption */
10130 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
10131
Zhu Yie43e3c12006-04-13 17:20:45 +080010132#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010133 if (fc & IEEE80211_STYPE_QOS_DATA)
10134 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
Zhu Yie43e3c12006-04-13 17:20:45 +080010135#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050010136
James Ketrenos43f66a62005-03-25 12:31:53 -060010137 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -050010138 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
10139 txb->nr_frags));
10140 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
10141 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
10142 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
10143 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
10144 i, le32_to_cpu(tfd->u.data.num_chunks),
10145 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010146 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -060010147 i, tfd->u.data.num_chunks,
10148 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -040010149 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -060010150 txb->fragments[i]->len - hdr_len);
10151
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010152 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010153 cpu_to_le32(pci_map_single
10154 (priv->pci_dev,
10155 txb->fragments[i]->data + hdr_len,
10156 txb->fragments[i]->len - hdr_len,
10157 PCI_DMA_TODEVICE));
10158 tfd->u.data.chunk_len[i] =
10159 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -060010160 }
10161
10162 if (i != txb->nr_frags) {
10163 struct sk_buff *skb;
10164 u16 remaining_bytes = 0;
10165 int j;
10166
10167 for (j = i; j < txb->nr_frags; j++)
10168 remaining_bytes += txb->fragments[j]->len - hdr_len;
10169
10170 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
10171 remaining_bytes);
10172 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
10173 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -050010174 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -060010175 for (j = i; j < txb->nr_frags; j++) {
10176 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010177
James Ketrenos43f66a62005-03-25 12:31:53 -060010178 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010179 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010180 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010181 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010182 }
10183 dev_kfree_skb_any(txb->fragments[i]);
10184 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010185 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -050010186 cpu_to_le32(pci_map_single
10187 (priv->pci_dev, skb->data,
10188 tfd->u.data.chunk_len[i],
10189 PCI_DMA_TODEVICE));
10190
10191 tfd->u.data.num_chunks =
10192 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
10193 1);
Jeff Garzikbf794512005-07-31 13:07:26 -040010194 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010195 }
10196
10197 /* kick DMA */
10198 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
10199 ipw_write32(priv, q->reg_w, q->first_empty);
10200
James Ketrenosf6970142006-02-14 09:10:51 +080010201 if (ipw_queue_space(q) < q->high_mark)
10202 netif_stop_queue(priv->net_dev);
10203
James Ketrenos227d2dc2005-07-28 16:25:55 -050010204 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -060010205
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010206 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -060010207 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
10208 ieee80211_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -050010209 return NETDEV_TX_OK;
10210}
10211
10212static int ipw_net_is_queue_full(struct net_device *dev, int pri)
10213{
10214 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yie43e3c12006-04-13 17:20:45 +080010215#ifdef CONFIG_IPW2200_QOS
James Ketrenos227d2dc2005-07-28 16:25:55 -050010216 int tx_id = ipw_get_tx_queue_number(priv, pri);
10217 struct clx2_tx_queue *txq = &priv->txq[tx_id];
10218#else
10219 struct clx2_tx_queue *txq = &priv->txq[0];
Zhu Yie43e3c12006-04-13 17:20:45 +080010220#endif /* CONFIG_IPW2200_QOS */
James Ketrenos227d2dc2005-07-28 16:25:55 -050010221
10222 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
10223 return 1;
10224
10225 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010226}
10227
Zhu Yid685b8c2006-04-13 17:20:27 +080010228#ifdef CONFIG_IPW2200_PROMISCUOUS
10229static void ipw_handle_promiscuous_tx(struct ipw_priv *priv,
10230 struct ieee80211_txb *txb)
10231{
10232 struct ieee80211_rx_stats dummystats;
10233 struct ieee80211_hdr *hdr;
10234 u8 n;
10235 u16 filter = priv->prom_priv->filter;
10236 int hdr_only = 0;
10237
10238 if (filter & IPW_PROM_NO_TX)
10239 return;
10240
10241 memset(&dummystats, 0, sizeof(dummystats));
10242
10243 /* Filtering of fragment chains is done agains the first fragment */
10244 hdr = (void *)txb->fragments[0]->data;
10245 if (ieee80211_is_management(hdr->frame_ctl)) {
10246 if (filter & IPW_PROM_NO_MGMT)
10247 return;
10248 if (filter & IPW_PROM_MGMT_HEADER_ONLY)
10249 hdr_only = 1;
10250 } else if (ieee80211_is_control(hdr->frame_ctl)) {
10251 if (filter & IPW_PROM_NO_CTL)
10252 return;
10253 if (filter & IPW_PROM_CTL_HEADER_ONLY)
10254 hdr_only = 1;
10255 } else if (ieee80211_is_data(hdr->frame_ctl)) {
10256 if (filter & IPW_PROM_NO_DATA)
10257 return;
10258 if (filter & IPW_PROM_DATA_HEADER_ONLY)
10259 hdr_only = 1;
10260 }
10261
10262 for(n=0; n<txb->nr_frags; ++n) {
10263 struct sk_buff *src = txb->fragments[n];
10264 struct sk_buff *dst;
10265 struct ieee80211_radiotap_header *rt_hdr;
10266 int len;
10267
10268 if (hdr_only) {
10269 hdr = (void *)src->data;
10270 len = ieee80211_get_hdrlen(hdr->frame_ctl);
10271 } else
10272 len = src->len;
10273
10274 dst = alloc_skb(
10275 len + IEEE80211_RADIOTAP_HDRLEN, GFP_ATOMIC);
10276 if (!dst) continue;
10277
10278 rt_hdr = (void *)skb_put(dst, sizeof(*rt_hdr));
10279
10280 rt_hdr->it_version = PKTHDR_RADIOTAP_VERSION;
10281 rt_hdr->it_pad = 0;
10282 rt_hdr->it_present = 0; /* after all, it's just an idea */
10283 rt_hdr->it_present |= (1 << IEEE80211_RADIOTAP_CHANNEL);
10284
10285 *(u16*)skb_put(dst, sizeof(u16)) = cpu_to_le16(
10286 ieee80211chan2mhz(priv->channel));
10287 if (priv->channel > 14) /* 802.11a */
10288 *(u16*)skb_put(dst, sizeof(u16)) =
10289 cpu_to_le16(IEEE80211_CHAN_OFDM |
10290 IEEE80211_CHAN_5GHZ);
10291 else if (priv->ieee->mode == IEEE_B) /* 802.11b */
10292 *(u16*)skb_put(dst, sizeof(u16)) =
10293 cpu_to_le16(IEEE80211_CHAN_CCK |
10294 IEEE80211_CHAN_2GHZ);
10295 else /* 802.11g */
10296 *(u16*)skb_put(dst, sizeof(u16)) =
10297 cpu_to_le16(IEEE80211_CHAN_OFDM |
10298 IEEE80211_CHAN_2GHZ);
10299
10300 rt_hdr->it_len = dst->len;
10301
10302 memcpy(skb_put(dst, len), src->data, len);
10303
10304 if (!ieee80211_rx(priv->prom_priv->ieee, dst, &dummystats))
10305 dev_kfree_skb_any(dst);
10306 }
10307}
10308#endif
10309
James Ketrenos43f66a62005-03-25 12:31:53 -060010310static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -050010311 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -060010312{
10313 struct ipw_priv *priv = ieee80211_priv(dev);
10314 unsigned long flags;
James Ketrenos227d2dc2005-07-28 16:25:55 -050010315 int ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010316
10317 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -060010318 spin_lock_irqsave(&priv->lock, flags);
10319
10320 if (!(priv->status & STATUS_ASSOCIATED)) {
10321 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
10322 priv->ieee->stats.tx_carrier_errors++;
10323 netif_stop_queue(dev);
10324 goto fail_unlock;
10325 }
10326
Zhu Yid685b8c2006-04-13 17:20:27 +080010327#ifdef CONFIG_IPW2200_PROMISCUOUS
10328 if (rtap_iface && netif_running(priv->prom_net_dev))
10329 ipw_handle_promiscuous_tx(priv, txb);
10330#endif
10331
James Ketrenos227d2dc2005-07-28 16:25:55 -050010332 ret = ipw_tx_skb(priv, txb, pri);
10333 if (ret == NETDEV_TX_OK)
10334 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010335 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -060010336
James Ketrenos227d2dc2005-07-28 16:25:55 -050010337 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -060010338
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010339 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010340 spin_unlock_irqrestore(&priv->lock, flags);
10341 return 1;
10342}
10343
10344static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
10345{
10346 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -040010347
James Ketrenos43f66a62005-03-25 12:31:53 -060010348 priv->ieee->stats.tx_packets = priv->tx_packets;
10349 priv->ieee->stats.rx_packets = priv->rx_packets;
10350 return &priv->ieee->stats;
10351}
10352
10353static void ipw_net_set_multicast_list(struct net_device *dev)
10354{
10355
10356}
10357
10358static int ipw_net_set_mac_address(struct net_device *dev, void *p)
10359{
10360 struct ipw_priv *priv = ieee80211_priv(dev);
10361 struct sockaddr *addr = p;
10362 if (!is_valid_ether_addr(addr->sa_data))
10363 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +080010364 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010365 priv->config |= CFG_CUSTOM_MAC;
10366 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
10367 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
10368 priv->net_dev->name, MAC_ARG(priv->mac_addr));
James Ketrenosa613bff2005-08-24 21:43:11 -050010369 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +080010370 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010371 return 0;
10372}
10373
Jeff Garzikbf794512005-07-31 13:07:26 -040010374static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -060010375 struct ethtool_drvinfo *info)
10376{
10377 struct ipw_priv *p = ieee80211_priv(dev);
10378 char vers[64];
10379 char date[32];
10380 u32 len;
10381
10382 strcpy(info->driver, DRV_NAME);
10383 strcpy(info->version, DRV_VERSION);
10384
10385 len = sizeof(vers);
10386 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
10387 len = sizeof(date);
10388 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
10389
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010390 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -060010391 vers, date);
10392 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -050010393 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010394}
10395
10396static u32 ipw_ethtool_get_link(struct net_device *dev)
10397{
10398 struct ipw_priv *priv = ieee80211_priv(dev);
10399 return (priv->status & STATUS_ASSOCIATED) != 0;
10400}
10401
10402static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
10403{
James Ketrenosb095c382005-08-24 22:04:42 -050010404 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010405}
10406
10407static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010408 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010409{
10410 struct ipw_priv *p = ieee80211_priv(dev);
10411
James Ketrenosb095c382005-08-24 22:04:42 -050010412 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010413 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010414 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010415 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +080010416 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010417 return 0;
10418}
10419
10420static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010421 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -060010422{
10423 struct ipw_priv *p = ieee80211_priv(dev);
10424 int i;
10425
James Ketrenosb095c382005-08-24 22:04:42 -050010426 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -060010427 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +080010428 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010429 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Adrian Bunk71e585f2006-03-11 04:42:58 +010010430 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
10431 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +080010432 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010433 return 0;
10434}
10435
10436static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010437 .get_link = ipw_ethtool_get_link,
10438 .get_drvinfo = ipw_ethtool_get_drvinfo,
10439 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10440 .get_eeprom = ipw_ethtool_get_eeprom,
10441 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010442};
10443
10444static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
10445{
10446 struct ipw_priv *priv = data;
10447 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010448
James Ketrenos43f66a62005-03-25 12:31:53 -060010449 if (!priv)
10450 return IRQ_NONE;
10451
Zhu Yi89c318e2006-06-08 22:19:49 -070010452 spin_lock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010453
10454 if (!(priv->status & STATUS_INT_ENABLED)) {
10455 /* Shared IRQ */
10456 goto none;
10457 }
10458
James Ketrenosb095c382005-08-24 22:04:42 -050010459 inta = ipw_read32(priv, IPW_INTA_RW);
10460 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010461
James Ketrenos43f66a62005-03-25 12:31:53 -060010462 if (inta == 0xFFFFFFFF) {
10463 /* Hardware disappeared */
10464 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10465 goto none;
10466 }
10467
James Ketrenosb095c382005-08-24 22:04:42 -050010468 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010469 /* Shared interrupt */
10470 goto none;
10471 }
10472
10473 /* tell the device to stop sending interrupts */
Zhu Yi89c318e2006-06-08 22:19:49 -070010474 __ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010475
James Ketrenos43f66a62005-03-25 12:31:53 -060010476 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010477 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10478 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010479
James Ketrenos43f66a62005-03-25 12:31:53 -060010480 /* Cache INTA value for our tasklet */
10481 priv->isr_inta = inta;
10482
10483 tasklet_schedule(&priv->irq_tasklet);
10484
Zhu Yi89c318e2006-06-08 22:19:49 -070010485 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010486
10487 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010488 none:
Zhu Yi89c318e2006-06-08 22:19:49 -070010489 spin_unlock(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010490 return IRQ_NONE;
10491}
10492
10493static void ipw_rf_kill(void *adapter)
10494{
10495 struct ipw_priv *priv = adapter;
10496 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010497
James Ketrenos43f66a62005-03-25 12:31:53 -060010498 spin_lock_irqsave(&priv->lock, flags);
10499
10500 if (rf_kill_active(priv)) {
10501 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10502 if (priv->workqueue)
10503 queue_delayed_work(priv->workqueue,
10504 &priv->rf_kill, 2 * HZ);
10505 goto exit_unlock;
10506 }
10507
10508 /* RF Kill is now disabled, so bring the device back up */
10509
10510 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10511 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10512 "device\n");
10513
10514 /* we can not do an adapter restart while inside an irq lock */
10515 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010516 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010517 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10518 "enabled\n");
10519
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010520 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010521 spin_unlock_irqrestore(&priv->lock, flags);
10522}
10523
James Ketrenosc848d0a2005-08-24 21:56:24 -050010524static void ipw_bg_rf_kill(void *data)
10525{
10526 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010527 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010528 ipw_rf_kill(data);
Zhu Yi46441512006-01-24 16:37:59 +080010529 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010530}
10531
Adrian Bunka73e22b2006-01-21 01:39:42 +010010532static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010533{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010534 priv->last_seq_num = -1;
10535 priv->last_frag_num = -1;
10536 priv->last_packet_time = 0;
10537
James Ketrenosa613bff2005-08-24 21:43:11 -050010538 netif_carrier_on(priv->net_dev);
10539 if (netif_queue_stopped(priv->net_dev)) {
10540 IPW_DEBUG_NOTIF("waking queue\n");
10541 netif_wake_queue(priv->net_dev);
10542 } else {
10543 IPW_DEBUG_NOTIF("starting queue\n");
10544 netif_start_queue(priv->net_dev);
10545 }
10546
James Ketrenosc848d0a2005-08-24 21:56:24 -050010547 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010548 ipw_reset_stats(priv);
10549 /* Ensure the rate is updated immediately */
10550 priv->last_rate = ipw_get_current_rate(priv);
10551 ipw_gather_stats(priv);
10552 ipw_led_link_up(priv);
10553 notify_wx_assoc_event(priv);
10554
10555 if (priv->config & CFG_BACKGROUND_SCAN)
10556 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10557}
10558
James Ketrenosc848d0a2005-08-24 21:56:24 -050010559static void ipw_bg_link_up(void *data)
10560{
10561 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010562 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010563 ipw_link_up(data);
Zhu Yi46441512006-01-24 16:37:59 +080010564 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010565}
10566
Adrian Bunka73e22b2006-01-21 01:39:42 +010010567static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010568{
10569 ipw_led_link_down(priv);
10570 netif_carrier_off(priv->net_dev);
10571 netif_stop_queue(priv->net_dev);
10572 notify_wx_assoc_event(priv);
10573
10574 /* Cancel any queued work ... */
10575 cancel_delayed_work(&priv->request_scan);
10576 cancel_delayed_work(&priv->adhoc_check);
10577 cancel_delayed_work(&priv->gather_stats);
10578
10579 ipw_reset_stats(priv);
10580
James Ketrenosafbf30a2005-08-25 00:05:33 -050010581 if (!(priv->status & STATUS_EXIT_PENDING)) {
10582 /* Queue up another scan... */
10583 queue_work(priv->workqueue, &priv->request_scan);
10584 }
James Ketrenosa613bff2005-08-24 21:43:11 -050010585}
10586
James Ketrenosc848d0a2005-08-24 21:56:24 -050010587static void ipw_bg_link_down(void *data)
10588{
10589 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010590 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010591 ipw_link_down(data);
Zhu Yi46441512006-01-24 16:37:59 +080010592 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010593}
10594
James Ketrenos43f66a62005-03-25 12:31:53 -060010595static int ipw_setup_deferred_work(struct ipw_priv *priv)
10596{
10597 int ret = 0;
10598
James Ketrenos43f66a62005-03-25 12:31:53 -060010599 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010600 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010601 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010602
James Ketrenosc848d0a2005-08-24 21:56:24 -050010603 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10604 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10605 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
Zhu Yid8bad6d2005-07-13 12:25:38 -050010606 INIT_WORK(&priv->system_config, ipw_system_config, priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010607 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10608 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10609 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10610 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10611 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010612 INIT_WORK(&priv->request_scan,
James Ketrenos43f66a62005-03-25 12:31:53 -060010613 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010614 INIT_WORK(&priv->gather_stats,
James Ketrenosc848d0a2005-08-24 21:56:24 -050010615 (void (*)(void *))ipw_bg_gather_stats, priv);
10616 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10617 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10618 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10619 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10620 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10621 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
James Ketrenosa613bff2005-08-24 21:43:11 -050010622 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010623 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
James Ketrenosa613bff2005-08-24 21:43:11 -050010624 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010625 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10626 priv);
10627 INIT_WORK(&priv->merge_networks,
10628 (void (*)(void *))ipw_merge_adhoc_network, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010629
Zhu Yie43e3c12006-04-13 17:20:45 +080010630#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010631 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10632 priv);
Zhu Yie43e3c12006-04-13 17:20:45 +080010633#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010634
10635 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10636 ipw_irq_tasklet, (unsigned long)priv);
10637
10638 return ret;
10639}
10640
James Ketrenos43f66a62005-03-25 12:31:53 -060010641static void shim__set_security(struct net_device *dev,
10642 struct ieee80211_security *sec)
10643{
10644 struct ipw_priv *priv = ieee80211_priv(dev);
10645 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010646 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010647 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010648 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010649 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010650 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010651 priv->ieee->sec.flags &= ~(1 << i);
10652 else {
10653 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010654 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010655 priv->ieee->sec.flags |= (1 << i);
10656 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010657 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010658 } else if (sec->level != SEC_LEVEL_1)
10659 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010660 }
10661
James Ketrenosb095c382005-08-24 22:04:42 -050010662 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010663 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010664 priv->ieee->sec.active_key = sec->active_key;
10665 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010666 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010667 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010668 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010669 } else
10670 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010671
10672 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010673 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10674 priv->ieee->sec.auth_mode = sec->auth_mode;
10675 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010676 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10677 priv->capability |= CAP_SHARED_KEY;
10678 else
10679 priv->capability &= ~CAP_SHARED_KEY;
10680 priv->status |= STATUS_SECURITY_UPDATED;
10681 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010682
James Ketrenosb095c382005-08-24 22:04:42 -050010683 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10684 priv->ieee->sec.flags |= SEC_ENABLED;
10685 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010686 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010687 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010688 priv->capability |= CAP_PRIVACY_ON;
10689 else
10690 priv->capability &= ~CAP_PRIVACY_ON;
10691 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010692
James Ketrenosafbf30a2005-08-25 00:05:33 -050010693 if (sec->flags & SEC_ENCRYPT)
10694 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010695
James Ketrenosb095c382005-08-24 22:04:42 -050010696 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10697 priv->ieee->sec.level = sec->level;
10698 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010699 priv->status |= STATUS_SECURITY_UPDATED;
10700 }
10701
Zhu Yi1fbfea52005-08-05 17:22:56 +080010702 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10703 ipw_set_hwcrypto_keys(priv);
10704
Jeff Garzikbf794512005-07-31 13:07:26 -040010705 /* To match current functionality of ipw2100 (which works well w/
10706 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010707 * privacy capability changes ... */
10708#if 0
10709 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010710 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -060010711 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010712 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010713 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010714 IPW_DEBUG_ASSOC("Disassociating due to capability "
10715 "change.\n");
10716 ipw_disassociate(priv);
10717 }
10718#endif
10719}
10720
Jeff Garzikbf794512005-07-31 13:07:26 -040010721static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010722 struct ipw_supported_rates *rates)
10723{
10724 /* TODO: Mask out rates based on priv->rates_mask */
10725
10726 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010727 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010728 switch (priv->ieee->freq_band) {
10729 case IEEE80211_52GHZ_BAND:
10730 rates->ieee_mode = IPW_A_MODE;
10731 rates->purpose = IPW_RATE_CAPABILITIES;
10732 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10733 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10734 break;
10735
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010736 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010737 rates->ieee_mode = IPW_G_MODE;
10738 rates->purpose = IPW_RATE_CAPABILITIES;
10739 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10740 IEEE80211_CCK_DEFAULT_RATES_MASK);
10741 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10742 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10743 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10744 }
10745 break;
10746 }
10747
10748 return 0;
10749}
10750
Jeff Garzikbf794512005-07-31 13:07:26 -040010751static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010752{
James Ketrenos43f66a62005-03-25 12:31:53 -060010753 /* This is only called from ipw_up, which resets/reloads the firmware
10754 so, we don't need to first disable the card before we configure
10755 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010756 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010757 goto error;
10758
10759 /* initialize adapter address */
10760 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10761 goto error;
10762
10763 /* set basic system config settings */
10764 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010765
10766 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10767 * Does not support BT priority yet (don't abort or defer our Tx) */
10768 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010769 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010770
10771 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10772 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010773 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010774 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10775 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010776 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010777 }
10778
Zhu Yid685b8c2006-04-13 17:20:27 +080010779#ifdef CONFIG_IPW2200_PROMISCUOUS
10780 if (priv->prom_net_dev && netif_running(priv->prom_net_dev)) {
10781 priv->sys_config.accept_all_data_frames = 1;
10782 priv->sys_config.accept_non_directed_frames = 1;
10783 priv->sys_config.accept_all_mgmt_bcpr = 1;
10784 priv->sys_config.accept_all_mgmt_frames = 1;
10785 }
10786#endif
10787
James Ketrenosc848d0a2005-08-24 21:56:24 -050010788 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10789 priv->sys_config.answer_broadcast_ssid_probe = 1;
10790 else
10791 priv->sys_config.answer_broadcast_ssid_probe = 0;
10792
Zhu Yid685b8c2006-04-13 17:20:27 +080010793 if (ipw_send_system_config(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010794 goto error;
10795
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010796 init_supported_rates(priv, &priv->rates);
10797 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010798 goto error;
10799
10800 /* Set request-to-send threshold */
10801 if (priv->rts_threshold) {
10802 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10803 goto error;
10804 }
Zhu Yie43e3c12006-04-13 17:20:45 +080010805#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050010806 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10807 ipw_qos_activate(priv, NULL);
Zhu Yie43e3c12006-04-13 17:20:45 +080010808#endif /* CONFIG_IPW2200_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010809
10810 if (ipw_set_random_seed(priv))
10811 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010812
James Ketrenos43f66a62005-03-25 12:31:53 -060010813 /* final state transition to the RUN state */
10814 if (ipw_send_host_complete(priv))
10815 goto error;
10816
James Ketrenose6666192005-08-12 09:17:04 -050010817 priv->status |= STATUS_INIT;
10818
10819 ipw_led_init(priv);
10820 ipw_led_radio_on(priv);
10821 priv->notif_missed_beacons = 0;
10822
10823 /* Set hardware WEP key if it is configured. */
10824 if ((priv->capability & CAP_PRIVACY_ON) &&
10825 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10826 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10827 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010828
10829 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010830
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010831 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010832 return -EIO;
10833}
10834
James Ketrenos4f36f802005-08-03 20:36:56 -050010835/*
10836 * NOTE:
10837 *
10838 * These tables have been tested in conjunction with the
10839 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10840 *
10841 * Altering this values, using it on other hardware, or in geographies
10842 * not intended for resale of the above mentioned Intel adapters has
10843 * not been tested.
10844 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080010845 * Remember to update the table in README.ipw2200 when changing this
10846 * table.
10847 *
James Ketrenos4f36f802005-08-03 20:36:56 -050010848 */
10849static const struct ieee80211_geo ipw_geos[] = {
10850 { /* Restricted */
10851 "---",
10852 .bg_channels = 11,
10853 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10854 {2427, 4}, {2432, 5}, {2437, 6},
10855 {2442, 7}, {2447, 8}, {2452, 9},
10856 {2457, 10}, {2462, 11}},
10857 },
10858
10859 { /* Custom US/Canada */
10860 "ZZF",
10861 .bg_channels = 11,
10862 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10863 {2427, 4}, {2432, 5}, {2437, 6},
10864 {2442, 7}, {2447, 8}, {2452, 9},
10865 {2457, 10}, {2462, 11}},
10866 .a_channels = 8,
10867 .a = {{5180, 36},
10868 {5200, 40},
10869 {5220, 44},
10870 {5240, 48},
10871 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10872 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10873 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10874 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10875 },
10876
10877 { /* Rest of World */
10878 "ZZD",
10879 .bg_channels = 13,
10880 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10881 {2427, 4}, {2432, 5}, {2437, 6},
10882 {2442, 7}, {2447, 8}, {2452, 9},
10883 {2457, 10}, {2462, 11}, {2467, 12},
10884 {2472, 13}},
10885 },
10886
10887 { /* Custom USA & Europe & High */
10888 "ZZA",
10889 .bg_channels = 11,
10890 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10891 {2427, 4}, {2432, 5}, {2437, 6},
10892 {2442, 7}, {2447, 8}, {2452, 9},
10893 {2457, 10}, {2462, 11}},
10894 .a_channels = 13,
10895 .a = {{5180, 36},
10896 {5200, 40},
10897 {5220, 44},
10898 {5240, 48},
10899 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10900 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10901 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10902 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10903 {5745, 149},
10904 {5765, 153},
10905 {5785, 157},
10906 {5805, 161},
10907 {5825, 165}},
10908 },
10909
10910 { /* Custom NA & Europe */
10911 "ZZB",
10912 .bg_channels = 11,
10913 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10914 {2427, 4}, {2432, 5}, {2437, 6},
10915 {2442, 7}, {2447, 8}, {2452, 9},
10916 {2457, 10}, {2462, 11}},
10917 .a_channels = 13,
10918 .a = {{5180, 36},
10919 {5200, 40},
10920 {5220, 44},
10921 {5240, 48},
10922 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10923 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10924 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10925 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10926 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10927 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10928 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10929 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10930 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10931 },
10932
10933 { /* Custom Japan */
10934 "ZZC",
10935 .bg_channels = 11,
10936 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10937 {2427, 4}, {2432, 5}, {2437, 6},
10938 {2442, 7}, {2447, 8}, {2452, 9},
10939 {2457, 10}, {2462, 11}},
10940 .a_channels = 4,
10941 .a = {{5170, 34}, {5190, 38},
10942 {5210, 42}, {5230, 46}},
10943 },
10944
10945 { /* Custom */
10946 "ZZM",
10947 .bg_channels = 11,
10948 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10949 {2427, 4}, {2432, 5}, {2437, 6},
10950 {2442, 7}, {2447, 8}, {2452, 9},
10951 {2457, 10}, {2462, 11}},
10952 },
10953
10954 { /* Europe */
10955 "ZZE",
10956 .bg_channels = 13,
10957 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10958 {2427, 4}, {2432, 5}, {2437, 6},
10959 {2442, 7}, {2447, 8}, {2452, 9},
10960 {2457, 10}, {2462, 11}, {2467, 12},
10961 {2472, 13}},
10962 .a_channels = 19,
10963 .a = {{5180, 36},
10964 {5200, 40},
10965 {5220, 44},
10966 {5240, 48},
10967 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10968 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10969 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10970 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10971 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10972 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10973 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10974 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10975 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10976 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10977 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10978 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10979 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10980 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10981 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10982 },
10983
10984 { /* Custom Japan */
10985 "ZZJ",
10986 .bg_channels = 14,
10987 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10988 {2427, 4}, {2432, 5}, {2437, 6},
10989 {2442, 7}, {2447, 8}, {2452, 9},
10990 {2457, 10}, {2462, 11}, {2467, 12},
10991 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10992 .a_channels = 4,
10993 .a = {{5170, 34}, {5190, 38},
10994 {5210, 42}, {5230, 46}},
10995 },
10996
James Ketrenos03520572005-10-19 16:12:31 -050010997 { /* Rest of World */
10998 "ZZR",
10999 .bg_channels = 14,
11000 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11001 {2427, 4}, {2432, 5}, {2437, 6},
11002 {2442, 7}, {2447, 8}, {2452, 9},
11003 {2457, 10}, {2462, 11}, {2467, 12},
11004 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
11005 IEEE80211_CH_PASSIVE_ONLY}},
11006 },
11007
James Ketrenos4f36f802005-08-03 20:36:56 -050011008 { /* High Band */
11009 "ZZH",
11010 .bg_channels = 13,
11011 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11012 {2427, 4}, {2432, 5}, {2437, 6},
11013 {2442, 7}, {2447, 8}, {2452, 9},
11014 {2457, 10}, {2462, 11},
11015 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
11016 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
11017 .a_channels = 4,
11018 .a = {{5745, 149}, {5765, 153},
11019 {5785, 157}, {5805, 161}},
11020 },
11021
11022 { /* Custom Europe */
11023 "ZZG",
11024 .bg_channels = 13,
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},
11029 {2467, 12}, {2472, 13}},
11030 .a_channels = 4,
11031 .a = {{5180, 36}, {5200, 40},
11032 {5220, 44}, {5240, 48}},
11033 },
11034
11035 { /* Europe */
11036 "ZZK",
11037 .bg_channels = 13,
11038 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11039 {2427, 4}, {2432, 5}, {2437, 6},
11040 {2442, 7}, {2447, 8}, {2452, 9},
11041 {2457, 10}, {2462, 11},
11042 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
11043 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
11044 .a_channels = 24,
11045 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
11046 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
11047 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
11048 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
11049 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11050 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11051 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11052 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11053 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
11054 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
11055 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
11056 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
11057 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
11058 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
11059 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
11060 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
11061 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
11062 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
11063 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
11064 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11065 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11066 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11067 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11068 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11069 },
11070
11071 { /* Europe */
11072 "ZZL",
11073 .bg_channels = 11,
11074 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
11075 {2427, 4}, {2432, 5}, {2437, 6},
11076 {2442, 7}, {2447, 8}, {2452, 9},
11077 {2457, 10}, {2462, 11}},
11078 .a_channels = 13,
11079 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
11080 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
11081 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
11082 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
11083 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
11084 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
11085 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
11086 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
11087 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
11088 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
11089 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
11090 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
11091 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
11092 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050011093};
11094
James Ketrenos43f66a62005-03-25 12:31:53 -060011095#define MAX_HW_RESTARTS 5
11096static int ipw_up(struct ipw_priv *priv)
11097{
James Ketrenos4f36f802005-08-03 20:36:56 -050011098 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060011099
11100 if (priv->status & STATUS_EXIT_PENDING)
11101 return -EIO;
11102
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011103 if (cmdlog && !priv->cmdlog) {
11104 priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
11105 GFP_KERNEL);
11106 if (priv->cmdlog == NULL) {
11107 IPW_ERROR("Error allocating %d command log entries.\n",
11108 cmdlog);
Zhu Yid0b526b2006-04-13 17:19:50 +080011109 return -ENOMEM;
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011110 } else {
11111 memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
11112 priv->cmdlog_len = cmdlog;
11113 }
11114 }
11115
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011116 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040011117 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060011118 * Also start the clocks. */
11119 rc = ipw_load(priv);
11120 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050011121 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011122 return rc;
11123 }
11124
11125 ipw_init_ordinals(priv);
11126 if (!(priv->config & CFG_CUSTOM_MAC))
11127 eeprom_parse_mac(priv, priv->mac_addr);
11128 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
11129
James Ketrenos4f36f802005-08-03 20:36:56 -050011130 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
11131 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
11132 ipw_geos[j].name, 3))
11133 break;
11134 }
James Ketrenos03520572005-10-19 16:12:31 -050011135 if (j == ARRAY_SIZE(ipw_geos)) {
11136 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
11137 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
11138 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
11139 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050011140 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050011141 }
Larry Finger1867b112006-02-28 09:48:28 -060011142 if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050011143 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060011144 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050011145 }
11146
James Ketrenosb095c382005-08-24 22:04:42 -050011147 if (priv->status & STATUS_RF_KILL_SW) {
11148 IPW_WARNING("Radio disabled by module parameter.\n");
11149 return 0;
11150 } else if (rf_kill_active(priv)) {
11151 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
11152 "Kill switch must be turned off for "
11153 "wireless networking to work.\n");
11154 queue_delayed_work(priv->workqueue, &priv->rf_kill,
11155 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060011156 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050011157 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011158
11159 rc = ipw_config(priv);
11160 if (!rc) {
11161 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011162
James Ketrenose6666192005-08-12 09:17:04 -050011163 /* If configure to try and auto-associate, kick
11164 * off a scan. */
11165 queue_work(priv->workqueue, &priv->request_scan);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011166
James Ketrenos43f66a62005-03-25 12:31:53 -060011167 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060011168 }
Jeff Garzikbf794512005-07-31 13:07:26 -040011169
James Ketrenosc848d0a2005-08-24 21:56:24 -050011170 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060011171 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
11172 i, MAX_HW_RESTARTS);
11173
11174 /* We had an error bringing up the hardware, so take it
11175 * all the way back down so we can try again */
11176 ipw_down(priv);
11177 }
11178
Jeff Garzikbf794512005-07-31 13:07:26 -040011179 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060011180 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011181 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011182
James Ketrenos43f66a62005-03-25 12:31:53 -060011183 return -EIO;
11184}
11185
James Ketrenosc848d0a2005-08-24 21:56:24 -050011186static void ipw_bg_up(void *data)
11187{
11188 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080011189 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011190 ipw_up(data);
Zhu Yi46441512006-01-24 16:37:59 +080011191 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011192}
11193
James Ketrenosb095c382005-08-24 22:04:42 -050011194static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060011195{
James Ketrenosb095c382005-08-24 22:04:42 -050011196 int i;
11197
11198 if (priv->status & STATUS_SCANNING) {
11199 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
11200 ipw_abort_scan(priv);
11201 }
11202
11203 if (priv->status & STATUS_ASSOCIATED) {
11204 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
11205 ipw_disassociate(priv);
11206 }
11207
11208 ipw_led_shutdown(priv);
11209
11210 /* Wait up to 1s for status to change to not scanning and not
11211 * associated (disassociation can take a while for a ful 802.11
11212 * exchange */
11213 for (i = 1000; i && (priv->status &
11214 (STATUS_DISASSOCIATING |
11215 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
11216 udelay(10);
11217
11218 if (priv->status & (STATUS_DISASSOCIATING |
11219 STATUS_ASSOCIATED | STATUS_SCANNING))
11220 IPW_DEBUG_INFO("Still associated or scanning...\n");
11221 else
11222 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
11223
James Ketrenosc848d0a2005-08-24 21:56:24 -050011224 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060011225 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050011226
11227 priv->status &= ~STATUS_INIT;
11228}
11229
James Ketrenos43f66a62005-03-25 12:31:53 -060011230static void ipw_down(struct ipw_priv *priv)
11231{
James Ketrenosb095c382005-08-24 22:04:42 -050011232 int exit_pending = priv->status & STATUS_EXIT_PENDING;
11233
11234 priv->status |= STATUS_EXIT_PENDING;
11235
11236 if (ipw_is_init(priv))
11237 ipw_deinit(priv);
11238
11239 /* Wipe out the EXIT_PENDING status bit if we are not actually
11240 * exiting the module */
11241 if (!exit_pending)
11242 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011243
11244 /* tell the device to stop sending interrupts */
11245 ipw_disable_interrupts(priv);
11246
11247 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050011248 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011249 netif_carrier_off(priv->net_dev);
11250 netif_stop_queue(priv->net_dev);
11251
11252 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050011253
11254 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011255}
11256
James Ketrenosc848d0a2005-08-24 21:56:24 -050011257static void ipw_bg_down(void *data)
11258{
11259 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080011260 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011261 ipw_down(data);
Zhu Yi46441512006-01-24 16:37:59 +080011262 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011263}
11264
11265/* Called by register_netdev() */
11266static int ipw_net_init(struct net_device *dev)
11267{
11268 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +080011269 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011270
James Ketrenosc848d0a2005-08-24 21:56:24 -050011271 if (ipw_up(priv)) {
Zhu Yi46441512006-01-24 16:37:59 +080011272 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011273 return -EIO;
James Ketrenos43f66a62005-03-25 12:31:53 -060011274 }
11275
Zhu Yi46441512006-01-24 16:37:59 +080011276 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011277 return 0;
11278}
11279
11280/* PCI driver stuff */
11281static struct pci_device_id card_ids[] = {
11282 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
11283 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
11284 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
11285 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
11286 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
11287 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
11288 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
11289 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
11290 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
11291 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
11292 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
11293 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
11294 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
11295 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
11296 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
11297 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
11298 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
11299 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011300 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
James Ketrenosa613bff2005-08-24 21:43:11 -050011301 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011302 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
11303 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040011304
James Ketrenos43f66a62005-03-25 12:31:53 -060011305 /* required last entry */
11306 {0,}
11307};
11308
11309MODULE_DEVICE_TABLE(pci, card_ids);
11310
11311static struct attribute *ipw_sysfs_entries[] = {
11312 &dev_attr_rf_kill.attr,
11313 &dev_attr_direct_dword.attr,
11314 &dev_attr_indirect_byte.attr,
11315 &dev_attr_indirect_dword.attr,
11316 &dev_attr_mem_gpio_reg.attr,
11317 &dev_attr_command_event_reg.attr,
11318 &dev_attr_nic_type.attr,
11319 &dev_attr_status.attr,
11320 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050011321 &dev_attr_error.attr,
11322 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011323 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060011324 &dev_attr_eeprom_delay.attr,
11325 &dev_attr_ucode_version.attr,
11326 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050011327 &dev_attr_scan_age.attr,
11328 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050011329 &dev_attr_speed_scan.attr,
11330 &dev_attr_net_stats.attr,
Zhu Yid685b8c2006-04-13 17:20:27 +080011331#ifdef CONFIG_IPW2200_PROMISCUOUS
11332 &dev_attr_rtap_iface.attr,
11333 &dev_attr_rtap_filter.attr,
11334#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011335 NULL
11336};
11337
11338static struct attribute_group ipw_attribute_group = {
11339 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011340 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060011341};
11342
Zhu Yid685b8c2006-04-13 17:20:27 +080011343#ifdef CONFIG_IPW2200_PROMISCUOUS
11344static int ipw_prom_open(struct net_device *dev)
11345{
11346 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11347 struct ipw_priv *priv = prom_priv->priv;
11348
11349 IPW_DEBUG_INFO("prom dev->open\n");
11350 netif_carrier_off(dev);
11351 netif_stop_queue(dev);
11352
11353 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11354 priv->sys_config.accept_all_data_frames = 1;
11355 priv->sys_config.accept_non_directed_frames = 1;
11356 priv->sys_config.accept_all_mgmt_bcpr = 1;
11357 priv->sys_config.accept_all_mgmt_frames = 1;
11358
11359 ipw_send_system_config(priv);
11360 }
11361
11362 return 0;
11363}
11364
11365static int ipw_prom_stop(struct net_device *dev)
11366{
11367 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11368 struct ipw_priv *priv = prom_priv->priv;
11369
11370 IPW_DEBUG_INFO("prom dev->stop\n");
11371
11372 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
11373 priv->sys_config.accept_all_data_frames = 0;
11374 priv->sys_config.accept_non_directed_frames = 0;
11375 priv->sys_config.accept_all_mgmt_bcpr = 0;
11376 priv->sys_config.accept_all_mgmt_frames = 0;
11377
11378 ipw_send_system_config(priv);
11379 }
11380
11381 return 0;
11382}
11383
11384static int ipw_prom_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
11385{
11386 IPW_DEBUG_INFO("prom dev->xmit\n");
11387 netif_stop_queue(dev);
11388 return -EOPNOTSUPP;
11389}
11390
11391static struct net_device_stats *ipw_prom_get_stats(struct net_device *dev)
11392{
11393 struct ipw_prom_priv *prom_priv = ieee80211_priv(dev);
11394 return &prom_priv->ieee->stats;
11395}
11396
11397static int ipw_prom_alloc(struct ipw_priv *priv)
11398{
11399 int rc = 0;
11400
11401 if (priv->prom_net_dev)
11402 return -EPERM;
11403
11404 priv->prom_net_dev = alloc_ieee80211(sizeof(struct ipw_prom_priv));
11405 if (priv->prom_net_dev == NULL)
11406 return -ENOMEM;
11407
11408 priv->prom_priv = ieee80211_priv(priv->prom_net_dev);
11409 priv->prom_priv->ieee = netdev_priv(priv->prom_net_dev);
11410 priv->prom_priv->priv = priv;
11411
11412 strcpy(priv->prom_net_dev->name, "rtap%d");
11413
11414 priv->prom_net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
11415 priv->prom_net_dev->open = ipw_prom_open;
11416 priv->prom_net_dev->stop = ipw_prom_stop;
11417 priv->prom_net_dev->get_stats = ipw_prom_get_stats;
11418 priv->prom_net_dev->hard_start_xmit = ipw_prom_hard_start_xmit;
11419
11420 priv->prom_priv->ieee->iw_mode = IW_MODE_MONITOR;
11421
11422 rc = register_netdev(priv->prom_net_dev);
11423 if (rc) {
11424 free_ieee80211(priv->prom_net_dev);
11425 priv->prom_net_dev = NULL;
11426 return rc;
11427 }
11428
11429 return 0;
11430}
11431
11432static void ipw_prom_free(struct ipw_priv *priv)
11433{
11434 if (!priv->prom_net_dev)
11435 return;
11436
11437 unregister_netdev(priv->prom_net_dev);
11438 free_ieee80211(priv->prom_net_dev);
11439
11440 priv->prom_net_dev = NULL;
11441}
11442
11443#endif
11444
11445
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011446static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060011447{
11448 int err = 0;
11449 struct net_device *net_dev;
11450 void __iomem *base;
11451 u32 length, val;
11452 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050011453 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060011454
11455 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
11456 if (net_dev == NULL) {
11457 err = -ENOMEM;
11458 goto out;
11459 }
11460
11461 priv = ieee80211_priv(net_dev);
11462 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050011463
James Ketrenos43f66a62005-03-25 12:31:53 -060011464 priv->net_dev = net_dev;
11465 priv->pci_dev = pdev;
James Ketrenos43f66a62005-03-25 12:31:53 -060011466 ipw_debug_level = debug;
Zhu Yi89c318e2006-06-08 22:19:49 -070011467 spin_lock_init(&priv->irq_lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060011468 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011469 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
11470 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060011471
Zhu Yi46441512006-01-24 16:37:59 +080011472 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011473 if (pci_enable_device(pdev)) {
11474 err = -ENODEV;
11475 goto out_free_ieee80211;
11476 }
11477
11478 pci_set_master(pdev);
11479
Tobias Klauser0e08b442005-06-20 14:28:41 -070011480 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -040011481 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -070011482 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060011483 if (err) {
11484 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
11485 goto out_pci_disable_device;
11486 }
11487
11488 pci_set_drvdata(pdev, priv);
11489
11490 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040011491 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060011492 goto out_pci_disable_device;
11493
Jeff Garzikbf794512005-07-31 13:07:26 -040011494 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060011495 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040011496 pci_read_config_dword(pdev, 0x40, &val);
11497 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011498 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040011499
James Ketrenos43f66a62005-03-25 12:31:53 -060011500 length = pci_resource_len(pdev, 0);
11501 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040011502
James Ketrenos43f66a62005-03-25 12:31:53 -060011503 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
11504 if (!base) {
11505 err = -ENODEV;
11506 goto out_pci_release_regions;
11507 }
11508
11509 priv->hw_base = base;
11510 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
11511 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
11512
11513 err = ipw_setup_deferred_work(priv);
11514 if (err) {
11515 IPW_ERROR("Unable to setup deferred work\n");
11516 goto out_iounmap;
11517 }
11518
James Ketrenosb095c382005-08-24 22:04:42 -050011519 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060011520
Thomas Gleixner1fb9df52006-07-01 19:29:39 -070011521 err = request_irq(pdev->irq, ipw_isr, IRQF_SHARED, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011522 if (err) {
11523 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
11524 goto out_destroy_workqueue;
11525 }
11526
11527 SET_MODULE_OWNER(net_dev);
11528 SET_NETDEV_DEV(net_dev, &pdev->dev);
11529
Zhu Yi46441512006-01-24 16:37:59 +080011530 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011531
James Ketrenos43f66a62005-03-25 12:31:53 -060011532 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
11533 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050011534 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060011535
Zhu Yie43e3c12006-04-13 17:20:45 +080011536#ifdef CONFIG_IPW2200_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080011537 priv->ieee->is_qos_active = ipw_is_qos_active;
James Ketrenos3b9990c2005-08-19 13:18:55 -050011538 priv->ieee->handle_probe_response = ipw_handle_beacon;
11539 priv->ieee->handle_beacon = ipw_handle_probe_response;
11540 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
Zhu Yie43e3c12006-04-13 17:20:45 +080011541#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011542
James Ketrenosc848d0a2005-08-24 21:56:24 -050011543 priv->ieee->perfect_rssi = -20;
11544 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060011545
11546 net_dev->open = ipw_net_open;
11547 net_dev->stop = ipw_net_stop;
11548 net_dev->init = ipw_net_init;
11549 net_dev->get_stats = ipw_net_get_stats;
11550 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11551 net_dev->set_mac_address = ipw_net_set_mac_address;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011552 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011553 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011554 net_dev->wireless_handlers = &ipw_wx_handler_def;
11555 net_dev->ethtool_ops = &ipw_ethtool_ops;
11556 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011557 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011558 net_dev->mem_start = pci_resource_start(pdev, 0);
11559 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11560
11561 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11562 if (err) {
11563 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011564 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011565 goto out_release_irq;
11566 }
11567
Zhu Yi46441512006-01-24 16:37:59 +080011568 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011569 err = register_netdev(net_dev);
11570 if (err) {
11571 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011572 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011573 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011574
Zhu Yid685b8c2006-04-13 17:20:27 +080011575#ifdef CONFIG_IPW2200_PROMISCUOUS
11576 if (rtap_iface) {
11577 err = ipw_prom_alloc(priv);
11578 if (err) {
11579 IPW_ERROR("Failed to register promiscuous network "
11580 "device (error %d).\n", err);
11581 unregister_netdev(priv->net_dev);
11582 goto out_remove_sysfs;
11583 }
11584 }
11585#endif
11586
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011587 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11588 "channels, %d 802.11a channels)\n",
11589 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11590 priv->ieee->geo.a_channels);
11591
James Ketrenos43f66a62005-03-25 12:31:53 -060011592 return 0;
11593
James Ketrenosa613bff2005-08-24 21:43:11 -050011594 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011595 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011596 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011597 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011598 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011599 destroy_workqueue(priv->workqueue);
11600 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011601 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011602 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011603 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011604 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011605 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011606 pci_disable_device(pdev);
11607 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011608 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -060011609 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011610 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011611 return err;
11612}
11613
11614static void ipw_pci_remove(struct pci_dev *pdev)
11615{
11616 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011617 struct list_head *p, *q;
11618 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011619
James Ketrenos43f66a62005-03-25 12:31:53 -060011620 if (!priv)
11621 return;
11622
Zhu Yi46441512006-01-24 16:37:59 +080011623 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011624
James Ketrenosafbf30a2005-08-25 00:05:33 -050011625 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011626 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011627 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11628
Zhu Yi46441512006-01-24 16:37:59 +080011629 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011630
11631 unregister_netdev(priv->net_dev);
11632
11633 if (priv->rxq) {
11634 ipw_rx_queue_free(priv, priv->rxq);
11635 priv->rxq = NULL;
11636 }
11637 ipw_tx_queue_free(priv);
11638
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011639 if (priv->cmdlog) {
11640 kfree(priv->cmdlog);
11641 priv->cmdlog = NULL;
11642 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011643 /* ipw_down will ensure that there is no more pending work
11644 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011645 cancel_delayed_work(&priv->adhoc_check);
11646 cancel_delayed_work(&priv->gather_stats);
11647 cancel_delayed_work(&priv->request_scan);
11648 cancel_delayed_work(&priv->rf_kill);
11649 cancel_delayed_work(&priv->scan_check);
11650 destroy_workqueue(priv->workqueue);
11651 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011652
James Ketrenosafbf30a2005-08-25 00:05:33 -050011653 /* Free MAC hash list for ADHOC */
11654 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11655 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011656 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011657 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011658 }
11659 }
11660
Jesper Juhl8f760782006-06-27 02:55:06 -070011661 kfree(priv->error);
11662 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011663
Zhu Yid685b8c2006-04-13 17:20:27 +080011664#ifdef CONFIG_IPW2200_PROMISCUOUS
11665 ipw_prom_free(priv);
11666#endif
11667
James Ketrenos43f66a62005-03-25 12:31:53 -060011668 free_irq(pdev->irq, priv);
11669 iounmap(priv->hw_base);
11670 pci_release_regions(pdev);
11671 pci_disable_device(pdev);
11672 pci_set_drvdata(pdev, NULL);
11673 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011674 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011675}
11676
James Ketrenos43f66a62005-03-25 12:31:53 -060011677#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011678static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011679{
11680 struct ipw_priv *priv = pci_get_drvdata(pdev);
11681 struct net_device *dev = priv->net_dev;
11682
11683 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11684
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011685 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011686 ipw_down(priv);
11687
11688 /* Remove the PRESENT state of the device */
11689 netif_device_detach(dev);
11690
James Ketrenos43f66a62005-03-25 12:31:53 -060011691 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011692 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011693 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011694
James Ketrenos43f66a62005-03-25 12:31:53 -060011695 return 0;
11696}
11697
11698static int ipw_pci_resume(struct pci_dev *pdev)
11699{
11700 struct ipw_priv *priv = pci_get_drvdata(pdev);
11701 struct net_device *dev = priv->net_dev;
11702 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011703
James Ketrenos43f66a62005-03-25 12:31:53 -060011704 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11705
James Ketrenosea2b26e2005-08-24 21:25:16 -050011706 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011707 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011708 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011709
James Ketrenos43f66a62005-03-25 12:31:53 -060011710 /*
11711 * Suspend/Resume resets the PCI configuration space, so we have to
11712 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11713 * from interfering with C3 CPU state. pci_restore_state won't help
11714 * here since it only restores the first 64 bytes pci config header.
11715 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011716 pci_read_config_dword(pdev, 0x40, &val);
11717 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011718 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11719
11720 /* Set the device back into the PRESENT state; this will also wake
11721 * the queue of needed */
11722 netif_device_attach(dev);
11723
11724 /* Bring the device back up */
11725 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011726
James Ketrenos43f66a62005-03-25 12:31:53 -060011727 return 0;
11728}
11729#endif
11730
11731/* driver initialization stuff */
11732static struct pci_driver ipw_driver = {
11733 .name = DRV_NAME,
11734 .id_table = card_ids,
11735 .probe = ipw_pci_probe,
11736 .remove = __devexit_p(ipw_pci_remove),
11737#ifdef CONFIG_PM
11738 .suspend = ipw_pci_suspend,
11739 .resume = ipw_pci_resume,
11740#endif
11741};
11742
11743static int __init ipw_init(void)
11744{
11745 int ret;
11746
11747 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11748 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11749
11750 ret = pci_module_init(&ipw_driver);
11751 if (ret) {
11752 IPW_ERROR("Unable to initialize PCI module\n");
11753 return ret;
11754 }
11755
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011756 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011757 if (ret) {
11758 IPW_ERROR("Unable to create driver sysfs file\n");
11759 pci_unregister_driver(&ipw_driver);
11760 return ret;
11761 }
11762
11763 return ret;
11764}
11765
11766static void __exit ipw_exit(void)
11767{
11768 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11769 pci_unregister_driver(&ipw_driver);
11770}
11771
11772module_param(disable, int, 0444);
11773MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11774
11775module_param(associate, int, 0444);
11776MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11777
11778module_param(auto_create, int, 0444);
11779MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11780
James Ketrenosa613bff2005-08-24 21:43:11 -050011781module_param(led, int, 0444);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011782MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011783
Zhu Yi3e1555b2006-03-06 05:48:37 +080011784#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060011785module_param(debug, int, 0444);
11786MODULE_PARM_DESC(debug, "debug output mask");
Zhu Yi3e1555b2006-03-06 05:48:37 +080011787#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011788
11789module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011790MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011791
Zhu Yid685b8c2006-04-13 17:20:27 +080011792#ifdef CONFIG_IPW2200_PROMISCUOUS
11793module_param(rtap_iface, int, 0444);
11794MODULE_PARM_DESC(rtap_iface, "create the rtap interface (1 - create, default 0)");
11795#endif
11796
Zhu Yie43e3c12006-04-13 17:20:45 +080011797#ifdef CONFIG_IPW2200_QOS
James Ketrenosb095c382005-08-24 22:04:42 -050011798module_param(qos_enable, int, 0444);
11799MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060011800
James Ketrenosb095c382005-08-24 22:04:42 -050011801module_param(qos_burst_enable, int, 0444);
11802MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11803
11804module_param(qos_no_ack_mask, int, 0444);
11805MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11806
11807module_param(burst_duration_CCK, int, 0444);
11808MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11809
11810module_param(burst_duration_OFDM, int, 0444);
11811MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
Zhu Yie43e3c12006-04-13 17:20:45 +080011812#endif /* CONFIG_IPW2200_QOS */
James Ketrenosb095c382005-08-24 22:04:42 -050011813
11814#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -060011815module_param(mode, int, 0444);
11816MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11817#else
11818module_param(mode, int, 0444);
11819MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11820#endif
11821
Zhu Yi810dabd2006-01-24 16:36:59 +080011822module_param(bt_coexist, int, 0444);
11823MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
11824
James Ketrenosb095c382005-08-24 22:04:42 -050011825module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080011826MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050011827
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011828module_param(cmdlog, int, 0444);
11829MODULE_PARM_DESC(cmdlog,
11830 "allocate a ring buffer for logging firmware commands");
11831
Zhu Yi4bfdb912006-01-24 16:37:16 +080011832module_param(roaming, int, 0444);
11833MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
11834
Zhu Yid2b83e12006-04-13 17:19:36 +080011835module_param(antenna, int, 0444);
11836MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
11837
James Ketrenos43f66a62005-03-25 12:31:53 -060011838module_exit(ipw_exit);
11839module_init(ipw_init);