blob: 7fceea64736e31ecb278b74a0441b6e2d3a25b30 [file] [log] [blame]
James Ketrenos43f66a62005-03-25 12:31:53 -06001/******************************************************************************
Jeff Garzikbf794512005-07-31 13:07:26 -04002
Zhu Yi171e7b22006-02-15 07:17:56 +08003 Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved.
James Ketrenos43f66a62005-03-25 12:31:53 -06004
5 802.11 status code portion of this file from ethereal-0.10.6:
6 Copyright 2000, Axis Communications AB
7 Ethereal - Network traffic analyzer
8 By Gerald Combs <gerald@ethereal.com>
9 Copyright 1998 Gerald Combs
10
Jeff Garzikbf794512005-07-31 13:07:26 -040011 This program is free software; you can redistribute it and/or modify it
12 under the terms of version 2 of the GNU General Public License as
James Ketrenos43f66a62005-03-25 12:31:53 -060013 published by the Free Software Foundation.
Jeff Garzikbf794512005-07-31 13:07:26 -040014
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
James Ketrenos43f66a62005-03-25 12:31:53 -060018 more details.
Jeff Garzikbf794512005-07-31 13:07:26 -040019
James Ketrenos43f66a62005-03-25 12:31:53 -060020 You should have received a copy of the GNU General Public License along with
Jeff Garzikbf794512005-07-31 13:07:26 -040021 this program; if not, write to the Free Software Foundation, Inc., 59
James Ketrenos43f66a62005-03-25 12:31:53 -060022 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Jeff Garzikbf794512005-07-31 13:07:26 -040023
James Ketrenos43f66a62005-03-25 12:31:53 -060024 The full GNU General Public License is included in this distribution in the
25 file called LICENSE.
Jeff Garzikbf794512005-07-31 13:07:26 -040026
James Ketrenos43f66a62005-03-25 12:31:53 -060027 Contact Information:
28 James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30
31******************************************************************************/
32
33#include "ipw2200.h"
Olaf Hering733482e2005-11-08 21:34:55 -080034#include <linux/version.h>
James Ketrenos43f66a62005-03-25 12:31:53 -060035
Zhu Yi7c567892006-02-24 04:20:48 +080036#define IPW2200_VERSION "git-1.1.1"
James Ketrenos43f66a62005-03-25 12:31:53 -060037#define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
Zhu Yi171e7b22006-02-15 07:17:56 +080038#define DRV_COPYRIGHT "Copyright(c) 2003-2006 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;
Zhu Yi5dc81c32006-04-13 17:19:44 +080049#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060050static int debug = 0;
Zhu Yi5dc81c32006-04-13 17:19:44 +080051#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060052static int channel = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060053static int mode = 0;
54
55static u32 ipw_debug_level;
56static int associate = 1;
57static int auto_create = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -050058static int led = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060059static int disable = 0;
Zhu Yi810dabd2006-01-24 16:36:59 +080060static int bt_coexist = 0;
Zhu Yibde37d02006-01-24 16:38:08 +080061static int hwcrypto = 0;
Zhu Yi4bfdb912006-01-24 16:37:16 +080062static int roaming = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -060063static const char ipw_modes[] = {
64 'a', 'b', 'g', '?'
65};
Zhu Yid2b83e12006-04-13 17:19:36 +080066static int antenna = CFG_SYS_ANTENNA_BOTH;
James Ketrenos43f66a62005-03-25 12:31:53 -060067
James Ketrenosb095c382005-08-24 22:04:42 -050068#ifdef CONFIG_IPW_QOS
69static int qos_enable = 0;
70static int qos_burst_enable = 0;
71static int qos_no_ack_mask = 0;
72static int burst_duration_CCK = 0;
73static int burst_duration_OFDM = 0;
74
75static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
76 {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
77 QOS_TX3_CW_MIN_OFDM},
78 {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
79 QOS_TX3_CW_MAX_OFDM},
80 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
81 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
82 {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
83 QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
84};
85
86static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
87 {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
88 QOS_TX3_CW_MIN_CCK},
89 {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
90 QOS_TX3_CW_MAX_CCK},
91 {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
92 {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
93 {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
94 QOS_TX3_TXOP_LIMIT_CCK}
95};
96
97static struct ieee80211_qos_parameters def_parameters_OFDM = {
98 {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
99 DEF_TX3_CW_MIN_OFDM},
100 {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
101 DEF_TX3_CW_MAX_OFDM},
102 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
103 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
104 {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
105 DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
106};
107
108static struct ieee80211_qos_parameters def_parameters_CCK = {
109 {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
110 DEF_TX3_CW_MIN_CCK},
111 {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
112 DEF_TX3_CW_MAX_CCK},
113 {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
114 {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
115 {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
116 DEF_TX3_TXOP_LIMIT_CCK}
117};
118
119static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
120
121static int from_priority_to_tx_queue[] = {
122 IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
123 IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
124};
125
126static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
127
128static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
129 *qos_param);
130static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
131 *qos_param);
132#endif /* CONFIG_IPW_QOS */
133
Benoit Boissinot97a78ca2005-09-15 17:30:28 +0000134static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev);
James Ketrenosb095c382005-08-24 22:04:42 -0500135static void ipw_remove_current_network(struct ipw_priv *priv);
James Ketrenos43f66a62005-03-25 12:31:53 -0600136static void ipw_rx(struct ipw_priv *priv);
Jeff Garzikbf794512005-07-31 13:07:26 -0400137static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -0600138 struct clx2_tx_queue *txq, int qindex);
139static int ipw_queue_reset(struct ipw_priv *priv);
140
141static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
142 int len, int sync);
143
144static void ipw_tx_queue_free(struct ipw_priv *);
145
146static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
147static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
148static void ipw_rx_queue_replenish(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600149static int ipw_up(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500150static void ipw_bg_up(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600151static void ipw_down(struct ipw_priv *);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500152static void ipw_bg_down(void *);
James Ketrenos43f66a62005-03-25 12:31:53 -0600153static int ipw_config(struct ipw_priv *);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400154static int init_supported_rates(struct ipw_priv *priv,
155 struct ipw_supported_rates *prates);
James Ketrenosb095c382005-08-24 22:04:42 -0500156static void ipw_set_hwcrypto_keys(struct ipw_priv *);
157static void ipw_send_wep_keys(struct ipw_priv *, int);
James Ketrenos43f66a62005-03-25 12:31:53 -0600158
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500159static int snprint_line(char *buf, size_t count,
160 const u8 * data, u32 len, u32 ofs)
James Ketrenos43f66a62005-03-25 12:31:53 -0600161{
162 int out, i, j, l;
163 char c;
Jeff Garzikbf794512005-07-31 13:07:26 -0400164
James Ketrenos43f66a62005-03-25 12:31:53 -0600165 out = snprintf(buf, count, "%08X", ofs);
166
167 for (l = 0, i = 0; i < 2; i++) {
168 out += snprintf(buf + out, count - out, " ");
Jeff Garzikbf794512005-07-31 13:07:26 -0400169 for (j = 0; j < 8 && l < len; j++, l++)
170 out += snprintf(buf + out, count - out, "%02X ",
James Ketrenos43f66a62005-03-25 12:31:53 -0600171 data[(i * 8 + j)]);
172 for (; j < 8; j++)
173 out += snprintf(buf + out, count - out, " ");
174 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400175
James Ketrenos43f66a62005-03-25 12:31:53 -0600176 out += snprintf(buf + out, count - out, " ");
177 for (l = 0, i = 0; i < 2; i++) {
178 out += snprintf(buf + out, count - out, " ");
179 for (j = 0; j < 8 && l < len; j++, l++) {
180 c = data[(i * 8 + j)];
181 if (!isascii(c) || !isprint(c))
182 c = '.';
Jeff Garzikbf794512005-07-31 13:07:26 -0400183
James Ketrenos43f66a62005-03-25 12:31:53 -0600184 out += snprintf(buf + out, count - out, "%c", c);
185 }
186
187 for (; j < 8; j++)
188 out += snprintf(buf + out, count - out, " ");
189 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400190
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500191 return out;
James Ketrenos43f66a62005-03-25 12:31:53 -0600192}
193
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400194static void printk_buf(int level, const u8 * data, u32 len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600195{
196 char line[81];
197 u32 ofs = 0;
198 if (!(ipw_debug_level & level))
199 return;
200
201 while (len) {
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500202 snprint_line(line, sizeof(line), &data[ofs],
203 min(len, 16U), ofs);
204 printk(KERN_DEBUG "%s\n", line);
James Ketrenos43f66a62005-03-25 12:31:53 -0600205 ofs += 16;
206 len -= min(len, 16U);
207 }
208}
209
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500210static int snprintk_buf(u8 * output, size_t size, const u8 * data, size_t len)
211{
212 size_t out = size;
213 u32 ofs = 0;
214 int total = 0;
215
216 while (size && len) {
217 out = snprint_line(output, size, &data[ofs],
218 min_t(size_t, len, 16U), ofs);
219
220 ofs += 16;
221 output += out;
222 size -= out;
223 len -= min_t(size_t, len, 16U);
224 total += out;
225 }
226 return total;
227}
228
Zhu Yic8fe6672006-01-24 16:36:36 +0800229/* alias for 32-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600230static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
231#define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
232
Zhu Yic8fe6672006-01-24 16:36:36 +0800233/* alias for 8-bit indirect read (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600234static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
235#define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
236
Zhu Yic8fe6672006-01-24 16:36:36 +0800237/* 8-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600238static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
239static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
240{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400241 IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
242 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600243 _ipw_write_reg8(a, b, c);
244}
245
Zhu Yic8fe6672006-01-24 16:36:36 +0800246/* 16-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600247static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
248static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
249{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400250 IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
251 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600252 _ipw_write_reg16(a, b, c);
253}
254
Zhu Yic8fe6672006-01-24 16:36:36 +0800255/* 32-bit indirect write (for SRAM/reg above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600256static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
257static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
258{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400259 IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
260 __LINE__, (u32) (b), (u32) (c));
James Ketrenos43f66a62005-03-25 12:31:53 -0600261 _ipw_write_reg32(a, b, c);
262}
263
Zhu Yic8fe6672006-01-24 16:36:36 +0800264/* 8-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600265#define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800266
267/* 8-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600268#define ipw_write8(ipw, ofs, val) \
269 IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
270 _ipw_write8(ipw, ofs, val)
271
Zhu Yic8fe6672006-01-24 16:36:36 +0800272/* 16-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600273#define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800274
275/* 16-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600276#define ipw_write16(ipw, ofs, val) \
277 IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
278 _ipw_write16(ipw, ofs, val)
279
Zhu Yic8fe6672006-01-24 16:36:36 +0800280/* 32-bit direct write (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600281#define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800282
283/* 32-bit direct write (for low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600284#define ipw_write32(ipw, ofs, val) \
285 IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
286 _ipw_write32(ipw, ofs, val)
287
Zhu Yic8fe6672006-01-24 16:36:36 +0800288/* 8-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600289#define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800290
291/* 8-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400292static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
293{
294 IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600295 return _ipw_read8(ipw, ofs);
296}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400297
Zhu Yic8fe6672006-01-24 16:36:36 +0800298/* alias to 8-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600299#define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
300
Zhu Yic8fe6672006-01-24 16:36:36 +0800301/* 16-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600302#define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800303
304/* 16-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400305static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
306{
307 IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600308 return _ipw_read16(ipw, ofs);
309}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400310
Zhu Yic8fe6672006-01-24 16:36:36 +0800311/* alias to 16-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600312#define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
313
Zhu Yic8fe6672006-01-24 16:36:36 +0800314/* 32-bit direct read (low 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600315#define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
Zhu Yic8fe6672006-01-24 16:36:36 +0800316
317/* 32-bit direct read (low 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400318static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
319{
320 IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
James Ketrenos43f66a62005-03-25 12:31:53 -0600321 return _ipw_read32(ipw, ofs);
322}
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400323
Zhu Yic8fe6672006-01-24 16:36:36 +0800324/* alias to 32-bit direct read (low 4K of SRAM/regs), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600325#define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
326
Zhu Yic8fe6672006-01-24 16:36:36 +0800327/* multi-byte read (above 4K), with debug wrapper */
James Ketrenos43f66a62005-03-25 12:31:53 -0600328static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500329static inline void __ipw_read_indirect(const char *f, int l,
330 struct ipw_priv *a, u32 b, u8 * c, int d)
331{
332 IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", f, l, (u32) (b),
333 d);
334 _ipw_read_indirect(a, b, c, d);
335}
336
Zhu Yic8fe6672006-01-24 16:36:36 +0800337/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
James Ketrenosf6c5cb72005-08-25 00:39:09 -0500338#define ipw_read_indirect(a, b, c, d) __ipw_read_indirect(__FILE__, __LINE__, a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600339
Zhu Yic8fe6672006-01-24 16:36:36 +0800340/* alias to multi-byte read (SRAM/regs above 4K), with debug wrapper */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400341static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
342 int num);
James Ketrenos43f66a62005-03-25 12:31:53 -0600343#define ipw_write_indirect(a, b, c, d) \
344 IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
James Ketrenosafbf30a2005-08-25 00:05:33 -0500345 _ipw_write_indirect(a, b, c, d)
James Ketrenos43f66a62005-03-25 12:31:53 -0600346
Zhu Yic8fe6672006-01-24 16:36:36 +0800347/* 32-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400348static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600349{
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400350 IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
James Ketrenosb095c382005-08-24 22:04:42 -0500351 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
352 _ipw_write32(priv, IPW_INDIRECT_DATA, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600353}
354
Zhu Yic8fe6672006-01-24 16:36:36 +0800355/* 8-bit indirect write (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600356static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
357{
Zhu Yi2638bc32006-01-24 16:37:52 +0800358 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800359 u32 dif_len = reg - aligned_addr;
360
James Ketrenos43f66a62005-03-25 12:31:53 -0600361 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800362 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
363 _ipw_write8(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600364}
365
Zhu Yic8fe6672006-01-24 16:36:36 +0800366/* 16-bit indirect write (above 4K) */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400367static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
James Ketrenos43f66a62005-03-25 12:31:53 -0600368{
Zhu Yi2638bc32006-01-24 16:37:52 +0800369 u32 aligned_addr = reg & IPW_INDIRECT_ADDR_MASK; /* dword align */
Zhu Yic8fe6672006-01-24 16:36:36 +0800370 u32 dif_len = (reg - aligned_addr) & (~0x1ul);
371
James Ketrenos43f66a62005-03-25 12:31:53 -0600372 IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
Zhu Yic8fe6672006-01-24 16:36:36 +0800373 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
374 _ipw_write16(priv, IPW_INDIRECT_DATA + dif_len, value);
James Ketrenos43f66a62005-03-25 12:31:53 -0600375}
376
Zhu Yic8fe6672006-01-24 16:36:36 +0800377/* 8-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600378static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
379{
380 u32 word;
James Ketrenosb095c382005-08-24 22:04:42 -0500381 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -0600382 IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
James Ketrenosb095c382005-08-24 22:04:42 -0500383 word = _ipw_read32(priv, IPW_INDIRECT_DATA);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400384 return (word >> ((reg & 0x3) * 8)) & 0xff;
James Ketrenos43f66a62005-03-25 12:31:53 -0600385}
386
Zhu Yic8fe6672006-01-24 16:36:36 +0800387/* 32-bit indirect read (above 4K) */
James Ketrenos43f66a62005-03-25 12:31:53 -0600388static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
389{
390 u32 value;
391
392 IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
393
James Ketrenosb095c382005-08-24 22:04:42 -0500394 _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
395 value = _ipw_read32(priv, IPW_INDIRECT_DATA);
James Ketrenos43f66a62005-03-25 12:31:53 -0600396 IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
397 return value;
398}
399
Zhu Yic8fe6672006-01-24 16:36:36 +0800400/* General purpose, no alignment requirement, iterative (multi-byte) read, */
401/* for area above 1st 4K of SRAM/reg space */
James Ketrenos43f66a62005-03-25 12:31:53 -0600402static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
403 int num)
404{
Zhu Yi2638bc32006-01-24 16:37:52 +0800405 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600406 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600407 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400408
James Ketrenos43f66a62005-03-25 12:31:53 -0600409 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
410
James Ketrenosea2b26e2005-08-24 21:25:16 -0500411 if (num <= 0) {
412 return;
413 }
414
Zhu Yic8fe6672006-01-24 16:36:36 +0800415 /* Read the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600416 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500417 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600418 /* Start reading at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500419 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500420 *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenos43f66a62005-03-25 12:31:53 -0600421 aligned_addr += 4;
422 }
423
Zhu Yic8fe6672006-01-24 16:36:36 +0800424 /* Read all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500425 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500426 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500427 *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
Jeff Garzikbf794512005-07-31 13:07:26 -0400428
Zhu Yic8fe6672006-01-24 16:36:36 +0800429 /* Read the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500430 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500431 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500432 for (i = 0; num > 0; i++, num--)
James Ketrenosb095c382005-08-24 22:04:42 -0500433 *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500434 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600435}
436
Zhu Yic8fe6672006-01-24 16:36:36 +0800437/* General purpose, no alignment requirement, iterative (multi-byte) write, */
438/* for area above 1st 4K of SRAM/reg space */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400439static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600440 int num)
441{
Zhu Yi2638bc32006-01-24 16:37:52 +0800442 u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK; /* dword align */
James Ketrenos43f66a62005-03-25 12:31:53 -0600443 u32 dif_len = addr - aligned_addr;
James Ketrenos43f66a62005-03-25 12:31:53 -0600444 u32 i;
Jeff Garzikbf794512005-07-31 13:07:26 -0400445
James Ketrenos43f66a62005-03-25 12:31:53 -0600446 IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
Jeff Garzikbf794512005-07-31 13:07:26 -0400447
James Ketrenosea2b26e2005-08-24 21:25:16 -0500448 if (num <= 0) {
449 return;
450 }
451
Zhu Yic8fe6672006-01-24 16:36:36 +0800452 /* Write the first dword (or portion) byte by byte */
James Ketrenos43f66a62005-03-25 12:31:53 -0600453 if (unlikely(dif_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500454 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
Zhu Yic8fe6672006-01-24 16:36:36 +0800455 /* Start writing at aligned_addr + dif_len */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500456 for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500457 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenos43f66a62005-03-25 12:31:53 -0600458 aligned_addr += 4;
459 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400460
Zhu Yic8fe6672006-01-24 16:36:36 +0800461 /* Write all of the middle dwords as dwords, with auto-increment */
James Ketrenosb095c382005-08-24 22:04:42 -0500462 _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500463 for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
James Ketrenosb095c382005-08-24 22:04:42 -0500464 _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
Jeff Garzikbf794512005-07-31 13:07:26 -0400465
Zhu Yic8fe6672006-01-24 16:36:36 +0800466 /* Write the last dword (or portion) byte by byte */
James Ketrenosea2b26e2005-08-24 21:25:16 -0500467 if (unlikely(num)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500468 _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500469 for (i = 0; num > 0; i++, num--, buf++)
James Ketrenosb095c382005-08-24 22:04:42 -0500470 _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
James Ketrenosea2b26e2005-08-24 21:25:16 -0500471 }
James Ketrenos43f66a62005-03-25 12:31:53 -0600472}
473
Zhu Yic8fe6672006-01-24 16:36:36 +0800474/* General purpose, no alignment requirement, iterative (multi-byte) write, */
475/* for 1st 4K of SRAM/regs space */
Jeff Garzikbf794512005-07-31 13:07:26 -0400476static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
James Ketrenos43f66a62005-03-25 12:31:53 -0600477 int num)
478{
479 memcpy_toio((priv->hw_base + addr), buf, num);
480}
481
Zhu Yic8fe6672006-01-24 16:36:36 +0800482/* Set bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600483static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
484{
485 ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
486}
487
Zhu Yic8fe6672006-01-24 16:36:36 +0800488/* Clear bit(s) in low 4K of SRAM/regs */
James Ketrenos43f66a62005-03-25 12:31:53 -0600489static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
490{
491 ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
492}
493
494static inline void ipw_enable_interrupts(struct ipw_priv *priv)
495{
496 if (priv->status & STATUS_INT_ENABLED)
497 return;
498 priv->status |= STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500499 ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600500}
501
502static inline void ipw_disable_interrupts(struct ipw_priv *priv)
503{
504 if (!(priv->status & STATUS_INT_ENABLED))
505 return;
506 priv->status &= ~STATUS_INT_ENABLED;
James Ketrenosb095c382005-08-24 22:04:42 -0500507 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -0600508}
509
Brice Goglin0f52bf92005-12-01 01:41:46 -0800510#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -0600511static char *ipw_error_desc(u32 val)
512{
513 switch (val) {
Jeff Garzikbf794512005-07-31 13:07:26 -0400514 case IPW_FW_ERROR_OK:
James Ketrenos43f66a62005-03-25 12:31:53 -0600515 return "ERROR_OK";
Jeff Garzikbf794512005-07-31 13:07:26 -0400516 case IPW_FW_ERROR_FAIL:
James Ketrenos43f66a62005-03-25 12:31:53 -0600517 return "ERROR_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400518 case IPW_FW_ERROR_MEMORY_UNDERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600519 return "MEMORY_UNDERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400520 case IPW_FW_ERROR_MEMORY_OVERFLOW:
James Ketrenos43f66a62005-03-25 12:31:53 -0600521 return "MEMORY_OVERFLOW";
Jeff Garzikbf794512005-07-31 13:07:26 -0400522 case IPW_FW_ERROR_BAD_PARAM:
James Ketrenosb095c382005-08-24 22:04:42 -0500523 return "BAD_PARAM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400524 case IPW_FW_ERROR_BAD_CHECKSUM:
James Ketrenosb095c382005-08-24 22:04:42 -0500525 return "BAD_CHECKSUM";
Jeff Garzikbf794512005-07-31 13:07:26 -0400526 case IPW_FW_ERROR_NMI_INTERRUPT:
James Ketrenosb095c382005-08-24 22:04:42 -0500527 return "NMI_INTERRUPT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400528 case IPW_FW_ERROR_BAD_DATABASE:
James Ketrenosb095c382005-08-24 22:04:42 -0500529 return "BAD_DATABASE";
Jeff Garzikbf794512005-07-31 13:07:26 -0400530 case IPW_FW_ERROR_ALLOC_FAIL:
James Ketrenosb095c382005-08-24 22:04:42 -0500531 return "ALLOC_FAIL";
Jeff Garzikbf794512005-07-31 13:07:26 -0400532 case IPW_FW_ERROR_DMA_UNDERRUN:
James Ketrenosb095c382005-08-24 22:04:42 -0500533 return "DMA_UNDERRUN";
Jeff Garzikbf794512005-07-31 13:07:26 -0400534 case IPW_FW_ERROR_DMA_STATUS:
James Ketrenosb095c382005-08-24 22:04:42 -0500535 return "DMA_STATUS";
536 case IPW_FW_ERROR_DINO_ERROR:
537 return "DINO_ERROR";
538 case IPW_FW_ERROR_EEPROM_ERROR:
539 return "EEPROM_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400540 case IPW_FW_ERROR_SYSASSERT:
James Ketrenosb095c382005-08-24 22:04:42 -0500541 return "SYSASSERT";
Jeff Garzikbf794512005-07-31 13:07:26 -0400542 case IPW_FW_ERROR_FATAL_ERROR:
James Ketrenosb095c382005-08-24 22:04:42 -0500543 return "FATAL_ERROR";
Jeff Garzikbf794512005-07-31 13:07:26 -0400544 default:
James Ketrenosb095c382005-08-24 22:04:42 -0500545 return "UNKNOWN_ERROR";
James Ketrenos43f66a62005-03-25 12:31:53 -0600546 }
547}
548
James Ketrenosb39860c2005-08-12 09:36:32 -0500549static void ipw_dump_error_log(struct ipw_priv *priv,
550 struct ipw_fw_error *error)
James Ketrenos43f66a62005-03-25 12:31:53 -0600551{
James Ketrenosb39860c2005-08-12 09:36:32 -0500552 u32 i;
James Ketrenos43f66a62005-03-25 12:31:53 -0600553
James Ketrenosb39860c2005-08-12 09:36:32 -0500554 if (!error) {
555 IPW_ERROR("Error allocating and capturing error log. "
556 "Nothing to dump.\n");
557 return;
James Ketrenos43f66a62005-03-25 12:31:53 -0600558 }
559
James Ketrenosb39860c2005-08-12 09:36:32 -0500560 IPW_ERROR("Start IPW Error Log Dump:\n");
561 IPW_ERROR("Status: 0x%08X, Config: %08X\n",
562 error->status, error->config);
James Ketrenos43f66a62005-03-25 12:31:53 -0600563
James Ketrenosb39860c2005-08-12 09:36:32 -0500564 for (i = 0; i < error->elem_len; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400565 IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
James Ketrenosb39860c2005-08-12 09:36:32 -0500566 ipw_error_desc(error->elem[i].desc),
567 error->elem[i].time,
568 error->elem[i].blink1,
569 error->elem[i].blink2,
570 error->elem[i].link1,
571 error->elem[i].link2, error->elem[i].data);
572 for (i = 0; i < error->log_len; i++)
573 IPW_ERROR("%i\t0x%08x\t%i\n",
574 error->log[i].time,
James Ketrenos286568a2005-08-30 10:34:25 -0500575 error->log[i].data, error->log[i].event);
James Ketrenos43f66a62005-03-25 12:31:53 -0600576}
James Ketrenos43f66a62005-03-25 12:31:53 -0600577#endif
James Ketrenos43f66a62005-03-25 12:31:53 -0600578
James Ketrenosc848d0a2005-08-24 21:56:24 -0500579static inline int ipw_is_init(struct ipw_priv *priv)
580{
581 return (priv->status & STATUS_INIT) ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -0600582}
583
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400584static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
James Ketrenos43f66a62005-03-25 12:31:53 -0600585{
586 u32 addr, field_info, field_len, field_count, total_len;
587
588 IPW_DEBUG_ORD("ordinal = %i\n", ord);
589
590 if (!priv || !val || !len) {
591 IPW_DEBUG_ORD("Invalid argument\n");
592 return -EINVAL;
593 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400594
James Ketrenos43f66a62005-03-25 12:31:53 -0600595 /* verify device ordinal tables have been initialized */
596 if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
597 IPW_DEBUG_ORD("Access ordinals before initialization\n");
598 return -EINVAL;
599 }
600
601 switch (IPW_ORD_TABLE_ID_MASK & ord) {
602 case IPW_ORD_TABLE_0_MASK:
603 /*
604 * TABLE 0: Direct access to a table of 32 bit values
605 *
Jeff Garzikbf794512005-07-31 13:07:26 -0400606 * This is a very simple table with the data directly
James Ketrenos43f66a62005-03-25 12:31:53 -0600607 * read from the table
608 */
609
610 /* remove the table id from the ordinal */
611 ord &= IPW_ORD_TABLE_VALUE_MASK;
612
613 /* boundary check */
614 if (ord > priv->table0_len) {
615 IPW_DEBUG_ORD("ordinal value (%i) longer then "
616 "max (%i)\n", ord, priv->table0_len);
617 return -EINVAL;
618 }
619
620 /* verify we have enough room to store the value */
621 if (*len < sizeof(u32)) {
622 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200623 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600624 return -EINVAL;
625 }
626
627 IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400628 ord, priv->table0_addr + (ord << 2));
James Ketrenos43f66a62005-03-25 12:31:53 -0600629
630 *len = sizeof(u32);
631 ord <<= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400632 *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
James Ketrenos43f66a62005-03-25 12:31:53 -0600633 break;
634
635 case IPW_ORD_TABLE_1_MASK:
636 /*
637 * TABLE 1: Indirect access to a table of 32 bit values
Jeff Garzikbf794512005-07-31 13:07:26 -0400638 *
639 * This is a fairly large table of u32 values each
James Ketrenos43f66a62005-03-25 12:31:53 -0600640 * representing starting addr for the data (which is
641 * also a u32)
642 */
643
644 /* remove the table id from the ordinal */
645 ord &= IPW_ORD_TABLE_VALUE_MASK;
Jeff Garzikbf794512005-07-31 13:07:26 -0400646
James Ketrenos43f66a62005-03-25 12:31:53 -0600647 /* boundary check */
648 if (ord > priv->table1_len) {
649 IPW_DEBUG_ORD("ordinal value too long\n");
650 return -EINVAL;
651 }
652
653 /* verify we have enough room to store the value */
654 if (*len < sizeof(u32)) {
655 IPW_DEBUG_ORD("ordinal buffer length too small, "
Jiri Bencaaa4d302005-06-07 14:58:41 +0200656 "need %zd\n", sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -0600657 return -EINVAL;
658 }
659
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400660 *((u32 *) val) =
661 ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
James Ketrenos43f66a62005-03-25 12:31:53 -0600662 *len = sizeof(u32);
663 break;
664
665 case IPW_ORD_TABLE_2_MASK:
666 /*
667 * TABLE 2: Indirect access to a table of variable sized values
668 *
669 * This table consist of six values, each containing
670 * - dword containing the starting offset of the data
671 * - dword containing the lengh in the first 16bits
672 * and the count in the second 16bits
673 */
674
675 /* remove the table id from the ordinal */
676 ord &= IPW_ORD_TABLE_VALUE_MASK;
677
678 /* boundary check */
679 if (ord > priv->table2_len) {
680 IPW_DEBUG_ORD("ordinal value too long\n");
681 return -EINVAL;
682 }
683
684 /* get the address of statistic */
685 addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
Jeff Garzikbf794512005-07-31 13:07:26 -0400686
687 /* get the second DW of statistics ;
James Ketrenos43f66a62005-03-25 12:31:53 -0600688 * two 16-bit words - first is length, second is count */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400689 field_info =
690 ipw_read_reg32(priv,
691 priv->table2_addr + (ord << 3) +
692 sizeof(u32));
Jeff Garzikbf794512005-07-31 13:07:26 -0400693
James Ketrenos43f66a62005-03-25 12:31:53 -0600694 /* get each entry length */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400695 field_len = *((u16 *) & field_info);
Jeff Garzikbf794512005-07-31 13:07:26 -0400696
James Ketrenos43f66a62005-03-25 12:31:53 -0600697 /* get number of entries */
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400698 field_count = *(((u16 *) & field_info) + 1);
Jeff Garzikbf794512005-07-31 13:07:26 -0400699
James Ketrenos43f66a62005-03-25 12:31:53 -0600700 /* abort if not enought memory */
701 total_len = field_len * field_count;
702 if (total_len > *len) {
703 *len = total_len;
704 return -EINVAL;
705 }
Jeff Garzikbf794512005-07-31 13:07:26 -0400706
James Ketrenos43f66a62005-03-25 12:31:53 -0600707 *len = total_len;
708 if (!total_len)
709 return 0;
710
711 IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
Jeff Garzikbf794512005-07-31 13:07:26 -0400712 "field_info = 0x%08x\n",
James Ketrenos43f66a62005-03-25 12:31:53 -0600713 addr, total_len, field_info);
714 ipw_read_indirect(priv, addr, val, total_len);
715 break;
716
717 default:
718 IPW_DEBUG_ORD("Invalid ordinal!\n");
719 return -EINVAL;
720
721 }
722
James Ketrenos43f66a62005-03-25 12:31:53 -0600723 return 0;
724}
725
726static void ipw_init_ordinals(struct ipw_priv *priv)
727{
728 priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
Jeff Garzikbf794512005-07-31 13:07:26 -0400729 priv->table0_len = ipw_read32(priv, priv->table0_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -0600730
731 IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
732 priv->table0_addr, priv->table0_len);
733
734 priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
735 priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
736
737 IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
738 priv->table1_addr, priv->table1_len);
739
740 priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
741 priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
Jeff Garzik0edd5b42005-09-07 00:48:31 -0400742 priv->table2_len &= 0x0000ffff; /* use first two bytes */
James Ketrenos43f66a62005-03-25 12:31:53 -0600743
744 IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
745 priv->table2_addr, priv->table2_len);
746
747}
748
Adrian Bunka73e22b2006-01-21 01:39:42 +0100749static u32 ipw_register_toggle(u32 reg)
James Ketrenosa613bff2005-08-24 21:43:11 -0500750{
James Ketrenosb095c382005-08-24 22:04:42 -0500751 reg &= ~IPW_START_STANDBY;
752 if (reg & IPW_GATE_ODMA)
753 reg &= ~IPW_GATE_ODMA;
754 if (reg & IPW_GATE_IDMA)
755 reg &= ~IPW_GATE_IDMA;
756 if (reg & IPW_GATE_ADMA)
757 reg &= ~IPW_GATE_ADMA;
James Ketrenosa613bff2005-08-24 21:43:11 -0500758 return reg;
759}
760
761/*
762 * LED behavior:
763 * - On radio ON, turn on any LEDs that require to be on during start
764 * - On initialization, start unassociated blink
765 * - On association, disable unassociated blink
766 * - On disassociation, start unassociated blink
767 * - On radio OFF, turn off any LEDs started during radio on
768 *
769 */
Zhu Yiede61112006-01-24 16:37:10 +0800770#define LD_TIME_LINK_ON msecs_to_jiffies(300)
771#define LD_TIME_LINK_OFF msecs_to_jiffies(2700)
772#define LD_TIME_ACT_ON msecs_to_jiffies(250)
James Ketrenosa613bff2005-08-24 21:43:11 -0500773
Adrian Bunka73e22b2006-01-21 01:39:42 +0100774static void ipw_led_link_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500775{
776 unsigned long flags;
777 u32 led;
778
779 /* If configured to not use LEDs, or nic_type is 1,
780 * then we don't toggle a LINK led */
781 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
782 return;
783
784 spin_lock_irqsave(&priv->lock, flags);
785
786 if (!(priv->status & STATUS_RF_KILL_MASK) &&
787 !(priv->status & STATUS_LED_LINK_ON)) {
788 IPW_DEBUG_LED("Link LED On\n");
James Ketrenosb095c382005-08-24 22:04:42 -0500789 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500790 led |= priv->led_association_on;
791
792 led = ipw_register_toggle(led);
793
794 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500795 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500796
797 priv->status |= STATUS_LED_LINK_ON;
798
799 /* If we aren't associated, schedule turning the LED off */
800 if (!(priv->status & STATUS_ASSOCIATED))
801 queue_delayed_work(priv->workqueue,
802 &priv->led_link_off,
803 LD_TIME_LINK_ON);
804 }
805
806 spin_unlock_irqrestore(&priv->lock, flags);
807}
808
James Ketrenosc848d0a2005-08-24 21:56:24 -0500809static void ipw_bg_led_link_on(void *data)
810{
811 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800812 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500813 ipw_led_link_on(data);
Zhu Yi46441512006-01-24 16:37:59 +0800814 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500815}
816
Adrian Bunka73e22b2006-01-21 01:39:42 +0100817static void ipw_led_link_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500818{
819 unsigned long flags;
820 u32 led;
821
822 /* If configured not to use LEDs, or nic type is 1,
823 * then we don't goggle the LINK led. */
824 if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
825 return;
826
827 spin_lock_irqsave(&priv->lock, flags);
828
829 if (priv->status & STATUS_LED_LINK_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500830 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500831 led &= priv->led_association_off;
832 led = ipw_register_toggle(led);
833
834 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500835 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500836
837 IPW_DEBUG_LED("Link LED Off\n");
838
839 priv->status &= ~STATUS_LED_LINK_ON;
840
841 /* If we aren't associated and the radio is on, schedule
842 * turning the LED on (blink while unassociated) */
843 if (!(priv->status & STATUS_RF_KILL_MASK) &&
844 !(priv->status & STATUS_ASSOCIATED))
845 queue_delayed_work(priv->workqueue, &priv->led_link_on,
846 LD_TIME_LINK_OFF);
847
848 }
849
850 spin_unlock_irqrestore(&priv->lock, flags);
851}
852
James Ketrenosc848d0a2005-08-24 21:56:24 -0500853static void ipw_bg_led_link_off(void *data)
854{
855 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800856 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500857 ipw_led_link_off(data);
Zhu Yi46441512006-01-24 16:37:59 +0800858 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500859}
860
Arjan van de Ven858119e2006-01-14 13:20:43 -0800861static void __ipw_led_activity_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500862{
James Ketrenosa613bff2005-08-24 21:43:11 -0500863 u32 led;
864
865 if (priv->config & CFG_NO_LED)
866 return;
867
James Ketrenosb095c382005-08-24 22:04:42 -0500868 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -0500869 return;
James Ketrenosa613bff2005-08-24 21:43:11 -0500870
871 if (!(priv->status & STATUS_LED_ACT_ON)) {
James Ketrenosb095c382005-08-24 22:04:42 -0500872 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500873 led |= priv->led_activity_on;
874
875 led = ipw_register_toggle(led);
876
877 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500878 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500879
880 IPW_DEBUG_LED("Activity LED On\n");
881
882 priv->status |= STATUS_LED_ACT_ON;
883
James Ketrenosc848d0a2005-08-24 21:56:24 -0500884 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -0500885 queue_delayed_work(priv->workqueue, &priv->led_act_off,
886 LD_TIME_ACT_ON);
887 } else {
888 /* Reschedule LED off for full time period */
889 cancel_delayed_work(&priv->led_act_off);
890 queue_delayed_work(priv->workqueue, &priv->led_act_off,
891 LD_TIME_ACT_ON);
892 }
James Ketrenosb095c382005-08-24 22:04:42 -0500893}
James Ketrenosa613bff2005-08-24 21:43:11 -0500894
Adrian Bunka73e22b2006-01-21 01:39:42 +0100895#if 0
James Ketrenosb095c382005-08-24 22:04:42 -0500896void ipw_led_activity_on(struct ipw_priv *priv)
897{
898 unsigned long flags;
899 spin_lock_irqsave(&priv->lock, flags);
900 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -0500901 spin_unlock_irqrestore(&priv->lock, flags);
902}
Adrian Bunka73e22b2006-01-21 01:39:42 +0100903#endif /* 0 */
James Ketrenosa613bff2005-08-24 21:43:11 -0500904
Adrian Bunka73e22b2006-01-21 01:39:42 +0100905static void ipw_led_activity_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500906{
907 unsigned long flags;
908 u32 led;
909
910 if (priv->config & CFG_NO_LED)
911 return;
912
913 spin_lock_irqsave(&priv->lock, flags);
914
915 if (priv->status & STATUS_LED_ACT_ON) {
James Ketrenosb095c382005-08-24 22:04:42 -0500916 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500917 led &= priv->led_activity_off;
918
919 led = ipw_register_toggle(led);
920
921 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500922 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500923
924 IPW_DEBUG_LED("Activity LED Off\n");
925
926 priv->status &= ~STATUS_LED_ACT_ON;
927 }
928
929 spin_unlock_irqrestore(&priv->lock, flags);
930}
931
James Ketrenosc848d0a2005-08-24 21:56:24 -0500932static void ipw_bg_led_activity_off(void *data)
933{
934 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +0800935 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500936 ipw_led_activity_off(data);
Zhu Yi46441512006-01-24 16:37:59 +0800937 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -0500938}
939
Adrian Bunka73e22b2006-01-21 01:39:42 +0100940static void ipw_led_band_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500941{
942 unsigned long flags;
943 u32 led;
944
945 /* Only nic type 1 supports mode LEDs */
James Ketrenosc848d0a2005-08-24 21:56:24 -0500946 if (priv->config & CFG_NO_LED ||
947 priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
James Ketrenosa613bff2005-08-24 21:43:11 -0500948 return;
949
950 spin_lock_irqsave(&priv->lock, flags);
951
James Ketrenosb095c382005-08-24 22:04:42 -0500952 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500953 if (priv->assoc_network->mode == IEEE_A) {
954 led |= priv->led_ofdm_on;
955 led &= priv->led_association_off;
956 IPW_DEBUG_LED("Mode LED On: 802.11a\n");
957 } else if (priv->assoc_network->mode == IEEE_G) {
958 led |= priv->led_ofdm_on;
959 led |= priv->led_association_on;
960 IPW_DEBUG_LED("Mode LED On: 802.11g\n");
961 } else {
962 led &= priv->led_ofdm_off;
963 led |= priv->led_association_on;
964 IPW_DEBUG_LED("Mode LED On: 802.11b\n");
965 }
966
967 led = ipw_register_toggle(led);
968
969 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500970 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500971
972 spin_unlock_irqrestore(&priv->lock, flags);
973}
974
Adrian Bunka73e22b2006-01-21 01:39:42 +0100975static void ipw_led_band_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500976{
977 unsigned long flags;
978 u32 led;
979
980 /* Only nic type 1 supports mode LEDs */
981 if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
982 return;
983
984 spin_lock_irqsave(&priv->lock, flags);
985
James Ketrenosb095c382005-08-24 22:04:42 -0500986 led = ipw_read_reg32(priv, IPW_EVENT_REG);
James Ketrenosa613bff2005-08-24 21:43:11 -0500987 led &= priv->led_ofdm_off;
988 led &= priv->led_association_off;
989
990 led = ipw_register_toggle(led);
991
992 IPW_DEBUG_LED("Reg: 0x%08X\n", led);
James Ketrenosb095c382005-08-24 22:04:42 -0500993 ipw_write_reg32(priv, IPW_EVENT_REG, led);
James Ketrenosa613bff2005-08-24 21:43:11 -0500994
995 spin_unlock_irqrestore(&priv->lock, flags);
996}
997
Adrian Bunka73e22b2006-01-21 01:39:42 +0100998static void ipw_led_radio_on(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -0500999{
1000 ipw_led_link_on(priv);
1001}
1002
Adrian Bunka73e22b2006-01-21 01:39:42 +01001003static void ipw_led_radio_off(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001004{
1005 ipw_led_activity_off(priv);
1006 ipw_led_link_off(priv);
1007}
1008
Adrian Bunka73e22b2006-01-21 01:39:42 +01001009static void ipw_led_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001010{
1011 /* Set the Link Led on for all nic types */
1012 ipw_led_link_on(priv);
1013}
1014
Adrian Bunka73e22b2006-01-21 01:39:42 +01001015static void ipw_led_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001016{
1017 ipw_led_activity_off(priv);
1018 ipw_led_link_off(priv);
1019
1020 if (priv->status & STATUS_RF_KILL_MASK)
1021 ipw_led_radio_off(priv);
1022}
1023
Adrian Bunka73e22b2006-01-21 01:39:42 +01001024static void ipw_led_init(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001025{
1026 priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
1027
1028 /* Set the default PINs for the link and activity leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001029 priv->led_activity_on = IPW_ACTIVITY_LED;
1030 priv->led_activity_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001031
James Ketrenosb095c382005-08-24 22:04:42 -05001032 priv->led_association_on = IPW_ASSOCIATED_LED;
1033 priv->led_association_off = ~(IPW_ASSOCIATED_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001034
1035 /* Set the default PINs for the OFDM leds */
James Ketrenosb095c382005-08-24 22:04:42 -05001036 priv->led_ofdm_on = IPW_OFDM_LED;
1037 priv->led_ofdm_off = ~(IPW_OFDM_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001038
1039 switch (priv->nic_type) {
1040 case EEPROM_NIC_TYPE_1:
1041 /* In this NIC type, the LEDs are reversed.... */
James Ketrenosb095c382005-08-24 22:04:42 -05001042 priv->led_activity_on = IPW_ASSOCIATED_LED;
1043 priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
1044 priv->led_association_on = IPW_ACTIVITY_LED;
1045 priv->led_association_off = ~(IPW_ACTIVITY_LED);
James Ketrenosa613bff2005-08-24 21:43:11 -05001046
1047 if (!(priv->config & CFG_NO_LED))
1048 ipw_led_band_on(priv);
1049
1050 /* And we don't blink link LEDs for this nic, so
1051 * just return here */
1052 return;
1053
1054 case EEPROM_NIC_TYPE_3:
1055 case EEPROM_NIC_TYPE_2:
1056 case EEPROM_NIC_TYPE_4:
1057 case EEPROM_NIC_TYPE_0:
1058 break;
1059
1060 default:
1061 IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
1062 priv->nic_type);
1063 priv->nic_type = EEPROM_NIC_TYPE_0;
1064 break;
1065 }
1066
1067 if (!(priv->config & CFG_NO_LED)) {
1068 if (priv->status & STATUS_ASSOCIATED)
1069 ipw_led_link_on(priv);
1070 else
1071 ipw_led_link_off(priv);
1072 }
1073}
1074
Adrian Bunka73e22b2006-01-21 01:39:42 +01001075static void ipw_led_shutdown(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -05001076{
James Ketrenosa613bff2005-08-24 21:43:11 -05001077 ipw_led_activity_off(priv);
1078 ipw_led_link_off(priv);
1079 ipw_led_band_off(priv);
James Ketrenosafbf30a2005-08-25 00:05:33 -05001080 cancel_delayed_work(&priv->led_link_on);
1081 cancel_delayed_work(&priv->led_link_off);
1082 cancel_delayed_work(&priv->led_act_off);
James Ketrenosa613bff2005-08-24 21:43:11 -05001083}
1084
James Ketrenos43f66a62005-03-25 12:31:53 -06001085/*
1086 * The following adds a new attribute to the sysfs representation
1087 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
1088 * used for controling the debug level.
Jeff Garzikbf794512005-07-31 13:07:26 -04001089 *
James Ketrenos43f66a62005-03-25 12:31:53 -06001090 * See the level definitions in ipw for details.
1091 */
1092static ssize_t show_debug_level(struct device_driver *d, char *buf)
1093{
1094 return sprintf(buf, "0x%08X\n", ipw_debug_level);
1095}
James Ketrenosa613bff2005-08-24 21:43:11 -05001096
1097static ssize_t store_debug_level(struct device_driver *d, const char *buf,
1098 size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001099{
1100 char *p = (char *)buf;
1101 u32 val;
1102
1103 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1104 p++;
1105 if (p[0] == 'x' || p[0] == 'X')
1106 p++;
1107 val = simple_strtoul(p, &p, 16);
1108 } else
1109 val = simple_strtoul(p, &p, 10);
Jeff Garzikbf794512005-07-31 13:07:26 -04001110 if (p == buf)
1111 printk(KERN_INFO DRV_NAME
James Ketrenos43f66a62005-03-25 12:31:53 -06001112 ": %s is not in hex or decimal form.\n", buf);
1113 else
1114 ipw_debug_level = val;
1115
1116 return strnlen(buf, count);
1117}
1118
Jeff Garzikbf794512005-07-31 13:07:26 -04001119static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001120 show_debug_level, store_debug_level);
1121
James Ketrenosb39860c2005-08-12 09:36:32 -05001122static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
1123{
Zhu Yic8fe6672006-01-24 16:36:36 +08001124 /* length = 1st dword in log */
James Ketrenosb39860c2005-08-12 09:36:32 -05001125 return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
1126}
1127
1128static void ipw_capture_event_log(struct ipw_priv *priv,
1129 u32 log_len, struct ipw_event *log)
1130{
1131 u32 base;
1132
1133 if (log_len) {
1134 base = ipw_read32(priv, IPW_EVENT_LOG);
1135 ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
1136 (u8 *) log, sizeof(*log) * log_len);
1137 }
1138}
1139
1140static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
1141{
1142 struct ipw_fw_error *error;
1143 u32 log_len = ipw_get_event_log_len(priv);
1144 u32 base = ipw_read32(priv, IPW_ERROR_LOG);
1145 u32 elem_len = ipw_read_reg32(priv, base);
1146
1147 error = kmalloc(sizeof(*error) +
1148 sizeof(*error->elem) * elem_len +
1149 sizeof(*error->log) * log_len, GFP_ATOMIC);
1150 if (!error) {
1151 IPW_ERROR("Memory allocation for firmware error log "
1152 "failed.\n");
1153 return NULL;
1154 }
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001155 error->jiffies = jiffies;
James Ketrenosb39860c2005-08-12 09:36:32 -05001156 error->status = priv->status;
1157 error->config = priv->config;
1158 error->elem_len = elem_len;
1159 error->log_len = log_len;
1160 error->elem = (struct ipw_error_elem *)error->payload;
Zhu Yi3b26b112005-11-17 13:58:30 +08001161 error->log = (struct ipw_event *)(error->elem + elem_len);
James Ketrenosb39860c2005-08-12 09:36:32 -05001162
1163 ipw_capture_event_log(priv, log_len, error->log);
1164
1165 if (elem_len)
1166 ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
1167 sizeof(*error->elem) * elem_len);
1168
1169 return error;
1170}
1171
1172static void ipw_free_error_log(struct ipw_fw_error *error)
1173{
1174 if (error)
1175 kfree(error);
1176}
1177
1178static ssize_t show_event_log(struct device *d,
1179 struct device_attribute *attr, char *buf)
1180{
1181 struct ipw_priv *priv = dev_get_drvdata(d);
1182 u32 log_len = ipw_get_event_log_len(priv);
1183 struct ipw_event log[log_len];
1184 u32 len = 0, i;
1185
1186 ipw_capture_event_log(priv, log_len, log);
1187
1188 len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
1189 for (i = 0; i < log_len; i++)
1190 len += snprintf(buf + len, PAGE_SIZE - len,
1191 "\n%08X%08X%08X",
1192 log[i].time, log[i].event, log[i].data);
1193 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1194 return len;
1195}
1196
1197static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
1198
1199static ssize_t show_error(struct device *d,
1200 struct device_attribute *attr, char *buf)
1201{
1202 struct ipw_priv *priv = dev_get_drvdata(d);
1203 u32 len = 0, i;
1204 if (!priv->error)
1205 return 0;
1206 len += snprintf(buf + len, PAGE_SIZE - len,
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001207 "%08lX%08X%08X%08X",
1208 priv->error->jiffies,
James Ketrenosb39860c2005-08-12 09:36:32 -05001209 priv->error->status,
1210 priv->error->config, priv->error->elem_len);
1211 for (i = 0; i < priv->error->elem_len; i++)
1212 len += snprintf(buf + len, PAGE_SIZE - len,
1213 "\n%08X%08X%08X%08X%08X%08X%08X",
1214 priv->error->elem[i].time,
1215 priv->error->elem[i].desc,
1216 priv->error->elem[i].blink1,
1217 priv->error->elem[i].blink2,
1218 priv->error->elem[i].link1,
1219 priv->error->elem[i].link2,
1220 priv->error->elem[i].data);
1221
1222 len += snprintf(buf + len, PAGE_SIZE - len,
1223 "\n%08X", priv->error->log_len);
1224 for (i = 0; i < priv->error->log_len; i++)
1225 len += snprintf(buf + len, PAGE_SIZE - len,
1226 "\n%08X%08X%08X",
1227 priv->error->log[i].time,
1228 priv->error->log[i].event,
1229 priv->error->log[i].data);
1230 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1231 return len;
1232}
1233
1234static ssize_t clear_error(struct device *d,
1235 struct device_attribute *attr,
1236 const char *buf, size_t count)
1237{
1238 struct ipw_priv *priv = dev_get_drvdata(d);
1239 if (priv->error) {
1240 ipw_free_error_log(priv->error);
1241 priv->error = NULL;
1242 }
1243 return count;
1244}
1245
1246static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
1247
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001248static ssize_t show_cmd_log(struct device *d,
1249 struct device_attribute *attr, char *buf)
1250{
1251 struct ipw_priv *priv = dev_get_drvdata(d);
1252 u32 len = 0, i;
1253 if (!priv->cmdlog)
1254 return 0;
1255 for (i = (priv->cmdlog_pos + 1) % priv->cmdlog_len;
1256 (i != priv->cmdlog_pos) && (PAGE_SIZE - len);
1257 i = (i + 1) % priv->cmdlog_len) {
1258 len +=
1259 snprintf(buf + len, PAGE_SIZE - len,
1260 "\n%08lX%08X%08X%08X\n", priv->cmdlog[i].jiffies,
1261 priv->cmdlog[i].retcode, priv->cmdlog[i].cmd.cmd,
1262 priv->cmdlog[i].cmd.len);
1263 len +=
1264 snprintk_buf(buf + len, PAGE_SIZE - len,
1265 (u8 *) priv->cmdlog[i].cmd.param,
1266 priv->cmdlog[i].cmd.len);
1267 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1268 }
1269 len += snprintf(buf + len, PAGE_SIZE - len, "\n");
1270 return len;
1271}
1272
1273static DEVICE_ATTR(cmd_log, S_IRUGO, show_cmd_log, NULL);
1274
James Ketrenosa613bff2005-08-24 21:43:11 -05001275static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
1276 char *buf)
1277{
1278 struct ipw_priv *priv = dev_get_drvdata(d);
1279 return sprintf(buf, "%d\n", priv->ieee->scan_age);
1280}
1281
1282static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
1283 const char *buf, size_t count)
1284{
1285 struct ipw_priv *priv = dev_get_drvdata(d);
Brice Goglin0f52bf92005-12-01 01:41:46 -08001286#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosa613bff2005-08-24 21:43:11 -05001287 struct net_device *dev = priv->net_dev;
James Ketrenosc848d0a2005-08-24 21:56:24 -05001288#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05001289 char buffer[] = "00000000";
1290 unsigned long len =
1291 (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
1292 unsigned long val;
1293 char *p = buffer;
1294
1295 IPW_DEBUG_INFO("enter\n");
1296
1297 strncpy(buffer, buf, len);
1298 buffer[len] = 0;
1299
1300 if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
1301 p++;
1302 if (p[0] == 'x' || p[0] == 'X')
1303 p++;
1304 val = simple_strtoul(p, &p, 16);
1305 } else
1306 val = simple_strtoul(p, &p, 10);
1307 if (p == buffer) {
1308 IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
1309 } else {
1310 priv->ieee->scan_age = val;
1311 IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
1312 }
1313
1314 IPW_DEBUG_INFO("exit\n");
1315 return len;
1316}
1317
1318static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
1319
1320static ssize_t show_led(struct device *d, struct device_attribute *attr,
1321 char *buf)
1322{
1323 struct ipw_priv *priv = dev_get_drvdata(d);
1324 return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
1325}
1326
1327static ssize_t store_led(struct device *d, struct device_attribute *attr,
1328 const char *buf, size_t count)
1329{
1330 struct ipw_priv *priv = dev_get_drvdata(d);
1331
1332 IPW_DEBUG_INFO("enter\n");
1333
1334 if (count == 0)
1335 return 0;
1336
1337 if (*buf == 0) {
1338 IPW_DEBUG_LED("Disabling LED control.\n");
1339 priv->config |= CFG_NO_LED;
1340 ipw_led_shutdown(priv);
1341 } else {
1342 IPW_DEBUG_LED("Enabling LED control.\n");
1343 priv->config &= ~CFG_NO_LED;
1344 ipw_led_init(priv);
1345 }
1346
1347 IPW_DEBUG_INFO("exit\n");
1348 return count;
1349}
1350
1351static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
1352
Andrew Mortonad3fee52005-06-20 14:30:36 -07001353static ssize_t show_status(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001354 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001355{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001356 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001357 return sprintf(buf, "0x%08x\n", (int)p->status);
1358}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001359
James Ketrenos43f66a62005-03-25 12:31:53 -06001360static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
1361
Andrew Mortonad3fee52005-06-20 14:30:36 -07001362static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
1363 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001364{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001365 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001366 return sprintf(buf, "0x%08x\n", (int)p->config);
1367}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001368
James Ketrenos43f66a62005-03-25 12:31:53 -06001369static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
1370
Andrew Mortonad3fee52005-06-20 14:30:36 -07001371static ssize_t show_nic_type(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001372 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001373{
James Ketrenosa613bff2005-08-24 21:43:11 -05001374 struct ipw_priv *priv = d->driver_data;
1375 return sprintf(buf, "TYPE: %d\n", priv->nic_type);
James Ketrenos43f66a62005-03-25 12:31:53 -06001376}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001377
James Ketrenos43f66a62005-03-25 12:31:53 -06001378static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
1379
Andrew Mortonad3fee52005-06-20 14:30:36 -07001380static ssize_t show_ucode_version(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001381 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001382{
1383 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001384 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001385
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001386 if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001387 return 0;
1388
1389 return sprintf(buf, "0x%08x\n", tmp);
1390}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001391
1392static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001393
Andrew Mortonad3fee52005-06-20 14:30:36 -07001394static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
1395 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001396{
1397 u32 len = sizeof(u32), tmp = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001398 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001399
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001400 if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
James Ketrenos43f66a62005-03-25 12:31:53 -06001401 return 0;
1402
1403 return sprintf(buf, "0x%08x\n", tmp);
1404}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001405
1406static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
James Ketrenos43f66a62005-03-25 12:31:53 -06001407
1408/*
1409 * Add a device attribute to view/control the delay between eeprom
1410 * operations.
1411 */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001412static ssize_t show_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001413 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001414{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001415 int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
James Ketrenos43f66a62005-03-25 12:31:53 -06001416 return sprintf(buf, "%i\n", n);
1417}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001418static ssize_t store_eeprom_delay(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001419 struct device_attribute *attr,
1420 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001421{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001422 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001423 sscanf(buf, "%i", &p->eeprom_delay);
1424 return strnlen(buf, count);
1425}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001426
1427static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
1428 show_eeprom_delay, store_eeprom_delay);
James Ketrenos43f66a62005-03-25 12:31:53 -06001429
Andrew Mortonad3fee52005-06-20 14:30:36 -07001430static ssize_t show_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001431 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001432{
1433 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001434 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001435
James Ketrenosb095c382005-08-24 22:04:42 -05001436 reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001437 return sprintf(buf, "0x%08x\n", reg);
1438}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001439static ssize_t store_command_event_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001440 struct device_attribute *attr,
1441 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001442{
1443 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001444 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001445
1446 sscanf(buf, "%x", &reg);
James Ketrenosb095c382005-08-24 22:04:42 -05001447 ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001448 return strnlen(buf, count);
1449}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001450
1451static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
1452 show_command_event_reg, store_command_event_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001453
Andrew Mortonad3fee52005-06-20 14:30:36 -07001454static ssize_t show_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001455 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001456{
1457 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001458 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001459
1460 reg = ipw_read_reg32(p, 0x301100);
1461 return sprintf(buf, "0x%08x\n", reg);
1462}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001463static ssize_t store_mem_gpio_reg(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001464 struct device_attribute *attr,
1465 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001466{
1467 u32 reg;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001468 struct ipw_priv *p = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001469
1470 sscanf(buf, "%x", &reg);
1471 ipw_write_reg32(p, 0x301100, reg);
1472 return strnlen(buf, count);
1473}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001474
1475static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
1476 show_mem_gpio_reg, store_mem_gpio_reg);
James Ketrenos43f66a62005-03-25 12:31:53 -06001477
Andrew Mortonad3fee52005-06-20 14:30:36 -07001478static ssize_t show_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001479 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001480{
1481 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001482 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001483
Jeff Garzikbf794512005-07-31 13:07:26 -04001484 if (priv->status & STATUS_INDIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001485 reg = ipw_read_reg32(priv, priv->indirect_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001486 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001487 reg = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04001488
James Ketrenos43f66a62005-03-25 12:31:53 -06001489 return sprintf(buf, "0x%08x\n", reg);
1490}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001491static ssize_t store_indirect_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001492 struct device_attribute *attr,
1493 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001494{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001495 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001496
1497 sscanf(buf, "%x", &priv->indirect_dword);
1498 priv->status |= STATUS_INDIRECT_DWORD;
1499 return strnlen(buf, count);
1500}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001501
1502static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
1503 show_indirect_dword, store_indirect_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001504
Andrew Mortonad3fee52005-06-20 14:30:36 -07001505static ssize_t show_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001506 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001507{
1508 u8 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001509 struct ipw_priv *priv = d->driver_data;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001510
Jeff Garzikbf794512005-07-31 13:07:26 -04001511 if (priv->status & STATUS_INDIRECT_BYTE)
James Ketrenos43f66a62005-03-25 12:31:53 -06001512 reg = ipw_read_reg8(priv, priv->indirect_byte);
Jeff Garzikbf794512005-07-31 13:07:26 -04001513 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001514 reg = 0;
1515
1516 return sprintf(buf, "0x%02x\n", reg);
1517}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001518static ssize_t store_indirect_byte(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001519 struct device_attribute *attr,
1520 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001521{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001522 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001523
1524 sscanf(buf, "%x", &priv->indirect_byte);
1525 priv->status |= STATUS_INDIRECT_BYTE;
1526 return strnlen(buf, count);
1527}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001528
1529static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
James Ketrenos43f66a62005-03-25 12:31:53 -06001530 show_indirect_byte, store_indirect_byte);
1531
Andrew Mortonad3fee52005-06-20 14:30:36 -07001532static ssize_t show_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001533 struct device_attribute *attr, char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001534{
1535 u32 reg = 0;
Andrew Mortonad3fee52005-06-20 14:30:36 -07001536 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001537
Jeff Garzikbf794512005-07-31 13:07:26 -04001538 if (priv->status & STATUS_DIRECT_DWORD)
James Ketrenos43f66a62005-03-25 12:31:53 -06001539 reg = ipw_read32(priv, priv->direct_dword);
Jeff Garzikbf794512005-07-31 13:07:26 -04001540 else
James Ketrenos43f66a62005-03-25 12:31:53 -06001541 reg = 0;
1542
1543 return sprintf(buf, "0x%08x\n", reg);
1544}
Andrew Mortonad3fee52005-06-20 14:30:36 -07001545static ssize_t store_direct_dword(struct device *d,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001546 struct device_attribute *attr,
1547 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001548{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001549 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001550
1551 sscanf(buf, "%x", &priv->direct_dword);
1552 priv->status |= STATUS_DIRECT_DWORD;
1553 return strnlen(buf, count);
1554}
James Ketrenos43f66a62005-03-25 12:31:53 -06001555
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001556static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
1557 show_direct_dword, store_direct_dword);
James Ketrenos43f66a62005-03-25 12:31:53 -06001558
Arjan van de Ven858119e2006-01-14 13:20:43 -08001559static int rf_kill_active(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06001560{
1561 if (0 == (ipw_read32(priv, 0x30) & 0x10000))
1562 priv->status |= STATUS_RF_KILL_HW;
1563 else
1564 priv->status &= ~STATUS_RF_KILL_HW;
1565
1566 return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
1567}
1568
Andrew Mortonad3fee52005-06-20 14:30:36 -07001569static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001570 char *buf)
James Ketrenos43f66a62005-03-25 12:31:53 -06001571{
1572 /* 0 - RF kill not enabled
Jeff Garzikbf794512005-07-31 13:07:26 -04001573 1 - SW based RF kill active (sysfs)
James Ketrenos43f66a62005-03-25 12:31:53 -06001574 2 - HW based RF kill active
1575 3 - Both HW and SW baed RF kill active */
Andrew Mortonad3fee52005-06-20 14:30:36 -07001576 struct ipw_priv *priv = d->driver_data;
James Ketrenos43f66a62005-03-25 12:31:53 -06001577 int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001578 (rf_kill_active(priv) ? 0x2 : 0x0);
James Ketrenos43f66a62005-03-25 12:31:53 -06001579 return sprintf(buf, "%i\n", val);
1580}
1581
1582static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
1583{
Jeff Garzikbf794512005-07-31 13:07:26 -04001584 if ((disable_radio ? 1 : 0) ==
James Ketrenosea2b26e2005-08-24 21:25:16 -05001585 ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001586 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06001587
1588 IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
1589 disable_radio ? "OFF" : "ON");
1590
1591 if (disable_radio) {
1592 priv->status |= STATUS_RF_KILL_SW;
1593
James Ketrenosa613bff2005-08-24 21:43:11 -05001594 if (priv->workqueue)
James Ketrenos43f66a62005-03-25 12:31:53 -06001595 cancel_delayed_work(&priv->request_scan);
James Ketrenos43f66a62005-03-25 12:31:53 -06001596 queue_work(priv->workqueue, &priv->down);
1597 } else {
1598 priv->status &= ~STATUS_RF_KILL_SW;
1599 if (rf_kill_active(priv)) {
1600 IPW_DEBUG_RF_KILL("Can not turn radio back on - "
1601 "disabled by HW switch\n");
1602 /* Make sure the RF_KILL check timer is running */
1603 cancel_delayed_work(&priv->rf_kill);
Jeff Garzikbf794512005-07-31 13:07:26 -04001604 queue_delayed_work(priv->workqueue, &priv->rf_kill,
James Ketrenos43f66a62005-03-25 12:31:53 -06001605 2 * HZ);
Jeff Garzikbf794512005-07-31 13:07:26 -04001606 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06001607 queue_work(priv->workqueue, &priv->up);
1608 }
1609
1610 return 1;
1611}
1612
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001613static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
1614 const char *buf, size_t count)
James Ketrenos43f66a62005-03-25 12:31:53 -06001615{
Andrew Mortonad3fee52005-06-20 14:30:36 -07001616 struct ipw_priv *priv = d->driver_data;
Jeff Garzikbf794512005-07-31 13:07:26 -04001617
James Ketrenos43f66a62005-03-25 12:31:53 -06001618 ipw_radio_kill_sw(priv, buf[0] == '1');
1619
1620 return count;
1621}
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001622
1623static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
James Ketrenos43f66a62005-03-25 12:31:53 -06001624
James Ketrenosb095c382005-08-24 22:04:42 -05001625static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
1626 char *buf)
1627{
1628 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1629 int pos = 0, len = 0;
1630 if (priv->config & CFG_SPEED_SCAN) {
1631 while (priv->speed_scan[pos] != 0)
1632 len += sprintf(&buf[len], "%d ",
1633 priv->speed_scan[pos++]);
1634 return len + sprintf(&buf[len], "\n");
1635 }
1636
1637 return sprintf(buf, "0\n");
1638}
1639
1640static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
1641 const char *buf, size_t count)
1642{
1643 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1644 int channel, pos = 0;
1645 const char *p = buf;
1646
1647 /* list of space separated channels to scan, optionally ending with 0 */
1648 while ((channel = simple_strtol(p, NULL, 0))) {
1649 if (pos == MAX_SPEED_SCAN - 1) {
1650 priv->speed_scan[pos] = 0;
1651 break;
1652 }
1653
Larry Finger1867b112006-02-28 09:48:28 -06001654 if (ieee80211_is_valid_channel(priv->ieee, channel))
James Ketrenosb095c382005-08-24 22:04:42 -05001655 priv->speed_scan[pos++] = channel;
1656 else
1657 IPW_WARNING("Skipping invalid channel request: %d\n",
1658 channel);
1659 p = strchr(p, ' ');
1660 if (!p)
1661 break;
1662 while (*p == ' ' || *p == '\t')
1663 p++;
1664 }
1665
1666 if (pos == 0)
1667 priv->config &= ~CFG_SPEED_SCAN;
1668 else {
1669 priv->speed_scan_pos = 0;
1670 priv->config |= CFG_SPEED_SCAN;
1671 }
1672
1673 return count;
1674}
1675
1676static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
1677 store_speed_scan);
1678
1679static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
1680 char *buf)
1681{
1682 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1683 return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
1684}
1685
1686static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
1687 const char *buf, size_t count)
1688{
1689 struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
1690 if (buf[0] == '1')
1691 priv->config |= CFG_NET_STATS;
1692 else
1693 priv->config &= ~CFG_NET_STATS;
1694
1695 return count;
1696}
1697
James Ketrenosafbf30a2005-08-25 00:05:33 -05001698static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
1699 show_net_stats, store_net_stats);
James Ketrenosb095c382005-08-24 22:04:42 -05001700
James Ketrenosea2b26e2005-08-24 21:25:16 -05001701static void notify_wx_assoc_event(struct ipw_priv *priv)
1702{
1703 union iwreq_data wrqu;
1704 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1705 if (priv->status & STATUS_ASSOCIATED)
1706 memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
1707 else
1708 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1709 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
1710}
1711
James Ketrenos43f66a62005-03-25 12:31:53 -06001712static void ipw_irq_tasklet(struct ipw_priv *priv)
1713{
1714 u32 inta, inta_mask, handled = 0;
1715 unsigned long flags;
1716 int rc = 0;
1717
1718 spin_lock_irqsave(&priv->lock, flags);
1719
James Ketrenosb095c382005-08-24 22:04:42 -05001720 inta = ipw_read32(priv, IPW_INTA_RW);
1721 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
1722 inta &= (IPW_INTA_MASK_ALL & inta_mask);
James Ketrenos43f66a62005-03-25 12:31:53 -06001723
1724 /* Add any cached INTA values that need to be handled */
1725 inta |= priv->isr_inta;
1726
1727 /* handle all the justifications for the interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05001728 if (inta & IPW_INTA_BIT_RX_TRANSFER) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001729 ipw_rx(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05001730 handled |= IPW_INTA_BIT_RX_TRANSFER;
James Ketrenos43f66a62005-03-25 12:31:53 -06001731 }
1732
James Ketrenosb095c382005-08-24 22:04:42 -05001733 if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001734 IPW_DEBUG_HC("Command completed.\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001735 rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
James Ketrenos43f66a62005-03-25 12:31:53 -06001736 priv->status &= ~STATUS_HCMD_ACTIVE;
1737 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosb095c382005-08-24 22:04:42 -05001738 handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001739 }
1740
James Ketrenosb095c382005-08-24 22:04:42 -05001741 if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001742 IPW_DEBUG_TX("TX_QUEUE_1\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001743 rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
James Ketrenosb095c382005-08-24 22:04:42 -05001744 handled |= IPW_INTA_BIT_TX_QUEUE_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06001745 }
1746
James Ketrenosb095c382005-08-24 22:04:42 -05001747 if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001748 IPW_DEBUG_TX("TX_QUEUE_2\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001749 rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
James Ketrenosb095c382005-08-24 22:04:42 -05001750 handled |= IPW_INTA_BIT_TX_QUEUE_2;
James Ketrenos43f66a62005-03-25 12:31:53 -06001751 }
1752
James Ketrenosb095c382005-08-24 22:04:42 -05001753 if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001754 IPW_DEBUG_TX("TX_QUEUE_3\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001755 rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
James Ketrenosb095c382005-08-24 22:04:42 -05001756 handled |= IPW_INTA_BIT_TX_QUEUE_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06001757 }
1758
James Ketrenosb095c382005-08-24 22:04:42 -05001759 if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001760 IPW_DEBUG_TX("TX_QUEUE_4\n");
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001761 rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
James Ketrenosb095c382005-08-24 22:04:42 -05001762 handled |= IPW_INTA_BIT_TX_QUEUE_4;
James Ketrenos43f66a62005-03-25 12:31:53 -06001763 }
1764
James Ketrenosb095c382005-08-24 22:04:42 -05001765 if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001766 IPW_WARNING("STATUS_CHANGE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001767 handled |= IPW_INTA_BIT_STATUS_CHANGE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001768 }
1769
James Ketrenosb095c382005-08-24 22:04:42 -05001770 if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001771 IPW_WARNING("TX_PERIOD_EXPIRED\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001772 handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
James Ketrenos43f66a62005-03-25 12:31:53 -06001773 }
1774
James Ketrenosb095c382005-08-24 22:04:42 -05001775 if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001776 IPW_WARNING("HOST_CMD_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001777 handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001778 }
1779
James Ketrenosb095c382005-08-24 22:04:42 -05001780 if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001781 IPW_WARNING("FW_INITIALIZATION_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001782 handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001783 }
1784
James Ketrenosb095c382005-08-24 22:04:42 -05001785 if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001786 IPW_WARNING("PHY_OFF_DONE\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001787 handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001788 }
1789
James Ketrenosb095c382005-08-24 22:04:42 -05001790 if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001791 IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
1792 priv->status |= STATUS_RF_KILL_HW;
1793 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosea2b26e2005-08-24 21:25:16 -05001794 priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
James Ketrenos43f66a62005-03-25 12:31:53 -06001795 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05001796 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06001797 queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
James Ketrenosb095c382005-08-24 22:04:42 -05001798 handled |= IPW_INTA_BIT_RF_KILL_DONE;
James Ketrenos43f66a62005-03-25 12:31:53 -06001799 }
Jeff Garzikbf794512005-07-31 13:07:26 -04001800
James Ketrenosb095c382005-08-24 22:04:42 -05001801 if (inta & IPW_INTA_BIT_FATAL_ERROR) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001802 IPW_WARNING("Firmware error detected. Restarting.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001803 if (priv->error) {
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001804 IPW_DEBUG_FW("Sysfs 'error' log already exists.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001805#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001806 if (ipw_debug_level & IPW_DL_FW_ERRORS) {
1807 struct ipw_fw_error *error =
1808 ipw_alloc_error_log(priv);
1809 ipw_dump_error_log(priv, error);
1810 if (error)
1811 ipw_free_error_log(error);
1812 }
James Ketrenos43f66a62005-03-25 12:31:53 -06001813#endif
James Ketrenosb39860c2005-08-12 09:36:32 -05001814 } else {
1815 priv->error = ipw_alloc_error_log(priv);
1816 if (priv->error)
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001817 IPW_DEBUG_FW("Sysfs 'error' log captured.\n");
James Ketrenosb39860c2005-08-12 09:36:32 -05001818 else
Zhu Yi1d1b09e2006-03-02 06:40:59 +08001819 IPW_DEBUG_FW("Error allocating sysfs 'error' "
1820 "log.\n");
Brice Goglin0f52bf92005-12-01 01:41:46 -08001821#ifdef CONFIG_IPW2200_DEBUG
James Ketrenosb39860c2005-08-12 09:36:32 -05001822 if (ipw_debug_level & IPW_DL_FW_ERRORS)
1823 ipw_dump_error_log(priv, priv->error);
1824#endif
1825 }
1826
James Ketrenosb095c382005-08-24 22:04:42 -05001827 /* XXX: If hardware encryption is for WPA/WPA2,
1828 * we have to notify the supplicant. */
1829 if (priv->ieee->sec.encrypt) {
1830 priv->status &= ~STATUS_ASSOCIATED;
1831 notify_wx_assoc_event(priv);
1832 }
1833
1834 /* Keep the restart process from trying to send host
1835 * commands by clearing the INIT status bit */
1836 priv->status &= ~STATUS_INIT;
James Ketrenosafbf30a2005-08-25 00:05:33 -05001837
1838 /* Cancel currently queued command. */
1839 priv->status &= ~STATUS_HCMD_ACTIVE;
1840 wake_up_interruptible(&priv->wait_command_queue);
1841
James Ketrenos43f66a62005-03-25 12:31:53 -06001842 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenosb095c382005-08-24 22:04:42 -05001843 handled |= IPW_INTA_BIT_FATAL_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001844 }
1845
James Ketrenosb095c382005-08-24 22:04:42 -05001846 if (inta & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06001847 IPW_ERROR("Parity error\n");
James Ketrenosb095c382005-08-24 22:04:42 -05001848 handled |= IPW_INTA_BIT_PARITY_ERROR;
James Ketrenos43f66a62005-03-25 12:31:53 -06001849 }
1850
1851 if (handled != inta) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001852 IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
James Ketrenos43f66a62005-03-25 12:31:53 -06001853 }
1854
1855 /* enable all interrupts */
1856 ipw_enable_interrupts(priv);
1857
1858 spin_unlock_irqrestore(&priv->lock, flags);
1859}
Jeff Garzikbf794512005-07-31 13:07:26 -04001860
James Ketrenos43f66a62005-03-25 12:31:53 -06001861#define IPW_CMD(x) case IPW_CMD_ ## x : return #x
1862static char *get_cmd_string(u8 cmd)
1863{
1864 switch (cmd) {
1865 IPW_CMD(HOST_COMPLETE);
Jeff Garzikbf794512005-07-31 13:07:26 -04001866 IPW_CMD(POWER_DOWN);
1867 IPW_CMD(SYSTEM_CONFIG);
1868 IPW_CMD(MULTICAST_ADDRESS);
1869 IPW_CMD(SSID);
1870 IPW_CMD(ADAPTER_ADDRESS);
1871 IPW_CMD(PORT_TYPE);
1872 IPW_CMD(RTS_THRESHOLD);
1873 IPW_CMD(FRAG_THRESHOLD);
1874 IPW_CMD(POWER_MODE);
1875 IPW_CMD(WEP_KEY);
1876 IPW_CMD(TGI_TX_KEY);
1877 IPW_CMD(SCAN_REQUEST);
1878 IPW_CMD(SCAN_REQUEST_EXT);
1879 IPW_CMD(ASSOCIATE);
1880 IPW_CMD(SUPPORTED_RATES);
1881 IPW_CMD(SCAN_ABORT);
1882 IPW_CMD(TX_FLUSH);
1883 IPW_CMD(QOS_PARAMETERS);
1884 IPW_CMD(DINO_CONFIG);
1885 IPW_CMD(RSN_CAPABILITIES);
1886 IPW_CMD(RX_KEY);
1887 IPW_CMD(CARD_DISABLE);
1888 IPW_CMD(SEED_NUMBER);
1889 IPW_CMD(TX_POWER);
1890 IPW_CMD(COUNTRY_INFO);
1891 IPW_CMD(AIRONET_INFO);
1892 IPW_CMD(AP_TX_POWER);
1893 IPW_CMD(CCKM_INFO);
1894 IPW_CMD(CCX_VER_INFO);
1895 IPW_CMD(SET_CALIBRATION);
1896 IPW_CMD(SENSITIVITY_CALIB);
1897 IPW_CMD(RETRY_LIMIT);
1898 IPW_CMD(IPW_PRE_POWER_DOWN);
1899 IPW_CMD(VAP_BEACON_TEMPLATE);
1900 IPW_CMD(VAP_DTIM_PERIOD);
1901 IPW_CMD(EXT_SUPPORTED_RATES);
1902 IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
1903 IPW_CMD(VAP_QUIET_INTERVALS);
1904 IPW_CMD(VAP_CHANNEL_SWITCH);
1905 IPW_CMD(VAP_MANDATORY_CHANNELS);
1906 IPW_CMD(VAP_CELL_PWR_LIMIT);
1907 IPW_CMD(VAP_CF_PARAM_SET);
1908 IPW_CMD(VAP_SET_BEACONING_STATE);
1909 IPW_CMD(MEASUREMENT);
1910 IPW_CMD(POWER_CAPABILITY);
1911 IPW_CMD(SUPPORTED_CHANNELS);
1912 IPW_CMD(TPC_REPORT);
1913 IPW_CMD(WME_INFO);
1914 IPW_CMD(PRODUCTION_COMMAND);
1915 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06001916 return "UNKNOWN";
1917 }
1918}
James Ketrenos43f66a62005-03-25 12:31:53 -06001919
1920#define HOST_COMPLETE_TIMEOUT HZ
Zhu Yi0a7bcf22006-01-24 16:37:28 +08001921
1922static int __ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
James Ketrenos43f66a62005-03-25 12:31:53 -06001923{
1924 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05001925 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06001926
James Ketrenosa613bff2005-08-24 21:43:11 -05001927 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001928 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001929 IPW_ERROR("Failed to send %s: Already sending a command.\n",
1930 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05001931 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001932 return -EAGAIN;
James Ketrenos43f66a62005-03-25 12:31:53 -06001933 }
1934
1935 priv->status |= STATUS_HCMD_ACTIVE;
Jeff Garzikbf794512005-07-31 13:07:26 -04001936
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001937 if (priv->cmdlog) {
1938 priv->cmdlog[priv->cmdlog_pos].jiffies = jiffies;
1939 priv->cmdlog[priv->cmdlog_pos].cmd.cmd = cmd->cmd;
1940 priv->cmdlog[priv->cmdlog_pos].cmd.len = cmd->len;
1941 memcpy(priv->cmdlog[priv->cmdlog_pos].cmd.param, cmd->param,
1942 cmd->len);
1943 priv->cmdlog[priv->cmdlog_pos].retcode = -1;
1944 }
1945
James Ketrenosb095c382005-08-24 22:04:42 -05001946 IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
1947 get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
1948 priv->status);
Zhu Yif516dbc2006-01-24 16:36:44 +08001949
1950#ifndef DEBUG_CMD_WEP_KEY
1951 if (cmd->cmd == IPW_CMD_WEP_KEY)
1952 IPW_DEBUG_HC("WEP_KEY command masked out for secure.\n");
1953 else
1954#endif
1955 printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
1956
Zhu Yi0a7bcf22006-01-24 16:37:28 +08001957 rc = ipw_queue_tx_hcmd(priv, cmd->cmd, cmd->param, cmd->len, 0);
James Ketrenosa613bff2005-08-24 21:43:11 -05001958 if (rc) {
1959 priv->status &= ~STATUS_HCMD_ACTIVE;
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001960 IPW_ERROR("Failed to send %s: Reason %d\n",
1961 get_cmd_string(cmd->cmd), rc);
James Ketrenosa613bff2005-08-24 21:43:11 -05001962 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001963 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05001964 }
1965 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06001966
Jeff Garzik0edd5b42005-09-07 00:48:31 -04001967 rc = wait_event_interruptible_timeout(priv->wait_command_queue,
1968 !(priv->
1969 status & STATUS_HCMD_ACTIVE),
1970 HOST_COMPLETE_TIMEOUT);
James Ketrenos43f66a62005-03-25 12:31:53 -06001971 if (rc == 0) {
James Ketrenosa613bff2005-08-24 21:43:11 -05001972 spin_lock_irqsave(&priv->lock, flags);
1973 if (priv->status & STATUS_HCMD_ACTIVE) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001974 IPW_ERROR("Failed to send %s: Command timed out.\n",
1975 get_cmd_string(cmd->cmd));
James Ketrenosa613bff2005-08-24 21:43:11 -05001976 priv->status &= ~STATUS_HCMD_ACTIVE;
1977 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001978 rc = -EIO;
1979 goto exit;
James Ketrenosa613bff2005-08-24 21:43:11 -05001980 }
1981 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos3b9990c2005-08-19 13:18:55 -05001982 } else
1983 rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05001984
James Ketrenosb095c382005-08-24 22:04:42 -05001985 if (priv->status & STATUS_RF_KILL_HW) {
James Ketrenos9ddf84f2005-08-16 17:07:11 -05001986 IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
1987 get_cmd_string(cmd->cmd));
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001988 rc = -EIO;
1989 goto exit;
James Ketrenos43f66a62005-03-25 12:31:53 -06001990 }
1991
Zhu Yi2638bc32006-01-24 16:37:52 +08001992 exit:
James Ketrenosf6c5cb72005-08-25 00:39:09 -05001993 if (priv->cmdlog) {
1994 priv->cmdlog[priv->cmdlog_pos++].retcode = rc;
1995 priv->cmdlog_pos %= priv->cmdlog_len;
1996 }
1997 return rc;
James Ketrenos43f66a62005-03-25 12:31:53 -06001998}
1999
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002000static int ipw_send_cmd_simple(struct ipw_priv *priv, u8 command)
James Ketrenos43f66a62005-03-25 12:31:53 -06002001{
2002 struct host_cmd cmd = {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002003 .cmd = command,
James Ketrenos43f66a62005-03-25 12:31:53 -06002004 };
2005
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002006 return __ipw_send_cmd(priv, &cmd);
2007}
2008
2009static int ipw_send_cmd_pdu(struct ipw_priv *priv, u8 command, u8 len,
2010 void *data)
2011{
2012 struct host_cmd cmd = {
2013 .cmd = command,
2014 .len = len,
2015 .param = data,
2016 };
2017
2018 return __ipw_send_cmd(priv, &cmd);
2019}
2020
2021static int ipw_send_host_complete(struct ipw_priv *priv)
2022{
James Ketrenos43f66a62005-03-25 12:31:53 -06002023 if (!priv) {
2024 IPW_ERROR("Invalid args\n");
2025 return -1;
2026 }
2027
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002028 return ipw_send_cmd_simple(priv, IPW_CMD_HOST_COMPLETE);
James Ketrenos43f66a62005-03-25 12:31:53 -06002029}
2030
Jeff Garzikbf794512005-07-31 13:07:26 -04002031static int ipw_send_system_config(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06002032 struct ipw_sys_config *config)
2033{
James Ketrenos43f66a62005-03-25 12:31:53 -06002034 if (!priv || !config) {
2035 IPW_ERROR("Invalid args\n");
2036 return -1;
2037 }
2038
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002039 return ipw_send_cmd_pdu(priv, IPW_CMD_SYSTEM_CONFIG, sizeof(*config),
Zhu Yi2638bc32006-01-24 16:37:52 +08002040 config);
James Ketrenos43f66a62005-03-25 12:31:53 -06002041}
2042
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002043static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002044{
James Ketrenos43f66a62005-03-25 12:31:53 -06002045 if (!priv || !ssid) {
2046 IPW_ERROR("Invalid args\n");
2047 return -1;
2048 }
2049
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002050 return ipw_send_cmd_pdu(priv, IPW_CMD_SSID, min(len, IW_ESSID_MAX_SIZE),
Zhu Yi2638bc32006-01-24 16:37:52 +08002051 ssid);
James Ketrenos43f66a62005-03-25 12:31:53 -06002052}
2053
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002054static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002055{
James Ketrenos43f66a62005-03-25 12:31:53 -06002056 if (!priv || !mac) {
2057 IPW_ERROR("Invalid args\n");
2058 return -1;
2059 }
2060
2061 IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
2062 priv->net_dev->name, MAC_ARG(mac));
2063
Zhu Yi2638bc32006-01-24 16:37:52 +08002064 return ipw_send_cmd_pdu(priv, IPW_CMD_ADAPTER_ADDRESS, ETH_ALEN, mac);
James Ketrenos43f66a62005-03-25 12:31:53 -06002065}
2066
James Ketrenosa613bff2005-08-24 21:43:11 -05002067/*
2068 * NOTE: This must be executed from our workqueue as it results in udelay
2069 * being called which may corrupt the keyboard if executed on default
2070 * workqueue
2071 */
James Ketrenos43f66a62005-03-25 12:31:53 -06002072static void ipw_adapter_restart(void *adapter)
2073{
2074 struct ipw_priv *priv = adapter;
2075
2076 if (priv->status & STATUS_RF_KILL_MASK)
2077 return;
2078
2079 ipw_down(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002080
2081 if (priv->assoc_network &&
2082 (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
2083 ipw_remove_current_network(priv);
2084
James Ketrenos43f66a62005-03-25 12:31:53 -06002085 if (ipw_up(priv)) {
2086 IPW_ERROR("Failed to up device\n");
2087 return;
2088 }
2089}
2090
James Ketrenosc848d0a2005-08-24 21:56:24 -05002091static void ipw_bg_adapter_restart(void *data)
2092{
2093 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08002094 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002095 ipw_adapter_restart(data);
Zhu Yi46441512006-01-24 16:37:59 +08002096 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002097}
2098
James Ketrenos43f66a62005-03-25 12:31:53 -06002099#define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
2100
2101static void ipw_scan_check(void *data)
2102{
2103 struct ipw_priv *priv = data;
2104 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
2105 IPW_DEBUG_SCAN("Scan completion watchdog resetting "
Zhu Yic7b6a672006-01-24 16:37:05 +08002106 "adapter after (%dms).\n",
2107 jiffies_to_msecs(IPW_SCAN_CHECK_WATCHDOG));
James Ketrenosa613bff2005-08-24 21:43:11 -05002108 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06002109 }
2110}
2111
James Ketrenosc848d0a2005-08-24 21:56:24 -05002112static void ipw_bg_scan_check(void *data)
2113{
2114 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08002115 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002116 ipw_scan_check(data);
Zhu Yi46441512006-01-24 16:37:59 +08002117 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05002118}
2119
James Ketrenos43f66a62005-03-25 12:31:53 -06002120static int ipw_send_scan_request_ext(struct ipw_priv *priv,
2121 struct ipw_scan_request_ext *request)
2122{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002123 return ipw_send_cmd_pdu(priv, IPW_CMD_SCAN_REQUEST_EXT,
Zhu Yi2638bc32006-01-24 16:37:52 +08002124 sizeof(*request), request);
James Ketrenos43f66a62005-03-25 12:31:53 -06002125}
2126
2127static int ipw_send_scan_abort(struct ipw_priv *priv)
2128{
James Ketrenos43f66a62005-03-25 12:31:53 -06002129 if (!priv) {
2130 IPW_ERROR("Invalid args\n");
2131 return -1;
2132 }
2133
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002134 return ipw_send_cmd_simple(priv, IPW_CMD_SCAN_ABORT);
James Ketrenos43f66a62005-03-25 12:31:53 -06002135}
2136
2137static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
2138{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002139 struct ipw_sensitivity_calib calib = {
2140 .beacon_rssi_raw = sens,
James Ketrenos43f66a62005-03-25 12:31:53 -06002141 };
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002142
2143 return ipw_send_cmd_pdu(priv, IPW_CMD_SENSITIVITY_CALIB, sizeof(calib),
Zhu Yi2638bc32006-01-24 16:37:52 +08002144 &calib);
James Ketrenos43f66a62005-03-25 12:31:53 -06002145}
2146
2147static int ipw_send_associate(struct ipw_priv *priv,
2148 struct ipw_associate *associate)
2149{
James Ketrenosa613bff2005-08-24 21:43:11 -05002150 struct ipw_associate tmp_associate;
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002151
2152 if (!priv || !associate) {
2153 IPW_ERROR("Invalid args\n");
2154 return -1;
2155 }
2156
James Ketrenosa613bff2005-08-24 21:43:11 -05002157 memcpy(&tmp_associate, associate, sizeof(*associate));
2158 tmp_associate.policy_support =
2159 cpu_to_le16(tmp_associate.policy_support);
2160 tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
2161 tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
2162 tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
2163 tmp_associate.listen_interval =
2164 cpu_to_le16(tmp_associate.listen_interval);
2165 tmp_associate.beacon_interval =
2166 cpu_to_le16(tmp_associate.beacon_interval);
2167 tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
2168
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002169 return ipw_send_cmd_pdu(priv, IPW_CMD_ASSOCIATE, sizeof(tmp_associate),
Zhu Yi2638bc32006-01-24 16:37:52 +08002170 &tmp_associate);
James Ketrenos43f66a62005-03-25 12:31:53 -06002171}
2172
2173static int ipw_send_supported_rates(struct ipw_priv *priv,
2174 struct ipw_supported_rates *rates)
2175{
James Ketrenos43f66a62005-03-25 12:31:53 -06002176 if (!priv || !rates) {
2177 IPW_ERROR("Invalid args\n");
2178 return -1;
2179 }
2180
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002181 return ipw_send_cmd_pdu(priv, IPW_CMD_SUPPORTED_RATES, sizeof(*rates),
Zhu Yi2638bc32006-01-24 16:37:52 +08002182 rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06002183}
2184
2185static int ipw_set_random_seed(struct ipw_priv *priv)
2186{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002187 u32 val;
James Ketrenos43f66a62005-03-25 12:31:53 -06002188
2189 if (!priv) {
2190 IPW_ERROR("Invalid args\n");
2191 return -1;
2192 }
2193
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002194 get_random_bytes(&val, sizeof(val));
James Ketrenos43f66a62005-03-25 12:31:53 -06002195
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002196 return ipw_send_cmd_pdu(priv, IPW_CMD_SEED_NUMBER, sizeof(val), &val);
James Ketrenos43f66a62005-03-25 12:31:53 -06002197}
2198
James Ketrenos43f66a62005-03-25 12:31:53 -06002199static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
2200{
James Ketrenos43f66a62005-03-25 12:31:53 -06002201 if (!priv) {
2202 IPW_ERROR("Invalid args\n");
2203 return -1;
2204 }
2205
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002206 return ipw_send_cmd_pdu(priv, IPW_CMD_CARD_DISABLE, sizeof(phy_off),
Zhu Yi2638bc32006-01-24 16:37:52 +08002207 &phy_off);
James Ketrenos43f66a62005-03-25 12:31:53 -06002208}
James Ketrenos43f66a62005-03-25 12:31:53 -06002209
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002210static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
James Ketrenos43f66a62005-03-25 12:31:53 -06002211{
James Ketrenos43f66a62005-03-25 12:31:53 -06002212 if (!priv || !power) {
2213 IPW_ERROR("Invalid args\n");
2214 return -1;
2215 }
2216
Zhu Yi2638bc32006-01-24 16:37:52 +08002217 return ipw_send_cmd_pdu(priv, IPW_CMD_TX_POWER, sizeof(*power), power);
James Ketrenos43f66a62005-03-25 12:31:53 -06002218}
James Ketrenos43f66a62005-03-25 12:31:53 -06002219
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002220static int ipw_set_tx_power(struct ipw_priv *priv)
2221{
Larry Finger1867b112006-02-28 09:48:28 -06002222 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08002223 struct ipw_tx_power tx_power;
2224 s8 max_power;
2225 int i;
2226
2227 memset(&tx_power, 0, sizeof(tx_power));
2228
2229 /* configure device for 'G' band */
2230 tx_power.ieee_mode = IPW_G_MODE;
2231 tx_power.num_channels = geo->bg_channels;
2232 for (i = 0; i < geo->bg_channels; i++) {
2233 max_power = geo->bg[i].max_power;
2234 tx_power.channels_tx_power[i].channel_number =
2235 geo->bg[i].channel;
2236 tx_power.channels_tx_power[i].tx_power = max_power ?
2237 min(max_power, priv->tx_power) : priv->tx_power;
2238 }
2239 if (ipw_send_tx_power(priv, &tx_power))
2240 return -EIO;
2241
2242 /* configure device to also handle 'B' band */
2243 tx_power.ieee_mode = IPW_B_MODE;
2244 if (ipw_send_tx_power(priv, &tx_power))
2245 return -EIO;
2246
2247 /* configure device to also handle 'A' band */
2248 if (priv->ieee->abg_true) {
2249 tx_power.ieee_mode = IPW_A_MODE;
2250 tx_power.num_channels = geo->a_channels;
2251 for (i = 0; i < tx_power.num_channels; i++) {
2252 max_power = geo->a[i].max_power;
2253 tx_power.channels_tx_power[i].channel_number =
2254 geo->a[i].channel;
2255 tx_power.channels_tx_power[i].tx_power = max_power ?
2256 min(max_power, priv->tx_power) : priv->tx_power;
2257 }
2258 if (ipw_send_tx_power(priv, &tx_power))
2259 return -EIO;
2260 }
James Ketrenos43f66a62005-03-25 12:31:53 -06002261 return 0;
2262}
2263
2264static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
2265{
2266 struct ipw_rts_threshold rts_threshold = {
2267 .rts_threshold = rts,
2268 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002269
2270 if (!priv) {
2271 IPW_ERROR("Invalid args\n");
2272 return -1;
2273 }
2274
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002275 return ipw_send_cmd_pdu(priv, IPW_CMD_RTS_THRESHOLD,
2276 sizeof(rts_threshold), &rts_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002277}
2278
2279static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
2280{
2281 struct ipw_frag_threshold frag_threshold = {
2282 .frag_threshold = frag,
2283 };
James Ketrenos43f66a62005-03-25 12:31:53 -06002284
2285 if (!priv) {
2286 IPW_ERROR("Invalid args\n");
2287 return -1;
2288 }
2289
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002290 return ipw_send_cmd_pdu(priv, IPW_CMD_FRAG_THRESHOLD,
2291 sizeof(frag_threshold), &frag_threshold);
James Ketrenos43f66a62005-03-25 12:31:53 -06002292}
2293
2294static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
2295{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002296 u32 param;
James Ketrenos43f66a62005-03-25 12:31:53 -06002297
2298 if (!priv) {
2299 IPW_ERROR("Invalid args\n");
2300 return -1;
2301 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002302
James Ketrenos43f66a62005-03-25 12:31:53 -06002303 /* If on battery, set to 3, if AC set to CAM, else user
2304 * level */
2305 switch (mode) {
2306 case IPW_POWER_BATTERY:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002307 param = IPW_POWER_INDEX_3;
James Ketrenos43f66a62005-03-25 12:31:53 -06002308 break;
2309 case IPW_POWER_AC:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002310 param = IPW_POWER_MODE_CAM;
James Ketrenos43f66a62005-03-25 12:31:53 -06002311 break;
2312 default:
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002313 param = mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06002314 break;
2315 }
2316
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002317 return ipw_send_cmd_pdu(priv, IPW_CMD_POWER_MODE, sizeof(param),
Zhu Yi2638bc32006-01-24 16:37:52 +08002318 &param);
James Ketrenos43f66a62005-03-25 12:31:53 -06002319}
2320
James Ketrenosafbf30a2005-08-25 00:05:33 -05002321static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
2322{
2323 struct ipw_retry_limit retry_limit = {
2324 .short_retry_limit = slimit,
2325 .long_retry_limit = llimit
2326 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05002327
2328 if (!priv) {
2329 IPW_ERROR("Invalid args\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002330 return -1;
2331 }
2332
Zhu Yi0a7bcf22006-01-24 16:37:28 +08002333 return ipw_send_cmd_pdu(priv, IPW_CMD_RETRY_LIMIT, sizeof(retry_limit),
Zhu Yi2638bc32006-01-24 16:37:52 +08002334 &retry_limit);
James Ketrenos43f66a62005-03-25 12:31:53 -06002335}
2336
2337/*
2338 * The IPW device contains a Microwire compatible EEPROM that stores
2339 * various data like the MAC address. Usually the firmware has exclusive
2340 * access to the eeprom, but during device initialization (before the
2341 * device driver has sent the HostComplete command to the firmware) the
2342 * device driver has read access to the EEPROM by way of indirect addressing
2343 * through a couple of memory mapped registers.
2344 *
2345 * The following is a simplified implementation for pulling data out of the
2346 * the eeprom, along with some helper functions to find information in
2347 * the per device private data's copy of the eeprom.
2348 *
2349 * NOTE: To better understand how these functions work (i.e what is a chip
2350 * select and why do have to keep driving the eeprom clock?), read
2351 * just about any data sheet for a Microwire compatible EEPROM.
2352 */
2353
2354/* write a 32 bit value into the indirect accessor register */
2355static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
2356{
2357 ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
Jeff Garzikbf794512005-07-31 13:07:26 -04002358
James Ketrenos43f66a62005-03-25 12:31:53 -06002359 /* the eeprom requires some time to complete the operation */
2360 udelay(p->eeprom_delay);
2361
2362 return;
2363}
2364
2365/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002366static void eeprom_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002367{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002368 eeprom_write_reg(priv, 0);
2369 eeprom_write_reg(priv, EEPROM_BIT_CS);
2370 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2371 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002372}
2373
2374/* perform a chip select operation */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002375static void eeprom_disable_cs(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002376{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002377 eeprom_write_reg(priv, EEPROM_BIT_CS);
2378 eeprom_write_reg(priv, 0);
2379 eeprom_write_reg(priv, EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002380}
2381
2382/* push a single bit down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002383static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
James Ketrenos43f66a62005-03-25 12:31:53 -06002384{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002385 int d = (bit ? EEPROM_BIT_DI : 0);
2386 eeprom_write_reg(p, EEPROM_BIT_CS | d);
2387 eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
James Ketrenos43f66a62005-03-25 12:31:53 -06002388}
2389
2390/* push an opcode followed by an address down to the eeprom */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002391static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002392{
2393 int i;
2394
2395 eeprom_cs(priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002396 eeprom_write_bit(priv, 1);
2397 eeprom_write_bit(priv, op & 2);
2398 eeprom_write_bit(priv, op & 1);
2399 for (i = 7; i >= 0; i--) {
2400 eeprom_write_bit(priv, addr & (1 << i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002401 }
2402}
2403
2404/* pull 16 bits off the eeprom, one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002405static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
James Ketrenos43f66a62005-03-25 12:31:53 -06002406{
2407 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002408 u16 r = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002409
James Ketrenos43f66a62005-03-25 12:31:53 -06002410 /* Send READ Opcode */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002411 eeprom_op(priv, EEPROM_CMD_READ, addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06002412
2413 /* Send dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002414 eeprom_write_reg(priv, EEPROM_BIT_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002415
2416 /* Read the byte off the eeprom one bit at a time */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002417 for (i = 0; i < 16; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002418 u32 data = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002419 eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
2420 eeprom_write_reg(priv, EEPROM_BIT_CS);
2421 data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
2422 r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002423 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002424
James Ketrenos43f66a62005-03-25 12:31:53 -06002425 /* Send another dummy bit */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002426 eeprom_write_reg(priv, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002427 eeprom_disable_cs(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002428
James Ketrenos43f66a62005-03-25 12:31:53 -06002429 return r;
2430}
2431
2432/* helper function for pulling the mac address out of the private */
2433/* data's copy of the eeprom data */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002434static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
James Ketrenos43f66a62005-03-25 12:31:53 -06002435{
James Ketrenosafbf30a2005-08-25 00:05:33 -05002436 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
James Ketrenos43f66a62005-03-25 12:31:53 -06002437}
2438
2439/*
2440 * Either the device driver (i.e. the host) or the firmware can
2441 * load eeprom data into the designated region in SRAM. If neither
2442 * happens then the FW will shutdown with a fatal error.
2443 *
2444 * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
2445 * bit needs region of shared SRAM needs to be non-zero.
2446 */
2447static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2448{
2449 int i;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002450 u16 *eeprom = (u16 *) priv->eeprom;
Jeff Garzikbf794512005-07-31 13:07:26 -04002451
James Ketrenos43f66a62005-03-25 12:31:53 -06002452 IPW_DEBUG_TRACE(">>\n");
2453
2454 /* read entire contents of eeprom into private buffer */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002455 for (i = 0; i < 128; i++)
James Ketrenosa613bff2005-08-24 21:43:11 -05002456 eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
James Ketrenos43f66a62005-03-25 12:31:53 -06002457
Jeff Garzikbf794512005-07-31 13:07:26 -04002458 /*
2459 If the data looks correct, then copy it to our private
James Ketrenos43f66a62005-03-25 12:31:53 -06002460 copy. Otherwise let the firmware know to perform the operation
Zhu Yic7b6a672006-01-24 16:37:05 +08002461 on its own.
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002462 */
Alexey Dobriyan386093e2006-02-01 03:04:57 -08002463 if (priv->eeprom[EEPROM_VERSION] != 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002464 IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
2465
2466 /* write the eeprom data to sram */
James Ketrenosb095c382005-08-24 22:04:42 -05002467 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002468 ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002469
2470 /* Do not load eeprom data on fatal error or suspend */
2471 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
2472 } else {
2473 IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
2474
2475 /* Load eeprom data on fatal error or suspend */
2476 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
2477 }
2478
2479 IPW_DEBUG_TRACE("<<\n");
2480}
2481
Arjan van de Ven858119e2006-01-14 13:20:43 -08002482static void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
James Ketrenos43f66a62005-03-25 12:31:53 -06002483{
2484 count >>= 2;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002485 if (!count)
2486 return;
James Ketrenosb095c382005-08-24 22:04:42 -05002487 _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
Jeff Garzikbf794512005-07-31 13:07:26 -04002488 while (count--)
James Ketrenosb095c382005-08-24 22:04:42 -05002489 _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002490}
2491
2492static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
2493{
James Ketrenosb095c382005-08-24 22:04:42 -05002494 ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
Jeff Garzikbf794512005-07-31 13:07:26 -04002495 CB_NUMBER_OF_ELEMENTS_SMALL *
James Ketrenos43f66a62005-03-25 12:31:53 -06002496 sizeof(struct command_block));
2497}
2498
2499static int ipw_fw_dma_enable(struct ipw_priv *priv)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002500{ /* start dma engine but no transfers yet */
James Ketrenos43f66a62005-03-25 12:31:53 -06002501
2502 IPW_DEBUG_FW(">> : \n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002503
James Ketrenos43f66a62005-03-25 12:31:53 -06002504 /* Start the dma */
2505 ipw_fw_dma_reset_command_blocks(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04002506
James Ketrenos43f66a62005-03-25 12:31:53 -06002507 /* Write CB base address */
James Ketrenosb095c382005-08-24 22:04:42 -05002508 ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
James Ketrenos43f66a62005-03-25 12:31:53 -06002509
2510 IPW_DEBUG_FW("<< : \n");
2511 return 0;
2512}
2513
2514static void ipw_fw_dma_abort(struct ipw_priv *priv)
2515{
2516 u32 control = 0;
2517
2518 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002519
2520 //set the Stop and Abort bit
James Ketrenos43f66a62005-03-25 12:31:53 -06002521 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
James Ketrenosb095c382005-08-24 22:04:42 -05002522 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002523 priv->sram_desc.last_cb_index = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04002524
James Ketrenos43f66a62005-03-25 12:31:53 -06002525 IPW_DEBUG_FW("<< \n");
2526}
2527
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002528static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
2529 struct command_block *cb)
James Ketrenos43f66a62005-03-25 12:31:53 -06002530{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002531 u32 address =
James Ketrenosb095c382005-08-24 22:04:42 -05002532 IPW_SHARED_SRAM_DMA_CONTROL +
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002533 (sizeof(struct command_block) * index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002534 IPW_DEBUG_FW(">> :\n");
2535
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002536 ipw_write_indirect(priv, address, (u8 *) cb,
2537 (int)sizeof(struct command_block));
James Ketrenos43f66a62005-03-25 12:31:53 -06002538
2539 IPW_DEBUG_FW("<< :\n");
2540 return 0;
2541
2542}
2543
2544static int ipw_fw_dma_kick(struct ipw_priv *priv)
2545{
2546 u32 control = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002547 u32 index = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002548
2549 IPW_DEBUG_FW(">> :\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04002550
James Ketrenos43f66a62005-03-25 12:31:53 -06002551 for (index = 0; index < priv->sram_desc.last_cb_index; index++)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002552 ipw_fw_dma_write_command_block(priv, index,
2553 &priv->sram_desc.cb_list[index]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002554
2555 /* Enable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002556 ipw_clear_bit(priv, IPW_RESET_REG,
2557 IPW_RESET_REG_MASTER_DISABLED |
2558 IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04002559
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002560 /* Set the Start bit. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002561 control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
James Ketrenosb095c382005-08-24 22:04:42 -05002562 ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
James Ketrenos43f66a62005-03-25 12:31:53 -06002563
2564 IPW_DEBUG_FW("<< :\n");
2565 return 0;
2566}
2567
2568static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
2569{
2570 u32 address;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002571 u32 register_value = 0;
2572 u32 cb_fields_address = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002573
2574 IPW_DEBUG_FW(">> :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002575 address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002576 IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002577
2578 /* Read the DMA Controlor register */
James Ketrenosb095c382005-08-24 22:04:42 -05002579 register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
2580 IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002581
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002582 /* Print the CB values */
James Ketrenos43f66a62005-03-25 12:31:53 -06002583 cb_fields_address = address;
2584 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002585 IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002586
2587 cb_fields_address += sizeof(u32);
2588 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002589 IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002590
2591 cb_fields_address += sizeof(u32);
2592 register_value = ipw_read_reg32(priv, cb_fields_address);
2593 IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
2594 register_value);
2595
2596 cb_fields_address += sizeof(u32);
2597 register_value = ipw_read_reg32(priv, cb_fields_address);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002598 IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
James Ketrenos43f66a62005-03-25 12:31:53 -06002599
2600 IPW_DEBUG_FW(">> :\n");
2601}
2602
2603static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
2604{
2605 u32 current_cb_address = 0;
2606 u32 current_cb_index = 0;
2607
2608 IPW_DEBUG_FW("<< :\n");
James Ketrenosb095c382005-08-24 22:04:42 -05002609 current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
Jeff Garzikbf794512005-07-31 13:07:26 -04002610
James Ketrenosb095c382005-08-24 22:04:42 -05002611 current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002612 sizeof(struct command_block);
Jeff Garzikbf794512005-07-31 13:07:26 -04002613
James Ketrenos43f66a62005-03-25 12:31:53 -06002614 IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002615 current_cb_index, current_cb_address);
James Ketrenos43f66a62005-03-25 12:31:53 -06002616
2617 IPW_DEBUG_FW(">> :\n");
2618 return current_cb_index;
2619
2620}
2621
2622static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
2623 u32 src_address,
2624 u32 dest_address,
2625 u32 length,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002626 int interrupt_enabled, int is_last)
James Ketrenos43f66a62005-03-25 12:31:53 -06002627{
2628
Jeff Garzikbf794512005-07-31 13:07:26 -04002629 u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002630 CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
2631 CB_DEST_SIZE_LONG;
James Ketrenos43f66a62005-03-25 12:31:53 -06002632 struct command_block *cb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002633 u32 last_cb_element = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002634
2635 IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
2636 src_address, dest_address, length);
2637
2638 if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
2639 return -1;
2640
2641 last_cb_element = priv->sram_desc.last_cb_index;
2642 cb = &priv->sram_desc.cb_list[last_cb_element];
2643 priv->sram_desc.last_cb_index++;
2644
2645 /* Calculate the new CB control word */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002646 if (interrupt_enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -06002647 control |= CB_INT_ENABLED;
2648
2649 if (is_last)
2650 control |= CB_LAST_VALID;
Jeff Garzikbf794512005-07-31 13:07:26 -04002651
James Ketrenos43f66a62005-03-25 12:31:53 -06002652 control |= length;
2653
2654 /* Calculate the CB Element's checksum value */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002655 cb->status = control ^ src_address ^ dest_address;
James Ketrenos43f66a62005-03-25 12:31:53 -06002656
2657 /* Copy the Source and Destination addresses */
2658 cb->dest_addr = dest_address;
2659 cb->source_addr = src_address;
2660
2661 /* Copy the Control Word last */
2662 cb->control = control;
2663
2664 return 0;
2665}
2666
2667static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002668 u32 src_phys, u32 dest_address, u32 length)
James Ketrenos43f66a62005-03-25 12:31:53 -06002669{
2670 u32 bytes_left = length;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002671 u32 src_offset = 0;
2672 u32 dest_offset = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06002673 int status = 0;
2674 IPW_DEBUG_FW(">> \n");
2675 IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
2676 src_phys, dest_address, length);
2677 while (bytes_left > CB_MAX_LENGTH) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002678 status = ipw_fw_dma_add_command_block(priv,
2679 src_phys + src_offset,
2680 dest_address +
2681 dest_offset,
2682 CB_MAX_LENGTH, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002683 if (status) {
2684 IPW_DEBUG_FW_INFO(": Failed\n");
2685 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002686 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06002687 IPW_DEBUG_FW_INFO(": Added new cb\n");
2688
2689 src_offset += CB_MAX_LENGTH;
2690 dest_offset += CB_MAX_LENGTH;
2691 bytes_left -= CB_MAX_LENGTH;
2692 }
2693
2694 /* add the buffer tail */
2695 if (bytes_left > 0) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002696 status =
2697 ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
2698 dest_address + dest_offset,
2699 bytes_left, 0, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002700 if (status) {
2701 IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
2702 return -1;
Jeff Garzikbf794512005-07-31 13:07:26 -04002703 } else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002704 IPW_DEBUG_FW_INFO
2705 (": Adding new cb - the buffer tail\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002706 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002707
James Ketrenos43f66a62005-03-25 12:31:53 -06002708 IPW_DEBUG_FW("<< \n");
2709 return 0;
2710}
2711
2712static int ipw_fw_dma_wait(struct ipw_priv *priv)
2713{
Zhu Yi397ae122006-01-24 16:37:22 +08002714 u32 current_index = 0, previous_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002715 u32 watchdog = 0;
2716
2717 IPW_DEBUG_FW(">> : \n");
2718
2719 current_index = ipw_fw_dma_command_block_index(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08002720 IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%08X\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002721 (int)priv->sram_desc.last_cb_index);
James Ketrenos43f66a62005-03-25 12:31:53 -06002722
2723 while (current_index < priv->sram_desc.last_cb_index) {
2724 udelay(50);
Zhu Yi397ae122006-01-24 16:37:22 +08002725 previous_index = current_index;
James Ketrenos43f66a62005-03-25 12:31:53 -06002726 current_index = ipw_fw_dma_command_block_index(priv);
2727
Zhu Yi397ae122006-01-24 16:37:22 +08002728 if (previous_index < current_index) {
2729 watchdog = 0;
2730 continue;
2731 }
2732 if (++watchdog > 400) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002733 IPW_DEBUG_FW_INFO("Timeout\n");
2734 ipw_fw_dma_dump_command_block(priv);
2735 ipw_fw_dma_abort(priv);
2736 return -1;
2737 }
2738 }
2739
2740 ipw_fw_dma_abort(priv);
2741
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002742 /*Disable the DMA in the CSR register */
James Ketrenosb095c382005-08-24 22:04:42 -05002743 ipw_set_bit(priv, IPW_RESET_REG,
2744 IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002745
2746 IPW_DEBUG_FW("<< dmaWaitSync \n");
2747 return 0;
2748}
2749
Jeff Garzikbf794512005-07-31 13:07:26 -04002750static void ipw_remove_current_network(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002751{
2752 struct list_head *element, *safe;
Jeff Garzikbf794512005-07-31 13:07:26 -04002753 struct ieee80211_network *network = NULL;
James Ketrenosa613bff2005-08-24 21:43:11 -05002754 unsigned long flags;
2755
2756 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002757 list_for_each_safe(element, safe, &priv->ieee->network_list) {
2758 network = list_entry(element, struct ieee80211_network, list);
2759 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
2760 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04002761 list_add_tail(&network->list,
James Ketrenos43f66a62005-03-25 12:31:53 -06002762 &priv->ieee->network_free_list);
2763 }
2764 }
James Ketrenosa613bff2005-08-24 21:43:11 -05002765 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002766}
2767
2768/**
Jeff Garzikbf794512005-07-31 13:07:26 -04002769 * Check that card is still alive.
James Ketrenos43f66a62005-03-25 12:31:53 -06002770 * Reads debug register from domain0.
2771 * If card is present, pre-defined value should
2772 * be found there.
Jeff Garzikbf794512005-07-31 13:07:26 -04002773 *
James Ketrenos43f66a62005-03-25 12:31:53 -06002774 * @param priv
2775 * @return 1 if card is present, 0 otherwise
2776 */
2777static inline int ipw_alive(struct ipw_priv *priv)
2778{
2779 return ipw_read32(priv, 0x90) == 0xd55555d5;
2780}
2781
Zhu Yic7b6a672006-01-24 16:37:05 +08002782/* timeout in msec, attempted in 10-msec quanta */
Arjan van de Ven858119e2006-01-14 13:20:43 -08002783static int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
James Ketrenos43f66a62005-03-25 12:31:53 -06002784 int timeout)
2785{
2786 int i = 0;
2787
2788 do {
Jeff Garzikbf794512005-07-31 13:07:26 -04002789 if ((ipw_read32(priv, addr) & mask) == mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06002790 return i;
2791 mdelay(10);
2792 i += 10;
2793 } while (i < timeout);
Jeff Garzikbf794512005-07-31 13:07:26 -04002794
James Ketrenos43f66a62005-03-25 12:31:53 -06002795 return -ETIME;
2796}
2797
Jeff Garzikbf794512005-07-31 13:07:26 -04002798/* These functions load the firmware and micro code for the operation of
James Ketrenos43f66a62005-03-25 12:31:53 -06002799 * the ipw hardware. It assumes the buffer has all the bits for the
2800 * image and the caller is handling the memory allocation and clean up.
2801 */
2802
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002803static int ipw_stop_master(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06002804{
2805 int rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002806
James Ketrenos43f66a62005-03-25 12:31:53 -06002807 IPW_DEBUG_TRACE(">> \n");
2808 /* stop master. typical delay - 0 */
James Ketrenosb095c382005-08-24 22:04:42 -05002809 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06002810
Zhu Yic7b6a672006-01-24 16:37:05 +08002811 /* timeout is in msec, polled in 10-msec quanta */
James Ketrenosb095c382005-08-24 22:04:42 -05002812 rc = ipw_poll_bit(priv, IPW_RESET_REG,
2813 IPW_RESET_REG_MASTER_DISABLED, 100);
James Ketrenos43f66a62005-03-25 12:31:53 -06002814 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08002815 IPW_ERROR("wait for stop master failed after 100ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06002816 return -1;
2817 }
2818
2819 IPW_DEBUG_INFO("stop master %dms\n", rc);
2820
2821 return rc;
2822}
2823
2824static void ipw_arc_release(struct ipw_priv *priv)
2825{
2826 IPW_DEBUG_TRACE(">> \n");
2827 mdelay(5);
2828
James Ketrenosb095c382005-08-24 22:04:42 -05002829 ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06002830
2831 /* no one knows timing, for safety add some delay */
2832 mdelay(5);
2833}
2834
James Ketrenos43f66a62005-03-25 12:31:53 -06002835struct fw_chunk {
2836 u32 address;
2837 u32 length;
2838};
2839
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002840static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002841{
2842 int rc = 0, i, addr;
2843 u8 cr = 0;
2844 u16 *image;
2845
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002846 image = (u16 *) data;
Jeff Garzikbf794512005-07-31 13:07:26 -04002847
James Ketrenos43f66a62005-03-25 12:31:53 -06002848 IPW_DEBUG_TRACE(">> \n");
2849
2850 rc = ipw_stop_master(priv);
2851
2852 if (rc < 0)
2853 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04002854
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002855// spin_lock_irqsave(&priv->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04002856
James Ketrenosb095c382005-08-24 22:04:42 -05002857 for (addr = IPW_SHARED_LOWER_BOUND;
2858 addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
James Ketrenos43f66a62005-03-25 12:31:53 -06002859 ipw_write32(priv, addr, 0);
2860 }
2861
2862 /* no ucode (yet) */
2863 memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
2864 /* destroy DMA queues */
2865 /* reset sequence */
2866
James Ketrenosb095c382005-08-24 22:04:42 -05002867 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
James Ketrenos43f66a62005-03-25 12:31:53 -06002868 ipw_arc_release(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05002869 ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
James Ketrenos43f66a62005-03-25 12:31:53 -06002870 mdelay(1);
2871
2872 /* reset PHY */
James Ketrenosb095c382005-08-24 22:04:42 -05002873 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
James Ketrenos43f66a62005-03-25 12:31:53 -06002874 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002875
James Ketrenosb095c382005-08-24 22:04:42 -05002876 ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002877 mdelay(1);
Jeff Garzikbf794512005-07-31 13:07:26 -04002878
James Ketrenos43f66a62005-03-25 12:31:53 -06002879 /* enable ucode store */
Zhu Yic8fe6672006-01-24 16:36:36 +08002880 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0x0);
2881 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_CS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002882 mdelay(1);
2883
2884 /* write ucode */
2885 /**
2886 * @bug
2887 * Do NOT set indirect address register once and then
2888 * store data to indirect data register in the loop.
2889 * It seems very reasonable, but in this case DINO do not
2890 * accept ucode. It is essential to set address each time.
2891 */
2892 /* load new ipw uCode */
2893 for (i = 0; i < len / 2; i++)
James Ketrenosb095c382005-08-24 22:04:42 -05002894 ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
James Ketrenosa613bff2005-08-24 21:43:11 -05002895 cpu_to_le16(image[i]));
James Ketrenos43f66a62005-03-25 12:31:53 -06002896
James Ketrenos43f66a62005-03-25 12:31:53 -06002897 /* enable DINO */
James Ketrenosb095c382005-08-24 22:04:42 -05002898 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
2899 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
James Ketrenos43f66a62005-03-25 12:31:53 -06002900
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002901 /* this is where the igx / win driver deveates from the VAP driver. */
James Ketrenos43f66a62005-03-25 12:31:53 -06002902
2903 /* wait for alive response */
2904 for (i = 0; i < 100; i++) {
2905 /* poll for incoming data */
James Ketrenosb095c382005-08-24 22:04:42 -05002906 cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
James Ketrenos43f66a62005-03-25 12:31:53 -06002907 if (cr & DINO_RXFIFO_DATA)
2908 break;
2909 mdelay(1);
2910 }
2911
2912 if (cr & DINO_RXFIFO_DATA) {
2913 /* alive_command_responce size is NOT multiple of 4 */
2914 u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
Jeff Garzikbf794512005-07-31 13:07:26 -04002915
2916 for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06002917 response_buffer[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05002918 le32_to_cpu(ipw_read_reg32(priv,
James Ketrenosb095c382005-08-24 22:04:42 -05002919 IPW_BASEBAND_RX_FIFO_READ));
James Ketrenos43f66a62005-03-25 12:31:53 -06002920 memcpy(&priv->dino_alive, response_buffer,
2921 sizeof(priv->dino_alive));
2922 if (priv->dino_alive.alive_command == 1
2923 && priv->dino_alive.ucode_valid == 1) {
2924 rc = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002925 IPW_DEBUG_INFO
2926 ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
2927 "of %02d/%02d/%02d %02d:%02d\n",
2928 priv->dino_alive.software_revision,
2929 priv->dino_alive.software_revision,
2930 priv->dino_alive.device_identifier,
2931 priv->dino_alive.device_identifier,
2932 priv->dino_alive.time_stamp[0],
2933 priv->dino_alive.time_stamp[1],
2934 priv->dino_alive.time_stamp[2],
2935 priv->dino_alive.time_stamp[3],
2936 priv->dino_alive.time_stamp[4]);
James Ketrenos43f66a62005-03-25 12:31:53 -06002937 } else {
2938 IPW_DEBUG_INFO("Microcode is not alive\n");
2939 rc = -EINVAL;
2940 }
2941 } else {
2942 IPW_DEBUG_INFO("No alive response from DINO\n");
2943 rc = -ETIME;
2944 }
2945
2946 /* disable DINO, otherwise for some reason
2947 firmware have problem getting alive resp. */
James Ketrenosb095c382005-08-24 22:04:42 -05002948 ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06002949
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002950// spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06002951
2952 return rc;
2953}
2954
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002955static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
James Ketrenos43f66a62005-03-25 12:31:53 -06002956{
2957 int rc = -1;
2958 int offset = 0;
2959 struct fw_chunk *chunk;
2960 dma_addr_t shared_phys;
2961 u8 *shared_virt;
2962
2963 IPW_DEBUG_TRACE("<< : \n");
2964 shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
2965
2966 if (!shared_virt)
2967 return -ENOMEM;
2968
2969 memmove(shared_virt, data, len);
2970
2971 /* Start the Dma */
2972 rc = ipw_fw_dma_enable(priv);
2973
2974 if (priv->sram_desc.last_cb_index > 0) {
2975 /* the DMA is already ready this would be a bug. */
2976 BUG();
2977 goto out;
2978 }
2979
2980 do {
2981 chunk = (struct fw_chunk *)(data + offset);
2982 offset += sizeof(struct fw_chunk);
2983 /* build DMA packet and queue up for sending */
Jeff Garzikbf794512005-07-31 13:07:26 -04002984 /* dma to chunk->address, the chunk->length bytes from data +
James Ketrenos43f66a62005-03-25 12:31:53 -06002985 * offeset*/
2986 /* Dma loading */
2987 rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
James Ketrenosa613bff2005-08-24 21:43:11 -05002988 le32_to_cpu(chunk->address),
2989 le32_to_cpu(chunk->length));
James Ketrenos43f66a62005-03-25 12:31:53 -06002990 if (rc) {
2991 IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
2992 goto out;
2993 }
Jeff Garzikbf794512005-07-31 13:07:26 -04002994
James Ketrenosa613bff2005-08-24 21:43:11 -05002995 offset += le32_to_cpu(chunk->length);
James Ketrenos43f66a62005-03-25 12:31:53 -06002996 } while (offset < len);
2997
Jeff Garzik0edd5b42005-09-07 00:48:31 -04002998 /* Run the DMA and wait for the answer */
James Ketrenos43f66a62005-03-25 12:31:53 -06002999 rc = ipw_fw_dma_kick(priv);
3000 if (rc) {
3001 IPW_ERROR("dmaKick Failed\n");
3002 goto out;
3003 }
3004
3005 rc = ipw_fw_dma_wait(priv);
3006 if (rc) {
3007 IPW_ERROR("dmaWaitSync Failed\n");
3008 goto out;
3009 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003010 out:
3011 pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
James Ketrenos43f66a62005-03-25 12:31:53 -06003012 return rc;
3013}
3014
3015/* stop nic */
3016static int ipw_stop_nic(struct ipw_priv *priv)
3017{
3018 int rc = 0;
3019
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003020 /* stop */
James Ketrenosb095c382005-08-24 22:04:42 -05003021 ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
Jeff Garzikbf794512005-07-31 13:07:26 -04003022
James Ketrenosb095c382005-08-24 22:04:42 -05003023 rc = ipw_poll_bit(priv, IPW_RESET_REG,
3024 IPW_RESET_REG_MASTER_DISABLED, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003025 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003026 IPW_ERROR("wait for reg master disabled failed after 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003027 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003028 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003029
James Ketrenosb095c382005-08-24 22:04:42 -05003030 ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003031
James Ketrenos43f66a62005-03-25 12:31:53 -06003032 return rc;
3033}
3034
3035static void ipw_start_nic(struct ipw_priv *priv)
3036{
3037 IPW_DEBUG_TRACE(">>\n");
3038
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003039 /* prvHwStartNic release ARC */
James Ketrenosb095c382005-08-24 22:04:42 -05003040 ipw_clear_bit(priv, IPW_RESET_REG,
3041 IPW_RESET_REG_MASTER_DISABLED |
3042 IPW_RESET_REG_STOP_MASTER |
James Ketrenos43f66a62005-03-25 12:31:53 -06003043 CBD_RESET_REG_PRINCETON_RESET);
Jeff Garzikbf794512005-07-31 13:07:26 -04003044
James Ketrenos43f66a62005-03-25 12:31:53 -06003045 /* enable power management */
James Ketrenosb095c382005-08-24 22:04:42 -05003046 ipw_set_bit(priv, IPW_GP_CNTRL_RW,
3047 IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
James Ketrenos43f66a62005-03-25 12:31:53 -06003048
3049 IPW_DEBUG_TRACE("<<\n");
3050}
Jeff Garzikbf794512005-07-31 13:07:26 -04003051
James Ketrenos43f66a62005-03-25 12:31:53 -06003052static int ipw_init_nic(struct ipw_priv *priv)
3053{
3054 int rc;
3055
3056 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003057 /* reset */
James Ketrenos43f66a62005-03-25 12:31:53 -06003058 /*prvHwInitNic */
3059 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003060 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003061
3062 /* low-level PLL activation */
James Ketrenosb095c382005-08-24 22:04:42 -05003063 ipw_write32(priv, IPW_READ_INT_REGISTER,
3064 IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
James Ketrenos43f66a62005-03-25 12:31:53 -06003065
3066 /* wait for clock stabilization */
James Ketrenosb095c382005-08-24 22:04:42 -05003067 rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
3068 IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003069 if (rc < 0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003070 IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
3071
3072 /* assert SW reset */
James Ketrenosb095c382005-08-24 22:04:42 -05003073 ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
James Ketrenos43f66a62005-03-25 12:31:53 -06003074
3075 udelay(10);
3076
3077 /* set "initialization complete" bit to move adapter to D0 state */
James Ketrenosb095c382005-08-24 22:04:42 -05003078 ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003079
3080 IPW_DEBUG_TRACE(">>\n");
3081 return 0;
3082}
3083
Jeff Garzikbf794512005-07-31 13:07:26 -04003084/* Call this function from process context, it will sleep in request_firmware.
James Ketrenos43f66a62005-03-25 12:31:53 -06003085 * Probe is an ok place to call this from.
3086 */
3087static int ipw_reset_nic(struct ipw_priv *priv)
3088{
3089 int rc = 0;
James Ketrenosa613bff2005-08-24 21:43:11 -05003090 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06003091
3092 IPW_DEBUG_TRACE(">>\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04003093
James Ketrenos43f66a62005-03-25 12:31:53 -06003094 rc = ipw_init_nic(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -04003095
James Ketrenosa613bff2005-08-24 21:43:11 -05003096 spin_lock_irqsave(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003097 /* Clear the 'host command active' bit... */
3098 priv->status &= ~STATUS_HCMD_ACTIVE;
3099 wake_up_interruptible(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -05003100 priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
3101 wake_up_interruptible(&priv->wait_state);
James Ketrenosa613bff2005-08-24 21:43:11 -05003102 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06003103
3104 IPW_DEBUG_TRACE("<<\n");
3105 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003106}
James Ketrenos43f66a62005-03-25 12:31:53 -06003107
James Ketrenos9006ea72006-03-08 03:22:28 +08003108
3109struct ipw_fw {
3110 u32 ver;
3111 u32 boot_size;
3112 u32 ucode_size;
3113 u32 fw_size;
3114 u8 data[0];
3115};
3116
Jeff Garzikbf794512005-07-31 13:07:26 -04003117static int ipw_get_fw(struct ipw_priv *priv,
James Ketrenos9006ea72006-03-08 03:22:28 +08003118 const struct firmware **raw, const char *name)
James Ketrenos43f66a62005-03-25 12:31:53 -06003119{
James Ketrenos9006ea72006-03-08 03:22:28 +08003120 struct ipw_fw *fw;
James Ketrenos43f66a62005-03-25 12:31:53 -06003121 int rc;
3122
3123 /* ask firmware_class module to get the boot firmware off disk */
James Ketrenos9006ea72006-03-08 03:22:28 +08003124 rc = request_firmware(raw, name, &priv->pci_dev->dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06003125 if (rc < 0) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003126 IPW_ERROR("%s request_firmware failed: Reason %d\n", name, rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003127 return rc;
Jeff Garzikbf794512005-07-31 13:07:26 -04003128 }
James Ketrenos43f66a62005-03-25 12:31:53 -06003129
James Ketrenos9006ea72006-03-08 03:22:28 +08003130 if ((*raw)->size < sizeof(*fw)) {
3131 IPW_ERROR("%s is too small (%zd)\n", name, (*raw)->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003132 return -EINVAL;
3133 }
3134
James Ketrenos9006ea72006-03-08 03:22:28 +08003135 fw = (void *)(*raw)->data;
3136
3137 if ((*raw)->size < sizeof(*fw) +
3138 fw->boot_size + fw->ucode_size + fw->fw_size) {
3139 IPW_ERROR("%s is too small or corrupt (%zd)\n",
3140 name, (*raw)->size);
3141 return -EINVAL;
3142 }
3143
3144 IPW_DEBUG_INFO("Read firmware '%s' image v%d.%d (%zd bytes)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003145 name,
James Ketrenos9006ea72006-03-08 03:22:28 +08003146 le32_to_cpu(fw->ver) >> 16,
3147 le32_to_cpu(fw->ver) & 0xff,
3148 (*raw)->size - sizeof(*fw));
James Ketrenos43f66a62005-03-25 12:31:53 -06003149 return 0;
3150}
3151
James Ketrenosb095c382005-08-24 22:04:42 -05003152#define IPW_RX_BUF_SIZE (3000)
James Ketrenos43f66a62005-03-25 12:31:53 -06003153
Arjan van de Ven858119e2006-01-14 13:20:43 -08003154static void ipw_rx_queue_reset(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003155 struct ipw_rx_queue *rxq)
3156{
3157 unsigned long flags;
3158 int i;
3159
3160 spin_lock_irqsave(&rxq->lock, flags);
3161
3162 INIT_LIST_HEAD(&rxq->rx_free);
3163 INIT_LIST_HEAD(&rxq->rx_used);
3164
3165 /* Fill the rx_used queue with _all_ of the Rx buffers */
3166 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
3167 /* In the reset function, these buffers may have been allocated
3168 * to an SKB, so we need to unmap and free potential storage */
3169 if (rxq->pool[i].skb != NULL) {
3170 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05003171 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003172 dev_kfree_skb(rxq->pool[i].skb);
James Ketrenosa613bff2005-08-24 21:43:11 -05003173 rxq->pool[i].skb = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003174 }
3175 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
3176 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003177
James Ketrenos43f66a62005-03-25 12:31:53 -06003178 /* Set us so that we have processed and used all buffers, but have
3179 * not restocked the Rx queue with fresh buffers */
3180 rxq->read = rxq->write = 0;
3181 rxq->processed = RX_QUEUE_SIZE - 1;
3182 rxq->free_count = 0;
3183 spin_unlock_irqrestore(&rxq->lock, flags);
3184}
3185
3186#ifdef CONFIG_PM
3187static int fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003188static const struct firmware *raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003189
3190static void free_firmware(void)
3191{
3192 if (fw_loaded) {
James Ketrenos9006ea72006-03-08 03:22:28 +08003193 release_firmware(raw);
3194 raw = NULL;
James Ketrenosafbf30a2005-08-25 00:05:33 -05003195 fw_loaded = 0;
3196 }
3197}
3198#else
3199#define free_firmware() do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06003200#endif
3201
3202static int ipw_load(struct ipw_priv *priv)
3203{
3204#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003205 const struct firmware *raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003206#endif
James Ketrenos9006ea72006-03-08 03:22:28 +08003207 struct ipw_fw *fw;
3208 u8 *boot_img, *ucode_img, *fw_img;
3209 u8 *name = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003210 int rc = 0, retries = 3;
3211
Zhu Yi397ae122006-01-24 16:37:22 +08003212 switch (priv->ieee->iw_mode) {
3213 case IW_MODE_ADHOC:
James Ketrenos9006ea72006-03-08 03:22:28 +08003214 name = "ipw2200-ibss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003215 break;
James Ketrenosb095c382005-08-24 22:04:42 -05003216#ifdef CONFIG_IPW2200_MONITOR
Zhu Yi397ae122006-01-24 16:37:22 +08003217 case IW_MODE_MONITOR:
James Ketrenos9006ea72006-03-08 03:22:28 +08003218 name = "ipw2200-sniffer.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003219 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003220#endif
Zhu Yi397ae122006-01-24 16:37:22 +08003221 case IW_MODE_INFRA:
James Ketrenos9006ea72006-03-08 03:22:28 +08003222 name = "ipw2200-bss.fw";
Zhu Yi397ae122006-01-24 16:37:22 +08003223 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06003224 }
Zhu Yi397ae122006-01-24 16:37:22 +08003225
James Ketrenos9006ea72006-03-08 03:22:28 +08003226 if (!name) {
3227 rc = -EINVAL;
3228 goto error;
3229 }
3230
3231#ifdef CONFIG_PM
3232 if (!fw_loaded) {
3233#endif
3234 rc = ipw_get_fw(priv, &raw, name);
3235 if (rc < 0)
3236 goto error;
3237#ifdef CONFIG_PM
3238 }
3239#endif
3240
3241 fw = (void *)raw->data;
3242 boot_img = &fw->data[0];
3243 ucode_img = &fw->data[fw->boot_size];
3244 fw_img = &fw->data[fw->boot_size + fw->ucode_size];
3245
Zhu Yi397ae122006-01-24 16:37:22 +08003246 if (rc < 0)
3247 goto error;
James Ketrenos43f66a62005-03-25 12:31:53 -06003248
3249 if (!priv->rxq)
3250 priv->rxq = ipw_rx_queue_alloc(priv);
3251 else
3252 ipw_rx_queue_reset(priv, priv->rxq);
3253 if (!priv->rxq) {
3254 IPW_ERROR("Unable to initialize Rx queue\n");
3255 goto error;
3256 }
3257
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003258 retry:
James Ketrenos43f66a62005-03-25 12:31:53 -06003259 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003260 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003261 priv->status &= ~STATUS_INT_ENABLED;
3262
3263 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003264 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003265
James Ketrenos43f66a62005-03-25 12:31:53 -06003266 ipw_stop_nic(priv);
3267
3268 rc = ipw_reset_nic(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003269 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003270 IPW_ERROR("Unable to reset NIC\n");
3271 goto error;
3272 }
3273
James Ketrenosb095c382005-08-24 22:04:42 -05003274 ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
3275 IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
James Ketrenos43f66a62005-03-25 12:31:53 -06003276
3277 /* DMA the initial boot firmware into the device */
James Ketrenos9006ea72006-03-08 03:22:28 +08003278 rc = ipw_load_firmware(priv, boot_img, fw->boot_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003279 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003280 IPW_ERROR("Unable to load boot firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003281 goto error;
3282 }
3283
3284 /* kick start the device */
3285 ipw_start_nic(priv);
3286
Zhu Yic7b6a672006-01-24 16:37:05 +08003287 /* wait for the device to finish its initial startup sequence */
James Ketrenosb095c382005-08-24 22:04:42 -05003288 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3289 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003290 if (rc < 0) {
3291 IPW_ERROR("device failed to boot initial fw image\n");
3292 goto error;
3293 }
3294 IPW_DEBUG_INFO("initial device response after %dms\n", rc);
3295
Jeff Garzikbf794512005-07-31 13:07:26 -04003296 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003297 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003298
3299 /* DMA the ucode into the device */
James Ketrenos9006ea72006-03-08 03:22:28 +08003300 rc = ipw_load_ucode(priv, ucode_img, fw->ucode_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06003301 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003302 IPW_ERROR("Unable to load ucode: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003303 goto error;
3304 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003305
James Ketrenos43f66a62005-03-25 12:31:53 -06003306 /* stop nic */
3307 ipw_stop_nic(priv);
3308
3309 /* DMA bss firmware into the device */
James Ketrenos9006ea72006-03-08 03:22:28 +08003310 rc = ipw_load_firmware(priv, fw_img, fw->fw_size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003311 if (rc < 0) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -05003312 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -06003313 goto error;
3314 }
Zhu Yi397ae122006-01-24 16:37:22 +08003315#ifdef CONFIG_PM
3316 fw_loaded = 1;
3317#endif
3318
James Ketrenos43f66a62005-03-25 12:31:53 -06003319 ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
3320
3321 rc = ipw_queue_reset(priv);
Zhu Yi397ae122006-01-24 16:37:22 +08003322 if (rc < 0) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003323 IPW_ERROR("Unable to initialize queues\n");
3324 goto error;
3325 }
3326
3327 /* Ensure interrupts are disabled */
James Ketrenosb095c382005-08-24 22:04:42 -05003328 ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003329 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003330 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
Jeff Garzikbf794512005-07-31 13:07:26 -04003331
James Ketrenos43f66a62005-03-25 12:31:53 -06003332 /* kick start the device */
3333 ipw_start_nic(priv);
3334
James Ketrenosb095c382005-08-24 22:04:42 -05003335 if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003336 if (retries > 0) {
3337 IPW_WARNING("Parity error. Retrying init.\n");
3338 retries--;
3339 goto retry;
3340 }
3341
3342 IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
3343 rc = -EIO;
3344 goto error;
3345 }
3346
3347 /* wait for the device */
James Ketrenosb095c382005-08-24 22:04:42 -05003348 rc = ipw_poll_bit(priv, IPW_INTA_RW,
3349 IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
James Ketrenos43f66a62005-03-25 12:31:53 -06003350 if (rc < 0) {
Zhu Yic7b6a672006-01-24 16:37:05 +08003351 IPW_ERROR("device failed to start within 500ms\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06003352 goto error;
3353 }
3354 IPW_DEBUG_INFO("device response after %dms\n", rc);
3355
3356 /* ack fw init done interrupt */
James Ketrenosb095c382005-08-24 22:04:42 -05003357 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003358
3359 /* read eeprom data and initialize the eeprom region of sram */
3360 priv->eeprom_delay = 1;
Jeff Garzikbf794512005-07-31 13:07:26 -04003361 ipw_eeprom_init_sram(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06003362
3363 /* enable interrupts */
3364 ipw_enable_interrupts(priv);
3365
3366 /* Ensure our queue has valid packets */
3367 ipw_rx_queue_replenish(priv);
3368
James Ketrenosb095c382005-08-24 22:04:42 -05003369 ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
James Ketrenos43f66a62005-03-25 12:31:53 -06003370
3371 /* ack pending interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -05003372 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
James Ketrenos43f66a62005-03-25 12:31:53 -06003373
3374#ifndef CONFIG_PM
James Ketrenos9006ea72006-03-08 03:22:28 +08003375 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003376#endif
3377 return 0;
3378
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003379 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06003380 if (priv->rxq) {
3381 ipw_rx_queue_free(priv, priv->rxq);
3382 priv->rxq = NULL;
3383 }
3384 ipw_tx_queue_free(priv);
James Ketrenos9006ea72006-03-08 03:22:28 +08003385 if (raw)
3386 release_firmware(raw);
James Ketrenos43f66a62005-03-25 12:31:53 -06003387#ifdef CONFIG_PM
3388 fw_loaded = 0;
James Ketrenos9006ea72006-03-08 03:22:28 +08003389 raw = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -06003390#endif
3391
3392 return rc;
3393}
3394
Jeff Garzikbf794512005-07-31 13:07:26 -04003395/**
James Ketrenos43f66a62005-03-25 12:31:53 -06003396 * DMA services
3397 *
3398 * Theory of operation
3399 *
3400 * A queue is a circular buffers with 'Read' and 'Write' pointers.
3401 * 2 empty entries always kept in the buffer to protect from overflow.
3402 *
3403 * For Tx queue, there are low mark and high mark limits. If, after queuing
Jeff Garzikbf794512005-07-31 13:07:26 -04003404 * the packet for Tx, free space become < low mark, Tx queue stopped. When
3405 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
James Ketrenos43f66a62005-03-25 12:31:53 -06003406 * Tx queue resumed.
3407 *
3408 * The IPW operates with six queues, one receive queue in the device's
3409 * sram, one transmit queue for sending commands to the device firmware,
Jeff Garzikbf794512005-07-31 13:07:26 -04003410 * and four transmit queues for data.
James Ketrenos43f66a62005-03-25 12:31:53 -06003411 *
Jeff Garzikbf794512005-07-31 13:07:26 -04003412 * The four transmit queues allow for performing quality of service (qos)
James Ketrenos43f66a62005-03-25 12:31:53 -06003413 * transmissions as per the 802.11 protocol. Currently Linux does not
Jeff Garzikbf794512005-07-31 13:07:26 -04003414 * provide a mechanism to the user for utilizing prioritized queues, so
James Ketrenos43f66a62005-03-25 12:31:53 -06003415 * we only utilize the first data transmit queue (queue1).
3416 */
3417
3418/**
3419 * Driver allocates buffers of this size for Rx
3420 */
3421
3422static inline int ipw_queue_space(const struct clx2_queue *q)
3423{
3424 int s = q->last_used - q->first_empty;
3425 if (s <= 0)
3426 s += q->n_bd;
3427 s -= 2; /* keep some reserve to not confuse empty and full situations */
3428 if (s < 0)
3429 s = 0;
3430 return s;
3431}
3432
3433static inline int ipw_queue_inc_wrap(int index, int n_bd)
3434{
3435 return (++index == n_bd) ? 0 : index;
3436}
3437
3438/**
3439 * Initialize common DMA queue structure
Jeff Garzikbf794512005-07-31 13:07:26 -04003440 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003441 * @param q queue to init
3442 * @param count Number of BD's to allocate. Should be power of 2
3443 * @param read_register Address for 'read' register
3444 * (not offset within BAR, full address)
3445 * @param write_register Address for 'write' register
3446 * (not offset within BAR, full address)
3447 * @param base_register Address for 'base' register
3448 * (not offset within BAR, full address)
3449 * @param size Address for 'size' register
3450 * (not offset within BAR, full address)
3451 */
Jeff Garzikbf794512005-07-31 13:07:26 -04003452static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003453 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003454{
3455 q->n_bd = count;
3456
3457 q->low_mark = q->n_bd / 4;
3458 if (q->low_mark < 4)
3459 q->low_mark = 4;
3460
3461 q->high_mark = q->n_bd / 8;
3462 if (q->high_mark < 2)
3463 q->high_mark = 2;
3464
3465 q->first_empty = q->last_used = 0;
3466 q->reg_r = read;
3467 q->reg_w = write;
3468
3469 ipw_write32(priv, base, q->dma_addr);
3470 ipw_write32(priv, size, count);
3471 ipw_write32(priv, read, 0);
3472 ipw_write32(priv, write, 0);
3473
3474 _ipw_read32(priv, 0x90);
3475}
3476
Jeff Garzikbf794512005-07-31 13:07:26 -04003477static int ipw_queue_tx_init(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06003478 struct clx2_tx_queue *q,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003479 int count, u32 read, u32 write, u32 base, u32 size)
James Ketrenos43f66a62005-03-25 12:31:53 -06003480{
3481 struct pci_dev *dev = priv->pci_dev;
3482
3483 q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
3484 if (!q->txb) {
3485 IPW_ERROR("vmalloc for auxilary BD structures failed\n");
3486 return -ENOMEM;
3487 }
3488
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003489 q->bd =
3490 pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
James Ketrenos43f66a62005-03-25 12:31:53 -06003491 if (!q->bd) {
Jiri Bencaaa4d302005-06-07 14:58:41 +02003492 IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003493 sizeof(q->bd[0]) * count);
James Ketrenos43f66a62005-03-25 12:31:53 -06003494 kfree(q->txb);
3495 q->txb = NULL;
3496 return -ENOMEM;
3497 }
3498
3499 ipw_queue_init(priv, &q->q, count, read, write, base, size);
3500 return 0;
3501}
3502
3503/**
3504 * Free one TFD, those at index [txq->q.last_used].
3505 * Do NOT advance any indexes
Jeff Garzikbf794512005-07-31 13:07:26 -04003506 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003507 * @param dev
3508 * @param txq
3509 */
3510static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
3511 struct clx2_tx_queue *txq)
3512{
3513 struct tfd_frame *bd = &txq->bd[txq->q.last_used];
3514 struct pci_dev *dev = priv->pci_dev;
3515 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003516
James Ketrenos43f66a62005-03-25 12:31:53 -06003517 /* classify bd */
3518 if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
3519 /* nothing to cleanup after for host commands */
3520 return;
3521
3522 /* sanity check */
James Ketrenosa613bff2005-08-24 21:43:11 -05003523 if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
3524 IPW_ERROR("Too many chunks: %i\n",
3525 le32_to_cpu(bd->u.data.num_chunks));
James Ketrenos43f66a62005-03-25 12:31:53 -06003526 /** @todo issue fatal error, it is quite serious situation */
3527 return;
3528 }
3529
3530 /* unmap chunks if any */
James Ketrenosa613bff2005-08-24 21:43:11 -05003531 for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
3532 pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
3533 le16_to_cpu(bd->u.data.chunk_len[i]),
3534 PCI_DMA_TODEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06003535 if (txq->txb[txq->q.last_used]) {
3536 ieee80211_txb_free(txq->txb[txq->q.last_used]);
3537 txq->txb[txq->q.last_used] = NULL;
3538 }
3539 }
3540}
3541
3542/**
3543 * Deallocate DMA queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04003544 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003545 * Empty queue by removing and destroying all BD's.
3546 * Free all buffers.
Jeff Garzikbf794512005-07-31 13:07:26 -04003547 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003548 * @param dev
3549 * @param q
3550 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003551static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
James Ketrenos43f66a62005-03-25 12:31:53 -06003552{
3553 struct clx2_queue *q = &txq->q;
3554 struct pci_dev *dev = priv->pci_dev;
3555
Jeff Garzikbf794512005-07-31 13:07:26 -04003556 if (q->n_bd == 0)
3557 return;
James Ketrenos43f66a62005-03-25 12:31:53 -06003558
3559 /* first, empty all BD's */
3560 for (; q->first_empty != q->last_used;
3561 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
3562 ipw_queue_tx_free_tfd(priv, txq);
3563 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003564
James Ketrenos43f66a62005-03-25 12:31:53 -06003565 /* free buffers belonging to queue itself */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003566 pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
James Ketrenos43f66a62005-03-25 12:31:53 -06003567 q->dma_addr);
3568 kfree(txq->txb);
3569
3570 /* 0 fill whole structure */
3571 memset(txq, 0, sizeof(*txq));
3572}
3573
James Ketrenos43f66a62005-03-25 12:31:53 -06003574/**
3575 * Destroy all DMA queues and structures
Jeff Garzikbf794512005-07-31 13:07:26 -04003576 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003577 * @param priv
3578 */
3579static void ipw_tx_queue_free(struct ipw_priv *priv)
3580{
3581 /* Tx CMD queue */
3582 ipw_queue_tx_free(priv, &priv->txq_cmd);
3583
3584 /* Tx queues */
3585 ipw_queue_tx_free(priv, &priv->txq[0]);
3586 ipw_queue_tx_free(priv, &priv->txq[1]);
3587 ipw_queue_tx_free(priv, &priv->txq[2]);
3588 ipw_queue_tx_free(priv, &priv->txq[3]);
3589}
3590
Arjan van de Ven858119e2006-01-14 13:20:43 -08003591static void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003592{
3593 /* First 3 bytes are manufacturer */
3594 bssid[0] = priv->mac_addr[0];
3595 bssid[1] = priv->mac_addr[1];
3596 bssid[2] = priv->mac_addr[2];
3597
3598 /* Last bytes are random */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003599 get_random_bytes(&bssid[3], ETH_ALEN - 3);
James Ketrenos43f66a62005-03-25 12:31:53 -06003600
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003601 bssid[0] &= 0xfe; /* clear multicast bit */
3602 bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
James Ketrenos43f66a62005-03-25 12:31:53 -06003603}
3604
Arjan van de Ven858119e2006-01-14 13:20:43 -08003605static u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003606{
3607 struct ipw_station_entry entry;
3608 int i;
3609
3610 for (i = 0; i < priv->num_stations; i++) {
3611 if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
3612 /* Another node is active in network */
3613 priv->missed_adhoc_beacons = 0;
3614 if (!(priv->config & CFG_STATIC_CHANNEL))
3615 /* when other nodes drop out, we drop out */
3616 priv->config &= ~CFG_ADHOC_PERSIST;
3617
3618 return i;
3619 }
3620 }
3621
3622 if (i == MAX_STATIONS)
3623 return IPW_INVALID_STATION;
3624
3625 IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
3626
3627 entry.reserved = 0;
3628 entry.support_mode = 0;
3629 memcpy(entry.mac_addr, bssid, ETH_ALEN);
3630 memcpy(priv->stations[i], bssid, ETH_ALEN);
3631 ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003632 &entry, sizeof(entry));
James Ketrenos43f66a62005-03-25 12:31:53 -06003633 priv->num_stations++;
3634
3635 return i;
3636}
3637
Arjan van de Ven858119e2006-01-14 13:20:43 -08003638static u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
James Ketrenos43f66a62005-03-25 12:31:53 -06003639{
3640 int i;
3641
Jeff Garzikbf794512005-07-31 13:07:26 -04003642 for (i = 0; i < priv->num_stations; i++)
3643 if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
James Ketrenos43f66a62005-03-25 12:31:53 -06003644 return i;
3645
3646 return IPW_INVALID_STATION;
3647}
3648
3649static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
3650{
3651 int err;
3652
Hong Liu7b996592005-08-25 17:36:13 +08003653 if (priv->status & STATUS_ASSOCIATING) {
3654 IPW_DEBUG_ASSOC("Disassociating while associating.\n");
3655 queue_work(priv->workqueue, &priv->disassociate);
3656 return;
3657 }
3658
3659 if (!(priv->status & STATUS_ASSOCIATED)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06003660 IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
3661 return;
3662 }
3663
3664 IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
3665 "on channel %d.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04003666 MAC_ARG(priv->assoc_request.bssid),
James Ketrenos43f66a62005-03-25 12:31:53 -06003667 priv->assoc_request.channel);
3668
3669 priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
3670 priv->status |= STATUS_DISASSOCIATING;
3671
3672 if (quiet)
3673 priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
3674 else
3675 priv->assoc_request.assoc_type = HC_DISASSOCIATE;
Hong Liue6324722005-09-14 21:04:15 -05003676
James Ketrenos43f66a62005-03-25 12:31:53 -06003677 err = ipw_send_associate(priv, &priv->assoc_request);
3678 if (err) {
3679 IPW_DEBUG_HC("Attempt to send [dis]associate command "
3680 "failed.\n");
3681 return;
3682 }
3683
3684}
3685
James Ketrenosc848d0a2005-08-24 21:56:24 -05003686static int ipw_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003687{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003688 struct ipw_priv *priv = data;
3689 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
3690 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06003691 ipw_send_disassociate(data, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003692 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003693}
3694
James Ketrenosc848d0a2005-08-24 21:56:24 -05003695static void ipw_bg_disassociate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06003696{
James Ketrenosc848d0a2005-08-24 21:56:24 -05003697 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08003698 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05003699 ipw_disassociate(data);
Zhu Yi46441512006-01-24 16:37:59 +08003700 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06003701}
3702
Zhu Yid8bad6d2005-07-13 12:25:38 -05003703static void ipw_system_config(void *data)
3704{
3705 struct ipw_priv *priv = data;
3706 ipw_send_system_config(priv, &priv->sys_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06003707}
3708
3709struct ipw_status_code {
3710 u16 status;
3711 const char *reason;
3712};
3713
3714static const struct ipw_status_code ipw_status_codes[] = {
3715 {0x00, "Successful"},
3716 {0x01, "Unspecified failure"},
3717 {0x0A, "Cannot support all requested capabilities in the "
3718 "Capability information field"},
3719 {0x0B, "Reassociation denied due to inability to confirm that "
3720 "association exists"},
3721 {0x0C, "Association denied due to reason outside the scope of this "
3722 "standard"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003723 {0x0D,
3724 "Responding station does not support the specified authentication "
James Ketrenos43f66a62005-03-25 12:31:53 -06003725 "algorithm"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003726 {0x0E,
3727 "Received an Authentication frame with authentication sequence "
James Ketrenos43f66a62005-03-25 12:31:53 -06003728 "transaction sequence number out of expected sequence"},
3729 {0x0F, "Authentication rejected because of challenge failure"},
3730 {0x10, "Authentication rejected due to timeout waiting for next "
3731 "frame in sequence"},
3732 {0x11, "Association denied because AP is unable to handle additional "
3733 "associated stations"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003734 {0x12,
3735 "Association denied due to requesting station not supporting all "
James Ketrenos43f66a62005-03-25 12:31:53 -06003736 "of the datarates in the BSSBasicServiceSet Parameter"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003737 {0x13,
3738 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003739 "short preamble operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003740 {0x14,
3741 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003742 "PBCC encoding"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003743 {0x15,
3744 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003745 "channel agility"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003746 {0x19,
3747 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003748 "short slot operation"},
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003749 {0x1A,
3750 "Association denied due to requesting station not supporting "
James Ketrenos43f66a62005-03-25 12:31:53 -06003751 "DSSS-OFDM operation"},
3752 {0x28, "Invalid Information Element"},
3753 {0x29, "Group Cipher is not valid"},
3754 {0x2A, "Pairwise Cipher is not valid"},
3755 {0x2B, "AKMP is not valid"},
3756 {0x2C, "Unsupported RSN IE version"},
3757 {0x2D, "Invalid RSN IE Capabilities"},
3758 {0x2E, "Cipher suite is rejected per security policy"},
3759};
3760
Brice Goglin0f52bf92005-12-01 01:41:46 -08003761#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzikbf794512005-07-31 13:07:26 -04003762static const char *ipw_get_status_code(u16 status)
James Ketrenos43f66a62005-03-25 12:31:53 -06003763{
3764 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -04003765 for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
James Ketrenosea2b26e2005-08-24 21:25:16 -05003766 if (ipw_status_codes[i].status == (status & 0xff))
James Ketrenos43f66a62005-03-25 12:31:53 -06003767 return ipw_status_codes[i].reason;
3768 return "Unknown status value.";
3769}
3770#endif
3771
3772static void inline average_init(struct average *avg)
3773{
3774 memset(avg, 0, sizeof(*avg));
3775}
3776
Zhu Yi00d21de2006-04-13 17:19:02 +08003777#define DEPTH_RSSI 8
3778#define DEPTH_NOISE 16
3779static s16 exponential_average(s16 prev_avg, s16 val, u8 depth)
3780{
3781 return ((depth-1)*prev_avg + val)/depth;
3782}
3783
Arjan van de Ven858119e2006-01-14 13:20:43 -08003784static void average_add(struct average *avg, s16 val)
James Ketrenos43f66a62005-03-25 12:31:53 -06003785{
3786 avg->sum -= avg->entries[avg->pos];
3787 avg->sum += val;
3788 avg->entries[avg->pos++] = val;
3789 if (unlikely(avg->pos == AVG_ENTRIES)) {
3790 avg->init = 1;
3791 avg->pos = 0;
3792 }
3793}
3794
Arjan van de Ven858119e2006-01-14 13:20:43 -08003795static s16 average_value(struct average *avg)
James Ketrenos43f66a62005-03-25 12:31:53 -06003796{
3797 if (!unlikely(avg->init)) {
3798 if (avg->pos)
3799 return avg->sum / avg->pos;
3800 return 0;
3801 }
3802
3803 return avg->sum / AVG_ENTRIES;
3804}
3805
3806static void ipw_reset_stats(struct ipw_priv *priv)
3807{
3808 u32 len = sizeof(u32);
3809
3810 priv->quality = 0;
3811
3812 average_init(&priv->average_missed_beacons);
Zhu Yi00d21de2006-04-13 17:19:02 +08003813 priv->exp_avg_rssi = -60;
3814 priv->exp_avg_noise = -85 + 0x100;
James Ketrenos43f66a62005-03-25 12:31:53 -06003815
3816 priv->last_rate = 0;
3817 priv->last_missed_beacons = 0;
3818 priv->last_rx_packets = 0;
3819 priv->last_tx_packets = 0;
3820 priv->last_tx_failures = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04003821
James Ketrenos43f66a62005-03-25 12:31:53 -06003822 /* Firmware managed, reset only when NIC is restarted, so we have to
3823 * normalize on the current value */
Jeff Garzikbf794512005-07-31 13:07:26 -04003824 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
James Ketrenos43f66a62005-03-25 12:31:53 -06003825 &priv->last_rx_err, &len);
Jeff Garzikbf794512005-07-31 13:07:26 -04003826 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
James Ketrenos43f66a62005-03-25 12:31:53 -06003827 &priv->last_tx_failures, &len);
3828
3829 /* Driver managed, reset with each association */
3830 priv->missed_adhoc_beacons = 0;
3831 priv->missed_beacons = 0;
3832 priv->tx_packets = 0;
3833 priv->rx_packets = 0;
3834
3835}
3836
Arjan van de Ven858119e2006-01-14 13:20:43 -08003837static u32 ipw_get_max_rate(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -06003838{
3839 u32 i = 0x80000000;
3840 u32 mask = priv->rates_mask;
3841 /* If currently associated in B mode, restrict the maximum
3842 * rate match to B rates */
3843 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
3844 mask &= IEEE80211_CCK_RATES_MASK;
3845
3846 /* TODO: Verify that the rate is supported by the current rates
3847 * list. */
3848
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003849 while (i && !(mask & i))
3850 i >>= 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06003851 switch (i) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003852 case IEEE80211_CCK_RATE_1MB_MASK:
3853 return 1000000;
3854 case IEEE80211_CCK_RATE_2MB_MASK:
3855 return 2000000;
3856 case IEEE80211_CCK_RATE_5MB_MASK:
3857 return 5500000;
3858 case IEEE80211_OFDM_RATE_6MB_MASK:
3859 return 6000000;
3860 case IEEE80211_OFDM_RATE_9MB_MASK:
3861 return 9000000;
3862 case IEEE80211_CCK_RATE_11MB_MASK:
3863 return 11000000;
3864 case IEEE80211_OFDM_RATE_12MB_MASK:
3865 return 12000000;
3866 case IEEE80211_OFDM_RATE_18MB_MASK:
3867 return 18000000;
3868 case IEEE80211_OFDM_RATE_24MB_MASK:
3869 return 24000000;
3870 case IEEE80211_OFDM_RATE_36MB_MASK:
3871 return 36000000;
3872 case IEEE80211_OFDM_RATE_48MB_MASK:
3873 return 48000000;
3874 case IEEE80211_OFDM_RATE_54MB_MASK:
3875 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003876 }
3877
Jeff Garzikbf794512005-07-31 13:07:26 -04003878 if (priv->ieee->mode == IEEE_B)
James Ketrenos43f66a62005-03-25 12:31:53 -06003879 return 11000000;
3880 else
3881 return 54000000;
3882}
3883
3884static u32 ipw_get_current_rate(struct ipw_priv *priv)
3885{
3886 u32 rate, len = sizeof(rate);
3887 int err;
3888
Jeff Garzikbf794512005-07-31 13:07:26 -04003889 if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06003890 return 0;
3891
3892 if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
Jeff Garzikbf794512005-07-31 13:07:26 -04003893 err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
James Ketrenos43f66a62005-03-25 12:31:53 -06003894 &len);
3895 if (err) {
3896 IPW_DEBUG_INFO("failed querying ordinals.\n");
3897 return 0;
3898 }
Jeff Garzikbf794512005-07-31 13:07:26 -04003899 } else
James Ketrenos43f66a62005-03-25 12:31:53 -06003900 return ipw_get_max_rate(priv);
3901
3902 switch (rate) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05003903 case IPW_TX_RATE_1MB:
3904 return 1000000;
3905 case IPW_TX_RATE_2MB:
3906 return 2000000;
3907 case IPW_TX_RATE_5MB:
3908 return 5500000;
3909 case IPW_TX_RATE_6MB:
3910 return 6000000;
3911 case IPW_TX_RATE_9MB:
3912 return 9000000;
3913 case IPW_TX_RATE_11MB:
3914 return 11000000;
3915 case IPW_TX_RATE_12MB:
3916 return 12000000;
3917 case IPW_TX_RATE_18MB:
3918 return 18000000;
3919 case IPW_TX_RATE_24MB:
3920 return 24000000;
3921 case IPW_TX_RATE_36MB:
3922 return 36000000;
3923 case IPW_TX_RATE_48MB:
3924 return 48000000;
3925 case IPW_TX_RATE_54MB:
3926 return 54000000;
James Ketrenos43f66a62005-03-25 12:31:53 -06003927 }
3928
3929 return 0;
3930}
3931
James Ketrenos43f66a62005-03-25 12:31:53 -06003932#define IPW_STATS_INTERVAL (2 * HZ)
3933static void ipw_gather_stats(struct ipw_priv *priv)
3934{
3935 u32 rx_err, rx_err_delta, rx_packets_delta;
3936 u32 tx_failures, tx_failures_delta, tx_packets_delta;
3937 u32 missed_beacons_percent, missed_beacons_delta;
3938 u32 quality = 0;
3939 u32 len = sizeof(u32);
3940 s16 rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04003941 u32 beacon_quality, signal_quality, tx_quality, rx_quality,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003942 rate_quality;
James Ketrenosea2b26e2005-08-24 21:25:16 -05003943 u32 max_rate;
James Ketrenos43f66a62005-03-25 12:31:53 -06003944
3945 if (!(priv->status & STATUS_ASSOCIATED)) {
3946 priv->quality = 0;
3947 return;
3948 }
3949
3950 /* Update the statistics */
Jeff Garzikbf794512005-07-31 13:07:26 -04003951 ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
James Ketrenos43f66a62005-03-25 12:31:53 -06003952 &priv->missed_beacons, &len);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003953 missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
James Ketrenos43f66a62005-03-25 12:31:53 -06003954 priv->last_missed_beacons = priv->missed_beacons;
3955 if (priv->assoc_request.beacon_interval) {
3956 missed_beacons_percent = missed_beacons_delta *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003957 (HZ * priv->assoc_request.beacon_interval) /
3958 (IPW_STATS_INTERVAL * 10);
James Ketrenos43f66a62005-03-25 12:31:53 -06003959 } else {
3960 missed_beacons_percent = 0;
3961 }
3962 average_add(&priv->average_missed_beacons, missed_beacons_percent);
3963
3964 ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
3965 rx_err_delta = rx_err - priv->last_rx_err;
3966 priv->last_rx_err = rx_err;
3967
3968 ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
3969 tx_failures_delta = tx_failures - priv->last_tx_failures;
3970 priv->last_tx_failures = tx_failures;
3971
3972 rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
3973 priv->last_rx_packets = priv->rx_packets;
3974
3975 tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
3976 priv->last_tx_packets = priv->tx_packets;
3977
3978 /* Calculate quality based on the following:
Jeff Garzikbf794512005-07-31 13:07:26 -04003979 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003980 * Missed beacon: 100% = 0, 0% = 70% missed
3981 * Rate: 60% = 1Mbs, 100% = Max
3982 * Rx and Tx errors represent a straight % of total Rx/Tx
3983 * RSSI: 100% = > -50, 0% = < -80
3984 * Rx errors: 100% = 0, 0% = 50% missed
Jeff Garzikbf794512005-07-31 13:07:26 -04003985 *
James Ketrenos43f66a62005-03-25 12:31:53 -06003986 * The lowest computed quality is used.
3987 *
3988 */
3989#define BEACON_THRESHOLD 5
3990 beacon_quality = 100 - missed_beacons_percent;
3991 if (beacon_quality < BEACON_THRESHOLD)
3992 beacon_quality = 0;
3993 else
Jeff Garzikbf794512005-07-31 13:07:26 -04003994 beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04003995 (100 - BEACON_THRESHOLD);
Jeff Garzikbf794512005-07-31 13:07:26 -04003996 IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06003997 beacon_quality, missed_beacons_percent);
Jeff Garzikbf794512005-07-31 13:07:26 -04003998
James Ketrenos43f66a62005-03-25 12:31:53 -06003999 priv->last_rate = ipw_get_current_rate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004000 max_rate = ipw_get_max_rate(priv);
4001 rate_quality = priv->last_rate * 40 / max_rate + 60;
James Ketrenos43f66a62005-03-25 12:31:53 -06004002 IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
4003 rate_quality, priv->last_rate / 1000000);
Jeff Garzikbf794512005-07-31 13:07:26 -04004004
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004005 if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004006 rx_quality = 100 - (rx_err_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004007 (rx_packets_delta + rx_err_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004008 else
4009 rx_quality = 100;
4010 IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
4011 rx_quality, rx_err_delta, rx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004012
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004013 if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
Jeff Garzikbf794512005-07-31 13:07:26 -04004014 tx_quality = 100 - (tx_failures_delta * 100) /
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004015 (tx_packets_delta + tx_failures_delta);
James Ketrenos43f66a62005-03-25 12:31:53 -06004016 else
4017 tx_quality = 100;
4018 IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
4019 tx_quality, tx_failures_delta, tx_packets_delta);
Jeff Garzikbf794512005-07-31 13:07:26 -04004020
Zhu Yi00d21de2006-04-13 17:19:02 +08004021 rssi = priv->exp_avg_rssi;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004022 signal_quality =
4023 (100 *
4024 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4025 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
4026 (priv->ieee->perfect_rssi - rssi) *
4027 (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
4028 62 * (priv->ieee->perfect_rssi - rssi))) /
4029 ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
4030 (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
4031 if (signal_quality > 100)
James Ketrenos43f66a62005-03-25 12:31:53 -06004032 signal_quality = 100;
James Ketrenosc848d0a2005-08-24 21:56:24 -05004033 else if (signal_quality < 1)
James Ketrenos43f66a62005-03-25 12:31:53 -06004034 signal_quality = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05004035
Zhu Yi61fb9ed2006-04-13 17:19:55 +08004036 IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06004037 signal_quality, rssi);
Jeff Garzikbf794512005-07-31 13:07:26 -04004038
4039 quality = min(beacon_quality,
James Ketrenos43f66a62005-03-25 12:31:53 -06004040 min(rate_quality,
4041 min(tx_quality, min(rx_quality, signal_quality))));
4042 if (quality == beacon_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004043 IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
4044 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004045 if (quality == rate_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004046 IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
4047 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004048 if (quality == tx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004049 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
4050 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004051 if (quality == rx_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004052 IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
4053 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004054 if (quality == signal_quality)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004055 IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
4056 quality);
James Ketrenos43f66a62005-03-25 12:31:53 -06004057
4058 priv->quality = quality;
Jeff Garzikbf794512005-07-31 13:07:26 -04004059
4060 queue_delayed_work(priv->workqueue, &priv->gather_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06004061 IPW_STATS_INTERVAL);
4062}
4063
James Ketrenosc848d0a2005-08-24 21:56:24 -05004064static void ipw_bg_gather_stats(void *data)
4065{
4066 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08004067 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004068 ipw_gather_stats(data);
Zhu Yi46441512006-01-24 16:37:59 +08004069 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004070}
4071
Ben Cahille7582562005-10-06 15:34:41 -05004072/* Missed beacon behavior:
4073 * 1st missed -> roaming_threshold, just wait, don't do any scan/roam.
4074 * roaming_threshold -> disassociate_threshold, scan and roam for better signal.
4075 * Above disassociate threshold, give up and stop scanning.
4076 * Roaming is disabled if disassociate_threshold <= roaming_threshold */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004077static void ipw_handle_missed_beacon(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004078 int missed_count)
4079{
4080 priv->notif_missed_beacons = missed_count;
4081
James Ketrenosafbf30a2005-08-25 00:05:33 -05004082 if (missed_count > priv->disassociate_threshold &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05004083 priv->status & STATUS_ASSOCIATED) {
4084 /* If associated and we've hit the missed
4085 * beacon threshold, disassociate, turn
4086 * off roaming, and abort any active scans */
4087 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
James Ketrenosafbf30a2005-08-25 00:05:33 -05004088 IPW_DL_STATE | IPW_DL_ASSOC,
James Ketrenosea2b26e2005-08-24 21:25:16 -05004089 "Missed beacon: %d - disassociate\n", missed_count);
4090 priv->status &= ~STATUS_ROAMING;
James Ketrenosa613bff2005-08-24 21:43:11 -05004091 if (priv->status & STATUS_SCANNING) {
4092 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
4093 IPW_DL_STATE,
4094 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004095 queue_work(priv->workqueue, &priv->abort_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004096 }
4097
James Ketrenosea2b26e2005-08-24 21:25:16 -05004098 queue_work(priv->workqueue, &priv->disassociate);
4099 return;
4100 }
4101
4102 if (priv->status & STATUS_ROAMING) {
4103 /* If we are currently roaming, then just
4104 * print a debug statement... */
4105 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4106 "Missed beacon: %d - roam in progress\n",
4107 missed_count);
4108 return;
4109 }
4110
Zhu Yi4bfdb912006-01-24 16:37:16 +08004111 if (roaming &&
4112 (missed_count > priv->roaming_threshold &&
4113 missed_count <= priv->disassociate_threshold)) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05004114 /* If we are not already roaming, set the ROAM
Ben Cahille7582562005-10-06 15:34:41 -05004115 * bit in the status and kick off a scan.
4116 * This can happen several times before we reach
4117 * disassociate_threshold. */
James Ketrenosea2b26e2005-08-24 21:25:16 -05004118 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4119 "Missed beacon: %d - initiate "
4120 "roaming\n", missed_count);
4121 if (!(priv->status & STATUS_ROAMING)) {
4122 priv->status |= STATUS_ROAMING;
4123 if (!(priv->status & STATUS_SCANNING))
4124 queue_work(priv->workqueue,
4125 &priv->request_scan);
4126 }
4127 return;
4128 }
4129
4130 if (priv->status & STATUS_SCANNING) {
4131 /* Stop scan to keep fw from getting
4132 * stuck (only if we aren't roaming --
4133 * otherwise we'll never scan more than 2 or 3
4134 * channels..) */
James Ketrenosb095c382005-08-24 22:04:42 -05004135 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
4136 "Aborting scan with missed beacon.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05004137 queue_work(priv->workqueue, &priv->abort_scan);
4138 }
4139
4140 IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
James Ketrenosea2b26e2005-08-24 21:25:16 -05004141}
4142
James Ketrenos43f66a62005-03-25 12:31:53 -06004143/**
4144 * Handle host notification packet.
4145 * Called from interrupt routine
4146 */
Arjan van de Ven858119e2006-01-14 13:20:43 -08004147static void ipw_rx_notification(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004148 struct ipw_rx_notification *notif)
4149{
James Ketrenosa613bff2005-08-24 21:43:11 -05004150 notif->size = le16_to_cpu(notif->size);
4151
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004152 IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
Jeff Garzikbf794512005-07-31 13:07:26 -04004153
James Ketrenos43f66a62005-03-25 12:31:53 -06004154 switch (notif->subtype) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004155 case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
4156 struct notif_association *assoc = &notif->u.assoc;
Jeff Garzikbf794512005-07-31 13:07:26 -04004157
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004158 switch (assoc->state) {
4159 case CMAS_ASSOCIATED:{
4160 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4161 IPW_DL_ASSOC,
4162 "associated: '%s' " MAC_FMT
4163 " \n",
4164 escape_essid(priv->essid,
4165 priv->essid_len),
4166 MAC_ARG(priv->bssid));
Jeff Garzikbf794512005-07-31 13:07:26 -04004167
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004168 switch (priv->ieee->iw_mode) {
4169 case IW_MODE_INFRA:
4170 memcpy(priv->ieee->bssid,
4171 priv->bssid, ETH_ALEN);
4172 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004173
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004174 case IW_MODE_ADHOC:
4175 memcpy(priv->ieee->bssid,
4176 priv->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04004177
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004178 /* clear out the station table */
4179 priv->num_stations = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06004180
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004181 IPW_DEBUG_ASSOC
4182 ("queueing adhoc check\n");
4183 queue_delayed_work(priv->
4184 workqueue,
4185 &priv->
4186 adhoc_check,
4187 priv->
4188 assoc_request.
4189 beacon_interval);
4190 break;
4191 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004192
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004193 priv->status &= ~STATUS_ASSOCIATING;
4194 priv->status |= STATUS_ASSOCIATED;
Zhu Yid8bad6d2005-07-13 12:25:38 -05004195 queue_work(priv->workqueue,
4196 &priv->system_config);
James Ketrenos43f66a62005-03-25 12:31:53 -06004197
James Ketrenosb095c382005-08-24 22:04:42 -05004198#ifdef CONFIG_IPW_QOS
James Ketrenosafbf30a2005-08-25 00:05:33 -05004199#define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
4200 le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
4201 if ((priv->status & STATUS_AUTH) &&
4202 (IPW_GET_PACKET_STYPE(&notif->u.raw)
4203 == IEEE80211_STYPE_ASSOC_RESP)) {
James Ketrenosb095c382005-08-24 22:04:42 -05004204 if ((sizeof
4205 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004206 ieee80211_assoc_response)
James Ketrenosb095c382005-08-24 22:04:42 -05004207 <= notif->size)
4208 && (notif->size <= 2314)) {
4209 struct
4210 ieee80211_rx_stats
4211 stats = {
4212 .len =
4213 notif->
4214 size - 1,
4215 };
4216
4217 IPW_DEBUG_QOS
4218 ("QoS Associate "
4219 "size %d\n",
4220 notif->size);
4221 ieee80211_rx_mgt(priv->
4222 ieee,
4223 (struct
James Ketrenos2b184d52005-08-03 20:33:14 -05004224 ieee80211_hdr_4addr
James Ketrenosb095c382005-08-24 22:04:42 -05004225 *)
4226 &notif->u.raw, &stats);
4227 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004228 }
James Ketrenosb095c382005-08-24 22:04:42 -05004229#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06004230
James Ketrenosa613bff2005-08-24 21:43:11 -05004231 schedule_work(&priv->link_up);
James Ketrenos43f66a62005-03-25 12:31:53 -06004232
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004233 break;
4234 }
4235
4236 case CMAS_AUTHENTICATED:{
4237 if (priv->
4238 status & (STATUS_ASSOCIATED |
4239 STATUS_AUTH)) {
Brice Goglin0f52bf92005-12-01 01:41:46 -08004240#ifdef CONFIG_IPW2200_DEBUG
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004241 struct notif_authenticate *auth
4242 = &notif->u.auth;
4243 IPW_DEBUG(IPW_DL_NOTIF |
4244 IPW_DL_STATE |
4245 IPW_DL_ASSOC,
4246 "deauthenticated: '%s' "
4247 MAC_FMT
4248 ": (0x%04X) - %s \n",
4249 escape_essid(priv->
4250 essid,
4251 priv->
4252 essid_len),
4253 MAC_ARG(priv->bssid),
4254 ntohs(auth->status),
4255 ipw_get_status_code
4256 (ntohs
4257 (auth->status)));
4258#endif
4259
4260 priv->status &=
4261 ~(STATUS_ASSOCIATING |
4262 STATUS_AUTH |
4263 STATUS_ASSOCIATED);
4264
James Ketrenosa613bff2005-08-24 21:43:11 -05004265 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004266 break;
4267 }
4268
4269 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4270 IPW_DL_ASSOC,
4271 "authenticated: '%s' " MAC_FMT
4272 "\n",
4273 escape_essid(priv->essid,
4274 priv->essid_len),
4275 MAC_ARG(priv->bssid));
4276 break;
4277 }
4278
4279 case CMAS_INIT:{
James Ketrenosea2b26e2005-08-24 21:25:16 -05004280 if (priv->status & STATUS_AUTH) {
4281 struct
4282 ieee80211_assoc_response
4283 *resp;
4284 resp =
4285 (struct
4286 ieee80211_assoc_response
4287 *)&notif->u.raw;
4288 IPW_DEBUG(IPW_DL_NOTIF |
4289 IPW_DL_STATE |
4290 IPW_DL_ASSOC,
4291 "association failed (0x%04X): %s\n",
4292 ntohs(resp->status),
4293 ipw_get_status_code
4294 (ntohs
4295 (resp->status)));
4296 }
4297
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004298 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4299 IPW_DL_ASSOC,
4300 "disassociated: '%s' " MAC_FMT
4301 " \n",
4302 escape_essid(priv->essid,
4303 priv->essid_len),
4304 MAC_ARG(priv->bssid));
4305
4306 priv->status &=
4307 ~(STATUS_DISASSOCIATING |
4308 STATUS_ASSOCIATING |
4309 STATUS_ASSOCIATED | STATUS_AUTH);
James Ketrenosb095c382005-08-24 22:04:42 -05004310 if (priv->assoc_network
4311 && (priv->assoc_network->
4312 capability &
4313 WLAN_CAPABILITY_IBSS))
4314 ipw_remove_current_network
4315 (priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004316
James Ketrenosa613bff2005-08-24 21:43:11 -05004317 schedule_work(&priv->link_down);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004318
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004319 break;
4320 }
4321
James Ketrenosb095c382005-08-24 22:04:42 -05004322 case CMAS_RX_ASSOC_RESP:
4323 break;
4324
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004325 default:
4326 IPW_ERROR("assoc: unknown (%d)\n",
4327 assoc->state);
4328 break;
4329 }
4330
James Ketrenos43f66a62005-03-25 12:31:53 -06004331 break;
4332 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004333
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004334 case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
4335 struct notif_authenticate *auth = &notif->u.auth;
4336 switch (auth->state) {
4337 case CMAS_AUTHENTICATED:
4338 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
4339 "authenticated: '%s' " MAC_FMT " \n",
4340 escape_essid(priv->essid,
4341 priv->essid_len),
4342 MAC_ARG(priv->bssid));
4343 priv->status |= STATUS_AUTH;
4344 break;
4345
4346 case CMAS_INIT:
4347 if (priv->status & STATUS_AUTH) {
4348 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4349 IPW_DL_ASSOC,
4350 "authentication failed (0x%04X): %s\n",
4351 ntohs(auth->status),
4352 ipw_get_status_code(ntohs
4353 (auth->
4354 status)));
4355 }
4356 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4357 IPW_DL_ASSOC,
4358 "deauthenticated: '%s' " MAC_FMT "\n",
4359 escape_essid(priv->essid,
4360 priv->essid_len),
4361 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06004362
4363 priv->status &= ~(STATUS_ASSOCIATING |
4364 STATUS_AUTH |
4365 STATUS_ASSOCIATED);
4366
James Ketrenosa613bff2005-08-24 21:43:11 -05004367 schedule_work(&priv->link_down);
James Ketrenos43f66a62005-03-25 12:31:53 -06004368 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004369
4370 case CMAS_TX_AUTH_SEQ_1:
4371 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4372 IPW_DL_ASSOC, "AUTH_SEQ_1\n");
4373 break;
4374 case CMAS_RX_AUTH_SEQ_2:
4375 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4376 IPW_DL_ASSOC, "AUTH_SEQ_2\n");
4377 break;
4378 case CMAS_AUTH_SEQ_1_PASS:
4379 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4380 IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
4381 break;
4382 case CMAS_AUTH_SEQ_1_FAIL:
4383 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4384 IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
4385 break;
4386 case CMAS_TX_AUTH_SEQ_3:
4387 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4388 IPW_DL_ASSOC, "AUTH_SEQ_3\n");
4389 break;
4390 case CMAS_RX_AUTH_SEQ_4:
4391 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4392 IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
4393 break;
4394 case CMAS_AUTH_SEQ_2_PASS:
4395 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4396 IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
4397 break;
4398 case CMAS_AUTH_SEQ_2_FAIL:
4399 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4400 IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
4401 break;
4402 case CMAS_TX_ASSOC:
4403 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4404 IPW_DL_ASSOC, "TX_ASSOC\n");
4405 break;
4406 case CMAS_RX_ASSOC_RESP:
4407 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4408 IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
James Ketrenosb095c382005-08-24 22:04:42 -05004409
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004410 break;
4411 case CMAS_ASSOCIATED:
4412 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
4413 IPW_DL_ASSOC, "ASSOCIATED\n");
4414 break;
4415 default:
4416 IPW_DEBUG_NOTIF("auth: failure - %d\n",
4417 auth->state);
4418 break;
4419 }
4420 break;
4421 }
4422
4423 case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
4424 struct notif_channel_result *x =
4425 &notif->u.channel_result;
4426
4427 if (notif->size == sizeof(*x)) {
4428 IPW_DEBUG_SCAN("Scan result for channel %d\n",
4429 x->channel_num);
4430 } else {
4431 IPW_DEBUG_SCAN("Scan result of wrong size %d "
4432 "(should be %zd)\n",
4433 notif->size, sizeof(*x));
4434 }
4435 break;
4436 }
4437
4438 case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
4439 struct notif_scan_complete *x = &notif->u.scan_complete;
4440 if (notif->size == sizeof(*x)) {
4441 IPW_DEBUG_SCAN
4442 ("Scan completed: type %d, %d channels, "
4443 "%d status\n", x->scan_type,
4444 x->num_channels, x->status);
4445 } else {
4446 IPW_ERROR("Scan completed of wrong size %d "
4447 "(should be %zd)\n",
4448 notif->size, sizeof(*x));
4449 }
4450
4451 priv->status &=
4452 ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
4453
James Ketrenosa0e04ab2005-08-25 00:49:43 -05004454 wake_up_interruptible(&priv->wait_state);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004455 cancel_delayed_work(&priv->scan_check);
4456
James Ketrenosb095c382005-08-24 22:04:42 -05004457 if (priv->status & STATUS_EXIT_PENDING)
4458 break;
4459
4460 priv->ieee->scans++;
4461
4462#ifdef CONFIG_IPW2200_MONITOR
4463 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05004464 priv->status |= STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004465 queue_work(priv->workqueue,
4466 &priv->request_scan);
4467 break;
4468 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05004469 priv->status &= ~STATUS_SCAN_FORCED;
James Ketrenosb095c382005-08-24 22:04:42 -05004470#endif /* CONFIG_IPW2200_MONITOR */
4471
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004472 if (!(priv->status & (STATUS_ASSOCIATED |
4473 STATUS_ASSOCIATING |
4474 STATUS_ROAMING |
4475 STATUS_DISASSOCIATING)))
4476 queue_work(priv->workqueue, &priv->associate);
4477 else if (priv->status & STATUS_ROAMING) {
Ben Cahille7582562005-10-06 15:34:41 -05004478 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE)
4479 /* If a scan completed and we are in roam mode, then
4480 * the scan that completed was the one requested as a
4481 * result of entering roam... so, schedule the
4482 * roam work */
4483 queue_work(priv->workqueue,
4484 &priv->roam);
4485 else
4486 /* Don't schedule if we aborted the scan */
4487 priv->status &= ~STATUS_ROAMING;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004488 } else if (priv->status & STATUS_SCAN_PENDING)
4489 queue_work(priv->workqueue,
4490 &priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -05004491 else if (priv->config & CFG_BACKGROUND_SCAN
4492 && priv->status & STATUS_ASSOCIATED)
4493 queue_delayed_work(priv->workqueue,
4494 &priv->request_scan, HZ);
Zhu Yi07f02e42006-04-13 17:19:25 +08004495
4496 /* Send an empty event to user space.
4497 * We don't send the received data on the event because
4498 * it would require us to do complex transcoding, and
4499 * we want to minimise the work done in the irq handler
4500 * Use a request to extract the data.
4501 * Also, we generate this even for any scan, regardless
4502 * on how the scan was initiated. User space can just
4503 * sync on periodic scan to get fresh data...
4504 * Jean II */
4505 if (x->status == SCAN_COMPLETED_STATUS_COMPLETE) {
4506 union iwreq_data wrqu;
4507
4508 wrqu.data.length = 0;
4509 wrqu.data.flags = 0;
4510 wireless_send_event(priv->net_dev, SIOCGIWSCAN,
4511 &wrqu, NULL);
4512 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004513 break;
4514 }
4515
4516 case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
4517 struct notif_frag_length *x = &notif->u.frag_len;
4518
James Ketrenosa613bff2005-08-24 21:43:11 -05004519 if (notif->size == sizeof(*x))
4520 IPW_ERROR("Frag length: %d\n",
4521 le16_to_cpu(x->frag_length));
4522 else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004523 IPW_ERROR("Frag length of wrong size %d "
4524 "(should be %zd)\n",
4525 notif->size, sizeof(*x));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004526 break;
4527 }
4528
4529 case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
4530 struct notif_link_deterioration *x =
4531 &notif->u.link_deterioration;
James Ketrenosafbf30a2005-08-25 00:05:33 -05004532
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004533 if (notif->size == sizeof(*x)) {
4534 IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
Cahill, Ben M12977152006-03-08 02:58:02 +08004535 "link deterioration: type %d, cnt %d\n",
4536 x->silence_notification_type,
4537 x->silence_count);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004538 memcpy(&priv->last_link_deterioration, x,
4539 sizeof(*x));
4540 } else {
4541 IPW_ERROR("Link Deterioration of wrong size %d "
4542 "(should be %zd)\n",
4543 notif->size, sizeof(*x));
4544 }
4545 break;
4546 }
4547
4548 case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
4549 IPW_ERROR("Dino config\n");
4550 if (priv->hcmd
James Ketrenosa613bff2005-08-24 21:43:11 -05004551 && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004552 IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05004553
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004554 break;
4555 }
4556
4557 case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
4558 struct notif_beacon_state *x = &notif->u.beacon_state;
4559 if (notif->size != sizeof(*x)) {
4560 IPW_ERROR
4561 ("Beacon state of wrong size %d (should "
4562 "be %zd)\n", notif->size, sizeof(*x));
4563 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004564 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004565
James Ketrenosa613bff2005-08-24 21:43:11 -05004566 if (le32_to_cpu(x->state) ==
4567 HOST_NOTIFICATION_STATUS_BEACON_MISSING)
4568 ipw_handle_missed_beacon(priv,
4569 le32_to_cpu(x->
4570 number));
Jeff Garzikbf794512005-07-31 13:07:26 -04004571
James Ketrenos43f66a62005-03-25 12:31:53 -06004572 break;
4573 }
Jeff Garzikbf794512005-07-31 13:07:26 -04004574
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004575 case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
4576 struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
4577 if (notif->size == sizeof(*x)) {
4578 IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
4579 "0x%02x station %d\n",
4580 x->key_state, x->security_type,
4581 x->station_index);
4582 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004583 }
4584
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004585 IPW_ERROR
4586 ("TGi Tx Key of wrong size %d (should be %zd)\n",
4587 notif->size, sizeof(*x));
4588 break;
4589 }
4590
4591 case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
4592 struct notif_calibration *x = &notif->u.calibration;
4593
4594 if (notif->size == sizeof(*x)) {
4595 memcpy(&priv->calib, x, sizeof(*x));
4596 IPW_DEBUG_INFO("TODO: Calibration\n");
4597 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06004598 }
4599
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004600 IPW_ERROR
4601 ("Calibration of wrong size %d (should be %zd)\n",
4602 notif->size, sizeof(*x));
James Ketrenos43f66a62005-03-25 12:31:53 -06004603 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004604 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004605
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004606 case HOST_NOTIFICATION_NOISE_STATS:{
4607 if (notif->size == sizeof(u32)) {
Zhu Yi00d21de2006-04-13 17:19:02 +08004608 priv->exp_avg_noise =
4609 exponential_average(priv->exp_avg_noise,
4610 (u8) (le32_to_cpu(notif->u.noise.value) & 0xff),
4611 DEPTH_NOISE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004612 break;
4613 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004614
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004615 IPW_ERROR
4616 ("Noise stat is wrong size %d (should be %zd)\n",
4617 notif->size, sizeof(u32));
James Ketrenos43f66a62005-03-25 12:31:53 -06004618 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04004619 }
4620
James Ketrenos43f66a62005-03-25 12:31:53 -06004621 default:
Zhu Yi1dd31b62006-02-20 18:28:09 -08004622 IPW_DEBUG_NOTIF("Unknown notification: "
4623 "subtype=%d,flags=0x%2x,size=%d\n",
4624 notif->subtype, notif->flags, notif->size);
James Ketrenos43f66a62005-03-25 12:31:53 -06004625 }
4626}
4627
4628/**
4629 * Destroys all DMA structures and initialise them again
Jeff Garzikbf794512005-07-31 13:07:26 -04004630 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004631 * @param priv
4632 * @return error code
4633 */
4634static int ipw_queue_reset(struct ipw_priv *priv)
4635{
4636 int rc = 0;
4637 /** @todo customize queue sizes */
4638 int nTx = 64, nTxCmd = 8;
4639 ipw_tx_queue_free(priv);
4640 /* Tx CMD queue */
4641 rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
James Ketrenosb095c382005-08-24 22:04:42 -05004642 IPW_TX_CMD_QUEUE_READ_INDEX,
4643 IPW_TX_CMD_QUEUE_WRITE_INDEX,
4644 IPW_TX_CMD_QUEUE_BD_BASE,
4645 IPW_TX_CMD_QUEUE_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004646 if (rc) {
4647 IPW_ERROR("Tx Cmd queue init failed\n");
4648 goto error;
4649 }
4650 /* Tx queue(s) */
4651 rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004652 IPW_TX_QUEUE_0_READ_INDEX,
4653 IPW_TX_QUEUE_0_WRITE_INDEX,
4654 IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004655 if (rc) {
4656 IPW_ERROR("Tx 0 queue init failed\n");
4657 goto error;
4658 }
4659 rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004660 IPW_TX_QUEUE_1_READ_INDEX,
4661 IPW_TX_QUEUE_1_WRITE_INDEX,
4662 IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004663 if (rc) {
4664 IPW_ERROR("Tx 1 queue init failed\n");
4665 goto error;
4666 }
4667 rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004668 IPW_TX_QUEUE_2_READ_INDEX,
4669 IPW_TX_QUEUE_2_WRITE_INDEX,
4670 IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004671 if (rc) {
4672 IPW_ERROR("Tx 2 queue init failed\n");
4673 goto error;
4674 }
4675 rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
James Ketrenosb095c382005-08-24 22:04:42 -05004676 IPW_TX_QUEUE_3_READ_INDEX,
4677 IPW_TX_QUEUE_3_WRITE_INDEX,
4678 IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004679 if (rc) {
4680 IPW_ERROR("Tx 3 queue init failed\n");
4681 goto error;
4682 }
4683 /* statistics */
4684 priv->rx_bufs_min = 0;
4685 priv->rx_pend_max = 0;
4686 return rc;
4687
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004688 error:
James Ketrenos43f66a62005-03-25 12:31:53 -06004689 ipw_tx_queue_free(priv);
4690 return rc;
4691}
4692
4693/**
4694 * Reclaim Tx queue entries no more used by NIC.
Jeff Garzikbf794512005-07-31 13:07:26 -04004695 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004696 * When FW adwances 'R' index, all entries between old and
4697 * new 'R' index need to be reclaimed. As result, some free space
4698 * forms. If there is enough free space (> low mark), wake Tx queue.
Jeff Garzikbf794512005-07-31 13:07:26 -04004699 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004700 * @note Need to protect against garbage in 'R' index
4701 * @param priv
4702 * @param txq
4703 * @param qindex
4704 * @return Number of used entries remains in the queue
4705 */
Jeff Garzikbf794512005-07-31 13:07:26 -04004706static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06004707 struct clx2_tx_queue *txq, int qindex)
4708{
4709 u32 hw_tail;
4710 int used;
4711 struct clx2_queue *q = &txq->q;
4712
4713 hw_tail = ipw_read32(priv, q->reg_r);
4714 if (hw_tail >= q->n_bd) {
4715 IPW_ERROR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004716 ("Read index for DMA queue (%d) is out of range [0-%d)\n",
4717 hw_tail, q->n_bd);
James Ketrenos43f66a62005-03-25 12:31:53 -06004718 goto done;
4719 }
4720 for (; q->last_used != hw_tail;
4721 q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
4722 ipw_queue_tx_free_tfd(priv, txq);
4723 priv->tx_packets++;
4724 }
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004725 done:
James Ketrenos9ddf84f2005-08-16 17:07:11 -05004726 if ((ipw_queue_space(q) > q->low_mark) &&
4727 (qindex >= 0) &&
4728 (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
4729 netif_wake_queue(priv->net_dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06004730 used = q->first_empty - q->last_used;
4731 if (used < 0)
4732 used += q->n_bd;
4733
4734 return used;
4735}
4736
4737static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
4738 int len, int sync)
4739{
4740 struct clx2_tx_queue *txq = &priv->txq_cmd;
4741 struct clx2_queue *q = &txq->q;
4742 struct tfd_frame *tfd;
4743
4744 if (ipw_queue_space(q) < (sync ? 1 : 2)) {
4745 IPW_ERROR("No space for Tx\n");
4746 return -EBUSY;
4747 }
4748
4749 tfd = &txq->bd[q->first_empty];
4750 txq->txb[q->first_empty] = NULL;
4751
4752 memset(tfd, 0, sizeof(*tfd));
4753 tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
4754 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
4755 priv->hcmd_seq++;
4756 tfd->u.cmd.index = hcmd;
4757 tfd->u.cmd.length = len;
4758 memcpy(tfd->u.cmd.payload, buf, len);
4759 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
4760 ipw_write32(priv, q->reg_w, q->first_empty);
4761 _ipw_read32(priv, 0x90);
4762
4763 return 0;
4764}
4765
Jeff Garzikbf794512005-07-31 13:07:26 -04004766/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004767 * Rx theory of operation
4768 *
4769 * The host allocates 32 DMA target addresses and passes the host address
James Ketrenosb095c382005-08-24 22:04:42 -05004770 * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
James Ketrenos43f66a62005-03-25 12:31:53 -06004771 * 0 to 31
4772 *
4773 * Rx Queue Indexes
4774 * The host/firmware share two index registers for managing the Rx buffers.
4775 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004776 * The READ index maps to the first position that the firmware may be writing
4777 * to -- the driver can read up to (but not including) this position and get
4778 * good data.
James Ketrenos43f66a62005-03-25 12:31:53 -06004779 * The READ index is managed by the firmware once the card is enabled.
4780 *
4781 * The WRITE index maps to the last position the driver has read from -- the
4782 * position preceding WRITE is the last slot the firmware can place a packet.
4783 *
4784 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
Jeff Garzikbf794512005-07-31 13:07:26 -04004785 * WRITE = READ.
James Ketrenos43f66a62005-03-25 12:31:53 -06004786 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004787 * During initialization the host sets up the READ queue position to the first
James Ketrenos43f66a62005-03-25 12:31:53 -06004788 * INDEX position, and WRITE to the last (READ - 1 wrapped)
4789 *
4790 * When the firmware places a packet in a buffer it will advance the READ index
4791 * and fire the RX interrupt. The driver can then query the READ index and
4792 * process as many packets as possible, moving the WRITE index forward as it
4793 * resets the Rx queue buffers with new memory.
Jeff Garzikbf794512005-07-31 13:07:26 -04004794 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004795 * The management in the driver is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04004796 * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
James Ketrenos43f66a62005-03-25 12:31:53 -06004797 * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Jeff Garzikbf794512005-07-31 13:07:26 -04004798 * to replensish the ipw->rxq->rx_free.
James Ketrenos43f66a62005-03-25 12:31:53 -06004799 * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
4800 * ipw->rxq is replenished and the READ INDEX is updated (updating the
4801 * 'processed' and 'read' driver indexes as well)
4802 * + A received packet is processed and handed to the kernel network stack,
4803 * detached from the ipw->rxq. The driver 'processed' index is updated.
4804 * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
Jeff Garzikbf794512005-07-31 13:07:26 -04004805 * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
4806 * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
James Ketrenos43f66a62005-03-25 12:31:53 -06004807 * were enough free buffers and RX_STALLED is set it is cleared.
4808 *
4809 *
4810 * Driver sequence:
4811 *
Jeff Garzikbf794512005-07-31 13:07:26 -04004812 * ipw_rx_queue_alloc() Allocates rx_free
James Ketrenos43f66a62005-03-25 12:31:53 -06004813 * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
4814 * ipw_rx_queue_restock
4815 * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
4816 * queue, updates firmware pointers, and updates
4817 * the WRITE index. If insufficient rx_free buffers
4818 * are available, schedules ipw_rx_queue_replenish
4819 *
4820 * -- enable interrupts --
4821 * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
Jeff Garzikbf794512005-07-31 13:07:26 -04004822 * READ INDEX, detaching the SKB from the pool.
James Ketrenos43f66a62005-03-25 12:31:53 -06004823 * Moves the packet buffer from queue to rx_used.
4824 * Calls ipw_rx_queue_restock to refill any empty
4825 * slots.
4826 * ...
4827 *
4828 */
4829
Jeff Garzikbf794512005-07-31 13:07:26 -04004830/*
James Ketrenos43f66a62005-03-25 12:31:53 -06004831 * If there are slots in the RX queue that need to be restocked,
4832 * and we have free pre-allocated buffers, fill the ranks as much
4833 * as we can pulling from rx_free.
4834 *
4835 * This moves the 'write' index forward to catch up with 'processed', and
4836 * also updates the memory address in the firmware to reference the new
4837 * target buffer.
4838 */
4839static void ipw_rx_queue_restock(struct ipw_priv *priv)
4840{
4841 struct ipw_rx_queue *rxq = priv->rxq;
4842 struct list_head *element;
4843 struct ipw_rx_mem_buffer *rxb;
4844 unsigned long flags;
4845 int write;
4846
4847 spin_lock_irqsave(&rxq->lock, flags);
4848 write = rxq->write;
4849 while ((rxq->write != rxq->processed) && (rxq->free_count)) {
4850 element = rxq->rx_free.next;
4851 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
4852 list_del(element);
4853
James Ketrenosb095c382005-08-24 22:04:42 -05004854 ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06004855 rxb->dma_addr);
4856 rxq->queue[rxq->write] = rxb;
4857 rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
4858 rxq->free_count--;
4859 }
4860 spin_unlock_irqrestore(&rxq->lock, flags);
4861
Jeff Garzikbf794512005-07-31 13:07:26 -04004862 /* If the pre-allocated buffer pool is dropping low, schedule to
James Ketrenos43f66a62005-03-25 12:31:53 -06004863 * refill it */
4864 if (rxq->free_count <= RX_LOW_WATERMARK)
4865 queue_work(priv->workqueue, &priv->rx_replenish);
4866
4867 /* If we've added more space for the firmware to place data, tell it */
Jeff Garzikbf794512005-07-31 13:07:26 -04004868 if (write != rxq->write)
James Ketrenosb095c382005-08-24 22:04:42 -05004869 ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
James Ketrenos43f66a62005-03-25 12:31:53 -06004870}
4871
4872/*
4873 * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
Jeff Garzikbf794512005-07-31 13:07:26 -04004874 * Also restock the Rx queue via ipw_rx_queue_restock.
4875 *
James Ketrenos43f66a62005-03-25 12:31:53 -06004876 * This is called as a scheduled work item (except for during intialization)
4877 */
4878static void ipw_rx_queue_replenish(void *data)
4879{
4880 struct ipw_priv *priv = data;
4881 struct ipw_rx_queue *rxq = priv->rxq;
4882 struct list_head *element;
4883 struct ipw_rx_mem_buffer *rxb;
4884 unsigned long flags;
4885
4886 spin_lock_irqsave(&rxq->lock, flags);
4887 while (!list_empty(&rxq->rx_used)) {
4888 element = rxq->rx_used.next;
4889 rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
James Ketrenosb095c382005-08-24 22:04:42 -05004890 rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
James Ketrenos43f66a62005-03-25 12:31:53 -06004891 if (!rxb->skb) {
4892 printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
4893 priv->net_dev->name);
4894 /* We don't reschedule replenish work here -- we will
4895 * call the restock method and if it still needs
4896 * more buffers it will schedule replenish */
4897 break;
4898 }
4899 list_del(element);
Jeff Garzikbf794512005-07-31 13:07:26 -04004900
James Ketrenos43f66a62005-03-25 12:31:53 -06004901 rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004902 rxb->dma_addr =
4903 pci_map_single(priv->pci_dev, rxb->skb->data,
James Ketrenosb095c382005-08-24 22:04:42 -05004904 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
Jeff Garzikbf794512005-07-31 13:07:26 -04004905
James Ketrenos43f66a62005-03-25 12:31:53 -06004906 list_add_tail(&rxb->list, &rxq->rx_free);
4907 rxq->free_count++;
4908 }
4909 spin_unlock_irqrestore(&rxq->lock, flags);
4910
4911 ipw_rx_queue_restock(priv);
4912}
4913
James Ketrenosc848d0a2005-08-24 21:56:24 -05004914static void ipw_bg_rx_queue_replenish(void *data)
4915{
4916 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08004917 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004918 ipw_rx_queue_replenish(data);
Zhu Yi46441512006-01-24 16:37:59 +08004919 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05004920}
4921
James Ketrenos43f66a62005-03-25 12:31:53 -06004922/* Assumes that the skb field of the buffers in 'pool' is kept accurate.
Zhu Yic7b6a672006-01-24 16:37:05 +08004923 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
Jeff Garzikbf794512005-07-31 13:07:26 -04004924 * This free routine walks the list of POOL entries and if SKB is set to
James Ketrenos43f66a62005-03-25 12:31:53 -06004925 * non NULL it is unmapped and freed
4926 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004927static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
James Ketrenos43f66a62005-03-25 12:31:53 -06004928{
4929 int i;
4930
4931 if (!rxq)
4932 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04004933
James Ketrenos43f66a62005-03-25 12:31:53 -06004934 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
4935 if (rxq->pool[i].skb != NULL) {
4936 pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05004937 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06004938 dev_kfree_skb(rxq->pool[i].skb);
4939 }
4940 }
4941
4942 kfree(rxq);
4943}
4944
4945static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
4946{
4947 struct ipw_rx_queue *rxq;
4948 int i;
4949
Takisc75f4742005-12-01 01:41:45 -08004950 rxq = kzalloc(sizeof(*rxq), GFP_KERNEL);
Panagiotis Issarisad18b0e2005-09-05 04:14:10 +02004951 if (unlikely(!rxq)) {
4952 IPW_ERROR("memory allocation failed\n");
4953 return NULL;
4954 }
James Ketrenos43f66a62005-03-25 12:31:53 -06004955 spin_lock_init(&rxq->lock);
4956 INIT_LIST_HEAD(&rxq->rx_free);
4957 INIT_LIST_HEAD(&rxq->rx_used);
4958
4959 /* Fill the rx_used queue with _all_ of the Rx buffers */
Jeff Garzikbf794512005-07-31 13:07:26 -04004960 for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
James Ketrenos43f66a62005-03-25 12:31:53 -06004961 list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
4962
4963 /* Set us so that we have processed and used all buffers, but have
4964 * not restocked the Rx queue with fresh buffers */
4965 rxq->read = rxq->write = 0;
4966 rxq->processed = RX_QUEUE_SIZE - 1;
4967 rxq->free_count = 0;
4968
4969 return rxq;
4970}
4971
4972static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
4973{
4974 rate &= ~IEEE80211_BASIC_RATE_MASK;
4975 if (ieee_mode == IEEE_A) {
4976 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04004977 case IEEE80211_OFDM_RATE_6MB:
4978 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004979 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004980 case IEEE80211_OFDM_RATE_9MB:
4981 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004982 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004983 case IEEE80211_OFDM_RATE_12MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004984 return priv->
4985 rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004986 case IEEE80211_OFDM_RATE_18MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004987 return priv->
4988 rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004989 case IEEE80211_OFDM_RATE_24MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004990 return priv->
4991 rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004992 case IEEE80211_OFDM_RATE_36MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004993 return priv->
4994 rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004995 case IEEE80211_OFDM_RATE_48MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004996 return priv->
4997 rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04004998 case IEEE80211_OFDM_RATE_54MB:
Jeff Garzik0edd5b42005-09-07 00:48:31 -04004999 return priv->
5000 rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005001 default:
5002 return 0;
5003 }
5004 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005005
James Ketrenos43f66a62005-03-25 12:31:53 -06005006 /* B and G mixed */
5007 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005008 case IEEE80211_CCK_RATE_1MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005009 return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005010 case IEEE80211_CCK_RATE_2MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005011 return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005012 case IEEE80211_CCK_RATE_5MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005013 return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005014 case IEEE80211_CCK_RATE_11MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005015 return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
5016 }
5017
5018 /* If we are limited to B modulations, bail at this point */
5019 if (ieee_mode == IEEE_B)
5020 return 0;
5021
5022 /* G */
5023 switch (rate) {
Jeff Garzikbf794512005-07-31 13:07:26 -04005024 case IEEE80211_OFDM_RATE_6MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005025 return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005026 case IEEE80211_OFDM_RATE_9MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005027 return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005028 case IEEE80211_OFDM_RATE_12MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005029 return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005030 case IEEE80211_OFDM_RATE_18MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005031 return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005032 case IEEE80211_OFDM_RATE_24MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005033 return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005034 case IEEE80211_OFDM_RATE_36MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005035 return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005036 case IEEE80211_OFDM_RATE_48MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005037 return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005038 case IEEE80211_OFDM_RATE_54MB:
James Ketrenos43f66a62005-03-25 12:31:53 -06005039 return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
5040 }
5041
5042 return 0;
5043}
5044
Jeff Garzikbf794512005-07-31 13:07:26 -04005045static int ipw_compatible_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -06005046 const struct ieee80211_network *network,
5047 struct ipw_supported_rates *rates)
5048{
5049 int num_rates, i;
5050
5051 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005052 num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06005053 rates->num_rates = 0;
5054 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005055 if (!ipw_is_rate_in_mask(priv, network->mode,
5056 network->rates[i])) {
5057
James Ketrenosea2b26e2005-08-24 21:25:16 -05005058 if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005059 IPW_DEBUG_SCAN("Adding masked mandatory "
5060 "rate %02X\n",
5061 network->rates[i]);
5062 rates->supported_rates[rates->num_rates++] =
5063 network->rates[i];
5064 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005065 }
5066
James Ketrenos43f66a62005-03-25 12:31:53 -06005067 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5068 network->rates[i], priv->rates_mask);
5069 continue;
5070 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005071
James Ketrenos43f66a62005-03-25 12:31:53 -06005072 rates->supported_rates[rates->num_rates++] = network->rates[i];
5073 }
5074
James Ketrenosa613bff2005-08-24 21:43:11 -05005075 num_rates = min(network->rates_ex_len,
5076 (u8) (IPW_MAX_RATES - num_rates));
James Ketrenos43f66a62005-03-25 12:31:53 -06005077 for (i = 0; i < num_rates; i++) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005078 if (!ipw_is_rate_in_mask(priv, network->mode,
5079 network->rates_ex[i])) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05005080 if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
James Ketrenosa613bff2005-08-24 21:43:11 -05005081 IPW_DEBUG_SCAN("Adding masked mandatory "
5082 "rate %02X\n",
5083 network->rates_ex[i]);
5084 rates->supported_rates[rates->num_rates++] =
5085 network->rates[i];
5086 continue;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005087 }
5088
James Ketrenos43f66a62005-03-25 12:31:53 -06005089 IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
5090 network->rates_ex[i], priv->rates_mask);
5091 continue;
5092 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005093
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005094 rates->supported_rates[rates->num_rates++] =
5095 network->rates_ex[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06005096 }
5097
James Ketrenosea2b26e2005-08-24 21:25:16 -05005098 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06005099}
5100
Arjan van de Ven858119e2006-01-14 13:20:43 -08005101static void ipw_copy_rates(struct ipw_supported_rates *dest,
James Ketrenos43f66a62005-03-25 12:31:53 -06005102 const struct ipw_supported_rates *src)
5103{
5104 u8 i;
5105 for (i = 0; i < src->num_rates; i++)
5106 dest->supported_rates[i] = src->supported_rates[i];
5107 dest->num_rates = src->num_rates;
5108}
5109
5110/* TODO: Look at sniffed packets in the air to determine if the basic rate
5111 * mask should ever be used -- right now all callers to add the scan rates are
5112 * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
5113static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005114 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005115{
Jeff Garzikbf794512005-07-31 13:07:26 -04005116 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005117 IEEE80211_BASIC_RATE_MASK : 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005118
James Ketrenos43f66a62005-03-25 12:31:53 -06005119 if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005120 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005121 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005122
5123 if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005124 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005125 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005126
5127 if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005128 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005129 IEEE80211_CCK_RATE_5MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005130
5131 if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005132 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005133 IEEE80211_CCK_RATE_11MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005134}
5135
5136static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005137 u8 modulation, u32 rate_mask)
James Ketrenos43f66a62005-03-25 12:31:53 -06005138{
Jeff Garzikbf794512005-07-31 13:07:26 -04005139 u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005140 IEEE80211_BASIC_RATE_MASK : 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005141
5142 if (rate_mask & IEEE80211_OFDM_RATE_6MB_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_OFDM_RATE_6MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005145
5146 if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005147 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005148 IEEE80211_OFDM_RATE_9MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005149
5150 if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005151 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005152 IEEE80211_OFDM_RATE_12MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005153
5154 if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005155 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005156 IEEE80211_OFDM_RATE_18MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005157
5158 if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005159 rates->supported_rates[rates->num_rates++] = basic_mask |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005160 IEEE80211_OFDM_RATE_24MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005161
5162 if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005163 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005164 IEEE80211_OFDM_RATE_36MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005165
5166 if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005167 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005168 IEEE80211_OFDM_RATE_48MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005169
5170 if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
Jeff Garzikbf794512005-07-31 13:07:26 -04005171 rates->supported_rates[rates->num_rates++] =
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005172 IEEE80211_OFDM_RATE_54MB;
James Ketrenos43f66a62005-03-25 12:31:53 -06005173}
5174
5175struct ipw_network_match {
5176 struct ieee80211_network *network;
5177 struct ipw_supported_rates rates;
5178};
5179
James Ketrenosc848d0a2005-08-24 21:56:24 -05005180static int ipw_find_adhoc_network(struct ipw_priv *priv,
5181 struct ipw_network_match *match,
5182 struct ieee80211_network *network,
5183 int roaming)
5184{
5185 struct ipw_supported_rates rates;
5186
5187 /* Verify that this network's capability is compatible with the
5188 * current mode (AdHoc or Infrastructure) */
5189 if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
5190 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5191 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
5192 "capability mismatch.\n",
5193 escape_essid(network->ssid, network->ssid_len),
5194 MAC_ARG(network->bssid));
5195 return 0;
5196 }
5197
5198 /* If we do not have an ESSID for this AP, we can not associate with
5199 * it */
5200 if (network->flags & NETWORK_EMPTY_ESSID) {
5201 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5202 "because of hidden ESSID.\n",
5203 escape_essid(network->ssid, network->ssid_len),
5204 MAC_ARG(network->bssid));
5205 return 0;
5206 }
5207
5208 if (unlikely(roaming)) {
5209 /* If we are roaming, then ensure check if this is a valid
5210 * network to try and roam to */
5211 if ((network->ssid_len != match->network->ssid_len) ||
5212 memcmp(network->ssid, match->network->ssid,
5213 network->ssid_len)) {
5214 IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
5215 "because of non-network ESSID.\n",
5216 escape_essid(network->ssid,
5217 network->ssid_len),
5218 MAC_ARG(network->bssid));
5219 return 0;
5220 }
5221 } else {
5222 /* If an ESSID has been configured then compare the broadcast
5223 * ESSID to ours */
5224 if ((priv->config & CFG_STATIC_ESSID) &&
5225 ((network->ssid_len != priv->essid_len) ||
5226 memcmp(network->ssid, priv->essid,
5227 min(network->ssid_len, priv->essid_len)))) {
5228 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
James Ketrenosafbf30a2005-08-25 00:05:33 -05005229
James Ketrenosc848d0a2005-08-24 21:56:24 -05005230 strncpy(escaped,
5231 escape_essid(network->ssid, network->ssid_len),
5232 sizeof(escaped));
5233 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5234 "because of ESSID mismatch: '%s'.\n",
5235 escaped, MAC_ARG(network->bssid),
5236 escape_essid(priv->essid,
5237 priv->essid_len));
5238 return 0;
5239 }
5240 }
5241
5242 /* If the old network rate is better than this one, don't bother
5243 * testing everything else. */
5244
5245 if (network->time_stamp[0] < match->network->time_stamp[0]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005246 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5247 "current network.\n",
5248 escape_essid(match->network->ssid,
5249 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005250 return 0;
5251 } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005252 IPW_DEBUG_MERGE("Network '%s excluded because newer than "
5253 "current network.\n",
5254 escape_essid(match->network->ssid,
5255 match->network->ssid_len));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005256 return 0;
5257 }
5258
5259 /* Now go through and see if the requested network is valid... */
5260 if (priv->ieee->scan_age != 0 &&
5261 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
5262 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005263 "because of age: %ums.\n",
James Ketrenosc848d0a2005-08-24 21:56:24 -05005264 escape_essid(network->ssid, network->ssid_len),
5265 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005266 jiffies_to_msecs(jiffies -
5267 network->last_scanned));
James Ketrenosc848d0a2005-08-24 21:56:24 -05005268 return 0;
5269 }
5270
5271 if ((priv->config & CFG_STATIC_CHANNEL) &&
5272 (network->channel != priv->channel)) {
5273 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5274 "because of channel mismatch: %d != %d.\n",
5275 escape_essid(network->ssid, network->ssid_len),
5276 MAC_ARG(network->bssid),
5277 network->channel, priv->channel);
5278 return 0;
5279 }
5280
5281 /* Verify privacy compatability */
5282 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
5283 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5284 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5285 "because of privacy mismatch: %s != %s.\n",
5286 escape_essid(network->ssid, network->ssid_len),
5287 MAC_ARG(network->bssid),
James Ketrenosafbf30a2005-08-25 00:05:33 -05005288 priv->
5289 capability & CAP_PRIVACY_ON ? "on" : "off",
5290 network->
5291 capability & WLAN_CAPABILITY_PRIVACY ? "on" :
5292 "off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05005293 return 0;
5294 }
5295
5296 if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5297 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5298 "because of the same BSSID match: " MAC_FMT
5299 ".\n", escape_essid(network->ssid,
5300 network->ssid_len),
5301 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
5302 return 0;
5303 }
5304
5305 /* Filter out any incompatible freq / mode combinations */
5306 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5307 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5308 "because of invalid frequency/mode "
5309 "combination.\n",
5310 escape_essid(network->ssid, network->ssid_len),
5311 MAC_ARG(network->bssid));
5312 return 0;
5313 }
5314
5315 /* Ensure that the rates supported by the driver are compatible with
5316 * this AP, including verification of basic rates (mandatory) */
5317 if (!ipw_compatible_rates(priv, network, &rates)) {
5318 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5319 "because configured rate mask excludes "
5320 "AP mandatory rate.\n",
5321 escape_essid(network->ssid, network->ssid_len),
5322 MAC_ARG(network->bssid));
5323 return 0;
5324 }
5325
5326 if (rates.num_rates == 0) {
5327 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
5328 "because of no compatible rates.\n",
5329 escape_essid(network->ssid, network->ssid_len),
5330 MAC_ARG(network->bssid));
5331 return 0;
5332 }
5333
5334 /* TODO: Perform any further minimal comparititive tests. We do not
5335 * want to put too much policy logic here; intelligent scan selection
5336 * should occur within a generic IEEE 802.11 user space tool. */
5337
5338 /* Set up 'new' AP to this network */
5339 ipw_copy_rates(&match->rates, &rates);
5340 match->network = network;
5341 IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
5342 escape_essid(network->ssid, network->ssid_len),
5343 MAC_ARG(network->bssid));
5344
5345 return 1;
5346}
5347
5348static void ipw_merge_adhoc_network(void *data)
5349{
5350 struct ipw_priv *priv = data;
5351 struct ieee80211_network *network = NULL;
5352 struct ipw_network_match match = {
5353 .network = priv->assoc_network
5354 };
5355
James Ketrenosafbf30a2005-08-25 00:05:33 -05005356 if ((priv->status & STATUS_ASSOCIATED) &&
5357 (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
James Ketrenosc848d0a2005-08-24 21:56:24 -05005358 /* First pass through ROAM process -- look for a better
5359 * network */
5360 unsigned long flags;
5361
5362 spin_lock_irqsave(&priv->ieee->lock, flags);
5363 list_for_each_entry(network, &priv->ieee->network_list, list) {
5364 if (network != priv->assoc_network)
5365 ipw_find_adhoc_network(priv, &match, network,
5366 1);
5367 }
5368 spin_unlock_irqrestore(&priv->ieee->lock, flags);
5369
5370 if (match.network == priv->assoc_network) {
5371 IPW_DEBUG_MERGE("No better ADHOC in this network to "
5372 "merge to.\n");
5373 return;
5374 }
5375
Zhu Yi46441512006-01-24 16:37:59 +08005376 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005377 if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
5378 IPW_DEBUG_MERGE("remove network %s\n",
5379 escape_essid(priv->essid,
5380 priv->essid_len));
5381 ipw_remove_current_network(priv);
5382 }
5383
5384 ipw_disassociate(priv);
5385 priv->assoc_network = match.network;
Zhu Yi46441512006-01-24 16:37:59 +08005386 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005387 return;
5388 }
James Ketrenosc848d0a2005-08-24 21:56:24 -05005389}
5390
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005391static int ipw_best_network(struct ipw_priv *priv,
5392 struct ipw_network_match *match,
5393 struct ieee80211_network *network, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06005394{
5395 struct ipw_supported_rates rates;
5396
5397 /* Verify that this network's capability is compatible with the
5398 * current mode (AdHoc or Infrastructure) */
5399 if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
Jouni Malinen24743852005-08-14 20:59:59 -07005400 !(network->capability & WLAN_CAPABILITY_ESS)) ||
James Ketrenos43f66a62005-03-25 12:31:53 -06005401 (priv->ieee->iw_mode == IW_MODE_ADHOC &&
5402 !(network->capability & WLAN_CAPABILITY_IBSS))) {
5403 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
Jeff Garzikbf794512005-07-31 13:07:26 -04005404 "capability mismatch.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005405 escape_essid(network->ssid, network->ssid_len),
5406 MAC_ARG(network->bssid));
5407 return 0;
5408 }
5409
5410 /* If we do not have an ESSID for this AP, we can not associate with
5411 * it */
5412 if (network->flags & NETWORK_EMPTY_ESSID) {
5413 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5414 "because of hidden ESSID.\n",
5415 escape_essid(network->ssid, network->ssid_len),
5416 MAC_ARG(network->bssid));
5417 return 0;
5418 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005419
James Ketrenos43f66a62005-03-25 12:31:53 -06005420 if (unlikely(roaming)) {
5421 /* If we are roaming, then ensure check if this is a valid
5422 * network to try and roam to */
5423 if ((network->ssid_len != match->network->ssid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005424 memcmp(network->ssid, match->network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005425 network->ssid_len)) {
5426 IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
5427 "because of non-network ESSID.\n",
Jeff Garzikbf794512005-07-31 13:07:26 -04005428 escape_essid(network->ssid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005429 network->ssid_len),
5430 MAC_ARG(network->bssid));
5431 return 0;
5432 }
5433 } else {
Jeff Garzikbf794512005-07-31 13:07:26 -04005434 /* If an ESSID has been configured then compare the broadcast
5435 * ESSID to ours */
5436 if ((priv->config & CFG_STATIC_ESSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005437 ((network->ssid_len != priv->essid_len) ||
Jeff Garzikbf794512005-07-31 13:07:26 -04005438 memcmp(network->ssid, priv->essid,
James Ketrenos43f66a62005-03-25 12:31:53 -06005439 min(network->ssid_len, priv->essid_len)))) {
5440 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005441 strncpy(escaped,
5442 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005443 sizeof(escaped));
5444 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Jeff Garzikbf794512005-07-31 13:07:26 -04005445 "because of ESSID mismatch: '%s'.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005446 escaped, MAC_ARG(network->bssid),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005447 escape_essid(priv->essid,
5448 priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005449 return 0;
5450 }
5451 }
5452
5453 /* If the old network rate is better than this one, don't bother
5454 * testing everything else. */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005455 if (match->network && match->network->stats.rssi > network->stats.rssi) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005456 char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
Jeff Garzikbf794512005-07-31 13:07:26 -04005457 strncpy(escaped,
5458 escape_essid(network->ssid, network->ssid_len),
James Ketrenos43f66a62005-03-25 12:31:53 -06005459 sizeof(escaped));
5460 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
5461 "'%s (" MAC_FMT ")' has a stronger signal.\n",
5462 escaped, MAC_ARG(network->bssid),
5463 escape_essid(match->network->ssid,
5464 match->network->ssid_len),
5465 MAC_ARG(match->network->bssid));
5466 return 0;
5467 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005468
James Ketrenos43f66a62005-03-25 12:31:53 -06005469 /* If this network has already had an association attempt within the
5470 * last 3 seconds, do not try and associate again... */
5471 if (network->last_associate &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005472 time_after(network->last_associate + (HZ * 3UL), jiffies)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005473 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005474 "because of storming (%ums since last "
James Ketrenos43f66a62005-03-25 12:31:53 -06005475 "assoc attempt).\n",
5476 escape_essid(network->ssid, network->ssid_len),
5477 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005478 jiffies_to_msecs(jiffies -
5479 network->last_associate));
James Ketrenos43f66a62005-03-25 12:31:53 -06005480 return 0;
5481 }
5482
5483 /* Now go through and see if the requested network is valid... */
Jeff Garzikbf794512005-07-31 13:07:26 -04005484 if (priv->ieee->scan_age != 0 &&
James Ketrenosea2b26e2005-08-24 21:25:16 -05005485 time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005486 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
Zhu Yic7b6a672006-01-24 16:37:05 +08005487 "because of age: %ums.\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06005488 escape_essid(network->ssid, network->ssid_len),
5489 MAC_ARG(network->bssid),
Zhu Yi2638bc32006-01-24 16:37:52 +08005490 jiffies_to_msecs(jiffies -
5491 network->last_scanned));
James Ketrenos43f66a62005-03-25 12:31:53 -06005492 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04005493 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005494
Jeff Garzikbf794512005-07-31 13:07:26 -04005495 if ((priv->config & CFG_STATIC_CHANNEL) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005496 (network->channel != priv->channel)) {
5497 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5498 "because of channel mismatch: %d != %d.\n",
5499 escape_essid(network->ssid, network->ssid_len),
5500 MAC_ARG(network->bssid),
5501 network->channel, priv->channel);
5502 return 0;
5503 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005504
James Ketrenos43f66a62005-03-25 12:31:53 -06005505 /* Verify privacy compatability */
Jeff Garzikbf794512005-07-31 13:07:26 -04005506 if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
James Ketrenos43f66a62005-03-25 12:31:53 -06005507 ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
5508 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5509 "because of privacy mismatch: %s != %s.\n",
5510 escape_essid(network->ssid, network->ssid_len),
5511 MAC_ARG(network->bssid),
Jeff Garzikbf794512005-07-31 13:07:26 -04005512 priv->capability & CAP_PRIVACY_ON ? "on" :
James Ketrenos43f66a62005-03-25 12:31:53 -06005513 "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04005514 network->capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005515 WLAN_CAPABILITY_PRIVACY ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06005516 return 0;
5517 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005518
5519 if ((priv->config & CFG_STATIC_BSSID) &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005520 memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
5521 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5522 "because of BSSID mismatch: " MAC_FMT ".\n",
5523 escape_essid(network->ssid, network->ssid_len),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005524 MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005525 return 0;
5526 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005527
James Ketrenos43f66a62005-03-25 12:31:53 -06005528 /* Filter out any incompatible freq / mode combinations */
5529 if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
5530 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5531 "because of invalid frequency/mode "
5532 "combination.\n",
5533 escape_essid(network->ssid, network->ssid_len),
5534 MAC_ARG(network->bssid));
5535 return 0;
5536 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005537
Liu Hong1fe0adb2005-08-19 09:33:10 -05005538 /* Filter out invalid channel in current GEO */
Larry Finger1867b112006-02-28 09:48:28 -06005539 if (!ieee80211_is_valid_channel(priv->ieee, network->channel)) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005540 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5541 "because of invalid channel in current GEO\n",
5542 escape_essid(network->ssid, network->ssid_len),
5543 MAC_ARG(network->bssid));
5544 return 0;
5545 }
5546
James Ketrenosea2b26e2005-08-24 21:25:16 -05005547 /* Ensure that the rates supported by the driver are compatible with
5548 * this AP, including verification of basic rates (mandatory) */
5549 if (!ipw_compatible_rates(priv, network, &rates)) {
5550 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5551 "because configured rate mask excludes "
5552 "AP mandatory rate.\n",
5553 escape_essid(network->ssid, network->ssid_len),
5554 MAC_ARG(network->bssid));
5555 return 0;
5556 }
5557
James Ketrenos43f66a62005-03-25 12:31:53 -06005558 if (rates.num_rates == 0) {
5559 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
5560 "because of no compatible rates.\n",
5561 escape_essid(network->ssid, network->ssid_len),
5562 MAC_ARG(network->bssid));
5563 return 0;
5564 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005565
James Ketrenos43f66a62005-03-25 12:31:53 -06005566 /* TODO: Perform any further minimal comparititive tests. We do not
5567 * want to put too much policy logic here; intelligent scan selection
5568 * should occur within a generic IEEE 802.11 user space tool. */
5569
5570 /* Set up 'new' AP to this network */
5571 ipw_copy_rates(&match->rates, &rates);
5572 match->network = network;
5573
5574 IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
5575 escape_essid(network->ssid, network->ssid_len),
5576 MAC_ARG(network->bssid));
5577
5578 return 1;
5579}
5580
Jeff Garzikbf794512005-07-31 13:07:26 -04005581static void ipw_adhoc_create(struct ipw_priv *priv,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005582 struct ieee80211_network *network)
James Ketrenos43f66a62005-03-25 12:31:53 -06005583{
Larry Finger1867b112006-02-28 09:48:28 -06005584 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005585 int i;
5586
James Ketrenos43f66a62005-03-25 12:31:53 -06005587 /*
5588 * For the purposes of scanning, we can set our wireless mode
5589 * to trigger scans across combinations of bands, but when it
5590 * comes to creating a new ad-hoc network, we have tell the FW
5591 * exactly which band to use.
5592 *
Jeff Garzikbf794512005-07-31 13:07:26 -04005593 * We also have the possibility of an invalid channel for the
James Ketrenos43f66a62005-03-25 12:31:53 -06005594 * chossen band. Attempting to create a new ad-hoc network
5595 * with an invalid channel for wireless mode will trigger a
5596 * FW fatal error.
James Ketrenosafbf30a2005-08-25 00:05:33 -05005597 *
James Ketrenos43f66a62005-03-25 12:31:53 -06005598 */
Larry Finger1867b112006-02-28 09:48:28 -06005599 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005600 case IEEE80211_52GHZ_BAND:
5601 network->mode = IEEE_A;
Larry Finger1867b112006-02-28 09:48:28 -06005602 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005603 BUG_ON(i == -1);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005604 if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5605 IPW_WARNING("Overriding invalid channel\n");
5606 priv->channel = geo->a[0].channel;
5607 }
5608 break;
5609
5610 case IEEE80211_24GHZ_BAND:
5611 if (priv->ieee->mode & IEEE_G)
5612 network->mode = IEEE_G;
5613 else
5614 network->mode = IEEE_B;
Larry Finger1867b112006-02-28 09:48:28 -06005615 i = ieee80211_channel_to_index(priv->ieee, priv->channel);
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02005616 BUG_ON(i == -1);
Liu Hong1fe0adb2005-08-19 09:33:10 -05005617 if (geo->bg[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
5618 IPW_WARNING("Overriding invalid channel\n");
5619 priv->channel = geo->bg[0].channel;
5620 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005621 break;
5622
5623 default:
James Ketrenos43f66a62005-03-25 12:31:53 -06005624 IPW_WARNING("Overriding invalid channel\n");
5625 if (priv->ieee->mode & IEEE_A) {
5626 network->mode = IEEE_A;
James Ketrenosb095c382005-08-24 22:04:42 -05005627 priv->channel = geo->a[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005628 } else if (priv->ieee->mode & IEEE_G) {
5629 network->mode = IEEE_G;
James Ketrenosb095c382005-08-24 22:04:42 -05005630 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005631 } else {
5632 network->mode = IEEE_B;
James Ketrenosb095c382005-08-24 22:04:42 -05005633 priv->channel = geo->bg[0].channel;
James Ketrenos43f66a62005-03-25 12:31:53 -06005634 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05005635 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005636 }
5637
5638 network->channel = priv->channel;
5639 priv->config |= CFG_ADHOC_PERSIST;
5640 ipw_create_bssid(priv, network->bssid);
5641 network->ssid_len = priv->essid_len;
5642 memcpy(network->ssid, priv->essid, priv->essid_len);
5643 memset(&network->stats, 0, sizeof(network->stats));
5644 network->capability = WLAN_CAPABILITY_IBSS;
James Ketrenosea2b26e2005-08-24 21:25:16 -05005645 if (!(priv->config & CFG_PREAMBLE_LONG))
5646 network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06005647 if (priv->capability & CAP_PRIVACY_ON)
5648 network->capability |= WLAN_CAPABILITY_PRIVACY;
5649 network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005650 memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06005651 network->rates_ex_len = priv->rates.num_rates - network->rates_len;
Jeff Garzikbf794512005-07-31 13:07:26 -04005652 memcpy(network->rates_ex,
James Ketrenos43f66a62005-03-25 12:31:53 -06005653 &priv->rates.supported_rates[network->rates_len],
5654 network->rates_ex_len);
5655 network->last_scanned = 0;
5656 network->flags = 0;
5657 network->last_associate = 0;
5658 network->time_stamp[0] = 0;
5659 network->time_stamp[1] = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005660 network->beacon_interval = 100; /* Default */
5661 network->listen_interval = 10; /* Default */
5662 network->atim_window = 0; /* Default */
James Ketrenos43f66a62005-03-25 12:31:53 -06005663 network->wpa_ie_len = 0;
5664 network->rsn_ie_len = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005665}
5666
James Ketrenosb095c382005-08-24 22:04:42 -05005667static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
5668{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005669 struct ipw_tgi_tx_key key;
James Ketrenosb095c382005-08-24 22:04:42 -05005670
5671 if (!(priv->ieee->sec.flags & (1 << index)))
5672 return;
5673
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005674 key.key_id = index;
5675 memcpy(key.key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
5676 key.security_type = type;
5677 key.station_index = 0; /* always 0 for BSS */
5678 key.flags = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005679 /* 0 for new key; previous value of counter (after fatal error) */
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005680 key.tx_counter[0] = 0;
5681 key.tx_counter[1] = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005682
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005683 ipw_send_cmd_pdu(priv, IPW_CMD_TGI_TX_KEY, sizeof(key), &key);
James Ketrenosb095c382005-08-24 22:04:42 -05005684}
5685
5686static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
James Ketrenos43f66a62005-03-25 12:31:53 -06005687{
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005688 struct ipw_wep_key key;
James Ketrenos43f66a62005-03-25 12:31:53 -06005689 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -06005690
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005691 key.cmd_id = DINO_CMD_WEP_KEY;
5692 key.seq_num = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06005693
James Ketrenosb095c382005-08-24 22:04:42 -05005694 /* Note: AES keys cannot be set for multiple times.
5695 * Only set it at the first time. */
Jeff Garzikbf794512005-07-31 13:07:26 -04005696 for (i = 0; i < 4; i++) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005697 key.key_index = i | type;
James Ketrenosb095c382005-08-24 22:04:42 -05005698 if (!(priv->ieee->sec.flags & (1 << i))) {
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005699 key.key_size = 0;
James Ketrenosb095c382005-08-24 22:04:42 -05005700 continue;
James Ketrenos43f66a62005-03-25 12:31:53 -06005701 }
5702
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005703 key.key_size = priv->ieee->sec.key_sizes[i];
5704 memcpy(key.key, priv->ieee->sec.keys[i], key.key_size);
James Ketrenosb095c382005-08-24 22:04:42 -05005705
Zhu Yi0a7bcf22006-01-24 16:37:28 +08005706 ipw_send_cmd_pdu(priv, IPW_CMD_WEP_KEY, sizeof(key), &key);
Jeff Garzikbf794512005-07-31 13:07:26 -04005707 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005708}
5709
Zhu Yi1fbfea52005-08-05 17:22:56 +08005710static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
5711{
5712 if (priv->ieee->host_encrypt)
5713 return;
5714
5715 switch (level) {
5716 case SEC_LEVEL_3:
5717 priv->sys_config.disable_unicast_decryption = 0;
5718 priv->ieee->host_decrypt = 0;
5719 break;
5720 case SEC_LEVEL_2:
5721 priv->sys_config.disable_unicast_decryption = 1;
5722 priv->ieee->host_decrypt = 1;
5723 break;
5724 case SEC_LEVEL_1:
5725 priv->sys_config.disable_unicast_decryption = 0;
5726 priv->ieee->host_decrypt = 0;
5727 break;
5728 case SEC_LEVEL_0:
5729 priv->sys_config.disable_unicast_decryption = 1;
5730 break;
5731 default:
5732 break;
5733 }
5734}
5735
5736static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
5737{
5738 if (priv->ieee->host_encrypt)
5739 return;
5740
5741 switch (level) {
5742 case SEC_LEVEL_3:
5743 priv->sys_config.disable_multicast_decryption = 0;
5744 break;
5745 case SEC_LEVEL_2:
5746 priv->sys_config.disable_multicast_decryption = 1;
5747 break;
5748 case SEC_LEVEL_1:
5749 priv->sys_config.disable_multicast_decryption = 0;
5750 break;
5751 case SEC_LEVEL_0:
5752 priv->sys_config.disable_multicast_decryption = 1;
5753 break;
5754 default:
5755 break;
5756 }
5757}
5758
James Ketrenosb095c382005-08-24 22:04:42 -05005759static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
5760{
5761 switch (priv->ieee->sec.level) {
5762 case SEC_LEVEL_3:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005763 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5764 ipw_send_tgi_tx_key(priv,
5765 DCT_FLAG_EXT_SECURITY_CCM,
5766 priv->ieee->sec.active_key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005767
Hong Liu567deaf2005-08-31 18:07:22 +08005768 if (!priv->ieee->host_mc_decrypt)
5769 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
James Ketrenosb095c382005-08-24 22:04:42 -05005770 break;
5771 case SEC_LEVEL_2:
Zhu Yid8bad6d2005-07-13 12:25:38 -05005772 if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
5773 ipw_send_tgi_tx_key(priv,
5774 DCT_FLAG_EXT_SECURITY_TKIP,
5775 priv->ieee->sec.active_key);
James Ketrenosb095c382005-08-24 22:04:42 -05005776 break;
5777 case SEC_LEVEL_1:
5778 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Hong Liu29cb8432005-09-12 10:43:33 -05005779 ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
5780 ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
James Ketrenosb095c382005-08-24 22:04:42 -05005781 break;
5782 case SEC_LEVEL_0:
5783 default:
5784 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06005785 }
5786}
5787
5788static void ipw_adhoc_check(void *data)
5789{
5790 struct ipw_priv *priv = data;
Jeff Garzikbf794512005-07-31 13:07:26 -04005791
James Ketrenosafbf30a2005-08-25 00:05:33 -05005792 if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
James Ketrenos43f66a62005-03-25 12:31:53 -06005793 !(priv->config & CFG_ADHOC_PERSIST)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05005794 IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
5795 IPW_DL_STATE | IPW_DL_ASSOC,
5796 "Missed beacon: %d - disassociate\n",
5797 priv->missed_adhoc_beacons);
James Ketrenos43f66a62005-03-25 12:31:53 -06005798 ipw_remove_current_network(priv);
5799 ipw_disassociate(priv);
5800 return;
5801 }
5802
Jeff Garzikbf794512005-07-31 13:07:26 -04005803 queue_delayed_work(priv->workqueue, &priv->adhoc_check,
James Ketrenos43f66a62005-03-25 12:31:53 -06005804 priv->assoc_request.beacon_interval);
5805}
5806
James Ketrenosc848d0a2005-08-24 21:56:24 -05005807static void ipw_bg_adhoc_check(void *data)
5808{
5809 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08005810 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005811 ipw_adhoc_check(data);
Zhu Yi46441512006-01-24 16:37:59 +08005812 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05005813}
5814
Brice Goglin0f52bf92005-12-01 01:41:46 -08005815#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -06005816static void ipw_debug_config(struct ipw_priv *priv)
5817{
5818 IPW_DEBUG_INFO("Scan completed, no valid APs matched "
5819 "[CFG 0x%08X]\n", priv->config);
5820 if (priv->config & CFG_STATIC_CHANNEL)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005821 IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06005822 else
5823 IPW_DEBUG_INFO("Channel unlocked.\n");
5824 if (priv->config & CFG_STATIC_ESSID)
Jeff Garzikbf794512005-07-31 13:07:26 -04005825 IPW_DEBUG_INFO("ESSID locked to '%s'\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005826 escape_essid(priv->essid, priv->essid_len));
James Ketrenos43f66a62005-03-25 12:31:53 -06005827 else
5828 IPW_DEBUG_INFO("ESSID unlocked.\n");
5829 if (priv->config & CFG_STATIC_BSSID)
James Ketrenosea2b26e2005-08-24 21:25:16 -05005830 IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
5831 MAC_ARG(priv->bssid));
James Ketrenos43f66a62005-03-25 12:31:53 -06005832 else
5833 IPW_DEBUG_INFO("BSSID unlocked.\n");
5834 if (priv->capability & CAP_PRIVACY_ON)
5835 IPW_DEBUG_INFO("PRIVACY on\n");
5836 else
5837 IPW_DEBUG_INFO("PRIVACY off\n");
5838 IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
5839}
5840#else
Jiri Benc8d45ff72005-08-25 20:09:39 -04005841#define ipw_debug_config(x) do {} while (0)
James Ketrenos43f66a62005-03-25 12:31:53 -06005842#endif
5843
Arjan van de Ven858119e2006-01-14 13:20:43 -08005844static void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
James Ketrenos43f66a62005-03-25 12:31:53 -06005845{
5846 /* TODO: Verify that this works... */
5847 struct ipw_fixed_rate fr = {
5848 .tx_rates = priv->rates_mask
5849 };
5850 u32 reg;
5851 u16 mask = 0;
5852
Jeff Garzikbf794512005-07-31 13:07:26 -04005853 /* Identify 'current FW band' and match it with the fixed
James Ketrenos43f66a62005-03-25 12:31:53 -06005854 * Tx rates */
Jeff Garzikbf794512005-07-31 13:07:26 -04005855
James Ketrenos43f66a62005-03-25 12:31:53 -06005856 switch (priv->ieee->freq_band) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005857 case IEEE80211_52GHZ_BAND: /* A only */
James Ketrenos43f66a62005-03-25 12:31:53 -06005858 /* IEEE_A */
5859 if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
5860 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005861 IPW_DEBUG_WX
5862 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005863 fr.tx_rates = 0;
5864 break;
5865 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005866
James Ketrenos43f66a62005-03-25 12:31:53 -06005867 fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
5868 break;
5869
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005870 default: /* 2.4Ghz or Mixed */
James Ketrenos43f66a62005-03-25 12:31:53 -06005871 /* IEEE_B */
James Ketrenosb095c382005-08-24 22:04:42 -05005872 if (mode == IEEE_B) {
James Ketrenos43f66a62005-03-25 12:31:53 -06005873 if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
5874 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005875 IPW_DEBUG_WX
5876 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005877 fr.tx_rates = 0;
5878 }
5879 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04005880 }
James Ketrenos43f66a62005-03-25 12:31:53 -06005881
5882 /* IEEE_G */
5883 if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
5884 IEEE80211_OFDM_RATES_MASK)) {
5885 /* Invalid fixed rate mask */
James Ketrenosea2b26e2005-08-24 21:25:16 -05005886 IPW_DEBUG_WX
5887 ("invalid fixed rate mask in ipw_set_fixed_rate\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06005888 fr.tx_rates = 0;
5889 break;
5890 }
5891
5892 if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
5893 mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
5894 fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
5895 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005896
James Ketrenos43f66a62005-03-25 12:31:53 -06005897 if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
5898 mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
5899 fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
5900 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005901
James Ketrenos43f66a62005-03-25 12:31:53 -06005902 if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
5903 mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
5904 fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
5905 }
Jeff Garzikbf794512005-07-31 13:07:26 -04005906
James Ketrenos43f66a62005-03-25 12:31:53 -06005907 fr.tx_rates |= mask;
5908 break;
5909 }
5910
5911 reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04005912 ipw_write_reg32(priv, reg, *(u32 *) & fr);
James Ketrenos43f66a62005-03-25 12:31:53 -06005913}
5914
James Ketrenosea2b26e2005-08-24 21:25:16 -05005915static void ipw_abort_scan(struct ipw_priv *priv)
5916{
5917 int err;
5918
5919 if (priv->status & STATUS_SCAN_ABORTING) {
5920 IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
5921 return;
5922 }
5923 priv->status |= STATUS_SCAN_ABORTING;
5924
5925 err = ipw_send_scan_abort(priv);
5926 if (err)
5927 IPW_DEBUG_HC("Request to abort scan failed.\n");
5928}
5929
James Ketrenosafbf30a2005-08-25 00:05:33 -05005930static void ipw_add_scan_channels(struct ipw_priv *priv,
5931 struct ipw_scan_request_ext *scan,
5932 int scan_type)
5933{
5934 int channel_index = 0;
5935 const struct ieee80211_geo *geo;
5936 int i;
5937
Larry Finger1867b112006-02-28 09:48:28 -06005938 geo = ieee80211_get_geo(priv->ieee);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005939
5940 if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
5941 int start = channel_index;
5942 for (i = 0; i < geo->a_channels; i++) {
5943 if ((priv->status & STATUS_ASSOCIATED) &&
5944 geo->a[i].channel == priv->channel)
5945 continue;
5946 channel_index++;
5947 scan->channels_list[channel_index] = geo->a[i].channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05005948 ipw_set_scan_type(scan, channel_index,
5949 geo->a[i].
5950 flags & IEEE80211_CH_PASSIVE_ONLY ?
5951 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN :
5952 scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005953 }
5954
5955 if (start != channel_index) {
5956 scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
5957 (channel_index - start);
5958 channel_index++;
5959 }
5960 }
5961
5962 if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
5963 int start = channel_index;
5964 if (priv->config & CFG_SPEED_SCAN) {
Liu Hong1fe0adb2005-08-19 09:33:10 -05005965 int index;
James Ketrenosafbf30a2005-08-25 00:05:33 -05005966 u8 channels[IEEE80211_24GHZ_CHANNELS] = {
5967 /* nop out the list */
5968 [0] = 0
5969 };
5970
5971 u8 channel;
5972 while (channel_index < IPW_SCAN_CHANNELS) {
5973 channel =
5974 priv->speed_scan[priv->speed_scan_pos];
5975 if (channel == 0) {
5976 priv->speed_scan_pos = 0;
5977 channel = priv->speed_scan[0];
5978 }
5979 if ((priv->status & STATUS_ASSOCIATED) &&
5980 channel == priv->channel) {
5981 priv->speed_scan_pos++;
5982 continue;
5983 }
5984
5985 /* If this channel has already been
5986 * added in scan, break from loop
5987 * and this will be the first channel
5988 * in the next scan.
5989 */
5990 if (channels[channel - 1] != 0)
5991 break;
5992
5993 channels[channel - 1] = 1;
5994 priv->speed_scan_pos++;
5995 channel_index++;
5996 scan->channels_list[channel_index] = channel;
Liu Hong1fe0adb2005-08-19 09:33:10 -05005997 index =
Larry Finger1867b112006-02-28 09:48:28 -06005998 ieee80211_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05005999 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006000 geo->bg[index].
6001 flags &
6002 IEEE80211_CH_PASSIVE_ONLY ?
6003 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6004 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006005 }
6006 } else {
6007 for (i = 0; i < geo->bg_channels; i++) {
6008 if ((priv->status & STATUS_ASSOCIATED) &&
6009 geo->bg[i].channel == priv->channel)
6010 continue;
6011 channel_index++;
6012 scan->channels_list[channel_index] =
6013 geo->bg[i].channel;
6014 ipw_set_scan_type(scan, channel_index,
Liu Hong1fe0adb2005-08-19 09:33:10 -05006015 geo->bg[i].
6016 flags &
6017 IEEE80211_CH_PASSIVE_ONLY ?
6018 IPW_SCAN_PASSIVE_FULL_DWELL_SCAN
6019 : scan_type);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006020 }
6021 }
6022
6023 if (start != channel_index) {
6024 scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
6025 (channel_index - start);
6026 }
6027 }
6028}
6029
James Ketrenosea2b26e2005-08-24 21:25:16 -05006030static int ipw_request_scan(struct ipw_priv *priv)
6031{
6032 struct ipw_scan_request_ext scan;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006033 int err = 0, scan_type;
6034
6035 if (!(priv->status & STATUS_INIT) ||
6036 (priv->status & STATUS_EXIT_PENDING))
6037 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006038
Zhu Yi46441512006-01-24 16:37:59 +08006039 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006040
James Ketrenosea2b26e2005-08-24 21:25:16 -05006041 if (priv->status & STATUS_SCANNING) {
James Ketrenosa613bff2005-08-24 21:43:11 -05006042 IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
James Ketrenosea2b26e2005-08-24 21:25:16 -05006043 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006044 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006045 }
6046
James Ketrenosafbf30a2005-08-25 00:05:33 -05006047 if (!(priv->status & STATUS_SCAN_FORCED) &&
6048 priv->status & STATUS_SCAN_ABORTING) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006049 IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6050 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006051 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006052 }
6053
6054 if (priv->status & STATUS_RF_KILL_MASK) {
6055 IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6056 priv->status |= STATUS_SCAN_PENDING;
James Ketrenosb095c382005-08-24 22:04:42 -05006057 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006058 }
6059
6060 memset(&scan, 0, sizeof(scan));
6061
James Ketrenosb095c382005-08-24 22:04:42 -05006062 if (priv->config & CFG_SPEED_SCAN)
6063 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6064 cpu_to_le16(30);
6065 else
6066 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
6067 cpu_to_le16(20);
6068
James Ketrenosa613bff2005-08-24 21:43:11 -05006069 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
6070 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05006071 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006072
James Ketrenosa613bff2005-08-24 21:43:11 -05006073 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
James Ketrenosea2b26e2005-08-24 21:25:16 -05006074
James Ketrenosb095c382005-08-24 22:04:42 -05006075#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006076 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006077 u8 channel;
James Ketrenosb095c382005-08-24 22:04:42 -05006078 u8 band = 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006079
Larry Finger1867b112006-02-28 09:48:28 -06006080 switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006081 case IEEE80211_52GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006082 band = (u8) (IPW_A_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006083 channel = priv->channel;
6084 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006085
James Ketrenosb095c382005-08-24 22:04:42 -05006086 case IEEE80211_24GHZ_BAND:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006087 band = (u8) (IPW_B_MODE << 6) | 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006088 channel = priv->channel;
6089 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006090
James Ketrenosb095c382005-08-24 22:04:42 -05006091 default:
James Ketrenosea2b26e2005-08-24 21:25:16 -05006092 band = (u8) (IPW_B_MODE << 6) | 1;
6093 channel = 9;
James Ketrenosb095c382005-08-24 22:04:42 -05006094 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006095 }
6096
James Ketrenosb095c382005-08-24 22:04:42 -05006097 scan.channels_list[0] = band;
6098 scan.channels_list[1] = channel;
6099 ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006100
James Ketrenosb095c382005-08-24 22:04:42 -05006101 /* NOTE: The card will sit on this channel for this time
6102 * period. Scan aborts are timing sensitive and frequently
6103 * result in firmware restarts. As such, it is best to
6104 * set a small dwell_time here and just keep re-issuing
6105 * scans. Otherwise fast channel hopping will not actually
6106 * hop channels.
6107 *
6108 * TODO: Move SPEED SCAN support to all modes and bands */
James Ketrenosa613bff2005-08-24 21:43:11 -05006109 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
6110 cpu_to_le16(2000);
James Ketrenosea2b26e2005-08-24 21:25:16 -05006111 } else {
James Ketrenosb095c382005-08-24 22:04:42 -05006112#endif /* CONFIG_IPW2200_MONITOR */
6113 /* If we are roaming, then make this a directed scan for the
6114 * current network. Otherwise, ensure that every other scan
6115 * is a fast channel hop scan */
6116 if ((priv->status & STATUS_ROAMING)
6117 || (!(priv->status & STATUS_ASSOCIATED)
6118 && (priv->config & CFG_STATIC_ESSID)
6119 && (le32_to_cpu(scan.full_scan_index) % 2))) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006120 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
6121 if (err) {
James Ketrenosb095c382005-08-24 22:04:42 -05006122 IPW_DEBUG_HC("Attempt to send SSID command "
6123 "failed.\n");
6124 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006125 }
6126
6127 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006128 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05006129 scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006130
James Ketrenosafbf30a2005-08-25 00:05:33 -05006131 ipw_add_scan_channels(priv, &scan, scan_type);
James Ketrenosb095c382005-08-24 22:04:42 -05006132#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05006133 }
6134#endif
6135
6136 err = ipw_send_scan_request_ext(priv, &scan);
6137 if (err) {
6138 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
James Ketrenosb095c382005-08-24 22:04:42 -05006139 goto done;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006140 }
6141
6142 priv->status |= STATUS_SCANNING;
6143 priv->status &= ~STATUS_SCAN_PENDING;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006144 queue_delayed_work(priv->workqueue, &priv->scan_check,
6145 IPW_SCAN_CHECK_WATCHDOG);
James Ketrenosb095c382005-08-24 22:04:42 -05006146 done:
Zhu Yi46441512006-01-24 16:37:59 +08006147 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006148 return err;
James Ketrenosc848d0a2005-08-24 21:56:24 -05006149}
6150
6151static void ipw_bg_abort_scan(void *data)
6152{
6153 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08006154 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006155 ipw_abort_scan(data);
Zhu Yi46441512006-01-24 16:37:59 +08006156 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05006157}
6158
James Ketrenosea2b26e2005-08-24 21:25:16 -05006159static int ipw_wpa_enable(struct ipw_priv *priv, int value)
6160{
James Ketrenosb095c382005-08-24 22:04:42 -05006161 /* This is called when wpa_supplicant loads and closes the driver
6162 * interface. */
Hong Liucdd1fa12005-08-31 18:14:27 +08006163 priv->ieee->wpa_enabled = value;
James Ketrenosb095c382005-08-24 22:04:42 -05006164 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006165}
6166
James Ketrenosea2b26e2005-08-24 21:25:16 -05006167static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
6168{
6169 struct ieee80211_device *ieee = priv->ieee;
6170 struct ieee80211_security sec = {
6171 .flags = SEC_AUTH_MODE,
6172 };
6173 int ret = 0;
6174
James Ketrenosafbf30a2005-08-25 00:05:33 -05006175 if (value & IW_AUTH_ALG_SHARED_KEY) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006176 sec.auth_mode = WLAN_AUTH_SHARED_KEY;
6177 ieee->open_wep = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006178 } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05006179 sec.auth_mode = WLAN_AUTH_OPEN;
6180 ieee->open_wep = 1;
Zhu Yi3e234b42006-01-24 16:36:52 +08006181 } else if (value & IW_AUTH_ALG_LEAP) {
6182 sec.auth_mode = WLAN_AUTH_LEAP;
6183 ieee->open_wep = 1;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006184 } else
6185 return -EINVAL;
James Ketrenosea2b26e2005-08-24 21:25:16 -05006186
6187 if (ieee->set_security)
6188 ieee->set_security(ieee->dev, &sec);
6189 else
6190 ret = -EOPNOTSUPP;
6191
6192 return ret;
6193}
6194
Adrian Bunka73e22b2006-01-21 01:39:42 +01006195static void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie,
6196 int wpa_ie_len)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006197{
6198 /* make sure WPA is enabled */
6199 ipw_wpa_enable(priv, 1);
6200
6201 ipw_disassociate(priv);
6202}
6203
6204static int ipw_set_rsn_capa(struct ipw_priv *priv,
6205 char *capabilities, int length)
6206{
James Ketrenosafbf30a2005-08-25 00:05:33 -05006207 IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
6208
Zhu Yi0a7bcf22006-01-24 16:37:28 +08006209 return ipw_send_cmd_pdu(priv, IPW_CMD_RSN_CAPABILITIES, length,
Zhu Yi2638bc32006-01-24 16:37:52 +08006210 capabilities);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006211}
6212
James Ketrenosafbf30a2005-08-25 00:05:33 -05006213/*
6214 * WE-18 support
6215 */
6216
6217/* SIOCSIWGENIE */
6218static int ipw_wx_set_genie(struct net_device *dev,
6219 struct iw_request_info *info,
6220 union iwreq_data *wrqu, char *extra)
6221{
6222 struct ipw_priv *priv = ieee80211_priv(dev);
6223 struct ieee80211_device *ieee = priv->ieee;
6224 u8 *buf;
6225 int err = 0;
6226
6227 if (wrqu->data.length > MAX_WPA_IE_LEN ||
6228 (wrqu->data.length && extra == NULL))
6229 return -EINVAL;
6230
Zhu Yi46441512006-01-24 16:37:59 +08006231 //mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006232
6233 //if (!ieee->wpa_enabled) {
6234 // err = -EOPNOTSUPP;
6235 // goto out;
6236 //}
6237
6238 if (wrqu->data.length) {
6239 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
6240 if (buf == NULL) {
6241 err = -ENOMEM;
6242 goto out;
6243 }
6244
6245 memcpy(buf, extra, wrqu->data.length);
6246 kfree(ieee->wpa_ie);
6247 ieee->wpa_ie = buf;
6248 ieee->wpa_ie_len = wrqu->data.length;
6249 } else {
6250 kfree(ieee->wpa_ie);
6251 ieee->wpa_ie = NULL;
6252 ieee->wpa_ie_len = 0;
6253 }
6254
6255 ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
6256 out:
Zhu Yi46441512006-01-24 16:37:59 +08006257 //mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006258 return err;
6259}
6260
6261/* SIOCGIWGENIE */
6262static int ipw_wx_get_genie(struct net_device *dev,
6263 struct iw_request_info *info,
6264 union iwreq_data *wrqu, char *extra)
6265{
6266 struct ipw_priv *priv = ieee80211_priv(dev);
6267 struct ieee80211_device *ieee = priv->ieee;
6268 int err = 0;
6269
Zhu Yi46441512006-01-24 16:37:59 +08006270 //mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006271
6272 //if (!ieee->wpa_enabled) {
6273 // err = -EOPNOTSUPP;
6274 // goto out;
6275 //}
6276
6277 if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
6278 wrqu->data.length = 0;
6279 goto out;
6280 }
6281
6282 if (wrqu->data.length < ieee->wpa_ie_len) {
6283 err = -E2BIG;
6284 goto out;
6285 }
6286
6287 wrqu->data.length = ieee->wpa_ie_len;
6288 memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
6289
6290 out:
Zhu Yi46441512006-01-24 16:37:59 +08006291 //mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006292 return err;
6293}
6294
Zhu Yi1fbfea52005-08-05 17:22:56 +08006295static int wext_cipher2level(int cipher)
6296{
6297 switch (cipher) {
6298 case IW_AUTH_CIPHER_NONE:
6299 return SEC_LEVEL_0;
6300 case IW_AUTH_CIPHER_WEP40:
6301 case IW_AUTH_CIPHER_WEP104:
6302 return SEC_LEVEL_1;
6303 case IW_AUTH_CIPHER_TKIP:
6304 return SEC_LEVEL_2;
6305 case IW_AUTH_CIPHER_CCMP:
6306 return SEC_LEVEL_3;
6307 default:
6308 return -1;
6309 }
6310}
6311
James Ketrenosafbf30a2005-08-25 00:05:33 -05006312/* SIOCSIWAUTH */
6313static int ipw_wx_set_auth(struct net_device *dev,
6314 struct iw_request_info *info,
6315 union iwreq_data *wrqu, char *extra)
6316{
6317 struct ipw_priv *priv = ieee80211_priv(dev);
6318 struct ieee80211_device *ieee = priv->ieee;
6319 struct iw_param *param = &wrqu->param;
6320 struct ieee80211_crypt_data *crypt;
6321 unsigned long flags;
6322 int ret = 0;
6323
6324 switch (param->flags & IW_AUTH_INDEX) {
6325 case IW_AUTH_WPA_VERSION:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006326 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006327 case IW_AUTH_CIPHER_PAIRWISE:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006328 ipw_set_hw_decrypt_unicast(priv,
6329 wext_cipher2level(param->value));
6330 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006331 case IW_AUTH_CIPHER_GROUP:
Zhu Yi1fbfea52005-08-05 17:22:56 +08006332 ipw_set_hw_decrypt_multicast(priv,
6333 wext_cipher2level(param->value));
6334 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006335 case IW_AUTH_KEY_MGMT:
6336 /*
6337 * ipw2200 does not use these parameters
6338 */
6339 break;
6340
6341 case IW_AUTH_TKIP_COUNTERMEASURES:
6342 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006343 if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006344 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006345
6346 flags = crypt->ops->get_flags(crypt->priv);
6347
6348 if (param->value)
6349 flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6350 else
6351 flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
6352
6353 crypt->ops->set_flags(flags, crypt->priv);
6354
6355 break;
6356
6357 case IW_AUTH_DROP_UNENCRYPTED:{
6358 /* HACK:
6359 *
6360 * wpa_supplicant calls set_wpa_enabled when the driver
6361 * is loaded and unloaded, regardless of if WPA is being
6362 * used. No other calls are made which can be used to
6363 * determine if encryption will be used or not prior to
6364 * association being expected. If encryption is not being
6365 * used, drop_unencrypted is set to false, else true -- we
6366 * can use this to determine if the CAP_PRIVACY_ON bit should
6367 * be set.
6368 */
6369 struct ieee80211_security sec = {
6370 .flags = SEC_ENABLED,
6371 .enabled = param->value,
6372 };
6373 priv->ieee->drop_unencrypted = param->value;
6374 /* We only change SEC_LEVEL for open mode. Others
6375 * are set by ipw_wpa_set_encryption.
6376 */
6377 if (!param->value) {
6378 sec.flags |= SEC_LEVEL;
6379 sec.level = SEC_LEVEL_0;
6380 } else {
6381 sec.flags |= SEC_LEVEL;
6382 sec.level = SEC_LEVEL_1;
6383 }
6384 if (priv->ieee->set_security)
6385 priv->ieee->set_security(priv->ieee->dev, &sec);
6386 break;
6387 }
6388
6389 case IW_AUTH_80211_AUTH_ALG:
6390 ret = ipw_wpa_set_auth_algs(priv, param->value);
6391 break;
6392
6393 case IW_AUTH_WPA_ENABLED:
6394 ret = ipw_wpa_enable(priv, param->value);
6395 break;
6396
6397 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6398 ieee->ieee802_1x = param->value;
6399 break;
6400
6401 //case IW_AUTH_ROAMING_CONTROL:
6402 case IW_AUTH_PRIVACY_INVOKED:
6403 ieee->privacy_invoked = param->value;
6404 break;
6405
6406 default:
6407 return -EOPNOTSUPP;
6408 }
6409 return ret;
6410}
6411
6412/* SIOCGIWAUTH */
6413static int ipw_wx_get_auth(struct net_device *dev,
6414 struct iw_request_info *info,
6415 union iwreq_data *wrqu, char *extra)
6416{
6417 struct ipw_priv *priv = ieee80211_priv(dev);
6418 struct ieee80211_device *ieee = priv->ieee;
6419 struct ieee80211_crypt_data *crypt;
6420 struct iw_param *param = &wrqu->param;
6421 int ret = 0;
6422
6423 switch (param->flags & IW_AUTH_INDEX) {
6424 case IW_AUTH_WPA_VERSION:
6425 case IW_AUTH_CIPHER_PAIRWISE:
6426 case IW_AUTH_CIPHER_GROUP:
6427 case IW_AUTH_KEY_MGMT:
6428 /*
6429 * wpa_supplicant will control these internally
6430 */
6431 ret = -EOPNOTSUPP;
6432 break;
6433
6434 case IW_AUTH_TKIP_COUNTERMEASURES:
6435 crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
James Ketrenos991d1cc2005-10-13 09:26:48 +00006436 if (!crypt || !crypt->ops->get_flags)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006437 break;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006438
6439 param->value = (crypt->ops->get_flags(crypt->priv) &
6440 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
6441
6442 break;
6443
6444 case IW_AUTH_DROP_UNENCRYPTED:
6445 param->value = ieee->drop_unencrypted;
6446 break;
6447
6448 case IW_AUTH_80211_AUTH_ALG:
6449 param->value = ieee->sec.auth_mode;
6450 break;
6451
6452 case IW_AUTH_WPA_ENABLED:
6453 param->value = ieee->wpa_enabled;
6454 break;
6455
6456 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6457 param->value = ieee->ieee802_1x;
6458 break;
6459
6460 case IW_AUTH_ROAMING_CONTROL:
6461 case IW_AUTH_PRIVACY_INVOKED:
6462 param->value = ieee->privacy_invoked;
6463 break;
6464
6465 default:
6466 return -EOPNOTSUPP;
6467 }
6468 return 0;
6469}
6470
6471/* SIOCSIWENCODEEXT */
6472static int ipw_wx_set_encodeext(struct net_device *dev,
6473 struct iw_request_info *info,
6474 union iwreq_data *wrqu, char *extra)
6475{
6476 struct ipw_priv *priv = ieee80211_priv(dev);
6477 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6478
6479 if (hwcrypto) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006480 if (ext->alg == IW_ENCODE_ALG_TKIP) {
Hong Liu567deaf2005-08-31 18:07:22 +08006481 /* IPW HW can't build TKIP MIC,
6482 host decryption still needed */
6483 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
6484 priv->ieee->host_mc_decrypt = 1;
6485 else {
6486 priv->ieee->host_encrypt = 0;
6487 priv->ieee->host_encrypt_msdu = 1;
6488 priv->ieee->host_decrypt = 1;
6489 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006490 } else {
6491 priv->ieee->host_encrypt = 0;
6492 priv->ieee->host_encrypt_msdu = 0;
6493 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08006494 priv->ieee->host_mc_decrypt = 0;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006495 }
6496 }
6497
6498 return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
6499}
6500
6501/* SIOCGIWENCODEEXT */
6502static int ipw_wx_get_encodeext(struct net_device *dev,
6503 struct iw_request_info *info,
6504 union iwreq_data *wrqu, char *extra)
6505{
6506 struct ipw_priv *priv = ieee80211_priv(dev);
6507 return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
6508}
6509
6510/* SIOCSIWMLME */
6511static int ipw_wx_set_mlme(struct net_device *dev,
6512 struct iw_request_info *info,
6513 union iwreq_data *wrqu, char *extra)
6514{
6515 struct ipw_priv *priv = ieee80211_priv(dev);
6516 struct iw_mlme *mlme = (struct iw_mlme *)extra;
6517 u16 reason;
6518
6519 reason = cpu_to_le16(mlme->reason_code);
6520
6521 switch (mlme->cmd) {
6522 case IW_MLME_DEAUTH:
6523 // silently ignore
6524 break;
6525
6526 case IW_MLME_DISASSOC:
6527 ipw_disassociate(priv);
6528 break;
6529
6530 default:
6531 return -EOPNOTSUPP;
6532 }
6533 return 0;
6534}
James Ketrenosea2b26e2005-08-24 21:25:16 -05006535
James Ketrenosb095c382005-08-24 22:04:42 -05006536#ifdef CONFIG_IPW_QOS
6537
6538/* QoS */
6539/*
6540* get the modulation type of the current network or
6541* the card current mode
6542*/
Adrian Bunk53d0bcf2006-03-04 13:14:31 +01006543static u8 ipw_qos_current_mode(struct ipw_priv * priv)
James Ketrenosb095c382005-08-24 22:04:42 -05006544{
6545 u8 mode = 0;
6546
6547 if (priv->status & STATUS_ASSOCIATED) {
6548 unsigned long flags;
6549
6550 spin_lock_irqsave(&priv->ieee->lock, flags);
6551 mode = priv->assoc_network->mode;
6552 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6553 } else {
6554 mode = priv->ieee->mode;
6555 }
6556 IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
6557 return mode;
6558}
6559
6560/*
6561* Handle management frame beacon and probe response
6562*/
James Ketrenos3b9990c2005-08-19 13:18:55 -05006563static int ipw_qos_handle_probe_response(struct ipw_priv *priv,
6564 int active_network,
6565 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006566{
6567 u32 size = sizeof(struct ieee80211_qos_parameters);
6568
James Ketrenosafbf30a2005-08-25 00:05:33 -05006569 if (network->capability & WLAN_CAPABILITY_IBSS)
James Ketrenosb095c382005-08-24 22:04:42 -05006570 network->qos_data.active = network->qos_data.supported;
6571
6572 if (network->flags & NETWORK_HAS_QOS_MASK) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006573 if (active_network &&
6574 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
James Ketrenosb095c382005-08-24 22:04:42 -05006575 network->qos_data.active = network->qos_data.supported;
6576
6577 if ((network->qos_data.active == 1) && (active_network == 1) &&
6578 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
6579 (network->qos_data.old_param_count !=
6580 network->qos_data.param_count)) {
6581 network->qos_data.old_param_count =
6582 network->qos_data.param_count;
6583 schedule_work(&priv->qos_activate);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006584 IPW_DEBUG_QOS("QoS parameters change call "
6585 "qos_activate\n");
James Ketrenosb095c382005-08-24 22:04:42 -05006586 }
6587 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006588 if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
6589 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006590 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006591 else
6592 memcpy(&network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006593 &def_parameters_OFDM, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006594
James Ketrenosb095c382005-08-24 22:04:42 -05006595 if ((network->qos_data.active == 1) && (active_network == 1)) {
6596 IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
6597 schedule_work(&priv->qos_activate);
6598 }
6599
6600 network->qos_data.active = 0;
6601 network->qos_data.supported = 0;
6602 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006603 if ((priv->status & STATUS_ASSOCIATED) &&
6604 (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
6605 if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
6606 if ((network->capability & WLAN_CAPABILITY_IBSS) &&
6607 !(network->flags & NETWORK_EMPTY_ESSID))
James Ketrenosb095c382005-08-24 22:04:42 -05006608 if ((network->ssid_len ==
James Ketrenosafbf30a2005-08-25 00:05:33 -05006609 priv->assoc_network->ssid_len) &&
6610 !memcmp(network->ssid,
6611 priv->assoc_network->ssid,
6612 network->ssid_len)) {
James Ketrenosb095c382005-08-24 22:04:42 -05006613 queue_work(priv->workqueue,
6614 &priv->merge_networks);
6615 }
James Ketrenosb095c382005-08-24 22:04:42 -05006616 }
6617
6618 return 0;
6619}
6620
6621/*
6622* This function set up the firmware to support QoS. It sends
6623* IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
6624*/
6625static int ipw_qos_activate(struct ipw_priv *priv,
6626 struct ieee80211_qos_data *qos_network_data)
6627{
6628 int err;
6629 struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
6630 struct ieee80211_qos_parameters *active_one = NULL;
6631 u32 size = sizeof(struct ieee80211_qos_parameters);
6632 u32 burst_duration;
6633 int i;
6634 u8 type;
6635
6636 type = ipw_qos_current_mode(priv);
6637
6638 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
6639 memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
6640 active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
6641 memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
6642
6643 if (qos_network_data == NULL) {
6644 if (type == IEEE_B) {
6645 IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
6646 active_one = &def_parameters_CCK;
6647 } else
6648 active_one = &def_parameters_OFDM;
6649
James Ketrenosafbf30a2005-08-25 00:05:33 -05006650 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006651 burst_duration = ipw_qos_get_burst_duration(priv);
6652 for (i = 0; i < QOS_QUEUE_NUM; i++)
James Ketrenosafbf30a2005-08-25 00:05:33 -05006653 qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
6654 (u16) burst_duration;
6655 } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
James Ketrenosb095c382005-08-24 22:04:42 -05006656 if (type == IEEE_B) {
6657 IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
6658 type);
6659 if (priv->qos_data.qos_enable == 0)
6660 active_one = &def_parameters_CCK;
6661 else
6662 active_one = priv->qos_data.def_qos_parm_CCK;
6663 } else {
6664 if (priv->qos_data.qos_enable == 0)
6665 active_one = &def_parameters_OFDM;
6666 else
6667 active_one = priv->qos_data.def_qos_parm_OFDM;
6668 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05006669 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006670 } else {
6671 unsigned long flags;
6672 int active;
6673
6674 spin_lock_irqsave(&priv->ieee->lock, flags);
6675 active_one = &(qos_network_data->parameters);
6676 qos_network_data->old_param_count =
6677 qos_network_data->param_count;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006678 memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006679 active = qos_network_data->supported;
6680 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6681
6682 if (active == 0) {
6683 burst_duration = ipw_qos_get_burst_duration(priv);
6684 for (i = 0; i < QOS_QUEUE_NUM; i++)
6685 qos_parameters[QOS_PARAM_SET_ACTIVE].
6686 tx_op_limit[i] = (u16) burst_duration;
6687 }
6688 }
6689
6690 IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05006691 err = ipw_send_qos_params_command(priv,
6692 (struct ieee80211_qos_parameters *)
6693 &(qos_parameters[0]));
James Ketrenosb095c382005-08-24 22:04:42 -05006694 if (err)
6695 IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
6696
6697 return err;
6698}
6699
6700/*
6701* send IPW_CMD_WME_INFO to the firmware
6702*/
6703static int ipw_qos_set_info_element(struct ipw_priv *priv)
6704{
6705 int ret = 0;
6706 struct ieee80211_qos_information_element qos_info;
6707
6708 if (priv == NULL)
6709 return -1;
6710
6711 qos_info.elementID = QOS_ELEMENT_ID;
6712 qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
6713
6714 qos_info.version = QOS_VERSION_1;
6715 qos_info.ac_info = 0;
6716
6717 memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
6718 qos_info.qui_type = QOS_OUI_TYPE;
6719 qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
6720
6721 ret = ipw_send_qos_info_command(priv, &qos_info);
6722 if (ret != 0) {
6723 IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
6724 }
6725 return ret;
6726}
6727
6728/*
6729* Set the QoS parameter with the association request structure
6730*/
6731static int ipw_qos_association(struct ipw_priv *priv,
6732 struct ieee80211_network *network)
6733{
6734 int err = 0;
6735 struct ieee80211_qos_data *qos_data = NULL;
6736 struct ieee80211_qos_data ibss_data = {
6737 .supported = 1,
6738 .active = 1,
6739 };
6740
6741 switch (priv->ieee->iw_mode) {
6742 case IW_MODE_ADHOC:
Eric Sesterhenn5d9428d2006-04-02 13:52:48 +02006743 BUG_ON(!(network->capability & WLAN_CAPABILITY_IBSS));
James Ketrenosb095c382005-08-24 22:04:42 -05006744
6745 qos_data = &ibss_data;
6746 break;
6747
6748 case IW_MODE_INFRA:
6749 qos_data = &network->qos_data;
6750 break;
6751
6752 default:
6753 BUG();
6754 break;
6755 }
6756
6757 err = ipw_qos_activate(priv, qos_data);
6758 if (err) {
6759 priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
6760 return err;
6761 }
6762
6763 if (priv->qos_data.qos_enable && qos_data->supported) {
6764 IPW_DEBUG_QOS("QoS will be enabled for this association\n");
6765 priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
6766 return ipw_qos_set_info_element(priv);
6767 }
6768
6769 return 0;
6770}
6771
6772/*
6773* handling the beaconing responces. if we get different QoS setting
6774* of the network from the the associated setting adjust the QoS
6775* setting
6776*/
6777static int ipw_qos_association_resp(struct ipw_priv *priv,
6778 struct ieee80211_network *network)
6779{
6780 int ret = 0;
6781 unsigned long flags;
6782 u32 size = sizeof(struct ieee80211_qos_parameters);
6783 int set_qos_param = 0;
6784
James Ketrenosafbf30a2005-08-25 00:05:33 -05006785 if ((priv == NULL) || (network == NULL) ||
6786 (priv->assoc_network == NULL))
James Ketrenosb095c382005-08-24 22:04:42 -05006787 return ret;
6788
6789 if (!(priv->status & STATUS_ASSOCIATED))
6790 return ret;
6791
James Ketrenosafbf30a2005-08-25 00:05:33 -05006792 if ((priv->ieee->iw_mode != IW_MODE_INFRA))
James Ketrenosb095c382005-08-24 22:04:42 -05006793 return ret;
James Ketrenosb095c382005-08-24 22:04:42 -05006794
6795 spin_lock_irqsave(&priv->ieee->lock, flags);
6796 if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006797 memcpy(&priv->assoc_network->qos_data, &network->qos_data,
James Ketrenosb095c382005-08-24 22:04:42 -05006798 sizeof(struct ieee80211_qos_data));
6799 priv->assoc_network->qos_data.active = 1;
6800 if ((network->qos_data.old_param_count !=
6801 network->qos_data.param_count)) {
6802 set_qos_param = 1;
6803 network->qos_data.old_param_count =
6804 network->qos_data.param_count;
6805 }
6806
6807 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05006808 if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
6809 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006810 &def_parameters_CCK, size);
James Ketrenosafbf30a2005-08-25 00:05:33 -05006811 else
6812 memcpy(&priv->assoc_network->qos_data.parameters,
James Ketrenosb095c382005-08-24 22:04:42 -05006813 &def_parameters_OFDM, size);
James Ketrenosb095c382005-08-24 22:04:42 -05006814 priv->assoc_network->qos_data.active = 0;
6815 priv->assoc_network->qos_data.supported = 0;
6816 set_qos_param = 1;
6817 }
6818
6819 spin_unlock_irqrestore(&priv->ieee->lock, flags);
6820
6821 if (set_qos_param == 1)
6822 schedule_work(&priv->qos_activate);
6823
6824 return ret;
6825}
6826
6827static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
6828{
6829 u32 ret = 0;
6830
6831 if ((priv == NULL))
6832 return 0;
6833
James Ketrenosafbf30a2005-08-25 00:05:33 -05006834 if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
James Ketrenosb095c382005-08-24 22:04:42 -05006835 ret = priv->qos_data.burst_duration_CCK;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006836 else
James Ketrenosb095c382005-08-24 22:04:42 -05006837 ret = priv->qos_data.burst_duration_OFDM;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006838
James Ketrenosb095c382005-08-24 22:04:42 -05006839 return ret;
6840}
6841
6842/*
6843* Initialize the setting of QoS global
6844*/
6845static void ipw_qos_init(struct ipw_priv *priv, int enable,
6846 int burst_enable, u32 burst_duration_CCK,
6847 u32 burst_duration_OFDM)
6848{
6849 priv->qos_data.qos_enable = enable;
6850
6851 if (priv->qos_data.qos_enable) {
6852 priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
6853 priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
6854 IPW_DEBUG_QOS("QoS is enabled\n");
6855 } else {
6856 priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
6857 priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
6858 IPW_DEBUG_QOS("QoS is not enabled\n");
6859 }
6860
6861 priv->qos_data.burst_enable = burst_enable;
6862
6863 if (burst_enable) {
6864 priv->qos_data.burst_duration_CCK = burst_duration_CCK;
6865 priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
6866 } else {
6867 priv->qos_data.burst_duration_CCK = 0;
6868 priv->qos_data.burst_duration_OFDM = 0;
6869 }
6870}
6871
6872/*
6873* map the packet priority to the right TX Queue
6874*/
6875static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
6876{
6877 if (priority > 7 || !priv->qos_data.qos_enable)
6878 priority = 0;
6879
6880 return from_priority_to_tx_queue[priority] - 1;
6881}
6882
Zhu Yia5cf4fe2006-04-13 17:19:11 +08006883static int ipw_is_qos_active(struct net_device *dev,
6884 struct sk_buff *skb)
James Ketrenosb095c382005-08-24 22:04:42 -05006885{
Zhu Yia5cf4fe2006-04-13 17:19:11 +08006886 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosb095c382005-08-24 22:04:42 -05006887 struct ieee80211_qos_data *qos_data = NULL;
6888 int active, supported;
Zhu Yia5cf4fe2006-04-13 17:19:11 +08006889 u8 *daddr = skb->data + ETH_ALEN;
6890 int unicast = !is_multicast_ether_addr(daddr);
James Ketrenosb095c382005-08-24 22:04:42 -05006891
6892 if (!(priv->status & STATUS_ASSOCIATED))
6893 return 0;
6894
6895 qos_data = &priv->assoc_network->qos_data;
6896
James Ketrenosb095c382005-08-24 22:04:42 -05006897 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
6898 if (unicast == 0)
6899 qos_data->active = 0;
6900 else
6901 qos_data->active = qos_data->supported;
6902 }
James Ketrenosb095c382005-08-24 22:04:42 -05006903 active = qos_data->active;
6904 supported = qos_data->supported;
James Ketrenosafbf30a2005-08-25 00:05:33 -05006905 IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
6906 "unicast %d\n",
6907 priv->qos_data.qos_enable, active, supported, unicast);
Zhu Yia5cf4fe2006-04-13 17:19:11 +08006908 if (active && priv->qos_data.qos_enable)
6909 return 1;
James Ketrenosb095c382005-08-24 22:04:42 -05006910
Zhu Yia5cf4fe2006-04-13 17:19:11 +08006911 return 0;
6912
6913}
6914/*
6915* add QoS parameter to the TX command
6916*/
6917static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
6918 u16 priority,
6919 struct tfd_data *tfd)
6920{
6921 int tx_queue_id = 0;
6922
6923
6924 tx_queue_id = from_priority_to_tx_queue[priority] - 1;
6925 tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
6926
6927 if (priv->qos_data.qos_no_ack_mask & (1UL << tx_queue_id)) {
6928 tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
6929 tfd->tfd.tfd_26.mchdr.qos_ctrl |= CTRL_QOS_NO_ACK;
James Ketrenosb095c382005-08-24 22:04:42 -05006930 }
Zhu Yia5cf4fe2006-04-13 17:19:11 +08006931 return 0;
James Ketrenosb095c382005-08-24 22:04:42 -05006932}
6933
6934/*
6935* background support to run QoS activate functionality
6936*/
6937static void ipw_bg_qos_activate(void *data)
6938{
6939 struct ipw_priv *priv = data;
6940
6941 if (priv == NULL)
6942 return;
6943
Zhu Yi46441512006-01-24 16:37:59 +08006944 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006945
6946 if (priv->status & STATUS_ASSOCIATED)
6947 ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
6948
Zhu Yi46441512006-01-24 16:37:59 +08006949 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05006950}
6951
James Ketrenos3b9990c2005-08-19 13:18:55 -05006952static int ipw_handle_probe_response(struct net_device *dev,
6953 struct ieee80211_probe_response *resp,
6954 struct ieee80211_network *network)
James Ketrenosb095c382005-08-24 22:04:42 -05006955{
6956 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos3b9990c2005-08-19 13:18:55 -05006957 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
6958 (network == priv->assoc_network));
James Ketrenosb095c382005-08-24 22:04:42 -05006959
James Ketrenos3b9990c2005-08-19 13:18:55 -05006960 ipw_qos_handle_probe_response(priv, active_network, network);
James Ketrenosb095c382005-08-24 22:04:42 -05006961
James Ketrenos3b9990c2005-08-19 13:18:55 -05006962 return 0;
6963}
James Ketrenosb095c382005-08-24 22:04:42 -05006964
James Ketrenos3b9990c2005-08-19 13:18:55 -05006965static int ipw_handle_beacon(struct net_device *dev,
6966 struct ieee80211_beacon *resp,
6967 struct ieee80211_network *network)
6968{
6969 struct ipw_priv *priv = ieee80211_priv(dev);
6970 int active_network = ((priv->status & STATUS_ASSOCIATED) &&
6971 (network == priv->assoc_network));
6972
6973 ipw_qos_handle_probe_response(priv, active_network, network);
6974
6975 return 0;
6976}
6977
6978static int ipw_handle_assoc_response(struct net_device *dev,
6979 struct ieee80211_assoc_response *resp,
6980 struct ieee80211_network *network)
6981{
6982 struct ipw_priv *priv = ieee80211_priv(dev);
6983 ipw_qos_association_resp(priv, network);
James Ketrenosb095c382005-08-24 22:04:42 -05006984 return 0;
6985}
6986
6987static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
6988 *qos_param)
6989{
Zhu Yi4e226992006-01-24 16:37:36 +08006990 return ipw_send_cmd_pdu(priv, IPW_CMD_QOS_PARAMETERS,
6991 sizeof(*qos_param) * 3, qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05006992}
6993
6994static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
6995 *qos_param)
6996{
Zhu Yi4e226992006-01-24 16:37:36 +08006997 return ipw_send_cmd_pdu(priv, IPW_CMD_WME_INFO, sizeof(*qos_param),
6998 qos_param);
James Ketrenosb095c382005-08-24 22:04:42 -05006999}
7000
7001#endif /* CONFIG_IPW_QOS */
7002
James Ketrenos43f66a62005-03-25 12:31:53 -06007003static int ipw_associate_network(struct ipw_priv *priv,
7004 struct ieee80211_network *network,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007005 struct ipw_supported_rates *rates, int roaming)
James Ketrenos43f66a62005-03-25 12:31:53 -06007006{
7007 int err;
7008
7009 if (priv->config & CFG_FIXED_RATE)
James Ketrenosb095c382005-08-24 22:04:42 -05007010 ipw_set_fixed_rate(priv, network->mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06007011
7012 if (!(priv->config & CFG_STATIC_ESSID)) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007013 priv->essid_len = min(network->ssid_len,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007014 (u8) IW_ESSID_MAX_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007015 memcpy(priv->essid, network->ssid, priv->essid_len);
7016 }
7017
7018 network->last_associate = jiffies;
7019
7020 memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
7021 priv->assoc_request.channel = network->channel;
Zhu Yi3e234b42006-01-24 16:36:52 +08007022 priv->assoc_request.auth_key = 0;
7023
James Ketrenos43f66a62005-03-25 12:31:53 -06007024 if ((priv->capability & CAP_PRIVACY_ON) &&
Zhu Yi3e234b42006-01-24 16:36:52 +08007025 (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007026 priv->assoc_request.auth_type = AUTH_SHARED_KEY;
James Ketrenosb095c382005-08-24 22:04:42 -05007027 priv->assoc_request.auth_key = priv->ieee->sec.active_key;
7028
Zhu Yi1ba61e02006-02-15 13:00:55 +08007029 if (priv->ieee->sec.level == SEC_LEVEL_1)
James Ketrenosb095c382005-08-24 22:04:42 -05007030 ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
Zhu Yi3e234b42006-01-24 16:36:52 +08007031
7032 } else if ((priv->capability & CAP_PRIVACY_ON) &&
7033 (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP))
7034 priv->assoc_request.auth_type = AUTH_LEAP;
7035 else
James Ketrenos43f66a62005-03-25 12:31:53 -06007036 priv->assoc_request.auth_type = AUTH_OPEN;
James Ketrenos43f66a62005-03-25 12:31:53 -06007037
James Ketrenosa613bff2005-08-24 21:43:11 -05007038 if (priv->ieee->wpa_ie_len) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05007039 priv->assoc_request.policy_support = 0x02; /* RSN active */
7040 ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
7041 priv->ieee->wpa_ie_len);
7042 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007043
Jeff Garzikbf794512005-07-31 13:07:26 -04007044 /*
7045 * It is valid for our ieee device to support multiple modes, but
7046 * when it comes to associating to a given network we have to choose
James Ketrenos43f66a62005-03-25 12:31:53 -06007047 * just one mode.
7048 */
7049 if (network->mode & priv->ieee->mode & IEEE_A)
7050 priv->assoc_request.ieee_mode = IPW_A_MODE;
7051 else if (network->mode & priv->ieee->mode & IEEE_G)
7052 priv->assoc_request.ieee_mode = IPW_G_MODE;
7053 else if (network->mode & priv->ieee->mode & IEEE_B)
7054 priv->assoc_request.ieee_mode = IPW_B_MODE;
7055
James Ketrenosea2b26e2005-08-24 21:25:16 -05007056 priv->assoc_request.capability = network->capability;
7057 if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
7058 && !(priv->config & CFG_PREAMBLE_LONG)) {
7059 priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
7060 } else {
7061 priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
7062
7063 /* Clear the short preamble if we won't be supporting it */
7064 priv->assoc_request.capability &=
7065 ~WLAN_CAPABILITY_SHORT_PREAMBLE;
7066 }
7067
James Ketrenosafbf30a2005-08-25 00:05:33 -05007068 /* Clear capability bits that aren't used in Ad Hoc */
7069 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7070 priv->assoc_request.capability &=
7071 ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
7072
James Ketrenos43f66a62005-03-25 12:31:53 -06007073 IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
James Ketrenosea2b26e2005-08-24 21:25:16 -05007074 "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007075 roaming ? "Rea" : "A",
Jeff Garzikbf794512005-07-31 13:07:26 -04007076 escape_essid(priv->essid, priv->essid_len),
7077 network->channel,
7078 ipw_modes[priv->assoc_request.ieee_mode],
7079 rates->num_rates,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007080 (priv->assoc_request.preamble_length ==
7081 DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
7082 network->capability &
7083 WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
James Ketrenos43f66a62005-03-25 12:31:53 -06007084 priv->capability & CAP_PRIVACY_ON ? "on " : "off",
Jeff Garzikbf794512005-07-31 13:07:26 -04007085 priv->capability & CAP_PRIVACY_ON ?
7086 (priv->capability & CAP_SHARED_KEY ? "(shared)" :
James Ketrenos43f66a62005-03-25 12:31:53 -06007087 "(open)") : "",
7088 priv->capability & CAP_PRIVACY_ON ? " key=" : "",
Jeff Garzikbf794512005-07-31 13:07:26 -04007089 priv->capability & CAP_PRIVACY_ON ?
James Ketrenosb095c382005-08-24 22:04:42 -05007090 '1' + priv->ieee->sec.active_key : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007091 priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
James Ketrenos43f66a62005-03-25 12:31:53 -06007092
7093 priv->assoc_request.beacon_interval = network->beacon_interval;
7094 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007095 (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007096 priv->assoc_request.assoc_type = HC_IBSS_START;
7097 priv->assoc_request.assoc_tsf_msw = 0;
7098 priv->assoc_request.assoc_tsf_lsw = 0;
7099 } else {
7100 if (unlikely(roaming))
7101 priv->assoc_request.assoc_type = HC_REASSOCIATE;
7102 else
7103 priv->assoc_request.assoc_type = HC_ASSOCIATE;
7104 priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
7105 priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
7106 }
7107
James Ketrenosafbf30a2005-08-25 00:05:33 -05007108 memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007109
7110 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
7111 memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
7112 priv->assoc_request.atim_window = network->atim_window;
7113 } else {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007114 memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06007115 priv->assoc_request.atim_window = 0;
7116 }
7117
James Ketrenos43f66a62005-03-25 12:31:53 -06007118 priv->assoc_request.listen_interval = network->listen_interval;
Jeff Garzikbf794512005-07-31 13:07:26 -04007119
James Ketrenos43f66a62005-03-25 12:31:53 -06007120 err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
7121 if (err) {
7122 IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
7123 return err;
7124 }
7125
7126 rates->ieee_mode = priv->assoc_request.ieee_mode;
7127 rates->purpose = IPW_RATE_CONNECT;
7128 ipw_send_supported_rates(priv, rates);
Jeff Garzikbf794512005-07-31 13:07:26 -04007129
James Ketrenos43f66a62005-03-25 12:31:53 -06007130 if (priv->assoc_request.ieee_mode == IPW_G_MODE)
7131 priv->sys_config.dot11g_auto_detection = 1;
7132 else
7133 priv->sys_config.dot11g_auto_detection = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007134
7135 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
7136 priv->sys_config.answer_broadcast_ssid_probe = 1;
7137 else
7138 priv->sys_config.answer_broadcast_ssid_probe = 0;
7139
James Ketrenos43f66a62005-03-25 12:31:53 -06007140 err = ipw_send_system_config(priv, &priv->sys_config);
7141 if (err) {
7142 IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
7143 return err;
7144 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007145
James Ketrenos43f66a62005-03-25 12:31:53 -06007146 IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007147 err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
James Ketrenos43f66a62005-03-25 12:31:53 -06007148 if (err) {
7149 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7150 return err;
7151 }
7152
7153 /*
7154 * If preemption is enabled, it is possible for the association
7155 * to complete before we return from ipw_send_associate. Therefore
7156 * we have to be sure and update our priviate data first.
7157 */
7158 priv->channel = network->channel;
7159 memcpy(priv->bssid, network->bssid, ETH_ALEN);
Jeff Garzikbf794512005-07-31 13:07:26 -04007160 priv->status |= STATUS_ASSOCIATING;
James Ketrenos43f66a62005-03-25 12:31:53 -06007161 priv->status &= ~STATUS_SECURITY_UPDATED;
7162
7163 priv->assoc_network = network;
7164
James Ketrenosb095c382005-08-24 22:04:42 -05007165#ifdef CONFIG_IPW_QOS
7166 ipw_qos_association(priv, network);
7167#endif
7168
James Ketrenos43f66a62005-03-25 12:31:53 -06007169 err = ipw_send_associate(priv, &priv->assoc_request);
7170 if (err) {
7171 IPW_DEBUG_HC("Attempt to send associate command failed.\n");
7172 return err;
7173 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007174
7175 IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007176 escape_essid(priv->essid, priv->essid_len),
7177 MAC_ARG(priv->bssid));
7178
7179 return 0;
7180}
7181
7182static void ipw_roam(void *data)
7183{
7184 struct ipw_priv *priv = data;
7185 struct ieee80211_network *network = NULL;
7186 struct ipw_network_match match = {
7187 .network = priv->assoc_network
7188 };
7189
7190 /* The roaming process is as follows:
Jeff Garzikbf794512005-07-31 13:07:26 -04007191 *
7192 * 1. Missed beacon threshold triggers the roaming process by
James Ketrenos43f66a62005-03-25 12:31:53 -06007193 * setting the status ROAM bit and requesting a scan.
7194 * 2. When the scan completes, it schedules the ROAM work
7195 * 3. The ROAM work looks at all of the known networks for one that
7196 * is a better network than the currently associated. If none
7197 * found, the ROAM process is over (ROAM bit cleared)
7198 * 4. If a better network is found, a disassociation request is
7199 * sent.
7200 * 5. When the disassociation completes, the roam work is again
7201 * scheduled. The second time through, the driver is no longer
7202 * associated, and the newly selected network is sent an
Jeff Garzikbf794512005-07-31 13:07:26 -04007203 * association request.
James Ketrenos43f66a62005-03-25 12:31:53 -06007204 * 6. At this point ,the roaming process is complete and the ROAM
7205 * status bit is cleared.
7206 */
7207
7208 /* If we are no longer associated, and the roaming bit is no longer
7209 * set, then we are not actively roaming, so just return */
7210 if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
7211 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007212
James Ketrenos43f66a62005-03-25 12:31:53 -06007213 if (priv->status & STATUS_ASSOCIATED) {
Jeff Garzikbf794512005-07-31 13:07:26 -04007214 /* First pass through ROAM process -- look for a better
James Ketrenos43f66a62005-03-25 12:31:53 -06007215 * network */
James Ketrenosa613bff2005-08-24 21:43:11 -05007216 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007217 u8 rssi = priv->assoc_network->stats.rssi;
7218 priv->assoc_network->stats.rssi = -128;
James Ketrenosa613bff2005-08-24 21:43:11 -05007219 spin_lock_irqsave(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007220 list_for_each_entry(network, &priv->ieee->network_list, list) {
7221 if (network != priv->assoc_network)
7222 ipw_best_network(priv, &match, network, 1);
7223 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007224 spin_unlock_irqrestore(&priv->ieee->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06007225 priv->assoc_network->stats.rssi = rssi;
Jeff Garzikbf794512005-07-31 13:07:26 -04007226
James Ketrenos43f66a62005-03-25 12:31:53 -06007227 if (match.network == priv->assoc_network) {
7228 IPW_DEBUG_ASSOC("No better APs in this network to "
7229 "roam to.\n");
7230 priv->status &= ~STATUS_ROAMING;
7231 ipw_debug_config(priv);
7232 return;
7233 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007234
James Ketrenos43f66a62005-03-25 12:31:53 -06007235 ipw_send_disassociate(priv, 1);
7236 priv->assoc_network = match.network;
7237
7238 return;
Jeff Garzikbf794512005-07-31 13:07:26 -04007239 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007240
7241 /* Second pass through ROAM process -- request association */
7242 ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
7243 ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
7244 priv->status &= ~STATUS_ROAMING;
7245}
7246
James Ketrenosc848d0a2005-08-24 21:56:24 -05007247static void ipw_bg_roam(void *data)
7248{
7249 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08007250 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007251 ipw_roam(data);
Zhu Yi46441512006-01-24 16:37:59 +08007252 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007253}
7254
7255static int ipw_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007256{
7257 struct ipw_priv *priv = data;
7258
7259 struct ieee80211_network *network = NULL;
7260 struct ipw_network_match match = {
7261 .network = NULL
7262 };
7263 struct ipw_supported_rates *rates;
7264 struct list_head *element;
James Ketrenosa613bff2005-08-24 21:43:11 -05007265 unsigned long flags;
James Ketrenos43f66a62005-03-25 12:31:53 -06007266
James Ketrenosb095c382005-08-24 22:04:42 -05007267 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
7268 IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
7269 return 0;
7270 }
7271
James Ketrenosc848d0a2005-08-24 21:56:24 -05007272 if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007273 IPW_DEBUG_ASSOC("Not attempting association (already in "
7274 "progress)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007275 return 0;
7276 }
7277
Hong Liue6324722005-09-14 21:04:15 -05007278 if (priv->status & STATUS_DISASSOCIATING) {
7279 IPW_DEBUG_ASSOC("Not attempting association (in "
7280 "disassociating)\n ");
7281 queue_work(priv->workqueue, &priv->associate);
7282 return 0;
7283 }
7284
James Ketrenosc848d0a2005-08-24 21:56:24 -05007285 if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007286 IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
7287 "initialized)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007288 return 0;
7289 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007290
7291 if (!(priv->config & CFG_ASSOCIATE) &&
7292 !(priv->config & (CFG_STATIC_ESSID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007293 CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
James Ketrenos43f66a62005-03-25 12:31:53 -06007294 IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
James Ketrenosc848d0a2005-08-24 21:56:24 -05007295 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007296 }
7297
James Ketrenosa613bff2005-08-24 21:43:11 -05007298 /* Protect our use of the network_list */
7299 spin_lock_irqsave(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007300 list_for_each_entry(network, &priv->ieee->network_list, list)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007301 ipw_best_network(priv, &match, network, 0);
James Ketrenos43f66a62005-03-25 12:31:53 -06007302
7303 network = match.network;
7304 rates = &match.rates;
7305
7306 if (network == NULL &&
7307 priv->ieee->iw_mode == IW_MODE_ADHOC &&
7308 priv->config & CFG_ADHOC_CREATE &&
7309 priv->config & CFG_STATIC_ESSID &&
James Ketrenosa613bff2005-08-24 21:43:11 -05007310 priv->config & CFG_STATIC_CHANNEL &&
James Ketrenos43f66a62005-03-25 12:31:53 -06007311 !list_empty(&priv->ieee->network_free_list)) {
7312 element = priv->ieee->network_free_list.next;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007313 network = list_entry(element, struct ieee80211_network, list);
James Ketrenos43f66a62005-03-25 12:31:53 -06007314 ipw_adhoc_create(priv, network);
7315 rates = &priv->rates;
7316 list_del(element);
7317 list_add_tail(&network->list, &priv->ieee->network_list);
7318 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007319 spin_unlock_irqrestore(&priv->ieee->lock, flags);
Jeff Garzikbf794512005-07-31 13:07:26 -04007320
James Ketrenos43f66a62005-03-25 12:31:53 -06007321 /* If we reached the end of the list, then we don't have any valid
7322 * matching APs */
7323 if (!network) {
7324 ipw_debug_config(priv);
7325
James Ketrenosb095c382005-08-24 22:04:42 -05007326 if (!(priv->status & STATUS_SCANNING)) {
7327 if (!(priv->config & CFG_SPEED_SCAN))
7328 queue_delayed_work(priv->workqueue,
7329 &priv->request_scan,
7330 SCAN_INTERVAL);
7331 else
7332 queue_work(priv->workqueue,
7333 &priv->request_scan);
7334 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007335
James Ketrenosc848d0a2005-08-24 21:56:24 -05007336 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007337 }
7338
7339 ipw_associate_network(priv, network, rates, 0);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007340
7341 return 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06007342}
Jeff Garzikbf794512005-07-31 13:07:26 -04007343
James Ketrenosc848d0a2005-08-24 21:56:24 -05007344static void ipw_bg_associate(void *data)
James Ketrenos43f66a62005-03-25 12:31:53 -06007345{
James Ketrenosc848d0a2005-08-24 21:56:24 -05007346 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +08007347 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05007348 ipw_associate(data);
Zhu Yi46441512006-01-24 16:37:59 +08007349 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06007350}
7351
James Ketrenosb095c382005-08-24 22:04:42 -05007352static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
7353 struct sk_buff *skb)
7354{
7355 struct ieee80211_hdr *hdr;
7356 u16 fc;
7357
7358 hdr = (struct ieee80211_hdr *)skb->data;
7359 fc = le16_to_cpu(hdr->frame_ctl);
7360 if (!(fc & IEEE80211_FCTL_PROTECTED))
7361 return;
7362
7363 fc &= ~IEEE80211_FCTL_PROTECTED;
7364 hdr->frame_ctl = cpu_to_le16(fc);
7365 switch (priv->ieee->sec.level) {
7366 case SEC_LEVEL_3:
7367 /* Remove CCMP HDR */
7368 memmove(skb->data + IEEE80211_3ADDR_LEN,
7369 skb->data + IEEE80211_3ADDR_LEN + 8,
7370 skb->len - IEEE80211_3ADDR_LEN - 8);
Zhu Yif4ff4972005-09-12 10:48:48 -05007371 skb_trim(skb, skb->len - 16); /* CCMP_HDR_LEN + CCMP_MIC_LEN */
James Ketrenosb095c382005-08-24 22:04:42 -05007372 break;
7373 case SEC_LEVEL_2:
7374 break;
7375 case SEC_LEVEL_1:
7376 /* Remove IV */
7377 memmove(skb->data + IEEE80211_3ADDR_LEN,
7378 skb->data + IEEE80211_3ADDR_LEN + 4,
7379 skb->len - IEEE80211_3ADDR_LEN - 4);
Zhu Yif4ff4972005-09-12 10:48:48 -05007380 skb_trim(skb, skb->len - 8); /* IV + ICV */
James Ketrenosb095c382005-08-24 22:04:42 -05007381 break;
7382 case SEC_LEVEL_0:
7383 break;
7384 default:
7385 printk(KERN_ERR "Unknow security level %d\n",
7386 priv->ieee->sec.level);
7387 break;
7388 }
7389}
7390
7391static void ipw_handle_data_packet(struct ipw_priv *priv,
7392 struct ipw_rx_mem_buffer *rxb,
7393 struct ieee80211_rx_stats *stats)
James Ketrenos43f66a62005-03-25 12:31:53 -06007394{
Hong Liu567deaf2005-08-31 18:07:22 +08007395 struct ieee80211_hdr_4addr *hdr;
James Ketrenos43f66a62005-03-25 12:31:53 -06007396 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7397
7398 /* We received data from the HW, so stop the watchdog */
7399 priv->net_dev->trans_start = jiffies;
7400
Jeff Garzikbf794512005-07-31 13:07:26 -04007401 /* We only process data packets if the
James Ketrenos43f66a62005-03-25 12:31:53 -06007402 * interface is open */
James Ketrenosa613bff2005-08-24 21:43:11 -05007403 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
James Ketrenos43f66a62005-03-25 12:31:53 -06007404 skb_tailroom(rxb->skb))) {
7405 priv->ieee->stats.rx_errors++;
7406 priv->wstats.discard.misc++;
7407 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7408 return;
7409 } else if (unlikely(!netif_running(priv->net_dev))) {
7410 priv->ieee->stats.rx_dropped++;
7411 priv->wstats.discard.misc++;
7412 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7413 return;
7414 }
7415
7416 /* Advance skb->data to the start of the actual payload */
Jiri Bencaaa4d302005-06-07 14:58:41 +02007417 skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
James Ketrenos43f66a62005-03-25 12:31:53 -06007418
7419 /* Set the size of the skb to the size of the frame */
James Ketrenosa613bff2005-08-24 21:43:11 -05007420 skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
James Ketrenos43f66a62005-03-25 12:31:53 -06007421
7422 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7423
James Ketrenosb095c382005-08-24 22:04:42 -05007424 /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
Hong Liu567deaf2005-08-31 18:07:22 +08007425 hdr = (struct ieee80211_hdr_4addr *)rxb->skb->data;
7426 if (priv->ieee->iw_mode != IW_MODE_MONITOR &&
Stephen Hemminger3c190652006-01-03 15:27:38 -08007427 (is_multicast_ether_addr(hdr->addr1) ?
Hong Liu567deaf2005-08-31 18:07:22 +08007428 !priv->ieee->host_mc_decrypt : !priv->ieee->host_decrypt))
James Ketrenosb095c382005-08-24 22:04:42 -05007429 ipw_rebuild_decrypted_skb(priv, rxb->skb);
7430
Jeff Garzikbf794512005-07-31 13:07:26 -04007431 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
James Ketrenos43f66a62005-03-25 12:31:53 -06007432 priv->ieee->stats.rx_errors++;
James Ketrenosa613bff2005-08-24 21:43:11 -05007433 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007434 rxb->skb = NULL;
James Ketrenosb095c382005-08-24 22:04:42 -05007435 __ipw_led_activity_on(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -05007436 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007437}
7438
Mike Kershaw24a47db2005-08-26 00:41:54 -05007439#ifdef CONFIG_IEEE80211_RADIOTAP
7440static void ipw_handle_data_packet_monitor(struct ipw_priv *priv,
7441 struct ipw_rx_mem_buffer *rxb,
7442 struct ieee80211_rx_stats *stats)
7443{
7444 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
7445 struct ipw_rx_frame *frame = &pkt->u.frame;
7446
7447 /* initial pull of some data */
7448 u16 received_channel = frame->received_channel;
7449 u8 antennaAndPhy = frame->antennaAndPhy;
7450 s8 antsignal = frame->rssi_dbm - IPW_RSSI_TO_DBM; /* call it signed anyhow */
7451 u16 pktrate = frame->rate;
7452
7453 /* Magic struct that slots into the radiotap header -- no reason
7454 * to build this manually element by element, we can write it much
7455 * more efficiently than we can parse it. ORDER MATTERS HERE */
7456 struct ipw_rt_hdr {
7457 struct ieee80211_radiotap_header rt_hdr;
7458 u8 rt_flags; /* radiotap packet flags */
7459 u8 rt_rate; /* rate in 500kb/s */
7460 u16 rt_channel; /* channel in mhz */
7461 u16 rt_chbitmask; /* channel bitfield */
7462 s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
7463 u8 rt_antenna; /* antenna number */
7464 } *ipw_rt;
7465
7466 short len = le16_to_cpu(pkt->u.frame.length);
7467
7468 /* We received data from the HW, so stop the watchdog */
7469 priv->net_dev->trans_start = jiffies;
7470
7471 /* We only process data packets if the
7472 * interface is open */
7473 if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
7474 skb_tailroom(rxb->skb))) {
7475 priv->ieee->stats.rx_errors++;
7476 priv->wstats.discard.misc++;
7477 IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
7478 return;
7479 } else if (unlikely(!netif_running(priv->net_dev))) {
7480 priv->ieee->stats.rx_dropped++;
7481 priv->wstats.discard.misc++;
7482 IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
7483 return;
7484 }
7485
7486 /* Libpcap 0.9.3+ can handle variable length radiotap, so we'll use
7487 * that now */
7488 if (len > IPW_RX_BUF_SIZE - sizeof(struct ipw_rt_hdr)) {
7489 /* FIXME: Should alloc bigger skb instead */
7490 priv->ieee->stats.rx_dropped++;
7491 priv->wstats.discard.misc++;
7492 IPW_DEBUG_DROP("Dropping too large packet in monitor\n");
7493 return;
7494 }
7495
7496 /* copy the frame itself */
7497 memmove(rxb->skb->data + sizeof(struct ipw_rt_hdr),
7498 rxb->skb->data + IPW_RX_FRAME_SIZE, len);
7499
7500 /* Zero the radiotap static buffer ... We only need to zero the bytes NOT
7501 * part of our real header, saves a little time.
7502 *
7503 * No longer necessary since we fill in all our data. Purge before merging
7504 * patch officially.
7505 * memset(rxb->skb->data + sizeof(struct ipw_rt_hdr), 0,
7506 * IEEE80211_RADIOTAP_HDRLEN - sizeof(struct ipw_rt_hdr));
7507 */
7508
7509 ipw_rt = (struct ipw_rt_hdr *)rxb->skb->data;
7510
7511 ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
7512 ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
7513 ipw_rt->rt_hdr.it_len = sizeof(struct ipw_rt_hdr); /* total header+data */
7514
7515 /* Big bitfield of all the fields we provide in radiotap */
7516 ipw_rt->rt_hdr.it_present =
7517 ((1 << IEEE80211_RADIOTAP_FLAGS) |
7518 (1 << IEEE80211_RADIOTAP_RATE) |
7519 (1 << IEEE80211_RADIOTAP_CHANNEL) |
7520 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
7521 (1 << IEEE80211_RADIOTAP_ANTENNA));
7522
7523 /* Zero the flags, we'll add to them as we go */
7524 ipw_rt->rt_flags = 0;
7525
7526 /* Convert signal to DBM */
7527 ipw_rt->rt_dbmsignal = antsignal;
7528
7529 /* Convert the channel data and set the flags */
7530 ipw_rt->rt_channel = cpu_to_le16(ieee80211chan2mhz(received_channel));
7531 if (received_channel > 14) { /* 802.11a */
7532 ipw_rt->rt_chbitmask =
7533 cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
7534 } else if (antennaAndPhy & 32) { /* 802.11b */
7535 ipw_rt->rt_chbitmask =
7536 cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
7537 } else { /* 802.11g */
7538 ipw_rt->rt_chbitmask =
7539 (IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ);
7540 }
7541
7542 /* set the rate in multiples of 500k/s */
7543 switch (pktrate) {
7544 case IPW_TX_RATE_1MB:
7545 ipw_rt->rt_rate = 2;
7546 break;
7547 case IPW_TX_RATE_2MB:
7548 ipw_rt->rt_rate = 4;
7549 break;
7550 case IPW_TX_RATE_5MB:
7551 ipw_rt->rt_rate = 10;
7552 break;
7553 case IPW_TX_RATE_6MB:
7554 ipw_rt->rt_rate = 12;
7555 break;
7556 case IPW_TX_RATE_9MB:
7557 ipw_rt->rt_rate = 18;
7558 break;
7559 case IPW_TX_RATE_11MB:
7560 ipw_rt->rt_rate = 22;
7561 break;
7562 case IPW_TX_RATE_12MB:
7563 ipw_rt->rt_rate = 24;
7564 break;
7565 case IPW_TX_RATE_18MB:
7566 ipw_rt->rt_rate = 36;
7567 break;
7568 case IPW_TX_RATE_24MB:
7569 ipw_rt->rt_rate = 48;
7570 break;
7571 case IPW_TX_RATE_36MB:
7572 ipw_rt->rt_rate = 72;
7573 break;
7574 case IPW_TX_RATE_48MB:
7575 ipw_rt->rt_rate = 96;
7576 break;
7577 case IPW_TX_RATE_54MB:
7578 ipw_rt->rt_rate = 108;
7579 break;
7580 default:
7581 ipw_rt->rt_rate = 0;
7582 break;
7583 }
7584
7585 /* antenna number */
7586 ipw_rt->rt_antenna = (antennaAndPhy & 3); /* Is this right? */
7587
7588 /* set the preamble flag if we have it */
7589 if ((antennaAndPhy & 64))
7590 ipw_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
7591
7592 /* Set the size of the skb to the size of the frame */
7593 skb_put(rxb->skb, len + sizeof(struct ipw_rt_hdr));
James Ketrenos43f66a62005-03-25 12:31:53 -06007594
7595 IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
7596
7597 if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
7598 priv->ieee->stats.rx_errors++;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007599 else { /* ieee80211_rx succeeded, so it now owns the SKB */
James Ketrenos43f66a62005-03-25 12:31:53 -06007600 rxb->skb = NULL;
Mike Kershaw24a47db2005-08-26 00:41:54 -05007601 /* no LED during capture */
7602 }
7603}
7604#endif
7605
Arjan van de Ven858119e2006-01-14 13:20:43 -08007606static int is_network_packet(struct ipw_priv *priv,
James Ketrenosea2b26e2005-08-24 21:25:16 -05007607 struct ieee80211_hdr_4addr *header)
7608{
7609 /* Filter incoming packets to determine if they are targetted toward
7610 * this network, discarding packets coming from ourselves */
7611 switch (priv->ieee->iw_mode) {
James Ketrenosa613bff2005-08-24 21:43:11 -05007612 case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007613 /* packets from our adapter are dropped (echo) */
7614 if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
7615 return 0;
7616
Peter Jones90700fd2005-08-26 16:51:06 -05007617 /* {broad,multi}cast packets to our BSSID go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007618 if (is_multicast_ether_addr(header->addr1))
James Ketrenosea2b26e2005-08-24 21:25:16 -05007619 return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007620
7621 /* packets to our adapter go through */
7622 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7623 ETH_ALEN);
James Ketrenosa613bff2005-08-24 21:43:11 -05007624
Peter Jones90700fd2005-08-26 16:51:06 -05007625 case IW_MODE_INFRA: /* Header: Dest. | BSSID | Source */
James Ketrenosc848d0a2005-08-24 21:56:24 -05007626 /* packets from our adapter are dropped (echo) */
7627 if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
7628 return 0;
7629
Peter Jones90700fd2005-08-26 16:51:06 -05007630 /* {broad,multi}cast packets to our BSS go through */
Stephen Hemminger3c190652006-01-03 15:27:38 -08007631 if (is_multicast_ether_addr(header->addr1))
James Ketrenosa613bff2005-08-24 21:43:11 -05007632 return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
7633
7634 /* packets to our adapter go through */
7635 return !memcmp(header->addr1, priv->net_dev->dev_addr,
7636 ETH_ALEN);
James Ketrenosea2b26e2005-08-24 21:25:16 -05007637 }
James Ketrenosa613bff2005-08-24 21:43:11 -05007638
James Ketrenosea2b26e2005-08-24 21:25:16 -05007639 return 1;
7640}
7641
James Ketrenosafbf30a2005-08-25 00:05:33 -05007642#define IPW_PACKET_RETRY_TIME HZ
7643
Arjan van de Ven858119e2006-01-14 13:20:43 -08007644static int is_duplicate_packet(struct ipw_priv *priv,
James Ketrenosafbf30a2005-08-25 00:05:33 -05007645 struct ieee80211_hdr_4addr *header)
7646{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007647 u16 sc = le16_to_cpu(header->seq_ctl);
7648 u16 seq = WLAN_GET_SEQ_SEQ(sc);
7649 u16 frag = WLAN_GET_SEQ_FRAG(sc);
7650 u16 *last_seq, *last_frag;
7651 unsigned long *last_time;
7652
7653 switch (priv->ieee->iw_mode) {
7654 case IW_MODE_ADHOC:
7655 {
7656 struct list_head *p;
7657 struct ipw_ibss_seq *entry = NULL;
7658 u8 *mac = header->addr2;
7659 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
7660
7661 __list_for_each(p, &priv->ibss_mac_hash[index]) {
7662 entry =
7663 list_entry(p, struct ipw_ibss_seq, list);
7664 if (!memcmp(entry->mac, mac, ETH_ALEN))
7665 break;
7666 }
7667 if (p == &priv->ibss_mac_hash[index]) {
7668 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
7669 if (!entry) {
7670 IPW_ERROR
7671 ("Cannot malloc new mac entry\n");
7672 return 0;
7673 }
7674 memcpy(entry->mac, mac, ETH_ALEN);
7675 entry->seq_num = seq;
7676 entry->frag_num = frag;
7677 entry->packet_time = jiffies;
7678 list_add(&entry->list,
7679 &priv->ibss_mac_hash[index]);
7680 return 0;
7681 }
7682 last_seq = &entry->seq_num;
7683 last_frag = &entry->frag_num;
7684 last_time = &entry->packet_time;
7685 break;
7686 }
7687 case IW_MODE_INFRA:
7688 last_seq = &priv->last_seq_num;
7689 last_frag = &priv->last_frag_num;
7690 last_time = &priv->last_packet_time;
7691 break;
7692 default:
7693 return 0;
7694 }
7695 if ((*last_seq == seq) &&
7696 time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
7697 if (*last_frag == frag)
7698 goto drop;
7699 if (*last_frag + 1 != frag)
7700 /* out-of-order fragment */
7701 goto drop;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007702 } else
7703 *last_seq = seq;
7704
Zhu Yif57ce7c2005-07-13 12:22:15 -05007705 *last_frag = frag;
James Ketrenosafbf30a2005-08-25 00:05:33 -05007706 *last_time = jiffies;
7707 return 0;
7708
7709 drop:
Zhu Yi87b016c2005-08-05 17:17:35 +08007710 /* Comment this line now since we observed the card receives
7711 * duplicate packets but the FCTL_RETRY bit is not set in the
7712 * IBSS mode with fragmentation enabled.
7713 BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
James Ketrenosafbf30a2005-08-25 00:05:33 -05007714 return 1;
7715}
7716
James Ketrenosb095c382005-08-24 22:04:42 -05007717static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
7718 struct ipw_rx_mem_buffer *rxb,
7719 struct ieee80211_rx_stats *stats)
7720{
7721 struct sk_buff *skb = rxb->skb;
7722 struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
7723 struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
7724 (skb->data + IPW_RX_FRAME_SIZE);
7725
7726 ieee80211_rx_mgt(priv->ieee, header, stats);
7727
7728 if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
7729 ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7730 IEEE80211_STYPE_PROBE_RESP) ||
7731 (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
7732 IEEE80211_STYPE_BEACON))) {
7733 if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
7734 ipw_add_station(priv, header->addr2);
7735 }
7736
7737 if (priv->config & CFG_NET_STATS) {
7738 IPW_DEBUG_HC("sending stat packet\n");
7739
7740 /* Set the size of the skb to the size of the full
7741 * ipw header and 802.11 frame */
7742 skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
7743 IPW_RX_FRAME_SIZE);
7744
7745 /* Advance past the ipw packet header to the 802.11 frame */
7746 skb_pull(skb, IPW_RX_FRAME_SIZE);
7747
7748 /* Push the ieee80211_rx_stats before the 802.11 frame */
7749 memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
7750
7751 skb->dev = priv->ieee->dev;
7752
7753 /* Point raw at the ieee80211_stats */
7754 skb->mac.raw = skb->data;
7755
7756 skb->pkt_type = PACKET_OTHERHOST;
7757 skb->protocol = __constant_htons(ETH_P_80211_STATS);
7758 memset(skb->cb, 0, sizeof(rxb->skb->cb));
7759 netif_rx(skb);
7760 rxb->skb = NULL;
7761 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007762}
7763
James Ketrenos43f66a62005-03-25 12:31:53 -06007764/*
7765 * Main entry function for recieving a packet with 80211 headers. This
7766 * should be called when ever the FW has notified us that there is a new
7767 * skb in the recieve queue.
7768 */
7769static void ipw_rx(struct ipw_priv *priv)
7770{
7771 struct ipw_rx_mem_buffer *rxb;
7772 struct ipw_rx_packet *pkt;
James Ketrenos0dacca12005-09-21 12:23:41 -05007773 struct ieee80211_hdr_4addr *header;
James Ketrenos43f66a62005-03-25 12:31:53 -06007774 u32 r, w, i;
7775 u8 network_packet;
7776
James Ketrenosb095c382005-08-24 22:04:42 -05007777 r = ipw_read32(priv, IPW_RX_READ_INDEX);
7778 w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
James Ketrenos43f66a62005-03-25 12:31:53 -06007779 i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
7780
7781 while (i != r) {
7782 rxb = priv->rxq->queue[i];
James Ketrenos43f66a62005-03-25 12:31:53 -06007783 if (unlikely(rxb == NULL)) {
7784 printk(KERN_CRIT "Queue not allocated!\n");
7785 break;
7786 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007787 priv->rxq->queue[i] = NULL;
7788
7789 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05007790 IPW_RX_BUF_SIZE,
James Ketrenos43f66a62005-03-25 12:31:53 -06007791 PCI_DMA_FROMDEVICE);
7792
7793 pkt = (struct ipw_rx_packet *)rxb->skb->data;
7794 IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
7795 pkt->header.message_type,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007796 pkt->header.rx_seq_num, pkt->header.control_bits);
James Ketrenos43f66a62005-03-25 12:31:53 -06007797
7798 switch (pkt->header.message_type) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007799 case RX_FRAME_TYPE: /* 802.11 frame */ {
7800 struct ieee80211_rx_stats stats = {
James Ketrenosc848d0a2005-08-24 21:56:24 -05007801 .rssi =
7802 le16_to_cpu(pkt->u.frame.rssi_dbm) -
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007803 IPW_RSSI_TO_DBM,
James Ketrenosc848d0a2005-08-24 21:56:24 -05007804 .signal =
Bill Mossb1916082006-02-15 08:50:18 +08007805 le16_to_cpu(pkt->u.frame.rssi_dbm) -
7806 IPW_RSSI_TO_DBM + 0x100,
James Ketrenosc848d0a2005-08-24 21:56:24 -05007807 .noise =
7808 le16_to_cpu(pkt->u.frame.noise),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007809 .rate = pkt->u.frame.rate,
7810 .mac_time = jiffies,
7811 .received_channel =
7812 pkt->u.frame.received_channel,
7813 .freq =
7814 (pkt->u.frame.
7815 control & (1 << 0)) ?
7816 IEEE80211_24GHZ_BAND :
7817 IEEE80211_52GHZ_BAND,
James Ketrenosa613bff2005-08-24 21:43:11 -05007818 .len = le16_to_cpu(pkt->u.frame.length),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007819 };
James Ketrenos43f66a62005-03-25 12:31:53 -06007820
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007821 if (stats.rssi != 0)
7822 stats.mask |= IEEE80211_STATMASK_RSSI;
7823 if (stats.signal != 0)
7824 stats.mask |= IEEE80211_STATMASK_SIGNAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05007825 if (stats.noise != 0)
7826 stats.mask |= IEEE80211_STATMASK_NOISE;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007827 if (stats.rate != 0)
7828 stats.mask |= IEEE80211_STATMASK_RATE;
James Ketrenos43f66a62005-03-25 12:31:53 -06007829
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007830 priv->rx_packets++;
James Ketrenos43f66a62005-03-25 12:31:53 -06007831
James Ketrenosb095c382005-08-24 22:04:42 -05007832#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007833 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
Mike Kershaw24a47db2005-08-26 00:41:54 -05007834#ifdef CONFIG_IEEE80211_RADIOTAP
7835 ipw_handle_data_packet_monitor(priv,
7836 rxb,
7837 &stats);
7838#else
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007839 ipw_handle_data_packet(priv, rxb,
7840 &stats);
Mike Kershaw24a47db2005-08-26 00:41:54 -05007841#endif
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007842 break;
7843 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007844#endif
Jeff Garzikbf794512005-07-31 13:07:26 -04007845
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007846 header =
James Ketrenos0dacca12005-09-21 12:23:41 -05007847 (struct ieee80211_hdr_4addr *)(rxb->skb->
7848 data +
7849 IPW_RX_FRAME_SIZE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007850 /* TODO: Check Ad-Hoc dest/source and make sure
7851 * that we are actually parsing these packets
Jeff Garzikbf794512005-07-31 13:07:26 -04007852 * correctly -- we should probably use the
James Ketrenos43f66a62005-03-25 12:31:53 -06007853 * frame control of the packet and disregard
7854 * the current iw_mode */
James Ketrenos43f66a62005-03-25 12:31:53 -06007855
James Ketrenosea2b26e2005-08-24 21:25:16 -05007856 network_packet =
7857 is_network_packet(priv, header);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007858 if (network_packet && priv->assoc_network) {
7859 priv->assoc_network->stats.rssi =
7860 stats.rssi;
Zhu Yi00d21de2006-04-13 17:19:02 +08007861 priv->exp_avg_rssi =
7862 exponential_average(priv->exp_avg_rssi,
7863 stats.rssi, DEPTH_RSSI);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007864 }
7865
7866 IPW_DEBUG_RX("Frame: len=%u\n",
James Ketrenosa613bff2005-08-24 21:43:11 -05007867 le16_to_cpu(pkt->u.frame.length));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007868
James Ketrenosa613bff2005-08-24 21:43:11 -05007869 if (le16_to_cpu(pkt->u.frame.length) <
Zhu Yi9d0be032006-02-15 06:18:19 +08007870 ieee80211_get_hdrlen(le16_to_cpu(
7871 header->frame_ctl))) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007872 IPW_DEBUG_DROP
7873 ("Received packet is too small. "
7874 "Dropping.\n");
7875 priv->ieee->stats.rx_errors++;
7876 priv->wstats.discard.misc++;
7877 break;
7878 }
7879
James Ketrenosa613bff2005-08-24 21:43:11 -05007880 switch (WLAN_FC_GET_TYPE
7881 (le16_to_cpu(header->frame_ctl))) {
James Ketrenosb095c382005-08-24 22:04:42 -05007882
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007883 case IEEE80211_FTYPE_MGMT:
James Ketrenosb095c382005-08-24 22:04:42 -05007884 ipw_handle_mgmt_packet(priv, rxb,
7885 &stats);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007886 break;
7887
7888 case IEEE80211_FTYPE_CTL:
7889 break;
7890
7891 case IEEE80211_FTYPE_DATA:
James Ketrenosafbf30a2005-08-25 00:05:33 -05007892 if (unlikely(!network_packet ||
7893 is_duplicate_packet(priv,
7894 header)))
7895 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007896 IPW_DEBUG_DROP("Dropping: "
7897 MAC_FMT ", "
7898 MAC_FMT ", "
7899 MAC_FMT "\n",
7900 MAC_ARG(header->
7901 addr1),
7902 MAC_ARG(header->
7903 addr2),
7904 MAC_ARG(header->
7905 addr3));
James Ketrenosb095c382005-08-24 22:04:42 -05007906 break;
7907 }
7908
7909 ipw_handle_data_packet(priv, rxb,
7910 &stats);
7911
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007912 break;
7913 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007914 break;
7915 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007916
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007917 case RX_HOST_NOTIFICATION_TYPE:{
7918 IPW_DEBUG_RX
7919 ("Notification: subtype=%02X flags=%02X size=%d\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06007920 pkt->u.notification.subtype,
7921 pkt->u.notification.flags,
7922 pkt->u.notification.size);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04007923 ipw_rx_notification(priv, &pkt->u.notification);
7924 break;
7925 }
James Ketrenos43f66a62005-03-25 12:31:53 -06007926
7927 default:
7928 IPW_DEBUG_RX("Bad Rx packet of type %d\n",
7929 pkt->header.message_type);
7930 break;
7931 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007932
7933 /* For now we just don't re-use anything. We can tweak this
7934 * later to try and re-use notification packets and SKBs that
James Ketrenos43f66a62005-03-25 12:31:53 -06007935 * fail to Rx correctly */
7936 if (rxb->skb != NULL) {
7937 dev_kfree_skb_any(rxb->skb);
7938 rxb->skb = NULL;
7939 }
Jeff Garzikbf794512005-07-31 13:07:26 -04007940
James Ketrenos43f66a62005-03-25 12:31:53 -06007941 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
James Ketrenosb095c382005-08-24 22:04:42 -05007942 IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
James Ketrenos43f66a62005-03-25 12:31:53 -06007943 list_add_tail(&rxb->list, &priv->rxq->rx_used);
Jeff Garzikbf794512005-07-31 13:07:26 -04007944
James Ketrenos43f66a62005-03-25 12:31:53 -06007945 i = (i + 1) % RX_QUEUE_SIZE;
7946 }
7947
7948 /* Backtrack one entry */
7949 priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
7950
7951 ipw_rx_queue_restock(priv);
7952}
7953
James Ketrenosafbf30a2005-08-25 00:05:33 -05007954#define DEFAULT_RTS_THRESHOLD 2304U
7955#define MIN_RTS_THRESHOLD 1U
7956#define MAX_RTS_THRESHOLD 2304U
7957#define DEFAULT_BEACON_INTERVAL 100U
7958#define DEFAULT_SHORT_RETRY_LIMIT 7U
7959#define DEFAULT_LONG_RETRY_LIMIT 4U
7960
Zhu Yid6d5b5c2006-02-16 16:21:09 +08007961/**
7962 * ipw_sw_reset
7963 * @option: options to control different reset behaviour
7964 * 0 = reset everything except the 'disable' module_param
7965 * 1 = reset everything and print out driver info (for probe only)
7966 * 2 = reset everything
7967 */
7968static int ipw_sw_reset(struct ipw_priv *priv, int option)
James Ketrenos43f66a62005-03-25 12:31:53 -06007969{
James Ketrenosafbf30a2005-08-25 00:05:33 -05007970 int band, modulation;
7971 int old_mode = priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06007972
James Ketrenosafbf30a2005-08-25 00:05:33 -05007973 /* Initialize module parameter values here */
7974 priv->config = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06007975
James Ketrenosafbf30a2005-08-25 00:05:33 -05007976 /* We default to disabling the LED code as right now it causes
7977 * too many systems to lock up... */
7978 if (!led)
7979 priv->config |= CFG_NO_LED;
James Ketrenos43f66a62005-03-25 12:31:53 -06007980
James Ketrenosafbf30a2005-08-25 00:05:33 -05007981 if (associate)
7982 priv->config |= CFG_ASSOCIATE;
7983 else
7984 IPW_DEBUG_INFO("Auto associate disabled.\n");
Jeff Garzikbf794512005-07-31 13:07:26 -04007985
James Ketrenosafbf30a2005-08-25 00:05:33 -05007986 if (auto_create)
7987 priv->config |= CFG_ADHOC_CREATE;
7988 else
7989 IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
7990
Zhu Yi17ed0812006-01-24 16:36:31 +08007991 priv->config &= ~CFG_STATIC_ESSID;
7992 priv->essid_len = 0;
7993 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
7994
Zhu Yid6d5b5c2006-02-16 16:21:09 +08007995 if (disable && option) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05007996 priv->status |= STATUS_RF_KILL_SW;
7997 IPW_DEBUG_INFO("Radio disabled.\n");
James Ketrenos43f66a62005-03-25 12:31:53 -06007998 }
7999
James Ketrenosafbf30a2005-08-25 00:05:33 -05008000 if (channel != 0) {
8001 priv->config |= CFG_STATIC_CHANNEL;
8002 priv->channel = channel;
8003 IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
8004 /* TODO: Validate that provided channel is in range */
8005 }
8006#ifdef CONFIG_IPW_QOS
8007 ipw_qos_init(priv, qos_enable, qos_burst_enable,
8008 burst_duration_CCK, burst_duration_OFDM);
8009#endif /* CONFIG_IPW_QOS */
8010
8011 switch (mode) {
8012 case 1:
8013 priv->ieee->iw_mode = IW_MODE_ADHOC;
8014 priv->net_dev->type = ARPHRD_ETHER;
8015
8016 break;
8017#ifdef CONFIG_IPW2200_MONITOR
8018 case 2:
8019 priv->ieee->iw_mode = IW_MODE_MONITOR;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008020#ifdef CONFIG_IEEE80211_RADIOTAP
8021 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8022#else
James Ketrenosafbf30a2005-08-25 00:05:33 -05008023 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008024#endif
James Ketrenosafbf30a2005-08-25 00:05:33 -05008025 break;
8026#endif
8027 default:
8028 case 0:
8029 priv->net_dev->type = ARPHRD_ETHER;
8030 priv->ieee->iw_mode = IW_MODE_INFRA;
8031 break;
James Ketrenos43f66a62005-03-25 12:31:53 -06008032 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008033
James Ketrenosafbf30a2005-08-25 00:05:33 -05008034 if (hwcrypto) {
8035 priv->ieee->host_encrypt = 0;
8036 priv->ieee->host_encrypt_msdu = 0;
8037 priv->ieee->host_decrypt = 0;
Hong Liu567deaf2005-08-31 18:07:22 +08008038 priv->ieee->host_mc_decrypt = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008039 }
James Ketrenosafbf30a2005-08-25 00:05:33 -05008040 IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
James Ketrenos43f66a62005-03-25 12:31:53 -06008041
Zhu Yie402c932005-08-05 17:20:40 +08008042 /* IPW2200/2915 is abled to do hardware fragmentation. */
8043 priv->ieee->host_open_frag = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008044
James Ketrenosafbf30a2005-08-25 00:05:33 -05008045 if ((priv->pci_dev->device == 0x4223) ||
8046 (priv->pci_dev->device == 0x4224)) {
Zhu Yie8c69e22006-02-17 08:25:12 +08008047 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008048 printk(KERN_INFO DRV_NAME
8049 ": Detected Intel PRO/Wireless 2915ABG Network "
8050 "Connection\n");
8051 priv->ieee->abg_true = 1;
8052 band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
8053 modulation = IEEE80211_OFDM_MODULATION |
8054 IEEE80211_CCK_MODULATION;
8055 priv->adapter = IPW_2915ABG;
8056 priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008057 } else {
Zhu Yie8c69e22006-02-17 08:25:12 +08008058 if (option == 1)
James Ketrenosafbf30a2005-08-25 00:05:33 -05008059 printk(KERN_INFO DRV_NAME
8060 ": Detected Intel PRO/Wireless 2200BG Network "
8061 "Connection\n");
8062
8063 priv->ieee->abg_true = 0;
8064 band = IEEE80211_24GHZ_BAND;
8065 modulation = IEEE80211_OFDM_MODULATION |
8066 IEEE80211_CCK_MODULATION;
8067 priv->adapter = IPW_2200BG;
8068 priv->ieee->mode = IEEE_G | IEEE_B;
James Ketrenos43f66a62005-03-25 12:31:53 -06008069 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008070
James Ketrenosafbf30a2005-08-25 00:05:33 -05008071 priv->ieee->freq_band = band;
8072 priv->ieee->modulation = modulation;
Jeff Garzikbf794512005-07-31 13:07:26 -04008073
James Ketrenosafbf30a2005-08-25 00:05:33 -05008074 priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
James Ketrenos43f66a62005-03-25 12:31:53 -06008075
James Ketrenosafbf30a2005-08-25 00:05:33 -05008076 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8077 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008078
James Ketrenosafbf30a2005-08-25 00:05:33 -05008079 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8080 priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
8081 priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
Jeff Garzikbf794512005-07-31 13:07:26 -04008082
James Ketrenosafbf30a2005-08-25 00:05:33 -05008083 /* If power management is turned on, default to AC mode */
8084 priv->power_mode = IPW_POWER_AC;
8085 priv->tx_power = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008086
Zhu Yi0ece35b2005-08-05 17:26:51 +08008087 return old_mode == priv->ieee->iw_mode;
James Ketrenos43f66a62005-03-25 12:31:53 -06008088}
8089
8090/*
8091 * This file defines the Wireless Extension handlers. It does not
8092 * define any methods of hardware manipulation and relies on the
8093 * functions defined in ipw_main to provide the HW interaction.
Jeff Garzikbf794512005-07-31 13:07:26 -04008094 *
8095 * The exception to this is the use of the ipw_get_ordinal()
James Ketrenos43f66a62005-03-25 12:31:53 -06008096 * function used to poll the hardware vs. making unecessary calls.
8097 *
8098 */
8099
Jeff Garzikbf794512005-07-31 13:07:26 -04008100static int ipw_wx_get_name(struct net_device *dev,
8101 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008102 union iwreq_data *wrqu, char *extra)
8103{
8104 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008105 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008106 if (priv->status & STATUS_RF_KILL_MASK)
James Ketrenosa613bff2005-08-24 21:43:11 -05008107 strcpy(wrqu->name, "radio off");
James Ketrenosc848d0a2005-08-24 21:56:24 -05008108 else if (!(priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06008109 strcpy(wrqu->name, "unassociated");
Jeff Garzikbf794512005-07-31 13:07:26 -04008110 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008111 snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
8112 ipw_modes[priv->assoc_request.ieee_mode]);
8113 IPW_DEBUG_WX("Name: %s\n", wrqu->name);
Zhu Yi46441512006-01-24 16:37:59 +08008114 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008115 return 0;
8116}
8117
8118static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
8119{
8120 if (channel == 0) {
8121 IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
8122 priv->config &= ~CFG_STATIC_CHANNEL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008123 IPW_DEBUG_ASSOC("Attempting to associate with new "
8124 "parameters.\n");
8125 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008126 return 0;
8127 }
8128
8129 priv->config |= CFG_STATIC_CHANNEL;
8130
8131 if (priv->channel == channel) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008132 IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
8133 channel);
James Ketrenos43f66a62005-03-25 12:31:53 -06008134 return 0;
8135 }
8136
8137 IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
8138 priv->channel = channel;
8139
James Ketrenosb095c382005-08-24 22:04:42 -05008140#ifdef CONFIG_IPW2200_MONITOR
8141 if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008142 int i;
James Ketrenosb095c382005-08-24 22:04:42 -05008143 if (priv->status & STATUS_SCANNING) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008144 IPW_DEBUG_SCAN("Scan abort triggered due to "
James Ketrenosb095c382005-08-24 22:04:42 -05008145 "channel change.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008146 ipw_abort_scan(priv);
James Ketrenosb095c382005-08-24 22:04:42 -05008147 }
8148
8149 for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
8150 udelay(10);
8151
8152 if (priv->status & STATUS_SCANNING)
8153 IPW_DEBUG_SCAN("Still scanning...\n");
8154 else
8155 IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
8156 1000 - i);
8157
8158 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008159 }
James Ketrenosb095c382005-08-24 22:04:42 -05008160#endif /* CONFIG_IPW2200_MONITOR */
8161
James Ketrenosc848d0a2005-08-24 21:56:24 -05008162 /* Network configuration changed -- force [re]association */
8163 IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
8164 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008165 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008166
8167 return 0;
8168}
8169
Jeff Garzikbf794512005-07-31 13:07:26 -04008170static int ipw_wx_set_freq(struct net_device *dev,
8171 struct iw_request_info *info,
8172 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008173{
8174 struct ipw_priv *priv = ieee80211_priv(dev);
Larry Finger1867b112006-02-28 09:48:28 -06008175 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenos43f66a62005-03-25 12:31:53 -06008176 struct iw_freq *fwrq = &wrqu->freq;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008177 int ret = 0, i;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008178 u8 channel, flags;
8179 int band;
Jeff Garzikbf794512005-07-31 13:07:26 -04008180
James Ketrenosb095c382005-08-24 22:04:42 -05008181 if (fwrq->m == 0) {
8182 IPW_DEBUG_WX("SET Freq/Channel -> any\n");
Zhu Yi46441512006-01-24 16:37:59 +08008183 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008184 ret = ipw_set_channel(priv, 0);
Zhu Yi46441512006-01-24 16:37:59 +08008185 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008186 return ret;
8187 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008188 /* if setting by freq convert to channel */
8189 if (fwrq->e == 1) {
Larry Finger1867b112006-02-28 09:48:28 -06008190 channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
James Ketrenosb095c382005-08-24 22:04:42 -05008191 if (channel == 0)
8192 return -EINVAL;
8193 } else
8194 channel = fwrq->m;
Jeff Garzikbf794512005-07-31 13:07:26 -04008195
Larry Finger1867b112006-02-28 09:48:28 -06008196 if (!(band = ieee80211_is_valid_channel(priv->ieee, channel)))
James Ketrenosb095c382005-08-24 22:04:42 -05008197 return -EINVAL;
Jeff Garzikbf794512005-07-31 13:07:26 -04008198
Liu Hong1fe0adb2005-08-19 09:33:10 -05008199 if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
Larry Finger1867b112006-02-28 09:48:28 -06008200 i = ieee80211_channel_to_index(priv->ieee, channel);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008201 if (i == -1)
8202 return -EINVAL;
Liu Hong1fe0adb2005-08-19 09:33:10 -05008203
8204 flags = (band == IEEE80211_24GHZ_BAND) ?
8205 geo->bg[i].flags : geo->a[i].flags;
8206 if (flags & IEEE80211_CH_PASSIVE_ONLY) {
James Ketrenosafbf30a2005-08-25 00:05:33 -05008207 IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
8208 return -EINVAL;
James Ketrenos43f66a62005-03-25 12:31:53 -06008209 }
8210 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008211
James Ketrenos43f66a62005-03-25 12:31:53 -06008212 IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
Zhu Yi46441512006-01-24 16:37:59 +08008213 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008214 ret = ipw_set_channel(priv, channel);
Zhu Yi46441512006-01-24 16:37:59 +08008215 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008216 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06008217}
8218
Jeff Garzikbf794512005-07-31 13:07:26 -04008219static int ipw_wx_get_freq(struct net_device *dev,
8220 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008221 union iwreq_data *wrqu, char *extra)
8222{
8223 struct ipw_priv *priv = ieee80211_priv(dev);
8224
8225 wrqu->freq.e = 0;
8226
8227 /* If we are associated, trying to associate, or have a statically
8228 * configured CHANNEL then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008229 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008230 if (priv->config & CFG_STATIC_CHANNEL ||
8231 priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
8232 wrqu->freq.m = priv->channel;
Jeff Garzikbf794512005-07-31 13:07:26 -04008233 else
James Ketrenos43f66a62005-03-25 12:31:53 -06008234 wrqu->freq.m = 0;
8235
Zhu Yi46441512006-01-24 16:37:59 +08008236 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008237 IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
8238 return 0;
8239}
8240
Jeff Garzikbf794512005-07-31 13:07:26 -04008241static int ipw_wx_set_mode(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 int err = 0;
8247
8248 IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
8249
James Ketrenos43f66a62005-03-25 12:31:53 -06008250 switch (wrqu->mode) {
James Ketrenosb095c382005-08-24 22:04:42 -05008251#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -06008252 case IW_MODE_MONITOR:
8253#endif
8254 case IW_MODE_ADHOC:
8255 case IW_MODE_INFRA:
8256 break;
8257 case IW_MODE_AUTO:
8258 wrqu->mode = IW_MODE_INFRA;
8259 break;
8260 default:
8261 return -EINVAL;
8262 }
James Ketrenosb095c382005-08-24 22:04:42 -05008263 if (wrqu->mode == priv->ieee->iw_mode)
8264 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008265
Zhu Yi46441512006-01-24 16:37:59 +08008266 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008267
8268 ipw_sw_reset(priv, 0);
8269
James Ketrenosb095c382005-08-24 22:04:42 -05008270#ifdef CONFIG_IPW2200_MONITOR
Jeff Garzikbf794512005-07-31 13:07:26 -04008271 if (priv->ieee->iw_mode == IW_MODE_MONITOR)
James Ketrenos43f66a62005-03-25 12:31:53 -06008272 priv->net_dev->type = ARPHRD_ETHER;
Jeff Garzikbf794512005-07-31 13:07:26 -04008273
8274 if (wrqu->mode == IW_MODE_MONITOR)
Mike Kershaw24a47db2005-08-26 00:41:54 -05008275#ifdef CONFIG_IEEE80211_RADIOTAP
8276 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
8277#else
James Ketrenos43f66a62005-03-25 12:31:53 -06008278 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05008279#endif
James Ketrenosb095c382005-08-24 22:04:42 -05008280#endif /* CONFIG_IPW2200_MONITOR */
Jeff Garzikbf794512005-07-31 13:07:26 -04008281
Jeff Garzikbf794512005-07-31 13:07:26 -04008282 /* Free the existing firmware and reset the fw_loaded
James Ketrenos43f66a62005-03-25 12:31:53 -06008283 * flag so ipw_load() will bring in the new firmawre */
James Ketrenosafbf30a2005-08-25 00:05:33 -05008284 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -06008285
8286 priv->ieee->iw_mode = wrqu->mode;
Jeff Garzikbf794512005-07-31 13:07:26 -04008287
James Ketrenosc848d0a2005-08-24 21:56:24 -05008288 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08008289 mutex_unlock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008290 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008291}
8292
Jeff Garzikbf794512005-07-31 13:07:26 -04008293static int ipw_wx_get_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008294 struct iw_request_info *info,
8295 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008296{
8297 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008298 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008299 wrqu->mode = priv->ieee->iw_mode;
8300 IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
Zhu Yi46441512006-01-24 16:37:59 +08008301 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008302 return 0;
8303}
8304
James Ketrenos43f66a62005-03-25 12:31:53 -06008305/* Values are in microsecond */
8306static const s32 timeout_duration[] = {
8307 350000,
8308 250000,
8309 75000,
8310 37000,
8311 25000,
8312};
8313
8314static const s32 period_duration[] = {
8315 400000,
8316 700000,
8317 1000000,
8318 1000000,
8319 1000000
8320};
8321
Jeff Garzikbf794512005-07-31 13:07:26 -04008322static int ipw_wx_get_range(struct net_device *dev,
8323 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008324 union iwreq_data *wrqu, char *extra)
8325{
8326 struct ipw_priv *priv = ieee80211_priv(dev);
8327 struct iw_range *range = (struct iw_range *)extra;
Larry Finger1867b112006-02-28 09:48:28 -06008328 const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
James Ketrenosb095c382005-08-24 22:04:42 -05008329 int i = 0, j;
James Ketrenos43f66a62005-03-25 12:31:53 -06008330
8331 wrqu->data.length = sizeof(*range);
8332 memset(range, 0, sizeof(*range));
8333
8334 /* 54Mbs == ~27 Mb/s real (802.11g) */
Jeff Garzikbf794512005-07-31 13:07:26 -04008335 range->throughput = 27 * 1000 * 1000;
James Ketrenos43f66a62005-03-25 12:31:53 -06008336
8337 range->max_qual.qual = 100;
8338 /* TODO: Find real max RSSI and stick here */
8339 range->max_qual.level = 0;
Bill Mossb1916082006-02-15 08:50:18 +08008340 range->max_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008341 range->max_qual.updated = 7; /* Updated all three */
James Ketrenos43f66a62005-03-25 12:31:53 -06008342
8343 range->avg_qual.qual = 70;
8344 /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008345 range->avg_qual.level = 0; /* FIXME to real average level */
James Ketrenos43f66a62005-03-25 12:31:53 -06008346 range->avg_qual.noise = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008347 range->avg_qual.updated = 7; /* Updated all three */
Zhu Yi46441512006-01-24 16:37:59 +08008348 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008349 range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
James Ketrenos43f66a62005-03-25 12:31:53 -06008350
Jeff Garzikbf794512005-07-31 13:07:26 -04008351 for (i = 0; i < range->num_bitrates; i++)
8352 range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008353 500000;
Jeff Garzikbf794512005-07-31 13:07:26 -04008354
James Ketrenos43f66a62005-03-25 12:31:53 -06008355 range->max_rts = DEFAULT_RTS_THRESHOLD;
8356 range->min_frag = MIN_FRAG_THRESHOLD;
8357 range->max_frag = MAX_FRAG_THRESHOLD;
8358
8359 range->encoding_size[0] = 5;
Jeff Garzikbf794512005-07-31 13:07:26 -04008360 range->encoding_size[1] = 13;
James Ketrenos43f66a62005-03-25 12:31:53 -06008361 range->num_encoding_sizes = 2;
8362 range->max_encoding_tokens = WEP_KEYS;
8363
8364 /* Set the Wireless Extension versions */
8365 range->we_version_compiled = WIRELESS_EXT;
Dan Williamsf1b50862006-01-30 13:58:56 -05008366 range->we_version_source = 18;
James Ketrenos43f66a62005-03-25 12:31:53 -06008367
James Ketrenosb095c382005-08-24 22:04:42 -05008368 i = 0;
8369 if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
Zhu Yie815de42006-03-02 05:55:51 +08008370 for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES; j++) {
8371 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8372 (geo->bg[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8373 continue;
8374
James Ketrenosb095c382005-08-24 22:04:42 -05008375 range->freq[i].i = geo->bg[j].channel;
8376 range->freq[i].m = geo->bg[j].freq * 100000;
8377 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008378 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008379 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008380 }
James Ketrenosb095c382005-08-24 22:04:42 -05008381
8382 if (priv->ieee->mode & IEEE_A) {
Zhu Yie815de42006-03-02 05:55:51 +08008383 for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES; j++) {
8384 if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
8385 (geo->a[j].flags & IEEE80211_CH_PASSIVE_ONLY))
8386 continue;
8387
James Ketrenosb095c382005-08-24 22:04:42 -05008388 range->freq[i].i = geo->a[j].channel;
8389 range->freq[i].m = geo->a[j].freq * 100000;
8390 range->freq[i].e = 1;
Zhu Yie815de42006-03-02 05:55:51 +08008391 i++;
James Ketrenosb095c382005-08-24 22:04:42 -05008392 }
8393 }
8394
8395 range->num_channels = i;
8396 range->num_frequency = i;
8397
Zhu Yi46441512006-01-24 16:37:59 +08008398 mutex_unlock(&priv->mutex);
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008399
8400 /* Event capability (kernel + driver) */
8401 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
8402 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
Zhu Yi07f02e42006-04-13 17:19:25 +08008403 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
8404 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00008405 range->event_capa[1] = IW_EVENT_CAPA_K_1;
James Ketrenos43f66a62005-03-25 12:31:53 -06008406
Dan Williamsf1b50862006-01-30 13:58:56 -05008407 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
8408 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
8409
James Ketrenos43f66a62005-03-25 12:31:53 -06008410 IPW_DEBUG_WX("GET Range\n");
8411 return 0;
8412}
8413
Jeff Garzikbf794512005-07-31 13:07:26 -04008414static int ipw_wx_set_wap(struct net_device *dev,
8415 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008416 union iwreq_data *wrqu, char *extra)
8417{
8418 struct ipw_priv *priv = ieee80211_priv(dev);
8419
8420 static const unsigned char any[] = {
8421 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
8422 };
8423 static const unsigned char off[] = {
8424 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
8425 };
8426
Jeff Garzikbf794512005-07-31 13:07:26 -04008427 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
James Ketrenos43f66a62005-03-25 12:31:53 -06008428 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08008429 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008430 if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
8431 !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8432 /* we disable mandatory BSSID association */
8433 IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
8434 priv->config &= ~CFG_STATIC_BSSID;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008435 IPW_DEBUG_ASSOC("Attempting to associate with new "
8436 "parameters.\n");
8437 ipw_associate(priv);
Zhu Yi46441512006-01-24 16:37:59 +08008438 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008439 return 0;
8440 }
8441
8442 priv->config |= CFG_STATIC_BSSID;
8443 if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
8444 IPW_DEBUG_WX("BSSID set to current BSSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008445 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008446 return 0;
8447 }
8448
8449 IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
8450 MAC_ARG(wrqu->ap_addr.sa_data));
8451
8452 memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
8453
James Ketrenosc848d0a2005-08-24 21:56:24 -05008454 /* Network configuration changed -- force [re]association */
8455 IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
8456 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008457 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008458
Zhu Yi46441512006-01-24 16:37:59 +08008459 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008460 return 0;
8461}
8462
Jeff Garzikbf794512005-07-31 13:07:26 -04008463static int ipw_wx_get_wap(struct net_device *dev,
8464 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008465 union iwreq_data *wrqu, char *extra)
8466{
8467 struct ipw_priv *priv = ieee80211_priv(dev);
8468 /* If we are associated, trying to associate, or have a statically
8469 * configured BSSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008470 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04008471 if (priv->config & CFG_STATIC_BSSID ||
James Ketrenos43f66a62005-03-25 12:31:53 -06008472 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8473 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008474 memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
James Ketrenos43f66a62005-03-25 12:31:53 -06008475 } else
8476 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
8477
8478 IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
8479 MAC_ARG(wrqu->ap_addr.sa_data));
Zhu Yi46441512006-01-24 16:37:59 +08008480 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008481 return 0;
8482}
8483
Jeff Garzikbf794512005-07-31 13:07:26 -04008484static int ipw_wx_set_essid(struct net_device *dev,
8485 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008486 union iwreq_data *wrqu, char *extra)
8487{
8488 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008489 char *essid = ""; /* ANY */
James Ketrenos43f66a62005-03-25 12:31:53 -06008490 int length = 0;
Zhu Yi46441512006-01-24 16:37:59 +08008491 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008492 if (wrqu->essid.flags && wrqu->essid.length) {
8493 length = wrqu->essid.length - 1;
8494 essid = extra;
8495 }
8496 if (length == 0) {
8497 IPW_DEBUG_WX("Setting ESSID to ANY\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008498 if ((priv->config & CFG_STATIC_ESSID) &&
8499 !(priv->status & (STATUS_ASSOCIATED |
James Ketrenos43f66a62005-03-25 12:31:53 -06008500 STATUS_ASSOCIATING))) {
8501 IPW_DEBUG_ASSOC("Attempting to associate with new "
8502 "parameters.\n");
James Ketrenosafbf30a2005-08-25 00:05:33 -05008503 priv->config &= ~CFG_STATIC_ESSID;
James Ketrenos43f66a62005-03-25 12:31:53 -06008504 ipw_associate(priv);
8505 }
Zhu Yi46441512006-01-24 16:37:59 +08008506 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008507 return 0;
8508 }
8509
8510 length = min(length, IW_ESSID_MAX_SIZE);
8511
8512 priv->config |= CFG_STATIC_ESSID;
8513
8514 if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
8515 IPW_DEBUG_WX("ESSID set to current ESSID.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008516 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008517 return 0;
8518 }
8519
8520 IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
8521 length);
8522
8523 priv->essid_len = length;
8524 memcpy(priv->essid, essid, priv->essid_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04008525
James Ketrenosc848d0a2005-08-24 21:56:24 -05008526 /* Network configuration changed -- force [re]association */
8527 IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
8528 if (!ipw_disassociate(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -06008529 ipw_associate(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06008530
Zhu Yi46441512006-01-24 16:37:59 +08008531 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008532 return 0;
8533}
8534
Jeff Garzikbf794512005-07-31 13:07:26 -04008535static int ipw_wx_get_essid(struct net_device *dev,
8536 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008537 union iwreq_data *wrqu, char *extra)
8538{
8539 struct ipw_priv *priv = ieee80211_priv(dev);
8540
8541 /* If we are associated, trying to associate, or have a statically
8542 * configured ESSID then return that; otherwise return ANY */
Zhu Yi46441512006-01-24 16:37:59 +08008543 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008544 if (priv->config & CFG_STATIC_ESSID ||
Jeff Garzikbf794512005-07-31 13:07:26 -04008545 priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
8546 IPW_DEBUG_WX("Getting essid: '%s'\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06008547 escape_essid(priv->essid, priv->essid_len));
Jeff Garzikbf794512005-07-31 13:07:26 -04008548 memcpy(extra, priv->essid, priv->essid_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06008549 wrqu->essid.length = priv->essid_len;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008550 wrqu->essid.flags = 1; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008551 } else {
8552 IPW_DEBUG_WX("Getting essid: ANY\n");
8553 wrqu->essid.length = 0;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008554 wrqu->essid.flags = 0; /* active */
James Ketrenos43f66a62005-03-25 12:31:53 -06008555 }
Zhu Yi46441512006-01-24 16:37:59 +08008556 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008557 return 0;
8558}
8559
Jeff Garzikbf794512005-07-31 13:07:26 -04008560static int ipw_wx_set_nick(struct net_device *dev,
8561 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008562 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008563{
James Ketrenos43f66a62005-03-25 12:31:53 -06008564 struct ipw_priv *priv = ieee80211_priv(dev);
8565
8566 IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
8567 if (wrqu->data.length > IW_ESSID_MAX_SIZE)
8568 return -E2BIG;
Zhu Yi46441512006-01-24 16:37:59 +08008569 mutex_lock(&priv->mutex);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008570 wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
James Ketrenos43f66a62005-03-25 12:31:53 -06008571 memset(priv->nick, 0, sizeof(priv->nick));
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008572 memcpy(priv->nick, extra, wrqu->data.length);
James Ketrenos43f66a62005-03-25 12:31:53 -06008573 IPW_DEBUG_TRACE("<<\n");
Zhu Yi46441512006-01-24 16:37:59 +08008574 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008575 return 0;
8576
8577}
8578
Jeff Garzikbf794512005-07-31 13:07:26 -04008579static int ipw_wx_get_nick(struct net_device *dev,
8580 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008581 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008582{
James Ketrenos43f66a62005-03-25 12:31:53 -06008583 struct ipw_priv *priv = ieee80211_priv(dev);
8584 IPW_DEBUG_WX("Getting nick\n");
Zhu Yi46441512006-01-24 16:37:59 +08008585 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008586 wrqu->data.length = strlen(priv->nick) + 1;
8587 memcpy(extra, priv->nick, wrqu->data.length);
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008588 wrqu->data.flags = 1; /* active */
Zhu Yi46441512006-01-24 16:37:59 +08008589 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008590 return 0;
8591}
8592
Olivier Hochreutiner651be262006-03-08 03:13:55 +08008593static int ipw_wx_set_sens(struct net_device *dev,
8594 struct iw_request_info *info,
8595 union iwreq_data *wrqu, char *extra)
8596{
8597 struct ipw_priv *priv = ieee80211_priv(dev);
8598 int err = 0;
8599
8600 IPW_DEBUG_WX("Setting roaming threshold to %d\n", wrqu->sens.value);
8601 IPW_DEBUG_WX("Setting disassociate threshold to %d\n", 3*wrqu->sens.value);
8602 mutex_lock(&priv->mutex);
8603
8604 if (wrqu->sens.fixed == 0)
8605 {
8606 priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
8607 priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
8608 goto out;
8609 }
8610 if ((wrqu->sens.value > IPW_MB_ROAMING_THRESHOLD_MAX) ||
8611 (wrqu->sens.value < IPW_MB_ROAMING_THRESHOLD_MIN)) {
8612 err = -EINVAL;
8613 goto out;
8614 }
8615
8616 priv->roaming_threshold = wrqu->sens.value;
8617 priv->disassociate_threshold = 3*wrqu->sens.value;
8618 out:
8619 mutex_unlock(&priv->mutex);
8620 return err;
8621}
8622
8623static int ipw_wx_get_sens(struct net_device *dev,
8624 struct iw_request_info *info,
8625 union iwreq_data *wrqu, char *extra)
8626{
8627 struct ipw_priv *priv = ieee80211_priv(dev);
8628 mutex_lock(&priv->mutex);
8629 wrqu->sens.fixed = 1;
8630 wrqu->sens.value = priv->roaming_threshold;
8631 mutex_unlock(&priv->mutex);
8632
8633 IPW_DEBUG_WX("GET roaming threshold -> %s %d \n",
8634 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
8635
8636 return 0;
8637}
8638
James Ketrenos43f66a62005-03-25 12:31:53 -06008639static int ipw_wx_set_rate(struct net_device *dev,
8640 struct iw_request_info *info,
8641 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008642{
James Ketrenosea2b26e2005-08-24 21:25:16 -05008643 /* TODO: We should use semaphores or locks for access to priv */
8644 struct ipw_priv *priv = ieee80211_priv(dev);
8645 u32 target_rate = wrqu->bitrate.value;
8646 u32 fixed, mask;
8647
8648 /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
8649 /* value = X, fixed = 1 means only rate X */
8650 /* value = X, fixed = 0 means all rates lower equal X */
8651
8652 if (target_rate == -1) {
8653 fixed = 0;
8654 mask = IEEE80211_DEFAULT_RATES_MASK;
8655 /* Now we should reassociate */
8656 goto apply;
8657 }
8658
8659 mask = 0;
8660 fixed = wrqu->bitrate.fixed;
8661
8662 if (target_rate == 1000000 || !fixed)
8663 mask |= IEEE80211_CCK_RATE_1MB_MASK;
8664 if (target_rate == 1000000)
8665 goto apply;
8666
8667 if (target_rate == 2000000 || !fixed)
8668 mask |= IEEE80211_CCK_RATE_2MB_MASK;
8669 if (target_rate == 2000000)
8670 goto apply;
8671
8672 if (target_rate == 5500000 || !fixed)
8673 mask |= IEEE80211_CCK_RATE_5MB_MASK;
8674 if (target_rate == 5500000)
8675 goto apply;
8676
8677 if (target_rate == 6000000 || !fixed)
8678 mask |= IEEE80211_OFDM_RATE_6MB_MASK;
8679 if (target_rate == 6000000)
8680 goto apply;
8681
8682 if (target_rate == 9000000 || !fixed)
8683 mask |= IEEE80211_OFDM_RATE_9MB_MASK;
8684 if (target_rate == 9000000)
8685 goto apply;
8686
8687 if (target_rate == 11000000 || !fixed)
8688 mask |= IEEE80211_CCK_RATE_11MB_MASK;
8689 if (target_rate == 11000000)
8690 goto apply;
8691
8692 if (target_rate == 12000000 || !fixed)
8693 mask |= IEEE80211_OFDM_RATE_12MB_MASK;
8694 if (target_rate == 12000000)
8695 goto apply;
8696
8697 if (target_rate == 18000000 || !fixed)
8698 mask |= IEEE80211_OFDM_RATE_18MB_MASK;
8699 if (target_rate == 18000000)
8700 goto apply;
8701
8702 if (target_rate == 24000000 || !fixed)
8703 mask |= IEEE80211_OFDM_RATE_24MB_MASK;
8704 if (target_rate == 24000000)
8705 goto apply;
8706
8707 if (target_rate == 36000000 || !fixed)
8708 mask |= IEEE80211_OFDM_RATE_36MB_MASK;
8709 if (target_rate == 36000000)
8710 goto apply;
8711
8712 if (target_rate == 48000000 || !fixed)
8713 mask |= IEEE80211_OFDM_RATE_48MB_MASK;
8714 if (target_rate == 48000000)
8715 goto apply;
8716
8717 if (target_rate == 54000000 || !fixed)
8718 mask |= IEEE80211_OFDM_RATE_54MB_MASK;
8719 if (target_rate == 54000000)
8720 goto apply;
8721
8722 IPW_DEBUG_WX("invalid rate specified, returning error\n");
8723 return -EINVAL;
8724
8725 apply:
8726 IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
8727 mask, fixed ? "fixed" : "sub-rates");
Zhu Yi46441512006-01-24 16:37:59 +08008728 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05008729 if (mask == IEEE80211_DEFAULT_RATES_MASK) {
James Ketrenosea2b26e2005-08-24 21:25:16 -05008730 priv->config &= ~CFG_FIXED_RATE;
James Ketrenosb095c382005-08-24 22:04:42 -05008731 ipw_set_fixed_rate(priv, priv->ieee->mode);
8732 } else
James Ketrenosea2b26e2005-08-24 21:25:16 -05008733 priv->config |= CFG_FIXED_RATE;
8734
James Ketrenosc848d0a2005-08-24 21:56:24 -05008735 if (priv->rates_mask == mask) {
8736 IPW_DEBUG_WX("Mask set to current mask.\n");
Zhu Yi46441512006-01-24 16:37:59 +08008737 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008738 return 0;
James Ketrenosea2b26e2005-08-24 21:25:16 -05008739 }
8740
James Ketrenosc848d0a2005-08-24 21:56:24 -05008741 priv->rates_mask = mask;
8742
8743 /* Network configuration changed -- force [re]association */
8744 IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
8745 if (!ipw_disassociate(priv))
8746 ipw_associate(priv);
8747
Zhu Yi46441512006-01-24 16:37:59 +08008748 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05008749 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008750}
8751
Jeff Garzikbf794512005-07-31 13:07:26 -04008752static int ipw_wx_get_rate(struct net_device *dev,
8753 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008754 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008755{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008756 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008757 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008758 wrqu->bitrate.value = priv->last_rate;
Zhu Yi46441512006-01-24 16:37:59 +08008759 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008760 IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
8761 return 0;
8762}
8763
Jeff Garzikbf794512005-07-31 13:07:26 -04008764static int ipw_wx_set_rts(struct net_device *dev,
8765 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008766 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008767{
James Ketrenos43f66a62005-03-25 12:31:53 -06008768 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008769 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008770 if (wrqu->rts.disabled)
8771 priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
8772 else {
8773 if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
James Ketrenosc848d0a2005-08-24 21:56:24 -05008774 wrqu->rts.value > MAX_RTS_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08008775 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008776 return -EINVAL;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008777 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008778 priv->rts_threshold = wrqu->rts.value;
8779 }
8780
8781 ipw_send_rts_threshold(priv, priv->rts_threshold);
Zhu Yi46441512006-01-24 16:37:59 +08008782 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008783 IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
8784 return 0;
8785}
8786
Jeff Garzikbf794512005-07-31 13:07:26 -04008787static int ipw_wx_get_rts(struct net_device *dev,
8788 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008789 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008790{
James Ketrenos43f66a62005-03-25 12:31:53 -06008791 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008792 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008793 wrqu->rts.value = priv->rts_threshold;
8794 wrqu->rts.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008795 wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
Zhu Yi46441512006-01-24 16:37:59 +08008796 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008797 IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
8798 return 0;
8799}
8800
Jeff Garzikbf794512005-07-31 13:07:26 -04008801static int ipw_wx_set_txpow(struct net_device *dev,
8802 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008803 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008804{
James Ketrenos43f66a62005-03-25 12:31:53 -06008805 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008806 int err = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008807
Zhu Yi46441512006-01-24 16:37:59 +08008808 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -05008809 if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008810 err = -EINPROGRESS;
8811 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008812 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008813
James Ketrenosb095c382005-08-24 22:04:42 -05008814 if (!wrqu->power.fixed)
8815 wrqu->power.value = IPW_TX_POWER_DEFAULT;
James Ketrenos43f66a62005-03-25 12:31:53 -06008816
James Ketrenosc848d0a2005-08-24 21:56:24 -05008817 if (wrqu->power.flags != IW_TXPOW_DBM) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008818 err = -EINVAL;
8819 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008820 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008821
James Ketrenosb095c382005-08-24 22:04:42 -05008822 if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
James Ketrenosafbf30a2005-08-25 00:05:33 -05008823 (wrqu->power.value < IPW_TX_POWER_MIN)) {
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008824 err = -EINVAL;
8825 goto out;
James Ketrenosc848d0a2005-08-24 21:56:24 -05008826 }
James Ketrenos43f66a62005-03-25 12:31:53 -06008827
8828 priv->tx_power = wrqu->power.value;
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008829 err = ipw_set_tx_power(priv);
8830 out:
Zhu Yi46441512006-01-24 16:37:59 +08008831 mutex_unlock(&priv->mutex);
Zhu Yi6de9f7f2005-08-11 14:39:33 +08008832 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06008833}
8834
Jeff Garzikbf794512005-07-31 13:07:26 -04008835static int ipw_wx_get_txpow(struct net_device *dev,
8836 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008837 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008838{
James Ketrenos43f66a62005-03-25 12:31:53 -06008839 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008840 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008841 wrqu->power.value = priv->tx_power;
8842 wrqu->power.fixed = 1;
8843 wrqu->power.flags = IW_TXPOW_DBM;
8844 wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
Zhu Yi46441512006-01-24 16:37:59 +08008845 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008846
Jeff Garzikbf794512005-07-31 13:07:26 -04008847 IPW_DEBUG_WX("GET TX Power -> %s %d \n",
Zhu Yi22501c82005-08-11 10:49:17 +08008848 wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
James Ketrenos43f66a62005-03-25 12:31:53 -06008849
8850 return 0;
8851}
8852
Jeff Garzikbf794512005-07-31 13:07:26 -04008853static int ipw_wx_set_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008854 struct iw_request_info *info,
8855 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008856{
8857 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008858 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008859 if (wrqu->frag.disabled)
8860 priv->ieee->fts = DEFAULT_FTS;
8861 else {
8862 if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
James Ketrenosb095c382005-08-24 22:04:42 -05008863 wrqu->frag.value > MAX_FRAG_THRESHOLD) {
Zhu Yi46441512006-01-24 16:37:59 +08008864 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008865 return -EINVAL;
James Ketrenosb095c382005-08-24 22:04:42 -05008866 }
Jeff Garzikbf794512005-07-31 13:07:26 -04008867
James Ketrenos43f66a62005-03-25 12:31:53 -06008868 priv->ieee->fts = wrqu->frag.value & ~0x1;
8869 }
8870
8871 ipw_send_frag_threshold(priv, wrqu->frag.value);
Zhu Yi46441512006-01-24 16:37:59 +08008872 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008873 IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
8874 return 0;
8875}
8876
Jeff Garzikbf794512005-07-31 13:07:26 -04008877static int ipw_wx_get_frag(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008878 struct iw_request_info *info,
8879 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06008880{
8881 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08008882 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008883 wrqu->frag.value = priv->ieee->fts;
8884 wrqu->frag.fixed = 0; /* no auto select */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04008885 wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
Zhu Yi46441512006-01-24 16:37:59 +08008886 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06008887 IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
8888
8889 return 0;
8890}
8891
Jeff Garzikbf794512005-07-31 13:07:26 -04008892static int ipw_wx_set_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
8898 if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
8899 return -EINVAL;
8900
8901 if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
8902 return 0;
8903
8904 if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
8905 return -EINVAL;
8906
Zhu Yi46441512006-01-24 16:37:59 +08008907 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008908 if (wrqu->retry.flags & IW_RETRY_MIN)
8909 priv->short_retry_limit = (u8) wrqu->retry.value;
8910 else if (wrqu->retry.flags & IW_RETRY_MAX)
8911 priv->long_retry_limit = (u8) wrqu->retry.value;
8912 else {
8913 priv->short_retry_limit = (u8) wrqu->retry.value;
8914 priv->long_retry_limit = (u8) wrqu->retry.value;
8915 }
8916
8917 ipw_send_retry_limit(priv, priv->short_retry_limit,
8918 priv->long_retry_limit);
Zhu Yi46441512006-01-24 16:37:59 +08008919 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008920 IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
8921 priv->short_retry_limit, priv->long_retry_limit);
8922 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008923}
8924
Jeff Garzikbf794512005-07-31 13:07:26 -04008925static int ipw_wx_get_retry(struct net_device *dev,
8926 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06008927 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04008928{
James Ketrenosafbf30a2005-08-25 00:05:33 -05008929 struct ipw_priv *priv = ieee80211_priv(dev);
8930
Zhu Yi46441512006-01-24 16:37:59 +08008931 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008932 wrqu->retry.disabled = 0;
8933
8934 if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
Zhu Yi46441512006-01-24 16:37:59 +08008935 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008936 return -EINVAL;
8937 }
8938
8939 if (wrqu->retry.flags & IW_RETRY_MAX) {
8940 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
8941 wrqu->retry.value = priv->long_retry_limit;
8942 } else if (wrqu->retry.flags & IW_RETRY_MIN) {
8943 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
8944 wrqu->retry.value = priv->short_retry_limit;
8945 } else {
8946 wrqu->retry.flags = IW_RETRY_LIMIT;
8947 wrqu->retry.value = priv->short_retry_limit;
8948 }
Zhu Yi46441512006-01-24 16:37:59 +08008949 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008950
8951 IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
8952
8953 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06008954}
8955
James Ketrenosafbf30a2005-08-25 00:05:33 -05008956static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
8957 int essid_len)
8958{
8959 struct ipw_scan_request_ext scan;
8960 int err = 0, scan_type;
8961
Pekka Enbergefb34422005-11-16 21:55:05 +02008962 if (!(priv->status & STATUS_INIT) ||
8963 (priv->status & STATUS_EXIT_PENDING))
8964 return 0;
8965
Zhu Yi46441512006-01-24 16:37:59 +08008966 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008967
8968 if (priv->status & STATUS_RF_KILL_MASK) {
8969 IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
8970 priv->status |= STATUS_SCAN_PENDING;
8971 goto done;
8972 }
8973
8974 IPW_DEBUG_HC("starting request direct scan!\n");
8975
8976 if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
Olaf Kirchd834a412006-01-09 17:00:37 +01008977 /* We should not sleep here; otherwise we will block most
8978 * of the system (for instance, we hold rtnl_lock when we
8979 * get here).
8980 */
8981 err = -EAGAIN;
8982 goto done;
James Ketrenosafbf30a2005-08-25 00:05:33 -05008983 }
8984 memset(&scan, 0, sizeof(scan));
8985
8986 if (priv->config & CFG_SPEED_SCAN)
8987 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
8988 cpu_to_le16(30);
8989 else
8990 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
8991 cpu_to_le16(20);
8992
8993 scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
8994 cpu_to_le16(20);
Liu Hong1fe0adb2005-08-19 09:33:10 -05008995 scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(120);
James Ketrenosafbf30a2005-08-25 00:05:33 -05008996 scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
8997
8998 scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
8999
9000 err = ipw_send_ssid(priv, essid, essid_len);
9001 if (err) {
9002 IPW_DEBUG_HC("Attempt to send SSID command failed\n");
9003 goto done;
9004 }
9005 scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
9006
9007 ipw_add_scan_channels(priv, &scan, scan_type);
9008
9009 err = ipw_send_scan_request_ext(priv, &scan);
9010 if (err) {
9011 IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
9012 goto done;
9013 }
9014
9015 priv->status |= STATUS_SCANNING;
9016
9017 done:
Zhu Yi46441512006-01-24 16:37:59 +08009018 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009019 return err;
James Ketrenos43f66a62005-03-25 12:31:53 -06009020}
9021
Jeff Garzikbf794512005-07-31 13:07:26 -04009022static int ipw_wx_set_scan(struct net_device *dev,
9023 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009024 union iwreq_data *wrqu, char *extra)
9025{
9026 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009027 struct iw_scan_req *req = NULL;
9028 if (wrqu->data.length
9029 && wrqu->data.length == sizeof(struct iw_scan_req)) {
9030 req = (struct iw_scan_req *)extra;
9031 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
9032 ipw_request_direct_scan(priv, req->essid,
9033 req->essid_len);
9034 return 0;
9035 }
9036 }
James Ketrenos8935f392005-10-05 15:59:08 -05009037
James Ketrenos43f66a62005-03-25 12:31:53 -06009038 IPW_DEBUG_WX("Start scan\n");
James Ketrenosb095c382005-08-24 22:04:42 -05009039
9040 queue_work(priv->workqueue, &priv->request_scan);
9041
James Ketrenos43f66a62005-03-25 12:31:53 -06009042 return 0;
9043}
9044
Jeff Garzikbf794512005-07-31 13:07:26 -04009045static int ipw_wx_get_scan(struct net_device *dev,
9046 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009047 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009048{
James Ketrenos43f66a62005-03-25 12:31:53 -06009049 struct ipw_priv *priv = ieee80211_priv(dev);
9050 return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
9051}
9052
Jeff Garzikbf794512005-07-31 13:07:26 -04009053static int ipw_wx_set_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009054 struct iw_request_info *info,
9055 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009056{
9057 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009058 int ret;
Hong Liucaeff812005-08-05 17:25:50 +08009059 u32 cap = priv->capability;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009060
Zhu Yi46441512006-01-24 16:37:59 +08009061 mutex_lock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009062 ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009063
Hong Liucaeff812005-08-05 17:25:50 +08009064 /* In IBSS mode, we need to notify the firmware to update
9065 * the beacon info after we changed the capability. */
9066 if (cap != priv->capability &&
9067 priv->ieee->iw_mode == IW_MODE_ADHOC &&
9068 priv->status & STATUS_ASSOCIATED)
9069 ipw_disassociate(priv);
9070
Zhu Yi46441512006-01-24 16:37:59 +08009071 mutex_unlock(&priv->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009072 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009073}
9074
Jeff Garzikbf794512005-07-31 13:07:26 -04009075static int ipw_wx_get_encode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009076 struct iw_request_info *info,
9077 union iwreq_data *wrqu, char *key)
James Ketrenos43f66a62005-03-25 12:31:53 -06009078{
9079 struct ipw_priv *priv = ieee80211_priv(dev);
9080 return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
9081}
9082
Jeff Garzikbf794512005-07-31 13:07:26 -04009083static int ipw_wx_set_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009084 struct iw_request_info *info,
9085 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009086{
9087 struct ipw_priv *priv = ieee80211_priv(dev);
9088 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009089 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009090 if (wrqu->power.disabled) {
9091 priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
9092 err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
9093 if (err) {
9094 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009095 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009096 return err;
9097 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009098 IPW_DEBUG_WX("SET Power Management Mode -> off\n");
Zhu Yi46441512006-01-24 16:37:59 +08009099 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009100 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009101 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009102
9103 switch (wrqu->power.flags & IW_POWER_MODE) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009104 case IW_POWER_ON: /* If not specified */
9105 case IW_POWER_MODE: /* If set all mask */
9106 case IW_POWER_ALL_R: /* If explicitely state all */
James Ketrenos43f66a62005-03-25 12:31:53 -06009107 break;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009108 default: /* Otherwise we don't support it */
James Ketrenos43f66a62005-03-25 12:31:53 -06009109 IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
9110 wrqu->power.flags);
Zhu Yi46441512006-01-24 16:37:59 +08009111 mutex_unlock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009112 return -EOPNOTSUPP;
James Ketrenos43f66a62005-03-25 12:31:53 -06009113 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009114
James Ketrenos43f66a62005-03-25 12:31:53 -06009115 /* If the user hasn't specified a power management mode yet, default
9116 * to BATTERY */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009117 if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
James Ketrenos43f66a62005-03-25 12:31:53 -06009118 priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
Jeff Garzikbf794512005-07-31 13:07:26 -04009119 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009120 priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
9121 err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
9122 if (err) {
9123 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009124 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009125 return err;
9126 }
9127
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009128 IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
Zhu Yi46441512006-01-24 16:37:59 +08009129 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009130 return 0;
9131}
9132
Jeff Garzikbf794512005-07-31 13:07:26 -04009133static int ipw_wx_get_power(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009134 struct iw_request_info *info,
9135 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009136{
9137 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009138 mutex_lock(&priv->mutex);
James Ketrenosa613bff2005-08-24 21:43:11 -05009139 if (!(priv->power_mode & IPW_POWER_ENABLED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009140 wrqu->power.disabled = 1;
James Ketrenosa613bff2005-08-24 21:43:11 -05009141 else
James Ketrenos43f66a62005-03-25 12:31:53 -06009142 wrqu->power.disabled = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009143
Zhu Yi46441512006-01-24 16:37:59 +08009144 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009145 IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009146
James Ketrenos43f66a62005-03-25 12:31:53 -06009147 return 0;
9148}
9149
Jeff Garzikbf794512005-07-31 13:07:26 -04009150static int ipw_wx_set_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009151 struct iw_request_info *info,
9152 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009153{
9154 struct ipw_priv *priv = ieee80211_priv(dev);
9155 int mode = *(int *)extra;
9156 int err;
Zhu Yi46441512006-01-24 16:37:59 +08009157 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009158 if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
9159 mode = IPW_POWER_AC;
9160 priv->power_mode = mode;
9161 } else {
9162 priv->power_mode = IPW_POWER_ENABLED | mode;
9163 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009164
James Ketrenos43f66a62005-03-25 12:31:53 -06009165 if (priv->power_mode != mode) {
9166 err = ipw_send_power_mode(priv, mode);
Jeff Garzikbf794512005-07-31 13:07:26 -04009167
James Ketrenos43f66a62005-03-25 12:31:53 -06009168 if (err) {
9169 IPW_DEBUG_WX("failed setting power mode.\n");
Zhu Yi46441512006-01-24 16:37:59 +08009170 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009171 return err;
9172 }
9173 }
Zhu Yi46441512006-01-24 16:37:59 +08009174 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009175 return 0;
9176}
9177
9178#define MAX_WX_STRING 80
Jeff Garzikbf794512005-07-31 13:07:26 -04009179static int ipw_wx_get_powermode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009180 struct iw_request_info *info,
9181 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009182{
9183 struct ipw_priv *priv = ieee80211_priv(dev);
9184 int level = IPW_POWER_LEVEL(priv->power_mode);
9185 char *p = extra;
9186
9187 p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
9188
9189 switch (level) {
9190 case IPW_POWER_AC:
9191 p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
9192 break;
9193 case IPW_POWER_BATTERY:
9194 p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
9195 break;
9196 default:
9197 p += snprintf(p, MAX_WX_STRING - (p - extra),
Jeff Garzikbf794512005-07-31 13:07:26 -04009198 "(Timeout %dms, Period %dms)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009199 timeout_duration[level - 1] / 1000,
9200 period_duration[level - 1] / 1000);
9201 }
9202
9203 if (!(priv->power_mode & IPW_POWER_ENABLED))
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009204 p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
James Ketrenos43f66a62005-03-25 12:31:53 -06009205
9206 wrqu->data.length = p - extra + 1;
9207
9208 return 0;
9209}
9210
9211static int ipw_wx_set_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009212 struct iw_request_info *info,
9213 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009214{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009215 struct ipw_priv *priv = ieee80211_priv(dev);
James Ketrenos43f66a62005-03-25 12:31:53 -06009216 int mode = *(int *)extra;
9217 u8 band = 0, modulation = 0;
9218
9219 if (mode == 0 || mode & ~IEEE_MODE_MASK) {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009220 IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
James Ketrenos43f66a62005-03-25 12:31:53 -06009221 return -EINVAL;
9222 }
Zhu Yi46441512006-01-24 16:37:59 +08009223 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009224 if (priv->adapter == IPW_2915ABG) {
James Ketrenosa33a1982005-09-14 14:28:59 -05009225 priv->ieee->abg_true = 1;
James Ketrenos43f66a62005-03-25 12:31:53 -06009226 if (mode & IEEE_A) {
9227 band |= IEEE80211_52GHZ_BAND;
9228 modulation |= IEEE80211_OFDM_MODULATION;
9229 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009230 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009231 } else {
9232 if (mode & IEEE_A) {
9233 IPW_WARNING("Attempt to set 2200BG into "
9234 "802.11a mode\n");
Zhu Yi46441512006-01-24 16:37:59 +08009235 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009236 return -EINVAL;
9237 }
9238
James Ketrenosa33a1982005-09-14 14:28:59 -05009239 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009240 }
9241
9242 if (mode & IEEE_B) {
9243 band |= IEEE80211_24GHZ_BAND;
9244 modulation |= IEEE80211_CCK_MODULATION;
9245 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009246 priv->ieee->abg_true = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009247
James Ketrenos43f66a62005-03-25 12:31:53 -06009248 if (mode & IEEE_G) {
9249 band |= IEEE80211_24GHZ_BAND;
9250 modulation |= IEEE80211_OFDM_MODULATION;
9251 } else
James Ketrenosa33a1982005-09-14 14:28:59 -05009252 priv->ieee->abg_true = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009253
9254 priv->ieee->mode = mode;
9255 priv->ieee->freq_band = band;
9256 priv->ieee->modulation = modulation;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009257 init_supported_rates(priv, &priv->rates);
James Ketrenos43f66a62005-03-25 12:31:53 -06009258
James Ketrenosc848d0a2005-08-24 21:56:24 -05009259 /* Network configuration changed -- force [re]association */
9260 IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
9261 if (!ipw_disassociate(priv)) {
James Ketrenos43f66a62005-03-25 12:31:53 -06009262 ipw_send_supported_rates(priv, &priv->rates);
James Ketrenosc848d0a2005-08-24 21:56:24 -05009263 ipw_associate(priv);
9264 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009265
James Ketrenosa613bff2005-08-24 21:43:11 -05009266 /* Update the band LEDs */
9267 ipw_led_band_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009268
Jeff Garzikbf794512005-07-31 13:07:26 -04009269 IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009270 mode & IEEE_A ? 'a' : '.',
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009271 mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
Zhu Yi46441512006-01-24 16:37:59 +08009272 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009273 return 0;
9274}
9275
9276static int ipw_wx_get_wireless_mode(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009277 struct iw_request_info *info,
9278 union iwreq_data *wrqu, char *extra)
James Ketrenos43f66a62005-03-25 12:31:53 -06009279{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009280 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009281 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009282 switch (priv->ieee->mode) {
9283 case IEEE_A:
James Ketrenos43f66a62005-03-25 12:31:53 -06009284 strncpy(extra, "802.11a (1)", MAX_WX_STRING);
9285 break;
James Ketrenosea2b26e2005-08-24 21:25:16 -05009286 case IEEE_B:
9287 strncpy(extra, "802.11b (2)", MAX_WX_STRING);
9288 break;
9289 case IEEE_A | IEEE_B:
9290 strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
9291 break;
9292 case IEEE_G:
9293 strncpy(extra, "802.11g (4)", MAX_WX_STRING);
9294 break;
9295 case IEEE_A | IEEE_G:
9296 strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
9297 break;
9298 case IEEE_B | IEEE_G:
9299 strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
9300 break;
9301 case IEEE_A | IEEE_B | IEEE_G:
9302 strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
9303 break;
9304 default:
9305 strncpy(extra, "unknown", MAX_WX_STRING);
James Ketrenos43f66a62005-03-25 12:31:53 -06009306 break;
Jeff Garzikbf794512005-07-31 13:07:26 -04009307 }
9308
James Ketrenos43f66a62005-03-25 12:31:53 -06009309 IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
9310
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009311 wrqu->data.length = strlen(extra) + 1;
Zhu Yi46441512006-01-24 16:37:59 +08009312 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009313
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009314 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009315}
9316
James Ketrenosea2b26e2005-08-24 21:25:16 -05009317static int ipw_wx_set_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);
9322 int mode = *(int *)extra;
Zhu Yi46441512006-01-24 16:37:59 +08009323 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009324 /* Switching from SHORT -> LONG requires a disassociation */
9325 if (mode == 1) {
9326 if (!(priv->config & CFG_PREAMBLE_LONG)) {
9327 priv->config |= CFG_PREAMBLE_LONG;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009328
9329 /* Network configuration changed -- force [re]association */
9330 IPW_DEBUG_ASSOC
9331 ("[re]association triggered due to preamble change.\n");
9332 if (!ipw_disassociate(priv))
9333 ipw_associate(priv);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009334 }
9335 goto done;
9336 }
9337
9338 if (mode == 0) {
9339 priv->config &= ~CFG_PREAMBLE_LONG;
9340 goto done;
9341 }
Zhu Yi46441512006-01-24 16:37:59 +08009342 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009343 return -EINVAL;
9344
9345 done:
Zhu Yi46441512006-01-24 16:37:59 +08009346 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009347 return 0;
9348}
9349
9350static int ipw_wx_get_preamble(struct net_device *dev,
9351 struct iw_request_info *info,
9352 union iwreq_data *wrqu, char *extra)
9353{
9354 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009355 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009356 if (priv->config & CFG_PREAMBLE_LONG)
9357 snprintf(wrqu->name, IFNAMSIZ, "long (1)");
9358 else
9359 snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
Zhu Yi46441512006-01-24 16:37:59 +08009360 mutex_unlock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009361 return 0;
9362}
9363
James Ketrenosb095c382005-08-24 22:04:42 -05009364#ifdef CONFIG_IPW2200_MONITOR
James Ketrenosea2b26e2005-08-24 21:25:16 -05009365static int ipw_wx_set_monitor(struct net_device *dev,
Jeff Garzikbf794512005-07-31 13:07:26 -04009366 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009367 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009368{
James Ketrenos43f66a62005-03-25 12:31:53 -06009369 struct ipw_priv *priv = ieee80211_priv(dev);
9370 int *parms = (int *)extra;
9371 int enable = (parms[0] > 0);
Zhu Yi46441512006-01-24 16:37:59 +08009372 mutex_lock(&priv->mutex);
James Ketrenosea2b26e2005-08-24 21:25:16 -05009373 IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
James Ketrenos43f66a62005-03-25 12:31:53 -06009374 if (enable) {
9375 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Mike Kershaw24a47db2005-08-26 00:41:54 -05009376#ifdef CONFIG_IEEE80211_RADIOTAP
9377 priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
9378#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009379 priv->net_dev->type = ARPHRD_IEEE80211;
Mike Kershaw24a47db2005-08-26 00:41:54 -05009380#endif
James Ketrenosa613bff2005-08-24 21:43:11 -05009381 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009382 }
Jeff Garzikbf794512005-07-31 13:07:26 -04009383
James Ketrenos43f66a62005-03-25 12:31:53 -06009384 ipw_set_channel(priv, parms[1]);
9385 } else {
James Ketrenosc848d0a2005-08-24 21:56:24 -05009386 if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
Zhu Yi46441512006-01-24 16:37:59 +08009387 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009388 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009389 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009390 priv->net_dev->type = ARPHRD_ETHER;
James Ketrenosa613bff2005-08-24 21:43:11 -05009391 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009392 }
Zhu Yi46441512006-01-24 16:37:59 +08009393 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009394 return 0;
9395}
9396
James Ketrenosb095c382005-08-24 22:04:42 -05009397#endif // CONFIG_IPW2200_MONITOR
9398
Jeff Garzikbf794512005-07-31 13:07:26 -04009399static int ipw_wx_reset(struct net_device *dev,
9400 struct iw_request_info *info,
James Ketrenos43f66a62005-03-25 12:31:53 -06009401 union iwreq_data *wrqu, char *extra)
Jeff Garzikbf794512005-07-31 13:07:26 -04009402{
James Ketrenos43f66a62005-03-25 12:31:53 -06009403 struct ipw_priv *priv = ieee80211_priv(dev);
9404 IPW_DEBUG_WX("RESET\n");
James Ketrenosa613bff2005-08-24 21:43:11 -05009405 queue_work(priv->workqueue, &priv->adapter_restart);
James Ketrenos43f66a62005-03-25 12:31:53 -06009406 return 0;
9407}
James Ketrenosb095c382005-08-24 22:04:42 -05009408
James Ketrenosb095c382005-08-24 22:04:42 -05009409static int ipw_wx_sw_reset(struct net_device *dev,
9410 struct iw_request_info *info,
9411 union iwreq_data *wrqu, char *extra)
9412{
9413 struct ipw_priv *priv = ieee80211_priv(dev);
9414 union iwreq_data wrqu_sec = {
9415 .encoding = {
9416 .flags = IW_ENCODE_DISABLED,
9417 },
9418 };
James Ketrenosafbf30a2005-08-25 00:05:33 -05009419 int ret;
James Ketrenosb095c382005-08-24 22:04:42 -05009420
9421 IPW_DEBUG_WX("SW_RESET\n");
9422
Zhu Yi46441512006-01-24 16:37:59 +08009423 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009424
Zhu Yid6d5b5c2006-02-16 16:21:09 +08009425 ret = ipw_sw_reset(priv, 2);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009426 if (!ret) {
9427 free_firmware();
9428 ipw_adapter_restart(priv);
9429 }
James Ketrenosb095c382005-08-24 22:04:42 -05009430
9431 /* The SW reset bit might have been toggled on by the 'disable'
9432 * module parameter, so take appropriate action */
9433 ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
9434
Zhu Yi46441512006-01-24 16:37:59 +08009435 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009436 ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
Zhu Yi46441512006-01-24 16:37:59 +08009437 mutex_lock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009438
9439 if (!(priv->status & STATUS_RF_KILL_MASK)) {
9440 /* Configuration likely changed -- force [re]association */
9441 IPW_DEBUG_ASSOC("[re]association triggered due to sw "
9442 "reset.\n");
9443 if (!ipw_disassociate(priv))
9444 ipw_associate(priv);
9445 }
9446
Zhu Yi46441512006-01-24 16:37:59 +08009447 mutex_unlock(&priv->mutex);
James Ketrenosb095c382005-08-24 22:04:42 -05009448
9449 return 0;
9450}
James Ketrenos43f66a62005-03-25 12:31:53 -06009451
9452/* Rebase the WE IOCTLs to zero for the handler array */
9453#define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009454static iw_handler ipw_wx_handlers[] = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009455 IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
9456 IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
9457 IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
9458 IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
9459 IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
Olivier Hochreutiner651be262006-03-08 03:13:55 +08009460 IW_IOCTL(SIOCSIWSENS) = ipw_wx_set_sens,
9461 IW_IOCTL(SIOCGIWSENS) = ipw_wx_get_sens,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009462 IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
9463 IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
9464 IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
9465 IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
9466 IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
9467 IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
9468 IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
9469 IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
9470 IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
9471 IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
9472 IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
9473 IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
9474 IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
9475 IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
9476 IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
9477 IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
9478 IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
9479 IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
9480 IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
9481 IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
9482 IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
9483 IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
9484 IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
James Ketrenosa613bff2005-08-24 21:43:11 -05009485 IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
9486 IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
9487 IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
9488 IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
James Ketrenosafbf30a2005-08-25 00:05:33 -05009489 IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
9490 IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
9491 IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
9492 IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
9493 IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
9494 IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
9495 IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
James Ketrenos43f66a62005-03-25 12:31:53 -06009496};
9497
James Ketrenosb095c382005-08-24 22:04:42 -05009498enum {
9499 IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
9500 IPW_PRIV_GET_POWER,
9501 IPW_PRIV_SET_MODE,
9502 IPW_PRIV_GET_MODE,
9503 IPW_PRIV_SET_PREAMBLE,
9504 IPW_PRIV_GET_PREAMBLE,
9505 IPW_PRIV_RESET,
9506 IPW_PRIV_SW_RESET,
9507#ifdef CONFIG_IPW2200_MONITOR
9508 IPW_PRIV_SET_MONITOR,
9509#endif
9510};
James Ketrenos43f66a62005-03-25 12:31:53 -06009511
Jeff Garzikbf794512005-07-31 13:07:26 -04009512static struct iw_priv_args ipw_priv_args[] = {
James Ketrenos43f66a62005-03-25 12:31:53 -06009513 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009514 .cmd = IPW_PRIV_SET_POWER,
9515 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9516 .name = "set_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009517 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009518 .cmd = IPW_PRIV_GET_POWER,
9519 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9520 .name = "get_power"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009521 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009522 .cmd = IPW_PRIV_SET_MODE,
9523 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9524 .name = "set_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009525 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009526 .cmd = IPW_PRIV_GET_MODE,
9527 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
9528 .name = "get_mode"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009529 {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009530 .cmd = IPW_PRIV_SET_PREAMBLE,
9531 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
9532 .name = "set_preamble"},
9533 {
9534 .cmd = IPW_PRIV_GET_PREAMBLE,
9535 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
9536 .name = "get_preamble"},
James Ketrenos43f66a62005-03-25 12:31:53 -06009537 {
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009538 IPW_PRIV_RESET,
9539 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
James Ketrenosb095c382005-08-24 22:04:42 -05009540 {
9541 IPW_PRIV_SW_RESET,
9542 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
9543#ifdef CONFIG_IPW2200_MONITOR
9544 {
9545 IPW_PRIV_SET_MONITOR,
9546 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
9547#endif /* CONFIG_IPW2200_MONITOR */
James Ketrenos43f66a62005-03-25 12:31:53 -06009548};
9549
9550static iw_handler ipw_priv_handler[] = {
9551 ipw_wx_set_powermode,
9552 ipw_wx_get_powermode,
9553 ipw_wx_set_wireless_mode,
9554 ipw_wx_get_wireless_mode,
James Ketrenosea2b26e2005-08-24 21:25:16 -05009555 ipw_wx_set_preamble,
9556 ipw_wx_get_preamble,
Jeff Garzikbf794512005-07-31 13:07:26 -04009557 ipw_wx_reset,
James Ketrenosb095c382005-08-24 22:04:42 -05009558 ipw_wx_sw_reset,
9559#ifdef CONFIG_IPW2200_MONITOR
9560 ipw_wx_set_monitor,
James Ketrenos43f66a62005-03-25 12:31:53 -06009561#endif
9562};
9563
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009564static struct iw_handler_def ipw_wx_handler_def = {
James Ketrenosea2b26e2005-08-24 21:25:16 -05009565 .standard = ipw_wx_handlers,
9566 .num_standard = ARRAY_SIZE(ipw_wx_handlers),
9567 .num_private = ARRAY_SIZE(ipw_priv_handler),
9568 .num_private_args = ARRAY_SIZE(ipw_priv_args),
9569 .private = ipw_priv_handler,
9570 .private_args = ipw_priv_args,
Benoit Boissinot97a78ca2005-09-15 17:30:28 +00009571 .get_wireless_stats = ipw_get_wireless_stats,
James Ketrenos43f66a62005-03-25 12:31:53 -06009572};
9573
James Ketrenos43f66a62005-03-25 12:31:53 -06009574/*
9575 * Get wireless statistics.
9576 * Called by /proc/net/wireless
9577 * Also called by SIOCGIWSTATS
9578 */
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009579static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
James Ketrenos43f66a62005-03-25 12:31:53 -06009580{
9581 struct ipw_priv *priv = ieee80211_priv(dev);
9582 struct iw_statistics *wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009583
James Ketrenos43f66a62005-03-25 12:31:53 -06009584 wstats = &priv->wstats;
9585
James Ketrenosea2b26e2005-08-24 21:25:16 -05009586 /* if hw is disabled, then ipw_get_ordinal() can't be called.
James Ketrenosafbf30a2005-08-25 00:05:33 -05009587 * netdev->get_wireless_stats seems to be called before fw is
James Ketrenos43f66a62005-03-25 12:31:53 -06009588 * initialized. STATUS_ASSOCIATED will only be set if the hw is up
9589 * and associated; if not associcated, the values are all meaningless
9590 * anyway, so set them all to NULL and INVALID */
9591 if (!(priv->status & STATUS_ASSOCIATED)) {
9592 wstats->miss.beacon = 0;
9593 wstats->discard.retries = 0;
9594 wstats->qual.qual = 0;
9595 wstats->qual.level = 0;
9596 wstats->qual.noise = 0;
9597 wstats->qual.updated = 7;
9598 wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009599 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
James Ketrenos43f66a62005-03-25 12:31:53 -06009600 return wstats;
Jeff Garzikbf794512005-07-31 13:07:26 -04009601 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009602
9603 wstats->qual.qual = priv->quality;
Zhu Yi00d21de2006-04-13 17:19:02 +08009604 wstats->qual.level = priv->exp_avg_rssi;
9605 wstats->qual.noise = priv->exp_avg_noise;
James Ketrenos43f66a62005-03-25 12:31:53 -06009606 wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
Bill Mossb1916082006-02-15 08:50:18 +08009607 IW_QUAL_NOISE_UPDATED | IW_QUAL_DBM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009608
9609 wstats->miss.beacon = average_value(&priv->average_missed_beacons);
9610 wstats->discard.retries = priv->last_tx_failures;
9611 wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
Jeff Garzikbf794512005-07-31 13:07:26 -04009612
James Ketrenos43f66a62005-03-25 12:31:53 -06009613/* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
9614 goto fail_get_ordinal;
9615 wstats->discard.retries += tx_retry; */
Jeff Garzikbf794512005-07-31 13:07:26 -04009616
James Ketrenos43f66a62005-03-25 12:31:53 -06009617 return wstats;
9618}
9619
James Ketrenos43f66a62005-03-25 12:31:53 -06009620/* net device stuff */
9621
Arjan van de Ven858119e2006-01-14 13:20:43 -08009622static void init_sys_config(struct ipw_sys_config *sys_config)
James Ketrenos43f66a62005-03-25 12:31:53 -06009623{
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009624 memset(sys_config, 0, sizeof(struct ipw_sys_config));
Zhu Yi810dabd2006-01-24 16:36:59 +08009625 sys_config->bt_coexistence = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009626 sys_config->answer_broadcast_ssid_probe = 0;
9627 sys_config->accept_all_data_frames = 0;
9628 sys_config->accept_non_directed_frames = 1;
9629 sys_config->exclude_unicast_unencrypted = 0;
9630 sys_config->disable_unicast_decryption = 1;
9631 sys_config->exclude_multicast_unencrypted = 0;
9632 sys_config->disable_multicast_decryption = 1;
Zhu Yid2b83e12006-04-13 17:19:36 +08009633 if (antenna < CFG_SYS_ANTENNA_BOTH || antenna > CFG_SYS_ANTENNA_B)
9634 antenna = CFG_SYS_ANTENNA_BOTH;
9635 sys_config->antenna_diversity = antenna;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009636 sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
James Ketrenos43f66a62005-03-25 12:31:53 -06009637 sys_config->dot11g_auto_detection = 0;
Jeff Garzikbf794512005-07-31 13:07:26 -04009638 sys_config->enable_cts_to_self = 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009639 sys_config->bt_coexist_collision_thr = 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009640 sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
Cahill, Ben M12977152006-03-08 02:58:02 +08009641 sys_config->silence_threshold = 0x1e;
James Ketrenos43f66a62005-03-25 12:31:53 -06009642}
9643
9644static int ipw_net_open(struct net_device *dev)
9645{
9646 struct ipw_priv *priv = ieee80211_priv(dev);
9647 IPW_DEBUG_INFO("dev->open\n");
9648 /* we should be verifying the device is ready to be opened */
Zhu Yi46441512006-01-24 16:37:59 +08009649 mutex_lock(&priv->mutex);
Jeff Garzikbf794512005-07-31 13:07:26 -04009650 if (!(priv->status & STATUS_RF_KILL_MASK) &&
9651 (priv->status & STATUS_ASSOCIATED))
James Ketrenos43f66a62005-03-25 12:31:53 -06009652 netif_start_queue(dev);
Zhu Yi46441512006-01-24 16:37:59 +08009653 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009654 return 0;
9655}
9656
9657static int ipw_net_stop(struct net_device *dev)
9658{
9659 IPW_DEBUG_INFO("dev->close\n");
9660 netif_stop_queue(dev);
9661 return 0;
9662}
9663
9664/*
9665todo:
9666
9667modify to send one tfd per fragment instead of using chunking. otherwise
9668we need to heavily modify the ieee80211_skb_to_txb.
9669*/
9670
Arjan van de Ven858119e2006-01-14 13:20:43 -08009671static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
James Ketrenos227d2dc2005-07-28 16:25:55 -05009672 int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009673{
Zhu Yia5cf4fe2006-04-13 17:19:11 +08009674 struct ieee80211_hdr_3addrqos *hdr = (struct ieee80211_hdr_3addrqos *)
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009675 txb->fragments[0]->data;
James Ketrenos43f66a62005-03-25 12:31:53 -06009676 int i = 0;
9677 struct tfd_frame *tfd;
James Ketrenosb095c382005-08-24 22:04:42 -05009678#ifdef CONFIG_IPW_QOS
9679 int tx_id = ipw_get_tx_queue_number(priv, pri);
9680 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9681#else
James Ketrenos43f66a62005-03-25 12:31:53 -06009682 struct clx2_tx_queue *txq = &priv->txq[0];
James Ketrenosb095c382005-08-24 22:04:42 -05009683#endif
James Ketrenos43f66a62005-03-25 12:31:53 -06009684 struct clx2_queue *q = &txq->q;
9685 u8 id, hdr_len, unicast;
9686 u16 remaining_bytes;
James Ketrenosc848d0a2005-08-24 21:56:24 -05009687 int fc;
James Ketrenos43f66a62005-03-25 12:31:53 -06009688
Zhu Yia5cf4fe2006-04-13 17:19:11 +08009689 hdr_len = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl));
James Ketrenos43f66a62005-03-25 12:31:53 -06009690 switch (priv->ieee->iw_mode) {
9691 case IW_MODE_ADHOC:
Stephen Hemminger3c190652006-01-03 15:27:38 -08009692 unicast = !is_multicast_ether_addr(hdr->addr1);
James Ketrenos43f66a62005-03-25 12:31:53 -06009693 id = ipw_find_station(priv, hdr->addr1);
9694 if (id == IPW_INVALID_STATION) {
9695 id = ipw_add_station(priv, hdr->addr1);
9696 if (id == IPW_INVALID_STATION) {
9697 IPW_WARNING("Attempt to send data to "
Jeff Garzikbf794512005-07-31 13:07:26 -04009698 "invalid cell: " MAC_FMT "\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009699 MAC_ARG(hdr->addr1));
9700 goto drop;
9701 }
9702 }
9703 break;
9704
9705 case IW_MODE_INFRA:
9706 default:
Stephen Hemminger3c190652006-01-03 15:27:38 -08009707 unicast = !is_multicast_ether_addr(hdr->addr3);
James Ketrenos43f66a62005-03-25 12:31:53 -06009708 id = 0;
9709 break;
9710 }
9711
9712 tfd = &txq->bd[q->first_empty];
9713 txq->txb[q->first_empty] = txb;
9714 memset(tfd, 0, sizeof(*tfd));
9715 tfd->u.data.station_number = id;
9716
9717 tfd->control_flags.message_type = TX_FRAME_TYPE;
9718 tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
9719
9720 tfd->u.data.cmd_id = DINO_CMD_TX;
James Ketrenosa613bff2005-08-24 21:43:11 -05009721 tfd->u.data.len = cpu_to_le16(txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009722 remaining_bytes = txb->payload_size;
Jeff Garzikbf794512005-07-31 13:07:26 -04009723
James Ketrenos43f66a62005-03-25 12:31:53 -06009724 if (priv->assoc_request.ieee_mode == IPW_B_MODE)
James Ketrenosb095c382005-08-24 22:04:42 -05009725 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009726 else
James Ketrenosb095c382005-08-24 22:04:42 -05009727 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
James Ketrenos43f66a62005-03-25 12:31:53 -06009728
James Ketrenosea2b26e2005-08-24 21:25:16 -05009729 if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
9730 tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009731
James Ketrenosc848d0a2005-08-24 21:56:24 -05009732 fc = le16_to_cpu(hdr->frame_ctl);
9733 hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
James Ketrenos43f66a62005-03-25 12:31:53 -06009734
9735 memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
9736
James Ketrenosb095c382005-08-24 22:04:42 -05009737 if (likely(unicast))
9738 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9739
9740 if (txb->encrypted && !priv->ieee->host_encrypt) {
9741 switch (priv->ieee->sec.level) {
9742 case SEC_LEVEL_3:
9743 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9744 IEEE80211_FCTL_PROTECTED;
9745 /* XXX: ACK flag must be set for CCMP even if it
9746 * is a multicast/broadcast packet, because CCMP
9747 * group communication encrypted by GTK is
9748 * actually done by the AP. */
9749 if (!unicast)
9750 tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
9751
9752 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9753 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
9754 tfd->u.data.key_index = 0;
9755 tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
9756 break;
9757 case SEC_LEVEL_2:
9758 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9759 IEEE80211_FCTL_PROTECTED;
9760 tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
9761 tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
9762 tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
9763 break;
9764 case SEC_LEVEL_1:
9765 tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
9766 IEEE80211_FCTL_PROTECTED;
9767 tfd->u.data.key_index = priv->ieee->tx_keyidx;
9768 if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
9769 40)
9770 tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
9771 else
9772 tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
9773 break;
9774 case SEC_LEVEL_0:
9775 break;
9776 default:
9777 printk(KERN_ERR "Unknow security level %d\n",
9778 priv->ieee->sec.level);
9779 break;
9780 }
9781 } else
9782 /* No hardware encryption */
9783 tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
9784
9785#ifdef CONFIG_IPW_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +08009786 if (fc & IEEE80211_STYPE_QOS_DATA)
9787 ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data));
James Ketrenosb095c382005-08-24 22:04:42 -05009788#endif /* CONFIG_IPW_QOS */
9789
James Ketrenos43f66a62005-03-25 12:31:53 -06009790 /* payload */
James Ketrenosa613bff2005-08-24 21:43:11 -05009791 tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
9792 txb->nr_frags));
9793 IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
9794 txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
9795 for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
9796 IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
9797 i, le32_to_cpu(tfd->u.data.num_chunks),
9798 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009799 IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
James Ketrenos43f66a62005-03-25 12:31:53 -06009800 i, tfd->u.data.num_chunks,
9801 txb->fragments[i]->len - hdr_len);
Jeff Garzikbf794512005-07-31 13:07:26 -04009802 printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
James Ketrenos43f66a62005-03-25 12:31:53 -06009803 txb->fragments[i]->len - hdr_len);
9804
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009805 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009806 cpu_to_le32(pci_map_single
9807 (priv->pci_dev,
9808 txb->fragments[i]->data + hdr_len,
9809 txb->fragments[i]->len - hdr_len,
9810 PCI_DMA_TODEVICE));
9811 tfd->u.data.chunk_len[i] =
9812 cpu_to_le16(txb->fragments[i]->len - hdr_len);
James Ketrenos43f66a62005-03-25 12:31:53 -06009813 }
9814
9815 if (i != txb->nr_frags) {
9816 struct sk_buff *skb;
9817 u16 remaining_bytes = 0;
9818 int j;
9819
9820 for (j = i; j < txb->nr_frags; j++)
9821 remaining_bytes += txb->fragments[j]->len - hdr_len;
9822
9823 printk(KERN_INFO "Trying to reallocate for %d bytes\n",
9824 remaining_bytes);
9825 skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
9826 if (skb != NULL) {
James Ketrenosa613bff2005-08-24 21:43:11 -05009827 tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
James Ketrenos43f66a62005-03-25 12:31:53 -06009828 for (j = i; j < txb->nr_frags; j++) {
9829 int size = txb->fragments[j]->len - hdr_len;
James Ketrenosafbf30a2005-08-25 00:05:33 -05009830
James Ketrenos43f66a62005-03-25 12:31:53 -06009831 printk(KERN_INFO "Adding frag %d %d...\n",
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009832 j, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009833 memcpy(skb_put(skb, size),
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009834 txb->fragments[j]->data + hdr_len, size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009835 }
9836 dev_kfree_skb_any(txb->fragments[i]);
9837 txb->fragments[i] = skb;
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009838 tfd->u.data.chunk_ptr[i] =
James Ketrenosa613bff2005-08-24 21:43:11 -05009839 cpu_to_le32(pci_map_single
9840 (priv->pci_dev, skb->data,
9841 tfd->u.data.chunk_len[i],
9842 PCI_DMA_TODEVICE));
9843
9844 tfd->u.data.num_chunks =
9845 cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
9846 1);
Jeff Garzikbf794512005-07-31 13:07:26 -04009847 }
James Ketrenos43f66a62005-03-25 12:31:53 -06009848 }
9849
9850 /* kick DMA */
9851 q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
9852 ipw_write32(priv, q->reg_w, q->first_empty);
9853
James Ketrenosf6970142006-02-14 09:10:51 +08009854 if (ipw_queue_space(q) < q->high_mark)
9855 netif_stop_queue(priv->net_dev);
9856
James Ketrenos227d2dc2005-07-28 16:25:55 -05009857 return NETDEV_TX_OK;
James Ketrenos43f66a62005-03-25 12:31:53 -06009858
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009859 drop:
James Ketrenos43f66a62005-03-25 12:31:53 -06009860 IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
9861 ieee80211_txb_free(txb);
James Ketrenos227d2dc2005-07-28 16:25:55 -05009862 return NETDEV_TX_OK;
9863}
9864
9865static int ipw_net_is_queue_full(struct net_device *dev, int pri)
9866{
9867 struct ipw_priv *priv = ieee80211_priv(dev);
9868#ifdef CONFIG_IPW_QOS
9869 int tx_id = ipw_get_tx_queue_number(priv, pri);
9870 struct clx2_tx_queue *txq = &priv->txq[tx_id];
9871#else
9872 struct clx2_tx_queue *txq = &priv->txq[0];
9873#endif /* CONFIG_IPW_QOS */
9874
9875 if (ipw_queue_space(&txq->q) < txq->q.high_mark)
9876 return 1;
9877
9878 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -06009879}
9880
9881static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
James Ketrenosc8d42d12005-09-21 12:23:43 -05009882 struct net_device *dev, int pri)
James Ketrenos43f66a62005-03-25 12:31:53 -06009883{
9884 struct ipw_priv *priv = ieee80211_priv(dev);
9885 unsigned long flags;
James Ketrenos227d2dc2005-07-28 16:25:55 -05009886 int ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009887
9888 IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
James Ketrenos43f66a62005-03-25 12:31:53 -06009889 spin_lock_irqsave(&priv->lock, flags);
9890
9891 if (!(priv->status & STATUS_ASSOCIATED)) {
9892 IPW_DEBUG_INFO("Tx attempt while not associated.\n");
9893 priv->ieee->stats.tx_carrier_errors++;
9894 netif_stop_queue(dev);
9895 goto fail_unlock;
9896 }
9897
James Ketrenos227d2dc2005-07-28 16:25:55 -05009898 ret = ipw_tx_skb(priv, txb, pri);
9899 if (ret == NETDEV_TX_OK)
9900 __ipw_led_activity_on(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -06009901 spin_unlock_irqrestore(&priv->lock, flags);
James Ketrenos43f66a62005-03-25 12:31:53 -06009902
James Ketrenos227d2dc2005-07-28 16:25:55 -05009903 return ret;
James Ketrenos43f66a62005-03-25 12:31:53 -06009904
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009905 fail_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -06009906 spin_unlock_irqrestore(&priv->lock, flags);
9907 return 1;
9908}
9909
9910static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
9911{
9912 struct ipw_priv *priv = ieee80211_priv(dev);
Jeff Garzikbf794512005-07-31 13:07:26 -04009913
James Ketrenos43f66a62005-03-25 12:31:53 -06009914 priv->ieee->stats.tx_packets = priv->tx_packets;
9915 priv->ieee->stats.rx_packets = priv->rx_packets;
9916 return &priv->ieee->stats;
9917}
9918
9919static void ipw_net_set_multicast_list(struct net_device *dev)
9920{
9921
9922}
9923
9924static int ipw_net_set_mac_address(struct net_device *dev, void *p)
9925{
9926 struct ipw_priv *priv = ieee80211_priv(dev);
9927 struct sockaddr *addr = p;
9928 if (!is_valid_ether_addr(addr->sa_data))
9929 return -EADDRNOTAVAIL;
Zhu Yi46441512006-01-24 16:37:59 +08009930 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009931 priv->config |= CFG_CUSTOM_MAC;
9932 memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
9933 printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
9934 priv->net_dev->name, MAC_ARG(priv->mac_addr));
James Ketrenosa613bff2005-08-24 21:43:11 -05009935 queue_work(priv->workqueue, &priv->adapter_restart);
Zhu Yi46441512006-01-24 16:37:59 +08009936 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009937 return 0;
9938}
9939
Jeff Garzikbf794512005-07-31 13:07:26 -04009940static void ipw_ethtool_get_drvinfo(struct net_device *dev,
James Ketrenos43f66a62005-03-25 12:31:53 -06009941 struct ethtool_drvinfo *info)
9942{
9943 struct ipw_priv *p = ieee80211_priv(dev);
9944 char vers[64];
9945 char date[32];
9946 u32 len;
9947
9948 strcpy(info->driver, DRV_NAME);
9949 strcpy(info->version, DRV_VERSION);
9950
9951 len = sizeof(vers);
9952 ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
9953 len = sizeof(date);
9954 ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
9955
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009956 snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
James Ketrenos43f66a62005-03-25 12:31:53 -06009957 vers, date);
9958 strcpy(info->bus_info, pci_name(p->pci_dev));
James Ketrenosb095c382005-08-24 22:04:42 -05009959 info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009960}
9961
9962static u32 ipw_ethtool_get_link(struct net_device *dev)
9963{
9964 struct ipw_priv *priv = ieee80211_priv(dev);
9965 return (priv->status & STATUS_ASSOCIATED) != 0;
9966}
9967
9968static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
9969{
James Ketrenosb095c382005-08-24 22:04:42 -05009970 return IPW_EEPROM_IMAGE_SIZE;
James Ketrenos43f66a62005-03-25 12:31:53 -06009971}
9972
9973static int ipw_ethtool_get_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009974 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -06009975{
9976 struct ipw_priv *p = ieee80211_priv(dev);
9977
James Ketrenosb095c382005-08-24 22:04:42 -05009978 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -06009979 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08009980 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009981 memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
Zhu Yi46441512006-01-24 16:37:59 +08009982 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009983 return 0;
9984}
9985
9986static int ipw_ethtool_set_eeprom(struct net_device *dev,
Jeff Garzik0edd5b42005-09-07 00:48:31 -04009987 struct ethtool_eeprom *eeprom, u8 * bytes)
James Ketrenos43f66a62005-03-25 12:31:53 -06009988{
9989 struct ipw_priv *p = ieee80211_priv(dev);
9990 int i;
9991
James Ketrenosb095c382005-08-24 22:04:42 -05009992 if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
James Ketrenos43f66a62005-03-25 12:31:53 -06009993 return -EINVAL;
Zhu Yi46441512006-01-24 16:37:59 +08009994 mutex_lock(&p->mutex);
James Ketrenosafbf30a2005-08-25 00:05:33 -05009995 memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
Adrian Bunk71e585f2006-03-11 04:42:58 +01009996 for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
9997 ipw_write8(p, i + IPW_EEPROM_DATA, p->eeprom[i]);
Zhu Yi46441512006-01-24 16:37:59 +08009998 mutex_unlock(&p->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -06009999 return 0;
10000}
10001
10002static struct ethtool_ops ipw_ethtool_ops = {
James Ketrenosea2b26e2005-08-24 21:25:16 -050010003 .get_link = ipw_ethtool_get_link,
10004 .get_drvinfo = ipw_ethtool_get_drvinfo,
10005 .get_eeprom_len = ipw_ethtool_get_eeprom_len,
10006 .get_eeprom = ipw_ethtool_get_eeprom,
10007 .set_eeprom = ipw_ethtool_set_eeprom,
James Ketrenos43f66a62005-03-25 12:31:53 -060010008};
10009
10010static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
10011{
10012 struct ipw_priv *priv = data;
10013 u32 inta, inta_mask;
Jeff Garzikbf794512005-07-31 13:07:26 -040010014
James Ketrenos43f66a62005-03-25 12:31:53 -060010015 if (!priv)
10016 return IRQ_NONE;
10017
10018 spin_lock(&priv->lock);
10019
10020 if (!(priv->status & STATUS_INT_ENABLED)) {
10021 /* Shared IRQ */
10022 goto none;
10023 }
10024
James Ketrenosb095c382005-08-24 22:04:42 -050010025 inta = ipw_read32(priv, IPW_INTA_RW);
10026 inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
Jeff Garzikbf794512005-07-31 13:07:26 -040010027
James Ketrenos43f66a62005-03-25 12:31:53 -060010028 if (inta == 0xFFFFFFFF) {
10029 /* Hardware disappeared */
10030 IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
10031 goto none;
10032 }
10033
James Ketrenosb095c382005-08-24 22:04:42 -050010034 if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010035 /* Shared interrupt */
10036 goto none;
10037 }
10038
10039 /* tell the device to stop sending interrupts */
10040 ipw_disable_interrupts(priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010041
James Ketrenos43f66a62005-03-25 12:31:53 -060010042 /* ack current interrupts */
James Ketrenosb095c382005-08-24 22:04:42 -050010043 inta &= (IPW_INTA_MASK_ALL & inta_mask);
10044 ipw_write32(priv, IPW_INTA_RW, inta);
Jeff Garzikbf794512005-07-31 13:07:26 -040010045
James Ketrenos43f66a62005-03-25 12:31:53 -060010046 /* Cache INTA value for our tasklet */
10047 priv->isr_inta = inta;
10048
10049 tasklet_schedule(&priv->irq_tasklet);
10050
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010051 spin_unlock(&priv->lock);
James Ketrenos43f66a62005-03-25 12:31:53 -060010052
10053 return IRQ_HANDLED;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010054 none:
James Ketrenos43f66a62005-03-25 12:31:53 -060010055 spin_unlock(&priv->lock);
10056 return IRQ_NONE;
10057}
10058
10059static void ipw_rf_kill(void *adapter)
10060{
10061 struct ipw_priv *priv = adapter;
10062 unsigned long flags;
Jeff Garzikbf794512005-07-31 13:07:26 -040010063
James Ketrenos43f66a62005-03-25 12:31:53 -060010064 spin_lock_irqsave(&priv->lock, flags);
10065
10066 if (rf_kill_active(priv)) {
10067 IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
10068 if (priv->workqueue)
10069 queue_delayed_work(priv->workqueue,
10070 &priv->rf_kill, 2 * HZ);
10071 goto exit_unlock;
10072 }
10073
10074 /* RF Kill is now disabled, so bring the device back up */
10075
10076 if (!(priv->status & STATUS_RF_KILL_MASK)) {
10077 IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
10078 "device\n");
10079
10080 /* we can not do an adapter restart while inside an irq lock */
10081 queue_work(priv->workqueue, &priv->adapter_restart);
Jeff Garzikbf794512005-07-31 13:07:26 -040010082 } else
James Ketrenos43f66a62005-03-25 12:31:53 -060010083 IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
10084 "enabled\n");
10085
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010086 exit_unlock:
James Ketrenos43f66a62005-03-25 12:31:53 -060010087 spin_unlock_irqrestore(&priv->lock, flags);
10088}
10089
James Ketrenosc848d0a2005-08-24 21:56:24 -050010090static void ipw_bg_rf_kill(void *data)
10091{
10092 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010093 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010094 ipw_rf_kill(data);
Zhu Yi46441512006-01-24 16:37:59 +080010095 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010096}
10097
Adrian Bunka73e22b2006-01-21 01:39:42 +010010098static void ipw_link_up(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010099{
James Ketrenosafbf30a2005-08-25 00:05:33 -050010100 priv->last_seq_num = -1;
10101 priv->last_frag_num = -1;
10102 priv->last_packet_time = 0;
10103
James Ketrenosa613bff2005-08-24 21:43:11 -050010104 netif_carrier_on(priv->net_dev);
10105 if (netif_queue_stopped(priv->net_dev)) {
10106 IPW_DEBUG_NOTIF("waking queue\n");
10107 netif_wake_queue(priv->net_dev);
10108 } else {
10109 IPW_DEBUG_NOTIF("starting queue\n");
10110 netif_start_queue(priv->net_dev);
10111 }
10112
James Ketrenosc848d0a2005-08-24 21:56:24 -050010113 cancel_delayed_work(&priv->request_scan);
James Ketrenosa613bff2005-08-24 21:43:11 -050010114 ipw_reset_stats(priv);
10115 /* Ensure the rate is updated immediately */
10116 priv->last_rate = ipw_get_current_rate(priv);
10117 ipw_gather_stats(priv);
10118 ipw_led_link_up(priv);
10119 notify_wx_assoc_event(priv);
10120
10121 if (priv->config & CFG_BACKGROUND_SCAN)
10122 queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
10123}
10124
James Ketrenosc848d0a2005-08-24 21:56:24 -050010125static void ipw_bg_link_up(void *data)
10126{
10127 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010128 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010129 ipw_link_up(data);
Zhu Yi46441512006-01-24 16:37:59 +080010130 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010131}
10132
Adrian Bunka73e22b2006-01-21 01:39:42 +010010133static void ipw_link_down(struct ipw_priv *priv)
James Ketrenosa613bff2005-08-24 21:43:11 -050010134{
10135 ipw_led_link_down(priv);
10136 netif_carrier_off(priv->net_dev);
10137 netif_stop_queue(priv->net_dev);
10138 notify_wx_assoc_event(priv);
10139
10140 /* Cancel any queued work ... */
10141 cancel_delayed_work(&priv->request_scan);
10142 cancel_delayed_work(&priv->adhoc_check);
10143 cancel_delayed_work(&priv->gather_stats);
10144
10145 ipw_reset_stats(priv);
10146
James Ketrenosafbf30a2005-08-25 00:05:33 -050010147 if (!(priv->status & STATUS_EXIT_PENDING)) {
10148 /* Queue up another scan... */
10149 queue_work(priv->workqueue, &priv->request_scan);
10150 }
James Ketrenosa613bff2005-08-24 21:43:11 -050010151}
10152
James Ketrenosc848d0a2005-08-24 21:56:24 -050010153static void ipw_bg_link_down(void *data)
10154{
10155 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010156 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010157 ipw_link_down(data);
Zhu Yi46441512006-01-24 16:37:59 +080010158 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010159}
10160
James Ketrenos43f66a62005-03-25 12:31:53 -060010161static int ipw_setup_deferred_work(struct ipw_priv *priv)
10162{
10163 int ret = 0;
10164
James Ketrenos43f66a62005-03-25 12:31:53 -060010165 priv->workqueue = create_workqueue(DRV_NAME);
James Ketrenos43f66a62005-03-25 12:31:53 -060010166 init_waitqueue_head(&priv->wait_command_queue);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010167 init_waitqueue_head(&priv->wait_state);
James Ketrenos43f66a62005-03-25 12:31:53 -060010168
James Ketrenosc848d0a2005-08-24 21:56:24 -050010169 INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
10170 INIT_WORK(&priv->associate, ipw_bg_associate, priv);
10171 INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
Zhu Yid8bad6d2005-07-13 12:25:38 -050010172 INIT_WORK(&priv->system_config, ipw_system_config, priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010173 INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
10174 INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
10175 INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
10176 INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
10177 INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010178 INIT_WORK(&priv->request_scan,
James Ketrenos43f66a62005-03-25 12:31:53 -060010179 (void (*)(void *))ipw_request_scan, priv);
Jeff Garzikbf794512005-07-31 13:07:26 -040010180 INIT_WORK(&priv->gather_stats,
James Ketrenosc848d0a2005-08-24 21:56:24 -050010181 (void (*)(void *))ipw_bg_gather_stats, priv);
10182 INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
10183 INIT_WORK(&priv->roam, ipw_bg_roam, priv);
10184 INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
10185 INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
10186 INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
10187 INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
James Ketrenosa613bff2005-08-24 21:43:11 -050010188 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010189 INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
James Ketrenosa613bff2005-08-24 21:43:11 -050010190 priv);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010191 INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
10192 priv);
10193 INIT_WORK(&priv->merge_networks,
10194 (void (*)(void *))ipw_merge_adhoc_network, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010195
James Ketrenosb095c382005-08-24 22:04:42 -050010196#ifdef CONFIG_IPW_QOS
10197 INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
10198 priv);
10199#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010200
10201 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
10202 ipw_irq_tasklet, (unsigned long)priv);
10203
10204 return ret;
10205}
10206
James Ketrenos43f66a62005-03-25 12:31:53 -060010207static void shim__set_security(struct net_device *dev,
10208 struct ieee80211_security *sec)
10209{
10210 struct ipw_priv *priv = ieee80211_priv(dev);
10211 int i;
Jeff Garzikbf794512005-07-31 13:07:26 -040010212 for (i = 0; i < 4; i++) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010213 if (sec->flags & (1 << i)) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050010214 priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
James Ketrenosb095c382005-08-24 22:04:42 -050010215 priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
James Ketrenos43f66a62005-03-25 12:31:53 -060010216 if (sec->key_sizes[i] == 0)
James Ketrenosb095c382005-08-24 22:04:42 -050010217 priv->ieee->sec.flags &= ~(1 << i);
10218 else {
10219 memcpy(priv->ieee->sec.keys[i], sec->keys[i],
James Ketrenos43f66a62005-03-25 12:31:53 -060010220 sec->key_sizes[i]);
James Ketrenosb095c382005-08-24 22:04:42 -050010221 priv->ieee->sec.flags |= (1 << i);
10222 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010223 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010224 } else if (sec->level != SEC_LEVEL_1)
10225 priv->ieee->sec.flags &= ~(1 << i);
James Ketrenos43f66a62005-03-25 12:31:53 -060010226 }
10227
James Ketrenosb095c382005-08-24 22:04:42 -050010228 if (sec->flags & SEC_ACTIVE_KEY) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010229 if (sec->active_key <= 3) {
James Ketrenosb095c382005-08-24 22:04:42 -050010230 priv->ieee->sec.active_key = sec->active_key;
10231 priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
Jeff Garzikbf794512005-07-31 13:07:26 -040010232 } else
James Ketrenosb095c382005-08-24 22:04:42 -050010233 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010234 priv->status |= STATUS_SECURITY_UPDATED;
James Ketrenosb095c382005-08-24 22:04:42 -050010235 } else
10236 priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
James Ketrenos43f66a62005-03-25 12:31:53 -060010237
10238 if ((sec->flags & SEC_AUTH_MODE) &&
James Ketrenosb095c382005-08-24 22:04:42 -050010239 (priv->ieee->sec.auth_mode != sec->auth_mode)) {
10240 priv->ieee->sec.auth_mode = sec->auth_mode;
10241 priv->ieee->sec.flags |= SEC_AUTH_MODE;
James Ketrenos43f66a62005-03-25 12:31:53 -060010242 if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
10243 priv->capability |= CAP_SHARED_KEY;
10244 else
10245 priv->capability &= ~CAP_SHARED_KEY;
10246 priv->status |= STATUS_SECURITY_UPDATED;
10247 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010248
James Ketrenosb095c382005-08-24 22:04:42 -050010249 if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
10250 priv->ieee->sec.flags |= SEC_ENABLED;
10251 priv->ieee->sec.enabled = sec->enabled;
James Ketrenos43f66a62005-03-25 12:31:53 -060010252 priv->status |= STATUS_SECURITY_UPDATED;
Jeff Garzikbf794512005-07-31 13:07:26 -040010253 if (sec->enabled)
James Ketrenos43f66a62005-03-25 12:31:53 -060010254 priv->capability |= CAP_PRIVACY_ON;
10255 else
10256 priv->capability &= ~CAP_PRIVACY_ON;
10257 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010258
James Ketrenosafbf30a2005-08-25 00:05:33 -050010259 if (sec->flags & SEC_ENCRYPT)
10260 priv->ieee->sec.encrypt = sec->encrypt;
James Ketrenos43f66a62005-03-25 12:31:53 -060010261
James Ketrenosb095c382005-08-24 22:04:42 -050010262 if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
10263 priv->ieee->sec.level = sec->level;
10264 priv->ieee->sec.flags |= SEC_LEVEL;
James Ketrenos43f66a62005-03-25 12:31:53 -060010265 priv->status |= STATUS_SECURITY_UPDATED;
10266 }
10267
Zhu Yi1fbfea52005-08-05 17:22:56 +080010268 if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
10269 ipw_set_hwcrypto_keys(priv);
10270
Jeff Garzikbf794512005-07-31 13:07:26 -040010271 /* To match current functionality of ipw2100 (which works well w/
10272 * various supplicants, we don't force a disassociate if the
James Ketrenos43f66a62005-03-25 12:31:53 -060010273 * privacy capability changes ... */
10274#if 0
10275 if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
Jeff Garzikbf794512005-07-31 13:07:26 -040010276 (((priv->assoc_request.capability &
James Ketrenos43f66a62005-03-25 12:31:53 -060010277 WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
Jeff Garzikbf794512005-07-31 13:07:26 -040010278 (!(priv->assoc_request.capability &
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010279 WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
James Ketrenos43f66a62005-03-25 12:31:53 -060010280 IPW_DEBUG_ASSOC("Disassociating due to capability "
10281 "change.\n");
10282 ipw_disassociate(priv);
10283 }
10284#endif
10285}
10286
Jeff Garzikbf794512005-07-31 13:07:26 -040010287static int init_supported_rates(struct ipw_priv *priv,
James Ketrenos43f66a62005-03-25 12:31:53 -060010288 struct ipw_supported_rates *rates)
10289{
10290 /* TODO: Mask out rates based on priv->rates_mask */
10291
10292 memset(rates, 0, sizeof(*rates));
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010293 /* configure supported rates */
James Ketrenos43f66a62005-03-25 12:31:53 -060010294 switch (priv->ieee->freq_band) {
10295 case IEEE80211_52GHZ_BAND:
10296 rates->ieee_mode = IPW_A_MODE;
10297 rates->purpose = IPW_RATE_CAPABILITIES;
10298 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10299 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10300 break;
10301
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010302 default: /* Mixed or 2.4Ghz */
James Ketrenos43f66a62005-03-25 12:31:53 -060010303 rates->ieee_mode = IPW_G_MODE;
10304 rates->purpose = IPW_RATE_CAPABILITIES;
10305 ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
10306 IEEE80211_CCK_DEFAULT_RATES_MASK);
10307 if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
10308 ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
10309 IEEE80211_OFDM_DEFAULT_RATES_MASK);
10310 }
10311 break;
10312 }
10313
10314 return 0;
10315}
10316
Jeff Garzikbf794512005-07-31 13:07:26 -040010317static int ipw_config(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010318{
James Ketrenos43f66a62005-03-25 12:31:53 -060010319 /* This is only called from ipw_up, which resets/reloads the firmware
10320 so, we don't need to first disable the card before we configure
10321 it */
Zhu Yi6de9f7f2005-08-11 14:39:33 +080010322 if (ipw_set_tx_power(priv))
James Ketrenos43f66a62005-03-25 12:31:53 -060010323 goto error;
10324
10325 /* initialize adapter address */
10326 if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
10327 goto error;
10328
10329 /* set basic system config settings */
10330 init_sys_config(&priv->sys_config);
Zhu Yi810dabd2006-01-24 16:36:59 +080010331
10332 /* Support Bluetooth if we have BT h/w on board, and user wants to.
10333 * Does not support BT priority yet (don't abort or defer our Tx) */
10334 if (bt_coexist) {
Zhu Yi2638bc32006-01-24 16:37:52 +080010335 unsigned char bt_caps = priv->eeprom[EEPROM_SKU_CAPABILITY];
Zhu Yi810dabd2006-01-24 16:36:59 +080010336
10337 if (bt_caps & EEPROM_SKU_CAP_BT_CHANNEL_SIG)
10338 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010339 |= CFG_BT_COEXISTENCE_SIGNAL_CHNL;
Zhu Yi810dabd2006-01-24 16:36:59 +080010340 if (bt_caps & EEPROM_SKU_CAP_BT_OOB)
10341 priv->sys_config.bt_coexistence
Zhu Yi2638bc32006-01-24 16:37:52 +080010342 |= CFG_BT_COEXISTENCE_OOB;
Zhu Yi810dabd2006-01-24 16:36:59 +080010343 }
10344
James Ketrenosc848d0a2005-08-24 21:56:24 -050010345 if (priv->ieee->iw_mode == IW_MODE_ADHOC)
10346 priv->sys_config.answer_broadcast_ssid_probe = 1;
10347 else
10348 priv->sys_config.answer_broadcast_ssid_probe = 0;
10349
James Ketrenos43f66a62005-03-25 12:31:53 -060010350 if (ipw_send_system_config(priv, &priv->sys_config))
10351 goto error;
10352
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010353 init_supported_rates(priv, &priv->rates);
10354 if (ipw_send_supported_rates(priv, &priv->rates))
James Ketrenos43f66a62005-03-25 12:31:53 -060010355 goto error;
10356
10357 /* Set request-to-send threshold */
10358 if (priv->rts_threshold) {
10359 if (ipw_send_rts_threshold(priv, priv->rts_threshold))
10360 goto error;
10361 }
James Ketrenosb095c382005-08-24 22:04:42 -050010362#ifdef CONFIG_IPW_QOS
10363 IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
10364 ipw_qos_activate(priv, NULL);
10365#endif /* CONFIG_IPW_QOS */
James Ketrenos43f66a62005-03-25 12:31:53 -060010366
10367 if (ipw_set_random_seed(priv))
10368 goto error;
Jeff Garzikbf794512005-07-31 13:07:26 -040010369
James Ketrenos43f66a62005-03-25 12:31:53 -060010370 /* final state transition to the RUN state */
10371 if (ipw_send_host_complete(priv))
10372 goto error;
10373
James Ketrenose6666192005-08-12 09:17:04 -050010374 priv->status |= STATUS_INIT;
10375
10376 ipw_led_init(priv);
10377 ipw_led_radio_on(priv);
10378 priv->notif_missed_beacons = 0;
10379
10380 /* Set hardware WEP key if it is configured. */
10381 if ((priv->capability & CAP_PRIVACY_ON) &&
10382 (priv->ieee->sec.level == SEC_LEVEL_1) &&
10383 !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
10384 ipw_set_hwcrypto_keys(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010385
10386 return 0;
Jeff Garzikbf794512005-07-31 13:07:26 -040010387
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010388 error:
James Ketrenos43f66a62005-03-25 12:31:53 -060010389 return -EIO;
10390}
10391
James Ketrenos4f36f802005-08-03 20:36:56 -050010392/*
10393 * NOTE:
10394 *
10395 * These tables have been tested in conjunction with the
10396 * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
10397 *
10398 * Altering this values, using it on other hardware, or in geographies
10399 * not intended for resale of the above mentioned Intel adapters has
10400 * not been tested.
10401 *
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080010402 * Remember to update the table in README.ipw2200 when changing this
10403 * table.
10404 *
James Ketrenos4f36f802005-08-03 20:36:56 -050010405 */
10406static const struct ieee80211_geo ipw_geos[] = {
10407 { /* Restricted */
10408 "---",
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 },
10415
10416 { /* Custom US/Canada */
10417 "ZZF",
10418 .bg_channels = 11,
10419 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10420 {2427, 4}, {2432, 5}, {2437, 6},
10421 {2442, 7}, {2447, 8}, {2452, 9},
10422 {2457, 10}, {2462, 11}},
10423 .a_channels = 8,
10424 .a = {{5180, 36},
10425 {5200, 40},
10426 {5220, 44},
10427 {5240, 48},
10428 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10429 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10430 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10431 {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
10432 },
10433
10434 { /* Rest of World */
10435 "ZZD",
10436 .bg_channels = 13,
10437 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10438 {2427, 4}, {2432, 5}, {2437, 6},
10439 {2442, 7}, {2447, 8}, {2452, 9},
10440 {2457, 10}, {2462, 11}, {2467, 12},
10441 {2472, 13}},
10442 },
10443
10444 { /* Custom USA & Europe & High */
10445 "ZZA",
10446 .bg_channels = 11,
10447 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10448 {2427, 4}, {2432, 5}, {2437, 6},
10449 {2442, 7}, {2447, 8}, {2452, 9},
10450 {2457, 10}, {2462, 11}},
10451 .a_channels = 13,
10452 .a = {{5180, 36},
10453 {5200, 40},
10454 {5220, 44},
10455 {5240, 48},
10456 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10457 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10458 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10459 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10460 {5745, 149},
10461 {5765, 153},
10462 {5785, 157},
10463 {5805, 161},
10464 {5825, 165}},
10465 },
10466
10467 { /* Custom NA & Europe */
10468 "ZZB",
10469 .bg_channels = 11,
10470 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10471 {2427, 4}, {2432, 5}, {2437, 6},
10472 {2442, 7}, {2447, 8}, {2452, 9},
10473 {2457, 10}, {2462, 11}},
10474 .a_channels = 13,
10475 .a = {{5180, 36},
10476 {5200, 40},
10477 {5220, 44},
10478 {5240, 48},
10479 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10480 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10481 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10482 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10483 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10484 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10485 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10486 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10487 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10488 },
10489
10490 { /* Custom Japan */
10491 "ZZC",
10492 .bg_channels = 11,
10493 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10494 {2427, 4}, {2432, 5}, {2437, 6},
10495 {2442, 7}, {2447, 8}, {2452, 9},
10496 {2457, 10}, {2462, 11}},
10497 .a_channels = 4,
10498 .a = {{5170, 34}, {5190, 38},
10499 {5210, 42}, {5230, 46}},
10500 },
10501
10502 { /* Custom */
10503 "ZZM",
10504 .bg_channels = 11,
10505 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10506 {2427, 4}, {2432, 5}, {2437, 6},
10507 {2442, 7}, {2447, 8}, {2452, 9},
10508 {2457, 10}, {2462, 11}},
10509 },
10510
10511 { /* Europe */
10512 "ZZE",
10513 .bg_channels = 13,
10514 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10515 {2427, 4}, {2432, 5}, {2437, 6},
10516 {2442, 7}, {2447, 8}, {2452, 9},
10517 {2457, 10}, {2462, 11}, {2467, 12},
10518 {2472, 13}},
10519 .a_channels = 19,
10520 .a = {{5180, 36},
10521 {5200, 40},
10522 {5220, 44},
10523 {5240, 48},
10524 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10525 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10526 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10527 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10528 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10529 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10530 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10531 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10532 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10533 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10534 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10535 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10536 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10537 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10538 {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
10539 },
10540
10541 { /* Custom Japan */
10542 "ZZJ",
10543 .bg_channels = 14,
10544 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10545 {2427, 4}, {2432, 5}, {2437, 6},
10546 {2442, 7}, {2447, 8}, {2452, 9},
10547 {2457, 10}, {2462, 11}, {2467, 12},
10548 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
10549 .a_channels = 4,
10550 .a = {{5170, 34}, {5190, 38},
10551 {5210, 42}, {5230, 46}},
10552 },
10553
James Ketrenos03520572005-10-19 16:12:31 -050010554 { /* Rest of World */
10555 "ZZR",
10556 .bg_channels = 14,
10557 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10558 {2427, 4}, {2432, 5}, {2437, 6},
10559 {2442, 7}, {2447, 8}, {2452, 9},
10560 {2457, 10}, {2462, 11}, {2467, 12},
10561 {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY |
10562 IEEE80211_CH_PASSIVE_ONLY}},
10563 },
10564
James Ketrenos4f36f802005-08-03 20:36:56 -050010565 { /* High Band */
10566 "ZZH",
10567 .bg_channels = 13,
10568 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10569 {2427, 4}, {2432, 5}, {2437, 6},
10570 {2442, 7}, {2447, 8}, {2452, 9},
10571 {2457, 10}, {2462, 11},
10572 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10573 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10574 .a_channels = 4,
10575 .a = {{5745, 149}, {5765, 153},
10576 {5785, 157}, {5805, 161}},
10577 },
10578
10579 { /* Custom Europe */
10580 "ZZG",
10581 .bg_channels = 13,
10582 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10583 {2427, 4}, {2432, 5}, {2437, 6},
10584 {2442, 7}, {2447, 8}, {2452, 9},
10585 {2457, 10}, {2462, 11},
10586 {2467, 12}, {2472, 13}},
10587 .a_channels = 4,
10588 .a = {{5180, 36}, {5200, 40},
10589 {5220, 44}, {5240, 48}},
10590 },
10591
10592 { /* Europe */
10593 "ZZK",
10594 .bg_channels = 13,
10595 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10596 {2427, 4}, {2432, 5}, {2437, 6},
10597 {2442, 7}, {2447, 8}, {2452, 9},
10598 {2457, 10}, {2462, 11},
10599 {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
10600 {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
10601 .a_channels = 24,
10602 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10603 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10604 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10605 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10606 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10607 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10608 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10609 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10610 {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
10611 {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
10612 {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
10613 {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
10614 {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
10615 {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
10616 {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
10617 {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
10618 {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
10619 {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
10620 {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
10621 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10622 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10623 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10624 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10625 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10626 },
10627
10628 { /* Europe */
10629 "ZZL",
10630 .bg_channels = 11,
10631 .bg = {{2412, 1}, {2417, 2}, {2422, 3},
10632 {2427, 4}, {2432, 5}, {2437, 6},
10633 {2442, 7}, {2447, 8}, {2452, 9},
10634 {2457, 10}, {2462, 11}},
10635 .a_channels = 13,
10636 .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
10637 {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
10638 {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
10639 {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
10640 {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
10641 {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
10642 {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
10643 {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
10644 {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
10645 {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
10646 {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
10647 {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
10648 {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
10649 }
James Ketrenosafbf30a2005-08-25 00:05:33 -050010650};
10651
James Ketrenos43f66a62005-03-25 12:31:53 -060010652#define MAX_HW_RESTARTS 5
10653static int ipw_up(struct ipw_priv *priv)
10654{
James Ketrenos4f36f802005-08-03 20:36:56 -050010655 int rc, i, j;
James Ketrenos43f66a62005-03-25 12:31:53 -060010656
10657 if (priv->status & STATUS_EXIT_PENDING)
10658 return -EIO;
10659
James Ketrenosf6c5cb72005-08-25 00:39:09 -050010660 if (cmdlog && !priv->cmdlog) {
10661 priv->cmdlog = kmalloc(sizeof(*priv->cmdlog) * cmdlog,
10662 GFP_KERNEL);
10663 if (priv->cmdlog == NULL) {
10664 IPW_ERROR("Error allocating %d command log entries.\n",
10665 cmdlog);
Zhu Yid0b526b2006-04-13 17:19:50 +080010666 return -ENOMEM;
James Ketrenosf6c5cb72005-08-25 00:39:09 -050010667 } else {
10668 memset(priv->cmdlog, 0, sizeof(*priv->cmdlog) * cmdlog);
10669 priv->cmdlog_len = cmdlog;
10670 }
10671 }
10672
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010673 for (i = 0; i < MAX_HW_RESTARTS; i++) {
Jeff Garzikbf794512005-07-31 13:07:26 -040010674 /* Load the microcode, firmware, and eeprom.
James Ketrenos43f66a62005-03-25 12:31:53 -060010675 * Also start the clocks. */
10676 rc = ipw_load(priv);
10677 if (rc) {
Peter Jonesa4f6bbb2005-08-26 00:33:34 -050010678 IPW_ERROR("Unable to load firmware: %d\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010679 return rc;
10680 }
10681
10682 ipw_init_ordinals(priv);
10683 if (!(priv->config & CFG_CUSTOM_MAC))
10684 eeprom_parse_mac(priv, priv->mac_addr);
10685 memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
10686
James Ketrenos4f36f802005-08-03 20:36:56 -050010687 for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
10688 if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
10689 ipw_geos[j].name, 3))
10690 break;
10691 }
James Ketrenos03520572005-10-19 16:12:31 -050010692 if (j == ARRAY_SIZE(ipw_geos)) {
10693 IPW_WARNING("SKU [%c%c%c] not recognized.\n",
10694 priv->eeprom[EEPROM_COUNTRY_CODE + 0],
10695 priv->eeprom[EEPROM_COUNTRY_CODE + 1],
10696 priv->eeprom[EEPROM_COUNTRY_CODE + 2]);
James Ketrenos4f36f802005-08-03 20:36:56 -050010697 j = 0;
James Ketrenos03520572005-10-19 16:12:31 -050010698 }
Larry Finger1867b112006-02-28 09:48:28 -060010699 if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
James Ketrenos4f36f802005-08-03 20:36:56 -050010700 IPW_WARNING("Could not set geography.");
James Ketrenos43f66a62005-03-25 12:31:53 -060010701 return 0;
James Ketrenos4f36f802005-08-03 20:36:56 -050010702 }
10703
James Ketrenosb095c382005-08-24 22:04:42 -050010704 if (priv->status & STATUS_RF_KILL_SW) {
10705 IPW_WARNING("Radio disabled by module parameter.\n");
10706 return 0;
10707 } else if (rf_kill_active(priv)) {
10708 IPW_WARNING("Radio Frequency Kill Switch is On:\n"
10709 "Kill switch must be turned off for "
10710 "wireless networking to work.\n");
10711 queue_delayed_work(priv->workqueue, &priv->rf_kill,
10712 2 * HZ);
James Ketrenos43f66a62005-03-25 12:31:53 -060010713 return 0;
James Ketrenosc848d0a2005-08-24 21:56:24 -050010714 }
James Ketrenos43f66a62005-03-25 12:31:53 -060010715
10716 rc = ipw_config(priv);
10717 if (!rc) {
10718 IPW_DEBUG_INFO("Configured device on count %i\n", i);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010719
James Ketrenose6666192005-08-12 09:17:04 -050010720 /* If configure to try and auto-associate, kick
10721 * off a scan. */
10722 queue_work(priv->workqueue, &priv->request_scan);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010723
James Ketrenos43f66a62005-03-25 12:31:53 -060010724 return 0;
James Ketrenos43f66a62005-03-25 12:31:53 -060010725 }
Jeff Garzikbf794512005-07-31 13:07:26 -040010726
James Ketrenosc848d0a2005-08-24 21:56:24 -050010727 IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
James Ketrenos43f66a62005-03-25 12:31:53 -060010728 IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
10729 i, MAX_HW_RESTARTS);
10730
10731 /* We had an error bringing up the hardware, so take it
10732 * all the way back down so we can try again */
10733 ipw_down(priv);
10734 }
10735
Jeff Garzikbf794512005-07-31 13:07:26 -040010736 /* tried to restart and config the device for as long as our
James Ketrenos43f66a62005-03-25 12:31:53 -060010737 * patience could withstand */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010738 IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010739
James Ketrenos43f66a62005-03-25 12:31:53 -060010740 return -EIO;
10741}
10742
James Ketrenosc848d0a2005-08-24 21:56:24 -050010743static void ipw_bg_up(void *data)
10744{
10745 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010746 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010747 ipw_up(data);
Zhu Yi46441512006-01-24 16:37:59 +080010748 mutex_unlock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010749}
10750
James Ketrenosb095c382005-08-24 22:04:42 -050010751static void ipw_deinit(struct ipw_priv *priv)
James Ketrenos43f66a62005-03-25 12:31:53 -060010752{
James Ketrenosb095c382005-08-24 22:04:42 -050010753 int i;
10754
10755 if (priv->status & STATUS_SCANNING) {
10756 IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
10757 ipw_abort_scan(priv);
10758 }
10759
10760 if (priv->status & STATUS_ASSOCIATED) {
10761 IPW_DEBUG_INFO("Disassociating during shutdown.\n");
10762 ipw_disassociate(priv);
10763 }
10764
10765 ipw_led_shutdown(priv);
10766
10767 /* Wait up to 1s for status to change to not scanning and not
10768 * associated (disassociation can take a while for a ful 802.11
10769 * exchange */
10770 for (i = 1000; i && (priv->status &
10771 (STATUS_DISASSOCIATING |
10772 STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
10773 udelay(10);
10774
10775 if (priv->status & (STATUS_DISASSOCIATING |
10776 STATUS_ASSOCIATED | STATUS_SCANNING))
10777 IPW_DEBUG_INFO("Still associated or scanning...\n");
10778 else
10779 IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
10780
James Ketrenosc848d0a2005-08-24 21:56:24 -050010781 /* Attempt to disable the card */
James Ketrenos43f66a62005-03-25 12:31:53 -060010782 ipw_send_card_disable(priv, 0);
James Ketrenosb095c382005-08-24 22:04:42 -050010783
10784 priv->status &= ~STATUS_INIT;
10785}
10786
James Ketrenos43f66a62005-03-25 12:31:53 -060010787static void ipw_down(struct ipw_priv *priv)
10788{
James Ketrenosb095c382005-08-24 22:04:42 -050010789 int exit_pending = priv->status & STATUS_EXIT_PENDING;
10790
10791 priv->status |= STATUS_EXIT_PENDING;
10792
10793 if (ipw_is_init(priv))
10794 ipw_deinit(priv);
10795
10796 /* Wipe out the EXIT_PENDING status bit if we are not actually
10797 * exiting the module */
10798 if (!exit_pending)
10799 priv->status &= ~STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010800
10801 /* tell the device to stop sending interrupts */
10802 ipw_disable_interrupts(priv);
10803
10804 /* Clear all bits but the RF Kill */
James Ketrenosb095c382005-08-24 22:04:42 -050010805 priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060010806 netif_carrier_off(priv->net_dev);
10807 netif_stop_queue(priv->net_dev);
10808
10809 ipw_stop_nic(priv);
James Ketrenosa613bff2005-08-24 21:43:11 -050010810
10811 ipw_led_radio_off(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010812}
10813
James Ketrenosc848d0a2005-08-24 21:56:24 -050010814static void ipw_bg_down(void *data)
10815{
10816 struct ipw_priv *priv = data;
Zhu Yi46441512006-01-24 16:37:59 +080010817 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010818 ipw_down(data);
Zhu Yi46441512006-01-24 16:37:59 +080010819 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010820}
10821
10822/* Called by register_netdev() */
10823static int ipw_net_init(struct net_device *dev)
10824{
10825 struct ipw_priv *priv = ieee80211_priv(dev);
Zhu Yi46441512006-01-24 16:37:59 +080010826 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010827
James Ketrenosc848d0a2005-08-24 21:56:24 -050010828 if (ipw_up(priv)) {
Zhu Yi46441512006-01-24 16:37:59 +080010829 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010830 return -EIO;
James Ketrenos43f66a62005-03-25 12:31:53 -060010831 }
10832
Zhu Yi46441512006-01-24 16:37:59 +080010833 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010834 return 0;
10835}
10836
10837/* PCI driver stuff */
10838static struct pci_device_id card_ids[] = {
10839 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
10840 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
10841 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
10842 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
10843 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
10844 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
10845 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
10846 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
10847 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
10848 {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
10849 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
10850 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
10851 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
10852 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
10853 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
10854 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
10855 {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
10856 {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010857 {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
James Ketrenosa613bff2005-08-24 21:43:11 -050010858 {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010859 {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
10860 {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
Jeff Garzikbf794512005-07-31 13:07:26 -040010861
James Ketrenos43f66a62005-03-25 12:31:53 -060010862 /* required last entry */
10863 {0,}
10864};
10865
10866MODULE_DEVICE_TABLE(pci, card_ids);
10867
10868static struct attribute *ipw_sysfs_entries[] = {
10869 &dev_attr_rf_kill.attr,
10870 &dev_attr_direct_dword.attr,
10871 &dev_attr_indirect_byte.attr,
10872 &dev_attr_indirect_dword.attr,
10873 &dev_attr_mem_gpio_reg.attr,
10874 &dev_attr_command_event_reg.attr,
10875 &dev_attr_nic_type.attr,
10876 &dev_attr_status.attr,
10877 &dev_attr_cfg.attr,
James Ketrenosb39860c2005-08-12 09:36:32 -050010878 &dev_attr_error.attr,
10879 &dev_attr_event_log.attr,
James Ketrenosf6c5cb72005-08-25 00:39:09 -050010880 &dev_attr_cmd_log.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060010881 &dev_attr_eeprom_delay.attr,
10882 &dev_attr_ucode_version.attr,
10883 &dev_attr_rtc.attr,
James Ketrenosa613bff2005-08-24 21:43:11 -050010884 &dev_attr_scan_age.attr,
10885 &dev_attr_led.attr,
James Ketrenosb095c382005-08-24 22:04:42 -050010886 &dev_attr_speed_scan.attr,
10887 &dev_attr_net_stats.attr,
James Ketrenos43f66a62005-03-25 12:31:53 -060010888 NULL
10889};
10890
10891static struct attribute_group ipw_attribute_group = {
10892 .name = NULL, /* put in device directory */
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010893 .attrs = ipw_sysfs_entries,
James Ketrenos43f66a62005-03-25 12:31:53 -060010894};
10895
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010896static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
James Ketrenos43f66a62005-03-25 12:31:53 -060010897{
10898 int err = 0;
10899 struct net_device *net_dev;
10900 void __iomem *base;
10901 u32 length, val;
10902 struct ipw_priv *priv;
James Ketrenosafbf30a2005-08-25 00:05:33 -050010903 int i;
James Ketrenos43f66a62005-03-25 12:31:53 -060010904
10905 net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
10906 if (net_dev == NULL) {
10907 err = -ENOMEM;
10908 goto out;
10909 }
10910
10911 priv = ieee80211_priv(net_dev);
10912 priv->ieee = netdev_priv(net_dev);
James Ketrenosa613bff2005-08-24 21:43:11 -050010913
James Ketrenos43f66a62005-03-25 12:31:53 -060010914 priv->net_dev = net_dev;
10915 priv->pci_dev = pdev;
Brice Goglin0f52bf92005-12-01 01:41:46 -080010916#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060010917 ipw_debug_level = debug;
10918#endif
10919 spin_lock_init(&priv->lock);
James Ketrenosafbf30a2005-08-25 00:05:33 -050010920 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
10921 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
James Ketrenos43f66a62005-03-25 12:31:53 -060010922
Zhu Yi46441512006-01-24 16:37:59 +080010923 mutex_init(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060010924 if (pci_enable_device(pdev)) {
10925 err = -ENODEV;
10926 goto out_free_ieee80211;
10927 }
10928
10929 pci_set_master(pdev);
10930
Tobias Klauser0e08b442005-06-20 14:28:41 -070010931 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
Jeff Garzikbf794512005-07-31 13:07:26 -040010932 if (!err)
Tobias Klauser0e08b442005-06-20 14:28:41 -070010933 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
James Ketrenos43f66a62005-03-25 12:31:53 -060010934 if (err) {
10935 printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
10936 goto out_pci_disable_device;
10937 }
10938
10939 pci_set_drvdata(pdev, priv);
10940
10941 err = pci_request_regions(pdev, DRV_NAME);
Jeff Garzikbf794512005-07-31 13:07:26 -040010942 if (err)
James Ketrenos43f66a62005-03-25 12:31:53 -060010943 goto out_pci_disable_device;
10944
Jeff Garzikbf794512005-07-31 13:07:26 -040010945 /* We disable the RETRY_TIMEOUT register (0x41) to keep
James Ketrenos43f66a62005-03-25 12:31:53 -060010946 * PCI Tx retries from interfering with C3 CPU state */
Jeff Garzikbf794512005-07-31 13:07:26 -040010947 pci_read_config_dword(pdev, 0x40, &val);
10948 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060010949 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
Jeff Garzikbf794512005-07-31 13:07:26 -040010950
James Ketrenos43f66a62005-03-25 12:31:53 -060010951 length = pci_resource_len(pdev, 0);
10952 priv->hw_len = length;
Jeff Garzikbf794512005-07-31 13:07:26 -040010953
James Ketrenos43f66a62005-03-25 12:31:53 -060010954 base = ioremap_nocache(pci_resource_start(pdev, 0), length);
10955 if (!base) {
10956 err = -ENODEV;
10957 goto out_pci_release_regions;
10958 }
10959
10960 priv->hw_base = base;
10961 IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
10962 IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
10963
10964 err = ipw_setup_deferred_work(priv);
10965 if (err) {
10966 IPW_ERROR("Unable to setup deferred work\n");
10967 goto out_iounmap;
10968 }
10969
James Ketrenosb095c382005-08-24 22:04:42 -050010970 ipw_sw_reset(priv, 1);
James Ketrenos43f66a62005-03-25 12:31:53 -060010971
Jeff Garzik0edd5b42005-09-07 00:48:31 -040010972 err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060010973 if (err) {
10974 IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
10975 goto out_destroy_workqueue;
10976 }
10977
10978 SET_MODULE_OWNER(net_dev);
10979 SET_NETDEV_DEV(net_dev, &pdev->dev);
10980
Zhu Yi46441512006-01-24 16:37:59 +080010981 mutex_lock(&priv->mutex);
James Ketrenosc848d0a2005-08-24 21:56:24 -050010982
James Ketrenos43f66a62005-03-25 12:31:53 -060010983 priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
10984 priv->ieee->set_security = shim__set_security;
James Ketrenos227d2dc2005-07-28 16:25:55 -050010985 priv->ieee->is_queue_full = ipw_net_is_queue_full;
James Ketrenos43f66a62005-03-25 12:31:53 -060010986
James Ketrenosb095c382005-08-24 22:04:42 -050010987#ifdef CONFIG_IPW_QOS
Zhu Yia5cf4fe2006-04-13 17:19:11 +080010988 priv->ieee->is_qos_active = ipw_is_qos_active;
James Ketrenos3b9990c2005-08-19 13:18:55 -050010989 priv->ieee->handle_probe_response = ipw_handle_beacon;
10990 priv->ieee->handle_beacon = ipw_handle_probe_response;
10991 priv->ieee->handle_assoc_response = ipw_handle_assoc_response;
James Ketrenosb095c382005-08-24 22:04:42 -050010992#endif /* CONFIG_IPW_QOS */
10993
James Ketrenosc848d0a2005-08-24 21:56:24 -050010994 priv->ieee->perfect_rssi = -20;
10995 priv->ieee->worst_rssi = -85;
James Ketrenos43f66a62005-03-25 12:31:53 -060010996
10997 net_dev->open = ipw_net_open;
10998 net_dev->stop = ipw_net_stop;
10999 net_dev->init = ipw_net_init;
11000 net_dev->get_stats = ipw_net_get_stats;
11001 net_dev->set_multicast_list = ipw_net_set_multicast_list;
11002 net_dev->set_mac_address = ipw_net_set_mac_address;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011003 priv->wireless_data.spy_data = &priv->ieee->spy_data;
Benoit Boissinot97a78ca2005-09-15 17:30:28 +000011004 net_dev->wireless_data = &priv->wireless_data;
James Ketrenos43f66a62005-03-25 12:31:53 -060011005 net_dev->wireless_handlers = &ipw_wx_handler_def;
11006 net_dev->ethtool_ops = &ipw_ethtool_ops;
11007 net_dev->irq = pdev->irq;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011008 net_dev->base_addr = (unsigned long)priv->hw_base;
James Ketrenos43f66a62005-03-25 12:31:53 -060011009 net_dev->mem_start = pci_resource_start(pdev, 0);
11010 net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
11011
11012 err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
11013 if (err) {
11014 IPW_ERROR("failed to create sysfs device attributes\n");
Zhu Yi46441512006-01-24 16:37:59 +080011015 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011016 goto out_release_irq;
11017 }
11018
Zhu Yi46441512006-01-24 16:37:59 +080011019 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011020 err = register_netdev(net_dev);
11021 if (err) {
11022 IPW_ERROR("failed to register network device\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011023 goto out_remove_sysfs;
James Ketrenos43f66a62005-03-25 12:31:53 -060011024 }
Henrik Brix Andersen48a84772006-02-14 09:09:52 +080011025
11026 printk(KERN_INFO DRV_NAME ": Detected geography %s (%d 802.11bg "
11027 "channels, %d 802.11a channels)\n",
11028 priv->ieee->geo.name, priv->ieee->geo.bg_channels,
11029 priv->ieee->geo.a_channels);
11030
James Ketrenos43f66a62005-03-25 12:31:53 -060011031 return 0;
11032
James Ketrenosa613bff2005-08-24 21:43:11 -050011033 out_remove_sysfs:
James Ketrenos43f66a62005-03-25 12:31:53 -060011034 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011035 out_release_irq:
James Ketrenos43f66a62005-03-25 12:31:53 -060011036 free_irq(pdev->irq, priv);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011037 out_destroy_workqueue:
James Ketrenos43f66a62005-03-25 12:31:53 -060011038 destroy_workqueue(priv->workqueue);
11039 priv->workqueue = NULL;
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011040 out_iounmap:
James Ketrenos43f66a62005-03-25 12:31:53 -060011041 iounmap(priv->hw_base);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011042 out_pci_release_regions:
James Ketrenos43f66a62005-03-25 12:31:53 -060011043 pci_release_regions(pdev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011044 out_pci_disable_device:
James Ketrenos43f66a62005-03-25 12:31:53 -060011045 pci_disable_device(pdev);
11046 pci_set_drvdata(pdev, NULL);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011047 out_free_ieee80211:
James Ketrenos43f66a62005-03-25 12:31:53 -060011048 free_ieee80211(priv->net_dev);
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011049 out:
James Ketrenos43f66a62005-03-25 12:31:53 -060011050 return err;
11051}
11052
11053static void ipw_pci_remove(struct pci_dev *pdev)
11054{
11055 struct ipw_priv *priv = pci_get_drvdata(pdev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011056 struct list_head *p, *q;
11057 int i;
James Ketrenosb095c382005-08-24 22:04:42 -050011058
James Ketrenos43f66a62005-03-25 12:31:53 -060011059 if (!priv)
11060 return;
11061
Zhu Yi46441512006-01-24 16:37:59 +080011062 mutex_lock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011063
James Ketrenosafbf30a2005-08-25 00:05:33 -050011064 priv->status |= STATUS_EXIT_PENDING;
James Ketrenos43f66a62005-03-25 12:31:53 -060011065 ipw_down(priv);
James Ketrenos43f66a62005-03-25 12:31:53 -060011066 sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
11067
Zhu Yi46441512006-01-24 16:37:59 +080011068 mutex_unlock(&priv->mutex);
James Ketrenos43f66a62005-03-25 12:31:53 -060011069
11070 unregister_netdev(priv->net_dev);
11071
11072 if (priv->rxq) {
11073 ipw_rx_queue_free(priv, priv->rxq);
11074 priv->rxq = NULL;
11075 }
11076 ipw_tx_queue_free(priv);
11077
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011078 if (priv->cmdlog) {
11079 kfree(priv->cmdlog);
11080 priv->cmdlog = NULL;
11081 }
James Ketrenos43f66a62005-03-25 12:31:53 -060011082 /* ipw_down will ensure that there is no more pending work
11083 * in the workqueue's, so we can safely remove them now. */
James Ketrenosa613bff2005-08-24 21:43:11 -050011084 cancel_delayed_work(&priv->adhoc_check);
11085 cancel_delayed_work(&priv->gather_stats);
11086 cancel_delayed_work(&priv->request_scan);
11087 cancel_delayed_work(&priv->rf_kill);
11088 cancel_delayed_work(&priv->scan_check);
11089 destroy_workqueue(priv->workqueue);
11090 priv->workqueue = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011091
James Ketrenosafbf30a2005-08-25 00:05:33 -050011092 /* Free MAC hash list for ADHOC */
11093 for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
11094 list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
James Ketrenosafbf30a2005-08-25 00:05:33 -050011095 list_del(p);
Zhu Yi489f4452006-01-24 16:37:41 +080011096 kfree(list_entry(p, struct ipw_ibss_seq, list));
James Ketrenosafbf30a2005-08-25 00:05:33 -050011097 }
11098 }
11099
James Ketrenosb39860c2005-08-12 09:36:32 -050011100 if (priv->error) {
11101 ipw_free_error_log(priv->error);
11102 priv->error = NULL;
James Ketrenos43f66a62005-03-25 12:31:53 -060011103 }
11104
11105 free_irq(pdev->irq, priv);
11106 iounmap(priv->hw_base);
11107 pci_release_regions(pdev);
11108 pci_disable_device(pdev);
11109 pci_set_drvdata(pdev, NULL);
11110 free_ieee80211(priv->net_dev);
James Ketrenosafbf30a2005-08-25 00:05:33 -050011111 free_firmware();
James Ketrenos43f66a62005-03-25 12:31:53 -060011112}
11113
James Ketrenos43f66a62005-03-25 12:31:53 -060011114#ifdef CONFIG_PM
Pavel Machek583a4e82005-09-03 15:56:58 -070011115static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
James Ketrenos43f66a62005-03-25 12:31:53 -060011116{
11117 struct ipw_priv *priv = pci_get_drvdata(pdev);
11118 struct net_device *dev = priv->net_dev;
11119
11120 printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
11121
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011122 /* Take down the device; powers it off, etc. */
James Ketrenos43f66a62005-03-25 12:31:53 -060011123 ipw_down(priv);
11124
11125 /* Remove the PRESENT state of the device */
11126 netif_device_detach(dev);
11127
James Ketrenos43f66a62005-03-25 12:31:53 -060011128 pci_save_state(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011129 pci_disable_device(pdev);
Pavel Machek583a4e82005-09-03 15:56:58 -070011130 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Jeff Garzikbf794512005-07-31 13:07:26 -040011131
James Ketrenos43f66a62005-03-25 12:31:53 -060011132 return 0;
11133}
11134
11135static int ipw_pci_resume(struct pci_dev *pdev)
11136{
11137 struct ipw_priv *priv = pci_get_drvdata(pdev);
11138 struct net_device *dev = priv->net_dev;
11139 u32 val;
Jeff Garzikbf794512005-07-31 13:07:26 -040011140
James Ketrenos43f66a62005-03-25 12:31:53 -060011141 printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
11142
James Ketrenosea2b26e2005-08-24 21:25:16 -050011143 pci_set_power_state(pdev, PCI_D0);
James Ketrenos43f66a62005-03-25 12:31:53 -060011144 pci_enable_device(pdev);
James Ketrenos43f66a62005-03-25 12:31:53 -060011145 pci_restore_state(pdev);
James Ketrenosea2b26e2005-08-24 21:25:16 -050011146
James Ketrenos43f66a62005-03-25 12:31:53 -060011147 /*
11148 * Suspend/Resume resets the PCI configuration space, so we have to
11149 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
11150 * from interfering with C3 CPU state. pci_restore_state won't help
11151 * here since it only restores the first 64 bytes pci config header.
11152 */
Jeff Garzikbf794512005-07-31 13:07:26 -040011153 pci_read_config_dword(pdev, 0x40, &val);
11154 if ((val & 0x0000ff00) != 0)
James Ketrenos43f66a62005-03-25 12:31:53 -060011155 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
11156
11157 /* Set the device back into the PRESENT state; this will also wake
11158 * the queue of needed */
11159 netif_device_attach(dev);
11160
11161 /* Bring the device back up */
11162 queue_work(priv->workqueue, &priv->up);
Jeff Garzikbf794512005-07-31 13:07:26 -040011163
James Ketrenos43f66a62005-03-25 12:31:53 -060011164 return 0;
11165}
11166#endif
11167
11168/* driver initialization stuff */
11169static struct pci_driver ipw_driver = {
11170 .name = DRV_NAME,
11171 .id_table = card_ids,
11172 .probe = ipw_pci_probe,
11173 .remove = __devexit_p(ipw_pci_remove),
11174#ifdef CONFIG_PM
11175 .suspend = ipw_pci_suspend,
11176 .resume = ipw_pci_resume,
11177#endif
11178};
11179
11180static int __init ipw_init(void)
11181{
11182 int ret;
11183
11184 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
11185 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
11186
11187 ret = pci_module_init(&ipw_driver);
11188 if (ret) {
11189 IPW_ERROR("Unable to initialize PCI module\n");
11190 return ret;
11191 }
11192
Jeff Garzik0edd5b42005-09-07 00:48:31 -040011193 ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
James Ketrenos43f66a62005-03-25 12:31:53 -060011194 if (ret) {
11195 IPW_ERROR("Unable to create driver sysfs file\n");
11196 pci_unregister_driver(&ipw_driver);
11197 return ret;
11198 }
11199
11200 return ret;
11201}
11202
11203static void __exit ipw_exit(void)
11204{
11205 driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
11206 pci_unregister_driver(&ipw_driver);
11207}
11208
11209module_param(disable, int, 0444);
11210MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
11211
11212module_param(associate, int, 0444);
11213MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
11214
11215module_param(auto_create, int, 0444);
11216MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
11217
James Ketrenosa613bff2005-08-24 21:43:11 -050011218module_param(led, int, 0444);
James Ketrenosc848d0a2005-08-24 21:56:24 -050011219MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
James Ketrenosa613bff2005-08-24 21:43:11 -050011220
Zhu Yi3e1555b2006-03-06 05:48:37 +080011221#ifdef CONFIG_IPW2200_DEBUG
James Ketrenos43f66a62005-03-25 12:31:53 -060011222module_param(debug, int, 0444);
11223MODULE_PARM_DESC(debug, "debug output mask");
Zhu Yi3e1555b2006-03-06 05:48:37 +080011224#endif
James Ketrenos43f66a62005-03-25 12:31:53 -060011225
11226module_param(channel, int, 0444);
Jeff Garzikbf794512005-07-31 13:07:26 -040011227MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
James Ketrenos43f66a62005-03-25 12:31:53 -060011228
James Ketrenosb095c382005-08-24 22:04:42 -050011229#ifdef CONFIG_IPW_QOS
11230module_param(qos_enable, int, 0444);
11231MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
James Ketrenos43f66a62005-03-25 12:31:53 -060011232
James Ketrenosb095c382005-08-24 22:04:42 -050011233module_param(qos_burst_enable, int, 0444);
11234MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
11235
11236module_param(qos_no_ack_mask, int, 0444);
11237MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
11238
11239module_param(burst_duration_CCK, int, 0444);
11240MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
11241
11242module_param(burst_duration_OFDM, int, 0444);
11243MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
11244#endif /* CONFIG_IPW_QOS */
11245
11246#ifdef CONFIG_IPW2200_MONITOR
James Ketrenos43f66a62005-03-25 12:31:53 -060011247module_param(mode, int, 0444);
11248MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
11249#else
11250module_param(mode, int, 0444);
11251MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
11252#endif
11253
Zhu Yi810dabd2006-01-24 16:36:59 +080011254module_param(bt_coexist, int, 0444);
11255MODULE_PARM_DESC(bt_coexist, "enable bluetooth coexistence (default off)");
11256
James Ketrenosb095c382005-08-24 22:04:42 -050011257module_param(hwcrypto, int, 0444);
Zhu Yibde37d02006-01-24 16:38:08 +080011258MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default off)");
James Ketrenosb095c382005-08-24 22:04:42 -050011259
James Ketrenosf6c5cb72005-08-25 00:39:09 -050011260module_param(cmdlog, int, 0444);
11261MODULE_PARM_DESC(cmdlog,
11262 "allocate a ring buffer for logging firmware commands");
11263
Zhu Yi4bfdb912006-01-24 16:37:16 +080011264module_param(roaming, int, 0444);
11265MODULE_PARM_DESC(roaming, "enable roaming support (default on)");
11266
Zhu Yid2b83e12006-04-13 17:19:36 +080011267module_param(antenna, int, 0444);
11268MODULE_PARM_DESC(antenna, "select antenna 1=Main, 3=Aux, default 0 [both], 2=slow_diversity (choose the one with lower background noise)");
11269
James Ketrenos43f66a62005-03-25 12:31:53 -060011270module_exit(ipw_exit);
11271module_init(ipw_init);