blob: c38d6a5fe9a30593bde0fb96cb710037eba7305b [file] [log] [blame]
James Ketrenos43f66a62005-03-25 12:31:53 -06001/******************************************************************************
Jeff Garzikbf794512005-07-31 13:07:26 -04002
James Ketrenosafbf30a2005-08-25 00:05:33 -05003 Copyright(c) 2003 - 2005 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 Yi7c97eb32006-01-24 16:37:47 +080036#define IPW2200_VERSION "git-1.0.10"
James Ketrenos43f66a62005-03-25 12:31:53 -060037#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
James Ketrenos2b184d52005-08-03 20:33:14 -050038#define DRV_COPYRIGHT "Copyright(c) 2003-2005 Intel Corporation"
James Ketrenos43f66a62005-03-25 12:31:53 -060039#define DRV_VERSION IPW2200_VERSION
40
James Ketrenosb095c382005-08-24 22:04:42 -050041#define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
42
James Ketrenos43f66a62005-03-25 12:31:53 -060043MODULE_DESCRIPTION(DRV_DESCRIPTION);
44MODULE_VERSION(DRV_VERSION);
45MODULE_AUTHOR(DRV_COPYRIGHT);
46MODULE_LICENSE("GPL");
47
James Ketrenosf6c5cb72005-08-25 00:39:09 -050048static int cmdlog = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060049static int debug = 0;
50static int channel = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060051static int mode = 0;
52
53static u32 ipw_debug_level;
54static int associate = 1;
55static int auto_create = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -050056static int led = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060057static int disable = 0;
Zhu Yi810dabd2006-01-24 16:36:59 +080058static int bt_coexist = 0;
Zhu Yibde37d02006-01-24 16:38:08 +080059static int hwcrypto = 0;
Zhu Yi4bfdb912006-01-24 16:37:16 +080060static int roaming = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -060061static const char ipw_modes[] = {
62 'a', 'b', 'g', '?'
63};
64
James Ketrenosb095c382005-08-24 22:04:42 -050065#ifdef CONFIG_IPW_QOS
66static int qos_enable = 0;
67static int qos_burst_enable = 0;
68static int qos_no_ack_mask = 0;
69static int burst_duration_CCK = 0;
70static int burst_duration_OFDM = 0;
71
72static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
73 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
74 QOS_TX3_CW_MIN_OFDM},
75 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
76 QOS_TX3_CW_MAX_OFDM},
77 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
78 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
79 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
80 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
81};
82
83static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
84 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
85 QOS_TX3_CW_MIN_CCK},
86 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
87 QOS_TX3_CW_MAX_CCK},
88 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
89 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
90 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
91 QOS_TX3_TXOP_LIMIT_CCK}
92};
93
94static struct ieee80211_qos_parameters def_parameters_OFDM = {
95 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
96 DEF_TX3_CW_MIN_OFDM},
97 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
98 DEF_TX3_CW_MAX_OFDM},
99 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
100 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
101 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
102 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
103};
104
105static struct ieee80211_qos_parameters def_parameters_CCK = {
106 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
107 DEF_TX3_CW_MIN_CCK},
108 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
109 DEF_TX3_CW_MAX_CCK},
110 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
111 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
112 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
113 DEF_TX3_TXOP_LIMIT_CCK}
114};
115
116static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
117
118static int from_priority_to_tx_queue[] = {
119 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
120 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
121};
122
123static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
124
125static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
126 *qos_param);
127static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
128 *qos_param);
129#endif /* CONFIG_IPW_QOS */
130
Benoit Boissinot97a78ca2005-09-15 17:30:28 +0000131static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
James Ketrenosb095c382005-08-24 22:04:42 -0500132static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600133static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400134static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600135 struct clx2_tx_queue *txq, int qindex);
136static int ipw_queue_reset(struct ipw_priv *priv);
137
138static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
139 int len, int sync);
140
141static void ipw_tx_queue_free(struct ipw_priv *);
142
143static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
144static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
145static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600146static int ipw_up(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500147static void ipw_bg_up(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600148static void ipw_down(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500149static void ipw_bg_down(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600150static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400151static int init_supported_rates(struct ipw_priv *priv,
152 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500153static void ipw_set_hwcrypto_keys(struct ipw_priv *);
154static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600155
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500156static int snprint_line(char *buf, size_t count,
157 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600158{
159 int out, i, j, l;
160 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400161
James Ketrenos43f66a62005-03-25 12:31:53 -0600162 out = snprintf(buf, count, "%08X", ofs);
163
164 for (l = 0, i = 0; i < 2; i++) {
165 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400166 for (j = 0; j < 8 && l < len; j++, l++)
167 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600168 data[(i * 8 + j)]);
169 for (; j < 8; j++)
170 out += snprintf(buf + out, count - out, " ");
171 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400172
James Ketrenos43f66a62005-03-25 12:31:53 -0600173 out += snprintf(buf + out, count - out, " ");
174 for (l = 0, i = 0; i < 2; i++) {
175 out += snprintf(buf + out, count - out, " ");
176 for (j = 0; j < 8 && l < len; j++, l++) {
177 c = data[(i * 8 + j)];
178 if (!isascii(c) || !isprint(c))
179 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400180
James Ketrenos43f66a62005-03-25 12:31:53 -0600181 out += snprintf(buf + out, count - out, "%c", c);
182 }
183
184 for (; j < 8; j++)
185 out += snprintf(buf + out, count - out, " ");
186 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400187
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500188 return out;
James Ketrenos43f66a62005-03-25 12:31:53 -0600189}
190
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400191static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600192{
193 char line[81];
194 u32 ofs = 0;
195 if (!(ipw_debug_level & level))
196 return;
197
198 while (len) {
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500199 snprint_line(line, sizeof(line), &data[ofs],
200 min(len, 16U), ofs);
201 printk(KERN_DEBUG "%s\n", line);
James Ketrenos43f66a62005-03-25 12:31:53 -0600202 ofs += 16;
203 len -= min(len, 16U);
204 }
205}
206
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500207static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
208{
209 size_t out = size;
210 u32 ofs = 0;
211 int total = 0;
212
213 while (size && len) {
214 out = snprint_line(output, size, &data[ofs],
215 min_t(size_t, len, 16U), ofs);
216
217 ofs += 16;
218 output += out;
219 size -= out;
220 len -= min_t(size_t, len, 16U);
221 total += out;
222 }
223 return total;
224}
225
Zhu Yic8fe6672006-01-24 16:36:36 +0800226/* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600227static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
228#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
229
Zhu Yic8fe6672006-01-24 16:36:36 +0800230/* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600231static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
232#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
233
Zhu Yic8fe6672006-01-24 16:36:36 +0800234/* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600235static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
236static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
237{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400238 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
239 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600240 _ipw_write_reg8(a, b, c);
241}
242
Zhu Yic8fe6672006-01-24 16:36:36 +0800243/* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600244static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
245static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
246{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400247 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
248 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600249 _ipw_write_reg16(a, b, c);
250}
251
Zhu Yic8fe6672006-01-24 16:36:36 +0800252/* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600253static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
254static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
255{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400256 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
257 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600258 _ipw_write_reg32(a, b, c);
259}
260
Zhu Yic8fe6672006-01-24 16:36:36 +0800261/* 8-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600262#define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800263
264/* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600265#define ipw_write8(ipw, ofs, val) \
266 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
267 _ipw_write8(ipw, ofs, val)
268
Zhu Yic8fe6672006-01-24 16:36:36 +0800269/* 16-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600270#define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800271
272/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600273#define ipw_write16(ipw, ofs, val) \
274 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
275 _ipw_write16(ipw, ofs, val)
276
Zhu Yic8fe6672006-01-24 16:36:36 +0800277/* 32-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600278#define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800279
280/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600281#define ipw_write32(ipw, ofs, val) \
282 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
283 _ipw_write32(ipw, ofs, val)
284
Zhu Yic8fe6672006-01-24 16:36:36 +0800285/* 8-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600286#define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800287
288/* 8-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400289static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
290{
291 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600292 return _ipw_read8(ipw, ofs);
293}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400294
Zhu Yic8fe6672006-01-24 16:36:36 +0800295/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600296#define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
297
Zhu Yic8fe6672006-01-24 16:36:36 +0800298/* 16-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600299#define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800300
301/* 16-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400302static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
303{
304 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600305 return _ipw_read16(ipw, ofs);
306}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400307
Zhu Yic8fe6672006-01-24 16:36:36 +0800308/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600309#define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
310
Zhu Yic8fe6672006-01-24 16:36:36 +0800311/* 32-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600312#define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800313
314/* 32-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400315static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
316{
317 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600318 return _ipw_read32(ipw, ofs);
319}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400320
Zhu Yic8fe6672006-01-24 16:36:36 +0800321/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600322#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
323
Zhu Yic8fe6672006-01-24 16:36:36 +0800324/* multi-byte read (above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600325static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500326static inline void __ipw_read_indirect(const char *f, int l,
327 struct ipw_priv *a, u32 b, u8 * c, int d)
328{
329 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
330 d);
331 _ipw_read_indirect(a, b, c, d);
332}
333
Zhu Yic8fe6672006-01-24 16:36:36 +0800334/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500335#define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600336
Zhu Yic8fe6672006-01-24 16:36:36 +0800337/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400338static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
339 int num);
James Ketrenos43f66a62005-03-25 12:31:53 -0600340#define ipw_write_indirect(a, b, c, d) \
341 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
James Ketrenosafbf30a2005-08-25 00:05:33 -0500342 _ipw_write_indirect(a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600343
Zhu Yic8fe6672006-01-24 16:36:36 +0800344/* 32-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400345static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600346{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400347 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500348 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
349 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600350}
351
Zhu Yic8fe6672006-01-24 16:36:36 +0800352/* 8-bit indirect write (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600353static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
354{
Zhu Yi2638bc32006-01-24 16:37:52 +0800355 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800356 u32 dif_len = reg - aligned_addr;
357
James Ketrenos43f66a62005-03-25 12:31:53 -0600358 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800359 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
360 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600361}
362
Zhu Yic8fe6672006-01-24 16:36:36 +0800363/* 16-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400364static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600365{
Zhu Yi2638bc32006-01-24 16:37:52 +0800366 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800367 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
368
James Ketrenos43f66a62005-03-25 12:31:53 -0600369 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800370 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
371 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600372}
373
Zhu Yic8fe6672006-01-24 16:36:36 +0800374/* 8-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600375static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
376{
377 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500378 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -0600379 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500380 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400381 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600382}
383
Zhu Yic8fe6672006-01-24 16:36:36 +0800384/* 32-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600385static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
386{
387 u32 value;
388
389 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
390
James Ketrenosb095c382005-08-24 22:04:42 -0500391 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
392 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
James Ketrenos43f66a62005-03-25 12:31:53 -0600393 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
394 return value;
395}
396
Zhu Yic8fe6672006-01-24 16:36:36 +0800397/* General purpose, no alignment requirement, iterative (multi-byte) read, */
398/* for area above 1st 4K of SRAM/reg space */
James Ketrenos43f66a62005-03-25 12:31:53 -0600399static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
400 int num)
401{
Zhu Yi2638bc32006-01-24 16:37:52 +0800402 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600403 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600404 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400405
James Ketrenos43f66a62005-03-25 12:31:53 -0600406 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
407
James Ketrenosea2b26e2005-08-24 21:25:16 -0500408 if (num <= 0) {
409 return;
410 }
411
Zhu Yic8fe6672006-01-24 16:36:36 +0800412 /* Read the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600413 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500414 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600415 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500416 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500417 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600418 aligned_addr += 4;
419 }
420
Zhu Yic8fe6672006-01-24 16:36:36 +0800421 /* Read all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500422 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500423 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500424 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400425
Zhu Yic8fe6672006-01-24 16:36:36 +0800426 /* Read the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500427 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500428 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500429 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500430 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500431 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600432}
433
Zhu Yic8fe6672006-01-24 16:36:36 +0800434/* General purpose, no alignment requirement, iterative (multi-byte) write, */
435/* for area above 1st 4K of SRAM/reg space */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400436static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600437 int num)
438{
Zhu Yi2638bc32006-01-24 16:37:52 +0800439 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600440 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600441 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400442
James Ketrenos43f66a62005-03-25 12:31:53 -0600443 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400444
James Ketrenosea2b26e2005-08-24 21:25:16 -0500445 if (num <= 0) {
446 return;
447 }
448
Zhu Yic8fe6672006-01-24 16:36:36 +0800449 /* Write the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600450 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500451 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
Zhu Yic8fe6672006-01-24 16:36:36 +0800452 /* Start writing at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500453 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500454 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600455 aligned_addr += 4;
456 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400457
Zhu Yic8fe6672006-01-24 16:36:36 +0800458 /* Write all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500459 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500460 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500461 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400462
Zhu Yic8fe6672006-01-24 16:36:36 +0800463 /* Write the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500464 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500465 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500466 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500467 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500468 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600469}
470
Zhu Yic8fe6672006-01-24 16:36:36 +0800471/* General purpose, no alignment requirement, iterative (multi-byte) write, */
472/* for 1st 4K of SRAM/regs space */
Jeff Garzikbf794512005-07-31 13:07:26 -0400473static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600474 int num)
475{
476 memcpy_toio((priv->hw_base + addr), buf, num);
477}
478
Zhu Yic8fe6672006-01-24 16:36:36 +0800479/* Set bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600480static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
481{
482 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
483}
484
Zhu Yic8fe6672006-01-24 16:36:36 +0800485/* Clear bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600486static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
487{
488 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
489}
490
491static inline void ipw_enable_interrupts(struct ipw_priv *priv)
492{
493 if (priv->status & STATUS_INT_ENABLED)
494 return;
495 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500496 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600497}
498
499static inline void ipw_disable_interrupts(struct ipw_priv *priv)
500{
501 if (!(priv->status & STATUS_INT_ENABLED))
502 return;
503 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500504 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600505}
506
Brice Goglin0f52bf92005-12-01 01:41:46 -0800507#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -0600508static char *ipw_error_desc(u32 val)
509{
510 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400511 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600512 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400513 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600514 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400515 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600516 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400517 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600518 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400519 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500520 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400521 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500522 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400523 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500524 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400525 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500526 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400527 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500528 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400529 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500530 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400531 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500532 return "DMA_STATUS";
533 case IPW_FW_ERROR_DINO_ERROR:
534 return "DINO_ERROR";
535 case IPW_FW_ERROR_EEPROM_ERROR:
536 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400537 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500538 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400539 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500540 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400541 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500542 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600543 }
544}
545
James Ketrenosb39860c2005-08-12 09:36:32 -0500546static void ipw_dump_error_log(struct ipw_priv *priv,
547 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600548{
James Ketrenosb39860c2005-08-12 09:36:32 -0500549 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600550
James Ketrenosb39860c2005-08-12 09:36:32 -0500551 if (!error) {
552 IPW_ERROR("Error allocating and capturing error log. "
553 "Nothing to dump.\n");
554 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600555 }
556
James Ketrenosb39860c2005-08-12 09:36:32 -0500557 IPW_ERROR("Start IPW Error Log Dump:\n");
558 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
559 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600560
James Ketrenosb39860c2005-08-12 09:36:32 -0500561 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400562 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500563 ipw_error_desc(error->elem[i].desc),
564 error->elem[i].time,
565 error->elem[i].blink1,
566 error->elem[i].blink2,
567 error->elem[i].link1,
568 error->elem[i].link2, error->elem[i].data);
569 for (i = 0; i < error->log_len; i++)
570 IPW_ERROR("%i\t0x%08x\t%i\n",
571 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500572 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600573}
James Ketrenos43f66a62005-03-25 12:31:53 -0600574#endif
James Ketrenos43f66a62005-03-25 12:31:53 -0600575
James Ketrenosc848d0a2005-08-24 21:56:24 -0500576static inline int ipw_is_init(struct ipw_priv *priv)
577{
578 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600579}
580
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400581static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600582{
583 u32 addr, field_info, field_len, field_count, total_len;
584
585 IPW_DEBUG_ORD("ordinal = %i\n", ord);
586
587 if (!priv || !val || !len) {
588 IPW_DEBUG_ORD("Invalid argument\n");
589 return -EINVAL;
590 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400591
James Ketrenos43f66a62005-03-25 12:31:53 -0600592 /* verify device ordinal tables have been initialized */
593 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
594 IPW_DEBUG_ORD("Access ordinals before initialization\n");
595 return -EINVAL;
596 }
597
598 switch (IPW_ORD_TABLE_ID_MASK & ord) {
599 case IPW_ORD_TABLE_0_MASK:
600 /*
601 * TABLE 0: Direct access to a table of 32 bit values
602 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400603 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600604 * read from the table
605 */
606
607 /* remove the table id from the ordinal */
608 ord &= IPW_ORD_TABLE_VALUE_MASK;
609
610 /* boundary check */
611 if (ord > priv->table0_len) {
612 IPW_DEBUG_ORD("ordinal value (%i) longer then "
613 "max (%i)\n", ord, priv->table0_len);
614 return -EINVAL;
615 }
616
617 /* verify we have enough room to store the value */
618 if (*len < sizeof(u32)) {
619 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200620 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600621 return -EINVAL;
622 }
623
624 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400625 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600626
627 *len = sizeof(u32);
628 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400629 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600630 break;
631
632 case IPW_ORD_TABLE_1_MASK:
633 /*
634 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400635 *
636 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600637 * representing starting addr for the data (which is
638 * also a u32)
639 */
640
641 /* remove the table id from the ordinal */
642 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400643
James Ketrenos43f66a62005-03-25 12:31:53 -0600644 /* boundary check */
645 if (ord > priv->table1_len) {
646 IPW_DEBUG_ORD("ordinal value too long\n");
647 return -EINVAL;
648 }
649
650 /* verify we have enough room to store the value */
651 if (*len < sizeof(u32)) {
652 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200653 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600654 return -EINVAL;
655 }
656
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400657 *((u32 *) val) =
658 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600659 *len = sizeof(u32);
660 break;
661
662 case IPW_ORD_TABLE_2_MASK:
663 /*
664 * TABLE 2: Indirect access to a table of variable sized values
665 *
666 * This table consist of six values, each containing
667 * - dword containing the starting offset of the data
668 * - dword containing the lengh in the first 16bits
669 * and the count in the second 16bits
670 */
671
672 /* remove the table id from the ordinal */
673 ord &= IPW_ORD_TABLE_VALUE_MASK;
674
675 /* boundary check */
676 if (ord > priv->table2_len) {
677 IPW_DEBUG_ORD("ordinal value too long\n");
678 return -EINVAL;
679 }
680
681 /* get the address of statistic */
682 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400683
684 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600685 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400686 field_info =
687 ipw_read_reg32(priv,
688 priv->table2_addr + (ord << 3) +
689 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400690
James Ketrenos43f66a62005-03-25 12:31:53 -0600691 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400692 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400693
James Ketrenos43f66a62005-03-25 12:31:53 -0600694 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400695 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400696
James Ketrenos43f66a62005-03-25 12:31:53 -0600697 /* abort if not enought memory */
698 total_len = field_len * field_count;
699 if (total_len > *len) {
700 *len = total_len;
701 return -EINVAL;
702 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400703
James Ketrenos43f66a62005-03-25 12:31:53 -0600704 *len = total_len;
705 if (!total_len)
706 return 0;
707
708 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400709 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600710 addr, total_len, field_info);
711 ipw_read_indirect(priv, addr, val, total_len);
712 break;
713
714 default:
715 IPW_DEBUG_ORD("Invalid ordinal!\n");
716 return -EINVAL;
717
718 }
719
James Ketrenos43f66a62005-03-25 12:31:53 -0600720 return 0;
721}
722
723static void ipw_init_ordinals(struct ipw_priv *priv)
724{
725 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400726 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600727
728 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
729 priv->table0_addr, priv->table0_len);
730
731 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
732 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
733
734 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
735 priv->table1_addr, priv->table1_len);
736
737 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
738 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400739 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600740
741 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
742 priv->table2_addr, priv->table2_len);
743
744}
745
Adrian Bunka73e22b2006-01-21 01:39:42 +0100746static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500747{
James Ketrenosb095c382005-08-24 22:04:42 -0500748 reg &= ~IPW_START_STANDBY;
749 if (reg & IPW_GATE_ODMA)
750 reg &= ~IPW_GATE_ODMA;
751 if (reg & IPW_GATE_IDMA)
752 reg &= ~IPW_GATE_IDMA;
753 if (reg & IPW_GATE_ADMA)
754 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500755 return reg;
756}
757
758/*
759 * LED behavior:
760 * - On radio ON, turn on any LEDs that require to be on during start
761 * - On initialization, start unassociated blink
762 * - On association, disable unassociated blink
763 * - On disassociation, start unassociated blink
764 * - On radio OFF, turn off any LEDs started during radio on
765 *
766 */
Zhu Yiede61112006-01-24 16:37:10 +0800767#define LD_TIME_LINK_ON msecs_to_jiffies(300)
768#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
769#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500770
Adrian Bunka73e22b2006-01-21 01:39:42 +0100771static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500772{
773 unsigned long flags;
774 u32 led;
775
776 /* If configured to not use LEDs, or nic_type is 1,
777 * then we don't toggle a LINK led */
778 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
779 return;
780
781 spin_lock_irqsave(&priv->lock, flags);
782
783 if (!(priv->status & STATUS_RF_KILL_MASK) &&
784 !(priv->status & STATUS_LED_LINK_ON)) {
785 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500786 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500787 led |= priv->led_association_on;
788
789 led = ipw_register_toggle(led);
790
791 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500792 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500793
794 priv->status |= STATUS_LED_LINK_ON;
795
796 /* If we aren't associated, schedule turning the LED off */
797 if (!(priv->status & STATUS_ASSOCIATED))
798 queue_delayed_work(priv->workqueue,
799 &priv->led_link_off,
800 LD_TIME_LINK_ON);
801 }
802
803 spin_unlock_irqrestore(&priv->lock, flags);
804}
805
James Ketrenosc848d0a2005-08-24 21:56:24 -0500806static void ipw_bg_led_link_on(void *data)
807{
808 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800809 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500810 ipw_led_link_on(data);
Zhu Yi46441512006-01-24 16:37:59 +0800811 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500812}
813
Adrian Bunka73e22b2006-01-21 01:39:42 +0100814static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500815{
816 unsigned long flags;
817 u32 led;
818
819 /* If configured not to use LEDs, or nic type is 1,
820 * then we don't goggle the LINK led. */
821 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
822 return;
823
824 spin_lock_irqsave(&priv->lock, flags);
825
826 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500827 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500828 led &= priv->led_association_off;
829 led = ipw_register_toggle(led);
830
831 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500832 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500833
834 IPW_DEBUG_LED("Link LED Off\n");
835
836 priv->status &= ~STATUS_LED_LINK_ON;
837
838 /* If we aren't associated and the radio is on, schedule
839 * turning the LED on (blink while unassociated) */
840 if (!(priv->status & STATUS_RF_KILL_MASK) &&
841 !(priv->status & STATUS_ASSOCIATED))
842 queue_delayed_work(priv->workqueue, &priv->led_link_on,
843 LD_TIME_LINK_OFF);
844
845 }
846
847 spin_unlock_irqrestore(&priv->lock, flags);
848}
849
James Ketrenosc848d0a2005-08-24 21:56:24 -0500850static void ipw_bg_led_link_off(void *data)
851{
852 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800853 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500854 ipw_led_link_off(data);
Zhu Yi46441512006-01-24 16:37:59 +0800855 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500856}
857
Arjan van de Ven858119e2006-01-14 13:20:43 -0800858static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500859{
James Ketrenosa613bff2005-08-24 21:43:11 -0500860 u32 led;
861
862 if (priv->config & CFG_NO_LED)
863 return;
864
James Ketrenosb095c382005-08-24 22:04:42 -0500865 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500866 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500867
868 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500869 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500870 led |= priv->led_activity_on;
871
872 led = ipw_register_toggle(led);
873
874 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500875 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500876
877 IPW_DEBUG_LED("Activity LED On\n");
878
879 priv->status |= STATUS_LED_ACT_ON;
880
James Ketrenosc848d0a2005-08-24 21:56:24 -0500881 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500882 queue_delayed_work(priv->workqueue, &priv->led_act_off,
883 LD_TIME_ACT_ON);
884 } else {
885 /* Reschedule LED off for full time period */
886 cancel_delayed_work(&priv->led_act_off);
887 queue_delayed_work(priv->workqueue, &priv->led_act_off,
888 LD_TIME_ACT_ON);
889 }
James Ketrenosb095c382005-08-24 22:04:42 -0500890}
James Ketrenosa613bff2005-08-24 21:43:11 -0500891
Adrian Bunka73e22b2006-01-21 01:39:42 +0100892#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500893void ipw_led_activity_on(struct ipw_priv *priv)
894{
895 unsigned long flags;
896 spin_lock_irqsave(&priv->lock, flags);
897 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500898 spin_unlock_irqrestore(&priv->lock, flags);
899}
Adrian Bunka73e22b2006-01-21 01:39:42 +0100900#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -0500901
Adrian Bunka73e22b2006-01-21 01:39:42 +0100902static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500903{
904 unsigned long flags;
905 u32 led;
906
907 if (priv->config & CFG_NO_LED)
908 return;
909
910 spin_lock_irqsave(&priv->lock, flags);
911
912 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500913 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500914 led &= priv->led_activity_off;
915
916 led = ipw_register_toggle(led);
917
918 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500919 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500920
921 IPW_DEBUG_LED("Activity LED Off\n");
922
923 priv->status &= ~STATUS_LED_ACT_ON;
924 }
925
926 spin_unlock_irqrestore(&priv->lock, flags);
927}
928
James Ketrenosc848d0a2005-08-24 21:56:24 -0500929static void ipw_bg_led_activity_off(void *data)
930{
931 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800932 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500933 ipw_led_activity_off(data);
Zhu Yi46441512006-01-24 16:37:59 +0800934 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500935}
936
Adrian Bunka73e22b2006-01-21 01:39:42 +0100937static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500938{
939 unsigned long flags;
940 u32 led;
941
942 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -0500943 if (priv->config & CFG_NO_LED ||
944 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -0500945 return;
946
947 spin_lock_irqsave(&priv->lock, flags);
948
James Ketrenosb095c382005-08-24 22:04:42 -0500949 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500950 if (priv->assoc_network->mode == IEEE_A) {
951 led |= priv->led_ofdm_on;
952 led &= priv->led_association_off;
953 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
954 } else if (priv->assoc_network->mode == IEEE_G) {
955 led |= priv->led_ofdm_on;
956 led |= priv->led_association_on;
957 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
958 } else {
959 led &= priv->led_ofdm_off;
960 led |= priv->led_association_on;
961 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
962 }
963
964 led = ipw_register_toggle(led);
965
966 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500967 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500968
969 spin_unlock_irqrestore(&priv->lock, flags);
970}
971
Adrian Bunka73e22b2006-01-21 01:39:42 +0100972static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500973{
974 unsigned long flags;
975 u32 led;
976
977 /* Only nic type 1 supports mode LEDs */
978 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
979 return;
980
981 spin_lock_irqsave(&priv->lock, flags);
982
James Ketrenosb095c382005-08-24 22:04:42 -0500983 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500984 led &= priv->led_ofdm_off;
985 led &= priv->led_association_off;
986
987 led = ipw_register_toggle(led);
988
989 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500990 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500991
992 spin_unlock_irqrestore(&priv->lock, flags);
993}
994
Adrian Bunka73e22b2006-01-21 01:39:42 +0100995static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500996{
997 ipw_led_link_on(priv);
998}
999
Adrian Bunka73e22b2006-01-21 01:39:42 +01001000static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001001{
1002 ipw_led_activity_off(priv);
1003 ipw_led_link_off(priv);
1004}
1005
Adrian Bunka73e22b2006-01-21 01:39:42 +01001006static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001007{
1008 /* Set the Link Led on for all nic types */
1009 ipw_led_link_on(priv);
1010}
1011
Adrian Bunka73e22b2006-01-21 01:39:42 +01001012static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001013{
1014 ipw_led_activity_off(priv);
1015 ipw_led_link_off(priv);
1016
1017 if (priv->status & STATUS_RF_KILL_MASK)
1018 ipw_led_radio_off(priv);
1019}
1020
Adrian Bunka73e22b2006-01-21 01:39:42 +01001021static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001022{
1023 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1024
1025 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001026 priv->led_activity_on = IPW_ACTIVITY_LED;
1027 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001028
James Ketrenosb095c382005-08-24 22:04:42 -05001029 priv->led_association_on = IPW_ASSOCIATED_LED;
1030 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001031
1032 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001033 priv->led_ofdm_on = IPW_OFDM_LED;
1034 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001035
1036 switch (priv->nic_type) {
1037 case EEPROM_NIC_TYPE_1:
1038 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001039 priv->led_activity_on = IPW_ASSOCIATED_LED;
1040 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1041 priv->led_association_on = IPW_ACTIVITY_LED;
1042 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001043
1044 if (!(priv->config & CFG_NO_LED))
1045 ipw_led_band_on(priv);
1046
1047 /* And we don't blink link LEDs for this nic, so
1048 * just return here */
1049 return;
1050
1051 case EEPROM_NIC_TYPE_3:
1052 case EEPROM_NIC_TYPE_2:
1053 case EEPROM_NIC_TYPE_4:
1054 case EEPROM_NIC_TYPE_0:
1055 break;
1056
1057 default:
1058 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1059 priv->nic_type);
1060 priv->nic_type = EEPROM_NIC_TYPE_0;
1061 break;
1062 }
1063
1064 if (!(priv->config & CFG_NO_LED)) {
1065 if (priv->status & STATUS_ASSOCIATED)
1066 ipw_led_link_on(priv);
1067 else
1068 ipw_led_link_off(priv);
1069 }
1070}
1071
Adrian Bunka73e22b2006-01-21 01:39:42 +01001072static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001073{
James Ketrenosa613bff2005-08-24 21:43:11 -05001074 ipw_led_activity_off(priv);
1075 ipw_led_link_off(priv);
1076 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001077 cancel_delayed_work(&priv->led_link_on);
1078 cancel_delayed_work(&priv->led_link_off);
1079 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001080}
1081
James Ketrenos43f66a62005-03-25 12:31:53 -06001082/*
1083 * The following adds a new attribute to the sysfs representation
1084 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1085 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001086 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001087 * See the level definitions in ipw for details.
1088 */
1089static ssize_t show_debug_level(struct device_driver *d, char *buf)
1090{
1091 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1092}
James Ketrenosa613bff2005-08-24 21:43:11 -05001093
1094static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1095 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001096{
1097 char *p = (char *)buf;
1098 u32 val;
1099
1100 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1101 p++;
1102 if (p[0] == 'x' || p[0] == 'X')
1103 p++;
1104 val = simple_strtoul(p, &p, 16);
1105 } else
1106 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001107 if (p == buf)
1108 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001109 ": %s is not in hex or decimal form.\n", buf);
1110 else
1111 ipw_debug_level = val;
1112
1113 return strnlen(buf, count);
1114}
1115
Jeff Garzikbf794512005-07-31 13:07:26 -04001116static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001117 show_debug_level, store_debug_level);
1118
James Ketrenosb39860c2005-08-12 09:36:32 -05001119static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1120{
Zhu Yic8fe6672006-01-24 16:36:36 +08001121 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001122 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1123}
1124
1125static void ipw_capture_event_log(struct ipw_priv *priv,
1126 u32 log_len, struct ipw_event *log)
1127{
1128 u32 base;
1129
1130 if (log_len) {
1131 base = ipw_read32(priv, IPW_EVENT_LOG);
1132 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1133 (u8 *) log, sizeof(*log) * log_len);
1134 }
1135}
1136
1137static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1138{
1139 struct ipw_fw_error *error;
1140 u32 log_len = ipw_get_event_log_len(priv);
1141 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1142 u32 elem_len = ipw_read_reg32(priv, base);
1143
1144 error = kmalloc(sizeof(*error) +
1145 sizeof(*error->elem) * elem_len +
1146 sizeof(*error->log) * log_len, GFP_ATOMIC);
1147 if (!error) {
1148 IPW_ERROR("Memory allocation for firmware error log "
1149 "failed.\n");
1150 return NULL;
1151 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001152 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001153 error->status = priv->status;
1154 error->config = priv->config;
1155 error->elem_len = elem_len;
1156 error->log_len = log_len;
1157 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001158 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001159
1160 ipw_capture_event_log(priv, log_len, error->log);
1161
1162 if (elem_len)
1163 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1164 sizeof(*error->elem) * elem_len);
1165
1166 return error;
1167}
1168
1169static void ipw_free_error_log(struct ipw_fw_error *error)
1170{
1171 if (error)
1172 kfree(error);
1173}
1174
1175static ssize_t show_event_log(struct device *d,
1176 struct device_attribute *attr, char *buf)
1177{
1178 struct ipw_priv *priv = dev_get_drvdata(d);
1179 u32 log_len = ipw_get_event_log_len(priv);
1180 struct ipw_event log[log_len];
1181 u32 len = 0, i;
1182
1183 ipw_capture_event_log(priv, log_len, log);
1184
1185 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1186 for (i = 0; i < log_len; i++)
1187 len += snprintf(buf + len, PAGE_SIZE - len,
1188 "\n%08X%08X%08X",
1189 log[i].time, log[i].event, log[i].data);
1190 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1191 return len;
1192}
1193
1194static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1195
1196static ssize_t show_error(struct device *d,
1197 struct device_attribute *attr, char *buf)
1198{
1199 struct ipw_priv *priv = dev_get_drvdata(d);
1200 u32 len = 0, i;
1201 if (!priv->error)
1202 return 0;
1203 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001204 "%08lX%08X%08X%08X",
1205 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001206 priv->error->status,
1207 priv->error->config, priv->error->elem_len);
1208 for (i = 0; i < priv->error->elem_len; i++)
1209 len += snprintf(buf + len, PAGE_SIZE - len,
1210 "\n%08X%08X%08X%08X%08X%08X%08X",
1211 priv->error->elem[i].time,
1212 priv->error->elem[i].desc,
1213 priv->error->elem[i].blink1,
1214 priv->error->elem[i].blink2,
1215 priv->error->elem[i].link1,
1216 priv->error->elem[i].link2,
1217 priv->error->elem[i].data);
1218
1219 len += snprintf(buf + len, PAGE_SIZE - len,
1220 "\n%08X", priv->error->log_len);
1221 for (i = 0; i < priv->error->log_len; i++)
1222 len += snprintf(buf + len, PAGE_SIZE - len,
1223 "\n%08X%08X%08X",
1224 priv->error->log[i].time,
1225 priv->error->log[i].event,
1226 priv->error->log[i].data);
1227 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1228 return len;
1229}
1230
1231static ssize_t clear_error(struct device *d,
1232 struct device_attribute *attr,
1233 const char *buf, size_t count)
1234{
1235 struct ipw_priv *priv = dev_get_drvdata(d);
1236 if (priv->error) {
1237 ipw_free_error_log(priv->error);
1238 priv->error = NULL;
1239 }
1240 return count;
1241}
1242
1243static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1244
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001245static ssize_t show_cmd_log(struct device *d,
1246 struct device_attribute *attr, char *buf)
1247{
1248 struct ipw_priv *priv = dev_get_drvdata(d);
1249 u32 len = 0, i;
1250 if (!priv->cmdlog)
1251 return 0;
1252 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1253 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1254 i = (i + 1) % priv->cmdlog_len) {
1255 len +=
1256 snprintf(buf + len, PAGE_SIZE - len,
1257 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1258 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1259 priv->cmdlog[i].cmd.len);
1260 len +=
1261 snprintk_buf(buf + len, PAGE_SIZE - len,
1262 (u8 *) priv->cmdlog[i].cmd.param,
1263 priv->cmdlog[i].cmd.len);
1264 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1265 }
1266 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1267 return len;
1268}
1269
1270static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1271
James Ketrenosa613bff2005-08-24 21:43:11 -05001272static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1273 char *buf)
1274{
1275 struct ipw_priv *priv = dev_get_drvdata(d);
1276 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1277}
1278
1279static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1280 const char *buf, size_t count)
1281{
1282 struct ipw_priv *priv = dev_get_drvdata(d);
Brice Goglin0f52bf92005-12-01 01:41:46 -08001283#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosa613bff2005-08-24 21:43:11 -05001284 struct net_device *dev = priv->net_dev;
James Ketrenosc848d0a2005-08-24 21:56:24 -05001285#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05001286 char buffer[] = "00000000";
1287 unsigned long len =
1288 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1289 unsigned long val;
1290 char *p = buffer;
1291
1292 IPW_DEBUG_INFO("enter\n");
1293
1294 strncpy(buffer, buf, len);
1295 buffer[len] = 0;
1296
1297 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1298 p++;
1299 if (p[0] == 'x' || p[0] == 'X')
1300 p++;
1301 val = simple_strtoul(p, &p, 16);
1302 } else
1303 val = simple_strtoul(p, &p, 10);
1304 if (p == buffer) {
1305 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1306 } else {
1307 priv->ieee->scan_age = val;
1308 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1309 }
1310
1311 IPW_DEBUG_INFO("exit\n");
1312 return len;
1313}
1314
1315static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1316
1317static ssize_t show_led(struct device *d, struct device_attribute *attr,
1318 char *buf)
1319{
1320 struct ipw_priv *priv = dev_get_drvdata(d);
1321 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1322}
1323
1324static ssize_t store_led(struct device *d, struct device_attribute *attr,
1325 const char *buf, size_t count)
1326{
1327 struct ipw_priv *priv = dev_get_drvdata(d);
1328
1329 IPW_DEBUG_INFO("enter\n");
1330
1331 if (count == 0)
1332 return 0;
1333
1334 if (*buf == 0) {
1335 IPW_DEBUG_LED("Disabling LED control.\n");
1336 priv->config |= CFG_NO_LED;
1337 ipw_led_shutdown(priv);
1338 } else {
1339 IPW_DEBUG_LED("Enabling LED control.\n");
1340 priv->config &= ~CFG_NO_LED;
1341 ipw_led_init(priv);
1342 }
1343
1344 IPW_DEBUG_INFO("exit\n");
1345 return count;
1346}
1347
1348static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1349
Andrew Mortonad3fee52005-06-20 14:30:36 -07001350static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001351 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001352{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001353 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001354 return sprintf(buf, "0x%08x\n", (int)p->status);
1355}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001356
James Ketrenos43f66a62005-03-25 12:31:53 -06001357static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1358
Andrew Mortonad3fee52005-06-20 14:30:36 -07001359static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1360 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001361{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001362 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001363 return sprintf(buf, "0x%08x\n", (int)p->config);
1364}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001365
James Ketrenos43f66a62005-03-25 12:31:53 -06001366static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1367
Andrew Mortonad3fee52005-06-20 14:30:36 -07001368static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001369 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001370{
James Ketrenosa613bff2005-08-24 21:43:11 -05001371 struct ipw_priv *priv = d->driver_data;
1372 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001373}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001374
James Ketrenos43f66a62005-03-25 12:31:53 -06001375static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1376
Andrew Mortonad3fee52005-06-20 14:30:36 -07001377static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001378 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001379{
1380 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001381 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001382
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001383 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001384 return 0;
1385
1386 return sprintf(buf, "0x%08x\n", tmp);
1387}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001388
1389static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001390
Andrew Mortonad3fee52005-06-20 14:30:36 -07001391static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1392 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001393{
1394 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001395 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001396
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001397 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001398 return 0;
1399
1400 return sprintf(buf, "0x%08x\n", tmp);
1401}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001402
1403static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001404
1405/*
1406 * Add a device attribute to view/control the delay between eeprom
1407 * operations.
1408 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001409static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001410 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001411{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001412 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001413 return sprintf(buf, "%i\n", n);
1414}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001415static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001416 struct device_attribute *attr,
1417 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001418{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001419 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001420 sscanf(buf, "%i", &p->eeprom_delay);
1421 return strnlen(buf, count);
1422}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001423
1424static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1425 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001426
Andrew Mortonad3fee52005-06-20 14:30:36 -07001427static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001428 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001429{
1430 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001431 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001432
James Ketrenosb095c382005-08-24 22:04:42 -05001433 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001434 return sprintf(buf, "0x%08x\n", reg);
1435}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001436static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001437 struct device_attribute *attr,
1438 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001439{
1440 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001441 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001442
1443 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001444 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001445 return strnlen(buf, count);
1446}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001447
1448static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1449 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001450
Andrew Mortonad3fee52005-06-20 14:30:36 -07001451static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001452 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001453{
1454 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001455 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001456
1457 reg = ipw_read_reg32(p, 0x301100);
1458 return sprintf(buf, "0x%08x\n", reg);
1459}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001460static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001461 struct device_attribute *attr,
1462 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001463{
1464 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001465 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001466
1467 sscanf(buf, "%x", &reg);
1468 ipw_write_reg32(p, 0x301100, reg);
1469 return strnlen(buf, count);
1470}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001471
1472static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1473 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001474
Andrew Mortonad3fee52005-06-20 14:30:36 -07001475static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001476 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001477{
1478 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001479 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001480
Jeff Garzikbf794512005-07-31 13:07:26 -04001481 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001482 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001483 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001484 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001485
James Ketrenos43f66a62005-03-25 12:31:53 -06001486 return sprintf(buf, "0x%08x\n", reg);
1487}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001488static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001489 struct device_attribute *attr,
1490 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001491{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001492 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001493
1494 sscanf(buf, "%x", &priv->indirect_dword);
1495 priv->status |= STATUS_INDIRECT_DWORD;
1496 return strnlen(buf, count);
1497}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001498
1499static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1500 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001501
Andrew Mortonad3fee52005-06-20 14:30:36 -07001502static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001503 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001504{
1505 u8 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001506 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001507
Jeff Garzikbf794512005-07-31 13:07:26 -04001508 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001509 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001510 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001511 reg = 0;
1512
1513 return sprintf(buf, "0x%02x\n", reg);
1514}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001515static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001516 struct device_attribute *attr,
1517 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001518{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001519 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001520
1521 sscanf(buf, "%x", &priv->indirect_byte);
1522 priv->status |= STATUS_INDIRECT_BYTE;
1523 return strnlen(buf, count);
1524}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001525
1526static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001527 show_indirect_byte, store_indirect_byte);
1528
Andrew Mortonad3fee52005-06-20 14:30:36 -07001529static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001530 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001531{
1532 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001533 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001534
Jeff Garzikbf794512005-07-31 13:07:26 -04001535 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001536 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001537 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001538 reg = 0;
1539
1540 return sprintf(buf, "0x%08x\n", reg);
1541}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001542static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001543 struct device_attribute *attr,
1544 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001545{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001546 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001547
1548 sscanf(buf, "%x", &priv->direct_dword);
1549 priv->status |= STATUS_DIRECT_DWORD;
1550 return strnlen(buf, count);
1551}
James Ketrenos43f66a62005-03-25 12:31:53 -06001552
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001553static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1554 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001555
Arjan van de Ven858119e2006-01-14 13:20:43 -08001556static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001557{
1558 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1559 priv->status |= STATUS_RF_KILL_HW;
1560 else
1561 priv->status &= ~STATUS_RF_KILL_HW;
1562
1563 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1564}
1565
Andrew Mortonad3fee52005-06-20 14:30:36 -07001566static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001567 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001568{
1569 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001570 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001571 2 - HW based RF kill active
1572 3 - Both HW and SW baed RF kill active */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001573 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001574 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001575 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001576 return sprintf(buf, "%i\n", val);
1577}
1578
1579static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1580{
Jeff Garzikbf794512005-07-31 13:07:26 -04001581 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001582 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001583 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001584
1585 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1586 disable_radio ? "OFF" : "ON");
1587
1588 if (disable_radio) {
1589 priv->status |= STATUS_RF_KILL_SW;
1590
James Ketrenosa613bff2005-08-24 21:43:11 -05001591 if (priv->workqueue)
James Ketrenos43f66a62005-03-25 12:31:53 -06001592 cancel_delayed_work(&priv->request_scan);
James Ketrenos43f66a62005-03-25 12:31:53 -06001593 queue_work(priv->workqueue, &priv->down);
1594 } else {
1595 priv->status &= ~STATUS_RF_KILL_SW;
1596 if (rf_kill_active(priv)) {
1597 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1598 "disabled by HW switch\n");
1599 /* Make sure the RF_KILL check timer is running */
1600 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001601 queue_delayed_work(priv->workqueue, &priv->rf_kill,
James Ketrenos43f66a62005-03-25 12:31:53 -06001602 2 * HZ);
Jeff Garzikbf794512005-07-31 13:07:26 -04001603 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001604 queue_work(priv->workqueue, &priv->up);
1605 }
1606
1607 return 1;
1608}
1609
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001610static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1611 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001612{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001613 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -04001614
James Ketrenos43f66a62005-03-25 12:31:53 -06001615 ipw_radio_kill_sw(priv, buf[0] == '1');
1616
1617 return count;
1618}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001619
1620static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001621
James Ketrenosb095c382005-08-24 22:04:42 -05001622static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1623 char *buf)
1624{
1625 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1626 int pos = 0, len = 0;
1627 if (priv->config & CFG_SPEED_SCAN) {
1628 while (priv->speed_scan[pos] != 0)
1629 len += sprintf(&buf[len], "%d ",
1630 priv->speed_scan[pos++]);
1631 return len + sprintf(&buf[len], "\n");
1632 }
1633
1634 return sprintf(buf, "0\n");
1635}
1636
1637static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1638 const char *buf, size_t count)
1639{
1640 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1641 int channel, pos = 0;
1642 const char *p = buf;
1643
1644 /* list of space separated channels to scan, optionally ending with 0 */
1645 while ((channel = simple_strtol(p, NULL, 0))) {
1646 if (pos == MAX_SPEED_SCAN - 1) {
1647 priv->speed_scan[pos] = 0;
1648 break;
1649 }
1650
Larry Finger1867b112006-02-28 09:48:28 -06001651 if (ieee80211_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001652 priv->speed_scan[pos++] = channel;
1653 else
1654 IPW_WARNING("Skipping invalid channel request: %d\n",
1655 channel);
1656 p = strchr(p, ' ');
1657 if (!p)
1658 break;
1659 while (*p == ' ' || *p == '\t')
1660 p++;
1661 }
1662
1663 if (pos == 0)
1664 priv->config &= ~CFG_SPEED_SCAN;
1665 else {
1666 priv->speed_scan_pos = 0;
1667 priv->config |= CFG_SPEED_SCAN;
1668 }
1669
1670 return count;
1671}
1672
1673static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1674 store_speed_scan);
1675
1676static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1677 char *buf)
1678{
1679 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1680 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1681}
1682
1683static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1684 const char *buf, size_t count)
1685{
1686 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1687 if (buf[0] == '1')
1688 priv->config |= CFG_NET_STATS;
1689 else
1690 priv->config &= ~CFG_NET_STATS;
1691
1692 return count;
1693}
1694
James Ketrenosafbf30a2005-08-25 00:05:33 -05001695static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1696 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001697
James Ketrenosea2b26e2005-08-24 21:25:16 -05001698static void notify_wx_assoc_event(struct ipw_priv *priv)
1699{
1700 union iwreq_data wrqu;
1701 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1702 if (priv->status & STATUS_ASSOCIATED)
1703 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1704 else
1705 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1706 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1707}
1708
James Ketrenos43f66a62005-03-25 12:31:53 -06001709static void ipw_irq_tasklet(struct ipw_priv *priv)
1710{
1711 u32 inta, inta_mask, handled = 0;
1712 unsigned long flags;
1713 int rc = 0;
1714
1715 spin_lock_irqsave(&priv->lock, flags);
1716
James Ketrenosb095c382005-08-24 22:04:42 -05001717 inta = ipw_read32(priv, IPW_INTA_RW);
1718 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1719 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001720
1721 /* Add any cached INTA values that need to be handled */
1722 inta |= priv->isr_inta;
1723
1724 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001725 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001726 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001727 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001728 }
1729
James Ketrenosb095c382005-08-24 22:04:42 -05001730 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001731 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001732 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001733 priv->status &= ~STATUS_HCMD_ACTIVE;
1734 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001735 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001736 }
1737
James Ketrenosb095c382005-08-24 22:04:42 -05001738 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001739 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001740 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05001741 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06001742 }
1743
James Ketrenosb095c382005-08-24 22:04:42 -05001744 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001745 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001746 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05001747 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06001748 }
1749
James Ketrenosb095c382005-08-24 22:04:42 -05001750 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001751 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001752 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05001753 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06001754 }
1755
James Ketrenosb095c382005-08-24 22:04:42 -05001756 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001757 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001758 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05001759 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06001760 }
1761
James Ketrenosb095c382005-08-24 22:04:42 -05001762 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001763 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001764 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001765 }
1766
James Ketrenosb095c382005-08-24 22:04:42 -05001767 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001768 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001769 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06001770 }
1771
James Ketrenosb095c382005-08-24 22:04:42 -05001772 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001773 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001774 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001775 }
1776
James Ketrenosb095c382005-08-24 22:04:42 -05001777 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001778 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001779 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001780 }
1781
James Ketrenosb095c382005-08-24 22:04:42 -05001782 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001783 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001784 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001785 }
1786
James Ketrenosb095c382005-08-24 22:04:42 -05001787 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001788 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1789 priv->status |= STATUS_RF_KILL_HW;
1790 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05001791 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06001792 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05001793 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001794 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05001795 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001796 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001797
James Ketrenosb095c382005-08-24 22:04:42 -05001798 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001799 IPW_ERROR("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001800 if (priv->error) {
1801 IPW_ERROR("Sysfs 'error' log already exists.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001802#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001803 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1804 struct ipw_fw_error *error =
1805 ipw_alloc_error_log(priv);
1806 ipw_dump_error_log(priv, error);
1807 if (error)
1808 ipw_free_error_log(error);
1809 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001810#endif
James Ketrenosb39860c2005-08-12 09:36:32 -05001811 } else {
1812 priv->error = ipw_alloc_error_log(priv);
1813 if (priv->error)
1814 IPW_ERROR("Sysfs 'error' log captured.\n");
1815 else
1816 IPW_ERROR("Error allocating sysfs 'error' "
1817 "log.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001818#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001819 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1820 ipw_dump_error_log(priv, priv->error);
1821#endif
1822 }
1823
James Ketrenosb095c382005-08-24 22:04:42 -05001824 /* XXX: If hardware encryption is for WPA/WPA2,
1825 * we have to notify the supplicant. */
1826 if (priv->ieee->sec.encrypt) {
1827 priv->status &= ~STATUS_ASSOCIATED;
1828 notify_wx_assoc_event(priv);
1829 }
1830
1831 /* Keep the restart process from trying to send host
1832 * commands by clearing the INIT status bit */
1833 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001834
1835 /* Cancel currently queued command. */
1836 priv->status &= ~STATUS_HCMD_ACTIVE;
1837 wake_up_interruptible(&priv->wait_command_queue);
1838
James Ketrenos43f66a62005-03-25 12:31:53 -06001839 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05001840 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001841 }
1842
James Ketrenosb095c382005-08-24 22:04:42 -05001843 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001844 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001845 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001846 }
1847
1848 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001849 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06001850 }
1851
1852 /* enable all interrupts */
1853 ipw_enable_interrupts(priv);
1854
1855 spin_unlock_irqrestore(&priv->lock, flags);
1856}
Jeff Garzikbf794512005-07-31 13:07:26 -04001857
James Ketrenos43f66a62005-03-25 12:31:53 -06001858#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1859static char *get_cmd_string(u8 cmd)
1860{
1861 switch (cmd) {
1862 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04001863 IPW_CMD(POWER_DOWN);
1864 IPW_CMD(SYSTEM_CONFIG);
1865 IPW_CMD(MULTICAST_ADDRESS);
1866 IPW_CMD(SSID);
1867 IPW_CMD(ADAPTER_ADDRESS);
1868 IPW_CMD(PORT_TYPE);
1869 IPW_CMD(RTS_THRESHOLD);
1870 IPW_CMD(FRAG_THRESHOLD);
1871 IPW_CMD(POWER_MODE);
1872 IPW_CMD(WEP_KEY);
1873 IPW_CMD(TGI_TX_KEY);
1874 IPW_CMD(SCAN_REQUEST);
1875 IPW_CMD(SCAN_REQUEST_EXT);
1876 IPW_CMD(ASSOCIATE);
1877 IPW_CMD(SUPPORTED_RATES);
1878 IPW_CMD(SCAN_ABORT);
1879 IPW_CMD(TX_FLUSH);
1880 IPW_CMD(QOS_PARAMETERS);
1881 IPW_CMD(DINO_CONFIG);
1882 IPW_CMD(RSN_CAPABILITIES);
1883 IPW_CMD(RX_KEY);
1884 IPW_CMD(CARD_DISABLE);
1885 IPW_CMD(SEED_NUMBER);
1886 IPW_CMD(TX_POWER);
1887 IPW_CMD(COUNTRY_INFO);
1888 IPW_CMD(AIRONET_INFO);
1889 IPW_CMD(AP_TX_POWER);
1890 IPW_CMD(CCKM_INFO);
1891 IPW_CMD(CCX_VER_INFO);
1892 IPW_CMD(SET_CALIBRATION);
1893 IPW_CMD(SENSITIVITY_CALIB);
1894 IPW_CMD(RETRY_LIMIT);
1895 IPW_CMD(IPW_PRE_POWER_DOWN);
1896 IPW_CMD(VAP_BEACON_TEMPLATE);
1897 IPW_CMD(VAP_DTIM_PERIOD);
1898 IPW_CMD(EXT_SUPPORTED_RATES);
1899 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
1900 IPW_CMD(VAP_QUIET_INTERVALS);
1901 IPW_CMD(VAP_CHANNEL_SWITCH);
1902 IPW_CMD(VAP_MANDATORY_CHANNELS);
1903 IPW_CMD(VAP_CELL_PWR_LIMIT);
1904 IPW_CMD(VAP_CF_PARAM_SET);
1905 IPW_CMD(VAP_SET_BEACONING_STATE);
1906 IPW_CMD(MEASUREMENT);
1907 IPW_CMD(POWER_CAPABILITY);
1908 IPW_CMD(SUPPORTED_CHANNELS);
1909 IPW_CMD(TPC_REPORT);
1910 IPW_CMD(WME_INFO);
1911 IPW_CMD(PRODUCTION_COMMAND);
1912 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06001913 return "UNKNOWN";
1914 }
1915}
James Ketrenos43f66a62005-03-25 12:31:53 -06001916
1917#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08001918
1919static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06001920{
1921 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05001922 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06001923
James Ketrenosa613bff2005-08-24 21:43:11 -05001924 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001925 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001926 IPW_ERROR("Failed to send %s: Already sending a command.\n",
1927 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05001928 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001929 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06001930 }
1931
1932 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04001933
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001934 if (priv->cmdlog) {
1935 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
1936 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
1937 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
1938 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
1939 cmd->len);
1940 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
1941 }
1942
James Ketrenosb095c382005-08-24 22:04:42 -05001943 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
1944 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
1945 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08001946
1947#ifndef DEBUG_CMD_WEP_KEY
1948 if (cmd->cmd == IPW_CMD_WEP_KEY)
1949 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
1950 else
1951#endif
1952 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
1953
Zhu Yi0a7bcf22006-01-24 16:37:28 +08001954 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05001955 if (rc) {
1956 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001957 IPW_ERROR("Failed to send %s: Reason %d\n",
1958 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05001959 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001960 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05001961 }
1962 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001963
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001964 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1965 !(priv->
1966 status & STATUS_HCMD_ACTIVE),
1967 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001968 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05001969 spin_lock_irqsave(&priv->lock, flags);
1970 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001971 IPW_ERROR("Failed to send %s: Command timed out.\n",
1972 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05001973 priv->status &= ~STATUS_HCMD_ACTIVE;
1974 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001975 rc = -EIO;
1976 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05001977 }
1978 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05001979 } else
1980 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05001981
James Ketrenosb095c382005-08-24 22:04:42 -05001982 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001983 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
1984 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001985 rc = -EIO;
1986 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06001987 }
1988
Zhu Yi2638bc32006-01-24 16:37:52 +08001989 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001990 if (priv->cmdlog) {
1991 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
1992 priv->cmdlog_pos %= priv->cmdlog_len;
1993 }
1994 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06001995}
1996
Zhu Yi0a7bcf22006-01-24 16:37:28 +08001997static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06001998{
1999 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002000 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002001 };
2002
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002003 return __ipw_send_cmd(priv, &cmd);
2004}
2005
2006static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2007 void *data)
2008{
2009 struct host_cmd cmd = {
2010 .cmd = command,
2011 .len = len,
2012 .param = data,
2013 };
2014
2015 return __ipw_send_cmd(priv, &cmd);
2016}
2017
2018static int ipw_send_host_complete(struct ipw_priv *priv)
2019{
James Ketrenos43f66a62005-03-25 12:31:53 -06002020 if (!priv) {
2021 IPW_ERROR("Invalid args\n");
2022 return -1;
2023 }
2024
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002025 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002026}
2027
Jeff Garzikbf794512005-07-31 13:07:26 -04002028static int ipw_send_system_config(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06002029 struct ipw_sys_config *config)
2030{
James Ketrenos43f66a62005-03-25 12:31:53 -06002031 if (!priv || !config) {
2032 IPW_ERROR("Invalid args\n");
2033 return -1;
2034 }
2035
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002036 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, sizeof(*config),
Zhu Yi2638bc32006-01-24 16:37:52 +08002037 config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002038}
2039
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002040static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002041{
James Ketrenos43f66a62005-03-25 12:31:53 -06002042 if (!priv || !ssid) {
2043 IPW_ERROR("Invalid args\n");
2044 return -1;
2045 }
2046
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002047 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002048 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002049}
2050
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002051static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002052{
James Ketrenos43f66a62005-03-25 12:31:53 -06002053 if (!priv || !mac) {
2054 IPW_ERROR("Invalid args\n");
2055 return -1;
2056 }
2057
2058 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2059 priv->net_dev->name, MAC_ARG(mac));
2060
Zhu Yi2638bc32006-01-24 16:37:52 +08002061 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002062}
2063
James Ketrenosa613bff2005-08-24 21:43:11 -05002064/*
2065 * NOTE: This must be executed from our workqueue as it results in udelay
2066 * being called which may corrupt the keyboard if executed on default
2067 * workqueue
2068 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002069static void ipw_adapter_restart(void *adapter)
2070{
2071 struct ipw_priv *priv = adapter;
2072
2073 if (priv->status & STATUS_RF_KILL_MASK)
2074 return;
2075
2076 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002077
2078 if (priv->assoc_network &&
2079 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2080 ipw_remove_current_network(priv);
2081
James Ketrenos43f66a62005-03-25 12:31:53 -06002082 if (ipw_up(priv)) {
2083 IPW_ERROR("Failed to up device\n");
2084 return;
2085 }
2086}
2087
James Ketrenosc848d0a2005-08-24 21:56:24 -05002088static void ipw_bg_adapter_restart(void *data)
2089{
2090 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08002091 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002092 ipw_adapter_restart(data);
Zhu Yi46441512006-01-24 16:37:59 +08002093 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002094}
2095
James Ketrenos43f66a62005-03-25 12:31:53 -06002096#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2097
2098static void ipw_scan_check(void *data)
2099{
2100 struct ipw_priv *priv = data;
2101 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2102 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002103 "adapter after (%dms).\n",
2104 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
James Ketrenosa613bff2005-08-24 21:43:11 -05002105 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06002106 }
2107}
2108
James Ketrenosc848d0a2005-08-24 21:56:24 -05002109static void ipw_bg_scan_check(void *data)
2110{
2111 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08002112 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002113 ipw_scan_check(data);
Zhu Yi46441512006-01-24 16:37:59 +08002114 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002115}
2116
James Ketrenos43f66a62005-03-25 12:31:53 -06002117static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2118 struct ipw_scan_request_ext *request)
2119{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002120 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002121 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002122}
2123
2124static int ipw_send_scan_abort(struct ipw_priv *priv)
2125{
James Ketrenos43f66a62005-03-25 12:31:53 -06002126 if (!priv) {
2127 IPW_ERROR("Invalid args\n");
2128 return -1;
2129 }
2130
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002131 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002132}
2133
2134static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2135{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002136 struct ipw_sensitivity_calib calib = {
2137 .beacon_rssi_raw = sens,
James Ketrenos43f66a62005-03-25 12:31:53 -06002138 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002139
2140 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002141 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002142}
2143
2144static int ipw_send_associate(struct ipw_priv *priv,
2145 struct ipw_associate *associate)
2146{
James Ketrenosa613bff2005-08-24 21:43:11 -05002147 struct ipw_associate tmp_associate;
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002148
2149 if (!priv || !associate) {
2150 IPW_ERROR("Invalid args\n");
2151 return -1;
2152 }
2153
James Ketrenosa613bff2005-08-24 21:43:11 -05002154 memcpy(&tmp_associate, associate, sizeof(*associate));
2155 tmp_associate.policy_support =
2156 cpu_to_le16(tmp_associate.policy_support);
2157 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2158 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2159 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2160 tmp_associate.listen_interval =
2161 cpu_to_le16(tmp_associate.listen_interval);
2162 tmp_associate.beacon_interval =
2163 cpu_to_le16(tmp_associate.beacon_interval);
2164 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2165
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002166 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
Zhu Yi2638bc32006-01-24 16:37:52 +08002167 &tmp_associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002168}
2169
2170static int ipw_send_supported_rates(struct ipw_priv *priv,
2171 struct ipw_supported_rates *rates)
2172{
James Ketrenos43f66a62005-03-25 12:31:53 -06002173 if (!priv || !rates) {
2174 IPW_ERROR("Invalid args\n");
2175 return -1;
2176 }
2177
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002178 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002179 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002180}
2181
2182static int ipw_set_random_seed(struct ipw_priv *priv)
2183{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002184 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002185
2186 if (!priv) {
2187 IPW_ERROR("Invalid args\n");
2188 return -1;
2189 }
2190
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002191 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002192
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002193 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002194}
2195
James Ketrenos43f66a62005-03-25 12:31:53 -06002196static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2197{
James Ketrenos43f66a62005-03-25 12:31:53 -06002198 if (!priv) {
2199 IPW_ERROR("Invalid args\n");
2200 return -1;
2201 }
2202
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002203 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off),
Zhu Yi2638bc32006-01-24 16:37:52 +08002204 &phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002205}
James Ketrenos43f66a62005-03-25 12:31:53 -06002206
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002207static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002208{
James Ketrenos43f66a62005-03-25 12:31:53 -06002209 if (!priv || !power) {
2210 IPW_ERROR("Invalid args\n");
2211 return -1;
2212 }
2213
Zhu Yi2638bc32006-01-24 16:37:52 +08002214 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002215}
James Ketrenos43f66a62005-03-25 12:31:53 -06002216
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002217static int ipw_set_tx_power(struct ipw_priv *priv)
2218{
Larry Finger1867b112006-02-28 09:48:28 -06002219 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002220 struct ipw_tx_power tx_power;
2221 s8 max_power;
2222 int i;
2223
2224 memset(&tx_power, 0, sizeof(tx_power));
2225
2226 /* configure device for 'G' band */
2227 tx_power.ieee_mode = IPW_G_MODE;
2228 tx_power.num_channels = geo->bg_channels;
2229 for (i = 0; i < geo->bg_channels; i++) {
2230 max_power = geo->bg[i].max_power;
2231 tx_power.channels_tx_power[i].channel_number =
2232 geo->bg[i].channel;
2233 tx_power.channels_tx_power[i].tx_power = max_power ?
2234 min(max_power, priv->tx_power) : priv->tx_power;
2235 }
2236 if (ipw_send_tx_power(priv, &tx_power))
2237 return -EIO;
2238
2239 /* configure device to also handle 'B' band */
2240 tx_power.ieee_mode = IPW_B_MODE;
2241 if (ipw_send_tx_power(priv, &tx_power))
2242 return -EIO;
2243
2244 /* configure device to also handle 'A' band */
2245 if (priv->ieee->abg_true) {
2246 tx_power.ieee_mode = IPW_A_MODE;
2247 tx_power.num_channels = geo->a_channels;
2248 for (i = 0; i < tx_power.num_channels; i++) {
2249 max_power = geo->a[i].max_power;
2250 tx_power.channels_tx_power[i].channel_number =
2251 geo->a[i].channel;
2252 tx_power.channels_tx_power[i].tx_power = max_power ?
2253 min(max_power, priv->tx_power) : priv->tx_power;
2254 }
2255 if (ipw_send_tx_power(priv, &tx_power))
2256 return -EIO;
2257 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002258 return 0;
2259}
2260
2261static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2262{
2263 struct ipw_rts_threshold rts_threshold = {
2264 .rts_threshold = rts,
2265 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002266
2267 if (!priv) {
2268 IPW_ERROR("Invalid args\n");
2269 return -1;
2270 }
2271
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002272 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2273 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002274}
2275
2276static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2277{
2278 struct ipw_frag_threshold frag_threshold = {
2279 .frag_threshold = frag,
2280 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002281
2282 if (!priv) {
2283 IPW_ERROR("Invalid args\n");
2284 return -1;
2285 }
2286
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002287 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2288 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002289}
2290
2291static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2292{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002293 u32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002294
2295 if (!priv) {
2296 IPW_ERROR("Invalid args\n");
2297 return -1;
2298 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002299
James Ketrenos43f66a62005-03-25 12:31:53 -06002300 /* If on battery, set to 3, if AC set to CAM, else user
2301 * level */
2302 switch (mode) {
2303 case IPW_POWER_BATTERY:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002304 param = IPW_POWER_INDEX_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06002305 break;
2306 case IPW_POWER_AC:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002307 param = IPW_POWER_MODE_CAM;
James Ketrenos43f66a62005-03-25 12:31:53 -06002308 break;
2309 default:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002310 param = mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06002311 break;
2312 }
2313
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002314 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002315 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002316}
2317
James Ketrenosafbf30a2005-08-25 00:05:33 -05002318static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2319{
2320 struct ipw_retry_limit retry_limit = {
2321 .short_retry_limit = slimit,
2322 .long_retry_limit = llimit
2323 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002324
2325 if (!priv) {
2326 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002327 return -1;
2328 }
2329
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002330 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002331 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002332}
2333
2334/*
2335 * The IPW device contains a Microwire compatible EEPROM that stores
2336 * various data like the MAC address. Usually the firmware has exclusive
2337 * access to the eeprom, but during device initialization (before the
2338 * device driver has sent the HostComplete command to the firmware) the
2339 * device driver has read access to the EEPROM by way of indirect addressing
2340 * through a couple of memory mapped registers.
2341 *
2342 * The following is a simplified implementation for pulling data out of the
2343 * the eeprom, along with some helper functions to find information in
2344 * the per device private data's copy of the eeprom.
2345 *
2346 * NOTE: To better understand how these functions work (i.e what is a chip
2347 * select and why do have to keep driving the eeprom clock?), read
2348 * just about any data sheet for a Microwire compatible EEPROM.
2349 */
2350
2351/* write a 32 bit value into the indirect accessor register */
2352static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2353{
2354 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002355
James Ketrenos43f66a62005-03-25 12:31:53 -06002356 /* the eeprom requires some time to complete the operation */
2357 udelay(p->eeprom_delay);
2358
2359 return;
2360}
2361
2362/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002363static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002364{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002365 eeprom_write_reg(priv, 0);
2366 eeprom_write_reg(priv, EEPROM_BIT_CS);
2367 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2368 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002369}
2370
2371/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002372static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002373{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002374 eeprom_write_reg(priv, EEPROM_BIT_CS);
2375 eeprom_write_reg(priv, 0);
2376 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002377}
2378
2379/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002380static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002381{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002382 int d = (bit ? EEPROM_BIT_DI : 0);
2383 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2384 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002385}
2386
2387/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002388static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002389{
2390 int i;
2391
2392 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002393 eeprom_write_bit(priv, 1);
2394 eeprom_write_bit(priv, op & 2);
2395 eeprom_write_bit(priv, op & 1);
2396 for (i = 7; i >= 0; i--) {
2397 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002398 }
2399}
2400
2401/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002402static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002403{
2404 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002405 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002406
James Ketrenos43f66a62005-03-25 12:31:53 -06002407 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002408 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002409
2410 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002411 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002412
2413 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002414 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002415 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002416 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2417 eeprom_write_reg(priv, EEPROM_BIT_CS);
2418 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2419 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002420 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002421
James Ketrenos43f66a62005-03-25 12:31:53 -06002422 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002423 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002424 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002425
James Ketrenos43f66a62005-03-25 12:31:53 -06002426 return r;
2427}
2428
2429/* helper function for pulling the mac address out of the private */
2430/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002431static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002432{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002433 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002434}
2435
2436/*
2437 * Either the device driver (i.e. the host) or the firmware can
2438 * load eeprom data into the designated region in SRAM. If neither
2439 * happens then the FW will shutdown with a fatal error.
2440 *
2441 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2442 * bit needs region of shared SRAM needs to be non-zero.
2443 */
2444static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2445{
2446 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002447 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002448
James Ketrenos43f66a62005-03-25 12:31:53 -06002449 IPW_DEBUG_TRACE(">>\n");
2450
2451 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002452 for (i = 0; i < 128; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002453 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002454
Jeff Garzikbf794512005-07-31 13:07:26 -04002455 /*
2456 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002457 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002458 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002459 */
Alexey Dobriyan386093e2006-02-01 03:04:57 -08002460 if (priv->eeprom[EEPROM_VERSION] != 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002461 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2462
2463 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002464 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002465 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002466
2467 /* Do not load eeprom data on fatal error or suspend */
2468 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2469 } else {
2470 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2471
2472 /* Load eeprom data on fatal error or suspend */
2473 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2474 }
2475
2476 IPW_DEBUG_TRACE("<<\n");
2477}
2478
Arjan van de Ven858119e2006-01-14 13:20:43 -08002479static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002480{
2481 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002482 if (!count)
2483 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002484 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002485 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002486 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002487}
2488
2489static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2490{
James Ketrenosb095c382005-08-24 22:04:42 -05002491 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002492 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002493 sizeof(struct command_block));
2494}
2495
2496static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002497{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002498
2499 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002500
James Ketrenos43f66a62005-03-25 12:31:53 -06002501 /* Start the dma */
2502 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002503
James Ketrenos43f66a62005-03-25 12:31:53 -06002504 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002505 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002506
2507 IPW_DEBUG_FW("<< : \n");
2508 return 0;
2509}
2510
2511static void ipw_fw_dma_abort(struct ipw_priv *priv)
2512{
2513 u32 control = 0;
2514
2515 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002516
2517 //set the Stop and Abort bit
James Ketrenos43f66a62005-03-25 12:31:53 -06002518 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002519 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002520 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002521
James Ketrenos43f66a62005-03-25 12:31:53 -06002522 IPW_DEBUG_FW("<< \n");
2523}
2524
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002525static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2526 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002527{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002528 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002529 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002530 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002531 IPW_DEBUG_FW(">> :\n");
2532
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002533 ipw_write_indirect(priv, address, (u8 *) cb,
2534 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002535
2536 IPW_DEBUG_FW("<< :\n");
2537 return 0;
2538
2539}
2540
2541static int ipw_fw_dma_kick(struct ipw_priv *priv)
2542{
2543 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002544 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002545
2546 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002547
James Ketrenos43f66a62005-03-25 12:31:53 -06002548 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002549 ipw_fw_dma_write_command_block(priv, index,
2550 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002551
2552 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002553 ipw_clear_bit(priv, IPW_RESET_REG,
2554 IPW_RESET_REG_MASTER_DISABLED |
2555 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002556
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002557 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002558 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002559 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002560
2561 IPW_DEBUG_FW("<< :\n");
2562 return 0;
2563}
2564
2565static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2566{
2567 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002568 u32 register_value = 0;
2569 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002570
2571 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002572 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002573 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002574
2575 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002576 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2577 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002578
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002579 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002580 cb_fields_address = address;
2581 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002582 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002583
2584 cb_fields_address += sizeof(u32);
2585 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002586 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002587
2588 cb_fields_address += sizeof(u32);
2589 register_value = ipw_read_reg32(priv, cb_fields_address);
2590 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2591 register_value);
2592
2593 cb_fields_address += sizeof(u32);
2594 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002595 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002596
2597 IPW_DEBUG_FW(">> :\n");
2598}
2599
2600static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2601{
2602 u32 current_cb_address = 0;
2603 u32 current_cb_index = 0;
2604
2605 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002606 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002607
James Ketrenosb095c382005-08-24 22:04:42 -05002608 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002609 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002610
James Ketrenos43f66a62005-03-25 12:31:53 -06002611 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002612 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002613
2614 IPW_DEBUG_FW(">> :\n");
2615 return current_cb_index;
2616
2617}
2618
2619static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2620 u32 src_address,
2621 u32 dest_address,
2622 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002623 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002624{
2625
Jeff Garzikbf794512005-07-31 13:07:26 -04002626 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002627 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2628 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002629 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002630 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002631
2632 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2633 src_address, dest_address, length);
2634
2635 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2636 return -1;
2637
2638 last_cb_element = priv->sram_desc.last_cb_index;
2639 cb = &priv->sram_desc.cb_list[last_cb_element];
2640 priv->sram_desc.last_cb_index++;
2641
2642 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002643 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002644 control |= CB_INT_ENABLED;
2645
2646 if (is_last)
2647 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002648
James Ketrenos43f66a62005-03-25 12:31:53 -06002649 control |= length;
2650
2651 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002652 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002653
2654 /* Copy the Source and Destination addresses */
2655 cb->dest_addr = dest_address;
2656 cb->source_addr = src_address;
2657
2658 /* Copy the Control Word last */
2659 cb->control = control;
2660
2661 return 0;
2662}
2663
2664static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002665 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06002666{
2667 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002668 u32 src_offset = 0;
2669 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002670 int status = 0;
2671 IPW_DEBUG_FW(">> \n");
2672 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2673 src_phys, dest_address, length);
2674 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002675 status = ipw_fw_dma_add_command_block(priv,
2676 src_phys + src_offset,
2677 dest_address +
2678 dest_offset,
2679 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002680 if (status) {
2681 IPW_DEBUG_FW_INFO(": Failed\n");
2682 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002683 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002684 IPW_DEBUG_FW_INFO(": Added new cb\n");
2685
2686 src_offset += CB_MAX_LENGTH;
2687 dest_offset += CB_MAX_LENGTH;
2688 bytes_left -= CB_MAX_LENGTH;
2689 }
2690
2691 /* add the buffer tail */
2692 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002693 status =
2694 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2695 dest_address + dest_offset,
2696 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002697 if (status) {
2698 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2699 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002700 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002701 IPW_DEBUG_FW_INFO
2702 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002703 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002704
James Ketrenos43f66a62005-03-25 12:31:53 -06002705 IPW_DEBUG_FW("<< \n");
2706 return 0;
2707}
2708
2709static int ipw_fw_dma_wait(struct ipw_priv *priv)
2710{
Zhu Yi397ae122006-01-24 16:37:22 +08002711 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002712 u32 watchdog = 0;
2713
2714 IPW_DEBUG_FW(">> : \n");
2715
2716 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002717 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002718 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002719
2720 while (current_index < priv->sram_desc.last_cb_index) {
2721 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002722 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002723 current_index = ipw_fw_dma_command_block_index(priv);
2724
Zhu Yi397ae122006-01-24 16:37:22 +08002725 if (previous_index < current_index) {
2726 watchdog = 0;
2727 continue;
2728 }
2729 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002730 IPW_DEBUG_FW_INFO("Timeout\n");
2731 ipw_fw_dma_dump_command_block(priv);
2732 ipw_fw_dma_abort(priv);
2733 return -1;
2734 }
2735 }
2736
2737 ipw_fw_dma_abort(priv);
2738
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002739 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002740 ipw_set_bit(priv, IPW_RESET_REG,
2741 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002742
2743 IPW_DEBUG_FW("<< dmaWaitSync \n");
2744 return 0;
2745}
2746
Jeff Garzikbf794512005-07-31 13:07:26 -04002747static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002748{
2749 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002750 struct ieee80211_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002751 unsigned long flags;
2752
2753 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002754 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2755 network = list_entry(element, struct ieee80211_network, list);
2756 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2757 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002758 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002759 &priv->ieee->network_free_list);
2760 }
2761 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002762 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002763}
2764
2765/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002766 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002767 * Reads debug register from domain0.
2768 * If card is present, pre-defined value should
2769 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002770 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002771 * @param priv
2772 * @return 1 if card is present, 0 otherwise
2773 */
2774static inline int ipw_alive(struct ipw_priv *priv)
2775{
2776 return ipw_read32(priv, 0x90) == 0xd55555d5;
2777}
2778
Zhu Yic7b6a672006-01-24 16:37:05 +08002779/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002780static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06002781 int timeout)
2782{
2783 int i = 0;
2784
2785 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002786 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002787 return i;
2788 mdelay(10);
2789 i += 10;
2790 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002791
James Ketrenos43f66a62005-03-25 12:31:53 -06002792 return -ETIME;
2793}
2794
Jeff Garzikbf794512005-07-31 13:07:26 -04002795/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002796 * the ipw hardware. It assumes the buffer has all the bits for the
2797 * image and the caller is handling the memory allocation and clean up.
2798 */
2799
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002800static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002801{
2802 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002803
James Ketrenos43f66a62005-03-25 12:31:53 -06002804 IPW_DEBUG_TRACE(">> \n");
2805 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05002806 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002807
Zhu Yic7b6a672006-01-24 16:37:05 +08002808 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05002809 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2810 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06002811 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08002812 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002813 return -1;
2814 }
2815
2816 IPW_DEBUG_INFO("stop master %dms\n", rc);
2817
2818 return rc;
2819}
2820
2821static void ipw_arc_release(struct ipw_priv *priv)
2822{
2823 IPW_DEBUG_TRACE(">> \n");
2824 mdelay(5);
2825
James Ketrenosb095c382005-08-24 22:04:42 -05002826 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002827
2828 /* no one knows timing, for safety add some delay */
2829 mdelay(5);
2830}
2831
2832struct fw_header {
2833 u32 version;
2834 u32 mode;
2835};
2836
2837struct fw_chunk {
2838 u32 address;
2839 u32 length;
2840};
2841
2842#define IPW_FW_MAJOR_VERSION 2
James Ketrenos817153762005-08-25 01:37:28 -05002843#define IPW_FW_MINOR_VERSION 4
James Ketrenos43f66a62005-03-25 12:31:53 -06002844
2845#define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
2846#define IPW_FW_MAJOR(x) (x & 0xff)
2847
James Ketrenosafbf30a2005-08-25 00:05:33 -05002848#define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | IPW_FW_MAJOR_VERSION)
James Ketrenos43f66a62005-03-25 12:31:53 -06002849
2850#define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
2851"." __stringify(IPW_FW_MINOR_VERSION) "-"
2852
2853#if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
2854#define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
2855#else
2856#define IPW_FW_NAME(x) "ipw2200_" x ".fw"
2857#endif
2858
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002859static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002860{
2861 int rc = 0, i, addr;
2862 u8 cr = 0;
2863 u16 *image;
2864
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002865 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002866
James Ketrenos43f66a62005-03-25 12:31:53 -06002867 IPW_DEBUG_TRACE(">> \n");
2868
2869 rc = ipw_stop_master(priv);
2870
2871 if (rc < 0)
2872 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002873
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002874// spin_lock_irqsave(&priv->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04002875
James Ketrenosb095c382005-08-24 22:04:42 -05002876 for (addr = IPW_SHARED_LOWER_BOUND;
2877 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002878 ipw_write32(priv, addr, 0);
2879 }
2880
2881 /* no ucode (yet) */
2882 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2883 /* destroy DMA queues */
2884 /* reset sequence */
2885
James Ketrenosb095c382005-08-24 22:04:42 -05002886 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06002887 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002888 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06002889 mdelay(1);
2890
2891 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05002892 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06002893 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002894
James Ketrenosb095c382005-08-24 22:04:42 -05002895 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002896 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002897
James Ketrenos43f66a62005-03-25 12:31:53 -06002898 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08002899 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
2900 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002901 mdelay(1);
2902
2903 /* write ucode */
2904 /**
2905 * @bug
2906 * Do NOT set indirect address register once and then
2907 * store data to indirect data register in the loop.
2908 * It seems very reasonable, but in this case DINO do not
2909 * accept ucode. It is essential to set address each time.
2910 */
2911 /* load new ipw uCode */
2912 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05002913 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
James Ketrenosa613bff2005-08-24 21:43:11 -05002914 cpu_to_le16(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06002915
James Ketrenos43f66a62005-03-25 12:31:53 -06002916 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05002917 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2918 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002919
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002920 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002921
2922 /* wait for alive response */
2923 for (i = 0; i < 100; i++) {
2924 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05002925 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002926 if (cr & DINO_RXFIFO_DATA)
2927 break;
2928 mdelay(1);
2929 }
2930
2931 if (cr & DINO_RXFIFO_DATA) {
2932 /* alive_command_responce size is NOT multiple of 4 */
2933 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04002934
2935 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06002936 response_buffer[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05002937 le32_to_cpu(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05002938 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06002939 memcpy(&priv->dino_alive, response_buffer,
2940 sizeof(priv->dino_alive));
2941 if (priv->dino_alive.alive_command == 1
2942 && priv->dino_alive.ucode_valid == 1) {
2943 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002944 IPW_DEBUG_INFO
2945 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2946 "of %02d/%02d/%02d %02d:%02d\n",
2947 priv->dino_alive.software_revision,
2948 priv->dino_alive.software_revision,
2949 priv->dino_alive.device_identifier,
2950 priv->dino_alive.device_identifier,
2951 priv->dino_alive.time_stamp[0],
2952 priv->dino_alive.time_stamp[1],
2953 priv->dino_alive.time_stamp[2],
2954 priv->dino_alive.time_stamp[3],
2955 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002956 } else {
2957 IPW_DEBUG_INFO("Microcode is not alive\n");
2958 rc = -EINVAL;
2959 }
2960 } else {
2961 IPW_DEBUG_INFO("No alive response from DINO\n");
2962 rc = -ETIME;
2963 }
2964
2965 /* disable DINO, otherwise for some reason
2966 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05002967 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002968
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002969// spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002970
2971 return rc;
2972}
2973
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002974static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002975{
2976 int rc = -1;
2977 int offset = 0;
2978 struct fw_chunk *chunk;
2979 dma_addr_t shared_phys;
2980 u8 *shared_virt;
2981
2982 IPW_DEBUG_TRACE("<< : \n");
2983 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
2984
2985 if (!shared_virt)
2986 return -ENOMEM;
2987
2988 memmove(shared_virt, data, len);
2989
2990 /* Start the Dma */
2991 rc = ipw_fw_dma_enable(priv);
2992
2993 if (priv->sram_desc.last_cb_index > 0) {
2994 /* the DMA is already ready this would be a bug. */
2995 BUG();
2996 goto out;
2997 }
2998
2999 do {
3000 chunk = (struct fw_chunk *)(data + offset);
3001 offset += sizeof(struct fw_chunk);
3002 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04003003 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06003004 * offeset*/
3005 /* Dma loading */
3006 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
James Ketrenosa613bff2005-08-24 21:43:11 -05003007 le32_to_cpu(chunk->address),
3008 le32_to_cpu(chunk->length));
James Ketrenos43f66a62005-03-25 12:31:53 -06003009 if (rc) {
3010 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
3011 goto out;
3012 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003013
James Ketrenosa613bff2005-08-24 21:43:11 -05003014 offset += le32_to_cpu(chunk->length);
James Ketrenos43f66a62005-03-25 12:31:53 -06003015 } while (offset < len);
3016
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003017 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06003018 rc = ipw_fw_dma_kick(priv);
3019 if (rc) {
3020 IPW_ERROR("dmaKick Failed\n");
3021 goto out;
3022 }
3023
3024 rc = ipw_fw_dma_wait(priv);
3025 if (rc) {
3026 IPW_ERROR("dmaWaitSync Failed\n");
3027 goto out;
3028 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003029 out:
3030 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06003031 return rc;
3032}
3033
3034/* stop nic */
3035static int ipw_stop_nic(struct ipw_priv *priv)
3036{
3037 int rc = 0;
3038
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003039 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003040 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003041
James Ketrenosb095c382005-08-24 22:04:42 -05003042 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3043 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003044 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003045 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003046 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003047 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003048
James Ketrenosb095c382005-08-24 22:04:42 -05003049 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003050
James Ketrenos43f66a62005-03-25 12:31:53 -06003051 return rc;
3052}
3053
3054static void ipw_start_nic(struct ipw_priv *priv)
3055{
3056 IPW_DEBUG_TRACE(">>\n");
3057
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003058 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003059 ipw_clear_bit(priv, IPW_RESET_REG,
3060 IPW_RESET_REG_MASTER_DISABLED |
3061 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003062 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003063
James Ketrenos43f66a62005-03-25 12:31:53 -06003064 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003065 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3066 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003067
3068 IPW_DEBUG_TRACE("<<\n");
3069}
Jeff Garzikbf794512005-07-31 13:07:26 -04003070
James Ketrenos43f66a62005-03-25 12:31:53 -06003071static int ipw_init_nic(struct ipw_priv *priv)
3072{
3073 int rc;
3074
3075 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003076 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003077 /*prvHwInitNic */
3078 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003079 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003080
3081 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003082 ipw_write32(priv, IPW_READ_INT_REGISTER,
3083 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003084
3085 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003086 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3087 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003088 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003089 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3090
3091 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003092 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003093
3094 udelay(10);
3095
3096 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003097 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003098
3099 IPW_DEBUG_TRACE(">>\n");
3100 return 0;
3101}
3102
Jeff Garzikbf794512005-07-31 13:07:26 -04003103/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003104 * Probe is an ok place to call this from.
3105 */
3106static int ipw_reset_nic(struct ipw_priv *priv)
3107{
3108 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003109 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003110
3111 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003112
James Ketrenos43f66a62005-03-25 12:31:53 -06003113 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003114
James Ketrenosa613bff2005-08-24 21:43:11 -05003115 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003116 /* Clear the 'host command active' bit... */
3117 priv->status &= ~STATUS_HCMD_ACTIVE;
3118 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003119 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3120 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003121 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003122
3123 IPW_DEBUG_TRACE("<<\n");
3124 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003125}
James Ketrenos43f66a62005-03-25 12:31:53 -06003126
Jeff Garzikbf794512005-07-31 13:07:26 -04003127static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003128 const struct firmware **fw, const char *name)
3129{
3130 struct fw_header *header;
3131 int rc;
3132
3133 /* ask firmware_class module to get the boot firmware off disk */
3134 rc = request_firmware(fw, name, &priv->pci_dev->dev);
3135 if (rc < 0) {
3136 IPW_ERROR("%s load failed: Reason %d\n", name, rc);
3137 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003138 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003139
3140 header = (struct fw_header *)(*fw)->data;
James Ketrenosa613bff2005-08-24 21:43:11 -05003141 if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003142 IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
3143 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003144 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3145 IPW_FW_MAJOR_VERSION);
James Ketrenos43f66a62005-03-25 12:31:53 -06003146 return -EINVAL;
3147 }
3148
Jiri Bencaaa4d302005-06-07 14:58:41 +02003149 IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003150 name,
James Ketrenosa613bff2005-08-24 21:43:11 -05003151 IPW_FW_MAJOR(le32_to_cpu(header->version)),
3152 IPW_FW_MINOR(le32_to_cpu(header->version)),
James Ketrenos43f66a62005-03-25 12:31:53 -06003153 (*fw)->size - sizeof(struct fw_header));
3154 return 0;
3155}
3156
James Ketrenosb095c382005-08-24 22:04:42 -05003157#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003158
Arjan van de Ven858119e2006-01-14 13:20:43 -08003159static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003160 struct ipw_rx_queue *rxq)
3161{
3162 unsigned long flags;
3163 int i;
3164
3165 spin_lock_irqsave(&rxq->lock, flags);
3166
3167 INIT_LIST_HEAD(&rxq->rx_free);
3168 INIT_LIST_HEAD(&rxq->rx_used);
3169
3170 /* Fill the rx_used queue with _all_ of the Rx buffers */
3171 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3172 /* In the reset function, these buffers may have been allocated
3173 * to an SKB, so we need to unmap and free potential storage */
3174 if (rxq->pool[i].skb != NULL) {
3175 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003176 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003177 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003178 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003179 }
3180 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3181 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003182
James Ketrenos43f66a62005-03-25 12:31:53 -06003183 /* Set us so that we have processed and used all buffers, but have
3184 * not restocked the Rx queue with fresh buffers */
3185 rxq->read = rxq->write = 0;
3186 rxq->processed = RX_QUEUE_SIZE - 1;
3187 rxq->free_count = 0;
3188 spin_unlock_irqrestore(&rxq->lock, flags);
3189}
3190
3191#ifdef CONFIG_PM
3192static int fw_loaded = 0;
3193static const struct firmware *bootfw = NULL;
3194static const struct firmware *firmware = NULL;
3195static const struct firmware *ucode = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003196
3197static void free_firmware(void)
3198{
3199 if (fw_loaded) {
3200 release_firmware(bootfw);
3201 release_firmware(ucode);
3202 release_firmware(firmware);
3203 bootfw = ucode = firmware = NULL;
3204 fw_loaded = 0;
3205 }
3206}
3207#else
3208#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003209#endif
3210
3211static int ipw_load(struct ipw_priv *priv)
3212{
3213#ifndef CONFIG_PM
3214 const struct firmware *bootfw = NULL;
3215 const struct firmware *firmware = NULL;
3216 const struct firmware *ucode = NULL;
3217#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003218 char *ucode_name;
3219 char *fw_name;
James Ketrenos43f66a62005-03-25 12:31:53 -06003220 int rc = 0, retries = 3;
3221
Zhu Yi397ae122006-01-24 16:37:22 +08003222 switch (priv->ieee->iw_mode) {
3223 case IW_MODE_ADHOC:
3224 ucode_name = IPW_FW_NAME("ibss_ucode");
3225 fw_name = IPW_FW_NAME("ibss");
3226 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003227#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003228 case IW_MODE_MONITOR:
3229 ucode_name = IPW_FW_NAME("sniffer_ucode");
3230 fw_name = IPW_FW_NAME("sniffer");
3231 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003232#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003233 case IW_MODE_INFRA:
3234 ucode_name = IPW_FW_NAME("bss_ucode");
3235 fw_name = IPW_FW_NAME("bss");
3236 break;
3237 default:
3238 rc = -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003239 }
Zhu Yi397ae122006-01-24 16:37:22 +08003240
3241 if (rc < 0)
3242 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003243
3244 if (!priv->rxq)
3245 priv->rxq = ipw_rx_queue_alloc(priv);
3246 else
3247 ipw_rx_queue_reset(priv, priv->rxq);
3248 if (!priv->rxq) {
3249 IPW_ERROR("Unable to initialize Rx queue\n");
3250 goto error;
3251 }
3252
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003253 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003254 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003255 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003256 priv->status &= ~STATUS_INT_ENABLED;
3257
3258 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003259 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003260
James Ketrenos43f66a62005-03-25 12:31:53 -06003261 ipw_stop_nic(priv);
3262
3263 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003264 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003265 IPW_ERROR("Unable to reset NIC\n");
3266 goto error;
3267 }
3268
James Ketrenosb095c382005-08-24 22:04:42 -05003269 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3270 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003271
Zhu Yi397ae122006-01-24 16:37:22 +08003272#ifdef CONFIG_PM
3273 if (!fw_loaded) {
3274#endif
3275 rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot"));
3276 if (rc < 0)
3277 goto error;
3278#ifdef CONFIG_PM
3279 }
3280#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06003281 /* DMA the initial boot firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003282 rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003283 bootfw->size - sizeof(struct fw_header));
3284 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003285 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003286 goto error;
3287 }
3288
3289 /* kick start the device */
3290 ipw_start_nic(priv);
3291
Zhu Yic7b6a672006-01-24 16:37:05 +08003292 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003293 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3294 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003295 if (rc < 0) {
3296 IPW_ERROR("device failed to boot initial fw image\n");
3297 goto error;
3298 }
3299 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3300
Jeff Garzikbf794512005-07-31 13:07:26 -04003301 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003302 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003303
Zhu Yi397ae122006-01-24 16:37:22 +08003304#ifdef CONFIG_PM
3305 if (!fw_loaded) {
3306#endif
3307 rc = ipw_get_fw(priv, &ucode, ucode_name);
3308 if (rc < 0)
3309 goto error;
3310#ifdef CONFIG_PM
3311 }
3312#endif
Zhu Yi2638bc32006-01-24 16:37:52 +08003313
James Ketrenos43f66a62005-03-25 12:31:53 -06003314 /* DMA the ucode into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003315 rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003316 ucode->size - sizeof(struct fw_header));
3317 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003318 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003319 goto error;
3320 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003321
James Ketrenos43f66a62005-03-25 12:31:53 -06003322 /* stop nic */
3323 ipw_stop_nic(priv);
3324
Zhu Yi397ae122006-01-24 16:37:22 +08003325#ifdef CONFIG_PM
3326 if (!fw_loaded) {
3327#endif
3328 rc = ipw_get_fw(priv, &firmware, fw_name);
3329 if (rc < 0)
3330 goto error;
3331#ifdef CONFIG_PM
3332 }
3333#endif
3334
James Ketrenos43f66a62005-03-25 12:31:53 -06003335 /* DMA bss firmware into the device */
Jeff Garzikbf794512005-07-31 13:07:26 -04003336 rc = ipw_load_firmware(priv, firmware->data +
3337 sizeof(struct fw_header),
James Ketrenos43f66a62005-03-25 12:31:53 -06003338 firmware->size - sizeof(struct fw_header));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003339 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003340 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003341 goto error;
3342 }
Zhu Yi397ae122006-01-24 16:37:22 +08003343#ifdef CONFIG_PM
3344 fw_loaded = 1;
3345#endif
3346
James Ketrenos43f66a62005-03-25 12:31:53 -06003347 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3348
3349 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003350 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003351 IPW_ERROR("Unable to initialize queues\n");
3352 goto error;
3353 }
3354
3355 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003356 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003357 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003358 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003359
James Ketrenos43f66a62005-03-25 12:31:53 -06003360 /* kick start the device */
3361 ipw_start_nic(priv);
3362
James Ketrenosb095c382005-08-24 22:04:42 -05003363 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003364 if (retries > 0) {
3365 IPW_WARNING("Parity error. Retrying init.\n");
3366 retries--;
3367 goto retry;
3368 }
3369
3370 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3371 rc = -EIO;
3372 goto error;
3373 }
3374
3375 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003376 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3377 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003378 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003379 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003380 goto error;
3381 }
3382 IPW_DEBUG_INFO("device response after %dms\n", rc);
3383
3384 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003385 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003386
3387 /* read eeprom data and initialize the eeprom region of sram */
3388 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003389 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003390
3391 /* enable interrupts */
3392 ipw_enable_interrupts(priv);
3393
3394 /* Ensure our queue has valid packets */
3395 ipw_rx_queue_replenish(priv);
3396
James Ketrenosb095c382005-08-24 22:04:42 -05003397 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003398
3399 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003400 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003401
3402#ifndef CONFIG_PM
3403 release_firmware(bootfw);
3404 release_firmware(ucode);
3405 release_firmware(firmware);
3406#endif
3407 return 0;
3408
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003409 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003410 if (priv->rxq) {
3411 ipw_rx_queue_free(priv, priv->rxq);
3412 priv->rxq = NULL;
3413 }
3414 ipw_tx_queue_free(priv);
3415 if (bootfw)
3416 release_firmware(bootfw);
3417 if (ucode)
3418 release_firmware(ucode);
3419 if (firmware)
3420 release_firmware(firmware);
3421#ifdef CONFIG_PM
3422 fw_loaded = 0;
3423 bootfw = ucode = firmware = NULL;
3424#endif
3425
3426 return rc;
3427}
3428
Jeff Garzikbf794512005-07-31 13:07:26 -04003429/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003430 * DMA services
3431 *
3432 * Theory of operation
3433 *
3434 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3435 * 2 empty entries always kept in the buffer to protect from overflow.
3436 *
3437 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003438 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3439 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003440 * Tx queue resumed.
3441 *
3442 * The IPW operates with six queues, one receive queue in the device's
3443 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003444 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003445 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003446 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003447 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003448 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003449 * we only utilize the first data transmit queue (queue1).
3450 */
3451
3452/**
3453 * Driver allocates buffers of this size for Rx
3454 */
3455
3456static inline int ipw_queue_space(const struct clx2_queue *q)
3457{
3458 int s = q->last_used - q->first_empty;
3459 if (s <= 0)
3460 s += q->n_bd;
3461 s -= 2; /* keep some reserve to not confuse empty and full situations */
3462 if (s < 0)
3463 s = 0;
3464 return s;
3465}
3466
3467static inline int ipw_queue_inc_wrap(int index, int n_bd)
3468{
3469 return (++index == n_bd) ? 0 : index;
3470}
3471
3472/**
3473 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003474 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003475 * @param q queue to init
3476 * @param count Number of BD's to allocate. Should be power of 2
3477 * @param read_register Address for 'read' register
3478 * (not offset within BAR, full address)
3479 * @param write_register Address for 'write' register
3480 * (not offset within BAR, full address)
3481 * @param base_register Address for 'base' register
3482 * (not offset within BAR, full address)
3483 * @param size Address for 'size' register
3484 * (not offset within BAR, full address)
3485 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003486static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003487 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003488{
3489 q->n_bd = count;
3490
3491 q->low_mark = q->n_bd / 4;
3492 if (q->low_mark < 4)
3493 q->low_mark = 4;
3494
3495 q->high_mark = q->n_bd / 8;
3496 if (q->high_mark < 2)
3497 q->high_mark = 2;
3498
3499 q->first_empty = q->last_used = 0;
3500 q->reg_r = read;
3501 q->reg_w = write;
3502
3503 ipw_write32(priv, base, q->dma_addr);
3504 ipw_write32(priv, size, count);
3505 ipw_write32(priv, read, 0);
3506 ipw_write32(priv, write, 0);
3507
3508 _ipw_read32(priv, 0x90);
3509}
3510
Jeff Garzikbf794512005-07-31 13:07:26 -04003511static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003512 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003513 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003514{
3515 struct pci_dev *dev = priv->pci_dev;
3516
3517 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3518 if (!q->txb) {
3519 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3520 return -ENOMEM;
3521 }
3522
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003523 q->bd =
3524 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003525 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003526 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003527 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003528 kfree(q->txb);
3529 q->txb = NULL;
3530 return -ENOMEM;
3531 }
3532
3533 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3534 return 0;
3535}
3536
3537/**
3538 * Free one TFD, those at index [txq->q.last_used].
3539 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003540 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003541 * @param dev
3542 * @param txq
3543 */
3544static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3545 struct clx2_tx_queue *txq)
3546{
3547 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3548 struct pci_dev *dev = priv->pci_dev;
3549 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003550
James Ketrenos43f66a62005-03-25 12:31:53 -06003551 /* classify bd */
3552 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3553 /* nothing to cleanup after for host commands */
3554 return;
3555
3556 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003557 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3558 IPW_ERROR("Too many chunks: %i\n",
3559 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003560 /** @todo issue fatal error, it is quite serious situation */
3561 return;
3562 }
3563
3564 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003565 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3566 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3567 le16_to_cpu(bd->u.data.chunk_len[i]),
3568 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003569 if (txq->txb[txq->q.last_used]) {
3570 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3571 txq->txb[txq->q.last_used] = NULL;
3572 }
3573 }
3574}
3575
3576/**
3577 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003578 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003579 * Empty queue by removing and destroying all BD's.
3580 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003581 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003582 * @param dev
3583 * @param q
3584 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003585static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003586{
3587 struct clx2_queue *q = &txq->q;
3588 struct pci_dev *dev = priv->pci_dev;
3589
Jeff Garzikbf794512005-07-31 13:07:26 -04003590 if (q->n_bd == 0)
3591 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003592
3593 /* first, empty all BD's */
3594 for (; q->first_empty != q->last_used;
3595 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3596 ipw_queue_tx_free_tfd(priv, txq);
3597 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003598
James Ketrenos43f66a62005-03-25 12:31:53 -06003599 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003600 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003601 q->dma_addr);
3602 kfree(txq->txb);
3603
3604 /* 0 fill whole structure */
3605 memset(txq, 0, sizeof(*txq));
3606}
3607
James Ketrenos43f66a62005-03-25 12:31:53 -06003608/**
3609 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003610 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003611 * @param priv
3612 */
3613static void ipw_tx_queue_free(struct ipw_priv *priv)
3614{
3615 /* Tx CMD queue */
3616 ipw_queue_tx_free(priv, &priv->txq_cmd);
3617
3618 /* Tx queues */
3619 ipw_queue_tx_free(priv, &priv->txq[0]);
3620 ipw_queue_tx_free(priv, &priv->txq[1]);
3621 ipw_queue_tx_free(priv, &priv->txq[2]);
3622 ipw_queue_tx_free(priv, &priv->txq[3]);
3623}
3624
Arjan van de Ven858119e2006-01-14 13:20:43 -08003625static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003626{
3627 /* First 3 bytes are manufacturer */
3628 bssid[0] = priv->mac_addr[0];
3629 bssid[1] = priv->mac_addr[1];
3630 bssid[2] = priv->mac_addr[2];
3631
3632 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003633 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003634
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003635 bssid[0] &= 0xfe; /* clear multicast bit */
3636 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003637}
3638
Arjan van de Ven858119e2006-01-14 13:20:43 -08003639static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003640{
3641 struct ipw_station_entry entry;
3642 int i;
3643
3644 for (i = 0; i < priv->num_stations; i++) {
3645 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3646 /* Another node is active in network */
3647 priv->missed_adhoc_beacons = 0;
3648 if (!(priv->config & CFG_STATIC_CHANNEL))
3649 /* when other nodes drop out, we drop out */
3650 priv->config &= ~CFG_ADHOC_PERSIST;
3651
3652 return i;
3653 }
3654 }
3655
3656 if (i == MAX_STATIONS)
3657 return IPW_INVALID_STATION;
3658
3659 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3660
3661 entry.reserved = 0;
3662 entry.support_mode = 0;
3663 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3664 memcpy(priv->stations[i], bssid, ETH_ALEN);
3665 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003666 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003667 priv->num_stations++;
3668
3669 return i;
3670}
3671
Arjan van de Ven858119e2006-01-14 13:20:43 -08003672static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003673{
3674 int i;
3675
Jeff Garzikbf794512005-07-31 13:07:26 -04003676 for (i = 0; i < priv->num_stations; i++)
3677 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003678 return i;
3679
3680 return IPW_INVALID_STATION;
3681}
3682
3683static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3684{
3685 int err;
3686
Hong Liu7b996592005-08-25 17:36:13 +08003687 if (priv->status & STATUS_ASSOCIATING) {
3688 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3689 queue_work(priv->workqueue, &priv->disassociate);
3690 return;
3691 }
3692
3693 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003694 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3695 return;
3696 }
3697
3698 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3699 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04003700 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06003701 priv->assoc_request.channel);
3702
3703 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3704 priv->status |= STATUS_DISASSOCIATING;
3705
3706 if (quiet)
3707 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3708 else
3709 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003710
James Ketrenos43f66a62005-03-25 12:31:53 -06003711 err = ipw_send_associate(priv, &priv->assoc_request);
3712 if (err) {
3713 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3714 "failed.\n");
3715 return;
3716 }
3717
3718}
3719
James Ketrenosc848d0a2005-08-24 21:56:24 -05003720static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003721{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003722 struct ipw_priv *priv = data;
3723 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3724 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003725 ipw_send_disassociate(data, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003726 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003727}
3728
James Ketrenosc848d0a2005-08-24 21:56:24 -05003729static void ipw_bg_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003730{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003731 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08003732 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003733 ipw_disassociate(data);
Zhu Yi46441512006-01-24 16:37:59 +08003734 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003735}
3736
Zhu Yid8bad6d2005-07-13 12:25:38 -05003737static void ipw_system_config(void *data)
3738{
3739 struct ipw_priv *priv = data;
3740 ipw_send_system_config(priv, &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06003741}
3742
3743struct ipw_status_code {
3744 u16 status;
3745 const char *reason;
3746};
3747
3748static const struct ipw_status_code ipw_status_codes[] = {
3749 {0x00, "Successful"},
3750 {0x01, "Unspecified failure"},
3751 {0x0A, "Cannot support all requested capabilities in the "
3752 "Capability information field"},
3753 {0x0B, "Reassociation denied due to inability to confirm that "
3754 "association exists"},
3755 {0x0C, "Association denied due to reason outside the scope of this "
3756 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003757 {0x0D,
3758 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003759 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003760 {0x0E,
3761 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003762 "transaction sequence number out of expected sequence"},
3763 {0x0F, "Authentication rejected because of challenge failure"},
3764 {0x10, "Authentication rejected due to timeout waiting for next "
3765 "frame in sequence"},
3766 {0x11, "Association denied because AP is unable to handle additional "
3767 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003768 {0x12,
3769 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003770 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003771 {0x13,
3772 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003773 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003774 {0x14,
3775 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003776 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003777 {0x15,
3778 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003779 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003780 {0x19,
3781 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003782 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003783 {0x1A,
3784 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003785 "DSSS-OFDM operation"},
3786 {0x28, "Invalid Information Element"},
3787 {0x29, "Group Cipher is not valid"},
3788 {0x2A, "Pairwise Cipher is not valid"},
3789 {0x2B, "AKMP is not valid"},
3790 {0x2C, "Unsupported RSN IE version"},
3791 {0x2D, "Invalid RSN IE Capabilities"},
3792 {0x2E, "Cipher suite is rejected per security policy"},
3793};
3794
Brice Goglin0f52bf92005-12-01 01:41:46 -08003795#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04003796static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003797{
3798 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003799 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003800 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003801 return ipw_status_codes[i].reason;
3802 return "Unknown status value.";
3803}
3804#endif
3805
3806static void inline average_init(struct average *avg)
3807{
3808 memset(avg, 0, sizeof(*avg));
3809}
3810
Arjan van de Ven858119e2006-01-14 13:20:43 -08003811static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06003812{
3813 avg->sum -= avg->entries[avg->pos];
3814 avg->sum += val;
3815 avg->entries[avg->pos++] = val;
3816 if (unlikely(avg->pos == AVG_ENTRIES)) {
3817 avg->init = 1;
3818 avg->pos = 0;
3819 }
3820}
3821
Arjan van de Ven858119e2006-01-14 13:20:43 -08003822static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06003823{
3824 if (!unlikely(avg->init)) {
3825 if (avg->pos)
3826 return avg->sum / avg->pos;
3827 return 0;
3828 }
3829
3830 return avg->sum / AVG_ENTRIES;
3831}
3832
3833static void ipw_reset_stats(struct ipw_priv *priv)
3834{
3835 u32 len = sizeof(u32);
3836
3837 priv->quality = 0;
3838
3839 average_init(&priv->average_missed_beacons);
3840 average_init(&priv->average_rssi);
3841 average_init(&priv->average_noise);
3842
3843 priv->last_rate = 0;
3844 priv->last_missed_beacons = 0;
3845 priv->last_rx_packets = 0;
3846 priv->last_tx_packets = 0;
3847 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003848
James Ketrenos43f66a62005-03-25 12:31:53 -06003849 /* Firmware managed, reset only when NIC is restarted, so we have to
3850 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003851 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003852 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003853 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003854 &priv->last_tx_failures, &len);
3855
3856 /* Driver managed, reset with each association */
3857 priv->missed_adhoc_beacons = 0;
3858 priv->missed_beacons = 0;
3859 priv->tx_packets = 0;
3860 priv->rx_packets = 0;
3861
3862}
3863
Arjan van de Ven858119e2006-01-14 13:20:43 -08003864static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003865{
3866 u32 i = 0x80000000;
3867 u32 mask = priv->rates_mask;
3868 /* If currently associated in B mode, restrict the maximum
3869 * rate match to B rates */
3870 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3871 mask &= IEEE80211_CCK_RATES_MASK;
3872
3873 /* TODO: Verify that the rate is supported by the current rates
3874 * list. */
3875
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003876 while (i && !(mask & i))
3877 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003878 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003879 case IEEE80211_CCK_RATE_1MB_MASK:
3880 return 1000000;
3881 case IEEE80211_CCK_RATE_2MB_MASK:
3882 return 2000000;
3883 case IEEE80211_CCK_RATE_5MB_MASK:
3884 return 5500000;
3885 case IEEE80211_OFDM_RATE_6MB_MASK:
3886 return 6000000;
3887 case IEEE80211_OFDM_RATE_9MB_MASK:
3888 return 9000000;
3889 case IEEE80211_CCK_RATE_11MB_MASK:
3890 return 11000000;
3891 case IEEE80211_OFDM_RATE_12MB_MASK:
3892 return 12000000;
3893 case IEEE80211_OFDM_RATE_18MB_MASK:
3894 return 18000000;
3895 case IEEE80211_OFDM_RATE_24MB_MASK:
3896 return 24000000;
3897 case IEEE80211_OFDM_RATE_36MB_MASK:
3898 return 36000000;
3899 case IEEE80211_OFDM_RATE_48MB_MASK:
3900 return 48000000;
3901 case IEEE80211_OFDM_RATE_54MB_MASK:
3902 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003903 }
3904
Jeff Garzikbf794512005-07-31 13:07:26 -04003905 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06003906 return 11000000;
3907 else
3908 return 54000000;
3909}
3910
3911static u32 ipw_get_current_rate(struct ipw_priv *priv)
3912{
3913 u32 rate, len = sizeof(rate);
3914 int err;
3915
Jeff Garzikbf794512005-07-31 13:07:26 -04003916 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003917 return 0;
3918
3919 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04003920 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06003921 &len);
3922 if (err) {
3923 IPW_DEBUG_INFO("failed querying ordinals.\n");
3924 return 0;
3925 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003926 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06003927 return ipw_get_max_rate(priv);
3928
3929 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003930 case IPW_TX_RATE_1MB:
3931 return 1000000;
3932 case IPW_TX_RATE_2MB:
3933 return 2000000;
3934 case IPW_TX_RATE_5MB:
3935 return 5500000;
3936 case IPW_TX_RATE_6MB:
3937 return 6000000;
3938 case IPW_TX_RATE_9MB:
3939 return 9000000;
3940 case IPW_TX_RATE_11MB:
3941 return 11000000;
3942 case IPW_TX_RATE_12MB:
3943 return 12000000;
3944 case IPW_TX_RATE_18MB:
3945 return 18000000;
3946 case IPW_TX_RATE_24MB:
3947 return 24000000;
3948 case IPW_TX_RATE_36MB:
3949 return 36000000;
3950 case IPW_TX_RATE_48MB:
3951 return 48000000;
3952 case IPW_TX_RATE_54MB:
3953 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003954 }
3955
3956 return 0;
3957}
3958
James Ketrenos43f66a62005-03-25 12:31:53 -06003959#define IPW_STATS_INTERVAL (2 * HZ)
3960static void ipw_gather_stats(struct ipw_priv *priv)
3961{
3962 u32 rx_err, rx_err_delta, rx_packets_delta;
3963 u32 tx_failures, tx_failures_delta, tx_packets_delta;
3964 u32 missed_beacons_percent, missed_beacons_delta;
3965 u32 quality = 0;
3966 u32 len = sizeof(u32);
3967 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04003968 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003969 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05003970 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06003971
3972 if (!(priv->status & STATUS_ASSOCIATED)) {
3973 priv->quality = 0;
3974 return;
3975 }
3976
3977 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04003978 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06003979 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003980 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06003981 priv->last_missed_beacons = priv->missed_beacons;
3982 if (priv->assoc_request.beacon_interval) {
3983 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003984 (HZ * priv->assoc_request.beacon_interval) /
3985 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06003986 } else {
3987 missed_beacons_percent = 0;
3988 }
3989 average_add(&priv->average_missed_beacons, missed_beacons_percent);
3990
3991 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
3992 rx_err_delta = rx_err - priv->last_rx_err;
3993 priv->last_rx_err = rx_err;
3994
3995 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
3996 tx_failures_delta = tx_failures - priv->last_tx_failures;
3997 priv->last_tx_failures = tx_failures;
3998
3999 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
4000 priv->last_rx_packets = priv->rx_packets;
4001
4002 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
4003 priv->last_tx_packets = priv->tx_packets;
4004
4005 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04004006 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004007 * Missed beacon: 100% = 0, 0% = 70% missed
4008 * Rate: 60% = 1Mbs, 100% = Max
4009 * Rx and Tx errors represent a straight % of total Rx/Tx
4010 * RSSI: 100% = > -50, 0% = < -80
4011 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04004012 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004013 * The lowest computed quality is used.
4014 *
4015 */
4016#define BEACON_THRESHOLD 5
4017 beacon_quality = 100 - missed_beacons_percent;
4018 if (beacon_quality < BEACON_THRESHOLD)
4019 beacon_quality = 0;
4020 else
Jeff Garzikbf794512005-07-31 13:07:26 -04004021 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004022 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04004023 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004024 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04004025
James Ketrenos43f66a62005-03-25 12:31:53 -06004026 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004027 max_rate = ipw_get_max_rate(priv);
4028 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004029 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4030 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004031
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004032 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004033 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004034 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004035 else
4036 rx_quality = 100;
4037 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4038 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004039
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004040 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004041 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004042 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004043 else
4044 tx_quality = 100;
4045 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4046 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004047
James Ketrenos43f66a62005-03-25 12:31:53 -06004048 rssi = average_value(&priv->average_rssi);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004049 signal_quality =
4050 (100 *
4051 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4052 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4053 (priv->ieee->perfect_rssi - rssi) *
4054 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4055 62 * (priv->ieee->perfect_rssi - rssi))) /
4056 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4057 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4058 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004059 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004060 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004061 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004062
James Ketrenos43f66a62005-03-25 12:31:53 -06004063 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
4064 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004065
4066 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06004067 min(rate_quality,
4068 min(tx_quality, min(rx_quality, signal_quality))));
4069 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004070 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4071 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004072 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004073 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4074 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004075 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004076 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4077 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004078 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004079 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4080 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004081 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004082 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4083 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004084
4085 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004086
4087 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004088 IPW_STATS_INTERVAL);
4089}
4090
James Ketrenosc848d0a2005-08-24 21:56:24 -05004091static void ipw_bg_gather_stats(void *data)
4092{
4093 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08004094 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004095 ipw_gather_stats(data);
Zhu Yi46441512006-01-24 16:37:59 +08004096 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004097}
4098
Ben Cahille7582562005-10-06 15:34:41 -05004099/* Missed beacon behavior:
4100 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4101 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4102 * Above disassociate threshold, give up and stop scanning.
4103 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004104static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004105 int missed_count)
4106{
4107 priv->notif_missed_beacons = missed_count;
4108
James Ketrenosafbf30a2005-08-25 00:05:33 -05004109 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004110 priv->status & STATUS_ASSOCIATED) {
4111 /* If associated and we've hit the missed
4112 * beacon threshold, disassociate, turn
4113 * off roaming, and abort any active scans */
4114 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004115 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004116 "Missed beacon: %d - disassociate\n", missed_count);
4117 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004118 if (priv->status & STATUS_SCANNING) {
4119 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4120 IPW_DL_STATE,
4121 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004122 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004123 }
4124
James Ketrenosea2b26e2005-08-24 21:25:16 -05004125 queue_work(priv->workqueue, &priv->disassociate);
4126 return;
4127 }
4128
4129 if (priv->status & STATUS_ROAMING) {
4130 /* If we are currently roaming, then just
4131 * print a debug statement... */
4132 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4133 "Missed beacon: %d - roam in progress\n",
4134 missed_count);
4135 return;
4136 }
4137
Zhu Yi4bfdb912006-01-24 16:37:16 +08004138 if (roaming &&
4139 (missed_count > priv->roaming_threshold &&
4140 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004141 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004142 * bit in the status and kick off a scan.
4143 * This can happen several times before we reach
4144 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004145 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4146 "Missed beacon: %d - initiate "
4147 "roaming\n", missed_count);
4148 if (!(priv->status & STATUS_ROAMING)) {
4149 priv->status |= STATUS_ROAMING;
4150 if (!(priv->status & STATUS_SCANNING))
4151 queue_work(priv->workqueue,
4152 &priv->request_scan);
4153 }
4154 return;
4155 }
4156
4157 if (priv->status & STATUS_SCANNING) {
4158 /* Stop scan to keep fw from getting
4159 * stuck (only if we aren't roaming --
4160 * otherwise we'll never scan more than 2 or 3
4161 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004162 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4163 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004164 queue_work(priv->workqueue, &priv->abort_scan);
4165 }
4166
4167 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004168}
4169
James Ketrenos43f66a62005-03-25 12:31:53 -06004170/**
4171 * Handle host notification packet.
4172 * Called from interrupt routine
4173 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004174static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004175 struct ipw_rx_notification *notif)
4176{
James Ketrenosa613bff2005-08-24 21:43:11 -05004177 notif->size = le16_to_cpu(notif->size);
4178
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004179 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004180
James Ketrenos43f66a62005-03-25 12:31:53 -06004181 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004182 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4183 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004184
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004185 switch (assoc->state) {
4186 case CMAS_ASSOCIATED:{
4187 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4188 IPW_DL_ASSOC,
4189 "associated: '%s' " MAC_FMT
4190 " \n",
4191 escape_essid(priv->essid,
4192 priv->essid_len),
4193 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04004194
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004195 switch (priv->ieee->iw_mode) {
4196 case IW_MODE_INFRA:
4197 memcpy(priv->ieee->bssid,
4198 priv->bssid, ETH_ALEN);
4199 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004200
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004201 case IW_MODE_ADHOC:
4202 memcpy(priv->ieee->bssid,
4203 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004204
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004205 /* clear out the station table */
4206 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004207
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004208 IPW_DEBUG_ASSOC
4209 ("queueing adhoc check\n");
4210 queue_delayed_work(priv->
4211 workqueue,
4212 &priv->
4213 adhoc_check,
4214 priv->
4215 assoc_request.
4216 beacon_interval);
4217 break;
4218 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004219
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004220 priv->status &= ~STATUS_ASSOCIATING;
4221 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004222 queue_work(priv->workqueue,
4223 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004224
James Ketrenosb095c382005-08-24 22:04:42 -05004225#ifdef CONFIG_IPW_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004226#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4227 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4228 if ((priv->status & STATUS_AUTH) &&
4229 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4230 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004231 if ((sizeof
4232 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004233 ieee80211_assoc_response)
James Ketrenosb095c382005-08-24 22:04:42 -05004234 <= notif->size)
4235 && (notif->size <= 2314)) {
4236 struct
4237 ieee80211_rx_stats
4238 stats = {
4239 .len =
4240 notif->
4241 size - 1,
4242 };
4243
4244 IPW_DEBUG_QOS
4245 ("QoS Associate "
4246 "size %d\n",
4247 notif->size);
4248 ieee80211_rx_mgt(priv->
4249 ieee,
4250 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004251 ieee80211_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004252 *)
4253 &notif->u.raw, &stats);
4254 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004255 }
James Ketrenosb095c382005-08-24 22:04:42 -05004256#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004257
James Ketrenosa613bff2005-08-24 21:43:11 -05004258 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004259
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004260 break;
4261 }
4262
4263 case CMAS_AUTHENTICATED:{
4264 if (priv->
4265 status & (STATUS_ASSOCIATED |
4266 STATUS_AUTH)) {
Brice Goglin0f52bf92005-12-01 01:41:46 -08004267#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004268 struct notif_authenticate *auth
4269 = &notif->u.auth;
4270 IPW_DEBUG(IPW_DL_NOTIF |
4271 IPW_DL_STATE |
4272 IPW_DL_ASSOC,
4273 "deauthenticated: '%s' "
4274 MAC_FMT
4275 ": (0x%04X) - %s \n",
4276 escape_essid(priv->
4277 essid,
4278 priv->
4279 essid_len),
4280 MAC_ARG(priv->bssid),
4281 ntohs(auth->status),
4282 ipw_get_status_code
4283 (ntohs
4284 (auth->status)));
4285#endif
4286
4287 priv->status &=
4288 ~(STATUS_ASSOCIATING |
4289 STATUS_AUTH |
4290 STATUS_ASSOCIATED);
4291
James Ketrenosa613bff2005-08-24 21:43:11 -05004292 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004293 break;
4294 }
4295
4296 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4297 IPW_DL_ASSOC,
4298 "authenticated: '%s' " MAC_FMT
4299 "\n",
4300 escape_essid(priv->essid,
4301 priv->essid_len),
4302 MAC_ARG(priv->bssid));
4303 break;
4304 }
4305
4306 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004307 if (priv->status & STATUS_AUTH) {
4308 struct
4309 ieee80211_assoc_response
4310 *resp;
4311 resp =
4312 (struct
4313 ieee80211_assoc_response
4314 *)&notif->u.raw;
4315 IPW_DEBUG(IPW_DL_NOTIF |
4316 IPW_DL_STATE |
4317 IPW_DL_ASSOC,
4318 "association failed (0x%04X): %s\n",
4319 ntohs(resp->status),
4320 ipw_get_status_code
4321 (ntohs
4322 (resp->status)));
4323 }
4324
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004325 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4326 IPW_DL_ASSOC,
4327 "disassociated: '%s' " MAC_FMT
4328 " \n",
4329 escape_essid(priv->essid,
4330 priv->essid_len),
4331 MAC_ARG(priv->bssid));
4332
4333 priv->status &=
4334 ~(STATUS_DISASSOCIATING |
4335 STATUS_ASSOCIATING |
4336 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004337 if (priv->assoc_network
4338 && (priv->assoc_network->
4339 capability &
4340 WLAN_CAPABILITY_IBSS))
4341 ipw_remove_current_network
4342 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004343
James Ketrenosa613bff2005-08-24 21:43:11 -05004344 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004345
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004346 break;
4347 }
4348
James Ketrenosb095c382005-08-24 22:04:42 -05004349 case CMAS_RX_ASSOC_RESP:
4350 break;
4351
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004352 default:
4353 IPW_ERROR("assoc: unknown (%d)\n",
4354 assoc->state);
4355 break;
4356 }
4357
James Ketrenos43f66a62005-03-25 12:31:53 -06004358 break;
4359 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004360
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004361 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4362 struct notif_authenticate *auth = &notif->u.auth;
4363 switch (auth->state) {
4364 case CMAS_AUTHENTICATED:
4365 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4366 "authenticated: '%s' " MAC_FMT " \n",
4367 escape_essid(priv->essid,
4368 priv->essid_len),
4369 MAC_ARG(priv->bssid));
4370 priv->status |= STATUS_AUTH;
4371 break;
4372
4373 case CMAS_INIT:
4374 if (priv->status & STATUS_AUTH) {
4375 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4376 IPW_DL_ASSOC,
4377 "authentication failed (0x%04X): %s\n",
4378 ntohs(auth->status),
4379 ipw_get_status_code(ntohs
4380 (auth->
4381 status)));
4382 }
4383 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4384 IPW_DL_ASSOC,
4385 "deauthenticated: '%s' " MAC_FMT "\n",
4386 escape_essid(priv->essid,
4387 priv->essid_len),
4388 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004389
4390 priv->status &= ~(STATUS_ASSOCIATING |
4391 STATUS_AUTH |
4392 STATUS_ASSOCIATED);
4393
James Ketrenosa613bff2005-08-24 21:43:11 -05004394 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004395 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004396
4397 case CMAS_TX_AUTH_SEQ_1:
4398 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4399 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4400 break;
4401 case CMAS_RX_AUTH_SEQ_2:
4402 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4403 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4404 break;
4405 case CMAS_AUTH_SEQ_1_PASS:
4406 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4407 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4408 break;
4409 case CMAS_AUTH_SEQ_1_FAIL:
4410 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4411 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4412 break;
4413 case CMAS_TX_AUTH_SEQ_3:
4414 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4415 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4416 break;
4417 case CMAS_RX_AUTH_SEQ_4:
4418 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4419 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4420 break;
4421 case CMAS_AUTH_SEQ_2_PASS:
4422 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4423 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4424 break;
4425 case CMAS_AUTH_SEQ_2_FAIL:
4426 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4427 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4428 break;
4429 case CMAS_TX_ASSOC:
4430 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4431 IPW_DL_ASSOC, "TX_ASSOC\n");
4432 break;
4433 case CMAS_RX_ASSOC_RESP:
4434 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4435 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004436
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004437 break;
4438 case CMAS_ASSOCIATED:
4439 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4440 IPW_DL_ASSOC, "ASSOCIATED\n");
4441 break;
4442 default:
4443 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4444 auth->state);
4445 break;
4446 }
4447 break;
4448 }
4449
4450 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4451 struct notif_channel_result *x =
4452 &notif->u.channel_result;
4453
4454 if (notif->size == sizeof(*x)) {
4455 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4456 x->channel_num);
4457 } else {
4458 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4459 "(should be %zd)\n",
4460 notif->size, sizeof(*x));
4461 }
4462 break;
4463 }
4464
4465 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4466 struct notif_scan_complete *x = &notif->u.scan_complete;
4467 if (notif->size == sizeof(*x)) {
4468 IPW_DEBUG_SCAN
4469 ("Scan completed: type %d, %d channels, "
4470 "%d status\n", x->scan_type,
4471 x->num_channels, x->status);
4472 } else {
4473 IPW_ERROR("Scan completed of wrong size %d "
4474 "(should be %zd)\n",
4475 notif->size, sizeof(*x));
4476 }
4477
4478 priv->status &=
4479 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4480
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004481 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004482 cancel_delayed_work(&priv->scan_check);
4483
James Ketrenosb095c382005-08-24 22:04:42 -05004484 if (priv->status & STATUS_EXIT_PENDING)
4485 break;
4486
4487 priv->ieee->scans++;
4488
4489#ifdef CONFIG_IPW2200_MONITOR
4490 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004491 priv->status |= STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004492 queue_work(priv->workqueue,
4493 &priv->request_scan);
4494 break;
4495 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004496 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004497#endif /* CONFIG_IPW2200_MONITOR */
4498
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004499 if (!(priv->status & (STATUS_ASSOCIATED |
4500 STATUS_ASSOCIATING |
4501 STATUS_ROAMING |
4502 STATUS_DISASSOCIATING)))
4503 queue_work(priv->workqueue, &priv->associate);
4504 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004505 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4506 /* If a scan completed and we are in roam mode, then
4507 * the scan that completed was the one requested as a
4508 * result of entering roam... so, schedule the
4509 * roam work */
4510 queue_work(priv->workqueue,
4511 &priv->roam);
4512 else
4513 /* Don't schedule if we aborted the scan */
4514 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004515 } else if (priv->status & STATUS_SCAN_PENDING)
4516 queue_work(priv->workqueue,
4517 &priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004518 else if (priv->config & CFG_BACKGROUND_SCAN
4519 && priv->status & STATUS_ASSOCIATED)
4520 queue_delayed_work(priv->workqueue,
4521 &priv->request_scan, HZ);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004522 break;
4523 }
4524
4525 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4526 struct notif_frag_length *x = &notif->u.frag_len;
4527
James Ketrenosa613bff2005-08-24 21:43:11 -05004528 if (notif->size == sizeof(*x))
4529 IPW_ERROR("Frag length: %d\n",
4530 le16_to_cpu(x->frag_length));
4531 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004532 IPW_ERROR("Frag length of wrong size %d "
4533 "(should be %zd)\n",
4534 notif->size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004535 break;
4536 }
4537
4538 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4539 struct notif_link_deterioration *x =
4540 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004541
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004542 if (notif->size == sizeof(*x)) {
4543 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4544 "link deterioration: '%s' " MAC_FMT
4545 " \n", escape_essid(priv->essid,
4546 priv->essid_len),
4547 MAC_ARG(priv->bssid));
4548 memcpy(&priv->last_link_deterioration, x,
4549 sizeof(*x));
4550 } else {
4551 IPW_ERROR("Link Deterioration of wrong size %d "
4552 "(should be %zd)\n",
4553 notif->size, sizeof(*x));
4554 }
4555 break;
4556 }
4557
4558 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4559 IPW_ERROR("Dino config\n");
4560 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004561 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004562 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004563
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004564 break;
4565 }
4566
4567 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4568 struct notif_beacon_state *x = &notif->u.beacon_state;
4569 if (notif->size != sizeof(*x)) {
4570 IPW_ERROR
4571 ("Beacon state of wrong size %d (should "
4572 "be %zd)\n", notif->size, sizeof(*x));
4573 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004574 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004575
James Ketrenosa613bff2005-08-24 21:43:11 -05004576 if (le32_to_cpu(x->state) ==
4577 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4578 ipw_handle_missed_beacon(priv,
4579 le32_to_cpu(x->
4580 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004581
James Ketrenos43f66a62005-03-25 12:31:53 -06004582 break;
4583 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004584
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004585 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4586 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
4587 if (notif->size == sizeof(*x)) {
4588 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4589 "0x%02x station %d\n",
4590 x->key_state, x->security_type,
4591 x->station_index);
4592 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004593 }
4594
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004595 IPW_ERROR
4596 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4597 notif->size, sizeof(*x));
4598 break;
4599 }
4600
4601 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4602 struct notif_calibration *x = &notif->u.calibration;
4603
4604 if (notif->size == sizeof(*x)) {
4605 memcpy(&priv->calib, x, sizeof(*x));
4606 IPW_DEBUG_INFO("TODO: Calibration\n");
4607 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004608 }
4609
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004610 IPW_ERROR
4611 ("Calibration of wrong size %d (should be %zd)\n",
4612 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004613 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004614 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004615
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004616 case HOST_NOTIFICATION_NOISE_STATS:{
4617 if (notif->size == sizeof(u32)) {
4618 priv->last_noise =
James Ketrenosa613bff2005-08-24 21:43:11 -05004619 (u8) (le32_to_cpu(notif->u.noise.value) &
4620 0xff);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004621 average_add(&priv->average_noise,
4622 priv->last_noise);
4623 break;
4624 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004625
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004626 IPW_ERROR
4627 ("Noise stat is wrong size %d (should be %zd)\n",
4628 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004629 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004630 }
4631
James Ketrenos43f66a62005-03-25 12:31:53 -06004632 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004633 IPW_DEBUG_NOTIF("Unknown notification: "
4634 "subtype=%d,flags=0x%2x,size=%d\n",
4635 notif->subtype, notif->flags, notif->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004636 }
4637}
4638
4639/**
4640 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004641 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004642 * @param priv
4643 * @return error code
4644 */
4645static int ipw_queue_reset(struct ipw_priv *priv)
4646{
4647 int rc = 0;
4648 /** @todo customize queue sizes */
4649 int nTx = 64, nTxCmd = 8;
4650 ipw_tx_queue_free(priv);
4651 /* Tx CMD queue */
4652 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004653 IPW_TX_CMD_QUEUE_READ_INDEX,
4654 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4655 IPW_TX_CMD_QUEUE_BD_BASE,
4656 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004657 if (rc) {
4658 IPW_ERROR("Tx Cmd queue init failed\n");
4659 goto error;
4660 }
4661 /* Tx queue(s) */
4662 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004663 IPW_TX_QUEUE_0_READ_INDEX,
4664 IPW_TX_QUEUE_0_WRITE_INDEX,
4665 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004666 if (rc) {
4667 IPW_ERROR("Tx 0 queue init failed\n");
4668 goto error;
4669 }
4670 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004671 IPW_TX_QUEUE_1_READ_INDEX,
4672 IPW_TX_QUEUE_1_WRITE_INDEX,
4673 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004674 if (rc) {
4675 IPW_ERROR("Tx 1 queue init failed\n");
4676 goto error;
4677 }
4678 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004679 IPW_TX_QUEUE_2_READ_INDEX,
4680 IPW_TX_QUEUE_2_WRITE_INDEX,
4681 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004682 if (rc) {
4683 IPW_ERROR("Tx 2 queue init failed\n");
4684 goto error;
4685 }
4686 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004687 IPW_TX_QUEUE_3_READ_INDEX,
4688 IPW_TX_QUEUE_3_WRITE_INDEX,
4689 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004690 if (rc) {
4691 IPW_ERROR("Tx 3 queue init failed\n");
4692 goto error;
4693 }
4694 /* statistics */
4695 priv->rx_bufs_min = 0;
4696 priv->rx_pend_max = 0;
4697 return rc;
4698
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004699 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004700 ipw_tx_queue_free(priv);
4701 return rc;
4702}
4703
4704/**
4705 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004706 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004707 * When FW adwances 'R' index, all entries between old and
4708 * new 'R' index need to be reclaimed. As result, some free space
4709 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004710 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004711 * @note Need to protect against garbage in 'R' index
4712 * @param priv
4713 * @param txq
4714 * @param qindex
4715 * @return Number of used entries remains in the queue
4716 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004717static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004718 struct clx2_tx_queue *txq, int qindex)
4719{
4720 u32 hw_tail;
4721 int used;
4722 struct clx2_queue *q = &txq->q;
4723
4724 hw_tail = ipw_read32(priv, q->reg_r);
4725 if (hw_tail >= q->n_bd) {
4726 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004727 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4728 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004729 goto done;
4730 }
4731 for (; q->last_used != hw_tail;
4732 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4733 ipw_queue_tx_free_tfd(priv, txq);
4734 priv->tx_packets++;
4735 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004736 done:
James Ketrenos9ddf84f2005-08-16 17:07:11 -05004737 if ((ipw_queue_space(q) > q->low_mark) &&
4738 (qindex >= 0) &&
4739 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4740 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06004741 used = q->first_empty - q->last_used;
4742 if (used < 0)
4743 used += q->n_bd;
4744
4745 return used;
4746}
4747
4748static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4749 int len, int sync)
4750{
4751 struct clx2_tx_queue *txq = &priv->txq_cmd;
4752 struct clx2_queue *q = &txq->q;
4753 struct tfd_frame *tfd;
4754
4755 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4756 IPW_ERROR("No space for Tx\n");
4757 return -EBUSY;
4758 }
4759
4760 tfd = &txq->bd[q->first_empty];
4761 txq->txb[q->first_empty] = NULL;
4762
4763 memset(tfd, 0, sizeof(*tfd));
4764 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4765 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4766 priv->hcmd_seq++;
4767 tfd->u.cmd.index = hcmd;
4768 tfd->u.cmd.length = len;
4769 memcpy(tfd->u.cmd.payload, buf, len);
4770 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4771 ipw_write32(priv, q->reg_w, q->first_empty);
4772 _ipw_read32(priv, 0x90);
4773
4774 return 0;
4775}
4776
Jeff Garzikbf794512005-07-31 13:07:26 -04004777/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004778 * Rx theory of operation
4779 *
4780 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05004781 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06004782 * 0 to 31
4783 *
4784 * Rx Queue Indexes
4785 * The host/firmware share two index registers for managing the Rx buffers.
4786 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004787 * The READ index maps to the first position that the firmware may be writing
4788 * to -- the driver can read up to (but not including) this position and get
4789 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06004790 * The READ index is managed by the firmware once the card is enabled.
4791 *
4792 * The WRITE index maps to the last position the driver has read from -- the
4793 * position preceding WRITE is the last slot the firmware can place a packet.
4794 *
4795 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04004796 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06004797 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004798 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06004799 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4800 *
4801 * When the firmware places a packet in a buffer it will advance the READ index
4802 * and fire the RX interrupt. The driver can then query the READ index and
4803 * process as many packets as possible, moving the WRITE index forward as it
4804 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04004805 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004806 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004807 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06004808 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04004809 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06004810 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4811 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4812 * 'processed' and 'read' driver indexes as well)
4813 * + A received packet is processed and handed to the kernel network stack,
4814 * detached from the ipw->rxq. The driver 'processed' index is updated.
4815 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04004816 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4817 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06004818 * were enough free buffers and RX_STALLED is set it is cleared.
4819 *
4820 *
4821 * Driver sequence:
4822 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004823 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06004824 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4825 * ipw_rx_queue_restock
4826 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4827 * queue, updates firmware pointers, and updates
4828 * the WRITE index. If insufficient rx_free buffers
4829 * are available, schedules ipw_rx_queue_replenish
4830 *
4831 * -- enable interrupts --
4832 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04004833 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06004834 * Moves the packet buffer from queue to rx_used.
4835 * Calls ipw_rx_queue_restock to refill any empty
4836 * slots.
4837 * ...
4838 *
4839 */
4840
Jeff Garzikbf794512005-07-31 13:07:26 -04004841/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004842 * If there are slots in the RX queue that need to be restocked,
4843 * and we have free pre-allocated buffers, fill the ranks as much
4844 * as we can pulling from rx_free.
4845 *
4846 * This moves the 'write' index forward to catch up with 'processed', and
4847 * also updates the memory address in the firmware to reference the new
4848 * target buffer.
4849 */
4850static void ipw_rx_queue_restock(struct ipw_priv *priv)
4851{
4852 struct ipw_rx_queue *rxq = priv->rxq;
4853 struct list_head *element;
4854 struct ipw_rx_mem_buffer *rxb;
4855 unsigned long flags;
4856 int write;
4857
4858 spin_lock_irqsave(&rxq->lock, flags);
4859 write = rxq->write;
4860 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4861 element = rxq->rx_free.next;
4862 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4863 list_del(element);
4864
James Ketrenosb095c382005-08-24 22:04:42 -05004865 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004866 rxb->dma_addr);
4867 rxq->queue[rxq->write] = rxb;
4868 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4869 rxq->free_count--;
4870 }
4871 spin_unlock_irqrestore(&rxq->lock, flags);
4872
Jeff Garzikbf794512005-07-31 13:07:26 -04004873 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06004874 * refill it */
4875 if (rxq->free_count <= RX_LOW_WATERMARK)
4876 queue_work(priv->workqueue, &priv->rx_replenish);
4877
4878 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04004879 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05004880 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06004881}
4882
4883/*
4884 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04004885 * Also restock the Rx queue via ipw_rx_queue_restock.
4886 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004887 * This is called as a scheduled work item (except for during intialization)
4888 */
4889static void ipw_rx_queue_replenish(void *data)
4890{
4891 struct ipw_priv *priv = data;
4892 struct ipw_rx_queue *rxq = priv->rxq;
4893 struct list_head *element;
4894 struct ipw_rx_mem_buffer *rxb;
4895 unsigned long flags;
4896
4897 spin_lock_irqsave(&rxq->lock, flags);
4898 while (!list_empty(&rxq->rx_used)) {
4899 element = rxq->rx_used.next;
4900 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05004901 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06004902 if (!rxb->skb) {
4903 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
4904 priv->net_dev->name);
4905 /* We don't reschedule replenish work here -- we will
4906 * call the restock method and if it still needs
4907 * more buffers it will schedule replenish */
4908 break;
4909 }
4910 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04004911
James Ketrenos43f66a62005-03-25 12:31:53 -06004912 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004913 rxb->dma_addr =
4914 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05004915 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04004916
James Ketrenos43f66a62005-03-25 12:31:53 -06004917 list_add_tail(&rxb->list, &rxq->rx_free);
4918 rxq->free_count++;
4919 }
4920 spin_unlock_irqrestore(&rxq->lock, flags);
4921
4922 ipw_rx_queue_restock(priv);
4923}
4924
James Ketrenosc848d0a2005-08-24 21:56:24 -05004925static void ipw_bg_rx_queue_replenish(void *data)
4926{
4927 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08004928 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004929 ipw_rx_queue_replenish(data);
Zhu Yi46441512006-01-24 16:37:59 +08004930 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004931}
4932
James Ketrenos43f66a62005-03-25 12:31:53 -06004933/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08004934 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04004935 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06004936 * non NULL it is unmapped and freed
4937 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004938static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06004939{
4940 int i;
4941
4942 if (!rxq)
4943 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04004944
James Ketrenos43f66a62005-03-25 12:31:53 -06004945 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4946 if (rxq->pool[i].skb != NULL) {
4947 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05004948 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004949 dev_kfree_skb(rxq->pool[i].skb);
4950 }
4951 }
4952
4953 kfree(rxq);
4954}
4955
4956static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4957{
4958 struct ipw_rx_queue *rxq;
4959 int i;
4960
Takisc75f4742005-12-01 01:41:45 -08004961 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02004962 if (unlikely(!rxq)) {
4963 IPW_ERROR("memory allocation failed\n");
4964 return NULL;
4965 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004966 spin_lock_init(&rxq->lock);
4967 INIT_LIST_HEAD(&rxq->rx_free);
4968 INIT_LIST_HEAD(&rxq->rx_used);
4969
4970 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04004971 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06004972 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4973
4974 /* Set us so that we have processed and used all buffers, but have
4975 * not restocked the Rx queue with fresh buffers */
4976 rxq->read = rxq->write = 0;
4977 rxq->processed = RX_QUEUE_SIZE - 1;
4978 rxq->free_count = 0;
4979
4980 return rxq;
4981}
4982
4983static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
4984{
4985 rate &= ~IEEE80211_BASIC_RATE_MASK;
4986 if (ieee_mode == IEEE_A) {
4987 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004988 case IEEE80211_OFDM_RATE_6MB:
4989 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004990 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004991 case IEEE80211_OFDM_RATE_9MB:
4992 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004993 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004994 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004995 return priv->
4996 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004997 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004998 return priv->
4999 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005000 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005001 return priv->
5002 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005003 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005004 return priv->
5005 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005006 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005007 return priv->
5008 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005009 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005010 return priv->
5011 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005012 default:
5013 return 0;
5014 }
5015 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005016
James Ketrenos43f66a62005-03-25 12:31:53 -06005017 /* B and G mixed */
5018 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005019 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005020 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005021 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005022 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005023 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005024 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005025 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005026 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
5027 }
5028
5029 /* If we are limited to B modulations, bail at this point */
5030 if (ieee_mode == IEEE_B)
5031 return 0;
5032
5033 /* G */
5034 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005035 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005036 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005037 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005038 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005039 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005040 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005041 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005042 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005043 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005044 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005045 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005046 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005047 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005048 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005049 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005050 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5051 }
5052
5053 return 0;
5054}
5055
Jeff Garzikbf794512005-07-31 13:07:26 -04005056static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005057 const struct ieee80211_network *network,
5058 struct ipw_supported_rates *rates)
5059{
5060 int num_rates, i;
5061
5062 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005063 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005064 rates->num_rates = 0;
5065 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005066 if (!ipw_is_rate_in_mask(priv, network->mode,
5067 network->rates[i])) {
5068
James Ketrenosea2b26e2005-08-24 21:25:16 -05005069 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005070 IPW_DEBUG_SCAN("Adding masked mandatory "
5071 "rate %02X\n",
5072 network->rates[i]);
5073 rates->supported_rates[rates->num_rates++] =
5074 network->rates[i];
5075 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005076 }
5077
James Ketrenos43f66a62005-03-25 12:31:53 -06005078 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5079 network->rates[i], priv->rates_mask);
5080 continue;
5081 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005082
James Ketrenos43f66a62005-03-25 12:31:53 -06005083 rates->supported_rates[rates->num_rates++] = network->rates[i];
5084 }
5085
James Ketrenosa613bff2005-08-24 21:43:11 -05005086 num_rates = min(network->rates_ex_len,
5087 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005088 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005089 if (!ipw_is_rate_in_mask(priv, network->mode,
5090 network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005091 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005092 IPW_DEBUG_SCAN("Adding masked mandatory "
5093 "rate %02X\n",
5094 network->rates_ex[i]);
5095 rates->supported_rates[rates->num_rates++] =
5096 network->rates[i];
5097 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005098 }
5099
James Ketrenos43f66a62005-03-25 12:31:53 -06005100 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5101 network->rates_ex[i], priv->rates_mask);
5102 continue;
5103 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005104
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005105 rates->supported_rates[rates->num_rates++] =
5106 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005107 }
5108
James Ketrenosea2b26e2005-08-24 21:25:16 -05005109 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005110}
5111
Arjan van de Ven858119e2006-01-14 13:20:43 -08005112static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005113 const struct ipw_supported_rates *src)
5114{
5115 u8 i;
5116 for (i = 0; i < src->num_rates; i++)
5117 dest->supported_rates[i] = src->supported_rates[i];
5118 dest->num_rates = src->num_rates;
5119}
5120
5121/* TODO: Look at sniffed packets in the air to determine if the basic rate
5122 * mask should ever be used -- right now all callers to add the scan rates are
5123 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5124static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005125 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005126{
Jeff Garzikbf794512005-07-31 13:07:26 -04005127 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005128 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005129
James Ketrenos43f66a62005-03-25 12:31:53 -06005130 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005131 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005132 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005133
5134 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005135 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005136 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005137
5138 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005139 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005140 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005141
5142 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005143 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005144 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005145}
5146
5147static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005148 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005149{
Jeff Garzikbf794512005-07-31 13:07:26 -04005150 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005151 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005152
5153 if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005154 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005155 IEEE80211_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005156
5157 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005158 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005159 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005160
5161 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005162 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005163 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005164
5165 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005166 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005167 IEEE80211_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005168
5169 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005170 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005171 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005172
5173 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005174 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005175 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005176
5177 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005178 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005179 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005180
5181 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005182 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005183 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005184}
5185
5186struct ipw_network_match {
5187 struct ieee80211_network *network;
5188 struct ipw_supported_rates rates;
5189};
5190
James Ketrenosc848d0a2005-08-24 21:56:24 -05005191static int ipw_find_adhoc_network(struct ipw_priv *priv,
5192 struct ipw_network_match *match,
5193 struct ieee80211_network *network,
5194 int roaming)
5195{
5196 struct ipw_supported_rates rates;
5197
5198 /* Verify that this network's capability is compatible with the
5199 * current mode (AdHoc or Infrastructure) */
5200 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5201 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5202 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5203 "capability mismatch.\n",
5204 escape_essid(network->ssid, network->ssid_len),
5205 MAC_ARG(network->bssid));
5206 return 0;
5207 }
5208
5209 /* If we do not have an ESSID for this AP, we can not associate with
5210 * it */
5211 if (network->flags & NETWORK_EMPTY_ESSID) {
5212 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5213 "because of hidden ESSID.\n",
5214 escape_essid(network->ssid, network->ssid_len),
5215 MAC_ARG(network->bssid));
5216 return 0;
5217 }
5218
5219 if (unlikely(roaming)) {
5220 /* If we are roaming, then ensure check if this is a valid
5221 * network to try and roam to */
5222 if ((network->ssid_len != match->network->ssid_len) ||
5223 memcmp(network->ssid, match->network->ssid,
5224 network->ssid_len)) {
5225 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5226 "because of non-network ESSID.\n",
5227 escape_essid(network->ssid,
5228 network->ssid_len),
5229 MAC_ARG(network->bssid));
5230 return 0;
5231 }
5232 } else {
5233 /* If an ESSID has been configured then compare the broadcast
5234 * ESSID to ours */
5235 if ((priv->config & CFG_STATIC_ESSID) &&
5236 ((network->ssid_len != priv->essid_len) ||
5237 memcmp(network->ssid, priv->essid,
5238 min(network->ssid_len, priv->essid_len)))) {
5239 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005240
James Ketrenosc848d0a2005-08-24 21:56:24 -05005241 strncpy(escaped,
5242 escape_essid(network->ssid, network->ssid_len),
5243 sizeof(escaped));
5244 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5245 "because of ESSID mismatch: '%s'.\n",
5246 escaped, MAC_ARG(network->bssid),
5247 escape_essid(priv->essid,
5248 priv->essid_len));
5249 return 0;
5250 }
5251 }
5252
5253 /* If the old network rate is better than this one, don't bother
5254 * testing everything else. */
5255
5256 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005257 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5258 "current network.\n",
5259 escape_essid(match->network->ssid,
5260 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005261 return 0;
5262 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005263 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5264 "current network.\n",
5265 escape_essid(match->network->ssid,
5266 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005267 return 0;
5268 }
5269
5270 /* Now go through and see if the requested network is valid... */
5271 if (priv->ieee->scan_age != 0 &&
5272 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5273 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005274 "because of age: %ums.\n",
James Ketrenosc848d0a2005-08-24 21:56:24 -05005275 escape_essid(network->ssid, network->ssid_len),
5276 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005277 jiffies_to_msecs(jiffies -
5278 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005279 return 0;
5280 }
5281
5282 if ((priv->config & CFG_STATIC_CHANNEL) &&
5283 (network->channel != priv->channel)) {
5284 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5285 "because of channel mismatch: %d != %d.\n",
5286 escape_essid(network->ssid, network->ssid_len),
5287 MAC_ARG(network->bssid),
5288 network->channel, priv->channel);
5289 return 0;
5290 }
5291
5292 /* Verify privacy compatability */
5293 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5294 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5295 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5296 "because of privacy mismatch: %s != %s.\n",
5297 escape_essid(network->ssid, network->ssid_len),
5298 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005299 priv->
5300 capability & CAP_PRIVACY_ON ? "on" : "off",
5301 network->
5302 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5303 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005304 return 0;
5305 }
5306
5307 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5308 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5309 "because of the same BSSID match: " MAC_FMT
5310 ".\n", escape_essid(network->ssid,
5311 network->ssid_len),
5312 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5313 return 0;
5314 }
5315
5316 /* Filter out any incompatible freq / mode combinations */
5317 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5318 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5319 "because of invalid frequency/mode "
5320 "combination.\n",
5321 escape_essid(network->ssid, network->ssid_len),
5322 MAC_ARG(network->bssid));
5323 return 0;
5324 }
5325
5326 /* Ensure that the rates supported by the driver are compatible with
5327 * this AP, including verification of basic rates (mandatory) */
5328 if (!ipw_compatible_rates(priv, network, &rates)) {
5329 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5330 "because configured rate mask excludes "
5331 "AP mandatory rate.\n",
5332 escape_essid(network->ssid, network->ssid_len),
5333 MAC_ARG(network->bssid));
5334 return 0;
5335 }
5336
5337 if (rates.num_rates == 0) {
5338 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5339 "because of no compatible rates.\n",
5340 escape_essid(network->ssid, network->ssid_len),
5341 MAC_ARG(network->bssid));
5342 return 0;
5343 }
5344
5345 /* TODO: Perform any further minimal comparititive tests. We do not
5346 * want to put too much policy logic here; intelligent scan selection
5347 * should occur within a generic IEEE 802.11 user space tool. */
5348
5349 /* Set up 'new' AP to this network */
5350 ipw_copy_rates(&match->rates, &rates);
5351 match->network = network;
5352 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5353 escape_essid(network->ssid, network->ssid_len),
5354 MAC_ARG(network->bssid));
5355
5356 return 1;
5357}
5358
5359static void ipw_merge_adhoc_network(void *data)
5360{
5361 struct ipw_priv *priv = data;
5362 struct ieee80211_network *network = NULL;
5363 struct ipw_network_match match = {
5364 .network = priv->assoc_network
5365 };
5366
James Ketrenosafbf30a2005-08-25 00:05:33 -05005367 if ((priv->status & STATUS_ASSOCIATED) &&
5368 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005369 /* First pass through ROAM process -- look for a better
5370 * network */
5371 unsigned long flags;
5372
5373 spin_lock_irqsave(&priv->ieee->lock, flags);
5374 list_for_each_entry(network, &priv->ieee->network_list, list) {
5375 if (network != priv->assoc_network)
5376 ipw_find_adhoc_network(priv, &match, network,
5377 1);
5378 }
5379 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5380
5381 if (match.network == priv->assoc_network) {
5382 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5383 "merge to.\n");
5384 return;
5385 }
5386
Zhu Yi46441512006-01-24 16:37:59 +08005387 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005388 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5389 IPW_DEBUG_MERGE("remove network %s\n",
5390 escape_essid(priv->essid,
5391 priv->essid_len));
5392 ipw_remove_current_network(priv);
5393 }
5394
5395 ipw_disassociate(priv);
5396 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005397 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005398 return;
5399 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005400}
5401
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005402static int ipw_best_network(struct ipw_priv *priv,
5403 struct ipw_network_match *match,
5404 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005405{
5406 struct ipw_supported_rates rates;
5407
5408 /* Verify that this network's capability is compatible with the
5409 * current mode (AdHoc or Infrastructure) */
5410 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005411 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005412 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5413 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5414 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005415 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005416 escape_essid(network->ssid, network->ssid_len),
5417 MAC_ARG(network->bssid));
5418 return 0;
5419 }
5420
5421 /* If we do not have an ESSID for this AP, we can not associate with
5422 * it */
5423 if (network->flags & NETWORK_EMPTY_ESSID) {
5424 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5425 "because of hidden ESSID.\n",
5426 escape_essid(network->ssid, network->ssid_len),
5427 MAC_ARG(network->bssid));
5428 return 0;
5429 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005430
James Ketrenos43f66a62005-03-25 12:31:53 -06005431 if (unlikely(roaming)) {
5432 /* If we are roaming, then ensure check if this is a valid
5433 * network to try and roam to */
5434 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005435 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005436 network->ssid_len)) {
5437 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5438 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04005439 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005440 network->ssid_len),
5441 MAC_ARG(network->bssid));
5442 return 0;
5443 }
5444 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005445 /* If an ESSID has been configured then compare the broadcast
5446 * ESSID to ours */
5447 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005448 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005449 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005450 min(network->ssid_len, priv->essid_len)))) {
5451 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005452 strncpy(escaped,
5453 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005454 sizeof(escaped));
5455 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005456 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005457 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005458 escape_essid(priv->essid,
5459 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005460 return 0;
5461 }
5462 }
5463
5464 /* If the old network rate is better than this one, don't bother
5465 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005466 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005467 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005468 strncpy(escaped,
5469 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005470 sizeof(escaped));
5471 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5472 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5473 escaped, MAC_ARG(network->bssid),
5474 escape_essid(match->network->ssid,
5475 match->network->ssid_len),
5476 MAC_ARG(match->network->bssid));
5477 return 0;
5478 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005479
James Ketrenos43f66a62005-03-25 12:31:53 -06005480 /* If this network has already had an association attempt within the
5481 * last 3 seconds, do not try and associate again... */
5482 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005483 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005484 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005485 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005486 "assoc attempt).\n",
5487 escape_essid(network->ssid, network->ssid_len),
5488 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005489 jiffies_to_msecs(jiffies -
5490 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005491 return 0;
5492 }
5493
5494 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005495 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005496 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005497 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005498 "because of age: %ums.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005499 escape_essid(network->ssid, network->ssid_len),
5500 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005501 jiffies_to_msecs(jiffies -
5502 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005503 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005504 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005505
Jeff Garzikbf794512005-07-31 13:07:26 -04005506 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005507 (network->channel != priv->channel)) {
5508 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5509 "because of channel mismatch: %d != %d.\n",
5510 escape_essid(network->ssid, network->ssid_len),
5511 MAC_ARG(network->bssid),
5512 network->channel, priv->channel);
5513 return 0;
5514 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005515
James Ketrenos43f66a62005-03-25 12:31:53 -06005516 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005517 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005518 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5519 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5520 "because of privacy mismatch: %s != %s.\n",
5521 escape_essid(network->ssid, network->ssid_len),
5522 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04005523 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005524 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005525 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005526 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005527 return 0;
5528 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005529
Stefan Rompf23afaec2006-02-07 03:42:23 +08005530 if (priv->ieee->wpa_enabled &&
5531 network->wpa_ie_len == 0 && network->rsn_ie_len == 0) {
Hong Liucdd1fa12005-08-31 18:14:27 +08005532 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5533 "because of WPA capability mismatch.\n",
5534 escape_essid(network->ssid, network->ssid_len),
5535 MAC_ARG(network->bssid));
5536 return 0;
5537 }
5538
Jeff Garzikbf794512005-07-31 13:07:26 -04005539 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005540 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5541 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5542 "because of BSSID mismatch: " MAC_FMT ".\n",
5543 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005544 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005545 return 0;
5546 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005547
James Ketrenos43f66a62005-03-25 12:31:53 -06005548 /* Filter out any incompatible freq / mode combinations */
5549 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5550 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5551 "because of invalid frequency/mode "
5552 "combination.\n",
5553 escape_essid(network->ssid, network->ssid_len),
5554 MAC_ARG(network->bssid));
5555 return 0;
5556 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005557
Liu Hong1fe0adb2005-08-19 09:33:10 -05005558 /* Filter out invalid channel in current GEO */
Larry Finger1867b112006-02-28 09:48:28 -06005559 if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005560 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5561 "because of invalid channel in current GEO\n",
5562 escape_essid(network->ssid, network->ssid_len),
5563 MAC_ARG(network->bssid));
5564 return 0;
5565 }
5566
James Ketrenosea2b26e2005-08-24 21:25:16 -05005567 /* Ensure that the rates supported by the driver are compatible with
5568 * this AP, including verification of basic rates (mandatory) */
5569 if (!ipw_compatible_rates(priv, network, &rates)) {
5570 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5571 "because configured rate mask excludes "
5572 "AP mandatory rate.\n",
5573 escape_essid(network->ssid, network->ssid_len),
5574 MAC_ARG(network->bssid));
5575 return 0;
5576 }
5577
James Ketrenos43f66a62005-03-25 12:31:53 -06005578 if (rates.num_rates == 0) {
5579 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5580 "because of no compatible rates.\n",
5581 escape_essid(network->ssid, network->ssid_len),
5582 MAC_ARG(network->bssid));
5583 return 0;
5584 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005585
James Ketrenos43f66a62005-03-25 12:31:53 -06005586 /* TODO: Perform any further minimal comparititive tests. We do not
5587 * want to put too much policy logic here; intelligent scan selection
5588 * should occur within a generic IEEE 802.11 user space tool. */
5589
5590 /* Set up 'new' AP to this network */
5591 ipw_copy_rates(&match->rates, &rates);
5592 match->network = network;
5593
5594 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5595 escape_essid(network->ssid, network->ssid_len),
5596 MAC_ARG(network->bssid));
5597
5598 return 1;
5599}
5600
Jeff Garzikbf794512005-07-31 13:07:26 -04005601static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005602 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005603{
Larry Finger1867b112006-02-28 09:48:28 -06005604 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005605 int i;
5606
James Ketrenos43f66a62005-03-25 12:31:53 -06005607 /*
5608 * For the purposes of scanning, we can set our wireless mode
5609 * to trigger scans across combinations of bands, but when it
5610 * comes to creating a new ad-hoc network, we have tell the FW
5611 * exactly which band to use.
5612 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005613 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005614 * chossen band. Attempting to create a new ad-hoc network
5615 * with an invalid channel for wireless mode will trigger a
5616 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005617 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005618 */
Larry Finger1867b112006-02-28 09:48:28 -06005619 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005620 case IEEE80211_52GHZ_BAND:
5621 network->mode = IEEE_A;
Larry Finger1867b112006-02-28 09:48:28 -06005622 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005623 if (i == -1)
5624 BUG();
5625 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5626 IPW_WARNING("Overriding invalid channel\n");
5627 priv->channel = geo->a[0].channel;
5628 }
5629 break;
5630
5631 case IEEE80211_24GHZ_BAND:
5632 if (priv->ieee->mode & IEEE_G)
5633 network->mode = IEEE_G;
5634 else
5635 network->mode = IEEE_B;
Larry Finger1867b112006-02-28 09:48:28 -06005636 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005637 if (i == -1)
5638 BUG();
5639 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5640 IPW_WARNING("Overriding invalid channel\n");
5641 priv->channel = geo->bg[0].channel;
5642 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005643 break;
5644
5645 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005646 IPW_WARNING("Overriding invalid channel\n");
5647 if (priv->ieee->mode & IEEE_A) {
5648 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005649 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005650 } else if (priv->ieee->mode & IEEE_G) {
5651 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005652 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005653 } else {
5654 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005655 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005656 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005657 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005658 }
5659
5660 network->channel = priv->channel;
5661 priv->config |= CFG_ADHOC_PERSIST;
5662 ipw_create_bssid(priv, network->bssid);
5663 network->ssid_len = priv->essid_len;
5664 memcpy(network->ssid, priv->essid, priv->essid_len);
5665 memset(&network->stats, 0, sizeof(network->stats));
5666 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005667 if (!(priv->config & CFG_PREAMBLE_LONG))
5668 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005669 if (priv->capability & CAP_PRIVACY_ON)
5670 network->capability |= WLAN_CAPABILITY_PRIVACY;
5671 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005672 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005673 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005674 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005675 &priv->rates.supported_rates[network->rates_len],
5676 network->rates_ex_len);
5677 network->last_scanned = 0;
5678 network->flags = 0;
5679 network->last_associate = 0;
5680 network->time_stamp[0] = 0;
5681 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005682 network->beacon_interval = 100; /* Default */
5683 network->listen_interval = 10; /* Default */
5684 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005685 network->wpa_ie_len = 0;
5686 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005687}
5688
James Ketrenosb095c382005-08-24 22:04:42 -05005689static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5690{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005691 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005692
5693 if (!(priv->ieee->sec.flags & (1 << index)))
5694 return;
5695
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005696 key.key_id = index;
5697 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5698 key.security_type = type;
5699 key.station_index = 0; /* always 0 for BSS */
5700 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005701 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005702 key.tx_counter[0] = 0;
5703 key.tx_counter[1] = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005704
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005705 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05005706}
5707
5708static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005709{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005710 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06005711 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06005712
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005713 key.cmd_id = DINO_CMD_WEP_KEY;
5714 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005715
James Ketrenosb095c382005-08-24 22:04:42 -05005716 /* Note: AES keys cannot be set for multiple times.
5717 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005718 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005719 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05005720 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005721 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005722 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005723 }
5724
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005725 key.key_size = priv->ieee->sec.key_sizes[i];
5726 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05005727
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005728 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04005729 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005730}
5731
Zhu Yi1fbfea52005-08-05 17:22:56 +08005732static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5733{
5734 if (priv->ieee->host_encrypt)
5735 return;
5736
5737 switch (level) {
5738 case SEC_LEVEL_3:
5739 priv->sys_config.disable_unicast_decryption = 0;
5740 priv->ieee->host_decrypt = 0;
5741 break;
5742 case SEC_LEVEL_2:
5743 priv->sys_config.disable_unicast_decryption = 1;
5744 priv->ieee->host_decrypt = 1;
5745 break;
5746 case SEC_LEVEL_1:
5747 priv->sys_config.disable_unicast_decryption = 0;
5748 priv->ieee->host_decrypt = 0;
5749 break;
5750 case SEC_LEVEL_0:
5751 priv->sys_config.disable_unicast_decryption = 1;
5752 break;
5753 default:
5754 break;
5755 }
5756}
5757
5758static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5759{
5760 if (priv->ieee->host_encrypt)
5761 return;
5762
5763 switch (level) {
5764 case SEC_LEVEL_3:
5765 priv->sys_config.disable_multicast_decryption = 0;
5766 break;
5767 case SEC_LEVEL_2:
5768 priv->sys_config.disable_multicast_decryption = 1;
5769 break;
5770 case SEC_LEVEL_1:
5771 priv->sys_config.disable_multicast_decryption = 0;
5772 break;
5773 case SEC_LEVEL_0:
5774 priv->sys_config.disable_multicast_decryption = 1;
5775 break;
5776 default:
5777 break;
5778 }
5779}
5780
James Ketrenosb095c382005-08-24 22:04:42 -05005781static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5782{
5783 switch (priv->ieee->sec.level) {
5784 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005785 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5786 ipw_send_tgi_tx_key(priv,
5787 DCT_FLAG_EXT_SECURITY_CCM,
5788 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005789
Hong Liu567deaf2005-08-31 18:07:22 +08005790 if (!priv->ieee->host_mc_decrypt)
5791 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05005792 break;
5793 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005794 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5795 ipw_send_tgi_tx_key(priv,
5796 DCT_FLAG_EXT_SECURITY_TKIP,
5797 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05005798 break;
5799 case SEC_LEVEL_1:
5800 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05005801 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5802 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05005803 break;
5804 case SEC_LEVEL_0:
5805 default:
5806 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005807 }
5808}
5809
5810static void ipw_adhoc_check(void *data)
5811{
5812 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04005813
James Ketrenosafbf30a2005-08-25 00:05:33 -05005814 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005815 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005816 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5817 IPW_DL_STATE | IPW_DL_ASSOC,
5818 "Missed beacon: %d - disassociate\n",
5819 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06005820 ipw_remove_current_network(priv);
5821 ipw_disassociate(priv);
5822 return;
5823 }
5824
Jeff Garzikbf794512005-07-31 13:07:26 -04005825 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06005826 priv->assoc_request.beacon_interval);
5827}
5828
James Ketrenosc848d0a2005-08-24 21:56:24 -05005829static void ipw_bg_adhoc_check(void *data)
5830{
5831 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08005832 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005833 ipw_adhoc_check(data);
Zhu Yi46441512006-01-24 16:37:59 +08005834 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005835}
5836
Brice Goglin0f52bf92005-12-01 01:41:46 -08005837#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -06005838static void ipw_debug_config(struct ipw_priv *priv)
5839{
5840 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5841 "[CFG 0x%08X]\n", priv->config);
5842 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005843 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005844 else
5845 IPW_DEBUG_INFO("Channel unlocked.\n");
5846 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04005847 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005848 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005849 else
5850 IPW_DEBUG_INFO("ESSID unlocked.\n");
5851 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05005852 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5853 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005854 else
5855 IPW_DEBUG_INFO("BSSID unlocked.\n");
5856 if (priv->capability & CAP_PRIVACY_ON)
5857 IPW_DEBUG_INFO("PRIVACY on\n");
5858 else
5859 IPW_DEBUG_INFO("PRIVACY off\n");
5860 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5861}
5862#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04005863#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06005864#endif
5865
Arjan van de Ven858119e2006-01-14 13:20:43 -08005866static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06005867{
5868 /* TODO: Verify that this works... */
5869 struct ipw_fixed_rate fr = {
5870 .tx_rates = priv->rates_mask
5871 };
5872 u32 reg;
5873 u16 mask = 0;
5874
Jeff Garzikbf794512005-07-31 13:07:26 -04005875 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06005876 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04005877
James Ketrenos43f66a62005-03-25 12:31:53 -06005878 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005879 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06005880 /* IEEE_A */
5881 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5882 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005883 IPW_DEBUG_WX
5884 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005885 fr.tx_rates = 0;
5886 break;
5887 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005888
James Ketrenos43f66a62005-03-25 12:31:53 -06005889 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5890 break;
5891
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005892 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06005893 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05005894 if (mode == IEEE_B) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005895 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
5896 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005897 IPW_DEBUG_WX
5898 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005899 fr.tx_rates = 0;
5900 }
5901 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04005902 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005903
5904 /* IEEE_G */
5905 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5906 IEEE80211_OFDM_RATES_MASK)) {
5907 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005908 IPW_DEBUG_WX
5909 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005910 fr.tx_rates = 0;
5911 break;
5912 }
5913
5914 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
5915 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
5916 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
5917 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005918
James Ketrenos43f66a62005-03-25 12:31:53 -06005919 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
5920 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
5921 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
5922 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005923
James Ketrenos43f66a62005-03-25 12:31:53 -06005924 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
5925 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
5926 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
5927 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005928
James Ketrenos43f66a62005-03-25 12:31:53 -06005929 fr.tx_rates |= mask;
5930 break;
5931 }
5932
5933 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005934 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06005935}
5936
James Ketrenosea2b26e2005-08-24 21:25:16 -05005937static void ipw_abort_scan(struct ipw_priv *priv)
5938{
5939 int err;
5940
5941 if (priv->status & STATUS_SCAN_ABORTING) {
5942 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5943 return;
5944 }
5945 priv->status |= STATUS_SCAN_ABORTING;
5946
5947 err = ipw_send_scan_abort(priv);
5948 if (err)
5949 IPW_DEBUG_HC("Request to abort scan failed.\n");
5950}
5951
James Ketrenosafbf30a2005-08-25 00:05:33 -05005952static void ipw_add_scan_channels(struct ipw_priv *priv,
5953 struct ipw_scan_request_ext *scan,
5954 int scan_type)
5955{
5956 int channel_index = 0;
5957 const struct ieee80211_geo *geo;
5958 int i;
5959
Larry Finger1867b112006-02-28 09:48:28 -06005960 geo = ieee80211_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005961
5962 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
5963 int start = channel_index;
5964 for (i = 0; i < geo->a_channels; i++) {
5965 if ((priv->status & STATUS_ASSOCIATED) &&
5966 geo->a[i].channel == priv->channel)
5967 continue;
5968 channel_index++;
5969 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05005970 ipw_set_scan_type(scan, channel_index,
5971 geo->a[i].
5972 flags & IEEE80211_CH_PASSIVE_ONLY ?
5973 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
5974 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005975 }
5976
5977 if (start != channel_index) {
5978 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
5979 (channel_index - start);
5980 channel_index++;
5981 }
5982 }
5983
5984 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
5985 int start = channel_index;
5986 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005987 int index;
James Ketrenosafbf30a2005-08-25 00:05:33 -05005988 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
5989 /* nop out the list */
5990 [0] = 0
5991 };
5992
5993 u8 channel;
5994 while (channel_index < IPW_SCAN_CHANNELS) {
5995 channel =
5996 priv->speed_scan[priv->speed_scan_pos];
5997 if (channel == 0) {
5998 priv->speed_scan_pos = 0;
5999 channel = priv->speed_scan[0];
6000 }
6001 if ((priv->status & STATUS_ASSOCIATED) &&
6002 channel == priv->channel) {
6003 priv->speed_scan_pos++;
6004 continue;
6005 }
6006
6007 /* If this channel has already been
6008 * added in scan, break from loop
6009 * and this will be the first channel
6010 * in the next scan.
6011 */
6012 if (channels[channel - 1] != 0)
6013 break;
6014
6015 channels[channel - 1] = 1;
6016 priv->speed_scan_pos++;
6017 channel_index++;
6018 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05006019 index =
Larry Finger1867b112006-02-28 09:48:28 -06006020 ieee80211_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006021 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006022 geo->bg[index].
6023 flags &
6024 IEEE80211_CH_PASSIVE_ONLY ?
6025 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6026 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006027 }
6028 } else {
6029 for (i = 0; i < geo->bg_channels; i++) {
6030 if ((priv->status & STATUS_ASSOCIATED) &&
6031 geo->bg[i].channel == priv->channel)
6032 continue;
6033 channel_index++;
6034 scan->channels_list[channel_index] =
6035 geo->bg[i].channel;
6036 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006037 geo->bg[i].
6038 flags &
6039 IEEE80211_CH_PASSIVE_ONLY ?
6040 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6041 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006042 }
6043 }
6044
6045 if (start != channel_index) {
6046 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6047 (channel_index - start);
6048 }
6049 }
6050}
6051
James Ketrenosea2b26e2005-08-24 21:25:16 -05006052static int ipw_request_scan(struct ipw_priv *priv)
6053{
6054 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006055 int err = 0, scan_type;
6056
6057 if (!(priv->status & STATUS_INIT) ||
6058 (priv->status & STATUS_EXIT_PENDING))
6059 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006060
Zhu Yi46441512006-01-24 16:37:59 +08006061 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006062
James Ketrenosea2b26e2005-08-24 21:25:16 -05006063 if (priv->status & STATUS_SCANNING) {
James Ketrenosa613bff2005-08-24 21:43:11 -05006064 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05006065 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006066 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006067 }
6068
James Ketrenosafbf30a2005-08-25 00:05:33 -05006069 if (!(priv->status & STATUS_SCAN_FORCED) &&
6070 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006071 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6072 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006073 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006074 }
6075
6076 if (priv->status & STATUS_RF_KILL_MASK) {
6077 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6078 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006079 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006080 }
6081
6082 memset(&scan, 0, sizeof(scan));
6083
James Ketrenosb095c382005-08-24 22:04:42 -05006084 if (priv->config & CFG_SPEED_SCAN)
6085 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6086 cpu_to_le16(30);
6087 else
6088 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6089 cpu_to_le16(20);
6090
James Ketrenosa613bff2005-08-24 21:43:11 -05006091 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6092 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05006093 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006094
James Ketrenosa613bff2005-08-24 21:43:11 -05006095 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006096
James Ketrenosb095c382005-08-24 22:04:42 -05006097#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006098 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006099 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006100 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006101
Larry Finger1867b112006-02-28 09:48:28 -06006102 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006103 case IEEE80211_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006104 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006105 channel = priv->channel;
6106 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006107
James Ketrenosb095c382005-08-24 22:04:42 -05006108 case IEEE80211_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006109 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006110 channel = priv->channel;
6111 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006112
James Ketrenosb095c382005-08-24 22:04:42 -05006113 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006114 band = (u8) (IPW_B_MODE << 6) | 1;
6115 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006116 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006117 }
6118
James Ketrenosb095c382005-08-24 22:04:42 -05006119 scan.channels_list[0] = band;
6120 scan.channels_list[1] = channel;
6121 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006122
James Ketrenosb095c382005-08-24 22:04:42 -05006123 /* NOTE: The card will sit on this channel for this time
6124 * period. Scan aborts are timing sensitive and frequently
6125 * result in firmware restarts. As such, it is best to
6126 * set a small dwell_time here and just keep re-issuing
6127 * scans. Otherwise fast channel hopping will not actually
6128 * hop channels.
6129 *
6130 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006131 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6132 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006133 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006134#endif /* CONFIG_IPW2200_MONITOR */
6135 /* If we are roaming, then make this a directed scan for the
6136 * current network. Otherwise, ensure that every other scan
6137 * is a fast channel hop scan */
6138 if ((priv->status & STATUS_ROAMING)
6139 || (!(priv->status & STATUS_ASSOCIATED)
6140 && (priv->config & CFG_STATIC_ESSID)
6141 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006142 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6143 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006144 IPW_DEBUG_HC("Attempt to send SSID command "
6145 "failed.\n");
6146 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006147 }
6148
6149 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006150 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006151 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006152
James Ketrenosafbf30a2005-08-25 00:05:33 -05006153 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006154#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006155 }
6156#endif
6157
6158 err = ipw_send_scan_request_ext(priv, &scan);
6159 if (err) {
6160 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006161 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006162 }
6163
6164 priv->status |= STATUS_SCANNING;
6165 priv->status &= ~STATUS_SCAN_PENDING;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006166 queue_delayed_work(priv->workqueue, &priv->scan_check,
6167 IPW_SCAN_CHECK_WATCHDOG);
James Ketrenosb095c382005-08-24 22:04:42 -05006168 done:
Zhu Yi46441512006-01-24 16:37:59 +08006169 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006170 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006171}
6172
6173static void ipw_bg_abort_scan(void *data)
6174{
6175 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08006176 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006177 ipw_abort_scan(data);
Zhu Yi46441512006-01-24 16:37:59 +08006178 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006179}
6180
James Ketrenosea2b26e2005-08-24 21:25:16 -05006181static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6182{
James Ketrenosb095c382005-08-24 22:04:42 -05006183 /* This is called when wpa_supplicant loads and closes the driver
6184 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006185 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006186 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006187}
6188
James Ketrenosea2b26e2005-08-24 21:25:16 -05006189static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6190{
6191 struct ieee80211_device *ieee = priv->ieee;
6192 struct ieee80211_security sec = {
6193 .flags = SEC_AUTH_MODE,
6194 };
6195 int ret = 0;
6196
James Ketrenosafbf30a2005-08-25 00:05:33 -05006197 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006198 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6199 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006200 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006201 sec.auth_mode = WLAN_AUTH_OPEN;
6202 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006203 } else if (value & IW_AUTH_ALG_LEAP) {
6204 sec.auth_mode = WLAN_AUTH_LEAP;
6205 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006206 } else
6207 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006208
6209 if (ieee->set_security)
6210 ieee->set_security(ieee->dev, &sec);
6211 else
6212 ret = -EOPNOTSUPP;
6213
6214 return ret;
6215}
6216
Adrian Bunka73e22b2006-01-21 01:39:42 +01006217static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6218 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006219{
6220 /* make sure WPA is enabled */
6221 ipw_wpa_enable(priv, 1);
6222
6223 ipw_disassociate(priv);
6224}
6225
6226static int ipw_set_rsn_capa(struct ipw_priv *priv,
6227 char *capabilities, int length)
6228{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006229 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6230
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006231 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006232 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006233}
6234
James Ketrenosafbf30a2005-08-25 00:05:33 -05006235/*
6236 * WE-18 support
6237 */
6238
6239/* SIOCSIWGENIE */
6240static int ipw_wx_set_genie(struct net_device *dev,
6241 struct iw_request_info *info,
6242 union iwreq_data *wrqu, char *extra)
6243{
6244 struct ipw_priv *priv = ieee80211_priv(dev);
6245 struct ieee80211_device *ieee = priv->ieee;
6246 u8 *buf;
6247 int err = 0;
6248
6249 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6250 (wrqu->data.length && extra == NULL))
6251 return -EINVAL;
6252
Zhu Yi46441512006-01-24 16:37:59 +08006253 //mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006254
6255 //if (!ieee->wpa_enabled) {
6256 // err = -EOPNOTSUPP;
6257 // goto out;
6258 //}
6259
6260 if (wrqu->data.length) {
6261 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6262 if (buf == NULL) {
6263 err = -ENOMEM;
6264 goto out;
6265 }
6266
6267 memcpy(buf, extra, wrqu->data.length);
6268 kfree(ieee->wpa_ie);
6269 ieee->wpa_ie = buf;
6270 ieee->wpa_ie_len = wrqu->data.length;
6271 } else {
6272 kfree(ieee->wpa_ie);
6273 ieee->wpa_ie = NULL;
6274 ieee->wpa_ie_len = 0;
6275 }
6276
6277 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6278 out:
Zhu Yi46441512006-01-24 16:37:59 +08006279 //mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006280 return err;
6281}
6282
6283/* SIOCGIWGENIE */
6284static int ipw_wx_get_genie(struct net_device *dev,
6285 struct iw_request_info *info,
6286 union iwreq_data *wrqu, char *extra)
6287{
6288 struct ipw_priv *priv = ieee80211_priv(dev);
6289 struct ieee80211_device *ieee = priv->ieee;
6290 int err = 0;
6291
Zhu Yi46441512006-01-24 16:37:59 +08006292 //mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006293
6294 //if (!ieee->wpa_enabled) {
6295 // err = -EOPNOTSUPP;
6296 // goto out;
6297 //}
6298
6299 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6300 wrqu->data.length = 0;
6301 goto out;
6302 }
6303
6304 if (wrqu->data.length < ieee->wpa_ie_len) {
6305 err = -E2BIG;
6306 goto out;
6307 }
6308
6309 wrqu->data.length = ieee->wpa_ie_len;
6310 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6311
6312 out:
Zhu Yi46441512006-01-24 16:37:59 +08006313 //mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006314 return err;
6315}
6316
Zhu Yi1fbfea52005-08-05 17:22:56 +08006317static int wext_cipher2level(int cipher)
6318{
6319 switch (cipher) {
6320 case IW_AUTH_CIPHER_NONE:
6321 return SEC_LEVEL_0;
6322 case IW_AUTH_CIPHER_WEP40:
6323 case IW_AUTH_CIPHER_WEP104:
6324 return SEC_LEVEL_1;
6325 case IW_AUTH_CIPHER_TKIP:
6326 return SEC_LEVEL_2;
6327 case IW_AUTH_CIPHER_CCMP:
6328 return SEC_LEVEL_3;
6329 default:
6330 return -1;
6331 }
6332}
6333
James Ketrenosafbf30a2005-08-25 00:05:33 -05006334/* SIOCSIWAUTH */
6335static int ipw_wx_set_auth(struct net_device *dev,
6336 struct iw_request_info *info,
6337 union iwreq_data *wrqu, char *extra)
6338{
6339 struct ipw_priv *priv = ieee80211_priv(dev);
6340 struct ieee80211_device *ieee = priv->ieee;
6341 struct iw_param *param = &wrqu->param;
6342 struct ieee80211_crypt_data *crypt;
6343 unsigned long flags;
6344 int ret = 0;
6345
6346 switch (param->flags & IW_AUTH_INDEX) {
6347 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006348 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006349 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006350 ipw_set_hw_decrypt_unicast(priv,
6351 wext_cipher2level(param->value));
6352 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006353 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006354 ipw_set_hw_decrypt_multicast(priv,
6355 wext_cipher2level(param->value));
6356 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006357 case IW_AUTH_KEY_MGMT:
6358 /*
6359 * ipw2200 does not use these parameters
6360 */
6361 break;
6362
6363 case IW_AUTH_TKIP_COUNTERMEASURES:
6364 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006365 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006366 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006367
6368 flags = crypt->ops->get_flags(crypt->priv);
6369
6370 if (param->value)
6371 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6372 else
6373 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6374
6375 crypt->ops->set_flags(flags, crypt->priv);
6376
6377 break;
6378
6379 case IW_AUTH_DROP_UNENCRYPTED:{
6380 /* HACK:
6381 *
6382 * wpa_supplicant calls set_wpa_enabled when the driver
6383 * is loaded and unloaded, regardless of if WPA is being
6384 * used. No other calls are made which can be used to
6385 * determine if encryption will be used or not prior to
6386 * association being expected. If encryption is not being
6387 * used, drop_unencrypted is set to false, else true -- we
6388 * can use this to determine if the CAP_PRIVACY_ON bit should
6389 * be set.
6390 */
6391 struct ieee80211_security sec = {
6392 .flags = SEC_ENABLED,
6393 .enabled = param->value,
6394 };
6395 priv->ieee->drop_unencrypted = param->value;
6396 /* We only change SEC_LEVEL for open mode. Others
6397 * are set by ipw_wpa_set_encryption.
6398 */
6399 if (!param->value) {
6400 sec.flags |= SEC_LEVEL;
6401 sec.level = SEC_LEVEL_0;
6402 } else {
6403 sec.flags |= SEC_LEVEL;
6404 sec.level = SEC_LEVEL_1;
6405 }
6406 if (priv->ieee->set_security)
6407 priv->ieee->set_security(priv->ieee->dev, &sec);
6408 break;
6409 }
6410
6411 case IW_AUTH_80211_AUTH_ALG:
6412 ret = ipw_wpa_set_auth_algs(priv, param->value);
6413 break;
6414
6415 case IW_AUTH_WPA_ENABLED:
6416 ret = ipw_wpa_enable(priv, param->value);
6417 break;
6418
6419 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6420 ieee->ieee802_1x = param->value;
6421 break;
6422
6423 //case IW_AUTH_ROAMING_CONTROL:
6424 case IW_AUTH_PRIVACY_INVOKED:
6425 ieee->privacy_invoked = param->value;
6426 break;
6427
6428 default:
6429 return -EOPNOTSUPP;
6430 }
6431 return ret;
6432}
6433
6434/* SIOCGIWAUTH */
6435static int ipw_wx_get_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 ieee80211_crypt_data *crypt;
6442 struct iw_param *param = &wrqu->param;
6443 int ret = 0;
6444
6445 switch (param->flags & IW_AUTH_INDEX) {
6446 case IW_AUTH_WPA_VERSION:
6447 case IW_AUTH_CIPHER_PAIRWISE:
6448 case IW_AUTH_CIPHER_GROUP:
6449 case IW_AUTH_KEY_MGMT:
6450 /*
6451 * wpa_supplicant will control these internally
6452 */
6453 ret = -EOPNOTSUPP;
6454 break;
6455
6456 case IW_AUTH_TKIP_COUNTERMEASURES:
6457 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006458 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006459 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006460
6461 param->value = (crypt->ops->get_flags(crypt->priv) &
6462 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6463
6464 break;
6465
6466 case IW_AUTH_DROP_UNENCRYPTED:
6467 param->value = ieee->drop_unencrypted;
6468 break;
6469
6470 case IW_AUTH_80211_AUTH_ALG:
6471 param->value = ieee->sec.auth_mode;
6472 break;
6473
6474 case IW_AUTH_WPA_ENABLED:
6475 param->value = ieee->wpa_enabled;
6476 break;
6477
6478 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6479 param->value = ieee->ieee802_1x;
6480 break;
6481
6482 case IW_AUTH_ROAMING_CONTROL:
6483 case IW_AUTH_PRIVACY_INVOKED:
6484 param->value = ieee->privacy_invoked;
6485 break;
6486
6487 default:
6488 return -EOPNOTSUPP;
6489 }
6490 return 0;
6491}
6492
6493/* SIOCSIWENCODEEXT */
6494static int ipw_wx_set_encodeext(struct net_device *dev,
6495 struct iw_request_info *info,
6496 union iwreq_data *wrqu, char *extra)
6497{
6498 struct ipw_priv *priv = ieee80211_priv(dev);
6499 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6500
6501 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006502 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006503 /* IPW HW can't build TKIP MIC,
6504 host decryption still needed */
6505 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6506 priv->ieee->host_mc_decrypt = 1;
6507 else {
6508 priv->ieee->host_encrypt = 0;
6509 priv->ieee->host_encrypt_msdu = 1;
6510 priv->ieee->host_decrypt = 1;
6511 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006512 } else {
6513 priv->ieee->host_encrypt = 0;
6514 priv->ieee->host_encrypt_msdu = 0;
6515 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006516 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006517 }
6518 }
6519
6520 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6521}
6522
6523/* SIOCGIWENCODEEXT */
6524static int ipw_wx_get_encodeext(struct net_device *dev,
6525 struct iw_request_info *info,
6526 union iwreq_data *wrqu, char *extra)
6527{
6528 struct ipw_priv *priv = ieee80211_priv(dev);
6529 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6530}
6531
6532/* SIOCSIWMLME */
6533static int ipw_wx_set_mlme(struct net_device *dev,
6534 struct iw_request_info *info,
6535 union iwreq_data *wrqu, char *extra)
6536{
6537 struct ipw_priv *priv = ieee80211_priv(dev);
6538 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6539 u16 reason;
6540
6541 reason = cpu_to_le16(mlme->reason_code);
6542
6543 switch (mlme->cmd) {
6544 case IW_MLME_DEAUTH:
6545 // silently ignore
6546 break;
6547
6548 case IW_MLME_DISASSOC:
6549 ipw_disassociate(priv);
6550 break;
6551
6552 default:
6553 return -EOPNOTSUPP;
6554 }
6555 return 0;
6556}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006557
James Ketrenosb095c382005-08-24 22:04:42 -05006558#ifdef CONFIG_IPW_QOS
6559
6560/* QoS */
6561/*
6562* get the modulation type of the current network or
6563* the card current mode
6564*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006565static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006566{
6567 u8 mode = 0;
6568
6569 if (priv->status & STATUS_ASSOCIATED) {
6570 unsigned long flags;
6571
6572 spin_lock_irqsave(&priv->ieee->lock, flags);
6573 mode = priv->assoc_network->mode;
6574 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6575 } else {
6576 mode = priv->ieee->mode;
6577 }
6578 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6579 return mode;
6580}
6581
6582/*
6583* Handle management frame beacon and probe response
6584*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006585static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6586 int active_network,
6587 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006588{
6589 u32 size = sizeof(struct ieee80211_qos_parameters);
6590
James Ketrenosafbf30a2005-08-25 00:05:33 -05006591 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006592 network->qos_data.active = network->qos_data.supported;
6593
6594 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006595 if (active_network &&
6596 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006597 network->qos_data.active = network->qos_data.supported;
6598
6599 if ((network->qos_data.active == 1) && (active_network == 1) &&
6600 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6601 (network->qos_data.old_param_count !=
6602 network->qos_data.param_count)) {
6603 network->qos_data.old_param_count =
6604 network->qos_data.param_count;
6605 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006606 IPW_DEBUG_QOS("QoS parameters change call "
6607 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006608 }
6609 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006610 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6611 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006612 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006613 else
6614 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006615 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006616
James Ketrenosb095c382005-08-24 22:04:42 -05006617 if ((network->qos_data.active == 1) && (active_network == 1)) {
6618 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6619 schedule_work(&priv->qos_activate);
6620 }
6621
6622 network->qos_data.active = 0;
6623 network->qos_data.supported = 0;
6624 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006625 if ((priv->status & STATUS_ASSOCIATED) &&
6626 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6627 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6628 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6629 !(network->flags & NETWORK_EMPTY_ESSID))
James Ketrenosb095c382005-08-24 22:04:42 -05006630 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006631 priv->assoc_network->ssid_len) &&
6632 !memcmp(network->ssid,
6633 priv->assoc_network->ssid,
6634 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006635 queue_work(priv->workqueue,
6636 &priv->merge_networks);
6637 }
James Ketrenosb095c382005-08-24 22:04:42 -05006638 }
6639
6640 return 0;
6641}
6642
6643/*
6644* This function set up the firmware to support QoS. It sends
6645* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6646*/
6647static int ipw_qos_activate(struct ipw_priv *priv,
6648 struct ieee80211_qos_data *qos_network_data)
6649{
6650 int err;
6651 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6652 struct ieee80211_qos_parameters *active_one = NULL;
6653 u32 size = sizeof(struct ieee80211_qos_parameters);
6654 u32 burst_duration;
6655 int i;
6656 u8 type;
6657
6658 type = ipw_qos_current_mode(priv);
6659
6660 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6661 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6662 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6663 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6664
6665 if (qos_network_data == NULL) {
6666 if (type == IEEE_B) {
6667 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6668 active_one = &def_parameters_CCK;
6669 } else
6670 active_one = &def_parameters_OFDM;
6671
James Ketrenosafbf30a2005-08-25 00:05:33 -05006672 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006673 burst_duration = ipw_qos_get_burst_duration(priv);
6674 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006675 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6676 (u16) burst_duration;
6677 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05006678 if (type == IEEE_B) {
6679 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6680 type);
6681 if (priv->qos_data.qos_enable == 0)
6682 active_one = &def_parameters_CCK;
6683 else
6684 active_one = priv->qos_data.def_qos_parm_CCK;
6685 } else {
6686 if (priv->qos_data.qos_enable == 0)
6687 active_one = &def_parameters_OFDM;
6688 else
6689 active_one = priv->qos_data.def_qos_parm_OFDM;
6690 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006691 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006692 } else {
6693 unsigned long flags;
6694 int active;
6695
6696 spin_lock_irqsave(&priv->ieee->lock, flags);
6697 active_one = &(qos_network_data->parameters);
6698 qos_network_data->old_param_count =
6699 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006700 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006701 active = qos_network_data->supported;
6702 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6703
6704 if (active == 0) {
6705 burst_duration = ipw_qos_get_burst_duration(priv);
6706 for (i = 0; i < QOS_QUEUE_NUM; i++)
6707 qos_parameters[QOS_PARAM_SET_ACTIVE].
6708 tx_op_limit[i] = (u16) burst_duration;
6709 }
6710 }
6711
6712 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05006713 err = ipw_send_qos_params_command(priv,
6714 (struct ieee80211_qos_parameters *)
6715 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05006716 if (err)
6717 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6718
6719 return err;
6720}
6721
6722/*
6723* send IPW_CMD_WME_INFO to the firmware
6724*/
6725static int ipw_qos_set_info_element(struct ipw_priv *priv)
6726{
6727 int ret = 0;
6728 struct ieee80211_qos_information_element qos_info;
6729
6730 if (priv == NULL)
6731 return -1;
6732
6733 qos_info.elementID = QOS_ELEMENT_ID;
6734 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6735
6736 qos_info.version = QOS_VERSION_1;
6737 qos_info.ac_info = 0;
6738
6739 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6740 qos_info.qui_type = QOS_OUI_TYPE;
6741 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6742
6743 ret = ipw_send_qos_info_command(priv, &qos_info);
6744 if (ret != 0) {
6745 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6746 }
6747 return ret;
6748}
6749
6750/*
6751* Set the QoS parameter with the association request structure
6752*/
6753static int ipw_qos_association(struct ipw_priv *priv,
6754 struct ieee80211_network *network)
6755{
6756 int err = 0;
6757 struct ieee80211_qos_data *qos_data = NULL;
6758 struct ieee80211_qos_data ibss_data = {
6759 .supported = 1,
6760 .active = 1,
6761 };
6762
6763 switch (priv->ieee->iw_mode) {
6764 case IW_MODE_ADHOC:
6765 if (!(network->capability & WLAN_CAPABILITY_IBSS))
6766 BUG();
6767
6768 qos_data = &ibss_data;
6769 break;
6770
6771 case IW_MODE_INFRA:
6772 qos_data = &network->qos_data;
6773 break;
6774
6775 default:
6776 BUG();
6777 break;
6778 }
6779
6780 err = ipw_qos_activate(priv, qos_data);
6781 if (err) {
6782 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6783 return err;
6784 }
6785
6786 if (priv->qos_data.qos_enable && qos_data->supported) {
6787 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6788 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6789 return ipw_qos_set_info_element(priv);
6790 }
6791
6792 return 0;
6793}
6794
6795/*
6796* handling the beaconing responces. if we get different QoS setting
6797* of the network from the the associated setting adjust the QoS
6798* setting
6799*/
6800static int ipw_qos_association_resp(struct ipw_priv *priv,
6801 struct ieee80211_network *network)
6802{
6803 int ret = 0;
6804 unsigned long flags;
6805 u32 size = sizeof(struct ieee80211_qos_parameters);
6806 int set_qos_param = 0;
6807
James Ketrenosafbf30a2005-08-25 00:05:33 -05006808 if ((priv == NULL) || (network == NULL) ||
6809 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05006810 return ret;
6811
6812 if (!(priv->status & STATUS_ASSOCIATED))
6813 return ret;
6814
James Ketrenosafbf30a2005-08-25 00:05:33 -05006815 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05006816 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05006817
6818 spin_lock_irqsave(&priv->ieee->lock, flags);
6819 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006820 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
James Ketrenosb095c382005-08-24 22:04:42 -05006821 sizeof(struct ieee80211_qos_data));
6822 priv->assoc_network->qos_data.active = 1;
6823 if ((network->qos_data.old_param_count !=
6824 network->qos_data.param_count)) {
6825 set_qos_param = 1;
6826 network->qos_data.old_param_count =
6827 network->qos_data.param_count;
6828 }
6829
6830 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006831 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
6832 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006833 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006834 else
6835 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006836 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006837 priv->assoc_network->qos_data.active = 0;
6838 priv->assoc_network->qos_data.supported = 0;
6839 set_qos_param = 1;
6840 }
6841
6842 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6843
6844 if (set_qos_param == 1)
6845 schedule_work(&priv->qos_activate);
6846
6847 return ret;
6848}
6849
6850static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
6851{
6852 u32 ret = 0;
6853
6854 if ((priv == NULL))
6855 return 0;
6856
James Ketrenosafbf30a2005-08-25 00:05:33 -05006857 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05006858 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006859 else
James Ketrenosb095c382005-08-24 22:04:42 -05006860 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006861
James Ketrenosb095c382005-08-24 22:04:42 -05006862 return ret;
6863}
6864
6865/*
6866* Initialize the setting of QoS global
6867*/
6868static void ipw_qos_init(struct ipw_priv *priv, int enable,
6869 int burst_enable, u32 burst_duration_CCK,
6870 u32 burst_duration_OFDM)
6871{
6872 priv->qos_data.qos_enable = enable;
6873
6874 if (priv->qos_data.qos_enable) {
6875 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
6876 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
6877 IPW_DEBUG_QOS("QoS is enabled\n");
6878 } else {
6879 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
6880 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
6881 IPW_DEBUG_QOS("QoS is not enabled\n");
6882 }
6883
6884 priv->qos_data.burst_enable = burst_enable;
6885
6886 if (burst_enable) {
6887 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
6888 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
6889 } else {
6890 priv->qos_data.burst_duration_CCK = 0;
6891 priv->qos_data.burst_duration_OFDM = 0;
6892 }
6893}
6894
6895/*
6896* map the packet priority to the right TX Queue
6897*/
6898static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
6899{
6900 if (priority > 7 || !priv->qos_data.qos_enable)
6901 priority = 0;
6902
6903 return from_priority_to_tx_queue[priority] - 1;
6904}
6905
6906/*
6907* add QoS parameter to the TX command
6908*/
6909static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
6910 u16 priority,
6911 struct tfd_data *tfd, u8 unicast)
6912{
6913 int ret = 0;
6914 int tx_queue_id = 0;
6915 struct ieee80211_qos_data *qos_data = NULL;
6916 int active, supported;
6917 unsigned long flags;
6918
6919 if (!(priv->status & STATUS_ASSOCIATED))
6920 return 0;
6921
6922 qos_data = &priv->assoc_network->qos_data;
6923
6924 spin_lock_irqsave(&priv->ieee->lock, flags);
6925
6926 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6927 if (unicast == 0)
6928 qos_data->active = 0;
6929 else
6930 qos_data->active = qos_data->supported;
6931 }
6932
6933 active = qos_data->active;
6934 supported = qos_data->supported;
6935
6936 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6937
James Ketrenosafbf30a2005-08-25 00:05:33 -05006938 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
6939 "unicast %d\n",
6940 priv->qos_data.qos_enable, active, supported, unicast);
James Ketrenosb095c382005-08-24 22:04:42 -05006941 if (active && priv->qos_data.qos_enable) {
6942 ret = from_priority_to_tx_queue[priority];
6943 tx_queue_id = ret - 1;
6944 IPW_DEBUG_QOS("QoS packet priority is %d \n", priority);
6945 if (priority <= 7) {
6946 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
6947 tfd->tfd.tfd_26.mchdr.qos_ctrl = priority;
6948 tfd->tfd.tfd_26.mchdr.frame_ctl |=
6949 IEEE80211_STYPE_QOS_DATA;
6950
6951 if (priv->qos_data.qos_no_ack_mask &
6952 (1UL << tx_queue_id)) {
6953 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
6954 tfd->tfd.tfd_26.mchdr.qos_ctrl |=
6955 CTRL_QOS_NO_ACK;
6956 }
6957 }
6958 }
6959
6960 return ret;
6961}
6962
6963/*
6964* background support to run QoS activate functionality
6965*/
6966static void ipw_bg_qos_activate(void *data)
6967{
6968 struct ipw_priv *priv = data;
6969
6970 if (priv == NULL)
6971 return;
6972
Zhu Yi46441512006-01-24 16:37:59 +08006973 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006974
6975 if (priv->status & STATUS_ASSOCIATED)
6976 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
6977
Zhu Yi46441512006-01-24 16:37:59 +08006978 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006979}
6980
James Ketrenos3b9990c2005-08-19 13:18:55 -05006981static int ipw_handle_probe_response(struct net_device *dev,
6982 struct ieee80211_probe_response *resp,
6983 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006984{
6985 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05006986 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
6987 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05006988
James Ketrenos3b9990c2005-08-19 13:18:55 -05006989 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05006990
James Ketrenos3b9990c2005-08-19 13:18:55 -05006991 return 0;
6992}
James Ketrenosb095c382005-08-24 22:04:42 -05006993
James Ketrenos3b9990c2005-08-19 13:18:55 -05006994static int ipw_handle_beacon(struct net_device *dev,
6995 struct ieee80211_beacon *resp,
6996 struct ieee80211_network *network)
6997{
6998 struct ipw_priv *priv = ieee80211_priv(dev);
6999 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
7000 (network == priv->assoc_network));
7001
7002 ipw_qos_handle_probe_response(priv, active_network, network);
7003
7004 return 0;
7005}
7006
7007static int ipw_handle_assoc_response(struct net_device *dev,
7008 struct ieee80211_assoc_response *resp,
7009 struct ieee80211_network *network)
7010{
7011 struct ipw_priv *priv = ieee80211_priv(dev);
7012 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05007013 return 0;
7014}
7015
7016static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
7017 *qos_param)
7018{
Zhu Yi4e226992006-01-24 16:37:36 +08007019 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
7020 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007021}
7022
7023static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
7024 *qos_param)
7025{
Zhu Yi4e226992006-01-24 16:37:36 +08007026 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
7027 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05007028}
7029
7030#endif /* CONFIG_IPW_QOS */
7031
James Ketrenos43f66a62005-03-25 12:31:53 -06007032static int ipw_associate_network(struct ipw_priv *priv,
7033 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007034 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007035{
7036 int err;
7037
7038 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007039 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007040
7041 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007042 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007043 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007044 memcpy(priv->essid, network->ssid, priv->essid_len);
7045 }
7046
7047 network->last_associate = jiffies;
7048
7049 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7050 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007051 priv->assoc_request.auth_key = 0;
7052
James Ketrenos43f66a62005-03-25 12:31:53 -06007053 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007054 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007055 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007056 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7057
Zhu Yi1ba61e02006-02-15 13:00:55 +08007058 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007059 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007060
7061 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7062 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7063 priv->assoc_request.auth_type = AUTH_LEAP;
7064 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007065 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007066
James Ketrenosa613bff2005-08-24 21:43:11 -05007067 if (priv->ieee->wpa_ie_len) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007068 priv->assoc_request.policy_support = 0x02; /* RSN active */
7069 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7070 priv->ieee->wpa_ie_len);
7071 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007072
Jeff Garzikbf794512005-07-31 13:07:26 -04007073 /*
7074 * It is valid for our ieee device to support multiple modes, but
7075 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007076 * just one mode.
7077 */
7078 if (network->mode & priv->ieee->mode & IEEE_A)
7079 priv->assoc_request.ieee_mode = IPW_A_MODE;
7080 else if (network->mode & priv->ieee->mode & IEEE_G)
7081 priv->assoc_request.ieee_mode = IPW_G_MODE;
7082 else if (network->mode & priv->ieee->mode & IEEE_B)
7083 priv->assoc_request.ieee_mode = IPW_B_MODE;
7084
James Ketrenosea2b26e2005-08-24 21:25:16 -05007085 priv->assoc_request.capability = network->capability;
7086 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7087 && !(priv->config & CFG_PREAMBLE_LONG)) {
7088 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7089 } else {
7090 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7091
7092 /* Clear the short preamble if we won't be supporting it */
7093 priv->assoc_request.capability &=
7094 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7095 }
7096
James Ketrenosafbf30a2005-08-25 00:05:33 -05007097 /* Clear capability bits that aren't used in Ad Hoc */
7098 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7099 priv->assoc_request.capability &=
7100 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7101
James Ketrenos43f66a62005-03-25 12:31:53 -06007102 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007103 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007104 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04007105 escape_essid(priv->essid, priv->essid_len),
7106 network->channel,
7107 ipw_modes[priv->assoc_request.ieee_mode],
7108 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007109 (priv->assoc_request.preamble_length ==
7110 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7111 network->capability &
7112 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007113 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007114 priv->capability & CAP_PRIVACY_ON ?
7115 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007116 "(open)") : "",
7117 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007118 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007119 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007120 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007121
7122 priv->assoc_request.beacon_interval = network->beacon_interval;
7123 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007124 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007125 priv->assoc_request.assoc_type = HC_IBSS_START;
7126 priv->assoc_request.assoc_tsf_msw = 0;
7127 priv->assoc_request.assoc_tsf_lsw = 0;
7128 } else {
7129 if (unlikely(roaming))
7130 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7131 else
7132 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7133 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7134 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7135 }
7136
James Ketrenosafbf30a2005-08-25 00:05:33 -05007137 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007138
7139 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7140 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7141 priv->assoc_request.atim_window = network->atim_window;
7142 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007143 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007144 priv->assoc_request.atim_window = 0;
7145 }
7146
James Ketrenos43f66a62005-03-25 12:31:53 -06007147 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04007148
James Ketrenos43f66a62005-03-25 12:31:53 -06007149 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7150 if (err) {
7151 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7152 return err;
7153 }
7154
7155 rates->ieee_mode = priv->assoc_request.ieee_mode;
7156 rates->purpose = IPW_RATE_CONNECT;
7157 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007158
James Ketrenos43f66a62005-03-25 12:31:53 -06007159 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7160 priv->sys_config.dot11g_auto_detection = 1;
7161 else
7162 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007163
7164 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7165 priv->sys_config.answer_broadcast_ssid_probe = 1;
7166 else
7167 priv->sys_config.answer_broadcast_ssid_probe = 0;
7168
James Ketrenos43f66a62005-03-25 12:31:53 -06007169 err = ipw_send_system_config(priv, &priv->sys_config);
7170 if (err) {
7171 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7172 return err;
7173 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007174
James Ketrenos43f66a62005-03-25 12:31:53 -06007175 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007176 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007177 if (err) {
7178 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7179 return err;
7180 }
7181
7182 /*
7183 * If preemption is enabled, it is possible for the association
7184 * to complete before we return from ipw_send_associate. Therefore
7185 * we have to be sure and update our priviate data first.
7186 */
7187 priv->channel = network->channel;
7188 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007189 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007190 priv->status &= ~STATUS_SECURITY_UPDATED;
7191
7192 priv->assoc_network = network;
7193
James Ketrenosb095c382005-08-24 22:04:42 -05007194#ifdef CONFIG_IPW_QOS
7195 ipw_qos_association(priv, network);
7196#endif
7197
James Ketrenos43f66a62005-03-25 12:31:53 -06007198 err = ipw_send_associate(priv, &priv->assoc_request);
7199 if (err) {
7200 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7201 return err;
7202 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007203
7204 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007205 escape_essid(priv->essid, priv->essid_len),
7206 MAC_ARG(priv->bssid));
7207
7208 return 0;
7209}
7210
7211static void ipw_roam(void *data)
7212{
7213 struct ipw_priv *priv = data;
7214 struct ieee80211_network *network = NULL;
7215 struct ipw_network_match match = {
7216 .network = priv->assoc_network
7217 };
7218
7219 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007220 *
7221 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007222 * setting the status ROAM bit and requesting a scan.
7223 * 2. When the scan completes, it schedules the ROAM work
7224 * 3. The ROAM work looks at all of the known networks for one that
7225 * is a better network than the currently associated. If none
7226 * found, the ROAM process is over (ROAM bit cleared)
7227 * 4. If a better network is found, a disassociation request is
7228 * sent.
7229 * 5. When the disassociation completes, the roam work is again
7230 * scheduled. The second time through, the driver is no longer
7231 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007232 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007233 * 6. At this point ,the roaming process is complete and the ROAM
7234 * status bit is cleared.
7235 */
7236
7237 /* If we are no longer associated, and the roaming bit is no longer
7238 * set, then we are not actively roaming, so just return */
7239 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7240 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007241
James Ketrenos43f66a62005-03-25 12:31:53 -06007242 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007243 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007244 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007245 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007246 u8 rssi = priv->assoc_network->stats.rssi;
7247 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007248 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007249 list_for_each_entry(network, &priv->ieee->network_list, list) {
7250 if (network != priv->assoc_network)
7251 ipw_best_network(priv, &match, network, 1);
7252 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007253 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007254 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007255
James Ketrenos43f66a62005-03-25 12:31:53 -06007256 if (match.network == priv->assoc_network) {
7257 IPW_DEBUG_ASSOC("No better APs in this network to "
7258 "roam to.\n");
7259 priv->status &= ~STATUS_ROAMING;
7260 ipw_debug_config(priv);
7261 return;
7262 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007263
James Ketrenos43f66a62005-03-25 12:31:53 -06007264 ipw_send_disassociate(priv, 1);
7265 priv->assoc_network = match.network;
7266
7267 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007268 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007269
7270 /* Second pass through ROAM process -- request association */
7271 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7272 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7273 priv->status &= ~STATUS_ROAMING;
7274}
7275
James Ketrenosc848d0a2005-08-24 21:56:24 -05007276static void ipw_bg_roam(void *data)
7277{
7278 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08007279 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007280 ipw_roam(data);
Zhu Yi46441512006-01-24 16:37:59 +08007281 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007282}
7283
7284static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007285{
7286 struct ipw_priv *priv = data;
7287
7288 struct ieee80211_network *network = NULL;
7289 struct ipw_network_match match = {
7290 .network = NULL
7291 };
7292 struct ipw_supported_rates *rates;
7293 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007294 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007295
James Ketrenosb095c382005-08-24 22:04:42 -05007296 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7297 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7298 return 0;
7299 }
7300
James Ketrenosc848d0a2005-08-24 21:56:24 -05007301 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007302 IPW_DEBUG_ASSOC("Not attempting association (already in "
7303 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007304 return 0;
7305 }
7306
Hong Liue6324722005-09-14 21:04:15 -05007307 if (priv->status & STATUS_DISASSOCIATING) {
7308 IPW_DEBUG_ASSOC("Not attempting association (in "
7309 "disassociating)\n ");
7310 queue_work(priv->workqueue, &priv->associate);
7311 return 0;
7312 }
7313
James Ketrenosc848d0a2005-08-24 21:56:24 -05007314 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007315 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7316 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007317 return 0;
7318 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007319
7320 if (!(priv->config & CFG_ASSOCIATE) &&
7321 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007322 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007323 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007324 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007325 }
7326
James Ketrenosa613bff2005-08-24 21:43:11 -05007327 /* Protect our use of the network_list */
7328 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007329 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007330 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007331
7332 network = match.network;
7333 rates = &match.rates;
7334
7335 if (network == NULL &&
7336 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7337 priv->config & CFG_ADHOC_CREATE &&
7338 priv->config & CFG_STATIC_ESSID &&
James Ketrenosa613bff2005-08-24 21:43:11 -05007339 priv->config & CFG_STATIC_CHANNEL &&
James Ketrenos43f66a62005-03-25 12:31:53 -06007340 !list_empty(&priv->ieee->network_free_list)) {
7341 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007342 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007343 ipw_adhoc_create(priv, network);
7344 rates = &priv->rates;
7345 list_del(element);
7346 list_add_tail(&network->list, &priv->ieee->network_list);
7347 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007348 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007349
James Ketrenos43f66a62005-03-25 12:31:53 -06007350 /* If we reached the end of the list, then we don't have any valid
7351 * matching APs */
7352 if (!network) {
7353 ipw_debug_config(priv);
7354
James Ketrenosb095c382005-08-24 22:04:42 -05007355 if (!(priv->status & STATUS_SCANNING)) {
7356 if (!(priv->config & CFG_SPEED_SCAN))
7357 queue_delayed_work(priv->workqueue,
7358 &priv->request_scan,
7359 SCAN_INTERVAL);
7360 else
7361 queue_work(priv->workqueue,
7362 &priv->request_scan);
7363 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007364
James Ketrenosc848d0a2005-08-24 21:56:24 -05007365 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007366 }
7367
7368 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007369
7370 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007371}
Jeff Garzikbf794512005-07-31 13:07:26 -04007372
James Ketrenosc848d0a2005-08-24 21:56:24 -05007373static void ipw_bg_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007374{
James Ketrenosc848d0a2005-08-24 21:56:24 -05007375 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08007376 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007377 ipw_associate(data);
Zhu Yi46441512006-01-24 16:37:59 +08007378 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007379}
7380
James Ketrenosb095c382005-08-24 22:04:42 -05007381static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7382 struct sk_buff *skb)
7383{
7384 struct ieee80211_hdr *hdr;
7385 u16 fc;
7386
7387 hdr = (struct ieee80211_hdr *)skb->data;
7388 fc = le16_to_cpu(hdr->frame_ctl);
7389 if (!(fc & IEEE80211_FCTL_PROTECTED))
7390 return;
7391
7392 fc &= ~IEEE80211_FCTL_PROTECTED;
7393 hdr->frame_ctl = cpu_to_le16(fc);
7394 switch (priv->ieee->sec.level) {
7395 case SEC_LEVEL_3:
7396 /* Remove CCMP HDR */
7397 memmove(skb->data + IEEE80211_3ADDR_LEN,
7398 skb->data + IEEE80211_3ADDR_LEN + 8,
7399 skb->len - IEEE80211_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007400 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007401 break;
7402 case SEC_LEVEL_2:
7403 break;
7404 case SEC_LEVEL_1:
7405 /* Remove IV */
7406 memmove(skb->data + IEEE80211_3ADDR_LEN,
7407 skb->data + IEEE80211_3ADDR_LEN + 4,
7408 skb->len - IEEE80211_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007409 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007410 break;
7411 case SEC_LEVEL_0:
7412 break;
7413 default:
7414 printk(KERN_ERR "Unknow security level %d\n",
7415 priv->ieee->sec.level);
7416 break;
7417 }
7418}
7419
7420static void ipw_handle_data_packet(struct ipw_priv *priv,
7421 struct ipw_rx_mem_buffer *rxb,
7422 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007423{
Hong Liu567deaf2005-08-31 18:07:22 +08007424 struct ieee80211_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007425 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7426
7427 /* We received data from the HW, so stop the watchdog */
7428 priv->net_dev->trans_start = jiffies;
7429
Jeff Garzikbf794512005-07-31 13:07:26 -04007430 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007431 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007432 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007433 skb_tailroom(rxb->skb))) {
7434 priv->ieee->stats.rx_errors++;
7435 priv->wstats.discard.misc++;
7436 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7437 return;
7438 } else if (unlikely(!netif_running(priv->net_dev))) {
7439 priv->ieee->stats.rx_dropped++;
7440 priv->wstats.discard.misc++;
7441 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7442 return;
7443 }
7444
7445 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007446 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007447
7448 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007449 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007450
7451 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7452
James Ketrenosb095c382005-08-24 22:04:42 -05007453 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
Hong Liu567deaf2005-08-31 18:07:22 +08007454 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7455 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007456 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007457 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007458 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7459
Jeff Garzikbf794512005-07-31 13:07:26 -04007460 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06007461 priv->ieee->stats.rx_errors++;
James Ketrenosa613bff2005-08-24 21:43:11 -05007462 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007463 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007464 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007465 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007466}
7467
Mike Kershaw24a47db2005-08-26 00:41:54 -05007468#ifdef CONFIG_IEEE80211_RADIOTAP
7469static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7470 struct ipw_rx_mem_buffer *rxb,
7471 struct ieee80211_rx_stats *stats)
7472{
7473 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7474 struct ipw_rx_frame *frame = &pkt->u.frame;
7475
7476 /* initial pull of some data */
7477 u16 received_channel = frame->received_channel;
7478 u8 antennaAndPhy = frame->antennaAndPhy;
7479 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7480 u16 pktrate = frame->rate;
7481
7482 /* Magic struct that slots into the radiotap header -- no reason
7483 * to build this manually element by element, we can write it much
7484 * more efficiently than we can parse it. ORDER MATTERS HERE */
7485 struct ipw_rt_hdr {
7486 struct ieee80211_radiotap_header rt_hdr;
7487 u8 rt_flags; /* radiotap packet flags */
7488 u8 rt_rate; /* rate in 500kb/s */
7489 u16 rt_channel; /* channel in mhz */
7490 u16 rt_chbitmask; /* channel bitfield */
7491 s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
7492 u8 rt_antenna; /* antenna number */
7493 } *ipw_rt;
7494
7495 short len = le16_to_cpu(pkt->u.frame.length);
7496
7497 /* We received data from the HW, so stop the watchdog */
7498 priv->net_dev->trans_start = jiffies;
7499
7500 /* We only process data packets if the
7501 * interface is open */
7502 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7503 skb_tailroom(rxb->skb))) {
7504 priv->ieee->stats.rx_errors++;
7505 priv->wstats.discard.misc++;
7506 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7507 return;
7508 } else if (unlikely(!netif_running(priv->net_dev))) {
7509 priv->ieee->stats.rx_dropped++;
7510 priv->wstats.discard.misc++;
7511 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7512 return;
7513 }
7514
7515 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7516 * that now */
7517 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7518 /* FIXME: Should alloc bigger skb instead */
7519 priv->ieee->stats.rx_dropped++;
7520 priv->wstats.discard.misc++;
7521 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7522 return;
7523 }
7524
7525 /* copy the frame itself */
7526 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7527 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7528
7529 /* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7530 * part of our real header, saves a little time.
7531 *
7532 * No longer necessary since we fill in all our data. Purge before merging
7533 * patch officially.
7534 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7535 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7536 */
7537
7538 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7539
7540 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7541 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7542 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7543
7544 /* Big bitfield of all the fields we provide in radiotap */
7545 ipw_rt->rt_hdr.it_present =
7546 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7547 (1 << IEEE80211_RADIOTAP_RATE) |
7548 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7549 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7550 (1 << IEEE80211_RADIOTAP_ANTENNA));
7551
7552 /* Zero the flags, we'll add to them as we go */
7553 ipw_rt->rt_flags = 0;
7554
7555 /* Convert signal to DBM */
7556 ipw_rt->rt_dbmsignal = antsignal;
7557
7558 /* Convert the channel data and set the flags */
7559 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7560 if (received_channel > 14) { /* 802.11a */
7561 ipw_rt->rt_chbitmask =
7562 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7563 } else if (antennaAndPhy & 32) { /* 802.11b */
7564 ipw_rt->rt_chbitmask =
7565 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7566 } else { /* 802.11g */
7567 ipw_rt->rt_chbitmask =
7568 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7569 }
7570
7571 /* set the rate in multiples of 500k/s */
7572 switch (pktrate) {
7573 case IPW_TX_RATE_1MB:
7574 ipw_rt->rt_rate = 2;
7575 break;
7576 case IPW_TX_RATE_2MB:
7577 ipw_rt->rt_rate = 4;
7578 break;
7579 case IPW_TX_RATE_5MB:
7580 ipw_rt->rt_rate = 10;
7581 break;
7582 case IPW_TX_RATE_6MB:
7583 ipw_rt->rt_rate = 12;
7584 break;
7585 case IPW_TX_RATE_9MB:
7586 ipw_rt->rt_rate = 18;
7587 break;
7588 case IPW_TX_RATE_11MB:
7589 ipw_rt->rt_rate = 22;
7590 break;
7591 case IPW_TX_RATE_12MB:
7592 ipw_rt->rt_rate = 24;
7593 break;
7594 case IPW_TX_RATE_18MB:
7595 ipw_rt->rt_rate = 36;
7596 break;
7597 case IPW_TX_RATE_24MB:
7598 ipw_rt->rt_rate = 48;
7599 break;
7600 case IPW_TX_RATE_36MB:
7601 ipw_rt->rt_rate = 72;
7602 break;
7603 case IPW_TX_RATE_48MB:
7604 ipw_rt->rt_rate = 96;
7605 break;
7606 case IPW_TX_RATE_54MB:
7607 ipw_rt->rt_rate = 108;
7608 break;
7609 default:
7610 ipw_rt->rt_rate = 0;
7611 break;
7612 }
7613
7614 /* antenna number */
7615 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7616
7617 /* set the preamble flag if we have it */
7618 if ((antennaAndPhy & 64))
7619 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7620
7621 /* Set the size of the skb to the size of the frame */
7622 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007623
7624 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7625
7626 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7627 priv->ieee->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007628 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007629 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007630 /* no LED during capture */
7631 }
7632}
7633#endif
7634
Arjan van de Ven858119e2006-01-14 13:20:43 -08007635static int is_network_packet(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007636 struct ieee80211_hdr_4addr *header)
7637{
7638 /* Filter incoming packets to determine if they are targetted toward
7639 * this network, discarding packets coming from ourselves */
7640 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05007641 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007642 /* packets from our adapter are dropped (echo) */
7643 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7644 return 0;
7645
Peter Jones90700fd2005-08-26 16:51:06 -05007646 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007647 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05007648 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007649
7650 /* packets to our adapter go through */
7651 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7652 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007653
Peter Jones90700fd2005-08-26 16:51:06 -05007654 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007655 /* packets from our adapter are dropped (echo) */
7656 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7657 return 0;
7658
Peter Jones90700fd2005-08-26 16:51:06 -05007659 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007660 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05007661 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7662
7663 /* packets to our adapter go through */
7664 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7665 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007666 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007667
James Ketrenosea2b26e2005-08-24 21:25:16 -05007668 return 1;
7669}
7670
James Ketrenosafbf30a2005-08-25 00:05:33 -05007671#define IPW_PACKET_RETRY_TIME HZ
7672
Arjan van de Ven858119e2006-01-14 13:20:43 -08007673static int is_duplicate_packet(struct ipw_priv *priv,
James Ketrenosafbf30a2005-08-25 00:05:33 -05007674 struct ieee80211_hdr_4addr *header)
7675{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007676 u16 sc = le16_to_cpu(header->seq_ctl);
7677 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7678 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7679 u16 *last_seq, *last_frag;
7680 unsigned long *last_time;
7681
7682 switch (priv->ieee->iw_mode) {
7683 case IW_MODE_ADHOC:
7684 {
7685 struct list_head *p;
7686 struct ipw_ibss_seq *entry = NULL;
7687 u8 *mac = header->addr2;
7688 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
7689
7690 __list_for_each(p, &priv->ibss_mac_hash[index]) {
7691 entry =
7692 list_entry(p, struct ipw_ibss_seq, list);
7693 if (!memcmp(entry->mac, mac, ETH_ALEN))
7694 break;
7695 }
7696 if (p == &priv->ibss_mac_hash[index]) {
7697 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
7698 if (!entry) {
7699 IPW_ERROR
7700 ("Cannot malloc new mac entry\n");
7701 return 0;
7702 }
7703 memcpy(entry->mac, mac, ETH_ALEN);
7704 entry->seq_num = seq;
7705 entry->frag_num = frag;
7706 entry->packet_time = jiffies;
7707 list_add(&entry->list,
7708 &priv->ibss_mac_hash[index]);
7709 return 0;
7710 }
7711 last_seq = &entry->seq_num;
7712 last_frag = &entry->frag_num;
7713 last_time = &entry->packet_time;
7714 break;
7715 }
7716 case IW_MODE_INFRA:
7717 last_seq = &priv->last_seq_num;
7718 last_frag = &priv->last_frag_num;
7719 last_time = &priv->last_packet_time;
7720 break;
7721 default:
7722 return 0;
7723 }
7724 if ((*last_seq == seq) &&
7725 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
7726 if (*last_frag == frag)
7727 goto drop;
7728 if (*last_frag + 1 != frag)
7729 /* out-of-order fragment */
7730 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007731 } else
7732 *last_seq = seq;
7733
Zhu Yif57ce7c2005-07-13 12:22:15 -05007734 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007735 *last_time = jiffies;
7736 return 0;
7737
7738 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08007739 /* Comment this line now since we observed the card receives
7740 * duplicate packets but the FCTL_RETRY bit is not set in the
7741 * IBSS mode with fragmentation enabled.
7742 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05007743 return 1;
7744}
7745
James Ketrenosb095c382005-08-24 22:04:42 -05007746static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
7747 struct ipw_rx_mem_buffer *rxb,
7748 struct ieee80211_rx_stats *stats)
7749{
7750 struct sk_buff *skb = rxb->skb;
7751 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
7752 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
7753 (skb->data + IPW_RX_FRAME_SIZE);
7754
7755 ieee80211_rx_mgt(priv->ieee, header, stats);
7756
7757 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
7758 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7759 IEEE80211_STYPE_PROBE_RESP) ||
7760 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7761 IEEE80211_STYPE_BEACON))) {
7762 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
7763 ipw_add_station(priv, header->addr2);
7764 }
7765
7766 if (priv->config & CFG_NET_STATS) {
7767 IPW_DEBUG_HC("sending stat packet\n");
7768
7769 /* Set the size of the skb to the size of the full
7770 * ipw header and 802.11 frame */
7771 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
7772 IPW_RX_FRAME_SIZE);
7773
7774 /* Advance past the ipw packet header to the 802.11 frame */
7775 skb_pull(skb, IPW_RX_FRAME_SIZE);
7776
7777 /* Push the ieee80211_rx_stats before the 802.11 frame */
7778 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
7779
7780 skb->dev = priv->ieee->dev;
7781
7782 /* Point raw at the ieee80211_stats */
7783 skb->mac.raw = skb->data;
7784
7785 skb->pkt_type = PACKET_OTHERHOST;
7786 skb->protocol = __constant_htons(ETH_P_80211_STATS);
7787 memset(skb->cb, 0, sizeof(rxb->skb->cb));
7788 netif_rx(skb);
7789 rxb->skb = NULL;
7790 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007791}
7792
James Ketrenos43f66a62005-03-25 12:31:53 -06007793/*
7794 * Main entry function for recieving a packet with 80211 headers. This
7795 * should be called when ever the FW has notified us that there is a new
7796 * skb in the recieve queue.
7797 */
7798static void ipw_rx(struct ipw_priv *priv)
7799{
7800 struct ipw_rx_mem_buffer *rxb;
7801 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05007802 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06007803 u32 r, w, i;
7804 u8 network_packet;
7805
James Ketrenosb095c382005-08-24 22:04:42 -05007806 r = ipw_read32(priv, IPW_RX_READ_INDEX);
7807 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
James Ketrenos43f66a62005-03-25 12:31:53 -06007808 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
7809
7810 while (i != r) {
7811 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06007812 if (unlikely(rxb == NULL)) {
7813 printk(KERN_CRIT "Queue not allocated!\n");
7814 break;
7815 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007816 priv->rxq->queue[i] = NULL;
7817
7818 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05007819 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06007820 PCI_DMA_FROMDEVICE);
7821
7822 pkt = (struct ipw_rx_packet *)rxb->skb->data;
7823 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
7824 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007825 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06007826
7827 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007828 case RX_FRAME_TYPE: /* 802.11 frame */ {
7829 struct ieee80211_rx_stats stats = {
James Ketrenosc848d0a2005-08-24 21:56:24 -05007830 .rssi =
7831 le16_to_cpu(pkt->u.frame.rssi_dbm) -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007832 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05007833 .signal =
Bill Mossb1916082006-02-15 08:50:18 +08007834 le16_to_cpu(pkt->u.frame.rssi_dbm) -
7835 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05007836 .noise =
7837 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007838 .rate = pkt->u.frame.rate,
7839 .mac_time = jiffies,
7840 .received_channel =
7841 pkt->u.frame.received_channel,
7842 .freq =
7843 (pkt->u.frame.
7844 control & (1 << 0)) ?
7845 IEEE80211_24GHZ_BAND :
7846 IEEE80211_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05007847 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007848 };
James Ketrenos43f66a62005-03-25 12:31:53 -06007849
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007850 if (stats.rssi != 0)
7851 stats.mask |= IEEE80211_STATMASK_RSSI;
7852 if (stats.signal != 0)
7853 stats.mask |= IEEE80211_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007854 if (stats.noise != 0)
7855 stats.mask |= IEEE80211_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007856 if (stats.rate != 0)
7857 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06007858
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007859 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007860
James Ketrenosb095c382005-08-24 22:04:42 -05007861#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007862 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Mike Kershaw24a47db2005-08-26 00:41:54 -05007863#ifdef CONFIG_IEEE80211_RADIOTAP
7864 ipw_handle_data_packet_monitor(priv,
7865 rxb,
7866 &stats);
7867#else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007868 ipw_handle_data_packet(priv, rxb,
7869 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007870#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007871 break;
7872 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007873#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04007874
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007875 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05007876 (struct ieee80211_hdr_4addr *)(rxb->skb->
7877 data +
7878 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007879 /* TODO: Check Ad-Hoc dest/source and make sure
7880 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04007881 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06007882 * frame control of the packet and disregard
7883 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06007884
James Ketrenosea2b26e2005-08-24 21:25:16 -05007885 network_packet =
7886 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007887 if (network_packet && priv->assoc_network) {
7888 priv->assoc_network->stats.rssi =
7889 stats.rssi;
7890 average_add(&priv->average_rssi,
7891 stats.rssi);
7892 priv->last_rx_rssi = stats.rssi;
7893 }
7894
7895 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05007896 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007897
James Ketrenosa613bff2005-08-24 21:43:11 -05007898 if (le16_to_cpu(pkt->u.frame.length) <
Zhu Yi9d0be032006-02-15 06:18:19 +08007899 ieee80211_get_hdrlen(le16_to_cpu(
7900 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007901 IPW_DEBUG_DROP
7902 ("Received packet is too small. "
7903 "Dropping.\n");
7904 priv->ieee->stats.rx_errors++;
7905 priv->wstats.discard.misc++;
7906 break;
7907 }
7908
James Ketrenosa613bff2005-08-24 21:43:11 -05007909 switch (WLAN_FC_GET_TYPE
7910 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05007911
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007912 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05007913 ipw_handle_mgmt_packet(priv, rxb,
7914 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007915 break;
7916
7917 case IEEE80211_FTYPE_CTL:
7918 break;
7919
7920 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05007921 if (unlikely(!network_packet ||
7922 is_duplicate_packet(priv,
7923 header)))
7924 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007925 IPW_DEBUG_DROP("Dropping: "
7926 MAC_FMT ", "
7927 MAC_FMT ", "
7928 MAC_FMT "\n",
7929 MAC_ARG(header->
7930 addr1),
7931 MAC_ARG(header->
7932 addr2),
7933 MAC_ARG(header->
7934 addr3));
James Ketrenosb095c382005-08-24 22:04:42 -05007935 break;
7936 }
7937
7938 ipw_handle_data_packet(priv, rxb,
7939 &stats);
7940
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007941 break;
7942 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007943 break;
7944 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007945
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007946 case RX_HOST_NOTIFICATION_TYPE:{
7947 IPW_DEBUG_RX
7948 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007949 pkt->u.notification.subtype,
7950 pkt->u.notification.flags,
7951 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007952 ipw_rx_notification(priv, &pkt->u.notification);
7953 break;
7954 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007955
7956 default:
7957 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
7958 pkt->header.message_type);
7959 break;
7960 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007961
7962 /* For now we just don't re-use anything. We can tweak this
7963 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06007964 * fail to Rx correctly */
7965 if (rxb->skb != NULL) {
7966 dev_kfree_skb_any(rxb->skb);
7967 rxb->skb = NULL;
7968 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007969
James Ketrenos43f66a62005-03-25 12:31:53 -06007970 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05007971 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007972 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04007973
James Ketrenos43f66a62005-03-25 12:31:53 -06007974 i = (i + 1) % RX_QUEUE_SIZE;
7975 }
7976
7977 /* Backtrack one entry */
7978 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
7979
7980 ipw_rx_queue_restock(priv);
7981}
7982
James Ketrenosafbf30a2005-08-25 00:05:33 -05007983#define DEFAULT_RTS_THRESHOLD 2304U
7984#define MIN_RTS_THRESHOLD 1U
7985#define MAX_RTS_THRESHOLD 2304U
7986#define DEFAULT_BEACON_INTERVAL 100U
7987#define DEFAULT_SHORT_RETRY_LIMIT 7U
7988#define DEFAULT_LONG_RETRY_LIMIT 4U
7989
7990static int ipw_sw_reset(struct ipw_priv *priv, int init)
James Ketrenos43f66a62005-03-25 12:31:53 -06007991{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007992 int band, modulation;
7993 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06007994
James Ketrenosafbf30a2005-08-25 00:05:33 -05007995 /* Initialize module parameter values here */
7996 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007997
James Ketrenosafbf30a2005-08-25 00:05:33 -05007998 /* We default to disabling the LED code as right now it causes
7999 * too many systems to lock up... */
8000 if (!led)
8001 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06008002
James Ketrenosafbf30a2005-08-25 00:05:33 -05008003 if (associate)
8004 priv->config |= CFG_ASSOCIATE;
8005 else
8006 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04008007
James Ketrenosafbf30a2005-08-25 00:05:33 -05008008 if (auto_create)
8009 priv->config |= CFG_ADHOC_CREATE;
8010 else
8011 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
8012
Zhu Yi17ed0812006-01-24 16:36:31 +08008013 priv->config &= ~CFG_STATIC_ESSID;
8014 priv->essid_len = 0;
8015 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
8016
James Ketrenosafbf30a2005-08-25 00:05:33 -05008017 if (disable) {
8018 priv->status |= STATUS_RF_KILL_SW;
8019 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06008020 }
8021
James Ketrenosafbf30a2005-08-25 00:05:33 -05008022 if (channel != 0) {
8023 priv->config |= CFG_STATIC_CHANNEL;
8024 priv->channel = channel;
8025 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8026 /* TODO: Validate that provided channel is in range */
8027 }
8028#ifdef CONFIG_IPW_QOS
8029 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8030 burst_duration_CCK, burst_duration_OFDM);
8031#endif /* CONFIG_IPW_QOS */
8032
8033 switch (mode) {
8034 case 1:
8035 priv->ieee->iw_mode = IW_MODE_ADHOC;
8036 priv->net_dev->type = ARPHRD_ETHER;
8037
8038 break;
8039#ifdef CONFIG_IPW2200_MONITOR
8040 case 2:
8041 priv->ieee->iw_mode = IW_MODE_MONITOR;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008042#ifdef CONFIG_IEEE80211_RADIOTAP
8043 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8044#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008045 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008046#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008047 break;
8048#endif
8049 default:
8050 case 0:
8051 priv->net_dev->type = ARPHRD_ETHER;
8052 priv->ieee->iw_mode = IW_MODE_INFRA;
8053 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008054 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008055
James Ketrenosafbf30a2005-08-25 00:05:33 -05008056 if (hwcrypto) {
8057 priv->ieee->host_encrypt = 0;
8058 priv->ieee->host_encrypt_msdu = 0;
8059 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008060 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008061 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008062 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008063
Zhu Yie402c932005-08-05 17:20:40 +08008064 /* IPW2200/2915 is abled to do hardware fragmentation. */
8065 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008066
James Ketrenosafbf30a2005-08-25 00:05:33 -05008067 if ((priv->pci_dev->device == 0x4223) ||
8068 (priv->pci_dev->device == 0x4224)) {
8069 if (init)
8070 printk(KERN_INFO DRV_NAME
8071 ": Detected Intel PRO/Wireless 2915ABG Network "
8072 "Connection\n");
8073 priv->ieee->abg_true = 1;
8074 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8075 modulation = IEEE80211_OFDM_MODULATION |
8076 IEEE80211_CCK_MODULATION;
8077 priv->adapter = IPW_2915ABG;
8078 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008079 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008080 if (init)
8081 printk(KERN_INFO DRV_NAME
8082 ": Detected Intel PRO/Wireless 2200BG Network "
8083 "Connection\n");
8084
8085 priv->ieee->abg_true = 0;
8086 band = IEEE80211_24GHZ_BAND;
8087 modulation = IEEE80211_OFDM_MODULATION |
8088 IEEE80211_CCK_MODULATION;
8089 priv->adapter = IPW_2200BG;
8090 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008091 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008092
James Ketrenosafbf30a2005-08-25 00:05:33 -05008093 priv->ieee->freq_band = band;
8094 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008095
James Ketrenosafbf30a2005-08-25 00:05:33 -05008096 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008097
James Ketrenosafbf30a2005-08-25 00:05:33 -05008098 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8099 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008100
James Ketrenosafbf30a2005-08-25 00:05:33 -05008101 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8102 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8103 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008104
James Ketrenosafbf30a2005-08-25 00:05:33 -05008105 /* If power management is turned on, default to AC mode */
8106 priv->power_mode = IPW_POWER_AC;
8107 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008108
Zhu Yi0ece35b2005-08-05 17:26:51 +08008109 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008110}
8111
8112/*
8113 * This file defines the Wireless Extension handlers. It does not
8114 * define any methods of hardware manipulation and relies on the
8115 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008116 *
8117 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008118 * function used to poll the hardware vs. making unecessary calls.
8119 *
8120 */
8121
Jeff Garzikbf794512005-07-31 13:07:26 -04008122static int ipw_wx_get_name(struct net_device *dev,
8123 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008124 union iwreq_data *wrqu, char *extra)
8125{
8126 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008127 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008128 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -05008129 strcpy(wrqu->name, "radio off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008130 else if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06008131 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04008132 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008133 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8134 ipw_modes[priv->assoc_request.ieee_mode]);
8135 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
Zhu Yi46441512006-01-24 16:37:59 +08008136 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008137 return 0;
8138}
8139
8140static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8141{
8142 if (channel == 0) {
8143 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8144 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008145 IPW_DEBUG_ASSOC("Attempting to associate with new "
8146 "parameters.\n");
8147 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008148 return 0;
8149 }
8150
8151 priv->config |= CFG_STATIC_CHANNEL;
8152
8153 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008154 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8155 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008156 return 0;
8157 }
8158
8159 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8160 priv->channel = channel;
8161
James Ketrenosb095c382005-08-24 22:04:42 -05008162#ifdef CONFIG_IPW2200_MONITOR
8163 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008164 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008165 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008166 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008167 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008168 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008169 }
8170
8171 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8172 udelay(10);
8173
8174 if (priv->status & STATUS_SCANNING)
8175 IPW_DEBUG_SCAN("Still scanning...\n");
8176 else
8177 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8178 1000 - i);
8179
8180 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008181 }
James Ketrenosb095c382005-08-24 22:04:42 -05008182#endif /* CONFIG_IPW2200_MONITOR */
8183
James Ketrenosc848d0a2005-08-24 21:56:24 -05008184 /* Network configuration changed -- force [re]association */
8185 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8186 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008187 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008188
8189 return 0;
8190}
8191
Jeff Garzikbf794512005-07-31 13:07:26 -04008192static int ipw_wx_set_freq(struct net_device *dev,
8193 struct iw_request_info *info,
8194 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008195{
8196 struct ipw_priv *priv = ieee80211_priv(dev);
Larry Finger1867b112006-02-28 09:48:28 -06008197 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008198 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008199 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008200 u8 channel, flags;
8201 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008202
James Ketrenosb095c382005-08-24 22:04:42 -05008203 if (fwrq->m == 0) {
8204 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008205 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008206 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008207 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008208 return ret;
8209 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008210 /* if setting by freq convert to channel */
8211 if (fwrq->e == 1) {
Larry Finger1867b112006-02-28 09:48:28 -06008212 channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008213 if (channel == 0)
8214 return -EINVAL;
8215 } else
8216 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008217
Larry Finger1867b112006-02-28 09:48:28 -06008218 if (!(band = ieee80211_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008219 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008220
Liu Hong1fe0adb2005-08-19 09:33:10 -05008221 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
Larry Finger1867b112006-02-28 09:48:28 -06008222 i = ieee80211_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008223 if (i == -1)
8224 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008225
8226 flags = (band == IEEE80211_24GHZ_BAND) ?
8227 geo->bg[i].flags : geo->a[i].flags;
8228 if (flags & IEEE80211_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008229 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8230 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008231 }
8232 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008233
James Ketrenos43f66a62005-03-25 12:31:53 -06008234 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008235 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008236 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008237 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008238 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008239}
8240
Jeff Garzikbf794512005-07-31 13:07:26 -04008241static int ipw_wx_get_freq(struct net_device *dev,
8242 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008243 union iwreq_data *wrqu, char *extra)
8244{
8245 struct ipw_priv *priv = ieee80211_priv(dev);
8246
8247 wrqu->freq.e = 0;
8248
8249 /* If we are associated, trying to associate, or have a statically
8250 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008251 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008252 if (priv->config & CFG_STATIC_CHANNEL ||
8253 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8254 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04008255 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008256 wrqu->freq.m = 0;
8257
Zhu Yi46441512006-01-24 16:37:59 +08008258 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008259 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8260 return 0;
8261}
8262
Jeff Garzikbf794512005-07-31 13:07:26 -04008263static int ipw_wx_set_mode(struct net_device *dev,
8264 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008265 union iwreq_data *wrqu, char *extra)
8266{
8267 struct ipw_priv *priv = ieee80211_priv(dev);
8268 int err = 0;
8269
8270 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8271
James Ketrenos43f66a62005-03-25 12:31:53 -06008272 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008273#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008274 case IW_MODE_MONITOR:
8275#endif
8276 case IW_MODE_ADHOC:
8277 case IW_MODE_INFRA:
8278 break;
8279 case IW_MODE_AUTO:
8280 wrqu->mode = IW_MODE_INFRA;
8281 break;
8282 default:
8283 return -EINVAL;
8284 }
James Ketrenosb095c382005-08-24 22:04:42 -05008285 if (wrqu->mode == priv->ieee->iw_mode)
8286 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008287
Zhu Yi46441512006-01-24 16:37:59 +08008288 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008289
8290 ipw_sw_reset(priv, 0);
8291
James Ketrenosb095c382005-08-24 22:04:42 -05008292#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008293 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008294 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008295
8296 if (wrqu->mode == IW_MODE_MONITOR)
Mike Kershaw24a47db2005-08-26 00:41:54 -05008297#ifdef CONFIG_IEEE80211_RADIOTAP
8298 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8299#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008300 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008301#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008302#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008303
Jeff Garzikbf794512005-07-31 13:07:26 -04008304 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06008305 * flag so ipw_load() will bring in the new firmawre */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008306 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008307
8308 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008309
James Ketrenosc848d0a2005-08-24 21:56:24 -05008310 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008311 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008312 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008313}
8314
Jeff Garzikbf794512005-07-31 13:07:26 -04008315static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008316 struct iw_request_info *info,
8317 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008318{
8319 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008320 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008321 wrqu->mode = priv->ieee->iw_mode;
8322 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008323 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008324 return 0;
8325}
8326
James Ketrenos43f66a62005-03-25 12:31:53 -06008327/* Values are in microsecond */
8328static const s32 timeout_duration[] = {
8329 350000,
8330 250000,
8331 75000,
8332 37000,
8333 25000,
8334};
8335
8336static const s32 period_duration[] = {
8337 400000,
8338 700000,
8339 1000000,
8340 1000000,
8341 1000000
8342};
8343
Jeff Garzikbf794512005-07-31 13:07:26 -04008344static int ipw_wx_get_range(struct net_device *dev,
8345 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008346 union iwreq_data *wrqu, char *extra)
8347{
8348 struct ipw_priv *priv = ieee80211_priv(dev);
8349 struct iw_range *range = (struct iw_range *)extra;
Larry Finger1867b112006-02-28 09:48:28 -06008350 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008351 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008352
8353 wrqu->data.length = sizeof(*range);
8354 memset(range, 0, sizeof(*range));
8355
8356 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008357 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008358
8359 range->max_qual.qual = 100;
8360 /* TODO: Find real max RSSI and stick here */
8361 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008362 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008363 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008364
8365 range->avg_qual.qual = 70;
8366 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008367 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008368 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008369 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008370 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008371 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008372
Jeff Garzikbf794512005-07-31 13:07:26 -04008373 for (i = 0; i < range->num_bitrates; i++)
8374 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008375 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008376
James Ketrenos43f66a62005-03-25 12:31:53 -06008377 range->max_rts = DEFAULT_RTS_THRESHOLD;
8378 range->min_frag = MIN_FRAG_THRESHOLD;
8379 range->max_frag = MAX_FRAG_THRESHOLD;
8380
8381 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008382 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008383 range->num_encoding_sizes = 2;
8384 range->max_encoding_tokens = WEP_KEYS;
8385
8386 /* Set the Wireless Extension versions */
8387 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008388 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008389
James Ketrenosb095c382005-08-24 22:04:42 -05008390 i = 0;
8391 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
8392 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES;
8393 i++, j++) {
8394 range->freq[i].i = geo->bg[j].channel;
8395 range->freq[i].m = geo->bg[j].freq * 100000;
8396 range->freq[i].e = 1;
8397 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008398 }
James Ketrenosb095c382005-08-24 22:04:42 -05008399
8400 if (priv->ieee->mode & IEEE_A) {
8401 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES;
8402 i++, j++) {
8403 range->freq[i].i = geo->a[j].channel;
8404 range->freq[i].m = geo->a[j].freq * 100000;
8405 range->freq[i].e = 1;
8406 }
8407 }
8408
8409 range->num_channels = i;
8410 range->num_frequency = i;
8411
Zhu Yi46441512006-01-24 16:37:59 +08008412 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008413
8414 /* Event capability (kernel + driver) */
8415 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8416 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
8417 IW_EVENT_CAPA_MASK(SIOCGIWAP));
8418 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008419
Dan Williamsf1b50862006-01-30 13:58:56 -05008420 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8421 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8422
James Ketrenos43f66a62005-03-25 12:31:53 -06008423 IPW_DEBUG_WX("GET Range\n");
8424 return 0;
8425}
8426
Jeff Garzikbf794512005-07-31 13:07:26 -04008427static int ipw_wx_set_wap(struct net_device *dev,
8428 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008429 union iwreq_data *wrqu, char *extra)
8430{
8431 struct ipw_priv *priv = ieee80211_priv(dev);
8432
8433 static const unsigned char any[] = {
8434 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8435 };
8436 static const unsigned char off[] = {
8437 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8438 };
8439
Jeff Garzikbf794512005-07-31 13:07:26 -04008440 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06008441 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08008442 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008443 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8444 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8445 /* we disable mandatory BSSID association */
8446 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8447 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008448 IPW_DEBUG_ASSOC("Attempting to associate with new "
8449 "parameters.\n");
8450 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08008451 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008452 return 0;
8453 }
8454
8455 priv->config |= CFG_STATIC_BSSID;
8456 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8457 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008458 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008459 return 0;
8460 }
8461
8462 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8463 MAC_ARG(wrqu->ap_addr.sa_data));
8464
8465 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8466
James Ketrenosc848d0a2005-08-24 21:56:24 -05008467 /* Network configuration changed -- force [re]association */
8468 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8469 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008470 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008471
Zhu Yi46441512006-01-24 16:37:59 +08008472 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008473 return 0;
8474}
8475
Jeff Garzikbf794512005-07-31 13:07:26 -04008476static int ipw_wx_get_wap(struct net_device *dev,
8477 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008478 union iwreq_data *wrqu, char *extra)
8479{
8480 struct ipw_priv *priv = ieee80211_priv(dev);
8481 /* If we are associated, trying to associate, or have a statically
8482 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008483 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04008484 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06008485 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8486 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008487 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06008488 } else
8489 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8490
8491 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8492 MAC_ARG(wrqu->ap_addr.sa_data));
Zhu Yi46441512006-01-24 16:37:59 +08008493 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008494 return 0;
8495}
8496
Jeff Garzikbf794512005-07-31 13:07:26 -04008497static int ipw_wx_set_essid(struct net_device *dev,
8498 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008499 union iwreq_data *wrqu, char *extra)
8500{
8501 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008502 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06008503 int length = 0;
Zhu Yi46441512006-01-24 16:37:59 +08008504 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008505 if (wrqu->essid.flags && wrqu->essid.length) {
8506 length = wrqu->essid.length - 1;
8507 essid = extra;
8508 }
8509 if (length == 0) {
8510 IPW_DEBUG_WX("Setting ESSID to ANY\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008511 if ((priv->config & CFG_STATIC_ESSID) &&
8512 !(priv->status & (STATUS_ASSOCIATED |
James Ketrenos43f66a62005-03-25 12:31:53 -06008513 STATUS_ASSOCIATING))) {
8514 IPW_DEBUG_ASSOC("Attempting to associate with new "
8515 "parameters.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008516 priv->config &= ~CFG_STATIC_ESSID;
James Ketrenos43f66a62005-03-25 12:31:53 -06008517 ipw_associate(priv);
8518 }
Zhu Yi46441512006-01-24 16:37:59 +08008519 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008520 return 0;
8521 }
8522
8523 length = min(length, IW_ESSID_MAX_SIZE);
8524
8525 priv->config |= CFG_STATIC_ESSID;
8526
8527 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8528 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008529 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008530 return 0;
8531 }
8532
8533 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8534 length);
8535
8536 priv->essid_len = length;
8537 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04008538
James Ketrenosc848d0a2005-08-24 21:56:24 -05008539 /* Network configuration changed -- force [re]association */
8540 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8541 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008542 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008543
Zhu Yi46441512006-01-24 16:37:59 +08008544 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008545 return 0;
8546}
8547
Jeff Garzikbf794512005-07-31 13:07:26 -04008548static int ipw_wx_get_essid(struct net_device *dev,
8549 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008550 union iwreq_data *wrqu, char *extra)
8551{
8552 struct ipw_priv *priv = ieee80211_priv(dev);
8553
8554 /* If we are associated, trying to associate, or have a statically
8555 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008556 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008557 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04008558 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8559 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008560 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04008561 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06008562 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008563 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008564 } else {
8565 IPW_DEBUG_WX("Getting essid: ANY\n");
8566 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008567 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008568 }
Zhu Yi46441512006-01-24 16:37:59 +08008569 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008570 return 0;
8571}
8572
Jeff Garzikbf794512005-07-31 13:07:26 -04008573static int ipw_wx_set_nick(struct net_device *dev,
8574 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008575 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008576{
James Ketrenos43f66a62005-03-25 12:31:53 -06008577 struct ipw_priv *priv = ieee80211_priv(dev);
8578
8579 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8580 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8581 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08008582 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008583 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06008584 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008585 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06008586 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08008587 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008588 return 0;
8589
8590}
8591
Jeff Garzikbf794512005-07-31 13:07:26 -04008592static int ipw_wx_get_nick(struct net_device *dev,
8593 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008594 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008595{
James Ketrenos43f66a62005-03-25 12:31:53 -06008596 struct ipw_priv *priv = ieee80211_priv(dev);
8597 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08008598 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008599 wrqu->data.length = strlen(priv->nick) + 1;
8600 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008601 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08008602 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008603 return 0;
8604}
8605
James Ketrenos43f66a62005-03-25 12:31:53 -06008606static int ipw_wx_set_rate(struct net_device *dev,
8607 struct iw_request_info *info,
8608 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008609{
James Ketrenosea2b26e2005-08-24 21:25:16 -05008610 /* TODO: We should use semaphores or locks for access to priv */
8611 struct ipw_priv *priv = ieee80211_priv(dev);
8612 u32 target_rate = wrqu->bitrate.value;
8613 u32 fixed, mask;
8614
8615 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8616 /* value = X, fixed = 1 means only rate X */
8617 /* value = X, fixed = 0 means all rates lower equal X */
8618
8619 if (target_rate == -1) {
8620 fixed = 0;
8621 mask = IEEE80211_DEFAULT_RATES_MASK;
8622 /* Now we should reassociate */
8623 goto apply;
8624 }
8625
8626 mask = 0;
8627 fixed = wrqu->bitrate.fixed;
8628
8629 if (target_rate == 1000000 || !fixed)
8630 mask |= IEEE80211_CCK_RATE_1MB_MASK;
8631 if (target_rate == 1000000)
8632 goto apply;
8633
8634 if (target_rate == 2000000 || !fixed)
8635 mask |= IEEE80211_CCK_RATE_2MB_MASK;
8636 if (target_rate == 2000000)
8637 goto apply;
8638
8639 if (target_rate == 5500000 || !fixed)
8640 mask |= IEEE80211_CCK_RATE_5MB_MASK;
8641 if (target_rate == 5500000)
8642 goto apply;
8643
8644 if (target_rate == 6000000 || !fixed)
8645 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
8646 if (target_rate == 6000000)
8647 goto apply;
8648
8649 if (target_rate == 9000000 || !fixed)
8650 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
8651 if (target_rate == 9000000)
8652 goto apply;
8653
8654 if (target_rate == 11000000 || !fixed)
8655 mask |= IEEE80211_CCK_RATE_11MB_MASK;
8656 if (target_rate == 11000000)
8657 goto apply;
8658
8659 if (target_rate == 12000000 || !fixed)
8660 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
8661 if (target_rate == 12000000)
8662 goto apply;
8663
8664 if (target_rate == 18000000 || !fixed)
8665 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
8666 if (target_rate == 18000000)
8667 goto apply;
8668
8669 if (target_rate == 24000000 || !fixed)
8670 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
8671 if (target_rate == 24000000)
8672 goto apply;
8673
8674 if (target_rate == 36000000 || !fixed)
8675 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
8676 if (target_rate == 36000000)
8677 goto apply;
8678
8679 if (target_rate == 48000000 || !fixed)
8680 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
8681 if (target_rate == 48000000)
8682 goto apply;
8683
8684 if (target_rate == 54000000 || !fixed)
8685 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
8686 if (target_rate == 54000000)
8687 goto apply;
8688
8689 IPW_DEBUG_WX("invalid rate specified, returning error\n");
8690 return -EINVAL;
8691
8692 apply:
8693 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
8694 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08008695 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008696 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05008697 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05008698 ipw_set_fixed_rate(priv, priv->ieee->mode);
8699 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05008700 priv->config |= CFG_FIXED_RATE;
8701
James Ketrenosc848d0a2005-08-24 21:56:24 -05008702 if (priv->rates_mask == mask) {
8703 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008704 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008705 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05008706 }
8707
James Ketrenosc848d0a2005-08-24 21:56:24 -05008708 priv->rates_mask = mask;
8709
8710 /* Network configuration changed -- force [re]association */
8711 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
8712 if (!ipw_disassociate(priv))
8713 ipw_associate(priv);
8714
Zhu Yi46441512006-01-24 16:37:59 +08008715 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008716 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008717}
8718
Jeff Garzikbf794512005-07-31 13:07:26 -04008719static int ipw_wx_get_rate(struct net_device *dev,
8720 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008721 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008722{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008723 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008724 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008725 wrqu->bitrate.value = priv->last_rate;
Zhu Yi46441512006-01-24 16:37:59 +08008726 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008727 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
8728 return 0;
8729}
8730
Jeff Garzikbf794512005-07-31 13:07:26 -04008731static int ipw_wx_set_rts(struct net_device *dev,
8732 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008733 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008734{
James Ketrenos43f66a62005-03-25 12:31:53 -06008735 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008736 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008737 if (wrqu->rts.disabled)
8738 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8739 else {
8740 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05008741 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08008742 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008743 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008744 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008745 priv->rts_threshold = wrqu->rts.value;
8746 }
8747
8748 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08008749 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008750 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
8751 return 0;
8752}
8753
Jeff Garzikbf794512005-07-31 13:07:26 -04008754static int ipw_wx_get_rts(struct net_device *dev,
8755 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008756 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008757{
James Ketrenos43f66a62005-03-25 12:31:53 -06008758 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008759 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008760 wrqu->rts.value = priv->rts_threshold;
8761 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008762 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08008763 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008764 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
8765 return 0;
8766}
8767
Jeff Garzikbf794512005-07-31 13:07:26 -04008768static int ipw_wx_set_txpow(struct net_device *dev,
8769 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008770 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008771{
James Ketrenos43f66a62005-03-25 12:31:53 -06008772 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008773 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008774
Zhu Yi46441512006-01-24 16:37:59 +08008775 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008776 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008777 err = -EINPROGRESS;
8778 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008779 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008780
James Ketrenosb095c382005-08-24 22:04:42 -05008781 if (!wrqu->power.fixed)
8782 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008783
James Ketrenosc848d0a2005-08-24 21:56:24 -05008784 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008785 err = -EINVAL;
8786 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008787 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008788
James Ketrenosb095c382005-08-24 22:04:42 -05008789 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05008790 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008791 err = -EINVAL;
8792 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008793 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008794
8795 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008796 err = ipw_set_tx_power(priv);
8797 out:
Zhu Yi46441512006-01-24 16:37:59 +08008798 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008799 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008800}
8801
Jeff Garzikbf794512005-07-31 13:07:26 -04008802static int ipw_wx_get_txpow(struct net_device *dev,
8803 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008804 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008805{
James Ketrenos43f66a62005-03-25 12:31:53 -06008806 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008807 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008808 wrqu->power.value = priv->tx_power;
8809 wrqu->power.fixed = 1;
8810 wrqu->power.flags = IW_TXPOW_DBM;
8811 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08008812 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008813
Jeff Garzikbf794512005-07-31 13:07:26 -04008814 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08008815 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06008816
8817 return 0;
8818}
8819
Jeff Garzikbf794512005-07-31 13:07:26 -04008820static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008821 struct iw_request_info *info,
8822 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008823{
8824 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008825 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008826 if (wrqu->frag.disabled)
8827 priv->ieee->fts = DEFAULT_FTS;
8828 else {
8829 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05008830 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08008831 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008832 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05008833 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008834
James Ketrenos43f66a62005-03-25 12:31:53 -06008835 priv->ieee->fts = wrqu->frag.value & ~0x1;
8836 }
8837
8838 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08008839 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008840 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
8841 return 0;
8842}
8843
Jeff Garzikbf794512005-07-31 13:07:26 -04008844static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008845 struct iw_request_info *info,
8846 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008847{
8848 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008849 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008850 wrqu->frag.value = priv->ieee->fts;
8851 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008852 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08008853 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008854 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
8855
8856 return 0;
8857}
8858
Jeff Garzikbf794512005-07-31 13:07:26 -04008859static int ipw_wx_set_retry(struct net_device *dev,
8860 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008861 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008862{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008863 struct ipw_priv *priv = ieee80211_priv(dev);
8864
8865 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
8866 return -EINVAL;
8867
8868 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
8869 return 0;
8870
8871 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
8872 return -EINVAL;
8873
Zhu Yi46441512006-01-24 16:37:59 +08008874 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008875 if (wrqu->retry.flags & IW_RETRY_MIN)
8876 priv->short_retry_limit = (u8) wrqu->retry.value;
8877 else if (wrqu->retry.flags & IW_RETRY_MAX)
8878 priv->long_retry_limit = (u8) wrqu->retry.value;
8879 else {
8880 priv->short_retry_limit = (u8) wrqu->retry.value;
8881 priv->long_retry_limit = (u8) wrqu->retry.value;
8882 }
8883
8884 ipw_send_retry_limit(priv, priv->short_retry_limit,
8885 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08008886 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008887 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
8888 priv->short_retry_limit, priv->long_retry_limit);
8889 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008890}
8891
Jeff Garzikbf794512005-07-31 13:07:26 -04008892static int ipw_wx_get_retry(struct net_device *dev,
8893 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008894 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008895{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008896 struct ipw_priv *priv = ieee80211_priv(dev);
8897
Zhu Yi46441512006-01-24 16:37:59 +08008898 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008899 wrqu->retry.disabled = 0;
8900
8901 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08008902 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008903 return -EINVAL;
8904 }
8905
8906 if (wrqu->retry.flags & IW_RETRY_MAX) {
8907 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
8908 wrqu->retry.value = priv->long_retry_limit;
8909 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
8910 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
8911 wrqu->retry.value = priv->short_retry_limit;
8912 } else {
8913 wrqu->retry.flags = IW_RETRY_LIMIT;
8914 wrqu->retry.value = priv->short_retry_limit;
8915 }
Zhu Yi46441512006-01-24 16:37:59 +08008916 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008917
8918 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
8919
8920 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008921}
8922
James Ketrenosafbf30a2005-08-25 00:05:33 -05008923static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
8924 int essid_len)
8925{
8926 struct ipw_scan_request_ext scan;
8927 int err = 0, scan_type;
8928
Pekka Enbergefb34422005-11-16 21:55:05 +02008929 if (!(priv->status & STATUS_INIT) ||
8930 (priv->status & STATUS_EXIT_PENDING))
8931 return 0;
8932
Zhu Yi46441512006-01-24 16:37:59 +08008933 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008934
8935 if (priv->status & STATUS_RF_KILL_MASK) {
8936 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
8937 priv->status |= STATUS_SCAN_PENDING;
8938 goto done;
8939 }
8940
8941 IPW_DEBUG_HC("starting request direct scan!\n");
8942
8943 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
Olaf Kirchd834a412006-01-09 17:00:37 +01008944 /* We should not sleep here; otherwise we will block most
8945 * of the system (for instance, we hold rtnl_lock when we
8946 * get here).
8947 */
8948 err = -EAGAIN;
8949 goto done;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008950 }
8951 memset(&scan, 0, sizeof(scan));
8952
8953 if (priv->config & CFG_SPEED_SCAN)
8954 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
8955 cpu_to_le16(30);
8956 else
8957 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
8958 cpu_to_le16(20);
8959
8960 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
8961 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05008962 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008963 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
8964
8965 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
8966
8967 err = ipw_send_ssid(priv, essid, essid_len);
8968 if (err) {
8969 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
8970 goto done;
8971 }
8972 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
8973
8974 ipw_add_scan_channels(priv, &scan, scan_type);
8975
8976 err = ipw_send_scan_request_ext(priv, &scan);
8977 if (err) {
8978 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
8979 goto done;
8980 }
8981
8982 priv->status |= STATUS_SCANNING;
8983
8984 done:
Zhu Yi46441512006-01-24 16:37:59 +08008985 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008986 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008987}
8988
Jeff Garzikbf794512005-07-31 13:07:26 -04008989static int ipw_wx_set_scan(struct net_device *dev,
8990 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008991 union iwreq_data *wrqu, char *extra)
8992{
8993 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008994 struct iw_scan_req *req = NULL;
8995 if (wrqu->data.length
8996 && wrqu->data.length == sizeof(struct iw_scan_req)) {
8997 req = (struct iw_scan_req *)extra;
8998 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
8999 ipw_request_direct_scan(priv, req->essid,
9000 req->essid_len);
9001 return 0;
9002 }
9003 }
James Ketrenos8935f392005-10-05 15:59:08 -05009004
James Ketrenos43f66a62005-03-25 12:31:53 -06009005 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009006
9007 queue_work(priv->workqueue, &priv->request_scan);
9008
James Ketrenos43f66a62005-03-25 12:31:53 -06009009 return 0;
9010}
9011
Jeff Garzikbf794512005-07-31 13:07:26 -04009012static int ipw_wx_get_scan(struct net_device *dev,
9013 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009014 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009015{
James Ketrenos43f66a62005-03-25 12:31:53 -06009016 struct ipw_priv *priv = ieee80211_priv(dev);
9017 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9018}
9019
Jeff Garzikbf794512005-07-31 13:07:26 -04009020static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009021 struct iw_request_info *info,
9022 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009023{
9024 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009025 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009026 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009027
Zhu Yi46441512006-01-24 16:37:59 +08009028 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009029 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009030
Hong Liucaeff812005-08-05 17:25:50 +08009031 /* In IBSS mode, we need to notify the firmware to update
9032 * the beacon info after we changed the capability. */
9033 if (cap != priv->capability &&
9034 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9035 priv->status & STATUS_ASSOCIATED)
9036 ipw_disassociate(priv);
9037
Zhu Yi46441512006-01-24 16:37:59 +08009038 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009039 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009040}
9041
Jeff Garzikbf794512005-07-31 13:07:26 -04009042static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009043 struct iw_request_info *info,
9044 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009045{
9046 struct ipw_priv *priv = ieee80211_priv(dev);
9047 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9048}
9049
Jeff Garzikbf794512005-07-31 13:07:26 -04009050static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009051 struct iw_request_info *info,
9052 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009053{
9054 struct ipw_priv *priv = ieee80211_priv(dev);
9055 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009056 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009057 if (wrqu->power.disabled) {
9058 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9059 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9060 if (err) {
9061 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009062 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009063 return err;
9064 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009065 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009066 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009067 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009068 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009069
9070 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009071 case IW_POWER_ON: /* If not specified */
9072 case IW_POWER_MODE: /* If set all mask */
9073 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009074 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009075 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009076 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9077 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009078 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009079 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009080 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009081
James Ketrenos43f66a62005-03-25 12:31:53 -06009082 /* If the user hasn't specified a power management mode yet, default
9083 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009084 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009085 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009086 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009087 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9088 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9089 if (err) {
9090 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009091 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009092 return err;
9093 }
9094
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009095 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009096 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009097 return 0;
9098}
9099
Jeff Garzikbf794512005-07-31 13:07:26 -04009100static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009101 struct iw_request_info *info,
9102 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009103{
9104 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009105 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009106 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009107 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009108 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009109 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009110
Zhu Yi46441512006-01-24 16:37:59 +08009111 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009112 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009113
James Ketrenos43f66a62005-03-25 12:31:53 -06009114 return 0;
9115}
9116
Jeff Garzikbf794512005-07-31 13:07:26 -04009117static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009118 struct iw_request_info *info,
9119 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009120{
9121 struct ipw_priv *priv = ieee80211_priv(dev);
9122 int mode = *(int *)extra;
9123 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009124 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009125 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9126 mode = IPW_POWER_AC;
9127 priv->power_mode = mode;
9128 } else {
9129 priv->power_mode = IPW_POWER_ENABLED | mode;
9130 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009131
James Ketrenos43f66a62005-03-25 12:31:53 -06009132 if (priv->power_mode != mode) {
9133 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009134
James Ketrenos43f66a62005-03-25 12:31:53 -06009135 if (err) {
9136 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009137 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009138 return err;
9139 }
9140 }
Zhu Yi46441512006-01-24 16:37:59 +08009141 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009142 return 0;
9143}
9144
9145#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009146static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009147 struct iw_request_info *info,
9148 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009149{
9150 struct ipw_priv *priv = ieee80211_priv(dev);
9151 int level = IPW_POWER_LEVEL(priv->power_mode);
9152 char *p = extra;
9153
9154 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9155
9156 switch (level) {
9157 case IPW_POWER_AC:
9158 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9159 break;
9160 case IPW_POWER_BATTERY:
9161 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9162 break;
9163 default:
9164 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009165 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009166 timeout_duration[level - 1] / 1000,
9167 period_duration[level - 1] / 1000);
9168 }
9169
9170 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009171 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009172
9173 wrqu->data.length = p - extra + 1;
9174
9175 return 0;
9176}
9177
9178static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009179 struct iw_request_info *info,
9180 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009181{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009182 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009183 int mode = *(int *)extra;
9184 u8 band = 0, modulation = 0;
9185
9186 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009187 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009188 return -EINVAL;
9189 }
Zhu Yi46441512006-01-24 16:37:59 +08009190 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009191 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009192 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009193 if (mode & IEEE_A) {
9194 band |= IEEE80211_52GHZ_BAND;
9195 modulation |= IEEE80211_OFDM_MODULATION;
9196 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009197 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009198 } else {
9199 if (mode & IEEE_A) {
9200 IPW_WARNING("Attempt to set 2200BG into "
9201 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009202 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009203 return -EINVAL;
9204 }
9205
James Ketrenosa33a1982005-09-14 14:28:59 -05009206 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009207 }
9208
9209 if (mode & IEEE_B) {
9210 band |= IEEE80211_24GHZ_BAND;
9211 modulation |= IEEE80211_CCK_MODULATION;
9212 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009213 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009214
James Ketrenos43f66a62005-03-25 12:31:53 -06009215 if (mode & IEEE_G) {
9216 band |= IEEE80211_24GHZ_BAND;
9217 modulation |= IEEE80211_OFDM_MODULATION;
9218 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009219 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009220
9221 priv->ieee->mode = mode;
9222 priv->ieee->freq_band = band;
9223 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009224 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009225
James Ketrenosc848d0a2005-08-24 21:56:24 -05009226 /* Network configuration changed -- force [re]association */
9227 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9228 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009229 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009230 ipw_associate(priv);
9231 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009232
James Ketrenosa613bff2005-08-24 21:43:11 -05009233 /* Update the band LEDs */
9234 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009235
Jeff Garzikbf794512005-07-31 13:07:26 -04009236 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009237 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009238 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009239 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009240 return 0;
9241}
9242
9243static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009244 struct iw_request_info *info,
9245 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009246{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009247 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009248 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009249 switch (priv->ieee->mode) {
9250 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009251 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9252 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009253 case IEEE_B:
9254 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9255 break;
9256 case IEEE_A | IEEE_B:
9257 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9258 break;
9259 case IEEE_G:
9260 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9261 break;
9262 case IEEE_A | IEEE_G:
9263 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9264 break;
9265 case IEEE_B | IEEE_G:
9266 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9267 break;
9268 case IEEE_A | IEEE_B | IEEE_G:
9269 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9270 break;
9271 default:
9272 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009273 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009274 }
9275
James Ketrenos43f66a62005-03-25 12:31:53 -06009276 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9277
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009278 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009279 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009280
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009281 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009282}
9283
James Ketrenosea2b26e2005-08-24 21:25:16 -05009284static int ipw_wx_set_preamble(struct net_device *dev,
9285 struct iw_request_info *info,
9286 union iwreq_data *wrqu, char *extra)
9287{
9288 struct ipw_priv *priv = ieee80211_priv(dev);
9289 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009290 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009291 /* Switching from SHORT -> LONG requires a disassociation */
9292 if (mode == 1) {
9293 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9294 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009295
9296 /* Network configuration changed -- force [re]association */
9297 IPW_DEBUG_ASSOC
9298 ("[re]association triggered due to preamble change.\n");
9299 if (!ipw_disassociate(priv))
9300 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009301 }
9302 goto done;
9303 }
9304
9305 if (mode == 0) {
9306 priv->config &= ~CFG_PREAMBLE_LONG;
9307 goto done;
9308 }
Zhu Yi46441512006-01-24 16:37:59 +08009309 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009310 return -EINVAL;
9311
9312 done:
Zhu Yi46441512006-01-24 16:37:59 +08009313 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009314 return 0;
9315}
9316
9317static int ipw_wx_get_preamble(struct net_device *dev,
9318 struct iw_request_info *info,
9319 union iwreq_data *wrqu, char *extra)
9320{
9321 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009322 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009323 if (priv->config & CFG_PREAMBLE_LONG)
9324 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9325 else
9326 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009327 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009328 return 0;
9329}
9330
James Ketrenosb095c382005-08-24 22:04:42 -05009331#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009332static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009333 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009334 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009335{
James Ketrenos43f66a62005-03-25 12:31:53 -06009336 struct ipw_priv *priv = ieee80211_priv(dev);
9337 int *parms = (int *)extra;
9338 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009339 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009340 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009341 if (enable) {
9342 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Mike Kershaw24a47db2005-08-26 00:41:54 -05009343#ifdef CONFIG_IEEE80211_RADIOTAP
9344 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9345#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009346 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009347#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009348 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009349 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009350
James Ketrenos43f66a62005-03-25 12:31:53 -06009351 ipw_set_channel(priv, parms[1]);
9352 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009353 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009354 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009355 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009356 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009357 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009358 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009359 }
Zhu Yi46441512006-01-24 16:37:59 +08009360 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009361 return 0;
9362}
9363
James Ketrenosb095c382005-08-24 22:04:42 -05009364#endif // CONFIG_IPW2200_MONITOR
9365
Jeff Garzikbf794512005-07-31 13:07:26 -04009366static int ipw_wx_reset(struct net_device *dev,
9367 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009368 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009369{
James Ketrenos43f66a62005-03-25 12:31:53 -06009370 struct ipw_priv *priv = ieee80211_priv(dev);
9371 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009372 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009373 return 0;
9374}
James Ketrenosb095c382005-08-24 22:04:42 -05009375
James Ketrenosb095c382005-08-24 22:04:42 -05009376static int ipw_wx_sw_reset(struct net_device *dev,
9377 struct iw_request_info *info,
9378 union iwreq_data *wrqu, char *extra)
9379{
9380 struct ipw_priv *priv = ieee80211_priv(dev);
9381 union iwreq_data wrqu_sec = {
9382 .encoding = {
9383 .flags = IW_ENCODE_DISABLED,
9384 },
9385 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009386 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009387
9388 IPW_DEBUG_WX("SW_RESET\n");
9389
Zhu Yi46441512006-01-24 16:37:59 +08009390 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009391
James Ketrenosafbf30a2005-08-25 00:05:33 -05009392 ret = ipw_sw_reset(priv, 0);
9393 if (!ret) {
9394 free_firmware();
9395 ipw_adapter_restart(priv);
9396 }
James Ketrenosb095c382005-08-24 22:04:42 -05009397
9398 /* The SW reset bit might have been toggled on by the 'disable'
9399 * module parameter, so take appropriate action */
9400 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9401
Zhu Yi46441512006-01-24 16:37:59 +08009402 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009403 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009404 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009405
9406 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9407 /* Configuration likely changed -- force [re]association */
9408 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9409 "reset.\n");
9410 if (!ipw_disassociate(priv))
9411 ipw_associate(priv);
9412 }
9413
Zhu Yi46441512006-01-24 16:37:59 +08009414 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009415
9416 return 0;
9417}
James Ketrenos43f66a62005-03-25 12:31:53 -06009418
9419/* Rebase the WE IOCTLs to zero for the handler array */
9420#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009421static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009422 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9423 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9424 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9425 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9426 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
9427 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9428 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9429 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9430 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9431 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9432 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9433 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9434 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9435 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9436 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9437 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9438 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9439 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9440 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9441 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9442 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9443 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9444 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9445 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9446 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9447 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9448 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9449 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -05009450 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9451 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9452 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9453 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -05009454 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9455 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9456 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9457 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9458 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9459 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9460 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
James Ketrenos43f66a62005-03-25 12:31:53 -06009461};
9462
James Ketrenosb095c382005-08-24 22:04:42 -05009463enum {
9464 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9465 IPW_PRIV_GET_POWER,
9466 IPW_PRIV_SET_MODE,
9467 IPW_PRIV_GET_MODE,
9468 IPW_PRIV_SET_PREAMBLE,
9469 IPW_PRIV_GET_PREAMBLE,
9470 IPW_PRIV_RESET,
9471 IPW_PRIV_SW_RESET,
9472#ifdef CONFIG_IPW2200_MONITOR
9473 IPW_PRIV_SET_MONITOR,
9474#endif
9475};
James Ketrenos43f66a62005-03-25 12:31:53 -06009476
Jeff Garzikbf794512005-07-31 13:07:26 -04009477static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06009478 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009479 .cmd = IPW_PRIV_SET_POWER,
9480 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9481 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009482 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009483 .cmd = IPW_PRIV_GET_POWER,
9484 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9485 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009486 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009487 .cmd = IPW_PRIV_SET_MODE,
9488 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9489 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009490 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009491 .cmd = IPW_PRIV_GET_MODE,
9492 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9493 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009494 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009495 .cmd = IPW_PRIV_SET_PREAMBLE,
9496 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9497 .name = "set_preamble"},
9498 {
9499 .cmd = IPW_PRIV_GET_PREAMBLE,
9500 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9501 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009502 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009503 IPW_PRIV_RESET,
9504 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -05009505 {
9506 IPW_PRIV_SW_RESET,
9507 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9508#ifdef CONFIG_IPW2200_MONITOR
9509 {
9510 IPW_PRIV_SET_MONITOR,
9511 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9512#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06009513};
9514
9515static iw_handler ipw_priv_handler[] = {
9516 ipw_wx_set_powermode,
9517 ipw_wx_get_powermode,
9518 ipw_wx_set_wireless_mode,
9519 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009520 ipw_wx_set_preamble,
9521 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -04009522 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -05009523 ipw_wx_sw_reset,
9524#ifdef CONFIG_IPW2200_MONITOR
9525 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -06009526#endif
9527};
9528
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009529static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009530 .standard = ipw_wx_handlers,
9531 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9532 .num_private = ARRAY_SIZE(ipw_priv_handler),
9533 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9534 .private = ipw_priv_handler,
9535 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009536 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06009537};
9538
James Ketrenos43f66a62005-03-25 12:31:53 -06009539/*
9540 * Get wireless statistics.
9541 * Called by /proc/net/wireless
9542 * Also called by SIOCGIWSTATS
9543 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009544static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06009545{
9546 struct ipw_priv *priv = ieee80211_priv(dev);
9547 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009548
James Ketrenos43f66a62005-03-25 12:31:53 -06009549 wstats = &priv->wstats;
9550
James Ketrenosea2b26e2005-08-24 21:25:16 -05009551 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -05009552 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06009553 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9554 * and associated; if not associcated, the values are all meaningless
9555 * anyway, so set them all to NULL and INVALID */
9556 if (!(priv->status & STATUS_ASSOCIATED)) {
9557 wstats->miss.beacon = 0;
9558 wstats->discard.retries = 0;
9559 wstats->qual.qual = 0;
9560 wstats->qual.level = 0;
9561 wstats->qual.noise = 0;
9562 wstats->qual.updated = 7;
9563 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009564 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06009565 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009566 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009567
9568 wstats->qual.qual = priv->quality;
9569 wstats->qual.level = average_value(&priv->average_rssi);
9570 wstats->qual.noise = average_value(&priv->average_noise);
9571 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +08009572 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009573
9574 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9575 wstats->discard.retries = priv->last_tx_failures;
9576 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04009577
James Ketrenos43f66a62005-03-25 12:31:53 -06009578/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9579 goto fail_get_ordinal;
9580 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04009581
James Ketrenos43f66a62005-03-25 12:31:53 -06009582 return wstats;
9583}
9584
James Ketrenos43f66a62005-03-25 12:31:53 -06009585/* net device stuff */
9586
Arjan van de Ven858119e2006-01-14 13:20:43 -08009587static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -06009588{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009589 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +08009590 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009591 sys_config->answer_broadcast_ssid_probe = 0;
9592 sys_config->accept_all_data_frames = 0;
9593 sys_config->accept_non_directed_frames = 1;
9594 sys_config->exclude_unicast_unencrypted = 0;
9595 sys_config->disable_unicast_decryption = 1;
9596 sys_config->exclude_multicast_unencrypted = 0;
9597 sys_config->disable_multicast_decryption = 1;
9598 sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009599 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -06009600 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009601 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009602 sys_config->bt_coexist_collision_thr = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009603 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
James Ketrenos43f66a62005-03-25 12:31:53 -06009604}
9605
9606static int ipw_net_open(struct net_device *dev)
9607{
9608 struct ipw_priv *priv = ieee80211_priv(dev);
9609 IPW_DEBUG_INFO("dev->open\n");
9610 /* we should be verifying the device is ready to be opened */
Zhu Yi46441512006-01-24 16:37:59 +08009611 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009612 if (!(priv->status & STATUS_RF_KILL_MASK) &&
9613 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009614 netif_start_queue(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009615 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009616 return 0;
9617}
9618
9619static int ipw_net_stop(struct net_device *dev)
9620{
9621 IPW_DEBUG_INFO("dev->close\n");
9622 netif_stop_queue(dev);
9623 return 0;
9624}
9625
9626/*
9627todo:
9628
9629modify to send one tfd per fragment instead of using chunking. otherwise
9630we need to heavily modify the ieee80211_skb_to_txb.
9631*/
9632
Arjan van de Ven858119e2006-01-14 13:20:43 -08009633static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -05009634 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009635{
James Ketrenos0dacca12005-09-21 12:23:41 -05009636 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009637 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -06009638 int i = 0;
9639 struct tfd_frame *tfd;
James Ketrenosb095c382005-08-24 22:04:42 -05009640#ifdef CONFIG_IPW_QOS
9641 int tx_id = ipw_get_tx_queue_number(priv, pri);
9642 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9643#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009644 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -05009645#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009646 struct clx2_queue *q = &txq->q;
9647 u8 id, hdr_len, unicast;
9648 u16 remaining_bytes;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009649 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -06009650
9651 switch (priv->ieee->iw_mode) {
9652 case IW_MODE_ADHOC:
9653 hdr_len = IEEE80211_3ADDR_LEN;
Stephen Hemminger3c190652006-01-03 15:27:38 -08009654 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -06009655 id = ipw_find_station(priv, hdr->addr1);
9656 if (id == IPW_INVALID_STATION) {
9657 id = ipw_add_station(priv, hdr->addr1);
9658 if (id == IPW_INVALID_STATION) {
9659 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -04009660 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009661 MAC_ARG(hdr->addr1));
9662 goto drop;
9663 }
9664 }
9665 break;
9666
9667 case IW_MODE_INFRA:
9668 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -08009669 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -06009670 hdr_len = IEEE80211_3ADDR_LEN;
9671 id = 0;
9672 break;
9673 }
9674
9675 tfd = &txq->bd[q->first_empty];
9676 txq->txb[q->first_empty] = txb;
9677 memset(tfd, 0, sizeof(*tfd));
9678 tfd->u.data.station_number = id;
9679
9680 tfd->control_flags.message_type = TX_FRAME_TYPE;
9681 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
9682
9683 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -05009684 tfd->u.data.len = cpu_to_le16(txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009685 remaining_bytes = txb->payload_size;
Jeff Garzikbf794512005-07-31 13:07:26 -04009686
James Ketrenos43f66a62005-03-25 12:31:53 -06009687 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -05009688 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009689 else
James Ketrenosb095c382005-08-24 22:04:42 -05009690 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009691
James Ketrenosea2b26e2005-08-24 21:25:16 -05009692 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
9693 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009694
James Ketrenosc848d0a2005-08-24 21:56:24 -05009695 fc = le16_to_cpu(hdr->frame_ctl);
9696 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -06009697
9698 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
9699
James Ketrenosb095c382005-08-24 22:04:42 -05009700 if (likely(unicast))
9701 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9702
9703 if (txb->encrypted && !priv->ieee->host_encrypt) {
9704 switch (priv->ieee->sec.level) {
9705 case SEC_LEVEL_3:
9706 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9707 IEEE80211_FCTL_PROTECTED;
9708 /* XXX: ACK flag must be set for CCMP even if it
9709 * is a multicast/broadcast packet, because CCMP
9710 * group communication encrypted by GTK is
9711 * actually done by the AP. */
9712 if (!unicast)
9713 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9714
9715 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9716 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
9717 tfd->u.data.key_index = 0;
9718 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
9719 break;
9720 case SEC_LEVEL_2:
9721 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9722 IEEE80211_FCTL_PROTECTED;
9723 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9724 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
9725 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
9726 break;
9727 case SEC_LEVEL_1:
9728 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9729 IEEE80211_FCTL_PROTECTED;
9730 tfd->u.data.key_index = priv->ieee->tx_keyidx;
9731 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
9732 40)
9733 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
9734 else
9735 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
9736 break;
9737 case SEC_LEVEL_0:
9738 break;
9739 default:
9740 printk(KERN_ERR "Unknow security level %d\n",
9741 priv->ieee->sec.level);
9742 break;
9743 }
9744 } else
9745 /* No hardware encryption */
9746 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
9747
9748#ifdef CONFIG_IPW_QOS
9749 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast);
9750#endif /* CONFIG_IPW_QOS */
9751
James Ketrenos43f66a62005-03-25 12:31:53 -06009752 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -05009753 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
9754 txb->nr_frags));
9755 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
9756 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
9757 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
9758 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
9759 i, le32_to_cpu(tfd->u.data.num_chunks),
9760 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009761 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009762 i, tfd->u.data.num_chunks,
9763 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009764 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -06009765 txb->fragments[i]->len - hdr_len);
9766
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009767 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009768 cpu_to_le32(pci_map_single
9769 (priv->pci_dev,
9770 txb->fragments[i]->data + hdr_len,
9771 txb->fragments[i]->len - hdr_len,
9772 PCI_DMA_TODEVICE));
9773 tfd->u.data.chunk_len[i] =
9774 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009775 }
9776
9777 if (i != txb->nr_frags) {
9778 struct sk_buff *skb;
9779 u16 remaining_bytes = 0;
9780 int j;
9781
9782 for (j = i; j < txb->nr_frags; j++)
9783 remaining_bytes += txb->fragments[j]->len - hdr_len;
9784
9785 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
9786 remaining_bytes);
9787 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
9788 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -05009789 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -06009790 for (j = i; j < txb->nr_frags; j++) {
9791 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009792
James Ketrenos43f66a62005-03-25 12:31:53 -06009793 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009794 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009795 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009796 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009797 }
9798 dev_kfree_skb_any(txb->fragments[i]);
9799 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009800 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009801 cpu_to_le32(pci_map_single
9802 (priv->pci_dev, skb->data,
9803 tfd->u.data.chunk_len[i],
9804 PCI_DMA_TODEVICE));
9805
9806 tfd->u.data.num_chunks =
9807 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
9808 1);
Jeff Garzikbf794512005-07-31 13:07:26 -04009809 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009810 }
9811
9812 /* kick DMA */
9813 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
9814 ipw_write32(priv, q->reg_w, q->first_empty);
9815
James Ketrenosf6970142006-02-14 09:10:51 +08009816 if (ipw_queue_space(q) < q->high_mark)
9817 netif_stop_queue(priv->net_dev);
9818
James Ketrenos227d2dc2005-07-28 16:25:55 -05009819 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009820
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009821 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -06009822 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
9823 ieee80211_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -05009824 return NETDEV_TX_OK;
9825}
9826
9827static int ipw_net_is_queue_full(struct net_device *dev, int pri)
9828{
9829 struct ipw_priv *priv = ieee80211_priv(dev);
9830#ifdef CONFIG_IPW_QOS
9831 int tx_id = ipw_get_tx_queue_number(priv, pri);
9832 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9833#else
9834 struct clx2_tx_queue *txq = &priv->txq[0];
9835#endif /* CONFIG_IPW_QOS */
9836
9837 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
9838 return 1;
9839
9840 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009841}
9842
9843static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -05009844 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009845{
9846 struct ipw_priv *priv = ieee80211_priv(dev);
9847 unsigned long flags;
James Ketrenos227d2dc2005-07-28 16:25:55 -05009848 int ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009849
9850 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009851 spin_lock_irqsave(&priv->lock, flags);
9852
9853 if (!(priv->status & STATUS_ASSOCIATED)) {
9854 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
9855 priv->ieee->stats.tx_carrier_errors++;
9856 netif_stop_queue(dev);
9857 goto fail_unlock;
9858 }
9859
James Ketrenos227d2dc2005-07-28 16:25:55 -05009860 ret = ipw_tx_skb(priv, txb, pri);
9861 if (ret == NETDEV_TX_OK)
9862 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009863 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06009864
James Ketrenos227d2dc2005-07-28 16:25:55 -05009865 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009866
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009867 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -06009868 spin_unlock_irqrestore(&priv->lock, flags);
9869 return 1;
9870}
9871
9872static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
9873{
9874 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -04009875
James Ketrenos43f66a62005-03-25 12:31:53 -06009876 priv->ieee->stats.tx_packets = priv->tx_packets;
9877 priv->ieee->stats.rx_packets = priv->rx_packets;
9878 return &priv->ieee->stats;
9879}
9880
9881static void ipw_net_set_multicast_list(struct net_device *dev)
9882{
9883
9884}
9885
9886static int ipw_net_set_mac_address(struct net_device *dev, void *p)
9887{
9888 struct ipw_priv *priv = ieee80211_priv(dev);
9889 struct sockaddr *addr = p;
9890 if (!is_valid_ether_addr(addr->sa_data))
9891 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +08009892 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009893 priv->config |= CFG_CUSTOM_MAC;
9894 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
9895 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
9896 priv->net_dev->name, MAC_ARG(priv->mac_addr));
James Ketrenosa613bff2005-08-24 21:43:11 -05009897 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08009898 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009899 return 0;
9900}
9901
Jeff Garzikbf794512005-07-31 13:07:26 -04009902static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -06009903 struct ethtool_drvinfo *info)
9904{
9905 struct ipw_priv *p = ieee80211_priv(dev);
9906 char vers[64];
9907 char date[32];
9908 u32 len;
9909
9910 strcpy(info->driver, DRV_NAME);
9911 strcpy(info->version, DRV_VERSION);
9912
9913 len = sizeof(vers);
9914 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
9915 len = sizeof(date);
9916 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
9917
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009918 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009919 vers, date);
9920 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -05009921 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009922}
9923
9924static u32 ipw_ethtool_get_link(struct net_device *dev)
9925{
9926 struct ipw_priv *priv = ieee80211_priv(dev);
9927 return (priv->status & STATUS_ASSOCIATED) != 0;
9928}
9929
9930static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
9931{
James Ketrenosb095c382005-08-24 22:04:42 -05009932 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009933}
9934
9935static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009936 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -06009937{
9938 struct ipw_priv *p = ieee80211_priv(dev);
9939
James Ketrenosb095c382005-08-24 22:04:42 -05009940 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -06009941 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08009942 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009943 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +08009944 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009945 return 0;
9946}
9947
9948static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009949 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -06009950{
9951 struct ipw_priv *p = ieee80211_priv(dev);
9952 int i;
9953
James Ketrenosb095c382005-08-24 22:04:42 -05009954 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -06009955 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08009956 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009957 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009958 for (i = IPW_EEPROM_DATA;
James Ketrenosb095c382005-08-24 22:04:42 -05009959 i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06009960 ipw_write8(p, i, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +08009961 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009962 return 0;
9963}
9964
9965static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009966 .get_link = ipw_ethtool_get_link,
9967 .get_drvinfo = ipw_ethtool_get_drvinfo,
9968 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
9969 .get_eeprom = ipw_ethtool_get_eeprom,
9970 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -06009971};
9972
9973static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
9974{
9975 struct ipw_priv *priv = data;
9976 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -04009977
James Ketrenos43f66a62005-03-25 12:31:53 -06009978 if (!priv)
9979 return IRQ_NONE;
9980
9981 spin_lock(&priv->lock);
9982
9983 if (!(priv->status & STATUS_INT_ENABLED)) {
9984 /* Shared IRQ */
9985 goto none;
9986 }
9987
James Ketrenosb095c382005-08-24 22:04:42 -05009988 inta = ipw_read32(priv, IPW_INTA_RW);
9989 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -04009990
James Ketrenos43f66a62005-03-25 12:31:53 -06009991 if (inta == 0xFFFFFFFF) {
9992 /* Hardware disappeared */
9993 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
9994 goto none;
9995 }
9996
James Ketrenosb095c382005-08-24 22:04:42 -05009997 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009998 /* Shared interrupt */
9999 goto none;
10000 }
10001
10002 /* tell the device to stop sending interrupts */
10003 ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010004
James Ketrenos43f66a62005-03-25 12:31:53 -060010005 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010006 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10007 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010008
James Ketrenos43f66a62005-03-25 12:31:53 -060010009 /* Cache INTA value for our tasklet */
10010 priv->isr_inta = inta;
10011
10012 tasklet_schedule(&priv->irq_tasklet);
10013
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010014 spin_unlock(&priv->lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010015
10016 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010017 none:
James Ketrenos43f66a62005-03-25 12:31:53 -060010018 spin_unlock(&priv->lock);
10019 return IRQ_NONE;
10020}
10021
10022static void ipw_rf_kill(void *adapter)
10023{
10024 struct ipw_priv *priv = adapter;
10025 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010026
James Ketrenos43f66a62005-03-25 12:31:53 -060010027 spin_lock_irqsave(&priv->lock, flags);
10028
10029 if (rf_kill_active(priv)) {
10030 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10031 if (priv->workqueue)
10032 queue_delayed_work(priv->workqueue,
10033 &priv->rf_kill, 2 * HZ);
10034 goto exit_unlock;
10035 }
10036
10037 /* RF Kill is now disabled, so bring the device back up */
10038
10039 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10040 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10041 "device\n");
10042
10043 /* we can not do an adapter restart while inside an irq lock */
10044 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010045 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010046 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10047 "enabled\n");
10048
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010049 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010050 spin_unlock_irqrestore(&priv->lock, flags);
10051}
10052
James Ketrenosc848d0a2005-08-24 21:56:24 -050010053static void ipw_bg_rf_kill(void *data)
10054{
10055 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010056 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010057 ipw_rf_kill(data);
Zhu Yi46441512006-01-24 16:37:59 +080010058 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010059}
10060
Adrian Bunka73e22b2006-01-21 01:39:42 +010010061static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010062{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010063 priv->last_seq_num = -1;
10064 priv->last_frag_num = -1;
10065 priv->last_packet_time = 0;
10066
James Ketrenosa613bff2005-08-24 21:43:11 -050010067 netif_carrier_on(priv->net_dev);
10068 if (netif_queue_stopped(priv->net_dev)) {
10069 IPW_DEBUG_NOTIF("waking queue\n");
10070 netif_wake_queue(priv->net_dev);
10071 } else {
10072 IPW_DEBUG_NOTIF("starting queue\n");
10073 netif_start_queue(priv->net_dev);
10074 }
10075
James Ketrenosc848d0a2005-08-24 21:56:24 -050010076 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010077 ipw_reset_stats(priv);
10078 /* Ensure the rate is updated immediately */
10079 priv->last_rate = ipw_get_current_rate(priv);
10080 ipw_gather_stats(priv);
10081 ipw_led_link_up(priv);
10082 notify_wx_assoc_event(priv);
10083
10084 if (priv->config & CFG_BACKGROUND_SCAN)
10085 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10086}
10087
James Ketrenosc848d0a2005-08-24 21:56:24 -050010088static void ipw_bg_link_up(void *data)
10089{
10090 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010091 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010092 ipw_link_up(data);
Zhu Yi46441512006-01-24 16:37:59 +080010093 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010094}
10095
Adrian Bunka73e22b2006-01-21 01:39:42 +010010096static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010097{
10098 ipw_led_link_down(priv);
10099 netif_carrier_off(priv->net_dev);
10100 netif_stop_queue(priv->net_dev);
10101 notify_wx_assoc_event(priv);
10102
10103 /* Cancel any queued work ... */
10104 cancel_delayed_work(&priv->request_scan);
10105 cancel_delayed_work(&priv->adhoc_check);
10106 cancel_delayed_work(&priv->gather_stats);
10107
10108 ipw_reset_stats(priv);
10109
James Ketrenosafbf30a2005-08-25 00:05:33 -050010110 if (!(priv->status & STATUS_EXIT_PENDING)) {
10111 /* Queue up another scan... */
10112 queue_work(priv->workqueue, &priv->request_scan);
10113 }
James Ketrenosa613bff2005-08-24 21:43:11 -050010114}
10115
James Ketrenosc848d0a2005-08-24 21:56:24 -050010116static void ipw_bg_link_down(void *data)
10117{
10118 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010119 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010120 ipw_link_down(data);
Zhu Yi46441512006-01-24 16:37:59 +080010121 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010122}
10123
James Ketrenos43f66a62005-03-25 12:31:53 -060010124static int ipw_setup_deferred_work(struct ipw_priv *priv)
10125{
10126 int ret = 0;
10127
James Ketrenos43f66a62005-03-25 12:31:53 -060010128 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010129 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010130 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010131
James Ketrenosc848d0a2005-08-24 21:56:24 -050010132 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10133 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10134 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
Zhu Yid8bad6d2005-07-13 12:25:38 -050010135 INIT_WORK(&priv->system_config, ipw_system_config, priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010136 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10137 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10138 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10139 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10140 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010141 INIT_WORK(&priv->request_scan,
James Ketrenos43f66a62005-03-25 12:31:53 -060010142 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010143 INIT_WORK(&priv->gather_stats,
James Ketrenosc848d0a2005-08-24 21:56:24 -050010144 (void (*)(void *))ipw_bg_gather_stats, priv);
10145 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10146 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10147 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10148 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10149 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10150 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
James Ketrenosa613bff2005-08-24 21:43:11 -050010151 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010152 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
James Ketrenosa613bff2005-08-24 21:43:11 -050010153 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010154 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10155 priv);
10156 INIT_WORK(&priv->merge_networks,
10157 (void (*)(void *))ipw_merge_adhoc_network, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010158
James Ketrenosb095c382005-08-24 22:04:42 -050010159#ifdef CONFIG_IPW_QOS
10160 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10161 priv);
10162#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010163
10164 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10165 ipw_irq_tasklet, (unsigned long)priv);
10166
10167 return ret;
10168}
10169
James Ketrenos43f66a62005-03-25 12:31:53 -060010170static void shim__set_security(struct net_device *dev,
10171 struct ieee80211_security *sec)
10172{
10173 struct ipw_priv *priv = ieee80211_priv(dev);
10174 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010175 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010176 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010177 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010178 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010179 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010180 priv->ieee->sec.flags &= ~(1 << i);
10181 else {
10182 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010183 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010184 priv->ieee->sec.flags |= (1 << i);
10185 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010186 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010187 } else if (sec->level != SEC_LEVEL_1)
10188 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010189 }
10190
James Ketrenosb095c382005-08-24 22:04:42 -050010191 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010192 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010193 priv->ieee->sec.active_key = sec->active_key;
10194 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010195 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010196 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010197 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010198 } else
10199 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010200
10201 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010202 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10203 priv->ieee->sec.auth_mode = sec->auth_mode;
10204 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010205 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10206 priv->capability |= CAP_SHARED_KEY;
10207 else
10208 priv->capability &= ~CAP_SHARED_KEY;
10209 priv->status |= STATUS_SECURITY_UPDATED;
10210 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010211
James Ketrenosb095c382005-08-24 22:04:42 -050010212 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10213 priv->ieee->sec.flags |= SEC_ENABLED;
10214 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010215 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010216 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010217 priv->capability |= CAP_PRIVACY_ON;
10218 else
10219 priv->capability &= ~CAP_PRIVACY_ON;
10220 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010221
James Ketrenosafbf30a2005-08-25 00:05:33 -050010222 if (sec->flags & SEC_ENCRYPT)
10223 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010224
James Ketrenosb095c382005-08-24 22:04:42 -050010225 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10226 priv->ieee->sec.level = sec->level;
10227 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010228 priv->status |= STATUS_SECURITY_UPDATED;
10229 }
10230
Zhu Yi1fbfea52005-08-05 17:22:56 +080010231 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10232 ipw_set_hwcrypto_keys(priv);
10233
Jeff Garzikbf794512005-07-31 13:07:26 -040010234 /* To match current functionality of ipw2100 (which works well w/
10235 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010236 * privacy capability changes ... */
10237#if 0
10238 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010239 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -060010240 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010241 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010242 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010243 IPW_DEBUG_ASSOC("Disassociating due to capability "
10244 "change.\n");
10245 ipw_disassociate(priv);
10246 }
10247#endif
10248}
10249
Jeff Garzikbf794512005-07-31 13:07:26 -040010250static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010251 struct ipw_supported_rates *rates)
10252{
10253 /* TODO: Mask out rates based on priv->rates_mask */
10254
10255 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010256 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010257 switch (priv->ieee->freq_band) {
10258 case IEEE80211_52GHZ_BAND:
10259 rates->ieee_mode = IPW_A_MODE;
10260 rates->purpose = IPW_RATE_CAPABILITIES;
10261 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10262 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10263 break;
10264
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010265 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010266 rates->ieee_mode = IPW_G_MODE;
10267 rates->purpose = IPW_RATE_CAPABILITIES;
10268 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10269 IEEE80211_CCK_DEFAULT_RATES_MASK);
10270 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10271 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10272 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10273 }
10274 break;
10275 }
10276
10277 return 0;
10278}
10279
Jeff Garzikbf794512005-07-31 13:07:26 -040010280static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010281{
James Ketrenos43f66a62005-03-25 12:31:53 -060010282 /* This is only called from ipw_up, which resets/reloads the firmware
10283 so, we don't need to first disable the card before we configure
10284 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010285 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010286 goto error;
10287
10288 /* initialize adapter address */
10289 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10290 goto error;
10291
10292 /* set basic system config settings */
10293 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010294
10295 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10296 * Does not support BT priority yet (don't abort or defer our Tx) */
10297 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010298 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010299
10300 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10301 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010302 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010303 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10304 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010305 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010306 }
10307
James Ketrenosc848d0a2005-08-24 21:56:24 -050010308 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10309 priv->sys_config.answer_broadcast_ssid_probe = 1;
10310 else
10311 priv->sys_config.answer_broadcast_ssid_probe = 0;
10312
James Ketrenos43f66a62005-03-25 12:31:53 -060010313 if (ipw_send_system_config(priv, &priv->sys_config))
10314 goto error;
10315
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010316 init_supported_rates(priv, &priv->rates);
10317 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010318 goto error;
10319
10320 /* Set request-to-send threshold */
10321 if (priv->rts_threshold) {
10322 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10323 goto error;
10324 }
James Ketrenosb095c382005-08-24 22:04:42 -050010325#ifdef CONFIG_IPW_QOS
10326 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10327 ipw_qos_activate(priv, NULL);
10328#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010329
10330 if (ipw_set_random_seed(priv))
10331 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010332
James Ketrenos43f66a62005-03-25 12:31:53 -060010333 /* final state transition to the RUN state */
10334 if (ipw_send_host_complete(priv))
10335 goto error;
10336
James Ketrenose6666192005-08-12 09:17:04 -050010337 priv->status |= STATUS_INIT;
10338
10339 ipw_led_init(priv);
10340 ipw_led_radio_on(priv);
10341 priv->notif_missed_beacons = 0;
10342
10343 /* Set hardware WEP key if it is configured. */
10344 if ((priv->capability & CAP_PRIVACY_ON) &&
10345 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10346 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10347 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010348
10349 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010350
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010351 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010352 return -EIO;
10353}
10354
James Ketrenos4f36f802005-08-03 20:36:56 -050010355/*
10356 * NOTE:
10357 *
10358 * These tables have been tested in conjunction with the
10359 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10360 *
10361 * Altering this values, using it on other hardware, or in geographies
10362 * not intended for resale of the above mentioned Intel adapters has
10363 * not been tested.
10364 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080010365 * Remember to update the table in README.ipw2200 when changing this
10366 * table.
10367 *
James Ketrenos4f36f802005-08-03 20:36:56 -050010368 */
10369static const struct ieee80211_geo ipw_geos[] = {
10370 { /* Restricted */
10371 "---",
10372 .bg_channels = 11,
10373 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10374 {2427, 4}, {2432, 5}, {2437, 6},
10375 {2442, 7}, {2447, 8}, {2452, 9},
10376 {2457, 10}, {2462, 11}},
10377 },
10378
10379 { /* Custom US/Canada */
10380 "ZZF",
10381 .bg_channels = 11,
10382 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10383 {2427, 4}, {2432, 5}, {2437, 6},
10384 {2442, 7}, {2447, 8}, {2452, 9},
10385 {2457, 10}, {2462, 11}},
10386 .a_channels = 8,
10387 .a = {{5180, 36},
10388 {5200, 40},
10389 {5220, 44},
10390 {5240, 48},
10391 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10392 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10393 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10394 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10395 },
10396
10397 { /* Rest of World */
10398 "ZZD",
10399 .bg_channels = 13,
10400 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10401 {2427, 4}, {2432, 5}, {2437, 6},
10402 {2442, 7}, {2447, 8}, {2452, 9},
10403 {2457, 10}, {2462, 11}, {2467, 12},
10404 {2472, 13}},
10405 },
10406
10407 { /* Custom USA & Europe & High */
10408 "ZZA",
10409 .bg_channels = 11,
10410 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10411 {2427, 4}, {2432, 5}, {2437, 6},
10412 {2442, 7}, {2447, 8}, {2452, 9},
10413 {2457, 10}, {2462, 11}},
10414 .a_channels = 13,
10415 .a = {{5180, 36},
10416 {5200, 40},
10417 {5220, 44},
10418 {5240, 48},
10419 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10420 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10421 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10422 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10423 {5745, 149},
10424 {5765, 153},
10425 {5785, 157},
10426 {5805, 161},
10427 {5825, 165}},
10428 },
10429
10430 { /* Custom NA & Europe */
10431 "ZZB",
10432 .bg_channels = 11,
10433 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10434 {2427, 4}, {2432, 5}, {2437, 6},
10435 {2442, 7}, {2447, 8}, {2452, 9},
10436 {2457, 10}, {2462, 11}},
10437 .a_channels = 13,
10438 .a = {{5180, 36},
10439 {5200, 40},
10440 {5220, 44},
10441 {5240, 48},
10442 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10443 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10444 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10445 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10446 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10447 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10448 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10449 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10450 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10451 },
10452
10453 { /* Custom Japan */
10454 "ZZC",
10455 .bg_channels = 11,
10456 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10457 {2427, 4}, {2432, 5}, {2437, 6},
10458 {2442, 7}, {2447, 8}, {2452, 9},
10459 {2457, 10}, {2462, 11}},
10460 .a_channels = 4,
10461 .a = {{5170, 34}, {5190, 38},
10462 {5210, 42}, {5230, 46}},
10463 },
10464
10465 { /* Custom */
10466 "ZZM",
10467 .bg_channels = 11,
10468 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10469 {2427, 4}, {2432, 5}, {2437, 6},
10470 {2442, 7}, {2447, 8}, {2452, 9},
10471 {2457, 10}, {2462, 11}},
10472 },
10473
10474 { /* Europe */
10475 "ZZE",
10476 .bg_channels = 13,
10477 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10478 {2427, 4}, {2432, 5}, {2437, 6},
10479 {2442, 7}, {2447, 8}, {2452, 9},
10480 {2457, 10}, {2462, 11}, {2467, 12},
10481 {2472, 13}},
10482 .a_channels = 19,
10483 .a = {{5180, 36},
10484 {5200, 40},
10485 {5220, 44},
10486 {5240, 48},
10487 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10488 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10489 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10490 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10491 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10492 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10493 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10494 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10495 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10496 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10497 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10498 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10499 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10500 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10501 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10502 },
10503
10504 { /* Custom Japan */
10505 "ZZJ",
10506 .bg_channels = 14,
10507 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10508 {2427, 4}, {2432, 5}, {2437, 6},
10509 {2442, 7}, {2447, 8}, {2452, 9},
10510 {2457, 10}, {2462, 11}, {2467, 12},
10511 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10512 .a_channels = 4,
10513 .a = {{5170, 34}, {5190, 38},
10514 {5210, 42}, {5230, 46}},
10515 },
10516
James Ketrenos03520572005-10-19 16:12:31 -050010517 { /* Rest of World */
10518 "ZZR",
10519 .bg_channels = 14,
10520 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10521 {2427, 4}, {2432, 5}, {2437, 6},
10522 {2442, 7}, {2447, 8}, {2452, 9},
10523 {2457, 10}, {2462, 11}, {2467, 12},
10524 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
10525 IEEE80211_CH_PASSIVE_ONLY}},
10526 },
10527
James Ketrenos4f36f802005-08-03 20:36:56 -050010528 { /* High Band */
10529 "ZZH",
10530 .bg_channels = 13,
10531 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10532 {2427, 4}, {2432, 5}, {2437, 6},
10533 {2442, 7}, {2447, 8}, {2452, 9},
10534 {2457, 10}, {2462, 11},
10535 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10536 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10537 .a_channels = 4,
10538 .a = {{5745, 149}, {5765, 153},
10539 {5785, 157}, {5805, 161}},
10540 },
10541
10542 { /* Custom Europe */
10543 "ZZG",
10544 .bg_channels = 13,
10545 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10546 {2427, 4}, {2432, 5}, {2437, 6},
10547 {2442, 7}, {2447, 8}, {2452, 9},
10548 {2457, 10}, {2462, 11},
10549 {2467, 12}, {2472, 13}},
10550 .a_channels = 4,
10551 .a = {{5180, 36}, {5200, 40},
10552 {5220, 44}, {5240, 48}},
10553 },
10554
10555 { /* Europe */
10556 "ZZK",
10557 .bg_channels = 13,
10558 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10559 {2427, 4}, {2432, 5}, {2437, 6},
10560 {2442, 7}, {2447, 8}, {2452, 9},
10561 {2457, 10}, {2462, 11},
10562 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10563 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10564 .a_channels = 24,
10565 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10566 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10567 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10568 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10569 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10570 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10571 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10572 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10573 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10574 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10575 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10576 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10577 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10578 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10579 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10580 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10581 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10582 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10583 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
10584 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10585 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10586 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10587 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10588 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10589 },
10590
10591 { /* Europe */
10592 "ZZL",
10593 .bg_channels = 11,
10594 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10595 {2427, 4}, {2432, 5}, {2437, 6},
10596 {2442, 7}, {2447, 8}, {2452, 9},
10597 {2457, 10}, {2462, 11}},
10598 .a_channels = 13,
10599 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10600 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10601 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10602 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10603 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10604 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10605 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10606 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10607 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10608 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10609 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10610 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10611 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10612 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050010613};
10614
James Ketrenos43f66a62005-03-25 12:31:53 -060010615#define MAX_HW_RESTARTS 5
10616static int ipw_up(struct ipw_priv *priv)
10617{
James Ketrenos4f36f802005-08-03 20:36:56 -050010618 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060010619
10620 if (priv->status & STATUS_EXIT_PENDING)
10621 return -EIO;
10622
James Ketrenosf6c5cb72005-08-25 00:39:09 -050010623 if (cmdlog && !priv->cmdlog) {
10624 priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
10625 GFP_KERNEL);
10626 if (priv->cmdlog == NULL) {
10627 IPW_ERROR("Error allocating %d command log entries.\n",
10628 cmdlog);
10629 } else {
10630 memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
10631 priv->cmdlog_len = cmdlog;
10632 }
10633 }
10634
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010635 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040010636 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060010637 * Also start the clocks. */
10638 rc = ipw_load(priv);
10639 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050010640 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010641 return rc;
10642 }
10643
10644 ipw_init_ordinals(priv);
10645 if (!(priv->config & CFG_CUSTOM_MAC))
10646 eeprom_parse_mac(priv, priv->mac_addr);
10647 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
10648
James Ketrenos4f36f802005-08-03 20:36:56 -050010649 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
10650 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
10651 ipw_geos[j].name, 3))
10652 break;
10653 }
James Ketrenos03520572005-10-19 16:12:31 -050010654 if (j == ARRAY_SIZE(ipw_geos)) {
10655 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
10656 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
10657 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
10658 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050010659 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050010660 }
Larry Finger1867b112006-02-28 09:48:28 -060010661 if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050010662 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060010663 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050010664 }
10665
James Ketrenosb095c382005-08-24 22:04:42 -050010666 if (priv->status & STATUS_RF_KILL_SW) {
10667 IPW_WARNING("Radio disabled by module parameter.\n");
10668 return 0;
10669 } else if (rf_kill_active(priv)) {
10670 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
10671 "Kill switch must be turned off for "
10672 "wireless networking to work.\n");
10673 queue_delayed_work(priv->workqueue, &priv->rf_kill,
10674 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060010675 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010676 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010677
10678 rc = ipw_config(priv);
10679 if (!rc) {
10680 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010681
James Ketrenose6666192005-08-12 09:17:04 -050010682 /* If configure to try and auto-associate, kick
10683 * off a scan. */
10684 queue_work(priv->workqueue, &priv->request_scan);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010685
James Ketrenos43f66a62005-03-25 12:31:53 -060010686 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010687 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010688
James Ketrenosc848d0a2005-08-24 21:56:24 -050010689 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010690 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
10691 i, MAX_HW_RESTARTS);
10692
10693 /* We had an error bringing up the hardware, so take it
10694 * all the way back down so we can try again */
10695 ipw_down(priv);
10696 }
10697
Jeff Garzikbf794512005-07-31 13:07:26 -040010698 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060010699 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010700 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010701
James Ketrenos43f66a62005-03-25 12:31:53 -060010702 return -EIO;
10703}
10704
James Ketrenosc848d0a2005-08-24 21:56:24 -050010705static void ipw_bg_up(void *data)
10706{
10707 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010708 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010709 ipw_up(data);
Zhu Yi46441512006-01-24 16:37:59 +080010710 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010711}
10712
James Ketrenosb095c382005-08-24 22:04:42 -050010713static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010714{
James Ketrenosb095c382005-08-24 22:04:42 -050010715 int i;
10716
10717 if (priv->status & STATUS_SCANNING) {
10718 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
10719 ipw_abort_scan(priv);
10720 }
10721
10722 if (priv->status & STATUS_ASSOCIATED) {
10723 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
10724 ipw_disassociate(priv);
10725 }
10726
10727 ipw_led_shutdown(priv);
10728
10729 /* Wait up to 1s for status to change to not scanning and not
10730 * associated (disassociation can take a while for a ful 802.11
10731 * exchange */
10732 for (i = 1000; i && (priv->status &
10733 (STATUS_DISASSOCIATING |
10734 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
10735 udelay(10);
10736
10737 if (priv->status & (STATUS_DISASSOCIATING |
10738 STATUS_ASSOCIATED | STATUS_SCANNING))
10739 IPW_DEBUG_INFO("Still associated or scanning...\n");
10740 else
10741 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
10742
James Ketrenosc848d0a2005-08-24 21:56:24 -050010743 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060010744 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050010745
10746 priv->status &= ~STATUS_INIT;
10747}
10748
James Ketrenos43f66a62005-03-25 12:31:53 -060010749static void ipw_down(struct ipw_priv *priv)
10750{
James Ketrenosb095c382005-08-24 22:04:42 -050010751 int exit_pending = priv->status & STATUS_EXIT_PENDING;
10752
10753 priv->status |= STATUS_EXIT_PENDING;
10754
10755 if (ipw_is_init(priv))
10756 ipw_deinit(priv);
10757
10758 /* Wipe out the EXIT_PENDING status bit if we are not actually
10759 * exiting the module */
10760 if (!exit_pending)
10761 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010762
10763 /* tell the device to stop sending interrupts */
10764 ipw_disable_interrupts(priv);
10765
10766 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050010767 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010768 netif_carrier_off(priv->net_dev);
10769 netif_stop_queue(priv->net_dev);
10770
10771 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050010772
10773 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010774}
10775
James Ketrenosc848d0a2005-08-24 21:56:24 -050010776static void ipw_bg_down(void *data)
10777{
10778 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010779 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010780 ipw_down(data);
Zhu Yi46441512006-01-24 16:37:59 +080010781 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010782}
10783
10784/* Called by register_netdev() */
10785static int ipw_net_init(struct net_device *dev)
10786{
10787 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +080010788 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010789
James Ketrenosc848d0a2005-08-24 21:56:24 -050010790 if (ipw_up(priv)) {
Zhu Yi46441512006-01-24 16:37:59 +080010791 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010792 return -EIO;
James Ketrenos43f66a62005-03-25 12:31:53 -060010793 }
10794
Zhu Yi46441512006-01-24 16:37:59 +080010795 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010796 return 0;
10797}
10798
10799/* PCI driver stuff */
10800static struct pci_device_id card_ids[] = {
10801 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
10802 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
10803 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
10804 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
10805 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
10806 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
10807 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
10808 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
10809 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
10810 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
10811 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
10812 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
10813 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
10814 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
10815 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
10816 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
10817 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
10818 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010819 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
James Ketrenosa613bff2005-08-24 21:43:11 -050010820 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010821 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
10822 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040010823
James Ketrenos43f66a62005-03-25 12:31:53 -060010824 /* required last entry */
10825 {0,}
10826};
10827
10828MODULE_DEVICE_TABLE(pci, card_ids);
10829
10830static struct attribute *ipw_sysfs_entries[] = {
10831 &dev_attr_rf_kill.attr,
10832 &dev_attr_direct_dword.attr,
10833 &dev_attr_indirect_byte.attr,
10834 &dev_attr_indirect_dword.attr,
10835 &dev_attr_mem_gpio_reg.attr,
10836 &dev_attr_command_event_reg.attr,
10837 &dev_attr_nic_type.attr,
10838 &dev_attr_status.attr,
10839 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050010840 &dev_attr_error.attr,
10841 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050010842 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060010843 &dev_attr_eeprom_delay.attr,
10844 &dev_attr_ucode_version.attr,
10845 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050010846 &dev_attr_scan_age.attr,
10847 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050010848 &dev_attr_speed_scan.attr,
10849 &dev_attr_net_stats.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060010850 NULL
10851};
10852
10853static struct attribute_group ipw_attribute_group = {
10854 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010855 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060010856};
10857
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010858static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060010859{
10860 int err = 0;
10861 struct net_device *net_dev;
10862 void __iomem *base;
10863 u32 length, val;
10864 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010865 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060010866
10867 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
10868 if (net_dev == NULL) {
10869 err = -ENOMEM;
10870 goto out;
10871 }
10872
10873 priv = ieee80211_priv(net_dev);
10874 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010875
James Ketrenos43f66a62005-03-25 12:31:53 -060010876 priv->net_dev = net_dev;
10877 priv->pci_dev = pdev;
Brice Goglin0f52bf92005-12-01 01:41:46 -080010878#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060010879 ipw_debug_level = debug;
10880#endif
10881 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010882 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
10883 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060010884
Zhu Yi46441512006-01-24 16:37:59 +080010885 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010886 if (pci_enable_device(pdev)) {
10887 err = -ENODEV;
10888 goto out_free_ieee80211;
10889 }
10890
10891 pci_set_master(pdev);
10892
Tobias Klauser0e08b442005-06-20 14:28:41 -070010893 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -040010894 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -070010895 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010896 if (err) {
10897 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
10898 goto out_pci_disable_device;
10899 }
10900
10901 pci_set_drvdata(pdev, priv);
10902
10903 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040010904 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060010905 goto out_pci_disable_device;
10906
Jeff Garzikbf794512005-07-31 13:07:26 -040010907 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060010908 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040010909 pci_read_config_dword(pdev, 0x40, &val);
10910 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060010911 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040010912
James Ketrenos43f66a62005-03-25 12:31:53 -060010913 length = pci_resource_len(pdev, 0);
10914 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040010915
James Ketrenos43f66a62005-03-25 12:31:53 -060010916 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
10917 if (!base) {
10918 err = -ENODEV;
10919 goto out_pci_release_regions;
10920 }
10921
10922 priv->hw_base = base;
10923 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
10924 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
10925
10926 err = ipw_setup_deferred_work(priv);
10927 if (err) {
10928 IPW_ERROR("Unable to setup deferred work\n");
10929 goto out_iounmap;
10930 }
10931
James Ketrenosb095c382005-08-24 22:04:42 -050010932 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010933
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010934 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010935 if (err) {
10936 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
10937 goto out_destroy_workqueue;
10938 }
10939
10940 SET_MODULE_OWNER(net_dev);
10941 SET_NETDEV_DEV(net_dev, &pdev->dev);
10942
Zhu Yi46441512006-01-24 16:37:59 +080010943 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010944
James Ketrenos43f66a62005-03-25 12:31:53 -060010945 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
10946 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050010947 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060010948
James Ketrenosb095c382005-08-24 22:04:42 -050010949#ifdef CONFIG_IPW_QOS
James Ketrenos3b9990c2005-08-19 13:18:55 -050010950 priv->ieee->handle_probe_response = ipw_handle_beacon;
10951 priv->ieee->handle_beacon = ipw_handle_probe_response;
10952 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
James Ketrenosb095c382005-08-24 22:04:42 -050010953#endif /* CONFIG_IPW_QOS */
10954
James Ketrenosc848d0a2005-08-24 21:56:24 -050010955 priv->ieee->perfect_rssi = -20;
10956 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060010957
10958 net_dev->open = ipw_net_open;
10959 net_dev->stop = ipw_net_stop;
10960 net_dev->init = ipw_net_init;
10961 net_dev->get_stats = ipw_net_get_stats;
10962 net_dev->set_multicast_list = ipw_net_set_multicast_list;
10963 net_dev->set_mac_address = ipw_net_set_mac_address;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000010964 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000010965 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060010966 net_dev->wireless_handlers = &ipw_wx_handler_def;
10967 net_dev->ethtool_ops = &ipw_ethtool_ops;
10968 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010969 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060010970 net_dev->mem_start = pci_resource_start(pdev, 0);
10971 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
10972
10973 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
10974 if (err) {
10975 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080010976 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010977 goto out_release_irq;
10978 }
10979
Zhu Yi46441512006-01-24 16:37:59 +080010980 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010981 err = register_netdev(net_dev);
10982 if (err) {
10983 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050010984 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060010985 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080010986
10987 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
10988 "channels, %d 802.11a channels)\n",
10989 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
10990 priv->ieee->geo.a_channels);
10991
James Ketrenos43f66a62005-03-25 12:31:53 -060010992 return 0;
10993
James Ketrenosa613bff2005-08-24 21:43:11 -050010994 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060010995 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010996 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060010997 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010998 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060010999 destroy_workqueue(priv->workqueue);
11000 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011001 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011002 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011003 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011004 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011005 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011006 pci_disable_device(pdev);
11007 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011008 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -060011009 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011010 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011011 return err;
11012}
11013
11014static void ipw_pci_remove(struct pci_dev *pdev)
11015{
11016 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011017 struct list_head *p, *q;
11018 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011019
James Ketrenos43f66a62005-03-25 12:31:53 -060011020 if (!priv)
11021 return;
11022
Zhu Yi46441512006-01-24 16:37:59 +080011023 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011024
James Ketrenosafbf30a2005-08-25 00:05:33 -050011025 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011026 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011027 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11028
Zhu Yi46441512006-01-24 16:37:59 +080011029 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011030
11031 unregister_netdev(priv->net_dev);
11032
11033 if (priv->rxq) {
11034 ipw_rx_queue_free(priv, priv->rxq);
11035 priv->rxq = NULL;
11036 }
11037 ipw_tx_queue_free(priv);
11038
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011039 if (priv->cmdlog) {
11040 kfree(priv->cmdlog);
11041 priv->cmdlog = NULL;
11042 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011043 /* ipw_down will ensure that there is no more pending work
11044 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011045 cancel_delayed_work(&priv->adhoc_check);
11046 cancel_delayed_work(&priv->gather_stats);
11047 cancel_delayed_work(&priv->request_scan);
11048 cancel_delayed_work(&priv->rf_kill);
11049 cancel_delayed_work(&priv->scan_check);
11050 destroy_workqueue(priv->workqueue);
11051 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011052
James Ketrenosafbf30a2005-08-25 00:05:33 -050011053 /* Free MAC hash list for ADHOC */
11054 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11055 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011056 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011057 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011058 }
11059 }
11060
James Ketrenosb39860c2005-08-12 09:36:32 -050011061 if (priv->error) {
11062 ipw_free_error_log(priv->error);
11063 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011064 }
11065
11066 free_irq(pdev->irq, priv);
11067 iounmap(priv->hw_base);
11068 pci_release_regions(pdev);
11069 pci_disable_device(pdev);
11070 pci_set_drvdata(pdev, NULL);
11071 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011072 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011073}
11074
James Ketrenos43f66a62005-03-25 12:31:53 -060011075#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011076static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011077{
11078 struct ipw_priv *priv = pci_get_drvdata(pdev);
11079 struct net_device *dev = priv->net_dev;
11080
11081 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11082
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011083 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011084 ipw_down(priv);
11085
11086 /* Remove the PRESENT state of the device */
11087 netif_device_detach(dev);
11088
James Ketrenos43f66a62005-03-25 12:31:53 -060011089 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011090 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011091 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011092
James Ketrenos43f66a62005-03-25 12:31:53 -060011093 return 0;
11094}
11095
11096static int ipw_pci_resume(struct pci_dev *pdev)
11097{
11098 struct ipw_priv *priv = pci_get_drvdata(pdev);
11099 struct net_device *dev = priv->net_dev;
11100 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011101
James Ketrenos43f66a62005-03-25 12:31:53 -060011102 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11103
James Ketrenosea2b26e2005-08-24 21:25:16 -050011104 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011105 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011106 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011107
James Ketrenos43f66a62005-03-25 12:31:53 -060011108 /*
11109 * Suspend/Resume resets the PCI configuration space, so we have to
11110 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11111 * from interfering with C3 CPU state. pci_restore_state won't help
11112 * here since it only restores the first 64 bytes pci config header.
11113 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011114 pci_read_config_dword(pdev, 0x40, &val);
11115 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011116 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11117
11118 /* Set the device back into the PRESENT state; this will also wake
11119 * the queue of needed */
11120 netif_device_attach(dev);
11121
11122 /* Bring the device back up */
11123 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011124
James Ketrenos43f66a62005-03-25 12:31:53 -060011125 return 0;
11126}
11127#endif
11128
11129/* driver initialization stuff */
11130static struct pci_driver ipw_driver = {
11131 .name = DRV_NAME,
11132 .id_table = card_ids,
11133 .probe = ipw_pci_probe,
11134 .remove = __devexit_p(ipw_pci_remove),
11135#ifdef CONFIG_PM
11136 .suspend = ipw_pci_suspend,
11137 .resume = ipw_pci_resume,
11138#endif
11139};
11140
11141static int __init ipw_init(void)
11142{
11143 int ret;
11144
11145 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11146 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11147
11148 ret = pci_module_init(&ipw_driver);
11149 if (ret) {
11150 IPW_ERROR("Unable to initialize PCI module\n");
11151 return ret;
11152 }
11153
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011154 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011155 if (ret) {
11156 IPW_ERROR("Unable to create driver sysfs file\n");
11157 pci_unregister_driver(&ipw_driver);
11158 return ret;
11159 }
11160
11161 return ret;
11162}
11163
11164static void __exit ipw_exit(void)
11165{
11166 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11167 pci_unregister_driver(&ipw_driver);
11168}
11169
11170module_param(disable, int, 0444);
11171MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11172
11173module_param(associate, int, 0444);
11174MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11175
11176module_param(auto_create, int, 0444);
11177MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11178
James Ketrenosa613bff2005-08-24 21:43:11 -050011179module_param(led, int, 0444);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011180MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011181
James Ketrenos43f66a62005-03-25 12:31:53 -060011182module_param(debug, int, 0444);
11183MODULE_PARM_DESC(debug, "debug output mask");
11184
11185module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011186MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011187
James Ketrenosb095c382005-08-24 22:04:42 -050011188#ifdef CONFIG_IPW_QOS
11189module_param(qos_enable, int, 0444);
11190MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060011191
James Ketrenosb095c382005-08-24 22:04:42 -050011192module_param(qos_burst_enable, int, 0444);
11193MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11194
11195module_param(qos_no_ack_mask, int, 0444);
11196MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11197
11198module_param(burst_duration_CCK, int, 0444);
11199MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11200
11201module_param(burst_duration_OFDM, int, 0444);
11202MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11203#endif /* CONFIG_IPW_QOS */
11204
11205#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -060011206module_param(mode, int, 0444);
11207MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11208#else
11209module_param(mode, int, 0444);
11210MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11211#endif
11212
Zhu Yi810dabd2006-01-24 16:36:59 +080011213module_param(bt_coexist, int, 0444);
11214MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
11215
James Ketrenosb095c382005-08-24 22:04:42 -050011216module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080011217MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050011218
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011219module_param(cmdlog, int, 0444);
11220MODULE_PARM_DESC(cmdlog,
11221 "allocate a ring buffer for logging firmware commands");
11222
Zhu Yi4bfdb912006-01-24 16:37:16 +080011223module_param(roaming, int, 0444);
11224MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
11225
James Ketrenos43f66a62005-03-25 12:31:53 -060011226module_exit(ipw_exit);
11227module_init(ipw_init);